vidcvideo.c revision 1.23 1 /* $NetBSD: vidcvideo.c,v 1.23 2006/04/15 17:48:23 jmmv Exp $ */
2
3 /*
4 * Copyright (c) 2001 Reinoud Zandijk
5 * Copyright (c) 1998, 1999 Tohru Nishimura. All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 * 3. All advertising materials mentioning features or use of this software
16 * must display the following acknowledgement:
17 * This product includes software developed by Tohru Nishimura
18 * and Reinoud Zandijk for the NetBSD Project.
19 * 4. The name of the author may not be used to endorse or promote products
20 * derived from this software without specific prior written permission
21 *
22 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
23 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
24 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
25 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
26 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
27 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
31 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32 *
33 * Created vidcvideo.c from /dev/tc/cfb.c to fit the Acorn/ARM VIDC1 and VIDC20 chips
34 *
35 */
36
37 #include <sys/cdefs.h> /* RCS ID & Copyright macro defns */
38
39 __KERNEL_RCSID(0, "$NetBSD: vidcvideo.c,v 1.23 2006/04/15 17:48:23 jmmv Exp $");
40
41 #include <sys/param.h>
42 #include <sys/systm.h>
43 #include <sys/kernel.h>
44 #include <sys/device.h>
45 #include <sys/malloc.h>
46 #include <sys/buf.h>
47 #include <sys/ioctl.h>
48
49 #include <arm/mainbus/mainbus.h>
50 #include <machine/bus.h>
51 #include <machine/intr.h>
52
53 #include <dev/wscons/wsconsio.h>
54 #include <dev/wscons/wsdisplayvar.h>
55
56 #include <dev/rasops/rasops.h>
57 #include <dev/wsfont/wsfont.h>
58
59 #include <uvm/uvm_extern.h>
60 #include <arm/arm32/pmap.h>
61 #include <arm/cpufunc.h>
62 #include <machine/intr.h>
63
64 /* for vidc_mode ... needs to be MI indepenent one day */
65 #include <arm/iomd/vidc.h>
66 #include <arm/iomd/vidc20config.h>
67 #include <arm/iomd/vidcvideo.h>
68 #include <machine/bootconfig.h>
69
70 /* FOR DEBUG */
71 extern videomemory_t videomemory;
72
73 struct hwcmap256 {
74 #define CMAP_SIZE 256 /* 256 R/G/B entries */
75 u_int8_t r[CMAP_SIZE];
76 u_int8_t g[CMAP_SIZE];
77 u_int8_t b[CMAP_SIZE];
78 };
79
80
81 /* XXX for CURSOR_MAX_WIDTH = 32 */
82 struct hwcursor32 {
83 struct wsdisplay_curpos cc_pos;
84 struct wsdisplay_curpos cc_hot;
85 struct wsdisplay_curpos cc_size;
86 struct wsdisplay_curpos cc_magic;
87 u_int8_t cc_color[6]; /* how many? */
88 u_int32_t cc_image[(CURSOR_MAX_WIDTH/4) * CURSOR_MAX_HEIGHT];
89 u_int32_t cc_mask[(CURSOR_MAX_WIDTH/4) * CURSOR_MAX_HEIGHT];
90 };
91
92
93 struct fb_devconfig {
94 vaddr_t dc_vaddr; /* memory space virtual base address */
95 paddr_t dc_paddr; /* memory space physical base address */
96 vsize_t dc_size; /* size of slot memory */
97 int dc_wid; /* width of frame buffer */
98 int dc_ht; /* height of frame buffer */
99 int dc_log2_depth; /* log2 of bits per pixel */
100 int dc_depth; /* depth, bits per pixel */
101 int dc_rowbytes; /* bytes in a FB scan line */
102 vaddr_t dc_videobase; /* base of flat frame buffer */
103 int dc_blanked; /* currently has video disabled */
104 void *dc_hwscroll_cookie; /* cookie for hardware scroll */
105
106 int dc_curenb; /* is cursor sprite enabled ? */
107 int dc_changed; /* need update of hardware */
108 int dc_writeback_delay; /* Screenarea write back vsync counter */
109 #define WSDISPLAY_CMAP_DOLUT 0x20
110 #define WSDISPLAY_VIDEO_ONOFF 0x40
111 #define WSDISPLAY_WB_COUNTER 0x80
112
113 struct hwcmap256 dc_cmap;/* software copy of colormap */
114 struct hwcursor32 dc_cursor;/* software copy of cursor */
115
116 struct vidc_mode mode_info;
117 struct rasops_info rinfo;
118
119 struct wsdisplay_emulops orig_ri_ops; /* Rasops functions for deligation */
120 };
121
122
123 struct vidcvideo_softc {
124 struct device sc_dev;
125 struct fb_devconfig *sc_dc; /* device configuration */
126 int nscreens; /* number of screens configured */
127 };
128
129
130 /* XXX has to go XXX */
131 #define CX_MAGIC_X 220
132 #define CX_MAGIC_Y 35
133 #define CX_FB_OFFSET 0x000000
134 #define CX_FB_SIZE 0x100000
135 #define CX_BT459_OFFSET 0x200000
136 #define CX_OFFSET_IREQ 0x300000 /* Interrupt req. control */
137 /* XXX till here XXX */
138
139
140 /* Function prototypes for glue */
141 static int vidcvideo_match __P((struct device *, struct cfdata *, void *));
142 static void vidcvideo_attach __P((struct device *, struct device *, void *));
143
144
145 /* config glue */
146 CFATTACH_DECL(vidcvideo, sizeof(struct vidcvideo_softc),
147 vidcvideo_match, vidcvideo_attach, NULL, NULL);
148
149 static struct fb_devconfig vidcvideo_console_dc;
150 static int vidcvideo_is_console;
151
152
153 static struct wsscreen_descr vidcvideo_stdscreen = {
154 "std", 0, 0,
155 0, /* textops */
156 0, 0,
157 WSSCREEN_REVERSE
158 };
159
160 static const struct wsscreen_descr *_vidcvideo_scrlist[] = {
161 &vidcvideo_stdscreen,
162 };
163
164 static const struct wsscreen_list vidcvideo_screenlist = {
165 sizeof(_vidcvideo_scrlist) / sizeof(struct wsscreen_descr *), _vidcvideo_scrlist
166 };
167
168 static int vidcvideoioctl __P((void *, void *, u_long, caddr_t, int,
169 struct lwp *));
170 static paddr_t vidcvideommap __P((void *, void *, off_t, int));
171
172 static int vidcvideo_alloc_screen __P((void *, const struct wsscreen_descr *,
173 void **, int *, int *, long *));
174 static void vidcvideo_free_screen __P((void *, void *));
175 static int vidcvideo_show_screen __P((void *, void *, int,
176 void (*) (void *, int, int), void *));
177
178 static const struct wsdisplay_accessops vidcvideo_accessops = {
179 vidcvideoioctl,
180 vidcvideommap,
181 vidcvideo_alloc_screen,
182 vidcvideo_free_screen,
183 vidcvideo_show_screen,
184 NULL, /* load_font */
185 NULL /* pollc */
186 };
187
188
189 /* Function prototypes */
190 int vidcvideo_cnattach __P((vaddr_t));
191 static void vidcvideo_colourmap_and_cursor_init __P((struct fb_devconfig *));
192
193 static int get_cmap __P((struct vidcvideo_softc *, struct wsdisplay_cmap *));
194 static int set_cmap __P((struct vidcvideo_softc *, struct wsdisplay_cmap *));
195 static int set_cursor __P((struct vidcvideo_softc *, struct wsdisplay_cursor *));
196 static int get_cursor __P((struct vidcvideo_softc *, struct wsdisplay_cursor *));
197 static void set_curpos __P((struct vidcvideo_softc *, struct wsdisplay_curpos *));
198 static void vidcvideo_getdevconfig __P((vaddr_t, struct fb_devconfig *));
199
200 static int vidcvideointr __P((void *));
201 static void vidcvideo_config_wscons __P((struct fb_devconfig *));
202
203
204 /* Acceleration function prototypes */
205 static void vv_copyrows __P((void *, int, int, int));
206 static void vv_eraserows __P((void *, int, int, long));
207 static void vv_putchar __P((void *c, int row, int col, u_int uc, long attr));
208
209
210 static int
211 vidcvideo_match(parent, match, aux)
212 struct device *parent;
213 struct cfdata *match;
214 void *aux;
215 {
216 /* Can't probe AFAIK ; how ? */
217 return (1);
218 }
219
220
221 static void
222 vidcvideo_getdevconfig(dense_addr, dc)
223 vaddr_t dense_addr;
224 struct fb_devconfig *dc;
225 {
226 dc->dc_vaddr = dense_addr;
227 (void) pmap_extract(pmap_kernel(), dc->dc_vaddr, &(dc->dc_paddr));
228
229 vidcvideo_getmode(&dc->mode_info);
230
231 dc->dc_wid = dc->mode_info.hder;
232 dc->dc_ht = dc->mode_info.vder;
233 dc->dc_log2_depth = dc->mode_info.log2_bpp;
234 dc->dc_depth = 1 << dc->dc_log2_depth;
235 dc->dc_videobase = dc->dc_vaddr;
236 dc->dc_blanked = 0;
237
238 /* this should/could be done somewhat more elegant! */
239 switch (dc->dc_depth) {
240 case 1:
241 dc->dc_rowbytes = dc->dc_wid / 8;
242 break;
243 case 2:
244 dc->dc_rowbytes = dc->dc_wid / 4;
245 break;
246 case 4:
247 dc->dc_rowbytes = dc->dc_wid / 2;
248 break;
249 case 8:
250 dc->dc_rowbytes = dc->dc_wid;
251 break;
252 case 16:
253 dc->dc_rowbytes = dc->dc_wid * 2;
254 break;
255 case 32:
256 dc->dc_rowbytes = dc->dc_wid * 4;
257 break;
258 default:
259 printf("Unknown colour depth %d ... what to do ?", dc->dc_depth);
260 break;
261 };
262
263 /* euhm... correct ? i.e. not complete VIDC memory */
264 dc->dc_size = dc->mode_info.vder * dc->dc_rowbytes;
265
266 /* initialize colormap and cursor resource */
267 vidcvideo_colourmap_and_cursor_init(dc);
268
269 dc->rinfo.ri_flg = 0; /* RI_CENTER; */
270 dc->rinfo.ri_depth = dc->dc_depth;
271 dc->rinfo.ri_bits = (void *) dc->dc_videobase;
272 dc->rinfo.ri_width = dc->dc_wid;
273 dc->rinfo.ri_height = dc->dc_ht;
274 dc->rinfo.ri_stride = dc->dc_rowbytes;
275 dc->rinfo.ri_hw = dc; /* link back */
276
277 /* intitialise miscelanious */
278 dc->dc_writeback_delay = 0;
279 }
280
281
282 static void
283 vidcvideo_config_wscons(dc)
284 struct fb_devconfig *dc;
285 {
286 int i, cookie, font_not_locked;
287
288 /* clear the screen ; why not a memset ? - it was this way so keep it for now */
289 for (i = 0; i < dc->dc_ht * dc->dc_rowbytes; i += sizeof(u_int32_t))
290 *(u_int32_t *)(dc->dc_videobase + i) = 0x0;
291
292 wsfont_init();
293
294 /* prefer 8 pixel wide font */
295 cookie = wsfont_find(NULL, 8, 0, 0, WSDISPLAY_FONTORDER_L2R,
296 WSDISPLAY_FONTORDER_L2R);
297 if (cookie <= 0)
298 cookie = wsfont_find(NULL, 0, 0, 0, WSDISPLAY_FONTORDER_L2R,
299 WSDISPLAY_FONTORDER_L2R);
300
301 if (cookie < 0) {
302 /* Can I even print here ? */
303 printf("Font table empty! exiting\n");
304 return;
305 };
306
307 font_not_locked = wsfont_lock(cookie, &dc->rinfo.ri_font);
308
309 dc->rinfo.ri_wsfcookie = cookie;
310
311 rasops_init(&dc->rinfo,
312 dc->rinfo.ri_height / dc->rinfo.ri_font->fontheight,
313 dc->rinfo.ri_width / dc->rinfo.ri_font->fontwidth
314 );
315
316 /*
317 * Provide a hook for the acceleration functions and make a copy of the
318 * original rasops functions for passing on calls
319 */
320 dc->rinfo.ri_hw = dc;
321 memcpy(&(dc->orig_ri_ops), &(dc->rinfo.ri_ops), sizeof(struct wsdisplay_emulops));
322
323 /* add our accelerated functions */
324 dc->rinfo.ri_ops.eraserows = vv_eraserows;
325 dc->rinfo.ri_ops.copyrows = vv_copyrows;
326
327 /* add the extra activity measuring functions; they just delegate on */
328 dc->rinfo.ri_ops.putchar = vv_putchar;
329
330 /* XXX shouldn't be global */
331 vidcvideo_stdscreen.nrows = dc->rinfo.ri_rows;
332 vidcvideo_stdscreen.ncols = dc->rinfo.ri_cols;
333 vidcvideo_stdscreen.textops = &dc->rinfo.ri_ops;
334 vidcvideo_stdscreen.capabilities = dc->rinfo.ri_caps;
335
336 if (font_not_locked) {
337 printf(" warning ... couldn't lock font! ");
338 };
339 }
340
341
342 static void
343 vidcvideo_attach(parent, self, aux)
344 struct device *parent, *self;
345 void *aux;
346 {
347 struct vidcvideo_softc *sc = (struct vidcvideo_softc *)self;
348 struct fb_devconfig *dc;
349 struct wsemuldisplaydev_attach_args waa;
350 struct hwcmap256 *cm;
351 const u_int8_t *p;
352 long defattr;
353 int index;
354
355 vidcvideo_init();
356 if (sc->nscreens == 0) {
357 sc->sc_dc = &vidcvideo_console_dc;
358 if (!vidcvideo_is_console) {
359 printf(" : non console (no kbd yet) ");
360 vidcvideo_getdevconfig(videomemory.vidm_vbase, sc->sc_dc);
361 vidcvideo_config_wscons(sc->sc_dc);
362 (*sc->sc_dc->rinfo.ri_ops.allocattr)(&sc->sc_dc->rinfo, 0, 0, 0, &defattr);
363 };
364 sc->nscreens = 1;
365 } else {
366 printf(": allready attached ... can't cope with this\n");
367 return;
368 };
369
370 dc = sc->sc_dc;
371
372 vidcvideo_printdetails();
373 printf(": using %d x %d, %dbpp\n", dc->dc_wid, dc->dc_ht,
374 dc->dc_depth);
375
376 /* initialise rasops */
377 cm = &dc->dc_cmap;
378 p = rasops_cmap;
379 for (index = 0; index < CMAP_SIZE; index++, p += 3) {
380 cm->r[index] = p[0];
381 cm->g[index] = p[1];
382 cm->b[index] = p[2];
383 }
384
385 /* what does these do ? */
386 dc->dc_cursor.cc_magic.x = CX_MAGIC_X;
387 dc->dc_cursor.cc_magic.y = CX_MAGIC_Y;
388
389 /* set up interrupt flags */
390 dc->dc_changed |= WSDISPLAY_CMAP_DOLUT;
391
392 /*
393 * Set up a link in the rasops structure to our device config
394 * for acceleration stuff
395 */
396 dc->rinfo.ri_hw = sc->sc_dc;
397
398 /* Establish an interrupt handler, and clear any pending interrupts */
399 intr_claim(IRQ_FLYBACK, IPL_TTY, "vblank", vidcvideointr, dc);
400
401 waa.console = (vidcvideo_is_console ? 1 : 0);
402 waa.scrdata = &vidcvideo_screenlist;
403 waa.accessops = &vidcvideo_accessops;
404 waa.accesscookie = sc;
405
406 config_found(self, &waa, wsemuldisplaydevprint);
407 }
408
409
410 static int
411 vidcvideoioctl(v, vs, cmd, data, flag, l)
412 void *v;
413 void *vs;
414 u_long cmd;
415 caddr_t data;
416 int flag;
417 struct lwp *l;
418 {
419 struct vidcvideo_softc *sc = v;
420 struct fb_devconfig *dc = sc->sc_dc;
421 int state;
422
423 switch (cmd) {
424 case WSDISPLAYIO_GTYPE:
425 *(u_int *)data = WSDISPLAY_TYPE_VIDC;
426 return (0);
427
428 case WSDISPLAYIO_GINFO:
429 #define wsd_fbip ((struct wsdisplay_fbinfo *)data)
430 wsd_fbip->height = dc->dc_ht;
431 wsd_fbip->width = dc->dc_wid;
432 wsd_fbip->depth = dc->dc_depth;
433 wsd_fbip->cmsize = CMAP_SIZE;
434 #undef fbt
435 return (0);
436
437 case WSDISPLAYIO_GETCMAP:
438 return get_cmap(sc, (struct wsdisplay_cmap *)data);
439
440 case WSDISPLAYIO_PUTCMAP:
441 return set_cmap(sc, (struct wsdisplay_cmap *)data);
442
443 case WSDISPLAYIO_SVIDEO:
444 state = *(int *)data;
445 dc->dc_blanked = (state == WSDISPLAYIO_VIDEO_OFF);
446 dc->dc_changed |= WSDISPLAY_VIDEO_ONOFF;
447 /* done on video blank */
448 return (0);
449
450 case WSDISPLAYIO_GVIDEO:
451 *(u_int *)data = dc->dc_blanked ?
452 WSDISPLAYIO_VIDEO_OFF : WSDISPLAYIO_VIDEO_ON;
453 return (0);
454
455 case WSDISPLAYIO_GCURPOS:
456 *(struct wsdisplay_curpos *)data = dc->dc_cursor.cc_pos;
457 return (0);
458
459 case WSDISPLAYIO_SCURPOS:
460 set_curpos(sc, (struct wsdisplay_curpos *)data);
461 dc->dc_changed |= WSDISPLAY_CURSOR_DOPOS;
462 return (0);
463
464 case WSDISPLAYIO_GCURMAX:
465 ((struct wsdisplay_curpos *)data)->x = CURSOR_MAX_WIDTH;
466 ((struct wsdisplay_curpos *)data)->y = CURSOR_MAX_HEIGHT;
467 return (0);
468
469 case WSDISPLAYIO_GCURSOR:
470 return get_cursor(sc, (struct wsdisplay_cursor *)data);
471
472 case WSDISPLAYIO_SCURSOR:
473 return set_cursor(sc, (struct wsdisplay_cursor *)data);
474
475 case WSDISPLAYIO_SMODE:
476 state = *(int *)data;
477 if (state == WSDISPLAYIO_MODE_MAPPED) {
478 dc->dc_hwscroll_cookie = vidcvideo_hwscroll_reset();
479 };
480 if (state == WSDISPLAYIO_MODE_EMUL) {
481 vidcvideo_hwscroll_back(dc->dc_hwscroll_cookie);
482 };
483 vidcvideo_progr_scroll();
484
485 return (0);
486 }
487 return EPASSTHROUGH;
488 }
489
490
491 paddr_t
492 vidcvideommap(v, vs, offset, prot)
493 void *v;
494 void *vs;
495 off_t offset;
496 int prot;
497 {
498 struct vidcvideo_softc *sc = v;
499
500 if (offset >= sc->sc_dc->dc_size || offset < 0)
501 return (-1);
502
503 return arm_btop(sc->sc_dc->dc_paddr + offset);
504 }
505
506
507 static int
508 vidcvideo_alloc_screen(v, type, cookiep, curxp, curyp, attrp)
509 void *v;
510 const struct wsscreen_descr *type;
511 void **cookiep;
512 int *curxp, *curyp;
513 long *attrp;
514 {
515 struct vidcvideo_softc *sc = v;
516 struct fb_devconfig *dc = sc->sc_dc;
517 long defattr;
518
519 /*
520 * One and just only one for now :( ... if the vidcconsole is not the
521 * console then this makes one wsconsole screen free for use !
522 */
523 if ((sc->nscreens > 1) || vidcvideo_is_console)
524 return (ENOMEM);
525
526 /* Add the screen to wscons to control */
527 *cookiep = &dc->rinfo;
528 *curxp = 0;
529 *curyp = 0;
530 vidcvideo_getdevconfig(videomemory.vidm_vbase, dc);
531 vidcvideo_config_wscons(dc);
532 (*dc->rinfo.ri_ops.allocattr)(&dc->rinfo, 0, 0, 0, &defattr);
533 *attrp = defattr;
534 sc->nscreens++;
535
536 return (0);
537 }
538
539
540 static void
541 vidcvideo_free_screen(v, cookie)
542 void *v;
543 void *cookie;
544 {
545 struct vidcvideo_softc *sc = v;
546
547 if (sc->sc_dc == &vidcvideo_console_dc)
548 panic("vidcvideo_free_screen: console");
549
550 sc->nscreens--;
551 }
552
553
554 static int
555 vidcvideo_show_screen(v, cookie, waitok, cb, cbarg)
556 void *v;
557 void *cookie;
558 int waitok;
559 void (*cb) __P((void *, int, int));
560 void *cbarg;
561 {
562
563 return (0);
564 }
565
566
567 /* EXPORT */ int
568 vidcvideo_cnattach(addr)
569 vaddr_t addr;
570 {
571 struct fb_devconfig *dcp = &vidcvideo_console_dc;
572 long defattr;
573
574 vidcvideo_init();
575 vidcvideo_getdevconfig(addr, dcp);
576 vidcvideo_config_wscons(dcp);
577 (*dcp->rinfo.ri_ops.allocattr)(&dcp->rinfo, 0, 0, 0, &defattr);
578 wsdisplay_cnattach(&vidcvideo_stdscreen, &dcp->rinfo, 0, 0, defattr);
579
580 vidcvideo_is_console = 1;
581 return(0);
582 }
583
584
585 static int
586 vidcvideointr(arg)
587 void *arg;
588 {
589 struct fb_devconfig *dc = arg;
590 int v, cleared = 0;
591
592 v = dc->dc_changed;
593 if (v == 0)
594 return (1);
595
596 if (v & WSDISPLAY_WB_COUNTER) {
597 dc->dc_writeback_delay--;
598 if (dc->dc_writeback_delay == 0) {
599 cpu_dcache_wb_range(dc->dc_vaddr, dc->dc_size);
600 cleared |= WSDISPLAY_WB_COUNTER;
601 };
602 }
603
604 if (v & WSDISPLAY_CMAP_DOLUT) {
605 struct hwcmap256 *cm = &dc->dc_cmap;
606 int index;
607
608 if (dc->dc_depth == 4) {
609 /* palette for 4 bpp is different from 8bpp */
610 vidcvideo_write(VIDC_PALREG, 0x00000000);
611 for (index=0; index < (1 << dc->dc_depth); index++)
612 vidcvideo_write(VIDC_PALETTE,
613 VIDC_COL(cm->r[index],
614 cm->g[index],
615 cm->b[index]));
616 ;
617 };
618
619 if (dc->dc_depth == 8) {
620 /* dunno what to do in more than 8bpp */
621 /* palettes only make sense in 8bpp and less modes on VIDC */
622 vidcvideo_write(VIDC_PALREG, 0x00000000);
623 for (index = 0; index < CMAP_SIZE; index++) {
624 vidcvideo_write(VIDC_PALETTE,
625 VIDC_COL(cm->r[index], cm->g[index], cm->b[index])
626 );
627 };
628 };
629 cleared |= WSDISPLAY_CMAP_DOLUT;
630 }
631
632 if (v & WSDISPLAY_VIDEO_ONOFF) {
633 vidcvideo_blank(dc->dc_blanked);
634 cleared |= WSDISPLAY_VIDEO_ONOFF;
635 };
636
637 if (v & (WSDISPLAY_CURSOR_DOPOS | WSDISPLAY_CURSOR_DOHOT)) {
638 int x, y;
639 x = dc->dc_cursor.cc_pos.x - dc->dc_cursor.cc_hot.x;
640 y = dc->dc_cursor.cc_pos.y - dc->dc_cursor.cc_hot.y;
641
642 vidcvideo_updatecursor(x, y);
643 cleared |= WSDISPLAY_CURSOR_DOPOS | WSDISPLAY_CURSOR_DOHOT;
644 };
645
646 if (v & WSDISPLAY_CURSOR_DOCUR) {
647 vidcvideo_enablecursor(dc->dc_curenb);
648 cleared |= WSDISPLAY_CURSOR_DOCUR;
649 };
650
651
652 #if 0 /* XXX snip XXX */
653 /* XXX kept here as an archive for now XXX */
654
655 vdac = vidcvideobase + CX_BT459_OFFSET;
656 v = sc->sc_changed;
657 if (v & WSDISPLAY_CURSOR_DOCUR) {
658 SELECT(vdac, BT459_IREG_CCR);
659 REG(vdac, bt_reg) = (sc->sc_curenb) ? 0xc0 : 0x00;
660 }
661 if (v & (WSDISPLAY_CURSOR_DOPOS | WSDISPLAY_CURSOR_DOHOT)) {
662 int x, y;
663
664 x = sc->sc_cursor.cc_pos.x - sc->sc_cursor.cc_hot.x;
665 y = sc->sc_cursor.cc_pos.y - sc->sc_cursor.cc_hot.y;
666
667 x += sc->sc_cursor.cc_magic.x;
668 y += sc->sc_cursor.cc_magic.y;
669
670 SELECT(vdac, BT459_IREG_CURSOR_X_LOW);
671 REG(vdac, bt_reg) = x; tc_wmb();
672 REG(vdac, bt_reg) = x >> 8; tc_wmb();
673 REG(vdac, bt_reg) = y; tc_wmb();
674 REG(vdac, bt_reg) = y >> 8; tc_wmb();
675 }
676 if (v & WSDISPLAY_CURSOR_DOCMAP) {
677 u_int8_t *cp = sc->sc_cursor.cc_color;
678
679 SELECT(vdac, BT459_IREG_CCOLOR_2);
680 REG(vdac, bt_reg) = cp[1]; tc_wmb();
681 REG(vdac, bt_reg) = cp[3]; tc_wmb();
682 REG(vdac, bt_reg) = cp[5]; tc_wmb();
683
684 REG(vdac, bt_reg) = cp[0]; tc_wmb();
685 REG(vdac, bt_reg) = cp[2]; tc_wmb();
686 REG(vdac, bt_reg) = cp[4]; tc_wmb();
687 }
688 if (v & WSDISPLAY_CURSOR_DOSHAPE) {
689 u_int8_t *ip, *mp, img, msk;
690 u_int8_t u;
691 int bcnt;
692
693 ip = (u_int8_t *)sc->sc_cursor.cc_image;
694 mp = (u_int8_t *)(sc->sc_cursor.cc_image + CURSOR_MAX_HEIGHT);
695
696 bcnt = 0;
697 SELECT(vdac, BT459_IREG_CRAM_BASE+0);
698 /* 64 pixel scan line is consisted with 16 byte cursor ram */
699 while (bcnt < sc->sc_cursor.cc_size.y * 16) {
700 /* pad right half 32 pixel when smaller than 33 */
701 if ((bcnt & 0x8) && sc->sc_cursor.cc_size.x < 33) {
702 REG(vdac, bt_reg) = 0; tc_wmb();
703 REG(vdac, bt_reg) = 0; tc_wmb();
704 }
705 else {
706 img = *ip++;
707 msk = *mp++;
708 img &= msk; /* cookie off image */
709 u = (msk & 0x0f) << 4 | (img & 0x0f);
710 REG(vdac, bt_reg) = shuffle[u]; tc_wmb();
711 u = (msk & 0xf0) | (img & 0xf0) >> 4;
712 REG(vdac, bt_reg) = shuffle[u]; tc_wmb();
713 }
714 bcnt += 2;
715 }
716 /* pad unoccupied scan lines */
717 while (bcnt < CURSOR_MAX_HEIGHT * 16) {
718 REG(vdac, bt_reg) = 0; tc_wmb();
719 REG(vdac, bt_reg) = 0; tc_wmb();
720 bcnt += 2;
721 }
722 }
723 #endif /* XXX snip XXX */
724
725 dc->dc_changed ^= cleared;
726
727 return (1);
728 }
729
730
731 static u_char ri_col_data[6][6] = {
732 { 0, 0, 0, 0, 0, 0}, /* 1 bpp */
733 { 0, 0, 0, 0, 0, 0}, /* 2 bpp */
734 { 0, 0, 0, 0, 0, 0}, /* 4 bpp */
735 { 0, 0, 0, 0, 0, 0}, /* 8 bpp */
736 { 6, 5, 5, 0, 6, 11}, /* 16 bpp */
737 { 8, 8, 8, 0, 8, 16}, /* 32 bpp */
738 };
739
740 static void
741 vidcvideo_colourmap_and_cursor_init(dc)
742 struct fb_devconfig *dc;
743 {
744 struct rasops_info *ri = &dc->rinfo;
745 u_char *rgbdat;
746
747 /* Whatever we do later... just make sure we have a
748 * sane palette to start with
749 */
750 vidcvideo_stdpalette();
751
752 /* set up rgb bit pattern values for rasops_init */
753 rgbdat = ri_col_data[dc->dc_log2_depth];
754 ri->ri_rnum = rgbdat[0];
755 ri->ri_gnum = rgbdat[1];
756 ri->ri_bnum = rgbdat[2];
757 ri->ri_rpos = rgbdat[3];
758 ri->ri_gpos = rgbdat[4];
759 ri->ri_bpos = rgbdat[5];
760
761 }
762
763
764 static int
765 get_cmap(sc, p)
766 struct vidcvideo_softc *sc;
767 struct wsdisplay_cmap *p;
768 {
769 u_int index = p->index, count = p->count;
770 int error;
771
772 if (index >= CMAP_SIZE || count > CMAP_SIZE - index)
773 return (EINVAL);
774
775 error = copyout(&sc->sc_dc->dc_cmap.r[index], p->red, count);
776 if (error)
777 return error;
778 error = copyout(&sc->sc_dc->dc_cmap.g[index], p->green, count);
779 if (error)
780 return error;
781 error = copyout(&sc->sc_dc->dc_cmap.b[index], p->blue, count);
782 return error;
783 }
784
785
786 static int
787 set_cmap(sc, p)
788 struct vidcvideo_softc *sc;
789 struct wsdisplay_cmap *p;
790 {
791 struct fb_devconfig *dc = sc->sc_dc;
792 struct hwcmap256 cmap;
793 u_int index = p->index, count = p->count;
794 int error;
795
796 if (index >= CMAP_SIZE || (index + count) > CMAP_SIZE)
797 return (EINVAL);
798
799 error = copyin(p->red, &cmap.r[index], count);
800 if (error)
801 return error;
802 error = copyin(p->green, &cmap.g[index], count);
803 if (error)
804 return error;
805 error = copyin(p->blue, &cmap.b[index], count);
806 if (error)
807 return error;
808 memcpy(&dc->dc_cmap.r[index], &cmap.r[index], count);
809 memcpy(&dc->dc_cmap.g[index], &cmap.g[index], count);
810 memcpy(&dc->dc_cmap.b[index], &cmap.b[index], count);
811 dc->dc_changed |= WSDISPLAY_CMAP_DOLUT;
812 return (0);
813 }
814
815
816 static int
817 set_cursor(sc, p)
818 struct vidcvideo_softc *sc;
819 struct wsdisplay_cursor *p;
820 {
821 #define cc (&dc->dc_cursor)
822 struct fb_devconfig *dc = sc->sc_dc;
823 u_int v, index = 0, count = 0, icount = 0;
824 uint8_t r[2], g[2], b[2], image[512], mask[512];
825 int error;
826
827 /* XXX gcc does not detect identical conditions */
828 index = count = icount = 0;
829
830 v = p->which;
831 if (v & WSDISPLAY_CURSOR_DOCMAP) {
832 index = p->cmap.index;
833 count = p->cmap.count;
834 if (index >= CURSOR_MAX_COLOURS ||
835 (index + count) > CURSOR_MAX_COLOURS)
836 return (EINVAL);
837 error = copyin(p->cmap.red, &r[index], count);
838 if (error)
839 return error;
840 error = copyin(p->cmap.green, &g[index], count);
841 if (error)
842 return error;
843 error = copyin(p->cmap.blue, &b[index], count);
844 if (error)
845 return error;
846 }
847 if (v & WSDISPLAY_CURSOR_DOSHAPE) {
848 if (p->size.x > CURSOR_MAX_WIDTH ||
849 p->size.y > CURSOR_MAX_HEIGHT)
850 return (EINVAL);
851 icount = sizeof(u_int32_t) * p->size.y;
852 error = copyin(p->image, &image, icount);
853 if (error)
854 return error;
855 error = copyin(p->mask, &mask, icount);
856 if (error)
857 return error;
858 }
859
860 if (v & WSDISPLAY_CURSOR_DOCUR)
861 dc->dc_curenb = p->enable;
862 if (v & WSDISPLAY_CURSOR_DOPOS)
863 set_curpos(sc, &p->pos);
864 if (v & WSDISPLAY_CURSOR_DOHOT)
865 cc->cc_hot = p->hot;
866 if (v & WSDISPLAY_CURSOR_DOCMAP) {
867 memcpy(&cc->cc_color[index], &r[index], count);
868 memcpy(&cc->cc_color[index + 2], &g[index], count);
869 memcpy(&cc->cc_color[index + 4], &b[index], count);
870 }
871 if (v & WSDISPLAY_CURSOR_DOSHAPE) {
872 cc->cc_size = p->size;
873 memset(cc->cc_image, 0, sizeof cc->cc_image);
874 memcpy(cc->cc_image, image, icount);
875 memset(cc->cc_mask, 0, sizeof cc->cc_mask);
876 memcpy(cc->cc_mask, mask, icount);
877 }
878 dc->dc_changed |= v;
879
880 return (0);
881 #undef cc
882 }
883
884
885 static int
886 get_cursor(sc, p)
887 struct vidcvideo_softc *sc;
888 struct wsdisplay_cursor *p;
889 {
890 return (EPASSTHROUGH); /* XXX */
891 }
892
893
894 static void
895 set_curpos(sc, curpos)
896 struct vidcvideo_softc *sc;
897 struct wsdisplay_curpos *curpos;
898 {
899 struct fb_devconfig *dc = sc->sc_dc;
900 int x = curpos->x, y = curpos->y;
901
902 if (y < 0)
903 y = 0;
904 else if (y > dc->dc_ht)
905 y = dc->dc_ht;
906 if (x < 0)
907 x = 0;
908 else if (x > dc->dc_wid)
909 x = dc->dc_wid;
910 dc->dc_cursor.cc_pos.x = x;
911 dc->dc_cursor.cc_pos.y = y;
912 }
913
914
915 static void vv_copyrows(id, srcrow, dstrow, nrows)
916 void *id;
917 int srcrow, dstrow, nrows;
918 {
919 struct rasops_info *ri = id;
920 int height, offset, size;
921 int scrollup, scrolldown;
922 unsigned char *src, *dst;
923
924 /* All movements are done in multiples of character heigths */
925 height = ri->ri_font->fontheight * nrows;
926 offset = (srcrow - dstrow) * ri->ri_yscale;
927 size = height * ri->ri_stride;
928
929 /* check if we are full screen scrolling */
930 scrollup = (srcrow + nrows >= ri->ri_rows);
931 scrolldown = (dstrow + nrows >= ri->ri_rows);
932
933 if ((scrollup || scrolldown) && (videomemory.vidm_type == VIDEOMEM_TYPE_VRAM)) {
934 ri->ri_bits = vidcvideo_hwscroll(offset);
935 vidcvideo_progr_scroll(); /* sadistic ; shouldnt this be on vsync? */
936
937 /* wipe out remains of the screen if nessisary */
938 if (ri->ri_emuheight != ri->ri_height) vv_eraserows(id, ri->ri_rows, 1, 0);
939 return;
940 };
941
942 /* Else we just copy the area : we're braindead for now
943 * Note: we can't use hardware scrolling when the softc isnt known yet...
944 * if its not known we dont have interrupts and we can't change the display
945 * address reliable other than in a Vsync
946 */
947
948 src = ri->ri_bits + srcrow * ri->ri_font->fontheight * ri->ri_stride;
949 dst = ri->ri_bits + dstrow * ri->ri_font->fontheight * ri->ri_stride;
950
951 bcopy(src, dst, size);
952 }
953
954
955 static void vv_eraserows(id, startrow, nrows, attr)
956 void *id;
957 int startrow, nrows;
958 long attr;
959 {
960 struct rasops_info *ri = id;
961 int height;
962 unsigned char *src;
963
964 /* we're braindead for now */
965 height = ri->ri_font->fontheight * nrows * ri->ri_stride;
966
967 src = ri->ri_bits + startrow * ri->ri_font->fontheight * ri->ri_stride;
968
969 bzero(src, height);
970 }
971
972
973 static void vv_putchar(id, row, col, uc, attr)
974 void *id;
975 int row, col;
976 u_int uc;
977 long attr;
978 {
979 struct rasops_info *ri = id;
980 struct fb_devconfig *dc = (struct fb_devconfig *) (ri->ri_hw);
981
982 /* delay the write back operation of the screen area */
983 dc->dc_writeback_delay = SCREEN_WRITE_BACK_DELAY;
984 dc->dc_changed |= WSDISPLAY_WB_COUNTER;
985
986 /* just delegate */
987 dc->orig_ri_ops.putchar(id, row, col, uc, attr);
988 }
989