- Support for IRP_MN_QUERY_BUS_INFORMATION and devices on multiple PCI buses.

svn path=/trunk/; revision=8662
This commit is contained in:
Filip Navara 2004-03-12 19:40:05 +00:00
parent 7b9bc747c8
commit 5c45ab6ac0
3 changed files with 112 additions and 68 deletions

View file

@ -1,4 +1,4 @@
/* $Id: fdo.c,v 1.5 2003/12/12 21:54:42 ekohl Exp $ /* $Id: fdo.c,v 1.6 2004/03/12 19:40:05 navaraf Exp $
* *
* PROJECT: ReactOS PCI bus driver * PROJECT: ReactOS PCI bus driver
* FILE: fdo.c * FILE: fdo.c
@ -13,7 +13,7 @@
#include "pcidef.h" #include "pcidef.h"
#include "pci.h" #include "pci.h"
#define NDEBUG //#define NDEBUG
#include <debug.h> #include <debug.h>
/*** PRIVATE *****************************************************************/ /*** PRIVATE *****************************************************************/
@ -61,6 +61,7 @@ FdoEnumerateDevices(
PLIST_ENTRY CurrentEntry; PLIST_ENTRY CurrentEntry;
PPCI_DEVICE Device; PPCI_DEVICE Device;
PCI_SLOT_NUMBER SlotNumber; PCI_SLOT_NUMBER SlotNumber;
ULONG BusNumber;
ULONG DeviceNumber; ULONG DeviceNumber;
ULONG FunctionNumber; ULONG FunctionNumber;
ULONG Size; ULONG Size;
@ -82,70 +83,75 @@ FdoEnumerateDevices(
DeviceExtension->DeviceListCount = 0; DeviceExtension->DeviceListCount = 0;
/* Enumerate devices on the PCI bus */ /* Enumerate devices on the PCI bus */
SlotNumber.u.AsULONG = 0; for (BusNumber = 0; BusNumber < 8; BusNumber++)
for (DeviceNumber = 0; DeviceNumber < PCI_MAX_DEVICES; DeviceNumber++)
{ {
SlotNumber.u.bits.DeviceNumber = DeviceNumber; SlotNumber.u.AsULONG = 0;
for (FunctionNumber = 0; FunctionNumber < PCI_MAX_FUNCTION; FunctionNumber++) for (DeviceNumber = 0; DeviceNumber < PCI_MAX_DEVICES; DeviceNumber++)
{ {
SlotNumber.u.bits.FunctionNumber = FunctionNumber; SlotNumber.u.bits.DeviceNumber = DeviceNumber;
for (FunctionNumber = 0; FunctionNumber < PCI_MAX_FUNCTION; FunctionNumber++)
Size= HalGetBusData(PCIConfiguration,
DeviceExtension->BusNumber,
SlotNumber.u.AsULONG,
&PciConfig,
sizeof(PCI_COMMON_CONFIG));
DPRINT("Size %lu\n", Size);
if (Size < sizeof(PCI_COMMON_CONFIG))
{ {
if (FunctionNumber == 0) SlotNumber.u.bits.FunctionNumber = FunctionNumber;
Size= HalGetBusData(PCIConfiguration,
BusNumber,
SlotNumber.u.AsULONG,
&PciConfig,
sizeof(PCI_COMMON_CONFIG));
DPRINT("Size %lu\n", Size);
if (Size < sizeof(PCI_COMMON_CONFIG))
{ {
break; if (FunctionNumber == 0)
{
break;
}
else
{
continue;
}
} }
else
DPRINT("Bus %1lu Device %2lu Func %1lu VenID 0x%04hx DevID 0x%04hx\n",
BusNumber,
DeviceNumber,
FunctionNumber,
PciConfig.VendorID,
PciConfig.DeviceID);
Status = FdoLocateChildDevice(&Device, DeviceExtension, SlotNumber, &PciConfig);
if (!NT_SUCCESS(Status))
{ {
continue; Device = (PPCI_DEVICE)ExAllocatePool(PagedPool, sizeof(PCI_DEVICE));
if (!Device)
{
/* FIXME: Cleanup resources for already discovered devices */
return STATUS_INSUFFICIENT_RESOURCES;
}
RtlZeroMemory (Device,
sizeof(PCI_DEVICE));
Device->BusNumber = BusNumber;
RtlCopyMemory (&Device->SlotNumber,
&SlotNumber,
sizeof(PCI_SLOT_NUMBER));
RtlCopyMemory (&Device->PciConfig,
&PciConfig,
sizeof(PCI_COMMON_CONFIG));
ExInterlockedInsertTailList(
&DeviceExtension->DeviceListHead,
&Device->ListEntry,
&DeviceExtension->DeviceListLock);
} }
/* Don't remove this device */
Device->RemovePending = FALSE;
DeviceExtension->DeviceListCount++;
} }
DPRINT("Bus %1lu Device %2lu Func %1lu VenID 0x%04hx DevID 0x%04hx\n",
DeviceExtension->BusNumber,
DeviceNumber,
FunctionNumber,
PciConfig.VendorID,
PciConfig.DeviceID);
Status = FdoLocateChildDevice(&Device, DeviceExtension, SlotNumber, &PciConfig);
if (!NT_SUCCESS(Status))
{
Device = (PPCI_DEVICE)ExAllocatePool(PagedPool, sizeof(PCI_DEVICE));
if (!Device)
{
/* FIXME: Cleanup resources for already discovered devices */
return STATUS_INSUFFICIENT_RESOURCES;
}
RtlZeroMemory (Device,
sizeof(PCI_DEVICE));
RtlCopyMemory (&Device->SlotNumber,
&SlotNumber,
sizeof(PCI_SLOT_NUMBER));
RtlCopyMemory (&Device->PciConfig,
&PciConfig,
sizeof(PCI_COMMON_CONFIG));
ExInterlockedInsertTailList(
&DeviceExtension->DeviceListHead,
&Device->ListEntry,
&DeviceExtension->DeviceListLock);
}
/* Don't remove this device */
Device->RemovePending = FALSE;
DeviceExtension->DeviceListCount++;
} }
} }
@ -239,6 +245,10 @@ FdoQueryBusRelations(
PdoDeviceExtension->Common.DevicePowerState = PowerDeviceD0; PdoDeviceExtension->Common.DevicePowerState = PowerDeviceD0;
PdoDeviceExtension->Fdo = DeviceObject;
PdoDeviceExtension->BusNumber = Device->BusNumber;
/* FIXME: Get device properties (Hardware IDs, etc.) */ /* FIXME: Get device properties (Hardware IDs, etc.) */
swprintf( swprintf(
@ -310,10 +320,6 @@ FdoStartDevice(
InitializeListHead(&DeviceExtension->DeviceListHead); InitializeListHead(&DeviceExtension->DeviceListHead);
KeInitializeSpinLock(&DeviceExtension->DeviceListLock); KeInitializeSpinLock(&DeviceExtension->DeviceListLock);
DeviceExtension->DeviceListCount = 0; DeviceExtension->DeviceListCount = 0;
/* FIXME: Find a way to get this information */
DeviceExtension->BusNumber = 0;
DeviceExtension->State = dsStarted; DeviceExtension->State = dsStarted;
//Irp->IoStatus.Information = 0; //Irp->IoStatus.Information = 0;

View file

@ -1,4 +1,4 @@
/* $Id: pci.h,v 1.4 2003/12/12 21:54:42 ekohl Exp $ */ /* $Id: pci.h,v 1.5 2004/03/12 19:40:05 navaraf Exp $ */
#ifndef __PCI_H #ifndef __PCI_H
#define __PCI_H #define __PCI_H
@ -17,7 +17,9 @@ typedef struct _PCI_DEVICE
LIST_ENTRY ListEntry; LIST_ENTRY ListEntry;
// Physical Device Object of device // Physical Device Object of device
PDEVICE_OBJECT Pdo; PDEVICE_OBJECT Pdo;
/* PCI Slot number */ // PCI bus number
ULONG BusNumber;
// PCI slot number
PCI_SLOT_NUMBER SlotNumber; PCI_SLOT_NUMBER SlotNumber;
// PCI configuration data // PCI configuration data
PCI_COMMON_CONFIG PciConfig; PCI_COMMON_CONFIG PciConfig;
@ -52,6 +54,10 @@ typedef struct _PDO_DEVICE_EXTENSION
{ {
// Common device data // Common device data
COMMON_DEVICE_EXTENSION Common; COMMON_DEVICE_EXTENSION Common;
// Functional device object
PDEVICE_OBJECT Fdo;
// PCI bus number
ULONG BusNumber;
// Device ID // Device ID
UNICODE_STRING DeviceID; UNICODE_STRING DeviceID;
// Instance ID // Instance ID
@ -71,8 +77,6 @@ typedef struct _FDO_DEVICE_EXTENSION
{ {
// Common device data // Common device data
COMMON_DEVICE_EXTENSION Common; COMMON_DEVICE_EXTENSION Common;
// Physical Device Object
PDEVICE_OBJECT Pdo;
// Current state of the driver // Current state of the driver
PCI_DEVICE_STATE State; PCI_DEVICE_STATE State;
// Namespace device list // Namespace device list
@ -82,7 +86,7 @@ typedef struct _FDO_DEVICE_EXTENSION
// Lock for namespace device list // Lock for namespace device list
KSPIN_LOCK DeviceListLock; KSPIN_LOCK DeviceListLock;
// PCI bus number // PCI bus number
ULONG BusNumber; /* ULONG BusNumber;*/
// Lower device object // Lower device object
PDEVICE_OBJECT Ldo; PDEVICE_OBJECT Ldo;
} __attribute((packed)) FDO_DEVICE_EXTENSION, *PFDO_DEVICE_EXTENSION; } __attribute((packed)) FDO_DEVICE_EXTENSION, *PFDO_DEVICE_EXTENSION;

View file

@ -1,4 +1,4 @@
/* $Id: pdo.c,v 1.2 2003/12/12 21:54:42 ekohl Exp $ /* $Id: pdo.c,v 1.3 2004/03/12 19:40:05 navaraf Exp $
* *
* PROJECT: ReactOS PCI bus driver * PROJECT: ReactOS PCI bus driver
* FILE: pdo.c * FILE: pdo.c
@ -16,6 +16,8 @@
#define NDEBUG #define NDEBUG
#include <debug.h> #include <debug.h>
DEFINE_GUID(GUID_BUS_TYPE_PCI, 0xc8ebdfb0L, 0xb510, 0x11d0, 0x80, 0xe5, 0x00, 0xa0, 0xc9, 0x25, 0x42, 0xe3);
/*** PRIVATE *****************************************************************/ /*** PRIVATE *****************************************************************/
NTSTATUS NTSTATUS
@ -75,6 +77,35 @@ PdoQueryId(
} }
NTSTATUS
PdoQueryBusInformation(
IN PDEVICE_OBJECT DeviceObject,
IN PIRP Irp,
PIO_STACK_LOCATION IrpSp)
{
PPDO_DEVICE_EXTENSION DeviceExtension;
PFDO_DEVICE_EXTENSION FdoDeviceExtension;
PPNP_BUS_INFORMATION BusInformation;
DPRINT("Called\n");
DeviceExtension = (PPDO_DEVICE_EXTENSION)DeviceObject->DeviceExtension;
FdoDeviceExtension = (PFDO_DEVICE_EXTENSION)DeviceExtension->Fdo->DeviceExtension;
BusInformation = ExAllocatePool(PagedPool, sizeof(PNP_BUS_INFORMATION));
Irp->IoStatus.Information = (ULONG_PTR)BusInformation;
if (BusInformation != NULL)
{
BusInformation->BusTypeGuid = GUID_BUS_TYPE_PCI;
BusInformation->LegacyBusType = PCIBus;
BusInformation->BusNumber = DeviceExtension->BusNumber;
return STATUS_INSUFFICIENT_RESOURCES;
}
return STATUS_SUCCESS;
}
NTSTATUS NTSTATUS
PdoSetPower( PdoSetPower(
IN PDEVICE_OBJECT DeviceObject, IN PDEVICE_OBJECT DeviceObject,
@ -139,10 +170,13 @@ PdoPnpControl(
case IRP_MN_EJECT: case IRP_MN_EJECT:
break; break;
#endif
case IRP_MN_QUERY_BUS_INFORMATION: case IRP_MN_QUERY_BUS_INFORMATION:
Status = PdoQueryBusInformation(DeviceObject, Irp, IrpSp);
break; break;
#if 0
case IRP_MN_QUERY_CAPABILITIES: case IRP_MN_QUERY_CAPABILITIES:
break; break;