From a98ac789aa458d775d170bf422890c532b0313e1 Mon Sep 17 00:00:00 2001 From: Daniil Tatianin <99danilt@gmail.com> Date: Mon, 30 Dec 2024 14:23:12 +0300 Subject: [PATCH] uacpi: don't forget to leave ACPI mode during state reset Signed-off-by: Daniil Tatianin <99danilt@gmail.com> --- include/uacpi/internal/context.h | 1 + source/uacpi.c | 73 ++++++++++++++++++-------------- 2 files changed, 43 insertions(+), 31 deletions(-) diff --git a/include/uacpi/internal/context.h b/include/uacpi/internal/context.h index 3b2d9b94..1b34d86e 100644 --- a/include/uacpi/internal/context.h +++ b/include/uacpi/internal/context.h @@ -47,6 +47,7 @@ struct uacpi_runtime_context { #ifndef UACPI_REDUCED_HARDWARE uacpi_bool is_hardware_reduced; + uacpi_bool was_in_legacy_mode; uacpi_bool has_global_lock; uacpi_bool sci_handle_valid; uacpi_handle sci_handle; diff --git a/source/uacpi.c b/source/uacpi.c index 6448a11f..d08ae31a 100644 --- a/source/uacpi.c +++ b/source/uacpi.c @@ -17,30 +17,6 @@ struct uacpi_runtime_context g_uacpi_rt_ctx = { 0 }; -void uacpi_state_reset(void) -{ - uacpi_deinitialize_namespace(); - uacpi_deinitialize_interfaces(); - uacpi_deinitialize_events(); - uacpi_deinitialize_notify(); - uacpi_deinitialize_opregion(); - uacpi_deininitialize_registers(); - uacpi_deinitialize_tables(); - -#ifndef UACPI_REDUCED_HARDWARE - if (g_uacpi_rt_ctx.global_lock_event) - uacpi_kernel_free_event(g_uacpi_rt_ctx.global_lock_event); - if (g_uacpi_rt_ctx.global_lock_spinlock) - uacpi_kernel_free_spinlock(g_uacpi_rt_ctx.global_lock_spinlock); -#endif - - uacpi_memzero(&g_uacpi_rt_ctx, sizeof(g_uacpi_rt_ctx)); - -#ifdef UACPI_KERNEL_INITIALIZATION - uacpi_kernel_deinitialize(); -#endif -} - void uacpi_context_set_log_level(uacpi_log_level lvl) { if (lvl == 0) @@ -225,7 +201,7 @@ static uacpi_status set_mode(enum hw_mode mode) return UACPI_STATUS_HARDWARE_TIMEOUT; } -static uacpi_status enter_mode(enum hw_mode mode) +static uacpi_status enter_mode(enum hw_mode mode, uacpi_bool *did_change) { uacpi_status ret; const uacpi_char *mode_str; @@ -252,18 +228,28 @@ static uacpi_status enter_mode(enum hw_mode mode) } uacpi_trace("entered %s mode\n", mode_str); + if (did_change != UACPI_NULL) + *did_change = UACPI_TRUE; + return ret; } uacpi_status uacpi_enter_acpi_mode(void) { - return enter_mode(HW_MODE_ACPI); + return enter_mode(HW_MODE_ACPI, UACPI_NULL); } uacpi_status uacpi_leave_acpi_mode(void) { - return enter_mode(HW_MODE_LEGACY); + return enter_mode(HW_MODE_LEGACY, UACPI_NULL); +} + +static void enter_acpi_mode_initial(void) +{ + enter_mode(HW_MODE_ACPI, &g_uacpi_rt_ctx.was_in_legacy_mode); } +#else +static void enter_acpi_mode_initial(void) { } #endif uacpi_init_level uacpi_get_current_init_level(void) @@ -271,6 +257,32 @@ uacpi_init_level uacpi_get_current_init_level(void) return g_uacpi_rt_ctx.init_level; } +void uacpi_state_reset(void) +{ + uacpi_deinitialize_namespace(); + uacpi_deinitialize_interfaces(); + uacpi_deinitialize_events(); + uacpi_deinitialize_notify(); + uacpi_deinitialize_opregion(); + uacpi_deininitialize_registers(); + uacpi_deinitialize_tables(); + +#ifndef UACPI_REDUCED_HARDWARE + if (g_uacpi_rt_ctx.was_in_legacy_mode) + uacpi_leave_acpi_mode(); + if (g_uacpi_rt_ctx.global_lock_event) + uacpi_kernel_free_event(g_uacpi_rt_ctx.global_lock_event); + if (g_uacpi_rt_ctx.global_lock_spinlock) + uacpi_kernel_free_spinlock(g_uacpi_rt_ctx.global_lock_spinlock); +#endif + + uacpi_memzero(&g_uacpi_rt_ctx, sizeof(g_uacpi_rt_ctx)); + +#ifdef UACPI_KERNEL_INITIALIZATION + uacpi_kernel_deinitialize(); +#endif +} + uacpi_status uacpi_initialize(uacpi_u64 flags) { uacpi_status ret; @@ -327,10 +339,9 @@ uacpi_status uacpi_initialize(uacpi_u64 flags) uacpi_install_default_address_space_handlers(); - if (!uacpi_check_flag(UACPI_FLAG_NO_ACPI_MODE)) { - // This is not critical, so just ignore the return status - uacpi_enter_acpi_mode(); - } + if (!uacpi_check_flag(UACPI_FLAG_NO_ACPI_MODE)) + enter_acpi_mode_initial(); + return UACPI_STATUS_OK; out_fatal_error: