Add generic 16 bit and 32 bit chip read/write emulation to the external flasher infrastructure
The emulation works by splitting 32 bit accesses into 16 bit accesses
and 16 bit accesses into to 8 bit accesses. That way, external flashers
can mix and match the amount of emulation they need.
Corresponding to flashrom svn r517.
Signed-off-by: Carl-Daniel Hailfinger <c-d.hailfinger.devel.2006@gmx.net>
Acked-by: Uwe Hermann <uwe@hermann-uwe.de>
diff --git a/flash.h b/flash.h
index 11e14c6..a51458e 100644
--- a/flash.h
+++ b/flash.h
@@ -611,6 +611,10 @@
uint8_t internal_chip_readb(const volatile void *addr);
uint16_t internal_chip_readw(const volatile void *addr);
uint32_t internal_chip_readl(const volatile void *addr);
+void fallback_chip_writew(uint16_t val, volatile void *addr);
+void fallback_chip_writel(uint32_t val, volatile void *addr);
+uint16_t fallback_chip_readw(const volatile void *addr);
+uint32_t fallback_chip_readl(const volatile void *addr);
#if defined(__FreeBSD__) || defined(__DragonFly__)
extern int io_fd;
#endif
@@ -635,11 +639,7 @@
void *nic3com_map(const char *descr, unsigned long phys_addr, size_t len);
void nic3com_unmap(void *virt_addr, size_t len);
void nic3com_chip_writeb(uint8_t val, volatile void *addr);
-void nic3com_chip_writew(uint16_t val, volatile void *addr);
-void nic3com_chip_writel(uint32_t val, volatile void *addr);
uint8_t nic3com_chip_readb(const volatile void *addr);
-uint16_t nic3com_chip_readw(const volatile void *addr);
-uint32_t nic3com_chip_readl(const volatile void *addr);
extern struct pcidev_status nics_3com[];
/* flashrom.c */
diff --git a/flashrom.c b/flashrom.c
index e00e678..5c5967a 100644
--- a/flashrom.c
+++ b/flashrom.c
@@ -69,11 +69,11 @@
.map_flash_region = nic3com_map,
.unmap_flash_region = nic3com_unmap,
.chip_readb = nic3com_chip_readb,
- .chip_readw = nic3com_chip_readw,
- .chip_readl = nic3com_chip_readl,
+ .chip_readw = fallback_chip_readw,
+ .chip_readl = fallback_chip_readl,
.chip_writeb = nic3com_chip_writeb,
- .chip_writew = nic3com_chip_writew,
- .chip_writel = nic3com_chip_writel,
+ .chip_writew = fallback_chip_writew,
+ .chip_writel = fallback_chip_writel,
},
{},
diff --git a/internal.c b/internal.c
index bbbf58b..f10d0d5 100644
--- a/internal.c
+++ b/internal.c
@@ -168,3 +168,34 @@
return *(volatile uint32_t *) addr;
}
+/* Little-endian fallback for drivers not supporting 16 bit accesses */
+void fallback_chip_writew(uint16_t val, volatile void *addr)
+{
+ chip_writeb(val & 0xff, addr);
+ chip_writeb((val >> 8) & 0xff, addr + 1);
+}
+
+/* Little-endian fallback for drivers not supporting 16 bit accesses */
+uint16_t fallback_chip_readw(const volatile void *addr)
+{
+ uint16_t val;
+ val = chip_readb(addr);
+ val |= chip_readb(addr + 1) << 8;
+ return val;
+}
+
+/* Little-endian fallback for drivers not supporting 32 bit accesses */
+void fallback_chip_writel(uint32_t val, volatile void *addr)
+{
+ chip_writew(val & 0xffff, addr);
+ chip_writew((val >> 16) & 0xffff, addr + 2);
+}
+
+/* Little-endian fallback for drivers not supporting 32 bit accesses */
+uint32_t fallback_chip_readl(const volatile void *addr)
+{
+ uint32_t val;
+ val = chip_readw(addr);
+ val |= chip_readw(addr + 2) << 16;
+ return val;
+}
diff --git a/nic3com.c b/nic3com.c
index a4b680a..84e506d 100644
--- a/nic3com.c
+++ b/nic3com.c
@@ -93,14 +93,6 @@
OUTB(val, io_base_addr + BIOS_ROM_DATA);
}
-void nic3com_chip_writew(uint16_t val, volatile void *addr)
-{
-}
-
-void nic3com_chip_writel(uint32_t val, volatile void *addr)
-{
-}
-
uint8_t nic3com_chip_readb(const volatile void *addr)
{
uint8_t val;
@@ -110,13 +102,3 @@
return val;
}
-
-uint16_t nic3com_chip_readw(const volatile void *addr)
-{
- return 0xffff;
-}
-
-uint32_t nic3com_chip_readl(const volatile void *addr)
-{
- return 0xffffffff;
-}