Module Name: src
Committed By: jmcneill
Date: Sat Oct 10 15:25:31 UTC 2020
Modified Files:
src/sys/arch/arm/acpi: acpi_platform.c files.acpi
src/sys/arch/arm/fdt: files.fdt
src/sys/arch/evbarm/fdt: fdt_machdep.c
Added Files:
src/sys/arch/arm/fdt: arm_simplefb.c arm_simplefb.h
Removed Files:
src/sys/arch/arm/acpi: acpi_simplefb.c acpi_simplefb.h
Log Message:
Support early FB console attachment when booting with a devicetree
(non-ACPI mode). Inform the pciconf code about the framebuffer to
prevent pciconf from changing resources out from under us when framebuffer
memory is in VRAM.
To generate a diff of this commit:
cvs rdiff -u -r1.20 -r1.21 src/sys/arch/arm/acpi/acpi_platform.c
cvs rdiff -u -r1.2 -r0 src/sys/arch/arm/acpi/acpi_simplefb.c
cvs rdiff -u -r1.1 -r0 src/sys/arch/arm/acpi/acpi_simplefb.h
cvs rdiff -u -r1.10 -r1.11 src/sys/arch/arm/acpi/files.acpi
cvs rdiff -u -r0 -r1.1 src/sys/arch/arm/fdt/arm_simplefb.c \
src/sys/arch/arm/fdt/arm_simplefb.h
cvs rdiff -u -r1.31 -r1.32 src/sys/arch/arm/fdt/files.fdt
cvs rdiff -u -r1.74 -r1.75 src/sys/arch/evbarm/fdt/fdt_machdep.c
Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.
Modified files:
Index: src/sys/arch/arm/acpi/acpi_platform.c
diff -u src/sys/arch/arm/acpi/acpi_platform.c:1.20 src/sys/arch/arm/acpi/acpi_platform.c:1.21
--- src/sys/arch/arm/acpi/acpi_platform.c:1.20 Mon Sep 28 11:54:22 2020
+++ src/sys/arch/arm/acpi/acpi_platform.c Sat Oct 10 15:25:31 2020
@@ -1,4 +1,4 @@
-/* $NetBSD: acpi_platform.c,v 1.20 2020/09/28 11:54:22 jmcneill Exp $ */
+/* $NetBSD: acpi_platform.c,v 1.21 2020/10/10 15:25:31 jmcneill Exp $ */
/*-
* Copyright (c) 2018 The NetBSD Foundation, Inc.
@@ -31,13 +31,11 @@
#include "com.h"
#include "plcom.h"
-#include "wsdisplay.h"
-#include "genfb.h"
#include "opt_efi.h"
#include "opt_multiprocessor.h"
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: acpi_platform.c,v 1.20 2020/09/28 11:54:22 jmcneill Exp $");
+__KERNEL_RCSID(0, "$NetBSD: acpi_platform.c,v 1.21 2020/10/10 15:25:31 jmcneill Exp $");
#include <sys/param.h>
#include <sys/bus.h>
@@ -73,10 +71,6 @@ __KERNEL_RCSID(0, "$NetBSD: acpi_platfor
#include <dev/pci/pucvar.h>
#endif
-#if NWSDISPLAY > 0 && NGENFB > 0
-#include <arm/acpi/acpi_simplefb.h>
-#endif
-
#ifdef EFI_RUNTIME
#include <arm/arm/efi_runtime.h>
#endif
@@ -247,15 +241,6 @@ acpi_platform_init_attach_args(struct fd
static void
acpi_platform_device_register(device_t self, void *aux)
{
-#if NWSDISPLAY > 0 && NGENFB > 0
- if (device_is_a(self, "armfdt")) {
- /*
- * Setup framebuffer console, if present.
- */
- acpi_simplefb_preattach();
- }
-#endif
-
#if NCOM > 0
prop_dictionary_t prop = device_properties(self);
Index: src/sys/arch/arm/acpi/files.acpi
diff -u src/sys/arch/arm/acpi/files.acpi:1.10 src/sys/arch/arm/acpi/files.acpi:1.11
--- src/sys/arch/arm/acpi/files.acpi:1.10 Sat Feb 1 13:26:43 2020
+++ src/sys/arch/arm/acpi/files.acpi Sat Oct 10 15:25:31 2020
@@ -1,4 +1,4 @@
-# $NetBSD: files.acpi,v 1.10 2020/02/01 13:26:43 jmcneill Exp $
+# $NetBSD: files.acpi,v 1.11 2020/10/10 15:25:31 jmcneill Exp $
#
# Configuration info for ACPI compliant ARM boards.
#
@@ -17,7 +17,6 @@ file arch/arm/acpi/acpi_pci_graviton.c a
file arch/arm/acpi/acpi_pci_layerscape_gen4.c acpi & pci
file arch/arm/acpi/acpi_pci_n1sdp.c acpi & pci
file arch/arm/acpi/acpi_platform.c acpi
-file arch/arm/acpi/acpi_simplefb.c acpi & wsdisplay & genfb
file arch/arm/acpi/acpi_table.c acpi
attach cpu at acpimadtbus with cpu_acpi
Index: src/sys/arch/arm/fdt/files.fdt
diff -u src/sys/arch/arm/fdt/files.fdt:1.31 src/sys/arch/arm/fdt/files.fdt:1.32
--- src/sys/arch/arm/fdt/files.fdt:1.31 Tue Jan 7 08:22:23 2020
+++ src/sys/arch/arm/fdt/files.fdt Sat Oct 10 15:25:31 2020
@@ -1,4 +1,4 @@
-# $NetBSD: files.fdt,v 1.31 2020/01/07 08:22:23 skrll Exp $
+# $NetBSD: files.fdt,v 1.32 2020/10/10 15:25:31 jmcneill Exp $
include "dev/pckbport/files.pckbport"
@@ -6,6 +6,7 @@ device armfdt { }: bus_space_generic, fd
attach armfdt at root with arm_fdt
file arch/arm/fdt/arm_fdt.c arm_fdt
file arch/arm/fdt/arm_platform.c arm_fdt & gtmr_fdt & psci_fdt
+file arch/arm/fdt/arm_simplefb.c arm_fdt & wsdisplay & genfb
attach cpu at fdt with cpu_fdt
file arch/arm/fdt/cpu_fdt.c cpu_fdt
Index: src/sys/arch/evbarm/fdt/fdt_machdep.c
diff -u src/sys/arch/evbarm/fdt/fdt_machdep.c:1.74 src/sys/arch/evbarm/fdt/fdt_machdep.c:1.75
--- src/sys/arch/evbarm/fdt/fdt_machdep.c:1.74 Fri Sep 25 06:47:24 2020
+++ src/sys/arch/evbarm/fdt/fdt_machdep.c Sat Oct 10 15:25:30 2020
@@ -1,4 +1,4 @@
-/* $NetBSD: fdt_machdep.c,v 1.74 2020/09/25 06:47:24 skrll Exp $ */
+/* $NetBSD: fdt_machdep.c,v 1.75 2020/10/10 15:25:30 jmcneill Exp $ */
/*-
* Copyright (c) 2015-2017 Jared McNeill <[email protected]>
@@ -27,7 +27,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: fdt_machdep.c,v 1.74 2020/09/25 06:47:24 skrll Exp $");
+__KERNEL_RCSID(0, "$NetBSD: fdt_machdep.c,v 1.75 2020/10/10 15:25:30 jmcneill Exp $");
#include "opt_machdep.h"
#include "opt_bootconfig.h"
@@ -38,6 +38,7 @@ __KERNEL_RCSID(0, "$NetBSD: fdt_machdep.
#include "opt_cpuoptions.h"
#include "opt_efi.h"
+#include "genfb.h"
#include "ukbd.h"
#include "wsdisplay.h"
@@ -96,6 +97,10 @@ __KERNEL_RCSID(0, "$NetBSD: fdt_machdep.
#include <arm/arm/efi_runtime.h>
#endif
+#if NWSDISPLAY > 0 && NGENFB > 0
+#include <arm/fdt/arm_simplefb.h>
+#endif
+
#if NUKBD > 0
#include <dev/usb/ukbdvar.h>
#endif
@@ -848,9 +853,17 @@ fdt_device_register(device_t self, void
{
const struct arm_platform *plat = arm_fdt_platform();
- if (device_is_a(self, "armfdt"))
+ if (device_is_a(self, "armfdt")) {
fdt_setup_initrd();
+#if NWSDISPLAY > 0 && NGENFB > 0
+ /*
+ * Setup framebuffer console, if present.
+ */
+ arm_simplefb_preattach();
+#endif
+ }
+
if (plat && plat->ap_device_register)
plat->ap_device_register(self, aux);
}
Added files:
Index: src/sys/arch/arm/fdt/arm_simplefb.c
diff -u /dev/null src/sys/arch/arm/fdt/arm_simplefb.c:1.1
--- /dev/null Sat Oct 10 15:25:31 2020
+++ src/sys/arch/arm/fdt/arm_simplefb.c Sat Oct 10 15:25:31 2020
@@ -0,0 +1,233 @@
+/* $NetBSD: arm_simplefb.c,v 1.1 2020/10/10 15:25:31 jmcneill Exp $ */
+
+/*-
+ * Copyright (c) 2019 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * This code is derived from software contributed to The NetBSD Foundation
+ * by Jared McNeill <[email protected]>.
+ *
+ * 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 NETBSD FOUNDATION, INC. 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 FOUNDATION 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 "pci.h"
+#include "opt_pci.h"
+
+#include <sys/cdefs.h>
+__KERNEL_RCSID(0, "$NetBSD: arm_simplefb.c,v 1.1 2020/10/10 15:25:31 jmcneill Exp $");
+
+#include <sys/param.h>
+#include <sys/bus.h>
+#include <sys/cpu.h>
+#include <sys/device.h>
+
+#include <dev/fdt/fdtvar.h>
+#include <arm/fdt/arm_fdtvar.h>
+
+#include <dev/wscons/wsconsio.h>
+#include <dev/wscons/wsdisplayvar.h>
+#include <dev/rasops/rasops.h>
+#include <dev/wsfont/wsfont.h>
+#include <dev/wscons/wsdisplay_vconsvar.h>
+
+#if NPCI > 0 && defined(PCI_NETBSD_CONFIGURE)
+#include <dev/pci/pcireg.h>
+#include <dev/pci/pcivar.h>
+#include <dev/pci/pciconf.h>
+#endif
+
+#include <arm/fdt/arm_simplefb.h>
+
+#include <libfdt.h>
+
+extern struct bus_space arm_generic_bs_tag;
+
+static struct arm_simplefb_softc {
+ uint32_t sc_width;
+ uint32_t sc_height;
+ uint32_t sc_stride;
+ uint16_t sc_depth;
+ void *sc_bits;
+} arm_simplefb_softc;
+
+static struct wsscreen_descr arm_simplefb_stdscreen = {
+ .name = "std",
+ .ncols = 0,
+ .nrows = 0,
+ .textops = NULL,
+ .fontwidth = 0,
+ .fontheight = 0,
+ .capabilities = 0,
+ .modecookie = NULL
+};
+
+static struct wsdisplay_accessops arm_simplefb_accessops;
+static struct vcons_data arm_simplefb_vcons_data;
+static struct vcons_screen arm_simplefb_screen;
+
+static int
+arm_simplefb_find_node(void)
+{
+ static const char * simplefb_compatible[] = { "simple-framebuffer", NULL };
+ int chosen_phandle, child;
+
+ chosen_phandle = OF_finddevice("/chosen");
+ if (chosen_phandle == -1)
+ return -1;
+
+ for (child = OF_child(chosen_phandle); child; child = OF_peer(child)) {
+ if (!fdtbus_status_okay(child))
+ continue;
+ if (!of_match_compatible(child, simplefb_compatible))
+ continue;
+
+ return child;
+ }
+
+ return -1;
+}
+
+static void
+arm_simplefb_init_screen(void *cookie, struct vcons_screen *scr,
+ int existing, long *defattr)
+{
+ struct arm_simplefb_softc * const sc = cookie;
+ struct rasops_info *ri = &scr->scr_ri;
+
+ ri->ri_width = sc->sc_width;
+ ri->ri_height = sc->sc_height;
+ ri->ri_depth = sc->sc_depth;
+ ri->ri_stride = sc->sc_stride;
+ ri->ri_bits = sc->sc_bits;
+ ri->ri_flg = RI_CENTER | RI_FULLCLEAR | RI_CLEAR;
+
+ scr->scr_flags |= VCONS_LOADFONT;
+ scr->scr_flags |= VCONS_DONT_READ;
+
+ rasops_init(ri, ri->ri_height / 8, ri->ri_width / 8);
+ ri->ri_caps = WSSCREEN_WSCOLORS | WSSCREEN_HILIT | WSSCREEN_UNDERLINE;
+ rasops_reconfig(ri, sc->sc_height / ri->ri_font->fontheight,
+ sc->sc_width / ri->ri_font->fontwidth);
+
+ ri->ri_hw = scr;
+}
+
+static int
+arm_simplefb_ioctl(void *v, void *vs, u_long cmd, void *data, int flag, lwp_t *l)
+{
+ return EPASSTHROUGH;
+}
+
+static paddr_t
+arm_simplefb_mmap(void *v, void *vs, off_t offset, int prot)
+{
+ return -1;
+}
+
+static void
+arm_simplefb_pollc(void *v, int on)
+{
+}
+
+void
+arm_simplefb_preattach(void)
+{
+ struct arm_simplefb_softc * const sc = &arm_simplefb_softc;
+ struct rasops_info *ri = &arm_simplefb_screen.scr_ri;
+ bus_space_tag_t bst = &arm_generic_bs_tag;
+ bus_space_handle_t bsh;
+ uint32_t width, height, stride;
+ const char *format;
+ bus_addr_t addr;
+ bus_size_t size;
+ uint16_t depth;
+ long defattr;
+
+ const int phandle = arm_simplefb_find_node();
+ if (phandle == -1)
+ return;
+
+ if (fdtbus_get_reg(phandle, 0, &addr, &size) != 0 || size == 0)
+ return;
+
+ if (of_getprop_uint32(phandle, "width", &width) != 0 ||
+ of_getprop_uint32(phandle, "height", &height) != 0 ||
+ of_getprop_uint32(phandle, "stride", &stride) != 0 ||
+ (format = fdtbus_get_string(phandle, "format")) == NULL)
+ return;
+
+ if (width == 0 || height == 0)
+ return;
+
+ if (strcmp(format, "a8b8g8r8") == 0 ||
+ strcmp(format, "x8r8g8b8") == 0) {
+ depth = 32;
+ } else if (strcmp(format, "r5g6b5") == 0) {
+ depth = 16;
+ } else {
+ return;
+ }
+
+ if (bus_space_map(bst, addr, size,
+ BUS_SPACE_MAP_LINEAR | BUS_SPACE_MAP_PREFETCHABLE, &bsh) != 0)
+ return;
+
+ sc->sc_width = width;
+ sc->sc_height = height;
+ sc->sc_depth = depth;
+ sc->sc_stride = stride;
+ sc->sc_bits = bus_space_vaddr(bst, bsh);
+
+ wsfont_init();
+
+ arm_simplefb_accessops.ioctl = arm_simplefb_ioctl;
+ arm_simplefb_accessops.mmap = arm_simplefb_mmap;
+ arm_simplefb_accessops.pollc = arm_simplefb_pollc;
+
+ vcons_init(&arm_simplefb_vcons_data, sc, &arm_simplefb_stdscreen,
+ &arm_simplefb_accessops);
+ arm_simplefb_vcons_data.init_screen = arm_simplefb_init_screen;
+ arm_simplefb_vcons_data.use_intr = 0;
+ vcons_init_screen(&arm_simplefb_vcons_data, &arm_simplefb_screen, 1, &defattr);
+ arm_simplefb_screen.scr_flags |= VCONS_SCREEN_IS_STATIC;
+
+ if (ri->ri_rows < 1 || ri->ri_cols < 1)
+ return;
+
+ arm_simplefb_stdscreen.nrows = ri->ri_rows;
+ arm_simplefb_stdscreen.ncols = ri->ri_cols;
+ arm_simplefb_stdscreen.textops = &ri->ri_ops;
+ arm_simplefb_stdscreen.capabilities = ri->ri_caps;
+
+ wsdisplay_preattach(&arm_simplefb_stdscreen, ri, 0, 0, defattr);
+
+ vcons_replay_msgbuf(&arm_simplefb_screen);
+
+#if NPCI > 0 && defined(PCI_NETBSD_CONFIGURE)
+ /*
+ * Let the PCI resource allocator know about our framebuffer. This
+ * protects the VGA device BARs from being reprogrammed when we the
+ * framebuffer is located in VRAM.
+ */
+ pciconf_resource_reserve(PCI_CONF_MAP_MEM, addr, size);
+#endif
+}
Index: src/sys/arch/arm/fdt/arm_simplefb.h
diff -u /dev/null src/sys/arch/arm/fdt/arm_simplefb.h:1.1
--- /dev/null Sat Oct 10 15:25:31 2020
+++ src/sys/arch/arm/fdt/arm_simplefb.h Sat Oct 10 15:25:31 2020
@@ -0,0 +1,37 @@
+/* $NetBSD: arm_simplefb.h,v 1.1 2020/10/10 15:25:31 jmcneill Exp $ */
+
+/*-
+ * Copyright (c) 2019 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * This code is derived from software contributed to The NetBSD Foundation
+ * by Jared McNeill <[email protected]>.
+ *
+ * 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 NETBSD FOUNDATION, INC. 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 FOUNDATION 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.
+ */
+
+#ifndef _ARM_ARM_SIMPLEFB_H
+#define _ARM_ARM_SIMPLEFB_H
+
+void arm_simplefb_preattach(void);
+
+#endif /* !_ARM_ARM_SIMPLEFB_H */