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 <device/pci_ops.h>
4 #include <console/console.h>
5 #include <cpu/x86/smm.h>
6 #include <soc/nvs.h>
11 
12 /* Include EC functions */
13 #include <ec/quanta/it8518/ec.h>
14 #include "ec.h"
15 
16 static u8 mainboard_smi_ec(void)
17 {
18  u8 cmd = ec_it8518_get_event();
19 
20  switch (cmd) {
21  case EC_SMI_LID_CLOSED:
22  printk(BIOS_DEBUG, "LID CLOSED, SHUTDOWN\n");
23  /* Go to S5 */
25  break;
26  }
27 
28  return cmd;
29 }
30 
31 void mainboard_smi_gpi(u32 gpi_sts)
32 {
33  if (gpi_sts & (1 << EC_SMI_GPI)) {
34  /* Process all pending events */
35  while (mainboard_smi_ec() != 0);
36  }
37 }
38 
39 void mainboard_smi_sleep(u8 slp_typ)
40 {
41  /*
42  * Tell the EC to Enable USB power for S3 if requested.
43  * Bit0 of 0x0D/Bit0 of 0x26
44  * 0/0 All USB port off
45  * 1/0 USB on, all USB port didn't support wake up
46  * 0/1 USB on, yellow port support wake up charge, but may not support
47  * charge smart phone.
48  * 1/1 USB on, yellow port in AUTO mode and didn't support wake up system.
49  */
50  if (gnvs->s3u0 != 0 || gnvs->s3u1 != 0) {
53  printk(BIOS_DEBUG, "USB wake from S3 enabled.\n");
54  } else {
55  /*
56  * If USB charging in suspend is disabled then also disable
57  * the XHCI PME to prevent wake when the port power is cut
58  * after the transition into suspend.
59  */
60  if (gnvs->xhci) {
61  u32 reg32 = pci_read_config32(PCH_XHCI_DEV, 0x74);
62  reg32 &= ~(1 << 8); /* disable PME */
63  reg32 |= (1 << 15); /* clear PME status */
64  pci_write_config32(PCH_XHCI_DEV, 0x74, reg32);
65  }
66  }
67 
70 }
71 
73 {
74  switch (apmc) {
75  case APM_CNT_FINALIZE:
77  break;
79  /*
80  * TODO(kimarie) Clear all pending events and enable SCI.
81  */
83  break;
85  /*
86  * TODO(kimarie) Clear all pending events and enable SMI.
87  */
89  break;
90  }
91  return 0;
92 }
#define PM1_CNT
Definition: pm.h:27
#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
int ec_write(u8 addr, u8 data)
Definition: ec.c:115
void ec_kbc_write_cmd(u8 cmd)
Definition: ec.c:77
void ec_write_cmd(u8 cmd)
Definition: ec.c:79
u8 ec_it8518_get_event(void)
Definition: ec.c:109
void ec_it8518_enable_wake_events(void)
Definition: ec.c:123
#define EC_USB_S3_EN
Definition: ec.h:51
#define EC_KBD_CMD_MUTE
Definition: ec.h:27
#define EC_CMD_NOTIFY_ACPI_EXIT
Definition: ec.h:46
#define EC_PERIPH_CNTL_3
Definition: ec.h:50
#define EC_CMD_NOTIFY_ACPI_ENTER
Definition: ec.h:45
#define APM_CNT_ACPI_DISABLE
Definition: smm.h:21
#define APM_CNT_ACPI_ENABLE
Definition: smm.h:22
#define APM_CNT_FINALIZE
Definition: smm.h:24
static __always_inline void pci_write_config32(const struct device *dev, u16 reg, u32 val)
Definition: pci_ops.h:76
static __always_inline u32 pci_read_config32(const struct device *dev, u16 reg)
Definition: pci_ops.h:58
#define BIOS_DEBUG
BIOS_DEBUG - Verbose output.
Definition: loglevel.h:128
#define EC_SMI_GPI
Definition: ec.h:10
void stout_ec_finalize_smm(void)
Definition: ec.c:41
#define EC_SMI_LID_CLOSED
Definition: ec.h:9
static u8 mainboard_smi_ec(void)
Definition: smihandler.c:16
u32 read_pmbase32(const u8 addr)
Definition: pmbase.c:57
void write_pmbase32(const u8 addr, const u32 val)
Definition: pmbase.c:36
struct global_nvs * gnvs
#define PCH_XHCI_DEV
Definition: pch.h:88
uint32_t u32
Definition: stdint.h:51
uint8_t u8
Definition: stdint.h:45
u8 s3u0
Definition: nvs.h:34
u8 s3u1
Definition: nvs.h:35
u8 xhci
Definition: nvs.h:99