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 Modified: trunk/reactos/bootdata/hivesys.inf Modified: trunk/reactos/drivers/bus/pci/fdo.c Modified: trunk/reactos/drivers/bus/pci/pci.c Modified: trunk/reactos/drivers/bus/pci/pci.h Modified: trunk/reactos/drivers/bus/pci/pdo.c _____
Modified: trunk/reactos/bootdata/hivesys.inf --- trunk/reactos/bootdata/hivesys.inf 2005-10-14 18:24:19 UTC (rev 18448) +++ trunk/reactos/bootdata/hivesys.inf 2005-10-14 18:29:55 UTC (rev 18449) @@ -583,16 +583,12 @@
HKLM,"SYSTEM\CurrentControlSet\Enum\Root\Ne2000\0000","Driver",0x0000000 0,"{4D36E972-E325-11CE-BFC1-08002BE10318}\0001"
; PCI driver -HKLM,"SYSTEM\CurrentControlSet\Services\Pci","ErrorControl",0x00010001, 0x00000000 -HKLM,"SYSTEM\CurrentControlSet\Services\Pci","Group",0x00000000,"Boot Bus Extender" -HKLM,"SYSTEM\CurrentControlSet\Services\Pci","ImagePath",0x00020000,"sy stem32\drivers\pci.sys" -HKLM,"SYSTEM\CurrentControlSet\Services\Pci","Start",0x00010001,0x00000 000 -HKLM,"SYSTEM\CurrentControlSet\Services\Pci","Tag",0x00010001,0x0000000 2 -HKLM,"SYSTEM\CurrentControlSet\Services\Pci","Type",0x00010001,0x000000 01 -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",0x000000 00,"{4D36E966-E325-11CE-BFC1-08002BE10318}" -HKLM,"SYSTEM\CurrentControlSet\Enum\Root\PCI\0000","ParentIdPrefix",0x0 000000,"0000" +HKLM,"SYSTEM\CurrentControlSet\Enum\Root*PNP0A03\0000","HardwareID",0x 00010000,"*PNP0A03" +HKLM,"SYSTEM\CurrentControlSet\Enum\Root*PNP0A03\0000","DeviceDesc",0x 00000000,"PCI bus" +HKLM,"SYSTEM\CurrentControlSet\Enum\Root*PNP0A03\0000\LogConf","BasicC onfigVector",0x000A0001, \ +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, \ +01,00,00,00,01,00,01,00,01,00,00,00, \ +00,06,00,00,00,00,00,00,01,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00
; ReactOS PCNet NIC driver ; To use the AMD supplied driver change the driver name to pcntn5m.sys _____
Modified: trunk/reactos/drivers/bus/pci/fdo.c --- trunk/reactos/drivers/bus/pci/fdo.c 2005-10-14 18:24:19 UTC (rev 18448) +++ trunk/reactos/drivers/bus/pci/fdo.c 2005-10-14 18:29:55 UTC (rev 18449) @@ -1,5 +1,4 @@
-/* $Id$ - * +/* * PROJECT: ReactOS PCI bus driver * FILE: fdo.c * PURPOSE: PCI device object dispatch routines @@ -22,7 +21,6 @@ FdoLocateChildDevice( PPCI_DEVICE *Device, PFDO_DEVICE_EXTENSION DeviceExtension, - ULONG BusNumber, PCI_SLOT_NUMBER SlotNumber, PPCI_COMMON_CONFIG PciConfig) { @@ -38,8 +36,7 @@ /* If both vendor ID and device ID match, it is the same device */ if ((PciConfig->VendorID == CurrentDevice->PciConfig.VendorID) && (PciConfig->DeviceID == CurrentDevice->PciConfig.DeviceID) && - (SlotNumber.u.AsULONG == CurrentDevice->SlotNumber.u.AsULONG) && - (BusNumber == CurrentDevice->BusNumber)) { + (SlotNumber.u.AsULONG == CurrentDevice->SlotNumber.u.AsULONG)) { *Device = CurrentDevice; DPRINT("Done\n"); return STATUS_SUCCESS; @@ -63,7 +60,6 @@ PLIST_ENTRY CurrentEntry; PPCI_DEVICE Device; PCI_SLOT_NUMBER SlotNumber; - ULONG BusNumber; ULONG DeviceNumber; ULONG FunctionNumber; ULONG Size; @@ -85,89 +81,86 @@ DeviceExtension->DeviceListCount = 0;
/* Enumerate devices on the PCI bus */ - for (BusNumber = 0; BusNumber < 8; BusNumber++) + SlotNumber.u.AsULONG = 0; + for (DeviceNumber = 0; DeviceNumber < PCI_MAX_DEVICES; DeviceNumber++) { - SlotNumber.u.AsULONG = 0; - for (DeviceNumber = 0; DeviceNumber < PCI_MAX_DEVICES; DeviceNumber++) + SlotNumber.u.bits.DeviceNumber = DeviceNumber; + for (FunctionNumber = 0; FunctionNumber < PCI_MAX_FUNCTION; FunctionNumber++) { - SlotNumber.u.bits.DeviceNumber = DeviceNumber; - for (FunctionNumber = 0; FunctionNumber < PCI_MAX_FUNCTION; FunctionNumber++) - { - SlotNumber.u.bits.FunctionNumber = FunctionNumber; + SlotNumber.u.bits.FunctionNumber = FunctionNumber;
- DPRINT("Bus %1lu Device %2lu Func %1lu\n", - BusNumber, - DeviceNumber, - FunctionNumber); + DPRINT("Bus %1lu Device %2lu Func %1lu\n", + DeviceExtension->BusNumber, + DeviceNumber, + FunctionNumber);
- RtlZeroMemory(&PciConfig, - sizeof(PCI_COMMON_CONFIG)); + RtlZeroMemory(&PciConfig, + sizeof(PCI_COMMON_CONFIG));
- Size = HalGetBusData(PCIConfiguration, - BusNumber, - SlotNumber.u.AsULONG, - &PciConfig, - PCI_COMMON_HDR_LENGTH); - DPRINT("Size %lu\n", Size); - if (Size < PCI_COMMON_HDR_LENGTH) + Size = HalGetBusData(PCIConfiguration, + DeviceExtension->BusNumber, + SlotNumber.u.AsULONG, + &PciConfig, + PCI_COMMON_HDR_LENGTH); + DPRINT("Size %lu\n", Size); + if (Size < PCI_COMMON_HDR_LENGTH) + { + if (FunctionNumber == 0) { - if (FunctionNumber == 0) - { - break; - } - else - { - continue; - } + break; } + else + { + continue; + } + }
- DPRINT("Bus %1lu Device %2lu Func %1lu VenID 0x%04hx DevID 0x%04hx\n", - BusNumber, - DeviceNumber, - FunctionNumber, - PciConfig.VendorID, - PciConfig.DeviceID); + 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, BusNumber, SlotNumber, &PciConfig); - if (!NT_SUCCESS(Status)) + Status = FdoLocateChildDevice(&Device, DeviceExtension, SlotNumber, &PciConfig); + if (!NT_SUCCESS(Status)) + { + Device = (PPCI_DEVICE)ExAllocatePool(PagedPool, sizeof(PCI_DEVICE)); + if (!Device) { - Device = (PPCI_DEVICE)ExAllocatePool(PagedPool, sizeof(PCI_DEVICE)); - if (!Device) - { - /* FIXME: Cleanup resources for already discovered devices */ - return STATUS_INSUFFICIENT_RESOURCES; - } + /* FIXME: Cleanup resources for already discovered devices */ + return STATUS_INSUFFICIENT_RESOURCES; + }
- RtlZeroMemory(Device, - sizeof(PCI_DEVICE)); + RtlZeroMemory(Device, + sizeof(PCI_DEVICE));
- Device->BusNumber = BusNumber; + Device->BusNumber = DeviceExtension->BusNumber;
- RtlCopyMemory(&Device->SlotNumber, - &SlotNumber, - sizeof(PCI_SLOT_NUMBER)); + RtlCopyMemory(&Device->SlotNumber, + &SlotNumber, + sizeof(PCI_SLOT_NUMBER));
- RtlCopyMemory(&Device->PciConfig, - &PciConfig, - sizeof(PCI_COMMON_CONFIG)); + RtlCopyMemory(&Device->PciConfig, + &PciConfig, + sizeof(PCI_COMMON_CONFIG));
- ExInterlockedInsertTailList( - &DeviceExtension->DeviceListHead, - &Device->ListEntry, - &DeviceExtension->DeviceListLock); - } + ExInterlockedInsertTailList( + &DeviceExtension->DeviceListHead, + &Device->ListEntry, + &DeviceExtension->DeviceListLock); + }
- /* Don't remove this device */ - Device->RemovePending = FALSE; + /* Don't remove this device */ + Device->RemovePending = FALSE;
- DeviceExtension->DeviceListCount++; + DeviceExtension->DeviceListCount++;
- /* Skip to next device if the current one is not a multifunction device */ - if ((FunctionNumber == 0) && - ((PciConfig.HeaderType & 0x80) == 0)) - { - break; - } + /* Skip to next device if the current one is not a multifunction device */ + if ((FunctionNumber == 0) && + ((PciConfig.HeaderType & 0x80) == 0)) + { + break; } } } @@ -263,18 +256,13 @@
PdoDeviceExtension->Fdo = DeviceObject;
- PdoDeviceExtension->BusNumber = Device->BusNumber; + PdoDeviceExtension->PciDevice = Device;
- RtlCopyMemory( - &PdoDeviceExtension->SlotNumber, - &Device->SlotNumber, - sizeof(PCI_SLOT_NUMBER)); - /* Add Device ID string */ - if (!PciCreateDeviceIDString(&PdoDeviceExtension->DeviceID, - Device)) + Status = PciCreateDeviceIDString(&PdoDeviceExtension->DeviceID, Device); + if (!NT_SUCCESS(Status)) { - ErrorStatus = STATUS_INSUFFICIENT_RESOURCES; + ErrorStatus = Status; ErrorOccurred = TRUE; break; } @@ -282,46 +270,46 @@ DPRINT("DeviceID: %S\n", PdoDeviceExtension->DeviceID.Buffer);
/* Add Instance ID string */ - if (!PciCreateInstanceIDString(&PdoDeviceExtension->InstanceID, - Device)) + Status = PciCreateInstanceIDString(&PdoDeviceExtension->InstanceID, Device); + if (!NT_SUCCESS(Status)) { - ErrorStatus = STATUS_INSUFFICIENT_RESOURCES; + ErrorStatus = Status; ErrorOccurred = TRUE; break; }
/* Add Hardware IDs string */ - if (!PciCreateHardwareIDsString(&PdoDeviceExtension->HardwareIDs, - Device)) + Status = PciCreateHardwareIDsString(&PdoDeviceExtension->HardwareIDs, Device); + if (!NT_SUCCESS(Status)) { - ErrorStatus = STATUS_INSUFFICIENT_RESOURCES; + ErrorStatus = Status; ErrorOccurred = TRUE; break; }
/* Add Compatible IDs string */ - if (!PciCreateCompatibleIDsString(&PdoDeviceExtension->CompatibleIDs, - Device)) + Status = PciCreateCompatibleIDsString(&PdoDeviceExtension->CompatibleIDs, Device); + if (!NT_SUCCESS(Status)) { - ErrorStatus = STATUS_INSUFFICIENT_RESOURCES; + ErrorStatus = Status; ErrorOccurred = TRUE; break; }
/* Add device description string */ - if (!PciCreateDeviceDescriptionString(&PdoDeviceExtension->DeviceDescriptio n, - Device)) + Status = PciCreateDeviceDescriptionString(&PdoDeviceExtension->DeviceDescription, Device); + if (!NT_SUCCESS(Status)) { - ErrorStatus = STATUS_INSUFFICIENT_RESOURCES; + ErrorStatus = Status; ErrorOccurred = TRUE; break; }
/* Add device location string */ - if (!PciCreateDeviceLocationString(&PdoDeviceExtension->DeviceLocation, - Device)) + Status = PciCreateDeviceLocationString(&PdoDeviceExtension->DeviceLocation, Device); + if (!NT_SUCCESS(Status)) { - ErrorStatus = STATUS_INSUFFICIENT_RESOURCES; + ErrorStatus = Status; ErrorOccurred = TRUE; break; } @@ -345,7 +333,11 @@ /* FIXME: Should IoAttachDeviceToDeviceStack() be undone? */ if (PdoDeviceExtension) { RtlFreeUnicodeString(&PdoDeviceExtension->DeviceID); - ExFreePool(PdoDeviceExtension); + RtlFreeUnicodeString(&PdoDeviceExtension->InstanceID); + RtlFreeUnicodeString(&PdoDeviceExtension->HardwareIDs); + RtlFreeUnicodeString(&PdoDeviceExtension->CompatibleIDs); + RtlFreeUnicodeString(&PdoDeviceExtension->DeviceDescription); + RtlFreeUnicodeString(&PdoDeviceExtension->DeviceLocation); }
ExFreePool(Relations); @@ -366,19 +358,62 @@ IN PIRP Irp) { PFDO_DEVICE_EXTENSION DeviceExtension; + PCM_RESOURCE_LIST AllocatedResources; + PCM_PARTIAL_RESOURCE_DESCRIPTOR ResourceDescriptor; + ULONG FoundBusNumber = FALSE; + ULONG i;
DPRINT("Called\n");
DeviceExtension = (PFDO_DEVICE_EXTENSION)DeviceObject->DeviceExtension; + + AllocatedResources = IoGetCurrentIrpStackLocation(Irp)->Parameters.StartDevice.AllocatedResou rces; + 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); + 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); KeInitializeSpinLock(&DeviceExtension->DeviceListLock); DeviceExtension->DeviceListCount = 0; DeviceExtension->State = dsStarted;
- //Irp->IoStatus.Information = 0; + Irp->IoStatus.Information = 0;
return STATUS_SUCCESS; } _____
Modified: trunk/reactos/drivers/bus/pci/pci.c --- trunk/reactos/drivers/bus/pci/pci.c 2005-10-14 18:24:19 UTC (rev 18448) +++ trunk/reactos/drivers/bus/pci/pci.c 2005-10-14 18:29:55 UTC (rev 18449) @@ -1,5 +1,4 @@
-/* $Id$ - * +/* * PROJECT: ReactOS PCI Bus driver * FILE: pci.c * PURPOSE: Driver entry @@ -185,7 +184,7 @@ }
-BOOLEAN +NTSTATUS PciCreateDeviceIDString(PUNICODE_STRING DeviceID, PPCI_DEVICE Device) { @@ -199,75 +198,36 @@ Device->PciConfig.u.type0.SubVendorID, Device->PciConfig.RevisionID);
- if (!RtlCreateUnicodeString(DeviceID, Buffer)) - { - return FALSE; - } - - return TRUE; + return RtlCreateUnicodeString(DeviceID, Buffer) ? STATUS_SUCCESS : STATUS_INSUFFICIENT_RESOURCES; }
-BOOLEAN +NTSTATUS PciCreateInstanceIDString(PUNICODE_STRING InstanceID, PPCI_DEVICE Device) { -#if 0 WCHAR Buffer[32]; - ULONG Length; ULONG Index;
- Index = swprintf(Buffer, - L"%lX&%02lX", - 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) + Index = 0; + if (((PPDO_DEVICE_EXTENSION)Device->Pdo->DeviceExtension)->PciDevice->BusNu mber != 0) { - return FALSE; + /* FIXME: Copy InstanceID of parent PCI bus to Buffer */ + // Index += swprintf(Buffer, ....); }
- InstanceID->Length = Length - sizeof(WCHAR); - InstanceID->MaximumLength = Length; - RtlCopyMemory(InstanceID->Buffer, Buffer, Length); + swprintf(&Buffer[Index], L"%02X", Device->SlotNumber.u.AsULONG & 0xff);
- return TRUE; -#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""); + return RtlCreateUnicodeString(InstanceID, Buffer) ? STATUS_SUCCESS : STATUS_INSUFFICIENT_RESOURCES; }
-BOOLEAN +NTSTATUS PciCreateHardwareIDsString(PUNICODE_STRING HardwareIDs, PPCI_DEVICE Device) { WCHAR Buffer[256]; - ULONG Length; + UNICODE_STRING BufferU; ULONG Index;
Index = 0; @@ -306,28 +266,20 @@ Index++;
Buffer[Index] = UNICODE_NULL; + + BufferU.Length = BufferU.MaximumLength = Index * sizeof(WCHAR); + BufferU.Buffer = Buffer;
- Length = (Index + 1) * sizeof(WCHAR); - HardwareIDs->Buffer = ExAllocatePool(PagedPool, Length); - if (HardwareIDs->Buffer == NULL) - { - return FALSE; - } - - HardwareIDs->Length = Length - sizeof(WCHAR); - HardwareIDs->MaximumLength = Length; - RtlCopyMemory(HardwareIDs->Buffer, Buffer, Length); - - return TRUE; + return RtlDuplicateUnicodeString(0, &BufferU, HardwareIDs); }
-BOOLEAN +NTSTATUS PciCreateCompatibleIDsString(PUNICODE_STRING CompatibleIDs, PPCI_DEVICE Device) { WCHAR Buffer[256]; - ULONG Length; + UNICODE_STRING BufferU; ULONG Index;
Index = 0; @@ -379,27 +331,18 @@
Buffer[Index] = UNICODE_NULL;
- Length = (Index + 1) * sizeof(WCHAR); - CompatibleIDs->Buffer = ExAllocatePool(PagedPool, Length); - if (CompatibleIDs->Buffer == NULL) - { - return FALSE; - } + BufferU.Length = BufferU.MaximumLength = Index * sizeof(WCHAR); + BufferU.Buffer = Buffer;
- CompatibleIDs->Length = Length - sizeof(WCHAR); - CompatibleIDs->MaximumLength = Length; - RtlCopyMemory(CompatibleIDs->Buffer, Buffer, Length); - - return TRUE; + return RtlDuplicateUnicodeString(0, &BufferU, CompatibleIDs); }
-BOOLEAN +NTSTATUS PciCreateDeviceDescriptionString(PUNICODE_STRING DeviceDescription, PPCI_DEVICE Device) { PWSTR Description; - ULONG Length;
switch (Device->PciConfig.BaseClass) { @@ -655,51 +598,23 @@ break; }
- Length = (wcslen(Description) + 1) * sizeof(WCHAR); - 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; + return RtlCreateUnicodeString(DeviceDescription, Description) ? STATUS_SUCCESS : STATUS_INSUFFICIENT_RESOURCES; }
-BOOLEAN +NTSTATUS PciCreateDeviceLocationString(PUNICODE_STRING DeviceLocation, PPCI_DEVICE Device) { WCHAR Buffer[256]; - ULONG Length; - ULONG Index;
- Index = 0; - Index += swprintf(&Buffer[Index], - L"PCI-Bus %lu, Device %u, Function %u", - Device->BusNumber, - Device->SlotNumber.u.bits.DeviceNumber, - Device->SlotNumber.u.bits.FunctionNumber); - Index++; + swprintf(Buffer, + L"PCI-Bus %lu, Device %u, Function %u", + Device->BusNumber, + Device->SlotNumber.u.bits.DeviceNumber, + Device->SlotNumber.u.bits.FunctionNumber);
- Buffer[Index] = UNICODE_NULL; - - 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; + return RtlCreateUnicodeString(DeviceLocation, Buffer) ? STATUS_SUCCESS : STATUS_INSUFFICIENT_RESOURCES; }
/* EOF */ _____
Modified: trunk/reactos/drivers/bus/pci/pci.h --- trunk/reactos/drivers/bus/pci/pci.h 2005-10-14 18:24:19 UTC (rev 18448) +++ trunk/reactos/drivers/bus/pci/pci.h 2005-10-14 18:29:55 UTC (rev 18449) @@ -1,5 +1,3 @@
-/* $Id$ */ - #ifndef __PCI_H #define __PCI_H
@@ -47,7 +45,7 @@ BOOLEAN Removed; // Current device power state for the device 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 */ typedef struct _PDO_DEVICE_EXTENSION @@ -56,10 +54,8 @@ COMMON_DEVICE_EXTENSION Common; // Functional device object PDEVICE_OBJECT Fdo; - // PCI bus number - ULONG BusNumber; - // PCI slot number - PCI_SLOT_NUMBER SlotNumber; + // Pointer to PCI Device informations + PPCI_DEVICE PciDevice; // Device ID UNICODE_STRING DeviceID; // Instance ID @@ -72,13 +68,15 @@ UNICODE_STRING DeviceDescription; // Textual description of device location 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 */ typedef struct _FDO_DEVICE_EXTENSION { // Common device data COMMON_DEVICE_EXTENSION Common; + // PCI bus number serviced by this FDO + ULONG BusNumber; // Current state of the driver PCI_DEVICE_STATE State; // Namespace device list @@ -89,7 +87,7 @@ KSPIN_LOCK DeviceListLock; // Lower device object PDEVICE_OBJECT Ldo; -} __attribute((packed)) FDO_DEVICE_EXTENSION, *PFDO_DEVICE_EXTENSION; +} FDO_DEVICE_EXTENSION, *PFDO_DEVICE_EXTENSION;
/* fdo.c */ @@ -106,38 +104,32 @@
/* pci.c */
-BOOLEAN -PciCreateUnicodeString( - PUNICODE_STRING Destination, - PWSTR Source, - POOL_TYPE PoolType); - -BOOLEAN +NTSTATUS PciCreateDeviceIDString( PUNICODE_STRING DeviceID, PPCI_DEVICE Device);
-BOOLEAN +NTSTATUS PciCreateInstanceIDString( PUNICODE_STRING InstanceID, PPCI_DEVICE Device);
-BOOLEAN +NTSTATUS PciCreateHardwareIDsString( PUNICODE_STRING HardwareIDs, PPCI_DEVICE Device);
-BOOLEAN +NTSTATUS PciCreateCompatibleIDsString( PUNICODE_STRING HardwareIDs, PPCI_DEVICE Device);
-BOOLEAN +NTSTATUS PciCreateDeviceDescriptionString( PUNICODE_STRING DeviceDescription, PPCI_DEVICE Device);
-BOOLEAN +NTSTATUS PciCreateDeviceLocationString( PUNICODE_STRING DeviceLocation, PPCI_DEVICE Device); _____
Modified: trunk/reactos/drivers/bus/pci/pdo.c --- trunk/reactos/drivers/bus/pci/pdo.c 2005-10-14 18:24:19 UTC (rev 18448) +++ trunk/reactos/drivers/bus/pci/pdo.c 2005-10-14 18:29:55 UTC (rev 18449) @@ -1,5 +1,4 @@
-/* $Id$ - * +/* * PROJECT: ReactOS PCI bus driver * FILE: pdo.c * PURPOSE: Child device object dispatch routines @@ -107,11 +106,8 @@ break;
case BusQueryInstanceID: - /* FIXME: RTL_DUPLICATE_UNICODE_STRING_ALLOCATE_NULL_STRING flag - * needs to be removed once PciCreateInstanceIDString is fixed - */ Status = RtlDuplicateUnicodeString( - RTL_DUPLICATE_UNICODE_STRING_NULL_TERMINATE | RTL_DUPLICATE_UNICODE_STRING_ALLOCATE_NULL_STRING, + RTL_DUPLICATE_UNICODE_STRING_NULL_TERMINATE, &DeviceExtension->InstanceID, &String);
@@ -149,7 +145,7 @@ { BusInformation->BusTypeGuid = GUID_BUS_TYPE_PCI; BusInformation->LegacyBusType = PCIBus; - BusInformation->BusNumber = DeviceExtension->BusNumber; + BusInformation->BusNumber = DeviceExtension->PciDevice->BusNumber;
return STATUS_SUCCESS; } @@ -176,7 +172,7 @@ return STATUS_UNSUCCESSFUL;
DeviceCapabilities->UniqueID = FALSE; - DeviceCapabilities->Address = DeviceExtension->SlotNumber.u.AsULONG; + DeviceCapabilities->Address = DeviceExtension->PciDevice->SlotNumber.u.AsULONG; DeviceCapabilities->UINumber = (ULONG)-1; /* FIXME */
return STATUS_SUCCESS; @@ -198,8 +194,8 @@
/* Save original value */ Size= HalGetBusDataByOffset(PCIConfiguration, - DeviceExtension->BusNumber, - DeviceExtension->SlotNumber.u.AsULONG, + DeviceExtension->PciDevice->BusNumber, + DeviceExtension->PciDevice->SlotNumber.u.AsULONG, &OrigValue, Offset, sizeof(ULONG)); @@ -216,8 +212,8 @@ /* Set magic value */ NewValue = (ULONG)-1; Size= HalSetBusDataByOffset(PCIConfiguration, - DeviceExtension->BusNumber, - DeviceExtension->SlotNumber.u.AsULONG, + DeviceExtension->PciDevice->BusNumber, + DeviceExtension->PciDevice->SlotNumber.u.AsULONG, &NewValue, Offset, sizeof(ULONG)); @@ -229,8 +225,8 @@
/* Get the range length */ Size= HalGetBusDataByOffset(PCIConfiguration, - DeviceExtension->BusNumber, - DeviceExtension->SlotNumber.u.AsULONG, + DeviceExtension->PciDevice->BusNumber, + DeviceExtension->PciDevice->SlotNumber.u.AsULONG, &NewValue, Offset, sizeof(ULONG)); @@ -242,8 +238,8 @@
/* Restore original value */ Size= HalSetBusDataByOffset(PCIConfiguration, - DeviceExtension->BusNumber, - DeviceExtension->SlotNumber.u.AsULONG, + DeviceExtension->PciDevice->BusNumber, + DeviceExtension->PciDevice->SlotNumber.u.AsULONG, &OrigValue, Offset, sizeof(ULONG)); @@ -328,8 +324,8 @@
/* Get PCI configuration space */ Size= HalGetBusData(PCIConfiguration, - DeviceExtension->BusNumber, - DeviceExtension->SlotNumber.u.AsULONG, + DeviceExtension->PciDevice->BusNumber, + DeviceExtension->PciDevice->SlotNumber.u.AsULONG, &PciConfig, sizeof(PCI_COMMON_CONFIG)); DPRINT("Size %lu\n", Size); @@ -377,6 +373,8 @@ if (Length != 0) ResCount += 2; } + if (DeviceExtension->PciDevice->PciConfig.BaseClass == PCI_CLASS_BRIDGE_DEV) + ResCount++; } else if (PCI_CONFIGURATION_TYPE(&PciConfig) == PCI_CARDBUS_BRIDGE_TYPE) { @@ -412,8 +410,8 @@
ResourceList->ListSize = ListSize; ResourceList->InterfaceType = PCIBus; - ResourceList->BusNumber = DeviceExtension->BusNumber, - ResourceList->SlotNumber = DeviceExtension->SlotNumber.u.AsULONG, + ResourceList->BusNumber = DeviceExtension->PciDevice->BusNumber; + ResourceList->SlotNumber = DeviceExtension->PciDevice->SlotNumber.u.AsULONG; ResourceList->AlternativeLists = 1;
ResourceList->List[0].Version = 1; @@ -587,6 +585,18 @@ } 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) { @@ -624,8 +634,8 @@
/* Get PCI configuration space */ Size= HalGetBusData(PCIConfiguration, - DeviceExtension->BusNumber, - DeviceExtension->SlotNumber.u.AsULONG, + DeviceExtension->PciDevice->BusNumber, + DeviceExtension->PciDevice->SlotNumber.u.AsULONG, &PciConfig, sizeof(PCI_COMMON_CONFIG)); DPRINT("Size %lu\n", Size); @@ -703,7 +713,7 @@
ResourceList->Count = 1; ResourceList->List[0].InterfaceType = PCIConfiguration; - ResourceList->List[0].BusNumber = DeviceExtension->BusNumber; + ResourceList->List[0].BusNumber = DeviceExtension->PciDevice->BusNumber;
PartialList = &ResourceList->List[0].PartialResourceList; PartialList->Version = 0; @@ -838,8 +848,8 @@
/* Get PCI configuration space */ Size= HalGetBusDataByOffset(PCIConfiguration, - DeviceExtension->BusNumber, - DeviceExtension->SlotNumber.u.AsULONG, + DeviceExtension->PciDevice->BusNumber, + DeviceExtension->PciDevice->SlotNumber.u.AsULONG, IrpSp->Parameters.ReadWriteConfig.Buffer, IrpSp->Parameters.ReadWriteConfig.Offset,
IrpSp->Parameters.ReadWriteConfig.Length); @@ -876,8 +886,8 @@
/* Get PCI configuration space */ Size= HalSetBusDataByOffset(PCIConfiguration, - DeviceExtension->BusNumber, - DeviceExtension->SlotNumber.u.AsULONG, + DeviceExtension->PciDevice->BusNumber, + DeviceExtension->PciDevice->SlotNumber.u.AsULONG, IrpSp->Parameters.ReadWriteConfig.Buffer, IrpSp->Parameters.ReadWriteConfig.Offset,
IrpSp->Parameters.ReadWriteConfig.Length);