aboutsummaryrefslogtreecommitdiff
path: root/src/soc/amd/common/block/acpi
diff options
context:
space:
mode:
Diffstat (limited to 'src/soc/amd/common/block/acpi')
-rw-r--r--src/soc/amd/common/block/acpi/Makefile.inc4
-rw-r--r--src/soc/amd/common/block/acpi/acpi.c144
2 files changed, 148 insertions, 0 deletions
diff --git a/src/soc/amd/common/block/acpi/Makefile.inc b/src/soc/amd/common/block/acpi/Makefile.inc
index 1320849fc3..708631a5e9 100644
--- a/src/soc/amd/common/block/acpi/Makefile.inc
+++ b/src/soc/amd/common/block/acpi/Makefile.inc
@@ -1,2 +1,6 @@
+bootblock-$(CONFIG_SOC_AMD_COMMON_BLOCK_ACPI) += acpi.c
+verstage-$(CONFIG_SOC_AMD_COMMON_BLOCK_ACPI) += acpi.c
+romstage-$(CONFIG_SOC_AMD_COMMON_BLOCK_ACPI) += acpi.c
ramstage-$(CONFIG_SOC_AMD_COMMON_BLOCK_ACPI) += acpi.c
+postcar-$(CONFIG_SOC_AMD_COMMON_BLOCK_ACPI) += acpi.c
smm-$(CONFIG_SOC_AMD_COMMON_BLOCK_ACPI) += acpi.c
diff --git a/src/soc/amd/common/block/acpi/acpi.c b/src/soc/amd/common/block/acpi/acpi.c
index 200b3c12f5..39e03e2c0c 100644
--- a/src/soc/amd/common/block/acpi/acpi.c
+++ b/src/soc/amd/common/block/acpi/acpi.c
@@ -14,9 +14,14 @@
*/
#include <arch/acpi.h>
+#include <cbmem.h>
+#include <elog.h>
+#include <console/console.h>
#include <soc/southbridge.h>
#include <amdblocks/acpimmio.h>
+#include <amdblocks/acpi.h>
#include <halt.h>
+#include <security/vboot/vboot_common.h>
void poweroff(void)
{
@@ -31,3 +36,142 @@ void poweroff(void)
if (!ENV_SMM)
halt();
}
+
+static uint16_t reset_pm1_status(void)
+{
+ uint16_t pm1_sts = acpi_read16(MMIO_ACPI_PM1_STS);
+ acpi_write16(MMIO_ACPI_PM1_STS, pm1_sts);
+ return pm1_sts;
+}
+
+static void print_num_status_bits(int num_bits, uint32_t status,
+ const char *const bit_names[])
+{
+ int i;
+
+ if (!status)
+ return;
+
+ for (i = num_bits - 1; i >= 0; i--) {
+ if (status & (1 << i)) {
+ if (bit_names[i])
+ printk(BIOS_DEBUG, "%s ", bit_names[i]);
+ else
+ printk(BIOS_DEBUG, "BIT%d ", i);
+ }
+ }
+}
+
+static uint16_t print_pm1_status(uint16_t pm1_sts)
+{
+ static const char *const pm1_sts_bits[16] = {
+ [0] = "TMROF",
+ [4] = "BMSTATUS",
+ [5] = "GBL",
+ [8] = "PWRBTN",
+ [10] = "RTC",
+ [14] = "PCIEXPWAK",
+ [15] = "WAK",
+ };
+
+ if (!pm1_sts)
+ return 0;
+
+ printk(BIOS_DEBUG, "PM1_STS: ");
+ print_num_status_bits(ARRAY_SIZE(pm1_sts_bits), pm1_sts, pm1_sts_bits);
+ printk(BIOS_DEBUG, "\n");
+
+ 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 save_sws(uint16_t pm1_status)
+{
+ struct soc_power_reg *sws;
+ uint32_t reg32;
+ uint16_t reg16;
+
+ sws = cbmem_add(CBMEM_ID_POWER_STATE, sizeof(struct soc_power_reg));
+ if (sws == NULL)
+ return;
+ sws->pm1_sts = pm1_status;
+ sws->pm1_en = acpi_read16(MMIO_ACPI_PM1_EN);
+ reg32 = acpi_read32(MMIO_ACPI_GPE0_STS);
+ acpi_write32(MMIO_ACPI_GPE0_STS, reg32);
+ sws->gpe0_sts = reg32;
+ sws->gpe0_en = acpi_read32(MMIO_ACPI_GPE0_EN);
+ reg16 = acpi_read16(MMIO_ACPI_PM1_CNT_BLK);
+ reg16 &= SLP_TYP;
+ sws->wake_from = reg16 >> SLP_TYP_SHIFT;
+}
+
+void acpi_clear_pm1_status(void)
+{
+ uint16_t pm1_sts = reset_pm1_status();
+
+ save_sws(pm1_sts);
+ log_pm1_status(pm1_sts);
+ print_pm1_status(pm1_sts);
+}
+
+int vboot_platform_is_resuming(void)
+{
+ if (!(acpi_read16(MMIO_ACPI_PM1_STS) & WAK_STS))
+ return 0;
+
+ uint16_t pm_cnt = acpi_read16(MMIO_ACPI_PM1_CNT_BLK);
+ return acpi_sleep_from_pm1(pm_cnt) == ACPI_S3;
+}
+
+/* If a system reset is about to be requested, modify the PM1 register so it
+ * will never be misinterpreted as an S3 resume. */
+void set_pm1cnt_s5(void)
+{
+ uint16_t pm1;
+
+ pm1 = acpi_read16(MMIO_ACPI_PM1_CNT_BLK);
+ pm1 &= ~SLP_TYP;
+ pm1 |= SLP_TYP_S5 << SLP_TYP_SHIFT;
+ acpi_write16(MMIO_ACPI_PM1_CNT_BLK, pm1);
+}
+
+void vboot_platform_prepare_reboot(void)
+{
+ set_pm1cnt_s5();
+}
+
+void acpi_enable_sci(void)
+{
+ uint32_t pm1;
+
+ pm1 = acpi_read32(MMIO_ACPI_PM1_CNT_BLK);
+ pm1 |= ACPI_PM1_CNT_SCIEN;
+ acpi_write32(MMIO_ACPI_PM1_CNT_BLK, pm1);
+}
+
+void acpi_disable_sci(void)
+{
+ uint32_t pm1;
+
+ pm1 = acpi_read32(MMIO_ACPI_PM1_CNT_BLK);
+ pm1 &= ~ACPI_PM1_CNT_SCIEN;
+ acpi_write32(MMIO_ACPI_PM1_CNT_BLK, pm1);
+}