1
0
mirror of https://review.coreboot.org/flashrom.git synced 2025-04-27 07:02:34 +02:00

spi_master: Move shutdown function above spi_master struct

This patch prepares spi masters to use new API which allows to
register shutdown function in spi_master struct. See also later
patch in this chain, where spi masters are converted to new API.

BUG=b:185191942
TEST=builds and ninja test
Comparing flashrom binary before and after the patch,
make clean && make CONFIG_EVERYTHING=yes VERSION=none
binary is the same

Change-Id: I50716686552b4ddcc6089d5afadb19ef59d9f9b4
Signed-off-by: Anastasia Klimchuk <aklm@chromium.org>
Reviewed-on: https://review.coreboot.org/c/flashrom/+/56101
Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
Reviewed-by: Edward O'Callaghan <quasisec@chromium.org>
Reviewed-by: Nico Huber <nico.h@gmx.de>
This commit is contained in:
Anastasia Klimchuk 2021-07-06 16:03:11 +10:00 committed by Nico Huber
parent 5a97be363a
commit 0a7f036610
14 changed files with 184 additions and 188 deletions

View File

@ -131,6 +131,13 @@ static int bitbang_spi_send_command(const struct flashctx *flash,
return 0;
}
static int bitbang_spi_shutdown(void *data)
{
/* FIXME: Run bitbang_spi_release_bus here or per command? */
free(data);
return 0;
}
static const struct spi_master spi_master_bitbang = {
.features = SPI_MASTER_4BA,
.max_data_read = MAX_DATA_READ_UNLIMITED,
@ -142,13 +149,6 @@ static const struct spi_master spi_master_bitbang = {
.write_aai = default_spi_write_aai,
};
static int bitbang_spi_shutdown(void *data)
{
/* FIXME: Run bitbang_spi_release_bus here or per command? */
free(data);
return 0;
}
int register_spi_bitbang_master(const struct bitbang_spi_master *master, void *spi_data)
{
struct spi_master mst = spi_master_bitbang;

View File

@ -130,38 +130,6 @@ static int buspirate_wait_for_string(unsigned char *buf, const char *key)
return ret;
}
static struct spi_master spi_master_buspirate = {
.features = SPI_MASTER_4BA,
.max_data_read = MAX_DATA_UNSPECIFIED,
.max_data_write = MAX_DATA_UNSPECIFIED,
.command = NULL,
.multicommand = default_spi_send_multicommand,
.read = default_spi_read,
.write_256 = default_spi_write_256,
.write_aai = default_spi_write_aai,
};
static const struct buspirate_speeds spispeeds[] = {
{"30k", 0x0},
{"125k", 0x1},
{"250k", 0x2},
{"1M", 0x3},
{"2M", 0x4},
{"2.6M", 0x5},
{"4M", 0x6},
{"8M", 0x7},
{NULL, 0x0}
};
static const struct buspirate_speeds serialspeeds[] = {
{"115200", 115200},
{"230400", 230400},
{"250000", 250000},
{"2000000", 2000000},
{"2M", 2000000},
{NULL, 0}
};
static int buspirate_spi_shutdown(void *data)
{
struct bp_spi_data *bp_data = data;
@ -204,6 +172,38 @@ out_shutdown:
return ret;
}
static struct spi_master spi_master_buspirate = {
.features = SPI_MASTER_4BA,
.max_data_read = MAX_DATA_UNSPECIFIED,
.max_data_write = MAX_DATA_UNSPECIFIED,
.command = NULL,
.multicommand = default_spi_send_multicommand,
.read = default_spi_read,
.write_256 = default_spi_write_256,
.write_aai = default_spi_write_aai,
};
static const struct buspirate_speeds spispeeds[] = {
{"30k", 0x0},
{"125k", 0x1},
{"250k", 0x2},
{"1M", 0x3},
{"2M", 0x4},
{"2.6M", 0x5},
{"4M", 0x6},
{"8M", 0x7},
{NULL, 0x0}
};
static const struct buspirate_speeds serialspeeds[] = {
{"115200", 115200},
{"230400", 230400},
{"250000", 250000},
{"2000000", 2000000},
{"2M", 2000000},
{NULL, 0}
};
static int buspirate_spi_send_command_v1(const struct flashctx *flash, unsigned int writecnt, unsigned int readcnt,
const unsigned char *writearr, unsigned char *readarr)
{

View File

@ -385,20 +385,6 @@ static int ch341a_spi_spi_send_command(const struct flashctx *flash, unsigned in
return 0;
}
static const struct spi_master spi_master_ch341a_spi = {
.features = SPI_MASTER_4BA,
/* flashrom's current maximum is 256 B. CH341A was tested on Linux and Windows to accept atleast
* 128 kB. Basically there should be no hard limit because transfers are broken up into USB packets
* sent to the device and most of their payload streamed via SPI. */
.max_data_read = 4 * 1024,
.max_data_write = 4 * 1024,
.command = ch341a_spi_spi_send_command,
.multicommand = default_spi_send_multicommand,
.read = default_spi_read,
.write_256 = default_spi_write_256,
.write_aai = default_spi_write_aai,
};
static int ch341a_spi_shutdown(void *data)
{
if (handle == NULL)
@ -419,6 +405,20 @@ static int ch341a_spi_shutdown(void *data)
return 0;
}
static const struct spi_master spi_master_ch341a_spi = {
.features = SPI_MASTER_4BA,
/* flashrom's current maximum is 256 B. CH341A was tested on Linux and Windows to accept atleast
* 128 kB. Basically there should be no hard limit because transfers are broken up into USB packets
* sent to the device and most of their payload streamed via SPI. */
.max_data_read = 4 * 1024,
.max_data_write = 4 * 1024,
.command = ch341a_spi_spi_send_command,
.multicommand = default_spi_send_multicommand,
.read = default_spi_read,
.write_256 = default_spi_write_256,
.write_aai = default_spi_write_aai,
};
static int ch341a_spi_init(void)
{
if (handle != NULL) {

View File

@ -992,6 +992,24 @@ static int parse_voltage(char *voltage)
return millivolt;
}
static int dediprog_shutdown(void *data)
{
dediprog_devicetype = DEV_UNKNOWN;
/* URB 28. Command Set SPI Voltage to 0. */
if (dediprog_set_spi_voltage(0x0))
return 1;
if (libusb_release_interface(dediprog_handle, 0)) {
msg_perr("Could not release USB interface!\n");
return 1;
}
libusb_close(dediprog_handle);
libusb_exit(usb_ctx);
return 0;
}
static struct spi_master spi_master_dediprog = {
.features = SPI_MASTER_NO_4BA_MODES,
.max_data_read = 16, /* 18 seems to work fine as well, but 19 times out sometimes with FW 5.15. */
@ -1037,24 +1055,6 @@ static int dediprog_open(int index)
return 0;
}
static int dediprog_shutdown(void *data)
{
dediprog_devicetype = DEV_UNKNOWN;
/* URB 28. Command Set SPI Voltage to 0. */
if (dediprog_set_spi_voltage(0x0))
return 1;
if (libusb_release_interface(dediprog_handle, 0)) {
msg_perr("Could not release USB interface!\n");
return 1;
}
libusb_close(dediprog_handle);
libusb_exit(usb_ctx);
return 0;
}
static int dediprog_init(void)
{
char *voltage, *id_str, *device, *spispeed, *target_str;

View File

@ -315,18 +315,6 @@ static int digilent_spi_send_command(const struct flashctx *flash, unsigned int
return 0;
}
static const struct spi_master spi_master_digilent_spi = {
.features = SPI_MASTER_4BA,
.max_data_read = 252,
.max_data_write = 252,
.command = digilent_spi_send_command,
.multicommand = default_spi_send_multicommand,
.read = default_spi_read,
.write_256 = default_spi_write_256,
.write_aai = default_spi_write_aai,
};
static int digilent_spi_shutdown(void *data)
{
struct digilent_spi_data *digilent_data = data;
@ -340,6 +328,17 @@ static int digilent_spi_shutdown(void *data)
return 0;
}
static const struct spi_master spi_master_digilent_spi = {
.features = SPI_MASTER_4BA,
.max_data_read = 252,
.max_data_write = 252,
.command = digilent_spi_send_command,
.multicommand = default_spi_send_multicommand,
.read = default_spi_read,
.write_256 = default_spi_write_256,
.write_aai = default_spi_write_aai,
};
static bool default_reset(struct libusb_device_handle *handle)
{
char board[17];

View File

@ -580,7 +580,23 @@ static int dummy_spi_send_command(const struct flashctx *flash, unsigned int wri
return 0;
}
static int dummy_shutdown(void *data)
{
msg_pspew("%s\n", __func__);
struct emu_data *emu_data = (struct emu_data *)data;
if (emu_data->emu_chip != EMULATE_NONE) {
if (emu_data->emu_persistent_image && emu_data->emu_modified) {
msg_pdbg("Writing %s\n", emu_data->emu_persistent_image);
write_buf_to_file(emu_data->flashchip_contents,
emu_data->emu_chip_size,
emu_data->emu_persistent_image);
}
free(emu_data->emu_persistent_image);
free(emu_data->flashchip_contents);
}
free(data);
return 0;
}
static const struct spi_master spi_master_dummyflasher = {
.features = SPI_MASTER_4BA,
@ -604,24 +620,6 @@ static const struct par_master par_master_dummyflasher = {
.chip_writen = dummy_chip_writen,
};
static int dummy_shutdown(void *data)
{
msg_pspew("%s\n", __func__);
struct emu_data *emu_data = (struct emu_data *)data;
if (emu_data->emu_chip != EMULATE_NONE) {
if (emu_data->emu_persistent_image && emu_data->emu_modified) {
msg_pdbg("Writing %s\n", emu_data->emu_persistent_image);
write_buf_to_file(emu_data->flashchip_contents,
emu_data->emu_chip_size,
emu_data->emu_persistent_image);
}
free(emu_data->emu_persistent_image);
free(emu_data->flashchip_contents);
}
free(data);
return 0;
}
static int init_data(struct emu_data *data, enum chipbustype *dummy_buses_supported)
{

View File

@ -290,6 +290,12 @@ static int it8716f_spi_chip_write_256(struct flashctx *flash, const uint8_t *buf
return 0;
}
static int it8716f_shutdown(void *data)
{
free(data);
return 0;
}
static const struct spi_master spi_master_it87xx = {
.max_data_read = 3,
.max_data_write = MAX_DATA_UNSPECIFIED,
@ -300,13 +306,6 @@ static const struct spi_master spi_master_it87xx = {
.write_aai = spi_chip_write_1,
};
static int it8716f_shutdown(void *data)
{
free(data);
return 0;
}
static uint16_t it87spi_probe(uint16_t port)
{
uint8_t tmp = 0;

View File

@ -155,19 +155,6 @@ static int jlink_spi_send_command(const struct flashctx *flash, unsigned int wri
return 0;
}
static const struct spi_master spi_master_jlink_spi = {
/* Maximum data read size in one go (excluding opcode+address). */
.max_data_read = JTAG_MAX_TRANSFER_SIZE - 5,
/* Maximum data write size in one go (excluding opcode+address). */
.max_data_write = JTAG_MAX_TRANSFER_SIZE - 5,
.command = jlink_spi_send_command,
.multicommand = default_spi_send_multicommand,
.read = default_spi_read,
.write_256 = default_spi_write_256,
.write_aai = default_spi_write_aai,
.features = SPI_MASTER_4BA,
};
static int jlink_spi_shutdown(void *data)
{
struct jlink_spi_data *jlink_data = data;
@ -181,6 +168,19 @@ static int jlink_spi_shutdown(void *data)
return 0;
}
static const struct spi_master spi_master_jlink_spi = {
/* Maximum data read size in one go (excluding opcode+address). */
.max_data_read = JTAG_MAX_TRANSFER_SIZE - 5,
/* Maximum data write size in one go (excluding opcode+address). */
.max_data_write = JTAG_MAX_TRANSFER_SIZE - 5,
.command = jlink_spi_send_command,
.multicommand = default_spi_send_multicommand,
.read = default_spi_read,
.write_256 = default_spi_write_256,
.write_aai = default_spi_write_aai,
.features = SPI_MASTER_4BA,
};
static int jlink_spi_init(void)
{
char *arg;

View File

@ -410,16 +410,6 @@ static int lspcon_i2c_spi_write_aai(struct flashctx *flash, const uint8_t *buf,
return SPI_GENERIC_ERROR;
}
static const struct spi_master spi_master_i2c_lspcon = {
.max_data_read = 16,
.max_data_write = 12,
.command = lspcon_i2c_spi_send_command,
.multicommand = default_spi_send_multicommand,
.read = lspcon_i2c_spi_read,
.write_256 = lspcon_i2c_spi_write_256,
.write_aai = lspcon_i2c_spi_write_aai,
};
static int lspcon_i2c_spi_shutdown(void *data)
{
int ret = 0;
@ -436,6 +426,16 @@ static int lspcon_i2c_spi_shutdown(void *data)
return ret;
}
static const struct spi_master spi_master_i2c_lspcon = {
.max_data_read = 16,
.max_data_write = 12,
.command = lspcon_i2c_spi_send_command,
.multicommand = default_spi_send_multicommand,
.read = lspcon_i2c_spi_read,
.write_256 = lspcon_i2c_spi_write_256,
.write_aai = lspcon_i2c_spi_write_aai,
};
static int lspcon_i2c_spi_init(void)
{
int fd = i2c_open_from_programmer_params(REGISTER_ADDRESS, 0);

View File

@ -340,16 +340,6 @@ static int parse_voltage(char *voltage)
return millivolt;
}
static const struct spi_master spi_master_pickit2 = {
.max_data_read = 40,
.max_data_write = 40,
.command = pickit2_spi_send_command,
.multicommand = default_spi_send_multicommand,
.read = default_spi_read,
.write_256 = default_spi_write_256,
.write_aai = default_spi_write_aai,
};
static int pickit2_shutdown(void *data)
{
struct pickit2_spi_data *pickit2_data = data;
@ -388,6 +378,16 @@ static int pickit2_shutdown(void *data)
return ret;
}
static const struct spi_master spi_master_pickit2 = {
.max_data_read = 40,
.max_data_write = 40,
.command = pickit2_spi_send_command,
.multicommand = default_spi_send_multicommand,
.read = default_spi_read,
.write_256 = default_spi_write_256,
.write_aai = default_spi_write_aai,
};
static int pickit2_spi_init(void)
{
uint8_t buf[CMD_LENGTH] = {

View File

@ -410,16 +410,6 @@ static int realtek_mst_i2c_spi_write_aai(struct flashctx *flash, const uint8_t *
return SPI_GENERIC_ERROR;
}
static const struct spi_master spi_master_i2c_realtek_mst = {
.max_data_read = 16,
.max_data_write = 8,
.command = realtek_mst_i2c_spi_send_command,
.multicommand = default_spi_send_multicommand,
.read = realtek_mst_i2c_spi_read,
.write_256 = realtek_mst_i2c_spi_write_256,
.write_aai = realtek_mst_i2c_spi_write_aai,
};
static int realtek_mst_i2c_spi_shutdown(void *data)
{
int ret = 0;
@ -442,6 +432,16 @@ static int realtek_mst_i2c_spi_shutdown(void *data)
return ret;
}
static const struct spi_master spi_master_i2c_realtek_mst = {
.max_data_read = 16,
.max_data_write = 8,
.command = realtek_mst_i2c_spi_send_command,
.multicommand = default_spi_send_multicommand,
.read = realtek_mst_i2c_spi_read,
.write_256 = realtek_mst_i2c_spi_write_256,
.write_aai = realtek_mst_i2c_spi_write_aai,
};
static int get_params(int *reset, int *enter_isp)
{
char *reset_str = NULL, *isp_str = NULL;

View File

@ -570,6 +570,17 @@ static int promontory_read_memmapped(struct flashctx *flash, uint8_t *buf,
return 0;
}
static int sb600spi_shutdown(void *data)
{
struct sb600spi_data *sb600_data = data;
struct flashctx *flash = sb600_data->flash;
if (flash)
finalize_flash_access(flash);
free(data);
return 0;
}
static const struct spi_master spi_master_sb600 = {
.max_data_read = FIFO_SIZE_OLD,
.max_data_write = FIFO_SIZE_OLD - 3,
@ -600,17 +611,6 @@ static const struct spi_master spi_master_promontory = {
.write_aai = default_spi_write_aai,
};
static int sb600spi_shutdown(void *data)
{
struct sb600spi_data *sb600_data = data;
struct flashctx *flash = sb600_data->flash;
if (flash)
finalize_flash_access(flash);
free(data);
return 0;
}
int sb600_probe_spi(struct pci_dev *dev)
{
struct pci_dev *smbus_dev;

View File

@ -394,6 +394,25 @@ static int serprog_spi_send_command(const struct flashctx *flash,
return ret;
}
static int serprog_shutdown(void *data)
{
if ((sp_opbuf_usage) || (sp_max_write_n && sp_write_n_bytes))
if (sp_execute_opbuf() != 0)
msg_pwarn("Could not flush command buffer.\n");
if (sp_check_commandavail(S_CMD_S_PIN_STATE)) {
uint8_t dis = 0;
if (sp_docommand(S_CMD_S_PIN_STATE, 1, &dis, 0, NULL) == 0)
msg_pdbg(MSGHEADER "Output drivers disabled\n");
else
msg_pwarn(MSGHEADER "%s: Warning: could not disable output buffers\n", __func__);
}
/* FIXME: fix sockets on windows(?), especially closing */
serialport_shutdown(&sp_fd);
if (sp_max_write_n)
free(sp_write_n_buf);
return 0;
}
static struct spi_master spi_master_serprog = {
.features = SPI_MASTER_4BA,
.max_data_read = MAX_DATA_READ_UNLIMITED,
@ -518,25 +537,6 @@ static const struct par_master par_master_serprog = {
.chip_writen = fallback_chip_writen,
};
static int serprog_shutdown(void *data)
{
if ((sp_opbuf_usage) || (sp_max_write_n && sp_write_n_bytes))
if (sp_execute_opbuf() != 0)
msg_pwarn("Could not flush command buffer.\n");
if (sp_check_commandavail(S_CMD_S_PIN_STATE)) {
uint8_t dis = 0;
if (sp_docommand(S_CMD_S_PIN_STATE, 1, &dis, 0, NULL) == 0)
msg_pdbg(MSGHEADER "Output drivers disabled\n");
else
msg_pwarn(MSGHEADER "%s: Warning: could not disable output buffers\n", __func__);
}
/* FIXME: fix sockets on windows(?), especially closing */
serialport_shutdown(&sp_fd);
if (sp_max_write_n)
free(sp_write_n_buf);
return 0;
}
static enum chipbustype serprog_buses_supported = BUS_NONE;
static int serprog_init(void)

View File

@ -177,6 +177,12 @@ static int wbsio_spi_read(struct flashctx *flash, uint8_t *buf,
return 0;
}
static int wbsio_spi_shutdown(void *data)
{
free(data);
return 0;
}
static const struct spi_master spi_master_wbsio = {
.max_data_read = MAX_DATA_UNSPECIFIED,
.max_data_write = MAX_DATA_UNSPECIFIED,
@ -187,12 +193,6 @@ static const struct spi_master spi_master_wbsio = {
.write_aai = spi_chip_write_1,
};
static int wbsio_spi_shutdown(void *data)
{
free(data);
return 0;
}
int wbsio_check_for_spi(void)
{
uint16_t wbsio_spibase = 0;