Differentiating between BAR0, BAR1, etc..., on PCIe card

I have a WDM driver being used with a proprietary PCIe card. The card has a single memory area so I only ever see one CmResourceTypeMemory in the resource list.

I am now changing the driver code to handle a variation of the previous PCIe card but the new card has multiple memory areas. The code appears to work fine by treating the first CmResourceTypeMemory resource as BAR0, the second one as BAR1, and so on. The memory resources appear to be reported to the driver code in the proper order.

Is it guaranteed that the order matches the order of resources on the card itself? Is there a way to know that a specific CmResourceTypeMemory resource is a particular BAR on the card?

Thanks.

Dave

It is not guaranteed, but has been the case. Most people plan their
cards so there is either different size memory or that there is an easy
test to determine which BAR is which once they are mapped.

Don Burn
Windows Filesystem and Driver Consulting
Website: http://www.windrvr.com
Blog: http://msmvps.com/blogs/WinDrvr

xxxxx@activemotif.com” wrote in message
news:xxxxx@ntdev:

> I have a WDM driver being used with a proprietary PCIe card. The card has a single memory area so I only ever see one CmResourceTypeMemory in the resource list.
>
> I am now changing the driver code to handle a variation of the previous PCIe card but the new card has multiple memory areas. The code appears to work fine by treating the first CmResourceTypeMemory resource as BAR0, the second one as BAR1, and so on. The memory resources appear to be reported to the driver code in the proper order.
>
> Is it guaranteed that the order matches the order of resources on the card itself? Is there a way to know that a specific CmResourceTypeMemory resource is a particular BAR on the card?
>
> Thanks.
>
> Dave

If it isn’t the case a whole lot of drivers are going to be horribly broken.

Mark Roddy

On Wed, Aug 17, 2011 at 3:47 PM, Don Burn wrote:

> It is not guaranteed, but has been the case. Most people plan their cards
> so there is either different size memory or that there is an easy test to
> determine which BAR is which once they are mapped.
>
>
> Don Burn
> Windows Filesystem and Driver Consulting
> Website: http://www.windrvr.com
> Blog: http://msmvps.com/blogs/ WinDrvr http:
>
>
>
> “xxxxx@activemotif.com” wrote in message
> news:xxxxx@ntdev:
>
>
> I have a WDM driver being used with a proprietary PCIe card. The card has
>> a single memory area so I only ever see one CmResourceTypeMemory in the
>> resource list.
>>
>> I am now changing the driver code to handle a variation of the previous
>> PCIe card but the new card has multiple memory areas. The code appears to
>> work fine by treating the first CmResourceTypeMemory resource as BAR0, the
>> second one as BAR1, and so on. The memory resources appear to be reported to
>> the driver code in the proper order.
>>
>> Is it guaranteed that the order matches the order of resources on the card
>> itself? Is there a way to know that a specific CmResourceTypeMemory resource
>> is a particular BAR on the card?
>>
>> Thanks.
>>
>> Dave
>>
>
>
> —
> NTDEV is sponsored by OSR
>
> For our schedule of WDF, WDM, debugging and other seminars visit:
> http://www.osr.com/seminars
>
> To unsubscribe, visit the List Server section of OSR Online at
> http://www.osronline.com/page.
cfm?name=ListServerhttp:
></http:></http:>

It is documented clearly:
http://msdn.microsoft.com/en-us/library/ff537445(VS.85).aspx

“The order of the resources that are reported in the start-device I/O
request packet (IRP) should match the order of the resources that are listed
in the PCI base address registers (BARs)…
The ordering of descriptors for BARs in a resource list is guaranteed to
match the BARs on a PCI device on all hardware platforms.”

–pa

“Mark Roddy” wrote in message news:xxxxx@ntdev…
> If it isn’t the case a whole lot of drivers are going to be horribly
> broken.
>
> Mark Roddy
>
>
> On Wed, Aug 17, 2011 at 3:47 PM, Don Burn wrote:
>
>> It is not guaranteed, but has been the case. Most people plan their
>> cards
>> so there is either different size memory or that there is an easy test to
>> determine which BAR is which once they are mapped.
>>
>>
>> Don Burn
>> Windows Filesystem and Driver Consulting
>> Website: http://www.windrvr.com
>> Blog: http://msmvps.com/blogs/ WinDrvr http:
>>
>>
>>
>> “xxxxx@activemotif.com” wrote in message
>> news:xxxxx@ntdev:
>>
>>
>> I have a WDM driver being used with a proprietary PCIe card. The card
>> has
>>> a single memory area so I only ever see one CmResourceTypeMemory in the
>>> resource list.
>>>
>>> I am now changing the driver code to handle a variation of the previous
>>> PCIe card but the new card has multiple memory areas. The code appears
>>> to
>>> work fine by treating the first CmResourceTypeMemory resource as BAR0,
>>> the
>>> second one as BAR1, and so on. The memory resources appear to be
>>> reported to
>>> the driver code in the proper order.
>>>
>>> Is it guaranteed that the order matches the order of resources on the
>>> card
>>> itself? Is there a way to know that a specific CmResourceTypeMemory
>>> resource
>>> is a particular BAR on the card?
>>>
>>> Thanks.
>>>
>>> Dave
>>>
>>
>>
>> —
>> NTDEV is sponsored by OSR
>>
>> For our schedule of WDF, WDM, debugging and other seminars visit:
>> http://www.osr.com/seminars
>>
>> To unsubscribe, visit the List Server section of OSR Online at
>> http://www.osronline.com/page.
cfm?name=ListServerhttp:
>>
></http:></http:>

Interesting, I still have an email from Redmond when I asked that years
ago, and that is what I based my answer on. Nice to know they decided
to make it predictable.

Don Burn
Windows Filesystem and Driver Consulting
Website: http://www.windrvr.com
Blog: http://msmvps.com/blogs/WinDrvr

“Pavel A.” wrote in message news:xxxxx@ntdev:

> It is documented clearly:
> http://msdn.microsoft.com/en-us/library/ff537445(VS.85).aspx
>
> “The order of the resources that are reported in the start-device I/O
> request packet (IRP) should match the order of the resources that are listed
> in the PCI base address registers (BARs)…
> The ordering of descriptors for BARs in a resource list is guaranteed to
> match the BARs on a PCI device on all hardware platforms.”
>
> --pa
>
> “Mark Roddy” wrote in message news:xxxxx@ntdev…
> > If it isn’t the case a whole lot of drivers are going to be horribly
> > broken.
> >
> > Mark Roddy
> >
> >
> > On Wed, Aug 17, 2011 at 3:47 PM, Don Burn wrote:
> >
> >> It is not guaranteed, but has been the case. Most people plan their
> >> cards
> >> so there is either different size memory or that there is an easy test to
> >> determine which BAR is which once they are mapped.
> >>
> >>
> >> Don Burn
> >> Windows Filesystem and Driver Consulting
> >> Website: http://www.windrvr.com
> >> Blog: http://msmvps.com/blogs/ WinDrvr http:
> >>
> >>
> >>
> >> “xxxxx@activemotif.com” wrote in message
> >> news:xxxxx@ntdev:
> >>
> >>
> >> I have a WDM driver being used with a proprietary PCIe card. The card
> >> has
> >>> a single memory area so I only ever see one CmResourceTypeMemory in the
> >>> resource list.
> >>>
> >>> I am now changing the driver code to handle a variation of the previous
> >>> PCIe card but the new card has multiple memory areas. The code appears
> >>> to
> >>> work fine by treating the first CmResourceTypeMemory resource as BAR0,
> >>> the
> >>> second one as BAR1, and so on. The memory resources appear to be
> >>> reported to
> >>> the driver code in the proper order.
> >>>
> >>> Is it guaranteed that the order matches the order of resources on the
> >>> card
> >>> itself? Is there a way to know that a specific CmResourceTypeMemory
> >>> resource
> >>> is a particular BAR on the card?
> >>>
> >>> Thanks.
> >>>
> >>> Dave
> >>>
> >>
> >>
> >> —
> >> NTDEV is sponsored by OSR
> >>
> >> For our schedule of WDF, WDM, debugging and other seminars visit:
> >> http://www.osr.com/seminars
> >>
> >> To unsubscribe, visit the List Server section of OSR Online at
> >> http://www.osronline.com/page.
cfm?name=ListServerhttp:
> >>
> ></http:></http:>

I was just in that code yesterday. Not only do the docs say that the order
is guaranteed, I’m certain that we’d keep it the same just to make sure that
we don’t break lots of drivers.

Just to underscore that point, we leave a “device private” resource
descriptor between every meaningful descriptor just because the original PCI
driver did that, even though it’s completely unused today. We’ve actually
seen drivers that broke when we remove them.

Jake Oshins
Hyper-V I/O Architect (occasional PCI guy)
Windows Kernel Group

This post implies no warranties and confers no rights.


“Don Burn” wrote in message news:xxxxx@ntdev…

Interesting, I still have an email from Redmond when I asked that years
ago, and that is what I based my answer on. Nice to know they decided
to make it predictable.

Don Burn
Windows Filesystem and Driver Consulting
Website: http://www.windrvr.com
Blog: http://msmvps.com/blogs/WinDrvr

“Pavel A.” wrote in message news:xxxxx@ntdev:

> It is documented clearly:
> http://msdn.microsoft.com/en-us/library/ff537445(VS.85).aspx
>
> “The order of the resources that are reported in the start-device I/O
> request packet (IRP) should match the order of the resources that are
> listed
> in the PCI base address registers (BARs)…
> The ordering of descriptors for BARs in a resource list is guaranteed to
> match the BARs on a PCI device on all hardware platforms.”
>
> --pa
>
> “Mark Roddy” wrote in message news:xxxxx@ntdev…
> > If it isn’t the case a whole lot of drivers are going to be horribly
> > broken.
> >
> > Mark Roddy
> >
> >
> > On Wed, Aug 17, 2011 at 3:47 PM, Don Burn wrote:
> >
> >> It is not guaranteed, but has been the case. Most people plan their
> >> cards
> >> so there is either different size memory or that there is an easy test
> >> to
> >> determine which BAR is which once they are mapped.
> >>
> >>
> >> Don Burn
> >> Windows Filesystem and Driver Consulting
> >> Website: http://www.windrvr.com
> >> Blog: http://msmvps.com/blogs/ WinDrvr
> >> http:
> >>
> >>
> >>
> >> “xxxxx@activemotif.com” wrote in message
> >> news:xxxxx@ntdev:
> >>
> >>
> >> I have a WDM driver being used with a proprietary PCIe card. The card
> >> has
> >>> a single memory area so I only ever see one CmResourceTypeMemory in
> >>> the
> >>> resource list.
> >>>
> >>> I am now changing the driver code to handle a variation of the
> >>> previous
> >>> PCIe card but the new card has multiple memory areas. The code appears
> >>> to
> >>> work fine by treating the first CmResourceTypeMemory resource as BAR0,
> >>> the
> >>> second one as BAR1, and so on. The memory resources appear to be
> >>> reported to
> >>> the driver code in the proper order.
> >>>
> >>> Is it guaranteed that the order matches the order of resources on the
> >>> card
> >>> itself? Is there a way to know that a specific CmResourceTypeMemory
> >>> resource
> >>> is a particular BAR on the card?
> >>>
> >>> Thanks.
> >>>
> >>> Dave
> >>>
> >>
> >>
> >> —
> >> NTDEV is sponsored by OSR
> >>
> >> For our schedule of WDF, WDM, debugging and other seminars visit:
> >> http://www.osr.com/seminars
> >>
> >> To unsubscribe, visit the List Server section of OSR Online at
> >> http://www.osronline.com/page.
cfm?name=ListServerhttp:
> >>
> ></http:></http:>