Expand PMF_FN_* macros.
[netbsd-mini2440.git] / sys / arch / amiga / dev / grf.c
blob3d9a4e79a1b4113a4077ea98e884ff63a75464a1
1 /* $NetBSD: grf.c,v 1.51 2009/03/18 17:06:41 cegger Exp $ */
3 /*
4 * Copyright (c) 1990 The Regents of the University of California.
5 * All rights reserved.
7 * This code is derived from software contributed to Berkeley by
8 * the Systems Programming Group of the University of Utah Computer
9 * Science Department.
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions
13 * are met:
14 * 1. Redistributions of source code must retain the above copyright
15 * notice, this list of conditions and the following disclaimer.
16 * 2. Redistributions in binary form must reproduce the above copyright
17 * notice, this list of conditions and the following disclaimer in the
18 * documentation and/or other materials provided with the distribution.
19 * 3. Neither the name of the University nor the names of its contributors
20 * may be used to endorse or promote products derived from this software
21 * without specific prior written permission.
23 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
24 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
25 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
26 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
27 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
28 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
29 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
30 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
32 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
33 * SUCH DAMAGE.
35 * from: Utah $Hdr: grf.c 1.31 91/01/21$
37 * @(#)grf.c 7.8 (Berkeley) 5/7/91
40 * Copyright (c) 1988 University of Utah.
42 * This code is derived from software contributed to Berkeley by
43 * the Systems Programming Group of the University of Utah Computer
44 * Science Department.
46 * Redistribution and use in source and binary forms, with or without
47 * modification, are permitted provided that the following conditions
48 * are met:
49 * 1. Redistributions of source code must retain the above copyright
50 * notice, this list of conditions and the following disclaimer.
51 * 2. Redistributions in binary form must reproduce the above copyright
52 * notice, this list of conditions and the following disclaimer in the
53 * documentation and/or other materials provided with the distribution.
54 * 3. All advertising materials mentioning features or use of this software
55 * must display the following acknowledgement:
56 * This product includes software developed by the University of
57 * California, Berkeley and its contributors.
58 * 4. Neither the name of the University nor the names of its contributors
59 * may be used to endorse or promote products derived from this software
60 * without specific prior written permission.
62 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
63 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
64 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
65 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
66 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
67 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
68 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
69 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
70 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
71 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
72 * SUCH DAMAGE.
74 * from: Utah $Hdr: grf.c 1.31 91/01/21$
76 * @(#)grf.c 7.8 (Berkeley) 5/7/91
79 #include <sys/cdefs.h>
80 __KERNEL_RCSID(0, "$NetBSD: grf.c,v 1.51 2009/03/18 17:06:41 cegger Exp $");
83 * Graphics display driver for the Amiga
84 * This is the hardware-independent portion of the driver.
85 * Hardware access is through the grf_softc->g_mode routine.
88 #include <sys/param.h>
89 #include <sys/proc.h>
90 #include <sys/ioctl.h>
91 #include <sys/device.h>
92 #include <sys/file.h>
93 #include <sys/malloc.h>
94 #include <sys/systm.h>
95 #include <sys/vnode.h>
96 #include <sys/mman.h>
97 #include <uvm/uvm_extern.h>
98 #include <machine/cpu.h>
99 #include <dev/sun/fbio.h>
100 #include <amiga/amiga/color.h> /* DEBUG */
101 #include <amiga/amiga/device.h>
102 #include <amiga/dev/grfioctl.h>
103 #include <amiga/dev/grfvar.h>
104 #include <amiga/dev/itevar.h>
105 #include <amiga/dev/viewioctl.h>
107 #include <sys/conf.h>
109 #include "view.h"
110 #include "grf.h"
112 #if NGRF > 0
113 #include "ite.h"
114 #if NITE == 0
115 #define ite_on(u,f)
116 #define ite_off(u,f)
117 #define ite_reinit(d)
118 #endif
120 int grfon(dev_t);
121 int grfoff(dev_t);
122 int grfsinfo(dev_t, struct grfdyninfo *);
124 void grfattach(struct device *, struct device *, void *);
125 int grfmatch(struct device *, struct cfdata *, void *);
126 int grfprint(void *, const char *);
128 * pointers to grf drivers device structs
130 struct grf_softc *grfsp[NGRF];
132 CFATTACH_DECL(grf, sizeof(struct device),
133 grfmatch, grfattach, NULL, NULL);
135 dev_type_open(grfopen);
136 dev_type_close(grfclose);
137 dev_type_ioctl(grfioctl);
138 dev_type_mmap(grfmmap);
140 const struct cdevsw grf_cdevsw = {
141 grfopen, grfclose, nullread, nullwrite, grfioctl,
142 nostop, notty, nopoll, grfmmap, nokqfilter,
146 * only used in console init.
148 static struct cfdata *cfdata;
151 * match if the unit of grf matches its perspective
152 * low level board driver.
155 grfmatch(struct device *pdp, struct cfdata *cfp, void *auxp)
158 if (cfp->cf_unit != ((struct grf_softc *)pdp)->g_unit)
159 return(0);
160 cfdata = cfp;
161 return(1);
165 * attach.. plug pointer in and print some info.
166 * then try and attach an ite to us. note: dp is NULL
167 * durring console init.
169 void
170 grfattach(struct device *pdp, struct device *dp, void *auxp)
172 struct grf_softc *gp;
173 int maj;
175 gp = (struct grf_softc *)pdp;
176 grfsp[gp->g_unit] = (struct grf_softc *)pdp;
179 * find our major device number
181 maj = cdevsw_lookup_major(&grf_cdevsw);
183 gp->g_grfdev = makedev(maj, gp->g_unit);
184 if (dp != NULL) {
185 printf(": width %d height %d", gp->g_display.gd_dwidth,
186 gp->g_display.gd_dheight);
187 if (gp->g_display.gd_colors == 2)
188 printf(" monochrome\n");
189 else
190 printf(" colors %d\n", gp->g_display.gd_colors);
194 * try and attach an ite
196 amiga_config_found(cfdata, dp, gp, grfprint);
200 grfprint(void *auxp, const char *pnp)
202 if (pnp)
203 aprint_normal("ite at %s", pnp);
204 return(UNCONF);
207 /*ARGSUSED*/
209 grfopen(dev_t dev, int flags, int devtype, struct lwp *l)
211 struct grf_softc *gp;
213 if (GRFUNIT(dev) >= NGRF || (gp = grfsp[GRFUNIT(dev)]) == NULL)
214 return(ENXIO);
216 if ((gp->g_flags & GF_ALIVE) == 0)
217 return(ENXIO);
219 if ((gp->g_flags & (GF_OPEN|GF_EXCLUDE)) == (GF_OPEN|GF_EXCLUDE))
220 return(EBUSY);
222 return(0);
225 /*ARGSUSED*/
227 grfclose(dev_t dev, int flags, int mode, struct lwp *l)
229 struct grf_softc *gp;
231 gp = grfsp[GRFUNIT(dev)];
232 (void)grfoff(dev);
233 gp->g_flags &= GF_ALIVE;
234 return(0);
237 /*ARGSUSED*/
239 grfioctl(dev_t dev, u_long cmd, void *data, int flag, struct lwp *l)
241 struct grf_softc *gp;
242 int error;
244 gp = grfsp[GRFUNIT(dev)];
245 error = 0;
247 switch (cmd) {
248 case OGRFIOCGINFO:
249 /* argl.. no bank-member.. */
250 memcpy(data, (void *)&gp->g_display, sizeof(struct grfinfo)-4);
251 break;
252 case GRFIOCGINFO:
253 memcpy(data, (void *)&gp->g_display, sizeof(struct grfinfo));
254 break;
255 case GRFIOCON:
256 error = grfon(dev);
257 break;
258 case GRFIOCOFF:
259 error = grfoff(dev);
260 break;
261 case GRFIOCSINFO:
262 error = grfsinfo(dev, (struct grfdyninfo *) data);
263 break;
264 case GRFGETVMODE:
265 return(gp->g_mode(gp, GM_GRFGETVMODE, data, 0, 0));
266 case GRFSETVMODE:
267 error = gp->g_mode(gp, GM_GRFSETVMODE, data, 0, 0);
268 if (error == 0 && gp->g_itedev && !(gp->g_flags & GF_GRFON))
269 ite_reinit(gp->g_itedev);
270 break;
271 case GRFGETNUMVM:
272 return(gp->g_mode(gp, GM_GRFGETNUMVM, data, 0, 0));
274 * these are all hardware dependant, and have to be resolved
275 * in the respective driver.
277 case GRFIOCPUTCMAP:
278 case GRFIOCGETCMAP:
279 case GRFIOCSSPRITEPOS:
280 case GRFIOCGSPRITEPOS:
281 case GRFIOCSSPRITEINF:
282 case GRFIOCGSPRITEINF:
283 case GRFIOCGSPRITEMAX:
284 case GRFIOCBITBLT:
285 case GRFIOCSETMON:
286 case GRFTOGGLE: /* Toggles between Cirrus boards and native ECS on
287 Amiga. 15/11/94 ill */
289 * We need the minor dev number to get the overlay/image
290 * information for grf_ul.
292 return(gp->g_mode(gp, GM_GRFIOCTL, data, cmd, dev));
294 case GRFIOCBLANK: /* blank ioctl, IOCON/OFF will turn ite on */
295 case FBIOSVIDEO:
296 error = gp->g_mode(gp, GM_GRFIOCTL, data, GRFIOCBLANK, dev);
297 if (!error)
298 gp->g_blank = *(int *)data;
299 return (error);
301 case FBIOGVIDEO:
302 *(int *)data = gp->g_blank;
303 return (0);
305 default:
306 #if NVIEW > 0
308 * check to see whether it's a command recognized by the
309 * view code if the unit is 0
310 * XXX
312 if (GRFUNIT(dev) == 0) {
313 extern const struct cdevsw view_cdevsw;
315 return((*view_cdevsw.d_ioctl)(dev, cmd, data, flag, l));
317 #endif
318 error = EPASSTHROUGH;
319 break;
322 return(error);
326 * map the contents of a graphics display card into process'
327 * memory space.
329 paddr_t
330 grfmmap(dev_t dev, off_t off, int prot)
332 struct grf_softc *gp;
333 struct grfinfo *gi;
335 gp = grfsp[GRFUNIT(dev)];
336 gi = &gp->g_display;
339 * control registers
341 if (off >= 0 && off < gi->gd_regsize)
342 return(((paddr_t)gi->gd_regaddr + off) >> PGSHIFT);
345 * frame buffer
347 if (off >= gi->gd_regsize && off < gi->gd_regsize+gi->gd_fbsize) {
348 off -= gi->gd_regsize;
349 return(((paddr_t)gi->gd_fbaddr + off) >> PGSHIFT);
351 /* bogus */
352 return(-1);
356 grfon(dev_t dev)
358 struct grf_softc *gp;
360 gp = grfsp[GRFUNIT(dev)];
362 if (gp->g_flags & GF_GRFON)
363 return(0);
365 gp->g_flags |= GF_GRFON;
366 if (gp->g_itedev != NODEV)
367 ite_off(gp->g_itedev, 3);
369 return(gp->g_mode(gp, (dev & GRFOVDEV) ? GM_GRFOVON : GM_GRFON,
370 NULL, 0, 0));
374 grfoff(dev_t dev)
376 struct grf_softc *gp;
377 int error;
379 gp = grfsp[GRFUNIT(dev)];
381 if ((gp->g_flags & GF_GRFON) == 0)
382 return(0);
384 gp->g_flags &= ~GF_GRFON;
385 error = gp->g_mode(gp, (dev & GRFOVDEV) ? GM_GRFOVOFF : GM_GRFOFF,
386 NULL, 0, 0);
389 * Closely tied together no X's
391 if (gp->g_itedev != NODEV)
392 ite_on(gp->g_itedev, 2);
394 return(error);
398 grfsinfo(dev_t dev, struct grfdyninfo *dyninfo)
400 struct grf_softc *gp;
401 int error;
403 gp = grfsp[GRFUNIT(dev)];
404 error = gp->g_mode(gp, GM_GRFCONFIG, dyninfo, 0, 0);
407 * Closely tied together no X's
409 if (gp->g_itedev != NODEV)
410 ite_reinit(gp->g_itedev);
411 return(error);
414 #endif /* NGRF > 0 */