Attention is currently required from: Edward O'Callaghan, Angel Pons, Anastasia Klimchuk.

Nico Huber would like Edward O'Callaghan, Angel Pons and Anastasia Klimchuk to review this change.

View Change

programmer: Smoothen register_spi_master() API

It was impossible to register a const struct spi_master that would
point to dynamically allocated `data`. Fix that so that we won't
have to create more mutable globals.

Change-Id: I0c753b3db050fb87d4bbe2301a7ead854f28456f
Signed-off-by: Nico Huber <nico.h@gmx.de>
---
M bitbang_spi.c
M buspirate_spi.c
M ch341a_spi.c
M dediprog.c
M digilent_spi.c
M dummyflasher.c
M ene_lpc.c
M ft2232_spi.c
M ichspi.c
M it85spi.c
M it87spi.c
M jlink_spi.c
M linux_spi.c
M lspcon_i2c_spi.c
M mec1308.c
M mstarddc_spi.c
M ni845x_spi.c
M pickit2_spi.c
M programmer.h
M raiden_debug_spi.c
M realtek_mst_i2c_spi.c
M sb600spi.c
M serprog.c
M spi.c
M stlinkv3_spi.c
M usbblaster_spi.c
M wbsio_spi.c
27 files changed, 33 insertions(+), 31 deletions(-)

git pull ssh://review.coreboot.org:29418/flashrom refs/changes/66/54066/1
diff --git a/bitbang_spi.c b/bitbang_spi.c
index b12d81a..bb89071 100644
--- a/bitbang_spi.c
+++ b/bitbang_spi.c
@@ -162,7 +162,7 @@
struct bitbang_spi_master_data *data = calloc(1, sizeof(struct bitbang_spi_master_data));
data->mst = master;
mst.data = data;
- register_spi_master(&mst);
+ register_spi_master(&mst, NULL);
register_shutdown(bitbang_spi_shutdown, data);

/* Only mess with the bus if we're sure nobody else uses it. */
diff --git a/buspirate_spi.c b/buspirate_spi.c
index eee8daa..96e9673 100644
--- a/buspirate_spi.c
+++ b/buspirate_spi.c
@@ -655,7 +655,7 @@
return 1;
}

- register_spi_master(&spi_master_buspirate);
+ register_spi_master(&spi_master_buspirate, NULL);

return 0;
}
diff --git a/ch341a_spi.c b/ch341a_spi.c
index 84cc3fe..f84add4 100644
--- a/ch341a_spi.c
+++ b/ch341a_spi.c
@@ -506,7 +506,7 @@
goto dealloc_transfers;

register_shutdown(ch341a_spi_shutdown, NULL);
- register_spi_master(&spi_master_ch341a_spi);
+ register_spi_master(&spi_master_ch341a_spi, NULL);

return 0;

diff --git a/dediprog.c b/dediprog.c
index 4f48f47..a8fe19e 100644
--- a/dediprog.c
+++ b/dediprog.c
@@ -1274,7 +1274,7 @@
if (protocol() >= PROTOCOL_V2)
spi_master_dediprog.features |= SPI_MASTER_4BA;

- if (register_spi_master(&spi_master_dediprog) || dediprog_set_leds(LED_NONE))
+ if (register_spi_master(&spi_master_dediprog, NULL) || dediprog_set_leds(LED_NONE))
return 1;

return 0;
diff --git a/digilent_spi.c b/digilent_spi.c
index 0f7a9da..d9a63ad 100644
--- a/digilent_spi.c
+++ b/digilent_spi.c
@@ -445,7 +445,7 @@
goto close_handle;

register_shutdown(digilent_spi_shutdown, NULL);
- register_spi_master(&spi_master_digilent_spi);
+ register_spi_master(&spi_master_digilent_spi, NULL);

return 0;

diff --git a/dummyflasher.c b/dummyflasher.c
index ec5060d..74075f4 100644
--- a/dummyflasher.c
+++ b/dummyflasher.c
@@ -1030,7 +1030,7 @@
register_par_master(&par_master_dummy,
dummy_buses_supported & (BUS_PARALLEL | BUS_LPC | BUS_FWH));
if (dummy_buses_supported & BUS_SPI)
- register_spi_master(&spi_master_dummyflasher);
+ register_spi_master(&spi_master_dummyflasher, NULL);

return 0;
}
diff --git a/ene_lpc.c b/ene_lpc.c
index b66e96e..46f1783 100644
--- a/ene_lpc.c
+++ b/ene_lpc.c
@@ -572,7 +572,7 @@

if (register_shutdown(ene_leave_flash_mode, ctx_data))
goto init_err_cleanup_exit;
- register_spi_master(&spi_master_ene);
+ register_spi_master(&spi_master_ene, NULL);
msg_pdbg("%s: successfully initialized ene\n", __func__);

return 0;
diff --git a/ft2232_spi.c b/ft2232_spi.c
index bdc6e37..8d50d20 100644
--- a/ft2232_spi.c
+++ b/ft2232_spi.c
@@ -626,7 +626,7 @@
free(spi_data);
goto ftdi_err;
}
- register_spi_master(&spi_master_ft2232);
+ register_spi_master(&spi_master_ft2232, NULL);

return 0;

diff --git a/ichspi.c b/ichspi.c
index e45b39a..613f3fc 100644
--- a/ichspi.c
+++ b/ichspi.c
@@ -1812,7 +1812,7 @@
}
ich_init_opcodes(ich_gen);
ich_set_bbar(0, ich_gen);
- register_spi_master(&spi_master_ich7);
+ register_spi_master(&spi_master_ich7, NULL);
break;
case CHIPSET_ICH8:
default: /* Future version might behave the same */
@@ -2041,7 +2041,7 @@

register_opaque_master(&opaque_master_ich_hwseq);
} else {
- register_spi_master(&spi_master_ich9);
+ register_spi_master(&spi_master_ich9, NULL);
}
break;
}
@@ -2071,7 +2071,7 @@
/* Not sure if it speaks all these bus protocols. */
internal_buses_supported &= BUS_LPC | BUS_FWH;
ich_generation = CHIPSET_ICH7;
- register_spi_master(&spi_master_via);
+ register_spi_master(&spi_master_via, NULL);

msg_pdbg("0x00: 0x%04x (SPIS)\n", mmio_readw(ich_spibar + 0));
msg_pdbg("0x02: 0x%04x (SPIC)\n", mmio_readw(ich_spibar + 2));
diff --git a/it85spi.c b/it85spi.c
index 9817c2a..4d0f988 100644
--- a/it85spi.c
+++ b/it85spi.c
@@ -366,7 +366,7 @@
* a debug message about it.
*/
/* Set this as SPI controller. */
- register_spi_master(&spi_master_it85xx);
+ register_spi_master(&spi_master_it85xx, NULL);

return 0;
}
diff --git a/it87spi.c b/it87spi.c
index 868b479..0760ac8 100644
--- a/it87spi.c
+++ b/it87spi.c
@@ -426,7 +426,7 @@
if (internal_buses_supported & BUS_SPI)
msg_pdbg("Overriding chipset SPI with IT87 SPI.\n");
/* FIXME: Add the SPI bus or replace the other buses with it? */
- register_spi_master(&spi_master_it87xx);
+ register_spi_master(&spi_master_it87xx, NULL);
return 0;
}

diff --git a/jlink_spi.c b/jlink_spi.c
index 8b5cd2c..9fe44a5 100644
--- a/jlink_spi.c
+++ b/jlink_spi.c
@@ -472,7 +472,7 @@

if (register_shutdown(jlink_spi_shutdown, jlink_data))
goto init_err;
- register_spi_master(&spi_master_jlink_spi);
+ register_spi_master(&spi_master_jlink_spi, NULL);

return 0;

diff --git a/linux_spi.c b/linux_spi.c
index 4668e7f..82741bf 100644
--- a/linux_spi.c
+++ b/linux_spi.c
@@ -244,7 +244,7 @@
free(spi_data);
goto init_err;
}
- register_spi_master(&spi_master_linux);
+ register_spi_master(&spi_master_linux, NULL);
return 0;

init_err:
diff --git a/lspcon_i2c_spi.c b/lspcon_i2c_spi.c
index 096fb76..6b8dfe6 100644
--- a/lspcon_i2c_spi.c
+++ b/lspcon_i2c_spi.c
@@ -457,7 +457,7 @@
spi_master_i2c_lspcon.data = data;

ret |= register_shutdown(lspcon_i2c_spi_shutdown, data);
- ret |= register_spi_master(&spi_master_i2c_lspcon);
+ ret |= register_spi_master(&spi_master_i2c_lspcon, NULL);

return ret;
}
diff --git a/mec1308.c b/mec1308.c
index 1530d9b..70d2a79 100644
--- a/mec1308.c
+++ b/mec1308.c
@@ -509,7 +509,7 @@

if (register_shutdown(mec1308_shutdown, ctx_data))
goto init_err_cleanup_exit;
- register_spi_master(&spi_master_mec1308);
+ register_spi_master(&spi_master_mec1308, NULL);
msg_pdbg("%s(): successfully initialized mec1308\n", __func__);

return 0;
diff --git a/mstarddc_spi.c b/mstarddc_spi.c
index c041bd3..32b77cd 100644
--- a/mstarddc_spi.c
+++ b/mstarddc_spi.c
@@ -221,7 +221,7 @@
register_shutdown(mstarddc_spi_shutdown, NULL);

// Register programmer
- register_spi_master(&spi_master_mstarddc);
+ register_spi_master(&spi_master_mstarddc, NULL);
out:
free(i2c_device);
return ret;
diff --git a/ni845x_spi.c b/ni845x_spi.c
index 765da8a..df8ae0d 100644
--- a/ni845x_spi.c
+++ b/ni845x_spi.c
@@ -630,7 +630,7 @@
return 1;
}

- register_spi_master(&spi_programmer_ni845x);
+ register_spi_master(&spi_programmer_ni845x, NULL);

return 0;
}
diff --git a/pickit2_spi.c b/pickit2_spi.c
index 0bc17af..7d1b969 100644
--- a/pickit2_spi.c
+++ b/pickit2_spi.c
@@ -485,7 +485,7 @@
return 1;
}

- register_spi_master(&spi_master_pickit2);
+ register_spi_master(&spi_master_pickit2, NULL);

return 0;
}
diff --git a/programmer.h b/programmer.h
index 675a259..1b0cdb9 100644
--- a/programmer.h
+++ b/programmer.h
@@ -643,7 +643,7 @@
int default_spi_read(struct flashctx *flash, uint8_t *buf, unsigned int start, unsigned int len);
int default_spi_write_256(struct flashctx *flash, const uint8_t *buf, unsigned int start, unsigned int len);
int default_spi_write_aai(struct flashctx *flash, const uint8_t *buf, unsigned int start, unsigned int len);
-int register_spi_master(const struct spi_master *mst);
+int register_spi_master(const struct spi_master *mst, void *data);

/* The following enum is needed by ich_descriptor_tool and ich* code as well as in chipset_enable.c. */
enum ich_chipset {
diff --git a/raiden_debug_spi.c b/raiden_debug_spi.c
index bd7c054..c275851 100644
--- a/raiden_debug_spi.c
+++ b/raiden_debug_spi.c
@@ -1614,7 +1614,7 @@
return SPI_GENERIC_ERROR;
}

- register_spi_master(spi_config);
+ register_spi_master(spi_config, NULL);
register_shutdown(raiden_debug_spi_shutdown, spi_config);

return 0;
diff --git a/realtek_mst_i2c_spi.c b/realtek_mst_i2c_spi.c
index 64579e1..1863ac9 100644
--- a/realtek_mst_i2c_spi.c
+++ b/realtek_mst_i2c_spi.c
@@ -515,7 +515,7 @@
ret |= register_shutdown(realtek_mst_i2c_spi_shutdown, data);

spi_master_i2c_realtek_mst.data = data;
- ret |= register_spi_master(&spi_master_i2c_realtek_mst);
+ ret |= register_spi_master(&spi_master_i2c_realtek_mst, NULL);

return ret;
}
diff --git a/sb600spi.c b/sb600spi.c
index ef9da4b..43bf407 100644
--- a/sb600spi.c
+++ b/sb600spi.c
@@ -786,11 +786,11 @@

/* Starting with Yangtze the SPI controller got a different interface with a much bigger buffer. */
if (amd_gen < CHIPSET_YANGTZE)
- register_spi_master(&spi_master_sb600);
+ register_spi_master(&spi_master_sb600, NULL);
else if (amd_gen == CHIPSET_YANGTZE)
- register_spi_master(&spi_master_yangtze);
+ register_spi_master(&spi_master_yangtze, NULL);
else
- register_spi_master(&spi_master_promontory);
+ register_spi_master(&spi_master_promontory, NULL);

return 0;
}
diff --git a/serprog.c b/serprog.c
index d583a40..056d8d1 100644
--- a/serprog.c
+++ b/serprog.c
@@ -883,7 +883,7 @@
sp_streamed_transmit_bytes = 0;
sp_opbuf_usage = 0;
if (serprog_buses_supported & BUS_SPI)
- register_spi_master(&spi_master_serprog);
+ register_spi_master(&spi_master_serprog, NULL);
if (serprog_buses_supported & BUS_NONSPI)
register_par_master(&par_master_serprog, serprog_buses_supported & BUS_NONSPI);
return 0;
diff --git a/spi.c b/spi.c
index aa245d7..4ac3914 100644
--- a/spi.c
+++ b/spi.c
@@ -131,7 +131,7 @@
return flash->mst->spi.write_aai(flash, buf, start, len);
}

-int register_spi_master(const struct spi_master *mst)
+int register_spi_master(const struct spi_master *mst, void *data)
{
struct registered_master rmst = {0};

@@ -148,5 +148,7 @@

rmst.buses_supported = BUS_SPI;
rmst.spi = *mst;
+ if (data)
+ rmst.spi.data = data;
return register_master(&rmst);
}
diff --git a/stlinkv3_spi.c b/stlinkv3_spi.c
index 7e8336e..7712ec2 100644
--- a/stlinkv3_spi.c
+++ b/stlinkv3_spi.c
@@ -509,7 +509,7 @@
if (register_shutdown(stlinkv3_spi_shutdown, NULL))
goto err_exit;

- if (register_spi_master(&spi_programmer_stlinkv3))
+ if (register_spi_master(&spi_programmer_stlinkv3, NULL))
goto err_exit;

return 0;
diff --git a/usbblaster_spi.c b/usbblaster_spi.c
index 020c3bf..18f8278 100644
--- a/usbblaster_spi.c
+++ b/usbblaster_spi.c
@@ -210,7 +210,7 @@
return -1;
}

- register_spi_master(&spi_master_usbblaster);
+ register_spi_master(&spi_master_usbblaster, NULL);
return 0;
}

diff --git a/wbsio_spi.c b/wbsio_spi.c
index 632ff72..9eed495 100644
--- a/wbsio_spi.c
+++ b/wbsio_spi.c
@@ -216,7 +216,7 @@

register_shutdown(wbsio_spi_shutdown, data);
spi_master_wbsio.data = data;
- register_spi_master(&spi_master_wbsio);
+ register_spi_master(&spi_master_wbsio, NULL);

return 0;
}

To view, visit change 54066. To unsubscribe, or for help writing mail filters, visit settings.

Gerrit-Project: flashrom
Gerrit-Branch: master
Gerrit-Change-Id: I0c753b3db050fb87d4bbe2301a7ead854f28456f
Gerrit-Change-Number: 54066
Gerrit-PatchSet: 1
Gerrit-Owner: Nico Huber <nico.h@gmx.de>
Gerrit-Reviewer: Anastasia Klimchuk <aklm@chromium.org>
Gerrit-Reviewer: Angel Pons <th3fanbus@gmail.com>
Gerrit-Reviewer: Edward O'Callaghan <quasisec@chromium.org>
Gerrit-Attention: Edward O'Callaghan <quasisec@chromium.org>
Gerrit-Attention: Angel Pons <th3fanbus@gmail.com>
Gerrit-Attention: Anastasia Klimchuk <aklm@chromium.org>
Gerrit-MessageType: newchange