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