blob: a4b61731840f6d43632e05f1cc721202224b72b7 [file] [log] [blame]
Arthur Heymans2e2f1662023-07-14 22:58:49 +02001/* SPDX-License-Identifier: GPL-2.0-or-later */
2
3#include <acpi/acpi.h>
4#include <amdblocks/acpi.h>
5#include <amdblocks/acpimmio.h>
6#include <amdblocks/psp.h>
7#include <amdblocks/smi.h>
8#include <amdblocks/smm.h>
9#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>
Arthur Heymans2e2f1662023-07-14 22:58:49 +020014#include <soc/smi.h>
15#include <soc/smu.h>
16#include <soc/southbridge.h>
17#include <types.h>
18
19/*
20 * Both the psp_notify_sx_info and the smu_sx_entry call will clobber the SMN index register
21 * during the SMN accesses. Since the SMI handler is the last thing that gets called before
22 * entering S3, this won't interfere with any indirect SMN accesses via the same register pair.
23 */
24static void fch_slp_typ_handler(void)
25{
26 uint32_t pci_ctrl;
27 uint16_t pm1cnt;
28 uint8_t slp_typ, rst_ctrl;
29
30 /* Figure out SLP_TYP */
31 pm1cnt = acpi_read16(MMIO_ACPI_PM1_CNT_BLK);
32 printk(BIOS_SPEW, "SMI#: SLP = 0x%04x\n", pm1cnt);
33 slp_typ = acpi_sleep_from_pm1(pm1cnt);
34
35 /* Do any mainboard sleep handling */
36 mainboard_smi_sleep(slp_typ);
37
38 switch (slp_typ) {
39 case ACPI_S0:
40 printk(BIOS_DEBUG, "SMI#: Entering S0 (On)\n");
41 break;
42 case ACPI_S3:
43 printk(BIOS_DEBUG, "SMI#: Entering S3 (Suspend-To-RAM)\n");
44 break;
45 case ACPI_S4:
46 printk(BIOS_DEBUG, "SMI#: Entering S4 (Suspend-To-Disk)\n");
47 break;
48 case ACPI_S5:
49 printk(BIOS_DEBUG, "SMI#: Entering S5 (Soft Power off)\n");
50 break;
51 default:
52 printk(BIOS_DEBUG, "SMI#: ERROR: SLP_TYP reserved\n");
53 break;
54 }
55
56 if (slp_typ >= ACPI_S3) {
57 wbinvd();
58
59 clear_all_smi_status();
60
61 /* Do not send SMI before AcpiPm1CntBlkx00[SlpTyp] */
62 pci_ctrl = pm_read32(PM_PCI_CTRL);
63 pci_ctrl &= ~FORCE_SLPSTATE_RETRY;
64 pm_write32(PM_PCI_CTRL, pci_ctrl);
65
66 /* Enable SlpTyp */
67 rst_ctrl = pm_read8(PM_RST_CTRL1);
68 rst_ctrl |= SLPTYPE_CONTROL_EN;
69 pm_write8(PM_RST_CTRL1, rst_ctrl);
70
71 smu_sx_entry(); /* Leave SlpTypeEn clear, SMU will set */
72 printk(BIOS_ERR, "System did not go to sleep\n");
73 hlt();
74 }
75}
76
77/*
78 * Table of functions supported in the SMI handler. Note that SMI source setup
79 * in fch.c is unrelated to this list.
80 */
81static const struct smi_sources_t smi_sources[] = {
82 { .type = SMITYPE_SMI_CMD_PORT, .handler = fch_apmc_smi_handler },
83 { .type = SMITYPE_SLP_TYP, .handler = fch_slp_typ_handler},
84};
85
86void *get_smi_source_handler(int source)
87{
88 size_t i;
89
90 for (i = 0 ; i < ARRAY_SIZE(smi_sources) ; i++)
91 if (smi_sources[i].type == source)
92 return smi_sources[i].handler;
93
94 return NULL;
95}