How can I get the BAR0 start address in my WDF PCI driver? RRS feed

  • Question

  • My PCI device has two BAR(BAR0 and BAR2).

    In EvtDevicePrepareHardware function,I use an ULONG varible( pDeviceContext->PhysicalAddressRegister ) to record the physical start address like this:

    for (i = 0; i < WdfCmResourceListGetCount(ResourceListTranslated); i++) {
    		descriptor = WdfCmResourceListGetDescriptor(ResourceListTranslated, i);
    		if (!descriptor) {
    		switch (descriptor->Type) {
    		case CmResourceTypeMemory:
    			pDeviceContext->PhysicalAddressRegister = descriptor->u.Memory.Start.LowPart;
    			pDeviceContext->MemBaseAddress = MmMapIoSpace(
    			pDeviceContext->MemLength = descriptor->u.Memory.Length;

    Then I find it's value is 0xD200 0000 in my application.Obviously,this is BAR2 physical start address rather than BAR0's,because in device manager it shows as following:

    So how can I get the BAR0 physical start address?

    I find the return value of WdfCmResourceListGetCount(ResourceListTranslated) is 5.So when i equals 4,I get the BAR2 physical start address.Will I get the BAR0 physical start address when i is less than 4?


    Monday, May 18, 2015 3:12 AM


All replies

  • I get the BAR0 physical start address  when i == 0.
    Monday, May 18, 2015 8:33 AM
  • You have to design your driver so that it can handle multiple memory BAR's.  Fortunately since your BAR's are differing sizes it is easy to distinguish between BAR0 (size 40000) and BAR2 (size 4000).  Use the size to test whether to store the data in the BAR0 or BAR2 information are in the context.

    Don Burn Windows Driver Consulting Website:

    Monday, May 18, 2015 11:06 AM
  • Also, note that memory resources for the BARs in the list _must_ go in sequential order (so BAR2 cannot get before BAR0, this is guaranteed).

    -- pa

    Monday, May 18, 2015 11:30 AM