soc/amd/common/block/acpi: Extract event logging helpers
Move the event logging helpers defined in acpi into a separate library.
This will allow logging power management and GPE events for both S3 and
Modern Standby. Introduce a single helper acpi_log_events function to
log both PM and GPE events.
BUG=None
TEST=Build and boot to OS in Guybrush.
Change-Id: I96df66edfc824eb3db108098a560d33d758f55ba
Signed-off-by: Karthikeyan Ramasubramanian <kramasub@google.com>
Reviewed-on: https://review.coreboot.org/c/coreboot/+/56360
Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
Reviewed-by: Furquan Shaikh <furquan@google.com>
Reviewed-by: Felix Held <felix-coreboot@felixheld.de>
diff --git a/src/soc/amd/common/block/acpi/Makefile.inc b/src/soc/amd/common/block/acpi/Makefile.inc
index 30e01dd..41ce92b 100644
--- a/src/soc/amd/common/block/acpi/Makefile.inc
+++ b/src/soc/amd/common/block/acpi/Makefile.inc
@@ -13,4 +13,7 @@
ramstage-$(CONFIG_SOC_AMD_COMMON_BLOCK_ACPI_ALIB) += alib.c
ramstage-$(CONFIG_SOC_AMD_COMMON_BLOCK_ACPI_GPIO) += gpio.c
+romstage-y += elog.c
+ramstage-y += elog.c
+
endif # CONFIG_SOC_AMD_COMMON_BLOCK_ACPI
diff --git a/src/soc/amd/common/block/acpi/acpi.c b/src/soc/amd/common/block/acpi/acpi.c
index df5b40d..9e4010d 100644
--- a/src/soc/amd/common/block/acpi/acpi.c
+++ b/src/soc/amd/common/block/acpi/acpi.c
@@ -1,12 +1,11 @@
/* SPDX-License-Identifier: GPL-2.0-only */
-#include <amdblocks/acpimmio.h>
-#include <amdblocks/acpi.h>
#include <acpi/acpi.h>
#include <acpi/acpi_pm.h>
+#include <amdblocks/acpimmio.h>
+#include <amdblocks/acpi.h>
#include <bootmode.h>
#include <console/console.h>
-#include <elog.h>
#include <halt.h>
#include <security/vboot/vboot_common.h>
#include <soc/southbridge.h>
@@ -65,36 +64,6 @@
return pm1_sts;
}
-static void log_pm1_status(uint16_t pm1_sts)
-{
- if (!CONFIG(ELOG))
- return;
-
- if (pm1_sts & WAK_STS)
- elog_add_event_byte(ELOG_TYPE_ACPI_WAKE,
- acpi_is_wakeup_s3() ? ACPI_S3 : ACPI_S5);
-
- if (pm1_sts & PWRBTN_STS)
- elog_add_event_wake(ELOG_WAKE_SOURCE_PWRBTN, 0);
-
- if (pm1_sts & RTC_STS)
- elog_add_event_wake(ELOG_WAKE_SOURCE_RTC, 0);
-
- if (pm1_sts & PCIEXPWAK_STS)
- elog_add_event_wake(ELOG_WAKE_SOURCE_PCIE, 0);
-}
-
-static void log_gpe_events(const struct acpi_pm_gpe_state *state)
-{
- int i;
- uint32_t valid_gpe = state->gpe0_sts & state->gpe0_en;
-
- for (i = 0; i <= 31; i++) {
- if (valid_gpe & (1U << i))
- elog_add_event_wake(ELOG_WAKE_SOURCE_GPE, i);
- }
-}
-
void acpi_fill_pm_gpe_state(struct acpi_pm_gpe_state *state)
{
state->pm1_sts = acpi_read16(MMIO_ACPI_PM1_STS);
@@ -114,9 +83,8 @@
return;
state = &ps->gpe_state;
- log_pm1_status(state->pm1_sts);
print_pm1_status(state->pm1_sts);
- log_gpe_events(state);
+ acpi_log_events(ps);
}
void acpi_clear_pm_gpe_status(void)
diff --git a/src/soc/amd/common/block/acpi/elog.c b/src/soc/amd/common/block/acpi/elog.c
new file mode 100644
index 0000000..b9268aa
--- /dev/null
+++ b/src/soc/amd/common/block/acpi/elog.c
@@ -0,0 +1,39 @@
+/* SPDX-License-Identifier: GPL-2.0-only */
+
+#include <amdblocks/acpi.h>
+#include <elog.h>
+#include <soc/southbridge.h>
+
+static void elog_pm1_status(const struct acpi_pm_gpe_state *state)
+{
+ uint16_t pm1_sts = state->pm1_sts;
+
+ if (pm1_sts & WAK_STS)
+ elog_add_event_byte(ELOG_TYPE_ACPI_WAKE, state->previous_sx_state);
+
+ if (pm1_sts & PWRBTN_STS)
+ elog_add_event_wake(ELOG_WAKE_SOURCE_PWRBTN, 0);
+
+ if (pm1_sts & RTC_STS)
+ elog_add_event_wake(ELOG_WAKE_SOURCE_RTC, 0);
+
+ if (pm1_sts & PCIEXPWAK_STS)
+ elog_add_event_wake(ELOG_WAKE_SOURCE_PCIE, 0);
+}
+
+static void elog_gpe_events(const struct acpi_pm_gpe_state *state)
+{
+ int i;
+ uint32_t valid_gpe = state->gpe0_sts & state->gpe0_en;
+
+ for (i = 0; i <= 31; i++) {
+ if (valid_gpe & (1U << i))
+ elog_add_event_wake(ELOG_WAKE_SOURCE_GPE, i);
+ }
+}
+
+void acpi_log_events(const struct chipset_power_state *ps)
+{
+ elog_pm1_status(&ps->gpe_state);
+ elog_gpe_events(&ps->gpe_state);
+}
diff --git a/src/soc/amd/common/block/include/amdblocks/acpi.h b/src/soc/amd/common/block/include/amdblocks/acpi.h
index eec5a3f..fa75e5a 100644
--- a/src/soc/amd/common/block/include/amdblocks/acpi.h
+++ b/src/soc/amd/common/block/include/amdblocks/acpi.h
@@ -59,4 +59,6 @@
uintptr_t add_agesa_fsp_acpi_table(guid_t guid, const char *name, acpi_rsdp_t *rsdp,
uintptr_t current);
+void acpi_log_events(const struct chipset_power_state *ps);
+
#endif /* AMD_BLOCK_ACPI_H */