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