1/*- 2 * Copyright (c) 2011 Nathan Whitehorn 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright 9 * notice, this list of conditions and the following disclaimer. 10 * 2. Redistributions in binary form must reproduce the above copyright 11 * notice, this list of conditions and the following disclaimer in the 12 * documentation and/or other materials provided with the distribution. 13 * 14 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 15 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 17 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 18 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 19 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 24 * SUCH DAMAGE. 25 */ 26 27#include <sys/cdefs.h>
| 1/*- 2 * Copyright (c) 2011 Nathan Whitehorn 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright 9 * notice, this list of conditions and the following disclaimer. 10 * 2. Redistributions in binary form must reproduce the above copyright 11 * notice, this list of conditions and the following disclaimer in the 12 * documentation and/or other materials provided with the distribution. 13 * 14 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 15 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 17 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 18 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 19 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 24 * SUCH DAMAGE. 25 */ 26 27#include <sys/cdefs.h>
|
29 30#include <sys/param.h> 31#include <sys/kernel.h> 32#include <sys/systm.h> 33#include <sys/fbio.h> 34 35#include <dev/vt/vt.h> 36#include <dev/vt/hw/fb/vt_fb.h> 37#include <dev/vt/colors/vt_termcolors.h> 38 39#include <vm/vm.h> 40#include <vm/pmap.h> 41 42#include <machine/bus.h> 43#ifdef __sparc64__ 44#include <machine/bus_private.h> 45#endif 46 47#include <dev/ofw/openfirm.h> 48#include <dev/ofw/ofw_bus.h> 49#include <dev/ofw/ofw_pci.h> 50 51struct ofwfb_softc { 52 struct fb_info fb; 53 54 phandle_t sc_node; 55 ihandle_t sc_handle; 56 bus_space_tag_t sc_memt; 57}; 58 59static vd_probe_t ofwfb_probe; 60static vd_init_t ofwfb_init; 61static vd_bitblt_text_t ofwfb_bitblt_text; 62static vd_bitblt_bmp_t ofwfb_bitblt_bitmap; 63 64static const struct vt_driver vt_ofwfb_driver = { 65 .vd_name = "ofwfb", 66 .vd_probe = ofwfb_probe, 67 .vd_init = ofwfb_init, 68 .vd_blank = vt_fb_blank, 69 .vd_bitblt_text = ofwfb_bitblt_text, 70 .vd_bitblt_bmp = ofwfb_bitblt_bitmap, 71 .vd_fb_ioctl = vt_fb_ioctl, 72 .vd_fb_mmap = vt_fb_mmap, 73 .vd_priority = VD_PRIORITY_GENERIC+1, 74}; 75 76static struct ofwfb_softc ofwfb_conssoftc; 77VT_DRIVER_DECLARE(vt_ofwfb, vt_ofwfb_driver); 78 79static int 80ofwfb_probe(struct vt_device *vd) 81{ 82 phandle_t chosen, node; 83 ihandle_t stdout; 84 char type[64]; 85 86 chosen = OF_finddevice("/chosen"); 87 OF_getprop(chosen, "stdout", &stdout, sizeof(stdout)); 88 node = OF_instance_to_package(stdout); 89 if (node == -1) { 90 /* 91 * The "/chosen/stdout" does not exist try 92 * using "screen" directly. 93 */ 94 node = OF_finddevice("screen"); 95 } 96 OF_getprop(node, "device_type", type, sizeof(type)); 97 if (strcmp(type, "display") != 0) 98 return (CN_DEAD); 99 100 /* Looks OK... */ 101 return (CN_INTERNAL); 102} 103 104static void 105ofwfb_bitblt_bitmap(struct vt_device *vd, const struct vt_window *vw, 106 const uint8_t *pattern, const uint8_t *mask, 107 unsigned int width, unsigned int height, 108 unsigned int x, unsigned int y, term_color_t fg, term_color_t bg) 109{ 110 struct fb_info *sc = vd->vd_softc; 111 u_long line; 112 uint32_t fgc, bgc; 113 int c; 114 uint8_t b, m; 115 union { 116 uint32_t l; 117 uint8_t c[4]; 118 } ch1, ch2; 119 120 fgc = sc->fb_cmap[fg]; 121 bgc = sc->fb_cmap[bg]; 122 b = m = 0; 123 124 /* Don't try to put off screen pixels */ 125 if (((x + width) > vd->vd_width) || ((y + height) > 126 vd->vd_height)) 127 return; 128 129 line = (sc->fb_stride * y) + x * sc->fb_bpp/8; 130 if (mask == NULL && sc->fb_bpp == 8 && (width % 8 == 0)) { 131 for (; height > 0; height--) { 132 for (c = 0; c < width; c += 8) { 133 b = *pattern++; 134 135 /* 136 * Assume that there is more background than 137 * foreground in characters and init accordingly 138 */ 139 ch1.l = ch2.l = (bg << 24) | (bg << 16) | 140 (bg << 8) | bg; 141 142 /* 143 * Calculate 2 x 4-chars at a time, and then 144 * write these out. 145 */ 146 if (b & 0x80) ch1.c[0] = fg; 147 if (b & 0x40) ch1.c[1] = fg; 148 if (b & 0x20) ch1.c[2] = fg; 149 if (b & 0x10) ch1.c[3] = fg; 150 151 if (b & 0x08) ch2.c[0] = fg; 152 if (b & 0x04) ch2.c[1] = fg; 153 if (b & 0x02) ch2.c[2] = fg; 154 if (b & 0x01) ch2.c[3] = fg; 155 156 *(uint32_t *)(sc->fb_vbase + line + c) = ch1.l; 157 *(uint32_t *)(sc->fb_vbase + line + c + 4) = 158 ch2.l; 159 } 160 line += sc->fb_stride; 161 } 162 } else { 163 for (; height > 0; height--) { 164 for (c = 0; c < width; c++) { 165 if (c % 8 == 0) 166 b = *pattern++; 167 else 168 b <<= 1; 169 if (mask != NULL) { 170 if (c % 8 == 0) 171 m = *mask++; 172 else 173 m <<= 1; 174 /* Skip pixel write, if mask not set. */ 175 if ((m & 0x80) == 0) 176 continue; 177 } 178 switch(sc->fb_bpp) { 179 case 8: 180 *(uint8_t *)(sc->fb_vbase + line + c) = 181 b & 0x80 ? fg : bg; 182 break; 183 case 32: 184 *(uint32_t *)(sc->fb_vbase + line + 4*c) 185 = (b & 0x80) ? fgc : bgc; 186 break; 187 default: 188 /* panic? */ 189 break; 190 } 191 } 192 line += sc->fb_stride; 193 } 194 } 195} 196 197void 198ofwfb_bitblt_text(struct vt_device *vd, const struct vt_window *vw, 199 const term_rect_t *area) 200{ 201 unsigned int col, row, x, y; 202 struct vt_font *vf; 203 term_char_t c; 204 term_color_t fg, bg; 205 const uint8_t *pattern; 206 207 vf = vw->vw_font; 208 209 for (row = area->tr_begin.tp_row; row < area->tr_end.tp_row; ++row) { 210 for (col = area->tr_begin.tp_col; col < area->tr_end.tp_col; 211 ++col) {
| 29 30#include <sys/param.h> 31#include <sys/kernel.h> 32#include <sys/systm.h> 33#include <sys/fbio.h> 34 35#include <dev/vt/vt.h> 36#include <dev/vt/hw/fb/vt_fb.h> 37#include <dev/vt/colors/vt_termcolors.h> 38 39#include <vm/vm.h> 40#include <vm/pmap.h> 41 42#include <machine/bus.h> 43#ifdef __sparc64__ 44#include <machine/bus_private.h> 45#endif 46 47#include <dev/ofw/openfirm.h> 48#include <dev/ofw/ofw_bus.h> 49#include <dev/ofw/ofw_pci.h> 50 51struct ofwfb_softc { 52 struct fb_info fb; 53 54 phandle_t sc_node; 55 ihandle_t sc_handle; 56 bus_space_tag_t sc_memt; 57}; 58 59static vd_probe_t ofwfb_probe; 60static vd_init_t ofwfb_init; 61static vd_bitblt_text_t ofwfb_bitblt_text; 62static vd_bitblt_bmp_t ofwfb_bitblt_bitmap; 63 64static const struct vt_driver vt_ofwfb_driver = { 65 .vd_name = "ofwfb", 66 .vd_probe = ofwfb_probe, 67 .vd_init = ofwfb_init, 68 .vd_blank = vt_fb_blank, 69 .vd_bitblt_text = ofwfb_bitblt_text, 70 .vd_bitblt_bmp = ofwfb_bitblt_bitmap, 71 .vd_fb_ioctl = vt_fb_ioctl, 72 .vd_fb_mmap = vt_fb_mmap, 73 .vd_priority = VD_PRIORITY_GENERIC+1, 74}; 75 76static struct ofwfb_softc ofwfb_conssoftc; 77VT_DRIVER_DECLARE(vt_ofwfb, vt_ofwfb_driver); 78 79static int 80ofwfb_probe(struct vt_device *vd) 81{ 82 phandle_t chosen, node; 83 ihandle_t stdout; 84 char type[64]; 85 86 chosen = OF_finddevice("/chosen"); 87 OF_getprop(chosen, "stdout", &stdout, sizeof(stdout)); 88 node = OF_instance_to_package(stdout); 89 if (node == -1) { 90 /* 91 * The "/chosen/stdout" does not exist try 92 * using "screen" directly. 93 */ 94 node = OF_finddevice("screen"); 95 } 96 OF_getprop(node, "device_type", type, sizeof(type)); 97 if (strcmp(type, "display") != 0) 98 return (CN_DEAD); 99 100 /* Looks OK... */ 101 return (CN_INTERNAL); 102} 103 104static void 105ofwfb_bitblt_bitmap(struct vt_device *vd, const struct vt_window *vw, 106 const uint8_t *pattern, const uint8_t *mask, 107 unsigned int width, unsigned int height, 108 unsigned int x, unsigned int y, term_color_t fg, term_color_t bg) 109{ 110 struct fb_info *sc = vd->vd_softc; 111 u_long line; 112 uint32_t fgc, bgc; 113 int c; 114 uint8_t b, m; 115 union { 116 uint32_t l; 117 uint8_t c[4]; 118 } ch1, ch2; 119 120 fgc = sc->fb_cmap[fg]; 121 bgc = sc->fb_cmap[bg]; 122 b = m = 0; 123 124 /* Don't try to put off screen pixels */ 125 if (((x + width) > vd->vd_width) || ((y + height) > 126 vd->vd_height)) 127 return; 128 129 line = (sc->fb_stride * y) + x * sc->fb_bpp/8; 130 if (mask == NULL && sc->fb_bpp == 8 && (width % 8 == 0)) { 131 for (; height > 0; height--) { 132 for (c = 0; c < width; c += 8) { 133 b = *pattern++; 134 135 /* 136 * Assume that there is more background than 137 * foreground in characters and init accordingly 138 */ 139 ch1.l = ch2.l = (bg << 24) | (bg << 16) | 140 (bg << 8) | bg; 141 142 /* 143 * Calculate 2 x 4-chars at a time, and then 144 * write these out. 145 */ 146 if (b & 0x80) ch1.c[0] = fg; 147 if (b & 0x40) ch1.c[1] = fg; 148 if (b & 0x20) ch1.c[2] = fg; 149 if (b & 0x10) ch1.c[3] = fg; 150 151 if (b & 0x08) ch2.c[0] = fg; 152 if (b & 0x04) ch2.c[1] = fg; 153 if (b & 0x02) ch2.c[2] = fg; 154 if (b & 0x01) ch2.c[3] = fg; 155 156 *(uint32_t *)(sc->fb_vbase + line + c) = ch1.l; 157 *(uint32_t *)(sc->fb_vbase + line + c + 4) = 158 ch2.l; 159 } 160 line += sc->fb_stride; 161 } 162 } else { 163 for (; height > 0; height--) { 164 for (c = 0; c < width; c++) { 165 if (c % 8 == 0) 166 b = *pattern++; 167 else 168 b <<= 1; 169 if (mask != NULL) { 170 if (c % 8 == 0) 171 m = *mask++; 172 else 173 m <<= 1; 174 /* Skip pixel write, if mask not set. */ 175 if ((m & 0x80) == 0) 176 continue; 177 } 178 switch(sc->fb_bpp) { 179 case 8: 180 *(uint8_t *)(sc->fb_vbase + line + c) = 181 b & 0x80 ? fg : bg; 182 break; 183 case 32: 184 *(uint32_t *)(sc->fb_vbase + line + 4*c) 185 = (b & 0x80) ? fgc : bgc; 186 break; 187 default: 188 /* panic? */ 189 break; 190 } 191 } 192 line += sc->fb_stride; 193 } 194 } 195} 196 197void 198ofwfb_bitblt_text(struct vt_device *vd, const struct vt_window *vw, 199 const term_rect_t *area) 200{ 201 unsigned int col, row, x, y; 202 struct vt_font *vf; 203 term_char_t c; 204 term_color_t fg, bg; 205 const uint8_t *pattern; 206 207 vf = vw->vw_font; 208 209 for (row = area->tr_begin.tp_row; row < area->tr_end.tp_row; ++row) { 210 for (col = area->tr_begin.tp_col; col < area->tr_end.tp_col; 211 ++col) {
|
240 241 if (vt_is_cursor_in_area(vd, &drawn_area)) { 242 ofwfb_bitblt_bitmap(vd, vw, 243 vd->vd_mcursor->map, vd->vd_mcursor->mask, 244 vd->vd_mcursor->width, vd->vd_mcursor->height, 245 vd->vd_mx_drawn, vd->vd_my_drawn, 246 vd->vd_mcursor_fg, vd->vd_mcursor_bg); 247 } 248#endif 249} 250 251static void 252ofwfb_initialize(struct vt_device *vd) 253{ 254 struct ofwfb_softc *sc = vd->vd_softc; 255 int i; 256 cell_t retval; 257 uint32_t oldpix; 258 259 /* 260 * Set up the color map 261 */ 262 263 switch (sc->fb.fb_bpp) { 264 case 8: 265 vt_generate_cons_palette(sc->fb.fb_cmap, COLOR_FORMAT_RGB, 255, 266 16, 255, 8, 255, 0); 267 268 for (i = 0; i < 16; i++) { 269 OF_call_method("color!", sc->sc_handle, 4, 1, 270 (cell_t)((sc->fb.fb_cmap[i] >> 16) & 0xff), 271 (cell_t)((sc->fb.fb_cmap[i] >> 8) & 0xff), 272 (cell_t)((sc->fb.fb_cmap[i] >> 0) & 0xff), 273 (cell_t)i, &retval); 274 } 275 break; 276 277 case 32: 278 /* 279 * We bypass the usual bus_space_() accessors here, mostly 280 * for performance reasons. In particular, we don't want 281 * any barrier operations that may be performed and handle 282 * endianness slightly different. Figure out the host-view 283 * endianness of the frame buffer. 284 */ 285 oldpix = bus_space_read_4(sc->sc_memt, sc->fb.fb_vbase, 0); 286 bus_space_write_4(sc->sc_memt, sc->fb.fb_vbase, 0, 0xff000000); 287 if (*(uint8_t *)(sc->fb.fb_vbase) == 0xff) 288 vt_generate_cons_palette(sc->fb.fb_cmap, 289 COLOR_FORMAT_RGB, 255, 0, 255, 8, 255, 16); 290 else 291 vt_generate_cons_palette(sc->fb.fb_cmap, 292 COLOR_FORMAT_RGB, 255, 16, 255, 8, 255, 0); 293 bus_space_write_4(sc->sc_memt, sc->fb.fb_vbase, 0, oldpix); 294 break; 295 296 default: 297 panic("Unknown color space depth %d", sc->fb.fb_bpp); 298 break; 299 } 300 301 sc->fb.fb_cmsize = 16; 302} 303 304static int 305ofwfb_init(struct vt_device *vd) 306{ 307 struct ofwfb_softc *sc; 308 char type[64]; 309 phandle_t chosen; 310 phandle_t node; 311 uint32_t depth, height, width, stride; 312 uint32_t fb_phys; 313 int i, len; 314#ifdef __sparc64__ 315 static struct bus_space_tag ofwfb_memt[1]; 316 bus_addr_t phys; 317 int space; 318#endif 319 320 /* Initialize softc */ 321 vd->vd_softc = sc = &ofwfb_conssoftc; 322 323 chosen = OF_finddevice("/chosen"); 324 OF_getprop(chosen, "stdout", &sc->sc_handle, sizeof(ihandle_t)); 325 node = OF_instance_to_package(sc->sc_handle); 326 if (node == -1) { 327 /* 328 * The "/chosen/stdout" does not exist try 329 * using "screen" directly. 330 */ 331 node = OF_finddevice("screen"); 332 sc->sc_handle = OF_open("screen"); 333 } 334 OF_getprop(node, "device_type", type, sizeof(type)); 335 if (strcmp(type, "display") != 0) 336 return (CN_DEAD); 337 338 /* Keep track of the OF node */ 339 sc->sc_node = node; 340 341 /* 342 * Try to use a 32-bit framebuffer if possible. This may be 343 * unimplemented and fail. That's fine -- it just means we are 344 * stuck with the defaults. 345 */ 346 OF_call_method("set-depth", sc->sc_handle, 1, 1, (cell_t)32, &i); 347 348 /* Make sure we have needed properties */ 349 if (OF_getproplen(node, "height") != sizeof(height) || 350 OF_getproplen(node, "width") != sizeof(width) || 351 OF_getproplen(node, "depth") != sizeof(depth) || 352 OF_getproplen(node, "linebytes") != sizeof(sc->fb.fb_stride)) 353 return (CN_DEAD); 354 355 /* Only support 8 and 32-bit framebuffers */ 356 OF_getprop(node, "depth", &depth, sizeof(depth)); 357 if (depth != 8 && depth != 32) 358 return (CN_DEAD); 359 sc->fb.fb_bpp = sc->fb.fb_depth = depth; 360 361 OF_getprop(node, "height", &height, sizeof(height)); 362 OF_getprop(node, "width", &width, sizeof(width)); 363 OF_getprop(node, "linebytes", &stride, sizeof(stride)); 364 365 sc->fb.fb_height = height; 366 sc->fb.fb_width = width; 367 sc->fb.fb_stride = stride; 368 sc->fb.fb_size = sc->fb.fb_height * sc->fb.fb_stride; 369 370 /* 371 * Grab the physical address of the framebuffer, and then map it 372 * into our memory space. If the MMU is not yet up, it will be 373 * remapped for us when relocation turns on. 374 */ 375 if (OF_getproplen(node, "address") == sizeof(fb_phys)) { 376 /* XXX We assume #address-cells is 1 at this point. */ 377 OF_getprop(node, "address", &fb_phys, sizeof(fb_phys)); 378 379 #if defined(__powerpc__) 380 sc->sc_memt = &bs_be_tag; 381 bus_space_map(sc->sc_memt, fb_phys, sc->fb.fb_size, 382 BUS_SPACE_MAP_PREFETCHABLE, &sc->fb.fb_vbase); 383 #elif defined(__sparc64__) 384 OF_decode_addr(node, 0, &space, &phys); 385 sc->sc_memt = &ofwfb_memt[0]; 386 sc->fb.fb_vbase = 387 sparc64_fake_bustag(space, fb_phys, sc->sc_memt); 388 #elif defined(__arm__) 389 sc->sc_memt = fdtbus_bs_tag; 390 bus_space_map(sc->sc_memt, sc->fb.fb_pbase, sc->fb.fb_size, 391 BUS_SPACE_MAP_PREFETCHABLE, 392 (bus_space_handle_t *)&sc->fb.fb_vbase); 393 #else 394 #error Unsupported platform! 395 #endif 396 397 sc->fb.fb_pbase = fb_phys; 398 } else { 399 /* 400 * Some IBM systems don't have an address property. Try to 401 * guess the framebuffer region from the assigned addresses. 402 * This is ugly, but there doesn't seem to be an alternative. 403 * Linux does the same thing. 404 */ 405 406 struct ofw_pci_register pciaddrs[8]; 407 int num_pciaddrs = 0; 408 409 /* 410 * Get the PCI addresses of the adapter, if present. The node 411 * may be the child of the PCI device: in that case, try the 412 * parent for the assigned-addresses property. 413 */ 414 len = OF_getprop(node, "assigned-addresses", pciaddrs, 415 sizeof(pciaddrs)); 416 if (len == -1) { 417 len = OF_getprop(OF_parent(node), "assigned-addresses", 418 pciaddrs, sizeof(pciaddrs)); 419 } 420 if (len == -1) 421 len = 0; 422 num_pciaddrs = len / sizeof(struct ofw_pci_register); 423 424 fb_phys = num_pciaddrs; 425 for (i = 0; i < num_pciaddrs; i++) { 426 /* If it is too small, not the framebuffer */ 427 if (pciaddrs[i].size_lo < sc->fb.fb_stride * height) 428 continue; 429 /* If it is not memory, it isn't either */ 430 if (!(pciaddrs[i].phys_hi & 431 OFW_PCI_PHYS_HI_SPACE_MEM32)) 432 continue; 433 434 /* This could be the framebuffer */ 435 fb_phys = i; 436 437 /* If it is prefetchable, it certainly is */ 438 if (pciaddrs[i].phys_hi & OFW_PCI_PHYS_HI_PREFETCHABLE) 439 break; 440 } 441 442 if (fb_phys == num_pciaddrs) /* No candidates found */ 443 return (CN_DEAD); 444 445 #if defined(__powerpc__) 446 OF_decode_addr(node, fb_phys, &sc->sc_memt, &sc->fb.fb_vbase); 447 sc->fb.fb_pbase = sc->fb.fb_vbase; /* 1:1 mapped */ 448 #else 449 /* No ability to interpret assigned-addresses otherwise */ 450 return (CN_DEAD); 451 #endif 452 } 453 454 455 ofwfb_initialize(vd); 456 vt_fb_init(vd); 457 458 return (CN_INTERNAL); 459} 460
| 242 243 if (vt_is_cursor_in_area(vd, &drawn_area)) { 244 ofwfb_bitblt_bitmap(vd, vw, 245 vd->vd_mcursor->map, vd->vd_mcursor->mask, 246 vd->vd_mcursor->width, vd->vd_mcursor->height, 247 vd->vd_mx_drawn, vd->vd_my_drawn, 248 vd->vd_mcursor_fg, vd->vd_mcursor_bg); 249 } 250#endif 251} 252 253static void 254ofwfb_initialize(struct vt_device *vd) 255{ 256 struct ofwfb_softc *sc = vd->vd_softc; 257 int i; 258 cell_t retval; 259 uint32_t oldpix; 260 261 /* 262 * Set up the color map 263 */ 264 265 switch (sc->fb.fb_bpp) { 266 case 8: 267 vt_generate_cons_palette(sc->fb.fb_cmap, COLOR_FORMAT_RGB, 255, 268 16, 255, 8, 255, 0); 269 270 for (i = 0; i < 16; i++) { 271 OF_call_method("color!", sc->sc_handle, 4, 1, 272 (cell_t)((sc->fb.fb_cmap[i] >> 16) & 0xff), 273 (cell_t)((sc->fb.fb_cmap[i] >> 8) & 0xff), 274 (cell_t)((sc->fb.fb_cmap[i] >> 0) & 0xff), 275 (cell_t)i, &retval); 276 } 277 break; 278 279 case 32: 280 /* 281 * We bypass the usual bus_space_() accessors here, mostly 282 * for performance reasons. In particular, we don't want 283 * any barrier operations that may be performed and handle 284 * endianness slightly different. Figure out the host-view 285 * endianness of the frame buffer. 286 */ 287 oldpix = bus_space_read_4(sc->sc_memt, sc->fb.fb_vbase, 0); 288 bus_space_write_4(sc->sc_memt, sc->fb.fb_vbase, 0, 0xff000000); 289 if (*(uint8_t *)(sc->fb.fb_vbase) == 0xff) 290 vt_generate_cons_palette(sc->fb.fb_cmap, 291 COLOR_FORMAT_RGB, 255, 0, 255, 8, 255, 16); 292 else 293 vt_generate_cons_palette(sc->fb.fb_cmap, 294 COLOR_FORMAT_RGB, 255, 16, 255, 8, 255, 0); 295 bus_space_write_4(sc->sc_memt, sc->fb.fb_vbase, 0, oldpix); 296 break; 297 298 default: 299 panic("Unknown color space depth %d", sc->fb.fb_bpp); 300 break; 301 } 302 303 sc->fb.fb_cmsize = 16; 304} 305 306static int 307ofwfb_init(struct vt_device *vd) 308{ 309 struct ofwfb_softc *sc; 310 char type[64]; 311 phandle_t chosen; 312 phandle_t node; 313 uint32_t depth, height, width, stride; 314 uint32_t fb_phys; 315 int i, len; 316#ifdef __sparc64__ 317 static struct bus_space_tag ofwfb_memt[1]; 318 bus_addr_t phys; 319 int space; 320#endif 321 322 /* Initialize softc */ 323 vd->vd_softc = sc = &ofwfb_conssoftc; 324 325 chosen = OF_finddevice("/chosen"); 326 OF_getprop(chosen, "stdout", &sc->sc_handle, sizeof(ihandle_t)); 327 node = OF_instance_to_package(sc->sc_handle); 328 if (node == -1) { 329 /* 330 * The "/chosen/stdout" does not exist try 331 * using "screen" directly. 332 */ 333 node = OF_finddevice("screen"); 334 sc->sc_handle = OF_open("screen"); 335 } 336 OF_getprop(node, "device_type", type, sizeof(type)); 337 if (strcmp(type, "display") != 0) 338 return (CN_DEAD); 339 340 /* Keep track of the OF node */ 341 sc->sc_node = node; 342 343 /* 344 * Try to use a 32-bit framebuffer if possible. This may be 345 * unimplemented and fail. That's fine -- it just means we are 346 * stuck with the defaults. 347 */ 348 OF_call_method("set-depth", sc->sc_handle, 1, 1, (cell_t)32, &i); 349 350 /* Make sure we have needed properties */ 351 if (OF_getproplen(node, "height") != sizeof(height) || 352 OF_getproplen(node, "width") != sizeof(width) || 353 OF_getproplen(node, "depth") != sizeof(depth) || 354 OF_getproplen(node, "linebytes") != sizeof(sc->fb.fb_stride)) 355 return (CN_DEAD); 356 357 /* Only support 8 and 32-bit framebuffers */ 358 OF_getprop(node, "depth", &depth, sizeof(depth)); 359 if (depth != 8 && depth != 32) 360 return (CN_DEAD); 361 sc->fb.fb_bpp = sc->fb.fb_depth = depth; 362 363 OF_getprop(node, "height", &height, sizeof(height)); 364 OF_getprop(node, "width", &width, sizeof(width)); 365 OF_getprop(node, "linebytes", &stride, sizeof(stride)); 366 367 sc->fb.fb_height = height; 368 sc->fb.fb_width = width; 369 sc->fb.fb_stride = stride; 370 sc->fb.fb_size = sc->fb.fb_height * sc->fb.fb_stride; 371 372 /* 373 * Grab the physical address of the framebuffer, and then map it 374 * into our memory space. If the MMU is not yet up, it will be 375 * remapped for us when relocation turns on. 376 */ 377 if (OF_getproplen(node, "address") == sizeof(fb_phys)) { 378 /* XXX We assume #address-cells is 1 at this point. */ 379 OF_getprop(node, "address", &fb_phys, sizeof(fb_phys)); 380 381 #if defined(__powerpc__) 382 sc->sc_memt = &bs_be_tag; 383 bus_space_map(sc->sc_memt, fb_phys, sc->fb.fb_size, 384 BUS_SPACE_MAP_PREFETCHABLE, &sc->fb.fb_vbase); 385 #elif defined(__sparc64__) 386 OF_decode_addr(node, 0, &space, &phys); 387 sc->sc_memt = &ofwfb_memt[0]; 388 sc->fb.fb_vbase = 389 sparc64_fake_bustag(space, fb_phys, sc->sc_memt); 390 #elif defined(__arm__) 391 sc->sc_memt = fdtbus_bs_tag; 392 bus_space_map(sc->sc_memt, sc->fb.fb_pbase, sc->fb.fb_size, 393 BUS_SPACE_MAP_PREFETCHABLE, 394 (bus_space_handle_t *)&sc->fb.fb_vbase); 395 #else 396 #error Unsupported platform! 397 #endif 398 399 sc->fb.fb_pbase = fb_phys; 400 } else { 401 /* 402 * Some IBM systems don't have an address property. Try to 403 * guess the framebuffer region from the assigned addresses. 404 * This is ugly, but there doesn't seem to be an alternative. 405 * Linux does the same thing. 406 */ 407 408 struct ofw_pci_register pciaddrs[8]; 409 int num_pciaddrs = 0; 410 411 /* 412 * Get the PCI addresses of the adapter, if present. The node 413 * may be the child of the PCI device: in that case, try the 414 * parent for the assigned-addresses property. 415 */ 416 len = OF_getprop(node, "assigned-addresses", pciaddrs, 417 sizeof(pciaddrs)); 418 if (len == -1) { 419 len = OF_getprop(OF_parent(node), "assigned-addresses", 420 pciaddrs, sizeof(pciaddrs)); 421 } 422 if (len == -1) 423 len = 0; 424 num_pciaddrs = len / sizeof(struct ofw_pci_register); 425 426 fb_phys = num_pciaddrs; 427 for (i = 0; i < num_pciaddrs; i++) { 428 /* If it is too small, not the framebuffer */ 429 if (pciaddrs[i].size_lo < sc->fb.fb_stride * height) 430 continue; 431 /* If it is not memory, it isn't either */ 432 if (!(pciaddrs[i].phys_hi & 433 OFW_PCI_PHYS_HI_SPACE_MEM32)) 434 continue; 435 436 /* This could be the framebuffer */ 437 fb_phys = i; 438 439 /* If it is prefetchable, it certainly is */ 440 if (pciaddrs[i].phys_hi & OFW_PCI_PHYS_HI_PREFETCHABLE) 441 break; 442 } 443 444 if (fb_phys == num_pciaddrs) /* No candidates found */ 445 return (CN_DEAD); 446 447 #if defined(__powerpc__) 448 OF_decode_addr(node, fb_phys, &sc->sc_memt, &sc->fb.fb_vbase); 449 sc->fb.fb_pbase = sc->fb.fb_vbase; /* 1:1 mapped */ 450 #else 451 /* No ability to interpret assigned-addresses otherwise */ 452 return (CN_DEAD); 453 #endif 454 } 455 456 457 ofwfb_initialize(vd); 458 vt_fb_init(vd); 459 460 return (CN_INTERNAL); 461} 462
|