ofb.c revision 1.11 1 1.11 tsubai /* $NetBSD: ofb.c,v 1.11 2000/02/09 13:08:36 tsubai Exp $ */
2 1.1 tsubai
3 1.1 tsubai /*
4 1.1 tsubai * Copyright (c) 1995, 1996 Carnegie-Mellon University.
5 1.1 tsubai * All rights reserved.
6 1.1 tsubai *
7 1.1 tsubai * Author: Chris G. Demetriou
8 1.1 tsubai *
9 1.1 tsubai * Permission to use, copy, modify and distribute this software and
10 1.1 tsubai * its documentation is hereby granted, provided that both the copyright
11 1.1 tsubai * notice and this permission notice appear in all copies of the
12 1.1 tsubai * software, derivative works or modified versions, and any portions
13 1.1 tsubai * thereof, and that both notices appear in supporting documentation.
14 1.1 tsubai *
15 1.1 tsubai * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
16 1.1 tsubai * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND
17 1.1 tsubai * FOR ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
18 1.1 tsubai *
19 1.1 tsubai * Carnegie Mellon requests users of this software to return to
20 1.1 tsubai *
21 1.1 tsubai * Software Distribution Coordinator or Software.Distribution (at) CS.CMU.EDU
22 1.1 tsubai * School of Computer Science
23 1.1 tsubai * Carnegie Mellon University
24 1.1 tsubai * Pittsburgh PA 15213-3890
25 1.1 tsubai *
26 1.1 tsubai * any improvements or extensions that they make and grant Carnegie the
27 1.1 tsubai * rights to redistribute these changes.
28 1.1 tsubai */
29 1.1 tsubai
30 1.1 tsubai #include <sys/param.h>
31 1.1 tsubai #include <sys/buf.h>
32 1.1 tsubai #include <sys/conf.h>
33 1.1 tsubai #include <sys/device.h>
34 1.1 tsubai #include <sys/ioctl.h>
35 1.1 tsubai #include <sys/kernel.h>
36 1.1 tsubai #include <sys/malloc.h>
37 1.1 tsubai #include <sys/systm.h>
38 1.1 tsubai
39 1.11 tsubai #include <vm/vm.h>
40 1.11 tsubai
41 1.3 tsubai #include <dev/pci/pcidevs.h>
42 1.1 tsubai #include <dev/pci/pcireg.h>
43 1.1 tsubai #include <dev/pci/pcivar.h>
44 1.1 tsubai
45 1.1 tsubai #include <dev/wscons/wsconsio.h>
46 1.1 tsubai #include <dev/wscons/wsdisplayvar.h>
47 1.11 tsubai #include <dev/rasops/rasops.h>
48 1.1 tsubai
49 1.1 tsubai #include <machine/bus.h>
50 1.1 tsubai #include <machine/grfioctl.h>
51 1.1 tsubai
52 1.1 tsubai #include <macppc/dev/ofbvar.h>
53 1.1 tsubai
54 1.1 tsubai int ofbmatch __P((struct device *, struct cfdata *, void *));
55 1.1 tsubai void ofbattach __P((struct device *, struct device *, void *));
56 1.1 tsubai int ofbprint __P((void *, const char *));
57 1.1 tsubai
58 1.1 tsubai struct cfattach ofb_ca = {
59 1.1 tsubai sizeof(struct ofb_softc), ofbmatch, ofbattach,
60 1.1 tsubai };
61 1.1 tsubai
62 1.1 tsubai struct ofb_devconfig ofb_console_dc;
63 1.1 tsubai
64 1.1 tsubai struct wsscreen_descr ofb_stdscreen = {
65 1.1 tsubai "std",
66 1.1 tsubai 0, 0, /* will be filled in -- XXX shouldn't, it's global */
67 1.11 tsubai 0,
68 1.1 tsubai 0, 0,
69 1.1 tsubai WSSCREEN_REVERSE
70 1.1 tsubai };
71 1.1 tsubai
72 1.1 tsubai const struct wsscreen_descr *_ofb_scrlist[] = {
73 1.1 tsubai &ofb_stdscreen,
74 1.1 tsubai /* XXX other formats, graphics screen? */
75 1.1 tsubai };
76 1.1 tsubai
77 1.1 tsubai struct wsscreen_list ofb_screenlist = {
78 1.1 tsubai sizeof(_ofb_scrlist) / sizeof(struct wsscreen_descr *), _ofb_scrlist
79 1.1 tsubai };
80 1.1 tsubai
81 1.1 tsubai static int ofb_ioctl __P((void *, u_long, caddr_t, int, struct proc *));
82 1.1 tsubai static int ofb_mmap __P((void *, off_t, int));
83 1.1 tsubai static int ofb_alloc_screen __P((void *, const struct wsscreen_descr *,
84 1.1 tsubai void **, int *, int *, long *));
85 1.1 tsubai static void ofb_free_screen __P((void *, void *));
86 1.10 drochner static int ofb_show_screen __P((void *, void *, int,
87 1.10 drochner void (*) (void *, int, int), void *));
88 1.1 tsubai
89 1.1 tsubai struct wsdisplay_accessops ofb_accessops = {
90 1.1 tsubai ofb_ioctl,
91 1.1 tsubai ofb_mmap,
92 1.1 tsubai ofb_alloc_screen,
93 1.1 tsubai ofb_free_screen,
94 1.1 tsubai ofb_show_screen,
95 1.6 drochner 0 /* load_font */
96 1.1 tsubai };
97 1.1 tsubai
98 1.11 tsubai static struct wsdisplay_font openfirm6x11;
99 1.11 tsubai
100 1.1 tsubai static void ofb_common_init __P((int, struct ofb_devconfig *));
101 1.11 tsubai static int ofb_getcmap __P((struct ofb_softc *, struct wsdisplay_cmap *));
102 1.11 tsubai static int ofb_putcmap __P((struct ofb_softc *, struct wsdisplay_cmap *));
103 1.1 tsubai
104 1.1 tsubai int
105 1.1 tsubai ofbmatch(parent, match, aux)
106 1.1 tsubai struct device *parent;
107 1.1 tsubai struct cfdata *match;
108 1.1 tsubai void *aux;
109 1.1 tsubai {
110 1.1 tsubai struct pci_attach_args *pa = aux;
111 1.1 tsubai
112 1.3 tsubai if (PCI_VENDOR(pa->pa_id) == PCI_VENDOR_APPLE &&
113 1.11 tsubai PCI_PRODUCT(pa->pa_id) == PCI_PRODUCT_APPLE_CONTROL)
114 1.3 tsubai return 1;
115 1.1 tsubai
116 1.3 tsubai if (PCI_CLASS(pa->pa_class) == PCI_CLASS_DISPLAY)
117 1.3 tsubai return 1;
118 1.3 tsubai
119 1.3 tsubai return 0;
120 1.1 tsubai }
121 1.1 tsubai
122 1.1 tsubai void
123 1.1 tsubai ofbattach(parent, self, aux)
124 1.1 tsubai struct device *parent, *self;
125 1.1 tsubai void *aux;
126 1.1 tsubai {
127 1.1 tsubai struct ofb_softc *sc = (struct ofb_softc *)self;
128 1.1 tsubai struct pci_attach_args *pa = aux;
129 1.1 tsubai struct wsemuldisplaydev_attach_args a;
130 1.1 tsubai int console;
131 1.1 tsubai struct ofb_devconfig *dc;
132 1.5 tsubai char devinfo[256];
133 1.1 tsubai
134 1.1 tsubai console = ofb_is_console();
135 1.1 tsubai
136 1.1 tsubai if (console) {
137 1.1 tsubai dc = &ofb_console_dc;
138 1.1 tsubai sc->nscreens = 1;
139 1.1 tsubai } else {
140 1.8 tsubai int node, i, screenbytes;
141 1.1 tsubai
142 1.1 tsubai dc = malloc(sizeof(struct ofb_devconfig), M_DEVBUF, M_WAITOK);
143 1.1 tsubai bzero(dc, sizeof(struct ofb_devconfig));
144 1.5 tsubai node = pcidev_to_ofdev(pa->pa_pc, pa->pa_tag);
145 1.3 tsubai if (node == 0) {
146 1.3 tsubai printf(": ofdev not found\n");
147 1.3 tsubai return;
148 1.3 tsubai }
149 1.1 tsubai ofb_common_init(node, dc);
150 1.8 tsubai
151 1.11 tsubai screenbytes = dc->dc_ri.ri_stride * dc->dc_ri.ri_height;
152 1.8 tsubai for (i = 0; i < screenbytes; i += sizeof(u_int32_t))
153 1.11 tsubai *(u_int32_t *)(dc->dc_paddr + i) = 0xffffffff;
154 1.1 tsubai }
155 1.1 tsubai sc->sc_dc = dc;
156 1.1 tsubai
157 1.1 tsubai if (dc->dc_paddr == 0) {
158 1.1 tsubai printf(": cannot map framebuffer\n");
159 1.1 tsubai return;
160 1.1 tsubai }
161 1.1 tsubai
162 1.5 tsubai pci_devinfo(pa->pa_id, pa->pa_class, 0, devinfo);
163 1.5 tsubai printf(": %s\n", devinfo);
164 1.5 tsubai printf("%s: %d x %d, %dbpp\n", self->dv_xname,
165 1.11 tsubai dc->dc_ri.ri_width, dc->dc_ri.ri_height, dc->dc_ri.ri_depth);
166 1.11 tsubai
167 1.11 tsubai sc->sc_cmap_red[0] = sc->sc_cmap_green[0] = sc->sc_cmap_blue[0] = 0;
168 1.11 tsubai sc->sc_cmap_red[15] = sc->sc_cmap_red[255] = 0xff;
169 1.11 tsubai sc->sc_cmap_green[15] = sc->sc_cmap_green[255] = 0xff;
170 1.11 tsubai sc->sc_cmap_blue[15] = sc->sc_cmap_blue[255] = 0xff;
171 1.1 tsubai
172 1.1 tsubai a.console = console;
173 1.1 tsubai a.scrdata = &ofb_screenlist;
174 1.1 tsubai a.accessops = &ofb_accessops;
175 1.1 tsubai a.accesscookie = sc;
176 1.1 tsubai
177 1.1 tsubai config_found(self, &a, wsemuldisplaydevprint);
178 1.1 tsubai }
179 1.1 tsubai
180 1.1 tsubai void
181 1.1 tsubai ofb_common_init(node, dc)
182 1.1 tsubai int node;
183 1.1 tsubai struct ofb_devconfig *dc;
184 1.1 tsubai {
185 1.11 tsubai struct rasops_info *ri = &dc->dc_ri;
186 1.11 tsubai int32_t addr, width, height, linebytes, depth;
187 1.1 tsubai
188 1.1 tsubai if (dc->dc_ih == 0) {
189 1.1 tsubai char name[64];
190 1.1 tsubai
191 1.1 tsubai bzero(name, 64);
192 1.1 tsubai OF_package_to_path(node, name, sizeof(name));
193 1.1 tsubai dc->dc_ih = OF_open(name);
194 1.1 tsubai }
195 1.3 tsubai
196 1.8 tsubai /* XXX /chaos/control doesn't have "width", "height", ... */
197 1.3 tsubai width = height = -1;
198 1.11 tsubai if (OF_getprop(node, "width", &width, 4) != 4)
199 1.3 tsubai OF_interpret("screen-width", 1, &width);
200 1.11 tsubai if (OF_getprop(node, "height", &height, 4) != 4)
201 1.3 tsubai OF_interpret("screen-height", 1, &height);
202 1.11 tsubai if (OF_getprop(node, "linebytes", &linebytes, 4) != 4)
203 1.3 tsubai linebytes = width; /* XXX */
204 1.11 tsubai if (OF_getprop(node, "depth", &depth, 4) != 4)
205 1.3 tsubai depth = 8; /* XXX */
206 1.11 tsubai if (OF_getprop(node, "address", &addr, 4) != 4)
207 1.11 tsubai OF_interpret("frame-buffer-adr", 1, &addr);
208 1.11 tsubai
209 1.11 tsubai if (width == -1 || height == -1 || addr == 0 || addr == -1)
210 1.3 tsubai return;
211 1.1 tsubai
212 1.11 tsubai dc->dc_paddr = addr; /* PA of the frame buffer */
213 1.11 tsubai
214 1.11 tsubai /* change 0xff/0xff/0xff to white */
215 1.11 tsubai OF_call_method_1("color!", dc->dc_ih, 4, 255, 255, 255, 255);
216 1.1 tsubai
217 1.11 tsubai /* initialize rasops */
218 1.11 tsubai ri->ri_width = width;
219 1.11 tsubai ri->ri_height = height;
220 1.11 tsubai ri->ri_depth = depth;
221 1.11 tsubai ri->ri_stride = linebytes;
222 1.11 tsubai ri->ri_bits = (char *)addr;
223 1.11 tsubai ri->ri_flg = RI_FORCEMONO | RI_FULLCLEAR | RI_CENTER;
224 1.1 tsubai
225 1.8 tsubai /* If screen is smaller than 1024x768, use small font. */
226 1.8 tsubai if ((width < 1024 || height < 768) && copy_rom_font() == 0) {
227 1.11 tsubai int cols, rows;
228 1.8 tsubai
229 1.11 tsubai OF_interpret("#lines", 1, &rows);
230 1.11 tsubai OF_interpret("#columns", 1, &cols);
231 1.8 tsubai
232 1.11 tsubai ri->ri_font = &openfirm6x11;
233 1.11 tsubai ri->ri_wsfcookie = -1; /* not using wsfont */
234 1.11 tsubai rasops_init(ri, rows, cols);
235 1.11 tsubai
236 1.11 tsubai ri->ri_xorigin = 2;
237 1.11 tsubai ri->ri_yorigin = 3;
238 1.11 tsubai ri->ri_bits = (char *)addr + ri->ri_xorigin +
239 1.11 tsubai ri->ri_stride * ri->ri_yorigin;
240 1.11 tsubai } else
241 1.11 tsubai rasops_init(ri, height/22, (width/12) & ~7); /* XXX 12x22 */
242 1.11 tsubai
243 1.11 tsubai /* black on white */
244 1.11 tsubai ri->ri_devcmap[0] = 0xffffffff; /* bg */
245 1.11 tsubai ri->ri_devcmap[1] = 0; /* fg */
246 1.11 tsubai
247 1.11 tsubai ofb_stdscreen.nrows = ri->ri_rows;
248 1.11 tsubai ofb_stdscreen.ncols = ri->ri_cols;
249 1.11 tsubai ofb_stdscreen.textops = &ri->ri_ops;
250 1.11 tsubai ofb_stdscreen.capabilities = ri->ri_caps;
251 1.1 tsubai }
252 1.1 tsubai
253 1.1 tsubai int
254 1.1 tsubai ofb_is_console()
255 1.1 tsubai {
256 1.1 tsubai int chosen, stdout, node;
257 1.1 tsubai char type[16];
258 1.1 tsubai
259 1.1 tsubai chosen = OF_finddevice("/chosen");
260 1.1 tsubai OF_getprop(chosen, "stdout", &stdout, 4);
261 1.1 tsubai node = OF_instance_to_package(stdout);
262 1.1 tsubai OF_getprop(node, "device_type", type, sizeof(type));
263 1.1 tsubai if (strcmp(type, "display") == 0)
264 1.1 tsubai return 1;
265 1.1 tsubai else
266 1.1 tsubai return 0;
267 1.1 tsubai }
268 1.1 tsubai
269 1.1 tsubai int
270 1.1 tsubai ofb_ioctl(v, cmd, data, flag, p)
271 1.1 tsubai void *v;
272 1.1 tsubai u_long cmd;
273 1.1 tsubai caddr_t data;
274 1.1 tsubai int flag;
275 1.1 tsubai struct proc *p;
276 1.1 tsubai {
277 1.1 tsubai struct ofb_softc *sc = v;
278 1.1 tsubai struct ofb_devconfig *dc = sc->sc_dc;
279 1.1 tsubai struct wsdisplay_fbinfo *wdf;
280 1.1 tsubai struct grfinfo *gm;
281 1.1 tsubai
282 1.1 tsubai switch (cmd) {
283 1.1 tsubai case WSDISPLAYIO_GTYPE:
284 1.1 tsubai *(u_int *)data = WSDISPLAY_TYPE_PCIMISC; /* XXX ? */
285 1.1 tsubai return 0;
286 1.1 tsubai
287 1.1 tsubai case WSDISPLAYIO_GINFO:
288 1.1 tsubai wdf = (void *)data;
289 1.11 tsubai wdf->height = dc->dc_ri.ri_height;
290 1.11 tsubai wdf->width = dc->dc_ri.ri_width;
291 1.11 tsubai wdf->depth = dc->dc_ri.ri_depth;
292 1.1 tsubai wdf->cmsize = 256;
293 1.1 tsubai return 0;
294 1.1 tsubai
295 1.11 tsubai case WSDISPLAYIO_GETCMAP:
296 1.11 tsubai return ofb_getcmap(sc, (struct wsdisplay_cmap *)data);
297 1.11 tsubai
298 1.1 tsubai case WSDISPLAYIO_PUTCMAP:
299 1.11 tsubai return ofb_putcmap(sc, (struct wsdisplay_cmap *)data);
300 1.1 tsubai
301 1.1 tsubai /* XXX There are no way to know framebuffer pa from a user program. */
302 1.1 tsubai case GRFIOCGINFO:
303 1.1 tsubai gm = (void *)data;
304 1.1 tsubai bzero(gm, sizeof(struct grfinfo));
305 1.11 tsubai gm->gd_fbaddr = (caddr_t)dc->dc_paddr;
306 1.11 tsubai gm->gd_fbrowbytes = dc->dc_ri.ri_stride;
307 1.1 tsubai return 0;
308 1.1 tsubai }
309 1.1 tsubai return -1;
310 1.1 tsubai }
311 1.1 tsubai
312 1.1 tsubai int
313 1.1 tsubai ofb_mmap(v, offset, prot)
314 1.1 tsubai void *v;
315 1.1 tsubai off_t offset;
316 1.1 tsubai int prot;
317 1.1 tsubai {
318 1.1 tsubai struct ofb_softc *sc = v;
319 1.1 tsubai struct ofb_devconfig *dc = sc->sc_dc;
320 1.11 tsubai struct rasops_info *ri = &dc->dc_ri;
321 1.1 tsubai
322 1.11 tsubai if (offset >= (ri->ri_stride * ri->ri_height) || offset < 0)
323 1.1 tsubai return -1;
324 1.1 tsubai
325 1.1 tsubai return dc->dc_paddr + offset;
326 1.1 tsubai }
327 1.1 tsubai
328 1.1 tsubai int
329 1.1 tsubai ofb_alloc_screen(v, type, cookiep, curxp, curyp, attrp)
330 1.1 tsubai void *v;
331 1.1 tsubai const struct wsscreen_descr *type;
332 1.1 tsubai void **cookiep;
333 1.1 tsubai int *curxp, *curyp;
334 1.1 tsubai long *attrp;
335 1.1 tsubai {
336 1.1 tsubai struct ofb_softc *sc = v;
337 1.11 tsubai struct rasops_info *ri = &sc->sc_dc->dc_ri;
338 1.1 tsubai long defattr;
339 1.1 tsubai
340 1.1 tsubai if (sc->nscreens > 0)
341 1.1 tsubai return (ENOMEM);
342 1.1 tsubai
343 1.11 tsubai *cookiep = ri; /* one and only for now */
344 1.1 tsubai *curxp = 0;
345 1.1 tsubai *curyp = 0;
346 1.11 tsubai (*ri->ri_ops.alloc_attr)(ri, 0, 0, 0, &defattr);
347 1.1 tsubai *attrp = defattr;
348 1.1 tsubai sc->nscreens++;
349 1.1 tsubai return 0;
350 1.1 tsubai }
351 1.1 tsubai
352 1.1 tsubai void
353 1.1 tsubai ofb_free_screen(v, cookie)
354 1.1 tsubai void *v;
355 1.1 tsubai void *cookie;
356 1.1 tsubai {
357 1.1 tsubai struct ofb_softc *sc = v;
358 1.1 tsubai
359 1.1 tsubai if (sc->sc_dc == &ofb_console_dc)
360 1.1 tsubai panic("ofb_free_screen: console");
361 1.1 tsubai
362 1.1 tsubai sc->nscreens--;
363 1.1 tsubai }
364 1.1 tsubai
365 1.10 drochner int
366 1.10 drochner ofb_show_screen(v, cookie, waitok, cb, cbarg)
367 1.1 tsubai void *v;
368 1.1 tsubai void *cookie;
369 1.10 drochner int waitok;
370 1.10 drochner void (*cb) __P((void *, int, int));
371 1.10 drochner void *cbarg;
372 1.1 tsubai {
373 1.10 drochner
374 1.10 drochner return (0);
375 1.1 tsubai }
376 1.1 tsubai
377 1.1 tsubai int
378 1.1 tsubai ofb_cnattach()
379 1.1 tsubai {
380 1.1 tsubai struct ofb_devconfig *dc = &ofb_console_dc;
381 1.11 tsubai struct rasops_info *ri = &dc->dc_ri;
382 1.1 tsubai long defattr;
383 1.11 tsubai int crow = 0;
384 1.1 tsubai int chosen, stdout, node;
385 1.1 tsubai
386 1.1 tsubai chosen = OF_finddevice("/chosen");
387 1.1 tsubai OF_getprop(chosen, "stdout", &stdout, sizeof(stdout));
388 1.1 tsubai node = OF_instance_to_package(stdout);
389 1.1 tsubai dc->dc_ih = stdout;
390 1.1 tsubai
391 1.11 tsubai /* get current cursor position */
392 1.11 tsubai OF_interpret("line#", 1, &crow);
393 1.8 tsubai
394 1.11 tsubai /* move (rom monitor) cursor to the lowest line - 1 */
395 1.11 tsubai OF_interpret("#lines 2 - to line#", 0);
396 1.8 tsubai
397 1.11 tsubai ofb_common_init(node, dc);
398 1.1 tsubai
399 1.11 tsubai if (ri->ri_width >= 1024 && ri->ri_height >= 768) {
400 1.11 tsubai int i, screenbytes = ri->ri_stride * ri->ri_height;
401 1.8 tsubai
402 1.8 tsubai for (i = 0; i < screenbytes; i += sizeof(u_int32_t))
403 1.11 tsubai *(u_int32_t *)(dc->dc_paddr + i) = 0xffffffff;
404 1.8 tsubai crow = 0;
405 1.8 tsubai }
406 1.8 tsubai
407 1.11 tsubai (*ri->ri_ops.alloc_attr)(ri, 0, 0, 0, &defattr);
408 1.11 tsubai wsdisplay_cnattach(&ofb_stdscreen, ri, 0, crow, defattr);
409 1.8 tsubai
410 1.8 tsubai return 0;
411 1.8 tsubai }
412 1.8 tsubai
413 1.8 tsubai int
414 1.8 tsubai copy_rom_font()
415 1.8 tsubai {
416 1.8 tsubai u_char *romfont;
417 1.8 tsubai int char_width, char_height;
418 1.8 tsubai int chosen, mmu, m, e;
419 1.8 tsubai
420 1.8 tsubai /* Get ROM FONT address. */
421 1.8 tsubai OF_interpret("font-adr", 1, &romfont);
422 1.8 tsubai if (romfont == NULL)
423 1.8 tsubai return -1;
424 1.8 tsubai
425 1.8 tsubai chosen = OF_finddevice("/chosen");
426 1.8 tsubai OF_getprop(chosen, "mmu", &mmu, 4);
427 1.1 tsubai
428 1.8 tsubai /*
429 1.8 tsubai * Convert to physcal address. We cannot access to Open Firmware's
430 1.8 tsubai * virtual address space.
431 1.8 tsubai */
432 1.8 tsubai OF_call_method("translate", mmu, 1, 3, romfont, &romfont, &m, &e);
433 1.8 tsubai
434 1.8 tsubai /* Get character size */
435 1.8 tsubai OF_interpret("char-width", 1, &char_width);
436 1.8 tsubai OF_interpret("char-height", 1, &char_height);
437 1.8 tsubai
438 1.11 tsubai openfirm6x11.name = "Open Firmware";
439 1.11 tsubai openfirm6x11.firstchar = 32;
440 1.11 tsubai openfirm6x11.numchars = 96;
441 1.11 tsubai openfirm6x11.encoding = WSDISPLAY_FONTENC_ISO;
442 1.11 tsubai openfirm6x11.fontwidth = char_width;
443 1.11 tsubai openfirm6x11.fontheight = char_height;
444 1.11 tsubai openfirm6x11.stride = 1;
445 1.11 tsubai openfirm6x11.bitorder = WSDISPLAY_FONTORDER_L2R;
446 1.11 tsubai openfirm6x11.byteorder = WSDISPLAY_FONTORDER_L2R;
447 1.11 tsubai openfirm6x11.data = romfont;
448 1.11 tsubai
449 1.11 tsubai return 0;
450 1.11 tsubai }
451 1.11 tsubai
452 1.11 tsubai int
453 1.11 tsubai ofb_getcmap(sc, cm)
454 1.11 tsubai struct ofb_softc *sc;
455 1.11 tsubai struct wsdisplay_cmap *cm;
456 1.11 tsubai {
457 1.11 tsubai u_int index = cm->index;
458 1.11 tsubai u_int count = cm->count;
459 1.11 tsubai int error;
460 1.11 tsubai
461 1.11 tsubai if (index >= 256 || count > 256 || index + count > 256)
462 1.11 tsubai return EINVAL;
463 1.11 tsubai
464 1.11 tsubai error = copyout(&sc->sc_cmap_red[index], cm->red, count);
465 1.11 tsubai if (error)
466 1.11 tsubai return error;
467 1.11 tsubai error = copyout(&sc->sc_cmap_green[index], cm->green, count);
468 1.11 tsubai if (error)
469 1.11 tsubai return error;
470 1.11 tsubai error = copyout(&sc->sc_cmap_blue[index], cm->blue, count);
471 1.11 tsubai if (error)
472 1.11 tsubai return error;
473 1.8 tsubai
474 1.1 tsubai return 0;
475 1.1 tsubai }
476 1.1 tsubai
477 1.1 tsubai int
478 1.11 tsubai ofb_putcmap(sc, cm)
479 1.1 tsubai struct ofb_softc *sc;
480 1.1 tsubai struct wsdisplay_cmap *cm;
481 1.1 tsubai {
482 1.1 tsubai struct ofb_devconfig *dc = sc->sc_dc;
483 1.1 tsubai int index = cm->index;
484 1.1 tsubai int count = cm->count;
485 1.7 tsubai int i;
486 1.1 tsubai u_char *r, *g, *b;
487 1.1 tsubai
488 1.1 tsubai if (cm->index >= 256 || cm->count > 256 ||
489 1.1 tsubai (cm->index + cm->count) > 256)
490 1.1 tsubai return EINVAL;
491 1.1 tsubai if (!uvm_useracc(cm->red, cm->count, B_READ) ||
492 1.1 tsubai !uvm_useracc(cm->green, cm->count, B_READ) ||
493 1.1 tsubai !uvm_useracc(cm->blue, cm->count, B_READ))
494 1.1 tsubai return EFAULT;
495 1.1 tsubai copyin(cm->red, &sc->sc_cmap_red[index], count);
496 1.1 tsubai copyin(cm->green, &sc->sc_cmap_green[index], count);
497 1.1 tsubai copyin(cm->blue, &sc->sc_cmap_blue[index], count);
498 1.1 tsubai
499 1.1 tsubai r = &sc->sc_cmap_red[index];
500 1.1 tsubai g = &sc->sc_cmap_green[index];
501 1.1 tsubai b = &sc->sc_cmap_blue[index];
502 1.1 tsubai
503 1.1 tsubai for (i = 0; i < count; i++) {
504 1.1 tsubai OF_call_method_1("color!", dc->dc_ih, 4, *r, *g, *b, index);
505 1.1 tsubai r++, g++, b++, index++;
506 1.1 tsubai }
507 1.1 tsubai
508 1.1 tsubai return 0;
509 1.1 tsubai }
510