|
VirtualAddress使用的是MmMapIoSpace()函数进行地址分配的
源码如下:
PUCHAR VirtualAddress(ULONG StartAddress, ULONG Length)
{
#ifndef HOST_ENABLE
ULONG inIoSpace;
#endif
PHYSICAL_ADDRESS ioPhysicalBase;
PUCHAR pjAddress;
#if 0 // Enable this section of the code for certain platforms, as necessary
// Some platform may not need this part...
#else
// Do translate to System address
#ifndef HOST_ENABLE
inIoSpace = 0;
#endif
ioPhysicalBase.HighPart = 0;
ioPhysicalBase.LowPart = StartAddress;
#ifndef HOST_ENABLE
if (!HalTranslateBusAddress(PCIBus, 0, ioPhysicalBase,
&inIoSpace,&ioPhysicalBase)
)
{
return(NULL);
}
#endif
#endif
#if 0//defined(XSCALE) // Enable this section of the code for certain platforms, as necessary
// Allocate a pointer that holds the virtual address.
pjAddress = (PUCHAR) VirtualAlloc(0, Length, MEM_RESERVE, PAGE_NOACCESS);
if (pjAddress == NULL)
return(NULL);
// (ioPhysicalBase.LowPart >> 8) because of PAGE_PHYSICAL flag
if (!VirtualCopy((PVOID) pjAddress, (PVOID) (ioPhysicalBase.LowPart >> 8), Length,
PAGE_READWRITE | PAGE_NOCACHE | PAGE_PHYSICAL))
{
VirtualFree((PVOID)pjAddress, 0, MEM_RELEASE);
return(NULL);
}
#else
pjAddress = (UCHAR*) MmMapIoSpace(ioPhysicalBase, Length, FALSE);
#endif
return(pjAddress);
} |
|