grf.c revision 1.26 1 /* $NetBSD: grf.c,v 1.26 1996/04/21 21:11:07 veego 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 <vm/vm.h>
61 #include <vm/vm_kern.h>
62 #include <vm/vm_page.h>
63 #include <vm/vm_pager.h>
64 #include <machine/cpu.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 *, void *, void *));
97 int grfprint __P((void *, 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 struct cfdriver grf_cd = {
108 NULL, "grf", DV_DULL, NULL, 0
109 };
110
111 /*
112 * only used in console init.
113 */
114 static struct cfdata *cfdata;
115
116 /*
117 * match if the unit of grf matches its perspective
118 * low level board driver.
119 */
120 int
121 grfmatch(pdp, match, auxp)
122 struct device *pdp;
123 void *match, *auxp;
124 {
125 struct cfdata *cfp = match;
126
127 if (cfp->cf_unit != ((struct grf_softc *)pdp)->g_unit)
128 return(0);
129 cfdata = cfp;
130 return(1);
131 }
132
133 /*
134 * attach.. plug pointer in and print some info.
135 * then try and attach an ite to us. note: dp is NULL
136 * durring console init.
137 */
138 void
139 grfattach(pdp, dp, auxp)
140 struct device *pdp, *dp;
141 void *auxp;
142 {
143 struct grf_softc *gp;
144 int maj;
145
146 gp = (struct grf_softc *)pdp;
147 grfsp[gp->g_unit] = (struct grf_softc *)pdp;
148
149 /*
150 * find our major device number
151 */
152 for(maj = 0; maj < nchrdev; maj++)
153 if (cdevsw[maj].d_open == grfopen)
154 break;
155
156 gp->g_grfdev = makedev(maj, gp->g_unit);
157 if (dp != NULL) {
158 printf(": width %d height %d", gp->g_display.gd_dwidth,
159 gp->g_display.gd_dheight);
160 if (gp->g_display.gd_colors == 2)
161 printf(" monochrome\n");
162 else
163 printf(" colors %d\n", gp->g_display.gd_colors);
164 }
165
166 /*
167 * try and attach an ite
168 */
169 amiga_config_found(cfdata, dp, gp, grfprint);
170 }
171
172 int
173 grfprint(auxp, pnp)
174 void *auxp;
175 char *pnp;
176 {
177 if (pnp)
178 printf("ite at %s", pnp);
179 return(UNCONF);
180 }
181
182 /*ARGSUSED*/
183 int
184 grfopen(dev, flags, devtype, p)
185 dev_t dev;
186 int flags, devtype;
187 struct proc *p;
188 {
189 struct grf_softc *gp;
190
191 if (GRFUNIT(dev) >= NGRF || (gp = grfsp[GRFUNIT(dev)]) == NULL)
192 return(ENXIO);
193
194 if ((gp->g_flags & GF_ALIVE) == 0)
195 return(ENXIO);
196
197 if ((gp->g_flags & (GF_OPEN|GF_EXCLUDE)) == (GF_OPEN|GF_EXCLUDE))
198 return(EBUSY);
199
200 return(0);
201 }
202
203 /*ARGSUSED*/
204 int
205 grfclose(dev, flags, mode, p)
206 dev_t dev;
207 int flags;
208 int mode;
209 struct proc *p;
210 {
211 struct grf_softc *gp;
212
213 gp = grfsp[GRFUNIT(dev)];
214 (void)grfoff(dev);
215 gp->g_flags &= GF_ALIVE;
216 return(0);
217 }
218
219 /*ARGSUSED*/
220 int
221 grfioctl(dev, cmd, data, flag, p)
222 dev_t dev;
223 u_long cmd;
224 caddr_t data;
225 int flag;
226 struct proc *p;
227 {
228 struct grf_softc *gp;
229 int error;
230
231 gp = grfsp[GRFUNIT(dev)];
232 error = 0;
233
234 switch (cmd) {
235 case OGRFIOCGINFO:
236 /* argl.. no bank-member.. */
237 bcopy((caddr_t)&gp->g_display, data, sizeof(struct grfinfo)-4);
238 break;
239 case GRFIOCGINFO:
240 bcopy((caddr_t)&gp->g_display, data, sizeof(struct grfinfo));
241 break;
242 case GRFIOCON:
243 error = grfon(dev);
244 break;
245 case GRFIOCOFF:
246 error = grfoff(dev);
247 break;
248 case GRFIOCSINFO:
249 error = grfsinfo(dev, (struct grfdyninfo *) data);
250 break;
251 case GRFGETVMODE:
252 return(gp->g_mode(gp, GM_GRFGETVMODE, data, 0, 0));
253 case GRFSETVMODE:
254 error = gp->g_mode(gp, GM_GRFSETVMODE, data, 0, 0);
255 if (error == 0 && gp->g_itedev && !(gp->g_flags & GF_GRFON))
256 ite_reinit(gp->g_itedev);
257 break;
258 case GRFGETNUMVM:
259 return(gp->g_mode(gp, GM_GRFGETNUMVM, data, 0, 0));
260 /*
261 * these are all hardware dependant, and have to be resolved
262 * in the respective driver.
263 */
264 case GRFIOCPUTCMAP:
265 case GRFIOCGETCMAP:
266 case GRFIOCSSPRITEPOS:
267 case GRFIOCGSPRITEPOS:
268 case GRFIOCSSPRITEINF:
269 case GRFIOCGSPRITEINF:
270 case GRFIOCGSPRITEMAX:
271 case GRFIOCBITBLT:
272 case GRFIOCSETMON:
273 case GRFIOCBLANK: /* blank ioctl, IOCON/OFF will turn ite on */
274 case GRFTOGGLE: /* Toggles between Cirrus boards and native ECS on
275 Amiga. 15/11/94 ill */
276 /*
277 * We need the minor dev number to get the overlay/image
278 * information for grf_ul.
279 */
280 return(gp->g_mode(gp, GM_GRFIOCTL, data, cmd, dev));
281 default:
282 #if NVIEW > 0
283 /*
284 * check to see whether it's a command recognized by the
285 * view code if the unit is 0
286 * XXX
287 */
288 if (GRFUNIT(dev) == 0)
289 return(viewioctl(dev, cmd, data, flag, p));
290 #endif
291 error = EINVAL;
292 break;
293
294 }
295 return(error);
296 }
297
298 /*ARGSUSED*/
299 int
300 grfselect(dev, rw, p)
301 dev_t dev;
302 int rw;
303 struct proc *p;
304 {
305 if (rw == FREAD)
306 return(0);
307 return(1);
308 }
309
310 /*
311 * map the contents of a graphics display card into process'
312 * memory space.
313 */
314 int
315 grfmmap(dev, off, prot)
316 dev_t dev;
317 int off, prot;
318 {
319 struct grf_softc *gp;
320 struct grfinfo *gi;
321
322 gp = grfsp[GRFUNIT(dev)];
323 gi = &gp->g_display;
324
325 /*
326 * control registers
327 */
328 if (off >= 0 && off < gi->gd_regsize)
329 return(((u_int)gi->gd_regaddr + off) >> PGSHIFT);
330
331 /*
332 * frame buffer
333 */
334 if (off >= gi->gd_regsize && off < gi->gd_regsize+gi->gd_fbsize) {
335 off -= gi->gd_regsize;
336 #ifdef BANKEDDEVPAGER
337 if (gi->gd_bank_size)
338 off %= gi->gd_bank_size;
339 #endif
340 return(((u_int)gi->gd_fbaddr + off) >> PGSHIFT);
341 }
342 /* bogus */
343 return(-1);
344 }
345
346 int
347 grfon(dev)
348 dev_t dev;
349 {
350 struct grf_softc *gp;
351
352 gp = grfsp[GRFUNIT(dev)];
353
354 if (gp->g_flags & GF_GRFON)
355 return(0);
356
357 gp->g_flags |= GF_GRFON;
358 if (gp->g_itedev != NODEV)
359 ite_off(gp->g_itedev, 3);
360
361 return(gp->g_mode(gp, (dev & GRFOVDEV) ? GM_GRFOVON : GM_GRFON,
362 NULL, 0, 0));
363 }
364
365 int
366 grfoff(dev)
367 dev_t dev;
368 {
369 struct grf_softc *gp;
370 int error;
371
372 gp = grfsp[GRFUNIT(dev)];
373
374 if ((gp->g_flags & GF_GRFON) == 0)
375 return(0);
376
377 gp->g_flags &= ~GF_GRFON;
378 error = gp->g_mode(gp, (dev & GRFOVDEV) ? GM_GRFOVOFF : GM_GRFOFF,
379 NULL, 0, 0);
380
381 /*
382 * Closely tied together no X's
383 */
384 if (gp->g_itedev != NODEV)
385 ite_on(gp->g_itedev, 2);
386
387 return(error);
388 }
389
390 int
391 grfsinfo(dev, dyninfo)
392 dev_t dev;
393 struct grfdyninfo *dyninfo;
394 {
395 struct grf_softc *gp;
396 int error;
397
398 gp = grfsp[GRFUNIT(dev)];
399 error = gp->g_mode(gp, GM_GRFCONFIG, dyninfo, 0, 0);
400
401 /*
402 * Closely tied together no X's
403 */
404 if (gp->g_itedev != NODEV)
405 ite_reinit(gp->g_itedev);
406 return(error);
407 }
408
409 #ifdef BANKEDDEVPAGER
410
411 int
412 grfbanked_get (dev, off, prot)
413 dev_t dev;
414 off_t off;
415 int prot;
416 {
417 struct grf_softc *gp;
418 struct grfinfo *gi;
419 int error, bank;
420
421 gp = grfsp[GRFUNIT(dev)];
422 gi = &gp->g_display;
423
424 off -= gi->gd_regsize;
425 if (off < 0 || off >= gi->gd_fbsize)
426 return -1;
427
428 error = gp->g_mode(gp, GM_GRFGETBANK, &bank, off, prot);
429 return error ? -1 : bank;
430 }
431
432 int
433 grfbanked_cur (dev)
434 dev_t dev;
435 {
436 struct grf_softc *gp;
437 int error, bank;
438
439 gp = grfsp[GRFUNIT(dev)];
440
441 error = gp->g_mode(gp, GM_GRFGETCURBANK, &bank, 0, 0);
442 return(error ? -1 : bank);
443 }
444
445 int
446 grfbanked_set (dev, bank)
447 dev_t dev;
448 int bank;
449 {
450 struct grf_softc *gp;
451
452 gp = grfsp[GRFUNIT(dev)];
453 return(gp->g_mode(gp, GM_GRFSETBANK, &bank, 0, 0) ? -1 : 0);
454 }
455
456 #endif /* BANKEDDEVPAGER */
457 #endif /* NGRF > 0 */
458