From a126040bb7dbd410d669f4963d9ae3bf2528c12b Mon Sep 17 00:00:00 2001 From: Pawel Wieczorkiewicz Date: Sat, 17 Oct 2020 21:07:32 +0200 Subject: [PATCH] acpi: use ACPI config by default User ACPI tables for system configuration by default, and only when not available fallback to MP tables configuration. Initialize ACPI after BSP traps and SLAB support are initialized. Fix MP tables IOINT and LINT data structure error (polarity and trigger_mode take 2 bits). init_mptables() is not called from setup and no longer returns number of detected CPUs. There is new function: mptables_get_nr_cpus() for that purpose. Signed-off-by: Pawel Wieczorkiewicz --- common/acpi.c | 15 ++++++++------- common/setup.c | 7 +++++-- include/acpi.h | 2 +- include/smp/mptables.h | 11 ++++------- smp/mptables.c | 16 +++++++++++----- smp/smp.c | 2 +- 6 files changed, 30 insertions(+), 23 deletions(-) diff --git a/common/acpi.c b/common/acpi.c index 6ab2265c..ea69b841 100644 --- a/common/acpi.c +++ b/common/acpi.c @@ -23,6 +23,7 @@ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #include +#include #include #include #include @@ -201,12 +202,12 @@ static inline void acpi_dump_tables(void) { acpi_dump_table(acpi_tables[i], &acpi_tables[i]->header); } -static unsigned process_madt_entries(void) { +static int process_madt_entries(void) { acpi_madt_t *madt = (acpi_madt_t *) acpi_find_table(MADT_SIGNATURE); acpi_madt_entry_t *entry; if (!madt) - return 0; + return -ENOENT; printk("ACPI: [MADT] LAPIC Addr: %p, Flags: %08x\n", _ptr(madt->lapic_addr), madt->flags); @@ -244,7 +245,7 @@ static unsigned process_madt_entries(void) { } } - return nr_cpus; + return 0; } acpi_table_t *acpi_find_table(uint32_t signature) { @@ -258,7 +259,7 @@ acpi_table_t *acpi_find_table(uint32_t signature) { return NULL; } -void init_acpi(void) { +int init_acpi(void) { unsigned acpi_nr_tables; rsdt_t *rsdt = NULL; xsdt_t *xsdt = NULL; @@ -267,7 +268,7 @@ void init_acpi(void) { rsdp_rev1_t *rsdp = acpi_find_rsdp(); if (!rsdp) - return; + return -ENOENT; if (rsdp->rev < 2) rsdt = acpi_find_rsdt((rsdp_rev1_t *) rsdp); @@ -275,7 +276,7 @@ void init_acpi(void) { xsdt = acpi_find_xsdt((rsdp_rev2_t *) rsdp); if (!rsdt && !xsdt) - return; + return -ENOENT; acpi_nr_tables = (rsdp->rev < 2) ? ACPI_NR_TABLES(rsdt) : ACPI_NR_TABLES(xsdt); @@ -306,5 +307,5 @@ void init_acpi(void) { } acpi_dump_tables(); - process_madt_entries(); + return process_madt_entries(); } diff --git a/common/setup.c b/common/setup.c index 9146a18b..6e9c8017 100644 --- a/common/setup.c +++ b/common/setup.c @@ -41,6 +41,7 @@ #include #include +#include #include #include @@ -204,12 +205,14 @@ void __noreturn __text_init kernel_start(uint32_t multiboot_magic, init_percpu(); - init_acpi(); - init_traps(0); init_slab(); + if (init_acpi() < 0 && init_mptables() < 0) { + BUG(); + } + init_apic(APIC_MODE_XAPIC); init_tasks(); diff --git a/include/acpi.h b/include/acpi.h index f0ca194d..320e52e1 100644 --- a/include/acpi.h +++ b/include/acpi.h @@ -189,6 +189,6 @@ typedef struct acpi_madt acpi_madt_t; extern acpi_table_t *acpi_find_table(uint32_t signature); extern unsigned acpi_get_nr_cpus(void); -extern void init_acpi(void); +extern int init_acpi(void); #endif /* KTF_ACPI_H */ diff --git a/include/smp/mptables.h b/include/smp/mptables.h index 4d928b96..2a15c05d 100644 --- a/include/smp/mptables.h +++ b/include/smp/mptables.h @@ -122,9 +122,7 @@ typedef struct mpc_ioapic_entry mpc_ioapic_entry_t; struct mpc_ioint_entry { uint8_t type; uint8_t int_type; - struct { - uint16_t po : 1, el : 1, rsvd : 14; - }; + uint16_t po : 2, el : 2, rsvd : 12; uint8_t src_bus_id; uint8_t src_bus_irq; uint8_t dst_ioapic_id; @@ -135,9 +133,7 @@ typedef struct mpc_ioint_entry mpc_ioint_entry_t; struct mpc_lint_entry { uint8_t type; uint8_t int_type; - struct { - uint16_t po : 1, el : 1, rsvd : 14; - }; + uint16_t po : 2, el : 2, rsvd : 12; uint8_t src_bus_id; uint8_t src_bus_irq; uint8_t dst_lapic_id; @@ -147,6 +143,7 @@ typedef struct mpc_lint_entry mpc_lint_entry_t; /* External declarations */ -extern unsigned mptables_init(void); +extern unsigned mptables_get_nr_cpus(void); +extern int init_mptables(void); #endif /* KTF_MPTABLES_H */ diff --git a/smp/mptables.c b/smp/mptables.c index c5897ff8..b3688ea1 100644 --- a/smp/mptables.c +++ b/smp/mptables.c @@ -23,6 +23,7 @@ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #include +#include #include #include #include @@ -252,25 +253,30 @@ static void process_mpc_entries(mpc_hdr_t *mpc_ptr) { } } -unsigned mptables_init(void) { +unsigned mptables_get_nr_cpus(void) { return nr_cpus; } + +int init_mptables(void) { mpf_t *mpf_ptr = get_mpf_addr(); mpc_hdr_t *mpc_ptr; if (!mpf_ptr) { printk("No MP Floating Structure Pointer found!\n"); - return 0; + nr_cpus = 0; + return -ENODEV; } if (opt_debug) dump_mpf(mpf_ptr); - if (mpf_ptr->mpc_type > 0 || mpf_ptr->mpc_base == 0x0) - panic("No MP Configuration Table present!\n"); + if (mpf_ptr->mpc_type > 0 || mpf_ptr->mpc_base == 0x0) { + printk("No MP Configuration Table present!\n"); + return -ENOENT; + } mpc_ptr = get_mpc_addr(mpf_ptr); if (opt_debug) dump_mpc_hdr(mpc_ptr); process_mpc_entries(mpc_ptr); - return nr_cpus; + return 0; } diff --git a/smp/smp.c b/smp/smp.c index a8de7fd3..9a6edbba 100644 --- a/smp/smp.c +++ b/smp/smp.c @@ -94,7 +94,7 @@ static __text_init void boot_cpu(unsigned int cpu) { } void __text_init init_smp(void) { - unsigned mp_nr_cpus = mptables_init(); + unsigned mp_nr_cpus = mptables_get_nr_cpus(); unsigned acpi_nr_cpus = acpi_get_nr_cpus(); nr_cpus = acpi_nr_cpus ?: mp_nr_cpus;