/// 申请全局物理连续内存,用于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.