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