blob: c3d2fbfc34afc9c3108feeeb31c2be0c92e034fb [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 Held3c4fd702021-02-10 03:47:38 +010012#include <cpu/x86/smm.h>
Felix Heldbe35a3a2021-02-10 16:34:31 +010013#include <soc/smi.h>
14#include <types.h>
15
16static void fch_apmc_smi_handler(void)
17{
18 const uint8_t cmd = inb(pm_acpi_smi_cmd_port());
19
20 switch (cmd) {
21 case APM_CNT_ACPI_ENABLE:
22 acpi_enable_sci();
23 break;
24 case APM_CNT_ACPI_DISABLE:
25 acpi_disable_sci();
Felix Heldd51fd302021-02-11 05:02:27 +010026 break;
27 case APM_CNT_SMMINFO:
28 psp_notify_smm();
29 break;
Felix Heldbe35a3a2021-02-10 16:34:31 +010030 }
31
32 mainboard_smi_apmc(cmd);
33}
34
35static void fch_slp_typ_handler(void)
36{
37 uint16_t pm1cnt;
38 uint8_t slp_typ;
39
40 /* Figure out SLP_TYP */
41 pm1cnt = acpi_read16(MMIO_ACPI_PM1_CNT_BLK);
42 printk(BIOS_SPEW, "SMI#: SLP = 0x%04x\n", pm1cnt);
43 slp_typ = acpi_sleep_from_pm1(pm1cnt);
44
45 /* Do any mainboard sleep handling */
46 mainboard_smi_sleep(slp_typ);
47
48 switch (slp_typ) {
49 case ACPI_S0:
50 printk(BIOS_DEBUG, "SMI#: Entering S0 (On)\n");
51 break;
52 case ACPI_S3:
53 printk(BIOS_DEBUG, "SMI#: Entering S3 (Suspend-To-RAM)\n");
54 break;
55 case ACPI_S4:
56 printk(BIOS_DEBUG, "SMI#: Entering S4 (Suspend-To-Disk)\n");
57 break;
58 case ACPI_S5:
59 printk(BIOS_DEBUG, "SMI#: Entering S5 (Soft Power off)\n");
60 break;
61 default:
62 printk(BIOS_DEBUG, "SMI#: ERROR: SLP_TYP reserved\n");
63 break;
64 }
65
66 if (slp_typ >= ACPI_S3) {
67 printk(BIOS_ERR, "Error: System did not go to sleep\n");
68 hlt();
69 }
70}
Felix Held3c4fd702021-02-10 03:47:38 +010071
72int southbridge_io_trap_handler(int smif)
73{
74 return 0;
75}
Felix Heldee2a3652021-02-09 23:43:17 +010076
Felix Heldbe35a3a2021-02-10 16:34:31 +010077/*
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
Felix Helda3a66b62021-02-10 03:29:48 +010086void *get_smi_source_handler(int source)
Felix Heldee2a3652021-02-09 23:43:17 +010087{
Felix Heldbe35a3a2021-02-10 16:34:31 +010088 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
Felix Helda3a66b62021-02-10 03:29:48 +010094 return NULL;
Felix Heldee2a3652021-02-09 23:43:17 +010095}