From nobody Wed Apr 26 05:45:29 2023 X-Original-To: dev-commits-src-all@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4Q5ns54ZWtz47Gp8; Wed, 26 Apr 2023 05:45:29 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4Q5ns548Q1z4NcK; Wed, 26 Apr 2023 05:45:29 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1682487929; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=1H4jYRobjNCD/13onLhOlAf+xH+ADouyDTXRbdY9D7A=; b=nP50/ho59AT086JvoBvZnBAg46I0lEf8UyFdXFMrFQbGfVZIw1qGWCr43g038/7Uhk3Vn8 MmwDTWv3meDx2ukXh6vVEL1nzT7XoFvZmADnrF+bPtObxxI8ozeNo3XmLzOJR0RRcozIcH heLRooL5x9xpfFzyXGPxMfeyYp+iAzV/WlEIPvZFQ8Ky/x4wL8MaNLzjr1c2WCVrl+F58r evkeJgkAaas7crh1BhnTMhnz4u93nfZRIrSU/psijrud3e9DlqNpOo9peqE7kq7aiqEgMr 5hPjub/BRyzEJ93zrfOsmYKYUABUpxnLBfTQFci8BZhX+AwMKf55PMHMYPBtPQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1682487929; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=1H4jYRobjNCD/13onLhOlAf+xH+ADouyDTXRbdY9D7A=; b=Pt4CsoRPotc5ydhW2Ft6IBkKQ2ZMCys98/+i65MISxfLp7HiOrKhcymSG/PCp7UEhFvxHC P+NNzdRyc45ZaRLYZ61WYzPcDa3BKAe7+AC8nHhjRxeQkL1Qr3e9isvWOFmmMj/TDtHEf/ DqoNj5r7V79qgSFCyIh5AwmW+K+ciA/3zopYhOFoK3A3TTrP/yCHtinOlb38KhGJq8g+tT YuBAjfRqKbzcTfGCPHmaRm3ryEPwuRrh5BasuOpcF62o5LoUP+c2PF+Qmu7ybIqIvr45CS eB2Tnq/dzojmMWqr5XNrZJtl2UwGW1ABazsTNj9lMeLtS81iK3bCodhuLdTHuQ== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1682487929; a=rsa-sha256; cv=none; b=od7zUw1xSwWt9x2Yqh9U8dC7YAjF3XXt072ZrpxlEfDU5xKF+UjhHzUdFVhaigfC5dOZ9W AeirbdHDsxqTH3KoKg5K/LzMRQ3IE4b/h7cA9p9v5RFWJ+fdYNBFMuCS+HXYW84KUg+C5k BAvlrrJ1iAvps6g6lxn6v01KmJc5vyi3klz2CpoZ4yd49b5LjRdvaYtRrnLQ4JG1yoC1lw znlmra7lZ0gzTPpW3+wlJYi3kVnySzFV/4r+gEeZ0q86G6CIDWaemuBXzd2e5kZMOCBZy1 FUBdUKniu65TFFNLJH9M+Yq52jUcivZfczgBjwK62TmRrZrpOwlCEfaR7/ybKQ== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 4Q5ns53D5szMyv; Wed, 26 Apr 2023 05:45:29 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.16.1/8.16.1) with ESMTP id 33Q5jTHv046691; Wed, 26 Apr 2023 05:45:29 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 33Q5jTsb046690; Wed, 26 Apr 2023 05:45:29 GMT (envelope-from git) Date: Wed, 26 Apr 2023 05:45:29 GMT Message-Id: <202304260545.33Q5jTsb046690@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Kyle Evans Subject: git: d5035d913cc6 - main - Add a simple-framebuffer vt driver List-Id: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-all@freebsd.org X-BeenThere: dev-commits-src-all@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: kevans X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: d5035d913cc6453320df53840fea2145fe1d0128 Auto-Submitted: auto-generated X-ThisMailContainsUnwantedMimeParts: N The branch main has been updated by kevans: URL: https://cgit.FreeBSD.org/src/commit/?id=d5035d913cc6453320df53840fea2145fe1d0128 commit d5035d913cc6453320df53840fea2145fe1d0128 Author: Andrew Turner AuthorDate: 2023-04-26 05:44:10 +0000 Commit: Kyle Evans CommitDate: 2023-04-26 05:44:48 +0000 Add a simple-framebuffer vt driver This allows us to support this hardware and, in the future, use clocks so they are enabled past the initial kernel boot process. Reviewed by: ray Differential Revision: https://reviews.freebsd.org/D30103 --- sys/arm64/conf/std.dev | 1 + sys/conf/files | 1 + sys/dev/vt/hw/simplefb/simplefb.c | 226 ++++++++++++++++++++++++++++++++++++++ 3 files changed, 228 insertions(+) diff --git a/sys/arm64/conf/std.dev b/sys/arm64/conf/std.dev index 0a0e1da8cf8b..74d2407e0aec 100644 --- a/sys/arm64/conf/std.dev +++ b/sys/arm64/conf/std.dev @@ -49,6 +49,7 @@ device vt device kbdmux device vt_efifb +device vt_simplefb # Pseudo devices. device crypto # core crypto support diff --git a/sys/conf/files b/sys/conf/files index ec3ffa0bffdd..8c573d3293ec 100644 --- a/sys/conf/files +++ b/sys/conf/files @@ -3432,6 +3432,7 @@ dev/vt/colors/vt_termcolors.c optional vt dev/vt/font/vt_font_default.c optional vt dev/vt/font/vt_mouse_cursor.c optional vt dev/vt/hw/efifb/efifb.c optional vt_efifb +dev/vt/hw/simplefb/simplefb.c optional vt_simplefb dev/vt/hw/vbefb/vbefb.c optional vt_vbefb dev/vt/hw/fb/vt_fb.c optional vt dev/vt/hw/vga/vt_vga.c optional vt vt_vga diff --git a/sys/dev/vt/hw/simplefb/simplefb.c b/sys/dev/vt/hw/simplefb/simplefb.c new file mode 100644 index 000000000000..8fdc7146f0a8 --- /dev/null +++ b/sys/dev/vt/hw/simplefb/simplefb.c @@ -0,0 +1,226 @@ +/*- + * SPDX-License-Identifier: BSD-2-Clause-FreeBSD + * + * Copyright (c) 2014 The FreeBSD Foundation + * Copyright (c) 2021 Andrew Turner + * + * Portions of this software was developed by Aleksandr Rybalko under + * sponsorship from the FreeBSD Foundation. + * + * 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$"); + +#include +#include +#include +#include + +#include +#include + +#include +#include +#include + +#include +#include +#include +#include + +static vd_init_t vt_simplefb_init; +static vd_fini_t vt_simplefb_fini; +static vd_probe_t vt_simplefb_probe; + +static struct vt_driver vt_simplefb_driver = { + .vd_name = "simplefb", + .vd_probe = vt_simplefb_probe, + .vd_init = vt_simplefb_init, + .vd_fini = vt_simplefb_fini, + .vd_blank = vt_fb_blank, + .vd_bitblt_text = vt_fb_bitblt_text, + .vd_invalidate_text = vt_fb_invalidate_text, + .vd_bitblt_bmp = vt_fb_bitblt_bitmap, + .vd_drawrect = vt_fb_drawrect, + .vd_setpixel = vt_fb_setpixel, + .vd_fb_ioctl = vt_fb_ioctl, + .vd_fb_mmap = vt_fb_mmap, + .vd_suspend = vt_suspend, + .vd_resume = vt_resume, + /* Better than efifb, but still generic driver. */ + .vd_priority = VD_PRIORITY_GENERIC + 2, +}; + +struct { + const char *name; + int rbits, rshift; + int gbits, gshift; + int bbits, bshift; + int depth; + enum vt_color_format format; +} simplefb_formats[] = { + { + .name = "r5g6b5", + .rbits = 5, .rshift = 11, + .gbits = 6, .gshift = 5, + .bbits = 5, .bshift = 0, + .depth = 16, .format = COLOR_FORMAT_RGB, + }, + { + .name = "r8g8b8", + .rbits = 8, .rshift = 16, + .gbits = 8, .gshift = 8, + .bbits = 8, .bshift = 0, + .depth = 24, .format = COLOR_FORMAT_RGB, + }, + { + .name = "a8r8g8b8", + .rbits = 8, .rshift = 16, + .gbits = 8, .gshift = 8, + .bbits = 8, .bshift = 0, + .depth = 32, .format = COLOR_FORMAT_RGB, + }, + { + .name = "x8r8g8b8", + .rbits = 8, .rshift = 16, + .gbits = 8, .gshift = 8, + .bbits = 8, .bshift = 0, + .depth = 32, .format = COLOR_FORMAT_RGB, + }, + { + .name = "x2r10g10b10", + .rbits = 10, .rshift = 20, + .gbits = 10, .gshift = 10, + .bbits = 10, .bshift = 0, + .depth = 32, .format = COLOR_FORMAT_RGB, + }, +}; + +static struct fb_info local_info; +VT_DRIVER_DECLARE(vt_simplefb, vt_simplefb_driver); + +static bool +vt_simplefb_node(phandle_t *nodep) +{ + phandle_t chosen, node; + + chosen = OF_finddevice("/chosen"); + if (chosen == -1) + return (false); + + for (node = OF_child(chosen); node != 0; node = OF_peer(node)) { + if (ofw_bus_node_is_compatible(node, "simple-framebuffer")) + break; + } + if (node == 0) + return (false); + + if (nodep != NULL) + *nodep = node; + + return (true); +} + +static int +vt_simplefb_probe(struct vt_device *vd) +{ + int disabled; + + disabled = 0; + TUNABLE_INT_FETCH("hw.syscons.disable", &disabled); + if (disabled != 0) + return (CN_DEAD); + + if (!vt_simplefb_node(NULL)) + return (CN_DEAD); + + return (CN_INTERNAL); +} + +static int +vt_simplefb_init(struct vt_device *vd) +{ + char format[16]; + pcell_t height, width, stride; + struct fb_info *sc; + phandle_t node; + bus_size_t size; + int error; + + /* Initialize softc */ + vd->vd_softc = sc = &local_info; + + if (!vt_simplefb_node(&node)) + return (CN_DEAD); + + if (OF_getencprop(node, "height", &height, sizeof(height)) == -1 || + OF_getencprop(node, "width", &width, sizeof(width)) == -1 || + OF_getencprop(node, "stride", &stride, sizeof(stride)) == -1 || + OF_getprop(node, "format", format, sizeof(format)) == -1) { + return (CN_DEAD); + } + + sc->fb_height = height; + sc->fb_width = width; + sc->fb_stride = stride; + sc->fb_cmsize = NCOLORS; + + error = 1; + for (int i = 0; i < nitems(simplefb_formats); i++) { + if (strcmp(format, simplefb_formats[i].name) == 0) { + vt_config_cons_colors(sc, + simplefb_formats[i].format, + (1 << simplefb_formats[i].rbits) - 1, + simplefb_formats[i].rshift, + (1 << simplefb_formats[i].gbits) - 1, + simplefb_formats[i].gshift, + (1 << simplefb_formats[i].bbits) - 1, + simplefb_formats[i].bshift); + sc->fb_depth = sc->fb_bpp = simplefb_formats[i].depth; + error = 0; + break; + } + } + if (error != 0) + return (CN_DEAD); + + ofw_reg_to_paddr(node, 0, &sc->fb_pbase, &size, NULL); + sc->fb_vbase = (intptr_t)pmap_mapdev_attr(sc->fb_pbase, + size, VM_MEMATTR_WRITE_COMBINING); + sc->fb_size = size; + + vt_fb_init(vd); + + return (CN_INTERNAL); +} + +static void +vt_simplefb_fini(struct vt_device *vd, void *softc) +{ + struct fb_info *sc; + + sc = softc; + vt_fb_fini(vd, softc); + pmap_unmapdev((void *)sc->fb_vbase, sc->fb_size); +}