From 658cb2d3c86aa97b541eca2cf00197cdb96cbb7a Mon Sep 17 00:00:00 2001 From: Rafal Kupiec Date: Thu, 6 Jun 2024 22:05:32 +0200 Subject: [PATCH] Get system information based on the ACPI (currently only number of CPUs) --- xtoskrnl/hl/acpi.c | 59 +++++++++++++++++++++++++++++++++++++ xtoskrnl/hl/globals.c | 3 ++ xtoskrnl/hl/init.c | 7 +++++ xtoskrnl/includes/globals.h | 3 ++ xtoskrnl/includes/hli.h | 4 +++ 5 files changed, 76 insertions(+) diff --git a/xtoskrnl/hl/acpi.c b/xtoskrnl/hl/acpi.c index ede4a22..89bd8bc 100644 --- a/xtoskrnl/hl/acpi.c +++ b/xtoskrnl/hl/acpi.c @@ -254,6 +254,65 @@ HlpInitializeAcpiSystemDescriptionTable(OUT PACPI_DESCRIPTION_HEADER *AcpiTable) return STATUS_SUCCESS; } +/** + * Initializes System Information structure based on the ACPI provided data. + * + * @return This routine returns a status code. + * + * @since XT 1.0 + */ +XTAPI +XTSTATUS +HlpInitializeAcpiSystemInformation(VOID) +{ + PUCHAR MadtTable; + PACPI_MADT Madt; + XTSTATUS Status; + ULONG CpuCount; + + /* Zero the ACPI system information structure */ + RtlZeroMemory(&HlpAcpiSystemInfo, sizeof(ACPI_SYSTEM_INFO)); + + /* Get Multi-APIC Description Table (MADT) */ + Status = HlGetAcpiTable(ACPI_MADT_SIGNATURE, (PACPI_DESCRIPTION_HEADER*)&Madt); + if(Status != STATUS_SUCCESS) + { + /* Failed to get MADT, return error */ + return STATUS_NOT_FOUND; + } + + /* Set APIC table traverse pointer and initialize number of CPUs */ + MadtTable = (PUCHAR)Madt->ApicTables; + CpuCount = 0; + + /* Traverse all MADT tables to get number of processors */ + while(MadtTable <= ((PUCHAR)Madt + Madt->Header.Length)) + { + /* Check if this is a local APIC subtable */ + if((((PACPI_MADT_TABLE_LOCAL_APIC)MadtTable)->Header.Type == ACPI_MADT_LOCAL_APIC) && + (((PACPI_MADT_TABLE_LOCAL_APIC)MadtTable)->Header.Length == sizeof(ACPI_MADT_TABLE_LOCAL_APIC))) + { + /* Make sure, this CPU can be enabled */ + if(((PACPI_MADT_TABLE_LOCAL_APIC)MadtTable)->LapicFlags & ACPI_MADT_PLAOC_ENABLED) + { + /* Increment number of CPUs */ + CpuCount++; + } + + /* Go to the next MADT table */ + MadtTable += ((PACPI_MADT_TABLE_LOCAL_APIC)MadtTable)->Header.Length; + } + else + { + /* Any other MADT table, try to go to the next one byte-by-byte */ + MadtTable += 1; + } + } + + /* Return success */ + return STATUS_SUCCESS; +} + /** * Initializes the ACPI Timer. * diff --git a/xtoskrnl/hl/globals.c b/xtoskrnl/hl/globals.c index be5fb40..a7bf5c0 100644 --- a/xtoskrnl/hl/globals.c +++ b/xtoskrnl/hl/globals.c @@ -15,6 +15,9 @@ LIST_ENTRY HlpAcpiCacheList; /* ACPI Root System Description Pointer (RSDP) */ PACPI_RSDP HlpAcpiRsdp; +/* ACPI system information */ +ACPI_SYSTEM_INFO HlpAcpiSystemInfo; + /* ACPI timer information */ ACPI_TIMER_INFO HlpAcpiTimerInfo; diff --git a/xtoskrnl/hl/init.c b/xtoskrnl/hl/init.c index 7b14e51..6119f9a 100644 --- a/xtoskrnl/hl/init.c +++ b/xtoskrnl/hl/init.c @@ -29,6 +29,13 @@ HlInitializeSystem(VOID) return Status; } + /* Get system information from ACPI */ + Status = HlpInitializeAcpiSystemInformation(); + if(Status != STATUS_SUCCESS) + { + return Status; + } + /* Return success */ return STATUS_SUCCESS; } diff --git a/xtoskrnl/includes/globals.h b/xtoskrnl/includes/globals.h index 8f4cf1b..7d2997c 100644 --- a/xtoskrnl/includes/globals.h +++ b/xtoskrnl/includes/globals.h @@ -18,6 +18,9 @@ EXTERN LIST_ENTRY HlpAcpiCacheList; /* ACPI Root System Description Pointer (RSDP) */ EXTERN PACPI_RSDP HlpAcpiRsdp; +/* ACPI system information */ +EXTERN ACPI_SYSTEM_INFO HlpAcpiSystemInfo; + /* ACPI timer information */ EXTERN ACPI_TIMER_INFO HlpAcpiTimerInfo; diff --git a/xtoskrnl/includes/hli.h b/xtoskrnl/includes/hli.h index b323110..0b869e7 100644 --- a/xtoskrnl/includes/hli.h +++ b/xtoskrnl/includes/hli.h @@ -99,6 +99,10 @@ XTAPI XTSTATUS HlpInitializeAcpiSystemDescriptionTable(OUT PACPI_DESCRIPTION_HEADER *AcpiTable); +XTAPI +XTSTATUS +HlpInitializeAcpiSystemInformation(VOID); + XTAPI XTSTATUS HlpInitializeAcpiTimer(VOID);