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.12 2006/04/30 17:22:15 dillon Exp $
16 #include <sys/param.h>
17 #include <sys/systm.h>
18 #include <sys/sysctl.h>
19 #include <sys/kernel.h>
22 #include <sys/malloc.h>
25 #include <sys/devicestat.h>
26 #include <sys/module.h>
27 #include <machine/clock.h>
28 #include <machine/resource.h>
32 #include <vm/vm_param.h>
34 #include <sys/thread2.h>
37 #include <bus/isa/isavar.h>
40 #include <machine/smp.h>
41 #define LEAVE() rel_mplock();
42 #define ENTER() get_mplock();
48 #include <contrib/dev/fla/msysosak.h>
50 MALLOC_DEFINE(M_FLA, "fla driver", "fla driver storage");
52 static int fla_debug = 0;
53 SYSCTL_INT(_debug, OID_AUTO, fladebug, CTLFLAG_RW, &fla_debug, 0, "");
55 #define CDEV_MAJOR 102
58 static d_strategy_t flastrategy;
59 static d_open_t flaopen;
60 static d_close_t flaclose;
61 static d_ioctl_t flaioctl;
63 static struct cdevsw fla_cdevsw = {
66 /* flags */ D_DISK | D_CANFREE,
73 /* write */ physwrite,
77 /* strategy */ flastrategy,
83 doc2k_malloc(int bytes)
85 return malloc(bytes, M_FLA, M_WAITOK);
95 doc2k_delay(unsigned msec)
101 doc2k_memcpy(void *dst, const void *src, unsigned len)
103 bcopy(src, dst, len);
107 doc2k_memcmp(const void *dst, const void *src, unsigned len)
109 return (bcmp(src, dst, len));
113 doc2k_memset(void *dst, int c, unsigned len)
120 static struct fla_s {
124 struct doc2k_stat ds;
125 struct bio_queue_head bio_queue;
126 struct devstat stats;
132 flaopen(dev_t dev, int flag, int fmt, struct thread *td)
136 struct disklabel *dl;
139 printf("flaopen(%s %x %x %p)\n",
140 devtoname(dev), flag, fmt, td);
144 error = doc2k_open(sc->unit);
147 printf("doc2k_open(%d) -> err %d\n", sc->unit, error);
151 dl = &sc->disk.d_label;
152 bzero(dl, sizeof(*dl));
153 error = doc2k_size(sc->unit, &dl->d_secperunit,
154 &dl->d_ncylinders, &dl->d_ntracks, &dl->d_nsectors);
155 dl->d_secsize = DEV_BSIZE;
156 dl->d_secpercyl = dl->d_ntracks * dl->d_nsectors; /* XXX */
162 flaclose(dev_t dev, int flags, int fmt, struct thread *td)
168 printf("flaclose(%s %x %x %p)\n",
169 devtoname(dev), flags, fmt, td);
173 error = doc2k_close(sc->unit);
175 printf("doc2k_close(%d) -> err %d\n", sc->unit, error);
182 flaioctl(dev_t dev, u_long cmd, caddr_t addr, int flags, struct thread *td)
186 printf("flaioctl(%s %lx %p %x %p)\n",
187 devtoname(dev), cmd, addr, flags, td);
193 flastrategy(dev_t dev, struct bio *bio)
195 struct buf *bp = bio->bio_buf;
198 enum doc2k_work what;
201 printf("flastrategy(%p) %s %lx, %lld, %ld, %p)\n",
202 bp, devtoname(dev), bp->b_flags, bio->bio_offset,
203 bp->b_bcount, bp->b_data);
207 bio->bio_driver_info = dev;
209 bioqdisksort(&sc->bio_queue, bio);
217 bio = bioq_first(&sc->bio_queue);
222 bioq_remove(&sc->bio_queue, bio);
224 dev = bio->bio_driver_info;
226 devstat_start_transaction(&sc->stats);
227 bp->b_resid = bp->b_bcount;
231 case BUF_CMD_FREEBLKS:
241 panic("fla: bad b_cmd %d", bp->b_cmd);
246 error = doc2k_rwe(unit, what,
247 (unsigned)(bio->bio_offset >> DEV_BSHIFT),
248 bp->b_bcount / DEV_BSIZE, bp->b_data);
252 if (fla_debug > 1 || error) {
253 printf("fla%d: %d = rwe(%p, %d, %d, %lld, %ld, %p)\n",
254 unit, error, bp, unit, what, bio->bio_offset,
255 bp->b_bcount, bp->b_data);
259 bp->b_flags |= B_ERROR;
263 devstat_end_transaction_buf(&sc->stats, bp);
273 flaprobe (device_t dev)
279 unit = device_get_unit(dev);
282 /* This is slightly ugly */
283 i = doc2k_probe(unit, KERNBASE + 0xc0000, KERNBASE + 0xe0000);
287 i = doc2k_info(unit, &sc->ds);
291 bus_set_resource(dev, SYS_RES_MEMORY, 0,
292 sc->ds.window - KERNBASE, 8192);
298 flaattach (device_t dev)
301 int i, j, k, l, m, error;
304 unit = device_get_unit(dev);
307 error = doc2k_open(unit);
309 printf("doc2k_open(%d) -> err %d\n", unit, error);
313 error = doc2k_size(unit, &sc->nsect, &i, &j, &k );
315 printf("doc2k_size(%d) -> err %d\n", unit, error);
319 printf("fla%d: <%s %s>\n", unit, sc->ds.product, sc->ds.model);
321 error = doc2k_close(unit);
323 printf("doc2k_close(%d) -> err %d\n", unit, error);
327 m = 1024L * 1024L / DEV_BSIZE;
328 l = (sc->nsect * 10 + m/2) / m;
329 printf("fla%d: %d.%01dMB (%u sectors),"
330 " %d cyls, %d heads, %d S/T, 512 B/S\n",
331 unit, l / 10, l % 10, sc->nsect, i, j, k);
334 printf("fla%d: JEDEC=0x%x unitsize=%ld mediasize=%ld"
335 " chipsize=%ld interleave=%d window=%lx\n",
336 unit, sc->ds.type, sc->ds.unitSize, sc->ds.mediaSize,
337 sc->ds.chipSize, sc->ds.interleaving, sc->ds.window);
339 bioq_init(&sc->bio_queue);
341 devstat_add_entry(&softc[unit].stats, "fla", unit, DEV_BSIZE,
342 DEVSTAT_NO_ORDERED_TAGS,
343 DEVSTAT_TYPE_DIRECT | DEVSTAT_TYPE_IF_OTHER,
344 DEVSTAT_PRIORITY_DISK);
346 sc->dev = disk_create(unit, &sc->disk, 0, &fla_cdevsw);
347 sc->dev->si_drv1 = sc;
353 static device_method_t fla_methods[] = {
354 /* Device interface */
355 DEVMETHOD(device_probe, flaprobe),
356 DEVMETHOD(device_attach, flaattach),
360 static driver_t fladriver = {
363 sizeof(struct fla_s),
366 static devclass_t fla_devclass;
368 DRIVER_MODULE(fla, isa, fladriver, fla_devclass, 0, 0);