libpayload: configs: Add new config.featuretest to broaden CI
[coreboot.git] / src / mainboard / lenovo / haswell / smihandler.c
blobde48240e8807238de9d184046a120f55006dff38
1 /* SPDX-License-Identifier: GPL-2.0-only */
3 #include <arch/io.h>
4 #include <device/pci_ops.h>
5 #include <console/console.h>
6 #include <cpu/x86/smm.h>
7 #include <ec/acpi/ec.h>
8 #include <ec/lenovo/h8/h8.h>
9 #include <southbridge/intel/lynxpoint/pch.h>
11 #define GPE_EC_SCI 1
12 #define GPE_EC_WAKE 13
14 static void mainboard_smi_handle_ec_sci(void)
16 u8 status = inb(EC_SC);
17 u8 event;
19 if (!(status & EC_SCI_EVT))
20 return;
22 event = ec_query();
23 printk(BIOS_DEBUG, "EC event %#02x\n", event);
26 void mainboard_smi_gpi(u32 gpi_sts)
28 if (gpi_sts & (1 << GPE_EC_SCI))
29 mainboard_smi_handle_ec_sci();
32 /* lynxpoint doesn't have gpi_route_interrupt, so add it */
33 #define GPI_DISABLE 0x00
34 #define GPI_IS_SMI 0x01
35 #define GPI_IS_SCI 0x02
36 #define GPI_IS_NMI 0x03
38 static void gpi_route_interrupt(u8 gpi, u8 mode)
40 u32 gpi_rout;
42 gpi_rout = pci_read_config32(PCI_DEV(0, 0x1f, 0), GPIO_ROUT);
43 gpi_rout &= ~(3 << (2 * gpi));
44 gpi_rout |= ((mode & 3) << (2 * gpi));
45 pci_write_config32(PCI_DEV(0, 0x1f, 0), GPIO_ROUT, gpi_rout);
48 int mainboard_smi_apmc(u8 data)
50 switch (data) {
51 case APM_CNT_ACPI_ENABLE:
52 /* use 0x1600/0x1604 to prevent races with userspace */
53 ec_set_ports(0x1604, 0x1600);
54 /* route EC_SCI to SCI */
55 gpi_route_interrupt(GPE_EC_SCI, GPI_IS_SCI);
56 /* discard all events, and enable attention */
57 ec_write(0x80, 0x01);
58 break;
59 case APM_CNT_ACPI_DISABLE:
60 /* we have to use port 0x62/0x66, as 0x1600/0x1604 doesn't
61 provide a EC query function */
62 ec_set_ports(0x66, 0x62);
63 /* route EC_SCI to SMI */
64 gpi_route_interrupt(GPE_EC_SCI, GPI_IS_SMI);
65 /* discard all events, and enable attention */
66 ec_write(0x80, 0x01);
67 break;
68 default:
69 break;
71 return 0;
74 void mainboard_smi_sleep(u8 slp_typ)
76 if (slp_typ == 3) {
77 u8 ec_wake = ec_read(0x32);
78 /* If EC wake events are enabled,
79 * enable wake on EC WAKE GPE. */
80 if (ec_wake & 0x14) {
81 /* Redirect EC WAKE GPE to SCI. */
82 gpi_route_interrupt(GPE_EC_WAKE, GPI_IS_SCI);