Accessing PCI Configuration space information from user mode

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

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.

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.

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

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.

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.

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.

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.

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

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
>

Thank you Mark !

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