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

Home NTDEV

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: https://www.osr.com/osr-learning-library/


Before Posting...

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

How dynamically re-assign bus numbers

MetekMetek Member - All Emails Posts: 55
Hi All,

I'm working on the driver for specific device connected to the system via ExpressCard. Operating system is Windows 7. Device itself represent two bridges with a secondary buse each. When ExpressCard is inserted by system startup, Windows enumerates buses properly:

[0:1C:0] PCIe Port1-> [0B - 0B]
[0:1C:1] PCIe Port2-> [0C - 0C]
[0:1C:2] PCIe Port3-> [0D - 0D]
[0:1C:3] PCIe Port4-> [0E - 10] -> [0E:0:0] Bridge1 -> [0F - 10] -> [0F:0:0] Bridge2 -> [10-10] - OK
[0:1C:4] PCIe Port5-> [11 - 11]
[0:1C:5] PCIe Port6-> [09 - 09]

However, when ExpressCard is hot inserted, Windows multi-level rebalancing works wrongly:

[0:1C:0] PCIe Port1-> [0B - 0B]
[0:1C:1] PCIe Port2-> [0C - 0C]
[0:1C:2] PCIe Port3-> [0D - 0B]
[0:1C:3] PCIe Port4-> [0E - 0F] -> [0E:0:0] Bridge1 -> [0F - 10] -> [0F:0:0] Bridge2 ->Fails
[0:1C:4] PCIe Port5-> [10 - 10]
[0:1C:5] PCIe Port6-> [09 - 09]

Visibly, in the second case, configuration fails because there is not enough buses reserved for PCIe Port 4. My questions:
1. How can I from driver for Bridge1 force rebalancing on PCIe Port 4?
Note: I tried already simple things like IoInvalidateDeviceState
2. Where pci.sys saves information which secondary/subordinate bus to assign to each bridge in the system during the initial enumeration?

Thank you in advance for any hint.

With best regards,

Al

Comments

  • Doron_HolanDoron_Holan Member - All Emails Posts: 10,645
    To short circuit this, your driver cannot change the way bus numbers are assigned, either through hw resource assignment or touching internal PCI.sys structures.

    d

    debt from my phone
    ________________________________
    From: [email protected]
    Sent: 3/26/2012 6:26 AM
    To: Windows System Software Devs Interest List
    Subject: [ntdev] How dynamically re-assign bus numbers

    Hi All,

    I'm working on the driver for specific device connected to the system via ExpressCard. Operating system is Windows 7. Device itself represent two bridges with a secondary buse each. When ExpressCard is inserted by system startup, Windows enumerates buses properly:

    [0:1C:0] PCIe Port1-> [0B - 0B]
    [0:1C:1] PCIe Port2-> [0C - 0C]
    [0:1C:2] PCIe Port3-> [0D - 0D]
    [0:1C:3] PCIe Port4-> [0E - 10] -> [0E:0:0] Bridge1 -> [0F - 10] -> [0F:0:0] Bridge2 -> [10-10] - OK
    [0:1C:4] PCIe Port5-> [11 - 11]
    [0:1C:5] PCIe Port6-> [09 - 09]

    However, when ExpressCard is hot inserted, Windows multi-level rebalancing works wrongly:

    [0:1C:0] PCIe Port1-> [0B - 0B]
    [0:1C:1] PCIe Port2-> [0C - 0C]
    [0:1C:2] PCIe Port3-> [0D - 0B]
    [0:1C:3] PCIe Port4-> [0E - 0F] -> [0E:0:0] Bridge1 -> [0F - 10] -> [0F:0:0] Bridge2 ->Fails
    [0:1C:4] PCIe Port5-> [10 - 10]
    [0:1C:5] PCIe Port6-> [09 - 09]

    Visibly, in the second case, configuration fails because there is not enough buses reserved for PCIe Port 4. My questions:
    1. How can I from driver for Bridge1 force rebalancing on PCIe Port 4?
    Note: I tried already simple things like IoInvalidateDeviceState
    2. Where pci.sys saves information which secondary/subordinate bus to assign to each bridge in the system during the initial enumeration?

    Thank you in advance for any hint.

    With best regards,

    Al

    ---
    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=ListServer
    d
  • MetekMetek Member - All Emails Posts: 55
    Hi Doron,

    Thank you for your reply.

    However, Windows 7 on startup without Express Card assigns 2 buses to PCIe Port 4, while only one bus is assigned to other PCIe ports. Furtermore buses are not assigned in order (Bus 9 is assigned to PCIe Port 5).
    I would assume that either Windows saves initial assignment of PCI buses somewhere in the registry. Question is where? Another possibility is that pci.sys uses configuration assigned by BIOS. In such case, it should be a possible to change this configuration even before pci.sys is started. Isn't?

    With best regards,

    Al
  • Pavel_APavel_A Member Posts: 2,802
    A test on win8 CP, while you're waiting for answers, may be helpful.

    --pa


    On 26-Mar-2012 15:25, [email protected] wrote:
    > Hi All,
    >
    > I'm working on the driver for specific device connected to the system via ExpressCard. Operating system is Windows 7. Device itself represent two bridges with a secondary buse each. When ExpressCard is inserted by system startup, Windows enumerates buses properly:
    >
    > [0:1C:0] PCIe Port1-> [0B - 0B]
    > [0:1C:1] PCIe Port2-> [0C - 0C]
    > [0:1C:2] PCIe Port3-> [0D - 0D]
    > [0:1C:3] PCIe Port4-> [0E - 10] -> [0E:0:0] Bridge1 -> [0F - 10] -> [0F:0:0] Bridge2 -> [10-10] - OK
    > [0:1C:4] PCIe Port5-> [11 - 11]
    > [0:1C:5] PCIe Port6-> [09 - 09]
    >
    > However, when ExpressCard is hot inserted, Windows multi-level rebalancing works wrongly:
    >
    > [0:1C:0] PCIe Port1-> [0B - 0B]
    > [0:1C:1] PCIe Port2-> [0C - 0C]
    > [0:1C:2] PCIe Port3-> [0D - 0B]
    > [0:1C:3] PCIe Port4-> [0E - 0F] -> [0E:0:0] Bridge1 -> [0F - 10] -> [0F:0:0] Bridge2 ->Fails
    > [0:1C:4] PCIe Port5-> [10 - 10]
    > [0:1C:5] PCIe Port6-> [09 - 09]
    >
    > Visibly, in the second case, configuration fails because there is not enough buses reserved for PCIe Port 4. My questions:
    > 1. How can I from driver for Bridge1 force rebalancing on PCIe Port 4?
    > Note: I tried already simple things like IoInvalidateDeviceState
    > 2. Where pci.sys saves information which secondary/subordinate bus to assign to each bridge in the system during the initial enumeration?
    >
    > Thank you in advance for any hint.
    >
    > With best regards,
    >
    > Al
    >
  • MetekMetek Member - All Emails Posts: 55
    Thank you, Pavel A. In my initial post is specified that I'm asking about Windows 7
  • Pavel_APavel_A Member Posts: 2,802
    On 26-Mar-2012 22:21, [email protected] wrote:
    > Thank you, Pavel A. In my initial post is specified that I'm asking about Windows 7

    So, it is useful for you to know about Win8.
    If your card works with Win8, you can request the fix backported to
    Win7. If not - file a bug against win8, it may get some attention.

    -- pa
  • MetekMetek Member - All Emails Posts: 55
    Pavel, please stop it. We need solution for existing Windows 7 and not back-ported thing. If you know solution, please tell us. If not, please do not participate in this thread.
  • Tim_RobertsTim_Roberts Member - All Emails Posts: 14,109
    [email protected] wrote:
    > Pavel, please stop it. We need solution for existing Windows 7 and not back-ported thing. If you know solution, please tell us. If not, please do not participate in this thread.

    I think you are being unreasonable. You seem to be describing what
    might be a problem in Windows. If you can show that the problem is
    fixed in Windows 8, then I don't see what's wrong with pursuing a course
    of action that tries to get Microsoft to port that fix back to Windows
    7. That is SURELY a far better solution that coding up some half-assed
    hack job that you downloaded off of a tricks web site somewhere.

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

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

  • Doron_HolanDoron_Holan Member - All Emails Posts: 10,645
    You are assuming you can fix this with a registry setting or API call. Not so. Rebalance is expensive. What you are seeing could very well be by design or a limitation of rebalance on win7. The suggestion to test on w8 is a very good one. If it still shows up in w8, it will probably be more difficult for you to get this fixed and thus realize you must take another course of action

    d

    debt from my phone
    ________________________________
    From: Tim Roberts
    Sent: 3/26/2012 5:42 PM
    To: Windows System Software Devs Interest List
    Subject: Re: [ntdev] How dynamically re-assign bus numbers

    [email protected] wrote:
    > Pavel, please stop it. We need solution for existing Windows 7 and not back-ported thing. If you know solution, please tell us. If not, please do not participate in this thread.

    I think you are being unreasonable. You seem to be describing what
    might be a problem in Windows. If you can show that the problem is
    fixed in Windows 8, then I don't see what's wrong with pursuing a course
    of action that tries to get Microsoft to port that fix back to Windows
    7. That is SURELY a far better solution that coding up some half-assed
    hack job that you downloaded off of a tricks web site somewhere.

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


    ---
    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=ListServer
    d
  • MetekMetek Member - All Emails Posts: 55
    Gentlemen,

    Thank you for your suggestions. We certainly will test under Win8. However right now we need a solution for Windows 7. I already understood from the very first reply from Doron that dynamic rebalancing will not be possible. However, it should not be a problem to reserve certain bus ranges at startup. Once again, is anybody know where Windows store the information used for initial buses configuration?

    With best regards,

    Al
  • Jake_OshinsJake_Oshins Member Posts: 1,058
    Windows doesn't renumber PCI buses. It will assign bus numbers to buses
    which seem to have none. But it won't change what the BIOS did.

    This is a stance that we've come to after many years of debugging machines
    where the BIOS has implicit assumptions that the bus numbers would never
    change and/or machines where the "bridges" in the chipset weren't really PCI
    at all and they weren't exactly PCI compliant.

    So, to answer your question, many machines will function if you renumber the
    PCI bus numbers before Windows takes control. Some others won't. In either
    case, Windows will think that the BIOS did it an preserve what you've done.
    I think that you're making a mistake with this strategy, however. The only
    safe way to deal with bus numbers is to leave it to the BIOS.



    Jake Oshins
    (most recent guy to touch all this code in PCI.sys)
    Windows Kernel Team


    This post implies no warrantees and confers no rights.
    ------------------------------------------------------------
    wrote in message news:[email protected].

    Hi Doron,

    Thank you for your reply.

    However, Windows 7 on startup without Express Card assigns 2 buses to PCIe
    Port 4, while only one bus is assigned to other PCIe ports. Furtermore buses
    are not assigned in order (Bus 9 is assigned to PCIe Port 5).
    I would assume that either Windows saves initial assignment of PCI buses
    somewhere in the registry. Question is where? Another possibility is that
    pci.sys uses configuration assigned by BIOS. In such case, it should be a
    possible to change this configuration even before pci.sys is started. Isn't?

    With best regards,

    Al
  • Jake_OshinsJake_Oshins Member Posts: 1,058
    Yes, I know exactly where Windows stores that information: in internal
    undocumented data structures, in RAM. This isn't something you can safely
    manipulate.




    Jake Oshins
    Windows Kernel Team


    This post implies no warrantees and confers no rights.
    ------------------------------------------------------------
    wrote in message news:[email protected]

    Gentlemen,

    Thank you for your suggestions. We certainly will test under Win8. However
    right now we need a solution for Windows 7. I already understood from the
    very first reply from Doron that dynamic rebalancing will not be possible.
    However, it should not be a problem to reserve certain bus ranges at
    startup. Once again, is anybody know where Windows store the information
    used for initial buses configuration?

    With best regards,

    Al
  • MetekMetek Member - All Emails Posts: 55
    Hi Jake,

    Thanks a lot for a clear and finally an engineering reply. I got your point. In my understanding, if Windows re-enumerates buses for cold-insertion scenario and system after such re-enumeration works fine, we can safely assume that if we will re-program subordinate bus at the system startup it will work either.

    Short extra question: pci.sys in Vista is more or less the same as in Win7?

    Best regards, and thank you again.

    Al
  • Doron_HolanDoron_Holan Member - All Emails Posts: 10,645
    No, the driver between the two releases is different

    d

    debt from my phone
    ________________________________
    From: [email protected]
    Sent: 3/27/2012 7:40 AM
    To: Windows System Software Devs Interest List
    Subject: RE:[ntdev] How dynamically re-assign bus numbers

    Hi Jake,

    Thanks a lot for a clear and finally an engineering reply. I got your point. In my understanding, if Windows re-enumerates buses for cold-insertion scenario and system after such re-enumeration works fine, we can safely assume that if we will re-program subordinate bus at the system startup it will work either.

    Short extra question: pci.sys in Vista is more or less the same as in Win7?

    Best regards, and thank you again.

    Al

    ---
    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=ListServer
    d
  • MetekMetek Member - All Emails Posts: 55
    Thank you, Doron.

    With best regards,

    Al
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 15 November 2021 Live, Online
Writing WDF Drivers 24 January 2022 Live, Online
Developing Minifilters 7 February 2022 Live, Online
Kernel Debugging 21 March 2022 Live, Online