Use accessor functions for MMIO
Some MMIO accesses used volatile, others didn't (and risked
non-execution of side effects) and even with volatile, some accesses
looked dubious.
Since the MMIO accessor functions and the onboard flash accessor
functions are functionally identical (but have different signatures),
make the flash accessors wrappers for the MMIO accessors.
For some of the conversions, I used Coccinelle. Semantic patch follows:
@@ typedef uint8_t; expression a; volatile uint8_t *b; @@ - b[a] + *(b
+ a) @@ expression a; volatile uint8_t *b; @@ - *(b) |= (a); + *(b) =
*(b) | (a); @@ expression a; volatile uint8_t *b; @@ - *(b) = (a); +
mmio_writeb(a, b); @@ volatile uint8_t *b; @@ - *(b) + mmio_readb(b) @@
type T; T b; @@ ( mmio_readb | mmio_writeb ) (..., - (T) - (b) + b )
Corresponding to flashrom svn r524.
Signed-off-by: Carl-Daniel Hailfinger <c-d.hailfinger.devel.2006@gmx.net>
Uwe tested read, write, erase with this patch on a random board to make
sure nothing breaks.
Acked-by: Uwe Hermann <uwe@hermann-uwe.de>
diff --git a/sb600spi.c b/sb600spi.c
index eaf92d2..03e1ab8 100644
--- a/sb600spi.c
+++ b/sb600spi.c
@@ -37,7 +37,7 @@
} sb600_spi_controller;
sb600_spi_controller *spi_bar = NULL;
-uint8_t volatile *sb600_spibar;
+uint8_t *sb600_spibar;
int sb600_spi_read(struct flashchip *flash, uint8_t *buf)
{
@@ -91,17 +91,17 @@
void reset_internal_fifo_pointer(void)
{
- sb600_spibar[2] |= 0x10;
+ mmio_writeb(mmio_readb(sb600_spibar + 2) | 0x10, sb600_spibar + 2);
- while (sb600_spibar[0xD] & 0x7)
+ while (mmio_readb(sb600_spibar + 0xD) & 0x7)
printf("reset\n");
}
void execute_command(void)
{
- sb600_spibar[2] |= 1;
+ mmio_writeb(mmio_readb(sb600_spibar + 2) | 1, sb600_spibar + 2);
- while (sb600_spibar[2] & 1)
+ while (mmio_readb(sb600_spibar + 2) & 1)
;
}
@@ -131,8 +131,8 @@
return 1;
}
- sb600_spibar[0] = cmd;
- sb600_spibar[1] = readcnt << 4 | (writecnt);
+ mmio_writeb(cmd, sb600_spibar + 0);
+ mmio_writeb(readcnt << 4 | (writecnt), sb600_spibar + 1);
/* Before we use the FIFO, reset it first. */
reset_internal_fifo_pointer();
@@ -140,7 +140,7 @@
/* Send the write byte to FIFO. */
for (count = 0; count < writecnt; count++, writearr++) {
printf_debug(" [%x]", *writearr);
- sb600_spibar[0xC] = *writearr;
+ mmio_writeb(*writearr, sb600_spibar + 0xC);
}
printf_debug("\n");
@@ -160,13 +160,13 @@
reset_internal_fifo_pointer();
for (count = 0; count < writecnt; count++) {
- cmd = sb600_spibar[0xC]; /* Skip the byte we send. */
+ cmd = mmio_readb(sb600_spibar + 0xC); /* Skip the byte we send. */
printf_debug("[ %2x]", cmd);
}
- printf_debug("The FIFO pointer 6 is %d.\n", sb600_spibar[0xd] & 0x07);
+ printf_debug("The FIFO pointer 6 is %d.\n", mmio_readb(sb600_spibar + 0xd) & 0x07);
for (count = 0; count < readcnt; count++, readarr++) {
- *readarr = sb600_spibar[0xC];
+ *readarr = mmio_readb(sb600_spibar + 0xC);
printf_debug("[%02x]", *readarr);
}
printf_debug("\n");