ofb.c revision 1.19 1 1.19 matt /* $NetBSD: ofb.c,v 1.19 2001/06/06 17:50:15 matt 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.15 mrg #include <uvm/uvm_extern.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.13 tsubai #include <dev/ofw/ofw_pci.h>
50 1.13 tsubai
51 1.1 tsubai #include <machine/bus.h>
52 1.19 matt #include <powerpc/mpc6xx/bat.h>
53 1.1 tsubai #include <machine/grfioctl.h>
54 1.1 tsubai
55 1.1 tsubai #include <macppc/dev/ofbvar.h>
56 1.1 tsubai
57 1.18 tsubai #if OFB_ENABLE_CACHE
58 1.18 tsubai int ofb_enable_cache = 1;
59 1.18 tsubai #else
60 1.18 tsubai int ofb_enable_cache = 0;
61 1.18 tsubai #endif
62 1.18 tsubai
63 1.1 tsubai int ofbmatch __P((struct device *, struct cfdata *, void *));
64 1.1 tsubai void ofbattach __P((struct device *, struct device *, void *));
65 1.1 tsubai int ofbprint __P((void *, const char *));
66 1.1 tsubai
67 1.1 tsubai struct cfattach ofb_ca = {
68 1.1 tsubai sizeof(struct ofb_softc), ofbmatch, ofbattach,
69 1.1 tsubai };
70 1.1 tsubai
71 1.1 tsubai struct ofb_devconfig ofb_console_dc;
72 1.1 tsubai
73 1.1 tsubai struct wsscreen_descr ofb_stdscreen = {
74 1.1 tsubai "std",
75 1.1 tsubai 0, 0, /* will be filled in -- XXX shouldn't, it's global */
76 1.11 tsubai 0,
77 1.1 tsubai 0, 0,
78 1.1 tsubai WSSCREEN_REVERSE
79 1.1 tsubai };
80 1.1 tsubai
81 1.1 tsubai const struct wsscreen_descr *_ofb_scrlist[] = {
82 1.1 tsubai &ofb_stdscreen,
83 1.1 tsubai /* XXX other formats, graphics screen? */
84 1.1 tsubai };
85 1.1 tsubai
86 1.1 tsubai struct wsscreen_list ofb_screenlist = {
87 1.1 tsubai sizeof(_ofb_scrlist) / sizeof(struct wsscreen_descr *), _ofb_scrlist
88 1.1 tsubai };
89 1.1 tsubai
90 1.1 tsubai static int ofb_ioctl __P((void *, u_long, caddr_t, int, struct proc *));
91 1.14 simonb static paddr_t ofb_mmap __P((void *, off_t, int));
92 1.1 tsubai static int ofb_alloc_screen __P((void *, const struct wsscreen_descr *,
93 1.1 tsubai void **, int *, int *, long *));
94 1.1 tsubai static void ofb_free_screen __P((void *, void *));
95 1.10 drochner static int ofb_show_screen __P((void *, void *, int,
96 1.10 drochner void (*) (void *, int, int), void *));
97 1.1 tsubai
98 1.1 tsubai struct wsdisplay_accessops ofb_accessops = {
99 1.1 tsubai ofb_ioctl,
100 1.1 tsubai ofb_mmap,
101 1.1 tsubai ofb_alloc_screen,
102 1.1 tsubai ofb_free_screen,
103 1.1 tsubai ofb_show_screen,
104 1.6 drochner 0 /* load_font */
105 1.1 tsubai };
106 1.1 tsubai
107 1.11 tsubai static struct wsdisplay_font openfirm6x11;
108 1.11 tsubai
109 1.1 tsubai static void ofb_common_init __P((int, struct ofb_devconfig *));
110 1.11 tsubai static int ofb_getcmap __P((struct ofb_softc *, struct wsdisplay_cmap *));
111 1.11 tsubai static int ofb_putcmap __P((struct ofb_softc *, struct wsdisplay_cmap *));
112 1.1 tsubai
113 1.1 tsubai int
114 1.1 tsubai ofbmatch(parent, match, aux)
115 1.1 tsubai struct device *parent;
116 1.1 tsubai struct cfdata *match;
117 1.1 tsubai void *aux;
118 1.1 tsubai {
119 1.1 tsubai struct pci_attach_args *pa = aux;
120 1.1 tsubai
121 1.3 tsubai if (PCI_VENDOR(pa->pa_id) == PCI_VENDOR_APPLE &&
122 1.11 tsubai PCI_PRODUCT(pa->pa_id) == PCI_PRODUCT_APPLE_CONTROL)
123 1.3 tsubai return 1;
124 1.1 tsubai
125 1.3 tsubai if (PCI_CLASS(pa->pa_class) == PCI_CLASS_DISPLAY)
126 1.3 tsubai return 1;
127 1.3 tsubai
128 1.3 tsubai return 0;
129 1.1 tsubai }
130 1.1 tsubai
131 1.1 tsubai void
132 1.1 tsubai ofbattach(parent, self, aux)
133 1.1 tsubai struct device *parent, *self;
134 1.1 tsubai void *aux;
135 1.1 tsubai {
136 1.1 tsubai struct ofb_softc *sc = (struct ofb_softc *)self;
137 1.1 tsubai struct pci_attach_args *pa = aux;
138 1.1 tsubai struct wsemuldisplaydev_attach_args a;
139 1.16 tsubai int console, node;
140 1.1 tsubai struct ofb_devconfig *dc;
141 1.5 tsubai char devinfo[256];
142 1.1 tsubai
143 1.1 tsubai console = ofb_is_console();
144 1.1 tsubai
145 1.1 tsubai if (console) {
146 1.1 tsubai dc = &ofb_console_dc;
147 1.16 tsubai node = dc->dc_node;
148 1.1 tsubai sc->nscreens = 1;
149 1.1 tsubai } else {
150 1.16 tsubai int i, len, screenbytes;
151 1.1 tsubai
152 1.1 tsubai dc = malloc(sizeof(struct ofb_devconfig), M_DEVBUF, M_WAITOK);
153 1.1 tsubai bzero(dc, sizeof(struct ofb_devconfig));
154 1.5 tsubai node = pcidev_to_ofdev(pa->pa_pc, pa->pa_tag);
155 1.3 tsubai if (node == 0) {
156 1.3 tsubai printf(": ofdev not found\n");
157 1.3 tsubai return;
158 1.3 tsubai }
159 1.16 tsubai
160 1.16 tsubai /* XXX There are two child screens on PowerBook. */
161 1.16 tsubai bzero(devinfo, sizeof(devinfo));
162 1.16 tsubai OF_getprop(node, "device_type", devinfo, sizeof(devinfo));
163 1.16 tsubai len = strlen(devinfo);
164 1.16 tsubai if (strcmp(devinfo + len - 7, "-parent") == 0)
165 1.16 tsubai node = OF_child(node);
166 1.16 tsubai
167 1.1 tsubai ofb_common_init(node, dc);
168 1.8 tsubai
169 1.11 tsubai screenbytes = dc->dc_ri.ri_stride * dc->dc_ri.ri_height;
170 1.8 tsubai for (i = 0; i < screenbytes; i += sizeof(u_int32_t))
171 1.11 tsubai *(u_int32_t *)(dc->dc_paddr + i) = 0xffffffff;
172 1.1 tsubai }
173 1.1 tsubai sc->sc_dc = dc;
174 1.1 tsubai
175 1.16 tsubai /* XXX */
176 1.16 tsubai if (OF_getprop(node, "assigned-addresses", sc->sc_addrs,
177 1.16 tsubai sizeof(sc->sc_addrs)) == -1) {
178 1.16 tsubai node = OF_parent(node);
179 1.16 tsubai OF_getprop(node, "assigned-addresses", sc->sc_addrs,
180 1.16 tsubai sizeof(sc->sc_addrs));
181 1.16 tsubai }
182 1.13 tsubai
183 1.1 tsubai if (dc->dc_paddr == 0) {
184 1.1 tsubai printf(": cannot map framebuffer\n");
185 1.1 tsubai return;
186 1.1 tsubai }
187 1.1 tsubai
188 1.5 tsubai pci_devinfo(pa->pa_id, pa->pa_class, 0, devinfo);
189 1.5 tsubai printf(": %s\n", devinfo);
190 1.5 tsubai printf("%s: %d x %d, %dbpp\n", self->dv_xname,
191 1.11 tsubai dc->dc_ri.ri_width, dc->dc_ri.ri_height, dc->dc_ri.ri_depth);
192 1.11 tsubai
193 1.11 tsubai sc->sc_cmap_red[0] = sc->sc_cmap_green[0] = sc->sc_cmap_blue[0] = 0;
194 1.11 tsubai sc->sc_cmap_red[15] = sc->sc_cmap_red[255] = 0xff;
195 1.11 tsubai sc->sc_cmap_green[15] = sc->sc_cmap_green[255] = 0xff;
196 1.11 tsubai sc->sc_cmap_blue[15] = sc->sc_cmap_blue[255] = 0xff;
197 1.1 tsubai
198 1.1 tsubai a.console = console;
199 1.1 tsubai a.scrdata = &ofb_screenlist;
200 1.1 tsubai a.accessops = &ofb_accessops;
201 1.1 tsubai a.accesscookie = sc;
202 1.1 tsubai
203 1.1 tsubai config_found(self, &a, wsemuldisplaydevprint);
204 1.1 tsubai }
205 1.1 tsubai
206 1.1 tsubai void
207 1.1 tsubai ofb_common_init(node, dc)
208 1.1 tsubai int node;
209 1.1 tsubai struct ofb_devconfig *dc;
210 1.1 tsubai {
211 1.11 tsubai struct rasops_info *ri = &dc->dc_ri;
212 1.11 tsubai int32_t addr, width, height, linebytes, depth;
213 1.1 tsubai
214 1.13 tsubai dc->dc_node = node;
215 1.1 tsubai if (dc->dc_ih == 0) {
216 1.1 tsubai char name[64];
217 1.1 tsubai
218 1.1 tsubai bzero(name, 64);
219 1.1 tsubai OF_package_to_path(node, name, sizeof(name));
220 1.1 tsubai dc->dc_ih = OF_open(name);
221 1.1 tsubai }
222 1.3 tsubai
223 1.8 tsubai /* XXX /chaos/control doesn't have "width", "height", ... */
224 1.3 tsubai width = height = -1;
225 1.11 tsubai if (OF_getprop(node, "width", &width, 4) != 4)
226 1.3 tsubai OF_interpret("screen-width", 1, &width);
227 1.11 tsubai if (OF_getprop(node, "height", &height, 4) != 4)
228 1.3 tsubai OF_interpret("screen-height", 1, &height);
229 1.11 tsubai if (OF_getprop(node, "linebytes", &linebytes, 4) != 4)
230 1.3 tsubai linebytes = width; /* XXX */
231 1.11 tsubai if (OF_getprop(node, "depth", &depth, 4) != 4)
232 1.3 tsubai depth = 8; /* XXX */
233 1.11 tsubai if (OF_getprop(node, "address", &addr, 4) != 4)
234 1.11 tsubai OF_interpret("frame-buffer-adr", 1, &addr);
235 1.11 tsubai
236 1.11 tsubai if (width == -1 || height == -1 || addr == 0 || addr == -1)
237 1.3 tsubai return;
238 1.1 tsubai
239 1.11 tsubai dc->dc_paddr = addr; /* PA of the frame buffer */
240 1.11 tsubai
241 1.12 tsubai /* Make sure 0/0/0 is black and 255/255/255 is white. */
242 1.12 tsubai OF_call_method_1("color!", dc->dc_ih, 4, 0, 0, 0, 0);
243 1.11 tsubai OF_call_method_1("color!", dc->dc_ih, 4, 255, 255, 255, 255);
244 1.18 tsubai
245 1.18 tsubai /* Enable write-through cache. */
246 1.18 tsubai if (ofb_enable_cache && battable[0xc].batu == 0) {
247 1.18 tsubai battable[0xc].batl = BATL(addr & 0xf0000000, BAT_W, BAT_PP_RW);
248 1.18 tsubai battable[0xc].batu = BATL(0xc0000000, BAT_BL_256M, BAT_Vs);
249 1.18 tsubai addr &= 0x0fffffff;
250 1.18 tsubai addr |= 0xc0000000;
251 1.18 tsubai }
252 1.1 tsubai
253 1.11 tsubai /* initialize rasops */
254 1.11 tsubai ri->ri_width = width;
255 1.11 tsubai ri->ri_height = height;
256 1.11 tsubai ri->ri_depth = depth;
257 1.11 tsubai ri->ri_stride = linebytes;
258 1.11 tsubai ri->ri_bits = (char *)addr;
259 1.11 tsubai ri->ri_flg = RI_FORCEMONO | RI_FULLCLEAR | RI_CENTER;
260 1.1 tsubai
261 1.8 tsubai /* If screen is smaller than 1024x768, use small font. */
262 1.8 tsubai if ((width < 1024 || height < 768) && copy_rom_font() == 0) {
263 1.11 tsubai int cols, rows;
264 1.8 tsubai
265 1.11 tsubai OF_interpret("#lines", 1, &rows);
266 1.11 tsubai OF_interpret("#columns", 1, &cols);
267 1.8 tsubai
268 1.11 tsubai ri->ri_font = &openfirm6x11;
269 1.11 tsubai ri->ri_wsfcookie = -1; /* not using wsfont */
270 1.11 tsubai rasops_init(ri, rows, cols);
271 1.11 tsubai
272 1.11 tsubai ri->ri_xorigin = 2;
273 1.11 tsubai ri->ri_yorigin = 3;
274 1.11 tsubai ri->ri_bits = (char *)addr + ri->ri_xorigin +
275 1.11 tsubai ri->ri_stride * ri->ri_yorigin;
276 1.17 tsubai } else {
277 1.17 tsubai rasops_init(ri, 24, 80);
278 1.17 tsubai rasops_reconfig(ri, (height - 2) / ri->ri_font->fontheight,
279 1.17 tsubai ((width - 2) / ri->ri_font->fontwidth) & ~7);
280 1.17 tsubai }
281 1.11 tsubai
282 1.11 tsubai /* black on white */
283 1.11 tsubai ri->ri_devcmap[0] = 0xffffffff; /* bg */
284 1.11 tsubai ri->ri_devcmap[1] = 0; /* fg */
285 1.11 tsubai
286 1.11 tsubai ofb_stdscreen.nrows = ri->ri_rows;
287 1.11 tsubai ofb_stdscreen.ncols = ri->ri_cols;
288 1.11 tsubai ofb_stdscreen.textops = &ri->ri_ops;
289 1.11 tsubai ofb_stdscreen.capabilities = ri->ri_caps;
290 1.1 tsubai }
291 1.1 tsubai
292 1.1 tsubai int
293 1.1 tsubai ofb_is_console()
294 1.1 tsubai {
295 1.1 tsubai int chosen, stdout, node;
296 1.1 tsubai char type[16];
297 1.1 tsubai
298 1.1 tsubai chosen = OF_finddevice("/chosen");
299 1.1 tsubai OF_getprop(chosen, "stdout", &stdout, 4);
300 1.1 tsubai node = OF_instance_to_package(stdout);
301 1.1 tsubai OF_getprop(node, "device_type", type, sizeof(type));
302 1.1 tsubai if (strcmp(type, "display") == 0)
303 1.1 tsubai return 1;
304 1.1 tsubai else
305 1.1 tsubai return 0;
306 1.1 tsubai }
307 1.1 tsubai
308 1.1 tsubai int
309 1.1 tsubai ofb_ioctl(v, cmd, data, flag, p)
310 1.1 tsubai void *v;
311 1.1 tsubai u_long cmd;
312 1.1 tsubai caddr_t data;
313 1.1 tsubai int flag;
314 1.1 tsubai struct proc *p;
315 1.1 tsubai {
316 1.1 tsubai struct ofb_softc *sc = v;
317 1.1 tsubai struct ofb_devconfig *dc = sc->sc_dc;
318 1.1 tsubai struct wsdisplay_fbinfo *wdf;
319 1.1 tsubai struct grfinfo *gm;
320 1.1 tsubai
321 1.1 tsubai switch (cmd) {
322 1.1 tsubai case WSDISPLAYIO_GTYPE:
323 1.1 tsubai *(u_int *)data = WSDISPLAY_TYPE_PCIMISC; /* XXX ? */
324 1.1 tsubai return 0;
325 1.1 tsubai
326 1.1 tsubai case WSDISPLAYIO_GINFO:
327 1.1 tsubai wdf = (void *)data;
328 1.11 tsubai wdf->height = dc->dc_ri.ri_height;
329 1.11 tsubai wdf->width = dc->dc_ri.ri_width;
330 1.11 tsubai wdf->depth = dc->dc_ri.ri_depth;
331 1.1 tsubai wdf->cmsize = 256;
332 1.1 tsubai return 0;
333 1.1 tsubai
334 1.11 tsubai case WSDISPLAYIO_GETCMAP:
335 1.11 tsubai return ofb_getcmap(sc, (struct wsdisplay_cmap *)data);
336 1.11 tsubai
337 1.1 tsubai case WSDISPLAYIO_PUTCMAP:
338 1.11 tsubai return ofb_putcmap(sc, (struct wsdisplay_cmap *)data);
339 1.1 tsubai
340 1.1 tsubai /* XXX There are no way to know framebuffer pa from a user program. */
341 1.1 tsubai case GRFIOCGINFO:
342 1.1 tsubai gm = (void *)data;
343 1.1 tsubai bzero(gm, sizeof(struct grfinfo));
344 1.11 tsubai gm->gd_fbaddr = (caddr_t)dc->dc_paddr;
345 1.11 tsubai gm->gd_fbrowbytes = dc->dc_ri.ri_stride;
346 1.1 tsubai return 0;
347 1.1 tsubai }
348 1.1 tsubai return -1;
349 1.1 tsubai }
350 1.1 tsubai
351 1.14 simonb paddr_t
352 1.1 tsubai ofb_mmap(v, offset, prot)
353 1.1 tsubai void *v;
354 1.1 tsubai off_t offset;
355 1.1 tsubai int prot;
356 1.1 tsubai {
357 1.1 tsubai struct ofb_softc *sc = v;
358 1.1 tsubai struct ofb_devconfig *dc = sc->sc_dc;
359 1.11 tsubai struct rasops_info *ri = &dc->dc_ri;
360 1.13 tsubai u_int32_t *ap = sc->sc_addrs;
361 1.13 tsubai paddr_t pa;
362 1.13 tsubai int i;
363 1.13 tsubai
364 1.13 tsubai if (offset >=0 && offset < (ri->ri_stride * ri->ri_height))
365 1.13 tsubai return dc->dc_paddr + offset;
366 1.13 tsubai
367 1.13 tsubai pa = offset;
368 1.13 tsubai for (i = 0; i < 6; i++) {
369 1.13 tsubai switch (ap[0] & OFW_PCI_PHYS_HI_SPACEMASK) {
370 1.13 tsubai case OFW_PCI_PHYS_HI_SPACE_MEM32:
371 1.13 tsubai if (pa >= ap[2] && pa < ap[2] + ap[4])
372 1.13 tsubai return pa;
373 1.13 tsubai /* XXX I/O space? */
374 1.13 tsubai }
375 1.13 tsubai ap += 5;
376 1.13 tsubai }
377 1.1 tsubai
378 1.13 tsubai return -1;
379 1.1 tsubai }
380 1.1 tsubai
381 1.1 tsubai int
382 1.1 tsubai ofb_alloc_screen(v, type, cookiep, curxp, curyp, attrp)
383 1.1 tsubai void *v;
384 1.1 tsubai const struct wsscreen_descr *type;
385 1.1 tsubai void **cookiep;
386 1.1 tsubai int *curxp, *curyp;
387 1.1 tsubai long *attrp;
388 1.1 tsubai {
389 1.1 tsubai struct ofb_softc *sc = v;
390 1.11 tsubai struct rasops_info *ri = &sc->sc_dc->dc_ri;
391 1.1 tsubai long defattr;
392 1.1 tsubai
393 1.1 tsubai if (sc->nscreens > 0)
394 1.1 tsubai return (ENOMEM);
395 1.1 tsubai
396 1.11 tsubai *cookiep = ri; /* one and only for now */
397 1.1 tsubai *curxp = 0;
398 1.1 tsubai *curyp = 0;
399 1.11 tsubai (*ri->ri_ops.alloc_attr)(ri, 0, 0, 0, &defattr);
400 1.1 tsubai *attrp = defattr;
401 1.1 tsubai sc->nscreens++;
402 1.1 tsubai return 0;
403 1.1 tsubai }
404 1.1 tsubai
405 1.1 tsubai void
406 1.1 tsubai ofb_free_screen(v, cookie)
407 1.1 tsubai void *v;
408 1.1 tsubai void *cookie;
409 1.1 tsubai {
410 1.1 tsubai struct ofb_softc *sc = v;
411 1.1 tsubai
412 1.1 tsubai if (sc->sc_dc == &ofb_console_dc)
413 1.1 tsubai panic("ofb_free_screen: console");
414 1.1 tsubai
415 1.1 tsubai sc->nscreens--;
416 1.1 tsubai }
417 1.1 tsubai
418 1.10 drochner int
419 1.10 drochner ofb_show_screen(v, cookie, waitok, cb, cbarg)
420 1.1 tsubai void *v;
421 1.1 tsubai void *cookie;
422 1.10 drochner int waitok;
423 1.10 drochner void (*cb) __P((void *, int, int));
424 1.10 drochner void *cbarg;
425 1.1 tsubai {
426 1.10 drochner
427 1.10 drochner return (0);
428 1.1 tsubai }
429 1.1 tsubai
430 1.1 tsubai int
431 1.1 tsubai ofb_cnattach()
432 1.1 tsubai {
433 1.1 tsubai struct ofb_devconfig *dc = &ofb_console_dc;
434 1.11 tsubai struct rasops_info *ri = &dc->dc_ri;
435 1.1 tsubai long defattr;
436 1.11 tsubai int crow = 0;
437 1.1 tsubai int chosen, stdout, node;
438 1.1 tsubai
439 1.1 tsubai chosen = OF_finddevice("/chosen");
440 1.1 tsubai OF_getprop(chosen, "stdout", &stdout, sizeof(stdout));
441 1.1 tsubai node = OF_instance_to_package(stdout);
442 1.1 tsubai dc->dc_ih = stdout;
443 1.1 tsubai
444 1.11 tsubai /* get current cursor position */
445 1.11 tsubai OF_interpret("line#", 1, &crow);
446 1.8 tsubai
447 1.11 tsubai /* move (rom monitor) cursor to the lowest line - 1 */
448 1.11 tsubai OF_interpret("#lines 2 - to line#", 0);
449 1.8 tsubai
450 1.11 tsubai ofb_common_init(node, dc);
451 1.1 tsubai
452 1.11 tsubai if (ri->ri_width >= 1024 && ri->ri_height >= 768) {
453 1.11 tsubai int i, screenbytes = ri->ri_stride * ri->ri_height;
454 1.8 tsubai
455 1.8 tsubai for (i = 0; i < screenbytes; i += sizeof(u_int32_t))
456 1.11 tsubai *(u_int32_t *)(dc->dc_paddr + i) = 0xffffffff;
457 1.8 tsubai crow = 0;
458 1.8 tsubai }
459 1.8 tsubai
460 1.11 tsubai (*ri->ri_ops.alloc_attr)(ri, 0, 0, 0, &defattr);
461 1.11 tsubai wsdisplay_cnattach(&ofb_stdscreen, ri, 0, crow, defattr);
462 1.8 tsubai
463 1.8 tsubai return 0;
464 1.8 tsubai }
465 1.8 tsubai
466 1.8 tsubai int
467 1.8 tsubai copy_rom_font()
468 1.8 tsubai {
469 1.8 tsubai u_char *romfont;
470 1.8 tsubai int char_width, char_height;
471 1.8 tsubai int chosen, mmu, m, e;
472 1.8 tsubai
473 1.8 tsubai /* Get ROM FONT address. */
474 1.8 tsubai OF_interpret("font-adr", 1, &romfont);
475 1.8 tsubai if (romfont == NULL)
476 1.8 tsubai return -1;
477 1.8 tsubai
478 1.8 tsubai chosen = OF_finddevice("/chosen");
479 1.8 tsubai OF_getprop(chosen, "mmu", &mmu, 4);
480 1.1 tsubai
481 1.8 tsubai /*
482 1.8 tsubai * Convert to physcal address. We cannot access to Open Firmware's
483 1.8 tsubai * virtual address space.
484 1.8 tsubai */
485 1.8 tsubai OF_call_method("translate", mmu, 1, 3, romfont, &romfont, &m, &e);
486 1.8 tsubai
487 1.8 tsubai /* Get character size */
488 1.8 tsubai OF_interpret("char-width", 1, &char_width);
489 1.8 tsubai OF_interpret("char-height", 1, &char_height);
490 1.8 tsubai
491 1.11 tsubai openfirm6x11.name = "Open Firmware";
492 1.11 tsubai openfirm6x11.firstchar = 32;
493 1.11 tsubai openfirm6x11.numchars = 96;
494 1.11 tsubai openfirm6x11.encoding = WSDISPLAY_FONTENC_ISO;
495 1.11 tsubai openfirm6x11.fontwidth = char_width;
496 1.11 tsubai openfirm6x11.fontheight = char_height;
497 1.11 tsubai openfirm6x11.stride = 1;
498 1.11 tsubai openfirm6x11.bitorder = WSDISPLAY_FONTORDER_L2R;
499 1.11 tsubai openfirm6x11.byteorder = WSDISPLAY_FONTORDER_L2R;
500 1.11 tsubai openfirm6x11.data = romfont;
501 1.11 tsubai
502 1.11 tsubai return 0;
503 1.11 tsubai }
504 1.11 tsubai
505 1.11 tsubai int
506 1.11 tsubai ofb_getcmap(sc, cm)
507 1.11 tsubai struct ofb_softc *sc;
508 1.11 tsubai struct wsdisplay_cmap *cm;
509 1.11 tsubai {
510 1.11 tsubai u_int index = cm->index;
511 1.11 tsubai u_int count = cm->count;
512 1.11 tsubai int error;
513 1.11 tsubai
514 1.11 tsubai if (index >= 256 || count > 256 || index + count > 256)
515 1.11 tsubai return EINVAL;
516 1.11 tsubai
517 1.11 tsubai error = copyout(&sc->sc_cmap_red[index], cm->red, count);
518 1.11 tsubai if (error)
519 1.11 tsubai return error;
520 1.11 tsubai error = copyout(&sc->sc_cmap_green[index], cm->green, count);
521 1.11 tsubai if (error)
522 1.11 tsubai return error;
523 1.11 tsubai error = copyout(&sc->sc_cmap_blue[index], cm->blue, count);
524 1.11 tsubai if (error)
525 1.11 tsubai return error;
526 1.8 tsubai
527 1.1 tsubai return 0;
528 1.1 tsubai }
529 1.1 tsubai
530 1.1 tsubai int
531 1.11 tsubai ofb_putcmap(sc, cm)
532 1.1 tsubai struct ofb_softc *sc;
533 1.1 tsubai struct wsdisplay_cmap *cm;
534 1.1 tsubai {
535 1.1 tsubai struct ofb_devconfig *dc = sc->sc_dc;
536 1.1 tsubai int index = cm->index;
537 1.1 tsubai int count = cm->count;
538 1.7 tsubai int i;
539 1.1 tsubai u_char *r, *g, *b;
540 1.1 tsubai
541 1.1 tsubai if (cm->index >= 256 || cm->count > 256 ||
542 1.1 tsubai (cm->index + cm->count) > 256)
543 1.1 tsubai return EINVAL;
544 1.1 tsubai if (!uvm_useracc(cm->red, cm->count, B_READ) ||
545 1.1 tsubai !uvm_useracc(cm->green, cm->count, B_READ) ||
546 1.1 tsubai !uvm_useracc(cm->blue, cm->count, B_READ))
547 1.1 tsubai return EFAULT;
548 1.1 tsubai copyin(cm->red, &sc->sc_cmap_red[index], count);
549 1.1 tsubai copyin(cm->green, &sc->sc_cmap_green[index], count);
550 1.1 tsubai copyin(cm->blue, &sc->sc_cmap_blue[index], count);
551 1.1 tsubai
552 1.1 tsubai r = &sc->sc_cmap_red[index];
553 1.1 tsubai g = &sc->sc_cmap_green[index];
554 1.1 tsubai b = &sc->sc_cmap_blue[index];
555 1.1 tsubai
556 1.19 matt #if 0
557 1.1 tsubai for (i = 0; i < count; i++) {
558 1.1 tsubai OF_call_method_1("color!", dc->dc_ih, 4, *r, *g, *b, index);
559 1.1 tsubai r++, g++, b++, index++;
560 1.1 tsubai }
561 1.19 matt #endif
562 1.1 tsubai
563 1.1 tsubai return 0;
564 1.1 tsubai }
565