/*- * Copyright (c) 2014 Nathan Whitehorn * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. */ #include __FBSDID("$FreeBSD: head/sys/dev/vt/hw/ofwfb/ofwfb.c 268350 2014-07-07 00:12:18Z nwhitehorn $"); #include #include #include #include #include #include #include #include #include #include #include "creatorreg.h" static vd_probe_t creatorfb_probe; static vd_init_t creatorfb_init; static const struct vt_driver vt_creatorfb_driver = { .vd_name = "creatorfb", .vd_probe = creatorfb_probe, .vd_init = creatorfb_init, .vd_blank = vt_fb_blank, .vd_bitbltchr = vt_fb_bitbltchr, .vd_maskbitbltchr = vt_fb_maskbitbltchr, .vd_fb_ioctl = vt_fb_ioctl, .vd_fb_mmap = vt_fb_mmap, .vd_priority = VD_PRIORITY_SPECIFIC }; static struct fb_info creatorfb_conssoftc; VT_DRIVER_DECLARE(vt_creatorfb, vt_creatorfb_driver); static int creatorfb_probe(struct vt_device *vd) { phandle_t chosen, node; ihandle_t stdout; char type[64], name[64]; OF_printf("%s: %d\n", __FILE__, __LINE__); chosen = OF_finddevice("/chosen"); OF_getprop(chosen, "stdout", &stdout, sizeof(stdout)); node = OF_instance_to_package(stdout); if (node == -1) { /* * The "/chosen/stdout" does not exist try * using "screen" directly. */ node = OF_finddevice("screen"); } OF_getprop(node, "device_type", type, sizeof(type)); if (strcmp(type, "display") != 0) return (CN_DEAD); OF_getprop(node, "name", name, sizeof(name)); if (strcmp(name, "SUNW,ffb") != 0 && strcmp(name, "SUNW,afb") != 0) return (CN_DEAD); OF_printf("%s: %d\n", __FILE__, __LINE__); /* Looks OK... */ return (CN_INTERNAL); } static int creatorfb_init(struct vt_device *vd) { struct fb_info *sc; phandle_t chosen; phandle_t node; ihandle_t handle; uint32_t height, width; static struct bus_space_tag ofwfb_memt[1]; char type[64], name[64]; bus_addr_t phys; int space; /* Initialize softc */ vd->vd_softc = sc = &creatorfb_conssoftc; OF_printf("%s: %d\n", __FILE__, __LINE__); chosen = OF_finddevice("/chosen"); OF_getprop(chosen, "stdout", &handle, sizeof(ihandle_t)); node = OF_instance_to_package(handle); if (node == -1) { /* * The "/chosen/stdout" does not exist try * using "screen" directly. */ node = OF_finddevice("screen"); handle = OF_open("screen"); } OF_getprop(node, "device_type", type, sizeof(type)); if (strcmp(type, "display") != 0) return (CN_DEAD); OF_printf("%s: %d\n", __FILE__, __LINE__); OF_getprop(node, "name", name, sizeof(name)); if (strcmp(name, "SUNW,ffb") != 0 && strcmp(name, "SUNW,afb") != 0) return (CN_DEAD); OF_printf("%s: %d\n", __FILE__, __LINE__); /* Make sure we have needed properties */ if (OF_getproplen(node, "height") != sizeof(height) || OF_getproplen(node, "width") != sizeof(width)) return (CN_DEAD); OF_printf("%s: %d\n", __FILE__, __LINE__); OF_getprop(node, "height", &height, sizeof(height)); OF_getprop(node, "width", &width, sizeof(width)); sc->fb_height = height; sc->fb_width = width; sc->fb_bpp = sc->fb_depth = 32; sc->fb_stride = 8192; /* Fixed */ sc->fb_size = sc->fb_height * sc->fb_stride; /* Map linear framebuffer */ if (OF_decode_addr(node, FFB_DFB24, &space, &phys) != 0) return (CN_DEAD); sc->fb_vbase = sparc64_fake_bustag(space, phys, &ofwfb_memt[0]); sc->fb_pbase = phys; OF_printf("%s: %d\n", __FILE__, __LINE__); { int i, j; for (i = 0; i < sc->fb_height; i++) for (j = 0; j < sc->fb_width; j++) bus_space_write_4(&ofwfb_memt[0], sc->fb_vbase, i*sc->fb_stride + j*4, 0); } /* 32-bit VGA palette */ vt_generate_vga_palette(sc->fb_cmap, COLOR_FORMAT_RGB, 255, 0, 255, 8, 255, 16); fb_probe(sc); vt_fb_init(vd); /* Clear the screen. */ vt_fb_blank(vd, TC_BLACK); return (CN_INTERNAL); }