coreboot
coreboot is an Open Source project aimed at replacing the proprietary BIOS found in most computers.
espi_util.c File Reference
#include <amdblocks/chip.h>
#include <amdblocks/espi.h>
#include <amdblocks/lpc.h>
#include <arch/mmio.h>
#include <console/console.h>
#include <espi.h>
#include <soc/pci_devs.h>
#include <timer.h>
#include <types.h>
#include "espi_def.h"
Include dependency graph for espi_util.c:

Go to the source code of this file.

Data Structures

union  espi_txhdr0
 
union  espi_txhdr1
 
union  espi_txhdr2
 
union  espi_txdata
 
struct  espi_cmd
 

Macros

#define ESPI_CMD_TIMEOUT_US   100
 
#define ESPI_CH_READY_TIMEOUT_US   10000
 
#define ESPI_CONFIGURATION_HDATA0(a)   (((a) >> 8) & 0xff)
 
#define ESPI_CONFIGURATION_HDATA1(a)   ((a) & 0xff)
 

Enumerations

enum  espi_cmd_type {
  CMD_TYPE_SET_CONFIGURATION = 0 , CMD_TYPE_GET_CONFIGURATION = 1 , CMD_TYPE_IN_BAND_RESET = 2 , CMD_TYPE_PERIPHERAL = 4 ,
  CMD_TYPE_VW = 5 , CMD_TYPE_OOB = 6 , CMD_TYPE_FLASH = 7
}
 

Functions

void espi_update_static_bar (uintptr_t bar)
 
__weak void mb_set_up_early_espi (void)
 
static uintptr_t espi_get_bar (void)
 
static uint32_t espi_read32 (unsigned int reg)
 
static void espi_write32 (unsigned int reg, uint32_t val)
 
static uint16_t espi_read16 (unsigned int reg)
 
static void espi_write16 (unsigned int reg, uint16_t val)
 
static uint8_t espi_read8 (unsigned int reg)
 
static void espi_write8 (unsigned int reg, uint8_t val)
 
static uint32_t espi_decode_io_range_en_bit (unsigned int idx)
 
static uint32_t espi_decode_mmio_range_en_bit (unsigned int idx)
 
static unsigned int espi_io_range_base_reg (unsigned int idx)
 
static unsigned int espi_io_range_size_reg (unsigned int idx)
 
static unsigned int espi_mmio_range_base_reg (unsigned int idx)
 
static unsigned int espi_mmio_range_size_reg (unsigned int idx)
 
static void espi_enable_decode (uint32_t decode_en)
 
static bool espi_is_decode_enabled (uint32_t decode)
 
static int espi_find_io_window (uint16_t win_base)
 
static int espi_get_unused_io_window (void)
 
static void espi_clear_decodes (void)
 
static int espi_std_io_decode (uint16_t base, size_t size)
 
static size_t espi_get_io_window_size (int idx)
 
static void espi_write_io_window (int idx, uint16_t base, size_t size)
 
static enum cb_err espi_open_generic_io_window (uint16_t base, size_t size)
 
enum cb_err espi_open_io_window (uint16_t base, size_t size)
 
static int espi_find_mmio_window (uint32_t win_base)
 
static int espi_get_unused_mmio_window (void)
 
static size_t espi_get_mmio_window_size (int idx)
 
static void espi_write_mmio_window (int idx, uint32_t base, size_t size)
 
enum cb_err espi_open_mmio_window (uint32_t base, size_t size)
 
static const struct espi_configespi_get_config (void)
 
static enum cb_err espi_configure_decodes (const struct espi_config *cfg)
 
static enum cb_err espi_wait_ready (void)
 
static void espi_clear_status (void)
 
static enum cb_err espi_poll_status (uint32_t *status)
 
static void espi_show_failure (const struct espi_cmd *cmd, const char *str, uint32_t status)
 
static enum cb_err espi_send_command (const struct espi_cmd *cmd)
 
static enum cb_err espi_send_reset (void)
 
static enum cb_err espi_send_pltrst (const struct espi_config *mb_cfg, bool assert)
 
static enum cb_err espi_get_configuration (uint16_t slave_reg_addr, uint32_t *config)
 
static enum cb_err espi_set_configuration (uint16_t slave_reg_addr, uint32_t config)
 
static enum cb_err espi_get_general_configuration (uint32_t *config)
 
static void espi_set_io_mode_config (enum espi_io_mode mb_io_mode, uint32_t slave_caps, uint32_t *slave_config, uint32_t *ctrlr_config)
 
static void espi_set_op_freq_config (enum espi_op_freq mb_op_freq, uint32_t slave_caps, uint32_t *slave_config, uint32_t *ctrlr_config)
 
static void espi_set_alert_pin_config (enum espi_alert_pin alert_pin, uint32_t slave_caps, uint32_t *slave_config, uint32_t *ctrlr_config)
 
static enum cb_err espi_set_general_configuration (const struct espi_config *mb_cfg, uint32_t slave_caps)
 
static enum cb_err espi_wait_channel_ready (uint16_t slave_reg_addr)
 
static void espi_enable_ctrlr_channel (uint32_t channel_en)
 
static enum cb_err espi_set_channel_configuration (uint32_t slave_config, uint32_t slave_reg_addr, uint32_t ctrlr_enable)
 
static enum cb_err espi_setup_vw_channel (const struct espi_config *mb_cfg, uint32_t slave_caps)
 
static enum cb_err espi_setup_periph_channel (const struct espi_config *mb_cfg, uint32_t slave_caps)
 
static enum cb_err espi_setup_oob_channel (const struct espi_config *mb_cfg, uint32_t slave_caps)
 
static enum cb_err espi_setup_flash_channel (const struct espi_config *mb_cfg, uint32_t slave_caps)
 
static void espi_set_initial_config (const struct espi_config *mb_cfg)
 
static void espi_setup_subtractive_decode (const struct espi_config *mb_cfg)
 
enum cb_err espi_setup (void)
 
void configure_espi_with_mb_hook (void)
 

Variables

static uintptr_t espi_bar
 
union espi_txhdr0 __packed
 

Macro Definition Documentation

◆ ESPI_CH_READY_TIMEOUT_US

#define ESPI_CH_READY_TIMEOUT_US   10000

Definition at line 364 of file espi_util.c.

◆ ESPI_CMD_TIMEOUT_US

#define ESPI_CMD_TIMEOUT_US   100

Definition at line 363 of file espi_util.c.

◆ ESPI_CONFIGURATION_HDATA0

#define ESPI_CONFIGURATION_HDATA0 (   a)    (((a) >> 8) & 0xff)

Definition at line 581 of file espi_util.c.

◆ ESPI_CONFIGURATION_HDATA1

#define ESPI_CONFIGURATION_HDATA1 (   a)    ((a) & 0xff)

Definition at line 582 of file espi_util.c.

Enumeration Type Documentation

◆ espi_cmd_type

Enumerator
CMD_TYPE_SET_CONFIGURATION 
CMD_TYPE_GET_CONFIGURATION 
CMD_TYPE_IN_BAND_RESET 
CMD_TYPE_PERIPHERAL 
CMD_TYPE_VW 
CMD_TYPE_OOB 
CMD_TYPE_FLASH 

Definition at line 353 of file espi_util.c.

Function Documentation

◆ configure_espi_with_mb_hook()

void configure_espi_with_mb_hook ( void  )

Definition at line 1052 of file espi_util.c.

References espi_setup(), and mb_set_up_early_espi().

Referenced by fch_pre_init().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ espi_clear_decodes()

◆ espi_clear_status()

static void espi_clear_status ( void  )
static

Definition at line 432 of file espi_util.c.

References espi_read32(), ESPI_SLAVE0_INT_STS, and espi_write32().

Here is the call graph for this function:

◆ espi_configure_decodes()

static enum cb_err espi_configure_decodes ( const struct espi_config cfg)
static

Definition at line 326 of file espi_util.c.

References die(), soc_amd_common_config::espi_config, and soc_get_common_config().

Here is the call graph for this function:

◆ espi_decode_io_range_en_bit()

static uint32_t espi_decode_io_range_en_bit ( unsigned int  idx)
inlinestatic

Definition at line 63 of file espi_util.c.

References ESPI_DECODE_IO_RANGE_EN.

Referenced by espi_find_io_window(), and espi_get_unused_io_window().

Here is the caller graph for this function:

◆ espi_decode_mmio_range_en_bit()

static uint32_t espi_decode_mmio_range_en_bit ( unsigned int  idx)
inlinestatic

Definition at line 68 of file espi_util.c.

References ESPI_DECODE_MMIO_RANGE_EN.

Referenced by espi_find_mmio_window(), and espi_get_unused_mmio_window().

Here is the caller graph for this function:

◆ espi_enable_ctrlr_channel()

static void espi_enable_ctrlr_channel ( uint32_t  channel_en)
static

Definition at line 773 of file espi_util.c.

References espi_read32(), ESPI_SLAVE0_CONFIG, and espi_write32().

Here is the call graph for this function:

◆ espi_enable_decode()

static void espi_enable_decode ( uint32_t  decode_en)
static

Definition at line 93 of file espi_util.c.

References ESPI_DECODE, espi_read32(), espi_write32(), and val.

Here is the call graph for this function:

◆ espi_find_io_window()

static int espi_find_io_window ( uint16_t  win_base)
static

Definition at line 110 of file espi_util.c.

References espi_decode_io_range_en_bit(), ESPI_GENERIC_IO_WIN_COUNT, espi_io_range_base_reg(), espi_is_decode_enabled(), and espi_read16().

Here is the call graph for this function:

◆ espi_find_mmio_window()

static int espi_find_mmio_window ( uint32_t  win_base)
static

Definition at line 247 of file espi_util.c.

References espi_decode_mmio_range_en_bit(), ESPI_GENERIC_MMIO_WIN_COUNT, espi_is_decode_enabled(), espi_mmio_range_base_reg(), and espi_read32().

Here is the call graph for this function:

◆ espi_get_bar()

static uintptr_t espi_get_bar ( void  )
static

Definition at line 26 of file espi_util.c.

References ENV_X86, espi_bar, ESPI_OFFSET_FROM_BAR, espi_update_static_bar(), and lpc_get_spibase().

Referenced by espi_read16(), espi_read32(), espi_read8(), espi_write16(), espi_write32(), and espi_write8().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ espi_get_config()

static const struct espi_config* espi_get_config ( void  )
static

Definition at line 326 of file espi_util.c.

◆ espi_get_configuration()

static enum cb_err espi_get_configuration ( uint16_t  slave_reg_addr,
uint32_t config 
)
static

◆ espi_get_general_configuration()

static enum cb_err espi_get_general_configuration ( uint32_t config)
static

Definition at line 459 of file espi_util.c.

◆ espi_get_io_window_size()

static size_t espi_get_io_window_size ( int  idx)
static

Definition at line 183 of file espi_util.c.

References espi_io_range_size_reg(), and espi_read8().

Here is the call graph for this function:

◆ espi_get_mmio_window_size()

static size_t espi_get_mmio_window_size ( int  idx)
static

Definition at line 275 of file espi_util.c.

References espi_mmio_range_size_reg(), and espi_read16().

Here is the call graph for this function:

◆ espi_get_unused_io_window()

static int espi_get_unused_io_window ( void  )
static

Definition at line 125 of file espi_util.c.

References espi_decode_io_range_en_bit(), ESPI_GENERIC_IO_WIN_COUNT, and espi_is_decode_enabled().

Here is the call graph for this function:

◆ espi_get_unused_mmio_window()

static int espi_get_unused_mmio_window ( void  )
static

Definition at line 262 of file espi_util.c.

References espi_decode_mmio_range_en_bit(), ESPI_GENERIC_MMIO_WIN_COUNT, and espi_is_decode_enabled().

Here is the call graph for this function:

◆ espi_io_range_base_reg()

static unsigned int espi_io_range_base_reg ( unsigned int  idx)
inlinestatic

Definition at line 73 of file espi_util.c.

References ESPI_IO_RANGE_BASE.

Referenced by espi_clear_decodes(), espi_find_io_window(), and espi_open_generic_io_window().

Here is the caller graph for this function:

◆ espi_io_range_size_reg()

static unsigned int espi_io_range_size_reg ( unsigned int  idx)
inlinestatic

Definition at line 78 of file espi_util.c.

References ESPI_IO_RANGE_SIZE.

Referenced by espi_clear_decodes(), espi_get_io_window_size(), and espi_open_generic_io_window().

Here is the caller graph for this function:

◆ espi_is_decode_enabled()

static bool espi_is_decode_enabled ( uint32_t  decode)
static

Definition at line 102 of file espi_util.c.

References ESPI_DECODE, espi_read32(), and val.

Referenced by espi_find_io_window(), espi_find_mmio_window(), espi_get_unused_io_window(), and espi_get_unused_mmio_window().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ espi_mmio_range_base_reg()

static unsigned int espi_mmio_range_base_reg ( unsigned int  idx)
inlinestatic

Definition at line 83 of file espi_util.c.

References ESPI_MMIO_RANGE_BASE.

Referenced by espi_clear_decodes(), espi_find_mmio_window(), and espi_open_mmio_window().

Here is the caller graph for this function:

◆ espi_mmio_range_size_reg()

static unsigned int espi_mmio_range_size_reg ( unsigned int  idx)
inlinestatic

Definition at line 88 of file espi_util.c.

References ESPI_MMIO_RANGE_SIZE.

Referenced by espi_clear_decodes(), espi_get_mmio_window_size(), and espi_open_mmio_window().

Here is the caller graph for this function:

◆ espi_open_generic_io_window()

static enum cb_err espi_open_generic_io_window ( uint16_t  base,
size_t  size 
)
static

Definition at line 188 of file espi_util.c.

References base, espi_io_range_base_reg(), espi_io_range_size_reg(), espi_write16(), and espi_write8().

Here is the call graph for this function:

◆ espi_open_io_window()

enum cb_err espi_open_io_window ( uint16_t  base,
size_t  size 
)

Definition at line 188 of file espi_util.c.

Referenced by configure_child_espi_windows().

Here is the caller graph for this function:

◆ espi_open_mmio_window()

enum cb_err espi_open_mmio_window ( uint32_t  base,
size_t  size 
)

Definition at line 280 of file espi_util.c.

References base, espi_mmio_range_base_reg(), espi_mmio_range_size_reg(), espi_write16(), and espi_write32().

Referenced by configure_child_espi_windows().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ espi_poll_status()

static enum cb_err espi_poll_status ( uint32_t status)
static

Definition at line 432 of file espi_util.c.

◆ espi_read16()

static uint16_t espi_read16 ( unsigned int  reg)
static

Definition at line 43 of file espi_util.c.

References espi_get_bar(), and read16().

Referenced by espi_clear_decodes(), espi_find_io_window(), and espi_get_mmio_window_size().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ espi_read32()

static uint32_t espi_read32 ( unsigned int  reg)
static

Definition at line 33 of file espi_util.c.

References espi_get_bar(), and read32().

Referenced by espi_clear_status(), espi_enable_ctrlr_channel(), espi_enable_decode(), espi_find_mmio_window(), espi_is_decode_enabled(), and espi_setup().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ espi_read8()

static uint8_t espi_read8 ( unsigned int  reg)
static

Definition at line 53 of file espi_util.c.

References espi_get_bar(), and read8().

Referenced by espi_get_io_window_size().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ espi_send_command()

static enum cb_err espi_send_command ( const struct espi_cmd cmd)
static

Definition at line 459 of file espi_util.c.

◆ espi_send_pltrst()

static enum cb_err espi_send_pltrst ( const struct espi_config mb_cfg,
bool  assert 
)
static

Definition at line 459 of file espi_util.c.

◆ espi_send_reset()

static enum cb_err espi_send_reset ( void  )
static

Definition at line 459 of file espi_util.c.

◆ espi_set_alert_pin_config()

static void espi_set_alert_pin_config ( enum espi_alert_pin  alert_pin,
uint32_t  slave_caps,
uint32_t slave_config,
uint32_t ctrlr_config 
)
static

◆ espi_set_channel_configuration()

static enum cb_err espi_set_channel_configuration ( uint32_t  slave_config,
uint32_t  slave_reg_addr,
uint32_t  ctrlr_enable 
)
static

Definition at line 773 of file espi_util.c.

◆ espi_set_configuration()

static enum cb_err espi_set_configuration ( uint16_t  slave_reg_addr,
uint32_t  config 
)
static

Definition at line 459 of file espi_util.c.

◆ espi_set_general_configuration()

static enum cb_err espi_set_general_configuration ( const struct espi_config mb_cfg,
uint32_t  slave_caps 
)
static

Definition at line 703 of file espi_util.c.

◆ espi_set_initial_config()

static void espi_set_initial_config ( const struct espi_config mb_cfg)
static

◆ espi_set_io_mode_config()

static void espi_set_io_mode_config ( enum espi_io_mode  mb_io_mode,
uint32_t  slave_caps,
uint32_t slave_config,
uint32_t ctrlr_config 
)
static

◆ espi_set_op_freq_config()

static void espi_set_op_freq_config ( enum espi_op_freq  mb_op_freq,
uint32_t  slave_caps,
uint32_t slave_config,
uint32_t ctrlr_config 
)
static

◆ espi_setup()

enum cb_err espi_setup ( void  )

Definition at line 922 of file espi_util.c.

References ESPI_GLOBAL_CONTROL_1, espi_read32(), ESPI_SUB_DECODE_EN, ESPI_SUB_DECODE_SLV_MASK, and espi_write32().

Referenced by configure_espi_with_mb_hook(), and verstage_soc_espi_init().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ espi_setup_flash_channel()

static enum cb_err espi_setup_flash_channel ( const struct espi_config mb_cfg,
uint32_t  slave_caps 
)
static

Definition at line 773 of file espi_util.c.

◆ espi_setup_oob_channel()

static enum cb_err espi_setup_oob_channel ( const struct espi_config mb_cfg,
uint32_t  slave_caps 
)
static

Definition at line 773 of file espi_util.c.

◆ espi_setup_periph_channel()

static enum cb_err espi_setup_periph_channel ( const struct espi_config mb_cfg,
uint32_t  slave_caps 
)
static

Definition at line 773 of file espi_util.c.

◆ espi_setup_subtractive_decode()

static void espi_setup_subtractive_decode ( const struct espi_config mb_cfg)
static

Definition at line 922 of file espi_util.c.

◆ espi_setup_vw_channel()

static enum cb_err espi_setup_vw_channel ( const struct espi_config mb_cfg,
uint32_t  slave_caps 
)
static

Definition at line 773 of file espi_util.c.

◆ espi_show_failure()

static void espi_show_failure ( const struct espi_cmd cmd,
const char *  str,
uint32_t  status 
)
static

Definition at line 459 of file espi_util.c.

◆ espi_std_io_decode()

static int espi_std_io_decode ( uint16_t  base,
size_t  size 
)
static

◆ espi_update_static_bar()

void espi_update_static_bar ( uintptr_t  bar)

Definition at line 17 of file espi_util.c.

References espi_bar.

Referenced by espi_get_bar(), and espi_set_bar().

Here is the caller graph for this function:

◆ espi_wait_channel_ready()

static enum cb_err espi_wait_channel_ready ( uint16_t  slave_reg_addr)
static

Definition at line 703 of file espi_util.c.

◆ espi_wait_ready()

static enum cb_err espi_wait_ready ( void  )
static

Definition at line 326 of file espi_util.c.

◆ espi_write16()

static void espi_write16 ( unsigned int  reg,
uint16_t  val 
)
static

Definition at line 48 of file espi_util.c.

References espi_get_bar(), val, and write16().

Referenced by espi_clear_decodes(), espi_open_generic_io_window(), and espi_open_mmio_window().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ espi_write32()

static void espi_write32 ( unsigned int  reg,
uint32_t  val 
)
static

Definition at line 38 of file espi_util.c.

References espi_get_bar(), val, and write32().

Referenced by espi_clear_decodes(), espi_clear_status(), espi_enable_ctrlr_channel(), espi_enable_decode(), espi_open_mmio_window(), espi_set_initial_config(), and espi_setup().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ espi_write8()

static void espi_write8 ( unsigned int  reg,
uint8_t  val 
)
static

Definition at line 58 of file espi_util.c.

References espi_get_bar(), val, and write8().

Referenced by espi_clear_decodes(), and espi_open_generic_io_window().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ espi_write_io_window()

static void espi_write_io_window ( int  idx,
uint16_t  base,
size_t  size 
)
static

Definition at line 188 of file espi_util.c.

◆ espi_write_mmio_window()

static void espi_write_mmio_window ( int  idx,
uint32_t  base,
size_t  size 
)
static

Definition at line 280 of file espi_util.c.

◆ mb_set_up_early_espi()

__weak void mb_set_up_early_espi ( void  )

Definition at line 22 of file espi_util.c.

Referenced by configure_espi_with_mb_hook().

Here is the caller graph for this function:

Variable Documentation

◆ __packed

◆ espi_bar

uintptr_t espi_bar
static

Definition at line 15 of file espi_util.c.

Referenced by espi_get_bar(), and espi_update_static_bar().