vidcvideo.c revision 1.26 1 /* $NetBSD: vidcvideo.c,v 1.26 2006/08/05 21:25:39 bjh21 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.26 2006/08/05 21:25:39 bjh21 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(struct device *, struct cfdata *, void *);
142 static void vidcvideo_attach(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 *),
166 _vidcvideo_scrlist
167 };
168
169 static int vidcvideoioctl(void *, void *, u_long, caddr_t, int,
170 struct lwp *);
171 static paddr_t vidcvideommap(void *, void *, off_t, int);
172
173 static int vidcvideo_alloc_screen(void *, const struct wsscreen_descr *,
174 void **, int *, int *, long *);
175 static void vidcvideo_free_screen(void *, void *);
176 static int vidcvideo_show_screen(void *, void *, int,
177 void (*) (void *, int, int), void *);
178
179 static const struct wsdisplay_accessops vidcvideo_accessops = {
180 vidcvideoioctl,
181 vidcvideommap,
182 vidcvideo_alloc_screen,
183 vidcvideo_free_screen,
184 vidcvideo_show_screen,
185 NULL, /* load_font */
186 NULL /* pollc */
187 };
188
189
190 /* Function prototypes */
191 int vidcvideo_cnattach(vaddr_t);
192 static void vidcvideo_colourmap_and_cursor_init(struct fb_devconfig *);
193
194 static int get_cmap(struct vidcvideo_softc *, struct wsdisplay_cmap *);
195 static int set_cmap(struct vidcvideo_softc *, struct wsdisplay_cmap *);
196 static int set_cursor(struct vidcvideo_softc *, struct wsdisplay_cursor *);
197 static int get_cursor(struct vidcvideo_softc *, struct wsdisplay_cursor *);
198 static void set_curpos(struct vidcvideo_softc *, struct wsdisplay_curpos *);
199 static void vidcvideo_getdevconfig(vaddr_t, struct fb_devconfig *);
200
201 static int vidcvideointr(void *);
202 static void vidcvideo_config_wscons(struct fb_devconfig *);
203
204
205 /* Acceleration function prototypes */
206 static void vv_copyrows(void *, int, int, int);
207 static void vv_eraserows(void *, int, int, long);
208 static void vv_putchar(void *c, int row, int col, u_int uc, long attr);
209
210
211 static int
212 vidcvideo_match(parent, match, aux)
213 struct device *parent;
214 struct cfdata *match;
215 void *aux;
216 {
217
218 /* Can't probe AFAIK ; how ? */
219 return 1;
220 }
221
222
223 static void
224 vidcvideo_getdevconfig(vaddr_t dense_addr, struct fb_devconfig *dc)
225 {
226
227 dc->dc_vaddr = dense_addr;
228 (void) pmap_extract(pmap_kernel(), dc->dc_vaddr, &(dc->dc_paddr));
229
230 vidcvideo_getmode(&dc->mode_info);
231
232 dc->dc_wid = dc->mode_info.hder;
233 dc->dc_ht = dc->mode_info.vder;
234 dc->dc_log2_depth = dc->mode_info.log2_bpp;
235 dc->dc_depth = 1 << dc->dc_log2_depth;
236 dc->dc_videobase = dc->dc_vaddr;
237 dc->dc_blanked = 0;
238
239 /* this should/could be done somewhat more elegant! */
240 switch (dc->dc_depth) {
241 case 1:
242 dc->dc_rowbytes = dc->dc_wid / 8;
243 break;
244 case 2:
245 dc->dc_rowbytes = dc->dc_wid / 4;
246 break;
247 case 4:
248 dc->dc_rowbytes = dc->dc_wid / 2;
249 break;
250 case 8:
251 dc->dc_rowbytes = dc->dc_wid;
252 break;
253 case 16:
254 dc->dc_rowbytes = dc->dc_wid * 2;
255 break;
256 case 32:
257 dc->dc_rowbytes = dc->dc_wid * 4;
258 break;
259 default:
260 printf("Unknown colour depth %d ... what to do ?", dc->dc_depth);
261 break;
262 }
263
264 /* euhm... correct ? i.e. not complete VIDC memory */
265 dc->dc_size = dc->mode_info.vder * dc->dc_rowbytes;
266
267 /* initialize colormap and cursor resource */
268 vidcvideo_colourmap_and_cursor_init(dc);
269
270 dc->rinfo.ri_flg = 0; /* RI_CENTER; */
271 dc->rinfo.ri_depth = dc->dc_depth;
272 dc->rinfo.ri_bits = (void *) dc->dc_videobase;
273 dc->rinfo.ri_width = dc->dc_wid;
274 dc->rinfo.ri_height = dc->dc_ht;
275 dc->rinfo.ri_stride = dc->dc_rowbytes;
276 dc->rinfo.ri_hw = dc; /* link back */
277
278 /* intitialise miscelanious */
279 dc->dc_writeback_delay = 0;
280 }
281
282
283 static void
284 vidcvideo_config_wscons(struct fb_devconfig *dc)
285 {
286 int i, cookie, font_not_locked;
287
288 /*
289 * clear the screen ; why not a memset ? - it was this way so
290 * keep it for now
291 */
292 for (i = 0; i < dc->dc_ht * dc->dc_rowbytes; i += sizeof(u_int32_t))
293 *(u_int32_t *)(dc->dc_videobase + i) = 0x0;
294
295 wsfont_init();
296
297 /* prefer 8 pixel wide font */
298 cookie = wsfont_find(NULL, 8, 0, 0, WSDISPLAY_FONTORDER_L2R,
299 WSDISPLAY_FONTORDER_L2R);
300 if (cookie <= 0)
301 cookie = wsfont_find(NULL, 0, 0, 0, WSDISPLAY_FONTORDER_L2R,
302 WSDISPLAY_FONTORDER_L2R);
303
304 if (cookie < 0) {
305 /* Can I even print here ? */
306 printf("Font table empty! exiting\n");
307 return;
308 }
309
310 font_not_locked = wsfont_lock(cookie, &dc->rinfo.ri_font);
311
312 dc->rinfo.ri_wsfcookie = cookie;
313
314 rasops_init(&dc->rinfo,
315 dc->rinfo.ri_height / dc->rinfo.ri_font->fontheight,
316 dc->rinfo.ri_width / dc->rinfo.ri_font->fontwidth);
317
318 /*
319 * Provide a hook for the acceleration functions and make a copy of the
320 * original rasops functions for passing on calls
321 */
322 dc->rinfo.ri_hw = dc;
323 memcpy(&(dc->orig_ri_ops), &(dc->rinfo.ri_ops),
324 sizeof(struct wsdisplay_emulops));
325
326 /* add our accelerated functions */
327 dc->rinfo.ri_ops.eraserows = vv_eraserows;
328 dc->rinfo.ri_ops.copyrows = vv_copyrows;
329
330 /* add the extra activity measuring functions; they just delegate on */
331 dc->rinfo.ri_ops.putchar = vv_putchar;
332
333 /* XXX shouldn't be global */
334 vidcvideo_stdscreen.nrows = dc->rinfo.ri_rows;
335 vidcvideo_stdscreen.ncols = dc->rinfo.ri_cols;
336 vidcvideo_stdscreen.textops = &dc->rinfo.ri_ops;
337 vidcvideo_stdscreen.capabilities = dc->rinfo.ri_caps;
338
339 if (font_not_locked)
340 printf(" warning ... couldn't lock font! ");
341 }
342
343
344 static void
345 vidcvideo_attach(struct device *parent, struct device *self, 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(": already 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(void *v, void *vs, u_long cmd, caddr_t data, int flag,
412 struct lwp *l)
413 {
414 struct vidcvideo_softc *sc = v;
415 struct fb_devconfig *dc = sc->sc_dc;
416 int state;
417
418 switch (cmd) {
419 case WSDISPLAYIO_GTYPE:
420 *(u_int *)data = WSDISPLAY_TYPE_VIDC;
421 return 0;
422
423 case WSDISPLAYIO_GINFO:
424 #define wsd_fbip ((struct wsdisplay_fbinfo *)data)
425 wsd_fbip->height = dc->dc_ht;
426 wsd_fbip->width = dc->dc_wid;
427 wsd_fbip->depth = dc->dc_depth;
428 wsd_fbip->cmsize = CMAP_SIZE;
429 #undef fbt
430 return 0;
431
432 case WSDISPLAYIO_GETCMAP:
433 return get_cmap(sc, (struct wsdisplay_cmap *)data);
434
435 case WSDISPLAYIO_PUTCMAP:
436 return set_cmap(sc, (struct wsdisplay_cmap *)data);
437
438 case WSDISPLAYIO_SVIDEO:
439 state = *(int *)data;
440 dc->dc_blanked = (state == WSDISPLAYIO_VIDEO_OFF);
441 dc->dc_changed |= WSDISPLAY_VIDEO_ONOFF;
442 /* done on video blank */
443 return 0;
444
445 case WSDISPLAYIO_GVIDEO:
446 *(u_int *)data = dc->dc_blanked ?
447 WSDISPLAYIO_VIDEO_OFF : WSDISPLAYIO_VIDEO_ON;
448 return 0;
449
450 case WSDISPLAYIO_GCURPOS:
451 *(struct wsdisplay_curpos *)data = dc->dc_cursor.cc_pos;
452 return 0;
453
454 case WSDISPLAYIO_SCURPOS:
455 set_curpos(sc, (struct wsdisplay_curpos *)data);
456 dc->dc_changed |= WSDISPLAY_CURSOR_DOPOS;
457 return 0;
458
459 case WSDISPLAYIO_GCURMAX:
460 ((struct wsdisplay_curpos *)data)->x = CURSOR_MAX_WIDTH;
461 ((struct wsdisplay_curpos *)data)->y = CURSOR_MAX_HEIGHT;
462 return 0;
463
464 case WSDISPLAYIO_GCURSOR:
465 return get_cursor(sc, (struct wsdisplay_cursor *)data);
466
467 case WSDISPLAYIO_SCURSOR:
468 return set_cursor(sc, (struct wsdisplay_cursor *)data);
469
470 case WSDISPLAYIO_SMODE:
471 state = *(int *)data;
472 if (state == WSDISPLAYIO_MODE_MAPPED)
473 dc->dc_hwscroll_cookie = vidcvideo_hwscroll_reset();
474 if (state == WSDISPLAYIO_MODE_EMUL)
475 vidcvideo_hwscroll_back(dc->dc_hwscroll_cookie);
476 vidcvideo_progr_scroll();
477
478 return 0;
479 }
480 return EPASSTHROUGH;
481 }
482
483
484 paddr_t
485 vidcvideommap(void *v, void *vs, off_t offset, int prot)
486 {
487 struct vidcvideo_softc *sc = v;
488
489 if (offset >= sc->sc_dc->dc_size || offset < 0)
490 return -1;
491
492 return arm_btop(sc->sc_dc->dc_paddr + offset);
493 }
494
495
496 static int
497 vidcvideo_alloc_screen(void *v, const struct wsscreen_descr *type,
498 void **cookiep, int *curxp, int *curyp, long *attrp)
499 {
500 struct vidcvideo_softc *sc = v;
501 struct fb_devconfig *dc = sc->sc_dc;
502 long defattr;
503
504 /*
505 * One and just only one for now :( ... if the vidcconsole is not the
506 * console then this makes one wsconsole screen free for use !
507 */
508 if ((sc->nscreens > 1) || vidcvideo_is_console)
509 return ENOMEM;
510
511 /* Add the screen to wscons to control */
512 *cookiep = &dc->rinfo;
513 *curxp = 0;
514 *curyp = 0;
515 vidcvideo_getdevconfig(videomemory.vidm_vbase, dc);
516 vidcvideo_config_wscons(dc);
517 (*dc->rinfo.ri_ops.allocattr)(&dc->rinfo, 0, 0, 0, &defattr);
518 *attrp = defattr;
519 sc->nscreens++;
520
521 return 0;
522 }
523
524
525 static void
526 vidcvideo_free_screen(void *v, void *cookie)
527 {
528 struct vidcvideo_softc *sc = v;
529
530 if (sc->sc_dc == &vidcvideo_console_dc)
531 panic("vidcvideo_free_screen: console");
532
533 sc->nscreens--;
534 }
535
536
537 static int
538 vidcvideo_show_screen(void *v, void *cookie, int waitok,
539 void (*cb)(void *, int, int), void *cbarg)
540 {
541
542 return 0;
543 }
544
545
546 /* EXPORT */ int
547 vidcvideo_cnattach(vaddr_t addr)
548 {
549 struct fb_devconfig *dcp = &vidcvideo_console_dc;
550 long defattr;
551
552 vidcvideo_init();
553 vidcvideo_getdevconfig(addr, dcp);
554 vidcvideo_config_wscons(dcp);
555 (*dcp->rinfo.ri_ops.allocattr)(&dcp->rinfo, 0, 0, 0, &defattr);
556 wsdisplay_cnattach(&vidcvideo_stdscreen, &dcp->rinfo, 0, 0, defattr);
557
558 vidcvideo_is_console = 1;
559 return 0;
560 }
561
562
563 static int
564 vidcvideointr(void *arg)
565 {
566 struct fb_devconfig *dc = arg;
567 int v, cleared = 0;
568
569 v = dc->dc_changed;
570 if (v == 0)
571 return 1;
572
573 if (v & WSDISPLAY_WB_COUNTER) {
574 dc->dc_writeback_delay--;
575 if (dc->dc_writeback_delay == 0) {
576 cpu_dcache_wb_range(dc->dc_vaddr, dc->dc_size);
577 cleared |= WSDISPLAY_WB_COUNTER;
578 }
579 }
580
581 if (v & WSDISPLAY_CMAP_DOLUT) {
582 struct hwcmap256 *cm = &dc->dc_cmap;
583 int index;
584
585 if (dc->dc_depth == 4) {
586 /* palette for 4 bpp is different from 8bpp */
587 vidcvideo_write(VIDC_PALREG, 0x00000000);
588 for (index=0; index < (1 << dc->dc_depth); index++)
589 vidcvideo_write(VIDC_PALETTE,
590 VIDC_COL(cm->r[index],
591 cm->g[index],
592 cm->b[index]));
593 }
594
595 if (dc->dc_depth == 8) {
596 /*
597 * dunno what to do in more than 8bpp
598 * palettes only make sense in 8bpp and less modes
599 * on VIDC
600 */
601 vidcvideo_write(VIDC_PALREG, 0x00000000);
602 for (index = 0; index < CMAP_SIZE; index++) {
603 vidcvideo_write(VIDC_PALETTE,
604 VIDC_COL(cm->r[index], cm->g[index],
605 cm->b[index]));
606 }
607 }
608 cleared |= WSDISPLAY_CMAP_DOLUT;
609 }
610
611 if (v & WSDISPLAY_VIDEO_ONOFF) {
612 vidcvideo_blank(dc->dc_blanked);
613 cleared |= WSDISPLAY_VIDEO_ONOFF;
614 }
615
616 if (v & (WSDISPLAY_CURSOR_DOPOS | WSDISPLAY_CURSOR_DOHOT)) {
617 int x, y;
618 x = dc->dc_cursor.cc_pos.x - dc->dc_cursor.cc_hot.x;
619 y = dc->dc_cursor.cc_pos.y - dc->dc_cursor.cc_hot.y;
620
621 vidcvideo_updatecursor(x, y);
622 cleared |= WSDISPLAY_CURSOR_DOPOS | WSDISPLAY_CURSOR_DOHOT;
623 }
624
625 if (v & WSDISPLAY_CURSOR_DOCUR) {
626 vidcvideo_enablecursor(dc->dc_curenb);
627 cleared |= WSDISPLAY_CURSOR_DOCUR;
628 }
629
630
631 #if 0 /* XXX snip XXX */
632 /* XXX kept here as an archive for now XXX */
633
634 vdac = vidcvideobase + CX_BT459_OFFSET;
635 v = sc->sc_changed;
636 if (v & WSDISPLAY_CURSOR_DOCUR) {
637 SELECT(vdac, BT459_IREG_CCR);
638 REG(vdac, bt_reg) = (sc->sc_curenb) ? 0xc0 : 0x00;
639 }
640 if (v & (WSDISPLAY_CURSOR_DOPOS | WSDISPLAY_CURSOR_DOHOT)) {
641 int x, y;
642
643 x = sc->sc_cursor.cc_pos.x - sc->sc_cursor.cc_hot.x;
644 y = sc->sc_cursor.cc_pos.y - sc->sc_cursor.cc_hot.y;
645
646 x += sc->sc_cursor.cc_magic.x;
647 y += sc->sc_cursor.cc_magic.y;
648
649 SELECT(vdac, BT459_IREG_CURSOR_X_LOW);
650 REG(vdac, bt_reg) = x; tc_wmb();
651 REG(vdac, bt_reg) = x >> 8; tc_wmb();
652 REG(vdac, bt_reg) = y; tc_wmb();
653 REG(vdac, bt_reg) = y >> 8; tc_wmb();
654 }
655 if (v & WSDISPLAY_CURSOR_DOCMAP) {
656 u_int8_t *cp = sc->sc_cursor.cc_color;
657
658 SELECT(vdac, BT459_IREG_CCOLOR_2);
659 REG(vdac, bt_reg) = cp[1]; tc_wmb();
660 REG(vdac, bt_reg) = cp[3]; tc_wmb();
661 REG(vdac, bt_reg) = cp[5]; tc_wmb();
662
663 REG(vdac, bt_reg) = cp[0]; tc_wmb();
664 REG(vdac, bt_reg) = cp[2]; tc_wmb();
665 REG(vdac, bt_reg) = cp[4]; tc_wmb();
666 }
667 if (v & WSDISPLAY_CURSOR_DOSHAPE) {
668 u_int8_t *ip, *mp, img, msk;
669 u_int8_t u;
670 int bcnt;
671
672 ip = (u_int8_t *)sc->sc_cursor.cc_image;
673 mp = (u_int8_t *)(sc->sc_cursor.cc_image + CURSOR_MAX_HEIGHT);
674
675 bcnt = 0;
676 SELECT(vdac, BT459_IREG_CRAM_BASE+0);
677 /* 64 pixel scan line is consisted with 16 byte cursor ram */
678 while (bcnt < sc->sc_cursor.cc_size.y * 16) {
679 /* pad right half 32 pixel when smaller than 33 */
680 if ((bcnt & 0x8) && sc->sc_cursor.cc_size.x < 33) {
681 REG(vdac, bt_reg) = 0; tc_wmb();
682 REG(vdac, bt_reg) = 0; tc_wmb();
683 }
684 else {
685 img = *ip++;
686 msk = *mp++;
687 img &= msk; /* cookie off image */
688 u = (msk & 0x0f) << 4 | (img & 0x0f);
689 REG(vdac, bt_reg) = shuffle[u]; tc_wmb();
690 u = (msk & 0xf0) | (img & 0xf0) >> 4;
691 REG(vdac, bt_reg) = shuffle[u]; tc_wmb();
692 }
693 bcnt += 2;
694 }
695 /* pad unoccupied scan lines */
696 while (bcnt < CURSOR_MAX_HEIGHT * 16) {
697 REG(vdac, bt_reg) = 0; tc_wmb();
698 REG(vdac, bt_reg) = 0; tc_wmb();
699 bcnt += 2;
700 }
701 }
702 #endif /* XXX snip XXX */
703
704 dc->dc_changed ^= cleared;
705
706 return 1;
707 }
708
709
710 static u_char ri_col_data[6][6] = {
711 { 0, 0, 0, 0, 0, 0}, /* 1 bpp */
712 { 0, 0, 0, 0, 0, 0}, /* 2 bpp */
713 { 0, 0, 0, 0, 0, 0}, /* 4 bpp */
714 { 0, 0, 0, 0, 0, 0}, /* 8 bpp */
715 { 6, 5, 5, 0, 6, 11}, /* 16 bpp */
716 { 8, 8, 8, 0, 8, 16}, /* 32 bpp */
717 };
718
719 static void
720 vidcvideo_colourmap_and_cursor_init(struct fb_devconfig *dc)
721 {
722 struct rasops_info *ri = &dc->rinfo;
723 u_char *rgbdat;
724
725 /* Whatever we do later... just make sure we have a
726 * sane palette to start with
727 */
728 vidcvideo_stdpalette();
729
730 /* set up rgb bit pattern values for rasops_init */
731 rgbdat = ri_col_data[dc->dc_log2_depth];
732 ri->ri_rnum = rgbdat[0];
733 ri->ri_gnum = rgbdat[1];
734 ri->ri_bnum = rgbdat[2];
735 ri->ri_rpos = rgbdat[3];
736 ri->ri_gpos = rgbdat[4];
737 ri->ri_bpos = rgbdat[5];
738 }
739
740
741 static int
742 get_cmap(struct vidcvideo_softc *sc, struct wsdisplay_cmap *p)
743 {
744 u_int index = p->index, count = p->count;
745 int error;
746
747 if (index >= CMAP_SIZE || count > CMAP_SIZE - index)
748 return EINVAL;
749
750 error = copyout(&sc->sc_dc->dc_cmap.r[index], p->red, count);
751 if (error)
752 return error;
753 error = copyout(&sc->sc_dc->dc_cmap.g[index], p->green, count);
754 if (error)
755 return error;
756 error = copyout(&sc->sc_dc->dc_cmap.b[index], p->blue, count);
757 return error;
758 }
759
760
761 static int
762 set_cmap(struct vidcvideo_softc *sc, struct wsdisplay_cmap *p)
763 {
764 struct fb_devconfig *dc = sc->sc_dc;
765 struct hwcmap256 cmap;
766 u_int index = p->index, count = p->count;
767 int error;
768
769 if (index >= CMAP_SIZE || (index + count) > CMAP_SIZE)
770 return EINVAL;
771
772 error = copyin(p->red, &cmap.r[index], count);
773 if (error)
774 return error;
775 error = copyin(p->green, &cmap.g[index], count);
776 if (error)
777 return error;
778 error = copyin(p->blue, &cmap.b[index], count);
779 if (error)
780 return error;
781 memcpy(&dc->dc_cmap.r[index], &cmap.r[index], count);
782 memcpy(&dc->dc_cmap.g[index], &cmap.g[index], count);
783 memcpy(&dc->dc_cmap.b[index], &cmap.b[index], count);
784 dc->dc_changed |= WSDISPLAY_CMAP_DOLUT;
785 return 0;
786 }
787
788
789 static int
790 set_cursor(struct vidcvideo_softc *sc, struct wsdisplay_cursor *p)
791 {
792 #define cc (&dc->dc_cursor)
793 struct fb_devconfig *dc = sc->sc_dc;
794 u_int v, index = 0, count = 0, icount = 0;
795 uint8_t r[2], g[2], b[2], image[512], mask[512];
796 int error;
797
798 /* XXX gcc does not detect identical conditions */
799 index = count = icount = 0;
800
801 v = p->which;
802 if (v & WSDISPLAY_CURSOR_DOCMAP) {
803 index = p->cmap.index;
804 count = p->cmap.count;
805 if (index >= CURSOR_MAX_COLOURS ||
806 (index + count) > CURSOR_MAX_COLOURS)
807 return EINVAL;
808 error = copyin(p->cmap.red, &r[index], count);
809 if (error)
810 return error;
811 error = copyin(p->cmap.green, &g[index], count);
812 if (error)
813 return error;
814 error = copyin(p->cmap.blue, &b[index], count);
815 if (error)
816 return error;
817 }
818 if (v & WSDISPLAY_CURSOR_DOSHAPE) {
819 if (p->size.x > CURSOR_MAX_WIDTH ||
820 p->size.y > CURSOR_MAX_HEIGHT)
821 return EINVAL;
822 icount = sizeof(u_int32_t) * p->size.y;
823 error = copyin(p->image, &image, icount);
824 if (error)
825 return error;
826 error = copyin(p->mask, &mask, icount);
827 if (error)
828 return error;
829 }
830
831 if (v & WSDISPLAY_CURSOR_DOCUR)
832 dc->dc_curenb = p->enable;
833 if (v & WSDISPLAY_CURSOR_DOPOS)
834 set_curpos(sc, &p->pos);
835 if (v & WSDISPLAY_CURSOR_DOHOT)
836 cc->cc_hot = p->hot;
837 if (v & WSDISPLAY_CURSOR_DOCMAP) {
838 memcpy(&cc->cc_color[index], &r[index], count);
839 memcpy(&cc->cc_color[index + 2], &g[index], count);
840 memcpy(&cc->cc_color[index + 4], &b[index], count);
841 }
842 if (v & WSDISPLAY_CURSOR_DOSHAPE) {
843 cc->cc_size = p->size;
844 memset(cc->cc_image, 0, sizeof cc->cc_image);
845 memcpy(cc->cc_image, image, icount);
846 memset(cc->cc_mask, 0, sizeof cc->cc_mask);
847 memcpy(cc->cc_mask, mask, icount);
848 }
849 dc->dc_changed |= v;
850
851 return 0;
852 #undef cc
853 }
854
855
856 static int
857 get_cursor(struct vidcvideo_softc *sc, struct wsdisplay_cursor *p)
858 {
859
860 return EPASSTHROUGH; /* XXX */
861 }
862
863
864 static void
865 set_curpos(struct vidcvideo_softc *sc, struct wsdisplay_curpos *curpos)
866 {
867 struct fb_devconfig *dc = sc->sc_dc;
868 int x = curpos->x, y = curpos->y;
869
870 if (y < 0)
871 y = 0;
872 else if (y > dc->dc_ht)
873 y = dc->dc_ht;
874 if (x < 0)
875 x = 0;
876 else if (x > dc->dc_wid)
877 x = dc->dc_wid;
878 dc->dc_cursor.cc_pos.x = x;
879 dc->dc_cursor.cc_pos.y = y;
880 }
881
882
883 static void vv_copyrows(void *id, int srcrow, int dstrow, int nrows)
884 {
885 struct rasops_info *ri = id;
886 int height, offset, size;
887 int scrollup, scrolldown;
888 unsigned char *src, *dst;
889
890 /* All movements are done in multiples of character heigths */
891 height = ri->ri_font->fontheight * nrows;
892 offset = (srcrow - dstrow) * ri->ri_yscale;
893 size = height * ri->ri_stride;
894
895 /* check if we are full screen scrolling */
896 scrollup = (srcrow + nrows >= ri->ri_rows);
897 scrolldown = (dstrow + nrows >= ri->ri_rows);
898
899 if ((scrollup || scrolldown) &&
900 (videomemory.vidm_type == VIDEOMEM_TYPE_VRAM)) {
901 ri->ri_bits = vidcvideo_hwscroll(offset);
902 vidcvideo_progr_scroll(); /* sadistic ; shouldnt this be on vsync? */
903
904 /* wipe out remains of the screen if nessisary */
905 if (ri->ri_emuheight != ri->ri_height)
906 vv_eraserows(id, ri->ri_rows, 1, 0);
907 return;
908 }
909
910 /*
911 * Else we just copy the area : we're braindead for now
912 * Note: we can't use hardware scrolling when the softc isnt
913 * known yet... if its not known we dont have interrupts and
914 * we can't change the display address reliable other than in
915 * a Vsync
916 */
917
918 src = ri->ri_bits + srcrow * ri->ri_font->fontheight * ri->ri_stride;
919 dst = ri->ri_bits + dstrow * ri->ri_font->fontheight * ri->ri_stride;
920
921 memcpy(dst, src, size);
922 }
923
924
925 static void vv_eraserows(void *id, int startrow, int nrows, long attr)
926 {
927 struct rasops_info *ri = id;
928 int height;
929 unsigned char *src;
930
931 /* we're braindead for now */
932 height = ri->ri_font->fontheight * nrows * ri->ri_stride;
933
934 src = ri->ri_bits + startrow * ri->ri_font->fontheight * ri->ri_stride;
935
936 memset(src, 0, height);
937 }
938
939
940 static void vv_putchar(void *id, int row, int col, u_int uc, long attr)
941 {
942 struct rasops_info *ri = id;
943 struct fb_devconfig *dc = (struct fb_devconfig *) (ri->ri_hw);
944
945 /* delay the write back operation of the screen area */
946 dc->dc_writeback_delay = SCREEN_WRITE_BACK_DELAY;
947 dc->dc_changed |= WSDISPLAY_WB_COUNTER;
948
949 /* just delegate */
950 dc->orig_ri_ops.putchar(id, row, col, uc, attr);
951 }
952