How to get the PCI slot and bus number on Win 2K.

0 Likes

Problem:

I wrote a WDM PCI driver for my card and I want to get the slot number and bus number. The functions in DriverWorks are defined out on WDM drivers. So how do I obtain this information.

Resolution:

The code in DriverWorks is defined out because the PnP manager has control of the resource that a device gets. The bus driver handles all communication with the bus and your device so there is not normally a need to do this.

In the rare case that one wants to do this there is a documented way to do this. The following is taken from an article by Mark Roddy of Hollis Technology Solutions. The original article can be found at http://www.hollistech.com/Resources/Misc articles/Howtobusslot.htm.

The function provided in the windows DDK is the IoGetDeviceProperty. It is defined as follows:

NTSTATUS

IoGetDeviceProperty(

IN PDEVICE_OBJECT DeviceObject,

IN DEVICE_REGISTRY_PROPERTY DeviceProperty,

IN ULONG BufferLength,

OUT PVOID PropertyBuffer,

OUT PULONG ResultLength

);

There are two keys here, The first is the DeviceObject. This is the address of the PDO that is handed to you when your StartDevice is called. You can save this into the DeviceExtension of your FDO DeviceObject. The second is the DeviceProperty this determines if you want the bus or the slot information. So your code might look like this:

//Get the bus number. Note the use of DevicePropertyBusNumber.

ULONG length = 0;

ULONG busNumber = 0xffffffff;

NTSTATUS

status = IoGetDeviceProperty(PdoDevice,

DevicePropertyBusNumber,

sizeof(ULONG),

&busNumber,

&length);

//On success the bus number will be filled in and the length will be

//the sizeof(ULONG).

//Now get the Slot number. Note the use of DevicePropertyAddress.

PCI_SLOT_NUMBER slotNumber;

ULONG length = 0;

NTSTATUS

status = IoGetDeviceProperty(PdoDevice,

DevicePropertyAddress,

sizeof(ULONG),

&slotNumber,

&length);

//On successful return the slotNumber will be in the DeviceNumber field of the SlotNumber structure.

The article pointed to above has some more details but this should be sufficient in most cases.

Old KB# 11330
Comment List
Anonymous
Related Discussions
Recommended