Transform pci.sys to a Plug-and-Play driver.

Simplify most of the PciCreateCompatible*String functions
Fix error handling in FdoQueryBusRelations
=> pci.sys now manages only 1 bus. It is still using HalGetBusDataByOffset/HalGetBusData which are deprecated, but it shouldn't be too hard to remove

svn path=/trunk/; revision=18449
This commit is contained in:
Hervé Poussineau 2005-10-14 18:29:55 +00:00
parent 72dd7eefe0
commit 463b91a5b9
5 changed files with 231 additions and 283 deletions

View file

@ -583,16 +583,12 @@ HKLM,"SYSTEM\CurrentControlSet\Enum\Root\Ne2000\0000","ClassGUID",0x00000000,"{4
HKLM,"SYSTEM\CurrentControlSet\Enum\Root\Ne2000\0000","Driver",0x00000000,"{4D36E972-E325-11CE-BFC1-08002BE10318}\0001" HKLM,"SYSTEM\CurrentControlSet\Enum\Root\Ne2000\0000","Driver",0x00000000,"{4D36E972-E325-11CE-BFC1-08002BE10318}\0001"
; PCI driver ; PCI driver
HKLM,"SYSTEM\CurrentControlSet\Services\Pci","ErrorControl",0x00010001,0x00000000 HKLM,"SYSTEM\CurrentControlSet\Enum\Root\*PNP0A03\0000","HardwareID",0x00010000,"*PNP0A03"
HKLM,"SYSTEM\CurrentControlSet\Services\Pci","Group",0x00000000,"Boot Bus Extender" HKLM,"SYSTEM\CurrentControlSet\Enum\Root\*PNP0A03\0000","DeviceDesc",0x00000000,"PCI bus"
HKLM,"SYSTEM\CurrentControlSet\Services\Pci","ImagePath",0x00020000,"system32\drivers\pci.sys" HKLM,"SYSTEM\CurrentControlSet\Enum\Root\*PNP0A03\0000\LogConf","BasicConfigVector",0x000A0001, \
HKLM,"SYSTEM\CurrentControlSet\Services\Pci","Start",0x00010001,0x00000000 40,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00, \
HKLM,"SYSTEM\CurrentControlSet\Services\Pci","Tag",0x00010001,0x00000002 01,00,00,00,01,00,01,00,01,00,00,00, \
HKLM,"SYSTEM\CurrentControlSet\Services\Pci","Type",0x00010001,0x00000001 00,06,00,00,00,00,00,00,01,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00
HKLM,"SYSTEM\CurrentControlSet\Enum\Root\PCI\0000","Service",0x00000000,"Pci"
HKLM,"SYSTEM\CurrentControlSet\Enum\Root\PCI\0000","Class",0x00000000,"Computer"
HKLM,"SYSTEM\CurrentControlSet\Enum\Root\PCI\0000","ClassGUID",0x00000000,"{4D36E966-E325-11CE-BFC1-08002BE10318}"
HKLM,"SYSTEM\CurrentControlSet\Enum\Root\PCI\0000","ParentIdPrefix",0x0000000,"0000"
; ReactOS PCNet NIC driver ; ReactOS PCNet NIC driver
; To use the AMD supplied driver change the driver name to pcntn5m.sys ; To use the AMD supplied driver change the driver name to pcntn5m.sys

View file

@ -1,5 +1,4 @@
/* $Id$ /*
*
* PROJECT: ReactOS PCI bus driver * PROJECT: ReactOS PCI bus driver
* FILE: fdo.c * FILE: fdo.c
* PURPOSE: PCI device object dispatch routines * PURPOSE: PCI device object dispatch routines
@ -22,7 +21,6 @@ static NTSTATUS
FdoLocateChildDevice( FdoLocateChildDevice(
PPCI_DEVICE *Device, PPCI_DEVICE *Device,
PFDO_DEVICE_EXTENSION DeviceExtension, PFDO_DEVICE_EXTENSION DeviceExtension,
ULONG BusNumber,
PCI_SLOT_NUMBER SlotNumber, PCI_SLOT_NUMBER SlotNumber,
PPCI_COMMON_CONFIG PciConfig) PPCI_COMMON_CONFIG PciConfig)
{ {
@ -38,8 +36,7 @@ FdoLocateChildDevice(
/* If both vendor ID and device ID match, it is the same device */ /* If both vendor ID and device ID match, it is the same device */
if ((PciConfig->VendorID == CurrentDevice->PciConfig.VendorID) && if ((PciConfig->VendorID == CurrentDevice->PciConfig.VendorID) &&
(PciConfig->DeviceID == CurrentDevice->PciConfig.DeviceID) && (PciConfig->DeviceID == CurrentDevice->PciConfig.DeviceID) &&
(SlotNumber.u.AsULONG == CurrentDevice->SlotNumber.u.AsULONG) && (SlotNumber.u.AsULONG == CurrentDevice->SlotNumber.u.AsULONG)) {
(BusNumber == CurrentDevice->BusNumber)) {
*Device = CurrentDevice; *Device = CurrentDevice;
DPRINT("Done\n"); DPRINT("Done\n");
return STATUS_SUCCESS; return STATUS_SUCCESS;
@ -63,7 +60,6 @@ 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;
@ -85,8 +81,6 @@ FdoEnumerateDevices(
DeviceExtension->DeviceListCount = 0; DeviceExtension->DeviceListCount = 0;
/* Enumerate devices on the PCI bus */ /* Enumerate devices on the PCI bus */
for (BusNumber = 0; BusNumber < 8; BusNumber++)
{
SlotNumber.u.AsULONG = 0; SlotNumber.u.AsULONG = 0;
for (DeviceNumber = 0; DeviceNumber < PCI_MAX_DEVICES; DeviceNumber++) for (DeviceNumber = 0; DeviceNumber < PCI_MAX_DEVICES; DeviceNumber++)
{ {
@ -96,7 +90,7 @@ FdoEnumerateDevices(
SlotNumber.u.bits.FunctionNumber = FunctionNumber; SlotNumber.u.bits.FunctionNumber = FunctionNumber;
DPRINT("Bus %1lu Device %2lu Func %1lu\n", DPRINT("Bus %1lu Device %2lu Func %1lu\n",
BusNumber, DeviceExtension->BusNumber,
DeviceNumber, DeviceNumber,
FunctionNumber); FunctionNumber);
@ -104,7 +98,7 @@ FdoEnumerateDevices(
sizeof(PCI_COMMON_CONFIG)); sizeof(PCI_COMMON_CONFIG));
Size = HalGetBusData(PCIConfiguration, Size = HalGetBusData(PCIConfiguration,
BusNumber, DeviceExtension->BusNumber,
SlotNumber.u.AsULONG, SlotNumber.u.AsULONG,
&PciConfig, &PciConfig,
PCI_COMMON_HDR_LENGTH); PCI_COMMON_HDR_LENGTH);
@ -122,13 +116,13 @@ FdoEnumerateDevices(
} }
DPRINT("Bus %1lu Device %2lu Func %1lu VenID 0x%04hx DevID 0x%04hx\n", DPRINT("Bus %1lu Device %2lu Func %1lu VenID 0x%04hx DevID 0x%04hx\n",
BusNumber, DeviceExtension->BusNumber,
DeviceNumber, DeviceNumber,
FunctionNumber, FunctionNumber,
PciConfig.VendorID, PciConfig.VendorID,
PciConfig.DeviceID); PciConfig.DeviceID);
Status = FdoLocateChildDevice(&Device, DeviceExtension, BusNumber, SlotNumber, &PciConfig); Status = FdoLocateChildDevice(&Device, DeviceExtension, SlotNumber, &PciConfig);
if (!NT_SUCCESS(Status)) if (!NT_SUCCESS(Status))
{ {
Device = (PPCI_DEVICE)ExAllocatePool(PagedPool, sizeof(PCI_DEVICE)); Device = (PPCI_DEVICE)ExAllocatePool(PagedPool, sizeof(PCI_DEVICE));
@ -141,7 +135,7 @@ FdoEnumerateDevices(
RtlZeroMemory(Device, RtlZeroMemory(Device,
sizeof(PCI_DEVICE)); sizeof(PCI_DEVICE));
Device->BusNumber = BusNumber; Device->BusNumber = DeviceExtension->BusNumber;
RtlCopyMemory(&Device->SlotNumber, RtlCopyMemory(&Device->SlotNumber,
&SlotNumber, &SlotNumber,
@ -170,7 +164,6 @@ FdoEnumerateDevices(
} }
} }
} }
}
DPRINT("Done\n"); DPRINT("Done\n");
@ -263,18 +256,13 @@ FdoQueryBusRelations(
PdoDeviceExtension->Fdo = DeviceObject; PdoDeviceExtension->Fdo = DeviceObject;
PdoDeviceExtension->BusNumber = Device->BusNumber; PdoDeviceExtension->PciDevice = Device;
RtlCopyMemory(
&PdoDeviceExtension->SlotNumber,
&Device->SlotNumber,
sizeof(PCI_SLOT_NUMBER));
/* Add Device ID string */ /* Add Device ID string */
if (!PciCreateDeviceIDString(&PdoDeviceExtension->DeviceID, Status = PciCreateDeviceIDString(&PdoDeviceExtension->DeviceID, Device);
Device)) if (!NT_SUCCESS(Status))
{ {
ErrorStatus = STATUS_INSUFFICIENT_RESOURCES; ErrorStatus = Status;
ErrorOccurred = TRUE; ErrorOccurred = TRUE;
break; break;
} }
@ -282,46 +270,46 @@ FdoQueryBusRelations(
DPRINT("DeviceID: %S\n", PdoDeviceExtension->DeviceID.Buffer); DPRINT("DeviceID: %S\n", PdoDeviceExtension->DeviceID.Buffer);
/* Add Instance ID string */ /* Add Instance ID string */
if (!PciCreateInstanceIDString(&PdoDeviceExtension->InstanceID, Status = PciCreateInstanceIDString(&PdoDeviceExtension->InstanceID, Device);
Device)) if (!NT_SUCCESS(Status))
{ {
ErrorStatus = STATUS_INSUFFICIENT_RESOURCES; ErrorStatus = Status;
ErrorOccurred = TRUE; ErrorOccurred = TRUE;
break; break;
} }
/* Add Hardware IDs string */ /* Add Hardware IDs string */
if (!PciCreateHardwareIDsString(&PdoDeviceExtension->HardwareIDs, Status = PciCreateHardwareIDsString(&PdoDeviceExtension->HardwareIDs, Device);
Device)) if (!NT_SUCCESS(Status))
{ {
ErrorStatus = STATUS_INSUFFICIENT_RESOURCES; ErrorStatus = Status;
ErrorOccurred = TRUE; ErrorOccurred = TRUE;
break; break;
} }
/* Add Compatible IDs string */ /* Add Compatible IDs string */
if (!PciCreateCompatibleIDsString(&PdoDeviceExtension->CompatibleIDs, Status = PciCreateCompatibleIDsString(&PdoDeviceExtension->CompatibleIDs, Device);
Device)) if (!NT_SUCCESS(Status))
{ {
ErrorStatus = STATUS_INSUFFICIENT_RESOURCES; ErrorStatus = Status;
ErrorOccurred = TRUE; ErrorOccurred = TRUE;
break; break;
} }
/* Add device description string */ /* Add device description string */
if (!PciCreateDeviceDescriptionString(&PdoDeviceExtension->DeviceDescription, Status = PciCreateDeviceDescriptionString(&PdoDeviceExtension->DeviceDescription, Device);
Device)) if (!NT_SUCCESS(Status))
{ {
ErrorStatus = STATUS_INSUFFICIENT_RESOURCES; ErrorStatus = Status;
ErrorOccurred = TRUE; ErrorOccurred = TRUE;
break; break;
} }
/* Add device location string */ /* Add device location string */
if (!PciCreateDeviceLocationString(&PdoDeviceExtension->DeviceLocation, Status = PciCreateDeviceLocationString(&PdoDeviceExtension->DeviceLocation, Device);
Device)) if (!NT_SUCCESS(Status))
{ {
ErrorStatus = STATUS_INSUFFICIENT_RESOURCES; ErrorStatus = Status;
ErrorOccurred = TRUE; ErrorOccurred = TRUE;
break; break;
} }
@ -345,7 +333,11 @@ FdoQueryBusRelations(
/* FIXME: Should IoAttachDeviceToDeviceStack() be undone? */ /* FIXME: Should IoAttachDeviceToDeviceStack() be undone? */
if (PdoDeviceExtension) { if (PdoDeviceExtension) {
RtlFreeUnicodeString(&PdoDeviceExtension->DeviceID); RtlFreeUnicodeString(&PdoDeviceExtension->DeviceID);
ExFreePool(PdoDeviceExtension); RtlFreeUnicodeString(&PdoDeviceExtension->InstanceID);
RtlFreeUnicodeString(&PdoDeviceExtension->HardwareIDs);
RtlFreeUnicodeString(&PdoDeviceExtension->CompatibleIDs);
RtlFreeUnicodeString(&PdoDeviceExtension->DeviceDescription);
RtlFreeUnicodeString(&PdoDeviceExtension->DeviceLocation);
} }
ExFreePool(Relations); ExFreePool(Relations);
@ -366,19 +358,62 @@ FdoStartDevice(
IN PIRP Irp) IN PIRP Irp)
{ {
PFDO_DEVICE_EXTENSION DeviceExtension; PFDO_DEVICE_EXTENSION DeviceExtension;
PCM_RESOURCE_LIST AllocatedResources;
PCM_PARTIAL_RESOURCE_DESCRIPTOR ResourceDescriptor;
ULONG FoundBusNumber = FALSE;
ULONG i;
DPRINT("Called\n"); DPRINT("Called\n");
DeviceExtension = (PFDO_DEVICE_EXTENSION)DeviceObject->DeviceExtension; DeviceExtension = (PFDO_DEVICE_EXTENSION)DeviceObject->DeviceExtension;
assert(DeviceExtension->State == dsStopped); AllocatedResources = IoGetCurrentIrpStackLocation(Irp)->Parameters.StartDevice.AllocatedResources;
if (!AllocatedResources)
{
DPRINT("PCI: No allocated resources sent to driver\n");
return STATUS_INSUFFICIENT_RESOURCES;
}
if (AllocatedResources->Count < 1)
{
DPRINT("PCI: Not enough allocated resources sent to driver\n");
return STATUS_INSUFFICIENT_RESOURCES;
}
if (AllocatedResources->List[0].PartialResourceList.Version != 1
|| AllocatedResources->List[0].PartialResourceList.Revision != 1)
return STATUS_REVISION_MISMATCH;
ASSERT(DeviceExtension->State == dsStopped);
for (i = 0; i < AllocatedResources->List[0].PartialResourceList.Count; i++)
{
ResourceDescriptor = &AllocatedResources->List[0].PartialResourceList.PartialDescriptors[i];
switch (ResourceDescriptor->Type)
{
case CmResourceTypeBusNumber:
{
if (FoundBusNumber || ResourceDescriptor->u.BusNumber.Length != 1)
return STATUS_INVALID_PARAMETER;
DeviceExtension->BusNumber = ResourceDescriptor->u.BusNumber.Start;
DPRINT("PCI: Found bus number resource: %lu\n", DeviceExtension->BusNumber);
FoundBusNumber = TRUE;
break;
}
default:
DPRINT1("PCI: Unknown resource descriptor type 0x%x\n", ResourceDescriptor->Type);
}
}
if (!FoundBusNumber)
{
DPRINT("PCI: All required resources were not found in allocated resources list\n");
return STATUS_INSUFFICIENT_RESOURCES;
}
InitializeListHead(&DeviceExtension->DeviceListHead); InitializeListHead(&DeviceExtension->DeviceListHead);
KeInitializeSpinLock(&DeviceExtension->DeviceListLock); KeInitializeSpinLock(&DeviceExtension->DeviceListLock);
DeviceExtension->DeviceListCount = 0; DeviceExtension->DeviceListCount = 0;
DeviceExtension->State = dsStarted; DeviceExtension->State = dsStarted;
//Irp->IoStatus.Information = 0; Irp->IoStatus.Information = 0;
return STATUS_SUCCESS; return STATUS_SUCCESS;
} }

View file

@ -1,5 +1,4 @@
/* $Id$ /*
*
* PROJECT: ReactOS PCI Bus driver * PROJECT: ReactOS PCI Bus driver
* FILE: pci.c * FILE: pci.c
* PURPOSE: Driver entry * PURPOSE: Driver entry
@ -185,7 +184,7 @@ DriverEntry(
} }
BOOLEAN NTSTATUS
PciCreateDeviceIDString(PUNICODE_STRING DeviceID, PciCreateDeviceIDString(PUNICODE_STRING DeviceID,
PPCI_DEVICE Device) PPCI_DEVICE Device)
{ {
@ -199,75 +198,36 @@ PciCreateDeviceIDString(PUNICODE_STRING DeviceID,
Device->PciConfig.u.type0.SubVendorID, Device->PciConfig.u.type0.SubVendorID,
Device->PciConfig.RevisionID); Device->PciConfig.RevisionID);
if (!RtlCreateUnicodeString(DeviceID, Buffer)) return RtlCreateUnicodeString(DeviceID, Buffer) ? STATUS_SUCCESS : STATUS_INSUFFICIENT_RESOURCES;
{
return FALSE;
}
return TRUE;
} }
BOOLEAN NTSTATUS
PciCreateInstanceIDString(PUNICODE_STRING InstanceID, PciCreateInstanceIDString(PUNICODE_STRING InstanceID,
PPCI_DEVICE Device) PPCI_DEVICE Device)
{ {
#if 0
WCHAR Buffer[32]; WCHAR Buffer[32];
ULONG Length;
ULONG Index; ULONG Index;
Index = swprintf(Buffer, Index = 0;
L"%lX&%02lX", if (((PPDO_DEVICE_EXTENSION)Device->Pdo->DeviceExtension)->PciDevice->BusNumber != 0)
Device->BusNumber,
(Device->SlotNumber.u.bits.DeviceNumber << 3) +
Device->SlotNumber.u.bits.FunctionNumber);
Index++;
Buffer[Index] = UNICODE_NULL;
Length = (Index + 1) * sizeof(WCHAR);
InstanceID->Buffer = ExAllocatePool(PagedPool, Length);
if (InstanceID->Buffer == NULL)
{ {
return FALSE; /* FIXME: Copy InstanceID of parent PCI bus to Buffer */
// Index += swprintf(Buffer, ....);
} }
InstanceID->Length = Length - sizeof(WCHAR); swprintf(&Buffer[Index], L"%02X", Device->SlotNumber.u.AsULONG & 0xff);
InstanceID->MaximumLength = Length;
RtlCopyMemory(InstanceID->Buffer, Buffer, Length);
return TRUE; return RtlCreateUnicodeString(InstanceID, Buffer) ? STATUS_SUCCESS : STATUS_INSUFFICIENT_RESOURCES;
#endif
WCHAR Buffer[256];
swprintf(Buffer,
L"PCI\\VEN_%04X&DEV_%04X&SUBSYS_%08X&REV_%02X",
Device->PciConfig.VendorID,
Device->PciConfig.DeviceID,
(Device->PciConfig.u.type0.SubSystemID << 16) +
Device->PciConfig.u.type0.SubVendorID,
Device->PciConfig.RevisionID);
// XBOX HACK
if (!wcscmp(L"PCI\\VEN_10DE&DEV_01C2&SUBSYS_00000000&REV_D4", Buffer))
{
//DPRINT("xbox ohci controler found at bus 0x%lX, dev num %d, func num %d\n", Device->BusNumber, Device->SlotNumber.u.bits.DeviceNumber, Device->SlotNumber.u.bits.FunctionNumber);
if (Device->SlotNumber.u.bits.DeviceNumber == 2)
return RtlCreateUnicodeString(InstanceID, L"0000");
else
return RtlCreateUnicodeString(InstanceID, L"0001");
}
else
return RtlCreateUnicodeString(InstanceID, L"");
} }
BOOLEAN NTSTATUS
PciCreateHardwareIDsString(PUNICODE_STRING HardwareIDs, PciCreateHardwareIDsString(PUNICODE_STRING HardwareIDs,
PPCI_DEVICE Device) PPCI_DEVICE Device)
{ {
WCHAR Buffer[256]; WCHAR Buffer[256];
ULONG Length; UNICODE_STRING BufferU;
ULONG Index; ULONG Index;
Index = 0; Index = 0;
@ -307,27 +267,19 @@ PciCreateHardwareIDsString(PUNICODE_STRING HardwareIDs,
Buffer[Index] = UNICODE_NULL; Buffer[Index] = UNICODE_NULL;
Length = (Index + 1) * sizeof(WCHAR); BufferU.Length = BufferU.MaximumLength = Index * sizeof(WCHAR);
HardwareIDs->Buffer = ExAllocatePool(PagedPool, Length); BufferU.Buffer = Buffer;
if (HardwareIDs->Buffer == NULL)
{
return FALSE;
}
HardwareIDs->Length = Length - sizeof(WCHAR); return RtlDuplicateUnicodeString(0, &BufferU, HardwareIDs);
HardwareIDs->MaximumLength = Length;
RtlCopyMemory(HardwareIDs->Buffer, Buffer, Length);
return TRUE;
} }
BOOLEAN NTSTATUS
PciCreateCompatibleIDsString(PUNICODE_STRING CompatibleIDs, PciCreateCompatibleIDsString(PUNICODE_STRING CompatibleIDs,
PPCI_DEVICE Device) PPCI_DEVICE Device)
{ {
WCHAR Buffer[256]; WCHAR Buffer[256];
ULONG Length; UNICODE_STRING BufferU;
ULONG Index; ULONG Index;
Index = 0; Index = 0;
@ -379,27 +331,18 @@ PciCreateCompatibleIDsString(PUNICODE_STRING CompatibleIDs,
Buffer[Index] = UNICODE_NULL; Buffer[Index] = UNICODE_NULL;
Length = (Index + 1) * sizeof(WCHAR); BufferU.Length = BufferU.MaximumLength = Index * sizeof(WCHAR);
CompatibleIDs->Buffer = ExAllocatePool(PagedPool, Length); BufferU.Buffer = Buffer;
if (CompatibleIDs->Buffer == NULL)
{
return FALSE;
}
CompatibleIDs->Length = Length - sizeof(WCHAR); return RtlDuplicateUnicodeString(0, &BufferU, CompatibleIDs);
CompatibleIDs->MaximumLength = Length;
RtlCopyMemory(CompatibleIDs->Buffer, Buffer, Length);
return TRUE;
} }
BOOLEAN NTSTATUS
PciCreateDeviceDescriptionString(PUNICODE_STRING DeviceDescription, PciCreateDeviceDescriptionString(PUNICODE_STRING DeviceDescription,
PPCI_DEVICE Device) PPCI_DEVICE Device)
{ {
PWSTR Description; PWSTR Description;
ULONG Length;
switch (Device->PciConfig.BaseClass) switch (Device->PciConfig.BaseClass)
{ {
@ -655,51 +598,23 @@ PciCreateDeviceDescriptionString(PUNICODE_STRING DeviceDescription,
break; break;
} }
Length = (wcslen(Description) + 1) * sizeof(WCHAR); return RtlCreateUnicodeString(DeviceDescription, Description) ? STATUS_SUCCESS : STATUS_INSUFFICIENT_RESOURCES;
DeviceDescription->Buffer = ExAllocatePool(PagedPool, Length);
if (DeviceDescription->Buffer == NULL)
{
return FALSE;
}
DeviceDescription->Length = Length - sizeof(WCHAR);
DeviceDescription->MaximumLength = Length;
RtlCopyMemory(DeviceDescription->Buffer, Description, Length);
return TRUE;
} }
BOOLEAN NTSTATUS
PciCreateDeviceLocationString(PUNICODE_STRING DeviceLocation, PciCreateDeviceLocationString(PUNICODE_STRING DeviceLocation,
PPCI_DEVICE Device) PPCI_DEVICE Device)
{ {
WCHAR Buffer[256]; WCHAR Buffer[256];
ULONG Length;
ULONG Index;
Index = 0; swprintf(Buffer,
Index += swprintf(&Buffer[Index],
L"PCI-Bus %lu, Device %u, Function %u", L"PCI-Bus %lu, Device %u, Function %u",
Device->BusNumber, Device->BusNumber,
Device->SlotNumber.u.bits.DeviceNumber, Device->SlotNumber.u.bits.DeviceNumber,
Device->SlotNumber.u.bits.FunctionNumber); Device->SlotNumber.u.bits.FunctionNumber);
Index++;
Buffer[Index] = UNICODE_NULL; return RtlCreateUnicodeString(DeviceLocation, Buffer) ? STATUS_SUCCESS : STATUS_INSUFFICIENT_RESOURCES;
Length = (Index + 1) * sizeof(WCHAR);
DeviceLocation->Buffer = ExAllocatePool(PagedPool, Length);
if (DeviceLocation->Buffer == NULL)
{
return FALSE;
}
DeviceLocation->Length = Length - sizeof(WCHAR);
DeviceLocation->MaximumLength = Length;
RtlCopyMemory(DeviceLocation->Buffer, Buffer, Length);
return TRUE;
} }
/* EOF */ /* EOF */

View file

@ -1,5 +1,3 @@
/* $Id$ */
#ifndef __PCI_H #ifndef __PCI_H
#define __PCI_H #define __PCI_H
@ -47,7 +45,7 @@ typedef struct _COMMON_DEVICE_EXTENSION
BOOLEAN Removed; BOOLEAN Removed;
// Current device power state for the device // Current device power state for the device
DEVICE_POWER_STATE DevicePowerState; DEVICE_POWER_STATE DevicePowerState;
} __attribute((packed)) COMMON_DEVICE_EXTENSION, *PCOMMON_DEVICE_EXTENSION; } COMMON_DEVICE_EXTENSION, *PCOMMON_DEVICE_EXTENSION;
/* Physical Device Object device extension for a child device */ /* Physical Device Object device extension for a child device */
typedef struct _PDO_DEVICE_EXTENSION typedef struct _PDO_DEVICE_EXTENSION
@ -56,10 +54,8 @@ typedef struct _PDO_DEVICE_EXTENSION
COMMON_DEVICE_EXTENSION Common; COMMON_DEVICE_EXTENSION Common;
// Functional device object // Functional device object
PDEVICE_OBJECT Fdo; PDEVICE_OBJECT Fdo;
// PCI bus number // Pointer to PCI Device informations
ULONG BusNumber; PPCI_DEVICE PciDevice;
// PCI slot number
PCI_SLOT_NUMBER SlotNumber;
// Device ID // Device ID
UNICODE_STRING DeviceID; UNICODE_STRING DeviceID;
// Instance ID // Instance ID
@ -72,13 +68,15 @@ typedef struct _PDO_DEVICE_EXTENSION
UNICODE_STRING DeviceDescription; UNICODE_STRING DeviceDescription;
// Textual description of device location // Textual description of device location
UNICODE_STRING DeviceLocation; UNICODE_STRING DeviceLocation;
} __attribute((packed)) PDO_DEVICE_EXTENSION, *PPDO_DEVICE_EXTENSION; } PDO_DEVICE_EXTENSION, *PPDO_DEVICE_EXTENSION;
/* Functional Device Object device extension for the PCI driver device object */ /* Functional Device Object device extension for the PCI driver device object */
typedef struct _FDO_DEVICE_EXTENSION typedef struct _FDO_DEVICE_EXTENSION
{ {
// Common device data // Common device data
COMMON_DEVICE_EXTENSION Common; COMMON_DEVICE_EXTENSION Common;
// PCI bus number serviced by this FDO
ULONG BusNumber;
// Current state of the driver // Current state of the driver
PCI_DEVICE_STATE State; PCI_DEVICE_STATE State;
// Namespace device list // Namespace device list
@ -89,7 +87,7 @@ typedef struct _FDO_DEVICE_EXTENSION
KSPIN_LOCK DeviceListLock; KSPIN_LOCK DeviceListLock;
// Lower device object // Lower device object
PDEVICE_OBJECT Ldo; PDEVICE_OBJECT Ldo;
} __attribute((packed)) FDO_DEVICE_EXTENSION, *PFDO_DEVICE_EXTENSION; } FDO_DEVICE_EXTENSION, *PFDO_DEVICE_EXTENSION;
/* fdo.c */ /* fdo.c */
@ -106,38 +104,32 @@ FdoPowerControl(
/* pci.c */ /* pci.c */
BOOLEAN NTSTATUS
PciCreateUnicodeString(
PUNICODE_STRING Destination,
PWSTR Source,
POOL_TYPE PoolType);
BOOLEAN
PciCreateDeviceIDString( PciCreateDeviceIDString(
PUNICODE_STRING DeviceID, PUNICODE_STRING DeviceID,
PPCI_DEVICE Device); PPCI_DEVICE Device);
BOOLEAN NTSTATUS
PciCreateInstanceIDString( PciCreateInstanceIDString(
PUNICODE_STRING InstanceID, PUNICODE_STRING InstanceID,
PPCI_DEVICE Device); PPCI_DEVICE Device);
BOOLEAN NTSTATUS
PciCreateHardwareIDsString( PciCreateHardwareIDsString(
PUNICODE_STRING HardwareIDs, PUNICODE_STRING HardwareIDs,
PPCI_DEVICE Device); PPCI_DEVICE Device);
BOOLEAN NTSTATUS
PciCreateCompatibleIDsString( PciCreateCompatibleIDsString(
PUNICODE_STRING HardwareIDs, PUNICODE_STRING HardwareIDs,
PPCI_DEVICE Device); PPCI_DEVICE Device);
BOOLEAN NTSTATUS
PciCreateDeviceDescriptionString( PciCreateDeviceDescriptionString(
PUNICODE_STRING DeviceDescription, PUNICODE_STRING DeviceDescription,
PPCI_DEVICE Device); PPCI_DEVICE Device);
BOOLEAN NTSTATUS
PciCreateDeviceLocationString( PciCreateDeviceLocationString(
PUNICODE_STRING DeviceLocation, PUNICODE_STRING DeviceLocation,
PPCI_DEVICE Device); PPCI_DEVICE Device);

View file

@ -1,5 +1,4 @@
/* $Id$ /*
*
* PROJECT: ReactOS PCI bus driver * PROJECT: ReactOS PCI bus driver
* FILE: pdo.c * FILE: pdo.c
* PURPOSE: Child device object dispatch routines * PURPOSE: Child device object dispatch routines
@ -107,11 +106,8 @@ PdoQueryId(
break; break;
case BusQueryInstanceID: case BusQueryInstanceID:
/* FIXME: RTL_DUPLICATE_UNICODE_STRING_ALLOCATE_NULL_STRING flag
* needs to be removed once PciCreateInstanceIDString is fixed
*/
Status = RtlDuplicateUnicodeString( Status = RtlDuplicateUnicodeString(
RTL_DUPLICATE_UNICODE_STRING_NULL_TERMINATE | RTL_DUPLICATE_UNICODE_STRING_ALLOCATE_NULL_STRING, RTL_DUPLICATE_UNICODE_STRING_NULL_TERMINATE,
&DeviceExtension->InstanceID, &DeviceExtension->InstanceID,
&String); &String);
@ -149,7 +145,7 @@ PdoQueryBusInformation(
{ {
BusInformation->BusTypeGuid = GUID_BUS_TYPE_PCI; BusInformation->BusTypeGuid = GUID_BUS_TYPE_PCI;
BusInformation->LegacyBusType = PCIBus; BusInformation->LegacyBusType = PCIBus;
BusInformation->BusNumber = DeviceExtension->BusNumber; BusInformation->BusNumber = DeviceExtension->PciDevice->BusNumber;
return STATUS_SUCCESS; return STATUS_SUCCESS;
} }
@ -176,7 +172,7 @@ PdoQueryCapabilities(
return STATUS_UNSUCCESSFUL; return STATUS_UNSUCCESSFUL;
DeviceCapabilities->UniqueID = FALSE; DeviceCapabilities->UniqueID = FALSE;
DeviceCapabilities->Address = DeviceExtension->SlotNumber.u.AsULONG; DeviceCapabilities->Address = DeviceExtension->PciDevice->SlotNumber.u.AsULONG;
DeviceCapabilities->UINumber = (ULONG)-1; /* FIXME */ DeviceCapabilities->UINumber = (ULONG)-1; /* FIXME */
return STATUS_SUCCESS; return STATUS_SUCCESS;
@ -198,8 +194,8 @@ PdoGetRangeLength(PPDO_DEVICE_EXTENSION DeviceExtension,
/* Save original value */ /* Save original value */
Size= HalGetBusDataByOffset(PCIConfiguration, Size= HalGetBusDataByOffset(PCIConfiguration,
DeviceExtension->BusNumber, DeviceExtension->PciDevice->BusNumber,
DeviceExtension->SlotNumber.u.AsULONG, DeviceExtension->PciDevice->SlotNumber.u.AsULONG,
&OrigValue, &OrigValue,
Offset, Offset,
sizeof(ULONG)); sizeof(ULONG));
@ -216,8 +212,8 @@ PdoGetRangeLength(PPDO_DEVICE_EXTENSION DeviceExtension,
/* Set magic value */ /* Set magic value */
NewValue = (ULONG)-1; NewValue = (ULONG)-1;
Size= HalSetBusDataByOffset(PCIConfiguration, Size= HalSetBusDataByOffset(PCIConfiguration,
DeviceExtension->BusNumber, DeviceExtension->PciDevice->BusNumber,
DeviceExtension->SlotNumber.u.AsULONG, DeviceExtension->PciDevice->SlotNumber.u.AsULONG,
&NewValue, &NewValue,
Offset, Offset,
sizeof(ULONG)); sizeof(ULONG));
@ -229,8 +225,8 @@ PdoGetRangeLength(PPDO_DEVICE_EXTENSION DeviceExtension,
/* Get the range length */ /* Get the range length */
Size= HalGetBusDataByOffset(PCIConfiguration, Size= HalGetBusDataByOffset(PCIConfiguration,
DeviceExtension->BusNumber, DeviceExtension->PciDevice->BusNumber,
DeviceExtension->SlotNumber.u.AsULONG, DeviceExtension->PciDevice->SlotNumber.u.AsULONG,
&NewValue, &NewValue,
Offset, Offset,
sizeof(ULONG)); sizeof(ULONG));
@ -242,8 +238,8 @@ PdoGetRangeLength(PPDO_DEVICE_EXTENSION DeviceExtension,
/* Restore original value */ /* Restore original value */
Size= HalSetBusDataByOffset(PCIConfiguration, Size= HalSetBusDataByOffset(PCIConfiguration,
DeviceExtension->BusNumber, DeviceExtension->PciDevice->BusNumber,
DeviceExtension->SlotNumber.u.AsULONG, DeviceExtension->PciDevice->SlotNumber.u.AsULONG,
&OrigValue, &OrigValue,
Offset, Offset,
sizeof(ULONG)); sizeof(ULONG));
@ -328,8 +324,8 @@ PdoQueryResourceRequirements(
/* Get PCI configuration space */ /* Get PCI configuration space */
Size= HalGetBusData(PCIConfiguration, Size= HalGetBusData(PCIConfiguration,
DeviceExtension->BusNumber, DeviceExtension->PciDevice->BusNumber,
DeviceExtension->SlotNumber.u.AsULONG, DeviceExtension->PciDevice->SlotNumber.u.AsULONG,
&PciConfig, &PciConfig,
sizeof(PCI_COMMON_CONFIG)); sizeof(PCI_COMMON_CONFIG));
DPRINT("Size %lu\n", Size); DPRINT("Size %lu\n", Size);
@ -377,6 +373,8 @@ PdoQueryResourceRequirements(
if (Length != 0) if (Length != 0)
ResCount += 2; ResCount += 2;
} }
if (DeviceExtension->PciDevice->PciConfig.BaseClass == PCI_CLASS_BRIDGE_DEV)
ResCount++;
} }
else if (PCI_CONFIGURATION_TYPE(&PciConfig) == PCI_CARDBUS_BRIDGE_TYPE) else if (PCI_CONFIGURATION_TYPE(&PciConfig) == PCI_CARDBUS_BRIDGE_TYPE)
{ {
@ -412,8 +410,8 @@ PdoQueryResourceRequirements(
ResourceList->ListSize = ListSize; ResourceList->ListSize = ListSize;
ResourceList->InterfaceType = PCIBus; ResourceList->InterfaceType = PCIBus;
ResourceList->BusNumber = DeviceExtension->BusNumber, ResourceList->BusNumber = DeviceExtension->PciDevice->BusNumber;
ResourceList->SlotNumber = DeviceExtension->SlotNumber.u.AsULONG, ResourceList->SlotNumber = DeviceExtension->PciDevice->SlotNumber.u.AsULONG;
ResourceList->AlternativeLists = 1; ResourceList->AlternativeLists = 1;
ResourceList->List[0].Version = 1; ResourceList->List[0].Version = 1;
@ -587,6 +585,18 @@ PdoQueryResourceRequirements(
} }
Descriptor++; Descriptor++;
} }
if (DeviceExtension->PciDevice->PciConfig.BaseClass == PCI_CLASS_BRIDGE_DEV)
{
Descriptor->Option = 0; /* Required */
Descriptor->Type = CmResourceTypeBusNumber;
Descriptor->ShareDisposition = CmResourceShareShared;
Descriptor->Flags = CM_RESOURCE_INTERRUPT_LEVEL_SENSITIVE;
Descriptor->u.BusNumber.MinBusNumber =
Descriptor->u.BusNumber.MaxBusNumber = DeviceExtension->PciDevice->PciConfig.u.type1.SubordinateBus;
Descriptor->u.BusNumber.Length = 1;
Descriptor->u.BusNumber.Reserved = 0;
}
} }
else if (PCI_CONFIGURATION_TYPE(&PciConfig) == 2) else if (PCI_CONFIGURATION_TYPE(&PciConfig) == 2)
{ {
@ -624,8 +634,8 @@ PdoQueryResources(
/* Get PCI configuration space */ /* Get PCI configuration space */
Size= HalGetBusData(PCIConfiguration, Size= HalGetBusData(PCIConfiguration,
DeviceExtension->BusNumber, DeviceExtension->PciDevice->BusNumber,
DeviceExtension->SlotNumber.u.AsULONG, DeviceExtension->PciDevice->SlotNumber.u.AsULONG,
&PciConfig, &PciConfig,
sizeof(PCI_COMMON_CONFIG)); sizeof(PCI_COMMON_CONFIG));
DPRINT("Size %lu\n", Size); DPRINT("Size %lu\n", Size);
@ -703,7 +713,7 @@ PdoQueryResources(
ResourceList->Count = 1; ResourceList->Count = 1;
ResourceList->List[0].InterfaceType = PCIConfiguration; ResourceList->List[0].InterfaceType = PCIConfiguration;
ResourceList->List[0].BusNumber = DeviceExtension->BusNumber; ResourceList->List[0].BusNumber = DeviceExtension->PciDevice->BusNumber;
PartialList = &ResourceList->List[0].PartialResourceList; PartialList = &ResourceList->List[0].PartialResourceList;
PartialList->Version = 0; PartialList->Version = 0;
@ -838,8 +848,8 @@ PdoReadConfig(
/* Get PCI configuration space */ /* Get PCI configuration space */
Size= HalGetBusDataByOffset(PCIConfiguration, Size= HalGetBusDataByOffset(PCIConfiguration,
DeviceExtension->BusNumber, DeviceExtension->PciDevice->BusNumber,
DeviceExtension->SlotNumber.u.AsULONG, DeviceExtension->PciDevice->SlotNumber.u.AsULONG,
IrpSp->Parameters.ReadWriteConfig.Buffer, IrpSp->Parameters.ReadWriteConfig.Buffer,
IrpSp->Parameters.ReadWriteConfig.Offset, IrpSp->Parameters.ReadWriteConfig.Offset,
IrpSp->Parameters.ReadWriteConfig.Length); IrpSp->Parameters.ReadWriteConfig.Length);
@ -876,8 +886,8 @@ PdoWriteConfig(
/* Get PCI configuration space */ /* Get PCI configuration space */
Size= HalSetBusDataByOffset(PCIConfiguration, Size= HalSetBusDataByOffset(PCIConfiguration,
DeviceExtension->BusNumber, DeviceExtension->PciDevice->BusNumber,
DeviceExtension->SlotNumber.u.AsULONG, DeviceExtension->PciDevice->SlotNumber.u.AsULONG,
IrpSp->Parameters.ReadWriteConfig.Buffer, IrpSp->Parameters.ReadWriteConfig.Buffer,
IrpSp->Parameters.ReadWriteConfig.Offset, IrpSp->Parameters.ReadWriteConfig.Offset,
IrpSp->Parameters.ReadWriteConfig.Length); IrpSp->Parameters.ReadWriteConfig.Length);