grf_ul.c revision 1.43 1 /* $NetBSD: grf_ul.c,v 1.43 2009/03/14 15:36:01 dsl Exp $ */
2 #define UL_DEBUG
3
4 /*-
5 * Copyright (c) 1995 The NetBSD Foundation, Inc.
6 * All rights reserved.
7 *
8 * This code is derived from software contributed to The NetBSD Foundation
9 * by Ignatios Souvatzis.
10 *
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions
13 * are met:
14 * 1. Redistributions of source code must retain the above copyright
15 * notice, this list of conditions and the following disclaimer.
16 * 2. Redistributions in binary form must reproduce the above copyright
17 * notice, this list of conditions and the following disclaimer in the
18 * documentation and/or other materials provided with the distribution.
19 *
20 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
21 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
22 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
23 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
24 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
25 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
26 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
27 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
28 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
29 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
30 * POSSIBILITY OF SUCH DAMAGE.
31 */
32
33 #include "opt_amigacons.h"
34
35 #include <sys/cdefs.h>
36 __KERNEL_RCSID(0, "$NetBSD: grf_ul.c,v 1.43 2009/03/14 15:36:01 dsl Exp $");
37
38 #include "grful.h"
39 #if NGRFUL > 0
40
41 /* Graphics routines for the University of Lowell A2410 board,
42 using the TMS34010 processor. */
43
44 #include <sys/param.h>
45 #include <sys/systm.h>
46 #include <sys/errno.h>
47 #include <sys/ioctl.h>
48 #include <sys/device.h>
49 #include <sys/malloc.h>
50 #include <sys/syslog.h>
51
52 #include <machine/cpu.h>
53
54 #include <amiga/amiga/device.h>
55 #include <amiga/amiga/isr.h>
56 #include <amiga/dev/zbusvar.h>
57 #include <amiga/dev/grfioctl.h>
58 #include <amiga/dev/grfvar.h>
59 #include <amiga/dev/grf_ulreg.h>
60
61 extern u_int16_t tmscode[];
62
63 int ul_ioctl(struct grf_softc *, u_long, void *, dev_t);
64 int ul_getcmap(struct grf_softc *, struct grf_colormap *, dev_t);
65 int ul_putcmap(struct grf_softc *, struct grf_colormap *, dev_t);
66 int ul_bitblt(struct grf_softc *, struct grf_bitblt *, dev_t);
67 int ul_blank(struct grf_softc *, int *, dev_t);
68
69 static int ulisr(void *);
70 int ulowell_alive(struct grfvideo_mode *);
71 static void ul_load_code(struct grf_softc *);
72 static int ul_load_mon(struct grf_softc *, struct grfvideo_mode *);
73 static int ul_getvmode(struct grf_softc *, struct grfvideo_mode *);
74 static int ul_setvmode(struct grf_softc *, unsigned);
75 static inline void ul_setfb(struct grf_softc *, u_long);
76
77 /*
78 * marked true early so that ulowell_cnprobe() can tell if we are alive.
79 */
80 int ulowell_inited;
81
82 /* standard-palette definition */
83 u_int8_t ul_std_palette[] = {
84 0,128, 0,128, 0,128, 0,128, 0,255, 0,255, 0,255, 0,255,
85 0, 0,128,128, 0, 0,128,128, 0, 0,255,255, 0, 0,255,255,
86 0, 0, 0, 0, 128,128,128,128, 0, 0, 0, 0, 255,255,255,255};
87
88 u_int8_t ul_ovl_palette[] = {
89 128, 0, 0, 0,
90 128, 0, 0, 0,
91 128, 0, 0, 0};
92
93 struct grfvideo_mode ul_monitor_defs[] = {
94
95 /*
96 * We give all these values in MI units, that is:
97 * horizontal timings in units of pixels
98 * vertical timings in units of lines
99 * point of reference is blanking end.
100 *
101 * The ul_load_mon transforms these values right before loading
102 * them into the chip.
103 *
104 * This leaves us with a single point where things are transformed,
105 * which should make life easier if we ever change things again.
106 */
107
108 /* 1024x768, 60Hz */
109 {1,"1024x768", 66667000, 1024,768,8, 1024,1088,1296,1392,
110 768,771,774,798, 0},
111 /* 864x648, 70Hz */
112 {2,"864x648", 50000000, 864,648,8, 864,928,992,1056,
113 648,658,663,678, 0},
114 /* 800x600, 60Hz */
115 {3, "800x600", 36000000, 800,600,8, 800,864,928,992,
116 600,610,615,630, 0},
117 /* 640x400, 60 Hz, interlaced */
118 {4, "640x400i", 14318000, 640,400,8, 640,768,832,912,
119 200,223,203,240, 1},
120 /* 1024x768, 65Hz interlaced, s.th. is strange */
121 {5, "1024x768?i", 44980000, 1024,768,8, 1024,1072,1136,1280,
122 488,509,512,534, 1},
123 /* 1024x1024, 60Hz */
124 {6, "1024x1024", 80000000, 1024,1024,8, 1024,1040,1120,1248,
125 1024,1027,1030,1055, 0},
126 /* 736x480, 60 Hz */
127 {7, "736x480", 28636300, 736,480,8, 736,784,848,928,
128 480,491,495,515, 0},
129 };
130
131 int ulowell_mon_max = sizeof (ul_monitor_defs)/sizeof (ul_monitor_defs[0]);
132
133 /* option settable */
134 #ifndef ULOWELL_OSC1
135 #define ULOWELL_OSC1 36000000
136 #endif
137
138 #ifndef ULOWELL_OSC2
139 #define ULOWELL_OSC2 66667000
140 #endif
141
142 #ifndef ULOWELL_DEFAULT_MON
143 #define ULOWELL_DEFAULT_MON 1
144 #endif
145
146 /* patchable */
147 int ulowell_default_mon = ULOWELL_DEFAULT_MON;
148 int ulowell_default_gfx = ULOWELL_DEFAULT_MON;
149
150 /*
151 * yes, this should be per board. We don't pay service to multiple boards,
152 * anyway.
153 */
154
155 u_long ulowell_clock[2] = { ULOWELL_OSC2, ULOWELL_OSC1 };
156
157 static struct grfvideo_mode *current_mon;
158
159 /*
160 * We dont use ints at the moment, but will need this later to avoid
161 * busy_waiting in gsp_write, and we use it for spurious int warnings.
162 */
163
164 static int
165 ulisr(void *arg)
166 {
167 struct grf_softc *gp = arg;
168 volatile struct gspregs *ba;
169 u_int16_t thebits;
170
171 if (gp == NULL)
172 return 0;
173
174 ba = (volatile struct gspregs *)gp->g_regkva;
175
176 if (ba == NULL)
177 return 0;
178
179 thebits = ba->ctrl;
180 if (thebits & INTOUT) {
181 log(LOG_INFO, "grf4: got interrupt, ctrl=0x%4x\n", thebits);
182 /* clear int */
183 ba->ctrl = thebits & ~INTOUT;
184 return 1;
185 }
186 return 0;
187 }
188
189 /*
190 * used to query the ulowell board to see if its alive.
191 * for the moment, a NOP.
192 */
193 int
194 ulowell_alive(struct grfvideo_mode *mdp)
195 {
196 return 1;
197 }
198
199 /*
200 * Load the (mostly) ite support code and the default colormaps.
201 */
202 static void
203 ul_load_code(struct grf_softc *gp)
204 {
205 struct grf_ul_softc *gup;
206 volatile struct gspregs *ba;
207 struct grfinfo *gi;
208 int i,j;
209 #if 0
210 struct grf_colormap gcm;
211 #endif
212
213 gup = (struct grf_ul_softc *)gp;
214 ba = (volatile struct gspregs *)gp->g_regkva;
215 gi = &gp->g_display;
216
217 gi->gd_regaddr = ztwopa((volatile void *)ba);
218 gi->gd_regsize = sizeof(struct gspregs);
219 gi->gd_fbaddr = NULL;
220 gi->gd_fbsize = 0;
221 gi->gd_fbwidth = 1024;
222 gi->gd_fbheight = 1024;
223 gi->gd_colors = 256;
224
225 ba->ctrl = (ba->ctrl & ~INCR) | (LBL | INCW);
226 ba->hstadrh = 0xC000;
227 ba->hstadrl = 0x0080;
228 ba->data = 0x0; /* disable screen refresh and video output */
229 ba->data = 0xFFFC; /* screen refresh base address */
230 ba->data = 0xFFFF; /* no display int possible */
231 ba->data = 0x000C; /* CAS before RAS refresh each 64 local clks */
232
233 ba->ctrl = (ba->ctrl & ~INCW) | LBL;
234 ba->hstadrh = 0xfe80;
235 ba->hstadrl = 0;
236 ba->data = 4;
237 ba->hstadrl = 0x20;
238 ba->data = 0xFF; /* all color planes visible */
239
240 ba->hstadrl = 0;
241 ba->data = 5;
242 ba->hstadrl = 0x20;
243 ba->data = 0; /* no color planes blinking */
244
245 ba->hstadrl = 0;
246 ba->data = 6;
247 ba->hstadrl = 0x20;
248 ba->data = gup->gus_ovslct = 0x43;
249 /* overlay visible, no overlay blinking, overlay color 0 transparent */
250
251 ba->hstadrl = 0;
252 ba->data = 7;
253 ba->hstadrl = 0x20;
254 ba->data = 0; /* voodoo */
255
256 /* clear overlay planes */
257 ba->ctrl |= INCW;
258 ba->hstadrh = 0xff80;
259 ba->hstadrl = 0x0000;
260 for (i=0xff80000; i< 0xffa0000; ++i) {
261 ba->data = 0;
262 }
263
264 /* download tms code */
265
266 ba->ctrl = LBL | INCW | NMI | NMIM | HLT | CF;
267
268 printf("\ndownloading TMS code");
269 i=0;
270 while ((j = tmscode[i++])) {
271 printf(".");
272 ba->hstadrh = tmscode[i++];
273 ba->hstadrl = tmscode[i++];
274 while (j-- > 0) {
275 ba->data = tmscode[i++];
276 }
277 }
278
279 /* font info was uploaded in ite_ul.c(ite_ulinit). */
280
281 #if 1
282 /* XXX load image palette with some initial values, slightly hacky */
283
284 ba->hstadrh = 0xfe80;
285 ba->hstadrl = 0x0000;
286 ba->ctrl |= INCW;
287 ba->data = 0;
288 ba->ctrl &= ~INCW;
289
290 for (i=0; i<16; ++i) {
291 ba->data = gup->gus_imcmap[i+ 0] = ul_std_palette[i+ 0];
292 ba->data = gup->gus_imcmap[i+256] = ul_std_palette[i+16];
293 ba->data = gup->gus_imcmap[i+512] = ul_std_palette[i+32];
294 }
295
296 /*
297 * XXX load shadow overlay palette with what the TMS code will load
298 * into the real one some time after the TMS code is started below.
299 * This might be considered a rude hack.
300 */
301 bcopy(ul_ovl_palette, gup->gus_ovcmap, 3*4);
302
303 /*
304 * Unflush cache, unhalt CPU -> nmi starts to run. This MUST NOT BE
305 * DONE before the image color map initialization above, to guarantee
306 * the index register in the BT458 is not used by more than one CPU
307 * at once.
308 *
309 * XXX For the same reason, we'll have to rething ul_putcmap(). For
310 * details, look at comment there.
311 */
312 ba->ctrl &= ~(HLT|CF);
313
314 #else
315 /*
316 * XXX I wonder why this partially ever worked.
317 *
318 * This can't possibly work this way, as we are copyin()ing data in
319 * ul_putcmap.
320 *
321 * I guess this partially worked because SFC happened to point to
322 * to supervisor data space on 68030 machines coming from the old
323 * boot loader.
324 *
325 * While this looks more correct than the hack in the other part of the
326 * loop, we would have to do our own version of the loop through
327 * colormap entries, set up command buffer, and call gsp_write(), or
328 * factor out some code.
329 */
330
331 /*
332 * XXX This version will work for the overlay, if our queue codes
333 * initial conditions are set at load time (not start time).
334 * It further assumes that ul_putcmap only uses the
335 * GRFIMDEV/GRFOVDEV bits of the dev parameter.
336 */
337
338
339 /* unflush cache, unhalt CPU first -> nmi starts to run */
340 ba->ctrl &= ~(HLT|CF);
341
342 gcm.index = 0;
343 gcm.count = 16;
344 gcm.red = ul_std_palette + 0;
345 gcm.green = ul_std_palette + 16;
346 gcm.blue = ul_std_palette + 32;
347 ul_putcmap(gp, &gcm, GRFIMDEV);
348
349 gcm.index = 0;
350 gcm.count = 4;
351 gcm.red = ul_ovl_palette + 0;
352 gcm.green = ul_ovl_palette + 4;
353 gcm.blue = ul_ovl_palette + 8;
354 ul_putcmap(gp, &gcm, GRFOVDEV);
355 #endif
356
357 }
358
359 static int
360 ul_load_mon(struct grf_softc *gp, struct grfvideo_mode *md)
361 {
362 struct grf_ul_softc *gup;
363 struct grfinfo *gi;
364 volatile struct gspregs *ba;
365 u_int16_t buf[8];
366
367 gup = (struct grf_ul_softc *)gp;
368 gi = &gp->g_display;
369 ba = (volatile struct gspregs *)gp->g_regkva;
370
371 gi->gd_dyn.gdi_fbx = 0;
372 gi->gd_dyn.gdi_fby = 0;
373 gi->gd_dyn.gdi_dwidth = md->disp_width;
374 gi->gd_dyn.gdi_dheight = md->disp_height;
375 gi->gd_dyn.gdi_dx = 0;
376 gi->gd_dyn.gdi_dy = 0;
377
378 ba->ctrl = (ba->ctrl & ~INCR) | (LBL | INCW); /* XXX */
379
380 ba->hstadrh = 0xC000;
381 ba->hstadrl = 0x0000;
382
383 ba->data = (md->hsync_stop - md->hsync_start)/16;
384 ba->data = (md->htotal - md->hsync_start)/16 - 1;
385 ba->data = (md->hblank_start + md->htotal - md->hsync_start)/16 - 1;
386 ba->data = md->htotal/16 - 1;
387
388 ba->data = md->vsync_stop - md->vsync_start;
389 ba->data = md->vtotal - md->vsync_start - 1;
390 ba->data = md->vblank_start + md->vtotal - md->vsync_start - 1;
391 ba->data = md->vtotal - 1;
392
393 ba->ctrl &= ~INCW;
394 ba->hstadrh = 0xFE90;
395 ba->hstadrl = 0x0000;
396
397 if (abs(md->pixel_clock - ulowell_clock[0]) >
398 abs(md->pixel_clock - ulowell_clock[1])) {
399
400 ba->data = (ba->data & 0xFC) | 2 | 1;
401 md->pixel_clock = ulowell_clock[1];
402
403 } else {
404 ba->data = (ba->data & 0xFC) | 2 | 0;
405 md->pixel_clock = ulowell_clock[0];
406 }
407
408 ba->ctrl |= LBL | INCW;
409 ba->hstadrh = 0xC000;
410 ba->hstadrl = 0x0080;
411 ba->data = md->disp_flags & GRF_FLAGS_LACE ? 0xb020 : 0xf020;
412
413 /* I guess this should be in the yet unimplemented mode select ioctl */
414 /* Hm.. maybe not. We always put the console on overlay plane no 0. */
415 /* Anyway, this _IS_ called in the mode select ioctl. */
416
417 /* ite support code parameters: */
418 buf[0] = GCMD_MCHG;
419 buf[1] = md->disp_width; /* display width */
420 buf[2] = md->disp_height; /* display height */
421 buf[3] = 0; /* LSW of frame buffer origin */
422 buf[4] = 0xFF80; /* MSW of frame buffer origin */
423 buf[5] = gi->gd_fbwidth * 1; /* frame buffer pitch */
424 buf[6] = 1; /* frame buffer depth */
425 gsp_write(ba, buf, 7);
426
427 return(1);
428 }
429
430 int ul_mode(struct grf_softc *, u_long, void *, u_long, int);
431
432 void grfulattach(struct device *, struct device *, void *);
433 int grfulprint(void *, const char *);
434 int grfulmatch(struct device *, struct cfdata *, void *);
435
436 CFATTACH_DECL(grful, sizeof(struct grf_ul_softc),
437 grfulmatch, grfulattach, NULL, NULL);
438
439 /*
440 * only used in console init
441 */
442 static struct cfdata *cfdata;
443
444 /*
445 * we make sure to only init things once. this is somewhat
446 * tricky regarding the console.
447 */
448 int
449 grfulmatch(struct device *pdp, struct cfdata *cfp, void *auxp)
450 {
451 #ifdef ULOWELLCONSOLE
452 static int ulconunit = -1;
453 #endif
454 struct zbus_args *zap;
455
456 zap = auxp;
457
458 /*
459 * allow only one ulowell console
460 */
461 if (amiga_realconfig == 0)
462 #ifdef ULOWELLCONSOLE
463 if (ulconunit != -1)
464 #endif
465 return(0);
466
467 if (zap->manid != 1030 || zap->prodid != 0)
468 return(0);
469
470 #ifdef ULOWELLCONSOLE
471 if (amiga_realconfig == 0 || ulconunit != cfp->cf_unit) {
472 #endif
473 if ((unsigned)ulowell_default_mon > ulowell_mon_max)
474 ulowell_default_mon = 1;
475
476 current_mon = ul_monitor_defs + ulowell_default_mon - 1;
477 if (ulowell_alive(current_mon) == 0)
478 return(0);
479 #ifdef ULOWELLCONSOLE
480 if (amiga_realconfig == 0) {
481 ulconunit = cfp->cf_unit;
482 cfdata = cfp;
483 }
484 }
485 #endif
486 return(1);
487 }
488
489 /*
490 * attach to the grfbus (zbus)
491 */
492 void
493 grfulattach(pdp, dp, auxp)
494 struct device *pdp, *dp;
495 void *auxp;
496 {
497 static struct grf_ul_softc congrf;
498 struct zbus_args *zap;
499 struct grf_softc *gp;
500 struct grf_ul_softc *gup;
501
502 zap = auxp;
503
504 if (dp == NULL)
505 gup = &congrf;
506 else
507 gup = (struct grf_ul_softc *)dp;
508
509 gp = &gup->gus_sc;
510
511 if (dp != NULL && congrf.gus_sc.g_regkva != 0) {
512 /*
513 * inited earlier, just copy (not device struct)
514 */
515 bcopy(&congrf.gus_sc.g_display, &gp->g_display,
516 (char *)&gup->gus_isr - (char *)&gp->g_display);
517
518 /* ...and transfer the isr */
519 gup->gus_isr.isr_ipl = 2;
520 gup->gus_isr.isr_intr = ulisr;
521 gup->gus_isr.isr_arg = (void *)gp;
522 /*
523 * To make sure ints are always catched, first add new isr
524 * then remove old:
525 */
526 add_isr(&gup->gus_isr);
527 remove_isr(&congrf.gus_isr);
528 } else {
529 gp->g_regkva = (void *)zap->va;
530 gp->g_fbkva = NULL;
531 gp->g_unit = GRF_ULOWELL_UNIT;
532 gp->g_flags = GF_ALIVE;
533 gp->g_mode = ul_mode;
534 gp->g_conpri = grful_cnprobe();
535 gp->g_data = NULL;
536
537 gup->gus_isr.isr_ipl = 2;
538 gup->gus_isr.isr_intr = ulisr;
539 gup->gus_isr.isr_arg = (void *)gp;
540 add_isr(&gup->gus_isr);
541
542 (void)ul_load_code(gp);
543 (void)ul_load_mon(gp, current_mon);
544 grful_iteinit(gp);
545 }
546 if (dp != NULL)
547 printf("\n");
548 /*
549 * attach grf
550 */
551 amiga_config_found(cfdata, &gp->g_device, gp, grfulprint);
552 }
553
554 int
555 grfulprint(void *auxp, const char *pnp)
556 {
557 if (pnp)
558 aprint_normal("grf%d at %s", ((struct grf_softc *)auxp)->g_unit,
559 pnp);
560 return(UNCONF);
561 }
562
563 static int
564 ul_getvmode (gp, vm)
565 struct grf_softc *gp;
566 struct grfvideo_mode *vm;
567 {
568 struct grfvideo_mode *md;
569
570 if (vm->mode_num && vm->mode_num > ulowell_mon_max)
571 return EINVAL;
572
573 if (! vm->mode_num)
574 vm->mode_num = current_mon - ul_monitor_defs + 1;
575
576 md = ul_monitor_defs + vm->mode_num - 1;
577 strncpy (vm->mode_descr, md->mode_descr,
578 sizeof (vm->mode_descr));
579
580 /* XXX should tell TMS to measure it */
581 vm->pixel_clock = md->pixel_clock;
582 vm->disp_width = md->disp_width;
583 vm->disp_height = md->disp_height;
584 vm->depth = md->depth;
585
586 vm->hblank_start = md->hblank_start;
587 vm->hsync_start = md->hsync_start;
588 vm->hsync_stop = md->hsync_stop;
589 vm->htotal = md->htotal;
590
591 vm->vblank_start = md->vblank_start;
592 vm->vsync_start = md->vsync_start;
593 vm->vsync_stop = md->vsync_stop;
594 vm->vtotal = md->vtotal;
595
596 vm->disp_flags = md->disp_flags;
597 return 0;
598 }
599
600
601 static int
602 ul_setvmode (gp, mode)
603 struct grf_softc *gp;
604 unsigned mode;
605 {
606 struct grf_ul_softc *gup;
607 volatile struct gspregs *ba;
608 int error;
609
610 if (!mode || mode > ulowell_mon_max)
611 return EINVAL;
612
613 ba = (volatile struct gspregs *)gp->g_regkva;
614 gup = (struct grf_ul_softc *)gp;
615 current_mon = ul_monitor_defs + mode - 1;
616
617 error = ul_load_mon (gp, current_mon) ? 0 : EINVAL;
618
619 return error;
620 }
621
622 /*
623 * Set the frame buffer or overlay planes on or off.
624 * Always succeeds.
625 */
626
627 static inline void
628 ul_setfb(struct grf_softc *gp, u_long cmd)
629 {
630 struct grf_ul_softc *gup;
631 volatile struct gspregs *ba;
632
633 gup = (struct grf_ul_softc *)gp;
634
635 ba = (volatile struct gspregs *)gp->g_regkva;
636 ba->ctrl = LBL;
637 ba->hstadrh = 0xfe80;
638 ba->hstadrl = 0x0000;
639 ba->data = 6;
640 ba->hstadrl = 0x0020;
641
642 switch (cmd) {
643 case GM_GRFON:
644 gup->gus_ovslct |= 0x40;
645 break;
646 case GM_GRFOFF:
647 gup->gus_ovslct &= ~0x40;
648 break;
649 case GM_GRFOVON:
650 gup->gus_ovslct |= 3;
651 break;
652 case GM_GRFOVOFF:
653 gup->gus_ovslct &= ~3;
654 break;
655 }
656 ba->data = gup->gus_ovslct;
657 }
658
659 /*
660 * Change the mode of the display.
661 * Return a UNIX error number or 0 for success.
662 */
663 int
664 ul_mode(struct grf_softc *gp, u_long cmd, void *arg, u_long a2, int a3)
665 {
666 int i;
667 struct grfdyninfo *gd;
668
669 switch (cmd) {
670 case GM_GRFON:
671 case GM_GRFOFF:
672 case GM_GRFOVON:
673 case GM_GRFOVOFF:
674 ul_setfb (gp, cmd);
675 return 0;
676
677 case GM_GRFCONFIG:
678 gd = (struct grfdyninfo *)arg;
679 for (i=0; i<ulowell_mon_max; ++i) {
680 if (ul_monitor_defs[i].disp_width == gd->gdi_dwidth &&
681 ul_monitor_defs[i].disp_height == gd->gdi_dheight)
682 return ul_setvmode(gp, i+1);
683 }
684 return EINVAL;
685
686 case GM_GRFGETVMODE:
687 return ul_getvmode (gp, (struct grfvideo_mode *) arg);
688
689 case GM_GRFSETVMODE:
690 return ul_setvmode (gp, *(unsigned *) arg);
691
692 case GM_GRFGETNUMVM:
693 *(int *)arg = ulowell_mon_max;
694 return 0;
695
696 case GM_GRFIOCTL:
697 return ul_ioctl (gp, a2, arg, (dev_t)a3);
698
699 default:
700 break;
701 }
702
703 return EPASSTHROUGH;
704 }
705
706 int
707 ul_ioctl (gp, cmd, data, dev)
708 register struct grf_softc *gp;
709 u_long cmd;
710 void *data;
711 dev_t dev;
712 {
713 switch (cmd) {
714 #if 0
715 /*
716 * XXX we have no hardware sprites, but might implement them
717 * later in TMS code.
718 */
719
720 case GRFIOCGSPRITEPOS:
721 return ul_getspritepos (gp, (struct grf_position *) data);
722
723 case GRFIOCSSPRITEPOS:
724 return ul_setspritepos (gp, (struct grf_position *) data);
725
726 case GRFIOCSSPRITEINF:
727 return ul_setspriteinfo (gp, (struct grf_spriteinfo *) data);
728
729 case GRFIOCGSPRITEINF:
730 return ul_getspriteinfo (gp, (struct grf_spriteinfo *) data);
731
732 case GRFIOCGSPRITEMAX:
733 return ul_getspritemax (gp, (struct grf_position *) data);
734
735 #endif
736
737 case GRFIOCGETCMAP:
738 return ul_getcmap (gp, (struct grf_colormap *) data, dev);
739
740 case GRFIOCPUTCMAP:
741 return ul_putcmap (gp, (struct grf_colormap *) data, dev);
742
743 case GRFIOCBITBLT:
744 return ul_bitblt (gp, (struct grf_bitblt *) data, dev);
745
746 case GRFIOCBLANK:
747 return ul_blank (gp, (int *) data, dev);
748 }
749
750 return EPASSTHROUGH;
751 }
752
753 int
754 ul_getcmap (gp, cmap, dev)
755 struct grf_softc *gp;
756 struct grf_colormap *cmap;
757 dev_t dev;
758 {
759 struct grf_ul_softc *gup;
760 u_int8_t *mymap;
761 int mxidx, error;
762
763 gup = (struct grf_ul_softc *)gp;
764
765 if (minor(dev) & GRFIMDEV) {
766 mxidx = 256;
767 mymap = gup->gus_imcmap;
768 } else {
769 mxidx = 4;
770 mymap = gup->gus_ovcmap;
771 }
772
773 if (cmap->count == 0 || cmap->index >= mxidx)
774 return 0;
775
776 if (cmap->count > mxidx - cmap->index)
777 cmap->count = mxidx - cmap->index;
778
779 /* just copyout from the shadow color map */
780
781 if ((error = copyout(mymap + cmap->index, cmap->red, cmap->count))
782
783 || (error = copyout(mymap + mxidx + cmap->index, cmap->green,
784 cmap->count))
785
786 || (error = copyout(mymap + mxidx * 2 + cmap->index, cmap->blue,
787 cmap->count)))
788
789 return(error);
790
791 return(0);
792 }
793
794 int
795 ul_putcmap (gp, cmap, dev)
796 struct grf_softc *gp;
797 struct grf_colormap *cmap;
798 dev_t dev;
799 {
800 struct grf_ul_softc *gup;
801 volatile struct gspregs *ba;
802 u_int16_t cmd[8];
803 int x, mxidx, error;
804 u_int8_t *mymap;
805
806 gup = (struct grf_ul_softc *)gp;
807
808 if (minor(dev) & GRFIMDEV) {
809 mxidx = 256;
810 mymap = gup->gus_imcmap;
811 } else {
812 mxidx = 4;
813 mymap = gup->gus_ovcmap;
814 }
815
816 if (cmap->count == 0 || cmap->index >= mxidx)
817 return 0;
818
819 if (cmap->count > mxidx - cmap->index)
820 cmap->count = mxidx - cmap->index;
821
822 /* first copyin to our shadow color map */
823
824 if ((error = copyin(cmap->red, mymap + cmap->index, cmap->count))
825
826 || (error = copyin(cmap->green, mymap + cmap->index + mxidx,
827 cmap->count))
828
829 || (error = copyin(cmap->blue, mymap + cmap->index + mxidx*2,
830 cmap->count)))
831
832 return error;
833
834
835 /* then write from there to the hardware */
836 ba = (volatile struct gspregs *)gp->g_regkva;
837 /*
838 * XXX This is a bad thing to do.
839 * We should always use the gsp call, or have a means to arbitrate
840 * the usage of the BT458 index register. Else there might be a
841 * race condition (when writing both colormaps at nearly the same
842 * time), where one CPU changes the index register when the other
843 * one has not finished using it.
844 */
845 if (mxidx > 4) {
846 /* image color map: we can write, with a hack, directly */
847 ba->ctrl = LBL;
848 ba->hstadrh = 0xfe80;
849 ba->hstadrl = 0x0000;
850 ba->ctrl |= INCW;
851 ba->data = cmap->index;
852 ba->ctrl &= ~INCW;
853
854 for (x=cmap->index; x < cmap->index + cmap->count; ++x) {
855 ba->data = (u_int16_t) mymap[x];
856 ba->data = (u_int16_t) mymap[x + mxidx];
857 ba->data = (u_int16_t) mymap[x + mxidx * 2];
858 }
859 } else {
860
861 /* overlay planes color map: have to call tms to do it */
862 cmd[0] = GCMD_CMAP;
863 cmd[1] = 1;
864 for (x=cmap->index; x < cmap->index + cmap->count; ++x) {
865 cmd[2] = x;
866 cmd[3] = mymap[x];
867 cmd[4] = mymap[x + mxidx];
868 cmd[5] = mymap[x + mxidx * 2];
869 gsp_write(ba, cmd, 6);
870 }
871 }
872 return 0;
873 }
874
875 int
876 ul_blank(struct grf_softc *gp, int *onoff, dev_t dev)
877 {
878 volatile struct gspregs *gsp;
879
880 gsp = (volatile struct gspregs *)gp->g_regkva;
881 gsp->ctrl = (gsp->ctrl & ~(INCR | INCW)) | LBL;
882 gsp->hstadrh = 0xC000;
883 gsp->hstadrl = 0x0080;
884 if (*onoff > 0)
885 gsp->data |= 0x9000;
886 else
887 gsp->data &= ~0x9000;
888
889 return 0;
890 }
891 /*
892 * !!! THIS AREA UNDER CONSTRUCTION !!!
893 */
894 int ul_BltOpMap[16] = {
895 3, 1, 2, 0, 11, 9, 10, 8,
896 7, 5, 6, 4, 15, 13, 14, 12
897 };
898
899 int
900 ul_bitblt (gp, bb, dev)
901 struct grf_softc *gp;
902 struct grf_bitblt *bb;
903 dev_t dev;
904 {
905 /* XXX not yet implemented, but pretty trivial */
906 return EPASSTHROUGH;
907 }
908
909 void
910 gsp_write(volatile struct gspregs *gsp, u_short *ptr, size_t size)
911 {
912 u_short put, new_put, next, oc;
913 u_long put_hi, oa;
914 size_t n;
915
916 if (size == 0 || size > 8)
917 return;
918
919 n = size;
920
921 oc = gsp->ctrl;
922 oa = GSPGETHADRS(gsp);
923
924 gsp->ctrl = (oc & ~INCR) | LBL | INCW;
925 GSPSETHADRS(gsp, GSP_MODE_ADRS);
926 gsp->data &= ~GMODE_FLUSH;
927
928 GSPSETHADRS(gsp, PUT_HI_PTR_ADRS);
929 put_hi = gsp->data << 16;
930
931 GSPSETHADRS(gsp, PUT_PTR_ADRS);
932 put = gsp->data;
933 new_put = put + (8<<4);
934
935 GSPSETHADRS(gsp, GET_PTR_ADRS);
936 next = gsp->data;
937
938 while (next == new_put) {
939 /*
940 * we should use an intr. here. unfortunately, we already
941 * are called from an interrupt and can't use tsleep.
942 * so we do busy waiting, at least for the moment.
943 */
944
945 GSPSETHADRS(gsp,GET_PTR_ADRS);
946 next = gsp->data;
947 }
948
949 GSPSETHADRS(gsp,put|put_hi);
950 gsp->data = *ptr++ | 8<<4;
951 while ( --n > 0) {
952 gsp->data = *ptr++;
953 }
954
955 GSPSETHADRS(gsp,PUT_PTR_ADRS);
956 gsp->data = new_put;
957 GSPSETHADRS(gsp,oa);
958 gsp->ctrl = oc;
959
960 return;
961 }
962
963 #endif /* NGRF */
964