2 * ----------------------------------------------------------------------------
3 * "THE BEER-WARE LICENSE" (Revision 42):
4 * <phk@FreeBSD.ORG> wrote this file. As long as you retain this notice you
5 * can do whatever you want with this stuff. If we meet some day, and you think
6 * this stuff is worth it, you can buy me a beer in return. Poul-Henning Kamp
7 * ----------------------------------------------------------------------------
9 * $FreeBSD: src/sys/contrib/dev/fla/fla.c,v 1.16 1999/12/08 04:45:16 ken Exp $
10 * $DragonFly: src/sys/contrib/dev/fla/Attic/fla.c,v 1.2 2003/06/17 04:28:20 dillon Exp $
15 #include <sys/param.h>
16 #include <sys/systm.h>
17 #include <sys/sysctl.h>
18 #include <sys/kernel.h>
20 #include <sys/malloc.h>
23 #include <sys/devicestat.h>
24 #include <sys/module.h>
25 #include <machine/clock.h>
26 #include <machine/resource.h>
30 #include <vm/vm_param.h>
33 #include <isa/isavar.h>
36 #include <machine/smp.h>
37 #define LEAVE() rel_mplock();
38 #define ENTER() get_mplock();
44 #include <contrib/dev/fla/msysosak.h>
46 MALLOC_DEFINE(M_FLA, "fla driver", "fla driver storage");
48 static int fla_debug = 0;
49 SYSCTL_INT(_debug, OID_AUTO, fladebug, CTLFLAG_RW, &fla_debug, 0, "");
51 #define CDEV_MAJOR 102
54 static d_strategy_t flastrategy;
55 static d_open_t flaopen;
56 static d_close_t flaclose;
57 static d_ioctl_t flaioctl;
59 static struct cdevsw fla_cdevsw = {
63 /* write */ physwrite,
67 /* strategy */ flastrategy,
72 /* flags */ D_DISK | D_CANFREE,
75 static struct cdevsw fladisk_cdevsw;
78 doc2k_malloc(int bytes)
80 return malloc(bytes, M_FLA, M_WAITOK);
90 doc2k_delay(unsigned msec)
96 doc2k_memcpy(void *dst, const void *src, unsigned len)
102 doc2k_memcmp(const void *dst, const void *src, unsigned len)
104 return (bcmp(src, dst, len));
108 doc2k_memset(void *dst, int c, unsigned len)
115 static struct fla_s {
119 struct doc2k_stat ds;
120 struct buf_queue_head buf_queue;
121 struct devstat stats;
127 flaopen(dev_t dev, int flag, int fmt, struct proc *p)
131 struct disklabel *dl;
134 printf("flaopen(%s %x %x %p)\n",
135 devtoname(dev), flag, fmt, p);
139 error = doc2k_open(sc->unit);
142 printf("doc2k_open(%d) -> err %d\n", sc->unit, error);
146 dl = &sc->disk.d_label;
147 bzero(dl, sizeof(*dl));
148 error = doc2k_size(sc->unit, &dl->d_secperunit,
149 &dl->d_ncylinders, &dl->d_ntracks, &dl->d_nsectors);
150 dl->d_secsize = DEV_BSIZE;
151 dl->d_secpercyl = dl->d_ntracks * dl->d_nsectors; /* XXX */
157 flaclose(dev_t dev, int flags, int fmt, struct proc *p)
163 printf("flaclose(%s %x %x %p)\n",
164 devtoname(dev), flags, fmt, p);
168 error = doc2k_close(sc->unit);
170 printf("doc2k_close(%d) -> err %d\n", sc->unit, error);
177 flaioctl(dev_t dev, u_long cmd, caddr_t addr, int flags, struct proc *p)
181 printf("flaioctl(%s %lx %p %x %p)\n",
182 devtoname(dev), cmd, addr, flags, p);
188 flastrategy(struct buf *bp)
193 enum doc2k_work what;
196 printf("flastrategy(%p) %s %lx, %d, %ld, %p)\n",
197 bp, devtoname(bp->b_dev), bp->b_flags, bp->b_blkno,
198 bp->b_bcount / DEV_BSIZE, bp->b_data);
200 sc = bp->b_dev->si_drv1;
204 bufqdisksort(&sc->buf_queue, bp);
214 bp = bufq_first(&sc->buf_queue);
216 bufq_remove(&sc->buf_queue, bp);
221 devstat_start_transaction(&sc->stats);
222 bp->b_resid = bp->b_bcount;
223 unit = dkunit(bp->b_dev);
225 if (bp->b_flags & B_FREEBUF)
227 else if (bp->b_flags & B_READ)
234 error = doc2k_rwe( unit, what, bp->b_pblkno,
235 bp->b_bcount / DEV_BSIZE, bp->b_data);
239 if (fla_debug > 1 || error) {
240 printf("fla%d: %d = rwe(%p, %d, %d, %d, %ld, %p)\n",
241 unit, error, bp, unit, what, bp->b_pblkno,
242 bp->b_bcount / DEV_BSIZE, bp->b_data);
246 bp->b_flags |= B_ERROR;
250 devstat_end_transaction_buf(&sc->stats, bp);
260 flaprobe (device_t dev)
266 unit = device_get_unit(dev);
269 /* This is slightly ugly */
270 i = doc2k_probe(unit, KERNBASE + 0xc0000, KERNBASE + 0xe0000);
274 i = doc2k_info(unit, &sc->ds);
278 bus_set_resource(dev, SYS_RES_MEMORY, 0,
279 sc->ds.window - KERNBASE, 8192);
285 flaattach (device_t dev)
288 int i, j, k, l, m, error;
291 unit = device_get_unit(dev);
294 error = doc2k_open(unit);
296 printf("doc2k_open(%d) -> err %d\n", unit, error);
300 error = doc2k_size(unit, &sc->nsect, &i, &j, &k );
302 printf("doc2k_size(%d) -> err %d\n", unit, error);
306 printf("fla%d: <%s %s>\n", unit, sc->ds.product, sc->ds.model);
308 error = doc2k_close(unit);
310 printf("doc2k_close(%d) -> err %d\n", unit, error);
314 m = 1024L * 1024L / DEV_BSIZE;
315 l = (sc->nsect * 10 + m/2) / m;
316 printf("fla%d: %d.%01dMB (%u sectors),"
317 " %d cyls, %d heads, %d S/T, 512 B/S\n",
318 unit, l / 10, l % 10, sc->nsect, i, j, k);
321 printf("fla%d: JEDEC=0x%x unitsize=%ld mediasize=%ld"
322 " chipsize=%ld interleave=%d window=%lx\n",
323 unit, sc->ds.type, sc->ds.unitSize, sc->ds.mediaSize,
324 sc->ds.chipSize, sc->ds.interleaving, sc->ds.window);
326 bufq_init(&sc->buf_queue);
328 devstat_add_entry(&softc[unit].stats, "fla", unit, DEV_BSIZE,
329 DEVSTAT_NO_ORDERED_TAGS,
330 DEVSTAT_TYPE_DIRECT | DEVSTAT_TYPE_IF_OTHER,
331 DEVSTAT_PRIORITY_DISK);
333 sc->dev = disk_create(unit, &sc->disk, 0, &fla_cdevsw, &fladisk_cdevsw);
334 sc->dev->si_drv1 = sc;
340 static device_method_t fla_methods[] = {
341 /* Device interface */
342 DEVMETHOD(device_probe, flaprobe),
343 DEVMETHOD(device_attach, flaattach),
347 static driver_t fladriver = {
350 sizeof(struct fla_s),
353 static devclass_t fla_devclass;
355 DRIVER_MODULE(fla, isa, fladriver, fla_devclass, 0, 0);