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.
This commit is contained in:
jmcneill 2020-10-10 15:25:30 +00:00
parent 45387a0c63
commit 2824038d80
6 changed files with 78 additions and 62 deletions

View File

@ -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_platform.c,v 1.20 2020/09/28 11:54:22 jmcneill
#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 fdt_attach_args *faa)
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);

View File

@ -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 acpi & pci
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

View File

@ -1,4 +1,4 @@
/* $NetBSD: acpi_simplefb.c,v 1.2 2020/01/24 10:49:41 jmcneill Exp $ */
/* $NetBSD: arm_simplefb.c,v 1.1 2020/10/10 15:25:31 jmcneill Exp $ */
/*-
* Copyright (c) 2019 The NetBSD Foundation, Inc.
@ -29,8 +29,11 @@
* POSSIBILITY OF SUCH DAMAGE.
*/
#include "pci.h"
#include "opt_pci.h"
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: acpi_simplefb.c,v 1.2 2020/01/24 10:49:41 jmcneill Exp $");
__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>
@ -46,21 +49,27 @@ __KERNEL_RCSID(0, "$NetBSD: acpi_simplefb.c,v 1.2 2020/01/24 10:49:41 jmcneill E
#include <dev/wsfont/wsfont.h>
#include <dev/wscons/wsdisplay_vconsvar.h>
#include <arm/acpi/acpi_simplefb.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 acpi_simplefb_softc {
static struct arm_simplefb_softc {
uint32_t sc_width;
uint32_t sc_height;
uint32_t sc_stride;
uint16_t sc_depth;
void *sc_bits;
} acpi_simplefb_softc;
} arm_simplefb_softc;
static struct wsscreen_descr acpi_simplefb_stdscreen = {
static struct wsscreen_descr arm_simplefb_stdscreen = {
.name = "std",
.ncols = 0,
.nrows = 0,
@ -71,12 +80,12 @@ static struct wsscreen_descr acpi_simplefb_stdscreen = {
.modecookie = NULL
};
static struct wsdisplay_accessops acpi_simplefb_accessops;
static struct vcons_data acpi_simplefb_vcons_data;
static struct vcons_screen acpi_simplefb_screen;
static struct wsdisplay_accessops arm_simplefb_accessops;
static struct vcons_data arm_simplefb_vcons_data;
static struct vcons_screen arm_simplefb_screen;
static int
acpi_simplefb_find_node(void)
arm_simplefb_find_node(void)
{
static const char * simplefb_compatible[] = { "simple-framebuffer", NULL };
int chosen_phandle, child;
@ -98,10 +107,10 @@ acpi_simplefb_find_node(void)
}
static void
acpi_simplefb_init_screen(void *cookie, struct vcons_screen *scr,
arm_simplefb_init_screen(void *cookie, struct vcons_screen *scr,
int existing, long *defattr)
{
struct acpi_simplefb_softc * const sc = cookie;
struct arm_simplefb_softc * const sc = cookie;
struct rasops_info *ri = &scr->scr_ri;
ri->ri_width = sc->sc_width;
@ -123,27 +132,27 @@ acpi_simplefb_init_screen(void *cookie, struct vcons_screen *scr,
}
static int
acpi_simplefb_ioctl(void *v, void *vs, u_long cmd, void *data, int flag, lwp_t *l)
arm_simplefb_ioctl(void *v, void *vs, u_long cmd, void *data, int flag, lwp_t *l)
{
return EPASSTHROUGH;
}
static paddr_t
acpi_simplefb_mmap(void *v, void *vs, off_t offset, int prot)
arm_simplefb_mmap(void *v, void *vs, off_t offset, int prot)
{
return -1;
}
static void
acpi_simplefb_pollc(void *v, int on)
arm_simplefb_pollc(void *v, int on)
{
}
void
acpi_simplefb_preattach(void)
arm_simplefb_preattach(void)
{
struct acpi_simplefb_softc * const sc = &acpi_simplefb_softc;
struct rasops_info *ri = &acpi_simplefb_screen.scr_ri;
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;
@ -153,7 +162,7 @@ acpi_simplefb_preattach(void)
uint16_t depth;
long defattr;
const int phandle = acpi_simplefb_find_node();
const int phandle = arm_simplefb_find_node();
if (phandle == -1)
return;
@ -190,26 +199,35 @@ acpi_simplefb_preattach(void)
wsfont_init();
acpi_simplefb_accessops.ioctl = acpi_simplefb_ioctl;
acpi_simplefb_accessops.mmap = acpi_simplefb_mmap;
acpi_simplefb_accessops.pollc = acpi_simplefb_pollc;
arm_simplefb_accessops.ioctl = arm_simplefb_ioctl;
arm_simplefb_accessops.mmap = arm_simplefb_mmap;
arm_simplefb_accessops.pollc = arm_simplefb_pollc;
vcons_init(&acpi_simplefb_vcons_data, sc, &acpi_simplefb_stdscreen,
&acpi_simplefb_accessops);
acpi_simplefb_vcons_data.init_screen = acpi_simplefb_init_screen;
acpi_simplefb_vcons_data.use_intr = 0;
vcons_init_screen(&acpi_simplefb_vcons_data, &acpi_simplefb_screen, 1, &defattr);
acpi_simplefb_screen.scr_flags |= VCONS_SCREEN_IS_STATIC;
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;
acpi_simplefb_stdscreen.nrows = ri->ri_rows;
acpi_simplefb_stdscreen.ncols = ri->ri_cols;
acpi_simplefb_stdscreen.textops = &ri->ri_ops;
acpi_simplefb_stdscreen.capabilities = ri->ri_caps;
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(&acpi_simplefb_stdscreen, ri, 0, 0, defattr);
wsdisplay_preattach(&arm_simplefb_stdscreen, ri, 0, 0, defattr);
vcons_replay_msgbuf(&acpi_simplefb_screen);
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
}

View File

@ -1,4 +1,4 @@
/* $NetBSD: acpi_simplefb.h,v 1.1 2019/09/22 18:31:59 jmcneill Exp $ */
/* $NetBSD: arm_simplefb.h,v 1.1 2020/10/10 15:25:31 jmcneill Exp $ */
/*-
* Copyright (c) 2019 The NetBSD Foundation, Inc.
@ -29,9 +29,9 @@
* POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef _ARM_ACPI_SIMPLEFB_H
#define _ARM_ACPI_SIMPLEFB_H
#ifndef _ARM_ARM_SIMPLEFB_H
#define _ARM_ARM_SIMPLEFB_H
void acpi_simplefb_preattach(void);
void arm_simplefb_preattach(void);
#endif /* !_ARM_ACPI_SIMPLEFB_H */
#endif /* !_ARM_ARM_SIMPLEFB_H */

View File

@ -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, fdt
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

View File

@ -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 <jmcneill@invisible.ca>
@ -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.c,v 1.74 2020/09/25 06:47:24 skrll Exp $
#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.c,v 1.74 2020/09/25 06:47:24 skrll Exp $
#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 *aux)
{
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);
}