coreboot
coreboot is an Open Source project aimed at replacing the proprietary BIOS found in most computers.
smihandler.c
Go to the documentation of this file.
1 /* SPDX-License-Identifier: GPL-2.0-or-later */
2 
3 /*
4  * SMI handler -- mostly takes care of SMIs from the EC
5  */
6 
7 #include <arch/io.h>
8 #include <console/console.h>
9 #include <cpu/x86/smm.h>
10 #include <ec/compal/ene932/ec.h>
13 
14 #include "ec.h"
15 
16 #define ACPI_PM1_CNT_SLEEP(state) ((1 << 13) | (state & 0x7) << 10)
17 
19  S0 = 0,
20  S1 = 1,
21  S3 = 3,
22  S4 = 4,
23  S5 = 5,
24 };
25 
29 };
30 
31 /* Tell EC to operate in APM mode. Events generate SMIs instead of SCIs */
32 static void ec_enter_apm_mode(void)
33 {
34  ec_kbc_write_cmd(0x59);
35  ec_kbc_write_ib(0xE9);
36 }
37 /* Tell EC to operate in ACPI mode, thus generating SCIs on events, not SMIs */
38 static void ec_enter_acpi_mode(void)
39 {
40  ec_kbc_write_cmd(0x59);
41  ec_kbc_write_ib(0xE8);
42 }
43 
45 {
46  ec_kbc_write_cmd(0x56);
47  return ec_kbc_read_ob();
48 }
49 
50 static void ec_process_smi(uint8_t src)
51 {
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.
54  */
55 
56  switch (src) {
57  case EC_SMI_BATTERY_LOW:
58  printk(BIOS_DEBUG, "Battery low. Shutting down\n");
60  break;
61  default:
62  printk(BIOS_DEBUG, "EC_SMI event 0x%x\n", src);
63  }
64 }
65 
66 static void handle_ec_smi(void)
67 {
68  uint8_t src;
69 
70  while ((src = ec_get_smi_event()) != EC_SMI_EVENT_IDLE)
71  ec_process_smi(src);
72 }
73 
74 static void handle_lid_smi(void)
75 {
76  /* Only triggered in non-ACPI mode on lid close. */
78 }
79 
81 {
82  switch (data) {
84  printk(BIOS_DEBUG, "Enable ACPI mode\n");
87  break;
89  printk(BIOS_DEBUG, "Disable ACPI mode\n");
92  SMI_LVL_LOW);
93  break;
94  default:
95  printk(BIOS_DEBUG, "Unhandled ACPI command: 0x%x\n", data);
96  }
97  return 0;
98 }
99 
101 {
102  if (gpi_sts & (1 << EC_SMI_GEVENT))
103  handle_ec_smi();
104  if (gpi_sts & (1 << EC_LID_GEVENT))
105  handle_lid_smi();
106 }
#define ACPI_SMI_CMD_ENABLE
Definition: hudson.h:29
#define ACPI_SMI_CMD_DISABLE
Definition: hudson.h:28
#define ACPI_PM1_CNT_BLK
Definition: iomap.h:43
#define printk(level,...)
Definition: stdlib.h:16
int __weak mainboard_smi_apmc(u8 data)
Definition: smihandler.c:209
void __weak mainboard_smi_gpi(u32 gpi_sts)
Definition: smihandler.c:208
void outl(u32 val, u16 port)
u8 ec_kbc_read_ob(void)
Definition: ec.c:71
void ec_kbc_write_ib(u8 data)
Definition: ec.c:83
void ec_kbc_write_cmd(u8 cmd)
Definition: ec.c:77
#define EC_SMI_GEVENT
Definition: mainboard.h:13
#define EC_LID_GEVENT
Definition: mainboard.h:12
#define BIOS_DEBUG
BIOS_DEBUG - Verbose output.
Definition: loglevel.h:128
static void handle_lid_smi(void)
Definition: smihandler.c:74
#define ACPI_PM1_CNT_SLEEP(state)
Definition: smihandler.c:16
ec_smi_event
Definition: smihandler.c:26
@ EC_SMI_EVENT_IDLE
Definition: smihandler.c:27
@ EC_SMI_BATTERY_LOW
Definition: smihandler.c:28
static void ec_enter_apm_mode(void)
Definition: smihandler.c:32
static void handle_ec_smi(void)
Definition: smihandler.c:66
sleep_states
Definition: smihandler.c:18
@ S3
Definition: smihandler.c:21
@ S1
Definition: smihandler.c:20
@ S5
Definition: smihandler.c:23
@ S4
Definition: smihandler.c:22
@ S0
Definition: smihandler.c:19
static uint8_t ec_get_smi_event(void)
Definition: smihandler.c:44
static void ec_enter_acpi_mode(void)
Definition: smihandler.c:38
static void ec_process_smi(uint8_t src)
Definition: smihandler.c:50
@ SMI_MODE_SMI
Definition: smi.h:10
void hudson_disable_gevent_smi(uint8_t gevent)
Disable events from given GEVENT pin.
Definition: smi_util.c:63
void hudson_configure_gevent_smi(uint8_t gevent, uint8_t mode, uint8_t level)
Configure generation of interrupts for given GEVENT pin.
Definition: smi_util.c:43
@ SMI_LVL_LOW
Definition: smi.h:32
unsigned int uint32_t
Definition: stdint.h:14
unsigned char uint8_t
Definition: stdint.h:8