Michael
below you will find a code fragment that I use to find the slot number of a
PCI card. I developed it using a sample from the MSDN library.
Best regards
F.X:
//
//============ PciFindDevice
/*
Routine Description:
Find a device on the PCI-Bus with given device and vendor ID
Arguments:
VendorId - Vendor Identifikation
DeviceId - Device Identifikation
PCISlot - Slot of PCI bus, where card is expected
BusNumber - returns bus number
SlotNumber - returns slot number
InterruptLine - returns Interrupt line
Base_0 - returns base address (HSSL Receive RAM)
Base_1 - returns base address (HSSL Transmitter)
Base_2 - returns base address (HSSL Receiver)
Return Value:
TRUE if card was found or FALSE otherwise
*/
BOOLEAN PciFindDevice(IN USHORT VendorId, IN USHORT DeviceId, IN ULONG
PCISlot, OUT PULONG BusNumber, OUT PULONG SlotNumber,
OUT PULONG InterruptLine, OUT PULONG Base_0, OUT PULONG Base_1, OUT
PULONG Base_2)
{
PCI_SLOT_NUMBER PciSlotNumberData;
PPCI_SLOT_NUMBER PciSlotNumber = &PciSlotNumberData;
PCI_COMMON_CONFIG PciCommonConfigData;
PPCI_COMMON_CONFIG PciCommonConfig = &PciCommonConfigData;
long i;
BOOLEAN bFound;
BOOLEAN FoundWrongSlot = FALSE;
ULONG ulReturn;
// initialize parameters
*BusNumber = 0;
PciSlotNumber->u.AsULONG = 0;
bFound = FALSE;
while( FALSE == bFound) // assume there are at most 4 buses
{
// get bus data
//KdPrint((“looking for Bus %d\n”,*BusNumber ));
ulReturn =
GetBusData(
PCIConfiguration,
*BusNumber,
PciSlotNumber->u.AsULONG,
PciCommonConfig,
sizeof (PCI_COMMON_CONFIG) );
// pci bus does not exist (assume that these start at
// 0 and go up with no gaps)
if( 0 == ulReturn )
{
break;
}
else if( sizeof (PCI_COMMON_CONFIG) == ulReturn )
{
// found a card… see if it is ours
if( VendorId == PciCommonConfig->VendorID &&
DeviceId == PciCommonConfig->DeviceID)
{
KdPrint((“VendorID %X DeviceID%X\n”, PciCommonConfig->VendorID, PciCommonConfig->DeviceID));
KdPrint((“Subsystem Vendor ID: %X Subsystem ID %X\n”, PciCommonConfig->u.type0.BaseAddresses[7] & 0xFFFF,
(PciCommonConfig->u.type0.BaseAddresses[7] >> 16) & 0xFFFF));
KdPrint((“PciSlotNumber->u.AsULONG %d\n”,PciSlotNumber->u.AsULONG));
if (PCISlot == PciSlotNumber->u.AsULONG)
{
// found our card… get its information
KdPrint((“VendorID %X DeviceID%X\n”, PciCommonConfig->VendorID, PciCommonConfig->DeviceID));
KdPrint((“Subsystem Vendor ID: %X Subsystem ID %X\n”, PciCommonConfig->u.type0.BaseAddresses[7] & 0xFFFF,
(PciCommonConfig->u.type0.BaseAddresses[7] >> 16) & 0xFFFF));
bFound = TRUE;
break;
}
else
{
*SlotNumber = PciSlotNumber->u.AsULONG;
FoundWrongSlot = TRUE;
}
}
}
//@@@ it appears that only the DeviceNumber of the SlotNumber is used…
//@@@ maybe if you have two or more of the same card it is used
//@@@ if it is never used or if it should be stepped first we could
//@@@ simplify the code
// step our BusNumber and/or SlotNumber
if( 31 == PciSlotNumber->u.bits.DeviceNumber &&
7 == PciSlotNumber->u.bits.FunctionNumber )
{
// try the next bus
(*BusNumber)++;
PciSlotNumber->u.AsULONG = 0;
}
else if( 7 == PciSlotNumber->u.bits.FunctionNumber )
{
// try the next device number
PciSlotNumber->u.bits.DeviceNumber++;
PciSlotNumber->u.bits.FunctionNumber = 0;
}
else
{
// try the next function number
PciSlotNumber->u.bits.FunctionNumber++;
}
}
if (bFound)
{
*SlotNumber = PciSlotNumber->u.AsULONG;
*InterruptLine = PciCommonConfig->u.type0.InterruptLine;
*Base_0 = PciCommonConfig->u.type0.BaseAddresses[0];
*Base_1 = PciCommonConfig->u.type0.BaseAddresses[1];
*Base_2 = PciCommonConfig->u.type0.BaseAddresses[2];
for (i = 0; i < 7; i++)
KdPrint((
“Base %d : %X\n”, i, PciCommonConfig->u.type0.BaseAddresses[i] - 1));
KdPrint((“Subsystem Vendor ID: %X Subsystem ID %X\n”,
PciCommonConfig->u.type0.BaseAddresses[7] & 0xFFFF,
(PciCommonConfig->u.type0.BaseAddresses[7] >> 16) &
0xFFFF));
}
return bFound || FoundWrongSlot;
}
-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com]On Behalf Of Michael Wade
Sent: Thursday, April 04, 2002 7:04 PM
To: NT Developers Interest List
Subject: [ntdev] Re: Multiple cards/devices. How does user know which is
which?
>> Just to give some background, I am trying to handle the case
where I have
>> one card simulating an Inertial Navigation System (INS) and another
> simulating the backup.
>How can 2 identical cards emulate different devices?
>If they are not really identical - can you make them different in terms
of PCI config space?
>Max
They are identical cards, but output different data. For example, each
unit outputs it’s flight address, one is 0x0a and the other 0x0b. PnP
gives them different resources, but I don’t know which is which.
The only
way I can think of to do it is by slot. But how does one get slot
information? Or is that a no no?
Thanks again,
Michael
You are currently subscribed to ntdev as: xxxxx@fxm.de
To unsubscribe send a blank email to %%email.unsub%%