Fri Jun 10 09:29:07 2011 UTC ()
- split device_t/softc
- struct proc -> struct lwp

XXX: this driver is not in the default kernels.


(tsutsui)
diff -r1.17 -r1.18 src/sys/arch/atari/vme/leo.c

cvs diff -r1.17 -r1.18 src/sys/arch/atari/vme/leo.c (expand / switch to unified diff)

--- src/sys/arch/atari/vme/leo.c 2010/04/13 09:51:07 1.17
+++ src/sys/arch/atari/vme/leo.c 2011/06/10 09:29:07 1.18
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: leo.c,v 1.17 2010/04/13 09:51:07 tsutsui Exp $ */ 1/* $NetBSD: leo.c,v 1.18 2011/06/10 09:29:07 tsutsui Exp $ */
2 2
3/*- 3/*-
4 * Copyright (c) 1997 maximum entropy <entropy@zippy.bernstein.com> 4 * Copyright (c) 1997 maximum entropy <entropy@zippy.bernstein.com>
5 * Copyright (c) 1997 The NetBSD Foundation, Inc. 5 * Copyright (c) 1997 The NetBSD Foundation, Inc.
6 * All rights reserved. 6 * All rights reserved.
7 * 7 *
8 * Redistribution and use in source and binary forms, with or without 8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions 9 * modification, are permitted provided that the following conditions
10 * are met: 10 * are met:
11 * 1. Redistributions of source code must retain the above copyright 11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer. 12 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright 13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the 14 * notice, this list of conditions and the following disclaimer in the
@@ -37,27 +37,27 @@ @@ -37,27 +37,27 @@
37 * drivers in the NetBSD distribution as examples. The file I referred to 37 * drivers in the NetBSD distribution as examples. The file I referred to
38 * the most was /sys/arch/atari/vme/if_le_vme.c. Due credits: 38 * the most was /sys/arch/atari/vme/if_le_vme.c. Due credits:
39 * Copyright (c) 1997 Leo Weppelman. All rights reserved. 39 * Copyright (c) 1997 Leo Weppelman. All rights reserved.
40 * Copyright (c) 1995 Charles M. Hannum. All rights reserved. 40 * Copyright (c) 1995 Charles M. Hannum. All rights reserved.
41 * Copyright (c) 1992, 1993 41 * Copyright (c) 1992, 1993
42 * The Regents of the University of California. All rights reserved. 42 * The Regents of the University of California. All rights reserved.
43 * This code is derived from software contributed to Berkeley by 43 * This code is derived from software contributed to Berkeley by
44 * Ralph Campbell and Rick Macklem. 44 * Ralph Campbell and Rick Macklem.
45 * This product includes software developed by the University of 45 * This product includes software developed by the University of
46 * California, Berkeley and its contributors. 46 * California, Berkeley and its contributors.
47 */ 47 */
48 48
49#include <sys/cdefs.h> 49#include <sys/cdefs.h>
50__KERNEL_RCSID(0, "$NetBSD: leo.c,v 1.17 2010/04/13 09:51:07 tsutsui Exp $"); 50__KERNEL_RCSID(0, "$NetBSD: leo.c,v 1.18 2011/06/10 09:29:07 tsutsui Exp $");
51 51
52#include <sys/param.h> 52#include <sys/param.h>
53#include <sys/systm.h> 53#include <sys/systm.h>
54#include <sys/proc.h> 54#include <sys/proc.h>
55#include <sys/errno.h> 55#include <sys/errno.h>
56#include <sys/device.h> 56#include <sys/device.h>
57#include <sys/conf.h> 57#include <sys/conf.h>
58#include <sys/ioctl.h> 58#include <sys/ioctl.h>
59#include <machine/cpu.h> 59#include <machine/cpu.h>
60#include <machine/bus.h> 60#include <machine/bus.h>
61#include <machine/iomap.h> 61#include <machine/iomap.h>
62#include <machine/scu.h> 62#include <machine/scu.h>
63#include <atari/vme/vmevar.h> 63#include <atari/vme/vmevar.h>
@@ -68,62 +68,62 @@ __KERNEL_RCSID(0, "$NetBSD: leo.c,v 1.17 @@ -68,62 +68,62 @@ __KERNEL_RCSID(0, "$NetBSD: leo.c,v 1.17
68 68
69static struct leo_addresses { 69static struct leo_addresses {
70 u_long reg_addr; 70 u_long reg_addr;
71 u_int reg_size; 71 u_int reg_size;
72 u_long mem_addr; 72 u_long mem_addr;
73 u_int mem_size; 73 u_int mem_size;
74} leostd[] = { 74} leostd[] = {
75 { 0xfed90000, 0x100, 0xfec00000, 0x100000 } 75 { 0xfed90000, 0x100, 0xfec00000, 0x100000 }
76}; 76};
77 77
78#define NLEOSTD (sizeof(leostd) / sizeof(leostd[0])) 78#define NLEOSTD (sizeof(leostd) / sizeof(leostd[0]))
79 79
80struct leo_softc { 80struct leo_softc {
81 struct device sc_dev; /* XXX what goes here? */ 81 device_t sc_dev; /* XXX what goes here? */
82 bus_space_tag_t sc_iot; 82 bus_space_tag_t sc_iot;
83 bus_space_tag_t sc_memt; 83 bus_space_tag_t sc_memt;
84 bus_space_handle_t sc_ioh; 84 bus_space_handle_t sc_ioh;
85 bus_space_handle_t sc_memh; 85 bus_space_handle_t sc_memh;
86 int sc_flags; 86 int sc_flags;
87 int sc_maddr; 87 int sc_maddr;
88 u_int sc_msize; 88 u_int sc_msize;
89}; 89};
90 90
91#define LEO_SC_FLAGS_INUSE 1 91#define LEO_SC_FLAGS_INUSE 1
92 92
93static int leo_match(struct device *, struct cfdata *, void *); 93static int leo_match(device_t, cfdata_t, void *);
94static void leo_attach(struct device *, struct device *, void *); 94static void leo_attach(device_t, device_t, void *);
95static int leo_probe(bus_space_tag_t *, bus_space_tag_t *, 95static int leo_probe(bus_space_tag_t *, bus_space_tag_t *,
96 bus_space_handle_t *, bus_space_handle_t *, 96 bus_space_handle_t *, bus_space_handle_t *,
97 u_int, u_int); 97 u_int, u_int);
98static int leo_init(struct leo_softc *, int); 98static int leo_init(struct leo_softc *, int);
99static int leo_scroll(struct leo_softc *, int); 99static int leo_scroll(struct leo_softc *, int);
100 100
101CFATTACH_DECL(leo, sizeof(struct leo_softc), 101CFATTACH_DECL_NEW(leo, sizeof(struct leo_softc),
102 leo_match, leo_attach, NULL, NULL); 102 leo_match, leo_attach, NULL, NULL);
103 103
104dev_type_open(leoopen); 104dev_type_open(leoopen);
105dev_type_close(leoclose); 105dev_type_close(leoclose);
106dev_type_read(leomove); 106dev_type_read(leomove);
107dev_type_ioctl(leoioctl); 107dev_type_ioctl(leoioctl);
108dev_type_mmap(leommap); 108dev_type_mmap(leommap);
109 109
110const struct cdevsw leo_cdevsw = { 110const struct cdevsw leo_cdevsw = {
111 leoopen, leoclose, leomove, leomove, leoioctl, 111 leoopen, leoclose, leomove, leomove, leoioctl,
112 nostop, notty, nopoll, leommap, nokqfilter, 112 nostop, notty, nopoll, leommap, nokqfilter,
113}; 113};
114 114
115static int 115static int
116leo_match(struct device *parent, struct cfdata *cfp, void *aux) 116leo_match(device_t parent, cfdata_t cf, void *aux)
117{ 117{
118 struct vme_attach_args *va = aux; 118 struct vme_attach_args *va = aux;
119 int i; 119 int i;
120 bus_space_tag_t iot; 120 bus_space_tag_t iot;
121 bus_space_tag_t memt; 121 bus_space_tag_t memt;
122 bus_space_handle_t ioh; 122 bus_space_handle_t ioh;
123 bus_space_handle_t memh; 123 bus_space_handle_t memh;
124 124
125 /* 125 /*
126 * We are passed our configuration in the attachment arguments. 126 * We are passed our configuration in the attachment arguments.
127 * The configuration information may be partially unspecified. 127 * The configuration information may be partially unspecified.
128 * For any unspecified configuration parameters, we fill in those 128 * For any unspecified configuration parameters, we fill in those
129 * parameters with data for a "standard" configuration. 129 * parameters with data for a "standard" configuration.
@@ -195,61 +195,63 @@ leo_probe(bus_space_tag_t *iot, bus_spac @@ -195,61 +195,63 @@ leo_probe(bus_space_tag_t *iot, bus_spac
195 * with the test pattern. 195 * with the test pattern.
196 */ 196 */
197 bus_space_write_4(*memt, *memh, 0, 0xa5a5a5a5); 197 bus_space_write_4(*memt, *memh, 0, 0xa5a5a5a5);
198 if ((bus_space_read_4(*memt, *memh, 0) & 0xffffff) != 0xa5a5a5) 198 if ((bus_space_read_4(*memt, *memh, 0) & 0xffffff) != 0xa5a5a5)
199 return 0; 199 return 0;
200 bus_space_write_4(*memt, *memh, msize - 4, 0xa5a5a5a5); 200 bus_space_write_4(*memt, *memh, msize - 4, 0xa5a5a5a5);
201 if ((bus_space_read_4(*memt, *memh, msize - 4) & 0xffffff) 201 if ((bus_space_read_4(*memt, *memh, msize - 4) & 0xffffff)
202 != 0xa5a5a5) 202 != 0xa5a5a5)
203 return 0; 203 return 0;
204 return 1; 204 return 1;
205} 205}
206 206
207static void 207static void
208leo_attach(struct device *parent, struct device *self, void *aux) 208leo_attach(device_t parent, device_t self, void *aux)
209{ 209{
210 struct leo_softc *sc = (struct leo_softc *)self; 210 struct leo_softc *sc = device_private(self);
211 struct vme_attach_args *va = aux; 211 struct vme_attach_args *va = aux;
212 bus_space_handle_t ioh; 212 bus_space_handle_t ioh;
213 bus_space_handle_t memh; 213 bus_space_handle_t memh;
214#ifndef SET_REGION 214#ifndef SET_REGION
215 int i; 215 int i;
216#endif 216#endif
217 217
 218 sc->sc_dev = self;
 219
218 printf("\n"); 220 printf("\n");
219 if (bus_space_map(va->va_iot, va->va_iobase, va->va_iosize, 0, &ioh)) 221 if (bus_space_map(va->va_iot, va->va_iobase, va->va_iosize, 0, &ioh))
220 panic("leo_attach: cannot map io area"); 222 panic("leo_attach: cannot map io area");
221 if (bus_space_map(va->va_memt, va->va_maddr, va->va_msize, 223 if (bus_space_map(va->va_memt, va->va_maddr, va->va_msize,
222 BUS_SPACE_MAP_LINEAR|BUS_SPACE_MAP_CACHEABLE, &memh)) 224 BUS_SPACE_MAP_LINEAR|BUS_SPACE_MAP_CACHEABLE, &memh))
223 panic("leo_attach: cannot map memory area"); 225 panic("leo_attach: cannot map memory area");
224#ifdef SET_REGION /* XXX seems to be unimplemented on atari? */ 226#ifdef SET_REGION /* XXX seems to be unimplemented on atari? */
225 bus_space_set_region_4(va->va_memt, memh, 0, 0, va->va_msize >> 2); 227 bus_space_set_region_4(va->va_memt, memh, 0, 0, va->va_msize >> 2);
226#else 228#else
227 for (i = 0; i < (va->va_msize >> 2); i++) 229 for (i = 0; i < (va->va_msize >> 2); i++)
228 bus_space_write_4(va->va_memt, memh, i << 2, 0); 230 bus_space_write_4(va->va_memt, memh, i << 2, 0);
229#endif 231#endif
230 sc->sc_iot = va->va_iot; 232 sc->sc_iot = va->va_iot;
231 sc->sc_ioh = ioh; 233 sc->sc_ioh = ioh;
232 sc->sc_memt = va->va_memt; 234 sc->sc_memt = va->va_memt;
233 sc->sc_memh = memh; 235 sc->sc_memh = memh;
234 sc->sc_flags = 0; 236 sc->sc_flags = 0;
235 sc->sc_maddr = va->va_maddr; 237 sc->sc_maddr = va->va_maddr;
236 sc->sc_msize = va->va_msize; 238 sc->sc_msize = va->va_msize;
237 leo_init(sc, 512); 239 leo_init(sc, 512);
238 leo_scroll(sc, 0); 240 leo_scroll(sc, 0);
239} 241}
240 242
241int 243int
242leoopen(dev_t dev, int flags, int devtype, struct proc *p) 244leoopen(dev_t dev, int flags, int devtype, struct lwp *l)
243{ 245{
244 struct leo_softc *sc; 246 struct leo_softc *sc;
245 int r; 247 int r;
246 248
247 sc = device_lookup_private(&leo_cd, minor(dev)); 249 sc = device_lookup_private(&leo_cd, minor(dev));
248 if (!sc) 250 if (!sc)
249 return ENXIO; 251 return ENXIO;
250 if (sc->sc_flags & LEO_SC_FLAGS_INUSE) 252 if (sc->sc_flags & LEO_SC_FLAGS_INUSE)
251 return EBUSY; 253 return EBUSY;
252 r = leo_init(sc, 512); 254 r = leo_init(sc, 512);
253 if (r != 0) 255 if (r != 0)
254 return r; 256 return r;
255 r = leo_scroll(sc, 0); 257 r = leo_scroll(sc, 0);
@@ -318,27 +320,27 @@ static int @@ -318,27 +320,27 @@ static int
318leo_scroll(struct leo_softc *sc, int scroll) 320leo_scroll(struct leo_softc *sc, int scroll)
319{ 321{
320 322
321 if ((scroll < 0) || (scroll > 255)) 323 if ((scroll < 0) || (scroll > 255))
322 return EINVAL; 324 return EINVAL;
323 bus_space_write_1(sc->sc_iot, sc->sc_ioh, LEO_REG_MSBSCROLL, 325 bus_space_write_1(sc->sc_iot, sc->sc_ioh, LEO_REG_MSBSCROLL,
324 (scroll >> 6) && 0xff); 326 (scroll >> 6) && 0xff);
325 bus_space_write_1(sc->sc_iot, sc->sc_ioh, LEO_REG_LSBSCROLL, 327 bus_space_write_1(sc->sc_iot, sc->sc_ioh, LEO_REG_LSBSCROLL,
326 (scroll << 2) && 0xff); 328 (scroll << 2) && 0xff);
327 return 0; 329 return 0;
328} 330}
329 331
330int 332int
331leoclose(dev_t dev, int flags, int devtype, struct proc *p) 333leoclose(dev_t dev, int flags, int devtype, struct lwp *l)
332{ 334{
333 struct leo_softc *sc; 335 struct leo_softc *sc;
334 336
335 sc = device_lookup_private(&leo_cd, minor(dev)); 337 sc = device_lookup_private(&leo_cd, minor(dev));
336 sc->sc_flags &= ~LEO_SC_FLAGS_INUSE; 338 sc->sc_flags &= ~LEO_SC_FLAGS_INUSE;
337 return 0; 339 return 0;
338} 340}
339 341
340#define SMALLBSIZE 32 342#define SMALLBSIZE 32
341 343
342int 344int
343leomove(dev_t dev, struct uio *uio, int flags) 345leomove(dev_t dev, struct uio *uio, int flags)
344{ 346{
@@ -362,27 +364,27 @@ leomove(dev_t dev, struct uio *uio, int  @@ -362,27 +364,27 @@ leomove(dev_t dev, struct uio *uio, int
362 if (uio->uio_rw == UIO_READ) 364 if (uio->uio_rw == UIO_READ)
363 bus_space_read_region_1(sc->sc_memt, sc->sc_memh, 365 bus_space_read_region_1(sc->sc_memt, sc->sc_memh,
364 offset, smallbuf, size); 366 offset, smallbuf, size);
365 if ((error = uiomove((void *)smallbuf, size, uio))) 367 if ((error = uiomove((void *)smallbuf, size, uio)))
366 return (error); 368 return (error);
367 if (uio->uio_rw == UIO_WRITE) 369 if (uio->uio_rw == UIO_WRITE)
368 bus_space_write_region_1(sc->sc_memt, sc->sc_memh, 370 bus_space_write_region_1(sc->sc_memt, sc->sc_memh,
369 offset, smallbuf, size); 371 offset, smallbuf, size);
370 } 372 }
371 return 0; 373 return 0;
372} 374}
373 375
374int 376int
375leoioctl(dev_t dev, u_long cmd, void *data, int flags, struct proc *p) 377leoioctl(dev_t dev, u_long cmd, void *data, int flags, struct lwp *l)
376{ 378{
377 struct leo_softc *sc; 379 struct leo_softc *sc;
378 380
379 sc = device_lookup_private(&leo_cd,minor(dev)); 381 sc = device_lookup_private(&leo_cd,minor(dev));
380 switch (cmd) { 382 switch (cmd) {
381 case LIOCYRES: 383 case LIOCYRES:
382 return leo_init(sc, *(int *)data); 384 return leo_init(sc, *(int *)data);
383 break; 385 break;
384 case LIOCSCRL: 386 case LIOCSCRL:
385 return leo_scroll(sc, *(int *)data); 387 return leo_scroll(sc, *(int *)data);
386 break; 388 break;
387 default: 389 default:
388 return EINVAL; 390 return EINVAL;