vidcvideo.c revision 1.32 1 /* $NetBSD: vidcvideo.c,v 1.32 2008/02/03 19:38:29 chris 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.32 2008/02/03 19:38:29 chris 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
63 /* for vidc_mode ... needs to be MI indepenent one day */
64 #include <arm/iomd/vidc.h>
65 #include <arm/iomd/vidc20config.h>
66 #include <arm/iomd/vidcvideo.h>
67 #include <machine/bootconfig.h>
68
69 /* FOR DEBUG */
70 extern videomemory_t videomemory;
71
72 struct hwcmap256 {
73 #define CMAP_SIZE 256 /* 256 R/G/B entries */
74 u_int8_t r[CMAP_SIZE];
75 u_int8_t g[CMAP_SIZE];
76 u_int8_t b[CMAP_SIZE];
77 };
78
79
80 /* XXX for CURSOR_MAX_WIDTH = 32 */
81 struct hwcursor32 {
82 struct wsdisplay_curpos cc_pos;
83 struct wsdisplay_curpos cc_hot;
84 struct wsdisplay_curpos cc_size;
85 u_int8_t cc_color[6]; /* how many? */
86 u_int32_t cc_image[(CURSOR_MAX_WIDTH/4) * CURSOR_MAX_HEIGHT];
87 u_int32_t cc_mask[(CURSOR_MAX_WIDTH/4) * CURSOR_MAX_HEIGHT];
88 };
89
90
91 struct fb_devconfig {
92 vaddr_t dc_vaddr; /* memory space virtual base address */
93 paddr_t dc_paddr; /* memory space physical base address */
94 vsize_t dc_size; /* size of slot memory */
95 int dc_wid; /* width of frame buffer */
96 int dc_ht; /* height of frame buffer */
97 int dc_log2_depth; /* log2 of bits per pixel */
98 int dc_depth; /* depth, bits per pixel */
99 int dc_rowbytes; /* bytes in a FB scan line */
100 vaddr_t dc_videobase; /* base of flat frame buffer */
101 int dc_blanked; /* currently has video disabled */
102 void *dc_hwscroll_cookie; /* cookie for hardware scroll */
103
104 int dc_curenb; /* is cursor sprite enabled ? */
105 int dc_changed; /* need update of hardware */
106 int dc_writeback_delay; /* Screenarea write back vsync counter */
107 #define WSDISPLAY_CMAP_DOLUT 0x20
108 #define WSDISPLAY_VIDEO_ONOFF 0x40
109 #define WSDISPLAY_WB_COUNTER 0x80
110
111 struct hwcmap256 dc_cmap;/* software copy of colormap */
112 struct hwcursor32 dc_cursor;/* software copy of cursor */
113
114 struct vidc_mode mode_info;
115 struct rasops_info rinfo;
116
117 struct wsdisplay_emulops orig_ri_ops; /* Rasops functions for deligation */
118 };
119
120
121 struct vidcvideo_softc {
122 struct device sc_dev;
123 struct fb_devconfig *sc_dc; /* device configuration */
124 int nscreens; /* number of screens configured */
125 };
126
127
128 /* Function prototypes for glue */
129 static int vidcvideo_match(struct device *, struct cfdata *, void *);
130 static void vidcvideo_attach(struct device *, struct device *, void *);
131
132
133 /* config glue */
134 CFATTACH_DECL(vidcvideo, sizeof(struct vidcvideo_softc),
135 vidcvideo_match, vidcvideo_attach, NULL, NULL);
136
137 static struct fb_devconfig vidcvideo_console_dc;
138 static int vidcvideo_is_console;
139
140
141 static struct wsscreen_descr vidcvideo_stdscreen = {
142 "std", 0, 0,
143 0, /* textops */
144 0, 0,
145 WSSCREEN_REVERSE
146 };
147
148 static const struct wsscreen_descr *_vidcvideo_scrlist[] = {
149 &vidcvideo_stdscreen,
150 };
151
152 static const struct wsscreen_list vidcvideo_screenlist = {
153 sizeof(_vidcvideo_scrlist) / sizeof(struct wsscreen_descr *),
154 _vidcvideo_scrlist
155 };
156
157 static int vidcvideoioctl(void *, void *, u_long, void *, int,
158 struct lwp *);
159 static paddr_t vidcvideommap(void *, void *, off_t, int);
160
161 static int vidcvideo_alloc_screen(void *, const struct wsscreen_descr *,
162 void **, int *, int *, long *);
163 static void vidcvideo_free_screen(void *, void *);
164 static int vidcvideo_show_screen(void *, void *, int,
165 void (*) (void *, int, int), void *);
166
167 static const struct wsdisplay_accessops vidcvideo_accessops = {
168 vidcvideoioctl,
169 vidcvideommap,
170 vidcvideo_alloc_screen,
171 vidcvideo_free_screen,
172 vidcvideo_show_screen,
173 NULL, /* load_font */
174 NULL /* pollc */
175 };
176
177
178 /* Function prototypes */
179 int vidcvideo_cnattach(vaddr_t);
180 static void vidcvideo_colourmap_and_cursor_init(struct fb_devconfig *);
181
182 static int get_cmap(struct vidcvideo_softc *, struct wsdisplay_cmap *);
183 static int set_cmap(struct vidcvideo_softc *, struct wsdisplay_cmap *);
184 static int set_cursor(struct vidcvideo_softc *, struct wsdisplay_cursor *);
185 static int get_cursor(struct vidcvideo_softc *, struct wsdisplay_cursor *);
186 static void set_curpos(struct vidcvideo_softc *, struct wsdisplay_curpos *);
187 static void vidcvideo_getdevconfig(vaddr_t, struct fb_devconfig *);
188
189 static int vidcvideointr(void *);
190 static void vidcvideo_config_wscons(struct fb_devconfig *);
191
192
193 /* Acceleration function prototypes */
194 static void vv_copyrows(void *, int, int, int);
195 static void vv_eraserows(void *, int, int, long);
196 static void vv_putchar(void *c, int row, int col, u_int uc, long attr);
197
198
199 static int
200 vidcvideo_match(parent, match, aux)
201 struct device *parent;
202 struct cfdata *match;
203 void *aux;
204 {
205
206 /* Can't probe AFAIK ; how ? */
207 return 1;
208 }
209
210
211 static void
212 vidcvideo_getdevconfig(vaddr_t dense_addr, struct fb_devconfig *dc)
213 {
214
215 dc->dc_vaddr = dense_addr;
216 (void) pmap_extract(pmap_kernel(), dc->dc_vaddr, &(dc->dc_paddr));
217
218 vidcvideo_getmode(&dc->mode_info);
219
220 dc->dc_wid = dc->mode_info.timings.hdisplay;
221 dc->dc_ht = dc->mode_info.timings.vdisplay;
222 dc->dc_log2_depth = dc->mode_info.log2_bpp;
223 dc->dc_depth = 1 << dc->dc_log2_depth;
224 dc->dc_videobase = dc->dc_vaddr;
225 dc->dc_blanked = 0;
226
227 /* this should/could be done somewhat more elegant! */
228 switch (dc->dc_depth) {
229 case 1:
230 dc->dc_rowbytes = dc->dc_wid / 8;
231 break;
232 case 2:
233 dc->dc_rowbytes = dc->dc_wid / 4;
234 break;
235 case 4:
236 dc->dc_rowbytes = dc->dc_wid / 2;
237 break;
238 case 8:
239 dc->dc_rowbytes = dc->dc_wid;
240 break;
241 case 16:
242 dc->dc_rowbytes = dc->dc_wid * 2;
243 break;
244 case 32:
245 dc->dc_rowbytes = dc->dc_wid * 4;
246 break;
247 default:
248 printf("Unknown colour depth %d ... what to do ?", dc->dc_depth);
249 break;
250 }
251
252 /* euhm... correct ? i.e. not complete VIDC memory */
253 dc->dc_size = dc->mode_info.timings.vdisplay * dc->dc_rowbytes;
254
255 /* initialize colormap and cursor resource */
256 vidcvideo_colourmap_and_cursor_init(dc);
257
258 dc->rinfo.ri_flg = 0; /* RI_CENTER; */
259 dc->rinfo.ri_depth = dc->dc_depth;
260 dc->rinfo.ri_bits = (void *) dc->dc_videobase;
261 dc->rinfo.ri_width = dc->dc_wid;
262 dc->rinfo.ri_height = dc->dc_ht;
263 dc->rinfo.ri_stride = dc->dc_rowbytes;
264 dc->rinfo.ri_hw = dc; /* link back */
265
266 /* intitialise miscelanious */
267 dc->dc_writeback_delay = 0;
268 }
269
270
271 static void
272 vidcvideo_config_wscons(struct fb_devconfig *dc)
273 {
274 int i, cookie, font_not_locked;
275
276 /*
277 * clear the screen ; why not a memset ? - it was this way so
278 * keep it for now
279 */
280 for (i = 0; i < dc->dc_ht * dc->dc_rowbytes; i += sizeof(u_int32_t))
281 *(u_int32_t *)(dc->dc_videobase + i) = 0x0;
282
283 wsfont_init();
284
285 /* prefer 8 pixel wide font */
286 cookie = wsfont_find(NULL, 8, 0, 0, WSDISPLAY_FONTORDER_L2R,
287 WSDISPLAY_FONTORDER_L2R);
288 if (cookie <= 0)
289 cookie = wsfont_find(NULL, 0, 0, 0, WSDISPLAY_FONTORDER_L2R,
290 WSDISPLAY_FONTORDER_L2R);
291
292 if (cookie < 0) {
293 /* Can I even print here ? */
294 printf("Font table empty! exiting\n");
295 return;
296 }
297
298 font_not_locked = wsfont_lock(cookie, &dc->rinfo.ri_font);
299
300 dc->rinfo.ri_wsfcookie = cookie;
301
302 rasops_init(&dc->rinfo,
303 dc->rinfo.ri_height / dc->rinfo.ri_font->fontheight,
304 dc->rinfo.ri_width / dc->rinfo.ri_font->fontwidth);
305
306 /*
307 * Provide a hook for the acceleration functions and make a copy of the
308 * original rasops functions for passing on calls
309 */
310 dc->rinfo.ri_hw = dc;
311 memcpy(&(dc->orig_ri_ops), &(dc->rinfo.ri_ops),
312 sizeof(struct wsdisplay_emulops));
313
314 /* add our accelerated functions */
315 dc->rinfo.ri_ops.eraserows = vv_eraserows;
316 dc->rinfo.ri_ops.copyrows = vv_copyrows;
317
318 /* add the extra activity measuring functions; they just delegate on */
319 dc->rinfo.ri_ops.putchar = vv_putchar;
320
321 /* XXX shouldn't be global */
322 vidcvideo_stdscreen.nrows = dc->rinfo.ri_rows;
323 vidcvideo_stdscreen.ncols = dc->rinfo.ri_cols;
324 vidcvideo_stdscreen.textops = &dc->rinfo.ri_ops;
325 vidcvideo_stdscreen.capabilities = dc->rinfo.ri_caps;
326
327 if (font_not_locked)
328 printf(" warning ... couldn't lock font! ");
329 }
330
331
332 static void
333 vidcvideo_attach(struct device *parent, struct device *self, void *aux)
334 {
335 struct vidcvideo_softc *sc = (struct vidcvideo_softc *)self;
336 struct fb_devconfig *dc;
337 struct wsemuldisplaydev_attach_args waa;
338 struct hwcmap256 *cm;
339 const u_int8_t *p;
340 long defattr;
341 int index;
342
343 vidcvideo_init();
344 if (sc->nscreens == 0) {
345 sc->sc_dc = &vidcvideo_console_dc;
346 if (!vidcvideo_is_console) {
347 printf(" : non console (no kbd yet) ");
348 vidcvideo_getdevconfig(videomemory.vidm_vbase, sc->sc_dc);
349 vidcvideo_config_wscons(sc->sc_dc);
350 (*sc->sc_dc->rinfo.ri_ops.allocattr)(&sc->sc_dc->rinfo, 0, 0, 0, &defattr);
351 }
352 sc->nscreens = 1;
353 } else {
354 printf(": already attached ... can't cope with this\n");
355 return;
356 }
357
358 dc = sc->sc_dc;
359
360 vidcvideo_printdetails();
361 printf(": mode %s, %dbpp\n", dc->mode_info.timings.name,
362 dc->dc_depth);
363
364 /* initialise rasops */
365 cm = &dc->dc_cmap;
366 p = rasops_cmap;
367 for (index = 0; index < CMAP_SIZE; index++, p += 3) {
368 cm->r[index] = p[0];
369 cm->g[index] = p[1];
370 cm->b[index] = p[2];
371 }
372
373 /* set up interrupt flags */
374 dc->dc_changed |= WSDISPLAY_CMAP_DOLUT;
375
376 /*
377 * Set up a link in the rasops structure to our device config
378 * for acceleration stuff
379 */
380 dc->rinfo.ri_hw = sc->sc_dc;
381
382 /* Establish an interrupt handler, and clear any pending interrupts */
383 intr_claim(IRQ_FLYBACK, IPL_TTY, "vblank", vidcvideointr, dc);
384
385 waa.console = (vidcvideo_is_console ? 1 : 0);
386 waa.scrdata = &vidcvideo_screenlist;
387 waa.accessops = &vidcvideo_accessops;
388 waa.accesscookie = sc;
389
390 config_found(self, &waa, wsemuldisplaydevprint);
391 }
392
393
394 static int
395 vidcvideoioctl(void *v, void *vs, u_long cmd, void *data, int flag,
396 struct lwp *l)
397 {
398 struct vidcvideo_softc *sc = v;
399 struct fb_devconfig *dc = sc->sc_dc;
400 int state;
401
402 switch (cmd) {
403 case WSDISPLAYIO_GTYPE:
404 *(u_int *)data = WSDISPLAY_TYPE_VIDC;
405 return 0;
406
407 case WSDISPLAYIO_GINFO:
408 #define wsd_fbip ((struct wsdisplay_fbinfo *)data)
409 wsd_fbip->height = dc->dc_ht;
410 wsd_fbip->width = dc->dc_wid;
411 wsd_fbip->depth = dc->dc_depth;
412 wsd_fbip->cmsize = CMAP_SIZE;
413 #undef fbt
414 return 0;
415
416 case WSDISPLAYIO_GETCMAP:
417 return get_cmap(sc, (struct wsdisplay_cmap *)data);
418
419 case WSDISPLAYIO_PUTCMAP:
420 return set_cmap(sc, (struct wsdisplay_cmap *)data);
421
422 case WSDISPLAYIO_SVIDEO:
423 state = *(int *)data;
424 dc->dc_blanked = (state == WSDISPLAYIO_VIDEO_OFF);
425 dc->dc_changed |= WSDISPLAY_VIDEO_ONOFF;
426 /* done on video blank */
427 return 0;
428
429 case WSDISPLAYIO_GVIDEO:
430 *(u_int *)data = dc->dc_blanked ?
431 WSDISPLAYIO_VIDEO_OFF : WSDISPLAYIO_VIDEO_ON;
432 return 0;
433
434 case WSDISPLAYIO_GCURPOS:
435 *(struct wsdisplay_curpos *)data = dc->dc_cursor.cc_pos;
436 return 0;
437
438 case WSDISPLAYIO_SCURPOS:
439 set_curpos(sc, (struct wsdisplay_curpos *)data);
440 dc->dc_changed |= WSDISPLAY_CURSOR_DOPOS;
441 return 0;
442
443 case WSDISPLAYIO_GCURMAX:
444 ((struct wsdisplay_curpos *)data)->x = CURSOR_MAX_WIDTH;
445 ((struct wsdisplay_curpos *)data)->y = CURSOR_MAX_HEIGHT;
446 return 0;
447
448 case WSDISPLAYIO_GCURSOR:
449 return get_cursor(sc, (struct wsdisplay_cursor *)data);
450
451 case WSDISPLAYIO_SCURSOR:
452 return set_cursor(sc, (struct wsdisplay_cursor *)data);
453
454 case WSDISPLAYIO_SMODE:
455 state = *(int *)data;
456 if (state == WSDISPLAYIO_MODE_MAPPED)
457 dc->dc_hwscroll_cookie = vidcvideo_hwscroll_reset();
458 if (state == WSDISPLAYIO_MODE_EMUL)
459 vidcvideo_hwscroll_back(dc->dc_hwscroll_cookie);
460 vidcvideo_progr_scroll();
461
462 return 0;
463 }
464 return EPASSTHROUGH;
465 }
466
467
468 paddr_t
469 vidcvideommap(void *v, void *vs, off_t offset, int prot)
470 {
471 struct vidcvideo_softc *sc = v;
472
473 if (offset >= sc->sc_dc->dc_size || offset < 0)
474 return -1;
475
476 return arm_btop(sc->sc_dc->dc_paddr + offset);
477 }
478
479
480 static int
481 vidcvideo_alloc_screen(void *v, const struct wsscreen_descr *type,
482 void **cookiep, int *curxp, int *curyp, long *attrp)
483 {
484 struct vidcvideo_softc *sc = v;
485 struct fb_devconfig *dc = sc->sc_dc;
486 long defattr;
487
488 /*
489 * One and just only one for now :( ... if the vidcconsole is not the
490 * console then this makes one wsconsole screen free for use !
491 */
492 if ((sc->nscreens > 1) || vidcvideo_is_console)
493 return ENOMEM;
494
495 /* Add the screen to wscons to control */
496 *cookiep = &dc->rinfo;
497 *curxp = 0;
498 *curyp = 0;
499 vidcvideo_getdevconfig(videomemory.vidm_vbase, dc);
500 vidcvideo_config_wscons(dc);
501 (*dc->rinfo.ri_ops.allocattr)(&dc->rinfo, 0, 0, 0, &defattr);
502 *attrp = defattr;
503 sc->nscreens++;
504
505 return 0;
506 }
507
508
509 static void
510 vidcvideo_free_screen(void *v, void *cookie)
511 {
512 struct vidcvideo_softc *sc = v;
513
514 if (sc->sc_dc == &vidcvideo_console_dc)
515 panic("vidcvideo_free_screen: console");
516
517 sc->nscreens--;
518 }
519
520
521 static int
522 vidcvideo_show_screen(void *v, void *cookie, int waitok,
523 void (*cb)(void *, int, int), void *cbarg)
524 {
525
526 return 0;
527 }
528
529
530 /* EXPORT */ int
531 vidcvideo_cnattach(vaddr_t addr)
532 {
533 struct fb_devconfig *dcp = &vidcvideo_console_dc;
534 long defattr;
535
536 vidcvideo_init();
537 vidcvideo_getdevconfig(addr, dcp);
538 vidcvideo_config_wscons(dcp);
539 (*dcp->rinfo.ri_ops.allocattr)(&dcp->rinfo, 0, 0, 0, &defattr);
540 wsdisplay_cnattach(&vidcvideo_stdscreen, &dcp->rinfo, 0, 0, defattr);
541
542 vidcvideo_is_console = 1;
543 return 0;
544 }
545
546
547 static int
548 vidcvideointr(void *arg)
549 {
550 struct fb_devconfig *dc = arg;
551 int v, cleared = 0;
552
553 v = dc->dc_changed;
554 if (v == 0)
555 return 1;
556
557 if (v & WSDISPLAY_WB_COUNTER) {
558 dc->dc_writeback_delay--;
559 if (dc->dc_writeback_delay == 0) {
560 cpu_dcache_wb_range(dc->dc_vaddr, dc->dc_size);
561 cleared |= WSDISPLAY_WB_COUNTER;
562 }
563 }
564
565 if (v & WSDISPLAY_CMAP_DOLUT) {
566 struct hwcmap256 *cm = &dc->dc_cmap;
567 int index;
568
569 if (dc->dc_depth == 4) {
570 /* palette for 4 bpp is different from 8bpp */
571 vidcvideo_write(VIDC_PALREG, 0x00000000);
572 for (index=0; index < (1 << dc->dc_depth); index++)
573 vidcvideo_write(VIDC_PALETTE,
574 VIDC_COL(cm->r[index],
575 cm->g[index],
576 cm->b[index]));
577 }
578
579 if (dc->dc_depth == 8) {
580 /*
581 * dunno what to do in more than 8bpp
582 * palettes only make sense in 8bpp and less modes
583 * on VIDC
584 */
585 vidcvideo_write(VIDC_PALREG, 0x00000000);
586 for (index = 0; index < CMAP_SIZE; index++) {
587 vidcvideo_write(VIDC_PALETTE,
588 VIDC_COL(cm->r[index], cm->g[index],
589 cm->b[index]));
590 }
591 }
592 cleared |= WSDISPLAY_CMAP_DOLUT;
593 }
594
595 if (v & WSDISPLAY_VIDEO_ONOFF) {
596 vidcvideo_blank(dc->dc_blanked);
597 cleared |= WSDISPLAY_VIDEO_ONOFF;
598 }
599
600 if (v & (WSDISPLAY_CURSOR_DOPOS | WSDISPLAY_CURSOR_DOHOT)) {
601 int x, y;
602 x = dc->dc_cursor.cc_pos.x - dc->dc_cursor.cc_hot.x;
603 y = dc->dc_cursor.cc_pos.y - dc->dc_cursor.cc_hot.y;
604
605 vidcvideo_updatecursor(x, y);
606 cleared |= WSDISPLAY_CURSOR_DOPOS | WSDISPLAY_CURSOR_DOHOT;
607 }
608
609 if (v & WSDISPLAY_CURSOR_DOCUR) {
610 vidcvideo_enablecursor(dc->dc_curenb);
611 cleared |= WSDISPLAY_CURSOR_DOCUR;
612 }
613
614 dc->dc_changed ^= cleared;
615
616 return 1;
617 }
618
619
620 static u_char ri_col_data[6][6] = {
621 { 0, 0, 0, 0, 0, 0}, /* 1 bpp */
622 { 0, 0, 0, 0, 0, 0}, /* 2 bpp */
623 { 0, 0, 0, 0, 0, 0}, /* 4 bpp */
624 { 0, 0, 0, 0, 0, 0}, /* 8 bpp */
625 { 6, 5, 5, 0, 6, 11}, /* 16 bpp */
626 { 8, 8, 8, 0, 8, 16}, /* 32 bpp */
627 };
628
629 static void
630 vidcvideo_colourmap_and_cursor_init(struct fb_devconfig *dc)
631 {
632 struct rasops_info *ri = &dc->rinfo;
633 u_char *rgbdat;
634
635 /* Whatever we do later... just make sure we have a
636 * sane palette to start with
637 */
638 vidcvideo_stdpalette();
639
640 /* set up rgb bit pattern values for rasops_init */
641 rgbdat = ri_col_data[dc->dc_log2_depth];
642 ri->ri_rnum = rgbdat[0];
643 ri->ri_gnum = rgbdat[1];
644 ri->ri_bnum = rgbdat[2];
645 ri->ri_rpos = rgbdat[3];
646 ri->ri_gpos = rgbdat[4];
647 ri->ri_bpos = rgbdat[5];
648 }
649
650
651 static int
652 get_cmap(struct vidcvideo_softc *sc, struct wsdisplay_cmap *p)
653 {
654 u_int index = p->index, count = p->count;
655 int error;
656
657 if (index >= CMAP_SIZE || count > CMAP_SIZE - index)
658 return EINVAL;
659
660 error = copyout(&sc->sc_dc->dc_cmap.r[index], p->red, count);
661 if (error)
662 return error;
663 error = copyout(&sc->sc_dc->dc_cmap.g[index], p->green, count);
664 if (error)
665 return error;
666 error = copyout(&sc->sc_dc->dc_cmap.b[index], p->blue, count);
667 return error;
668 }
669
670
671 static int
672 set_cmap(struct vidcvideo_softc *sc, struct wsdisplay_cmap *p)
673 {
674 struct fb_devconfig *dc = sc->sc_dc;
675 struct hwcmap256 cmap;
676 u_int index = p->index, count = p->count;
677 int error;
678
679 if (index >= CMAP_SIZE || (index + count) > CMAP_SIZE)
680 return EINVAL;
681
682 error = copyin(p->red, &cmap.r[index], count);
683 if (error)
684 return error;
685 error = copyin(p->green, &cmap.g[index], count);
686 if (error)
687 return error;
688 error = copyin(p->blue, &cmap.b[index], count);
689 if (error)
690 return error;
691 memcpy(&dc->dc_cmap.r[index], &cmap.r[index], count);
692 memcpy(&dc->dc_cmap.g[index], &cmap.g[index], count);
693 memcpy(&dc->dc_cmap.b[index], &cmap.b[index], count);
694 dc->dc_changed |= WSDISPLAY_CMAP_DOLUT;
695 return 0;
696 }
697
698
699 static int
700 set_cursor(struct vidcvideo_softc *sc, struct wsdisplay_cursor *p)
701 {
702 #define cc (&dc->dc_cursor)
703 struct fb_devconfig *dc = sc->sc_dc;
704 u_int v, index = 0, count = 0, icount = 0;
705 uint8_t r[2], g[2], b[2], image[512], mask[512];
706 int error;
707
708 /* XXX gcc does not detect identical conditions */
709 index = count = icount = 0;
710
711 v = p->which;
712 if (v & WSDISPLAY_CURSOR_DOCMAP) {
713 index = p->cmap.index;
714 count = p->cmap.count;
715 if (index >= CURSOR_MAX_COLOURS ||
716 (index + count) > CURSOR_MAX_COLOURS)
717 return EINVAL;
718 error = copyin(p->cmap.red, &r[index], count);
719 if (error)
720 return error;
721 error = copyin(p->cmap.green, &g[index], count);
722 if (error)
723 return error;
724 error = copyin(p->cmap.blue, &b[index], count);
725 if (error)
726 return error;
727 }
728 if (v & WSDISPLAY_CURSOR_DOSHAPE) {
729 if (p->size.x > CURSOR_MAX_WIDTH ||
730 p->size.y > CURSOR_MAX_HEIGHT)
731 return EINVAL;
732 icount = sizeof(u_int32_t) * p->size.y;
733 error = copyin(p->image, &image, icount);
734 if (error)
735 return error;
736 error = copyin(p->mask, &mask, icount);
737 if (error)
738 return error;
739 }
740
741 if (v & WSDISPLAY_CURSOR_DOCUR)
742 dc->dc_curenb = p->enable;
743 if (v & WSDISPLAY_CURSOR_DOPOS)
744 set_curpos(sc, &p->pos);
745 if (v & WSDISPLAY_CURSOR_DOHOT)
746 cc->cc_hot = p->hot;
747 if (v & WSDISPLAY_CURSOR_DOCMAP) {
748 memcpy(&cc->cc_color[index], &r[index], count);
749 memcpy(&cc->cc_color[index + 2], &g[index], count);
750 memcpy(&cc->cc_color[index + 4], &b[index], count);
751 }
752 if (v & WSDISPLAY_CURSOR_DOSHAPE) {
753 cc->cc_size = p->size;
754 memset(cc->cc_image, 0, sizeof cc->cc_image);
755 memcpy(cc->cc_image, image, icount);
756 memset(cc->cc_mask, 0, sizeof cc->cc_mask);
757 memcpy(cc->cc_mask, mask, icount);
758 }
759 dc->dc_changed |= v;
760
761 return 0;
762 #undef cc
763 }
764
765
766 static int
767 get_cursor(struct vidcvideo_softc *sc, struct wsdisplay_cursor *p)
768 {
769
770 return EPASSTHROUGH; /* XXX */
771 }
772
773
774 static void
775 set_curpos(struct vidcvideo_softc *sc, struct wsdisplay_curpos *curpos)
776 {
777 struct fb_devconfig *dc = sc->sc_dc;
778 int x = curpos->x, y = curpos->y;
779
780 if (y < 0)
781 y = 0;
782 else if (y > dc->dc_ht)
783 y = dc->dc_ht;
784 if (x < 0)
785 x = 0;
786 else if (x > dc->dc_wid)
787 x = dc->dc_wid;
788 dc->dc_cursor.cc_pos.x = x;
789 dc->dc_cursor.cc_pos.y = y;
790 }
791
792
793 static void vv_copyrows(void *id, int srcrow, int dstrow, int nrows)
794 {
795 struct rasops_info *ri = id;
796 int height, offset, size;
797 int scrollup, scrolldown;
798 unsigned char *src, *dst;
799
800 /* All movements are done in multiples of character heigths */
801 height = ri->ri_font->fontheight * nrows;
802 offset = (srcrow - dstrow) * ri->ri_yscale;
803 size = height * ri->ri_stride;
804
805 /* check if we are full screen scrolling */
806 scrollup = (srcrow + nrows >= ri->ri_rows);
807 scrolldown = (dstrow + nrows >= ri->ri_rows);
808
809 if ((scrollup || scrolldown) &&
810 (videomemory.vidm_type == VIDEOMEM_TYPE_VRAM)) {
811 ri->ri_bits = vidcvideo_hwscroll(offset);
812 vidcvideo_progr_scroll(); /* sadistic ; shouldnt this be on vsync? */
813
814 /* wipe out remains of the screen if nessisary */
815 if (ri->ri_emuheight != ri->ri_height)
816 vv_eraserows(id, ri->ri_rows, 1, 0);
817 return;
818 }
819
820 /*
821 * Else we just copy the area : we're braindead for now
822 * Note: we can't use hardware scrolling when the softc isnt
823 * known yet... if its not known we dont have interrupts and
824 * we can't change the display address reliable other than in
825 * a Vsync
826 */
827
828 src = ri->ri_bits + srcrow * ri->ri_font->fontheight * ri->ri_stride;
829 dst = ri->ri_bits + dstrow * ri->ri_font->fontheight * ri->ri_stride;
830
831 memmove(dst, src, size);
832 }
833
834
835 static void vv_eraserows(void *id, int startrow, int nrows, long attr)
836 {
837 struct rasops_info *ri = id;
838 int height;
839 unsigned char *src;
840
841 /* we're braindead for now */
842 height = ri->ri_font->fontheight * nrows * ri->ri_stride;
843
844 src = ri->ri_bits + startrow * ri->ri_font->fontheight * ri->ri_stride;
845
846 memset(src, 0, height);
847 }
848
849
850 static void vv_putchar(void *id, int row, int col, u_int uc, long attr)
851 {
852 struct rasops_info *ri = id;
853 struct fb_devconfig *dc = (struct fb_devconfig *) (ri->ri_hw);
854
855 /* delay the write back operation of the screen area */
856 dc->dc_writeback_delay = SCREEN_WRITE_BACK_DELAY;
857 dc->dc_changed |= WSDISPLAY_WB_COUNTER;
858
859 /* just delegate */
860 dc->orig_ri_ops.putchar(id, row, col, uc, attr);
861 }
862