blob: 509a1d404aac05e69c9e99b092a8cebf5ad59cb5 [file] [log] [blame]
Felix Heldee2a3652021-02-09 23:43:17 +01001/* SPDX-License-Identifier: GPL-2.0-or-later */
2
Felix Heldbe35a3a2021-02-10 16:34:31 +01003#include <acpi/acpi.h>
4#include <amdblocks/acpi.h>
5#include <amdblocks/acpimmio.h>
Felix Heldd51fd302021-02-11 05:02:27 +01006#include <amdblocks/psp.h>
Felix Heldbe35a3a2021-02-10 16:34:31 +01007#include <amdblocks/smi.h>
Felix Helda3a66b62021-02-10 03:29:48 +01008#include <amdblocks/smm.h>
Felix Heldbe35a3a2021-02-10 16:34:31 +01009#include <arch/hlt.h>
10#include <arch/io.h>
11#include <console/console.h>
Felix Held913dcf62021-03-03 19:03:37 +010012#include <cpu/x86/cache.h>
Felix Held3c4fd702021-02-10 03:47:38 +010013#include <cpu/x86/smm.h>
Felix Held3680e022021-03-09 00:08:52 +010014#include <elog.h>
Felix Heldbe35a3a2021-02-10 16:34:31 +010015#include <soc/smi.h>
Felix Held913dcf62021-03-03 19:03:37 +010016#include <soc/smu.h>
17#include <soc/southbridge.h>
Felix Heldbe35a3a2021-02-10 16:34:31 +010018#include <types.h>
19
20static void fch_apmc_smi_handler(void)
21{
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();
Felix Heldbe35a3a2021-02-10 16:34:31 +010027 acpi_enable_sci();
28 break;
29 case APM_CNT_ACPI_DISABLE:
30 acpi_disable_sci();
Felix Heldd51fd302021-02-11 05:02:27 +010031 break;
Felix Held3680e022021-03-09 00:08:52 +010032 case APM_CNT_ELOG_GSMI:
33 if (CONFIG(ELOG_GSMI))
34 handle_smi_gsmi();
35 break;
36 case APM_CNT_SMMSTORE:
37 if (CONFIG(SMMSTORE))
38 handle_smi_store();
39 break;
Felix Heldd51fd302021-02-11 05:02:27 +010040 case APM_CNT_SMMINFO:
41 psp_notify_smm();
42 break;
Felix Heldbe35a3a2021-02-10 16:34:31 +010043 }
44
45 mainboard_smi_apmc(cmd);
46}
47
48static void fch_slp_typ_handler(void)
49{
Felix Held3680e022021-03-09 00:08:52 +010050 uint32_t pci_ctrl, reg32;
51 uint16_t pm1cnt, reg16;
Felix Held913dcf62021-03-03 19:03:37 +010052 uint8_t slp_typ, rst_ctrl;
Felix Heldbe35a3a2021-02-10 16:34:31 +010053
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) {
Felix Held913dcf62021-03-03 19:03:37 +010081 wbinvd();
82
83 clear_all_smi_status();
84
85 /* Do not send SMI before AcpiPm1CntBlkx00[SlpTyp] */
86 pci_ctrl = pm_read32(PM_PCI_CTRL);
87 pci_ctrl &= ~FORCE_SLPSTATE_RETRY;
88 pm_write32(PM_PCI_CTRL, pci_ctrl);
89
90 /* Enable SlpTyp */
91 rst_ctrl = pm_read8(PM_RST_CTRL1);
92 rst_ctrl |= SLPTYPE_CONTROL_EN;
93 pm_write8(PM_RST_CTRL1, rst_ctrl);
94
Felix Held3680e022021-03-09 00:08:52 +010095 /*
96 * Before the final command, check if there's pending wake
97 * event. Read enable first, so that reading the actual status
98 * is as close as possible to entering S3. The idea is to
99 * minimize the opportunity for a wake event to happen before
100 * actually entering S3. If there's a pending wake event, log
101 * it and continue normal path. S3 will fail and the wake event
102 * becomes a SCI.
103 */
104 if (CONFIG(ELOG_GSMI)) {
105 reg16 = acpi_read16(MMIO_ACPI_PM1_EN);
106 reg16 &= acpi_read16(MMIO_ACPI_PM1_STS);
107 if (reg16)
108 elog_add_extended_event(
109 ELOG_SLEEP_PENDING_PM1_WAKE,
110 (u32)reg16);
111
112 reg32 = acpi_read32(MMIO_ACPI_GPE0_EN);
113 reg32 &= acpi_read32(MMIO_ACPI_GPE0_STS);
114 if (reg32)
115 elog_add_extended_event(
116 ELOG_SLEEP_PENDING_GPE0_WAKE,
117 reg32);
118 } /* if (CONFIG(ELOG_GSMI)) */
119
Felix Held913dcf62021-03-03 19:03:37 +0100120 if (slp_typ == ACPI_S3)
121 psp_notify_sx_info(ACPI_S3);
122
123 smu_sx_entry(); /* Leave SlpTypeEn clear, SMU will set */
Julius Wernere9665952022-01-21 17:06:20 -0800124 printk(BIOS_ERR, "System did not go to sleep\n");
Felix Heldbe35a3a2021-02-10 16:34:31 +0100125 hlt();
126 }
127}
Felix Held3c4fd702021-02-10 03:47:38 +0100128
129int southbridge_io_trap_handler(int smif)
130{
131 return 0;
132}
Felix Heldee2a3652021-02-09 23:43:17 +0100133
Felix Heldbe35a3a2021-02-10 16:34:31 +0100134/*
135 * Table of functions supported in the SMI handler. Note that SMI source setup
136 * in fch.c is unrelated to this list.
137 */
138static const struct smi_sources_t smi_sources[] = {
139 { .type = SMITYPE_SMI_CMD_PORT, .handler = fch_apmc_smi_handler },
140 { .type = SMITYPE_SLP_TYP, .handler = fch_slp_typ_handler},
141};
142
Felix Helda3a66b62021-02-10 03:29:48 +0100143void *get_smi_source_handler(int source)
Felix Heldee2a3652021-02-09 23:43:17 +0100144{
Felix Heldbe35a3a2021-02-10 16:34:31 +0100145 size_t i;
146
147 for (i = 0 ; i < ARRAY_SIZE(smi_sources) ; i++)
148 if (smi_sources[i].type == source)
149 return smi_sources[i].handler;
150
Felix Helda3a66b62021-02-10 03:29:48 +0100151 return NULL;
Felix Heldee2a3652021-02-09 23:43:17 +0100152}