gfb.c revision 1.2.4.2 1 1.2.4.2 yamt /* $NetBSD: gfb.c,v 1.2.4.2 2010/03/11 15:03:00 yamt Exp $ */
2 1.2.4.2 yamt
3 1.2.4.2 yamt /*
4 1.2.4.2 yamt * Copyright (c) 2009 Michael Lorenz
5 1.2.4.2 yamt * All rights reserved.
6 1.2.4.2 yamt *
7 1.2.4.2 yamt * Redistribution and use in source and binary forms, with or without
8 1.2.4.2 yamt * modification, are permitted provided that the following conditions
9 1.2.4.2 yamt * are met:
10 1.2.4.2 yamt * 1. Redistributions of source code must retain the above copyright
11 1.2.4.2 yamt * notice, this list of conditions and the following disclaimer.
12 1.2.4.2 yamt * 2. Redistributions in binary form must reproduce the above copyright
13 1.2.4.2 yamt * notice, this list of conditions and the following disclaimer in the
14 1.2.4.2 yamt * documentation and/or other materials provided with the distribution.
15 1.2.4.2 yamt *
16 1.2.4.2 yamt * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
17 1.2.4.2 yamt * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
18 1.2.4.2 yamt * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
19 1.2.4.2 yamt * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
20 1.2.4.2 yamt * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
21 1.2.4.2 yamt * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
22 1.2.4.2 yamt * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
23 1.2.4.2 yamt * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 1.2.4.2 yamt * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
25 1.2.4.2 yamt * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 1.2.4.2 yamt */
27 1.2.4.2 yamt
28 1.2.4.2 yamt /*
29 1.2.4.2 yamt * A console driver for Sun XVR-1000 graphics cards
30 1.2.4.2 yamt */
31 1.2.4.2 yamt
32 1.2.4.2 yamt #include <sys/cdefs.h>
33 1.2.4.2 yamt __KERNEL_RCSID(0, "$NetBSD: gfb.c,v 1.2.4.2 2010/03/11 15:03:00 yamt Exp $");
34 1.2.4.2 yamt
35 1.2.4.2 yamt #include <sys/param.h>
36 1.2.4.2 yamt #include <sys/systm.h>
37 1.2.4.2 yamt #include <sys/kernel.h>
38 1.2.4.2 yamt #include <sys/device.h>
39 1.2.4.2 yamt #include <sys/malloc.h>
40 1.2.4.2 yamt #include <sys/lwp.h>
41 1.2.4.2 yamt #include <sys/kauth.h>
42 1.2.4.2 yamt #include <sys/kmem.h>
43 1.2.4.2 yamt
44 1.2.4.2 yamt #include <uvm/uvm_extern.h>
45 1.2.4.2 yamt
46 1.2.4.2 yamt #include <dev/videomode/videomode.h>
47 1.2.4.2 yamt
48 1.2.4.2 yamt #include <machine/bus.h>
49 1.2.4.2 yamt #include <machine/autoconf.h>
50 1.2.4.2 yamt #include <machine/openfirm.h>
51 1.2.4.2 yamt
52 1.2.4.2 yamt #include <dev/wscons/wsdisplayvar.h>
53 1.2.4.2 yamt #include <dev/wscons/wsconsio.h>
54 1.2.4.2 yamt #include <dev/wsfont/wsfont.h>
55 1.2.4.2 yamt #include <dev/rasops/rasops.h>
56 1.2.4.2 yamt #include <dev/wscons/wsdisplay_vconsvar.h>
57 1.2.4.2 yamt
58 1.2.4.2 yamt
59 1.2.4.2 yamt struct gfb_softc {
60 1.2.4.2 yamt device_t sc_dev;
61 1.2.4.2 yamt
62 1.2.4.2 yamt bus_space_tag_t sc_memt;
63 1.2.4.2 yamt
64 1.2.4.2 yamt bus_space_handle_t sc_fbh;
65 1.2.4.2 yamt bus_addr_t sc_fb_paddr;
66 1.2.4.2 yamt
67 1.2.4.2 yamt int sc_width, sc_height, sc_depth, sc_stride, sc_fblen;
68 1.2.4.2 yamt int sc_locked;
69 1.2.4.2 yamt void *sc_fbaddr, *sc_shadow;
70 1.2.4.2 yamt struct vcons_screen sc_console_screen;
71 1.2.4.2 yamt struct wsscreen_descr sc_defaultscreen_descr;
72 1.2.4.2 yamt const struct wsscreen_descr *sc_screens[1];
73 1.2.4.2 yamt struct wsscreen_list sc_screenlist;
74 1.2.4.2 yamt struct vcons_data vd;
75 1.2.4.2 yamt int sc_mode;
76 1.2.4.2 yamt int sc_node;
77 1.2.4.2 yamt u_char sc_cmap_red[256];
78 1.2.4.2 yamt u_char sc_cmap_green[256];
79 1.2.4.2 yamt u_char sc_cmap_blue[256];
80 1.2.4.2 yamt };
81 1.2.4.2 yamt
82 1.2.4.2 yamt static int gfb_match(device_t, cfdata_t, void *);
83 1.2.4.2 yamt static void gfb_attach(device_t, device_t, void *);
84 1.2.4.2 yamt
85 1.2.4.2 yamt CFATTACH_DECL_NEW(gfb, sizeof(struct gfb_softc),
86 1.2.4.2 yamt gfb_match, gfb_attach, NULL, NULL);
87 1.2.4.2 yamt
88 1.2.4.2 yamt extern const u_char rasops_cmap[768];
89 1.2.4.2 yamt
90 1.2.4.2 yamt static int gfb_ioctl(void *, void *, u_long, void *, int,
91 1.2.4.2 yamt struct lwp *);
92 1.2.4.2 yamt static paddr_t gfb_mmap(void *, void *, off_t, int);
93 1.2.4.2 yamt static void gfb_init_screen(void *, struct vcons_screen *, int, long *);
94 1.2.4.2 yamt
95 1.2.4.2 yamt static int gfb_putcmap(struct gfb_softc *, struct wsdisplay_cmap *);
96 1.2.4.2 yamt static int gfb_getcmap(struct gfb_softc *, struct wsdisplay_cmap *);
97 1.2.4.2 yamt static void gfb_restore_palette(struct gfb_softc *);
98 1.2.4.2 yamt static int gfb_putpalreg(struct gfb_softc *, uint8_t, uint8_t,
99 1.2.4.2 yamt uint8_t, uint8_t);
100 1.2.4.2 yamt
101 1.2.4.2 yamt struct wsdisplay_accessops gfb_accessops = {
102 1.2.4.2 yamt gfb_ioctl,
103 1.2.4.2 yamt gfb_mmap,
104 1.2.4.2 yamt NULL, /* alloc_screen */
105 1.2.4.2 yamt NULL, /* free_screen */
106 1.2.4.2 yamt NULL, /* show_screen */
107 1.2.4.2 yamt NULL, /* load_font */
108 1.2.4.2 yamt NULL, /* pollc */
109 1.2.4.2 yamt NULL /* scroll */
110 1.2.4.2 yamt };
111 1.2.4.2 yamt
112 1.2.4.2 yamt extern int prom_stdout_node;
113 1.2.4.2 yamt
114 1.2.4.2 yamt static int
115 1.2.4.2 yamt gfb_match(device_t parent, cfdata_t match, void *aux)
116 1.2.4.2 yamt {
117 1.2.4.2 yamt struct mainbus_attach_args *ma = aux;
118 1.2.4.2 yamt
119 1.2.4.2 yamt if (strcmp(ma->ma_name, "SUNW,gfb") == 0 )
120 1.2.4.2 yamt return 100;
121 1.2.4.2 yamt return 0;
122 1.2.4.2 yamt }
123 1.2.4.2 yamt
124 1.2.4.2 yamt static void
125 1.2.4.2 yamt gfb_attach(device_t parent, device_t self, void *aux)
126 1.2.4.2 yamt {
127 1.2.4.2 yamt struct gfb_softc *sc = device_private(self);
128 1.2.4.2 yamt struct mainbus_attach_args *ma = aux;
129 1.2.4.2 yamt struct rasops_info *ri;
130 1.2.4.2 yamt struct wsemuldisplaydev_attach_args aa;
131 1.2.4.2 yamt unsigned long defattr;
132 1.2.4.2 yamt bool is_console;
133 1.2.4.2 yamt int i, j;
134 1.2.4.2 yamt
135 1.2.4.2 yamt sc->sc_memt = ma->ma_bustag;
136 1.2.4.2 yamt sc->sc_dev = self;
137 1.2.4.2 yamt sc->sc_node = ma->ma_node;
138 1.2.4.2 yamt
139 1.2.4.2 yamt if (ma->ma_nreg < 7) {
140 1.2.4.2 yamt aprint_error("%s: can't find the fb range\n",
141 1.2.4.2 yamt device_xname(self));
142 1.2.4.2 yamt return;
143 1.2.4.2 yamt }
144 1.2.4.2 yamt
145 1.2.4.2 yamt is_console = (prom_stdout_node == ma->ma_node);
146 1.2.4.2 yamt
147 1.2.4.2 yamt aprint_normal(": Sun XVR-1000%s\n", is_console ? " (console)" : "");
148 1.2.4.2 yamt
149 1.2.4.2 yamt sc->sc_depth = 32;
150 1.2.4.2 yamt sc->sc_stride = 0x4000;
151 1.2.4.2 yamt sc->sc_height = prom_getpropint(sc->sc_node, "height", 0);
152 1.2.4.2 yamt sc->sc_width = prom_getpropint(sc->sc_node, "width", 0);
153 1.2.4.2 yamt sc->sc_fblen = sc->sc_stride * sc->sc_height;
154 1.2.4.2 yamt
155 1.2.4.2 yamt if (sc->sc_fblen == 0) {
156 1.2.4.2 yamt aprint_error("%s: not set up by firmware, can't continue.\n",
157 1.2.4.2 yamt device_xname(self));
158 1.2.4.2 yamt return;
159 1.2.4.2 yamt }
160 1.2.4.2 yamt
161 1.2.4.2 yamt sc->sc_shadow = kmem_alloc(sc->sc_fblen, KM_SLEEP);
162 1.2.4.2 yamt sc->sc_locked = 0;
163 1.2.4.2 yamt sc->sc_mode = WSDISPLAYIO_MODE_EMUL;
164 1.2.4.2 yamt
165 1.2.4.2 yamt if (bus_space_map(sc->sc_memt, ma->ma_reg[6].ur_paddr,
166 1.2.4.2 yamt sc->sc_fblen, BUS_SPACE_MAP_LINEAR, &sc->sc_fbh)) {
167 1.2.4.2 yamt printf(": failed to map the framebuffer\n");
168 1.2.4.2 yamt return;
169 1.2.4.2 yamt }
170 1.2.4.2 yamt sc->sc_fbaddr = bus_space_vaddr(sc->sc_memt, sc->sc_fbh);
171 1.2.4.2 yamt sc->sc_fb_paddr = ma->ma_reg[6].ur_paddr;
172 1.2.4.2 yamt
173 1.2.4.2 yamt sc->sc_defaultscreen_descr = (struct wsscreen_descr){
174 1.2.4.2 yamt "default",
175 1.2.4.2 yamt 0, 0,
176 1.2.4.2 yamt NULL,
177 1.2.4.2 yamt 8, 16,
178 1.2.4.2 yamt WSSCREEN_WSCOLORS | WSSCREEN_HILIT,
179 1.2.4.2 yamt NULL
180 1.2.4.2 yamt };
181 1.2.4.2 yamt sc->sc_screens[0] = &sc->sc_defaultscreen_descr;
182 1.2.4.2 yamt sc->sc_screenlist = (struct wsscreen_list){1, sc->sc_screens};
183 1.2.4.2 yamt sc->sc_mode = WSDISPLAYIO_MODE_EMUL;
184 1.2.4.2 yamt sc->sc_locked = 0;
185 1.2.4.2 yamt
186 1.2.4.2 yamt vcons_init(&sc->vd, sc, &sc->sc_defaultscreen_descr,
187 1.2.4.2 yamt &gfb_accessops);
188 1.2.4.2 yamt sc->vd.init_screen = gfb_init_screen;
189 1.2.4.2 yamt
190 1.2.4.2 yamt ri = &sc->sc_console_screen.scr_ri;
191 1.2.4.2 yamt
192 1.2.4.2 yamt j = 0;
193 1.2.4.2 yamt for (i = 0; i < (1 << sc->sc_depth); i++) {
194 1.2.4.2 yamt
195 1.2.4.2 yamt sc->sc_cmap_red[i] = rasops_cmap[j];
196 1.2.4.2 yamt sc->sc_cmap_green[i] = rasops_cmap[j + 1];
197 1.2.4.2 yamt sc->sc_cmap_blue[i] = rasops_cmap[j + 2];
198 1.2.4.2 yamt gfb_putpalreg(sc, i, rasops_cmap[j], rasops_cmap[j + 1],
199 1.2.4.2 yamt rasops_cmap[j + 2]);
200 1.2.4.2 yamt j += 3;
201 1.2.4.2 yamt }
202 1.2.4.2 yamt
203 1.2.4.2 yamt if (is_console) {
204 1.2.4.2 yamt vcons_init_screen(&sc->vd, &sc->sc_console_screen, 1,
205 1.2.4.2 yamt &defattr);
206 1.2.4.2 yamt sc->sc_console_screen.scr_flags |= VCONS_SCREEN_IS_STATIC;
207 1.2.4.2 yamt
208 1.2.4.2 yamt #if notyet
209 1.2.4.2 yamt gfb_rectfill(sc, 0, 0, sc->sc_width, sc->sc_height,
210 1.2.4.2 yamt ri->ri_devcmap[(defattr >> 16) & 0xff]);
211 1.2.4.2 yamt #endif
212 1.2.4.2 yamt sc->sc_defaultscreen_descr.textops = &ri->ri_ops;
213 1.2.4.2 yamt sc->sc_defaultscreen_descr.capabilities = ri->ri_caps;
214 1.2.4.2 yamt sc->sc_defaultscreen_descr.nrows = ri->ri_rows;
215 1.2.4.2 yamt sc->sc_defaultscreen_descr.ncols = ri->ri_cols;
216 1.2.4.2 yamt wsdisplay_cnattach(&sc->sc_defaultscreen_descr, ri, 0, 0,
217 1.2.4.2 yamt defattr);
218 1.2.4.2 yamt vcons_replay_msgbuf(&sc->sc_console_screen);
219 1.2.4.2 yamt } else {
220 1.2.4.2 yamt /*
221 1.2.4.2 yamt * since we're not the console we can postpone the rest
222 1.2.4.2 yamt * until someone actually allocates a screen for us
223 1.2.4.2 yamt */
224 1.2.4.2 yamt (*ri->ri_ops.allocattr)(ri, 0, 0, 0, &defattr);
225 1.2.4.2 yamt }
226 1.2.4.2 yamt
227 1.2.4.2 yamt aa.console = is_console;
228 1.2.4.2 yamt aa.scrdata = &sc->sc_screenlist;
229 1.2.4.2 yamt aa.accessops = &gfb_accessops;
230 1.2.4.2 yamt aa.accesscookie = &sc->vd;
231 1.2.4.2 yamt
232 1.2.4.2 yamt config_found(sc->sc_dev, &aa, wsemuldisplaydevprint);
233 1.2.4.2 yamt }
234 1.2.4.2 yamt
235 1.2.4.2 yamt static int
236 1.2.4.2 yamt gfb_ioctl(void *v, void *vs, u_long cmd, void *data, int flag,
237 1.2.4.2 yamt struct lwp *l)
238 1.2.4.2 yamt {
239 1.2.4.2 yamt struct vcons_data *vd = v;
240 1.2.4.2 yamt struct gfb_softc *sc = vd->cookie;
241 1.2.4.2 yamt struct wsdisplay_fbinfo *wdf;
242 1.2.4.2 yamt struct vcons_screen *ms = vd->active;
243 1.2.4.2 yamt
244 1.2.4.2 yamt switch (cmd) {
245 1.2.4.2 yamt
246 1.2.4.2 yamt case WSDISPLAYIO_GTYPE:
247 1.2.4.2 yamt *(u_int *)data = WSDISPLAY_TYPE_XVR1000;
248 1.2.4.2 yamt return 0;
249 1.2.4.2 yamt
250 1.2.4.2 yamt case WSDISPLAYIO_GINFO:
251 1.2.4.2 yamt if (ms == NULL)
252 1.2.4.2 yamt return ENODEV;
253 1.2.4.2 yamt wdf = (void *)data;
254 1.2.4.2 yamt wdf->height = ms->scr_ri.ri_height;
255 1.2.4.2 yamt wdf->width = ms->scr_ri.ri_width;
256 1.2.4.2 yamt wdf->depth = ms->scr_ri.ri_depth;
257 1.2.4.2 yamt wdf->cmsize = 256;
258 1.2.4.2 yamt return 0;
259 1.2.4.2 yamt
260 1.2.4.2 yamt case WSDISPLAYIO_GETCMAP:
261 1.2.4.2 yamt return gfb_getcmap(sc,
262 1.2.4.2 yamt (struct wsdisplay_cmap *)data);
263 1.2.4.2 yamt
264 1.2.4.2 yamt case WSDISPLAYIO_PUTCMAP:
265 1.2.4.2 yamt return gfb_putcmap(sc,
266 1.2.4.2 yamt (struct wsdisplay_cmap *)data);
267 1.2.4.2 yamt
268 1.2.4.2 yamt case WSDISPLAYIO_LINEBYTES:
269 1.2.4.2 yamt *(u_int *)data = sc->sc_stride;
270 1.2.4.2 yamt return 0;
271 1.2.4.2 yamt
272 1.2.4.2 yamt case WSDISPLAYIO_SMODE:
273 1.2.4.2 yamt {
274 1.2.4.2 yamt int new_mode = *(int*)data;
275 1.2.4.2 yamt
276 1.2.4.2 yamt /* notify the bus backend */
277 1.2.4.2 yamt if (new_mode != sc->sc_mode) {
278 1.2.4.2 yamt sc->sc_mode = new_mode;
279 1.2.4.2 yamt if(new_mode == WSDISPLAYIO_MODE_EMUL) {
280 1.2.4.2 yamt gfb_restore_palette(sc);
281 1.2.4.2 yamt vcons_redraw_screen(ms);
282 1.2.4.2 yamt }
283 1.2.4.2 yamt }
284 1.2.4.2 yamt }
285 1.2.4.2 yamt return 0;
286 1.2.4.2 yamt }
287 1.2.4.2 yamt return EPASSTHROUGH;
288 1.2.4.2 yamt }
289 1.2.4.2 yamt
290 1.2.4.2 yamt static paddr_t
291 1.2.4.2 yamt gfb_mmap(void *v, void *vs, off_t offset, int prot)
292 1.2.4.2 yamt {
293 1.2.4.2 yamt struct vcons_data *vd = v;
294 1.2.4.2 yamt struct gfb_softc *sc = vd->cookie;
295 1.2.4.2 yamt paddr_t pa;
296 1.2.4.2 yamt
297 1.2.4.2 yamt /* 'regular' framebuffer mmap()ing */
298 1.2.4.2 yamt if (offset < sc->sc_fblen) {
299 1.2.4.2 yamt pa = bus_space_mmap(sc->sc_memt, sc->sc_fb_paddr + offset, 0,
300 1.2.4.2 yamt prot, BUS_SPACE_MAP_LINEAR);
301 1.2.4.2 yamt return pa;
302 1.2.4.2 yamt }
303 1.2.4.2 yamt
304 1.2.4.2 yamt /*
305 1.2.4.2 yamt * restrict all other mappings to processes with superuser privileges
306 1.2.4.2 yamt * or the kernel itself
307 1.2.4.2 yamt */
308 1.2.4.2 yamt if (kauth_authorize_generic(kauth_cred_get(), KAUTH_GENERIC_ISSUSER,
309 1.2.4.2 yamt NULL) != 0) {
310 1.2.4.2 yamt aprint_normal("%s: mmap() rejected.\n",
311 1.2.4.2 yamt device_xname(sc->sc_dev));
312 1.2.4.2 yamt return -1;
313 1.2.4.2 yamt }
314 1.2.4.2 yamt
315 1.2.4.2 yamt /* let userland map other ranges */
316 1.2.4.2 yamt
317 1.2.4.2 yamt return -1;
318 1.2.4.2 yamt }
319 1.2.4.2 yamt
320 1.2.4.2 yamt static void
321 1.2.4.2 yamt gfb_init_screen(void *cookie, struct vcons_screen *scr,
322 1.2.4.2 yamt int existing, long *defattr)
323 1.2.4.2 yamt {
324 1.2.4.2 yamt struct gfb_softc *sc = cookie;
325 1.2.4.2 yamt struct rasops_info *ri = &scr->scr_ri;
326 1.2.4.2 yamt
327 1.2.4.2 yamt ri->ri_depth = sc->sc_depth;
328 1.2.4.2 yamt ri->ri_width = sc->sc_width;
329 1.2.4.2 yamt ri->ri_height = sc->sc_height;
330 1.2.4.2 yamt ri->ri_stride = sc->sc_stride;
331 1.2.4.2 yamt ri->ri_flg = RI_CENTER | RI_FULLCLEAR;
332 1.2.4.2 yamt
333 1.2.4.2 yamt ri->ri_bits = sc->sc_shadow;
334 1.2.4.2 yamt ri->ri_hwbits = (char *)sc->sc_fbaddr;
335 1.2.4.2 yamt
336 1.2.4.2 yamt if (existing) {
337 1.2.4.2 yamt ri->ri_flg |= RI_CLEAR;
338 1.2.4.2 yamt }
339 1.2.4.2 yamt
340 1.2.4.2 yamt rasops_init(ri, sc->sc_height / 8, sc->sc_width / 8);
341 1.2.4.2 yamt ri->ri_caps = WSSCREEN_WSCOLORS;
342 1.2.4.2 yamt
343 1.2.4.2 yamt rasops_reconfig(ri, sc->sc_height / ri->ri_font->fontheight,
344 1.2.4.2 yamt sc->sc_width / ri->ri_font->fontwidth);
345 1.2.4.2 yamt
346 1.2.4.2 yamt ri->ri_hw = scr;
347 1.2.4.2 yamt #if 0
348 1.2.4.2 yamt ri->ri_ops.copyrows = gfb_copyrows;
349 1.2.4.2 yamt ri->ri_ops.copycols = gfb_copycols;
350 1.2.4.2 yamt ri->ri_ops.cursor = gfb_cursor;
351 1.2.4.2 yamt ri->ri_ops.eraserows = gfb_eraserows;
352 1.2.4.2 yamt ri->ri_ops.erasecols = gfb_erasecols;
353 1.2.4.2 yamt ri->ri_ops.putchar = gfb_putchar;
354 1.2.4.2 yamt #endif
355 1.2.4.2 yamt }
356 1.2.4.2 yamt
357 1.2.4.2 yamt static int
358 1.2.4.2 yamt gfb_putcmap(struct gfb_softc *sc, struct wsdisplay_cmap *cm)
359 1.2.4.2 yamt {
360 1.2.4.2 yamt u_char *r, *g, *b;
361 1.2.4.2 yamt u_int index = cm->index;
362 1.2.4.2 yamt u_int count = cm->count;
363 1.2.4.2 yamt int i, error;
364 1.2.4.2 yamt u_char rbuf[256], gbuf[256], bbuf[256];
365 1.2.4.2 yamt
366 1.2.4.2 yamt #ifdef GFB_DEBUG
367 1.2.4.2 yamt aprint_debug("putcmap: %d %d\n",index, count);
368 1.2.4.2 yamt #endif
369 1.2.4.2 yamt if (cm->index >= 256 || cm->count > 256 ||
370 1.2.4.2 yamt (cm->index + cm->count) > 256)
371 1.2.4.2 yamt return EINVAL;
372 1.2.4.2 yamt error = copyin(cm->red, &rbuf[index], count);
373 1.2.4.2 yamt if (error)
374 1.2.4.2 yamt return error;
375 1.2.4.2 yamt error = copyin(cm->green, &gbuf[index], count);
376 1.2.4.2 yamt if (error)
377 1.2.4.2 yamt return error;
378 1.2.4.2 yamt error = copyin(cm->blue, &bbuf[index], count);
379 1.2.4.2 yamt if (error)
380 1.2.4.2 yamt return error;
381 1.2.4.2 yamt
382 1.2.4.2 yamt memcpy(&sc->sc_cmap_red[index], &rbuf[index], count);
383 1.2.4.2 yamt memcpy(&sc->sc_cmap_green[index], &gbuf[index], count);
384 1.2.4.2 yamt memcpy(&sc->sc_cmap_blue[index], &bbuf[index], count);
385 1.2.4.2 yamt
386 1.2.4.2 yamt r = &sc->sc_cmap_red[index];
387 1.2.4.2 yamt g = &sc->sc_cmap_green[index];
388 1.2.4.2 yamt b = &sc->sc_cmap_blue[index];
389 1.2.4.2 yamt
390 1.2.4.2 yamt for (i = 0; i < count; i++) {
391 1.2.4.2 yamt gfb_putpalreg(sc, index, *r, *g, *b);
392 1.2.4.2 yamt index++;
393 1.2.4.2 yamt r++, g++, b++;
394 1.2.4.2 yamt }
395 1.2.4.2 yamt return 0;
396 1.2.4.2 yamt }
397 1.2.4.2 yamt
398 1.2.4.2 yamt static int
399 1.2.4.2 yamt gfb_getcmap(struct gfb_softc *sc, struct wsdisplay_cmap *cm)
400 1.2.4.2 yamt {
401 1.2.4.2 yamt u_int index = cm->index;
402 1.2.4.2 yamt u_int count = cm->count;
403 1.2.4.2 yamt int error;
404 1.2.4.2 yamt
405 1.2.4.2 yamt if (index >= 255 || count > 256 || index + count > 256)
406 1.2.4.2 yamt return EINVAL;
407 1.2.4.2 yamt
408 1.2.4.2 yamt error = copyout(&sc->sc_cmap_red[index], cm->red, count);
409 1.2.4.2 yamt if (error)
410 1.2.4.2 yamt return error;
411 1.2.4.2 yamt error = copyout(&sc->sc_cmap_green[index], cm->green, count);
412 1.2.4.2 yamt if (error)
413 1.2.4.2 yamt return error;
414 1.2.4.2 yamt error = copyout(&sc->sc_cmap_blue[index], cm->blue, count);
415 1.2.4.2 yamt if (error)
416 1.2.4.2 yamt return error;
417 1.2.4.2 yamt
418 1.2.4.2 yamt return 0;
419 1.2.4.2 yamt }
420 1.2.4.2 yamt
421 1.2.4.2 yamt static void
422 1.2.4.2 yamt gfb_restore_palette(struct gfb_softc *sc)
423 1.2.4.2 yamt {
424 1.2.4.2 yamt int i;
425 1.2.4.2 yamt
426 1.2.4.2 yamt for (i = 0; i < (1 << sc->sc_depth); i++) {
427 1.2.4.2 yamt gfb_putpalreg(sc, i, sc->sc_cmap_red[i],
428 1.2.4.2 yamt sc->sc_cmap_green[i], sc->sc_cmap_blue[i]);
429 1.2.4.2 yamt }
430 1.2.4.2 yamt }
431 1.2.4.2 yamt
432 1.2.4.2 yamt static int
433 1.2.4.2 yamt gfb_putpalreg(struct gfb_softc *sc, uint8_t idx, uint8_t r, uint8_t g,
434 1.2.4.2 yamt uint8_t b)
435 1.2.4.2 yamt {
436 1.2.4.2 yamt return 0;
437 1.2.4.2 yamt }
438