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