p9100.c revision 1.37.4.3 1 /* $NetBSD: p9100.c,v 1.37.4.3 2009/05/16 10:41:43 yamt Exp $ */
2
3 /*-
4 * Copyright (c) 1998, 2005, 2006 The NetBSD Foundation, Inc.
5 * All rights reserved.
6 *
7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Matt Thomas.
9 *
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
12 * are met:
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
18 *
19 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 * POSSIBILITY OF SUCH DAMAGE.
30 */
31
32 /*
33 * color display (p9100) driver.
34 *
35 * Does not handle interrupts, even though they can occur.
36 *
37 * XXX should defer colormap updates to vertical retrace interrupts
38 */
39
40 #include <sys/cdefs.h>
41 __KERNEL_RCSID(0, "$NetBSD: p9100.c,v 1.37.4.3 2009/05/16 10:41:43 yamt Exp $");
42
43 #include <sys/param.h>
44 #include <sys/systm.h>
45 #include <sys/buf.h>
46 #include <sys/device.h>
47 #include <sys/ioctl.h>
48 #include <sys/malloc.h>
49 #include <sys/mman.h>
50 #include <sys/tty.h>
51 #include <sys/conf.h>
52
53 #include <sys/bus.h>
54 #include <machine/autoconf.h>
55
56 #include <dev/sun/fbio.h>
57 #include <dev/sun/fbvar.h>
58 #include <dev/sun/btreg.h>
59 #include <dev/sun/btvar.h>
60
61 #include <dev/sbus/p9100reg.h>
62
63 #include <dev/sbus/sbusvar.h>
64
65 /*#include <dev/wscons/wsdisplayvar.h>*/
66 #include <dev/wscons/wsconsio.h>
67 #include <dev/wsfont/wsfont.h>
68 #include <dev/rasops/rasops.h>
69
70 #include <dev/wscons/wsdisplay_vconsvar.h>
71
72 #include "opt_wsemul.h"
73 #include "rasops_glue.h"
74
75 #include "tctrl.h"
76 #if NTCTRL > 0
77 #include <machine/tctrl.h>
78 #include <sparc/dev/tctrlvar.h>/*XXX*/
79 #endif
80
81 struct pnozz_cursor {
82 short pc_enable; /* cursor is enabled */
83 struct fbcurpos pc_pos; /* position */
84 struct fbcurpos pc_hot; /* hot-spot */
85 struct fbcurpos pc_size; /* size of mask & image fields */
86 uint32_t pc_bits[0x100]; /* space for mask & image bits */
87 unsigned char red[3], green[3];
88 unsigned char blue[3]; /* cursor palette */
89 };
90
91 /* per-display variables */
92 struct p9100_softc {
93 struct device sc_dev; /* base device */
94 struct sbusdev sc_sd; /* sbus device */
95 struct fbdevice sc_fb; /* frame buffer device */
96
97 bus_space_tag_t sc_bustag;
98
99 bus_addr_t sc_ctl_paddr; /* phys address description */
100 bus_size_t sc_ctl_psize; /* for device mmap() */
101 bus_space_handle_t sc_ctl_memh; /* bus space handle */
102
103 bus_addr_t sc_cmd_paddr; /* phys address description */
104 bus_size_t sc_cmd_psize; /* for device mmap() */
105 bus_space_handle_t sc_cmd_memh; /* bus space handle */
106
107 bus_addr_t sc_fb_paddr; /* phys address description */
108 bus_size_t sc_fb_psize; /* for device mmap() */
109 bus_space_handle_t sc_fb_memh; /* bus space handle */
110
111 volatile uint32_t sc_junk;
112 uint32_t sc_mono_width; /* for setup_mono */
113
114 uint32_t sc_width;
115 uint32_t sc_height; /* panel width / height */
116 uint32_t sc_stride;
117 uint32_t sc_depth;
118 union bt_cmap sc_cmap; /* Brooktree color map */
119
120 struct pnozz_cursor sc_cursor;
121
122 int sc_mode;
123 int sc_video, sc_powerstate;
124 uint32_t sc_bg;
125 volatile uint32_t sc_last_offset;
126 struct vcons_data vd;
127 };
128
129
130 static struct vcons_screen p9100_console_screen;
131
132 extern const u_char rasops_cmap[768];
133
134 struct wsscreen_descr p9100_defscreendesc = {
135 "default",
136 0, 0,
137 NULL,
138 8, 16,
139 WSSCREEN_WSCOLORS,
140 };
141
142 const struct wsscreen_descr *_p9100_scrlist[] = {
143 &p9100_defscreendesc,
144 /* XXX other formats, graphics screen? */
145 };
146
147 struct wsscreen_list p9100_screenlist = {
148 sizeof(_p9100_scrlist) / sizeof(struct wsscreen_descr *), _p9100_scrlist
149 };
150
151 /* autoconfiguration driver */
152 static int p9100_sbus_match(device_t, cfdata_t, void *);
153 static void p9100_sbus_attach(device_t, device_t, void *);
154
155 static void p9100unblank(device_t);
156 static void p9100_shutdown(void *);
157
158 CFATTACH_DECL(pnozz, sizeof(struct p9100_softc),
159 p9100_sbus_match, p9100_sbus_attach, NULL, NULL);
160
161 extern struct cfdriver pnozz_cd;
162
163 static dev_type_open(p9100open);
164 static dev_type_ioctl(p9100ioctl);
165 static dev_type_mmap(p9100mmap);
166
167 const struct cdevsw pnozz_cdevsw = {
168 p9100open, nullclose, noread, nowrite, p9100ioctl,
169 nostop, notty, nopoll, p9100mmap, nokqfilter,
170 };
171
172 /* frame buffer generic driver */
173 static struct fbdriver p9100fbdriver = {
174 p9100unblank, p9100open, nullclose, p9100ioctl, nopoll,
175 p9100mmap, nokqfilter
176 };
177
178 static void p9100loadcmap(struct p9100_softc *, int, int);
179 static void p9100_set_video(struct p9100_softc *, int);
180 static int p9100_get_video(struct p9100_softc *);
181 static uint32_t p9100_ctl_read_4(struct p9100_softc *, bus_size_t);
182 static void p9100_ctl_write_4(struct p9100_softc *, bus_size_t, uint32_t);
183 static uint8_t p9100_ramdac_read(struct p9100_softc *, bus_size_t);
184 static void p9100_ramdac_write(struct p9100_softc *, bus_size_t, uint8_t);
185
186 static uint8_t p9100_ramdac_read_ctl(struct p9100_softc *, int);
187 #if NTCTRL > 0
188 static void p9100_ramdac_write_ctl(struct p9100_softc *, int, uint8_t);
189 #endif
190
191 static void p9100_init_engine(struct p9100_softc *);
192
193 #if NWSDISPLAY > 0
194 static void p9100_sync(struct p9100_softc *);
195 static void p9100_bitblt(void *, int, int, int, int, int, int, uint32_t);
196 static void p9100_rectfill(void *, int, int, int, int, uint32_t);
197 static void p9100_clearscreen(struct p9100_softc *);
198
199 static void p9100_setup_mono(struct p9100_softc *, int, int, int, int,
200 uint32_t, uint32_t);
201 static void p9100_feed_line(struct p9100_softc *, int, uint8_t *);
202 static void p9100_set_color_reg(struct p9100_softc *, int, int32_t);
203
204 static void p9100_copycols(void *, int, int, int, int);
205 static void p9100_erasecols(void *, int, int, int, long);
206 static void p9100_copyrows(void *, int, int, int);
207 static void p9100_eraserows(void *, int, int, long);
208 /*static int p9100_mapchar(void *, int, u_int *);*/
209 static void p9100_putchar(void *, int, int, u_int, long);
210 static void p9100_cursor(void *, int, int, int);
211 static int p9100_allocattr(void *, int, int, int, long *);
212
213 /*static void p9100_scroll(void *, void *, int);*/
214
215 static int p9100_putcmap(struct p9100_softc *, struct wsdisplay_cmap *);
216 static int p9100_getcmap(struct p9100_softc *, struct wsdisplay_cmap *);
217 static int p9100_ioctl(void *, void *, u_long, void *, int, struct lwp *);
218 static paddr_t p9100_mmap(void *, void *, off_t, int);
219
220 /*static int p9100_load_font(void *, void *, struct wsdisplay_font *);*/
221
222 static void p9100_init_screen(void *, struct vcons_screen *, int,
223 long *);
224 #endif
225
226 static void p9100_init_cursor(struct p9100_softc *);
227
228 static void p9100_set_fbcursor(struct p9100_softc *);
229 static void p9100_setcursorcmap(struct p9100_softc *);
230 static void p9100_loadcursor(struct p9100_softc *);
231
232 static int p9100_intr(void *);
233
234 /* power management stuff */
235 static void p9100_power_hook(int, void *);
236
237 #if NTCTRL > 0
238 static void p9100_set_extvga(void *, int);
239 #endif
240
241 #if NWSDISPLAY > 0
242 struct wsdisplay_accessops p9100_accessops = {
243 p9100_ioctl,
244 p9100_mmap,
245 NULL, /* vcons_alloc_screen */
246 NULL, /* vcons_free_screen */
247 NULL, /* vcons_show_screen */
248 NULL, /* load_font */
249 NULL, /* polls */
250 NULL, /* scroll */
251 };
252 #endif
253
254 #define PNOZZ_LATCH(sc, off) if(sc->sc_last_offset == (off & 0xffffff80)) { \
255 sc->sc_junk = bus_space_read_4(sc->sc_bustag, sc->sc_fb_memh, \
256 off); \
257 sc->sc_last_offset = off & 0xffffff80; }
258
259 /*
260 * Match a p9100.
261 */
262 static int
263 p9100_sbus_match(device_t parent, cfdata_t cf, void *aux)
264 {
265 struct sbus_attach_args *sa = aux;
266
267 return (strcmp("p9100", sa->sa_name) == 0);
268 }
269
270
271 /*
272 * Attach a display. We need to notice if it is the console, too.
273 */
274 static void
275 p9100_sbus_attach(device_t parent, device_t self, void *args)
276 {
277 struct p9100_softc *sc = device_private(self);
278 struct sbus_attach_args *sa = args;
279 struct fbdevice *fb = &sc->sc_fb;
280 int isconsole;
281 int node;
282 int i, j;
283 uint8_t ver;
284
285 #if NWSDISPLAY > 0
286 struct wsemuldisplaydev_attach_args aa;
287 struct rasops_info *ri;
288 unsigned long defattr;
289 #endif
290
291 sc->sc_last_offset = 0xffffffff;
292
293 /* Remember cookies for p9100_mmap() */
294 sc->sc_bustag = sa->sa_bustag;
295 sc->sc_ctl_paddr = sbus_bus_addr(sa->sa_bustag,
296 sa->sa_reg[0].oa_space, sa->sa_reg[0].oa_base);
297 sc->sc_ctl_psize = 0x8000;/*(bus_size_t)sa->sa_reg[0].oa_size;*/
298
299 sc->sc_cmd_paddr = sbus_bus_addr(sa->sa_bustag,
300 sa->sa_reg[1].oa_space, sa->sa_reg[1].oa_base);
301 sc->sc_cmd_psize = (bus_size_t)sa->sa_reg[1].oa_size;
302
303 sc->sc_fb_paddr = sbus_bus_addr(sa->sa_bustag,
304 sa->sa_reg[2].oa_space, sa->sa_reg[2].oa_base);
305 sc->sc_fb_psize = (bus_size_t)sa->sa_reg[2].oa_size;
306
307 fb->fb_driver = &p9100fbdriver;
308 fb->fb_device = &sc->sc_dev;
309 fb->fb_flags = device_cfdata(&sc->sc_dev)->cf_flags & FB_USERMASK;
310 #ifdef PNOZZ_EMUL_CG3
311 fb->fb_type.fb_type = FBTYPE_SUN3COLOR;
312 #else
313 fb->fb_type.fb_type = FBTYPE_P9100;
314 #endif
315 fb->fb_pixels = NULL;
316
317 sc->sc_mode = WSDISPLAYIO_MODE_EMUL;
318
319 node = sa->sa_node;
320 isconsole = fb_is_console(node);
321 if (!isconsole) {
322 aprint_normal("\n");
323 aprint_error_dev(self, "fatal error: PROM didn't configure device\n");
324 return;
325 }
326
327 /*
328 * When the ROM has mapped in a p9100 display, the address
329 * maps only the video RAM, so in any case we have to map the
330 * registers ourselves. We only need the video RAM if we are
331 * going to print characters via rconsole.
332 */
333 if (sbus_bus_map(sc->sc_bustag,
334 sa->sa_reg[0].oa_space,
335 sa->sa_reg[0].oa_base,
336 /*
337 * XXX for some reason the SBus resources don't cover
338 * all registers, so we just map what we need
339 */
340 /*sc->sc_ctl_psize*/ 0x8000,
341 /*BUS_SPACE_MAP_LINEAR*/0, &sc->sc_ctl_memh) != 0) {
342 aprint_error_dev(self, "cannot map control registers\n");
343 return;
344 }
345
346 if (sa->sa_npromvaddrs != 0)
347 fb->fb_pixels = (void *)sa->sa_promvaddrs[0];
348
349 if (fb->fb_pixels == NULL) {
350 if (sbus_bus_map(sc->sc_bustag,
351 sa->sa_reg[2].oa_space,
352 sa->sa_reg[2].oa_base,
353 sc->sc_fb_psize,
354 BUS_SPACE_MAP_LINEAR, &sc->sc_fb_memh) != 0) {
355 aprint_error_dev(self, "cannot map framebuffer\n");
356 return;
357 }
358 fb->fb_pixels = (char *)sc->sc_fb_memh;
359 } else {
360 sc->sc_fb_memh = (bus_space_handle_t) fb->fb_pixels;
361 }
362
363 i = p9100_ctl_read_4(sc, 0x0004);
364 switch ((i >> 26) & 7) {
365 case 5: fb->fb_type.fb_depth = 32; break;
366 case 7: fb->fb_type.fb_depth = 24; break;
367 case 3: fb->fb_type.fb_depth = 16; break;
368 case 2: fb->fb_type.fb_depth = 8; break;
369 default: {
370 panic("pnozz: can't determine screen depth (0x%02x)", i);
371 }
372 }
373 sc->sc_depth = (fb->fb_type.fb_depth >> 3);
374
375 /* XXX for some reason I get a kernel trap with this */
376 sc->sc_width = prom_getpropint(node, "width", 800);
377 sc->sc_height = prom_getpropint(node, "height", 600);
378
379 sc->sc_stride = prom_getpropint(node, "linebytes", sc->sc_width *
380 (fb->fb_type.fb_depth >> 3));
381
382 /* check the RAMDAC */
383 ver = p9100_ramdac_read_ctl(sc, DAC_VERSION);
384
385 p9100_init_engine(sc);
386
387 fb_setsize_obp(fb, fb->fb_type.fb_depth, sc->sc_width, sc->sc_height,
388 node);
389
390 sbus_establish(&sc->sc_sd, &sc->sc_dev);
391 bus_intr_establish(sc->sc_bustag, sa->sa_pri, IPL_BIO,
392 p9100_intr, sc);
393
394 fb->fb_type.fb_size = fb->fb_type.fb_height * fb->fb_linebytes;
395 printf(": rev %d / %x, %dx%d, depth %d mem %x",
396 (i & 7), ver, fb->fb_type.fb_width, fb->fb_type.fb_height,
397 fb->fb_type.fb_depth, (unsigned int)sc->sc_fb_psize);
398
399 fb->fb_type.fb_cmsize = prom_getpropint(node, "cmsize", 256);
400 if ((1 << fb->fb_type.fb_depth) != fb->fb_type.fb_cmsize)
401 printf(", %d entry colormap", fb->fb_type.fb_cmsize);
402
403 /* Initialize the default color map. */
404 /*bt_initcmap(&sc->sc_cmap, 256);*/
405 j = 0;
406 for (i = 0; i < 256; i++) {
407 sc->sc_cmap.cm_map[i][0] = rasops_cmap[j];
408 j++;
409 sc->sc_cmap.cm_map[i][1] = rasops_cmap[j];
410 j++;
411 sc->sc_cmap.cm_map[i][2] = rasops_cmap[j];
412 j++;
413 }
414 p9100loadcmap(sc, 0, 256);
415
416 /* make sure we are not blanked */
417 if (isconsole)
418 p9100_set_video(sc, 1);
419
420 if (shutdownhook_establish(p9100_shutdown, sc) == NULL) {
421 panic("%s: could not establish shutdown hook",
422 device_xname(&sc->sc_dev));
423 }
424
425 if (isconsole) {
426 printf(" (console)\n");
427 #ifdef RASTERCONSOLE
428 /*p9100loadcmap(sc, 255, 1);*/
429 fbrcons_init(fb);
430 #endif
431 } else
432 printf("\n");
433
434 #if NWSDISPLAY > 0
435 wsfont_init();
436
437 vcons_init(&sc->vd, sc, &p9100_defscreendesc, &p9100_accessops);
438 sc->vd.init_screen = p9100_init_screen;
439
440 vcons_init_screen(&sc->vd, &p9100_console_screen, 1, &defattr);
441 p9100_console_screen.scr_flags |= VCONS_SCREEN_IS_STATIC;
442
443 sc->sc_bg = (defattr >> 16) & 0xff;
444 p9100_clearscreen(sc);
445
446 ri = &p9100_console_screen.scr_ri;
447
448 p9100_defscreendesc.nrows = ri->ri_rows;
449 p9100_defscreendesc.ncols = ri->ri_cols;
450 p9100_defscreendesc.textops = &ri->ri_ops;
451 p9100_defscreendesc.capabilities = ri->ri_caps;
452
453 if(isconsole) {
454 wsdisplay_cnattach(&p9100_defscreendesc, ri, 0, 0, defattr);
455 }
456
457 aa.console = isconsole;
458 aa.scrdata = &p9100_screenlist;
459 aa.accessops = &p9100_accessops;
460 aa.accesscookie = &sc->vd;
461
462 config_found(self, &aa, wsemuldisplaydevprint);
463 #endif
464 /* cursor sprite handling */
465 p9100_init_cursor(sc);
466
467 /* attach the fb */
468 fb_attach(fb, isconsole);
469
470 /* register with power management */
471 sc->sc_video = 1;
472 sc->sc_powerstate = PWR_RESUME;
473 powerhook_establish(device_xname(&sc->sc_dev), p9100_power_hook, sc);
474
475 #if NTCTRL > 0
476 /* register callback for external monitor status change */
477 tadpole_register_callback(p9100_set_extvga, sc);
478 #endif
479 }
480
481 static void
482 p9100_shutdown(void *arg)
483 {
484 struct p9100_softc *sc = arg;
485
486 #ifdef RASTERCONSOLE
487 sc->sc_cmap.cm_map[0][0] = 0xff;
488 sc->sc_cmap.cm_map[0][1] = 0xff;
489 sc->sc_cmap.cm_map[0][2] = 0xff;
490 sc->sc_cmap.cm_map[1][0] = 0;
491 sc->sc_cmap.cm_map[1][1] = 0;
492 sc->sc_cmap.cm_map[1][2] = 0x00;
493 p9100loadcmap(sc, 0, 2);
494 sc->sc_cmap.cm_map[255][0] = 0;
495 sc->sc_cmap.cm_map[255][1] = 0;
496 sc->sc_cmap.cm_map[255][2] = 0;
497 p9100loadcmap(sc, 255, 1);
498 #endif
499 p9100_set_video(sc, 1);
500 }
501
502 int
503 p9100open(dev_t dev, int flags, int mode, struct lwp *l)
504 {
505 int unit = minor(dev);
506
507 if (device_lookup(&pnozz_cd, unit) == NULL)
508 return (ENXIO);
509 return (0);
510 }
511
512 int
513 p9100ioctl(dev_t dev, u_long cmd, void *data, int flags, struct lwp *l)
514 {
515 struct p9100_softc *sc = device_lookup_private(&pnozz_cd, minor(dev));
516 struct fbgattr *fba;
517 int error, v;
518
519 switch (cmd) {
520
521 case FBIOGTYPE:
522 *(struct fbtype *)data = sc->sc_fb.fb_type;
523 break;
524
525 case FBIOGATTR:
526 fba = (struct fbgattr *)data;
527 fba->real_type = sc->sc_fb.fb_type.fb_type;
528 fba->owner = 0; /* XXX ??? */
529 fba->fbtype = sc->sc_fb.fb_type;
530 fba->sattr.flags = 0;
531 fba->sattr.emu_type = sc->sc_fb.fb_type.fb_type;
532 fba->sattr.dev_specific[0] = -1;
533 fba->emu_types[0] = sc->sc_fb.fb_type.fb_type;
534 fba->emu_types[1] = -1;
535 break;
536
537 case FBIOGETCMAP:
538 #define p ((struct fbcmap *)data)
539 return (bt_getcmap(p, &sc->sc_cmap, 256, 1));
540
541 case FBIOPUTCMAP:
542 /* copy to software map */
543 error = bt_putcmap(p, &sc->sc_cmap, 256, 1);
544 if (error)
545 return (error);
546 /* now blast them into the chip */
547 /* XXX should use retrace interrupt */
548 p9100loadcmap(sc, p->index, p->count);
549 #undef p
550 break;
551
552 case FBIOGVIDEO:
553 *(int *)data = p9100_get_video(sc);
554 break;
555
556 case FBIOSVIDEO:
557 p9100_set_video(sc, *(int *)data);
558 break;
559
560 /* these are for both FBIOSCURSOR and FBIOGCURSOR */
561 #define p ((struct fbcursor *)data)
562 #define pc (&sc->sc_cursor)
563
564 case FBIOGCURSOR:
565 p->set = FB_CUR_SETALL; /* close enough, anyway */
566 p->enable = pc->pc_enable;
567 p->pos = pc->pc_pos;
568 p->hot = pc->pc_hot;
569 p->size = pc->pc_size;
570
571 if (p->image != NULL) {
572 error = copyout(pc->pc_bits, p->image, 0x200);
573 if (error)
574 return error;
575 error = copyout(&pc->pc_bits[0x80], p->mask, 0x200);
576 if (error)
577 return error;
578 }
579
580 p->cmap.index = 0;
581 p->cmap.count = 3;
582 if (p->cmap.red != NULL) {
583 copyout(pc->red, p->cmap.red, 3);
584 copyout(pc->green, p->cmap.green, 3);
585 copyout(pc->blue, p->cmap.blue, 3);
586 }
587 break;
588
589 case FBIOSCURSOR:
590 {
591 int count;
592 uint32_t image[0x80], mask[0x80];
593 uint8_t red[3], green[3], blue[3];
594
595 v = p->set;
596 if (v & FB_CUR_SETCMAP) {
597 error = copyin(p->cmap.red, red, 3);
598 error |= copyin(p->cmap.green, green, 3);
599 error |= copyin(p->cmap.blue, blue, 3);
600 if (error)
601 return error;
602 }
603 if (v & FB_CUR_SETSHAPE) {
604 if (p->size.x > 64 || p->size.y > 64)
605 return EINVAL;
606 memset(&mask, 0, 0x200);
607 memset(&image, 0, 0x200);
608 count = p->size.y * 8;
609 error = copyin(p->image, image, count);
610 if (error)
611 return error;
612 error = copyin(p->mask, mask, count);
613 if (error)
614 return error;
615 }
616
617 /* parameters are OK; do it */
618 if (v & (FB_CUR_SETCUR | FB_CUR_SETPOS | FB_CUR_SETHOT)) {
619 if (v & FB_CUR_SETCUR)
620 pc->pc_enable = p->enable;
621 if (v & FB_CUR_SETPOS)
622 pc->pc_pos = p->pos;
623 if (v & FB_CUR_SETHOT)
624 pc->pc_hot = p->hot;
625 p9100_set_fbcursor(sc);
626 }
627
628 if (v & FB_CUR_SETCMAP) {
629 memcpy(pc->red, red, 3);
630 memcpy(pc->green, green, 3);
631 memcpy(pc->blue, blue, 3);
632 p9100_setcursorcmap(sc);
633 }
634
635 if (v & FB_CUR_SETSHAPE) {
636 memcpy(pc->pc_bits, image, 0x200);
637 memcpy(&pc->pc_bits[0x80], mask, 0x200);
638 p9100_loadcursor(sc);
639 }
640 }
641 break;
642
643 #undef p
644 #undef cc
645
646 case FBIOGCURPOS:
647 *(struct fbcurpos *)data = sc->sc_cursor.pc_pos;
648 break;
649
650 case FBIOSCURPOS:
651 sc->sc_cursor.pc_pos = *(struct fbcurpos *)data;
652 p9100_set_fbcursor(sc);
653 break;
654
655 case FBIOGCURMAX:
656 /* max cursor size is 64x64 */
657 ((struct fbcurpos *)data)->x = 64;
658 ((struct fbcurpos *)data)->y = 64;
659 break;
660
661 default:
662 return (ENOTTY);
663 }
664 return (0);
665 }
666
667 static uint32_t
668 p9100_ctl_read_4(struct p9100_softc *sc, bus_size_t off)
669 {
670
671 PNOZZ_LATCH(sc, off);
672 return bus_space_read_4(sc->sc_bustag, sc->sc_ctl_memh, off);
673 }
674
675 static void
676 p9100_ctl_write_4(struct p9100_softc *sc, bus_size_t off, uint32_t v)
677 {
678
679 PNOZZ_LATCH(sc, off);
680 bus_space_write_4(sc->sc_bustag, sc->sc_ctl_memh, off, v);
681 }
682
683 /* initialize the drawing engine */
684 static void
685 p9100_init_engine(struct p9100_softc *sc)
686 {
687 /* reset clipping rectangles */
688 uint32_t rmax = ((sc->sc_width & 0x3fff) << 16) |
689 (sc->sc_height & 0x3fff);
690
691 sc->sc_last_offset = 0xffffffff;
692
693 p9100_ctl_write_4(sc, WINDOW_OFFSET, 0);
694 p9100_ctl_write_4(sc, WINDOW_MIN, 0);
695 p9100_ctl_write_4(sc, WINDOW_MAX, rmax);
696 p9100_ctl_write_4(sc, BYTE_CLIP_MIN, 0);
697 p9100_ctl_write_4(sc, BYTE_CLIP_MAX, rmax);
698 p9100_ctl_write_4(sc, DRAW_MODE, 0);
699 p9100_ctl_write_4(sc, PLANE_MASK, 0xffffffff);
700 p9100_ctl_write_4(sc, PATTERN0, 0xffffffff);
701 p9100_ctl_write_4(sc, PATTERN1, 0xffffffff);
702 p9100_ctl_write_4(sc, PATTERN2, 0xffffffff);
703 p9100_ctl_write_4(sc, PATTERN3, 0xffffffff);
704 }
705
706 /* we only need these in the wsdisplay case */
707 #if NWSDISPLAY > 0
708
709 /* wait until the engine is idle */
710 static void
711 p9100_sync(struct p9100_softc *sc)
712 {
713 while((p9100_ctl_read_4(sc, ENGINE_STATUS) &
714 (ENGINE_BUSY | BLITTER_BUSY)) != 0);
715 }
716
717 static void
718 p9100_set_color_reg(struct p9100_softc *sc, int reg, int32_t col)
719 {
720 uint32_t out;
721
722 switch(sc->sc_depth)
723 {
724 case 1: /* 8 bit */
725 out = (col << 8) | col;
726 out |= out << 16;
727 break;
728 case 2: /* 16 bit */
729 out = col | (col << 16);
730 break;
731 default:
732 out = col;
733 }
734 p9100_ctl_write_4(sc, reg, out);
735 }
736
737 /* screen-to-screen blit */
738 static void
739 p9100_bitblt(void *cookie, int xs, int ys, int xd, int yd, int wi,
740 int he, uint32_t rop)
741 {
742 struct p9100_softc *sc = cookie;
743 uint32_t src, dst, srcw, dstw;
744
745 sc->sc_last_offset = 0xffffffff;
746
747 src = ((xs & 0x3fff) << 16) | (ys & 0x3fff);
748 dst = ((xd & 0x3fff) << 16) | (yd & 0x3fff);
749 srcw = (((xs + wi - 1) & 0x3fff) << 16) | ((ys + he - 1) & 0x3fff);
750 dstw = (((xd + wi - 1) & 0x3fff) << 16) | ((yd + he - 1) & 0x3fff);
751 p9100_sync(sc);
752 p9100_ctl_write_4(sc, RASTER_OP, rop);
753
754 p9100_ctl_write_4(sc, ABS_XY0, src);
755
756 p9100_ctl_write_4(sc, ABS_XY1, srcw);
757 p9100_ctl_write_4(sc, ABS_XY2, dst);
758 p9100_ctl_write_4(sc, ABS_XY3, dstw);
759 sc->sc_junk = p9100_ctl_read_4(sc, COMMAND_BLIT);
760 }
761
762 /* solid rectangle fill */
763 static void
764 p9100_rectfill(void *cookie, int xs, int ys, int wi, int he, uint32_t col)
765 {
766 struct p9100_softc *sc = cookie;
767 uint32_t src, srcw;
768
769 sc->sc_last_offset = 0xffffffff;
770
771 src = ((xs & 0x3fff) << 16) | (ys & 0x3fff);
772 srcw = (((xs + wi) & 0x3fff) << 16) | ((ys + he) & 0x3fff);
773 p9100_sync(sc);
774 p9100_set_color_reg(sc, FOREGROUND_COLOR, col);
775 p9100_set_color_reg(sc, BACKGROUND_COLOR, col);
776 p9100_ctl_write_4(sc, RASTER_OP, ROP_PAT);
777 p9100_ctl_write_4(sc, COORD_INDEX, 0);
778 p9100_ctl_write_4(sc, RECT_RTW_XY, src);
779 p9100_ctl_write_4(sc, RECT_RTW_XY, srcw);
780 sc->sc_junk = p9100_ctl_read_4(sc, COMMAND_QUAD);
781 }
782
783 /* setup for mono->colour expansion */
784 static void
785 p9100_setup_mono(struct p9100_softc *sc, int x, int y, int wi, int he,
786 uint32_t fg, uint32_t bg)
787 {
788
789 sc->sc_last_offset = 0xffffffff;
790
791 p9100_sync(sc);
792 /*
793 * this doesn't make any sense to me either, but for some reason the
794 * chip applies the foreground colour to 0 pixels
795 */
796
797 p9100_set_color_reg(sc,FOREGROUND_COLOR,bg);
798 p9100_set_color_reg(sc,BACKGROUND_COLOR,fg);
799
800 p9100_ctl_write_4(sc, RASTER_OP, ROP_SRC);
801 p9100_ctl_write_4(sc, ABS_X0, x);
802 p9100_ctl_write_4(sc, ABS_XY1, (x << 16) | (y & 0xFFFFL));
803 p9100_ctl_write_4(sc, ABS_X2, (x + wi));
804 p9100_ctl_write_4(sc, ABS_Y3, he);
805 /* now feed the data into the chip */
806 sc->sc_mono_width = wi;
807 }
808
809 /* write monochrome data to the screen through the blitter */
810 static void
811 p9100_feed_line(struct p9100_softc *sc, int count, uint8_t *data)
812 {
813 int i;
814 uint32_t latch = 0, bork;
815 int shift = 24;
816 int to_go = sc->sc_mono_width;
817
818 PNOZZ_LATCH(sc, PIXEL_1);
819
820 for (i = 0; i < count; i++) {
821 bork = data[i];
822 latch |= (bork << shift);
823 if (shift == 0) {
824 /* check how many bits are significant */
825 if (to_go > 31) {
826 bus_space_write_4(sc->sc_bustag, sc->sc_ctl_memh,
827 (PIXEL_1 + (31 << 2)), latch);
828 /*p9100_ctl_write_4(sc, (PIXEL_1 +
829 (31 << 2)), latch);*/
830 to_go -= 32;
831 } else
832 {
833 bus_space_write_4(sc->sc_bustag, sc->sc_ctl_memh,
834 (PIXEL_1 + ((to_go - 1) << 2)), latch);
835 /*p9100_ctl_write_4(sc, (PIXEL_1 +
836 ((to_go - 1) << 2)), latch);*/
837 to_go = 0;
838 }
839 latch = 0;
840 shift = 24;
841 } else
842 shift -= 8;
843 }
844 if (shift != 24)
845 p9100_ctl_write_4(sc, (PIXEL_1 + ((to_go - 1) << 2)), latch);
846 }
847
848 static void
849 p9100_clearscreen(struct p9100_softc *sc)
850 {
851
852 p9100_rectfill(sc, 0, 0, sc->sc_width, sc->sc_height, sc->sc_bg);
853 }
854 #endif /* NWSDISPLAY > 0 */
855
856 static uint8_t
857 p9100_ramdac_read(struct p9100_softc *sc, bus_size_t off)
858 {
859
860 sc->sc_junk = p9100_ctl_read_4(sc, PWRUP_CNFG);
861 return ((bus_space_read_4(sc->sc_bustag,
862 sc->sc_ctl_memh, off) >> 16) & 0xff);
863 }
864
865 static void
866 p9100_ramdac_write(struct p9100_softc *sc, bus_size_t off, uint8_t v)
867 {
868
869 sc->sc_junk = p9100_ctl_read_4(sc, PWRUP_CNFG);
870 bus_space_write_4(sc->sc_bustag, sc->sc_ctl_memh, off,
871 ((uint32_t)v) << 16);
872 }
873
874 static uint8_t
875 p9100_ramdac_read_ctl(struct p9100_softc *sc, int off)
876 {
877 p9100_ramdac_write(sc, DAC_INDX_LO, off & 0xff);
878 p9100_ramdac_write(sc, DAC_INDX_HI, (off & 0xff00) >> 8);
879 return p9100_ramdac_read(sc, DAC_INDX_DATA);
880 }
881
882 #if NTCTRL > 0
883 static void
884 p9100_ramdac_write_ctl(struct p9100_softc *sc, int off, uint8_t val)
885 {
886 p9100_ramdac_write(sc, DAC_INDX_LO, off & 0xff);
887 p9100_ramdac_write(sc, DAC_INDX_HI, (off & 0xff00) >> 8);
888 p9100_ramdac_write(sc, DAC_INDX_DATA, val);
889 }
890 #endif /* NTCTRL > 0 */
891
892 /*
893 * Undo the effect of an FBIOSVIDEO that turns the video off.
894 */
895 static void
896 p9100unblank(device_t dev)
897 {
898 struct p9100_softc *sc = device_private(dev);
899
900 p9100_set_video((struct p9100_softc *)dev, 1);
901
902 /*
903 * Check if we're in terminal mode. If not force the console screen
904 * to front so we can see ddb, panic messages and so on
905 */
906 if (sc->sc_mode != WSDISPLAYIO_MODE_EMUL) {
907 sc->sc_mode = WSDISPLAYIO_MODE_EMUL;
908 if (sc->vd.active != &p9100_console_screen) {
909 SCREEN_INVISIBLE(sc->vd.active);
910 sc->vd.active = &p9100_console_screen;
911 SCREEN_VISIBLE(&p9100_console_screen);
912 }
913 vcons_redraw_screen(&p9100_console_screen);
914 }
915 }
916
917 static void
918 p9100_set_video(struct p9100_softc *sc, int enable)
919 {
920 u_int32_t v = p9100_ctl_read_4(sc, SCRN_RPNT_CTL_1);
921
922 if (enable)
923 v |= VIDEO_ENABLED;
924 else
925 v &= ~VIDEO_ENABLED;
926 p9100_ctl_write_4(sc, SCRN_RPNT_CTL_1, v);
927 #if NTCTRL > 0
928 /* Turn On/Off the TFT if we know how.
929 */
930 tadpole_set_video(enable);
931 #endif
932 }
933
934 static int
935 p9100_get_video(struct p9100_softc *sc)
936 {
937 return (p9100_ctl_read_4(sc, SCRN_RPNT_CTL_1) & VIDEO_ENABLED) != 0;
938 }
939
940 static void
941 p9100_power_hook(int why, void *cookie)
942 {
943 struct p9100_softc *sc = cookie;
944
945 if (why == sc->sc_powerstate)
946 return;
947
948 switch(why)
949 {
950 case PWR_SUSPEND:
951 case PWR_STANDBY:
952 sc->sc_video = p9100_get_video(sc);
953 p9100_set_video(sc, 0);
954 sc->sc_powerstate = why;
955 break;
956 case PWR_RESUME:
957 p9100_set_video(sc, sc->sc_video);
958 sc->sc_powerstate = why;
959 break;
960 }
961 }
962
963 /*
964 * Load a subset of the current (new) colormap into the IBM RAMDAC.
965 */
966 static void
967 p9100loadcmap(struct p9100_softc *sc, int start, int ncolors)
968 {
969 int i;
970
971 sc->sc_last_offset = 0xffffffff;
972
973 p9100_ramdac_write(sc, DAC_CMAP_WRIDX, start);
974
975 for (i=0;i<ncolors;i++) {
976 p9100_ramdac_write(sc, DAC_CMAP_DATA,
977 sc->sc_cmap.cm_map[i + start][0]);
978 p9100_ramdac_write(sc, DAC_CMAP_DATA,
979 sc->sc_cmap.cm_map[i + start][1]);
980 p9100_ramdac_write(sc, DAC_CMAP_DATA,
981 sc->sc_cmap.cm_map[i + start][2]);
982 }
983 }
984
985 /*
986 * Return the address that would map the given device at the given
987 * offset, allowing for the given protection, or return -1 for error.
988 */
989 static paddr_t
990 p9100mmap(dev_t dev, off_t off, int prot)
991 {
992 struct p9100_softc *sc = device_lookup_private(&pnozz_cd, minor(dev));
993
994 if (off & PGOFSET)
995 panic("p9100mmap");
996 if (off < 0)
997 return (-1);
998
999 #ifdef PNOZZ_EMUL_CG3
1000 #define CG3_MMAP_OFFSET 0x04000000
1001 /* Make Xsun think we are a CG3 (SUN3COLOR)
1002 */
1003 if (off >= CG3_MMAP_OFFSET && off < CG3_MMAP_OFFSET + sc->sc_fb_psize) {
1004 off -= CG3_MMAP_OFFSET;
1005 return (bus_space_mmap(sc->sc_bustag,
1006 sc->sc_fb_paddr,
1007 off,
1008 prot,
1009 BUS_SPACE_MAP_LINEAR));
1010 }
1011 #endif
1012
1013 if (off >= sc->sc_fb_psize + sc->sc_ctl_psize + sc->sc_cmd_psize)
1014 return (-1);
1015
1016 if (off < sc->sc_fb_psize) {
1017 return (bus_space_mmap(sc->sc_bustag,
1018 sc->sc_fb_paddr,
1019 off,
1020 prot,
1021 BUS_SPACE_MAP_LINEAR));
1022 }
1023 off -= sc->sc_fb_psize;
1024 if (off < sc->sc_ctl_psize) {
1025 return (bus_space_mmap(sc->sc_bustag,
1026 sc->sc_ctl_paddr,
1027 off,
1028 prot,
1029 BUS_SPACE_MAP_LINEAR));
1030 }
1031 off -= sc->sc_ctl_psize;
1032
1033 return (bus_space_mmap(sc->sc_bustag,
1034 sc->sc_cmd_paddr,
1035 off,
1036 prot,
1037 BUS_SPACE_MAP_LINEAR));
1038 }
1039
1040 /* wscons stuff */
1041 #if NWSDISPLAY > 0
1042
1043 static void
1044 p9100_cursor(void *cookie, int on, int row, int col)
1045 {
1046 struct rasops_info *ri = cookie;
1047 struct vcons_screen *scr = ri->ri_hw;
1048 struct p9100_softc *sc = scr->scr_cookie;
1049 int x, y, wi,he;
1050
1051 wi = ri->ri_font->fontwidth;
1052 he = ri->ri_font->fontheight;
1053
1054 if (ri->ri_flg & RI_CURSOR) {
1055 x = ri->ri_ccol * wi + ri->ri_xorigin;
1056 y = ri->ri_crow * he + ri->ri_yorigin;
1057 p9100_bitblt(sc, x, y, x, y, wi, he, ROP_SRC ^ 0xff);
1058 ri->ri_flg &= ~RI_CURSOR;
1059 }
1060 ri->ri_crow = row;
1061 ri->ri_ccol = col;
1062 if (on)
1063 {
1064 x = ri->ri_ccol * wi + ri->ri_xorigin;
1065 y = ri->ri_crow * he + ri->ri_yorigin;
1066 p9100_bitblt(sc, x, y, x, y, wi, he, ROP_SRC ^ 0xff);
1067 ri->ri_flg |= RI_CURSOR;
1068 }
1069 }
1070
1071 #if 0
1072 static int
1073 p9100_mapchar(void *cookie, int uni, u_int *index)
1074 {
1075 return 0;
1076 }
1077 #endif
1078
1079 static void
1080 p9100_putchar(void *cookie, int row, int col, u_int c, long attr)
1081 {
1082 struct rasops_info *ri = cookie;
1083 struct vcons_screen *scr = ri->ri_hw;
1084 struct p9100_softc *sc = scr->scr_cookie;
1085
1086 int fg, bg, uc, i;
1087 uint8_t *data;
1088 int x, y, wi,he;
1089
1090 wi = ri->ri_font->fontwidth;
1091 he = ri->ri_font->fontheight;
1092
1093 if (!CHAR_IN_FONT(c, ri->ri_font))
1094 return;
1095 bg = (u_char)ri->ri_devcmap[(attr >> 16) & 0xff];
1096 fg = (u_char)ri->ri_devcmap[(attr >> 24) & 0xff];
1097 x = ri->ri_xorigin + col * wi;
1098 y = ri->ri_yorigin + row * he;
1099 if (c == 0x20) {
1100 p9100_rectfill(sc, x, y, wi, he, bg);
1101 } else {
1102 uc = c-ri->ri_font->firstchar;
1103 data = (uint8_t *)ri->ri_font->data + uc *
1104 ri->ri_fontscale;
1105
1106 p9100_setup_mono(sc, x, y, wi, 1, fg, bg);
1107 for (i = 0; i < he; i++) {
1108 p9100_feed_line(sc, ri->ri_font->stride,
1109 data);
1110 data += ri->ri_font->stride;
1111 }
1112 /*p9100_sync(sc);*/
1113 }
1114 }
1115
1116 /*
1117 * wsdisplay_accessops
1118 */
1119
1120 int
1121 p9100_ioctl(void *v, void *vs, u_long cmd, void *data, int flag,
1122 struct lwp *l)
1123 {
1124 struct vcons_data *vd = v;
1125 struct p9100_softc *sc = vd->cookie;
1126 struct wsdisplay_fbinfo *wdf;
1127 struct vcons_screen *ms = vd->active;
1128
1129 switch (cmd) {
1130 case WSDISPLAYIO_GTYPE:
1131 *(u_int *)data = WSDISPLAY_TYPE_SB_P9100;
1132 return 0;
1133
1134 case FBIOGVIDEO:
1135 case WSDISPLAYIO_GVIDEO:
1136 *(int *)data = p9100_get_video(sc);
1137 return 0;
1138
1139 case WSDISPLAYIO_SVIDEO:
1140 case FBIOSVIDEO:
1141 p9100_set_video(sc, *(int *)data);
1142 return 0;
1143
1144 case WSDISPLAYIO_GINFO:
1145 wdf = (void *)data;
1146 wdf->height = ms->scr_ri.ri_height;
1147 wdf->width = ms->scr_ri.ri_width;
1148 wdf->depth = ms->scr_ri.ri_depth;
1149 wdf->cmsize = 256;
1150 return 0;
1151
1152 case WSDISPLAYIO_GETCMAP:
1153 return p9100_getcmap(sc, (struct wsdisplay_cmap *)data);
1154
1155 case WSDISPLAYIO_PUTCMAP:
1156 return p9100_putcmap(sc, (struct wsdisplay_cmap *)data);
1157
1158 case WSDISPLAYIO_SMODE:
1159 {
1160 int new_mode = *(int*)data;
1161 if (new_mode != sc->sc_mode)
1162 {
1163 sc->sc_mode = new_mode;
1164 if (new_mode == WSDISPLAYIO_MODE_EMUL)
1165 {
1166 p9100_init_engine(sc);
1167 p9100loadcmap(sc, 0, 256);
1168 p9100_clearscreen(sc);
1169 vcons_redraw_screen(ms);
1170 }
1171 }
1172 }
1173 }
1174 return EPASSTHROUGH;
1175 }
1176
1177 static paddr_t
1178 p9100_mmap(void *v, void *vs, off_t offset, int prot)
1179 {
1180 struct vcons_data *vd = v;
1181 struct p9100_softc *sc = vd->cookie;
1182 paddr_t pa;
1183
1184 /* 'regular' framebuffer mmap()ing */
1185 if (offset < sc->sc_fb_psize) {
1186 pa = bus_space_mmap(sc->sc_bustag, sc->sc_fb_paddr + offset, 0,
1187 prot, BUS_SPACE_MAP_LINEAR);
1188 return pa;
1189 }
1190
1191 if ((offset >= sc->sc_fb_paddr) && (offset < (sc->sc_fb_paddr +
1192 sc->sc_fb_psize))) {
1193 pa = bus_space_mmap(sc->sc_bustag, offset, 0, prot,
1194 BUS_SPACE_MAP_LINEAR);
1195 return pa;
1196 }
1197
1198 if ((offset >= sc->sc_ctl_paddr) && (offset < (sc->sc_ctl_paddr +
1199 sc->sc_ctl_psize))) {
1200 pa = bus_space_mmap(sc->sc_bustag, offset, 0, prot,
1201 BUS_SPACE_MAP_LINEAR);
1202 return pa;
1203 }
1204
1205 return -1;
1206 }
1207
1208 static void
1209 p9100_init_screen(void *cookie, struct vcons_screen *scr,
1210 int existing, long *defattr)
1211 {
1212 struct p9100_softc *sc = cookie;
1213 struct rasops_info *ri = &scr->scr_ri;
1214
1215 ri->ri_depth = sc->sc_depth << 3;
1216 ri->ri_width = sc->sc_width;
1217 ri->ri_height = sc->sc_height;
1218 ri->ri_stride = sc->sc_stride;
1219 ri->ri_flg = RI_CENTER | RI_FULLCLEAR;
1220
1221 ri->ri_bits = bus_space_vaddr(sc->sc_bustag, sc->sc_fb_memh);
1222
1223 #ifdef DEBUG_P9100
1224 printf("addr: %08lx\n",(ulong)ri->ri_bits);
1225 #endif
1226 rasops_init(ri, sc->sc_height/8, sc->sc_width/8);
1227 ri->ri_caps = WSSCREEN_WSCOLORS;
1228 rasops_reconfig(ri, sc->sc_height / ri->ri_font->fontheight,
1229 sc->sc_width / ri->ri_font->fontwidth);
1230
1231 /* enable acceleration */
1232 ri->ri_ops.cursor = p9100_cursor;
1233 ri->ri_ops.copyrows = p9100_copyrows;
1234 ri->ri_ops.eraserows = p9100_eraserows;
1235 ri->ri_ops.copycols = p9100_copycols;
1236 ri->ri_ops.erasecols = p9100_erasecols;
1237 ri->ri_ops.putchar = p9100_putchar;
1238 ri->ri_ops.allocattr = p9100_allocattr;
1239 }
1240
1241 static int
1242 p9100_putcmap(struct p9100_softc *sc, struct wsdisplay_cmap *cm)
1243 {
1244 u_int index = cm->index;
1245 u_int count = cm->count;
1246 int i, error;
1247 u_char rbuf[256], gbuf[256], bbuf[256];
1248 u_char *r, *g, *b;
1249
1250 if (cm->index >= 256 || cm->count > 256 ||
1251 (cm->index + cm->count) > 256)
1252 return EINVAL;
1253 error = copyin(cm->red, &rbuf[index], count);
1254 if (error)
1255 return error;
1256 error = copyin(cm->green, &gbuf[index], count);
1257 if (error)
1258 return error;
1259 error = copyin(cm->blue, &bbuf[index], count);
1260 if (error)
1261 return error;
1262
1263 r = &rbuf[index];
1264 g = &gbuf[index];
1265 b = &bbuf[index];
1266
1267 for (i = 0; i < count; i++) {
1268 sc->sc_cmap.cm_map[index][0] = *r;
1269 sc->sc_cmap.cm_map[index][1] = *g;
1270 sc->sc_cmap.cm_map[index][2] = *b;
1271 index++;
1272 r++, g++, b++;
1273 }
1274 p9100loadcmap(sc, 0, 256);
1275 return 0;
1276 }
1277
1278 static int
1279 p9100_getcmap(struct p9100_softc *sc, struct wsdisplay_cmap *cm)
1280 {
1281 u_int index = cm->index;
1282 u_int count = cm->count;
1283 int error, i;
1284 uint8_t red[256], green[256], blue[256];
1285
1286 if (index >= 255 || count > 256 || index + count > 256)
1287 return EINVAL;
1288
1289 i = index;
1290 while (i < (index + count)) {
1291 red[i] = sc->sc_cmap.cm_map[i][0];
1292 green[i] = sc->sc_cmap.cm_map[i][1];
1293 blue[i] = sc->sc_cmap.cm_map[i][2];
1294 i++;
1295 }
1296 error = copyout(&red[index], cm->red, count);
1297 if (error)
1298 return error;
1299 error = copyout(&green[index], cm->green, count);
1300 if (error)
1301 return error;
1302 error = copyout(&blue[index], cm->blue, count);
1303 if (error)
1304 return error;
1305
1306 return 0;
1307 }
1308
1309 static void
1310 p9100_copycols(void *cookie, int row, int srccol, int dstcol, int ncols)
1311 {
1312 struct rasops_info *ri = cookie;
1313 struct vcons_screen *scr = ri->ri_hw;
1314 int32_t xs, xd, y, width, height;
1315
1316 xs = ri->ri_xorigin + ri->ri_font->fontwidth * srccol;
1317 xd = ri->ri_xorigin + ri->ri_font->fontwidth * dstcol;
1318 y = ri->ri_yorigin + ri->ri_font->fontheight * row;
1319 width = ri->ri_font->fontwidth * ncols;
1320 height = ri->ri_font->fontheight;
1321 p9100_bitblt(scr->scr_cookie, xs, y, xd, y, width, height, ROP_SRC);
1322 }
1323
1324 static void
1325 p9100_erasecols(void *cookie, int row, int startcol, int ncols, long fillattr)
1326 {
1327 struct rasops_info *ri = cookie;
1328 struct vcons_screen *scr = ri->ri_hw;
1329 int32_t x, y, width, height, bg;
1330
1331 x = ri->ri_xorigin + ri->ri_font->fontwidth * startcol;
1332 y = ri->ri_yorigin + ri->ri_font->fontheight * row;
1333 width = ri->ri_font->fontwidth * ncols;
1334 height = ri->ri_font->fontheight;
1335 bg = (uint32_t)ri->ri_devcmap[(fillattr >> 16) & 0xff];
1336 p9100_rectfill(scr->scr_cookie, x, y, width, height, bg);
1337 }
1338
1339 static void
1340 p9100_copyrows(void *cookie, int srcrow, int dstrow, int nrows)
1341 {
1342 struct rasops_info *ri = cookie;
1343 struct vcons_screen *scr = ri->ri_hw;
1344 int32_t x, ys, yd, width, height;
1345
1346 x = ri->ri_xorigin;
1347 ys = ri->ri_yorigin + ri->ri_font->fontheight * srcrow;
1348 yd = ri->ri_yorigin + ri->ri_font->fontheight * dstrow;
1349 width = ri->ri_emuwidth;
1350 height = ri->ri_font->fontheight * nrows;
1351 p9100_bitblt(scr->scr_cookie, x, ys, x, yd, width, height, ROP_SRC);
1352 }
1353
1354 static void
1355 p9100_eraserows(void *cookie, int row, int nrows, long fillattr)
1356 {
1357 struct rasops_info *ri = cookie;
1358 struct vcons_screen *scr = ri->ri_hw;
1359 int32_t x, y, width, height, bg;
1360
1361 if ((row == 0) && (nrows == ri->ri_rows)) {
1362 x = y = 0;
1363 width = ri->ri_width;
1364 height = ri->ri_height;
1365 } else {
1366 x = ri->ri_xorigin;
1367 y = ri->ri_yorigin + ri->ri_font->fontheight * row;
1368 width = ri->ri_emuwidth;
1369 height = ri->ri_font->fontheight * nrows;
1370 }
1371 bg = (uint32_t)ri->ri_devcmap[(fillattr >> 16) & 0xff];
1372 p9100_rectfill(scr->scr_cookie, x, y, width, height, bg);
1373 }
1374
1375
1376 static int
1377 p9100_allocattr(void *cookie, int fg, int bg, int flags, long *attrp)
1378 {
1379 if ((fg == 0) && (bg == 0))
1380 {
1381 fg = WS_DEFAULT_FG;
1382 bg = WS_DEFAULT_BG;
1383 }
1384 if (flags & WSATTR_REVERSE) {
1385 *attrp = (bg & 0xff) << 24 | (fg & 0xff) << 16 |
1386 (flags & 0xff) << 8;
1387 } else
1388 *attrp = (fg & 0xff) << 24 | (bg & 0xff) << 16 |
1389 (flags & 0xff) << 8;
1390 return 0;
1391 }
1392
1393 #if 0
1394 static int
1395 p9100_load_font(void *v, void *cookie, struct wsdisplay_font *data)
1396 {
1397
1398 return 0;
1399 }
1400 #endif
1401
1402 #endif /* NWSDISPLAY > 0 */
1403
1404 static int
1405 p9100_intr(void *arg)
1406 {
1407 /*p9100_softc *sc=arg;
1408 printf(".");*/
1409 return 1;
1410 }
1411
1412 static void
1413 p9100_init_cursor(struct p9100_softc *sc)
1414 {
1415
1416 memset(&sc->sc_cursor, 0, sizeof(struct pnozz_cursor));
1417 sc->sc_cursor.pc_size.x = 64;
1418 sc->sc_cursor.pc_size.y = 64;
1419
1420 }
1421
1422 static void
1423 p9100_set_fbcursor(struct p9100_softc *sc)
1424 {
1425 #ifdef PNOZZ_PARANOID
1426 int s;
1427
1428 s = splhigh(); /* just in case... */
1429 #endif
1430 sc->sc_last_offset = 0xffffffff;
1431
1432 /* set position and hotspot */
1433 p9100_ramdac_write(sc, DAC_INDX_CTL, DAC_INDX_AUTOINCR);
1434 p9100_ramdac_write(sc, DAC_INDX_HI, 0);
1435 p9100_ramdac_write(sc, DAC_INDX_LO, DAC_CURSOR_CTL);
1436 if (sc->sc_cursor.pc_enable) {
1437 p9100_ramdac_write(sc, DAC_INDX_DATA, DAC_CURSOR_X11 |
1438 DAC_CURSOR_64);
1439 } else
1440 p9100_ramdac_write(sc, DAC_INDX_DATA, DAC_CURSOR_OFF);
1441 /* next two registers - x low, high, y low, high */
1442 p9100_ramdac_write(sc, DAC_INDX_DATA, sc->sc_cursor.pc_pos.x & 0xff);
1443 p9100_ramdac_write(sc, DAC_INDX_DATA, (sc->sc_cursor.pc_pos.x >> 8) &
1444 0xff);
1445 p9100_ramdac_write(sc, DAC_INDX_DATA, sc->sc_cursor.pc_pos.y & 0xff);
1446 p9100_ramdac_write(sc, DAC_INDX_DATA, (sc->sc_cursor.pc_pos.y >> 8) &
1447 0xff);
1448 /* hotspot */
1449 p9100_ramdac_write(sc, DAC_INDX_DATA, sc->sc_cursor.pc_hot.x & 0xff);
1450 p9100_ramdac_write(sc, DAC_INDX_DATA, sc->sc_cursor.pc_hot.y & 0xff);
1451
1452 #ifdef PNOZZ_PARANOID
1453 splx(s);
1454 #endif
1455
1456 }
1457
1458 static void
1459 p9100_setcursorcmap(struct p9100_softc *sc)
1460 {
1461 int i;
1462
1463 #ifdef PNOZZ_PARANOID
1464 int s;
1465 s = splhigh(); /* just in case... */
1466 #endif
1467 sc->sc_last_offset = 0xffffffff;
1468
1469 /* set cursor colours */
1470 p9100_ramdac_write(sc, DAC_INDX_CTL, DAC_INDX_AUTOINCR);
1471 p9100_ramdac_write(sc, DAC_INDX_HI, 0);
1472 p9100_ramdac_write(sc, DAC_INDX_LO, DAC_CURSOR_COL_1);
1473
1474 for (i = 0; i < 3; i++) {
1475 p9100_ramdac_write(sc, DAC_INDX_DATA, sc->sc_cursor.red[i]);
1476 p9100_ramdac_write(sc, DAC_INDX_DATA, sc->sc_cursor.green[i]);
1477 p9100_ramdac_write(sc, DAC_INDX_DATA, sc->sc_cursor.blue[i]);
1478 }
1479
1480 #ifdef PNOZZ_PARANOID
1481 splx(s);
1482 #endif
1483 }
1484
1485 static void
1486 p9100_loadcursor(struct p9100_softc *sc)
1487 {
1488 uint32_t *image, *mask;
1489 uint32_t bit, bbit, im, ma;
1490 int i, j, k;
1491 uint8_t latch1, latch2;
1492
1493 #ifdef PNOZZ_PARANOID
1494 int s;
1495 s = splhigh(); /* just in case... */
1496 #endif
1497 sc->sc_last_offset = 0xffffffff;
1498
1499 /* set cursor shape */
1500 p9100_ramdac_write(sc, DAC_INDX_CTL, DAC_INDX_AUTOINCR);
1501 p9100_ramdac_write(sc, DAC_INDX_HI, 1);
1502 p9100_ramdac_write(sc, DAC_INDX_LO, 0);
1503
1504 image = sc->sc_cursor.pc_bits;
1505 mask = &sc->sc_cursor.pc_bits[0x80];
1506
1507 for (i = 0; i < 0x80; i++) {
1508 bit = 0x80000000;
1509 im = image[i];
1510 ma = mask[i];
1511 for (k = 0; k < 4; k++) {
1512 bbit = 0x1;
1513 latch1 = 0;
1514 for (j = 0; j < 4; j++) {
1515 if (im & bit)
1516 latch1 |= bbit;
1517 bbit <<= 1;
1518 if (ma & bit)
1519 latch1 |= bbit;
1520 bbit <<= 1;
1521 bit >>= 1;
1522 }
1523 bbit = 0x1;
1524 latch2 = 0;
1525 for (j = 0; j < 4; j++) {
1526 if (im & bit)
1527 latch2 |= bbit;
1528 bbit <<= 1;
1529 if (ma & bit)
1530 latch2 |= bbit;
1531 bbit <<= 1;
1532 bit >>= 1;
1533 }
1534 p9100_ramdac_write(sc, DAC_INDX_DATA, latch1);
1535 p9100_ramdac_write(sc, DAC_INDX_DATA, latch2);
1536 }
1537 }
1538 #ifdef DEBUG_CURSOR
1539 printf("image:\n");
1540 for (i=0;i<0x80;i+=2)
1541 printf("%08x %08x\n", image[i], image[i+1]);
1542 printf("mask:\n");
1543 for (i=0;i<0x80;i+=2)
1544 printf("%08x %08x\n", mask[i], mask[i+1]);
1545 #endif
1546 #ifdef PNOZZ_PARANOID
1547 splx(s);
1548 #endif
1549 }
1550
1551 #if NTCTRL > 0
1552 static void
1553 p9100_set_extvga(void *cookie, int status)
1554 {
1555 struct p9100_softc *sc = cookie;
1556 #ifdef PNOZZ_PARANOID
1557 int s;
1558
1559 s = splhigh();
1560 #endif
1561 #ifdef DEBUG
1562 printf("%s: external VGA %s\n", device_xname(&sc->sc_dev),
1563 status ? "on" : "off");
1564 #endif
1565 sc->sc_last_offset = 0xffffffff;
1566
1567 if (status) {
1568 p9100_ramdac_write_ctl(sc, DAC_POWER,
1569 p9100_ramdac_read_ctl(sc, DAC_POWER) &
1570 ~DAC_POWER_IPWR_DISABLE);
1571 } else {
1572 p9100_ramdac_write_ctl(sc, DAC_POWER,
1573 p9100_ramdac_read_ctl(sc, DAC_POWER) |
1574 DAC_POWER_IPWR_DISABLE);
1575 }
1576 #ifdef PNOZZ_PARANOID
1577 splx(s);
1578 #endif
1579 }
1580 #endif /* NTCTRL > 0 */
1581