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.

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值