coreboot
coreboot is an Open Source project aimed at replacing the proprietary BIOS found in most computers.
espi.h
Go to the documentation of this file.
1 /* SPDX-License-Identifier: GPL-2.0-only */
2 
3 #ifndef AMD_BLOCK_ESPI_H
4 #define AMD_BLOCK_ESPI_H
5 
6 #include <types.h>
7 
8 /* eSPI MMIO base lives at an offset of 0x10000 from the address in SPI BAR. */
9 #define ESPI_OFFSET_FROM_BAR 0x10000
10 
11 #define ESPI_DECODE 0x40
12 #define ESPI_DECODE_MMIO_RANGE_EN(range) (1 << (((range) & 3) + 12))
13 #define ESPI_DECODE_IO_RANGE_EN(range) (1 << (((range) & 3) + 8))
14 #define ESPI_DECODE_IO_0x80_EN (1 << 2)
15 #define ESPI_DECODE_IO_0X60_0X64_EN (1 << 1)
16 #define ESPI_DECODE_IO_0X2E_0X2F_EN (1 << 0)
17 
18 #define ESPI_IO_BASE_REG0 0x44
19 #define ESPI_IO_BASE_REG1 0x48
20 #define ESPI_IO_SIZE0 0x4c
21 #define ESPI_MMIO_BASE_REG0 0x50
22 #define ESPI_MMIO_BASE_REG1 0x54
23 #define ESPI_MMIO_BASE_REG2 0x58
24 #define ESPI_MMIO_BASE_REG3 0x5c
25 #define ESPI_MMIO_SIZE_REG0 0x60
26 #define ESPI_MMIO_SIZE_REG1 0x64
27 
28 #define ESPI_IO_RANGE_BASE(range) (ESPI_IO_BASE_REG0 + ((range) & 3) * 2)
29 #define ESPI_IO_RANGE_SIZE(range) (ESPI_IO_SIZE0 + ((range) & 3))
30 #define ESPI_MMIO_RANGE_BASE(range) (ESPI_MMIO_BASE_REG0 + ((range) & 3) * 4)
31 #define ESPI_MMIO_RANGE_SIZE(range) (ESPI_MMIO_SIZE_REG0 + ((range) & 3) * 2)
32 
33 #define ESPI_GENERIC_IO_WIN_COUNT 4
34 #define ESPI_GENERIC_IO_MAX_WIN_SIZE 0x100
35 #define ESPI_GENERIC_MMIO_WIN_COUNT 4
36 #define ESPI_GENERIC_MMIO_MAX_WIN_SIZE 0x10000
37 
38 #define ESPI_SLAVE0_CONFIG 0x68
39 #define ESPI_CRC_CHECKING_EN (1 << 31)
40 #define ESPI_ALERT_MODE (1 << 30)
41 
42 #define ESPI_IO_MODE_SHIFT 28
43 #define ESPI_IO_MODE_MASK (0x3 << ESPI_IO_MODE_SHIFT)
44 #define ESPI_IO_MODE_VALUE(x) ((x) << ESPI_IO_MODE_SHIFT)
45 
46 #define ESPI_OP_FREQ_SHIFT 25
47 #define ESPI_OP_FREQ_MASK (0x7 << ESPI_OP_FREQ_SHIFT)
48 #define ESPI_OP_FREQ_VALUE(x) ((x) << ESPI_OP_FREQ_SHIFT)
49 
50 #define ESPI_PERIPH_CH_EN (1 << 3)
51 #define ESPI_VW_CH_EN (1 << 2)
52 #define ESPI_OOB_CH_EN (1 << 1)
53 #define ESPI_FLASH_CH_EN (1 << 0)
54 
55 /* Virtual wire interrupt polarity. eSPI interrupts are active level high signals. The
56  polarity register inverts the incoming signal if the associated bit with the irq is
57  0. */
58 #define ESPI_VW_IRQ_LEVEL_HIGH(x) (1 << (x))
59 #define ESPI_VW_IRQ_LEVEL_LOW(x) (0 << (x))
60 #define ESPI_VW_IRQ_EDGE_HIGH(x) (1 << (x))
61 #define ESPI_VW_IRQ_EDGE_LOW(x) (0 << (x))
62 
67 };
68 
73 };
74 
79 };
80 
81 struct espi_config {
82  /* Bitmap for standard IO decodes. Use ESPI_DECODE_IO_* above. */
84 
85  struct {
87  size_t size;
89 
90  /* Slave configuration parameters */
91  enum espi_io_mode io_mode;
94 
101 
102  /* Use ESPI_VW_IRQ_* above */
104 };
105 
106 /*
107  * Open I/O window using the provided base and size.
108  */
109 enum cb_err espi_open_io_window(uint16_t base, size_t size);
110 
111 /*
112  * Open MMIO window using the provided base and size.
113  */
114 enum cb_err espi_open_mmio_window(uint32_t base, size_t size);
115 
116 /*
117  * In cases where eSPI BAR is statically provided by SoC, use that BAR instead of reading
118  * SPIBASE. This is required for cases where verstage runs on PSP.
119  */
121 
122 /*
123  * Perform eSPI connection setup to the slave. Currently, this supports slave0 only.
124  */
125 enum cb_err espi_setup(void);
126 
127 /* Run mainboard configuration needed to set up eSPI */
128 void mb_set_up_early_espi(void);
129 
130 /* Setup eSPI with any mainboard specific initialization. */
131 void configure_espi_with_mb_hook(void);
132 
133 #endif /* AMD_BLOCK_ESPI_H */
cb_err
coreboot error codes
Definition: cb_err.h:15
uintptr_t base
Definition: uart.c:17
enum cb_err espi_open_io_window(uint16_t base, size_t size)
Definition: espi_util.c:234
espi_io_mode
Definition: espi.h:63
@ ESPI_IO_MODE_DUAL
Definition: espi.h:65
@ ESPI_IO_MODE_SINGLE
Definition: espi.h:64
@ ESPI_IO_MODE_QUAD
Definition: espi.h:66
espi_op_freq
Definition: espi.h:69
@ ESPI_OP_FREQ_33_MHZ
Definition: espi.h:71
@ ESPI_OP_FREQ_16_MHZ
Definition: espi.h:70
@ ESPI_OP_FREQ_66_MHZ
Definition: espi.h:72
void mb_set_up_early_espi(void)
Definition: bootblock.c:15
void espi_update_static_bar(uintptr_t bar)
Definition: espi_util.c:17
#define ESPI_GENERIC_IO_WIN_COUNT
Definition: espi.h:33
enum cb_err espi_open_mmio_window(uint32_t base, size_t size)
Definition: espi_util.c:286
void configure_espi_with_mb_hook(void)
Definition: espi_util.c:1052
#define ESPI_OP_FREQ_VALUE(x)
Definition: espi.h:48
enum cb_err espi_setup(void)
Definition: espi_util.c:937
espi_alert_pin
Definition: espi.h:75
@ ESPI_ALERT_PIN_PUSH_PULL
Definition: espi.h:77
@ ESPI_ALERT_PIN_IN_BAND
Definition: espi.h:76
@ ESPI_ALERT_PIN_OPEN_DRAIN
Definition: espi.h:78
#define ESPI_IO_MODE_VALUE(x)
Definition: espi.h:44
unsigned short uint16_t
Definition: stdint.h:11
unsigned int uint32_t
Definition: stdint.h:14
unsigned long uintptr_t
Definition: stdint.h:21
uint32_t std_io_decode_bitmap
Definition: espi.h:83
struct espi_config::@401 generic_io_range[ESPI_GENERIC_IO_WIN_COUNT]
uint16_t base
Definition: espi.h:86
uint32_t vw_ch_en
Definition: espi.h:97
uint32_t flash_ch_en
Definition: espi.h:99
uint32_t periph_ch_en
Definition: espi.h:96
enum espi_alert_pin alert_pin
Definition: espi.h:93
uint32_t crc_check_enable
Definition: espi.h:95
uint32_t oob_ch_en
Definition: espi.h:98
uint32_t vw_irq_polarity
Definition: espi.h:103
uint32_t subtractive_decode
Definition: espi.h:100
enum espi_op_freq op_freq_mhz
Definition: espi.h:92
enum espi_io_mode io_mode
Definition: espi.h:91
size_t size
Definition: espi.h:87