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