xafb.c revision 1.1.2.2 1 1.1.2.2 bouyer /* $NetBSD: xafb.c,v 1.1.2.2 2000/11/22 16:01:06 bouyer Exp $ */
2 1.1.2.2 bouyer
3 1.1.2.2 bouyer /*-
4 1.1.2.2 bouyer * Copyright (c) 2000 Tsubai Masanari. All rights reserved.
5 1.1.2.2 bouyer *
6 1.1.2.2 bouyer * Redistribution and use in source and binary forms, with or without
7 1.1.2.2 bouyer * modification, are permitted provided that the following conditions
8 1.1.2.2 bouyer * are met:
9 1.1.2.2 bouyer * 1. Redistributions of source code must retain the above copyright
10 1.1.2.2 bouyer * notice, this list of conditions and the following disclaimer.
11 1.1.2.2 bouyer * 2. Redistributions in binary form must reproduce the above copyright
12 1.1.2.2 bouyer * notice, this list of conditions and the following disclaimer in the
13 1.1.2.2 bouyer * documentation and/or other materials provided with the distribution.
14 1.1.2.2 bouyer * 3. The name of the author may not be used to endorse or promote products
15 1.1.2.2 bouyer * derived from this software without specific prior written permission.
16 1.1.2.2 bouyer *
17 1.1.2.2 bouyer * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
18 1.1.2.2 bouyer * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19 1.1.2.2 bouyer * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20 1.1.2.2 bouyer * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21 1.1.2.2 bouyer * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22 1.1.2.2 bouyer * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 1.1.2.2 bouyer * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 1.1.2.2 bouyer * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 1.1.2.2 bouyer * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26 1.1.2.2 bouyer * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 1.1.2.2 bouyer */
28 1.1.2.2 bouyer
29 1.1.2.2 bouyer /* "xa" frame buffer driver. Currently supports 1280x1024x8 only. */
30 1.1.2.2 bouyer
31 1.1.2.2 bouyer #include <sys/param.h>
32 1.1.2.2 bouyer #include <sys/buf.h>
33 1.1.2.2 bouyer #include <sys/device.h>
34 1.1.2.2 bouyer #include <sys/ioctl.h>
35 1.1.2.2 bouyer #include <sys/malloc.h>
36 1.1.2.2 bouyer #include <sys/systm.h>
37 1.1.2.2 bouyer
38 1.1.2.2 bouyer #include <uvm/uvm_extern.h>
39 1.1.2.2 bouyer
40 1.1.2.2 bouyer #include <machine/adrsmap.h>
41 1.1.2.2 bouyer #include <machine/apcall.h>
42 1.1.2.2 bouyer
43 1.1.2.2 bouyer #include <dev/wscons/wsconsio.h>
44 1.1.2.2 bouyer #include <dev/wscons/wsdisplayvar.h>
45 1.1.2.2 bouyer #include <dev/rasops/rasops.h>
46 1.1.2.2 bouyer
47 1.1.2.2 bouyer #include <newsmips/apbus/apbusvar.h>
48 1.1.2.2 bouyer
49 1.1.2.2 bouyer struct xafb_reg {
50 1.1.2.2 bouyer volatile u_int r0;
51 1.1.2.2 bouyer volatile u_int index;
52 1.1.2.2 bouyer volatile u_int r2;
53 1.1.2.2 bouyer volatile u_int zero;
54 1.1.2.2 bouyer volatile u_int r4;
55 1.1.2.2 bouyer volatile u_int r5;
56 1.1.2.2 bouyer volatile u_int r6;
57 1.1.2.2 bouyer volatile u_int rgb;
58 1.1.2.2 bouyer };
59 1.1.2.2 bouyer
60 1.1.2.2 bouyer struct xafb_devconfig {
61 1.1.2.2 bouyer volatile u_char *dc_fbbase; /* VRAM base address */
62 1.1.2.2 bouyer struct xafb_reg *dc_reg; /* register address */
63 1.1.2.2 bouyer struct rasops_info dc_ri;
64 1.1.2.2 bouyer };
65 1.1.2.2 bouyer
66 1.1.2.2 bouyer struct xafb_softc {
67 1.1.2.2 bouyer struct device sc_dev;
68 1.1.2.2 bouyer struct xafb_devconfig *sc_dc;
69 1.1.2.2 bouyer int sc_nscreens;
70 1.1.2.2 bouyer u_char sc_cmap_red[256];
71 1.1.2.2 bouyer u_char sc_cmap_green[256];
72 1.1.2.2 bouyer u_char sc_cmap_blue[256];
73 1.1.2.2 bouyer };
74 1.1.2.2 bouyer
75 1.1.2.2 bouyer int xafb_match __P((struct device *, struct cfdata *, void *));
76 1.1.2.2 bouyer void xafb_attach __P((struct device *, struct device *, void *));
77 1.1.2.2 bouyer
78 1.1.2.2 bouyer int xafb_common_init __P((struct xafb_devconfig *));
79 1.1.2.2 bouyer int xafb_is_console __P((void));
80 1.1.2.2 bouyer
81 1.1.2.2 bouyer int xafb_ioctl __P((void *, u_long, caddr_t, int, struct proc *));
82 1.1.2.2 bouyer paddr_t xafb_mmap __P((void *, off_t, int));
83 1.1.2.2 bouyer int xafb_alloc_screen __P((void *, const struct wsscreen_descr *,
84 1.1.2.2 bouyer void **, int *, int *, long *));
85 1.1.2.2 bouyer void xafb_free_screen __P((void *, void *));
86 1.1.2.2 bouyer int xafb_show_screen __P((void *, void *, int,
87 1.1.2.2 bouyer void (*) (void *, int, int), void *));
88 1.1.2.2 bouyer
89 1.1.2.2 bouyer int xafb_cnattach __P((void));
90 1.1.2.2 bouyer int xafb_getcmap __P((struct xafb_softc *, struct wsdisplay_cmap *));
91 1.1.2.2 bouyer int xafb_putcmap __P((struct xafb_softc *, struct wsdisplay_cmap *));
92 1.1.2.2 bouyer
93 1.1.2.2 bouyer static __inline void xafb_setcolor(struct xafb_devconfig *, int, int, int, int);
94 1.1.2.2 bouyer
95 1.1.2.2 bouyer struct cfattach xafb_ca = {
96 1.1.2.2 bouyer sizeof(struct xafb_softc), xafb_match, xafb_attach,
97 1.1.2.2 bouyer };
98 1.1.2.2 bouyer
99 1.1.2.2 bouyer struct xafb_devconfig xafb_console_dc;
100 1.1.2.2 bouyer
101 1.1.2.2 bouyer struct wsdisplay_accessops xafb_accessops = {
102 1.1.2.2 bouyer xafb_ioctl,
103 1.1.2.2 bouyer xafb_mmap,
104 1.1.2.2 bouyer xafb_alloc_screen,
105 1.1.2.2 bouyer xafb_free_screen,
106 1.1.2.2 bouyer xafb_show_screen,
107 1.1.2.2 bouyer NULL /* load_font */
108 1.1.2.2 bouyer };
109 1.1.2.2 bouyer
110 1.1.2.2 bouyer struct wsscreen_descr xafb_stdscreen = {
111 1.1.2.2 bouyer "std",
112 1.1.2.2 bouyer 0, 0,
113 1.1.2.2 bouyer 0,
114 1.1.2.2 bouyer 0, 0,
115 1.1.2.2 bouyer WSSCREEN_REVERSE
116 1.1.2.2 bouyer };
117 1.1.2.2 bouyer
118 1.1.2.2 bouyer const struct wsscreen_descr *xafb_scrlist[] = {
119 1.1.2.2 bouyer &xafb_stdscreen
120 1.1.2.2 bouyer };
121 1.1.2.2 bouyer
122 1.1.2.2 bouyer struct wsscreen_list xafb_screenlist = {
123 1.1.2.2 bouyer sizeof(xafb_scrlist) / sizeof(xafb_scrlist[0]), xafb_scrlist
124 1.1.2.2 bouyer };
125 1.1.2.2 bouyer
126 1.1.2.2 bouyer int
127 1.1.2.2 bouyer xafb_match(parent, match, aux)
128 1.1.2.2 bouyer struct device *parent;
129 1.1.2.2 bouyer struct cfdata *match;
130 1.1.2.2 bouyer void *aux;
131 1.1.2.2 bouyer {
132 1.1.2.2 bouyer struct apbus_attach_args *apa = aux;
133 1.1.2.2 bouyer
134 1.1.2.2 bouyer if (strcmp(apa->apa_name, "xa") != 0)
135 1.1.2.2 bouyer return 0;
136 1.1.2.2 bouyer
137 1.1.2.2 bouyer return 1;
138 1.1.2.2 bouyer }
139 1.1.2.2 bouyer
140 1.1.2.2 bouyer void
141 1.1.2.2 bouyer xafb_attach(parent, self, aux)
142 1.1.2.2 bouyer struct device *parent, *self;
143 1.1.2.2 bouyer void *aux;
144 1.1.2.2 bouyer {
145 1.1.2.2 bouyer struct xafb_softc *sc = (void *)self;
146 1.1.2.2 bouyer struct apbus_attach_args *apa = aux;
147 1.1.2.2 bouyer struct wsemuldisplaydev_attach_args wsa;
148 1.1.2.2 bouyer struct xafb_devconfig *dc;
149 1.1.2.2 bouyer struct rasops_info *ri;
150 1.1.2.2 bouyer int console, i;
151 1.1.2.2 bouyer
152 1.1.2.2 bouyer console = xafb_is_console();
153 1.1.2.2 bouyer
154 1.1.2.2 bouyer if (console) {
155 1.1.2.2 bouyer dc = &xafb_console_dc;
156 1.1.2.2 bouyer ri = &dc->dc_ri;
157 1.1.2.2 bouyer sc->sc_nscreens = 1;
158 1.1.2.2 bouyer } else {
159 1.1.2.2 bouyer dc = malloc(sizeof(struct xafb_devconfig), M_DEVBUF, M_WAITOK);
160 1.1.2.2 bouyer bzero(dc, sizeof(struct xafb_devconfig));
161 1.1.2.2 bouyer
162 1.1.2.2 bouyer dc->dc_fbbase = (void *)0xb0000000; /* XXX */
163 1.1.2.2 bouyer dc->dc_reg = (void *)(apa->apa_hwbase + 0x3000);
164 1.1.2.2 bouyer if (xafb_common_init(dc) != 0) {
165 1.1.2.2 bouyer printf(": couldn't initialize device\n");
166 1.1.2.2 bouyer return;
167 1.1.2.2 bouyer }
168 1.1.2.2 bouyer
169 1.1.2.2 bouyer ri = &dc->dc_ri;
170 1.1.2.2 bouyer
171 1.1.2.2 bouyer /* clear screen */
172 1.1.2.2 bouyer (*ri->ri_ops.eraserows)(ri, 0, ri->ri_rows, 0);
173 1.1.2.2 bouyer }
174 1.1.2.2 bouyer sc->sc_dc = dc;
175 1.1.2.2 bouyer
176 1.1.2.2 bouyer for (i = 0; i < 256; i++) {
177 1.1.2.2 bouyer sc->sc_cmap_red[i] = i;
178 1.1.2.2 bouyer sc->sc_cmap_green[i] = i;
179 1.1.2.2 bouyer sc->sc_cmap_blue[i] = i;
180 1.1.2.2 bouyer }
181 1.1.2.2 bouyer
182 1.1.2.2 bouyer printf(": %d x %d, %dbpp\n", ri->ri_width, ri->ri_height, ri->ri_depth);
183 1.1.2.2 bouyer
184 1.1.2.2 bouyer wsa.console = console;
185 1.1.2.2 bouyer wsa.scrdata = &xafb_screenlist;
186 1.1.2.2 bouyer wsa.accessops = &xafb_accessops;
187 1.1.2.2 bouyer wsa.accesscookie = sc;
188 1.1.2.2 bouyer
189 1.1.2.2 bouyer config_found(self, &wsa, wsemuldisplaydevprint);
190 1.1.2.2 bouyer }
191 1.1.2.2 bouyer
192 1.1.2.2 bouyer void
193 1.1.2.2 bouyer xafb_setcolor(dc, index, r, g, b)
194 1.1.2.2 bouyer struct xafb_devconfig *dc;
195 1.1.2.2 bouyer int index, r, g, b;
196 1.1.2.2 bouyer {
197 1.1.2.2 bouyer volatile struct xafb_reg *reg = dc->dc_reg;
198 1.1.2.2 bouyer
199 1.1.2.2 bouyer reg->index = index;
200 1.1.2.2 bouyer reg->zero = 0;
201 1.1.2.2 bouyer reg->rgb = r;
202 1.1.2.2 bouyer reg->rgb = g;
203 1.1.2.2 bouyer reg->rgb = b;
204 1.1.2.2 bouyer }
205 1.1.2.2 bouyer
206 1.1.2.2 bouyer int
207 1.1.2.2 bouyer xafb_common_init(dc)
208 1.1.2.2 bouyer struct xafb_devconfig *dc;
209 1.1.2.2 bouyer {
210 1.1.2.2 bouyer struct rasops_info *ri = &dc->dc_ri;
211 1.1.2.2 bouyer int i;
212 1.1.2.2 bouyer
213 1.1.2.2 bouyer for (i = 0; i < 256; i++)
214 1.1.2.2 bouyer xafb_setcolor(dc, i, i, i, i);
215 1.1.2.2 bouyer
216 1.1.2.2 bouyer /* initialize rasops */
217 1.1.2.2 bouyer ri->ri_width = 1280;
218 1.1.2.2 bouyer ri->ri_height = 1024;
219 1.1.2.2 bouyer ri->ri_depth = 8;
220 1.1.2.2 bouyer ri->ri_stride = 2048;
221 1.1.2.2 bouyer ri->ri_bits = (void *)dc->dc_fbbase;
222 1.1.2.2 bouyer ri->ri_flg = RI_FORCEMONO | RI_FULLCLEAR;
223 1.1.2.2 bouyer
224 1.1.2.2 bouyer rasops_init(ri, 44, 100);
225 1.1.2.2 bouyer
226 1.1.2.2 bouyer /* mono */
227 1.1.2.2 bouyer ri->ri_devcmap[0] = 0; /* bg */
228 1.1.2.2 bouyer ri->ri_devcmap[1] = 0xffffffff; /* fg */
229 1.1.2.2 bouyer
230 1.1.2.2 bouyer xafb_stdscreen.nrows = ri->ri_rows;
231 1.1.2.2 bouyer xafb_stdscreen.ncols = ri->ri_cols;
232 1.1.2.2 bouyer xafb_stdscreen.textops = &ri->ri_ops;
233 1.1.2.2 bouyer xafb_stdscreen.capabilities = ri->ri_caps;
234 1.1.2.2 bouyer
235 1.1.2.2 bouyer return 0;
236 1.1.2.2 bouyer }
237 1.1.2.2 bouyer
238 1.1.2.2 bouyer int
239 1.1.2.2 bouyer xafb_is_console()
240 1.1.2.2 bouyer {
241 1.1.2.2 bouyer volatile u_int *dipsw = (void *)NEWS5000_DIP_SWITCH;
242 1.1.2.2 bouyer
243 1.1.2.2 bouyer if (*dipsw & 1) /* XXX right? */
244 1.1.2.2 bouyer return 1;
245 1.1.2.2 bouyer
246 1.1.2.2 bouyer return 0;
247 1.1.2.2 bouyer }
248 1.1.2.2 bouyer
249 1.1.2.2 bouyer int
250 1.1.2.2 bouyer xafb_ioctl(v, cmd, data, flag, p)
251 1.1.2.2 bouyer void *v;
252 1.1.2.2 bouyer u_long cmd;
253 1.1.2.2 bouyer caddr_t data;
254 1.1.2.2 bouyer int flag;
255 1.1.2.2 bouyer struct proc *p;
256 1.1.2.2 bouyer {
257 1.1.2.2 bouyer struct xafb_softc *sc = v;
258 1.1.2.2 bouyer struct xafb_devconfig *dc = sc->sc_dc;
259 1.1.2.2 bouyer struct wsdisplay_fbinfo *wdf;
260 1.1.2.2 bouyer
261 1.1.2.2 bouyer switch (cmd) {
262 1.1.2.2 bouyer case WSDISPLAYIO_GTYPE:
263 1.1.2.2 bouyer *(int *)data = WSDISPLAY_TYPE_UNKNOWN; /* XXX */
264 1.1.2.2 bouyer return 0;
265 1.1.2.2 bouyer
266 1.1.2.2 bouyer case WSDISPLAYIO_GINFO:
267 1.1.2.2 bouyer wdf = (void *)data;
268 1.1.2.2 bouyer wdf->height = dc->dc_ri.ri_height;
269 1.1.2.2 bouyer wdf->width = dc->dc_ri.ri_width;
270 1.1.2.2 bouyer wdf->depth = dc->dc_ri.ri_depth;
271 1.1.2.2 bouyer wdf->cmsize = 256;
272 1.1.2.2 bouyer return 0;
273 1.1.2.2 bouyer
274 1.1.2.2 bouyer case WSDISPLAYIO_GETCMAP:
275 1.1.2.2 bouyer return xafb_getcmap(sc, (struct wsdisplay_cmap *)data);
276 1.1.2.2 bouyer
277 1.1.2.2 bouyer case WSDISPLAYIO_PUTCMAP:
278 1.1.2.2 bouyer return xafb_putcmap(sc, (struct wsdisplay_cmap *)data);
279 1.1.2.2 bouyer
280 1.1.2.2 bouyer /* case WSDISPLAYIO_SVIDEO: */
281 1.1.2.2 bouyer }
282 1.1.2.2 bouyer return -1;
283 1.1.2.2 bouyer }
284 1.1.2.2 bouyer
285 1.1.2.2 bouyer paddr_t
286 1.1.2.2 bouyer xafb_mmap(v, offset, prot)
287 1.1.2.2 bouyer void *v;
288 1.1.2.2 bouyer off_t offset;
289 1.1.2.2 bouyer int prot;
290 1.1.2.2 bouyer {
291 1.1.2.2 bouyer struct xafb_softc *sc = v;
292 1.1.2.2 bouyer struct xafb_devconfig *dc = sc->sc_dc;
293 1.1.2.2 bouyer struct rasops_info *ri = &dc->dc_ri;
294 1.1.2.2 bouyer
295 1.1.2.2 bouyer if (offset >= (ri->ri_stride * ri->ri_height) || offset < 0)
296 1.1.2.2 bouyer return -1;
297 1.1.2.2 bouyer
298 1.1.2.2 bouyer return mips_btop((int)dc->dc_fbbase + offset);
299 1.1.2.2 bouyer }
300 1.1.2.2 bouyer
301 1.1.2.2 bouyer int
302 1.1.2.2 bouyer xafb_alloc_screen(v, scrdesc, cookiep, ccolp, crowp, attrp)
303 1.1.2.2 bouyer void *v;
304 1.1.2.2 bouyer const struct wsscreen_descr *scrdesc;
305 1.1.2.2 bouyer void **cookiep;
306 1.1.2.2 bouyer int *ccolp, *crowp;
307 1.1.2.2 bouyer long *attrp;
308 1.1.2.2 bouyer {
309 1.1.2.2 bouyer struct xafb_softc *sc = v;
310 1.1.2.2 bouyer struct rasops_info *ri = &sc->sc_dc->dc_ri;
311 1.1.2.2 bouyer long defattr;
312 1.1.2.2 bouyer
313 1.1.2.2 bouyer if (sc->sc_nscreens > 0)
314 1.1.2.2 bouyer return ENOMEM;
315 1.1.2.2 bouyer
316 1.1.2.2 bouyer *cookiep = ri;
317 1.1.2.2 bouyer *ccolp = *crowp = 0;
318 1.1.2.2 bouyer (*ri->ri_ops.alloc_attr)(ri, 0, 0, 0, &defattr);
319 1.1.2.2 bouyer *attrp = defattr;
320 1.1.2.2 bouyer sc->sc_nscreens++;
321 1.1.2.2 bouyer
322 1.1.2.2 bouyer return 0;
323 1.1.2.2 bouyer }
324 1.1.2.2 bouyer
325 1.1.2.2 bouyer void
326 1.1.2.2 bouyer xafb_free_screen(v, cookie)
327 1.1.2.2 bouyer void *v;
328 1.1.2.2 bouyer void *cookie;
329 1.1.2.2 bouyer {
330 1.1.2.2 bouyer struct xafb_softc *sc = v;
331 1.1.2.2 bouyer
332 1.1.2.2 bouyer if (sc->sc_dc == &xafb_console_dc)
333 1.1.2.2 bouyer panic("xafb_free_screen: console");
334 1.1.2.2 bouyer
335 1.1.2.2 bouyer sc->sc_nscreens--;
336 1.1.2.2 bouyer }
337 1.1.2.2 bouyer
338 1.1.2.2 bouyer int
339 1.1.2.2 bouyer xafb_show_screen(v, cookie, waitok, cb, cbarg)
340 1.1.2.2 bouyer void *v;
341 1.1.2.2 bouyer void *cookie;
342 1.1.2.2 bouyer int waitok;
343 1.1.2.2 bouyer void (*cb) __P((void *, int, int));
344 1.1.2.2 bouyer void *cbarg;
345 1.1.2.2 bouyer {
346 1.1.2.2 bouyer return 0;
347 1.1.2.2 bouyer }
348 1.1.2.2 bouyer
349 1.1.2.2 bouyer int
350 1.1.2.2 bouyer xafb_cnattach()
351 1.1.2.2 bouyer {
352 1.1.2.2 bouyer struct xafb_devconfig *dc = &xafb_console_dc;
353 1.1.2.2 bouyer struct rasops_info *ri = &dc->dc_ri;
354 1.1.2.2 bouyer long defattr;
355 1.1.2.2 bouyer int crow = 0;
356 1.1.2.2 bouyer
357 1.1.2.2 bouyer if (!xafb_is_console())
358 1.1.2.2 bouyer return -1;
359 1.1.2.2 bouyer
360 1.1.2.2 bouyer dc->dc_fbbase = (void *)0xb0000000; /* XXX */
361 1.1.2.2 bouyer dc->dc_reg = (void *)0xb4903000; /* XXX */
362 1.1.2.2 bouyer xafb_common_init(dc);
363 1.1.2.2 bouyer
364 1.1.2.2 bouyer crow = 0; /* XXX current cursor pos */
365 1.1.2.2 bouyer
366 1.1.2.2 bouyer (*ri->ri_ops.alloc_attr)(ri, 0, 0, 0, &defattr);
367 1.1.2.2 bouyer wsdisplay_cnattach(&xafb_stdscreen, &dc->dc_ri, 0, crow, defattr);
368 1.1.2.2 bouyer
369 1.1.2.2 bouyer return 0;
370 1.1.2.2 bouyer }
371 1.1.2.2 bouyer
372 1.1.2.2 bouyer int
373 1.1.2.2 bouyer xafb_getcmap(sc, cm)
374 1.1.2.2 bouyer struct xafb_softc *sc;
375 1.1.2.2 bouyer struct wsdisplay_cmap *cm;
376 1.1.2.2 bouyer {
377 1.1.2.2 bouyer u_int index = cm->index;
378 1.1.2.2 bouyer u_int count = cm->count;
379 1.1.2.2 bouyer int error;
380 1.1.2.2 bouyer
381 1.1.2.2 bouyer if (index >= 256 || count > 256 || index + count > 256)
382 1.1.2.2 bouyer return EINVAL;
383 1.1.2.2 bouyer
384 1.1.2.2 bouyer error = copyout(&sc->sc_cmap_red[index], cm->red, count);
385 1.1.2.2 bouyer if (error)
386 1.1.2.2 bouyer return error;
387 1.1.2.2 bouyer error = copyout(&sc->sc_cmap_green[index], cm->green, count);
388 1.1.2.2 bouyer if (error)
389 1.1.2.2 bouyer return error;
390 1.1.2.2 bouyer error = copyout(&sc->sc_cmap_blue[index], cm->blue, count);
391 1.1.2.2 bouyer if (error)
392 1.1.2.2 bouyer return error;
393 1.1.2.2 bouyer
394 1.1.2.2 bouyer return 0;
395 1.1.2.2 bouyer }
396 1.1.2.2 bouyer
397 1.1.2.2 bouyer int
398 1.1.2.2 bouyer xafb_putcmap(sc, cm)
399 1.1.2.2 bouyer struct xafb_softc *sc;
400 1.1.2.2 bouyer struct wsdisplay_cmap *cm;
401 1.1.2.2 bouyer {
402 1.1.2.2 bouyer u_int index = cm->index;
403 1.1.2.2 bouyer u_int count = cm->count;
404 1.1.2.2 bouyer int i;
405 1.1.2.2 bouyer u_char *r, *g, *b;
406 1.1.2.2 bouyer
407 1.1.2.2 bouyer if (index >= 256 || count > 256 || index + count > 256)
408 1.1.2.2 bouyer return EINVAL;
409 1.1.2.2 bouyer if (!uvm_useracc(cm->red, count, B_READ) ||
410 1.1.2.2 bouyer !uvm_useracc(cm->green, count, B_READ) ||
411 1.1.2.2 bouyer !uvm_useracc(cm->blue, count, B_READ))
412 1.1.2.2 bouyer return EFAULT;
413 1.1.2.2 bouyer copyin(cm->red, &sc->sc_cmap_red[index], count);
414 1.1.2.2 bouyer copyin(cm->green, &sc->sc_cmap_green[index], count);
415 1.1.2.2 bouyer copyin(cm->blue, &sc->sc_cmap_blue[index], count);
416 1.1.2.2 bouyer
417 1.1.2.2 bouyer r = &sc->sc_cmap_red[index];
418 1.1.2.2 bouyer g = &sc->sc_cmap_green[index];
419 1.1.2.2 bouyer b = &sc->sc_cmap_blue[index];
420 1.1.2.2 bouyer
421 1.1.2.2 bouyer for (i = 0; i < count; i++)
422 1.1.2.2 bouyer xafb_setcolor(sc->sc_dc, index++, *r++, *g++, *b++);
423 1.1.2.2 bouyer
424 1.1.2.2 bouyer return 0;
425 1.1.2.2 bouyer }
426