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
>
7
#include <
southbridge/intel/bd82x6x/pch.h
>
8
#include <
southbridge/intel/common/pmutil.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
19
enum
sleep_states
{
20
S0
= 0,
21
S1
= 1,
22
S3
= 3,
23
S4
= 4,
24
S5
= 5,
25
};
26
27
enum
ec_smi_event
{
28
EC_SMI_EVENT_IDLE
= 0x80,
29
EC_SMI_BATTERY_LOW
= 0xb3,
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
45
static
uint8_t
ec_get_smi_event
(
void
)
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
75
int
mainboard_smi_apmc
(
u8
data)
76
{
77
switch
(data) {
78
case
APM_CNT_ACPI_ENABLE
:
79
ec_enter_acpi_mode
();
80
gpi_route_interrupt
(
GPE_EC_SCI
,
GPI_IS_SCI
);
81
gpi_route_interrupt
(
GPE_PALMDET1
,
GPI_IS_SCI
);
82
gpi_route_interrupt
(
GPE_PALMDET2
,
GPI_IS_SCI
);
83
break
;
84
case
APM_CNT_ACPI_DISABLE
:
85
ec_enter_apm_mode
();
86
gpi_route_interrupt
(
GPE_EC_SCI
,
GPI_IS_SMI
);
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)
100
gpi_route_interrupt
(
GPE_EC_WAKE
,
GPI_IS_SCI
);
101
}
102
}
printk
#define printk(level,...)
Definition:
stdlib.h:16
console.h
mainboard_smi_sleep
void __weak mainboard_smi_sleep(u8 slp_typ)
Definition:
smihandler.c:210
mainboard_smi_apmc
int __weak mainboard_smi_apmc(u8 data)
Definition:
smihandler.c:209
mainboard_smi_gpi
void __weak mainboard_smi_gpi(u32 gpi_sts)
Definition:
smihandler.c:208
ec_read
u8 ec_read(u8 addr)
Definition:
ec.c:107
ec.h
ec_kbc_read_ob
u8 ec_kbc_read_ob(void)
Definition:
ec.c:71
ec_kbc_write_ib
void ec_kbc_write_ib(u8 data)
Definition:
ec.c:83
ec_kbc_write_cmd
void ec_kbc_write_cmd(u8 cmd)
Definition:
ec.c:77
ec.h
smm.h
APM_CNT_ACPI_DISABLE
#define APM_CNT_ACPI_DISABLE
Definition:
smm.h:21
APM_CNT_ACPI_ENABLE
#define APM_CNT_ACPI_ENABLE
Definition:
smm.h:22
BIOS_DEBUG
#define BIOS_DEBUG
BIOS_DEBUG - Verbose output.
Definition:
loglevel.h:128
ec_smi_event
ec_smi_event
Definition:
smihandler.c:26
EC_SMI_EVENT_IDLE
@ EC_SMI_EVENT_IDLE
Definition:
smihandler.c:27
EC_SMI_BATTERY_LOW
@ EC_SMI_BATTERY_LOW
Definition:
smihandler.c:28
sleep_states
sleep_states
Definition:
smihandler.c:18
S3
@ S3
Definition:
smihandler.c:21
S1
@ S1
Definition:
smihandler.c:20
S5
@ S5
Definition:
smihandler.c:23
S4
@ S4
Definition:
smihandler.c:22
S0
@ S0
Definition:
smihandler.c:19
GPE_PALMDET2
#define GPE_PALMDET2
Definition:
smihandler.c:13
GPE_PALMDET1
#define GPE_PALMDET1
Definition:
smihandler.c:12
ec_enter_apm_mode
static void ec_enter_apm_mode(void)
Definition:
smihandler.c:33
handle_ec_smi
static void handle_ec_smi(void)
Definition:
smihandler.c:61
ec_get_smi_event
static uint8_t ec_get_smi_event(void)
Definition:
smihandler.c:45
GPE_EC_WAKE
#define GPE_EC_WAKE
Definition:
smihandler.c:17
ec_enter_acpi_mode
static void ec_enter_acpi_mode(void)
Definition:
smihandler.c:39
GPE_EC_SMI
#define GPE_EC_SMI
Definition:
smihandler.c:15
GPE_EC_SCI
#define GPE_EC_SCI
Definition:
smihandler.c:14
ec_process_smi
static void ec_process_smi(uint8_t src)
Definition:
smihandler.c:51
GPI_IS_SMI
#define GPI_IS_SMI
Definition:
smihandler.c:34
GPI_IS_SCI
#define GPI_IS_SCI
Definition:
smihandler.c:35
ec.h
pmutil.h
pch.h
gpi_route_interrupt
void gpi_route_interrupt(u8 gpi, u8 mode)
Definition:
smihandler.c:25
u32
uint32_t u32
Definition:
stdint.h:51
u8
uint8_t u8
Definition:
stdint.h:45
uint8_t
unsigned char uint8_t
Definition:
stdint.h:8
src
mainboard
lenovo
s230u
smihandler.c
Generated by
1.9.1