ofw_syscons.c revision 143830
1/*- 2 * Copyright (c) 2003 Peter Grehan 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 * $FreeBSD: head/sys/powerpc/ofw/ofw_syscons.c 143830 2005-03-19 01:43:29Z grehan $ 27 */ 28 29#include <sys/cdefs.h> 30__FBSDID("$FreeBSD: head/sys/powerpc/ofw/ofw_syscons.c 143830 2005-03-19 01:43:29Z grehan $"); 31 32#include <sys/param.h> 33#include <sys/systm.h> 34#include <sys/module.h> 35#include <sys/bus.h> 36#include <sys/kernel.h> 37#include <sys/sysctl.h> 38#include <sys/limits.h> 39#include <sys/conf.h> 40#include <sys/cons.h> 41#include <sys/proc.h> 42#include <sys/fcntl.h> 43#include <sys/malloc.h> 44#include <sys/fbio.h> 45#include <sys/consio.h> 46 47#include <machine/bus.h> 48#include <machine/sc_machdep.h> 49 50#include <sys/rman.h> 51 52#include <dev/fb/fbreg.h> 53#include <dev/syscons/syscons.h> 54 55#include <dev/ofw/openfirm.h> 56#include <dev/ofw/ofw_pci.h> 57#include <powerpc/ofw/ofw_syscons.h> 58#include <machine/nexusvar.h> 59 60extern u_char dflt_font_16[]; 61extern u_char dflt_font_14[]; 62extern u_char dflt_font_8[]; 63 64static int ofwfb_configure(int flags); 65 66static vi_probe_t ofwfb_probe; 67static vi_init_t ofwfb_init; 68static vi_get_info_t ofwfb_get_info; 69static vi_query_mode_t ofwfb_query_mode; 70static vi_set_mode_t ofwfb_set_mode; 71static vi_save_font_t ofwfb_save_font; 72static vi_load_font_t ofwfb_load_font; 73static vi_show_font_t ofwfb_show_font; 74static vi_save_palette_t ofwfb_save_palette; 75static vi_load_palette_t ofwfb_load_palette; 76static vi_set_border_t ofwfb_set_border; 77static vi_save_state_t ofwfb_save_state; 78static vi_load_state_t ofwfb_load_state; 79static vi_set_win_org_t ofwfb_set_win_org; 80static vi_read_hw_cursor_t ofwfb_read_hw_cursor; 81static vi_set_hw_cursor_t ofwfb_set_hw_cursor; 82static vi_set_hw_cursor_shape_t ofwfb_set_hw_cursor_shape; 83static vi_blank_display_t ofwfb_blank_display; 84static vi_mmap_t ofwfb_mmap; 85static vi_ioctl_t ofwfb_ioctl; 86static vi_clear_t ofwfb_clear; 87static vi_fill_rect_t ofwfb_fill_rect; 88static vi_bitblt_t ofwfb_bitblt; 89static vi_diag_t ofwfb_diag; 90static vi_save_cursor_palette_t ofwfb_save_cursor_palette; 91static vi_load_cursor_palette_t ofwfb_load_cursor_palette; 92static vi_copy_t ofwfb_copy; 93static vi_putp_t ofwfb_putp; 94static vi_putc_t ofwfb_putc; 95static vi_puts_t ofwfb_puts; 96static vi_putm_t ofwfb_putm; 97 98static video_switch_t ofwfbvidsw = { 99 .probe = ofwfb_probe, 100 .init = ofwfb_init, 101 .get_info = ofwfb_get_info, 102 .query_mode = ofwfb_query_mode, 103 .set_mode = ofwfb_set_mode, 104 .save_font = ofwfb_save_font, 105 .load_font = ofwfb_load_font, 106 .show_font = ofwfb_show_font, 107 .save_palette = ofwfb_save_palette, 108 .load_palette = ofwfb_load_palette, 109 .set_border = ofwfb_set_border, 110 .save_state = ofwfb_save_state, 111 .load_state = ofwfb_load_state, 112 .set_win_org = ofwfb_set_win_org, 113 .read_hw_cursor = ofwfb_read_hw_cursor, 114 .set_hw_cursor = ofwfb_set_hw_cursor, 115 .set_hw_cursor_shape = ofwfb_set_hw_cursor_shape, 116 .blank_display = ofwfb_blank_display, 117 .mmap = ofwfb_mmap, 118 .ioctl = ofwfb_ioctl, 119 .clear = ofwfb_clear, 120 .fill_rect = ofwfb_fill_rect, 121 .bitblt = ofwfb_bitblt, 122 .diag = ofwfb_diag, 123 .save_cursor_palette = ofwfb_save_cursor_palette, 124 .load_cursor_palette = ofwfb_load_cursor_palette, 125 .copy = ofwfb_copy, 126 .putp = ofwfb_putp, 127 .putc = ofwfb_putc, 128 .puts = ofwfb_puts, 129 .putm = ofwfb_putm, 130}; 131 132/* 133 * bitmap depth-specific routines 134 */ 135static vi_blank_display_t ofwfb_blank_display8; 136static vi_putc_t ofwfb_putc8; 137static vi_set_border_t ofwfb_set_border8; 138 139static vi_blank_display_t ofwfb_blank_display32; 140static vi_putc_t ofwfb_putc32; 141static vi_set_border_t ofwfb_set_border32; 142 143VIDEO_DRIVER(ofwfb, ofwfbvidsw, ofwfb_configure); 144 145extern sc_rndr_sw_t txtrndrsw; 146RENDERER(ofwfb, 0, txtrndrsw, gfb_set); 147 148RENDERER_MODULE(ofwfb, gfb_set); 149 150/* 151 * Define the iso6429-1983 colormap 152 */ 153static struct { 154 uint8_t red; 155 uint8_t green; 156 uint8_t blue; 157} ofwfb_cmap[16] = { /* # R G B Color */ 158 /* - - - - ----- */ 159 { 0x00, 0x00, 0x00 }, /* 0 0 0 0 Black */ 160 { 0x00, 0x00, 0xaa }, /* 1 0 0 2/3 Blue */ 161 { 0x00, 0xaa, 0x00 }, /* 2 0 2/3 0 Green */ 162 { 0x00, 0xaa, 0xaa }, /* 3 0 2/3 2/3 Cyan */ 163 { 0xaa, 0x00, 0x00 }, /* 4 2/3 0 0 Red */ 164 { 0xaa, 0x00, 0xaa }, /* 5 2/3 0 2/3 Magenta */ 165 { 0xaa, 0x55, 0x00 }, /* 6 2/3 1/3 0 Brown */ 166 { 0xaa, 0xaa, 0xaa }, /* 7 2/3 2/3 2/3 White */ 167 { 0x55, 0x55, 0x55 }, /* 8 1/3 1/3 1/3 Gray */ 168 { 0x55, 0x55, 0xff }, /* 9 1/3 1/3 1 Bright Blue */ 169 { 0x55, 0xff, 0x55 }, /* 10 1/3 1 1/3 Bright Green */ 170 { 0x55, 0xff, 0xff }, /* 11 1/3 1 1 Bright Cyan */ 171 { 0xff, 0x55, 0x55 }, /* 12 1 1/3 1/3 Bright Red */ 172 { 0xff, 0x55, 0xff }, /* 13 1 1/3 1 Bright Magenta */ 173 { 0xff, 0xff, 0x80 }, /* 14 1 1 1/3 Bright Yellow */ 174 { 0xff, 0xff, 0xff } /* 15 1 1 1 Bright White */ 175}; 176 177#define TODO printf("%s: unimplemented\n", __func__) 178 179static u_int16_t ofwfb_static_window[ROW*COL]; 180 181static struct ofwfb_softc ofwfb_softc; 182 183static __inline int 184ofwfb_background(uint8_t attr) 185{ 186 return (attr >> 4); 187} 188 189static __inline int 190ofwfb_foreground(uint8_t attr) 191{ 192 return (attr & 0x0f); 193} 194 195static u_int 196ofwfb_pix32(int attr) 197{ 198 u_int retval; 199 200 retval = (ofwfb_cmap[attr].blue << 16) | 201 (ofwfb_cmap[attr].green << 8) | 202 ofwfb_cmap[attr].red; 203 204 return (retval); 205} 206 207static int 208ofwfb_configure(int flags) 209{ 210 struct ofwfb_softc *sc; 211 phandle_t chosen; 212 ihandle_t stdout; 213 phandle_t node; 214 int depth; 215 int disable; 216 int len; 217 char type[16]; 218 static int done = 0; 219 220 disable = 0; 221 TUNABLE_INT_FETCH("hw.syscons.disable", &disable); 222 if (disable != 0) 223 return (0); 224 225 if (done != 0) 226 return (0); 227 done = 1; 228 229 sc = &ofwfb_softc; 230 231 chosen = OF_finddevice("/chosen"); 232 OF_getprop(chosen, "stdout", &stdout, sizeof(stdout)); 233 node = OF_instance_to_package(stdout); 234 OF_getprop(node, "device_type", type, sizeof(type)); 235 if (strcmp(type, "display") != 0) 236 return (0); 237 238 /* Only support 8 and 32-bit framebuffers */ 239 OF_getprop(node, "depth", &depth, sizeof(depth)); 240 if (depth == 8) { 241 sc->sc_blank = ofwfb_blank_display8; 242 sc->sc_putc = ofwfb_putc8; 243 sc->sc_set_border = ofwfb_set_border8; 244 } else if (depth == 32) { 245 sc->sc_blank = ofwfb_blank_display32; 246 sc->sc_putc = ofwfb_putc32; 247 sc->sc_set_border = ofwfb_set_border32; 248 } else 249 return (0); 250 251 sc->sc_depth = depth; 252 sc->sc_node = node; 253 sc->sc_console = 1; 254 OF_getprop(node, "height", &sc->sc_height, sizeof(sc->sc_height)); 255 OF_getprop(node, "width", &sc->sc_width, sizeof(sc->sc_width)); 256 OF_getprop(node, "linebytes", &sc->sc_stride, sizeof(sc->sc_stride)); 257 258 /* 259 * XXX the physical address of the frame buffer is assumed to be 260 * BAT-mapped so it can be accessed directly 261 */ 262 OF_getprop(node, "address", &sc->sc_addr, sizeof(sc->sc_addr)); 263 264 /* 265 * Get the PCI addresses of the adapter. The node may be the 266 * child of the PCI device: in that case, try the parent for 267 * the assigned-addresses property. 268 */ 269 len = OF_getprop(node, "assigned-addresses", sc->sc_pciaddrs, 270 sizeof(sc->sc_pciaddrs)); 271 if (len == -1) { 272 len = OF_getprop(OF_parent(node), "assigned-addresses", sc->sc_pciaddrs, 273 sizeof(sc->sc_pciaddrs)); 274 } 275 276 if (len != -1) { 277 sc->sc_num_pciaddrs = len / sizeof(struct ofw_pci_register); 278 } 279 280 ofwfb_init(0, &sc->sc_va, 0); 281 282 return (0); 283} 284 285static int 286ofwfb_probe(int unit, video_adapter_t **adp, void *arg, int flags) 287{ 288 TODO; 289 return (0); 290} 291 292static int 293ofwfb_init(int unit, video_adapter_t *adp, int flags) 294{ 295 struct ofwfb_softc *sc; 296 video_info_t *vi; 297 char name[64]; 298 ihandle_t ih; 299 int i; 300 int cborder; 301 int font_height; 302 int retval; 303 304 sc = (struct ofwfb_softc *)adp; 305 vi = &adp->va_info; 306 307 vid_init_struct(adp, "ofwfb", -1, unit); 308 309 if (sc->sc_depth == 8) { 310 /* 311 * Install the ISO6429 colormap - older OFW systems 312 * don't do this by default 313 */ 314 memset(name, 0, sizeof(name)); 315 OF_package_to_path(sc->sc_node, name, sizeof(name)); 316 ih = OF_open(name); 317 for (i = 0; i < 16; i++) { 318 OF_call_method("color!", ih, 4, 1, 319 ofwfb_cmap[i].red, 320 ofwfb_cmap[i].green, 321 ofwfb_cmap[i].blue, 322 i, 323 &retval); 324 } 325 } 326 327 /* The default font size can be overridden by loader */ 328 font_height = 16; 329 TUNABLE_INT_FETCH("hw.syscons.fsize", &font_height); 330 if (font_height == 8) { 331 sc->sc_font = dflt_font_8; 332 sc->sc_font_height = 8; 333 } else if (font_height == 14) { 334 sc->sc_font = dflt_font_14; 335 sc->sc_font_height = 14; 336 } else { 337 /* default is 8x16 */ 338 sc->sc_font = dflt_font_16; 339 sc->sc_font_height = 16; 340 } 341 342 /* The user can set a border in chars - default is 1 char width */ 343 cborder = 1; 344 TUNABLE_INT_FETCH("hw.syscons.border", &cborder); 345 346 vi->vi_cheight = sc->sc_font_height; 347 vi->vi_width = sc->sc_width/8 - 2*cborder; 348 vi->vi_height = sc->sc_height/sc->sc_font_height - 2*cborder; 349 vi->vi_cwidth = 8; 350 351 /* 352 * Clamp width/height to syscons maximums 353 */ 354 if (vi->vi_width > COL) 355 vi->vi_width = COL; 356 if (vi->vi_height > ROW) 357 vi->vi_height = ROW; 358 359 sc->sc_xmargin = (sc->sc_width - (vi->vi_width * vi->vi_cwidth)) / 2; 360 sc->sc_ymargin = (sc->sc_height - (vi->vi_height * vi->vi_cheight))/2; 361 362 /* 363 * Avoid huge amounts of conditional code in syscons by 364 * defining a dummy h/w text display buffer. 365 */ 366 adp->va_window = (vm_offset_t) ofwfb_static_window; 367 368 /* Enable future font-loading and flag color support */ 369 adp->va_flags |= V_ADP_FONT | V_ADP_COLOR; 370 371 ofwfb_blank_display(&sc->sc_va, V_DISPLAY_ON); 372 373 ofwfb_set_mode(&sc->sc_va, 0); 374 375 vid_register(&sc->sc_va); 376 377 return (0); 378} 379 380static int 381ofwfb_get_info(video_adapter_t *adp, int mode, video_info_t *info) 382{ 383 bcopy(&adp->va_info, info, sizeof(*info)); 384 return (0); 385} 386 387static int 388ofwfb_query_mode(video_adapter_t *adp, video_info_t *info) 389{ 390 TODO; 391 return (0); 392} 393 394static int 395ofwfb_set_mode(video_adapter_t *adp, int mode) 396{ 397 398 return (0); 399} 400 401static int 402ofwfb_save_font(video_adapter_t *adp, int page, int size, u_char *data, 403 int c, int count) 404{ 405 TODO; 406 return (0); 407} 408 409static int 410ofwfb_load_font(video_adapter_t *adp, int page, int size, u_char *data, 411 int c, int count) 412{ 413 struct ofwfb_softc *sc; 414 415 sc = (struct ofwfb_softc *)adp; 416 417 /* 418 * syscons code has already determined that current width/height 419 * are unchanged for this new font 420 */ 421 sc->sc_font = data; 422 return (0); 423} 424 425static int 426ofwfb_show_font(video_adapter_t *adp, int page) 427{ 428 429 return (0); 430} 431 432static int 433ofwfb_save_palette(video_adapter_t *adp, u_char *palette) 434{ 435 /* TODO; */ 436 return (0); 437} 438 439static int 440ofwfb_load_palette(video_adapter_t *adp, u_char *palette) 441{ 442 /* TODO; */ 443 return (0); 444} 445 446static int 447ofwfb_set_border8(video_adapter_t *adp, int border) 448{ 449 struct ofwfb_softc *sc; 450 int i, j; 451 uint8_t *addr; 452 uint8_t bground; 453 454 sc = (struct ofwfb_softc *)adp; 455 456 bground = ofwfb_background(border); 457 458 /* Set top margin */ 459 addr = (uint8_t *) sc->sc_addr; 460 for (i = 0; i < sc->sc_ymargin; i++) { 461 for (j = 0; j < sc->sc_width; j++) { 462 *(addr + j) = bground; 463 } 464 addr += sc->sc_stride; 465 } 466 467 /* bottom margin */ 468 addr = (uint8_t *) sc->sc_addr + (sc->sc_height - sc->sc_ymargin)*sc->sc_stride; 469 for (i = 0; i < sc->sc_ymargin; i++) { 470 for (j = 0; j < sc->sc_width; j++) { 471 *(addr + j) = bground; 472 } 473 addr += sc->sc_stride; 474 } 475 476 /* remaining left and right borders */ 477 addr = (uint8_t *) sc->sc_addr + sc->sc_ymargin*sc->sc_stride; 478 for (i = 0; i < sc->sc_height - 2*sc->sc_xmargin; i++) { 479 for (j = 0; j < sc->sc_xmargin; j++) { 480 *(addr + j) = bground; 481 *(addr + j + sc->sc_width - sc->sc_xmargin) = bground; 482 } 483 addr += sc->sc_stride; 484 } 485 486 return (0); 487} 488 489static int 490ofwfb_set_border32(video_adapter_t *adp, int border) 491{ 492 /* XXX Be lazy for now and blank entire screen */ 493 return (ofwfb_blank_display32(adp, border)); 494} 495 496static int 497ofwfb_set_border(video_adapter_t *adp, int border) 498{ 499 struct ofwfb_softc *sc; 500 501 sc = (struct ofwfb_softc *)adp; 502 503 return ((*sc->sc_set_border)(adp, border)); 504} 505 506static int 507ofwfb_save_state(video_adapter_t *adp, void *p, size_t size) 508{ 509 TODO; 510 return (0); 511} 512 513static int 514ofwfb_load_state(video_adapter_t *adp, void *p) 515{ 516 TODO; 517 return (0); 518} 519 520static int 521ofwfb_set_win_org(video_adapter_t *adp, off_t offset) 522{ 523 TODO; 524 return (0); 525} 526 527static int 528ofwfb_read_hw_cursor(video_adapter_t *adp, int *col, int *row) 529{ 530 *col = 0; 531 *row = 0; 532 533 return (0); 534} 535 536static int 537ofwfb_set_hw_cursor(video_adapter_t *adp, int col, int row) 538{ 539 540 return (0); 541} 542 543static int 544ofwfb_set_hw_cursor_shape(video_adapter_t *adp, int base, int height, 545 int celsize, int blink) 546{ 547 return (0); 548} 549 550static int 551ofwfb_blank_display8(video_adapter_t *adp, int mode) 552{ 553 struct ofwfb_softc *sc; 554 int i; 555 uint8_t *addr; 556 557 sc = (struct ofwfb_softc *)adp; 558 addr = (uint8_t *) sc->sc_addr; 559 560 /* Could be done a lot faster e.g. 32-bits, or Altivec'd */ 561 for (i = 0; i < sc->sc_stride*sc->sc_height; i++) 562 *(addr + i) = ofwfb_background(SC_NORM_ATTR); 563 564 return (0); 565} 566 567static int 568ofwfb_blank_display32(video_adapter_t *adp, int mode) 569{ 570 struct ofwfb_softc *sc; 571 int i; 572 uint32_t *addr; 573 574 sc = (struct ofwfb_softc *)adp; 575 addr = (uint32_t *) sc->sc_addr; 576 577 for (i = 0; i < (sc->sc_stride/4)*sc->sc_height; i++) 578 *(addr + i) = ofwfb_pix32(ofwfb_background(SC_NORM_ATTR)); 579 580 return (0); 581} 582 583static int 584ofwfb_blank_display(video_adapter_t *adp, int mode) 585{ 586 struct ofwfb_softc *sc; 587 588 sc = (struct ofwfb_softc *)adp; 589 590 return ((*sc->sc_blank)(adp, mode)); 591} 592 593static int 594ofwfb_mmap(video_adapter_t *adp, vm_offset_t offset, vm_paddr_t *paddr, 595 int prot) 596{ 597 struct ofwfb_softc *sc; 598 int i; 599 600 sc = (struct ofwfb_softc *)adp; 601 602 if (sc->sc_num_pciaddrs == 0) 603 return (ENOMEM); 604 605 /* 606 * Make sure the requested address lies within the PCI device's assigned addrs 607 */ 608 for (i = 0; i < sc->sc_num_pciaddrs; i++) 609 if (offset >= sc->sc_pciaddrs[i].phys_lo && 610 offset < (sc->sc_pciaddrs[i].phys_lo + sc->sc_pciaddrs[i].size_lo)) { 611 *paddr = offset; 612 return (0); 613 } 614 615 /* 616 * This might be a legacy VGA mem request: if so, just point it at the 617 * framebuffer, since it shouldn't be touched 618 */ 619 if (offset < sc->sc_stride*sc->sc_height) { 620 *paddr = sc->sc_addr + offset; 621 return (0); 622 } 623 624 return (EINVAL); 625} 626 627static int 628ofwfb_ioctl(video_adapter_t *adp, u_long cmd, caddr_t data) 629{ 630 TODO; 631 return (0); 632} 633 634static int 635ofwfb_clear(video_adapter_t *adp) 636{ 637 TODO; 638 return (0); 639} 640 641static int 642ofwfb_fill_rect(video_adapter_t *adp, int val, int x, int y, int cx, int cy) 643{ 644 TODO; 645 return (0); 646} 647 648static int 649ofwfb_bitblt(video_adapter_t *adp, ...) 650{ 651 TODO; 652 return (0); 653} 654 655static int 656ofwfb_diag(video_adapter_t *adp, int level) 657{ 658 TODO; 659 return (0); 660} 661 662static int 663ofwfb_save_cursor_palette(video_adapter_t *adp, u_char *palette) 664{ 665 TODO; 666 return (0); 667} 668 669static int 670ofwfb_load_cursor_palette(video_adapter_t *adp, u_char *palette) 671{ 672 TODO; 673 return (0); 674} 675 676static int 677ofwfb_copy(video_adapter_t *adp, vm_offset_t src, vm_offset_t dst, int n) 678{ 679 TODO; 680 return (0); 681} 682 683static int 684ofwfb_putp(video_adapter_t *adp, vm_offset_t off, uint32_t p, uint32_t a, 685 int size, int bpp, int bit_ltor, int byte_ltor) 686{ 687 TODO; 688 return (0); 689} 690 691static int 692ofwfb_putc8(video_adapter_t *adp, vm_offset_t off, uint8_t c, uint8_t a) 693{ 694 struct ofwfb_softc *sc; 695 int row; 696 int col; 697 int i; 698 uint32_t *addr; 699 u_char *p, fg, bg; 700 union { 701 uint32_t l; 702 uint8_t c[4]; 703 } ch1, ch2; 704 705 706 sc = (struct ofwfb_softc *)adp; 707 row = (off / adp->va_info.vi_width) * adp->va_info.vi_cheight; 708 col = (off % adp->va_info.vi_width) * adp->va_info.vi_cwidth; 709 p = sc->sc_font + c*sc->sc_font_height; 710 addr = (u_int32_t *)((int)sc->sc_addr 711 + (row + sc->sc_ymargin)*sc->sc_stride 712 + col + sc->sc_xmargin); 713 714 fg = ofwfb_foreground(a); 715 bg = ofwfb_background(a); 716 717 for (i = 0; i < sc->sc_font_height; i++) { 718 u_char fline = p[i]; 719 720 /* 721 * Assume that there is more background than foreground 722 * in characters and init accordingly 723 */ 724 ch1.l = ch2.l = (bg << 24) | (bg << 16) | (bg << 8) | bg; 725 726 /* 727 * Calculate 2 x 4-chars at a time, and then 728 * write these out. 729 */ 730 if (fline & 0x80) ch1.c[0] = fg; 731 if (fline & 0x40) ch1.c[1] = fg; 732 if (fline & 0x20) ch1.c[2] = fg; 733 if (fline & 0x10) ch1.c[3] = fg; 734 735 if (fline & 0x08) ch2.c[0] = fg; 736 if (fline & 0x04) ch2.c[1] = fg; 737 if (fline & 0x02) ch2.c[2] = fg; 738 if (fline & 0x01) ch2.c[3] = fg; 739 740 addr[0] = ch1.l; 741 addr[1] = ch2.l; 742 addr += (sc->sc_stride / sizeof(u_int32_t)); 743 } 744 745 return (0); 746} 747 748static int 749ofwfb_putc32(video_adapter_t *adp, vm_offset_t off, uint8_t c, uint8_t a) 750{ 751 struct ofwfb_softc *sc; 752 int row; 753 int col; 754 int i, j, k; 755 uint32_t *addr; 756 u_char *p; 757 758 sc = (struct ofwfb_softc *)adp; 759 row = (off / adp->va_info.vi_width) * adp->va_info.vi_cheight; 760 col = (off % adp->va_info.vi_width) * adp->va_info.vi_cwidth; 761 p = sc->sc_font + c*sc->sc_font_height; 762 addr = (uint32_t *)sc->sc_addr 763 + (row + sc->sc_ymargin)*(sc->sc_stride/4) 764 + col + sc->sc_xmargin; 765 766 for (i = 0; i < sc->sc_font_height; i++) { 767 for (j = 0, k = 7; j < 8; j++, k--) { 768 if ((p[i] & (1 << k)) == 0) 769 *(addr + j) = ofwfb_pix32(ofwfb_background(a)); 770 else 771 *(addr + j) = ofwfb_pix32(ofwfb_foreground(a)); 772 } 773 addr += (sc->sc_stride/4); 774 } 775 776 return (0); 777} 778 779static int 780ofwfb_putc(video_adapter_t *adp, vm_offset_t off, uint8_t c, uint8_t a) 781{ 782 struct ofwfb_softc *sc; 783 784 sc = (struct ofwfb_softc *)adp; 785 786 return ((*sc->sc_putc)(adp, off, c, a)); 787} 788 789static int 790ofwfb_puts(video_adapter_t *adp, vm_offset_t off, u_int16_t *s, int len) 791{ 792 int i; 793 794 for (i = 0; i < len; i++) { 795 ofwfb_putc(adp, off + i, s[i] & 0xff, (s[i] & 0xff00) >> 8); 796 } 797 return (0); 798} 799 800static int 801ofwfb_putm(video_adapter_t *adp, int x, int y, uint8_t *pixel_image, 802 uint32_t pixel_mask, int size) 803{ 804 struct ofwfb_softc *sc; 805 806 sc = (struct ofwfb_softc *)adp; 807 808 /* put mouse */ 809 810 return (0); 811} 812 813/* 814 * Define the syscons nexus device attachment 815 */ 816static void 817ofwfb_scidentify(driver_t *driver, device_t parent) 818{ 819 device_t child; 820 821 /* 822 * Add with a priority guaranteed to make it last on 823 * the device list 824 */ 825 child = BUS_ADD_CHILD(parent, INT_MAX, SC_DRIVER_NAME, 0); 826 if (child != NULL) 827 nexus_set_device_type(child, "syscons"); 828} 829 830static int 831ofwfb_scprobe(device_t dev) 832{ 833 char *name; 834 835 name = nexus_get_name(dev); 836 if (strcmp(SC_DRIVER_NAME, name) != 0) 837 return (ENXIO); 838 839 device_set_desc(dev, "System console"); 840 return (sc_probe_unit(device_get_unit(dev), 841 device_get_flags(dev) | SC_AUTODETECT_KBD)); 842} 843 844static int 845ofwfb_scattach(device_t dev) 846{ 847 return (sc_attach_unit(device_get_unit(dev), 848 device_get_flags(dev) | SC_AUTODETECT_KBD)); 849} 850 851static device_method_t ofwfb_sc_methods[] = { 852 DEVMETHOD(device_identify, ofwfb_scidentify), 853 DEVMETHOD(device_probe, ofwfb_scprobe), 854 DEVMETHOD(device_attach, ofwfb_scattach), 855 { 0, 0 } 856}; 857 858static driver_t ofwfb_sc_driver = { 859 SC_DRIVER_NAME, 860 ofwfb_sc_methods, 861 sizeof(sc_softc_t), 862}; 863 864static devclass_t sc_devclass; 865 866DRIVER_MODULE(sc, nexus, ofwfb_sc_driver, sc_devclass, 0, 0); 867 868/* 869 * Define a stub keyboard driver in case one hasn't been 870 * compiled into the kernel 871 */ 872#include <sys/kbio.h> 873#include <dev/kbd/kbdreg.h> 874 875static int dummy_kbd_configure(int flags); 876 877keyboard_switch_t dummysw; 878 879static int 880dummy_kbd_configure(int flags) 881{ 882 883 return (0); 884} 885KEYBOARD_DRIVER(dummy, dummysw, dummy_kbd_configure); 886 887/* 888 * Utility routines from <dev/fb/fbreg.h> 889 */ 890void 891ofwfb_bcopy(const void *s, void *d, size_t c) 892{ 893 bcopy(s, d, c); 894} 895 896void 897ofwfb_bzero(void *d, size_t c) 898{ 899 bzero(d, c); 900} 901 902void 903ofwfb_fillw(int pat, void *base, size_t cnt) 904{ 905 u_int16_t *bptr = base; 906 907 while (cnt--) 908 *bptr++ = pat; 909} 910 911u_int16_t 912ofwfb_readw(u_int16_t *addr) 913{ 914 return (*addr); 915} 916 917void 918ofwfb_writew(u_int16_t *addr, u_int16_t val) 919{ 920 *addr = val; 921} 922