drivers/spi/spi_flash: assume spi_flash read callback exists
spi_flash_erase() and spi_flash_write() already assume their
respective callbacks are supplied in the spi_flash_ops object.
Make the same assumption in spi_flash_read(). In order to do this
the spi_flash_ops objects from the drivers need to reference the
the previously used fallback read command, spi_flash_read_chunked().
This function is made global and renamed to spi_flash_cmd_read() for
consistency.
By doing this further dead code elimination can be achieved when the
spi flash drivers aren't included in the build.
A Hatch Chrome OS build achieves a further text segment reduction of
0.5KiB in verstage, romstage, and ramstage.
Change-Id: I7fee55e6ffc1983657c3adde025a0e8c9d12ca23
Signed-off-by: Aaron Durbin <adurbin@chromium.org>
Reviewed-on: https://review.coreboot.org/c/coreboot/+/38366
Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
Reviewed-by: Furquan Shaikh <furquan@google.com>
diff --git a/src/drivers/spi/adesto.c b/src/drivers/spi/adesto.c
index 5f46741..1339ed2 100644
--- a/src/drivers/spi/adesto.c
+++ b/src/drivers/spi/adesto.c
@@ -149,6 +149,7 @@
};
static const struct spi_flash_ops spi_flash_ops = {
+ .read = spi_flash_cmd_read,
.write = spi_flash_cmd_write_page_program,
.erase = spi_flash_cmd_erase,
};
diff --git a/src/drivers/spi/amic.c b/src/drivers/spi/amic.c
index 54c03c0..fdaf1ba 100644
--- a/src/drivers/spi/amic.c
+++ b/src/drivers/spi/amic.c
@@ -120,6 +120,7 @@
};
static const struct spi_flash_ops spi_flash_ops = {
+ .read = spi_flash_cmd_read,
.write = spi_flash_cmd_write_page_program,
.erase = spi_flash_cmd_erase,
};
diff --git a/src/drivers/spi/atmel.c b/src/drivers/spi/atmel.c
index 5e22eb6..64bc9f8 100644
--- a/src/drivers/spi/atmel.c
+++ b/src/drivers/spi/atmel.c
@@ -104,6 +104,7 @@
};
static const struct spi_flash_ops spi_flash_ops = {
+ .read = spi_flash_cmd_read,
.write = spi_flash_cmd_write_page_program,
.erase = spi_flash_cmd_erase,
};
diff --git a/src/drivers/spi/eon.c b/src/drivers/spi/eon.c
index 1f3cbf3..b2c7ddc 100644
--- a/src/drivers/spi/eon.c
+++ b/src/drivers/spi/eon.c
@@ -236,6 +236,7 @@
};
static const struct spi_flash_ops spi_flash_ops = {
+ .read = spi_flash_cmd_read,
.write = spi_flash_cmd_write_page_program,
.erase = spi_flash_cmd_erase,
.status = spi_flash_cmd_status,
diff --git a/src/drivers/spi/gigadevice.c b/src/drivers/spi/gigadevice.c
index 1f478a8..b78b830 100644
--- a/src/drivers/spi/gigadevice.c
+++ b/src/drivers/spi/gigadevice.c
@@ -165,6 +165,7 @@
};
static const struct spi_flash_ops spi_flash_ops = {
+ .read = spi_flash_cmd_read,
.write = spi_flash_cmd_write_page_program,
.erase = spi_flash_cmd_erase,
.status = spi_flash_cmd_status,
diff --git a/src/drivers/spi/macronix.c b/src/drivers/spi/macronix.c
index adf4f23..334404de 100644
--- a/src/drivers/spi/macronix.c
+++ b/src/drivers/spi/macronix.c
@@ -201,6 +201,7 @@
};
static const struct spi_flash_ops spi_flash_ops = {
+ .read = spi_flash_cmd_read,
.write = spi_flash_cmd_write_page_program,
.erase = spi_flash_cmd_erase,
.status = spi_flash_cmd_status,
diff --git a/src/drivers/spi/spansion.c b/src/drivers/spi/spansion.c
index 01911a0..3d2f39d 100644
--- a/src/drivers/spi/spansion.c
+++ b/src/drivers/spi/spansion.c
@@ -219,6 +219,7 @@
};
static const struct spi_flash_ops spi_flash_ops = {
+ .read = spi_flash_cmd_read,
.write = spi_flash_cmd_write_page_program,
.erase = spi_flash_cmd_erase,
.status = spi_flash_cmd_status,
diff --git a/src/drivers/spi/spi_flash.c b/src/drivers/spi/spi_flash.c
index 4a86146..8f3a829 100644
--- a/src/drivers/spi/spi_flash.c
+++ b/src/drivers/spi/spi_flash.c
@@ -127,7 +127,7 @@
/* Perform the read operation honoring spi controller fifo size, reissuing
* the read command until the full request completed. */
-static int spi_flash_read_chunked(const struct spi_flash *flash, u32 offset,
+int spi_flash_cmd_read(const struct spi_flash *flash, u32 offset,
size_t len, void *buf)
{
u8 cmd[5];
@@ -465,10 +465,7 @@
int spi_flash_read(const struct spi_flash *flash, u32 offset, size_t len,
void *buf)
{
- if (flash->ops->read)
- return flash->ops->read(flash, offset, len, buf);
-
- return spi_flash_read_chunked(flash, offset, len, buf);
+ return flash->ops->read(flash, offset, len, buf);
}
int spi_flash_write(const struct spi_flash *flash, u32 offset, size_t len,
diff --git a/src/drivers/spi/spi_flash_internal.h b/src/drivers/spi/spi_flash_internal.h
index 58172ce..ef756c7 100644
--- a/src/drivers/spi/spi_flash_internal.h
+++ b/src/drivers/spi/spi_flash_internal.h
@@ -66,6 +66,9 @@
int spi_flash_cmd_write_page_program(const struct spi_flash *flash, u32 offset,
size_t len, const void *buf);
+/* Read len bytes into buf at offset. */
+int spi_flash_cmd_read(const struct spi_flash *flash, u32 offset, size_t len, void *buf);
+
/* Manufacturer-specific probe functions */
int spi_flash_probe_spansion(const struct spi_slave *spi, u8 *idcode,
struct spi_flash *flash);
diff --git a/src/drivers/spi/sst.c b/src/drivers/spi/sst.c
index bcc4770..1fb6446 100644
--- a/src/drivers/spi/sst.c
+++ b/src/drivers/spi/sst.c
@@ -55,12 +55,14 @@
const void *buf);
static const struct spi_flash_ops spi_flash_ops_write_ai = {
+ .read = spi_flash_cmd_read,
.write = sst_write_ai,
.erase = spi_flash_cmd_erase,
.status = spi_flash_cmd_status,
};
static const struct spi_flash_ops spi_flash_ops_write_256 = {
+ .read = spi_flash_cmd_read,
.write = spi_flash_cmd_write_page_program,
.erase = spi_flash_cmd_erase,
.status = spi_flash_cmd_status,
diff --git a/src/drivers/spi/stmicro.c b/src/drivers/spi/stmicro.c
index 83d0749..3f1a78c 100644
--- a/src/drivers/spi/stmicro.c
+++ b/src/drivers/spi/stmicro.c
@@ -285,6 +285,7 @@
};
static const struct spi_flash_ops spi_flash_ops = {
+ .read = spi_flash_cmd_read,
.write = spi_flash_cmd_write_page_program,
.erase = spi_flash_cmd_erase,
};
diff --git a/src/drivers/spi/winbond.c b/src/drivers/spi/winbond.c
index b6735c0..68cf1a3 100644
--- a/src/drivers/spi/winbond.c
+++ b/src/drivers/spi/winbond.c
@@ -611,6 +611,7 @@
}
static const struct spi_flash_ops spi_flash_ops = {
+ .read = spi_flash_cmd_read,
.write = spi_flash_cmd_write_page_program,
.erase = spi_flash_cmd_erase,
.status = spi_flash_cmd_status,