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

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


Accessing PCI Configuration space information from user mode

aadit0402aadit0402 Member Posts: 2

Hi All,

I am trying to write an application that should display the device's pci config space information and registers in that space. I have found out the B/D/F using the setupapi library. From the wiki.osdev.org, there I can see the calculated address of configuration space and that requires the register offset value. I passed the register offset value as 0x12. Still not sure about what register value could be passed as parameter in the pciConfigReadWord (wiki.osdev.org/PCI). I have got another address using this flag SPDRP_ADDRESS that indicates the device address. How one can find out the content of link capabilities register and status registers? Any leads will be highly appreciated.

Thanks,
Aditya

Comments

  • aadit0402aadit0402 Member Posts: 2

    this is the code snippet what i used to calculate the slot and func:
    slot = (addr >> 16) & 0xFFFF;
    func = addr & 0xFFFF;

    and these two values, I am using to read the pciconfigword.

  • Don_BurnDon_Burn Member - All Emails Posts: 1,710

    All I can say is don't do what you are attempting. The OS owns the registers to read/write the PCI config space, your poking into them can cause big problems. Consider that you need to set the address in one register, then read or write the second register, you can't be sure that you are not interrupting the OS doing the same thing, i.e. the system could have set the address, then you overwrite the address, then the system reads a value that it thinks is from the address it set and instead gets the wrong data.

    If you want to do this you will need to write a bus filter driver (which is not well documented) to capture the data you need. This is a big project.

    Before you think this is hypothetical years ago I was involved with a company that kept getting weird crashes only on their biggest customers systems. The customer was losing a ton of work, and very angry, turned out to be a 3rd party that was doing exactly what you proposed for a management tool. The 3rd party company was sued out of existence, by the customer.

  • Mark_RoddyMark_Roddy Member - All Emails Posts: 4,367
    via Email
    In reality a bus filter driver that is intended for simple tasks like this
    is fairly trivial, not "a big project". Too bad it isn't documented.

    Mark Roddy
  • Sergey_PisarevSergey_Pisarev Member - All Emails Posts: 259

    Little ot question:
    Is it difficult to do bus filter even with kmdf ? Passthrough implementation ?
    Never tried to make one, but would like to know just in case.

  • Don_BurnDon_Burn Member - All Emails Posts: 1,710

    KMDF does not support bus filters. Mark is technically correct that the bus filter should be "trivial" unfortunately having done several I find that the details of being in the middle of the PnP processing can be a pain, so it becomes a big project to get all the details right.

  • Sergey_PisarevSergey_Pisarev Member - All Emails Posts: 259

    Thank you Don !

    So bus filter should be implemented as wdm driver ? Or kmdf does support bus filtering in practice even though doesn’t formally ?
    Sorry if my question is stupid, as I have said I never tried to implement bus filters.
    Class filters with kmdf were indeed trivial.

  • Don_BurnDon_Burn Member - All Emails Posts: 1,710

    Unfortunately, KMDF does not support bus filtering at all. So you have to do it with WDM, this means tracking all the exposed PDO's so you can handle the device relations and add the filter device object to a new PDO as it occurs. Technically the logic is fairly easy, but doing it well can be challenging.

  • Sergey_PisarevSergey_Pisarev Member - All Emails Posts: 259

    Thank you very much Don !
    Really important things to know.

  • Mark_RoddyMark_Roddy Member - All Emails Posts: 4,367
    via Email
    While it is true that WDF has no explicit support for bus filters, it does
    support the entire WDM api.

    If you view a bus filter driver as having two mostly independent ‘roles’:
    1) a standard fdo upper filter role, 2) a pdo filter role, the first is
    fully supported by kmdf. Your design just has to figure out how to
    implement the second role. Using kmdf gets you the first role with only
    minimal coding. 2) is left as an exercise for the reader :-).

    On Thu, Aug 6, 2020 at 14:52 Sergey_Pisarev
    wrote:

    > OSR https://community.osr.com/
    >
    > Sergey_Pisarev commented on Accessing PCI Configuration space information
    > from user mode
    >
    > Thank you very much Don !
    >
    > Really important things to know.
    >
    > --
    > Reply to this email directly or follow the link below to check it out:
    > https://community.osr.com/discussion/comment/298104#Comment_298104
    >
    > Check it out:
    > https://community.osr.com/discussion/comment/298104#Comment_298104
    >
  • Sergey_PisarevSergey_Pisarev Member - All Emails Posts: 259

    Thank you Mark !

    I am learning many important things from OSR community this week.

Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

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 30 Nov 2020 LIVE ONLINE
Writing WDF Drivers 7 Dec 2020 LIVE ONLINE
Developing Minifilters Early 2021 LIVE ONLINE