MmMapIoSpace failure

I am trying to map PCI-BAR addresses using MmMapIoSpace, for few devices MmMapIoSpace returns NULL.
As per the windows document “MmMapIoSpace returns the base virtual address that maps the base physical address for the range. If space for mapping the range is insufficient, it returns NULL.”

any idea how to resolve this issue? any system setting required?

I see this issue on Windows-2022, on Windows-2019 its working fine.

How large is the region?

64K, I have 6 PCI devices on this system.
Out of 6 PCI devices, MmMapIoSpace succeeds for 2 or 3 devices(have tried after system reboot) and fails for rest.

Is there a way to check how is the maximum available memory which can used for mapping? and to know which devices are consuming how much?

Also is there any registry entry which can be tuned to get going?

There are many gigabytes of non-paged address space available for this. Are the physical addresses all reasonable? Have you printed them out?

Tim,
This is how I am mapping
bRet = HalTranslateBusAddress (MaximumInterfaceType, ptrContext->NumBus, phyBusAddress, &addressSpace, &phySysAddress);
if (bRet)
{
ptrVirtualKernel = MmMapIoSpace (phySysAddress, ptrContext->Bytes, MmNonCached);

}

Looks like when the BAR address is** greater than 32-bits Mapping fails** i.e. if “address.high” is not zero…i see below from logs

Logs:
This succeeds as “high” is 0x0
00000008 10.68698788 MAP Bus Translate (Buffer) for high:0x00000000 low:0x92c20000
00000009 10.68699265 MAP Bus Translate for 0x0000000092c20000 bytes:0x10000

this fails as “high” is not 0x0
00000071 11.16248894 MAP Bus Translate (Buffer) for high:0x00000001 low:0x92c00000
00000072 11.16249466 MAP Bus Translate for 0x0000000192c00000 bytes:0x10000
00000073 11.16249943 Bus Translated to 0000000192c00000, Address Space 0x0
00000074 11.16250515 Insufficent resource error…

You should not need to use HalTranslateBusAddress. Start there.

1 Like

Those addresses do not make sense. You would not get both 00000000_92c20000 and 00000001_92c20000 for the same kind of device. In fact, it’s unlikely that you would get 0x92c20000 at all. BIOSes put the PCIe space up near 0xFFFFFFFF. I would expect addresses in the 0xFxxxxxxx region, or maybe 0xExxxxxxx. Where do you get those physical addresses? Are you processing this during EvtDevicePrepareHardware, or are you using some hackery to read config space on your own?

And WHY ON EARTH would you specify “MaximumInterfaceType”? That’s a flag value, and is not a legitimate value under any circumstances. These are PCI devices, yes? The bus type is “PCIBus”.

Could you share your EvtDevicePrepareHardware callback?

Let’s back up.

Tell us what you’re doing. You DO realize that HalTranslateBusAddress is no longer supported, right? Is this an NT V4 style driver that you’re trying to “fix”?

Please explain to us what you’re trying to do, and how you’re getting your device resources.

Peter