blob: 80dbb7be0103255247ef2bcb376a88650a52fb4c [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>
6#include <amdblocks/smi.h>
Felix Helda3a66b62021-02-10 03:29:48 +01007#include <amdblocks/smm.h>
Felix Heldbe35a3a2021-02-10 16:34:31 +01008#include <arch/hlt.h>
9#include <arch/io.h>
10#include <console/console.h>
Felix Held3c4fd702021-02-10 03:47:38 +010011#include <cpu/x86/smm.h>
Felix Heldbe35a3a2021-02-10 16:34:31 +010012#include <soc/smi.h>
13#include <types.h>
14
15static void fch_apmc_smi_handler(void)
16{
17 const uint8_t cmd = inb(pm_acpi_smi_cmd_port());
18
19 switch (cmd) {
20 case APM_CNT_ACPI_ENABLE:
21 acpi_enable_sci();
22 break;
23 case APM_CNT_ACPI_DISABLE:
24 acpi_disable_sci();
25 }
26
27 mainboard_smi_apmc(cmd);
28}
29
30static void fch_slp_typ_handler(void)
31{
32 uint16_t pm1cnt;
33 uint8_t slp_typ;
34
35 /* Figure out SLP_TYP */
36 pm1cnt = acpi_read16(MMIO_ACPI_PM1_CNT_BLK);
37 printk(BIOS_SPEW, "SMI#: SLP = 0x%04x\n", pm1cnt);
38 slp_typ = acpi_sleep_from_pm1(pm1cnt);
39
40 /* Do any mainboard sleep handling */
41 mainboard_smi_sleep(slp_typ);
42
43 switch (slp_typ) {
44 case ACPI_S0:
45 printk(BIOS_DEBUG, "SMI#: Entering S0 (On)\n");
46 break;
47 case ACPI_S3:
48 printk(BIOS_DEBUG, "SMI#: Entering S3 (Suspend-To-RAM)\n");
49 break;
50 case ACPI_S4:
51 printk(BIOS_DEBUG, "SMI#: Entering S4 (Suspend-To-Disk)\n");
52 break;
53 case ACPI_S5:
54 printk(BIOS_DEBUG, "SMI#: Entering S5 (Soft Power off)\n");
55 break;
56 default:
57 printk(BIOS_DEBUG, "SMI#: ERROR: SLP_TYP reserved\n");
58 break;
59 }
60
61 if (slp_typ >= ACPI_S3) {
62 printk(BIOS_ERR, "Error: System did not go to sleep\n");
63 hlt();
64 }
65}
Felix Held3c4fd702021-02-10 03:47:38 +010066
67int southbridge_io_trap_handler(int smif)
68{
69 return 0;
70}
Felix Heldee2a3652021-02-09 23:43:17 +010071
Felix Heldbe35a3a2021-02-10 16:34:31 +010072/*
73 * Table of functions supported in the SMI handler. Note that SMI source setup
74 * in fch.c is unrelated to this list.
75 */
76static const struct smi_sources_t smi_sources[] = {
77 { .type = SMITYPE_SMI_CMD_PORT, .handler = fch_apmc_smi_handler },
78 { .type = SMITYPE_SLP_TYP, .handler = fch_slp_typ_handler},
79};
80
Felix Helda3a66b62021-02-10 03:29:48 +010081void *get_smi_source_handler(int source)
Felix Heldee2a3652021-02-09 23:43:17 +010082{
Felix Heldbe35a3a2021-02-10 16:34:31 +010083 size_t i;
84
85 for (i = 0 ; i < ARRAY_SIZE(smi_sources) ; i++)
86 if (smi_sources[i].type == source)
87 return smi_sources[i].handler;
88
Felix Helda3a66b62021-02-10 03:29:48 +010089 return NULL;
Felix Heldee2a3652021-02-09 23:43:17 +010090}