ofb.c revision 1.45 1 1.44 macallan /* $NetBSD: ofb.c,v 1.45 2006/02/12 21:00:46 macallan 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.36 lukem
30 1.36 lukem #include <sys/cdefs.h>
31 1.44 macallan __KERNEL_RCSID(0, "$NetBSD: ofb.c,v 1.45 2006/02/12 21:00:46 macallan Exp $");
32 1.1 tsubai
33 1.1 tsubai #include <sys/param.h>
34 1.1 tsubai #include <sys/buf.h>
35 1.1 tsubai #include <sys/conf.h>
36 1.1 tsubai #include <sys/device.h>
37 1.1 tsubai #include <sys/ioctl.h>
38 1.1 tsubai #include <sys/kernel.h>
39 1.1 tsubai #include <sys/malloc.h>
40 1.1 tsubai #include <sys/systm.h>
41 1.1 tsubai
42 1.15 mrg #include <uvm/uvm_extern.h>
43 1.11 tsubai
44 1.3 tsubai #include <dev/pci/pcidevs.h>
45 1.1 tsubai #include <dev/pci/pcireg.h>
46 1.1 tsubai #include <dev/pci/pcivar.h>
47 1.27 nathanw #include <dev/pci/pciio.h>
48 1.1 tsubai
49 1.1 tsubai #include <dev/wscons/wsconsio.h>
50 1.1 tsubai #include <dev/wscons/wsdisplayvar.h>
51 1.11 tsubai #include <dev/rasops/rasops.h>
52 1.45 macallan #include <dev/wsfont/wsfont.h>
53 1.1 tsubai
54 1.20 matt #include <dev/ofw/openfirm.h>
55 1.13 tsubai #include <dev/ofw/ofw_pci.h>
56 1.13 tsubai
57 1.1 tsubai #include <machine/bus.h>
58 1.20 matt #include <machine/autoconf.h>
59 1.1 tsubai #include <machine/grfioctl.h>
60 1.37 matt
61 1.37 matt #include <powerpc/oea/bat.h>
62 1.1 tsubai
63 1.45 macallan #include <dev/wscons/wsdisplay_vconsvar.h>
64 1.1 tsubai #include <macppc/dev/ofbvar.h>
65 1.1 tsubai
66 1.18 tsubai #if OFB_ENABLE_CACHE
67 1.18 tsubai int ofb_enable_cache = 1;
68 1.18 tsubai #else
69 1.18 tsubai int ofb_enable_cache = 0;
70 1.18 tsubai #endif
71 1.18 tsubai
72 1.44 macallan static int ofbmatch(struct device *, struct cfdata *, void *);
73 1.44 macallan static void ofbattach(struct device *, struct device *, void *);
74 1.1 tsubai
75 1.32 thorpej CFATTACH_DECL(ofb, sizeof(struct ofb_softc),
76 1.32 thorpej ofbmatch, ofbattach, NULL, NULL);
77 1.1 tsubai
78 1.1 tsubai struct wsscreen_descr ofb_stdscreen = {
79 1.1 tsubai "std",
80 1.1 tsubai 0, 0, /* will be filled in -- XXX shouldn't, it's global */
81 1.11 tsubai 0,
82 1.1 tsubai 0, 0,
83 1.1 tsubai WSSCREEN_REVERSE
84 1.1 tsubai };
85 1.1 tsubai
86 1.1 tsubai const struct wsscreen_descr *_ofb_scrlist[] = {
87 1.1 tsubai &ofb_stdscreen,
88 1.1 tsubai /* XXX other formats, graphics screen? */
89 1.1 tsubai };
90 1.1 tsubai
91 1.1 tsubai struct wsscreen_list ofb_screenlist = {
92 1.1 tsubai sizeof(_ofb_scrlist) / sizeof(struct wsscreen_descr *), _ofb_scrlist
93 1.1 tsubai };
94 1.1 tsubai
95 1.45 macallan static int ofb_ioctl(void *, u_long, caddr_t, int, struct lwp *);
96 1.45 macallan static paddr_t ofb_mmap(void *, off_t, int);
97 1.45 macallan static int copy_rom_font(void);
98 1.45 macallan
99 1.45 macallan static int ofb_init_rasops(int, struct rasops_info *);
100 1.45 macallan static void ofb_init_screen(void *, struct vcons_screen *, int, long *);
101 1.1 tsubai
102 1.1 tsubai struct wsdisplay_accessops ofb_accessops = {
103 1.1 tsubai ofb_ioctl,
104 1.1 tsubai ofb_mmap,
105 1.45 macallan NULL, /* vcons_alloc_screen */
106 1.45 macallan NULL, /* vcons_free_screen */
107 1.45 macallan NULL, /* vcons_show_screen */
108 1.45 macallan NULL /* load_font */
109 1.1 tsubai };
110 1.1 tsubai
111 1.45 macallan static struct vcons_screen ofb_console_screen;
112 1.11 tsubai static struct wsdisplay_font openfirm6x11;
113 1.45 macallan static int console_node, console_instance;
114 1.45 macallan static vaddr_t fbaddr;
115 1.45 macallan static int romfont_loaded = 0;
116 1.45 macallan
117 1.45 macallan static void ofb_putpalreg(struct ofb_softc *, int, uint8_t, uint8_t,
118 1.45 macallan uint8_t);
119 1.45 macallan
120 1.45 macallan static int ofb_getcmap(struct ofb_softc *, struct wsdisplay_cmap *);
121 1.45 macallan static int ofb_putcmap(struct ofb_softc *, struct wsdisplay_cmap *);
122 1.45 macallan static void ofb_init_cmap(struct ofb_softc *);
123 1.11 tsubai
124 1.45 macallan extern const u_char rasops_cmap[768];
125 1.1 tsubai
126 1.45 macallan static int
127 1.44 macallan ofbmatch(struct device *parent, struct cfdata *match, void *aux)
128 1.1 tsubai {
129 1.1 tsubai struct pci_attach_args *pa = aux;
130 1.1 tsubai
131 1.3 tsubai if (PCI_VENDOR(pa->pa_id) == PCI_VENDOR_APPLE &&
132 1.11 tsubai PCI_PRODUCT(pa->pa_id) == PCI_PRODUCT_APPLE_CONTROL)
133 1.3 tsubai return 1;
134 1.1 tsubai
135 1.3 tsubai if (PCI_CLASS(pa->pa_class) == PCI_CLASS_DISPLAY)
136 1.3 tsubai return 1;
137 1.3 tsubai
138 1.3 tsubai return 0;
139 1.1 tsubai }
140 1.1 tsubai
141 1.44 macallan static void
142 1.44 macallan ofbattach(struct device *parent, struct device *self, void *aux)
143 1.1 tsubai {
144 1.22 tsubai struct ofb_softc *sc = (struct ofb_softc *)self;
145 1.1 tsubai struct pci_attach_args *pa = aux;
146 1.1 tsubai struct wsemuldisplaydev_attach_args a;
147 1.45 macallan struct rasops_info *ri = &ofb_console_screen.scr_ri;
148 1.45 macallan long defattr;
149 1.45 macallan int console, len;
150 1.5 tsubai char devinfo[256];
151 1.1 tsubai
152 1.42 macallan sc->sc_memt = pa->pa_memt;
153 1.42 macallan sc->sc_iot = pa->pa_iot;
154 1.45 macallan sc->sc_pc = pa->pa_pc;
155 1.45 macallan sc->sc_pcitag = pa->pa_tag;
156 1.45 macallan sc->sc_mode = WSDISPLAYIO_MODE_EMUL;
157 1.42 macallan
158 1.45 macallan pci_devinfo(pa->pa_id, pa->pa_class, 0, devinfo, sizeof(devinfo));
159 1.45 macallan printf(": %s\n", devinfo);
160 1.45 macallan
161 1.45 macallan vcons_init(&sc->vd, sc, &ofb_stdscreen, &ofb_accessops);
162 1.45 macallan sc->vd.init_screen = ofb_init_screen;
163 1.45 macallan
164 1.1 tsubai console = ofb_is_console();
165 1.1 tsubai
166 1.1 tsubai if (console) {
167 1.45 macallan sc->sc_node = console_node;
168 1.45 macallan sc->sc_ih = console_instance;
169 1.45 macallan vcons_init_screen(&sc->vd, &ofb_console_screen, 1, &defattr);
170 1.45 macallan SCREEN_VISIBLE((&ofb_console_screen));
171 1.45 macallan sc->vd.active = &ofb_console_screen;
172 1.45 macallan ofb_console_screen.scr_flags |= VCONS_SCREEN_IS_STATIC;
173 1.45 macallan printf("%s: %d x %d, %dbpp\n", self->dv_xname,
174 1.45 macallan ri->ri_width, ri->ri_height, ri->ri_depth);
175 1.1 tsubai } else {
176 1.45 macallan char name[64];
177 1.45 macallan sc->sc_node = pcidev_to_ofdev(pa->pa_pc, pa->pa_tag);
178 1.45 macallan if (sc->sc_node == 0) {
179 1.3 tsubai printf(": ofdev not found\n");
180 1.3 tsubai return;
181 1.3 tsubai }
182 1.16 tsubai
183 1.16 tsubai /* XXX There are two child screens on PowerBook. */
184 1.24 wiz memset(devinfo, 0, sizeof(devinfo));
185 1.45 macallan OF_getprop(sc->sc_node, "device_type", devinfo, sizeof(devinfo));
186 1.16 tsubai len = strlen(devinfo);
187 1.16 tsubai if (strcmp(devinfo + len - 7, "-parent") == 0)
188 1.45 macallan sc->sc_node = OF_child(sc->sc_node);
189 1.16 tsubai
190 1.45 macallan memset(name, 0, 64);
191 1.45 macallan OF_package_to_path(sc->sc_node, name, sizeof(name));
192 1.45 macallan sc->sc_ih = OF_open(name);
193 1.45 macallan
194 1.45 macallan }
195 1.45 macallan
196 1.45 macallan sc->sc_fbaddr = 0;
197 1.45 macallan if (OF_getprop(sc->sc_node, "address", &sc->sc_fbaddr, 4) != 4)
198 1.45 macallan OF_interpret("frame-buffer-adr", 1, &sc->sc_fbaddr);
199 1.45 macallan if (sc->sc_fbaddr == 0) {
200 1.45 macallan printf("%s: Unable to find the framebuffer address.\n",
201 1.45 macallan sc->sc_dev.dv_xname);
202 1.45 macallan return;
203 1.1 tsubai }
204 1.45 macallan
205 1.16 tsubai /* XXX */
206 1.45 macallan if (OF_getprop(sc->sc_node, "assigned-addresses", sc->sc_addrs,
207 1.16 tsubai sizeof(sc->sc_addrs)) == -1) {
208 1.45 macallan sc->sc_node = OF_parent(sc->sc_node);
209 1.45 macallan OF_getprop(sc->sc_node, "assigned-addresses", sc->sc_addrs,
210 1.16 tsubai sizeof(sc->sc_addrs));
211 1.16 tsubai }
212 1.13 tsubai
213 1.45 macallan ofb_init_cmap(sc);
214 1.1 tsubai
215 1.1 tsubai a.console = console;
216 1.1 tsubai a.scrdata = &ofb_screenlist;
217 1.1 tsubai a.accessops = &ofb_accessops;
218 1.45 macallan a.accesscookie = &sc->vd;
219 1.1 tsubai
220 1.1 tsubai config_found(self, &a, wsemuldisplaydevprint);
221 1.1 tsubai }
222 1.1 tsubai
223 1.44 macallan static void
224 1.45 macallan ofb_init_screen(void *cookie, struct vcons_screen *scr,
225 1.45 macallan int existing, long *defattr)
226 1.1 tsubai {
227 1.45 macallan struct ofb_softc *sc = cookie;
228 1.45 macallan struct rasops_info *ri = &scr->scr_ri;
229 1.45 macallan
230 1.45 macallan if (scr != &ofb_console_screen) {
231 1.45 macallan ofb_init_rasops(sc->sc_node, ri);
232 1.45 macallan }
233 1.45 macallan }
234 1.1 tsubai
235 1.45 macallan static int
236 1.45 macallan ofb_init_rasops(int node, struct rasops_info *ri)
237 1.45 macallan {
238 1.45 macallan int32_t width, height, linebytes, depth;
239 1.3 tsubai
240 1.8 tsubai /* XXX /chaos/control doesn't have "width", "height", ... */
241 1.3 tsubai width = height = -1;
242 1.11 tsubai if (OF_getprop(node, "width", &width, 4) != 4)
243 1.3 tsubai OF_interpret("screen-width", 1, &width);
244 1.11 tsubai if (OF_getprop(node, "height", &height, 4) != 4)
245 1.3 tsubai OF_interpret("screen-height", 1, &height);
246 1.11 tsubai if (OF_getprop(node, "linebytes", &linebytes, 4) != 4)
247 1.3 tsubai linebytes = width; /* XXX */
248 1.11 tsubai if (OF_getprop(node, "depth", &depth, 4) != 4)
249 1.3 tsubai depth = 8; /* XXX */
250 1.45 macallan if (OF_getprop(node, "address", &fbaddr, 4) != 4)
251 1.45 macallan OF_interpret("frame-buffer-adr", 1, &fbaddr);
252 1.11 tsubai
253 1.45 macallan if (width == -1 || height == -1 || fbaddr == 0 || fbaddr == -1)
254 1.45 macallan return FALSE;
255 1.18 tsubai
256 1.18 tsubai /* Enable write-through cache. */
257 1.29 matt if (ofb_enable_cache) {
258 1.29 matt vaddr_t va;
259 1.29 matt /*
260 1.29 matt * Let's try to find an empty BAT to use
261 1.29 matt */
262 1.29 matt for (va = SEGMENT_LENGTH; va < (USER_SR << ADDR_SR_SHFT);
263 1.29 matt va += SEGMENT_LENGTH) {
264 1.29 matt if (battable[va >> ADDR_SR_SHFT].batu == 0) {
265 1.29 matt battable[va >> ADDR_SR_SHFT].batl =
266 1.45 macallan BATL(fbaddr & 0xf0000000,
267 1.33 briggs BAT_G | BAT_W | BAT_M, BAT_PP_RW);
268 1.29 matt battable[va >> ADDR_SR_SHFT].batu =
269 1.29 matt BATL(va, BAT_BL_256M, BAT_Vs);
270 1.45 macallan fbaddr &= 0x0fffffff;
271 1.45 macallan fbaddr |= va;
272 1.29 matt break;
273 1.29 matt }
274 1.29 matt }
275 1.18 tsubai }
276 1.1 tsubai
277 1.11 tsubai /* initialize rasops */
278 1.11 tsubai ri->ri_width = width;
279 1.11 tsubai ri->ri_height = height;
280 1.11 tsubai ri->ri_depth = depth;
281 1.11 tsubai ri->ri_stride = linebytes;
282 1.45 macallan ri->ri_bits = (char *)fbaddr;
283 1.45 macallan ri->ri_flg = RI_CENTER | RI_FULLCLEAR;
284 1.1 tsubai
285 1.8 tsubai /* If screen is smaller than 1024x768, use small font. */
286 1.45 macallan if ((width < 1024 || height < 768) && (romfont_loaded)) {
287 1.11 tsubai int cols, rows;
288 1.8 tsubai
289 1.45 macallan /*
290 1.45 macallan * XXX this assumes we're the console which may or may not
291 1.45 macallan * be the case
292 1.45 macallan */
293 1.11 tsubai OF_interpret("#lines", 1, &rows);
294 1.11 tsubai OF_interpret("#columns", 1, &cols);
295 1.11 tsubai ri->ri_font = &openfirm6x11;
296 1.11 tsubai ri->ri_wsfcookie = -1; /* not using wsfont */
297 1.11 tsubai rasops_init(ri, rows, cols);
298 1.11 tsubai
299 1.42 macallan ri->ri_xorigin = (width - cols * ri->ri_font->fontwidth) >> 1;
300 1.42 macallan ri->ri_yorigin = (height - rows * ri->ri_font->fontheight)
301 1.42 macallan >> 1;
302 1.45 macallan ri->ri_bits = (char *)fbaddr + ri->ri_xorigin +
303 1.11 tsubai ri->ri_stride * ri->ri_yorigin;
304 1.17 tsubai } else {
305 1.45 macallan /* use as much of the screen as the font permits */
306 1.45 macallan rasops_init(ri, height/8, width/8);
307 1.45 macallan ri->ri_caps = WSSCREEN_WSCOLORS;
308 1.45 macallan rasops_reconfig(ri, height / ri->ri_font->fontheight,
309 1.45 macallan width / ri->ri_font->fontwidth);
310 1.17 tsubai }
311 1.11 tsubai
312 1.45 macallan return TRUE;
313 1.1 tsubai }
314 1.1 tsubai
315 1.1 tsubai int
316 1.1 tsubai ofb_is_console()
317 1.1 tsubai {
318 1.1 tsubai int chosen, stdout, node;
319 1.1 tsubai char type[16];
320 1.1 tsubai
321 1.1 tsubai chosen = OF_finddevice("/chosen");
322 1.1 tsubai OF_getprop(chosen, "stdout", &stdout, 4);
323 1.1 tsubai node = OF_instance_to_package(stdout);
324 1.1 tsubai OF_getprop(node, "device_type", type, sizeof(type));
325 1.1 tsubai if (strcmp(type, "display") == 0)
326 1.1 tsubai return 1;
327 1.1 tsubai else
328 1.1 tsubai return 0;
329 1.1 tsubai }
330 1.1 tsubai
331 1.44 macallan static int
332 1.44 macallan ofb_ioctl(void *v, u_long cmd, caddr_t data, int flag, struct lwp *l)
333 1.1 tsubai {
334 1.45 macallan struct vcons_data *vd = v;
335 1.45 macallan struct ofb_softc *sc = vd->cookie;
336 1.1 tsubai struct wsdisplay_fbinfo *wdf;
337 1.45 macallan struct vcons_screen *ms = vd->active;
338 1.1 tsubai struct grfinfo *gm;
339 1.1 tsubai
340 1.1 tsubai switch (cmd) {
341 1.1 tsubai case WSDISPLAYIO_GTYPE:
342 1.1 tsubai *(u_int *)data = WSDISPLAY_TYPE_PCIMISC; /* XXX ? */
343 1.1 tsubai return 0;
344 1.1 tsubai
345 1.1 tsubai case WSDISPLAYIO_GINFO:
346 1.45 macallan /* we won't get here without any screen anyway */
347 1.45 macallan if (ms != NULL) {
348 1.45 macallan wdf = (void *)data;
349 1.45 macallan wdf->height = ms->scr_ri.ri_width;
350 1.45 macallan wdf->width = ms->scr_ri.ri_height;
351 1.45 macallan wdf->depth = ms->scr_ri.ri_depth;
352 1.45 macallan wdf->cmsize = 256;
353 1.45 macallan return 0;
354 1.45 macallan } else
355 1.45 macallan return ENODEV;
356 1.1 tsubai
357 1.11 tsubai case WSDISPLAYIO_GETCMAP:
358 1.11 tsubai return ofb_getcmap(sc, (struct wsdisplay_cmap *)data);
359 1.11 tsubai
360 1.1 tsubai case WSDISPLAYIO_PUTCMAP:
361 1.11 tsubai return ofb_putcmap(sc, (struct wsdisplay_cmap *)data);
362 1.1 tsubai
363 1.1 tsubai /* XXX There are no way to know framebuffer pa from a user program. */
364 1.1 tsubai case GRFIOCGINFO:
365 1.45 macallan if (ms != NULL) {
366 1.45 macallan gm = (void *)data;
367 1.45 macallan memset(gm, 0, sizeof(struct grfinfo));
368 1.45 macallan gm->gd_fbaddr = (caddr_t)sc->sc_fbaddr;
369 1.45 macallan gm->gd_fbrowbytes = ms->scr_ri.ri_stride;
370 1.45 macallan return 0;
371 1.45 macallan } else
372 1.45 macallan return ENODEV;
373 1.45 macallan case WSDISPLAYIO_SMODE:
374 1.45 macallan {
375 1.45 macallan int new_mode = *(int*)data;
376 1.45 macallan if (new_mode != sc->sc_mode)
377 1.45 macallan {
378 1.45 macallan sc->sc_mode = new_mode;
379 1.45 macallan if (new_mode == WSDISPLAYIO_MODE_EMUL)
380 1.45 macallan {
381 1.45 macallan ofb_init_cmap(sc);
382 1.45 macallan vcons_redraw_screen(ms);
383 1.45 macallan }
384 1.45 macallan }
385 1.45 macallan }
386 1.1 tsubai return 0;
387 1.27 nathanw /* PCI config read/write passthrough. */
388 1.27 nathanw case PCI_IOC_CFGREAD:
389 1.27 nathanw case PCI_IOC_CFGWRITE:
390 1.27 nathanw return (pci_devioctl(sc->sc_pc, sc->sc_pcitag,
391 1.43 christos cmd, data, flag, l));
392 1.1 tsubai }
393 1.26 atatat return EPASSTHROUGH;
394 1.1 tsubai }
395 1.1 tsubai
396 1.44 macallan static paddr_t
397 1.44 macallan ofb_mmap(void *v, off_t offset, int prot)
398 1.1 tsubai {
399 1.45 macallan struct vcons_data *vd = v;
400 1.45 macallan struct ofb_softc *sc = vd->cookie;
401 1.45 macallan struct rasops_info *ri;
402 1.13 tsubai u_int32_t *ap = sc->sc_addrs;
403 1.42 macallan struct proc *me;
404 1.13 tsubai int i;
405 1.13 tsubai
406 1.45 macallan if (vd->active == NULL) {
407 1.45 macallan printf("%s: no active screen.\n", sc->sc_dev.dv_xname);
408 1.45 macallan return -1;
409 1.45 macallan }
410 1.45 macallan
411 1.45 macallan ri = &vd->active->scr_ri;
412 1.45 macallan
413 1.42 macallan /* framebuffer at offset 0 */
414 1.13 tsubai if (offset >=0 && offset < (ri->ri_stride * ri->ri_height))
415 1.45 macallan return sc->sc_fbaddr + offset;
416 1.13 tsubai
417 1.42 macallan /*
418 1.42 macallan * restrict all other mappings to processes with superuser privileges
419 1.42 macallan * or the kernel itself
420 1.42 macallan */
421 1.42 macallan me = __curproc();
422 1.42 macallan if (me != NULL) {
423 1.42 macallan if (suser(me->p_ucred, NULL) != 0) {
424 1.45 macallan printf("%s: mmap() rejected.\n", sc->sc_dev.dv_xname);
425 1.42 macallan return -1;
426 1.42 macallan }
427 1.42 macallan }
428 1.42 macallan
429 1.42 macallan /* let them mmap() 0xa0000 - 0xbffff if it's not covered above */
430 1.42 macallan #ifdef OFB_FAKE_VGA_FB
431 1.42 macallan if (offset >=0xa0000 && offset < 0xbffff)
432 1.45 macallan return sc->sc_fbaddr + offset - 0xa0000;
433 1.42 macallan #endif
434 1.42 macallan
435 1.42 macallan /* allow to map our IO space */
436 1.42 macallan if ((offset >= 0xf2000000) && (offset < 0xf2800000)) {
437 1.42 macallan return bus_space_mmap(sc->sc_iot, offset-0xf2000000, 0, prot,
438 1.42 macallan BUS_SPACE_MAP_LINEAR);
439 1.42 macallan }
440 1.42 macallan
441 1.13 tsubai for (i = 0; i < 6; i++) {
442 1.13 tsubai switch (ap[0] & OFW_PCI_PHYS_HI_SPACEMASK) {
443 1.13 tsubai case OFW_PCI_PHYS_HI_SPACE_MEM32:
444 1.42 macallan if (offset >= ap[2] && offset < ap[2] + ap[4])
445 1.42 macallan return bus_space_mmap(sc->sc_memt, offset, 0,
446 1.42 macallan prot, BUS_SPACE_MAP_LINEAR);
447 1.13 tsubai }
448 1.13 tsubai ap += 5;
449 1.13 tsubai }
450 1.1 tsubai
451 1.13 tsubai return -1;
452 1.1 tsubai }
453 1.1 tsubai
454 1.1 tsubai int
455 1.1 tsubai ofb_cnattach()
456 1.1 tsubai {
457 1.45 macallan struct rasops_info *ri = &ofb_console_screen.scr_ri;
458 1.1 tsubai long defattr;
459 1.11 tsubai int crow = 0;
460 1.1 tsubai int chosen, stdout, node;
461 1.1 tsubai
462 1.1 tsubai chosen = OF_finddevice("/chosen");
463 1.1 tsubai OF_getprop(chosen, "stdout", &stdout, sizeof(stdout));
464 1.1 tsubai node = OF_instance_to_package(stdout);
465 1.45 macallan console_node = node;
466 1.45 macallan console_instance = stdout;
467 1.1 tsubai
468 1.11 tsubai /* get current cursor position */
469 1.11 tsubai OF_interpret("line#", 1, &crow);
470 1.8 tsubai
471 1.11 tsubai /* move (rom monitor) cursor to the lowest line - 1 */
472 1.11 tsubai OF_interpret("#lines 2 - to line#", 0);
473 1.45 macallan
474 1.45 macallan wsfont_init();
475 1.45 macallan if (copy_rom_font() == 0) {
476 1.45 macallan romfont_loaded = 1;
477 1.45 macallan }
478 1.45 macallan
479 1.45 macallan /* set up rasops */
480 1.45 macallan ofb_init_rasops(console_node, ri);
481 1.8 tsubai
482 1.45 macallan /*
483 1.45 macallan * no need to clear the screen here when we're mimicing firmware
484 1.45 macallan * output anyway
485 1.45 macallan */
486 1.45 macallan #if 0
487 1.11 tsubai if (ri->ri_width >= 1024 && ri->ri_height >= 768) {
488 1.11 tsubai int i, screenbytes = ri->ri_stride * ri->ri_height;
489 1.8 tsubai
490 1.8 tsubai for (i = 0; i < screenbytes; i += sizeof(u_int32_t))
491 1.45 macallan *(u_int32_t *)(fbaddr + i) = 0xffffffff;
492 1.8 tsubai crow = 0;
493 1.8 tsubai }
494 1.45 macallan #endif
495 1.45 macallan
496 1.45 macallan ofb_stdscreen.nrows = ri->ri_rows;
497 1.45 macallan ofb_stdscreen.ncols = ri->ri_cols;
498 1.45 macallan ofb_stdscreen.textops = &ri->ri_ops;
499 1.45 macallan ofb_stdscreen.capabilities = ri->ri_caps;
500 1.8 tsubai
501 1.45 macallan ri->ri_ops.allocattr(ri, 0, 0, 0, &defattr);
502 1.11 tsubai wsdisplay_cnattach(&ofb_stdscreen, ri, 0, crow, defattr);
503 1.8 tsubai
504 1.8 tsubai return 0;
505 1.8 tsubai }
506 1.8 tsubai
507 1.44 macallan static int
508 1.8 tsubai copy_rom_font()
509 1.8 tsubai {
510 1.8 tsubai u_char *romfont;
511 1.8 tsubai int char_width, char_height;
512 1.8 tsubai int chosen, mmu, m, e;
513 1.8 tsubai
514 1.8 tsubai /* Get ROM FONT address. */
515 1.8 tsubai OF_interpret("font-adr", 1, &romfont);
516 1.8 tsubai if (romfont == NULL)
517 1.8 tsubai return -1;
518 1.8 tsubai
519 1.8 tsubai chosen = OF_finddevice("/chosen");
520 1.8 tsubai OF_getprop(chosen, "mmu", &mmu, 4);
521 1.1 tsubai
522 1.8 tsubai /*
523 1.8 tsubai * Convert to physcal address. We cannot access to Open Firmware's
524 1.8 tsubai * virtual address space.
525 1.8 tsubai */
526 1.8 tsubai OF_call_method("translate", mmu, 1, 3, romfont, &romfont, &m, &e);
527 1.8 tsubai
528 1.8 tsubai /* Get character size */
529 1.8 tsubai OF_interpret("char-width", 1, &char_width);
530 1.8 tsubai OF_interpret("char-height", 1, &char_height);
531 1.8 tsubai
532 1.11 tsubai openfirm6x11.name = "Open Firmware";
533 1.11 tsubai openfirm6x11.firstchar = 32;
534 1.11 tsubai openfirm6x11.numchars = 96;
535 1.11 tsubai openfirm6x11.encoding = WSDISPLAY_FONTENC_ISO;
536 1.11 tsubai openfirm6x11.fontwidth = char_width;
537 1.11 tsubai openfirm6x11.fontheight = char_height;
538 1.11 tsubai openfirm6x11.stride = 1;
539 1.11 tsubai openfirm6x11.bitorder = WSDISPLAY_FONTORDER_L2R;
540 1.11 tsubai openfirm6x11.byteorder = WSDISPLAY_FONTORDER_L2R;
541 1.11 tsubai openfirm6x11.data = romfont;
542 1.11 tsubai
543 1.11 tsubai return 0;
544 1.11 tsubai }
545 1.11 tsubai
546 1.44 macallan static int
547 1.44 macallan ofb_getcmap(struct ofb_softc *sc, struct wsdisplay_cmap *cm)
548 1.11 tsubai {
549 1.11 tsubai u_int index = cm->index;
550 1.11 tsubai u_int count = cm->count;
551 1.11 tsubai int error;
552 1.11 tsubai
553 1.11 tsubai if (index >= 256 || count > 256 || index + count > 256)
554 1.11 tsubai return EINVAL;
555 1.11 tsubai
556 1.11 tsubai error = copyout(&sc->sc_cmap_red[index], cm->red, count);
557 1.11 tsubai if (error)
558 1.11 tsubai return error;
559 1.11 tsubai error = copyout(&sc->sc_cmap_green[index], cm->green, count);
560 1.11 tsubai if (error)
561 1.11 tsubai return error;
562 1.11 tsubai error = copyout(&sc->sc_cmap_blue[index], cm->blue, count);
563 1.11 tsubai if (error)
564 1.11 tsubai return error;
565 1.8 tsubai
566 1.1 tsubai return 0;
567 1.1 tsubai }
568 1.1 tsubai
569 1.45 macallan int
570 1.44 macallan ofb_putcmap(struct ofb_softc *sc, struct wsdisplay_cmap *cm)
571 1.1 tsubai {
572 1.25 jdolecek u_int index = cm->index;
573 1.25 jdolecek u_int count = cm->count;
574 1.38 chs int i, error;
575 1.38 chs u_char rbuf[256], gbuf[256], bbuf[256];
576 1.1 tsubai u_char *r, *g, *b;
577 1.1 tsubai
578 1.1 tsubai if (cm->index >= 256 || cm->count > 256 ||
579 1.1 tsubai (cm->index + cm->count) > 256)
580 1.1 tsubai return EINVAL;
581 1.38 chs error = copyin(cm->red, &rbuf[index], count);
582 1.38 chs if (error)
583 1.38 chs return error;
584 1.38 chs error = copyin(cm->green, &gbuf[index], count);
585 1.38 chs if (error)
586 1.38 chs return error;
587 1.38 chs error = copyin(cm->blue, &bbuf[index], count);
588 1.38 chs if (error)
589 1.38 chs return error;
590 1.38 chs
591 1.38 chs memcpy(&sc->sc_cmap_red[index], &rbuf[index], count);
592 1.38 chs memcpy(&sc->sc_cmap_green[index], &gbuf[index], count);
593 1.38 chs memcpy(&sc->sc_cmap_blue[index], &bbuf[index], count);
594 1.1 tsubai
595 1.1 tsubai r = &sc->sc_cmap_red[index];
596 1.1 tsubai g = &sc->sc_cmap_green[index];
597 1.1 tsubai b = &sc->sc_cmap_blue[index];
598 1.1 tsubai for (i = 0; i < count; i++) {
599 1.45 macallan OF_call_method_1("color!", sc->sc_ih, 4, *r, *g, *b, index);
600 1.1 tsubai r++, g++, b++, index++;
601 1.1 tsubai }
602 1.1 tsubai return 0;
603 1.1 tsubai }
604 1.45 macallan
605 1.45 macallan static void
606 1.45 macallan ofb_putpalreg(struct ofb_softc *sc, int idx, uint8_t r, uint8_t g, uint8_t b)
607 1.45 macallan {
608 1.45 macallan if ((idx<0) || (idx > 255))
609 1.45 macallan return;
610 1.45 macallan OF_call_method_1("color!", sc->sc_ih, 4, r, g, b, idx);
611 1.45 macallan sc->sc_cmap_red[idx] = r;
612 1.45 macallan sc->sc_cmap_green[idx] = g;
613 1.45 macallan sc->sc_cmap_blue[idx] = b;
614 1.45 macallan }
615 1.45 macallan
616 1.45 macallan static void
617 1.45 macallan ofb_init_cmap(struct ofb_softc *sc)
618 1.45 macallan {
619 1.45 macallan int idx, i;
620 1.45 macallan /* mess with the palette only when we're running in 8 bit */
621 1.45 macallan if (ofb_console_screen.scr_ri.ri_depth == 8) {
622 1.45 macallan idx = 0;
623 1.45 macallan for (i = 0; i < 256; i++) {
624 1.45 macallan ofb_putpalreg(sc, i, rasops_cmap[idx],
625 1.45 macallan rasops_cmap[idx + 1], rasops_cmap[idx + 2]);
626 1.45 macallan idx += 3;
627 1.45 macallan }
628 1.45 macallan }
629 1.45 macallan }
630