it87spi: Request memory mapping locally
Our SPI chip drivers are not aware of any memory mapping. However, two
of our SPI master drivers that implement an LPC-to-SPI bridge make use
of the memory mapping originally intended for memory mapped flash chips.
This unnecessarily breaks the abstraction in core flashprog code. There
is no other component than the master driver involved with the mapping,
hence we can simply perform it locally in this driver.
The driver already assumed a maximum memory mapped space of 512KiB. We
always try to map this whole space and than adapt the address offsets
accordingly.
Change-Id: I1cd828d3286ce0f7a02d15b035df368c67e0b2db
Signed-off-by: Nico Huber <nico.h@gmx.de>
Reviewed-on: https://review.sourcearcade.org/c/flashprog/+/72519
diff --git a/it87spi.c b/it87spi.c
index cd3ccef..6dfbe5c 100644
--- a/it87spi.c
+++ b/it87spi.c
@@ -32,6 +32,9 @@
#define ITE_SUPERIO_PORT1 0x2e
#define ITE_SUPERIO_PORT2 0x4e
+const size_t it87spi_max_mmapped = 512*KiB; /* maximum of memory mapped flash this driver can handle */
+static unsigned char *it87spi_mmapped_flash;
+
static uint16_t it8716f_flashport = 0;
/* use fast 33MHz SPI (<>0) or slow 16MHz (0) */
static int fast_spi = 1;
@@ -220,6 +223,12 @@
}
free(param);
exit_conf_mode_ite(port);
+
+ it87spi_mmapped_flash = rphysmap("it87spi memory mapped SPI",
+ 0xffffffff - it87spi_max_mmapped + 1, it87spi_max_mmapped);
+ if (it87spi_mmapped_flash == ERROR_PTR)
+ return 1;
+
it8716f_flashport = flashport;
if (internal_buses_supported & BUS_SPI)
msg_pdbg("Overriding chipset SPI with IT87 SPI.\n");
@@ -337,7 +346,8 @@
{
unsigned int i;
int result;
- chipaddr bios = flash->virtual_memory;
+ unsigned char *const bios = it87spi_mmapped_flash +
+ it87spi_max_mmapped - flashprog_flash_getsize(flash);
result = spi_write_enable(flash);
if (result)
@@ -380,10 +390,12 @@
* the mainboard does not use IT87 SPI translation. This should be done
* via a programmer parameter for the internal programmer.
*/
- if ((flash->chip->total_size * 1024 > 512 * 1024)) {
+ if ((flash->chip->total_size * 1024 > it87spi_max_mmapped)) {
default_spi_read(flash, buf, start, len);
} else {
- mmio_readn((void *)(flash->virtual_memory + start), buf, len);
+ unsigned char *const bios = it87spi_mmapped_flash +
+ it87spi_max_mmapped - flashprog_flash_getsize(flash);
+ mmio_readn(bios + start, buf, len);
}
return 0;
@@ -403,7 +415,7 @@
* the mainboard does not use IT87 SPI translation. This should be done
* via a programmer parameter for the internal programmer.
*/
- if ((chip->total_size * 1024 > 512 * 1024) || (chip->page_size > 256)) {
+ if ((chip->total_size * 1024 > it87spi_max_mmapped) || (chip->page_size > 256)) {
spi_chip_write_1(flash, buf, start, len);
} else {
unsigned int lenhere;