Debian Codegraph @

src/soc/amd/cezanne/smihandler.c

raw symbols SCIP
1 /* 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 <amdblocks/smu.h>
10 #include <amdblocks/spi.h>
11 #include <arch/hlt.h>
12 #include <arch/io.h>
13 #include <console/console.h>
14 #include <console/cbmem_console.h>
15 #include <cpu/x86/cache.h>
16 #include <cpu/x86/smm.h>
17 #include <elog.h>
18 #include <psp_verstage/psp_transfer.h>
19 #include <soc/smi.h>
20 #include <soc/smu.h>
21 #include <soc/southbridge.h>
22 #include <types.h>
23
24 /*
25 * Both the psp_notify_sx_info and the smu_sx_entry call will clobber the SMN index register
26 * during the SMN accesses. Since the SMI handler is the last thing that gets called before
27 * entering S3, this won't interfere with any indirect SMN accesses via the same register pair.
28 */
29 static void fch_slp_typ_handler(void)
30 {
31 uint32_t pci_ctrl, reg32;
32 uint16_t pm1cnt, reg16;
33 uint8_t slp_typ, rst_ctrl;
34 struct smu_payload msg = { 0 };
35
36 /* Figure out SLP_TYP */
37 pm1cnt = acpi_read16(MMIO_ACPI_PM1_CNT_BLK);
38 printk(BIOS_SPEW, "SMI#: SLP = 0x%04x\n", pm1cnt);
39 slp_typ = acpi_sleep_from_pm1(pm1cnt);
40
41 /* Do any mainboard sleep handling */
42 mainboard_smi_sleep(slp_typ);
43
44 switch (slp_typ) {
45 case ACPI_S0:
46 printk(BIOS_DEBUG, "SMI#: Entering S0 (On)\n");
47 break;
48 case ACPI_S3:
49 printk(BIOS_DEBUG, "SMI#: Entering S3 (Suspend-To-RAM)\n");
50 break;
51 case ACPI_S4:
52 printk(BIOS_DEBUG, "SMI#: Entering S4 (Suspend-To-Disk)\n");
53 break;
54 case ACPI_S5:
55 printk(BIOS_DEBUG, "SMI#: Entering S5 (Soft Power off)\n");
56 break;
57 default:
58 printk(BIOS_DEBUG, "SMI#: ERROR: SLP_TYP reserved\n");
59 break;
60 }
61
62 if (slp_typ >= ACPI_S3) {
63 wbinvd();
64
65 clear_all_smi_status();
66
67 /* Do not send SMI before AcpiPm1CntBlkx00[SlpTyp] */
68 pci_ctrl = pm_read32(PM_PCI_CTRL);
69 pci_ctrl &= ~FORCE_SLPSTATE_RETRY;
70 pm_write32(PM_PCI_CTRL, pci_ctrl);
71
72 /* Enable SlpTyp */
73 rst_ctrl = pm_read8(PM_RST_CTRL1);
74 rst_ctrl |= SLPTYPE_CONTROL_EN;
75 pm_write8(PM_RST_CTRL1, rst_ctrl);
76
77 /*
78 * Before the final command, check if there's pending wake
79 * event. Read enable first, so that reading the actual status
80 * is as close as possible to entering S3. The idea is to
81 * minimize the opportunity for a wake event to happen before
82 * actually entering S3. If there's a pending wake event, log
83 * it and continue normal path. S3 will fail and the wake event
84 * becomes a SCI.
85 */
86 if (CONFIG(ELOG_GSMI)) {
87 reg16 = acpi_read16(MMIO_ACPI_PM1_EN);
88 reg16 &= acpi_read16(MMIO_ACPI_PM1_STS);
89 if (reg16)
90 elog_add_extended_event(
91 ELOG_SLEEP_PENDING_PM1_WAKE,
92 (u32)reg16);
93
94 reg32 = acpi_read32(MMIO_ACPI_GPE0_EN);
95 reg32 &= acpi_read32(MMIO_ACPI_GPE0_STS);
96 if (reg32)
97 elog_add_extended_event(
98 ELOG_SLEEP_PENDING_GPE0_WAKE,
99 reg32);
100 } /* if (CONFIG(ELOG_GSMI)) */
101
102 if (slp_typ == ACPI_S3) {
103 psp_notify_sx_info(ACPI_S3);
104 send_smu_message(SMC_MSG_USBS3ENTRY, &msg);
105 }
106
107 smu_sx_entry(); /* Leave SlpTypeEn clear, SMU will set */
108 printk(BIOS_ERR, "System did not go to sleep\n");
109 hlt();
110 }
111 }
112
113 /*
114 * Table of functions supported in the SMI handler. Note that SMI source setup
115 * in fch.c is unrelated to this list.
116 */
117 static const struct smi_sources_t smi_sources[] = {
118 { .type = SMITYPE_SMI_CMD_PORT, .handler = fch_apmc_smi_handler },
119 { .type = SMITYPE_SLP_TYP, .handler = fch_slp_typ_handler},
120 { .type = SMITYPE_PSP, .handler = psp_smi_handler },
121 };
122
123 void *get_smi_source_handler(int source)
124 {
125 size_t i;
126
127 for (i = 0 ; i < ARRAY_SIZE(smi_sources) ; i++)
128 if (smi_sources[i].type == source)
129 return smi_sources[i].handler;
130
131 return NULL;
132 }
133
134 void smm_soc_early_init(void)
135 {
136 if (CONFIG(VBOOT_STARTS_BEFORE_BOOTBLOCK) && __CBMEM_CONSOLE_ENABLE__)
137 replay_transfer_buffer_cbmemc();
138
139 if (CONFIG(SPI_FLASH_SMM))
140 fch_spi_backup_registers();
141 }
142
143 void smm_soc_exit(void)
144 {
145 if (CONFIG(SPI_FLASH_SMM))
146 fch_spi_restore_registers();
147 }