The Design and Implementation of the FreeBSD Operating System, Second Edition
Now available: The Design and Implementation of the FreeBSD Operating System (Second Edition)


[ source navigation ] [ diff markup ] [ identifier search ] [ freetext search ] [ file search ] [ list types ] [ track identifier ]

FreeBSD/Linux Kernel Cross Reference
sys/arm/broadcom/bcm2835/bcm2835_fb.c

Version: -  FREEBSD  -  FREEBSD-13-STABLE  -  FREEBSD-13-0  -  FREEBSD-12-STABLE  -  FREEBSD-12-0  -  FREEBSD-11-STABLE  -  FREEBSD-11-0  -  FREEBSD-10-STABLE  -  FREEBSD-10-0  -  FREEBSD-9-STABLE  -  FREEBSD-9-0  -  FREEBSD-8-STABLE  -  FREEBSD-8-0  -  FREEBSD-7-STABLE  -  FREEBSD-7-0  -  FREEBSD-6-STABLE  -  FREEBSD-6-0  -  FREEBSD-5-STABLE  -  FREEBSD-5-0  -  FREEBSD-4-STABLE  -  FREEBSD-3-STABLE  -  FREEBSD22  -  l41  -  OPENBSD  -  linux-2.6  -  MK84  -  PLAN9  -  xnu-8792 
SearchContext: -  none  -  3  -  10 

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

Cache object: a5d96b48f9ee6a07e6248f407092e16b


[ source navigation ] [ diff markup ] [ identifier search ] [ freetext search ] [ file search ] [ list types ] [ track identifier ]


This page is part of the FreeBSD/Linux Linux Kernel Cross-Reference, and was automatically generated using a modified version of the LXR engine.