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>
Original-Reviewed-on: https://review.coreboot.org/c/flashrom/+/54066
Original-Reviewed-by: Anastasia Klimchuk <aklm@chromium.org>
Original-Reviewed-by: Angel Pons <th3fanbus@gmail.com>
Reviewed-on: https://review.coreboot.org/c/flashrom-stable/+/72179
Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
diff --git a/bitbang_spi.c b/bitbang_spi.c
index d22b6fc..f319957 100644
--- a/bitbang_spi.c
+++ b/bitbang_spi.c
@@ -103,7 +103,7 @@
/* Cast away `const`, but local code must ensure it's still treated as such. */
mst.data = (struct bitbang_spi_master *)master;
- register_spi_master(&mst);
+ register_spi_master(&mst, NULL);
/* Only mess with the bus if we're sure nobody else uses it. */
bitbang_spi_request_bus(master);
diff --git a/buspirate_spi.c b/buspirate_spi.c
index 2f58f0a..6c9ee4a 100644
--- a/buspirate_spi.c
+++ b/buspirate_spi.c
@@ -592,7 +592,7 @@
ret = 1;
goto init_err_cleanup_exit;
}
- 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 67a78ee..e26f9e9 100644
--- a/ch341a_spi.c
+++ b/ch341a_spi.c
@@ -507,7 +507,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 841cc02..69c4782 100644
--- a/dediprog.c
+++ b/dediprog.c
@@ -1309,7 +1309,7 @@
goto init_err_cleanup_exit;
spi_master_dediprog.data = dp_data;
- return register_spi_master(&spi_master_dediprog);
+ return register_spi_master(&spi_master_dediprog, NULL);
init_err_cleanup_exit:
dediprog_shutdown(dp_data);
diff --git a/digilent_spi.c b/digilent_spi.c
index bcd73ae..d39d686 100644
--- a/digilent_spi.c
+++ b/digilent_spi.c
@@ -447,7 +447,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/dirtyjtag_spi.c b/dirtyjtag_spi.c
index 5b08952..c9e921f 100644
--- a/dirtyjtag_spi.c
+++ b/dirtyjtag_spi.c
@@ -301,7 +301,7 @@
goto cleanup_libusb_handle;
spi_master_dirtyjtag_spi.data = djtag_data;
- return register_spi_master(&spi_master_dirtyjtag_spi);
+ return register_spi_master(&spi_master_dirtyjtag_spi, NULL);
cleanup_libusb_handle:
libusb_attach_kernel_driver(handle, 0);
diff --git a/dummyflasher.c b/dummyflasher.c
index 72d0259..01597f9 100644
--- a/dummyflasher.c
+++ b/dummyflasher.c
@@ -499,7 +499,7 @@
register_par_master(&par_master_dummy,
dummy_buses_supported & BUS_NONSPI);
if (dummy_buses_supported & BUS_SPI)
- register_spi_master(&spi_master_dummyflasher);
+ register_spi_master(&spi_master_dummyflasher, NULL);
return 0;
}
diff --git a/ft2232_spi.c b/ft2232_spi.c
index 1f813fb..2737dae 100644
--- a/ft2232_spi.c
+++ b/ft2232_spi.c
@@ -701,7 +701,7 @@
ret = -9;
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 0996d2d..929dcc4 100644
--- a/ichspi.c
+++ b/ichspi.c
@@ -1824,7 +1824,7 @@
}
ich_init_opcodes();
ich_set_bbar(0);
- register_spi_master(&spi_master_ich7);
+ register_spi_master(&spi_master_ich7, NULL);
break;
case CHIPSET_ICH8:
default: /* Future version might behave the same */
@@ -2062,7 +2062,7 @@
register_opaque_master(&opaque_master_ich_hwseq);
} else {
- register_spi_master(&spi_master_ich9);
+ register_spi_master(&spi_master_ich9, NULL);
}
break;
}
@@ -2092,7 +2092,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/it87spi.c b/it87spi.c
index 5713bde..0903911 100644
--- a/it87spi.c
+++ b/it87spi.c
@@ -224,7 +224,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 7fcfc35..ffa547d 100644
--- a/jlink_spi.c
+++ b/jlink_spi.c
@@ -518,7 +518,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 033c94a..697a8a2 100644
--- a/linux_spi.c
+++ b/linux_spi.c
@@ -192,7 +192,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/mstarddc_spi.c b/mstarddc_spi.c
index 9c53f14..460a382 100644
--- a/mstarddc_spi.c
+++ b/mstarddc_spi.c
@@ -146,7 +146,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 1df76c0..6e274ac 100644
--- a/ni845x_spi.c
+++ b/ni845x_spi.c
@@ -481,7 +481,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 9c78138..5d0b573 100644
--- a/pickit2_spi.c
+++ b/pickit2_spi.c
@@ -500,7 +500,7 @@
if (register_shutdown(pickit2_shutdown, pickit2_data))
goto init_err_cleanup_exit;
- register_spi_master(&spi_master_pickit2);
+ register_spi_master(&spi_master_pickit2, NULL);
return 0;
diff --git a/programmer.h b/programmer.h
index 9217c0d..f7ce7bc 100644
--- a/programmer.h
+++ b/programmer.h
@@ -328,7 +328,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/sb600spi.c b/sb600spi.c
index 7727118..3a1445a 100644
--- a/sb600spi.c
+++ b/sb600spi.c
@@ -701,9 +701,9 @@
/* 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
- register_spi_master(&spi_master_yangtze);
+ register_spi_master(&spi_master_yangtze, NULL);
return 0;
}
diff --git a/serprog.c b/serprog.c
index 7acba36..2626be1 100644
--- a/serprog.c
+++ b/serprog.c
@@ -704,7 +704,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 86141cc..5ee9a24 100644
--- a/spi.c
+++ b/spi.c
@@ -129,7 +129,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;
@@ -146,5 +146,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 68790cf..50b5c85 100644
--- a/stlinkv3_spi.c
+++ b/stlinkv3_spi.c
@@ -507,7 +507,7 @@
if (register_shutdown(stlinkv3_spi_shutdown, NULL))
goto init_err_cleanup_exit;
- if (register_spi_master(&spi_programmer_stlinkv3))
+ if (register_spi_master(&spi_programmer_stlinkv3, NULL))
return 1; /* shutdown function does cleanup */
return 0;
diff --git a/usbblaster_spi.c b/usbblaster_spi.c
index 5659535..8b442db 100644
--- a/usbblaster_spi.c
+++ b/usbblaster_spi.c
@@ -112,7 +112,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 9145814..d7c1b0b 100644
--- a/wbsio_spi.c
+++ b/wbsio_spi.c
@@ -85,7 +85,7 @@
msg_pdbg("%s: Winbond saved on 4 register bits so max chip size is "
"1024 kB!\n", __func__);
max_rom_decode.spi = 1024 * 1024;
- register_spi_master(&spi_master_wbsio);
+ register_spi_master(&spi_master_wbsio, NULL);
return 0;
}