bcm47xxsflash: just use memcpy for reading
RFC PATCH 1/1 bcm47xxsflash: just use memcpy for reading
---
Still have to check it with aiaiai
--- drivers/mtd/devices/bcm47xxsflash.c | 31 ++----------------------------- 1 files changed, 2 insertions(+), 29 deletions(-)
drivers/mtd/devices/bcm47xxsflash.c +2 -29
@@ -14,41 +14,14 @@ static int bcm47xxsflash_read(struct mtd_info *mtd, loff_t from, size_t len, size_t *retlen, u_char *buf) { struct bcma_sflash *sflash = mtd->priv; -size_t bytes_read =0 ; -__iomem u8 *src = (__iomem u8 *)KSEG0ADDR (sflash->window + from); -int i; -size_t unaligned_before, unaligned_after;/* Check address range */ if ((from + len) > mtd->size)return -EINVAL ; - unaligned_before = from &0x3 ; - unaligned_after = (from + len) &0x3 ; +memcpy (buf, (void *)KSEG0ADDR (sflash->window + from), len); -for (i =0 ; i < unaligned_before; i++) { - *buf =readb (src); - buf++; - src++; - bytes_read++; - } -for (i = from - unaligned_before; i < from + len - unaligned_after; - i +=4 ) { - *(u32 *)buf =readl (src); - buf +=4 ; - src +=4 ; - bytes_read +=4 ; - } -for (i =0 ; i < unaligned_after; i++) { - *buf =readb (src); - buf++; - src++; - bytes_read++; - } - - *retlen = bytes_read; - -return 0 ; +return len; } static void bcm47xxsflash_fill_mtd(struct bcma_sflash *sflash,
Signature · 1 line
1.7.7
Quoted 16 lines · Rafał Miłecki
---
Still have to check it with aiaiai--- drivers/mtd/devices/bcm47xxsflash.c | 31 ++----------------------------- 1 files changed, 2 insertions(+), 29 deletions(-)drivers/mtd/devices/bcm47xxsflash.c +0
-2@@ -14,41 +14,14 @@ static int bcm47xxsflash_read(struct mtd_info *mtd, loff_t from, size_t len, size_t *retlen, u_char *buf) { struct bcma_sflash *sflash = mtd->priv; -size_t bytes_read =0 ; -__iomem u8 *src = (__iomem u8 *)KSEG0ADDR (sflash->window + from);
drivers/mtd/devices/bcm47xxsflash.c static int bcm47xxsflash_read(struct mtd_info *mtd, loff_t from, size_t len, · line 22
Quoted 10 lines
drivers/mtd/devices/bcm47xxsflash.c +1
-4-int i; -size_t unaligned_before, unaligned_after;/* Check address range */ if ((from + len) > mtd->size)return -EINVAL ; - unaligned_before = from &0x3 ; - unaligned_after = (from + len) &0x3 ; +memcpy (buf, (void *)KSEG0ADDR (sflash->window + from), len);
You should not access iomem with memcpy, there is a memcpy_fromio(), but it's an unoptimized readb loop on arm.
Marc
Quoted 29 lines
drivers/mtd/devices/bcm47xxsflash.c +1
-23-for (i =0 ; i < unaligned_before; i++) { - *buf =readb (src); - buf++; - src++; - bytes_read++; - } -for (i = from - unaligned_before; i < from + len - unaligned_after; - i +=4 ) { - *(u32 *)buf =readl (src); - buf +=4 ; - src +=4 ; - bytes_read +=4 ; - } -for (i =0 ; i < unaligned_after; i++) { - *buf =readb (src); - buf++; - src++; - bytes_read++; - } - - *retlen = bytes_read; - -return 0 ; +return len; } static void bcm47xxsflash_fill_mtd(struct bcma_sflash *sflash,
Signature · 4 lines
Pengutronix e.K. | Marc Kleine-Budde | Industrial Linux Solutions | Phone: +49-231-2826-924 | Vertretung West/Dortmund | Fax: +49-5121-206917-5555 | Amtsgericht Hildesheim, HRA 2686 | http://www.pengutronix.de |
2012/9/19 Marc Kleine-Budde <[email protected]>:
Quoted 24 lines · Rafał Miłecki
Quoted 23 lines
---
Still have to check it with aiaiai--- drivers/mtd/devices/bcm47xxsflash.c | 31 ++----------------------------- 1 files changed, 2 insertions(+), 29 deletions(-)drivers/mtd/devices/bcm47xxsflash.c +0
-4@@ -14,41 +14,14 @@ static int bcm47xxsflash_read(struct mtd_info *mtd, loff_t from, size_t len, size_t *retlen, u_char *buf) { struct bcma_sflash *sflash = mtd->priv; -size_t bytes_read =0 ; -__iomem u8 *src = (__iomem u8 *)KSEG0ADDR (sflash->window + from); -int i; -size_t unaligned_before, unaligned_after;/* Check address range */ if ((from + len) > mtd->size)return -EINVAL ;
Quoted 6 lines
drivers/mtd/devices/bcm47xxsflash.c static int bcm47xxsflash_read(struct mtd_info *mtd, loff_t from, size_t len, · line 22
Quoted 3 lines
drivers/mtd/devices/bcm47xxsflash.c +1
-2- unaligned_before = from &0x3 ; - unaligned_after = (from + len) &0x3 ; +memcpy (buf, (void *)KSEG0ADDR (sflash->window + from), len);You should not access iomem with memcpy, there is a
memcpy_fromio(), but it's an unoptimized readb loop on arm.
Sure, I can replace that with _fromio, which AFAIK is the same for mips.
I'm afraid access to the serial flash can't be really optimal. Saving is actually even worse, it requires some operations on BCMA core, polling for ready, etc.
Signature · 1 line
Rafał