From 111a56f09bbdb7dce970a44629a91666e068fa61 Mon Sep 17 00:00:00 2001 From: Sir Richard Date: Thu, 1 Apr 2010 19:42:07 +0000 Subject: [PATCH] [HAL]: Split HalReportResouceUsage into per-platform function, since PC/AT HAL and ACPI HAL have different requirements. As a bonus, the ACPI HAL now identifies itself as ACPI Compatible, instead of using the "PC Compatible" moniker. [HAL]: Implement HalpGetNMICrashFlag so you can do NMI crashes now. [HAL]: Implement basic HalpRegistryPciDebuggingDeviceInfo for the day someone implements the Kd routines. [HAL]: HalpInitializePciBus needs to be different between "Bus Handler HALs" (non-ACPI/embedded) and "Non-Bus Handler HALs" (ACPI/x64). On ACPI, all we do is setup the raw PCI Stubs and NMI crashing. PC/AT will need more involved code. svn path=/trunk/; revision=46647 --- reactos/hal/halx86/generic/acpi/halacpi.c | 60 ++++++++++++++ reactos/hal/halx86/generic/bus/pcibus.c | 36 +++++++-- reactos/hal/halx86/generic/legacy/halpcat.c | 63 +++++++++++++++ reactos/hal/halx86/generic/usage.c | 86 +++++++++++---------- reactos/hal/halx86/include/bus.h | 38 +++++++++ reactos/hal/halx86/include/halp.h | 13 ++++ 6 files changed, 248 insertions(+), 48 deletions(-) diff --git a/reactos/hal/halx86/generic/acpi/halacpi.c b/reactos/hal/halx86/generic/acpi/halacpi.c index f9fe8731dcc..8a4a445a1a0 100644 --- a/reactos/hal/halx86/generic/acpi/halacpi.c +++ b/reactos/hal/halx86/generic/acpi/halacpi.c @@ -861,4 +861,64 @@ HalpSetupAcpiPhase0(IN PLOADER_PARAMETER_BLOCK LoaderBlock) return STATUS_SUCCESS; } +VOID +NTAPI +HalpInitializePciBus(VOID) +{ + /* Setup the PCI stub support */ + HalpInitializePciStubs(); + + /* Set the NMI crash flag */ + HalpGetNMICrashFlag(); +} + +/* + * @implemented + */ +VOID +NTAPI +HalReportResourceUsage(VOID) +{ + INTERFACE_TYPE InterfaceType; + UNICODE_STRING HalString; + + /* FIXME: Initialize DMA 64-bit support */ + + /* FIXME: Initialize MCA bus */ + + /* Initialize PCI bus. */ + HalpInitializePciBus(); + + /* What kind of bus is this? */ + switch (HalpBusType) + { + /* ISA Machine */ + case MACHINE_TYPE_ISA: + InterfaceType = Isa; + break; + + /* EISA Machine */ + case MACHINE_TYPE_EISA: + InterfaceType = Eisa; + break; + + /* MCA Machine */ + case MACHINE_TYPE_MCA: + InterfaceType = MicroChannel; + break; + + /* Unknown */ + default: + InterfaceType = Internal; + break; + } + + /* Build HAL usage */ + RtlInitUnicodeString(&HalString, L"ACPI Compatible Eisa/Isa HAL"); + HalpReportResourceUsage(&HalString, InterfaceType); + + /* Setup PCI debugging and Hibernation */ + HalpRegisterPciDebuggingDeviceInfo(); +} + /* EOF */ diff --git a/reactos/hal/halx86/generic/bus/pcibus.c b/reactos/hal/halx86/generic/bus/pcibus.c index 50f1add18d8..2440cd4182b 100644 --- a/reactos/hal/halx86/generic/bus/pcibus.c +++ b/reactos/hal/halx86/generic/bus/pcibus.c @@ -14,6 +14,8 @@ /* GLOBALS *******************************************************************/ +PCI_TYPE1_CFG_CYCLE_BITS HalpPciDebuggingDevice[2] = {{{{0}}}}; + BOOLEAN HalpPCIConfigInitialized; ULONG HalpMinPciBus, HalpMaxPciBus; KSPIN_LOCK HalpPCIConfigLock; @@ -521,6 +523,34 @@ HalpReleasePciDeviceForDebugging(IN OUT PDEBUG_DEVICE_DESCRIPTOR PciDevice) return STATUS_NOT_IMPLEMENTED; } +VOID +NTAPI +HalpRegisterPciDebuggingDeviceInfo(VOID) +{ + BOOLEAN Found = FALSE; + ULONG i; + PAGED_CODE(); + + /* Loop PCI debugging devices */ + for (i = 0; i < 2; i++) + { + /* Reserved bit is set if we found one */ + if (HalpPciDebuggingDevice[i].u.bits.Reserved1) + { + Found = TRUE; + break; + } + } + + /* Bail out if there aren't any */ + if (!Found) return; + + /* FIXME: TODO */ + DPRINT1("You have implemented the KD routines for searching PCI debugger" + "devices, but you have forgotten to implement this routine\n"); + while (TRUE); +} + static ULONG NTAPI PciSize(ULONG Base, ULONG Mask) { @@ -1026,9 +1056,3 @@ HalpInitializePciStubs(VOID) HalpPCIConfigInitialized = TRUE; } -VOID -NTAPI -HalpInitializePciBus(VOID) -{ - /* FIXME: Initialize NMI Crash Flag */ -} diff --git a/reactos/hal/halx86/generic/legacy/halpcat.c b/reactos/hal/halx86/generic/legacy/halpcat.c index bbabb9c7aa2..db04395ff3d 100644 --- a/reactos/hal/halx86/generic/legacy/halpcat.c +++ b/reactos/hal/halx86/generic/legacy/halpcat.c @@ -24,4 +24,67 @@ HalpSetupAcpiPhase0(IN PLOADER_PARAMETER_BLOCK LoaderBlock) return STATUS_NO_SUCH_DEVICE; } +VOID +NTAPI +HalpInitializePciBus(VOID) +{ + /* FIXME: Should do legacy PCI bus detection */ + + /* FIXME: Should detect chipset hacks */ + + /* FIXME: Should detect broken PCI hardware and apply hacks */ + + /* FIXME: Should build resource ranges */ +} + +/* + * @implemented + */ +VOID +NTAPI +HalReportResourceUsage(VOID) +{ + INTERFACE_TYPE InterfaceType; + UNICODE_STRING HalString; + + /* FIXME: Initialize MCA bus */ + + /* Initialize PCI bus. */ + HalpInitializePciBus(); + + /* Initialize the stubs */ + HalpInitializePciStubs(); + + /* What kind of bus is this? */ + switch (HalpBusType) + { + /* ISA Machine */ + case MACHINE_TYPE_ISA: + InterfaceType = Isa; + break; + + /* EISA Machine */ + case MACHINE_TYPE_EISA: + InterfaceType = Eisa; + break; + + /* MCA Machine */ + case MACHINE_TYPE_MCA: + InterfaceType = MicroChannel; + break; + + /* Unknown */ + default: + InterfaceType = Internal; + break; + } + + /* Build HAL usage */ + RtlInitUnicodeString(&HalString, L"PC Compatible Eisa/Isa HAL"); + HalpReportResourceUsage(&HalString, InterfaceType); + + /* Setup PCI debugging and Hibernation */ + HalpRegisterPciDebuggingDeviceInfo(); +} + /* EOF */ diff --git a/reactos/hal/halx86/generic/usage.c b/reactos/hal/halx86/generic/usage.c index d35a3e3a964..aa500fa5ebe 100644 --- a/reactos/hal/halx86/generic/usage.c +++ b/reactos/hal/halx86/generic/usage.c @@ -14,6 +14,7 @@ /* GLOBALS ********************************************************************/ +BOOLEAN HalpNMIDumpFlag; PUCHAR KdComPortInUse; PADDRESS_USAGE HalpAddressUsageList; IDTUsageFlags HalpIDTUsageFlags[MAXIMUM_IDTVECTOR]; @@ -88,55 +89,56 @@ HalpEnableInterruptHandler(IN UCHAR Flags, /* Enable the interrupt */ HalEnableSystemInterrupt(SystemVector, Irql, Mode); } -#endif -/* - * @unimplemented - */ VOID NTAPI -HalReportResourceUsage(VOID) +HalpGetNMICrashFlag(VOID) { - INTERFACE_TYPE InterfaceType; - UNICODE_STRING HalString; + UNICODE_STRING ValueName; + UNICODE_STRING KeyName = RTL_CONSTANT_STRING(L"\\Registry\\Machine\\System\\CurrentControlSet\\Control\\CrashControl"); + OBJECT_ATTRIBUTES ObjectAttributes; + ULONG ResultLength; + HANDLE Handle; + NTSTATUS Status; + KEY_VALUE_PARTIAL_INFORMATION KeyValueInformation; - /* FIXME: Initialize DMA 64-bit support */ + /* Set default */ + HalpNMIDumpFlag = 0; - /* FIXME: Initialize MCA bus */ - - /* Initialize PCI bus. */ - HalpInitializePciBus(); + /* Initialize attributes */ + InitializeObjectAttributes(&ObjectAttributes, + &KeyName, + OBJ_CASE_INSENSITIVE, + NULL, + NULL); - /* Initialize the stubs */ - HalpInitializePciStubs(); - - /* What kind of bus is this? */ - switch (HalpBusType) + /* Open crash key */ + Status = ZwOpenKey(&Handle, KEY_READ, &ObjectAttributes); + if (NT_SUCCESS(Status)) { - /* ISA Machine */ - case MACHINE_TYPE_ISA: - InterfaceType = Isa; - break; - - /* EISA Machine */ - case MACHINE_TYPE_EISA: - InterfaceType = Eisa; - break; - - /* MCA Machine */ - case MACHINE_TYPE_MCA: - InterfaceType = MicroChannel; - break; - - /* Unknown */ - default: - InterfaceType = Internal; - break; + /* Query key value */ + RtlInitUnicodeString(&ValueName, L"NMICrashDump"); + Status = ZwQueryValueKey(Handle, + &ValueName, + KeyValuePartialInformation, + &KeyValueInformation, + sizeof(KeyValueInformation), + &ResultLength); + if (NT_SUCCESS(Status)) + { + /* Check for valid data */ + if (ResultLength == sizeof(KEY_VALUE_PARTIAL_INFORMATION)) + { + /* Read the flag */ + HalpNMIDumpFlag = KeyValueInformation.Data[0]; + } + } + + /* We're done */ + ZwClose(Handle); } - - /* Build HAL usage */ - RtlInitUnicodeString(&HalString, L"PC Compatible Eisa/Isa HAL"); - HalpReportResourceUsage(&HalString, InterfaceType); - - /* FIXME: Setup PCI debugging and Hibernation */ } +#endif + +/* EOF */ + diff --git a/reactos/hal/halx86/include/bus.h b/reactos/hal/halx86/include/bus.h index 3e07190f470..03840227411 100644 --- a/reactos/hal/halx86/include/bus.h +++ b/reactos/hal/halx86/include/bus.h @@ -158,6 +158,38 @@ typedef struct _PCI_REGISTRY_INFO_INTERNAL PCI_CARD_DESCRIPTOR CardList[ANYSIZE_ARRAY]; } PCI_REGISTRY_INFO_INTERNAL, *PPCI_REGISTRY_INFO_INTERNAL; +typedef struct _PCI_TYPE0_CFG_CYCLE_BITS +{ + union + { + struct + { + ULONG Reserved1:2; + ULONG RegisterNumber:6; + ULONG FunctionNumber:3; + ULONG Reserved2:21; + } bits; + ULONG AsULONG; + } u; +} PCI_TYPE0_CFG_CYCLE_BITS, *PPCI_TYPE0_CFG_CYCLE_BITS; + +typedef struct _PCI_TYPE1_CFG_CYCLE_BITS +{ + union + { + struct + { + ULONG Reserved1:2; + ULONG RegisterNumber:6; + ULONG FunctionNumber:3; + ULONG DeviceNumber:5; + ULONG BusNumber:8; + ULONG Reserved2:8; + } bits; + ULONG AsULONG; + } u; +} PCI_TYPE1_CFG_CYCLE_BITS, *PPCI_TYPE1_CFG_CYCLE_BITS; + typedef struct _ARRAY { ULONG ArraySize; @@ -359,6 +391,12 @@ HalpFindBusAddressTranslation( IN BOOLEAN NextBus ); +VOID +NTAPI +HalpRegisterPciDebuggingDeviceInfo( + VOID +); + extern ULONG HalpBusType; extern BOOLEAN HalpPCIConfigInitialized; extern BUS_HANDLER HalpFakePciBusHandler; diff --git a/reactos/hal/halx86/include/halp.h b/reactos/hal/halx86/include/halp.h index 44b81a08791..3bf4a808138 100644 --- a/reactos/hal/halx86/include/halp.h +++ b/reactos/hal/halx86/include/halp.h @@ -707,6 +707,19 @@ HalpOpenRegistryKey( IN BOOLEAN Create ); +VOID +NTAPI +HalpGetNMICrashFlag( + VOID +); + +VOID +NTAPI +HalpReportResourceUsage( + IN PUNICODE_STRING HalName, + IN INTERFACE_TYPE InterfaceType +); + VOID FASTCALL KeUpdateSystemTime(