Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sys Refactor flash and nand driver, so we can reuse the io t...



details:   https://anonhg.NetBSD.org/src/rev/85a59ec59f3f
branches:  trunk
changeset: 766604:85a59ec59f3f
user:      ahoka <ahoka%NetBSD.org@localhost>
date:      Tue Jun 28 18:14:11 2011 +0000

description:
Refactor flash and nand driver, so we can reuse the io thread code
in the future nor driver (and any other future driver).

Also simplify some of the code in the process, eg. saner flash attachment.

diffstat:

 sys/dev/flash/files.flash  |    3 +-
 sys/dev/flash/flash.c      |   69 +++---
 sys/dev/flash/flash.h      |   51 +---
 sys/dev/flash/flash_io.c   |  419 +++++++++++++++++++++++++++++++++++++++++++++
 sys/dev/flash/flash_io.h   |   24 ++
 sys/dev/nand/files.nand    |    3 +-
 sys/dev/nand/nand.c        |  123 ++----------
 sys/dev/nand/nand.h        |    7 +-
 sys/dev/nand/nand_io.c     |  367 ---------------------------------------
 sys/modules/flash/Makefile |    4 +-
 sys/modules/nand/Makefile  |    3 +-
 11 files changed, 528 insertions(+), 545 deletions(-)

diffs (truncated from 1436 to 300 lines):

diff -r b5814d101c51 -r 85a59ec59f3f sys/dev/flash/files.flash
--- a/sys/dev/flash/files.flash Tue Jun 28 17:33:47 2011 +0000
+++ b/sys/dev/flash/files.flash Tue Jun 28 18:14:11 2011 +0000
@@ -1,9 +1,10 @@
-# $NetBSD: files.flash,v 1.1 2011/02/26 18:07:30 ahoka Exp $
+# $NetBSD: files.flash,v 1.2 2011/06/28 18:14:11 ahoka Exp $
 
 define flashbus        { [offset = 0], [size = 0], [readonly = 0] }
 
 device flash
 attach flash at flashbus
 file   dev/flash/flash.c               flash
+file   dev/flash/flash_io.c            flash
 
 defflag opt_flash.h                    FLASH_STATIC_PARTITIONS
diff -r b5814d101c51 -r 85a59ec59f3f sys/dev/flash/flash.c
--- a/sys/dev/flash/flash.c     Tue Jun 28 17:33:47 2011 +0000
+++ b/sys/dev/flash/flash.c     Tue Jun 28 18:14:11 2011 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: flash.c,v 1.6 2011/06/28 07:00:17 ahoka Exp $  */
+/*     $NetBSD: flash.c,v 1.7 2011/06/28 18:14:11 ahoka Exp $  */
 
 /*-
  * Copyright (c) 2011 Department of Software Engineering,
@@ -37,7 +37,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: flash.c,v 1.6 2011/06/28 07:00:17 ahoka Exp $");
+__KERNEL_RCSID(0, "$NetBSD: flash.c,v 1.7 2011/06/28 18:14:11 ahoka Exp $");
 
 #include <sys/param.h>
 #include <sys/types.h>
@@ -61,14 +61,8 @@
 #include <sys/flashio.h>
 #include "flash.h"
 
-#define FLASH_DEBUG 1
 #ifdef FLASH_DEBUG
-#define DPRINTF(x)     if (flashdebug) printf x
-#define DPRINTFN(n,x)  if (flashdebug>(n)) printf x
-int    flashdebug = FLASH_DEBUG;
-#else
-#define DPRINTF(x)
-#define DPRINTFN(n,x)
+int flashdebug = FLASH_DEBUG;
 #endif
 
 extern struct cfdriver flash_cd;
@@ -146,9 +140,10 @@
        sc->sc_dev = self;
        sc->sc_parent_dev = parent;
        sc->flash_if = faa->flash_if;
+       sc->sc_partinfo = faa->partinfo;
        sc->hw_softc = device_private(parent);
 
-       format_bytes(pbuf[0], sizeof(pbuf[0]), sc->flash_if->size);
+       format_bytes(pbuf[0], sizeof(pbuf[0]), sc->sc_partinfo.part_size);
        format_bytes(pbuf[1], sizeof(pbuf[1]), sc->flash_if->erasesize);
 
        aprint_naive("\n");
@@ -168,10 +163,10 @@
 
        aprint_normal_dev(sc->sc_dev,
            "size: %#jx, offset: %#jx",
-           (uintmax_t )sc->flash_if->partition.part_size,
-           (uintmax_t )sc->flash_if->partition.part_offset);
+           (uintmax_t )sc->sc_partinfo.part_size,
+           (uintmax_t )sc->sc_partinfo.part_offset);
 
-       if (sc->flash_if->partition.part_flags & FLASH_PART_READONLY) {
+       if (sc->sc_partinfo.part_flags & FLASH_PART_READONLY) {
                sc->sc_readonly = true;
                aprint_normal(", read only");
        } else {
@@ -180,7 +175,7 @@
 
        aprint_normal("\n");
 
-       if (sc->flash_if->partition.part_size == 0) {
+       if (sc->sc_partinfo.part_size == 0) {
                aprint_error_dev(self,
                    "partition size must be larger than 0\n");
                return;
@@ -271,7 +266,7 @@
        int unit = minor(dev);
        struct flash_softc *sc;
 
-       DPRINTFN(1, ("flash: opening device unit %d\n", unit));
+       FLDPRINTFN(1, ("flash: opening device unit %d\n", unit));
 
        if ((sc = device_lookup_private(&flash_cd, unit)) == NULL)
                return ENXIO;
@@ -295,7 +290,7 @@
        struct flash_softc *sc;
        int err;
 
-       DPRINTFN(1, ("flash: closing flash device unit %d\n", unit));
+       FLDPRINTFN(1, ("flash: closing flash device unit %d\n", unit));
 
        if ((sc = device_lookup_private(&flash_cd, unit)) == NULL)
                return ENXIO;
@@ -348,7 +343,7 @@
        }
 
        flash_if = sc->flash_if;
-       part = &flash_if->partition;
+       part = &sc->sc_partinfo;
 
        /* divider */
        KASSERT(flash_if->writesize != 0);
@@ -371,7 +366,7 @@
                goto done;
        }
 
-       device_blks = sc->flash_if->size / DEV_BSIZE;
+       device_blks = sc->sc_partinfo.part_size / DEV_BSIZE;
        KASSERT(part->part_offset % DEV_BSIZE == 0);
        bp->b_rawblkno = bp->b_blkno + (part->part_offset / DEV_BSIZE);
 
@@ -455,7 +450,7 @@
        case FLASH_DUMP:
                dp = data;
                offset = dp->dp_block * sc->flash_if->erasesize;
-               DPRINTF(("Reading from block: %jd len: %jd\n",
+               FLDPRINTF(("Reading from block: %jd len: %jd\n",
                        (intmax_t )dp->dp_block, (intmax_t )dp->dp_len));
                err = flash_read(sc->sc_parent_dev, offset, dp->dp_len,
                    &retlen, dp->dp_buf);
@@ -473,7 +468,7 @@
                ip->ip_page_size = sc->flash_if->page_size;
                ip->ip_erase_size = sc->flash_if->erasesize;
                ip->ip_flash_type = sc->flash_if->type;
-               ip->ip_flash_size = sc->flash_if->size;
+               ip->ip_flash_size = sc->sc_partinfo.part_size;
                break;
        default:
                err = ENODEV;
@@ -537,9 +532,9 @@
 }
 
 static inline flash_off_t
-flash_get_part_offset(struct flash_softc *fl, size_t poffset)
+flash_get_part_offset(struct flash_softc *sc, size_t poffset)
 {
-       return fl->flash_if->partition.part_offset + poffset;
+       return sc->sc_partinfo.part_offset + poffset;
 }
 
 int
@@ -553,11 +548,11 @@
                return EACCES;
 
        /* adjust for flash partition */
-       e.ei_addr += sc->flash_if->partition.part_offset;
+       e.ei_addr += sc->sc_partinfo.part_offset;
 
        /* bounds check for flash partition */
-       if (e.ei_addr + e.ei_len > sc->flash_if->partition.part_size +
-           sc->flash_if->partition.part_offset)
+       if (e.ei_addr + e.ei_len > sc->sc_partinfo.part_size +
+           sc->sc_partinfo.part_offset)
                return EINVAL;
 
        return sc->flash_if->erase(device_parent(self), &e);
@@ -569,10 +564,10 @@
 {
        struct flash_softc *sc = device_private(self);
 
-       offset += sc->flash_if->partition.part_offset;
+       offset += sc->sc_partinfo.part_offset;
 
-       if (offset + len > sc->flash_if->partition.part_size +
-           sc->flash_if->partition.part_offset)
+       if (offset + len > sc->sc_partinfo.part_size +
+           sc->sc_partinfo.part_offset)
                return EINVAL;
 
        return sc->flash_if->read(device_parent(self),
@@ -588,10 +583,10 @@
        if (sc->sc_readonly)
                return EACCES;
 
-       offset += sc->flash_if->partition.part_offset;
+       offset += sc->sc_partinfo.part_offset;
 
-       if (offset + len > sc->flash_if->partition.part_size +
-           sc->flash_if->partition.part_offset)
+       if (offset + len > sc->sc_partinfo.part_size +
+           sc->sc_partinfo.part_offset)
                return EINVAL;
 
        return sc->flash_if->write(device_parent(self),
@@ -606,11 +601,11 @@
        if (sc->sc_readonly)
                return EACCES;
 
-       offset += sc->flash_if->partition.part_offset;
+       offset += sc->sc_partinfo.part_offset;
 
        if (offset + sc->flash_if->erasesize >=
-           sc->flash_if->partition.part_size +
-           sc->flash_if->partition.part_offset)
+           sc->sc_partinfo.part_size +
+           sc->sc_partinfo.part_offset)
                return EINVAL;
 
        return sc->flash_if->block_markbad(device_parent(self), offset);
@@ -621,11 +616,11 @@
 {
        struct flash_softc *sc = device_private(self);
 
-       offset += sc->flash_if->partition.part_offset;
+       offset += sc->sc_partinfo.part_offset;
 
        if (offset + sc->flash_if->erasesize >
-           sc->flash_if->partition.part_size +
-           sc->flash_if->partition.part_offset)
+           sc->sc_partinfo.part_size +
+           sc->sc_partinfo.part_offset)
                return EINVAL;
 
        return sc->flash_if->block_isbad(device_parent(self), offset, bad);
diff -r b5814d101c51 -r 85a59ec59f3f sys/dev/flash/flash.h
--- a/sys/dev/flash/flash.h     Tue Jun 28 17:33:47 2011 +0000
+++ b/sys/dev/flash/flash.h     Tue Jun 28 18:14:11 2011 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: flash.h,v 1.3 2011/04/04 14:25:09 ahoka Exp $  */
+/*     $NetBSD: flash.h,v 1.4 2011/06/28 18:14:11 ahoka Exp $  */
 
 /*-
  * Copyright (c) 2011 Department of Software Engineering,
@@ -41,6 +41,21 @@
 #include <sys/buf.h>
 #include <sys/flashio.h>
 
+#define FLASH_DEBUG 1
+#ifdef FLASH_DEBUG
+#define FLDPRINTF(x)   if (flashdebug) printf x
+#define FLDPRINTFN(n,x)        if (flashdebug>(n)) printf x
+#else
+#define FLDPRINTF(x)
+#define FLDPRINTFN(n,x)
+#endif
+
+struct flash_partition {
+       flash_off_t part_offset;
+       flash_size_t part_size;
+       int part_flags;
+};
+
 /**
  *  flash_softc - private structure for flash layer driver
  */
@@ -50,12 +65,14 @@
        device_t sc_parent_dev;         /* Hardware (parent) device */
        void *hw_softc;                 /* Hardware device private softc */
        struct flash_interface *flash_if;       /* Hardware interface */
+       struct flash_partition sc_partinfo;     /* partition information */
 
        bool sc_readonly;               /* read only flash device */
 };
 
 struct flash_attach_args {
        struct flash_interface *flash_if;       /* Hardware interface */
+       struct flash_partition partinfo;
 };
 
 device_t flash_attach_mi(struct flash_interface *, device_t);
@@ -65,12 +82,6 @@
 
 /**
  * struct erase_instruction - instructions to erase a flash eraseblock
- * @fd: flash descriptor
- * @addr: start address of the erase operation
- * @len: the erase length
- * @callback: callback operation, called when erase finished
- * @priv: private data
- * @state: the erase operation's result
  */
 struct flash_erase_instruction {
        flash_off_t ei_addr;
@@ -85,25 +96,8 @@
        FLASH_PART_FILESYSTEM   = (1<<2)
 };
 
-struct flash_partition {
-       flash_off_t part_offset;
-       flash_off_t part_size;
-       int part_flags;
-};
-
 /**
  * struct flash_interface - interface for flash operations
- * @type: type of flash device
- * @size: size of flash
- * @page_size: page size of flash
- * @erasesize: erase size of flash
- * @writesize: minimum write size of flash
- * @minor: minor number of the character device attached to this driver



Home | Main Index | Thread Index | Old Index