Author: hailfinger Date: 2009-05-16 03:23:55 +0200 (Sat, 16 May 2009) New Revision: 517
Modified: trunk/flash.h trunk/flashrom.c trunk/internal.c trunk/nic3com.c Log: 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.
Signed-off-by: Carl-Daniel Hailfinger c-d.hailfinger.devel.2006@gmx.net Acked-by: Uwe Hermann uwe@hermann-uwe.de
Modified: trunk/flash.h =================================================================== --- trunk/flash.h 2009-05-15 23:36:23 UTC (rev 516) +++ trunk/flash.h 2009-05-16 01:23:55 UTC (rev 517) @@ -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 */
Modified: trunk/flashrom.c =================================================================== --- trunk/flashrom.c 2009-05-15 23:36:23 UTC (rev 516) +++ trunk/flashrom.c 2009-05-16 01:23:55 UTC (rev 517) @@ -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, },
{},
Modified: trunk/internal.c =================================================================== --- trunk/internal.c 2009-05-15 23:36:23 UTC (rev 516) +++ trunk/internal.c 2009-05-16 01:23:55 UTC (rev 517) @@ -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; +}
Modified: trunk/nic3com.c =================================================================== --- trunk/nic3com.c 2009-05-15 23:36:23 UTC (rev 516) +++ trunk/nic3com.c 2009-05-16 01:23:55 UTC (rev 517) @@ -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; -}