efifb.c revision 262785
1/*- 2 * Copyright (c) 2014 The FreeBSD Foundation 3 * All rights reserved. 4 * 5 * This software was developed by Aleksandr Rybalko under sponsorship from the 6 * FreeBSD Foundation. 7 * 8 * Redistribution and use in source and binary forms, with or without 9 * modification, are permitted provided that the following conditions 10 * are met: 11 * 1. Redistributions of source code must retain the above copyright 12 * notice, this list of conditions and the following disclaimer. 13 * 2. Redistributions in binary form must reproduce the above copyright 14 * notice, this list of conditions and the following disclaimer in the 15 * documentation and/or other materials provided with the distribution. 16 * 17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 18 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 19 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 20 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 21 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 22 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 23 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 24 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 25 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 26 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 27 * SUCH DAMAGE. 28 * 29 * $FreeBSD: head/sys/dev/vt/hw/efifb/efifb.c 262785 2014-03-05 14:37:45Z ray $ 30 */ 31 32#include <sys/cdefs.h> 33__FBSDID("$FreeBSD: head/sys/dev/vt/hw/efifb/efifb.c 262785 2014-03-05 14:37:45Z ray $"); 34 35#include <sys/param.h> 36#include <sys/systm.h> 37#include <sys/kernel.h> 38#include <sys/fbio.h> 39#include <sys/linker.h> 40 41#include "opt_platform.h" 42 43#include <machine/efi.h> 44#include <machine/metadata.h> 45#include <machine/vm.h> 46#include <machine/vmparam.h> 47#include <vm/vm.h> 48#include <vm/pmap.h> 49#include <machine/pmap.h> 50 51#include <dev/vt/vt.h> 52#include <dev/vt/hw/fb/vt_fb.h> 53#include <dev/vt/colors/vt_termcolors.h> 54 55static vd_init_t vt_efb_init; 56 57static struct vt_driver vt_efb_driver = { 58 .vd_init = vt_efb_init, 59 .vd_blank = vt_fb_blank, 60 .vd_bitbltchr = vt_fb_bitbltchr, 61 /* Better than VGA, but still generic driver. */ 62 .vd_priority = VD_PRIORITY_GENERIC + 1, 63}; 64 65static struct fb_info info; 66VT_CONSDEV_DECLARE(vt_efb_driver, 67 MAX(80, PIXEL_WIDTH(VT_FB_DEFAULT_WIDTH)), 68 MAX(25, PIXEL_HEIGHT(VT_FB_DEFAULT_HEIGHT)), &info); 69 70static int 71vt_efb_init(struct vt_device *vd) 72{ 73 int depth, d, disable, i, len; 74 struct fb_info *info; 75 struct efi_fb *efifb; 76 caddr_t kmdp; 77 78 info = vd->vd_softc; 79 80 disable = 0; 81 TUNABLE_INT_FETCH("hw.syscons.disable", &disable); 82 if (disable != 0) 83 return (CN_DEAD); 84 85 kmdp = preload_search_by_type("elf kernel"); 86 if (kmdp == NULL) 87 kmdp = preload_search_by_type("elf64 kernel"); 88 efifb = (struct efi_fb *)preload_search_info(kmdp, 89 MODINFO_METADATA | MODINFOMD_EFI_FB); 90 if (!efifb->fb_present) 91 return (CN_DEAD); 92 93 info->fb_height = efifb->fb_height; 94 info->fb_width = efifb->fb_width; 95 96 depth = fls(efifb->fb_mask_red); 97 d = fls(efifb->fb_mask_green); 98 depth = d > depth ? d : depth; 99 d = fls(efifb->fb_mask_blue); 100 depth = d > depth ? d : depth; 101 d = fls(efifb->fb_mask_reserved); 102 depth = d > depth ? d : depth; 103 info->fb_depth = depth; 104 105 info->fb_stride = efifb->fb_stride * (depth / 8); 106 107 vt_generate_vga_palette(info->fb_cmap, COLOR_FORMAT_RGB, 108 efifb->fb_mask_red, ffs(efifb->fb_mask_red) - 1, 109 efifb->fb_mask_green, ffs(efifb->fb_mask_green) - 1, 110 efifb->fb_mask_blue, ffs(efifb->fb_mask_blue) - 1); 111 112 info->fb_size = info->fb_height * info->fb_stride; 113 info->fb_pbase = efifb->fb_addr; 114 /* 115 * We could use pmap_mapdev here except that the kernel pmap 116 * hasn't been created yet and hence any attempt to lock it will 117 * fail. 118 */ 119 info->fb_vbase = PHYS_TO_DMAP(efifb->fb_addr); 120 121 /* blank full size */ 122 len = info->fb_size / 4; 123 for (i = 0; i < len; i++) { 124 ((uint32_t *)info->fb_vbase)[i] = 0; 125 } 126 127 /* Get pixel storage size. */ 128 info->fb_bpp = info->fb_stride / info->fb_width * 8; 129 130 /* 131 * Early FB driver work with static window buffer, so reduce to minimal 132 * size, buffer or screen. 133 */ 134 info->fb_width = MIN(info->fb_width, VT_FB_DEFAULT_WIDTH); 135 info->fb_height = MIN(info->fb_height, VT_FB_DEFAULT_HEIGHT); 136 137 fb_probe(info); 138 vt_fb_init(vd); 139 140 141 return (CN_INTERNAL); 142} 143 144