Debian Codegraph @

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