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.14 2006/09/05 00:55:36 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 dev_ops fla_ops = {
64 { "fla", CDEV_MAJOR, D_DISK | D_CANFREE },
70 .d_strategy = flastrategy,
74 doc2k_malloc(int bytes)
76 return kmalloc(bytes, M_FLA, M_WAITOK);
86 doc2k_delay(unsigned msec)
92 doc2k_memcpy(void *dst, const void *src, unsigned len)
98 doc2k_memcmp(const void *dst, const void *src, unsigned len)
100 return (bcmp(src, dst, len));
104 doc2k_memset(void *dst, int c, unsigned len)
111 static struct fla_s {
115 struct doc2k_stat ds;
116 struct bio_queue_head bio_queue;
117 struct devstat stats;
123 flaopen(struct dev_open_args *ap)
125 dev_t dev = ap->a_head.a_dev;
128 struct disklabel *dl;
131 printf("flaopen(%s %x %x)\n",
132 devtoname(dev), ap->a_oflags, ap->a_devtype);
136 error = doc2k_open(sc->unit);
139 printf("doc2k_open(%d) -> err %d\n", sc->unit, error);
143 dl = &sc->disk.d_label;
144 bzero(dl, sizeof(*dl));
145 error = doc2k_size(sc->unit, &dl->d_secperunit,
146 &dl->d_ncylinders, &dl->d_ntracks, &dl->d_nsectors);
147 dl->d_secsize = DEV_BSIZE;
148 dl->d_secpercyl = dl->d_ntracks * dl->d_nsectors; /* XXX */
154 flaclose(struct dev_close_args *ap)
156 dev_t dev = ap->a_head.a_dev;
161 printf("flaclose(%s %x %x)\n",
162 devtoname(dev), ap->a_fflag, ap->a_devtype);
166 error = doc2k_close(sc->unit);
168 printf("doc2k_close(%d) -> err %d\n", sc->unit, error);
175 flaioctl(struct dev_ioctl_args *ap)
177 dev_t dev = ap->a_head.a_dev;
180 printf("flaioctl(%s %lx %p %x)\n",
181 devtoname(dev), ap->a_cmd, ap->a_data, ap->a_fflag);
187 flastrategy(struct dev_strategy_args *ap)
189 dev_t dev = ap->a_head.a_dev;
190 struct bio *bio = ap->a_bio;
191 struct buf *bp = bio->bio_buf;
194 enum doc2k_work what;
197 printf("flastrategy(%p) %s %x, %lld, %d, %p)\n",
198 bp, devtoname(dev), bp->b_flags, bio->bio_offset,
199 bp->b_bcount, bp->b_data);
203 bio->bio_driver_info = dev;
205 bioqdisksort(&sc->bio_queue, bio);
213 bio = bioq_first(&sc->bio_queue);
218 bioq_remove(&sc->bio_queue, bio);
220 dev = bio->bio_driver_info;
222 devstat_start_transaction(&sc->stats);
223 bp->b_resid = bp->b_bcount;
227 case BUF_CMD_FREEBLKS:
237 panic("fla: bad b_cmd %d", bp->b_cmd);
242 error = doc2k_rwe(unit, what,
243 (unsigned)(bio->bio_offset >> DEV_BSHIFT),
244 bp->b_bcount / DEV_BSIZE, bp->b_data);
248 if (fla_debug > 1 || error) {
249 printf("fla%d: %d = rwe(%p, %d, %d, %lld, %d, %p)\n",
250 unit, error, bp, unit, what, bio->bio_offset,
251 bp->b_bcount, bp->b_data);
255 bp->b_flags |= B_ERROR;
259 devstat_end_transaction_buf(&sc->stats, bp);
269 flaprobe (device_t dev)
275 unit = device_get_unit(dev);
278 /* This is slightly ugly */
279 i = doc2k_probe(unit, KERNBASE + 0xc0000, KERNBASE + 0xe0000);
283 i = doc2k_info(unit, &sc->ds);
287 bus_set_resource(dev, SYS_RES_MEMORY, 0,
288 sc->ds.window - KERNBASE, 8192);
294 flaattach (device_t dev)
297 int i, j, k, l, m, error;
300 unit = device_get_unit(dev);
303 error = doc2k_open(unit);
305 printf("doc2k_open(%d) -> err %d\n", unit, error);
309 error = doc2k_size(unit, &sc->nsect, &i, &j, &k );
311 printf("doc2k_size(%d) -> err %d\n", unit, error);
315 printf("fla%d: <%s %s>\n", unit, sc->ds.product, sc->ds.model);
317 error = doc2k_close(unit);
319 printf("doc2k_close(%d) -> err %d\n", unit, error);
323 m = 1024L * 1024L / DEV_BSIZE;
324 l = (sc->nsect * 10 + m/2) / m;
325 printf("fla%d: %d.%01dMB (%u sectors),"
326 " %d cyls, %d heads, %d S/T, 512 B/S\n",
327 unit, l / 10, l % 10, sc->nsect, i, j, k);
330 printf("fla%d: JEDEC=0x%x unitsize=%ld mediasize=%ld"
331 " chipsize=%ld interleave=%d window=%lx\n",
332 unit, sc->ds.type, sc->ds.unitSize, sc->ds.mediaSize,
333 sc->ds.chipSize, sc->ds.interleaving, sc->ds.window);
335 bioq_init(&sc->bio_queue);
337 devstat_add_entry(&softc[unit].stats, "fla", unit, DEV_BSIZE,
338 DEVSTAT_NO_ORDERED_TAGS,
339 DEVSTAT_TYPE_DIRECT | DEVSTAT_TYPE_IF_OTHER,
340 DEVSTAT_PRIORITY_DISK);
342 sc->dev = disk_create(unit, &sc->disk, 0, &fla_ops);
343 sc->dev->si_drv1 = sc;
349 static device_method_t fla_methods[] = {
350 /* Device interface */
351 DEVMETHOD(device_probe, flaprobe),
352 DEVMETHOD(device_attach, flaattach),
356 static driver_t fladriver = {
359 sizeof(struct fla_s),
362 static devclass_t fla_devclass;
364 DRIVER_MODULE(fla, isa, fladriver, fla_devclass, 0, 0);