gfb.c revision 1.2.4.3 1 1.2.4.3 yamt /* $NetBSD: gfb.c,v 1.2.4.3 2010/10/09 03:31:54 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.3 yamt __KERNEL_RCSID(0, "$NetBSD: gfb.c,v 1.2.4.3 2010/10/09 03:31:54 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.3 yamt void *sc_fbaddr;
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_locked = 0;
162 1.2.4.2 yamt sc->sc_mode = WSDISPLAYIO_MODE_EMUL;
163 1.2.4.2 yamt
164 1.2.4.2 yamt if (bus_space_map(sc->sc_memt, ma->ma_reg[6].ur_paddr,
165 1.2.4.2 yamt sc->sc_fblen, BUS_SPACE_MAP_LINEAR, &sc->sc_fbh)) {
166 1.2.4.2 yamt printf(": failed to map the framebuffer\n");
167 1.2.4.2 yamt return;
168 1.2.4.2 yamt }
169 1.2.4.2 yamt sc->sc_fbaddr = bus_space_vaddr(sc->sc_memt, sc->sc_fbh);
170 1.2.4.2 yamt sc->sc_fb_paddr = ma->ma_reg[6].ur_paddr;
171 1.2.4.2 yamt
172 1.2.4.2 yamt sc->sc_defaultscreen_descr = (struct wsscreen_descr){
173 1.2.4.2 yamt "default",
174 1.2.4.2 yamt 0, 0,
175 1.2.4.2 yamt NULL,
176 1.2.4.2 yamt 8, 16,
177 1.2.4.2 yamt WSSCREEN_WSCOLORS | WSSCREEN_HILIT,
178 1.2.4.2 yamt NULL
179 1.2.4.2 yamt };
180 1.2.4.2 yamt sc->sc_screens[0] = &sc->sc_defaultscreen_descr;
181 1.2.4.2 yamt sc->sc_screenlist = (struct wsscreen_list){1, sc->sc_screens};
182 1.2.4.2 yamt sc->sc_mode = WSDISPLAYIO_MODE_EMUL;
183 1.2.4.2 yamt sc->sc_locked = 0;
184 1.2.4.2 yamt
185 1.2.4.2 yamt vcons_init(&sc->vd, sc, &sc->sc_defaultscreen_descr,
186 1.2.4.2 yamt &gfb_accessops);
187 1.2.4.2 yamt sc->vd.init_screen = gfb_init_screen;
188 1.2.4.2 yamt
189 1.2.4.2 yamt ri = &sc->sc_console_screen.scr_ri;
190 1.2.4.2 yamt
191 1.2.4.2 yamt j = 0;
192 1.2.4.2 yamt for (i = 0; i < (1 << sc->sc_depth); i++) {
193 1.2.4.2 yamt
194 1.2.4.2 yamt sc->sc_cmap_red[i] = rasops_cmap[j];
195 1.2.4.2 yamt sc->sc_cmap_green[i] = rasops_cmap[j + 1];
196 1.2.4.2 yamt sc->sc_cmap_blue[i] = rasops_cmap[j + 2];
197 1.2.4.2 yamt gfb_putpalreg(sc, i, rasops_cmap[j], rasops_cmap[j + 1],
198 1.2.4.2 yamt rasops_cmap[j + 2]);
199 1.2.4.2 yamt j += 3;
200 1.2.4.2 yamt }
201 1.2.4.2 yamt
202 1.2.4.2 yamt if (is_console) {
203 1.2.4.2 yamt vcons_init_screen(&sc->vd, &sc->sc_console_screen, 1,
204 1.2.4.2 yamt &defattr);
205 1.2.4.2 yamt sc->sc_console_screen.scr_flags |= VCONS_SCREEN_IS_STATIC;
206 1.2.4.2 yamt
207 1.2.4.2 yamt #if notyet
208 1.2.4.2 yamt gfb_rectfill(sc, 0, 0, sc->sc_width, sc->sc_height,
209 1.2.4.2 yamt ri->ri_devcmap[(defattr >> 16) & 0xff]);
210 1.2.4.2 yamt #endif
211 1.2.4.2 yamt sc->sc_defaultscreen_descr.textops = &ri->ri_ops;
212 1.2.4.2 yamt sc->sc_defaultscreen_descr.capabilities = ri->ri_caps;
213 1.2.4.2 yamt sc->sc_defaultscreen_descr.nrows = ri->ri_rows;
214 1.2.4.2 yamt sc->sc_defaultscreen_descr.ncols = ri->ri_cols;
215 1.2.4.2 yamt wsdisplay_cnattach(&sc->sc_defaultscreen_descr, ri, 0, 0,
216 1.2.4.2 yamt defattr);
217 1.2.4.2 yamt vcons_replay_msgbuf(&sc->sc_console_screen);
218 1.2.4.2 yamt } else {
219 1.2.4.2 yamt /*
220 1.2.4.2 yamt * since we're not the console we can postpone the rest
221 1.2.4.2 yamt * until someone actually allocates a screen for us
222 1.2.4.2 yamt */
223 1.2.4.2 yamt (*ri->ri_ops.allocattr)(ri, 0, 0, 0, &defattr);
224 1.2.4.2 yamt }
225 1.2.4.2 yamt
226 1.2.4.2 yamt aa.console = is_console;
227 1.2.4.2 yamt aa.scrdata = &sc->sc_screenlist;
228 1.2.4.2 yamt aa.accessops = &gfb_accessops;
229 1.2.4.2 yamt aa.accesscookie = &sc->vd;
230 1.2.4.2 yamt
231 1.2.4.2 yamt config_found(sc->sc_dev, &aa, wsemuldisplaydevprint);
232 1.2.4.3 yamt
233 1.2.4.3 yamt #ifdef GFB_DEBUG
234 1.2.4.3 yamt /*
235 1.2.4.3 yamt * now dump a register range
236 1.2.4.3 yamt * try 1, 2 and 4 since they're only 0x2000 each
237 1.2.4.3 yamt */
238 1.2.4.3 yamt bus_space_handle_t regh;
239 1.2.4.3 yamt
240 1.2.4.3 yamt if (bus_space_map(sc->sc_memt, ma->ma_reg[3].ur_paddr,
241 1.2.4.3 yamt 0x2000, BUS_SPACE_MAP_LINEAR, ®h) == 0) {
242 1.2.4.3 yamt for (i = 0; i < 0x200; i += 32) {
243 1.2.4.3 yamt printf("%04x", i);
244 1.2.4.3 yamt for (j = 0; j < 32; j += 4) {
245 1.2.4.3 yamt printf(" %08x", bus_space_read_4(sc->sc_memt,
246 1.2.4.3 yamt regh, i + j));
247 1.2.4.3 yamt }
248 1.2.4.3 yamt printf("\n");
249 1.2.4.3 yamt }
250 1.2.4.3 yamt bus_space_unmap(sc->sc_memt, regh, 0x2000);
251 1.2.4.3 yamt }
252 1.2.4.3 yamt #endif
253 1.2.4.2 yamt }
254 1.2.4.2 yamt
255 1.2.4.2 yamt static int
256 1.2.4.2 yamt gfb_ioctl(void *v, void *vs, u_long cmd, void *data, int flag,
257 1.2.4.2 yamt struct lwp *l)
258 1.2.4.2 yamt {
259 1.2.4.2 yamt struct vcons_data *vd = v;
260 1.2.4.2 yamt struct gfb_softc *sc = vd->cookie;
261 1.2.4.2 yamt struct wsdisplay_fbinfo *wdf;
262 1.2.4.2 yamt struct vcons_screen *ms = vd->active;
263 1.2.4.2 yamt
264 1.2.4.2 yamt switch (cmd) {
265 1.2.4.2 yamt
266 1.2.4.2 yamt case WSDISPLAYIO_GTYPE:
267 1.2.4.2 yamt *(u_int *)data = WSDISPLAY_TYPE_XVR1000;
268 1.2.4.2 yamt return 0;
269 1.2.4.2 yamt
270 1.2.4.2 yamt case WSDISPLAYIO_GINFO:
271 1.2.4.2 yamt if (ms == NULL)
272 1.2.4.2 yamt return ENODEV;
273 1.2.4.2 yamt wdf = (void *)data;
274 1.2.4.2 yamt wdf->height = ms->scr_ri.ri_height;
275 1.2.4.2 yamt wdf->width = ms->scr_ri.ri_width;
276 1.2.4.2 yamt wdf->depth = ms->scr_ri.ri_depth;
277 1.2.4.2 yamt wdf->cmsize = 256;
278 1.2.4.2 yamt return 0;
279 1.2.4.2 yamt
280 1.2.4.2 yamt case WSDISPLAYIO_GETCMAP:
281 1.2.4.2 yamt return gfb_getcmap(sc,
282 1.2.4.2 yamt (struct wsdisplay_cmap *)data);
283 1.2.4.2 yamt
284 1.2.4.2 yamt case WSDISPLAYIO_PUTCMAP:
285 1.2.4.2 yamt return gfb_putcmap(sc,
286 1.2.4.2 yamt (struct wsdisplay_cmap *)data);
287 1.2.4.2 yamt
288 1.2.4.2 yamt case WSDISPLAYIO_LINEBYTES:
289 1.2.4.2 yamt *(u_int *)data = sc->sc_stride;
290 1.2.4.2 yamt return 0;
291 1.2.4.2 yamt
292 1.2.4.2 yamt case WSDISPLAYIO_SMODE:
293 1.2.4.2 yamt {
294 1.2.4.2 yamt int new_mode = *(int*)data;
295 1.2.4.2 yamt
296 1.2.4.2 yamt /* notify the bus backend */
297 1.2.4.2 yamt if (new_mode != sc->sc_mode) {
298 1.2.4.2 yamt sc->sc_mode = new_mode;
299 1.2.4.2 yamt if(new_mode == WSDISPLAYIO_MODE_EMUL) {
300 1.2.4.2 yamt gfb_restore_palette(sc);
301 1.2.4.2 yamt vcons_redraw_screen(ms);
302 1.2.4.2 yamt }
303 1.2.4.2 yamt }
304 1.2.4.2 yamt }
305 1.2.4.2 yamt return 0;
306 1.2.4.2 yamt }
307 1.2.4.2 yamt return EPASSTHROUGH;
308 1.2.4.2 yamt }
309 1.2.4.2 yamt
310 1.2.4.2 yamt static paddr_t
311 1.2.4.2 yamt gfb_mmap(void *v, void *vs, off_t offset, int prot)
312 1.2.4.2 yamt {
313 1.2.4.2 yamt struct vcons_data *vd = v;
314 1.2.4.2 yamt struct gfb_softc *sc = vd->cookie;
315 1.2.4.2 yamt paddr_t pa;
316 1.2.4.2 yamt
317 1.2.4.2 yamt /* 'regular' framebuffer mmap()ing */
318 1.2.4.2 yamt if (offset < sc->sc_fblen) {
319 1.2.4.2 yamt pa = bus_space_mmap(sc->sc_memt, sc->sc_fb_paddr + offset, 0,
320 1.2.4.2 yamt prot, BUS_SPACE_MAP_LINEAR);
321 1.2.4.2 yamt return pa;
322 1.2.4.2 yamt }
323 1.2.4.2 yamt
324 1.2.4.2 yamt /*
325 1.2.4.2 yamt * restrict all other mappings to processes with superuser privileges
326 1.2.4.2 yamt * or the kernel itself
327 1.2.4.2 yamt */
328 1.2.4.2 yamt if (kauth_authorize_generic(kauth_cred_get(), KAUTH_GENERIC_ISSUSER,
329 1.2.4.2 yamt NULL) != 0) {
330 1.2.4.2 yamt aprint_normal("%s: mmap() rejected.\n",
331 1.2.4.2 yamt device_xname(sc->sc_dev));
332 1.2.4.2 yamt return -1;
333 1.2.4.2 yamt }
334 1.2.4.2 yamt
335 1.2.4.2 yamt /* let userland map other ranges */
336 1.2.4.2 yamt
337 1.2.4.2 yamt return -1;
338 1.2.4.2 yamt }
339 1.2.4.2 yamt
340 1.2.4.2 yamt static void
341 1.2.4.2 yamt gfb_init_screen(void *cookie, struct vcons_screen *scr,
342 1.2.4.2 yamt int existing, long *defattr)
343 1.2.4.2 yamt {
344 1.2.4.2 yamt struct gfb_softc *sc = cookie;
345 1.2.4.2 yamt struct rasops_info *ri = &scr->scr_ri;
346 1.2.4.2 yamt
347 1.2.4.2 yamt ri->ri_depth = sc->sc_depth;
348 1.2.4.2 yamt ri->ri_width = sc->sc_width;
349 1.2.4.2 yamt ri->ri_height = sc->sc_height;
350 1.2.4.2 yamt ri->ri_stride = sc->sc_stride;
351 1.2.4.2 yamt ri->ri_flg = RI_CENTER | RI_FULLCLEAR;
352 1.2.4.2 yamt
353 1.2.4.3 yamt ri->ri_bits = (char *)sc->sc_fbaddr;
354 1.2.4.3 yamt scr->scr_flags |= VCONS_DONT_READ;
355 1.2.4.2 yamt
356 1.2.4.2 yamt if (existing) {
357 1.2.4.2 yamt ri->ri_flg |= RI_CLEAR;
358 1.2.4.2 yamt }
359 1.2.4.2 yamt
360 1.2.4.2 yamt rasops_init(ri, sc->sc_height / 8, sc->sc_width / 8);
361 1.2.4.2 yamt ri->ri_caps = WSSCREEN_WSCOLORS;
362 1.2.4.2 yamt
363 1.2.4.2 yamt rasops_reconfig(ri, sc->sc_height / ri->ri_font->fontheight,
364 1.2.4.2 yamt sc->sc_width / ri->ri_font->fontwidth);
365 1.2.4.2 yamt
366 1.2.4.2 yamt ri->ri_hw = scr;
367 1.2.4.2 yamt #if 0
368 1.2.4.2 yamt ri->ri_ops.copyrows = gfb_copyrows;
369 1.2.4.2 yamt ri->ri_ops.copycols = gfb_copycols;
370 1.2.4.2 yamt ri->ri_ops.cursor = gfb_cursor;
371 1.2.4.2 yamt ri->ri_ops.eraserows = gfb_eraserows;
372 1.2.4.2 yamt ri->ri_ops.erasecols = gfb_erasecols;
373 1.2.4.2 yamt ri->ri_ops.putchar = gfb_putchar;
374 1.2.4.2 yamt #endif
375 1.2.4.2 yamt }
376 1.2.4.2 yamt
377 1.2.4.2 yamt static int
378 1.2.4.2 yamt gfb_putcmap(struct gfb_softc *sc, struct wsdisplay_cmap *cm)
379 1.2.4.2 yamt {
380 1.2.4.2 yamt u_char *r, *g, *b;
381 1.2.4.2 yamt u_int index = cm->index;
382 1.2.4.2 yamt u_int count = cm->count;
383 1.2.4.2 yamt int i, error;
384 1.2.4.2 yamt u_char rbuf[256], gbuf[256], bbuf[256];
385 1.2.4.2 yamt
386 1.2.4.2 yamt #ifdef GFB_DEBUG
387 1.2.4.2 yamt aprint_debug("putcmap: %d %d\n",index, count);
388 1.2.4.2 yamt #endif
389 1.2.4.2 yamt if (cm->index >= 256 || cm->count > 256 ||
390 1.2.4.2 yamt (cm->index + cm->count) > 256)
391 1.2.4.2 yamt return EINVAL;
392 1.2.4.2 yamt error = copyin(cm->red, &rbuf[index], count);
393 1.2.4.2 yamt if (error)
394 1.2.4.2 yamt return error;
395 1.2.4.2 yamt error = copyin(cm->green, &gbuf[index], count);
396 1.2.4.2 yamt if (error)
397 1.2.4.2 yamt return error;
398 1.2.4.2 yamt error = copyin(cm->blue, &bbuf[index], count);
399 1.2.4.2 yamt if (error)
400 1.2.4.2 yamt return error;
401 1.2.4.2 yamt
402 1.2.4.2 yamt memcpy(&sc->sc_cmap_red[index], &rbuf[index], count);
403 1.2.4.2 yamt memcpy(&sc->sc_cmap_green[index], &gbuf[index], count);
404 1.2.4.2 yamt memcpy(&sc->sc_cmap_blue[index], &bbuf[index], count);
405 1.2.4.2 yamt
406 1.2.4.2 yamt r = &sc->sc_cmap_red[index];
407 1.2.4.2 yamt g = &sc->sc_cmap_green[index];
408 1.2.4.2 yamt b = &sc->sc_cmap_blue[index];
409 1.2.4.2 yamt
410 1.2.4.2 yamt for (i = 0; i < count; i++) {
411 1.2.4.2 yamt gfb_putpalreg(sc, index, *r, *g, *b);
412 1.2.4.2 yamt index++;
413 1.2.4.2 yamt r++, g++, b++;
414 1.2.4.2 yamt }
415 1.2.4.2 yamt return 0;
416 1.2.4.2 yamt }
417 1.2.4.2 yamt
418 1.2.4.2 yamt static int
419 1.2.4.2 yamt gfb_getcmap(struct gfb_softc *sc, struct wsdisplay_cmap *cm)
420 1.2.4.2 yamt {
421 1.2.4.2 yamt u_int index = cm->index;
422 1.2.4.2 yamt u_int count = cm->count;
423 1.2.4.2 yamt int error;
424 1.2.4.2 yamt
425 1.2.4.2 yamt if (index >= 255 || count > 256 || index + count > 256)
426 1.2.4.2 yamt return EINVAL;
427 1.2.4.2 yamt
428 1.2.4.2 yamt error = copyout(&sc->sc_cmap_red[index], cm->red, count);
429 1.2.4.2 yamt if (error)
430 1.2.4.2 yamt return error;
431 1.2.4.2 yamt error = copyout(&sc->sc_cmap_green[index], cm->green, count);
432 1.2.4.2 yamt if (error)
433 1.2.4.2 yamt return error;
434 1.2.4.2 yamt error = copyout(&sc->sc_cmap_blue[index], cm->blue, count);
435 1.2.4.2 yamt if (error)
436 1.2.4.2 yamt return error;
437 1.2.4.2 yamt
438 1.2.4.2 yamt return 0;
439 1.2.4.2 yamt }
440 1.2.4.2 yamt
441 1.2.4.2 yamt static void
442 1.2.4.2 yamt gfb_restore_palette(struct gfb_softc *sc)
443 1.2.4.2 yamt {
444 1.2.4.2 yamt int i;
445 1.2.4.2 yamt
446 1.2.4.2 yamt for (i = 0; i < (1 << sc->sc_depth); i++) {
447 1.2.4.2 yamt gfb_putpalreg(sc, i, sc->sc_cmap_red[i],
448 1.2.4.2 yamt sc->sc_cmap_green[i], sc->sc_cmap_blue[i]);
449 1.2.4.2 yamt }
450 1.2.4.2 yamt }
451 1.2.4.2 yamt
452 1.2.4.2 yamt static int
453 1.2.4.2 yamt gfb_putpalreg(struct gfb_softc *sc, uint8_t idx, uint8_t r, uint8_t g,
454 1.2.4.2 yamt uint8_t b)
455 1.2.4.2 yamt {
456 1.2.4.2 yamt return 0;
457 1.2.4.2 yamt }
458