coreboot
coreboot is an Open Source project aimed at replacing the proprietary BIOS found in most computers.
fast_spi_flash.c File Reference
#include <device/mmio.h>
#include <commonlib/helpers.h>
#include <console/console.h>
#include <fast_spi_def.h>
#include <intelblocks/fast_spi.h>
#include <soc/pci_devs.h>
#include <spi_flash.h>
#include <string.h>
#include <timer.h>
Include dependency graph for fast_spi_flash.c:

Go to the source code of this file.

Data Structures

struct  fast_spi_flash_ctx
 

Macros

#define BOILERPLATE_CREATE_CTX(ctx)
 
#define SPI_FPR_SHIFT   12
 
#define SPI_FPR_MASK   0x7fff
 
#define SPI_FPR_BASE_SHIFT   0
 
#define SPI_FPR_LIMIT_SHIFT   16
 
#define SPI_FPR_RPE   (1 << 15) /* Read Protect */
 
#define SPI_FPR_WPE   (1 << 31) /* Write Protect */
 
#define SPI_FPR(base, limit)
 

Enumerations

enum  errors { SUCCESS = 0 , E_TIMEOUT = -1 , E_HW_ERROR = -2 , E_ARGUMENT = -3 }
 

Functions

static void _fast_spi_flash_get_ctx (struct fast_spi_flash_ctx *ctx)
 
static uint32_t fast_spi_flash_ctrlr_reg_read (struct fast_spi_flash_ctx *ctx, uint16_t reg)
 
static void fast_spi_flash_ctrlr_reg_write (struct fast_spi_flash_ctx *ctx, uint16_t reg, uint32_t val)
 
static uint32_t fast_spi_flash_read_sfdp_param (struct fast_spi_flash_ctx *ctx, uint16_t sfdp_reg)
 
static void fill_xfer_fifo (struct fast_spi_flash_ctx *ctx, const void *data, size_t len)
 
static void drain_xfer_fifo (struct fast_spi_flash_ctx *ctx, void *dest, size_t len)
 
static void start_hwseq_xfer (struct fast_spi_flash_ctx *ctx, uint32_t hsfsts_cycle, uint32_t flash_addr, size_t len)
 
static int wait_for_hwseq_xfer (struct fast_spi_flash_ctx *ctx, uint32_t flash_addr)
 
static int wait_for_hwseq_spi_cycle_complete (struct fast_spi_flash_ctx *ctx)
 
static int exec_sync_hwseq_xfer (struct fast_spi_flash_ctx *ctx, uint32_t hsfsts_cycle, uint32_t flash_addr, size_t len)
 
int fast_spi_cycle_in_progress (void)
 
static size_t get_xfer_len (const struct spi_flash *flash, uint32_t addr, size_t len)
 
static int fast_spi_flash_erase (const struct spi_flash *flash, uint32_t offset, size_t len)
 
static int fast_spi_flash_read (const struct spi_flash *flash, uint32_t addr, size_t len, void *buf)
 
static int fast_spi_flash_write (const struct spi_flash *flash, uint32_t addr, size_t len, const void *buf)
 
static int fast_spi_flash_status (const struct spi_flash *flash, uint8_t *reg)
 
static int fast_spi_flash_probe (const struct spi_slave *dev, struct spi_flash *flash)
 
static int fast_spi_flash_ctrlr_setup (const struct spi_slave *dev)
 
static int fast_spi_flash_protect (const struct spi_flash *flash, const struct region *region, const enum ctrlr_prot_type type)
 

Variables

const struct spi_flash_ops fast_spi_flash_ops
 
const struct spi_ctrlr fast_spi_flash_ctrlr
 

Macro Definition Documentation

◆ BOILERPLATE_CREATE_CTX

#define BOILERPLATE_CREATE_CTX (   ctx)
Value:
struct fast_spi_flash_ctx real_ctx; \
struct fast_spi_flash_ctx *ctx = &real_ctx; \
_fast_spi_flash_get_ctx(ctx)

Definition at line 14 of file fast_spi_flash.c.

◆ SPI_FPR

#define SPI_FPR (   base,
  limit 
)
Value:
#define SPI_FPR_LIMIT_SHIFT
#define SPI_FPR_BASE_SHIFT
#define SPI_FPR_MASK
#define SPI_FPR_SHIFT
uintptr_t base
Definition: uart.c:17

Definition at line 357 of file fast_spi_flash.c.

◆ SPI_FPR_BASE_SHIFT

#define SPI_FPR_BASE_SHIFT   0

Definition at line 353 of file fast_spi_flash.c.

◆ SPI_FPR_LIMIT_SHIFT

#define SPI_FPR_LIMIT_SHIFT   16

Definition at line 354 of file fast_spi_flash.c.

◆ SPI_FPR_MASK

#define SPI_FPR_MASK   0x7fff

Definition at line 352 of file fast_spi_flash.c.

◆ SPI_FPR_RPE

#define SPI_FPR_RPE   (1 << 15) /* Read Protect */

Definition at line 355 of file fast_spi_flash.c.

◆ SPI_FPR_SHIFT

#define SPI_FPR_SHIFT   12

Definition at line 351 of file fast_spi_flash.c.

◆ SPI_FPR_WPE

#define SPI_FPR_WPE   (1 << 31) /* Write Protect */

Definition at line 356 of file fast_spi_flash.c.

Enumeration Type Documentation

◆ errors

enum errors
Enumerator
SUCCESS 
E_TIMEOUT 
E_HW_ERROR 
E_ARGUMENT 

Definition at line 23 of file fast_spi_flash.c.

Function Documentation

◆ _fast_spi_flash_get_ctx()

static void _fast_spi_flash_get_ctx ( struct fast_spi_flash_ctx ctx)
static

Definition at line 35 of file fast_spi_flash.c.

References fast_spi_get_bar(), and fast_spi_flash_ctx::mmio_base.

Here is the call graph for this function:

◆ drain_xfer_fifo()

static void drain_xfer_fifo ( struct fast_spi_flash_ctx ctx,
void dest,
size_t  len 
)
static

Definition at line 85 of file fast_spi_flash.c.

References memcpy(), fast_spi_flash_ctx::mmio_base, and SPIBAR_FDATA.

Referenced by fast_spi_flash_read().

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

◆ exec_sync_hwseq_xfer()

static int exec_sync_hwseq_xfer ( struct fast_spi_flash_ctx ctx,
uint32_t  hsfsts_cycle,
uint32_t  flash_addr,
size_t  len 
)
static

Definition at line 149 of file fast_spi_flash.c.

References BIOS_ERR, E_TIMEOUT, printk, SPIBAR_HWSEQ_XFER_TIMEOUT_MS, start_hwseq_xfer(), SUCCESS, wait_for_hwseq_spi_cycle_complete(), and wait_for_hwseq_xfer().

Referenced by fast_spi_flash_erase(), fast_spi_flash_read(), and fast_spi_flash_write().

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

◆ fast_spi_cycle_in_progress()

int fast_spi_cycle_in_progress ( void  )

Definition at line 164 of file fast_spi_flash.c.

References BIOS_ERR, BOILERPLATE_CREATE_CTX, printk, SPIBAR_HWSEQ_XFER_TIMEOUT_MS, SUCCESS, and wait_for_hwseq_spi_cycle_complete().

Referenced by fast_spi_lockdown_cfg().

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

◆ fast_spi_flash_ctrlr_reg_read()

static uint32_t fast_spi_flash_ctrlr_reg_read ( struct fast_spi_flash_ctx ctx,
uint16_t  reg 
)
static

Definition at line 41 of file fast_spi_flash.c.

References addr, ALIGN_DOWN, fast_spi_flash_ctx::mmio_base, and read32().

Referenced by fast_spi_flash_read_sfdp_param(), wait_for_hwseq_spi_cycle_complete(), and wait_for_hwseq_xfer().

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

◆ fast_spi_flash_ctrlr_reg_write()

static void fast_spi_flash_ctrlr_reg_write ( struct fast_spi_flash_ctx ctx,
uint16_t  reg,
uint32_t  val 
)
static

Definition at line 49 of file fast_spi_flash.c.

References addr, ALIGN_DOWN, fast_spi_flash_ctx::mmio_base, val, and write32().

Referenced by fast_spi_flash_read_sfdp_param(), and start_hwseq_xfer().

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

◆ fast_spi_flash_ctrlr_setup()

static int fast_spi_flash_ctrlr_setup ( const struct spi_slave dev)
static

Definition at line 340 of file fast_spi_flash.c.

References BIOS_ERR, spi_slave::bus, spi_slave::cs, and printk.

◆ fast_spi_flash_erase()

static int fast_spi_flash_erase ( const struct spi_flash flash,
uint32_t  offset,
size_t  len 
)
static

◆ fast_spi_flash_probe()

static int fast_spi_flash_probe ( const struct spi_slave dev,
struct spi_flash flash 
)
static

◆ fast_spi_flash_protect()

static int fast_spi_flash_protect ( const struct spi_flash flash,
const struct region region,
const enum ctrlr_prot_type  type 
)
static

Definition at line 365 of file fast_spi_flash.c.

◆ fast_spi_flash_read()

static int fast_spi_flash_read ( const struct spi_flash flash,
uint32_t  addr,
size_t  len,
void buf 
)
static

Definition at line 228 of file fast_spi_flash.c.

References addr, BOILERPLATE_CREATE_CTX, buf, drain_xfer_fifo(), exec_sync_hwseq_xfer(), get_xfer_len(), SPIBAR_HSFSTS_CYCLE_READ, and SUCCESS.

Here is the call graph for this function:

◆ fast_spi_flash_read_sfdp_param()

static uint32_t fast_spi_flash_read_sfdp_param ( struct fast_spi_flash_ctx ctx,
uint16_t  sfdp_reg 
)
static

Definition at line 67 of file fast_spi_flash.c.

References fast_spi_flash_ctrlr_reg_read(), fast_spi_flash_ctrlr_reg_write(), SPIBAR_PTDATA, SPIBAR_PTINX, SPIBAR_PTINX_HORD_JEDEC, and SPIBAR_PTINX_IDX_MASK.

Referenced by fast_spi_flash_probe().

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

◆ fast_spi_flash_status()

static int fast_spi_flash_status ( const struct spi_flash flash,
uint8_t reg 
)
static

Definition at line 281 of file fast_spi_flash.c.

◆ fast_spi_flash_write()

static int fast_spi_flash_write ( const struct spi_flash flash,
uint32_t  addr,
size_t  len,
const void buf 
)
static

Definition at line 255 of file fast_spi_flash.c.

References addr, BOILERPLATE_CREATE_CTX, buf, exec_sync_hwseq_xfer(), fill_xfer_fifo(), get_xfer_len(), SPIBAR_HSFSTS_CYCLE_WRITE, and SUCCESS.

Here is the call graph for this function:

◆ fill_xfer_fifo()

static void fill_xfer_fifo ( struct fast_spi_flash_ctx ctx,
const void data,
size_t  len 
)
static

Definition at line 77 of file fast_spi_flash.c.

References memcpy(), fast_spi_flash_ctx::mmio_base, and SPIBAR_FDATA.

Referenced by fast_spi_flash_write().

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

◆ get_xfer_len()

static size_t get_xfer_len ( const struct spi_flash flash,
uint32_t  addr,
size_t  len 
)
static

Definition at line 180 of file fast_spi_flash.c.

References addr, ALIGN_UP, MIN, spi_flash::page_size, and SPIBAR_FDATA_FIFO_SIZE.

Referenced by fast_spi_flash_read(), and fast_spi_flash_write().

Here is the caller graph for this function:

◆ start_hwseq_xfer()

static void start_hwseq_xfer ( struct fast_spi_flash_ctx ctx,
uint32_t  hsfsts_cycle,
uint32_t  flash_addr,
size_t  len 
)
static

Definition at line 93 of file fast_spi_flash.c.

References fast_spi_flash_ctrlr_reg_write(), SPIBAR_FADDR, SPIBAR_HSFSTS_CTL, SPIBAR_HSFSTS_FCYCLE_MASK, SPIBAR_HSFSTS_FDBC, SPIBAR_HSFSTS_FGO, and SPIBAR_HSFSTS_W1C_BITS.

Referenced by exec_sync_hwseq_xfer().

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

◆ wait_for_hwseq_spi_cycle_complete()

static int wait_for_hwseq_spi_cycle_complete ( struct fast_spi_flash_ctx ctx)
static

Definition at line 132 of file fast_spi_flash.c.

References E_TIMEOUT, fast_spi_flash_ctrlr_reg_read(), SPIBAR_HSFSTS_CTL, SPIBAR_HSFSTS_SCIP, SPIBAR_HWSEQ_XFER_TIMEOUT_MS, stopwatch_expired(), stopwatch_init_msecs_expire(), and SUCCESS.

Referenced by exec_sync_hwseq_xfer(), and fast_spi_cycle_in_progress().

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

◆ wait_for_hwseq_xfer()

static int wait_for_hwseq_xfer ( struct fast_spi_flash_ctx ctx,
uint32_t  flash_addr 
)
static

Definition at line 107 of file fast_spi_flash.c.

References BIOS_ERR, E_HW_ERROR, E_TIMEOUT, fast_spi_flash_ctrlr_reg_read(), printk, SPIBAR_HSFSTS_CTL, SPIBAR_HSFSTS_FCERR, SPIBAR_HSFSTS_FDONE, SPIBAR_HWSEQ_XFER_TIMEOUT_MS, stopwatch_expired(), stopwatch_init_msecs_expire(), and SUCCESS.

Referenced by exec_sync_hwseq_xfer().

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

Variable Documentation

◆ fast_spi_flash_ctrlr

const struct spi_ctrlr fast_spi_flash_ctrlr
Initial value:
= {
.flash_probe = fast_spi_flash_probe,
.flash_protect = fast_spi_flash_protect,
}
static int fast_spi_flash_ctrlr_setup(const struct spi_slave *dev)
static int fast_spi_flash_probe(const struct spi_slave *dev, struct spi_flash *flash)
static int fast_spi_flash_protect(const struct spi_flash *flash, const struct region *region, const enum ctrlr_prot_type type)
#define SPI_CTRLR_DEFAULT_MAX_XFER_SIZE
Definition: spi-generic.h:102

Definition at line 365 of file fast_spi_flash.c.

◆ fast_spi_flash_ops

const struct spi_flash_ops fast_spi_flash_ops
Initial value:
= {
}
static int fast_spi_flash_status(const struct spi_flash *flash, uint8_t *reg)
static int fast_spi_flash_write(const struct spi_flash *flash, uint32_t addr, size_t len, const void *buf)
static int fast_spi_flash_erase(const struct spi_flash *flash, uint32_t offset, size_t len)
static int fast_spi_flash_read(const struct spi_flash *flash, uint32_t addr, size_t len, void *buf)

Definition at line 281 of file fast_spi_flash.c.

Referenced by fast_spi_flash_probe().