- 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
* FILE: fdo.c
@ -13,7 +13,7 @@
#include "pcidef.h"
#include "pci.h"
#define NDEBUG
//#define NDEBUG
#include <debug.h>
/*** PRIVATE *****************************************************************/
@ -61,6 +61,7 @@ FdoEnumerateDevices(
PLIST_ENTRY CurrentEntry;
PPCI_DEVICE Device;
PCI_SLOT_NUMBER SlotNumber;
ULONG BusNumber;
ULONG DeviceNumber;
ULONG FunctionNumber;
ULONG Size;
@ -82,70 +83,75 @@ FdoEnumerateDevices(
DeviceExtension->DeviceListCount = 0;
/* Enumerate devices on the PCI bus */
SlotNumber.u.AsULONG = 0;
for (DeviceNumber = 0; DeviceNumber < PCI_MAX_DEVICES; DeviceNumber++)
for (BusNumber = 0; BusNumber < 8; BusNumber++)
{
SlotNumber.u.bits.DeviceNumber = DeviceNumber;
for (FunctionNumber = 0; FunctionNumber < PCI_MAX_FUNCTION; FunctionNumber++)
SlotNumber.u.AsULONG = 0;
for (DeviceNumber = 0; DeviceNumber < PCI_MAX_DEVICES; DeviceNumber++)
{
SlotNumber.u.bits.FunctionNumber = 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))
SlotNumber.u.bits.DeviceNumber = DeviceNumber;
for (FunctionNumber = 0; FunctionNumber < PCI_MAX_FUNCTION; FunctionNumber++)
{
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->Fdo = DeviceObject;
PdoDeviceExtension->BusNumber = Device->BusNumber;
/* FIXME: Get device properties (Hardware IDs, etc.) */
swprintf(
@ -310,10 +320,6 @@ FdoStartDevice(
InitializeListHead(&DeviceExtension->DeviceListHead);
KeInitializeSpinLock(&DeviceExtension->DeviceListLock);
DeviceExtension->DeviceListCount = 0;
/* FIXME: Find a way to get this information */
DeviceExtension->BusNumber = 0;
DeviceExtension->State = dsStarted;
//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
#define __PCI_H
@ -17,7 +17,9 @@ typedef struct _PCI_DEVICE
LIST_ENTRY ListEntry;
// Physical Device Object of device
PDEVICE_OBJECT Pdo;
/* PCI Slot number */
// PCI bus number
ULONG BusNumber;
// PCI slot number
PCI_SLOT_NUMBER SlotNumber;
// PCI configuration data
PCI_COMMON_CONFIG PciConfig;
@ -52,6 +54,10 @@ typedef struct _PDO_DEVICE_EXTENSION
{
// Common device data
COMMON_DEVICE_EXTENSION Common;
// Functional device object
PDEVICE_OBJECT Fdo;
// PCI bus number
ULONG BusNumber;
// Device ID
UNICODE_STRING DeviceID;
// Instance ID
@ -71,8 +77,6 @@ typedef struct _FDO_DEVICE_EXTENSION
{
// Common device data
COMMON_DEVICE_EXTENSION Common;
// Physical Device Object
PDEVICE_OBJECT Pdo;
// Current state of the driver
PCI_DEVICE_STATE State;
// Namespace device list
@ -82,7 +86,7 @@ typedef struct _FDO_DEVICE_EXTENSION
// Lock for namespace device list
KSPIN_LOCK DeviceListLock;
// PCI bus number
ULONG BusNumber;
/* ULONG BusNumber;*/
// Lower device object
PDEVICE_OBJECT Ldo;
} __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
* FILE: pdo.c
@ -16,6 +16,8 @@
#define NDEBUG
#include <debug.h>
DEFINE_GUID(GUID_BUS_TYPE_PCI, 0xc8ebdfb0L, 0xb510, 0x11d0, 0x80, 0xe5, 0x00, 0xa0, 0xc9, 0x25, 0x42, 0xe3);
/*** PRIVATE *****************************************************************/
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
PdoSetPower(
IN PDEVICE_OBJECT DeviceObject,
@ -139,10 +170,13 @@ PdoPnpControl(
case IRP_MN_EJECT:
break;
#endif
case IRP_MN_QUERY_BUS_INFORMATION:
Status = PdoQueryBusInformation(DeviceObject, Irp, IrpSp);
break;
#if 0
case IRP_MN_QUERY_CAPABILITIES:
break;