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 <acpi/acpi.h>
4 #include <arch/io.h>
5 #include <console/console.h>
6 #include <cpu/x86/smm.h>
7 #include "ec.h"
8 
10 #include <elog.h>
11 
12 #include <soc/nvs.h>
13 #include <soc/pm.h>
14 #include <soc/gpio.h>
15 
16 #include "onboard.h"
17 
18 /* The wake gpio is SUS_GPIO[0]. */
19 #define WAKE_GPIO_EN SUS_GPIO_EN0
20 
22 {
23  switch (smif) {
24  case 0x99:
25  printk(BIOS_DEBUG, "Sample\n");
26  gnvs->smif = 0;
27  break;
28  default:
29  return 0;
30  }
31 
32  /*
33  * On success, the IO Trap Handler returns 0
34  * On failure, the IO Trap Handler returns a value != 0
35  *
36  * For now, we force the return value to 0 and log all traps to
37  * see what's going on.
38  */
39  //gnvs->smif = 0;
40  return 1;
41 }
42 
44 {
47  uint32_t pm1_cnt;
48 
49  /* Log this event */
50  if (cmd)
52 
53  switch (cmd) {
55  printk(BIOS_DEBUG, "LID CLOSED, SHUTDOWN\n");
56 
57  /* Go to S5 */
58  pm1_cnt = inl(pmbase + PM1_CNT);
59  pm1_cnt |= SLP_EN | (SLP_TYP_S5 << SLP_TYP_SHIFT);
60  outl(pm1_cnt, pmbase + PM1_CNT);
61  break;
62  }
63 
64  return cmd;
65 }
66 
67 /*
68  * The entire 32-bit ALT_GPIO_SMI register is passed as a parameter. Note, that
69  * this includes the enable bits in the lower 16 bits.
70  */
71 void mainboard_smi_gpi(uint32_t alt_gpio_smi)
72 {
73  if (alt_gpio_smi & (1 << EC_SMI_GPI)) {
74  /* Process all pending events */
75  while (mainboard_smi_ec() != 0)
76  ;
77  }
78 }
79 
81 {
82  /* Disable USB charging if required */
83  switch (slp_typ) {
84  case ACPI_S3:
85  if (gnvs->s3u0 == 0)
88  if (gnvs->s3u1 == 0)
91 
92  /* Enable wake events */
94  /* Enable wake pin in GPE block. */
96  break;
97  case ACPI_S5:
98  if (gnvs->s5u0 == 0)
101  if (gnvs->s5u1 == 0)
104 
105  /* Enable wake events */
107  break;
108  }
109 
110  /* Disable SCI and SMI events */
113 
114  /* Clear pending events that may trigger immediate wake */
116  ;
117 
118  /* Set LPC lines to low power in S3/S5. */
119  if ((slp_typ == ACPI_S3) || (slp_typ == ACPI_S5))
121 }
122 
124 {
125  switch (apmc) {
126  case APM_CNT_ACPI_ENABLE:
128  /* Clear all pending events */
130  ;
132  break;
135  /* Clear all pending events */
137  ;
139  break;
140  }
141  return 0;
142 }
#define PM1_CNT
Definition: pm.h:27
void enable_gpe(uint32_t mask)
Definition: pmutil.c:194
#define ELOG_TYPE_EC_EVENT
Definition: elog.h:90
#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
int __weak mainboard_io_trap_handler(int smif)
Definition: smihandler.c:206
u32 inl(u16 port)
void outl(u32 val, u16 port)
int google_chromeec_set_wake_mask(uint64_t mask)
Definition: ec.c:1131
int google_chromeec_set_smi_mask(uint64_t mask)
Definition: ec.c:1125
int google_chromeec_set_usb_charge_mode(uint8_t port_id, enum usb_charge_mode mode)
Definition: ec.c:1143
int google_chromeec_set_sci_mask(uint64_t mask)
Definition: ec.c:1119
enum host_event_code google_chromeec_get_event(void)
Definition: ec_i2c.c:242
@ EC_HOST_EVENT_NONE
Definition: ec_commands.h:654
@ EC_HOST_EVENT_LID_CLOSED
Definition: ec_commands.h:655
@ USB_CHARGE_MODE_DISABLED
Definition: ec_commands.h:3240
@ ACPI_S5
Definition: acpi.h:1385
@ ACPI_S3
Definition: acpi.h:1383
#define APM_CNT_ACPI_DISABLE
Definition: smm.h:21
#define APM_CNT_ACPI_ENABLE
Definition: smm.h:22
static int elog_gsmi_add_event_byte(u8 event_type, u8 data)
Definition: elog.h:46
#define SLP_EN
Definition: pmc.h:62
#define SLP_TYP_S5
Definition: pmc.h:69
#define SLP_TYP_SHIFT
Definition: pmc.h:63
#define BIOS_DEBUG
BIOS_DEBUG - Verbose output.
Definition: loglevel.h:128
#define MAINBOARD_EC_S5_WAKE_EVENTS
Definition: ec.h:32
#define MAINBOARD_EC_SCI_EVENTS
Definition: ec.h:12
#define MAINBOARD_EC_SMI_EVENTS
Definition: ec.h:28
#define EC_SMI_GPI
Definition: ec.h:10
#define MAINBOARD_EC_S3_WAKE_EVENTS
Definition: ec.h:37
static uint8_t mainboard_smi_ec(void)
Definition: smihandler.c:43
#define WAKE_GPIO_EN
Definition: smihandler.c:19
struct global_nvs * gnvs
void lpc_set_low_power(void)
Definition: lpc_init.c:82
u16 get_pmbase(void)
Definition: smihandler.c:20
u16 pmbase
Definition: smihandler.c:25
unsigned short uint16_t
Definition: stdint.h:11
unsigned int uint32_t
Definition: stdint.h:14
unsigned char uint8_t
Definition: stdint.h:8
u8 s5u1
Definition: nvs.h:33
u8 s3u0
Definition: nvs.h:34
u8 s3u1
Definition: nvs.h:35
u8 s5u0
Definition: nvs.h:32
u8 smif
Definition: nvs.h:11