amd64: Allow early ACPICA table subsystem init

Add a method for initializing the ACPICA table subsystem earlier than
the initilization of the entire ACPICA subsystem. Also add a method to
walk through the subtables of an ACPI table
This commit is contained in:
Matheus Pecoraro
2024-07-23 17:28:13 -03:00
committed by Chris Johns
parent f920b6f1e4
commit 0665da8f1d
2 changed files with 68 additions and 3 deletions

View File

@@ -37,19 +37,57 @@
#include <assert.h> #include <assert.h>
#include <acpi/acpi.h> #include <acpi/acpi.h>
#include <acpi/acpica/acpi.h>
#include <rtems/sysinit.h> #include <rtems/sysinit.h>
uint64_t acpi_rsdp_addr = 0; uint64_t acpi_rsdp_addr = 0;
static bool acpi_tables_initialized = false;
bool acpi_tables_initialize(void)
{
ACPI_STATUS status;
status = AcpiInitializeTables(NULL, ACPI_MAX_INIT_TABLES, FALSE);
if (status == (AE_OK)) {
acpi_tables_initialized = true;
return true;
}
return false;
}
void acpi_walk_subtables(
ACPI_TABLE_HEADER* table,
size_t size_of_header,
void (*handler)(ACPI_SUBTABLE_HEADER*)
)
{
ACPI_SUBTABLE_HEADER* entry;
ACPI_SUBTABLE_HEADER* end;
if (table == NULL) {
return;
}
entry = (ACPI_SUBTABLE_HEADER*) ((uint8_t*) table + size_of_header);
end = (ACPI_SUBTABLE_HEADER*) ((uint8_t*) table + table->Length);
while (entry < end) {
handler(entry);
entry = (ACPI_SUBTABLE_HEADER*) ((uint8_t*) entry + entry->Length);
}
}
static void initialize_acpi(void) static void initialize_acpi(void)
{ {
ACPI_STATUS status; ACPI_STATUS status;
status = AcpiInitializeSubsystem(); status = AcpiInitializeSubsystem();
assert(status == (AE_OK)); assert(status == (AE_OK));
status = AcpiInitializeTables(NULL, ACPI_MAX_INIT_TABLES, FALSE); if (acpi_tables_initialized == false) {
assert(status == (AE_OK)); status = AcpiInitializeTables(NULL, ACPI_MAX_INIT_TABLES, FALSE);
assert(status == (AE_OK));
}
status = AcpiLoadTables(); status = AcpiLoadTables();
assert(status == (AE_OK)); assert(status == (AE_OK));

View File

@@ -39,9 +39,36 @@
#define _AMD64_ACPI_H_ #define _AMD64_ACPI_H_
#include <bsp.h> #include <bsp.h>
#include <acpi/acpica/acpi.h>
#define ACPI_MAX_INIT_TABLES 16 #define ACPI_MAX_INIT_TABLES 16
extern uint64_t acpi_rsdp_addr; extern uint64_t acpi_rsdp_addr;
/**
* @brief Initializes the ACPICA Table Manager. Requires dynamic memory.
*
* The ACPICA Table Manager is independent of the rest of the ACPICA subsystem
* and only requires dynamic memory to be initialized (unless a statically
* allocated array for the tables is provided). Since access to ACPI tables
* may be required before the entire ACPICA subsystem can be initialized
* this routine can be used earlier in the system intialization.
*
* @return true if successful.
*/
bool acpi_tables_initialize(void);
/**
* @brief Walks through the subtables of an ACPI table.
*
* @param table Pointer to the table.
* @param size_of_header Size of the table header (used to offset into first subtable).
* @param handler Handler that is called for each subtable found.
*/
void acpi_walk_subtables(
ACPI_TABLE_HEADER *table,
size_t size_of_header,
void (*handler)(ACPI_SUBTABLE_HEADER*)
);
#endif /* _AMD64_ACPI_H_ */ #endif /* _AMD64_ACPI_H_ */