1 /* 2 * PROJECT: ReactOS Kernel 3 * LICENSE: GPL-2.0-or-later (https://spdx.org/licenses/GPL-2.0-or-later) 4 * PURPOSE: Source File for MADT Table parsing 5 * COPYRIGHT: Copyright 2021 Justin Miller <justinmiller100@gmail.com> 6 */ 7 8 /* INCLUDES *******************************************************************/ 9 10 #include <hal.h> 11 #include <acpi.h> 12 /* ACPI_BIOS_ERROR defined in acoutput.h and bugcodes.h */ 13 #undef ACPI_BIOS_ERROR 14 #include <smp.h> 15 #define NDEBUG 16 #include <debug.h> 17 18 /* GLOBALS ********************************************************************/ 19 20 PROCESSOR_IDENTITY HalpStaticProcessorIdentity[MAXIMUM_PROCESSORS] = {{0}}; 21 PPROCESSOR_IDENTITY HalpProcessorIdentity = NULL; 22 HALP_APIC_INFO_TABLE HalpApicInfoTable; 23 ACPI_TABLE_MADT *MadtTable; 24 ACPI_SUBTABLE_HEADER *AcpiHeader; 25 ACPI_MADT_LOCAL_APIC *LocalApic; 26 27 /* FUNCTIONS ******************************************************************/ 28 29 VOID 30 HalpParseApicTables( 31 _In_ PLOADER_PARAMETER_BLOCK LoaderBlock) 32 { 33 ULONG_PTR TableEnd; 34 ULONG ValidProcessorCount; 35 36 /* We only support legacy APIC for now, this will be updated in the future */ 37 HalpApicInfoTable.ApicMode = 0x10; 38 MadtTable = HalAcpiGetTable(LoaderBlock, 'CIPA'); 39 40 AcpiHeader = (ACPI_SUBTABLE_HEADER*)MadtTable; 41 AcpiHeader->Length = sizeof(ACPI_TABLE_MADT); 42 TableEnd = (ULONG_PTR)MadtTable + MadtTable->Header.Length; 43 44 HalpApicInfoTable.ProcessorCount = 0; 45 HalpProcessorIdentity = HalpStaticProcessorIdentity; 46 47 AcpiHeader = (ACPI_SUBTABLE_HEADER*)MadtTable; 48 AcpiHeader->Length = sizeof(ACPI_TABLE_MADT); 49 TableEnd = (ULONG_PTR)MadtTable + MadtTable->Header.Length; 50 51 while ((ULONG_PTR)AcpiHeader <= TableEnd) 52 { 53 LocalApic = (ACPI_MADT_LOCAL_APIC*)AcpiHeader; 54 55 if (LocalApic->Header.Type == ACPI_MADT_TYPE_LOCAL_APIC && 56 LocalApic->Header.Length == sizeof(ACPI_MADT_LOCAL_APIC)) 57 { 58 ValidProcessorCount = HalpApicInfoTable.ProcessorCount; 59 60 HalpProcessorIdentity[ValidProcessorCount].LapicId = LocalApic->Id; 61 HalpProcessorIdentity[ValidProcessorCount].ProcessorId = LocalApic->ProcessorId; 62 63 HalpApicInfoTable.ProcessorCount++; 64 65 AcpiHeader = (ACPI_SUBTABLE_HEADER*)((ULONG_PTR)AcpiHeader + AcpiHeader->Length); 66 } 67 else 68 { 69 /* End the parsing early if we don't use the currently selected table */ 70 AcpiHeader = (ACPI_SUBTABLE_HEADER*)((ULONG_PTR)AcpiHeader + 1); 71 } 72 } 73 } 74 75 VOID 76 HalpPrintApicTables(VOID) 77 { 78 UINT32 i; 79 80 DPRINT1("HAL has detected a physical processor count of: %d\n", HalpApicInfoTable.ProcessorCount); 81 for (i = 0; i < HalpApicInfoTable.ProcessorCount; i++) 82 { 83 DPRINT1("Information about the following processor is for processors number: %d\n" 84 " The BSPCheck is set to: %X\n" 85 " The LapicID is set to: %X\n", 86 i, HalpProcessorIdentity[i].BSPCheck, HalpProcessorIdentity[i].LapicId); 87 } 88 } 89