From 0d2d27e90713ca497f4d0e87c981d732cff0baf8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Beno=C3=AEt=20Canet?= <benoit@irqsave.net> Date: Mon, 14 Oct 2013 16:17:39 +0200 Subject: [PATCH] acpi: initialize ACPICA subsystem in main_cont() The initialization is done a this time so everything needed is ready. Signed-off-by: Benoit Canet <benoit@irqsave.net> Signed-off-by: Avi Kivity <avi@cloudius-systems.com> --- core/power.cc | 14 +------------ drivers/acpi.cc | 54 ++++++++++++++++++++++++++++++++++++++++++++++++- drivers/acpi.hh | 18 +++++++++++++++++ loader.cc | 2 ++ 4 files changed, 74 insertions(+), 14 deletions(-) create mode 100644 drivers/acpi.hh diff --git a/core/power.cc b/core/power.cc index 857ae7050..dd1107613 100644 --- a/core/power.cc +++ b/core/power.cc @@ -30,19 +30,7 @@ void halt(void) void poweroff(void) { - ACPI_STATUS status; - status = AcpiInitializeSubsystem(); - if (ACPI_FAILURE(status)) { - debug("AcpiInitializeSubsystem failed: %s\n", AcpiFormatException(status)); - halt(); - } - status = AcpiLoadTables(); - if (ACPI_FAILURE(status)) { - debug("AcpiLoadTables failed: %s\n", AcpiFormatException(status)); - halt(); - } - - status = AcpiEnterSleepStatePrep(ACPI_STATE_S5); + ACPI_STATUS status = AcpiEnterSleepStatePrep(ACPI_STATE_S5); if (ACPI_FAILURE(status)) { debug("AcpiEnterSleepStatePrep failed: %s\n", AcpiFormatException(status)); halt(); diff --git a/drivers/acpi.cc b/drivers/acpi.cc index 3d65893c2..be7703489 100644 --- a/drivers/acpi.cc +++ b/drivers/acpi.cc @@ -21,6 +21,7 @@ extern "C" { #include "align.hh" #include "xen.hh" +#include <osv/debug.h> #include <osv/mutex.h> #include <osv/semaphore.hh> @@ -480,7 +481,58 @@ void AcpiOsVprintf(const char *Format, va_list Args) vprintf(Format, Args); } -void __attribute__((constructor(ACPI_INIT_PRIO))) acpi_init() +void __attribute__((constructor(ACPI_INIT_PRIO))) acpi_init_early() { XENPV_ALTERNATIVE({auto st = AcpiInitializeTables(NULL, 0, false); assert(st == AE_OK);}, {}); } + +namespace acpi { + +// must be called after the scheduler, apic and smp where started to run +// The following function comes from the documentation example page 262 +void init() +{ + bool allow_resize = false; + static int max_acpi_tables = 16; + + // Initialize ACPICA subsystem + ACPI_STATUS status = AcpiInitializeSubsystem(); + if (ACPI_FAILURE(status)) { + debug("AcpiInitializeSubsystem() failed: %s\n", + AcpiFormatException(status)); + return; + } + + // Initialize the ACPICA Table Manager and get all ACPI tables + // nothing is preallocated so pass a nullptr so the code will allocate and + // fill up to max_acpi_tables + status = AcpiInitializeTables(nullptr, max_acpi_tables, allow_resize); + if (ACPI_FAILURE(status)) { + debug("AcpiInitializeTables failed: %s\n", AcpiFormatException(status)); + return; + } + + // Create the ACPI namespace from ACPI tables + status = AcpiLoadTables(); + if (ACPI_FAILURE(status)) { + debug("AcpiLoadTables failed: %s\n", AcpiFormatException(status)); + return; + } + + // TODO: Installation of Local handlers + + // Initialize the ACPI hardware + status = AcpiEnableSubsystem(ACPI_FULL_INITIALIZATION); + if (ACPI_FAILURE(status)) { + debug("AcpiEnableSubsystem failed: %s\n", AcpiFormatException(status)); + return; + } + + // Complete the ACPI namespace object initialization + status = AcpiInitializeObjects(ACPI_FULL_INITIALIZATION); + if (ACPI_FAILURE(status)) { + debug("AcpiInitializeObjects failed: %s\n", AcpiFormatException(status)); + } +} + +} diff --git a/drivers/acpi.hh b/drivers/acpi.hh new file mode 100644 index 000000000..8373745b8 --- /dev/null +++ b/drivers/acpi.hh @@ -0,0 +1,18 @@ +/* + * Copyright (C) 2013 Nodalink, SARL. + * + * This work is open source software, licensed under the terms of the + * BSD license as described in the LICENSE file in the top-level directory. + */ +#ifndef _OSV_DRIVER_ACPI_HH_ +#define _OSV_DRIVER_ACPI_HH_ + +#include "acpi.h" + +namespace acpi { + +void init(); + +} + +#endif //!_OSV_DRIVER_ACPI_HH_ diff --git a/loader.cc b/loader.cc index e9a2589f4..4f042848c 100644 --- a/loader.cc +++ b/loader.cc @@ -22,6 +22,7 @@ #include "xen.hh" #include "ioapic.hh" +#include "drivers/acpi.hh" #include "drivers/driver.hh" #include "drivers/virtio-net.hh" #include "drivers/virtio-blk.hh" @@ -256,6 +257,7 @@ void main_cont(int ac, char** av) std::tie(ac, av) = parse_options(ac, av); ioapic::init(); smp_launch(); + acpi::init(); sched::preempt_enable(); console::console_init(); memory::enable_debug_allocator(); -- GitLab