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-or-later */
2 
3 #include <baseboard/gpio.h>
4 #include <baseboard/variants.h>
5 #include <console/console.h>
6 #include <cpu/x86/smm.h>
9 #include <elog.h>
10 #include <gpio.h>
11 #include <intelblocks/gpio.h>
12 #include <intelblocks/smihandler.h>
13 #include <spi_flash.h>
14 #include <variant/ec.h>
15 
16 void mainboard_smi_gpi_handler(const struct gpi_status *sts)
17 {
18  /* TODO: Process SMI events from GPI */
19 }
20 
21 void mainboard_smi_sleep(u8 slp_typ)
22 {
23  const struct pad_config *pads;
24  size_t num;
25 
26  pads = variant_sleep_gpio_table(&num);
27  gpio_configure_pads(pads, num);
28 
29  variant_smi_sleep(slp_typ);
30 
33 }
34 
36 {
39  return 0;
40 }
41 
43 {
45 }
46 
48 {
50 }
51 
53 {
54 }
55 
56 static void mainboard_config_cbi_wp(void)
57 {
58  int hw_wp = gpio_get(GPIO_PCH_WP);
59  const struct spi_flash *spi_flash_dev = boot_device_spi_flash();
60  uint8_t sr1;
61  int rv;
62 
63  /*
64  * The CBI EEPROM WP should mirror our software write protect status if
65  * hardware write protect is set. If software write protect status is
66  * set at all via status register 1, that should be a sufficient signal.
67  * If the hardware WP is not set, or software write protect is not set
68  * while hardware write protect is set, deassert the CBI EEPROM WP.
69  *
70  * HW WP | SW WP | CBI WP
71  * ------|-------|-------
72  * 0 | X | 0
73  * 1 | 0 | 0
74  * 1 | 1 | 1
75  */
76  if (spi_flash_status(spi_flash_dev, &sr1) < 0) {
77  printk(BIOS_ERR, "MB: Failed to read SPI status register 1\n");
78  printk(BIOS_ERR, "MB: CBI EEPROM WP cannot change!");
79  return;
80  }
81 
82  /*
83  * Note that we are assuming that the Status Register protect bits are
84  * are located at this index and that 1 means hardware protected. This
85  * should be the case for these boards.
86  */
87  const bool is_wp = !!(sr1 & 0x80) && hw_wp;
88  printk(BIOS_INFO, "MB: SPI flash is %swrite protected\n",
89  is_wp ? "" : "not ");
90 
91  /* Inverted because the signal is active low. */
92  gpio_set(GPP_B16, !is_wp);
93 
94  /* Lock the configuration down. */
96  if (rv)
97  printk(BIOS_ERR, "MB: Failed to lock CBI WP (rv=%d)\n",
98  rv);
99 }
100 
102 {
103  if (CONFIG(BOARD_GOOGLE_BASEBOARD_DEDEDE_TPM2))
105 }
#define GPP_B16
Definition: gpio_soc_defs.h:69
const struct spi_flash * boot_device_spi_flash(void)
#define printk(level,...)
Definition: stdlib.h:16
void __weak mainboard_smi_finalize(void)
Definition: smihandler.c:211
void __weak mainboard_smi_sleep(u8 slp_typ)
Definition: smihandler.c:210
int __weak mainboard_smi_apmc(u8 data)
Definition: smihandler.c:209
@ CONFIG
Definition: dsi_common.h:201
void google_chromeec_log_events(uint64_t mask)
Definition: ec.c:386
void chromeec_smi_sleep(int slp_type, uint64_t s3_mask, uint64_t s5_mask)
Definition: smihandler.c:48
void chromeec_smi_process_events(void)
Definition: smihandler.c:29
void chromeec_smi_apmc(int apmc, uint64_t sci_mask, uint64_t smi_mask)
Definition: smihandler.c:89
int gpio_get(gpio_t gpio)
Definition: gpio.c:166
void gpio_set(gpio_t gpio, int value)
Definition: gpio.c:174
#define BIOS_INFO
BIOS_INFO - Expected events.
Definition: loglevel.h:113
#define BIOS_ERR
BIOS_ERR - System in incomplete state.
Definition: loglevel.h:72
#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 MAINBOARD_EC_LOG_EVENTS
Definition: ec.h:42
#define MAINBOARD_EC_S3_WAKE_EVENTS
Definition: ec.h:37
void mainboard_smi_espi_handler(void)
Definition: smihandler.c:26
void elog_gsmi_cb_mainboard_log_wake_source(void)
Definition: smihandler.c:21
#define MAINBOARD_EC_S0IX_WAKE_EVENTS
Definition: ec.h:25
#define GPIO_PCH_WP
Definition: gpio.h:14
static void mainboard_config_cbi_wp(void)
Definition: smihandler.c:56
void mainboard_smi_gpi_handler(const struct gpi_status *sts)
Definition: smihandler.c:16
void __weak variant_smi_sleep(u8 slp_typ)
Definition: smihandler.c:52
const struct pad_config *__weak variant_sleep_gpio_table(size_t *num)
Definition: gpio.c:466
const struct smm_save_state_ops *legacy_ops __weak
Definition: save_state.c:8
void gpio_configure_pads(const struct soc_amd_gpio *gpio_list_ptr, size_t size)
program a particular set of GPIO
Definition: gpio.c:307
int gpio_lock_pad(const gpio_t pad, enum gpio_lock_action lock_action)
Definition: gpio.c:618
@ GPIO_LOCK_FULL
Definition: gpio.h:72
int spi_flash_status(const struct spi_flash *flash, u8 *reg)
Definition: spi_flash.c:568
uint8_t u8
Definition: stdint.h:45
unsigned char uint8_t
Definition: stdint.h:8