PERFORCE change 107427 for review
Warner Losh
imp at FreeBSD.org
Sat Oct 7 09:52:26 PDT 2006
http://perforce.freebsd.org/chv.cgi?CH=107427
Change 107427 by imp at imp_lighthouse on 2006/10/07 16:51:55
Add stubs for disk goo. Need to fill them in.
Affected files ...
.. //depot/projects/arm/src/sys/dev/flash/at45d.c#6 edit
Differences ...
==== //depot/projects/arm/src/sys/dev/flash/at45d.c#6 (text+ko) ====
@@ -27,15 +27,18 @@
#include <sys/param.h>
#include <sys/systm.h>
+#include <sys/bio.h>
#include <sys/bus.h>
#include <sys/conf.h>
#include <sys/gpio.h>
#include <sys/kernel.h>
+#include <sys/kthread.h>
#include <sys/lock.h>
#include <sys/mbuf.h>
#include <sys/malloc.h>
#include <sys/module.h>
#include <sys/mutex.h>
+#include <geom/geom_disk.h>
#include <dev/spibus/spi.h>
#include "spibus_if.h"
@@ -45,7 +48,9 @@
struct intr_config_hook config_intrhook;
device_t dev;
struct mtx sc_mtx;
- int dummy;
+ struct disk *disk;
+ struct proc *p;
+ struct bio_queue_head bio_queue;
};
#define AT45D_LOCK(_sc) mtx_lock(&(_sc)->sc_mtx)
@@ -59,6 +64,12 @@
static void at45d_delayed_attach(void *xsc);
+/* disk routines */
+static int at45d_open(struct disk *dp);
+static int at45d_close(struct disk *dp);
+static void at45d_strategy(struct bio *bp);
+static void at45d_task(void *arg);
+
#define CONTINUOUS_ARRAY_READ 0xE8
#define CONTINUOUS_ARRAY_READ_HF 0x0B
#define CONTINUOUS_ARRAY_READ_LF 0x03
@@ -343,9 +354,67 @@
printf("Reply is %#x %#x %#x %#x\n", buf[0], buf[1], buf[2], buf[3]);
at45d_wait_for_device_ready(sc->dev);
printf("Status is %#x\b", at45d_get_status(sc->dev));
+
+ sc->disk = disk_alloc();
+ sc->disk->d_open = at45d_open;
+ sc->disk->d_close = at45d_close;
+ sc->disk->d_strategy = at45d_strategy;
+ sc->disk->d_name = "flash/spi";
+ sc->disk->d_drv1 = sc;
+ sc->disk->d_maxsize = DFLTPHYS;
+ sc->disk->d_sectorsize = 1056; // XXX
+ sc->disk->d_mediasize = 8192 * 1056; // XXX
+ sc->disk->d_unit = device_get_unit(sc->dev);
+ disk_create(sc->disk, DISK_VERSION);
+ bioq_init(&sc->bio_queue);
+ kthread_create(&at45d_task, sc, &sc->p, 0, 0, "task: at45d flash");
+
config_intrhook_disestablish(&sc->config_intrhook);
}
+static int
+at45d_open(struct disk *dp)
+{
+ return 0;
+}
+
+static int
+at45d_close(struct disk *dp)
+{
+ return 0;
+}
+
+static void
+at45d_strategy(struct bio *bp)
+{
+ struct at45d_softc *sc;
+
+ sc = (struct at45d_softc *)bp->bio_disk->d_drv1;
+ AT45D_LOCK(sc);
+ bioq_disksort(&sc->bio_queue, bp);
+ wakeup(sc);
+ AT45D_UNLOCK(sc);
+}
+
+static void
+at45d_task(void *arg)
+{
+ struct at45d_softc *sc = (struct at45d_softc*)arg;
+ struct bio *bp;
+
+ for (;;) {
+ AT45D_LOCK(sc);
+ do {
+ bp = bioq_first(&sc->bio_queue);
+ if (bp == NULL)
+ msleep(sc, &sc->sc_mtx, PRIBIO, "jobqueue", 0);
+ } while (bp == NULL);
+ bioq_remove(&sc->bio_queue, bp);
+ AT45D_UNLOCK(sc);
+ }
+}
+
+
static devclass_t at45d_devclass;
static device_method_t at45d_methods[] = {
More information about the p4-projects
mailing list