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