coreboot
coreboot is an Open Source project aimed at replacing the proprietary BIOS found in most computers.
spi_flash.c File Reference
#include <assert.h>
#include <boot/coreboot_tables.h>
#include <commonlib/region.h>
#include <console/console.h>
#include <string.h>
#include <spi-generic.h>
#include <spi_flash.h>
#include <timer.h>
#include <types.h>
#include "spi_flash_internal.h"
Include dependency graph for spi_flash.c:

Go to the source code of this file.

Macros

#define IDCODE_LEN   5
 

Functions

static void spi_flash_addr (u32 addr, u8 *cmd)
 
static int do_spi_flash_cmd (const struct spi_slave *spi, const u8 *dout, size_t bytes_out, void *din, size_t bytes_in)
 
static int do_dual_output_cmd (const struct spi_slave *spi, const u8 *dout, size_t bytes_out, void *din, size_t bytes_in)
 
static int do_dual_io_cmd (const struct spi_slave *spi, const u8 *dout, size_t bytes_out, void *din, size_t bytes_in)
 
int spi_flash_cmd (const struct spi_slave *spi, u8 cmd, void *response, size_t len)
 
int spi_flash_cmd_write (const struct spi_slave *spi, const u8 *cmd, size_t cmd_len, const void *data, size_t data_len)
 
int spi_flash_cmd_read (const struct spi_flash *flash, u32 offset, size_t len, void *buf)
 
int spi_flash_cmd_poll_bit (const struct spi_flash *flash, unsigned long timeout, u8 cmd, u8 poll_bit)
 
int spi_flash_cmd_wait_ready (const struct spi_flash *flash, unsigned long timeout)
 
int spi_flash_cmd_erase (const struct spi_flash *flash, u32 offset, size_t len)
 
int spi_flash_cmd_status (const struct spi_flash *flash, u8 *reg)
 
int spi_flash_cmd_write_page_program (const struct spi_flash *flash, u32 offset, size_t len, const void *buf)
 
static int fill_spi_flash (const struct spi_slave *spi, struct spi_flash *flash, const struct spi_flash_vendor_info *vi, const struct spi_flash_part_id *part)
 
static const struct spi_flash_part_idfind_part (const struct spi_flash_vendor_info *vi, uint16_t id[2])
 
static int find_match (const struct spi_slave *spi, struct spi_flash *flash, uint8_t manuf_id, uint16_t id[2])
 
int spi_flash_generic_probe (const struct spi_slave *spi, struct spi_flash *flash)
 
int spi_flash_probe (unsigned int bus, unsigned int cs, struct spi_flash *flash)
 
int spi_flash_read (const struct spi_flash *flash, u32 offset, size_t len, void *buf)
 
int spi_flash_write (const struct spi_flash *flash, u32 offset, size_t len, const void *buf)
 
int spi_flash_erase (const struct spi_flash *flash, u32 offset, size_t len)
 
int spi_flash_status (const struct spi_flash *flash, u8 *reg)
 
int spi_flash_is_write_protected (const struct spi_flash *flash, const struct region *region)
 
int spi_flash_set_write_protected (const struct spi_flash *flash, const struct region *region, const enum spi_flash_status_reg_lockdown mode)
 
int spi_flash_volatile_group_begin (const struct spi_flash *flash)
 
int spi_flash_volatile_group_end (const struct spi_flash *flash)
 
void lb_spi_flash (struct lb_header *header)
 
int spi_flash_ctrlr_protect_region (const struct spi_flash *flash, const struct region *region, const enum ctrlr_prot_type type)
 
int spi_flash_vector_helper (const struct spi_slave *slave, struct spi_op vectors[], size_t count, int(*func)(const struct spi_slave *slave, const void *dout, size_t bytesout, void *din, size_t bytesin))
 

Variables

static const struct spi_flash_vendor_infospi_flash_vendors []
 
static uint32_t volatile_group_count
 
const struct spi_flash_ops_descriptor spi_flash_pp_0x20_sector_desc
 
const struct spi_flash_ops_descriptor spi_flash_pp_0xd8_sector_desc
 

Macro Definition Documentation

◆ IDCODE_LEN

#define IDCODE_LEN   5

Definition at line 373 of file spi_flash.c.

Function Documentation

◆ do_dual_io_cmd()

static int do_dual_io_cmd ( const struct spi_slave spi,
const u8 dout,
size_t  bytes_out,
void din,
size_t  bytes_in 
)
static

Definition at line 82 of file spi_flash.c.

References spi_slave::ctrlr, spi_op::din, spi_op::dout, NULL, spi_claim_bus(), spi_release_bus(), spi_xfer_vector(), and spi_ctrlr::xfer_dual.

Referenced by spi_flash_cmd_read().

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

◆ do_dual_output_cmd()

static int do_dual_output_cmd ( const struct spi_slave spi,
const u8 dout,
size_t  bytes_out,
void din,
size_t  bytes_in 
)
static

Definition at line 54 of file spi_flash.c.

References spi_slave::ctrlr, spi_op::din, spi_op::dout, NULL, spi_claim_bus(), spi_release_bus(), spi_xfer_vector(), and spi_ctrlr::xfer_dual.

Referenced by spi_flash_cmd_read().

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

◆ do_spi_flash_cmd()

static int do_spi_flash_cmd ( const struct spi_slave spi,
const u8 dout,
size_t  bytes_out,
void din,
size_t  bytes_in 
)
static

Definition at line 23 of file spi_flash.c.

References ARRAY_SIZE, count, spi_op::din, spi_op::dout, NULL, spi_claim_bus(), spi_release_bus(), and spi_xfer_vector().

Referenced by spi_flash_cmd(), spi_flash_cmd_poll_bit(), spi_flash_cmd_read(), and spi_flash_cmd_write().

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

◆ fill_spi_flash()

◆ find_match()

static int find_match ( const struct spi_slave spi,
struct spi_flash flash,
uint8_t  manuf_id,
uint16_t  id[2] 
)
static

Definition at line 423 of file spi_flash.c.

References ARRAY_SIZE, fill_spi_flash(), find_part(), spi_flash_vendor_info::id, NULL, and spi_flash_vendors.

Referenced by spi_flash_generic_probe().

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

◆ find_part()

static const struct spi_flash_part_id* find_part ( const struct spi_flash_vendor_info vi,
uint16_t  id[2] 
)
static

Definition at line 404 of file spi_flash.c.

References spi_flash_part_id::id, spi_flash_vendor_info::ids, spi_flash_vendor_info::match_id_mask, spi_flash_vendor_info::nr_part_ids, and NULL.

Referenced by find_match().

Here is the caller graph for this function:

◆ lb_spi_flash()

◆ spi_flash_addr()

static void spi_flash_addr ( u32  addr,
u8 cmd 
)
static

Definition at line 15 of file spi_flash.c.

References addr.

Referenced by spi_flash_cmd_erase(), spi_flash_cmd_read(), and spi_flash_cmd_write_page_program().

Here is the caller graph for this function:

◆ spi_flash_cmd()

int spi_flash_cmd ( const struct spi_slave spi,
u8  cmd,
void response,
size_t  len 
)

◆ spi_flash_cmd_erase()

int spi_flash_cmd_erase ( const struct spi_flash flash,
u32  offset,
size_t  len 
)

◆ spi_flash_cmd_poll_bit()

int spi_flash_cmd_poll_bit ( const struct spi_flash flash,
unsigned long  timeout,
u8  cmd,
u8  poll_bit 
)

Definition at line 190 of file spi_flash.c.

References BIOS_WARNING, do_spi_flash_cmd(), printk, spi_flash::spi, stopwatch_duration_msecs(), stopwatch_expired(), and stopwatch_init_msecs_expire().

Referenced by spi_flash_cmd_wait_ready().

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

◆ spi_flash_cmd_read()

◆ spi_flash_cmd_status()

int spi_flash_cmd_status ( const struct spi_flash flash,
u8 reg 
)

Definition at line 276 of file spi_flash.c.

References spi_flash::spi, spi_flash_cmd(), and spi_flash::status_cmd.

Here is the call graph for this function:

◆ spi_flash_cmd_wait_ready()

int spi_flash_cmd_wait_ready ( const struct spi_flash flash,
unsigned long  timeout 
)

Definition at line 221 of file spi_flash.c.

References CMD_READ_STATUS, spi_flash_cmd_poll_bit(), and STATUS_WIP.

Referenced by spi_flash_cmd_erase(), spi_flash_cmd_write_page_program(), sst_byte_write(), sst_write_ai(), and winbond_flash_cmd_status().

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

◆ spi_flash_cmd_write()

int spi_flash_cmd_write ( const struct spi_slave spi,
const u8 cmd,
size_t  cmd_len,
const void data,
size_t  data_len 
)

Definition at line 122 of file spi_flash.c.

References BIOS_WARNING, do_spi_flash_cmd(), memcpy(), NULL, and printk.

Referenced by spi_flash_cmd_erase(), spi_flash_cmd_write_page_program(), sst_byte_write(), sst_write_ai(), and winbond_flash_cmd_status().

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

◆ spi_flash_cmd_write_page_program()

int spi_flash_cmd_write_page_program ( const struct spi_flash flash,
u32  offset,
size_t  len,
const void buf 
)

◆ spi_flash_ctrlr_protect_region()

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

Definition at line 719 of file spi_flash.c.

References spi_slave::ctrlr, spi_ctrlr::flash_protect, region_is_subregion(), region::size, spi_flash::size, spi_flash::spi, and type.

Referenced by boot_device_wp_region(), and nvm_protect().

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

◆ spi_flash_erase()

int spi_flash_erase ( const struct spi_flash flash,
u32  offset,
size_t  len 
)

Definition at line 553 of file spi_flash.c.

References spi_flash_ops::erase, offset, spi_flash::ops, spi_flash_volatile_group_begin(), and spi_flash_volatile_group_end().

Referenced by spi_eraseat().

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

◆ spi_flash_generic_probe()

int spi_flash_generic_probe ( const struct spi_slave spi,
struct spi_flash flash 
)

Definition at line 448 of file spi_flash.c.

References BIOS_INFO, BIOS_SPEW, CMD_READ_ID, CONFIG, find_match(), IDCODE_LEN, printk, spi_flash_cmd(), and stmicro_release_deep_sleep_identify().

Referenced by spi_flash_probe(), and spi_flash_programmer_probe().

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

◆ spi_flash_is_write_protected()

int spi_flash_is_write_protected ( const struct spi_flash flash,
const struct region region 
)

Definition at line 576 of file spi_flash.c.

References BIOS_WARNING, spi_flash_protection_ops::get_write, printk, spi_flash::prot_ops, region_is_subregion(), region::size, and spi_flash::size.

Referenced by boot_device_wp_region(), mainboard_print_info(), and protect_ro_rgn_spi_flash().

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

◆ spi_flash_probe()

◆ spi_flash_read()

int spi_flash_read ( const struct spi_flash flash,
u32  offset,
size_t  len,
void buf 
)

Definition at line 531 of file spi_flash.c.

References buf, offset, spi_flash::ops, and spi_flash_ops::read.

Referenced by pre_mem_debug_init(), and spi_readat().

Here is the caller graph for this function:

◆ spi_flash_set_write_protected()

int spi_flash_set_write_protected ( const struct spi_flash flash,
const struct region region,
const enum spi_flash_status_reg_lockdown  mode 
)

◆ spi_flash_status()

int spi_flash_status ( const struct spi_flash flash,
u8 reg 
)

Definition at line 568 of file spi_flash.c.

References spi_flash::ops, and spi_flash_ops::status.

Referenced by mainboard_config_cbi_wp(), nvm_is_write_protected(), and protect_ro_rgn_spi_flash().

Here is the caller graph for this function:

◆ spi_flash_vector_helper()

int spi_flash_vector_helper ( const struct spi_slave slave,
struct spi_op  vectors[],
size_t  count,
int(*)(const struct spi_slave *slave, const void *dout, size_t bytesout, void *din, size_t bytesin)  func 
)

Definition at line 745 of file spi_flash.c.

Referenced by xfer_vectors().

Here is the caller graph for this function:

◆ spi_flash_volatile_group_begin()

int spi_flash_volatile_group_begin ( const struct spi_flash flash)

Definition at line 647 of file spi_flash.c.

References chipset_volatile_group_begin(), CONFIG, count, and volatile_group_count.

Referenced by spi_flash_erase(), and spi_flash_write().

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

◆ spi_flash_volatile_group_end()

int spi_flash_volatile_group_end ( const struct spi_flash flash)

Definition at line 664 of file spi_flash.c.

References assert, chipset_volatile_group_end(), CONFIG, count, and volatile_group_count.

Referenced by spi_flash_erase(), and spi_flash_write().

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

◆ spi_flash_write()

int spi_flash_write ( const struct spi_flash flash,
u32  offset,
size_t  len,
const void buf 
)

Definition at line 537 of file spi_flash.c.

References buf, offset, spi_flash::ops, spi_flash_volatile_group_begin(), spi_flash_volatile_group_end(), and spi_flash_ops::write.

Referenced by spi_writeat().

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

Variable Documentation

◆ spi_flash_pp_0x20_sector_desc

const struct spi_flash_ops_descriptor spi_flash_pp_0x20_sector_desc
Initial value:
= {
.erase_cmd = 0x20,
.status_cmd = 0x05,
.pp_cmd = 0x02,
.wren_cmd = 0x06,
.ops = {
},
}
int spi_flash_cmd_write_page_program(const struct spi_flash *flash, u32 offset, size_t len, const void *buf)
Definition: spi_flash.c:281
int spi_flash_cmd_read(const struct spi_flash *flash, u32 offset, size_t len, void *buf)
Definition: spi_flash.c:142
int spi_flash_cmd_erase(const struct spi_flash *flash, u32 offset, size_t len)
Definition: spi_flash.c:228
int spi_flash_cmd_status(const struct spi_flash *flash, u8 *reg)
Definition: spi_flash.c:276

Definition at line 745 of file spi_flash.c.

◆ spi_flash_pp_0xd8_sector_desc

const struct spi_flash_ops_descriptor spi_flash_pp_0xd8_sector_desc
Initial value:
= {
.erase_cmd = 0xd8,
.status_cmd = 0x05,
.pp_cmd = 0x02,
.wren_cmd = 0x06,
.ops = {
},
}

Definition at line 745 of file spi_flash.c.

◆ spi_flash_vendors

const struct spi_flash_vendor_info* spi_flash_vendors[]
static

Definition at line 335 of file spi_flash.c.

Referenced by find_match().

◆ volatile_group_count

uint32_t volatile_group_count
static

Definition at line 645 of file spi_flash.c.

Referenced by spi_flash_volatile_group_begin(), and spi_flash_volatile_group_end().