cgthree.c revision 1.16.4.3 1 1.16.4.3 skrll /* $NetBSD: cgthree.c,v 1.16.4.3 2009/04/28 07:36:38 skrll 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 Paul Kranenburg.
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 *
19 1.1 pk * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20 1.1 pk * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21 1.1 pk * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 1.1 pk * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23 1.1 pk * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 1.1 pk * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 1.1 pk * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 1.1 pk * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 1.1 pk * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 1.1 pk * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 1.1 pk * POSSIBILITY OF SUCH DAMAGE.
30 1.1 pk */
31 1.1 pk
32 1.1 pk /*
33 1.1 pk * color display (cgthree) driver.
34 1.1 pk *
35 1.1 pk * Does not handle interrupts, even though they can occur.
36 1.1 pk *
37 1.1 pk * XXX should defer colormap updates to vertical retrace interrupts
38 1.1 pk */
39 1.4 lukem
40 1.4 lukem #include <sys/cdefs.h>
41 1.16.4.3 skrll __KERNEL_RCSID(0, "$NetBSD: cgthree.c,v 1.16.4.3 2009/04/28 07:36:38 skrll Exp $");
42 1.1 pk
43 1.1 pk #include <sys/param.h>
44 1.1 pk #include <sys/systm.h>
45 1.1 pk #include <sys/buf.h>
46 1.1 pk #include <sys/device.h>
47 1.1 pk #include <sys/ioctl.h>
48 1.1 pk #include <sys/malloc.h>
49 1.1 pk #include <sys/mman.h>
50 1.1 pk #include <sys/tty.h>
51 1.1 pk #include <sys/conf.h>
52 1.1 pk
53 1.14 ad #include <sys/bus.h>
54 1.1 pk #include <machine/autoconf.h>
55 1.1 pk
56 1.1 pk #include <dev/sun/fbio.h>
57 1.1 pk #include <dev/sun/fbvar.h>
58 1.1 pk
59 1.16.4.2 skrll #include <dev/sun/btreg.h>
60 1.16.4.2 skrll #include <dev/sun/btvar.h>
61 1.16.4.2 skrll #include <dev/sun/cgthreereg.h>
62 1.16.4.2 skrll #include <dev/sun/cgthreevar.h>
63 1.16.4.2 skrll
64 1.16.4.1 skrll #if NWSDISPLAY > 0
65 1.16.4.1 skrll #include <dev/wscons/wsconsio.h>
66 1.16.4.1 skrll #include <dev/wsfont/wsfont.h>
67 1.16.4.1 skrll #include <dev/rasops/rasops.h>
68 1.16.4.1 skrll
69 1.16.4.1 skrll #include "opt_wsemul.h"
70 1.16.4.1 skrll #endif
71 1.16.4.1 skrll
72 1.2 pk static void cgthreeunblank(struct device *);
73 1.2 pk static void cgthreeloadcmap(struct cgthree_softc *, int, int);
74 1.2 pk static void cgthree_set_video(struct cgthree_softc *, int);
75 1.2 pk static int cgthree_get_video(struct cgthree_softc *);
76 1.2 pk
77 1.5 gehenna extern struct cfdriver cgthree_cd;
78 1.1 pk
79 1.5 gehenna dev_type_open(cgthreeopen);
80 1.5 gehenna dev_type_ioctl(cgthreeioctl);
81 1.5 gehenna dev_type_mmap(cgthreemmap);
82 1.5 gehenna
83 1.5 gehenna const struct cdevsw cgthree_cdevsw = {
84 1.5 gehenna cgthreeopen, nullclose, noread, nowrite, cgthreeioctl,
85 1.6 jdolecek nostop, notty, nopoll, cgthreemmap, nokqfilter
86 1.5 gehenna };
87 1.1 pk
88 1.1 pk /* frame buffer generic driver */
89 1.1 pk static struct fbdriver cgthreefbdriver = {
90 1.5 gehenna cgthreeunblank, cgthreeopen, nullclose, cgthreeioctl, nopoll,
91 1.6 jdolecek cgthreemmap, nokqfilter
92 1.1 pk };
93 1.1 pk
94 1.1 pk /* Video control parameters */
95 1.1 pk struct cg3_videoctrl {
96 1.1 pk unsigned char sense; /* Monitor sense value */
97 1.1 pk unsigned char vctrl[12];
98 1.1 pk } cg3_videoctrl[] = {
99 1.1 pk /* Missing entries: sense 0x10, 0x30, 0x50 */
100 1.1 pk { 0x40, /* this happens to be my 19'' 1152x900 gray-scale monitor */
101 1.1 pk {0xbb, 0x2b, 0x3, 0xb, 0xb3, 0x3, 0xaf, 0x2b, 0x2, 0xa, 0xff, 0x1}
102 1.1 pk },
103 1.1 pk { 0x00, /* default? must be last */
104 1.1 pk {0xbb, 0x2b, 0x3, 0xb, 0xb3, 0x3, 0xaf, 0x2b, 0x2, 0xa, 0xff, 0x1}
105 1.1 pk }
106 1.1 pk };
107 1.1 pk
108 1.16.4.1 skrll #if NWSDISPLAY > 0
109 1.16.4.1 skrll #ifdef RASTERCONSOLE
110 1.16.4.1 skrll #error RASTERCONSOLE and wsdisplay are mutually exclusive
111 1.16.4.1 skrll #endif
112 1.16.4.1 skrll
113 1.16.4.1 skrll static void cg3_setup_palette(struct cgthree_softc *);
114 1.16.4.1 skrll
115 1.16.4.1 skrll struct wsscreen_descr cgthree_defaultscreen = {
116 1.16.4.1 skrll "std",
117 1.16.4.1 skrll 0, 0, /* will be filled in -- XXX shouldn't, it's global */
118 1.16.4.1 skrll NULL, /* textops */
119 1.16.4.1 skrll 8, 16, /* font width/height */
120 1.16.4.1 skrll WSSCREEN_WSCOLORS, /* capabilities */
121 1.16.4.1 skrll NULL /* modecookie */
122 1.16.4.1 skrll };
123 1.16.4.1 skrll
124 1.16.4.1 skrll static int cgthree_ioctl(void *, void *, u_long, void *, int, struct lwp *);
125 1.16.4.1 skrll static paddr_t cgthree_mmap(void *, void *, off_t, int);
126 1.16.4.1 skrll static void cgthree_init_screen(void *, struct vcons_screen *, int, long *);
127 1.16.4.1 skrll
128 1.16.4.1 skrll int cgthree_putcmap(struct cgthree_softc *, struct wsdisplay_cmap *);
129 1.16.4.1 skrll int cgthree_getcmap(struct cgthree_softc *, struct wsdisplay_cmap *);
130 1.16.4.1 skrll
131 1.16.4.1 skrll struct wsdisplay_accessops cgthree_accessops = {
132 1.16.4.1 skrll cgthree_ioctl,
133 1.16.4.1 skrll cgthree_mmap,
134 1.16.4.1 skrll NULL, /* alloc_screen */
135 1.16.4.1 skrll NULL, /* free_screen */
136 1.16.4.1 skrll NULL, /* show_screen */
137 1.16.4.1 skrll NULL, /* load_font */
138 1.16.4.1 skrll NULL, /* pollc */
139 1.16.4.1 skrll NULL /* scroll */
140 1.16.4.1 skrll };
141 1.16.4.1 skrll
142 1.16.4.1 skrll const struct wsscreen_descr *_cgthree_scrlist[] = {
143 1.16.4.1 skrll &cgthree_defaultscreen
144 1.16.4.1 skrll };
145 1.16.4.1 skrll
146 1.16.4.1 skrll struct wsscreen_list cgthree_screenlist = {
147 1.16.4.1 skrll sizeof(_cgthree_scrlist) / sizeof(struct wsscreen_descr *),
148 1.16.4.1 skrll _cgthree_scrlist
149 1.16.4.1 skrll };
150 1.16.4.1 skrll
151 1.16.4.1 skrll
152 1.16.4.1 skrll extern const u_char rasops_cmap[768];
153 1.16.4.1 skrll
154 1.16.4.1 skrll static struct vcons_screen cg3_console_screen;
155 1.16.4.1 skrll #endif /* NWSDISPLAY > 0 */
156 1.1 pk
157 1.1 pk void
158 1.16.4.3 skrll cgthreeattach(struct cgthree_softc *sc, const char *name, int isconsole)
159 1.1 pk {
160 1.1 pk int i;
161 1.1 pk struct fbdevice *fb = &sc->sc_fb;
162 1.16.4.1 skrll #if NWSDISPLAY > 0
163 1.16.4.1 skrll struct wsemuldisplaydev_attach_args aa;
164 1.16.4.1 skrll struct rasops_info *ri = &cg3_console_screen.scr_ri;
165 1.16.4.1 skrll unsigned long defattr;
166 1.16.4.1 skrll #endif
167 1.1 pk volatile struct fbcontrol *fbc = sc->sc_fbc;
168 1.1 pk volatile struct bt_regs *bt = &fbc->fbc_dac;
169 1.1 pk
170 1.1 pk fb->fb_driver = &cgthreefbdriver;
171 1.1 pk fb->fb_type.fb_cmsize = 256;
172 1.1 pk fb->fb_type.fb_size = fb->fb_type.fb_height * fb->fb_linebytes;
173 1.1 pk printf(": %s, %d x %d", name,
174 1.1 pk fb->fb_type.fb_width, fb->fb_type.fb_height);
175 1.1 pk
176 1.1 pk /* Transfer video magic to board, if it's not running */
177 1.1 pk if ((fbc->fbc_ctrl & FBC_TIMING) == 0) {
178 1.1 pk int sense = (fbc->fbc_status & FBS_MSENSE);
179 1.1 pk /* Search table for video timings fitting this monitor */
180 1.1 pk for (i = 0; i < sizeof(cg3_videoctrl)/sizeof(cg3_videoctrl[0]);
181 1.1 pk i++) {
182 1.1 pk int j;
183 1.1 pk if (sense != cg3_videoctrl[i].sense)
184 1.1 pk continue;
185 1.1 pk
186 1.1 pk printf(" setting video ctrl");
187 1.1 pk for (j = 0; j < 12; j++)
188 1.1 pk fbc->fbc_vcontrol[j] =
189 1.1 pk cg3_videoctrl[i].vctrl[j];
190 1.1 pk fbc->fbc_ctrl |= FBC_TIMING;
191 1.1 pk break;
192 1.1 pk }
193 1.1 pk }
194 1.1 pk
195 1.1 pk /* make sure we are not blanked */
196 1.1 pk cgthree_set_video(sc, 1);
197 1.1 pk BT_INIT(bt, 0);
198 1.1 pk
199 1.1 pk if (isconsole) {
200 1.1 pk printf(" (console)\n");
201 1.1 pk #ifdef RASTERCONSOLE
202 1.1 pk fbrcons_init(fb);
203 1.1 pk #endif
204 1.1 pk } else
205 1.1 pk printf("\n");
206 1.1 pk
207 1.1 pk fb_attach(fb, isconsole);
208 1.16.4.1 skrll
209 1.16.4.1 skrll #if NWSDISPLAY > 0
210 1.16.4.1 skrll sc->sc_width = fb->fb_type.fb_width;
211 1.16.4.1 skrll sc->sc_stride = fb->fb_type.fb_width;
212 1.16.4.1 skrll sc->sc_height = fb->fb_type.fb_height;
213 1.16.4.1 skrll
214 1.16.4.1 skrll /* setup rasops and so on for wsdisplay */
215 1.16.4.1 skrll sc->sc_mode = WSDISPLAYIO_MODE_EMUL;
216 1.16.4.1 skrll
217 1.16.4.1 skrll vcons_init(&sc->vd, sc, &cgthree_defaultscreen, &cgthree_accessops);
218 1.16.4.1 skrll sc->vd.init_screen = cgthree_init_screen;
219 1.16.4.1 skrll
220 1.16.4.1 skrll if(isconsole) {
221 1.16.4.1 skrll /* we mess with cg3_console_screen only once */
222 1.16.4.1 skrll vcons_init_screen(&sc->vd, &cg3_console_screen, 1,
223 1.16.4.1 skrll &defattr);
224 1.16.4.1 skrll cg3_console_screen.scr_flags |= VCONS_SCREEN_IS_STATIC;
225 1.16.4.1 skrll
226 1.16.4.1 skrll cgthree_defaultscreen.textops = &ri->ri_ops;
227 1.16.4.1 skrll cgthree_defaultscreen.capabilities = ri->ri_caps;
228 1.16.4.1 skrll cgthree_defaultscreen.nrows = ri->ri_rows;
229 1.16.4.1 skrll cgthree_defaultscreen.ncols = ri->ri_cols;
230 1.16.4.1 skrll sc->vd.active = &cg3_console_screen;
231 1.16.4.1 skrll wsdisplay_cnattach(&cgthree_defaultscreen, ri, 0, 0, defattr);
232 1.16.4.1 skrll } else {
233 1.16.4.1 skrll /*
234 1.16.4.1 skrll * we're not the console so we just clear the screen and don't
235 1.16.4.1 skrll * set up any sort of text display
236 1.16.4.1 skrll */
237 1.16.4.1 skrll if (cgthree_defaultscreen.textops == NULL) {
238 1.16.4.1 skrll /*
239 1.16.4.1 skrll * ugly, but...
240 1.16.4.1 skrll * we want the console settings to win, so we only
241 1.16.4.1 skrll * touch anything when we find an untouched screen
242 1.16.4.1 skrll * definition. In this case we fill it from fb to
243 1.16.4.1 skrll * avoid problems in case no cgthree is the console
244 1.16.4.1 skrll */
245 1.16.4.1 skrll ri = &sc->sc_fb.fb_rinfo;
246 1.16.4.1 skrll cgthree_defaultscreen.textops = &ri->ri_ops;
247 1.16.4.1 skrll cgthree_defaultscreen.capabilities = ri->ri_caps;
248 1.16.4.1 skrll cgthree_defaultscreen.nrows = ri->ri_rows;
249 1.16.4.1 skrll cgthree_defaultscreen.ncols = ri->ri_cols;
250 1.16.4.1 skrll }
251 1.16.4.1 skrll }
252 1.16.4.1 skrll
253 1.16.4.1 skrll /* Initialize the default color map. */
254 1.16.4.1 skrll cg3_setup_palette(sc);
255 1.16.4.1 skrll
256 1.16.4.1 skrll aa.scrdata = &cgthree_screenlist;
257 1.16.4.1 skrll aa.console = isconsole;
258 1.16.4.1 skrll aa.accessops = &cgthree_accessops;
259 1.16.4.1 skrll aa.accesscookie = &sc->vd;
260 1.16.4.1 skrll config_found(&sc->sc_dev, &aa, wsemuldisplaydevprint);
261 1.16.4.1 skrll #else
262 1.16.4.1 skrll /* Initialize the default color map. */
263 1.16.4.1 skrll bt_initcmap(&sc->sc_cmap, 256);
264 1.16.4.1 skrll cgthreeloadcmap(sc, 0, 256);
265 1.16.4.1 skrll #endif
266 1.16.4.1 skrll
267 1.1 pk }
268 1.1 pk
269 1.1 pk
270 1.1 pk int
271 1.16.4.3 skrll cgthreeopen(dev_t dev, int flags, int mode, struct lwp *l)
272 1.1 pk {
273 1.1 pk int unit = minor(dev);
274 1.1 pk
275 1.16 drochner if (device_lookup(&cgthree_cd, unit) == NULL)
276 1.1 pk return (ENXIO);
277 1.1 pk return (0);
278 1.1 pk }
279 1.1 pk
280 1.1 pk int
281 1.16.4.3 skrll cgthreeioctl(dev_t dev, u_long cmd, void *data, int flags, struct lwp *l)
282 1.1 pk {
283 1.16 drochner struct cgthree_softc *sc = device_lookup_private(&cgthree_cd,
284 1.16 drochner minor(dev));
285 1.1 pk struct fbgattr *fba;
286 1.1 pk int error;
287 1.1 pk
288 1.1 pk switch (cmd) {
289 1.1 pk
290 1.1 pk case FBIOGTYPE:
291 1.1 pk *(struct fbtype *)data = sc->sc_fb.fb_type;
292 1.1 pk break;
293 1.1 pk
294 1.1 pk case FBIOGATTR:
295 1.1 pk fba = (struct fbgattr *)data;
296 1.1 pk fba->real_type = sc->sc_fb.fb_type.fb_type;
297 1.1 pk fba->owner = 0; /* XXX ??? */
298 1.1 pk fba->fbtype = sc->sc_fb.fb_type;
299 1.1 pk fba->sattr.flags = 0;
300 1.1 pk fba->sattr.emu_type = sc->sc_fb.fb_type.fb_type;
301 1.1 pk fba->sattr.dev_specific[0] = -1;
302 1.1 pk fba->emu_types[0] = sc->sc_fb.fb_type.fb_type;
303 1.1 pk fba->emu_types[1] = -1;
304 1.1 pk break;
305 1.1 pk
306 1.1 pk case FBIOGETCMAP:
307 1.1 pk #define p ((struct fbcmap *)data)
308 1.1 pk return (bt_getcmap(p, &sc->sc_cmap, 256, 1));
309 1.1 pk
310 1.1 pk case FBIOPUTCMAP:
311 1.1 pk /* copy to software map */
312 1.1 pk error = bt_putcmap(p, &sc->sc_cmap, 256, 1);
313 1.1 pk if (error)
314 1.1 pk return (error);
315 1.1 pk /* now blast them into the chip */
316 1.1 pk /* XXX should use retrace interrupt */
317 1.1 pk cgthreeloadcmap(sc, p->index, p->count);
318 1.1 pk #undef p
319 1.1 pk break;
320 1.1 pk
321 1.1 pk case FBIOGVIDEO:
322 1.1 pk *(int *)data = cgthree_get_video(sc);
323 1.1 pk break;
324 1.1 pk
325 1.1 pk case FBIOSVIDEO:
326 1.1 pk cgthree_set_video(sc, *(int *)data);
327 1.1 pk break;
328 1.1 pk
329 1.1 pk default:
330 1.1 pk return (ENOTTY);
331 1.1 pk }
332 1.1 pk return (0);
333 1.1 pk }
334 1.1 pk
335 1.1 pk /*
336 1.1 pk * Undo the effect of an FBIOSVIDEO that turns the video off.
337 1.1 pk */
338 1.1 pk static void
339 1.16.4.3 skrll cgthreeunblank(struct device *dev)
340 1.1 pk {
341 1.1 pk
342 1.16 drochner cgthree_set_video(device_private(dev), 1);
343 1.1 pk }
344 1.1 pk
345 1.1 pk static void
346 1.16.4.3 skrll cgthree_set_video(struct cgthree_softc *sc, int enable)
347 1.1 pk {
348 1.1 pk
349 1.1 pk if (enable)
350 1.1 pk sc->sc_fbc->fbc_ctrl |= FBC_VENAB;
351 1.1 pk else
352 1.1 pk sc->sc_fbc->fbc_ctrl &= ~FBC_VENAB;
353 1.1 pk }
354 1.1 pk
355 1.1 pk static int
356 1.16.4.3 skrll cgthree_get_video(struct cgthree_softc *sc)
357 1.1 pk {
358 1.1 pk
359 1.1 pk return ((sc->sc_fbc->fbc_ctrl & FBC_VENAB) != 0);
360 1.1 pk }
361 1.1 pk
362 1.1 pk /*
363 1.1 pk * Load a subset of the current (new) colormap into the Brooktree DAC.
364 1.1 pk */
365 1.1 pk static void
366 1.16.4.3 skrll cgthreeloadcmap(struct cgthree_softc *sc, int start, int ncolors)
367 1.1 pk {
368 1.1 pk volatile struct bt_regs *bt;
369 1.1 pk u_int *ip;
370 1.1 pk int count;
371 1.1 pk
372 1.1 pk ip = &sc->sc_cmap.cm_chip[BT_D4M3(start)]; /* start/4 * 3 */
373 1.1 pk count = BT_D4M3(start + ncolors - 1) - BT_D4M3(start) + 3;
374 1.1 pk bt = &sc->sc_fbc->fbc_dac;
375 1.1 pk bt->bt_addr = BT_D4M4(start);
376 1.1 pk while (--count >= 0)
377 1.1 pk bt->bt_cmap = *ip++;
378 1.1 pk }
379 1.1 pk
380 1.1 pk /*
381 1.1 pk * Return the address that would map the given device at the given
382 1.1 pk * offset, allowing for the given protection, or return -1 for error.
383 1.1 pk *
384 1.1 pk * The cg3 is mapped starting at 256KB, for pseudo-compatibility with
385 1.1 pk * the cg4 (which had an overlay plane in the first 128K and an enable
386 1.1 pk * plane in the next 128K). X11 uses only 256k+ region but tries to
387 1.1 pk * map the whole thing, so we repeatedly map the first 256K to the
388 1.1 pk * first page of the color screen. If someone tries to use the overlay
389 1.1 pk * and enable regions, they will get a surprise....
390 1.1 pk *
391 1.1 pk * As well, mapping at an offset of 0x04000000 causes the cg3 to be
392 1.1 pk * mapped in flat mode without the cg4 emulation.
393 1.1 pk */
394 1.1 pk paddr_t
395 1.16.4.3 skrll cgthreemmap(dev_t dev, off_t off, int prot)
396 1.1 pk {
397 1.16 drochner struct cgthree_softc *sc = device_lookup_private(&cgthree_cd,
398 1.16 drochner minor(dev));
399 1.1 pk
400 1.1 pk #define START (128*1024 + 128*1024)
401 1.1 pk #define NOOVERLAY (0x04000000)
402 1.1 pk
403 1.1 pk if (off & PGOFSET)
404 1.1 pk panic("cgthreemmap");
405 1.1 pk if (off < 0)
406 1.1 pk return (-1);
407 1.1 pk if ((u_int)off >= NOOVERLAY)
408 1.1 pk off -= NOOVERLAY;
409 1.1 pk else if ((u_int)off >= START)
410 1.1 pk off -= START;
411 1.1 pk else
412 1.1 pk off = 0;
413 1.1 pk
414 1.1 pk if (off >= sc->sc_fb.fb_type.fb_size)
415 1.1 pk return (-1);
416 1.1 pk
417 1.3 eeh return (bus_space_mmap(sc->sc_bustag,
418 1.3 eeh sc->sc_paddr, CG3REG_MEM + off,
419 1.3 eeh prot, BUS_SPACE_MAP_LINEAR));
420 1.1 pk }
421 1.16.4.1 skrll
422 1.16.4.1 skrll #if NWSDISPLAY > 0
423 1.16.4.1 skrll
424 1.16.4.1 skrll static void
425 1.16.4.1 skrll cg3_setup_palette(struct cgthree_softc *sc)
426 1.16.4.1 skrll {
427 1.16.4.1 skrll int i, j;
428 1.16.4.1 skrll
429 1.16.4.1 skrll j = 0;
430 1.16.4.1 skrll for (i = 0; i < 256; i++) {
431 1.16.4.1 skrll sc->sc_cmap.cm_map[i][0] = rasops_cmap[j];
432 1.16.4.1 skrll j++;
433 1.16.4.1 skrll sc->sc_cmap.cm_map[i][1] = rasops_cmap[j];
434 1.16.4.1 skrll j++;
435 1.16.4.1 skrll sc->sc_cmap.cm_map[i][2] = rasops_cmap[j];
436 1.16.4.1 skrll j++;
437 1.16.4.1 skrll }
438 1.16.4.1 skrll cgthreeloadcmap(sc, 0, 256);
439 1.16.4.1 skrll }
440 1.16.4.1 skrll
441 1.16.4.1 skrll int
442 1.16.4.1 skrll cgthree_ioctl(void *v, void *vs, u_long cmd, void *data, int flag,
443 1.16.4.1 skrll struct lwp *l)
444 1.16.4.1 skrll {
445 1.16.4.1 skrll /* we'll probably need to add more stuff here */
446 1.16.4.1 skrll struct vcons_data *vd = v;
447 1.16.4.1 skrll struct cgthree_softc *sc = vd->cookie;
448 1.16.4.1 skrll struct wsdisplay_fbinfo *wdf;
449 1.16.4.1 skrll struct rasops_info *ri = &sc->sc_fb.fb_rinfo;
450 1.16.4.1 skrll struct vcons_screen *ms = sc->vd.active;
451 1.16.4.1 skrll switch (cmd) {
452 1.16.4.1 skrll case WSDISPLAYIO_GTYPE:
453 1.16.4.1 skrll *(u_int *)data = WSDISPLAY_TYPE_SUNTCX;
454 1.16.4.1 skrll return 0;
455 1.16.4.1 skrll case WSDISPLAYIO_GINFO:
456 1.16.4.1 skrll wdf = (void *)data;
457 1.16.4.1 skrll wdf->height = ri->ri_height;
458 1.16.4.1 skrll wdf->width = ri->ri_width;
459 1.16.4.1 skrll wdf->depth = ri->ri_depth;
460 1.16.4.1 skrll wdf->cmsize = 256;
461 1.16.4.1 skrll return 0;
462 1.16.4.1 skrll
463 1.16.4.1 skrll case WSDISPLAYIO_GETCMAP:
464 1.16.4.1 skrll return cgthree_getcmap(sc,
465 1.16.4.1 skrll (struct wsdisplay_cmap *)data);
466 1.16.4.1 skrll case WSDISPLAYIO_PUTCMAP:
467 1.16.4.1 skrll return cgthree_putcmap(sc,
468 1.16.4.1 skrll (struct wsdisplay_cmap *)data);
469 1.16.4.1 skrll
470 1.16.4.1 skrll case WSDISPLAYIO_SMODE:
471 1.16.4.1 skrll {
472 1.16.4.1 skrll int new_mode = *(int*)data;
473 1.16.4.1 skrll if (new_mode != sc->sc_mode)
474 1.16.4.1 skrll {
475 1.16.4.1 skrll sc->sc_mode = new_mode;
476 1.16.4.1 skrll if(new_mode == WSDISPLAYIO_MODE_EMUL)
477 1.16.4.1 skrll {
478 1.16.4.1 skrll cg3_setup_palette(sc);
479 1.16.4.1 skrll vcons_redraw_screen(ms);
480 1.16.4.1 skrll }
481 1.16.4.1 skrll }
482 1.16.4.1 skrll }
483 1.16.4.1 skrll }
484 1.16.4.1 skrll return EPASSTHROUGH;
485 1.16.4.1 skrll }
486 1.16.4.1 skrll
487 1.16.4.1 skrll paddr_t
488 1.16.4.1 skrll cgthree_mmap(void *v, void *vs, off_t offset, int prot)
489 1.16.4.1 skrll {
490 1.16.4.1 skrll /* I'm not at all sure this is the right thing to do */
491 1.16.4.1 skrll return cgthreemmap(0, offset, prot); /* assume minor dev 0 for now */
492 1.16.4.1 skrll }
493 1.16.4.1 skrll
494 1.16.4.1 skrll int
495 1.16.4.1 skrll cgthree_putcmap(struct cgthree_softc *sc, struct wsdisplay_cmap *cm)
496 1.16.4.1 skrll {
497 1.16.4.1 skrll u_int index = cm->index;
498 1.16.4.1 skrll u_int count = cm->count;
499 1.16.4.1 skrll int error,i;
500 1.16.4.1 skrll if (index >= 256 || count > 256 || index + count > 256)
501 1.16.4.1 skrll return EINVAL;
502 1.16.4.1 skrll
503 1.16.4.1 skrll for (i = 0; i < count; i++)
504 1.16.4.1 skrll {
505 1.16.4.1 skrll error = copyin(&cm->red[i],
506 1.16.4.1 skrll &sc->sc_cmap.cm_map[index + i][0], 1);
507 1.16.4.1 skrll if (error)
508 1.16.4.1 skrll return error;
509 1.16.4.1 skrll error = copyin(&cm->green[i],
510 1.16.4.1 skrll &sc->sc_cmap.cm_map[index + i][1],
511 1.16.4.1 skrll 1);
512 1.16.4.1 skrll if (error)
513 1.16.4.1 skrll return error;
514 1.16.4.1 skrll error = copyin(&cm->blue[i],
515 1.16.4.1 skrll &sc->sc_cmap.cm_map[index + i][2], 1);
516 1.16.4.1 skrll if (error)
517 1.16.4.1 skrll return error;
518 1.16.4.1 skrll }
519 1.16.4.1 skrll cgthreeloadcmap(sc, index, count);
520 1.16.4.1 skrll
521 1.16.4.1 skrll return 0;
522 1.16.4.1 skrll }
523 1.16.4.1 skrll
524 1.16.4.1 skrll int
525 1.16.4.1 skrll cgthree_getcmap(struct cgthree_softc *sc, struct wsdisplay_cmap *cm)
526 1.16.4.1 skrll {
527 1.16.4.1 skrll u_int index = cm->index;
528 1.16.4.1 skrll u_int count = cm->count;
529 1.16.4.1 skrll int error,i;
530 1.16.4.1 skrll
531 1.16.4.1 skrll if (index >= 256 || count > 256 || index + count > 256)
532 1.16.4.1 skrll return EINVAL;
533 1.16.4.1 skrll
534 1.16.4.1 skrll for (i = 0; i < count; i++)
535 1.16.4.1 skrll {
536 1.16.4.1 skrll error = copyout(&sc->sc_cmap.cm_map[index + i][0],
537 1.16.4.1 skrll &cm->red[i], 1);
538 1.16.4.1 skrll if (error)
539 1.16.4.1 skrll return error;
540 1.16.4.1 skrll error = copyout(&sc->sc_cmap.cm_map[index + i][1],
541 1.16.4.1 skrll &cm->green[i], 1);
542 1.16.4.1 skrll if (error)
543 1.16.4.1 skrll return error;
544 1.16.4.1 skrll error = copyout(&sc->sc_cmap.cm_map[index + i][2],
545 1.16.4.1 skrll &cm->blue[i], 1);
546 1.16.4.1 skrll if (error)
547 1.16.4.1 skrll return error;
548 1.16.4.1 skrll }
549 1.16.4.1 skrll
550 1.16.4.1 skrll return 0;
551 1.16.4.1 skrll }
552 1.16.4.1 skrll
553 1.16.4.1 skrll void
554 1.16.4.1 skrll cgthree_init_screen(void *cookie, struct vcons_screen *scr,
555 1.16.4.1 skrll int existing, long *defattr)
556 1.16.4.1 skrll {
557 1.16.4.1 skrll struct cgthree_softc *sc = cookie;
558 1.16.4.1 skrll struct rasops_info *ri = &scr->scr_ri;
559 1.16.4.1 skrll
560 1.16.4.1 skrll ri->ri_depth = 8;
561 1.16.4.1 skrll ri->ri_width = sc->sc_width;
562 1.16.4.1 skrll ri->ri_height = sc->sc_height;
563 1.16.4.1 skrll ri->ri_stride = sc->sc_stride;
564 1.16.4.1 skrll ri->ri_flg = RI_CENTER;
565 1.16.4.1 skrll
566 1.16.4.1 skrll ri->ri_bits = sc->sc_fb.fb_pixels;
567 1.16.4.1 skrll
568 1.16.4.1 skrll memset(sc->sc_fb.fb_pixels, (*defattr >> 16) & 0xff,
569 1.16.4.1 skrll sc->sc_stride * sc->sc_height);
570 1.16.4.1 skrll rasops_init(ri, sc->sc_height/8, sc->sc_width/8);
571 1.16.4.1 skrll ri->ri_caps = WSSCREEN_WSCOLORS | WSSCREEN_REVERSE;
572 1.16.4.1 skrll rasops_reconfig(ri, sc->sc_height / ri->ri_font->fontheight,
573 1.16.4.1 skrll sc->sc_width / ri->ri_font->fontwidth);
574 1.16.4.1 skrll
575 1.16.4.1 skrll ri->ri_hw = scr;
576 1.16.4.1 skrll }
577 1.16.4.1 skrll
578 1.16.4.1 skrll #endif /* NWSDISPLAY > 0 */
579