Debian Codegraph @

src/soc/amd/mendocino/smihandler.c

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