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