Help! How to get the DriverObject of PCI

X

Xinhai Kang

Let me clarify the problem I am facing with now.

We have a PCIe controller which includes a PCI bridge device and another PCI
device. Our driver only controls the PCI device while the PCI bridge device
is handled by Windows PCI driver. Now due to a hardware problem, I need to
access PCI configuration space of the bridge device. Well, by following the
rules of WDM, I wrote a PCI bus filter driver to filter pci.sys. This filter
driver sends IRP_MJ_PNP/IRP_MN_QUERY_INTERFACE with InterfaceType
GUID_PCI_BUS_INTERFACE_STANDARD to the PCI driver to get the
PCI_BUS_INTERFACE_STANDARD. And then our original driver communicates with
this filter driver and uses
PCI_BUS_INTERFACE_STANDARD.ReadConfig/WriteConfig to enumerate and access
any PCI devices on the system.

This works fine. However, I am looking for a simpler solution (two driver
solution is not convinient for user and I don't know if a PCI bus filter
driver is elligible for WHQL or not).

First of all, I thought I could use IoGetDeviceObjectPointer to get the DO
of PCI driver if it is created with a name, unfortunately it looks like the
DO is created without a name.

Now I thought if I could get the DriverObject of the PCI driver, then I
should be able find the PCI DO by walking through the
DriverObject->DeviceObject list. I know this list holds the PCI FDO and
PDOs for all enumerated PCI devices, however I can tell which is the FDO I
needed by checking DeviceObject->Flags.

Well, then now I am looking for a documented (or at least stable among
different Windows versions) solution to find the DriverObject of PCI. By
playing with WinDbg, it looks like I can find the PCI driver by walking
through DeviceObject->DeviceObjectExtension->AttachedTo starts with my own
DeviceObject. Unfortunately DeviceObjectExtension->AttachedTo is not a
documented field.

WinDbg command `!drvobj pci` to get the DriverObject of PCI driver. So does
WinDbg command `!object \driver\pci`. I don't know how WinDbg implements
these commands. Maybe it checks \driver in the object directory and matches
with the name, However, it looks like Windows doesn't publish the DDIs
needed to query objects under \driver directory. And also I don't know how
to interprete the queried data.

The OSR tool DeviceTree now is shipped with Windows DDK. I believe it uses
undocument fields or APIs. If MS can accept that as its public tool, Could
MS make it published to simplify our developers' life?

As you see, I am running out of solution now. Maybe I missed something,
maybe I am wrong on something, Could anybody here help me to step out of it?

Thanks a lot!
 
M

Mark Roddy

The only valid solutions are a pci bus filter driver (which you
already have implemented) or a driver for your PCI bridge device -
which I would not recommend. Walking the DriverObject is not a valid
approach. As you discovered PCI bus devices don't have names so you
can't just open them.

You have no synchronization mechanism for walking DriverObject
pointers - so this can not be done safely. You have an implemented
functional PCI bus filter driver that provides the services you need
and does so using legitimate documented methods (even if bus filter
drivers remain undocumented.) Your objections appear to be:
1) it is inconvenient to the user;
2) WHQL worthiness of filter drivers.

(1) should not be a problem - just automate and hide everything to do
with this driver from the user.

(2) filter drivers currently don't have to whql at all however VISTA
may be changing that. If it does, this sort of driver ought to qualify
for self signing.

Let me clarify the problem I am facing with now.

We have a PCIe controller which includes a PCI bridge device and another PCI
device. Our driver only controls the PCI device while the PCI bridge device
is handled by Windows PCI driver. Now due to a hardware problem, I need to
access PCI configuration space of the bridge device. Well, by following the
rules of WDM, I wrote a PCI bus filter driver to filter pci.sys. This filter
driver sends IRP_MJ_PNP/IRP_MN_QUERY_INTERFACE with InterfaceType
GUID_PCI_BUS_INTERFACE_STANDARD to the PCI driver to get the
PCI_BUS_INTERFACE_STANDARD. And then our original driver communicates with
this filter driver and uses
PCI_BUS_INTERFACE_STANDARD.ReadConfig/WriteConfig to enumerate and access
any PCI devices on the system.

This works fine. However, I am looking for a simpler solution (two driver
solution is not convinient for user and I don't know if a PCI bus filter
driver is elligible for WHQL or not).

First of all, I thought I could use IoGetDeviceObjectPointer to get the DO
of PCI driver if it is created with a name, unfortunately it looks like the
DO is created without a name.

Now I thought if I could get the DriverObject of the PCI driver, then I
should be able find the PCI DO by walking through the
DriverObject->DeviceObject list. I know this list holds the PCI FDO and
PDOs for all enumerated PCI devices, however I can tell which is the FDO I
needed by checking DeviceObject->Flags.

Well, then now I am looking for a documented (or at least stable among
different Windows versions) solution to find the DriverObject of PCI. By
playing with WinDbg, it looks like I can find the PCI driver by walking
through DeviceObject->DeviceObjectExtension->AttachedTo starts with my own
DeviceObject. Unfortunately DeviceObjectExtension->AttachedTo is not a
documented field.

WinDbg command `!drvobj pci` to get the DriverObject of PCI driver. So does
WinDbg command `!object \driver\pci`. I don't know how WinDbg implements
these commands. Maybe it checks \driver in the object directory and matches
with the name, However, it looks like Windows doesn't publish the DDIs
needed to query objects under \driver directory. And also I don't know how
to interprete the queried data.

The OSR tool DeviceTree now is shipped with Windows DDK. I believe it uses
undocument fields or APIs. If MS can accept that as its public tool, Could
MS make it published to simplify our developers' life?

As you see, I am running out of solution now. Maybe I missed something,
maybe I am wrong on something, Could anybody here help me to step out of it?

Thanks a lot!


=====================
Mark Roddy DDK MVP
Windows Vista/2003/XP/2000 Consulting
Device and Filesystem Drivers
Hollis Technology Solutions 603-321-1032
www.hollistech.com
 
D

Don Burn

While Mark is correct on not needing to WHQL the filter driver, if you need
the filter driver for proper operation of the device and you want to WHQL
the other driver you may have a problem. Microsoft is pretty strict that
drivers / devices standalone, this looks somewhat into the category that
they place virtual devices, etc. You may want to check carefully with WHQL.
 
X

Xinhai Kang

Hmm, fortunately I have made the other driver runnable without the filter
driver. And more, the hardware problem is not so easy to be triggered. So I
can pass WHQL without the filter driver installed.

Really appreciate your information.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top