genfb.c revision 1.30 1 1.30 macallan /* $NetBSD: genfb.c,v 1.30 2010/08/31 02:49:17 macallan Exp $ */
2 1.1 macallan
3 1.1 macallan /*-
4 1.1 macallan * Copyright (c) 2007 Michael Lorenz
5 1.1 macallan * All rights reserved.
6 1.1 macallan *
7 1.1 macallan * Redistribution and use in source and binary forms, with or without
8 1.1 macallan * modification, are permitted provided that the following conditions
9 1.1 macallan * are met:
10 1.1 macallan * 1. Redistributions of source code must retain the above copyright
11 1.1 macallan * notice, this list of conditions and the following disclaimer.
12 1.1 macallan * 2. Redistributions in binary form must reproduce the above copyright
13 1.1 macallan * notice, this list of conditions and the following disclaimer in the
14 1.1 macallan * documentation and/or other materials provided with the distribution.
15 1.1 macallan *
16 1.1 macallan * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
17 1.1 macallan * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
18 1.1 macallan * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
19 1.1 macallan * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
20 1.1 macallan * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21 1.1 macallan * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22 1.1 macallan * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23 1.1 macallan * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24 1.1 macallan * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25 1.1 macallan * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26 1.1 macallan * POSSIBILITY OF SUCH DAMAGE.
27 1.1 macallan */
28 1.1 macallan
29 1.1 macallan #include <sys/cdefs.h>
30 1.30 macallan __KERNEL_RCSID(0, "$NetBSD: genfb.c,v 1.30 2010/08/31 02:49:17 macallan Exp $");
31 1.1 macallan
32 1.1 macallan #include <sys/param.h>
33 1.1 macallan #include <sys/systm.h>
34 1.1 macallan #include <sys/kernel.h>
35 1.1 macallan #include <sys/device.h>
36 1.1 macallan #include <sys/proc.h>
37 1.1 macallan #include <sys/mutex.h>
38 1.1 macallan #include <sys/ioctl.h>
39 1.1 macallan #include <sys/kernel.h>
40 1.1 macallan #include <sys/systm.h>
41 1.23 jmcneill #include <sys/kmem.h>
42 1.1 macallan
43 1.1 macallan #include <dev/wscons/wsconsio.h>
44 1.1 macallan #include <dev/wscons/wsdisplayvar.h>
45 1.1 macallan #include <dev/rasops/rasops.h>
46 1.1 macallan #include <dev/wsfont/wsfont.h>
47 1.1 macallan
48 1.1 macallan #include <dev/wscons/wsdisplay_vconsvar.h>
49 1.1 macallan
50 1.1 macallan #include <dev/wsfb/genfbvar.h>
51 1.1 macallan
52 1.29 ahoka #ifdef GENFB_DISABLE_TEXT
53 1.29 ahoka #include <sys/reboot.h>
54 1.29 ahoka #define DISABLESPLASH (boothowto & (RB_SINGLE | RB_USERCONF | RB_ASKNAME | \
55 1.29 ahoka AB_VERBOSE | AB_DEBUG) )
56 1.29 ahoka #endif
57 1.29 ahoka
58 1.1 macallan #include "opt_genfb.h"
59 1.1 macallan #include "opt_wsfb.h"
60 1.1 macallan
61 1.11 macallan #ifdef GENFB_DEBUG
62 1.11 macallan #define GPRINTF panic
63 1.11 macallan #else
64 1.11 macallan #define GPRINTF aprint_verbose
65 1.11 macallan #endif
66 1.11 macallan
67 1.1 macallan static int genfb_ioctl(void *, void *, u_long, void *, int, struct lwp *);
68 1.1 macallan static paddr_t genfb_mmap(void *, void *, off_t, int);
69 1.1 macallan static void genfb_init_screen(void *, struct vcons_screen *, int, long *);
70 1.1 macallan
71 1.1 macallan static int genfb_putcmap(struct genfb_softc *, struct wsdisplay_cmap *);
72 1.1 macallan static int genfb_getcmap(struct genfb_softc *, struct wsdisplay_cmap *);
73 1.1 macallan static int genfb_putpalreg(struct genfb_softc *, uint8_t, uint8_t,
74 1.1 macallan uint8_t, uint8_t);
75 1.1 macallan
76 1.1 macallan extern const u_char rasops_cmap[768];
77 1.1 macallan
78 1.18 jmcneill static int genfb_cnattach_called = 0;
79 1.20 jmcneill static int genfb_enabled = 1;
80 1.18 jmcneill
81 1.1 macallan struct wsdisplay_accessops genfb_accessops = {
82 1.1 macallan genfb_ioctl,
83 1.1 macallan genfb_mmap,
84 1.3 macallan NULL, /* alloc_screen */
85 1.3 macallan NULL, /* free_screen */
86 1.3 macallan NULL, /* show_screen */
87 1.3 macallan NULL, /* load_font */
88 1.3 macallan NULL, /* pollc */
89 1.3 macallan NULL /* scroll */
90 1.1 macallan };
91 1.1 macallan
92 1.19 jmcneill static struct genfb_softc *genfb_softc = NULL;
93 1.19 jmcneill
94 1.2 macallan void
95 1.2 macallan genfb_init(struct genfb_softc *sc)
96 1.2 macallan {
97 1.2 macallan prop_dictionary_t dict;
98 1.28 jmcneill uint64_t cmap_cb, pmf_cb;
99 1.2 macallan uint32_t fboffset;
100 1.2 macallan
101 1.2 macallan dict = device_properties(&sc->sc_dev);
102 1.2 macallan #ifdef GENFB_DEBUG
103 1.2 macallan printf(prop_dictionary_externalize(dict));
104 1.2 macallan #endif
105 1.11 macallan if (!prop_dictionary_get_uint32(dict, "width", &sc->sc_width)) {
106 1.12 macallan GPRINTF("no width property\n");
107 1.11 macallan return;
108 1.11 macallan }
109 1.11 macallan if (!prop_dictionary_get_uint32(dict, "height", &sc->sc_height)) {
110 1.12 macallan GPRINTF("no height property\n");
111 1.11 macallan return;
112 1.11 macallan }
113 1.11 macallan if (!prop_dictionary_get_uint32(dict, "depth", &sc->sc_depth)) {
114 1.12 macallan GPRINTF("no depth property\n");
115 1.11 macallan return;
116 1.11 macallan }
117 1.2 macallan
118 1.2 macallan /* XXX should be a 64bit value */
119 1.11 macallan if (!prop_dictionary_get_uint32(dict, "address", &fboffset)) {
120 1.12 macallan GPRINTF("no address property\n");
121 1.11 macallan return;
122 1.11 macallan }
123 1.11 macallan
124 1.2 macallan sc->sc_fboffset = fboffset;
125 1.2 macallan
126 1.2 macallan if (!prop_dictionary_get_uint32(dict, "linebytes", &sc->sc_stride))
127 1.2 macallan sc->sc_stride = (sc->sc_width * sc->sc_depth) >> 3;
128 1.13 macallan
129 1.13 macallan /*
130 1.13 macallan * deal with a bug in the Raptor firmware which always sets
131 1.13 macallan * stride = width even when depth != 8
132 1.13 macallan */
133 1.13 macallan if (sc->sc_stride < sc->sc_width * (sc->sc_depth >> 3))
134 1.13 macallan sc->sc_stride = sc->sc_width * (sc->sc_depth >> 3);
135 1.13 macallan
136 1.6 macallan sc->sc_fbsize = sc->sc_height * sc->sc_stride;
137 1.4 macallan
138 1.4 macallan /* optional colour map callback */
139 1.4 macallan sc->sc_cmcb = NULL;
140 1.4 macallan if (prop_dictionary_get_uint64(dict, "cmap_callback", &cmap_cb)) {
141 1.4 macallan if (cmap_cb != 0)
142 1.4 macallan sc->sc_cmcb = (void *)(vaddr_t)cmap_cb;
143 1.4 macallan }
144 1.28 jmcneill /* optional pmf callback */
145 1.28 jmcneill sc->sc_pmfcb = NULL;
146 1.28 jmcneill if (prop_dictionary_get_uint64(dict, "pmf_callback", &pmf_cb)) {
147 1.28 jmcneill if (pmf_cb != 0)
148 1.28 jmcneill sc->sc_pmfcb = (void *)(vaddr_t)pmf_cb;
149 1.28 jmcneill }
150 1.2 macallan }
151 1.2 macallan
152 1.2 macallan int
153 1.2 macallan genfb_attach(struct genfb_softc *sc, struct genfb_ops *ops)
154 1.1 macallan {
155 1.1 macallan struct wsemuldisplaydev_attach_args aa;
156 1.1 macallan prop_dictionary_t dict;
157 1.1 macallan struct rasops_info *ri;
158 1.21 jmcneill uint16_t crow;
159 1.1 macallan long defattr;
160 1.7 macallan int i, j;
161 1.7 macallan bool console;
162 1.9 jmmv
163 1.14 phx dict = device_properties(&sc->sc_dev);
164 1.14 phx prop_dictionary_get_bool(dict, "is_console", &console);
165 1.14 phx
166 1.21 jmcneill if (prop_dictionary_get_uint16(dict, "cursor-row", &crow) == false)
167 1.21 jmcneill crow = 0;
168 1.21 jmcneill if (prop_dictionary_get_bool(dict, "clear-screen", &sc->sc_want_clear)
169 1.21 jmcneill == false)
170 1.21 jmcneill sc->sc_want_clear = true;
171 1.21 jmcneill
172 1.14 phx /* do not attach when we're not console */
173 1.14 phx if (!console) {
174 1.16 cegger aprint_normal_dev(&sc->sc_dev, "no console, unable to continue\n");
175 1.14 phx return -1;
176 1.14 phx }
177 1.14 phx
178 1.16 cegger aprint_verbose_dev(&sc->sc_dev, "framebuffer at %p, size %dx%d, depth %d, "
179 1.22 jmcneill "stride %d\n",
180 1.26 christos sc->sc_fboffset ? (void *)(intptr_t)sc->sc_fboffset : sc->sc_fbaddr,
181 1.9 jmmv sc->sc_width, sc->sc_height, sc->sc_depth, sc->sc_stride);
182 1.9 jmmv
183 1.1 macallan sc->sc_defaultscreen_descr = (struct wsscreen_descr){
184 1.1 macallan "default",
185 1.1 macallan 0, 0,
186 1.1 macallan NULL,
187 1.1 macallan 8, 16,
188 1.1 macallan WSSCREEN_WSCOLORS | WSSCREEN_HILIT,
189 1.3 macallan NULL
190 1.1 macallan };
191 1.1 macallan sc->sc_screens[0] = &sc->sc_defaultscreen_descr;
192 1.1 macallan sc->sc_screenlist = (struct wsscreen_list){1, sc->sc_screens};
193 1.1 macallan memcpy(&sc->sc_ops, ops, sizeof(struct genfb_ops));
194 1.1 macallan sc->sc_mode = WSDISPLAYIO_MODE_EMUL;
195 1.1 macallan
196 1.30 macallan #ifdef GENFB_SHADOWFB
197 1.23 jmcneill sc->sc_shadowfb = kmem_alloc(sc->sc_fbsize, KM_SLEEP);
198 1.23 jmcneill if (sc->sc_want_clear == false && sc->sc_shadowfb != NULL)
199 1.21 jmcneill memcpy(sc->sc_shadowfb, sc->sc_fbaddr, sc->sc_fbsize);
200 1.30 macallan #endif
201 1.5 macallan
202 1.1 macallan vcons_init(&sc->vd, sc, &sc->sc_defaultscreen_descr,
203 1.1 macallan &genfb_accessops);
204 1.1 macallan sc->vd.init_screen = genfb_init_screen;
205 1.1 macallan
206 1.10 jmmv /* Do not print anything between this point and the screen
207 1.10 jmmv * clear operation below. Otherwise it will be lost. */
208 1.10 jmmv
209 1.1 macallan ri = &sc->sc_console_screen.scr_ri;
210 1.1 macallan
211 1.14 phx vcons_init_screen(&sc->vd, &sc->sc_console_screen, 1,
212 1.14 phx &defattr);
213 1.14 phx sc->sc_console_screen.scr_flags |= VCONS_SCREEN_IS_STATIC;
214 1.14 phx
215 1.29 ahoka #ifdef SPLASHSCREEN
216 1.29 ahoka /*
217 1.29 ahoka * If system isn't going to go multiuser, or user has requested to see
218 1.29 ahoka * boot text, don't render splash screen immediately
219 1.29 ahoka */
220 1.29 ahoka if (DISABLESPLASH)
221 1.29 ahoka #endif
222 1.29 ahoka vcons_redraw_screen(&sc->sc_console_screen);
223 1.29 ahoka
224 1.14 phx sc->sc_defaultscreen_descr.textops = &ri->ri_ops;
225 1.14 phx sc->sc_defaultscreen_descr.capabilities = ri->ri_caps;
226 1.14 phx sc->sc_defaultscreen_descr.nrows = ri->ri_rows;
227 1.14 phx sc->sc_defaultscreen_descr.ncols = ri->ri_cols;
228 1.21 jmcneill wsdisplay_cnattach(&sc->sc_defaultscreen_descr, ri, 0, crow,
229 1.14 phx defattr);
230 1.1 macallan
231 1.10 jmmv /* Clear the whole screen to bring it to a known state. */
232 1.21 jmcneill if (sc->sc_want_clear)
233 1.21 jmcneill (*ri->ri_ops.eraserows)(ri, 0, ri->ri_rows, defattr);
234 1.10 jmmv
235 1.1 macallan j = 0;
236 1.27 macallan for (i = 0; i < min(1 << sc->sc_depth, 256); i++) {
237 1.29 ahoka #ifndef SPLASHSCREEN
238 1.4 macallan sc->sc_cmap_red[i] = rasops_cmap[j];
239 1.4 macallan sc->sc_cmap_green[i] = rasops_cmap[j + 1];
240 1.4 macallan sc->sc_cmap_blue[i] = rasops_cmap[j + 2];
241 1.1 macallan genfb_putpalreg(sc, i, rasops_cmap[j], rasops_cmap[j + 1],
242 1.1 macallan rasops_cmap[j + 2]);
243 1.1 macallan j += 3;
244 1.29 ahoka #else
245 1.29 ahoka if(i >= SPLASH_CMAP_OFFSET &&
246 1.29 ahoka i < SPLASH_CMAP_OFFSET + SPLASH_CMAP_SIZE) {
247 1.29 ahoka sc->sc_cmap_red[i] = _splash_header_data_cmap[j][0];
248 1.29 ahoka sc->sc_cmap_green[i] = _splash_header_data_cmap[j][1];
249 1.29 ahoka sc->sc_cmap_blue[i] = _splash_header_data_cmap[j][2];
250 1.29 ahoka } else {
251 1.29 ahoka sc->sc_cmap_red[i] = rasops_cmap[j];
252 1.29 ahoka sc->sc_cmap_green[i] = rasops_cmap[j + 1];
253 1.29 ahoka sc->sc_cmap_blue[i] = rasops_cmap[j + 2];
254 1.29 ahoka genfb_putpalreg(sc, i, rasops_cmap[j],
255 1.29 ahoka rasops_cmap[j + 1],
256 1.29 ahoka rasops_cmap[j + 2]);
257 1.29 ahoka }
258 1.29 ahoka j += 3;
259 1.29 ahoka #endif
260 1.1 macallan }
261 1.1 macallan
262 1.29 ahoka #ifdef SPLASHSCREEN
263 1.29 ahoka sc->sc_splash.si_depth = sc->sc_depth;
264 1.29 ahoka sc->sc_splash.si_bits = sc->sc_console_screen.scr_ri.ri_bits;
265 1.29 ahoka sc->sc_splash.si_hwbits = sc->sc_fbaddr;
266 1.29 ahoka sc->sc_splash.si_width = sc->sc_width;
267 1.29 ahoka sc->sc_splash.si_height = sc->sc_height;
268 1.29 ahoka sc->sc_splash.si_stride = sc->sc_stride;
269 1.29 ahoka sc->sc_splash.si_fillrect = NULL;
270 1.29 ahoka if (!DISABLESPLASH)
271 1.29 ahoka splash_render(&sc->sc_splash, SPLASH_F_CENTER|SPLASH_F_FILL);
272 1.29 ahoka #ifdef SPLASHSCREEN_PROGRESS
273 1.29 ahoka sc->sc_progress.sp_top = (sc->sc_height / 8) * 7;
274 1.29 ahoka sc->sc_progress.sp_width = (sc->sc_width / 4) * 3;
275 1.29 ahoka sc->sc_progress.sp_left = (sc->sc_width / 8) * 7;
276 1.29 ahoka sc->sc_progress.sp_height = 20;
277 1.29 ahoka sc->sc_progress.sp_state = -1;
278 1.29 ahoka sc->sc_progress.sp_si = &sc->sc_splash;
279 1.29 ahoka splash_progress_init(&sc->sc_progress);
280 1.29 ahoka #endif
281 1.29 ahoka #else
282 1.27 macallan vcons_replay_msgbuf(&sc->sc_console_screen);
283 1.29 ahoka #endif
284 1.27 macallan
285 1.19 jmcneill if (genfb_softc == NULL)
286 1.19 jmcneill genfb_softc = sc;
287 1.19 jmcneill
288 1.1 macallan aa.console = console;
289 1.1 macallan aa.scrdata = &sc->sc_screenlist;
290 1.1 macallan aa.accessops = &genfb_accessops;
291 1.1 macallan aa.accesscookie = &sc->vd;
292 1.1 macallan
293 1.29 ahoka #ifdef GENFB_DISABLE_TEXT
294 1.29 ahoka if (!DISABLESPLASH)
295 1.29 ahoka SCREEN_DISABLE_DRAWING(&sc->sc_console_screen);
296 1.29 ahoka #endif
297 1.29 ahoka
298 1.1 macallan config_found(&sc->sc_dev, &aa, wsemuldisplaydevprint);
299 1.1 macallan
300 1.1 macallan return 0;
301 1.1 macallan }
302 1.1 macallan
303 1.1 macallan static int
304 1.1 macallan genfb_ioctl(void *v, void *vs, u_long cmd, void *data, int flag,
305 1.1 macallan struct lwp *l)
306 1.1 macallan {
307 1.1 macallan struct vcons_data *vd = v;
308 1.1 macallan struct genfb_softc *sc = vd->cookie;
309 1.1 macallan struct wsdisplay_fbinfo *wdf;
310 1.1 macallan struct vcons_screen *ms = vd->active;
311 1.24 jmcneill int new_mode, error;
312 1.1 macallan
313 1.1 macallan switch (cmd) {
314 1.1 macallan case WSDISPLAYIO_GINFO:
315 1.6 macallan if (ms == NULL)
316 1.6 macallan return ENODEV;
317 1.1 macallan wdf = (void *)data;
318 1.1 macallan wdf->height = ms->scr_ri.ri_height;
319 1.1 macallan wdf->width = ms->scr_ri.ri_width;
320 1.1 macallan wdf->depth = ms->scr_ri.ri_depth;
321 1.1 macallan wdf->cmsize = 256;
322 1.1 macallan return 0;
323 1.1 macallan
324 1.1 macallan case WSDISPLAYIO_GETCMAP:
325 1.1 macallan return genfb_getcmap(sc,
326 1.1 macallan (struct wsdisplay_cmap *)data);
327 1.1 macallan
328 1.1 macallan case WSDISPLAYIO_PUTCMAP:
329 1.1 macallan return genfb_putcmap(sc,
330 1.1 macallan (struct wsdisplay_cmap *)data);
331 1.1 macallan
332 1.3 macallan case WSDISPLAYIO_LINEBYTES:
333 1.3 macallan *(u_int *)data = sc->sc_stride;
334 1.3 macallan return 0;
335 1.3 macallan
336 1.1 macallan case WSDISPLAYIO_SMODE:
337 1.24 jmcneill new_mode = *(int *)data;
338 1.11 macallan
339 1.24 jmcneill /* notify the bus backend */
340 1.24 jmcneill error = 0;
341 1.24 jmcneill if (sc->sc_ops.genfb_ioctl)
342 1.24 jmcneill error = sc->sc_ops.genfb_ioctl(sc, vs,
343 1.11 macallan cmd, data, flag, l);
344 1.24 jmcneill if (error)
345 1.24 jmcneill return error;
346 1.11 macallan
347 1.24 jmcneill if (new_mode != sc->sc_mode) {
348 1.24 jmcneill sc->sc_mode = new_mode;
349 1.24 jmcneill if (new_mode == WSDISPLAYIO_MODE_EMUL) {
350 1.24 jmcneill genfb_restore_palette(sc);
351 1.24 jmcneill vcons_redraw_screen(ms);
352 1.1 macallan }
353 1.1 macallan }
354 1.1 macallan return 0;
355 1.29 ahoka case WSDISPLAYIO_SSPLASH:
356 1.29 ahoka #if defined(SPLASHSCREEN)
357 1.29 ahoka if(*(int *)data == 1) {
358 1.29 ahoka SCREEN_DISABLE_DRAWING(&sc->sc_console_screen);
359 1.29 ahoka splash_render(&sc->sc_splash,
360 1.29 ahoka SPLASH_F_CENTER|SPLASH_F_FILL);
361 1.29 ahoka #if defined(SPLASHSCREEN_PROGRESS)
362 1.29 ahoka sc->sc_progress.sp_running = 1;
363 1.29 ahoka #endif
364 1.29 ahoka } else {
365 1.29 ahoka SCREEN_ENABLE_DRAWING(&sc->sc_console_screen);
366 1.29 ahoka #if defined(SPLASHSCREEN_PROGRESS)
367 1.29 ahoka sc->sc_progress.sp_running = 0;
368 1.29 ahoka #endif
369 1.29 ahoka }
370 1.29 ahoka vcons_redraw_screen(ms);
371 1.29 ahoka return 0;
372 1.29 ahoka #else
373 1.29 ahoka return ENODEV;
374 1.29 ahoka #endif
375 1.29 ahoka case WSDISPLAYIO_SPROGRESS:
376 1.29 ahoka #if defined(SPLASHSCREEN) && defined(SPLASHSCREEN_PROGRESS)
377 1.29 ahoka sc->sc_progress.sp_force = 1;
378 1.29 ahoka splash_progress_update(&sc->sc_progress);
379 1.29 ahoka sc->sc_progress.sp_force = 0;
380 1.29 ahoka vcons_redraw_screen(ms);
381 1.29 ahoka return 0;
382 1.29 ahoka #else
383 1.29 ahoka return ENODEV;
384 1.29 ahoka #endif
385 1.1 macallan default:
386 1.1 macallan if (sc->sc_ops.genfb_ioctl)
387 1.1 macallan return sc->sc_ops.genfb_ioctl(sc, vs, cmd,
388 1.1 macallan data, flag, l);
389 1.1 macallan }
390 1.1 macallan return EPASSTHROUGH;
391 1.1 macallan }
392 1.1 macallan
393 1.1 macallan static paddr_t
394 1.1 macallan genfb_mmap(void *v, void *vs, off_t offset, int prot)
395 1.1 macallan {
396 1.1 macallan struct vcons_data *vd = v;
397 1.1 macallan struct genfb_softc *sc = vd->cookie;
398 1.1 macallan
399 1.1 macallan if (sc->sc_ops.genfb_mmap)
400 1.1 macallan return sc->sc_ops.genfb_mmap(sc, vs, offset, prot);
401 1.1 macallan
402 1.1 macallan return -1;
403 1.1 macallan }
404 1.1 macallan
405 1.1 macallan static void
406 1.1 macallan genfb_init_screen(void *cookie, struct vcons_screen *scr,
407 1.1 macallan int existing, long *defattr)
408 1.1 macallan {
409 1.1 macallan struct genfb_softc *sc = cookie;
410 1.1 macallan struct rasops_info *ri = &scr->scr_ri;
411 1.1 macallan
412 1.1 macallan ri->ri_depth = sc->sc_depth;
413 1.1 macallan ri->ri_width = sc->sc_width;
414 1.1 macallan ri->ri_height = sc->sc_height;
415 1.1 macallan ri->ri_stride = sc->sc_stride;
416 1.21 jmcneill ri->ri_flg = RI_CENTER;
417 1.21 jmcneill if (sc->sc_want_clear)
418 1.21 jmcneill ri->ri_flg |= RI_FULLCLEAR;
419 1.1 macallan
420 1.30 macallan #ifdef GENFB_SHADOWFB
421 1.5 macallan if (sc->sc_shadowfb != NULL) {
422 1.5 macallan
423 1.5 macallan ri->ri_hwbits = (char *)sc->sc_fbaddr;
424 1.5 macallan ri->ri_bits = (char *)sc->sc_shadowfb;
425 1.5 macallan } else
426 1.30 macallan #endif
427 1.30 macallan {
428 1.5 macallan ri->ri_bits = (char *)sc->sc_fbaddr;
429 1.30 macallan scr->scr_flags |= VCONS_DONT_READ;
430 1.30 macallan }
431 1.1 macallan
432 1.21 jmcneill if (existing && sc->sc_want_clear) {
433 1.1 macallan ri->ri_flg |= RI_CLEAR;
434 1.1 macallan }
435 1.1 macallan
436 1.1 macallan rasops_init(ri, sc->sc_height / 8, sc->sc_width / 8);
437 1.1 macallan ri->ri_caps = WSSCREEN_WSCOLORS;
438 1.1 macallan
439 1.1 macallan rasops_reconfig(ri, sc->sc_height / ri->ri_font->fontheight,
440 1.1 macallan sc->sc_width / ri->ri_font->fontwidth);
441 1.1 macallan
442 1.27 macallan /* TODO: actually center output */
443 1.1 macallan ri->ri_hw = scr;
444 1.29 ahoka
445 1.29 ahoka #ifdef GENFB_DISABLE_TEXT
446 1.29 ahoka if (scr == &sc->sc_console_screen && !DISABLESPLASH)
447 1.29 ahoka SCREEN_DISABLE_DRAWING(&sc->sc_console_screen);
448 1.29 ahoka #endif
449 1.1 macallan }
450 1.1 macallan
451 1.1 macallan static int
452 1.1 macallan genfb_putcmap(struct genfb_softc *sc, struct wsdisplay_cmap *cm)
453 1.1 macallan {
454 1.1 macallan u_char *r, *g, *b;
455 1.1 macallan u_int index = cm->index;
456 1.1 macallan u_int count = cm->count;
457 1.1 macallan int i, error;
458 1.1 macallan u_char rbuf[256], gbuf[256], bbuf[256];
459 1.1 macallan
460 1.1 macallan #ifdef GENFB_DEBUG
461 1.1 macallan aprint_debug("putcmap: %d %d\n",index, count);
462 1.1 macallan #endif
463 1.1 macallan if (cm->index >= 256 || cm->count > 256 ||
464 1.1 macallan (cm->index + cm->count) > 256)
465 1.1 macallan return EINVAL;
466 1.1 macallan error = copyin(cm->red, &rbuf[index], count);
467 1.1 macallan if (error)
468 1.1 macallan return error;
469 1.1 macallan error = copyin(cm->green, &gbuf[index], count);
470 1.1 macallan if (error)
471 1.1 macallan return error;
472 1.1 macallan error = copyin(cm->blue, &bbuf[index], count);
473 1.1 macallan if (error)
474 1.1 macallan return error;
475 1.1 macallan
476 1.1 macallan memcpy(&sc->sc_cmap_red[index], &rbuf[index], count);
477 1.1 macallan memcpy(&sc->sc_cmap_green[index], &gbuf[index], count);
478 1.1 macallan memcpy(&sc->sc_cmap_blue[index], &bbuf[index], count);
479 1.1 macallan
480 1.1 macallan r = &sc->sc_cmap_red[index];
481 1.1 macallan g = &sc->sc_cmap_green[index];
482 1.1 macallan b = &sc->sc_cmap_blue[index];
483 1.1 macallan
484 1.1 macallan for (i = 0; i < count; i++) {
485 1.1 macallan genfb_putpalreg(sc, index, *r, *g, *b);
486 1.1 macallan index++;
487 1.1 macallan r++, g++, b++;
488 1.1 macallan }
489 1.1 macallan return 0;
490 1.1 macallan }
491 1.1 macallan
492 1.1 macallan static int
493 1.1 macallan genfb_getcmap(struct genfb_softc *sc, struct wsdisplay_cmap *cm)
494 1.1 macallan {
495 1.1 macallan u_int index = cm->index;
496 1.1 macallan u_int count = cm->count;
497 1.1 macallan int error;
498 1.1 macallan
499 1.1 macallan if (index >= 255 || count > 256 || index + count > 256)
500 1.1 macallan return EINVAL;
501 1.1 macallan
502 1.1 macallan error = copyout(&sc->sc_cmap_red[index], cm->red, count);
503 1.1 macallan if (error)
504 1.1 macallan return error;
505 1.1 macallan error = copyout(&sc->sc_cmap_green[index], cm->green, count);
506 1.1 macallan if (error)
507 1.1 macallan return error;
508 1.1 macallan error = copyout(&sc->sc_cmap_blue[index], cm->blue, count);
509 1.1 macallan if (error)
510 1.1 macallan return error;
511 1.1 macallan
512 1.1 macallan return 0;
513 1.1 macallan }
514 1.1 macallan
515 1.28 jmcneill void
516 1.1 macallan genfb_restore_palette(struct genfb_softc *sc)
517 1.1 macallan {
518 1.1 macallan int i;
519 1.1 macallan
520 1.27 macallan if (sc->sc_depth <= 8) {
521 1.27 macallan for (i = 0; i < (1 << sc->sc_depth); i++) {
522 1.27 macallan genfb_putpalreg(sc, i, sc->sc_cmap_red[i],
523 1.27 macallan sc->sc_cmap_green[i], sc->sc_cmap_blue[i]);
524 1.27 macallan }
525 1.1 macallan }
526 1.1 macallan }
527 1.1 macallan
528 1.1 macallan static int
529 1.1 macallan genfb_putpalreg(struct genfb_softc *sc, uint8_t idx, uint8_t r, uint8_t g,
530 1.1 macallan uint8_t b)
531 1.1 macallan {
532 1.1 macallan
533 1.4 macallan if (sc->sc_cmcb) {
534 1.4 macallan
535 1.4 macallan sc->sc_cmcb->gcc_set_mapreg(sc->sc_cmcb->gcc_cookie,
536 1.4 macallan idx, r, g, b);
537 1.4 macallan }
538 1.1 macallan return 0;
539 1.1 macallan }
540 1.1 macallan
541 1.18 jmcneill void
542 1.18 jmcneill genfb_cnattach(void)
543 1.18 jmcneill {
544 1.18 jmcneill genfb_cnattach_called = 1;
545 1.18 jmcneill }
546 1.18 jmcneill
547 1.20 jmcneill void
548 1.20 jmcneill genfb_disable(void)
549 1.20 jmcneill {
550 1.20 jmcneill genfb_enabled = 0;
551 1.20 jmcneill }
552 1.20 jmcneill
553 1.18 jmcneill int
554 1.18 jmcneill genfb_is_console(void)
555 1.18 jmcneill {
556 1.18 jmcneill return genfb_cnattach_called;
557 1.18 jmcneill }
558 1.19 jmcneill
559 1.19 jmcneill int
560 1.20 jmcneill genfb_is_enabled(void)
561 1.20 jmcneill {
562 1.20 jmcneill return genfb_enabled;
563 1.20 jmcneill }
564 1.20 jmcneill
565 1.20 jmcneill int
566 1.19 jmcneill genfb_borrow(bus_addr_t addr, bus_space_handle_t *hdlp)
567 1.19 jmcneill {
568 1.19 jmcneill struct genfb_softc *sc = genfb_softc;
569 1.19 jmcneill
570 1.19 jmcneill if (sc && sc->sc_ops.genfb_borrow)
571 1.19 jmcneill return sc->sc_ops.genfb_borrow(sc, addr, hdlp);
572 1.19 jmcneill return 0;
573 1.19 jmcneill }
574