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