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