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-only */
2 
3 #include <console/console.h>
4 #include <cpu/x86/smm.h>
5 #include <ec/acpi/ec.h>
6 #include <ec/compal/ene932/ec.h>
9 
10 #include "ec.h"
11 
12 #define GPE_PALMDET1 2
13 #define GPE_PALMDET2 4
14 #define GPE_EC_SCI 7
15 #define GPE_EC_SMI 8
16 /* FIXME: check this */
17 #define GPE_EC_WAKE 13
18 
20  S0 = 0,
21  S1 = 1,
22  S3 = 3,
23  S4 = 4,
24  S5 = 5,
25 };
26 
30 };
31 
32 /* Tell EC to operate in APM mode. Events generate SMIs instead of SCIs. */
33 static void ec_enter_apm_mode(void)
34 {
35  ec_kbc_write_cmd(0x59);
36  ec_kbc_write_ib(0xE9);
37 }
38 /* Tell EC to operate in ACPI mode, thus generating SCIs on events, not SMIs. */
39 static void ec_enter_acpi_mode(void)
40 {
41  ec_kbc_write_cmd(0x59);
42  ec_kbc_write_ib(0xE8);
43 }
44 
46 {
47  ec_kbc_write_cmd(0x56);
48  return ec_kbc_read_ob();
49 }
50 
51 static void ec_process_smi(uint8_t src)
52 {
53  /*
54  * Reading the SMI source satisfies the EC in terms of responding to
55  * the event, regardless of whether we take an action or not.
56  */
57 
58  printk(BIOS_DEBUG, "Unhandled EC_SMI event 0x%x\n", src);
59 }
60 
61 static void handle_ec_smi(void)
62 {
63  uint8_t src;
64 
65  while ((src = ec_get_smi_event()) != EC_SMI_EVENT_IDLE)
66  ec_process_smi(src);
67 }
68 
69 void mainboard_smi_gpi(u32 gpi_sts)
70 {
71  if (gpi_sts & (1 << GPE_EC_SMI))
72  handle_ec_smi();
73 }
74 
76 {
77  switch (data) {
83  break;
87  break;
88  default:
89  printk(BIOS_DEBUG, "Unhandled ACPI command: 0x%x\n", data);
90  }
91  return 0;
92 }
93 
94 void mainboard_smi_sleep(u8 slp_typ)
95 {
96  if (slp_typ == S3) {
97  u8 ec_wake = ec_read(0x32);
98  /* If EC wake events are enabled, enable wake on EC WAKE GPE. */
99  if (ec_wake & 0x14)
101  }
102 }
#define printk(level,...)
Definition: stdlib.h:16
void __weak mainboard_smi_sleep(u8 slp_typ)
Definition: smihandler.c:210
int __weak mainboard_smi_apmc(u8 data)
Definition: smihandler.c:209
void __weak mainboard_smi_gpi(u32 gpi_sts)
Definition: smihandler.c:208
u8 ec_read(u8 addr)
Definition: ec.c:107
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 APM_CNT_ACPI_DISABLE
Definition: smm.h:21
#define APM_CNT_ACPI_ENABLE
Definition: smm.h:22
#define BIOS_DEBUG
BIOS_DEBUG - Verbose output.
Definition: loglevel.h:128
ec_smi_event
Definition: smihandler.c:26
@ EC_SMI_EVENT_IDLE
Definition: smihandler.c:27
@ EC_SMI_BATTERY_LOW
Definition: smihandler.c:28
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
#define GPE_PALMDET2
Definition: smihandler.c:13
#define GPE_PALMDET1
Definition: smihandler.c:12
static void ec_enter_apm_mode(void)
Definition: smihandler.c:33
static void handle_ec_smi(void)
Definition: smihandler.c:61
static uint8_t ec_get_smi_event(void)
Definition: smihandler.c:45
#define GPE_EC_WAKE
Definition: smihandler.c:17
static void ec_enter_acpi_mode(void)
Definition: smihandler.c:39
#define GPE_EC_SMI
Definition: smihandler.c:15
#define GPE_EC_SCI
Definition: smihandler.c:14
static void ec_process_smi(uint8_t src)
Definition: smihandler.c:51
#define GPI_IS_SMI
Definition: smihandler.c:34
#define GPI_IS_SCI
Definition: smihandler.c:35
void gpi_route_interrupt(u8 gpi, u8 mode)
Definition: smihandler.c:25
uint32_t u32
Definition: stdint.h:51
uint8_t u8
Definition: stdint.h:45
unsigned char uint8_t
Definition: stdint.h:8