1/*- 2 * Copyright (c) 2012 Oleksandr Tymoshenko <gonzo@freebsd.org> 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: stable/11/sys/arm/broadcom/bcm2835/bcm2835_fb.c 356110 2019-12-27 03:00:18Z kevans $"); 29 30#include <sys/param.h> 31#include <sys/systm.h> 32#include <sys/bus.h> 33#include <sys/consio.h> 34#include <sys/fbio.h> 35#include <sys/kdb.h> 36#include <sys/kernel.h> 37#include <sys/malloc.h> 38#include <sys/module.h> 39 40#include <vm/vm.h> 41#include <vm/pmap.h> 42 43#include <dev/fb/fbreg.h> 44#include <dev/fdt/fdt_common.h> 45#include <dev/ofw/ofw_bus.h> 46#include <dev/ofw/ofw_bus_subr.h> 47#include <dev/syscons/syscons.h> 48 49#include <arm/broadcom/bcm2835/bcm2835_mbox_prop.h> 50 51#include "mbox_if.h" 52 53struct argb { 54 uint8_t a; 55 uint8_t r; 56 uint8_t g; 57 uint8_t b; 58}; 59 60static struct argb bcmfb_palette[16] = { 61 {0x00, 0x00, 0x00, 0x00}, 62 {0x00, 0x00, 0x00, 0xaa}, 63 {0x00, 0x00, 0xaa, 0x00}, 64 {0x00, 0x00, 0xaa, 0xaa}, 65 {0x00, 0xaa, 0x00, 0x00}, 66 {0x00, 0xaa, 0x00, 0xaa}, 67 {0x00, 0xaa, 0x55, 0x00}, 68 {0x00, 0xaa, 0xaa, 0xaa}, 69 {0x00, 0x55, 0x55, 0x55}, 70 {0x00, 0x55, 0x55, 0xff}, 71 {0x00, 0x55, 0xff, 0x55}, 72 {0x00, 0x55, 0xff, 0xff}, 73 {0x00, 0xff, 0x55, 0x55}, 74 {0x00, 0xff, 0x55, 0xff}, 75 {0x00, 0xff, 0xff, 0x55}, 76 {0x00, 0xff, 0xff, 0xff} 77}; 78 79/* mouse pointer from dev/syscons/scgfbrndr.c */ 80static u_char mouse_pointer[16] = { 81 0x00, 0x40, 0x60, 0x70, 0x78, 0x7c, 0x7e, 0x68, 82 0x0c, 0x0c, 0x06, 0x06, 0x00, 0x00, 0x00, 0x00 83}; 84 85#define BCMFB_FONT_HEIGHT 16 86#define BCMFB_FONT_WIDTH 8 87#define FB_WIDTH 640 88#define FB_HEIGHT 480 89#define FB_DEPTH 24 90 91struct bcmsc_softc { 92 /* Videoadpater part */ 93 video_adapter_t va; 94 95 intptr_t fb_addr; 96 intptr_t fb_paddr; 97 unsigned int fb_size; 98 99 unsigned int height; 100 unsigned int width; 101 unsigned int depth; 102 unsigned int stride; 103 104 unsigned int xmargin; 105 unsigned int ymargin; 106 107 unsigned char *font; 108 int fbswap; 109 int initialized; 110}; 111 112static struct bcmsc_softc bcmsc; 113 114static struct ofw_compat_data compat_data[] = { 115 {"broadcom,bcm2835-fb", 1}, 116 {"brcm,bcm2708-fb", 1}, 117 {NULL, 0} 118}; 119 120static int bcm_fb_probe(device_t); 121static int bcm_fb_attach(device_t); 122static void bcmfb_update_margins(video_adapter_t *adp); 123static int bcmfb_configure(int); 124 125static int 126bcm_fb_probe(device_t dev) 127{ 128 int error; 129 130 if (ofw_bus_search_compatible(dev, compat_data)->ocd_data == 0) 131 return (ENXIO); 132 133 device_set_desc(dev, "BCM2835 framebuffer device"); 134 error = sc_probe_unit(device_get_unit(dev), 135 device_get_flags(dev) | SC_AUTODETECT_KBD); 136 if (error != 0) 137 return (error); 138 139 return (BUS_PROBE_DEFAULT); 140} 141 142static int 143bcm_fb_attach(device_t dev) 144{ 145 struct bcm2835_fb_config fb; 146 struct bcmsc_softc *sc; 147 148 sc = (struct bcmsc_softc *)vid_get_adapter(vid_find_adapter( 149 "bcmfb", 0)); 150 if (sc != NULL) 151 device_set_softc(dev, sc); 152 else 153 sc = device_get_softc(dev); 154 155 memset(&fb, 0, sizeof(fb)); 156 if (bcm2835_mbox_fb_get_w_h(&fb) != 0) 157 return (ENXIO); 158 fb.bpp = FB_DEPTH; 159 fb.vxres = fb.xres; 160 fb.vyres = fb.yres; 161 fb.xoffset = fb.yoffset = 0; 162 if (bcm2835_mbox_fb_init(&fb) != 0) 163 return (ENXIO); 164 165 sc->fb_addr = (intptr_t)pmap_mapdev(fb.base, fb.size); 166 sc->fb_paddr = fb.base; 167 sc->fb_size = fb.size; 168 sc->depth = fb.bpp; 169 sc->stride = fb.pitch; 170 sc->width = fb.xres; 171 sc->height = fb.yres; 172 bcmfb_update_margins(&sc->va); 173 174 if (sc_attach_unit(device_get_unit(dev), 175 device_get_flags(dev) | SC_AUTODETECT_KBD) != 0) { 176 device_printf(dev, "failed to attach syscons\n"); 177 return (ENXIO); 178 } 179 180 device_printf(dev, "%dx%d(%dx%d@%d,%d) %dbpp\n", fb.xres, fb.yres, 181 fb.vxres, fb.vyres, fb.xoffset, fb.yoffset, fb.bpp); 182 device_printf(dev, 183 "fbswap: %d, pitch %d, base 0x%08x, screen_size %d\n", 184 sc->fbswap, fb.pitch, fb.base, fb.size); 185 186 return (0); 187} 188 189static device_method_t bcm_fb_methods[] = { 190 /* Device interface */ 191 DEVMETHOD(device_probe, bcm_fb_probe), 192 DEVMETHOD(device_attach, bcm_fb_attach), 193 194 { 0, 0 } 195}; 196 197static devclass_t bcm_fb_devclass; 198 199static driver_t bcm_fb_driver = { 200 "fb", 201 bcm_fb_methods, 202 sizeof(struct bcmsc_softc), 203}; 204 205DRIVER_MODULE(bcm2835fb, ofwbus, bcm_fb_driver, bcm_fb_devclass, 0, 0); 206DRIVER_MODULE(bcm2835fb, simplebus, bcm_fb_driver, bcm_fb_devclass, 0, 0); 207 208/* 209 * Video driver routines and glue. 210 */ 211static vi_probe_t bcmfb_probe; 212static vi_init_t bcmfb_init; 213static vi_get_info_t bcmfb_get_info; 214static vi_query_mode_t bcmfb_query_mode; 215static vi_set_mode_t bcmfb_set_mode; 216static vi_save_font_t bcmfb_save_font; 217static vi_load_font_t bcmfb_load_font; 218static vi_show_font_t bcmfb_show_font; 219static vi_save_palette_t bcmfb_save_palette; 220static vi_load_palette_t bcmfb_load_palette; 221static vi_set_border_t bcmfb_set_border; 222static vi_save_state_t bcmfb_save_state; 223static vi_load_state_t bcmfb_load_state; 224static vi_set_win_org_t bcmfb_set_win_org; 225static vi_read_hw_cursor_t bcmfb_read_hw_cursor; 226static vi_set_hw_cursor_t bcmfb_set_hw_cursor; 227static vi_set_hw_cursor_shape_t bcmfb_set_hw_cursor_shape; 228static vi_blank_display_t bcmfb_blank_display; 229static vi_mmap_t bcmfb_mmap; 230static vi_ioctl_t bcmfb_ioctl; 231static vi_clear_t bcmfb_clear; 232static vi_fill_rect_t bcmfb_fill_rect; 233static vi_bitblt_t bcmfb_bitblt; 234static vi_diag_t bcmfb_diag; 235static vi_save_cursor_palette_t bcmfb_save_cursor_palette; 236static vi_load_cursor_palette_t bcmfb_load_cursor_palette; 237static vi_copy_t bcmfb_copy; 238static vi_putp_t bcmfb_putp; 239static vi_putc_t bcmfb_putc; 240static vi_puts_t bcmfb_puts; 241static vi_putm_t bcmfb_putm; 242 243static video_switch_t bcmfbvidsw = { 244 .probe = bcmfb_probe, 245 .init = bcmfb_init, 246 .get_info = bcmfb_get_info, 247 .query_mode = bcmfb_query_mode, 248 .set_mode = bcmfb_set_mode, 249 .save_font = bcmfb_save_font, 250 .load_font = bcmfb_load_font, 251 .show_font = bcmfb_show_font, 252 .save_palette = bcmfb_save_palette, 253 .load_palette = bcmfb_load_palette, 254 .set_border = bcmfb_set_border, 255 .save_state = bcmfb_save_state, 256 .load_state = bcmfb_load_state, 257 .set_win_org = bcmfb_set_win_org, 258 .read_hw_cursor = bcmfb_read_hw_cursor, 259 .set_hw_cursor = bcmfb_set_hw_cursor, 260 .set_hw_cursor_shape = bcmfb_set_hw_cursor_shape, 261 .blank_display = bcmfb_blank_display, 262 .mmap = bcmfb_mmap, 263 .ioctl = bcmfb_ioctl, 264 .clear = bcmfb_clear, 265 .fill_rect = bcmfb_fill_rect, 266 .bitblt = bcmfb_bitblt, 267 .diag = bcmfb_diag, 268 .save_cursor_palette = bcmfb_save_cursor_palette, 269 .load_cursor_palette = bcmfb_load_cursor_palette, 270 .copy = bcmfb_copy, 271 .putp = bcmfb_putp, 272 .putc = bcmfb_putc, 273 .puts = bcmfb_puts, 274 .putm = bcmfb_putm, 275}; 276 277VIDEO_DRIVER(bcmfb, bcmfbvidsw, bcmfb_configure); 278 279static vr_init_t bcmrend_init; 280static vr_clear_t bcmrend_clear; 281static vr_draw_border_t bcmrend_draw_border; 282static vr_draw_t bcmrend_draw; 283static vr_set_cursor_t bcmrend_set_cursor; 284static vr_draw_cursor_t bcmrend_draw_cursor; 285static vr_blink_cursor_t bcmrend_blink_cursor; 286static vr_set_mouse_t bcmrend_set_mouse; 287static vr_draw_mouse_t bcmrend_draw_mouse; 288 289/* 290 * We use our own renderer; this is because we must emulate a hardware 291 * cursor. 292 */ 293static sc_rndr_sw_t bcmrend = { 294 bcmrend_init, 295 bcmrend_clear, 296 bcmrend_draw_border, 297 bcmrend_draw, 298 bcmrend_set_cursor, 299 bcmrend_draw_cursor, 300 bcmrend_blink_cursor, 301 bcmrend_set_mouse, 302 bcmrend_draw_mouse 303}; 304 305RENDERER(bcmfb, 0, bcmrend, gfb_set); 306RENDERER_MODULE(bcmfb, gfb_set); 307 308static void 309bcmrend_init(scr_stat* scp) 310{ 311} 312 313static void 314bcmrend_clear(scr_stat* scp, int c, int attr) 315{ 316} 317 318static void 319bcmrend_draw_border(scr_stat* scp, int color) 320{ 321} 322 323static void 324bcmrend_draw(scr_stat* scp, int from, int count, int flip) 325{ 326 video_adapter_t* adp = scp->sc->adp; 327 int i, c, a; 328 329 if (!flip) { 330 /* Normal printing */ 331 vidd_puts(adp, from, (uint16_t*)sc_vtb_pointer(&scp->vtb, from), count); 332 } else { 333 /* This is for selections and such: invert the color attribute */ 334 for (i = count; i-- > 0; ++from) { 335 c = sc_vtb_getc(&scp->vtb, from); 336 a = sc_vtb_geta(&scp->vtb, from) >> 8; 337 vidd_putc(adp, from, c, (a >> 4) | ((a & 0xf) << 4)); 338 } 339 } 340} 341 342static void 343bcmrend_set_cursor(scr_stat* scp, int base, int height, int blink) 344{ 345} 346 347static void 348bcmrend_draw_cursor(scr_stat* scp, int off, int blink, int on, int flip) 349{ 350 int bytes, col, i, j, row; 351 struct bcmsc_softc *sc; 352 uint8_t *addr; 353 video_adapter_t *adp; 354 355 adp = scp->sc->adp; 356 sc = (struct bcmsc_softc *)adp; 357 358 if (scp->curs_attr.height <= 0) 359 return; 360 361 if (sc->fb_addr == 0) 362 return; 363 364 if (off >= adp->va_info.vi_width * adp->va_info.vi_height) 365 return; 366 367 /* calculate the coordinates in the video buffer */ 368 row = (off / adp->va_info.vi_width) * adp->va_info.vi_cheight; 369 col = (off % adp->va_info.vi_width) * adp->va_info.vi_cwidth; 370 371 addr = (uint8_t *)sc->fb_addr 372 + (row + sc->ymargin)*(sc->stride) 373 + (sc->depth/8) * (col + sc->xmargin); 374 375 bytes = sc->depth / 8; 376 /* our cursor consists of simply inverting the char under it */ 377 for (i = 0; i < adp->va_info.vi_cheight; i++) { 378 for (j = 0; j < adp->va_info.vi_cwidth; j++) { 379 switch (sc->depth) { 380 case 32: 381 case 24: 382 addr[bytes*j + 2] ^= 0xff; 383 /* FALLTHROUGH */ 384 case 16: 385 addr[bytes*j + 1] ^= 0xff; 386 addr[bytes*j] ^= 0xff; 387 break; 388 default: 389 break; 390 } 391 } 392 393 addr += sc->stride; 394 } 395} 396 397static void 398bcmrend_blink_cursor(scr_stat* scp, int at, int flip) 399{ 400} 401 402static void 403bcmrend_set_mouse(scr_stat* scp) 404{ 405} 406 407static void 408bcmrend_draw_mouse(scr_stat* scp, int x, int y, int on) 409{ 410 vidd_putm(scp->sc->adp, x, y, mouse_pointer, 0xffffffff, 16, 8); 411} 412 413static uint16_t bcmfb_static_window[ROW*COL]; 414extern u_char dflt_font_16[]; 415 416/* 417 * Update videoadapter settings after changing resolution 418 */ 419static void 420bcmfb_update_margins(video_adapter_t *adp) 421{ 422 struct bcmsc_softc *sc; 423 video_info_t *vi; 424 425 sc = (struct bcmsc_softc *)adp; 426 vi = &adp->va_info; 427 428 sc->xmargin = (sc->width - (vi->vi_width * vi->vi_cwidth)) / 2; 429 sc->ymargin = (sc->height - (vi->vi_height * vi->vi_cheight)) / 2; 430} 431 432static int 433bcmfb_configure(int flags) 434{ 435 char bootargs[2048], *n, *p, *v; 436 pcell_t cell; 437 phandle_t chosen, display, root; 438 struct bcmsc_softc *sc; 439 440 sc = &bcmsc; 441 if (sc->initialized) 442 return (0); 443 444 sc->width = 0; 445 sc->height = 0; 446 447 /* 448 * It seems there is no way to let syscons framework know 449 * that framebuffer resolution has changed. So just try 450 * to fetch data from FDT bootargs, FDT display data and 451 * finally go with defaults if everything else has failed. 452 */ 453 chosen = OF_finddevice("/chosen"); 454 if (chosen != 0 && 455 OF_getprop(chosen, "bootargs", &bootargs, sizeof(bootargs)) > 0) { 456 p = bootargs; 457 while ((v = strsep(&p, " ")) != NULL) { 458 if (*v == '\0') 459 continue; 460 n = strsep(&v, "="); 461 if (strcmp(n, "bcm2708_fb.fbwidth") == 0 && v != NULL) 462 sc->width = (unsigned int)strtol(v, NULL, 0); 463 else if (strcmp(n, "bcm2708_fb.fbheight") == 0 && 464 v != NULL) 465 sc->height = (unsigned int)strtol(v, NULL, 0); 466 else if (strcmp(n, "bcm2708_fb.fbswap") == 0 && 467 v != NULL) 468 if (*v == '1') 469 sc->fbswap = 1; 470 } 471 } 472 473 root = OF_finddevice("/"); 474 if ((root != 0) && 475 (display = fdt_find_compatible(root, "broadcom,bcm2835-fb", 1))) { 476 if (sc->width == 0) { 477 if ((OF_getencprop(display, "broadcom,width", 478 &cell, sizeof(cell))) > 0) 479 sc->width = cell; 480 } 481 482 if (sc->height == 0) { 483 if ((OF_getprop(display, "broadcom,height", 484 &cell, sizeof(cell))) > 0) 485 sc->height = cell; 486 } 487 } 488 489 if (sc->width == 0) 490 sc->width = FB_WIDTH; 491 if (sc->height == 0) 492 sc->height = FB_HEIGHT; 493 494 bcmfb_init(0, &sc->va, 0); 495 sc->initialized = 1; 496 497 return (0); 498} 499 500static int 501bcmfb_probe(int unit, video_adapter_t **adp, void *arg, int flags) 502{ 503 504 return (0); 505} 506 507static int 508bcmfb_init(int unit, video_adapter_t *adp, int flags) 509{ 510 struct bcmsc_softc *sc; 511 video_info_t *vi; 512 513 sc = (struct bcmsc_softc *)adp; 514 vi = &adp->va_info; 515 516 vid_init_struct(adp, "bcmfb", -1, unit); 517 518 sc->font = dflt_font_16; 519 vi->vi_cheight = BCMFB_FONT_HEIGHT; 520 vi->vi_cwidth = BCMFB_FONT_WIDTH; 521 vi->vi_width = sc->width / vi->vi_cwidth; 522 vi->vi_height = sc->height / vi->vi_cheight; 523 524 /* 525 * Clamp width/height to syscons maximums 526 */ 527 if (vi->vi_width > COL) 528 vi->vi_width = COL; 529 if (vi->vi_height > ROW) 530 vi->vi_height = ROW; 531 532 sc->xmargin = (sc->width - (vi->vi_width * vi->vi_cwidth)) / 2; 533 sc->ymargin = (sc->height - (vi->vi_height * vi->vi_cheight)) / 2; 534 535 adp->va_window = (vm_offset_t) bcmfb_static_window; 536 adp->va_flags |= V_ADP_FONT /* | V_ADP_COLOR | V_ADP_MODECHANGE */; 537 538 vid_register(&sc->va); 539 540 return (0); 541} 542 543static int 544bcmfb_get_info(video_adapter_t *adp, int mode, video_info_t *info) 545{ 546 bcopy(&adp->va_info, info, sizeof(*info)); 547 return (0); 548} 549 550static int 551bcmfb_query_mode(video_adapter_t *adp, video_info_t *info) 552{ 553 return (0); 554} 555 556static int 557bcmfb_set_mode(video_adapter_t *adp, int mode) 558{ 559 return (0); 560} 561 562static int 563bcmfb_save_font(video_adapter_t *adp, int page, int size, int width, 564 u_char *data, int c, int count) 565{ 566 return (0); 567} 568 569static int 570bcmfb_load_font(video_adapter_t *adp, int page, int size, int width, 571 u_char *data, int c, int count) 572{ 573 struct bcmsc_softc *sc; 574 575 sc = (struct bcmsc_softc *)adp; 576 sc->font = data; 577 578 return (0); 579} 580 581static int 582bcmfb_show_font(video_adapter_t *adp, int page) 583{ 584 return (0); 585} 586 587static int 588bcmfb_save_palette(video_adapter_t *adp, u_char *palette) 589{ 590 return (0); 591} 592 593static int 594bcmfb_load_palette(video_adapter_t *adp, u_char *palette) 595{ 596 return (0); 597} 598 599static int 600bcmfb_set_border(video_adapter_t *adp, int border) 601{ 602 return (bcmfb_blank_display(adp, border)); 603} 604 605static int 606bcmfb_save_state(video_adapter_t *adp, void *p, size_t size) 607{ 608 return (0); 609} 610 611static int 612bcmfb_load_state(video_adapter_t *adp, void *p) 613{ 614 return (0); 615} 616 617static int 618bcmfb_set_win_org(video_adapter_t *adp, off_t offset) 619{ 620 return (0); 621} 622 623static int 624bcmfb_read_hw_cursor(video_adapter_t *adp, int *col, int *row) 625{ 626 *col = *row = 0; 627 628 return (0); 629} 630 631static int 632bcmfb_set_hw_cursor(video_adapter_t *adp, int col, int row) 633{ 634 return (0); 635} 636 637static int 638bcmfb_set_hw_cursor_shape(video_adapter_t *adp, int base, int height, 639 int celsize, int blink) 640{ 641 return (0); 642} 643 644static int 645bcmfb_blank_display(video_adapter_t *adp, int mode) 646{ 647 648 struct bcmsc_softc *sc; 649 650 sc = (struct bcmsc_softc *)adp; 651 if (sc && sc->fb_addr) 652 memset((void*)sc->fb_addr, 0, sc->fb_size); 653 654 return (0); 655} 656 657static int 658bcmfb_mmap(video_adapter_t *adp, vm_ooffset_t offset, vm_paddr_t *paddr, 659 int prot, vm_memattr_t *memattr) 660{ 661 struct bcmsc_softc *sc; 662 663 sc = (struct bcmsc_softc *)adp; 664 665 /* 666 * This might be a legacy VGA mem request: if so, just point it at the 667 * framebuffer, since it shouldn't be touched 668 */ 669 if (offset < sc->stride*sc->height) { 670 *paddr = sc->fb_paddr + offset; 671 return (0); 672 } 673 674 return (EINVAL); 675} 676 677static int 678bcmfb_ioctl(video_adapter_t *adp, u_long cmd, caddr_t data) 679{ 680 struct bcmsc_softc *sc; 681 struct fbtype *fb; 682 683 sc = (struct bcmsc_softc *)adp; 684 685 switch (cmd) { 686 case FBIOGTYPE: 687 fb = (struct fbtype *)data; 688 fb->fb_type = FBTYPE_PCIMISC; 689 fb->fb_height = sc->height; 690 fb->fb_width = sc->width; 691 fb->fb_depth = sc->depth; 692 if (sc->depth <= 1 || sc->depth > 8) 693 fb->fb_cmsize = 0; 694 else 695 fb->fb_cmsize = 1 << sc->depth; 696 fb->fb_size = sc->fb_size; 697 break; 698 default: 699 return (fb_commonioctl(adp, cmd, data)); 700 } 701 702 return (0); 703} 704 705static int 706bcmfb_clear(video_adapter_t *adp) 707{ 708 709 return (bcmfb_blank_display(adp, 0)); 710} 711 712static int 713bcmfb_fill_rect(video_adapter_t *adp, int val, int x, int y, int cx, int cy) 714{ 715 716 return (0); 717} 718 719static int 720bcmfb_bitblt(video_adapter_t *adp, ...) 721{ 722 723 return (0); 724} 725 726static int 727bcmfb_diag(video_adapter_t *adp, int level) 728{ 729 730 return (0); 731} 732 733static int 734bcmfb_save_cursor_palette(video_adapter_t *adp, u_char *palette) 735{ 736 737 return (0); 738} 739 740static int 741bcmfb_load_cursor_palette(video_adapter_t *adp, u_char *palette) 742{ 743 744 return (0); 745} 746 747static int 748bcmfb_copy(video_adapter_t *adp, vm_offset_t src, vm_offset_t dst, int n) 749{ 750 751 return (0); 752} 753 754static int 755bcmfb_putp(video_adapter_t *adp, vm_offset_t off, uint32_t p, uint32_t a, 756 int size, int bpp, int bit_ltor, int byte_ltor) 757{ 758 759 return (0); 760} 761 762static int 763bcmfb_putc(video_adapter_t *adp, vm_offset_t off, uint8_t c, uint8_t a) 764{ 765 int bytes, col, i, j, k, row; 766 struct bcmsc_softc *sc; 767 u_char *p; 768 uint8_t *addr, fg, bg, color; 769 uint16_t rgb; 770 771 sc = (struct bcmsc_softc *)adp; 772 773 if (sc->fb_addr == 0) 774 return (0); 775 776 row = (off / adp->va_info.vi_width) * adp->va_info.vi_cheight; 777 col = (off % adp->va_info.vi_width) * adp->va_info.vi_cwidth; 778 p = sc->font + c*BCMFB_FONT_HEIGHT; 779 addr = (uint8_t *)sc->fb_addr 780 + (row + sc->ymargin)*(sc->stride) 781 + (sc->depth/8) * (col + sc->xmargin); 782 783 fg = a & 0xf ; 784 bg = (a >> 4) & 0xf; 785 786 bytes = sc->depth / 8; 787 for (i = 0; i < BCMFB_FONT_HEIGHT; i++) { 788 for (j = 0, k = 7; j < 8; j++, k--) { 789 if ((p[i] & (1 << k)) == 0) 790 color = bg; 791 else 792 color = fg; 793 794 switch (sc->depth) { 795 case 32: 796 case 24: 797 if (sc->fbswap) { 798 addr[bytes * j + 0] = 799 bcmfb_palette[color].b; 800 addr[bytes * j + 1] = 801 bcmfb_palette[color].g; 802 addr[bytes * j + 2] = 803 bcmfb_palette[color].r; 804 } else { 805 addr[bytes * j + 0] = 806 bcmfb_palette[color].r; 807 addr[bytes * j + 1] = 808 bcmfb_palette[color].g; 809 addr[bytes * j + 2] = 810 bcmfb_palette[color].b; 811 } 812 if (sc->depth == 32) 813 addr[bytes * j + 3] = 814 bcmfb_palette[color].a; 815 break; 816 case 16: 817 rgb = (bcmfb_palette[color].r >> 3) << 11; 818 rgb |= (bcmfb_palette[color].g >> 2) << 5; 819 rgb |= (bcmfb_palette[color].b >> 3); 820 addr[bytes * j] = rgb & 0xff; 821 addr[bytes * j + 1] = (rgb >> 8) & 0xff; 822 default: 823 /* Not supported yet */ 824 break; 825 } 826 } 827 828 addr += (sc->stride); 829 } 830 831 return (0); 832} 833 834static int 835bcmfb_puts(video_adapter_t *adp, vm_offset_t off, u_int16_t *s, int len) 836{ 837 int i; 838 839 for (i = 0; i < len; i++) 840 bcmfb_putc(adp, off + i, s[i] & 0xff, (s[i] & 0xff00) >> 8); 841 842 return (0); 843} 844 845static int 846bcmfb_putm(video_adapter_t *adp, int x, int y, uint8_t *pixel_image, 847 uint32_t pixel_mask, int size, int width) 848{ 849 850 return (0); 851} 852