payloads/edk2: Disable the CPU Timer Lib unless supported
[coreboot.git] / src / mainboard / lenovo / g505s / smihandler.c
blobfa81b280ee42c56aae75dce6af19ec38476634b9
1 /* SPDX-License-Identifier: GPL-2.0-or-later */
3 /*
4 * SMI handler -- mostly takes care of SMIs from the EC
5 */
7 #include <arch/io.h>
8 #include <console/console.h>
9 #include <cpu/x86/smm.h>
10 #include <ec/compal/ene932/ec.h>
11 #include <southbridge/amd/agesa/hudson/hudson.h>
12 #include <southbridge/amd/agesa/hudson/smi.h>
14 #include "ec.h"
16 #define ACPI_PM1_CNT_SLEEP(state) ((1 << 13) | (state & 0x7) << 10)
18 enum sleep_states {
19 S0 = 0,
20 S1 = 1,
21 S3 = 3,
22 S4 = 4,
23 S5 = 5,
26 enum ec_smi_event {
27 EC_SMI_EVENT_IDLE = 0x80,
28 EC_SMI_BATTERY_LOW = 0xb3,
31 /* Tell EC to operate in APM mode. Events generate SMIs instead of SCIs */
32 static void ec_enter_apm_mode(void)
34 ec_kbc_write_cmd(0x59);
35 ec_kbc_write_ib(0xE9);
37 /* Tell EC to operate in ACPI mode, thus generating SCIs on events, not SMIs */
38 static void ec_enter_acpi_mode(void)
40 ec_kbc_write_cmd(0x59);
41 ec_kbc_write_ib(0xE8);
44 static uint8_t ec_get_smi_event(void)
46 ec_kbc_write_cmd(0x56);
47 return ec_kbc_read_ob();
50 static void ec_process_smi(uint8_t src)
52 /* Reading the SMI source satisfies the EC in terms of responding to
53 * the event, regardless of whether we take an action or not.
56 switch (src) {
57 case EC_SMI_BATTERY_LOW:
58 printk(BIOS_DEBUG, "Battery low. Shutting down\n");
59 outl(ACPI_PM1_CNT_SLEEP(S5), ACPI_PM1_CNT_BLK);
60 break;
61 default:
62 printk(BIOS_DEBUG, "EC_SMI event 0x%x\n", src);
66 static void handle_ec_smi(void)
68 uint8_t src;
70 while ((src = ec_get_smi_event()) != EC_SMI_EVENT_IDLE)
71 ec_process_smi(src);
74 static void handle_lid_smi(void)
76 /* Only triggered in non-ACPI mode on lid close. */
77 outl(ACPI_PM1_CNT_SLEEP(S4), ACPI_PM1_CNT_BLK);
80 int mainboard_smi_apmc(uint8_t data)
82 switch (data) {
83 case ACPI_SMI_CMD_ENABLE:
84 printk(BIOS_DEBUG, "Enable ACPI mode\n");
85 ec_enter_acpi_mode();
86 hudson_disable_gevent_smi(EC_LID_GEVENT);
87 break;
88 case ACPI_SMI_CMD_DISABLE:
89 printk(BIOS_DEBUG, "Disable ACPI mode\n");
90 ec_enter_apm_mode();
91 hudson_configure_gevent_smi(EC_LID_GEVENT, SMI_MODE_SMI,
92 SMI_LVL_LOW);
93 break;
94 default:
95 printk(BIOS_DEBUG, "Unhandled ACPI command: 0x%x\n", data);
97 return 0;
100 void mainboard_smi_gpi(uint32_t gpi_sts)
102 if (gpi_sts & (1 << EC_SMI_GEVENT))
103 handle_ec_smi();
104 if (gpi_sts & (1 << EC_LID_GEVENT))
105 handle_lid_smi();