Skip to content

Commit

Permalink
tree/: Convert printlock func ptr into enumerate values
Browse files Browse the repository at this point in the history
Converting the printlock function pointer
within the flashchip struct into enum values allows for
the flashchips db to be turn into pure, declarative data.
A nice side-effect of this is to reduce link-time symbol
space of chipdrivers and increase modularity of the
spi25_statusreg.c and related implementations.

BUG=none
TEST=ninja test.

Change-Id: I9131348f72c1010e2c213dca4dc4b675a8d8681e
Signed-off-by: Edward O'Callaghan <[email protected]>
Reviewed-on: https://review.coreboot.org/c/flashrom/+/69934
Tested-by: build bot (Jenkins) <[email protected]>
Reviewed-by: Sam McNally <[email protected]>
Reviewed-by: Nikolai Artemiev <[email protected]>
  • Loading branch information
quasisec authored and Edward O'Callaghan committed Mar 22, 2023
1 parent e1cdbdb commit 5cff668
Show file tree
Hide file tree
Showing 4 changed files with 135 additions and 97 deletions.
8 changes: 5 additions & 3 deletions flashrom.c
Original file line number Diff line number Diff line change
Expand Up @@ -1179,9 +1179,11 @@ int probe_flash(struct registered_master *mst, int startchip, struct flashctx *f

/* Flash registers may more likely not be mapped if the chip was forced.
* Lock info may be stored in registers, so avoid lock info printing. */
if (!force)
if (flash->chip->printlock)
flash->chip->printlock(flash);
if (!force) {
printlockfunc_t *printlock = lookup_printlock_func_ptr(flash);
if (printlock)
printlock(flash);
}

/* Get out of the way for later runs. */
unmap_flash(flash);
Expand Down
24 changes: 0 additions & 24 deletions include/chipdrivers.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,30 +68,6 @@ int spi_set_extended_address(struct flashctx *, uint8_t addr_high);
int spi_read_register(const struct flashctx *flash, enum flash_reg reg, uint8_t *value);
int spi_write_register(const struct flashctx *flash, enum flash_reg reg, uint8_t value);
void spi_prettyprint_status_register_bit(uint8_t status, int bit);
int spi_prettyprint_status_register_plain(struct flashctx *flash);
int spi_prettyprint_status_register_default_welwip(struct flashctx *flash);
int spi_prettyprint_status_register_bp1_srwd(struct flashctx *flash);
int spi_prettyprint_status_register_bp2_srwd(struct flashctx *flash);
int spi_prettyprint_status_register_bp3_srwd(struct flashctx *flash);
int spi_prettyprint_status_register_bp4_srwd(struct flashctx *flash);
int spi_prettyprint_status_register_bp2_bpl(struct flashctx *flash);
int spi_prettyprint_status_register_bp2_tb_bpl(struct flashctx *flash);
int spi_prettyprint_status_register_amic_a25l032(struct flashctx *flash);
int spi_prettyprint_status_register_at25df(struct flashctx *flash);
int spi_prettyprint_status_register_at25df_sec(struct flashctx *flash);
int spi_prettyprint_status_register_at25f(struct flashctx *flash);
int spi_prettyprint_status_register_at25f512a(struct flashctx *flash);
int spi_prettyprint_status_register_at25f512b(struct flashctx *flash);
int spi_prettyprint_status_register_at25f4096(struct flashctx *flash);
int spi_prettyprint_status_register_at25fs010(struct flashctx *flash);
int spi_prettyprint_status_register_at25fs040(struct flashctx *flash);
int spi_prettyprint_status_register_at26df081a(struct flashctx *flash);
int spi_prettyprint_status_register_en25s_wp(struct flashctx *flash);
int spi_prettyprint_status_register_n25q(struct flashctx *flash);
int spi_prettyprint_status_register_bp2_ep_srwd(struct flashctx *flash);
int spi_prettyprint_status_register_sst25(struct flashctx *flash);
int spi_prettyprint_status_register_sst25vf016(struct flashctx *flash);
int spi_prettyprint_status_register_sst25vf040b(struct flashctx *flash);

/* sfdp.c */
int probe_spi_sfdp(struct flashctx *flash);
Expand Down
92 changes: 48 additions & 44 deletions include/flash.h
Original file line number Diff line number Diff line change
Expand Up @@ -351,49 +351,53 @@ enum blockprotect_func {
TEST_UNLOCK_INJECTOR, /* special case must come last. */
};

#define NO_PRINTLOCK_FUNC NULL
#define PRINTLOCK_AT49F printlock_at49f
#define PRINTLOCK_REGSPACE2_BLOCK_ERASER_0 printlock_regspace2_block_eraser_0
#define PRINTLOCK_REGSPACE2_BLOCK_ERASER_1 printlock_regspace2_block_eraser_1
#define PRINTLOCK_SST_FWHUB printlock_sst_fwhub
#define PRINTLOCK_W39F010 printlock_w39f010
#define PRINTLOCK_W39L010 printlock_w39l010
#define PRINTLOCK_W39L020 printlock_w39l020
#define PRINTLOCK_W39L040 printlock_w39l040
#define PRINTLOCK_W39V040A printlock_w39v040a
#define PRINTLOCK_W39V040B printlock_w39v040b
#define PRINTLOCK_W39V040C printlock_w39v040c
#define PRINTLOCK_W39V040FA printlock_w39v040fa
#define PRINTLOCK_W39V040FB printlock_w39v040fb
#define PRINTLOCK_W39V040FC printlock_w39v040fc
#define PRINTLOCK_W39V080A printlock_w39v080a
#define PRINTLOCK_W39V080FA printlock_w39v080fa
#define PRINTLOCK_W39V080FA_DUAL printlock_w39v080fa_dual
#define SPI_PRETTYPRINT_STATUS_REGISTER_AMIC_A25L032 spi_prettyprint_status_register_amic_a25l032
#define SPI_PRETTYPRINT_STATUS_REGISTER_AT25DF spi_prettyprint_status_register_at25df
#define SPI_PRETTYPRINT_STATUS_REGISTER_AT25DF_SEC spi_prettyprint_status_register_at25df_sec
#define SPI_PRETTYPRINT_STATUS_REGISTER_AT25F spi_prettyprint_status_register_at25f
#define SPI_PRETTYPRINT_STATUS_REGISTER_AT25F4096 spi_prettyprint_status_register_at25f4096
#define SPI_PRETTYPRINT_STATUS_REGISTER_AT25F512A spi_prettyprint_status_register_at25f512a
#define SPI_PRETTYPRINT_STATUS_REGISTER_AT25F512B spi_prettyprint_status_register_at25f512b
#define SPI_PRETTYPRINT_STATUS_REGISTER_AT25FS010 spi_prettyprint_status_register_at25fs010
#define SPI_PRETTYPRINT_STATUS_REGISTER_AT25FS040 spi_prettyprint_status_register_at25fs040
#define SPI_PRETTYPRINT_STATUS_REGISTER_AT26DF081A spi_prettyprint_status_register_at26df081a
#define SPI_PRETTYPRINT_STATUS_REGISTER_AT45DB spi_prettyprint_status_register_at45db
#define SPI_PRETTYPRINT_STATUS_REGISTER_BP1_SRWD spi_prettyprint_status_register_bp1_srwd
#define SPI_PRETTYPRINT_STATUS_REGISTER_BP2_BPL spi_prettyprint_status_register_bp2_bpl
#define SPI_PRETTYPRINT_STATUS_REGISTER_BP2_EP_SRWD spi_prettyprint_status_register_bp2_ep_srwd
#define SPI_PRETTYPRINT_STATUS_REGISTER_BP2_SRWD spi_prettyprint_status_register_bp2_srwd
#define SPI_PRETTYPRINT_STATUS_REGISTER_BP2_TB_BPL spi_prettyprint_status_register_bp2_tb_bpl
#define SPI_PRETTYPRINT_STATUS_REGISTER_BP3_SRWD spi_prettyprint_status_register_bp3_srwd
#define SPI_PRETTYPRINT_STATUS_REGISTER_BP4_SRWD spi_prettyprint_status_register_bp4_srwd
#define SPI_PRETTYPRINT_STATUS_REGISTER_DEFAULT_WELWIP spi_prettyprint_status_register_default_welwip
#define SPI_PRETTYPRINT_STATUS_REGISTER_EN25S_WP spi_prettyprint_status_register_en25s_wp
#define SPI_PRETTYPRINT_STATUS_REGISTER_N25Q spi_prettyprint_status_register_n25q
#define SPI_PRETTYPRINT_STATUS_REGISTER_PLAIN spi_prettyprint_status_register_plain
#define SPI_PRETTYPRINT_STATUS_REGISTER_SST25 spi_prettyprint_status_register_sst25
#define SPI_PRETTYPRINT_STATUS_REGISTER_SST25VF016 spi_prettyprint_status_register_sst25vf016
#define SPI_PRETTYPRINT_STATUS_REGISTER_SST25VF040B spi_prettyprint_status_register_sst25vf040b
enum printlock_func {
NO_PRINTLOCK_FUNC,
PRINTLOCK_AT49F,
PRINTLOCK_REGSPACE2_BLOCK_ERASER_0,
PRINTLOCK_REGSPACE2_BLOCK_ERASER_1,
PRINTLOCK_SST_FWHUB,
PRINTLOCK_W39F010,
PRINTLOCK_W39L010,
PRINTLOCK_W39L020,
PRINTLOCK_W39L040,
PRINTLOCK_W39V040A,
PRINTLOCK_W39V040B,
PRINTLOCK_W39V040C,
PRINTLOCK_W39V040FA,
PRINTLOCK_W39V040FB,
PRINTLOCK_W39V040FC,
PRINTLOCK_W39V080A,
PRINTLOCK_W39V080FA,
PRINTLOCK_W39V080FA_DUAL,
SPI_PRETTYPRINT_STATUS_REGISTER_AMIC_A25L032,
SPI_PRETTYPRINT_STATUS_REGISTER_AT25DF,
SPI_PRETTYPRINT_STATUS_REGISTER_AT25DF_SEC,
SPI_PRETTYPRINT_STATUS_REGISTER_AT25F,
SPI_PRETTYPRINT_STATUS_REGISTER_AT25F4096,
SPI_PRETTYPRINT_STATUS_REGISTER_AT25F512A,
SPI_PRETTYPRINT_STATUS_REGISTER_AT25F512B,
SPI_PRETTYPRINT_STATUS_REGISTER_AT25FS010,
SPI_PRETTYPRINT_STATUS_REGISTER_AT25FS040,
SPI_PRETTYPRINT_STATUS_REGISTER_AT26DF081A,
SPI_PRETTYPRINT_STATUS_REGISTER_AT45DB,
SPI_PRETTYPRINT_STATUS_REGISTER_BP1_SRWD,
SPI_PRETTYPRINT_STATUS_REGISTER_BP2_BPL,
SPI_PRETTYPRINT_STATUS_REGISTER_BP2_EP_SRWD,
SPI_PRETTYPRINT_STATUS_REGISTER_BP2_SRWD,
SPI_PRETTYPRINT_STATUS_REGISTER_BP2_TB_BPL,
SPI_PRETTYPRINT_STATUS_REGISTER_BP3_SRWD,
SPI_PRETTYPRINT_STATUS_REGISTER_BP4_SRWD,
SPI_PRETTYPRINT_STATUS_REGISTER_DEFAULT_WELWIP,
SPI_PRETTYPRINT_STATUS_REGISTER_EN25S_WP,
SPI_PRETTYPRINT_STATUS_REGISTER_N25Q,
SPI_PRETTYPRINT_STATUS_REGISTER_PLAIN,
SPI_PRETTYPRINT_STATUS_REGISTER_SST25,
SPI_PRETTYPRINT_STATUS_REGISTER_SST25VF016,
SPI_PRETTYPRINT_STATUS_REGISTER_SST25VF040B,
};
typedef int (printlockfunc_t)(struct flashctx *flash);
printlockfunc_t *lookup_printlock_func_ptr(struct flashctx *flash);

struct flashchip {
const char *vendor;
Expand Down Expand Up @@ -460,7 +464,7 @@ struct flashchip {
enum block_erase_func block_erase;
} block_erasers[NUM_ERASEFUNCTIONS];

int (*printlock) (struct flashctx *flash);
enum printlock_func printlock;
enum blockprotect_func unlock;
enum write_func write;
enum read_func read;
Expand Down
Loading

0 comments on commit 5cff668

Please sign in to comment.