grf.c revision 1.25.2.1 1 /* $NetBSD: grf.c,v 1.25.2.1 2001/10/10 11:55:59 fvdl 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
64 #include <machine/cpu.h>
65
66 #include <uvm/uvm_extern.h>
67
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(devvp, flags, devtype, p)
163 struct vnode *devvp;
164 int flags, devtype;
165 struct proc *p;
166 {
167 struct grf_softc *gp;
168 dev_t dev;
169
170 dev = vdev_rdev(devvp);
171
172 if (GRFUNIT(dev) >= NGRF)
173 return(ENXIO);
174
175 gp = grfsp[GRFUNIT(dev)];
176 if (gp == NULL)
177 return(ENXIO);
178
179 if ((gp->g_flags & GF_ALIVE) == 0)
180 return(ENXIO);
181
182 if ((gp->g_flags & (GF_OPEN|GF_EXCLUDE)) == (GF_OPEN|GF_EXCLUDE))
183 return(EBUSY);
184
185 vdev_setprivdata(devvp, gp);
186
187 grf_viewsync(gp);
188
189 return(0);
190 }
191
192 /*ARGSUSED*/
193 int
194 grfclose(devvp, flags, mode, p)
195 struct vnode *devvp;
196 int flags;
197 int mode;
198 struct proc *p;
199 {
200 struct grf_softc *gp;
201 dev_t dev;
202
203 gp = vdev_privdata(devvp);
204 dev = vdev_rdev(devvp);
205
206 (void)grfoff(dev);
207 gp->g_flags &= GF_ALIVE;
208 return(0);
209 }
210
211 /*ARGSUSED*/
212 int
213 grfioctl(devvp, cmd, data, flag, p)
214 struct vnode *devvp;
215 u_long cmd;
216 int flag;
217 caddr_t data;
218 struct proc *p;
219 {
220 struct grf_softc *gp;
221 int error;
222 dev_t dev;
223
224 gp = vdev_privdata(devvp);
225 dev = vdev_rdev(devvp);
226
227 error = 0;
228
229 switch (cmd) {
230 case OGRFIOCGINFO:
231 /* argl.. no bank-member.. */
232 bcopy((caddr_t)&gp->g_display, data, sizeof(struct grfinfo)-4);
233 break;
234 case GRFIOCGINFO:
235 bcopy((caddr_t)&gp->g_display, data, sizeof(struct grfinfo));
236 break;
237 case GRFIOCON:
238 error = grfon(dev);
239 break;
240 case GRFIOCOFF:
241 error = grfoff(dev);
242 break;
243 case GRFIOCSINFO:
244 error = grfsinfo(dev, (struct grfdyninfo *) data);
245 break;
246 case GRFGETVMODE:
247 return(gp->g_mode(gp, GM_GRFGETVMODE, data, 0, 0));
248 case GRFSETVMODE:
249 error = gp->g_mode(gp, GM_GRFSETVMODE, data, 0, 0);
250 if (error == 0 && gp->g_itedev)
251 ite_reinit(gp->g_itedev);
252 break;
253 case GRFGETNUMVM:
254 return(gp->g_mode(gp, GM_GRFGETNUMVM, data, 0, 0));
255 /*
256 * these are all hardware dependant, and have to be resolved
257 * in the respective driver.
258 */
259 case GRFIOCPUTCMAP:
260 case GRFIOCGETCMAP:
261 case GRFIOCSSPRITEPOS:
262 case GRFIOCGSPRITEPOS:
263 case GRFIOCSSPRITEINF:
264 case GRFIOCGSPRITEINF:
265 case GRFIOCGSPRITEMAX:
266 default:
267 /*
268 * check to see whether it's a command recognized by the
269 * view code.
270 */
271 return(viewioctl(gp->g_viewdev, cmd, data, flag, p));
272 error = EINVAL;
273 break;
274
275 }
276 return(error);
277 }
278
279 /*ARGSUSED*/
280 int
281 grfpoll(devvp, events, p)
282 struct vnode *devvp;
283 int events;
284 struct proc *p;
285 {
286 int revents = 0;
287
288 if (events & (POLLOUT | POLLWRNORM))
289 revents |= events & (POLLOUT | POLLWRNORM);
290 return (revents);
291 }
292
293 /*
294 * map the contents of a graphics display card into process'
295 * memory space.
296 */
297 paddr_t
298 grfmmap(devvp, off, prot)
299 struct vnode *devvp;
300 off_t off;
301 int prot;
302 {
303 struct grf_softc *gp;
304 struct grfinfo *gi;
305 u_int vgabase, linbase;
306
307 gp = vdev_privdata(devvp);
308
309 gi = &gp->g_display;
310
311 vgabase = gi->gd_vgabase;
312 linbase = gi->gd_linbase;
313
314 /*
315 * control registers
316 */
317 if (off >= 0 && off < gi->gd_regsize)
318 return(((paddr_t)gi->gd_regaddr + off) >> PGSHIFT);
319
320 /*
321 * VGA memory
322 */
323 if (off >= vgabase && off < (vgabase + gi->gd_vgasize))
324 return(((paddr_t)gi->gd_vgaaddr - vgabase + off) >> PGSHIFT);
325
326 /*
327 * frame buffer
328 */
329 if (off >= linbase && off < (linbase + gi->gd_fbsize))
330 return(((paddr_t)gi->gd_fbaddr - linbase + off) >> PGSHIFT);
331 return(-1);
332 }
333
334 int
335 grfon(dev)
336 dev_t dev;
337 {
338 struct grf_softc *gp;
339
340 gp = grfsp[GRFUNIT(dev)];
341
342 if (gp->g_flags & GF_GRFON)
343 return(0);
344
345 gp->g_flags |= GF_GRFON;
346 if (gp->g_itedev != NODEV)
347 ite_off(gp->g_itedev, 3);
348
349 return(gp->g_mode(gp, (dev & GRFOVDEV) ? GM_GRFOVON : GM_GRFON,
350 NULL, 0, 0));
351 }
352
353 int
354 grfoff(dev)
355 dev_t dev;
356 {
357 struct grf_softc *gp;
358 int error;
359
360 gp = grfsp[GRFUNIT(dev)];
361
362 if ((gp->g_flags & GF_GRFON) == 0)
363 return(0);
364
365 gp->g_flags &= ~GF_GRFON;
366 error = gp->g_mode(gp, (dev & GRFOVDEV) ? GM_GRFOVOFF : GM_GRFOFF,
367 NULL, 0, 0);
368
369 /*
370 * Closely tied together no X's
371 */
372 if (gp->g_itedev != NODEV)
373 ite_on(gp->g_itedev, 2);
374
375 return(error);
376 }
377
378 int
379 grfsinfo(dev, dyninfo)
380 dev_t dev;
381 struct grfdyninfo *dyninfo;
382 {
383 struct grf_softc *gp;
384 int error;
385
386 gp = grfsp[GRFUNIT(dev)];
387 error = gp->g_mode(gp, GM_GRFCONFIG, dyninfo, 0, 0);
388
389 /*
390 * Closely tied together no X's
391 */
392 if (gp->g_itedev != NODEV)
393 ite_reinit(gp->g_itedev);
394 return(error);
395 }
396
397 /*
398 * Get the grf-info in sync with underlying view.
399 */
400 void
401 grf_viewsync(gp)
402 struct grf_softc *gp;
403 {
404 struct view_size vs;
405 bmap_t bm;
406 struct grfinfo *gi;
407
408 gi = &gp->g_display;
409
410 viewioctl(gp->g_viewdev, VIOCGBMAP, (caddr_t)&bm, 0, NOPROC);
411
412 gp->g_data = (caddr_t) 0xDeadBeaf; /* not particularly clean.. */
413
414 gi->gd_fbaddr = bm.hw_address;
415 gi->gd_fbsize = bm.phys_mappable;
416 gi->gd_linbase = bm.lin_base;
417 gi->gd_regaddr = bm.hw_regs;
418 gi->gd_regsize = bm.reg_size;
419 gi->gd_vgaaddr = bm.vga_address;
420 gi->gd_vgasize = bm.vga_mappable;
421 gi->gd_vgabase = bm.vga_base;
422
423 if(viewioctl(gp->g_viewdev, VIOCGSIZE, (caddr_t)&vs, 0, NOPROC)) {
424 /*
425 * fill in some default values...
426 * XXX: Should _never_ happen
427 */
428 vs.width = 640;
429 vs.height = 400;
430 vs.depth = 1;
431 }
432 gi->gd_colors = 1 << vs.depth;
433 gi->gd_planes = vs.depth;
434
435 gi->gd_fbwidth = vs.width;
436 gi->gd_fbheight = vs.height;
437 gi->gd_dyn.gdi_fbx = 0;
438 gi->gd_dyn.gdi_fby = 0;
439 gi->gd_dyn.gdi_dwidth = vs.width;
440 gi->gd_dyn.gdi_dheight = vs.height;
441 gi->gd_dyn.gdi_dx = 0;
442 gi->gd_dyn.gdi_dy = 0;
443 }
444
445 /*
446 * Change the mode of the display.
447 * Right now all we can do is grfon/grfoff.
448 * Return a UNIX error number or 0 for success.
449 */
450 /*ARGSUSED*/
451 int
452 grf_mode(gp, cmd, arg, a2, a3)
453 struct grf_softc *gp;
454 int cmd, a2, a3;
455 void *arg;
456 {
457 switch (cmd) {
458 case GM_GRFON:
459 /*
460 * Get in sync with view, ite might have changed it.
461 */
462 grf_viewsync(gp);
463 viewioctl(gp->g_viewdev, VIOCDISPLAY, NULL, 0, NOPROC);
464 return(0);
465 case GM_GRFOFF:
466 viewioctl(gp->g_viewdev, VIOCREMOVE, NULL, 0, NOPROC);
467 return(0);
468 case GM_GRFCONFIG:
469 default:
470 break;
471 }
472 return(EINVAL);
473 }
474 #endif /* NGRF > 0 */
475