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 27 #include <sys/cdefs.h> 28 __FBSDID("$FreeBSD$"); 29 30 #include <sys/param.h> 31 #include <sys/systm.h> 32 #include <sys/module.h> 33 #include <sys/bus.h> 34 #include <sys/kernel.h> 35 #include <sys/sysctl.h> 36 #include <sys/limits.h> 37 #include <sys/conf.h> 38 #include <sys/cons.h> 39 #include <sys/proc.h> 40 #include <sys/fcntl.h> 41 #include <sys/malloc.h> 42 #include <sys/fbio.h> 43 #include <sys/consio.h> 44 45 #include <vm/vm.h> 46 #include <vm/pmap.h> 47 48 #include <machine/bus.h> 49 #include <machine/sc_machdep.h> 50 #include <machine/platform.h> 51 #include <machine/pmap.h> 52 53 #include <sys/rman.h> 54 55 #include <dev/fb/fbreg.h> 56 #include <dev/syscons/syscons.h> 57 58 #include "ps3-hvcall.h" 59 60 #define PS3FB_SIZE (4*1024*1024) 61 62 #define L1GPU_CONTEXT_ATTRIBUTE_DISPLAY_MODE_SET 0x0100 63 #define L1GPU_CONTEXT_ATTRIBUTE_DISPLAY_SYNC 0x0101 64 #define L1GPU_DISPLAY_SYNC_HSYNC 1 65 #define L1GPU_DISPLAY_SYNC_VSYNC 2 66 #define L1GPU_CONTEXT_ATTRIBUTE_DISPLAY_FLIP 0x0102 67 68 extern u_char dflt_font_16[]; 69 extern u_char dflt_font_14[]; 70 extern u_char dflt_font_8[]; 71 72 static int ps3fb_configure(int flags); 73 void ps3fb_remap(void); 74 75 static vi_probe_t ps3fb_probe; 76 static vi_init_t ps3fb_init; 77 static vi_get_info_t ps3fb_get_info; 78 static vi_query_mode_t ps3fb_query_mode; 79 static vi_set_mode_t ps3fb_set_mode; 80 static vi_save_font_t ps3fb_save_font; 81 static vi_load_font_t ps3fb_load_font; 82 static vi_show_font_t ps3fb_show_font; 83 static vi_save_palette_t ps3fb_save_palette; 84 static vi_load_palette_t ps3fb_load_palette; 85 static vi_set_border_t ps3fb_set_border; 86 static vi_save_state_t ps3fb_save_state; 87 static vi_load_state_t ps3fb_load_state; 88 static vi_set_win_org_t ps3fb_set_win_org; 89 static vi_read_hw_cursor_t ps3fb_read_hw_cursor; 90 static vi_set_hw_cursor_t ps3fb_set_hw_cursor; 91 static vi_set_hw_cursor_shape_t ps3fb_set_hw_cursor_shape; 92 static vi_blank_display_t ps3fb_blank_display; 93 static vi_mmap_t ps3fb_mmap; 94 static vi_ioctl_t ps3fb_ioctl; 95 static vi_clear_t ps3fb_clear; 96 static vi_fill_rect_t ps3fb_fill_rect; 97 static vi_bitblt_t ps3fb_bitblt; 98 static vi_diag_t ps3fb_diag; 99 static vi_save_cursor_palette_t ps3fb_save_cursor_palette; 100 static vi_load_cursor_palette_t ps3fb_load_cursor_palette; 101 static vi_copy_t ps3fb_copy; 102 static vi_putp_t ps3fb_putp; 103 static vi_putc_t ps3fb_putc; 104 static vi_puts_t ps3fb_puts; 105 static vi_putm_t ps3fb_putm; 106 107 struct ps3fb_softc { 108 video_adapter_t sc_va; 109 struct cdev *sc_si; 110 int sc_console; 111 112 intptr_t sc_addr; 113 int sc_height; 114 int sc_width; 115 int sc_stride; 116 int sc_ncol; 117 int sc_nrow; 118 119 int sc_xmargin; 120 int sc_ymargin; 121 122 u_char *sc_font; 123 int sc_font_height; 124 125 uint64_t sc_fbhandle; 126 uint64_t sc_fbcontext; 127 uint64_t sc_dma_control; 128 uint64_t sc_driver_info; 129 uint64_t sc_reports; 130 uint64_t sc_reports_size; 131 }; 132 133 static video_switch_t ps3fbvidsw = { 134 .probe = ps3fb_probe, 135 .init = ps3fb_init, 136 .get_info = ps3fb_get_info, 137 .query_mode = ps3fb_query_mode, 138 .set_mode = ps3fb_set_mode, 139 .save_font = ps3fb_save_font, 140 .load_font = ps3fb_load_font, 141 .show_font = ps3fb_show_font, 142 .save_palette = ps3fb_save_palette, 143 .load_palette = ps3fb_load_palette, 144 .set_border = ps3fb_set_border, 145 .save_state = ps3fb_save_state, 146 .load_state = ps3fb_load_state, 147 .set_win_org = ps3fb_set_win_org, 148 .read_hw_cursor = ps3fb_read_hw_cursor, 149 .set_hw_cursor = ps3fb_set_hw_cursor, 150 .set_hw_cursor_shape = ps3fb_set_hw_cursor_shape, 151 .blank_display = ps3fb_blank_display, 152 .mmap = ps3fb_mmap, 153 .ioctl = ps3fb_ioctl, 154 .clear = ps3fb_clear, 155 .fill_rect = ps3fb_fill_rect, 156 .bitblt = ps3fb_bitblt, 157 .diag = ps3fb_diag, 158 .save_cursor_palette = ps3fb_save_cursor_palette, 159 .load_cursor_palette = ps3fb_load_cursor_palette, 160 .copy = ps3fb_copy, 161 .putp = ps3fb_putp, 162 .putc = ps3fb_putc, 163 .puts = ps3fb_puts, 164 .putm = ps3fb_putm, 165 }; 166 167 VIDEO_DRIVER(ps3fb, ps3fbvidsw, ps3fb_configure); 168 169 extern sc_rndr_sw_t txtrndrsw; 170 RENDERER(ps3fb, 0, txtrndrsw, gfb_set); 171 172 RENDERER_MODULE(ps3fb, gfb_set); 173 174 /* 175 * Define the iso6429-1983 colormap 176 */ 177 static struct { 178 uint8_t red; 179 uint8_t green; 180 uint8_t blue; 181 } ps3fb_cmap[16] = { /* # R G B Color */ 182 /* - - - - ----- */ 183 { 0x00, 0x00, 0x00 }, /* 0 0 0 0 Black */ 184 { 0x00, 0x00, 0xaa }, /* 1 0 0 2/3 Blue */ 185 { 0x00, 0xaa, 0x00 }, /* 2 0 2/3 0 Green */ 186 { 0x00, 0xaa, 0xaa }, /* 3 0 2/3 2/3 Cyan */ 187 { 0xaa, 0x00, 0x00 }, /* 4 2/3 0 0 Red */ 188 { 0xaa, 0x00, 0xaa }, /* 5 2/3 0 2/3 Magenta */ 189 { 0xaa, 0x55, 0x00 }, /* 6 2/3 1/3 0 Brown */ 190 { 0xaa, 0xaa, 0xaa }, /* 7 2/3 2/3 2/3 White */ 191 { 0x55, 0x55, 0x55 }, /* 8 1/3 1/3 1/3 Gray */ 192 { 0x55, 0x55, 0xff }, /* 9 1/3 1/3 1 Bright Blue */ 193 { 0x55, 0xff, 0x55 }, /* 10 1/3 1 1/3 Bright Green */ 194 { 0x55, 0xff, 0xff }, /* 11 1/3 1 1 Bright Cyan */ 195 { 0xff, 0x55, 0x55 }, /* 12 1 1/3 1/3 Bright Red */ 196 { 0xff, 0x55, 0xff }, /* 13 1 1/3 1 Bright Magenta */ 197 { 0xff, 0xff, 0x80 }, /* 14 1 1 1/3 Bright Yellow */ 198 { 0xff, 0xff, 0xff } /* 15 1 1 1 Bright White */ 199 }; 200 201 #define TODO printf("%s: unimplemented\n", __func__) 202 203 static u_int16_t ps3fb_static_window[ROW*COL]; 204 205 static struct ps3fb_softc ps3fb_softc; 206 207 static __inline int 208 ps3fb_background(uint8_t attr) 209 { 210 return (attr >> 4); 211 } 212 213 static __inline int 214 ps3fb_foreground(uint8_t attr) 215 { 216 return (attr & 0x0f); 217 } 218 219 static u_int 220 ps3fb_pix32(int attr) 221 { 222 u_int retval; 223 224 retval = (ps3fb_cmap[attr].red << 16) | 225 (ps3fb_cmap[attr].green << 8) | 226 ps3fb_cmap[attr].blue; 227 228 return (retval); 229 } 230 231 static int 232 ps3fb_configure(int flags) 233 { 234 struct ps3fb_softc *sc; 235 int disable; 236 char compatible[64]; 237 #if 0 238 phandle_t root; 239 #endif 240 static int done = 0; 241 242 disable = 0; 243 TUNABLE_INT_FETCH("hw.syscons.disable", &disable); 244 if (disable != 0) 245 return (0); 246 247 if (done != 0) 248 return (0); 249 done = 1; 250 251 sc = &ps3fb_softc; 252 253 #if 0 254 root = OF_finddevice("/"); 255 if (OF_getprop(root, "compatible", compatible, sizeof(compatible)) <= 0) 256 return (0); 257 258 if (strncmp(compatible, "sony,ps3", sizeof(compatible)) != 0) 259 return (0); 260 #else 261 TUNABLE_STR_FETCH("hw.platform", compatible, sizeof(compatible)); 262 if (strcmp(compatible, "ps3") != 0) 263 return (0); 264 #endif 265 266 sc->sc_console = 1; 267 268 /* XXX: get from HV repository */ 269 sc->sc_height = 480; 270 sc->sc_width = 720; 271 sc->sc_stride = sc->sc_width*4; 272 273 /* 274 * The loader puts the FB at 0x10000000, so use that for now. 275 */ 276 277 sc->sc_addr = 0x10000000; 278 ps3fb_init(0, &sc->sc_va, 0); 279 280 return (0); 281 } 282 283 void 284 ps3fb_remap(void) 285 { 286 struct ps3fb_softc *sc; 287 vm_offset_t va, fb_paddr; 288 289 sc = &ps3fb_softc; 290 291 lv1_gpu_close(); 292 lv1_gpu_open(0); 293 294 lv1_gpu_context_attribute(0, L1GPU_CONTEXT_ATTRIBUTE_DISPLAY_MODE_SET, 295 0,0,0,0); 296 lv1_gpu_context_attribute(0, L1GPU_CONTEXT_ATTRIBUTE_DISPLAY_MODE_SET, 297 0,0,1,0); 298 lv1_gpu_context_attribute(0, L1GPU_CONTEXT_ATTRIBUTE_DISPLAY_SYNC, 299 0,L1GPU_DISPLAY_SYNC_VSYNC,0,0); 300 lv1_gpu_context_attribute(0, L1GPU_CONTEXT_ATTRIBUTE_DISPLAY_SYNC, 301 1,L1GPU_DISPLAY_SYNC_VSYNC,0,0); 302 lv1_gpu_memory_allocate(PS3FB_SIZE, 0, 0, 0, 0, &sc->sc_fbhandle, &fb_paddr); 303 lv1_gpu_context_allocate(sc->sc_fbhandle, 0, &sc->sc_fbcontext, &sc->sc_dma_control, 304 &sc->sc_driver_info, &sc->sc_reports, &sc->sc_reports_size); 305 306 lv1_gpu_context_attribute(sc->sc_fbcontext, 307 L1GPU_CONTEXT_ATTRIBUTE_DISPLAY_FLIP, 0, 0, 0, 0); 308 lv1_gpu_context_attribute(sc->sc_fbcontext, 309 L1GPU_CONTEXT_ATTRIBUTE_DISPLAY_FLIP, 1, 0, 0, 0); 310 311 for (va = 0; va < PS3FB_SIZE; va += PAGE_SIZE) 312 pmap_kenter_attr(0x10000000 + va, fb_paddr + va, 313 VM_MEMATTR_WRITE_COMBINING); 314 } 315 316 static int 317 ps3fb_probe(int unit, video_adapter_t **adp, void *arg, int flags) 318 { 319 TODO; 320 return (0); 321 } 322 323 static int 324 ps3fb_init(int unit, video_adapter_t *adp, int flags) 325 { 326 struct ps3fb_softc *sc; 327 video_info_t *vi; 328 int cxborder, cyborder; 329 int font_height; 330 331 sc = (struct ps3fb_softc *)adp; 332 vi = &adp->va_info; 333 334 vid_init_struct(adp, "ps3fb", -1, unit); 335 336 /* The default font size can be overridden by loader */ 337 font_height = 16; 338 TUNABLE_INT_FETCH("hw.syscons.fsize", &font_height); 339 if (font_height == 8) { 340 sc->sc_font = dflt_font_8; 341 sc->sc_font_height = 8; 342 } else if (font_height == 14) { 343 sc->sc_font = dflt_font_14; 344 sc->sc_font_height = 14; 345 } else { 346 /* default is 8x16 */ 347 sc->sc_font = dflt_font_16; 348 sc->sc_font_height = 16; 349 } 350 351 /* The user can set a border in chars - default is 1 char width */ 352 cxborder = 8; 353 cyborder = 2; 354 TUNABLE_INT_FETCH("hw.syscons.xborder", &cxborder); 355 TUNABLE_INT_FETCH("hw.syscons.yborder", &cyborder); 356 357 vi->vi_cheight = sc->sc_font_height; 358 vi->vi_width = sc->sc_width/8 - 2*cxborder; 359 vi->vi_height = sc->sc_height/sc->sc_font_height - 2*cyborder; 360 vi->vi_cwidth = 8; 361 362 /* 363 * Clamp width/height to syscons maximums 364 */ 365 if (vi->vi_width > COL) 366 vi->vi_width = COL; 367 if (vi->vi_height > ROW) 368 vi->vi_height = ROW; 369 370 sc->sc_xmargin = (sc->sc_width - (vi->vi_width * vi->vi_cwidth)) / 2; 371 sc->sc_ymargin = (sc->sc_height - (vi->vi_height * vi->vi_cheight))/2; 372 373 /* 374 * Avoid huge amounts of conditional code in syscons by 375 * defining a dummy h/w text display buffer. 376 */ 377 adp->va_window = (vm_offset_t) ps3fb_static_window; 378 379 /* 380 * Enable future font-loading and flag color support, as well as 381 * adding V_ADP_MODECHANGE so that we ps3fb_set_mode() gets called 382 * when the X server shuts down. This enables us to get the console 383 * back when X disappears. 384 */ 385 adp->va_flags |= V_ADP_FONT | V_ADP_COLOR | V_ADP_MODECHANGE; 386 387 ps3fb_set_mode(&sc->sc_va, 0); 388 vid_register(&sc->sc_va); 389 390 return (0); 391 } 392 393 static int 394 ps3fb_get_info(video_adapter_t *adp, int mode, video_info_t *info) 395 { 396 bcopy(&adp->va_info, info, sizeof(*info)); 397 return (0); 398 } 399 400 static int 401 ps3fb_query_mode(video_adapter_t *adp, video_info_t *info) 402 { 403 TODO; 404 return (0); 405 } 406 407 static int 408 ps3fb_set_mode(video_adapter_t *adp, int mode) 409 { 410 struct ps3fb_softc *sc; 411 412 sc = (struct ps3fb_softc *)adp; 413 414 /* XXX: no real mode setting at the moment */ 415 416 ps3fb_blank_display(&sc->sc_va, V_DISPLAY_ON); 417 418 lv1_gpu_context_attribute(sc->sc_fbcontext, 419 L1GPU_CONTEXT_ATTRIBUTE_DISPLAY_FLIP, 0, 0, 0, 0); 420 lv1_gpu_context_attribute(sc->sc_fbcontext, 421 L1GPU_CONTEXT_ATTRIBUTE_DISPLAY_FLIP, 1, 0, 0, 0); 422 423 return (0); 424 } 425 426 static int 427 ps3fb_save_font(video_adapter_t *adp, int page, int size, int width, 428 u_char *data, int c, int count) 429 { 430 TODO; 431 return (0); 432 } 433 434 static int 435 ps3fb_load_font(video_adapter_t *adp, int page, int size, int width, 436 u_char *data, int c, int count) 437 { 438 struct ps3fb_softc *sc; 439 440 sc = (struct ps3fb_softc *)adp; 441 442 /* 443 * syscons code has already determined that current width/height 444 * are unchanged for this new font 445 */ 446 sc->sc_font = data; 447 return (0); 448 } 449 450 static int 451 ps3fb_show_font(video_adapter_t *adp, int page) 452 { 453 454 return (0); 455 } 456 457 static int 458 ps3fb_save_palette(video_adapter_t *adp, u_char *palette) 459 { 460 /* TODO; */ 461 return (0); 462 } 463 464 static int 465 ps3fb_load_palette(video_adapter_t *adp, u_char *palette) 466 { 467 /* TODO; */ 468 return (0); 469 } 470 471 static int 472 ps3fb_set_border(video_adapter_t *adp, int border) 473 { 474 /* XXX Be lazy for now and blank entire screen */ 475 return (ps3fb_blank_display(adp, border)); 476 } 477 478 static int 479 ps3fb_save_state(video_adapter_t *adp, void *p, size_t size) 480 { 481 TODO; 482 return (0); 483 } 484 485 static int 486 ps3fb_load_state(video_adapter_t *adp, void *p) 487 { 488 TODO; 489 return (0); 490 } 491 492 static int 493 ps3fb_set_win_org(video_adapter_t *adp, off_t offset) 494 { 495 TODO; 496 return (0); 497 } 498 499 static int 500 ps3fb_read_hw_cursor(video_adapter_t *adp, int *col, int *row) 501 { 502 *col = 0; 503 *row = 0; 504 505 return (0); 506 } 507 508 static int 509 ps3fb_set_hw_cursor(video_adapter_t *adp, int col, int row) 510 { 511 512 return (0); 513 } 514 515 static int 516 ps3fb_set_hw_cursor_shape(video_adapter_t *adp, int base, int height, 517 int celsize, int blink) 518 { 519 return (0); 520 } 521 522 static int 523 ps3fb_blank_display(video_adapter_t *adp, int mode) 524 { 525 struct ps3fb_softc *sc; 526 int i; 527 uint32_t *addr; 528 529 sc = (struct ps3fb_softc *)adp; 530 addr = (uint32_t *) sc->sc_addr; 531 532 for (i = 0; i < (sc->sc_stride/4)*sc->sc_height; i++) 533 *(addr + i) = ps3fb_pix32(ps3fb_background(SC_NORM_ATTR)); 534 535 return (0); 536 } 537 538 static int 539 ps3fb_mmap(video_adapter_t *adp, vm_ooffset_t offset, vm_paddr_t *paddr, 540 int prot, vm_memattr_t *memattr) 541 { 542 struct ps3fb_softc *sc; 543 544 sc = (struct ps3fb_softc *)adp; 545 546 /* 547 * This might be a legacy VGA mem request: if so, just point it at the 548 * framebuffer, since it shouldn't be touched 549 */ 550 if (offset < sc->sc_stride*sc->sc_height) { 551 *paddr = sc->sc_addr + offset; 552 return (0); 553 } 554 555 return (EINVAL); 556 } 557 558 static int 559 ps3fb_ioctl(video_adapter_t *adp, u_long cmd, caddr_t data) 560 { 561 562 return (0); 563 } 564 565 static int 566 ps3fb_clear(video_adapter_t *adp) 567 { 568 TODO; 569 return (0); 570 } 571 572 static int 573 ps3fb_fill_rect(video_adapter_t *adp, int val, int x, int y, int cx, int cy) 574 { 575 TODO; 576 return (0); 577 } 578 579 static int 580 ps3fb_bitblt(video_adapter_t *adp, ...) 581 { 582 TODO; 583 return (0); 584 } 585 586 static int 587 ps3fb_diag(video_adapter_t *adp, int level) 588 { 589 TODO; 590 return (0); 591 } 592 593 static int 594 ps3fb_save_cursor_palette(video_adapter_t *adp, u_char *palette) 595 { 596 TODO; 597 return (0); 598 } 599 600 static int 601 ps3fb_load_cursor_palette(video_adapter_t *adp, u_char *palette) 602 { 603 TODO; 604 return (0); 605 } 606 607 static int 608 ps3fb_copy(video_adapter_t *adp, vm_offset_t src, vm_offset_t dst, int n) 609 { 610 TODO; 611 return (0); 612 } 613 614 static int 615 ps3fb_putp(video_adapter_t *adp, vm_offset_t off, uint32_t p, uint32_t a, 616 int size, int bpp, int bit_ltor, int byte_ltor) 617 { 618 TODO; 619 return (0); 620 } 621 622 static int 623 ps3fb_putc(video_adapter_t *adp, vm_offset_t off, uint8_t c, uint8_t a) 624 { 625 struct ps3fb_softc *sc; 626 int row; 627 int col; 628 int i, j, k; 629 uint32_t *addr; 630 u_char *p; 631 632 sc = (struct ps3fb_softc *)adp; 633 row = (off / adp->va_info.vi_width) * adp->va_info.vi_cheight; 634 col = (off % adp->va_info.vi_width) * adp->va_info.vi_cwidth; 635 p = sc->sc_font + c*sc->sc_font_height; 636 addr = (uint32_t *)sc->sc_addr 637 + (row + sc->sc_ymargin)*(sc->sc_stride/4) 638 + col + sc->sc_xmargin; 639 640 for (i = 0; i < sc->sc_font_height; i++) { 641 for (j = 0, k = 7; j < 8; j++, k--) { 642 if ((p[i] & (1 << k)) == 0) 643 *(addr + j) = ps3fb_pix32(ps3fb_background(a)); 644 else 645 *(addr + j) = ps3fb_pix32(ps3fb_foreground(a)); 646 } 647 addr += (sc->sc_stride/4); 648 } 649 650 return (0); 651 } 652 653 static int 654 ps3fb_puts(video_adapter_t *adp, vm_offset_t off, u_int16_t *s, int len) 655 { 656 int i; 657 658 for (i = 0; i < len; i++) { 659 ps3fb_putc(adp, off + i, s[i] & 0xff, (s[i] & 0xff00) >> 8); 660 } 661 return (0); 662 } 663 664 static int 665 ps3fb_putm(video_adapter_t *adp, int x, int y, uint8_t *pixel_image, 666 uint32_t pixel_mask, int size, int width) 667 { 668 struct ps3fb_softc *sc; 669 int i, j, k; 670 uint32_t fg, bg; 671 uint32_t *addr; 672 673 sc = (struct ps3fb_softc *)adp; 674 addr = (uint32_t *)sc->sc_addr 675 + (y + sc->sc_ymargin)*(sc->sc_stride/4) 676 + x + sc->sc_xmargin; 677 678 fg = ps3fb_pix32(ps3fb_foreground(SC_NORM_ATTR)); 679 bg = ps3fb_pix32(ps3fb_background(SC_NORM_ATTR)); 680 681 for (i = 0; i < size && i+y < sc->sc_height - 2*sc->sc_ymargin; i++) { 682 for (j = 0, k = width; j < 8; j++, k--) { 683 if (x + j >= sc->sc_width - 2*sc->sc_xmargin) 684 continue; 685 686 if (pixel_image[i] & (1 << k)) 687 *(addr + j) = (*(addr + j) == fg) ? bg : fg; 688 } 689 addr += (sc->sc_stride/4); 690 } 691 692 return (0); 693 } 694 695 /* 696 * Define the syscons nexus device attachment 697 */ 698 static void 699 ps3fb_scidentify(driver_t *driver, device_t parent) 700 { 701 device_t child; 702 703 /* 704 * Add with a priority guaranteed to make it last on 705 * the device list 706 */ 707 if (strcmp(installed_platform(), "ps3") == 0) 708 child = BUS_ADD_CHILD(parent, INT_MAX, SC_DRIVER_NAME, 0); 709 } 710 711 static int 712 ps3fb_scprobe(device_t dev) 713 { 714 int error; 715 716 if (strcmp(installed_platform(), "ps3") != 0) 717 return (ENXIO); 718 719 device_set_desc(dev, "System console"); 720 721 error = sc_probe_unit(device_get_unit(dev), 722 device_get_flags(dev) | SC_AUTODETECT_KBD); 723 if (error != 0) 724 return (error); 725 726 /* This is a fake device, so make sure we added it ourselves */ 727 return (BUS_PROBE_NOWILDCARD); 728 } 729 730 static int 731 ps3fb_scattach(device_t dev) 732 { 733 return (sc_attach_unit(device_get_unit(dev), 734 device_get_flags(dev) | SC_AUTODETECT_KBD)); 735 } 736 737 static device_method_t ps3fb_sc_methods[] = { 738 DEVMETHOD(device_identify, ps3fb_scidentify), 739 DEVMETHOD(device_probe, ps3fb_scprobe), 740 DEVMETHOD(device_attach, ps3fb_scattach), 741 { 0, 0 } 742 }; 743 744 static driver_t ps3fb_sc_driver = { 745 SC_DRIVER_NAME, 746 ps3fb_sc_methods, 747 sizeof(sc_softc_t), 748 }; 749 750 static devclass_t sc_devclass; 751 752 DRIVER_MODULE(sc, nexus, ps3fb_sc_driver, sc_devclass, 0, 0); 753 754 /* 755 * Define a stub keyboard driver in case one hasn't been 756 * compiled into the kernel 757 */ 758 #include <sys/kbio.h> 759 #include <dev/kbd/kbdreg.h> 760 761 static int dummy_kbd_configure(int flags); 762 763 keyboard_switch_t ps3dummysw; 764 765 static int 766 dummy_kbd_configure(int flags) 767 { 768 769 return (0); 770 } 771 KEYBOARD_DRIVER(ps3dummy, ps3dummysw, dummy_kbd_configure); 772 773