Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

51 lines
1.6 KiB

  1. // $Header: G:/SwDev/WDM/Video/bt848/rcs/Riscmem.cpp 1.5 1998/04/29 22:43:38 tomz Exp $
  2. #include "pspagebl.h"
  3. #include "defaults.h"
  4. typedef struct
  5. {
  6. DWORD dwSize;
  7. } BT_MEMBLOCK, *PBT_MEMBLOCK;
  8. /* this is a rather simple allocator. It divides entire space into 2 parts:
  9. 1 - for VBI program allocations, 2 - for video program allocations. In addi-
  10. tion, each VBI program is equal in size ( same goes for video programs ).
  11. The distinction between video and VBI programs is made based on asked size.
  12. It is known the VBI programs are always smaller. VBI programs range is from
  13. zero to MaxVBISize, above memory is for video programs. Total size is big
  14. enough to hold all risc programs.
  15. */
  16. void PsPageBlock::AllocateSpace( DWORD dwSize )
  17. {
  18. PBYTE pBuf = (PBYTE)StreamClassGetDmaBuffer( gpHwDeviceExtension );
  19. DWORD dwBlockSize = MaxVBISize;
  20. if ( dwSize > MaxVBISize ) {
  21. pBuf += VideoOffset;
  22. dwBlockSize = MaxVidSize;
  23. }
  24. // now start searching for the available spot
  25. while ( 1 ) {
  26. PBT_MEMBLOCK pMemBlk = PBT_MEMBLOCK( pBuf );
  27. if ( pMemBlk->dwSize ) // this block is occupied
  28. pBuf += dwBlockSize;
  29. else {
  30. pMemBlk->dwSize = dwBlockSize;
  31. LinAddr_ = pMemBlk + 1;
  32. ULONG len;
  33. PhysAddr_ = StreamClassGetPhysicalAddress( gpHwDeviceExtension, NULL, LinAddr_,
  34. DmaBuffer, &len ).LowPart;
  35. break;
  36. }
  37. }
  38. }
  39. void PsPageBlock::FreeSpace()
  40. {
  41. PBT_MEMBLOCK pMemBlk = PBT_MEMBLOCK( (PDWORD)LinAddr_ - 1 );
  42. pMemBlk->dwSize = 0;
  43. }