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