Windows System Software -- Consulting, Training, Development -- Unique Expertise, Guaranteed Results


Before Posting...

Please check out the Community Guidelines in the Announcements and Administration Category.

More Info on Driver Writing and Debugging

The free OSR Learning Library has more than 50 articles on a wide variety of topics about writing and debugging device drivers and Minifilters. From introductory level to advanced. All the articles have been recently reviewed and updated, and are written using the clear and definitive style you've come to expect from OSR over the years.

Check out The OSR Learning Library at:

MmMapIoSpace failure

shonnurshonnur Member Posts: 10

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?


  • shonnurshonnur Member Posts: 10

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

  • Tim_RobertsTim_Roberts Member - All Emails Posts: 14,295

    How large is the region?

    Tim Roberts, [email protected]
    Providenza & Boekelheide, Inc.

  • shonnurshonnur Member Posts: 10

    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?

  • Tim_RobertsTim_Roberts Member - All Emails Posts: 14,295

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

    Tim Roberts, [email protected]
    Providenza & Boekelheide, Inc.

  • shonnurshonnur Member Posts: 10

    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

    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...

  • Mark_RoddyMark_Roddy Member - All Emails Posts: 4,526

    You should not need to use HalTranslateBusAddress. Start there.

  • Tim_RobertsTim_Roberts Member - All Emails Posts: 14,295
    edited April 27

    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".

    Tim Roberts, [email protected]
    Providenza & Boekelheide, Inc.

  • Shane_CorbinShane_Corbin Member Posts: 284

    Could you share your EvtDevicePrepareHardware callback?

  • Peter_Viscarola_(OSR)Peter_Viscarola_(OSR) Administrator Posts: 8,963

    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 Viscarola

Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. Sign in or register to get started.

Upcoming OSR Seminars
OSR has suspended in-person seminars due to the Covid-19 outbreak. But, don't miss your training! Attend via the internet instead!
Internals & Software Drivers 7 February 2022 Live, Online
Kernel Debugging 21 March 2022 Live, Online
Developing Minifilters 23 May 2022 Live, Online
Writing WDF Drivers 12 September 2022 Live, Online