grf.c revision 1.25.4.4 1 /* $NetBSD: grf.c,v 1.25.4.4 2002/10/10 18:32:00 jdolecek 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
93 int grfbusprint __P((void *auxp, const char *));
94 int grfbusmatch __P((struct device *, struct cfdata *, void *));
95 void grfbusattach __P((struct device *, struct device *, void *));
96
97 /*
98 * pointers to grf drivers device structs
99 */
100 struct grf_softc *grfsp[NGRF]; /* XXX */
101
102 CFATTACH_DECL(grfbus, sizeof(struct device),
103 grfbusmatch, grfbusattach, NULL, NULL);
104
105 extern struct cfdriver grfbus_cd;
106
107 dev_type_open(grfopen);
108 dev_type_close(grfclose);
109 dev_type_ioctl(grfioctl);
110 dev_type_poll(grfpoll);
111 dev_type_mmap(grfmmap);
112 dev_type_kqfilter(grfkqfilter);
113
114 const struct cdevsw grf_cdevsw = {
115 grfopen, grfclose, noread, nowrite, grfioctl,
116 nostop, notty, grfpoll, grfmmap, grfkqfilter,
117 };
118
119 /*
120 * only used in console init.
121 */
122 static struct cfdata *cfdata_gbus = NULL;
123
124 int
125 grfbusmatch(pdp, cfp, auxp)
126 struct device *pdp;
127 struct cfdata *cfp;
128 void *auxp;
129 {
130 if(strcmp(auxp, grfbus_cd.cd_name))
131 return(0);
132
133 if(atari_realconfig == 0)
134 cfdata_gbus = cfp;
135 return(1); /* Always there */
136 }
137
138 void
139 grfbusattach(pdp, dp, auxp)
140 struct device *pdp, *dp;
141 void *auxp;
142 {
143 grf_auxp_t grf_auxp;
144
145 grf_auxp.busprint = grfbusprint;
146 grf_auxp.from_bus_match = 1;
147
148 if(dp == NULL) /* Console init */
149 atari_config_found(cfdata_gbus, NULL, (void*)&grf_auxp, grfbusprint);
150 else {
151 printf("\n");
152 config_found(dp, (void*)&grf_auxp, grfbusprint);
153 }
154 }
155
156 int
157 grfbusprint(auxp, name)
158 void *auxp;
159 const char *name;
160 {
161 if(name == NULL)
162 return(UNCONF);
163 return(QUIET);
164 }
165
166 /*ARGSUSED*/
167 int
168 grfopen(dev, flags, devtype, p)
169 dev_t dev;
170 int flags, devtype;
171 struct proc *p;
172 {
173 struct grf_softc *gp;
174
175 if (GRFUNIT(dev) >= NGRF)
176 return(ENXIO);
177
178 gp = grfsp[GRFUNIT(dev)];
179 if (gp == NULL)
180 return(ENXIO);
181
182 if ((gp->g_flags & GF_ALIVE) == 0)
183 return(ENXIO);
184
185 if ((gp->g_flags & (GF_OPEN|GF_EXCLUDE)) == (GF_OPEN|GF_EXCLUDE))
186 return(EBUSY);
187 grf_viewsync(gp);
188
189 return(0);
190 }
191
192 /*ARGSUSED*/
193 int
194 grfclose(dev, flags, mode, p)
195 dev_t dev;
196 int flags;
197 int mode;
198 struct proc *p;
199 {
200 struct grf_softc *gp;
201
202 gp = grfsp[GRFUNIT(dev)];
203 (void)grfoff(dev);
204 gp->g_flags &= GF_ALIVE;
205 return(0);
206 }
207
208 /*ARGSUSED*/
209 int
210 grfioctl(dev, cmd, data, flag, p)
211 dev_t dev;
212 u_long cmd;
213 int flag;
214 caddr_t data;
215 struct proc *p;
216 {
217 struct grf_softc *gp;
218 int error;
219 extern const struct cdevsw view_cdevsw;
220
221 gp = grfsp[GRFUNIT(dev)];
222 error = 0;
223
224 switch (cmd) {
225 case OGRFIOCGINFO:
226 /* argl.. no bank-member.. */
227 bcopy((caddr_t)&gp->g_display, data, sizeof(struct grfinfo)-4);
228 break;
229 case GRFIOCGINFO:
230 bcopy((caddr_t)&gp->g_display, data, sizeof(struct grfinfo));
231 break;
232 case GRFIOCON:
233 error = grfon(dev);
234 break;
235 case GRFIOCOFF:
236 error = grfoff(dev);
237 break;
238 case GRFIOCSINFO:
239 error = grfsinfo(dev, (struct grfdyninfo *) data);
240 break;
241 case GRFGETVMODE:
242 return(gp->g_mode(gp, GM_GRFGETVMODE, data, 0, 0));
243 case GRFSETVMODE:
244 error = gp->g_mode(gp, GM_GRFSETVMODE, data, 0, 0);
245 if (error == 0 && gp->g_itedev)
246 ite_reinit(gp->g_itedev);
247 break;
248 case GRFGETNUMVM:
249 return(gp->g_mode(gp, GM_GRFGETNUMVM, data, 0, 0));
250 /*
251 * these are all hardware dependant, and have to be resolved
252 * in the respective driver.
253 */
254 case GRFIOCPUTCMAP:
255 case GRFIOCGETCMAP:
256 case GRFIOCSSPRITEPOS:
257 case GRFIOCGSPRITEPOS:
258 case GRFIOCSSPRITEINF:
259 case GRFIOCGSPRITEINF:
260 case GRFIOCGSPRITEMAX:
261 default:
262 /*
263 * check to see whether it's a command recognized by the
264 * view code.
265 */
266 return((*view_cdevsw.d_ioctl)(gp->g_viewdev, cmd, data, flag,
267 p));
268 error = EINVAL;
269 break;
270
271 }
272 return(error);
273 }
274
275 /*ARGSUSED*/
276 int
277 grfpoll(dev, events, p)
278 dev_t dev;
279 int events;
280 struct proc *p;
281 {
282 int revents = 0;
283
284 if (events & (POLLOUT | POLLWRNORM))
285 revents |= events & (POLLOUT | POLLWRNORM);
286 return (revents);
287 }
288
289 int
290 grfkqfilter(dev_t dev, struct knote *kn)
291 {
292
293 /* XXXLUKEM (thorpej): not supported -- why is poll? */
294 return (1);
295 }
296
297 /*
298 * map the contents of a graphics display card into process'
299 * memory space.
300 */
301 paddr_t
302 grfmmap(dev, off, prot)
303 dev_t dev;
304 off_t off;
305 int prot;
306 {
307 struct grf_softc *gp;
308 struct grfinfo *gi;
309 u_int vgabase, linbase;
310
311 gp = grfsp[GRFUNIT(dev)];
312 gi = &gp->g_display;
313
314 vgabase = gi->gd_vgabase;
315 linbase = gi->gd_linbase;
316
317 /*
318 * control registers
319 */
320 if (off >= 0 && off < gi->gd_regsize)
321 return(((paddr_t)gi->gd_regaddr + off) >> PGSHIFT);
322
323 /*
324 * VGA memory
325 */
326 if (off >= vgabase && off < (vgabase + gi->gd_vgasize))
327 return(((paddr_t)gi->gd_vgaaddr - vgabase + off) >> PGSHIFT);
328
329 /*
330 * frame buffer
331 */
332 if (off >= linbase && off < (linbase + gi->gd_fbsize))
333 return(((paddr_t)gi->gd_fbaddr - linbase + off) >> PGSHIFT);
334 return(-1);
335 }
336
337 int
338 grfon(dev)
339 dev_t dev;
340 {
341 struct grf_softc *gp;
342
343 gp = grfsp[GRFUNIT(dev)];
344
345 if (gp->g_flags & GF_GRFON)
346 return(0);
347
348 gp->g_flags |= GF_GRFON;
349 if (gp->g_itedev != NODEV)
350 ite_off(gp->g_itedev, 3);
351
352 return(gp->g_mode(gp, (dev & GRFOVDEV) ? GM_GRFOVON : GM_GRFON,
353 NULL, 0, 0));
354 }
355
356 int
357 grfoff(dev)
358 dev_t dev;
359 {
360 struct grf_softc *gp;
361 int error;
362
363 gp = grfsp[GRFUNIT(dev)];
364
365 if ((gp->g_flags & GF_GRFON) == 0)
366 return(0);
367
368 gp->g_flags &= ~GF_GRFON;
369 error = gp->g_mode(gp, (dev & GRFOVDEV) ? GM_GRFOVOFF : GM_GRFOFF,
370 NULL, 0, 0);
371
372 /*
373 * Closely tied together no X's
374 */
375 if (gp->g_itedev != NODEV)
376 ite_on(gp->g_itedev, 2);
377
378 return(error);
379 }
380
381 int
382 grfsinfo(dev, dyninfo)
383 dev_t dev;
384 struct grfdyninfo *dyninfo;
385 {
386 struct grf_softc *gp;
387 int error;
388
389 gp = grfsp[GRFUNIT(dev)];
390 error = gp->g_mode(gp, GM_GRFCONFIG, dyninfo, 0, 0);
391
392 /*
393 * Closely tied together no X's
394 */
395 if (gp->g_itedev != NODEV)
396 ite_reinit(gp->g_itedev);
397 return(error);
398 }
399
400 /*
401 * Get the grf-info in sync with underlying view.
402 */
403 void
404 grf_viewsync(gp)
405 struct grf_softc *gp;
406 {
407 struct view_size vs;
408 bmap_t bm;
409 struct grfinfo *gi;
410 extern const struct cdevsw view_cdevsw;
411
412 gi = &gp->g_display;
413
414 (*view_cdevsw.d_ioctl)(gp->g_viewdev, VIOCGBMAP, (caddr_t)&bm,
415 0, NOPROC);
416
417 gp->g_data = (caddr_t) 0xDeadBeaf; /* not particularly clean.. */
418
419 gi->gd_fbaddr = bm.hw_address;
420 gi->gd_fbsize = bm.phys_mappable;
421 gi->gd_linbase = bm.lin_base;
422 gi->gd_regaddr = bm.hw_regs;
423 gi->gd_regsize = bm.reg_size;
424 gi->gd_vgaaddr = bm.vga_address;
425 gi->gd_vgasize = bm.vga_mappable;
426 gi->gd_vgabase = bm.vga_base;
427
428 if((*view_cdevsw.d_ioctl)(gp->g_viewdev, VIOCGSIZE, (caddr_t)&vs, 0,
429 NOPROC)) {
430 /*
431 * fill in some default values...
432 * XXX: Should _never_ happen
433 */
434 vs.width = 640;
435 vs.height = 400;
436 vs.depth = 1;
437 }
438 gi->gd_colors = 1 << vs.depth;
439 gi->gd_planes = vs.depth;
440
441 gi->gd_fbwidth = vs.width;
442 gi->gd_fbheight = vs.height;
443 gi->gd_dyn.gdi_fbx = 0;
444 gi->gd_dyn.gdi_fby = 0;
445 gi->gd_dyn.gdi_dwidth = vs.width;
446 gi->gd_dyn.gdi_dheight = vs.height;
447 gi->gd_dyn.gdi_dx = 0;
448 gi->gd_dyn.gdi_dy = 0;
449 }
450
451 /*
452 * Change the mode of the display.
453 * Right now all we can do is grfon/grfoff.
454 * Return a UNIX error number or 0 for success.
455 */
456 /*ARGSUSED*/
457 int
458 grf_mode(gp, cmd, arg, a2, a3)
459 struct grf_softc *gp;
460 int cmd, a2, a3;
461 void *arg;
462 {
463 extern const struct cdevsw view_cdevsw;
464
465 switch (cmd) {
466 case GM_GRFON:
467 /*
468 * Get in sync with view, ite might have changed it.
469 */
470 grf_viewsync(gp);
471 (*view_cdevsw.d_ioctl)(gp->g_viewdev, VIOCDISPLAY,
472 NULL, 0, NOPROC);
473 return(0);
474 case GM_GRFOFF:
475 (*view_cdevsw.d_ioctl)(gp->g_viewdev, VIOCREMOVE,
476 NULL, 0, NOPROC);
477 return(0);
478 case GM_GRFCONFIG:
479 default:
480 break;
481 }
482 return(EPASSTHROUGH);
483 }
484 #endif /* NGRF > 0 */
485