blob: f9f5fc021084b1a2bdb6195ca75bf4c036748399 [file] [log] [blame]
Felix Held4a8cd722020-04-18 22:26:39 +02001/* SPDX-License-Identifier: GPL-2.0-or-later */
Martin Roth5c354b92019-04-22 14:55:16 -06002
Furquan Shaikh76cedd22020-05-02 10:24:23 -07003#include <acpi/acpi.h>
Martin Roth5c354b92019-04-22 14:55:16 -06004#include <amdblocks/acpi.h>
Felix Held15c43452021-03-09 00:14:48 +01005#include <amdblocks/acpimmio.h>
Marshall Dawsone8ffa9f2020-03-16 19:20:20 -06006#include <amdblocks/psp.h>
Felix Helda5a52952020-12-01 18:14:01 +01007#include <amdblocks/smi.h>
Felix Helda3a66b62021-02-10 03:29:48 +01008#include <amdblocks/smm.h>
Felix Held15c43452021-03-09 00:14:48 +01009#include <arch/hlt.h>
10#include <arch/io.h>
11#include <console/console.h>
12#include <cpu/x86/cache.h>
13#include <cpu/x86/smm.h>
Martin Roth5c354b92019-04-22 14:55:16 -060014#include <elog.h>
Felix Held15c43452021-03-09 00:14:48 +010015#include <soc/smi.h>
Marshall Dawson4dc4cb62020-04-03 12:07:00 -060016#include <soc/smu.h>
Felix Held15c43452021-03-09 00:14:48 +010017#include <soc/southbridge.h>
Felix Held2e978972021-02-10 16:48:23 +010018#include <types.h>
Martin Roth5c354b92019-04-22 14:55:16 -060019
Felix Helda2db88e2021-02-10 16:46:11 +010020static void fch_apmc_smi_handler(void)
Martin Roth5c354b92019-04-22 14:55:16 -060021{
22 const uint8_t cmd = inb(pm_acpi_smi_cmd_port());
23
24 switch (cmd) {
25 case APM_CNT_ACPI_ENABLE:
Raul E Rangelc7ab9f42021-12-06 10:53:54 -070026 acpi_clear_pm_gpe_status();
Martin Roth5c354b92019-04-22 14:55:16 -060027 acpi_enable_sci();
28 break;
29 case APM_CNT_ACPI_DISABLE:
30 acpi_disable_sci();
31 break;
32 case APM_CNT_ELOG_GSMI:
33 if (CONFIG(ELOG_GSMI))
Felix Held90bcdb42021-03-08 23:54:18 +010034 handle_smi_gsmi();
Martin Roth5c354b92019-04-22 14:55:16 -060035 break;
Marshall Dawsond1255932020-01-19 10:22:43 -070036 case APM_CNT_SMMSTORE:
37 if (CONFIG(SMMSTORE))
Felix Held90bcdb42021-03-08 23:54:18 +010038 handle_smi_store();
Marshall Dawsond1255932020-01-19 10:22:43 -070039 break;
Marshall Dawsone8ffa9f2020-03-16 19:20:20 -060040 case APM_CNT_SMMINFO:
41 psp_notify_smm();
42 break;
Martin Roth5c354b92019-04-22 14:55:16 -060043 }
44
45 mainboard_smi_apmc(cmd);
46}
47
Felix Helda2db88e2021-02-10 16:46:11 +010048static void fch_slp_typ_handler(void)
Martin Roth5c354b92019-04-22 14:55:16 -060049{
50 uint32_t pci_ctrl, reg32;
51 uint16_t pm1cnt, reg16;
52 uint8_t slp_typ, rst_ctrl;
53
54 /* Figure out SLP_TYP */
55 pm1cnt = acpi_read16(MMIO_ACPI_PM1_CNT_BLK);
56 printk(BIOS_SPEW, "SMI#: SLP = 0x%04x\n", pm1cnt);
57 slp_typ = acpi_sleep_from_pm1(pm1cnt);
58
59 /* Do any mainboard sleep handling */
60 mainboard_smi_sleep(slp_typ);
61
62 switch (slp_typ) {
63 case ACPI_S0:
64 printk(BIOS_DEBUG, "SMI#: Entering S0 (On)\n");
65 break;
66 case ACPI_S3:
67 printk(BIOS_DEBUG, "SMI#: Entering S3 (Suspend-To-RAM)\n");
68 break;
69 case ACPI_S4:
70 printk(BIOS_DEBUG, "SMI#: Entering S4 (Suspend-To-Disk)\n");
71 break;
72 case ACPI_S5:
73 printk(BIOS_DEBUG, "SMI#: Entering S5 (Soft Power off)\n");
74 break;
75 default:
76 printk(BIOS_DEBUG, "SMI#: ERROR: SLP_TYP reserved\n");
77 break;
78 }
79
80 if (slp_typ >= ACPI_S3) {
81 /* Sleep Type Elog S3, S4, and S5 entry */
Kyösti Mälkki9dd1a122019-11-06 11:04:27 +020082 elog_gsmi_add_event_byte(ELOG_TYPE_ACPI_ENTER, slp_typ);
Martin Roth5c354b92019-04-22 14:55:16 -060083
84 wbinvd();
85
Felix Held4f69ab72021-02-10 01:26:07 +010086 clear_all_smi_status();
Martin Roth5c354b92019-04-22 14:55:16 -060087
88 /* Do not send SMI before AcpiPm1CntBlkx00[SlpTyp] */
89 pci_ctrl = pm_read32(PM_PCI_CTRL);
90 pci_ctrl &= ~FORCE_SLPSTATE_RETRY;
Martin Roth5c354b92019-04-22 14:55:16 -060091 pm_write32(PM_PCI_CTRL, pci_ctrl);
92
93 /* Enable SlpTyp */
94 rst_ctrl = pm_read8(PM_RST_CTRL1);
95 rst_ctrl |= SLPTYPE_CONTROL_EN;
96 pm_write8(PM_RST_CTRL1, rst_ctrl);
97
98 /*
99 * Before the final command, check if there's pending wake
100 * event. Read enable first, so that reading the actual status
101 * is as close as possible to entering S3. The idea is to
102 * minimize the opportunity for a wake event to happen before
103 * actually entering S3. If there's a pending wake event, log
104 * it and continue normal path. S3 will fail and the wake event
105 * becomes a SCI.
106 */
107 if (CONFIG(ELOG_GSMI)) {
108 reg16 = acpi_read16(MMIO_ACPI_PM1_EN);
109 reg16 &= acpi_read16(MMIO_ACPI_PM1_STS);
110 if (reg16)
111 elog_add_extended_event(
112 ELOG_SLEEP_PENDING_PM1_WAKE,
113 (u32)reg16);
114
115 reg32 = acpi_read32(MMIO_ACPI_GPE0_EN);
116 reg32 &= acpi_read32(MMIO_ACPI_GPE0_STS);
117 if (reg32)
118 elog_add_extended_event(
119 ELOG_SLEEP_PENDING_GPE0_WAKE,
120 reg32);
121 } /* if (CONFIG(ELOG_GSMI)) */
122
Marshall Dawson4d38c752020-07-01 17:04:03 -0600123 if (slp_typ == ACPI_S3)
124 psp_notify_sx_info(ACPI_S3);
Marshall Dawson90b83392020-03-19 15:08:01 -0600125
Marshall Dawson4dc4cb62020-04-03 12:07:00 -0600126 smu_sx_entry(); /* Leave SlpTypeEn clear, SMU will set */
127 printk(BIOS_ERR, "Error: System did not go to sleep\n");
128
Martin Roth5c354b92019-04-22 14:55:16 -0600129 hlt();
130 }
131}
132
133int southbridge_io_trap_handler(int smif)
134{
135 return 0;
136}
137
138/*
139 * Table of functions supported in the SMI handler. Note that SMI source setup
Felix Held37fbbfd2021-02-10 00:48:33 +0100140 * in fch.c is unrelated to this list.
Martin Roth5c354b92019-04-22 14:55:16 -0600141 */
142static const struct smi_sources_t smi_sources[] = {
Felix Helda2db88e2021-02-10 16:46:11 +0100143 { .type = SMITYPE_SMI_CMD_PORT, .handler = fch_apmc_smi_handler },
144 { .type = SMITYPE_SLP_TYP, .handler = fch_slp_typ_handler},
Martin Roth5c354b92019-04-22 14:55:16 -0600145};
146
Felix Helda3a66b62021-02-10 03:29:48 +0100147void *get_smi_source_handler(int source)
Martin Roth5c354b92019-04-22 14:55:16 -0600148{
Felix Held2e978972021-02-10 16:48:23 +0100149 size_t i;
Martin Roth5c354b92019-04-22 14:55:16 -0600150
151 for (i = 0 ; i < ARRAY_SIZE(smi_sources) ; i++)
152 if (smi_sources[i].type == source)
153 return smi_sources[i].handler;
154
155 return NULL;
156}