From 30e37d90ddeec2cbfc6089bb0b5f5f64f3317cc1 Mon Sep 17 00:00:00 2001 From: Christian Helmuth Date: Mon, 18 Dec 2023 11:47:08 +0100 Subject: [PATCH] acpica: provide verbose config If "verbose" is set to true in the config, AcpiOsPrintf etc. are enabled to log to a dedicated LOG session using the Format:Console utility. Issue #5083 --- repos/libports/run/acpica.run | 5 +- repos/libports/src/app/acpica/README | 5 +- repos/libports/src/app/acpica/os.cc | 4 ++ repos/libports/src/app/acpica/printf.cc | 65 +++++++++++++++++++++++-- repos/libports/src/app/acpica/target.mk | 2 +- repos/libports/src/app/acpica/util.h | 8 +++ 6 files changed, 80 insertions(+), 9 deletions(-) diff --git a/repos/libports/run/acpica.run b/repos/libports/run/acpica.run index 67b54e048e..0d49ce7e5c 100644 --- a/repos/libports/run/acpica.run +++ b/repos/libports/run/acpica.run @@ -162,9 +162,10 @@ set config { - + - + diff --git a/repos/libports/src/app/acpica/README b/repos/libports/src/app/acpica/README index 8a82b75127..9637bcde6d 100644 --- a/repos/libports/src/app/acpica/README +++ b/repos/libports/src/app/acpica/README @@ -41,13 +41,16 @@ Furthermore the ACPICA library may trigger, dependent on the ACPI ASL code, various I/O port and I/O mem accesses to hardware. Accesses to PCI devices are ignored and dropped by this component. +Log verbosity can be increased by the "verbose" config attribute. + Excerpt of important parts of the acpica configuration ------------------------------------------------------ ! ! ! ... -! +! ! ! ! diff --git a/repos/libports/src/app/acpica/os.cc b/repos/libports/src/app/acpica/os.cc index 92f9c44fdd..cfdcafe1b0 100644 --- a/repos/libports/src/app/acpica/os.cc +++ b/repos/libports/src/app/acpica/os.cc @@ -200,11 +200,15 @@ struct Acpica::Main bool const enable_reset = config.xml().attribute_value("reset", false); bool const enable_poweroff = config.xml().attribute_value("poweroff", false); bool const enable_report = config.xml().attribute_value("report", false); + bool const verbose = config.xml().attribute_value("verbose", false); auto const periodic_ms = config.xml().attribute_value("report_period_ms", 0ULL); if (enable_report) report = new (heap) Acpica::Reportstate(env); + if (verbose) + init_printf(env); + init_acpica(config.xml().attribute_value("use_gpe", true)); if (enable_report) diff --git a/repos/libports/src/app/acpica/printf.cc b/repos/libports/src/app/acpica/printf.cc index 86269eadbe..4afcb2d2cc 100644 --- a/repos/libports/src/app/acpica/printf.cc +++ b/repos/libports/src/app/acpica/printf.cc @@ -6,12 +6,67 @@ */ #include +#include +#include -extern "C" -void AcpiOsPrintf (const char *fmt, ...) -{ } +#include "util.h" + +using namespace Genode; + + +struct Formatted_log : Format::Console +{ + Log_connection con; + + char str[Log_session::MAX_STRING_LEN] { }; + + size_t pos { }; + + Formatted_log(Env &env) : con(env, "debug") { } + + void _out_char(char c) override + { + if (c != '\n') + str[pos++] = c; + + if (c == '\n' || pos == sizeof(str)) { + str[pos] = 0; + con.write(str); + pos = 0; + } + } +}; + + +static Formatted_log *formatted_log; + + +void Acpica::init_printf(Env &env) +{ + static Formatted_log instance(env); + + formatted_log = &instance; +}; + + +extern "C" { + +#include "acpi.h" +#include "acpiosxf.h" -extern "C" void AcpiOsVprintf (const char *fmt, va_list va) -{ } +{ + if (formatted_log) + formatted_log->vprintf(fmt, va); +} + +void AcpiOsPrintf (const char *fmt, ...) +{ + va_list args; + va_start(args, fmt); + AcpiOsVprintf(fmt, args); + va_end(args); +} + +} diff --git a/repos/libports/src/app/acpica/target.mk b/repos/libports/src/app/acpica/target.mk index 0db7d0f48c..51c6b05a8c 100644 --- a/repos/libports/src/app/acpica/target.mk +++ b/repos/libports/src/app/acpica/target.mk @@ -1,6 +1,6 @@ TARGET := acpica SRC_CC := os.cc printf.cc report.cc REQUIRES := x86 -LIBS += base acpica +LIBS += base acpica format CC_CXX_WARN_STRICT = diff --git a/repos/libports/src/app/acpica/util.h b/repos/libports/src/app/acpica/util.h index a37d81f5e1..0d2200fbe3 100644 --- a/repos/libports/src/app/acpica/util.h +++ b/repos/libports/src/app/acpica/util.h @@ -13,12 +13,18 @@ #ifndef _ACPICA__UTIL_H_ #define _ACPICA__UTIL_H_ +#include +#include + extern "C" { #include "acpi.h" } namespace Acpica { + + using namespace Genode; + template class Buffer; template class Callback; @@ -26,6 +32,8 @@ namespace Acpica { void for_each_element(H const head, S *, F const &fn, FSIZE const &fn_size); void generate_suspend_report(Genode::Reporter::Xml_generator &); + + void init_printf(Env &); } template