From nobody Fri Nov 26 20:50:40 2021 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 17B9C18A3F24; Fri, 26 Nov 2021 20:50:41 +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 4J16Mh4kBPz3pN0; Fri, 26 Nov 2021 20:50:40 +0000 (UTC) (envelope-from git@FreeBSD.org) 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 82A9F6FF6; Fri, 26 Nov 2021 20:50:40 +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 1AQKoeK9018475; Fri, 26 Nov 2021 20:50:40 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 1AQKoePn018473; Fri, 26 Nov 2021 20:50:40 GMT (envelope-from git) Date: Fri, 26 Nov 2021 20:50:40 GMT Message-Id: <202111262050.1AQKoePn018473@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: "Alfredo Dal'Ava Junior" Subject: git: c41d129485e0 - stable/13 - ofwfb: fix vga/hdmi console with ASMEDIA during boot on powerpc64(le) 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: alfredo X-Git-Repository: src X-Git-Refname: refs/heads/stable/13 X-Git-Reftype: branch X-Git-Commit: c41d129485e0c2519397ff7e740e9401f948a74c Auto-Submitted: auto-generated ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1637959840; 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=1YmG/cJ+wAlsHPaZwWr+YwtJ5itD7qsDL+syliECGEE=; b=CerdLU4iqep58tY7p12tCOWajS1JJ966fwTYpvas0/VXY5f9FrMhUy1AEYajioG0kWpL+M ZzAHnooUNsO+F9ohK5tIEjx8ltwcpjpwdwUkxGEz+XLIoPRLqk75FAI3RHbA/6UViRE7JE ugmbRDnDFOi6zN71NrsjySfs7AwdA4kCQ3LlfQLKQtY2A67MBgmZMt//6FA/PILZRsfhiM BTFrPH8TSLFnvUF8v+0FVuCKryurtaqJOY+Ed2koWfQFbJ8YjnnNFiN3HpcWA4fwpSmnzd Stj5m7zN83M1SXQFGPGr62vPVNeaXcn5Ge5u8sJpSCkQpayvBqZKJ4/lAtyR9A== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1637959840; a=rsa-sha256; cv=none; b=PeQnF0iZVm7NXzxlNOjFp7FohFVQevyQBtXLcb17vQRdFHiVenEnx3fi0fYR66DpXw80+J YfbcH+mA6ucfe2Hc+xfgsdvw9RqO7WQs5yqlXu9E06HigmzJsc1QEI8W2oWGWItgT2IFRp Y6qNR+47izdQpru4NHh5/WoZLimh+BgYytPxRG8a0ukj7RirMdHxXtIj77/XeqP3dQ9NWk 1ftEt4SJcBzkUFUYiLKLdLS3+/7sF2zLjQF/GZbU9/UgoL0k/ggR+kNSgPG6Wk0BGqEu+X wvRppmGdyu/23lbIShppiEz0yZVLIcNIGzhwE2DchL0HXLOzHdpfMcSoZtdjcw== ARC-Authentication-Results: i=1; mx1.freebsd.org; none X-ThisMailContainsUnwantedMimeParts: N The branch stable/13 has been updated by alfredo: URL: https://cgit.FreeBSD.org/src/commit/?id=c41d129485e0c2519397ff7e740e9401f948a74c commit c41d129485e0c2519397ff7e740e9401f948a74c Author: Alfredo Dal'Ava Junior AuthorDate: 2021-11-03 16:42:28 +0000 Commit: Alfredo Dal'Ava Junior CommitDate: 2021-11-26 23:50:55 +0000 ofwfb: fix vga/hdmi console with ASMEDIA during boot on powerpc64(le) On recent OpenBMC firmware, the onboard ASMEDIA video card framebuffer address was removed from device tree for security purposes (value is set to zero to avoid leaking the address). This patch works around the problem by taking framebuffer base address from the "ranges" property of a parent node. Reviewed by: luporl, jhibbits (on IRC) MFC after: 2 weeks Sponsored by: Instituto de Pesquisas Eldorado (eldorado.org.br) Differential Revision: https://reviews.freebsd.org/D30626 (cherry picked from commit b042d10cdc71ddd6ef3449261d712b05c648746e) --- sys/dev/vt/hw/ofwfb/ofwfb.c | 116 +++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 110 insertions(+), 6 deletions(-) diff --git a/sys/dev/vt/hw/ofwfb/ofwfb.c b/sys/dev/vt/hw/ofwfb/ofwfb.c index 9dc674c0ebf9..e388356450d6 100644 --- a/sys/dev/vt/hw/ofwfb/ofwfb.c +++ b/sys/dev/vt/hw/ofwfb/ofwfb.c @@ -61,7 +61,8 @@ struct ofwfb_softc { uint32_t vendor_id; }; -#define PCI_VENDOR_ID_NVIDIA 0x10de +#define PCI_VID_NVIDIA 0x10de /* NVIDIA Corporation */ +#define PCI_VID_ASPEED 0x1a03 /* ASPEED Technology, Inc. */ static void ofwfb_initialize(struct vt_device *vd); static vd_probe_t ofwfb_probe; @@ -297,6 +298,104 @@ ofwfb_bitblt_text(struct vt_device *vd, const struct vt_window *vw, #endif } + +/* + * Decode OpenFirmware/IEEE 1275-1994 "ranges" property + * + * XXX: this is similar to ofw_pcib_fill_ranges but cannot use it here because + * it's not possible to allocate memory at the moment this is funcion is + * used. Since there are other similar functions dealing with "ranges" + * property, a proper refactoring is suggested. + */ +static uint64_t +decode_pci_ranges_host_addr(phandle_t pcinode) +{ + struct simplebus_range { + uint64_t bus; + uint64_t host; + uint64_t size; + }; + + struct simplebus_range ranges[4]; + int nranges, host_address_cells; + pcell_t acells, scells; + cell_t base_ranges[64]; + + ssize_t nbase_ranges; + int i, j, k; + + if (!OF_hasprop(pcinode, "ranges")) + return (0); + + if (OF_getencprop(pcinode, "#address-cells", &acells, sizeof(acells)) != + sizeof(acells)) + return (0); + + if (OF_getencprop(pcinode, "#size-cells", &scells, sizeof(scells)) != + sizeof(scells)) + return (0); + + if (OF_searchencprop(OF_parent(pcinode), "#address-cells", + &host_address_cells, sizeof(host_address_cells)) != + sizeof(host_address_cells)) + return (0); + + nbase_ranges = OF_getproplen(pcinode, "ranges"); + nranges = nbase_ranges / sizeof(cell_t) / (acells + host_address_cells + scells); + + /* prevent buffer overflow during iteration */ + if (nranges > sizeof(ranges) / sizeof(ranges[0])) + nranges = sizeof(ranges) / sizeof(ranges[0]); + + /* decode range value and return the first valid address */ + OF_getencprop(pcinode, "ranges", base_ranges, nbase_ranges); + for (i = 0, j = 0; i < nranges; i++) { + ranges[i].bus = 0; + for (k = 0; k < acells; k++) { + ranges[i].bus <<= 32; + ranges[i].bus |= base_ranges[j++]; + } + + ranges[i].host = 0; + for (k = 0; k < host_address_cells; k++) { + ranges[i].host <<= 32; + ranges[i].host |= base_ranges[j++]; + } + ranges[i].size = 0; + for (k = 0; k < scells; k++) { + ranges[i].size <<= 32; + ranges[i].size |= base_ranges[j++]; + } + + if (ranges[i].host != 0) + return (ranges[i].host); + } + + return (0); +} + +static bus_addr_t +find_pci_host_address(phandle_t node) +{ + uint64_t addr; + + /* + * According to IEEE STD 1275, if property "ranges" exists but has a + * zero-length property value, the child address space is identical + * to the parent address space. + */ + while (node) { + if (OF_hasprop(node, "ranges")) { + addr = decode_pci_ranges_host_addr(node); + if (addr != 0) + return ((bus_addr_t)addr); + } + node = OF_parent(node); + } + + return (0); +} + static void ofwfb_initialize(struct vt_device *vd) { @@ -350,7 +449,7 @@ ofwfb_initialize(struct vt_device *vd) * There is no good way to determine the correct option, as this * is independent of endian swapping. */ - if (sc->vendor_id == PCI_VENDOR_ID_NVIDIA) + if (sc->vendor_id == PCI_VID_NVIDIA) sc->argb = 0; else sc->argb = 1; @@ -430,7 +529,6 @@ ofwfb_init(struct vt_device *vd) sizeof(vendor_id)) == sizeof(vendor_id)) sc->vendor_id = vendor_id; - /* Keep track of the OF node */ sc->sc_node = node; @@ -497,12 +595,18 @@ ofwfb_init(struct vt_device *vd) * Grab the physical address of the framebuffer, and then map it * into our memory space. If the MMU is not yet up, it will be * remapped for us when relocation turns on. + * + * The ASPEED driver on recent petitboot versions doesn't expose the + * physical address of framebuffer anymore for security. So it should + * retrieve the address from PCI device properties. */ user_phys = 0; TUNABLE_UINT64_FETCH("hw.ofwfb.physaddr", &user_phys); - fb_phys = (bus_addr_t)user_phys; - if (fb_phys) - sc->fb.fb_pbase = (vm_paddr_t)fb_phys; + + if (user_phys) + sc->fb.fb_pbase = (vm_paddr_t)user_phys; + else if (sc->vendor_id == PCI_VID_ASPEED) + sc->fb.fb_pbase = find_pci_host_address(node); else if (OF_hasprop(node, "address")) { switch (OF_getproplen(node, "address")) {