MmAllocateContiguousMemory&&MmGetPhysicalAddress

 /////////////////////// 申請全局物理連續內存,用於D1預覽及原始視頻/////////////////////

 RtlZeroMemory(&g_DriverInfo,sizeof(g_DriverInfo));

 PHYSICAL_ADDRESS pa;          //物理地址
 pa.QuadPart = 0xFFFFFFFFFFFFFFFF; //@最大的可用的物理地址

// g_DriverInfo.vaD1Buffer = MmAllocateContiguousMemory(MAX_DMA_PVBUF,pa);
// if ( g_DriverInfo.vaD1Buffer != NULL )
// {
//  g_DriverInfo.paD1Buffer = MmGetPhysicalAddress(g_DriverInfo.vaD1Buffer);
//  }

 g_DriverInfo.vaOvBuffer = MmAllocateContiguousMemory(MAX_DMA_OVBUF,pa);//@原始視頻虛擬地址
 if ( g_DriverInfo.vaOvBuffer != NULL )//@虛擬地址分配成功
 {
  g_DriverInfo.paOvBuffer = MmGetPhysicalAddress(g_DriverInfo.vaOvBuffer);//@返回虛擬地址對應的物理地址
 }
 ///////////////////////20080218-END////////////////////////////////////////////////////////////

 

用到的函數:

1、MmAllocateContiguousMemory

     函數原型:

  PVOID
  MmAllocateContiguousMemory(
  IN ULONG NumberOfBytes,
  IN PHYSICAL_ADDRESS HighestAcceptableAddress
  );

 

2、MmGetPhysicalAddress()

 

MmGetPhysicalAddress

PHYSICAL_ADDRESS
  MmGetPhysicalAddress(
  IN PVOID BaseAddress
  );

MmGetPhysicalAddress returns the physical address corresponding to a valid virtual address.

Parameters

BaseAddress
Points to the virtual address for which to return the physical address.

Include

ntddk.h

Return Value

MmGetPhysicalAddress returns the physical address that corresponds to the given virtual address.

Comments

Callers of MmGetPhysicalAddress can be running at any IRQL, provided that the BaseAddress value is valid.

 

MmAllocateContiguousMemory allocates a range of physically contiguous, cache-aligned memory from nonpaged pool.

Parameters

NumberOfBytes
Specifies the size in bytes of the block of contiguous memory to be allocated.
HighestAcceptableAddress
Specifies the highest valid physical address the driver can use. For example, if a device can only reference physical memory in the lower 16MB, this value would be set to 0x00000000FFFFFF.

Include

ntddk.h

Return Value

MmAllocateContiguousMemory returns the base virtual address for the allocated memory. If the request cannot be satisfied, NULL is returned.

發佈了21 篇原創文章 · 獲贊 3 · 訪問量 10萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章