I try to make it work, but …
The following is the code:
MyStartDevice(…)
{
…
case CmResourceTypeMemory:
port = resource->u.Memory.Start;
nports = resource->u.Memory.Length;
needmap = TRUE;
index = GetBarIndex(rawresource->u.Port.Start, &pciRegs);
if (index != (U32)(-1))
{
pdExt->PtrKernelBar[index] = (PU32) MmMapIoSpace(port,
nports, MmNonCached);
if (!pdExtx->PtrKernelBar[index])
return STATUS_NO_MEMORY;
// Get a MDL. The MDL will be used to map into user space
pMdl = IoAllocateMdl(pdExt->PtrKernelBar[index], nports,
FALSE, FALSE, NULL);
// Check if the MDL allocation succeeded
if (pMdl == NULL) {
DbgPrint(“my43: [StartDevice]No mdl available for BAR%i!\n”, index);
return (STATUS_INSUFFICIENT_RESOURCES);
}
// Build the MDL
MmBuildMdlForNonPagedPool(pMdl);
// Map into user space
pdExt->UserVirtual[index] = MmMapLockedPagesSpecifyCache(pMdl, UserMode,
MmNonCached, NULL, FALSE, HighPagePriority);
// Check if the mapping succeeded
if (pdExt->UserVirtual[index] == NULL) {
IoFreeMdl(pMdl);
DbgPrint(“my43: [StartDevice]No usr address available for BAR%i mdl
!\n”, index);
return (STATUS_INSUFFICIENT_RESOURCES);
}
}
break;
…
When I check “pdExt->UserVirtual[index]”, it is 0xC0000 or 0xD0000,
depending which BAR is. I pass the address through the ioctl command to the
user mode application. Of course, the application can not use it. It
appears to me 0xc0000 or 0xD0000 is like an offset to some base address
instaed of the address itself. Do I miss something? The platform is XP Pro
on Intel Pentium PC.
Thanks
AH