From nobody Thu Oct 27 17:56:40 2022 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 4MytfJ5nJwz4gdwl; Thu, 27 Oct 2022 17:56:40 +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 4MytfJ3lh7z41NJ; Thu, 27 Oct 2022 17:56:40 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1666893400; 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=dhBTXV5hACL4P7nwTAPtPA0LhPAkqWtugTtO0j64Hb0=; b=XJbLzk3d/Hbl46c0DOx/LdwgU81VPxDfOZCNTkDQZM2/lUMc06J5LqR4UHNBRCkHKb8mvg vIT0KoxXp7qRJqZ44TQZg6fwrVhTjAq9lPGkHbHCjlG+ckeP2ewBoHaDusK8VYgdR8paSe arOsCNwBNP5Z+U6VY+jYLAHEoHTOaCbkAFse5bPeR06Od7c6zdDv6YRl/8iL3KUSpNlhRX u1sdOw3Kv7CinZcoOm+LZe+9E+sMbjnmGJvDttvdk6WcqQgEKJpQJkwSW4CTN8yY/uGhzi kQzNubLLcUfLNwCtBl9c3zfkES5I5ZKKxqPJN5TXm1TPZSy61QzlPb7iidAI1Q== 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 4MytfJ2ctLz16Mr; Thu, 27 Oct 2022 17:56: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 29RHued2018693; Thu, 27 Oct 2022 17:56:40 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 29RHuemA018692; Thu, 27 Oct 2022 17:56:40 GMT (envelope-from git) Date: Thu, 27 Oct 2022 17:56:40 GMT Message-Id: <202210271756.29RHuemA018692@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Warner Losh Subject: git: cc9f1b4c3597 - main - stand/kboot: Make FDT fixup per-arch 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: imp X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: cc9f1b4c35974972c36553d4ca07ac91dc4262a2 Auto-Submitted: auto-generated ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1666893400; 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=dhBTXV5hACL4P7nwTAPtPA0LhPAkqWtugTtO0j64Hb0=; b=hSkfEWpBeORZzNSLatMX9yrY73+EE++mAnc5EsAzwnvNGK/eyJYoL8QUYNRRCxOIHvlogF 8UNovfWpXWt3L/D/ZIpYBc06+bBEvHzGpcrtK3GCOMm54aynqWC1oPzcJH9mkD+MHV1O0v 4WWVLo/Dxoy6bsy0nc8ctu7YrYeohtH30wFxHhcLkyrZ5m3Yy+eHwskLtfJr902UAxnvOy P93QLl7jyXi6NBeWqvqiwxySBJkZnCZHpyCgFU6iZ/973CsQpqKtibxWE+iw3yJeqBI6fz WYc1QQ9VHQFPsdtLFBe2zTS+A648KNUvts7x4dl0JpFV3Bqq8rHQU+R0VGGL+A== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1666893400; a=rsa-sha256; cv=none; b=n0oa8cXqhpJnaYZGEB0XHUeFNeuC6ur0NLMHPJVkERm29QJ7mt/LimbcFknXgL3ccF35uz QQI6ypdnLOaW4L9BM0EDPrOQ3+eKLPx6JVSlubu1AbNwwqA2s9Iwr4xfIY0foL5rzpJ8Tl CENLh5i0iZ50hgoK92wY8C6vtD+zkDecd+qdZRlF2pnw6k0BjE/xACtZjO1Fg42DDDZNND MEQZQrl1nGeF4U2sDEvr7B9IVDUbwR5V4Xm3gmWKLkFflD+rsaA43INvL+Vt6wAhWsdI31 HeBsTO2KQ3ock7OwVwuFp4lehVnxfpM+tRQ3Ci18NEeM7MbKryz/ZdtUH0wDFQ== ARC-Authentication-Results: i=1; mx1.freebsd.org; none X-ThisMailContainsUnwantedMimeParts: N The branch main has been updated by imp: URL: https://cgit.FreeBSD.org/src/commit/?id=cc9f1b4c35974972c36553d4ca07ac91dc4262a2 commit cc9f1b4c35974972c36553d4ca07ac91dc4262a2 Author: Warner Losh AuthorDate: 2022-10-27 17:36:51 +0000 Commit: Warner Losh CommitDate: 2022-10-27 17:36:51 +0000 stand/kboot: Make FDT fixup per-arch The fixups needed vary somewhat by architecture, so move the FDT fixup to be per-arch. Rename the fdt_linux_fixup() routine to be fdt_arch_fixup() and expect all architecutres to fix things up as needed. Sponsored by: Netflix Differential Revision: https://reviews.freebsd.org/D36604 --- stand/kboot/arch/amd64/Makefile.inc | 2 +- stand/kboot/arch/amd64/fdt_arch.c | 32 ++++++++++++ stand/kboot/arch/powerpc64/Makefile.inc | 2 +- stand/kboot/arch/powerpc64/fdt_arch.c | 89 +++++++++++++++++++++++++++++++++ stand/kboot/kboot.h | 4 ++ stand/kboot/kbootfdt.c | 63 +---------------------- 6 files changed, 129 insertions(+), 63 deletions(-) diff --git a/stand/kboot/arch/amd64/Makefile.inc b/stand/kboot/arch/amd64/Makefile.inc index e2f5b9038ee6..fdd40fe9bc5a 100644 --- a/stand/kboot/arch/amd64/Makefile.inc +++ b/stand/kboot/arch/amd64/Makefile.inc @@ -1,4 +1,4 @@ -SRCS+= host_syscall.S amd64_tramp.S elf64_freebsd.c load_addr.c +SRCS+= host_syscall.S amd64_tramp.S elf64_freebsd.c load_addr.c fdt_arch.c CFLAGS+= -I${SYSDIR}/contrib/dev/acpica/include diff --git a/stand/kboot/arch/amd64/fdt_arch.c b/stand/kboot/arch/amd64/fdt_arch.c new file mode 100644 index 000000000000..eefb76b1f92c --- /dev/null +++ b/stand/kboot/arch/amd64/fdt_arch.c @@ -0,0 +1,32 @@ +/*- + * Copyright (c) 2022 Netflix, Inc + * + * 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 ``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 TOOLS GMBH 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 +#include "kboot.h" + +void +fdt_arch_fixups(void *fdtp) +{ + /* amd64 doesn't pass in a FDT, so nothing to fix */ +} diff --git a/stand/kboot/arch/powerpc64/Makefile.inc b/stand/kboot/arch/powerpc64/Makefile.inc index 4c863553397c..c29e69970505 100644 --- a/stand/kboot/arch/powerpc64/Makefile.inc +++ b/stand/kboot/arch/powerpc64/Makefile.inc @@ -1,6 +1,6 @@ CFLAGS+= -mcpu=powerpc64 -SRCS+= ppc64_elf_freebsd.c host_syscall.S kerneltramp.S load_addr.c +SRCS+= ppc64_elf_freebsd.c host_syscall.S kerneltramp.S load_addr.c fdt_arch.c SRCS+= ucmpdi2.c LDFLAGS= -nostdlib -static -T ${.CURDIR}/arch/${MACHINE_ARCH}/ldscript.powerpc diff --git a/stand/kboot/arch/powerpc64/fdt_arch.c b/stand/kboot/arch/powerpc64/fdt_arch.c new file mode 100644 index 000000000000..dc5f0fbd8fb6 --- /dev/null +++ b/stand/kboot/arch/powerpc64/fdt_arch.c @@ -0,0 +1,89 @@ +/*- + * 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 ``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 TOOLS GMBH 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 +#include +#include +#include "kboot.h" + +/* Fix up wrong values added to the device tree by prom_init() in Linux */ + +void +fdt_arch_fixups(void *fdtp) +{ + int offset, len; + const void *prop; + + /* + * Remove /memory/available properties, which reflect long-gone OF + * state + */ + + offset = fdt_path_offset(fdtp, "/memory@0"); + if (offset > 0) + fdt_delprop(fdtp, offset, "available"); + + /* + * Add reservations for OPAL and RTAS state if present + */ + + offset = fdt_path_offset(fdtp, "/ibm,opal"); + if (offset > 0) { + const uint64_t *base, *size; + base = fdt_getprop(fdtp, offset, "opal-base-address", + &len); + size = fdt_getprop(fdtp, offset, "opal-runtime-size", + &len); + if (base != NULL && size != NULL) + fdt_add_mem_rsv(fdtp, fdt64_to_cpu(*base), + fdt64_to_cpu(*size)); + } + offset = fdt_path_offset(fdtp, "/rtas"); + if (offset > 0) { + const uint32_t *base, *size; + base = fdt_getprop(fdtp, offset, "linux,rtas-base", &len); + size = fdt_getprop(fdtp, offset, "rtas-size", &len); + if (base != NULL && size != NULL) + fdt_add_mem_rsv(fdtp, fdt32_to_cpu(*base), + fdt32_to_cpu(*size)); + } + + /* + * Patch up /chosen nodes so that the stored handles mean something, + * where possible. + */ + offset = fdt_path_offset(fdtp, "/chosen"); + if (offset > 0) { + fdt_delprop(fdtp, offset, "cpu"); /* This node not meaningful */ + + offset = fdt_path_offset(fdtp, "/chosen"); + prop = fdt_getprop(fdtp, offset, "linux,stdout-package", &len); + if (prop != NULL) { + fdt_setprop(fdtp, offset, "stdout", prop, len); + offset = fdt_path_offset(fdtp, "/chosen"); + fdt_setprop(fdtp, offset, "stdin", prop, len); + } + } +} diff --git a/stand/kboot/kboot.h b/stand/kboot/kboot.h index 679d645d8ff0..81bd18faa893 100644 --- a/stand/kboot/kboot.h +++ b/stand/kboot/kboot.h @@ -10,6 +10,10 @@ #define DEVT_HOSTDISK 1234 void do_init(void); + +/* Per-platform fdt fixup */ +void fdt_arch_fixups(void *fdtp); + uint64_t kboot_get_phys_load_segment(void); uint8_t kboot_get_kernel_machine_bits(void); diff --git a/stand/kboot/kbootfdt.c b/stand/kboot/kbootfdt.c index e4e8e7cfbf04..df9506af6773 100644 --- a/stand/kboot/kbootfdt.c +++ b/stand/kboot/kbootfdt.c @@ -31,6 +31,7 @@ __FBSDID("$FreeBSD$"); #include #include "bootstrap.h" #include "host_syscall.h" +#include "kboot.h" static void add_node_to_fdt(void *buffer, const char *path, int fdt_offset) @@ -88,66 +89,6 @@ add_node_to_fdt(void *buffer, const char *path, int fdt_offset) host_close(fd); } -/* Fix up wrong values added to the device tree by prom_init() in Linux */ - -static void -fdt_linux_fixups(void *fdtp) -{ - int offset, len; - const void *prop; - - /* - * Remove /memory/available properties, which reflect long-gone OF - * state - */ - - offset = fdt_path_offset(fdtp, "/memory@0"); - if (offset > 0) - fdt_delprop(fdtp, offset, "available"); - - /* - * Add reservations for OPAL and RTAS state if present - */ - - offset = fdt_path_offset(fdtp, "/ibm,opal"); - if (offset > 0) { - const uint64_t *base, *size; - base = fdt_getprop(fdtp, offset, "opal-base-address", - &len); - size = fdt_getprop(fdtp, offset, "opal-runtime-size", - &len); - if (base != NULL && size != NULL) - fdt_add_mem_rsv(fdtp, fdt64_to_cpu(*base), - fdt64_to_cpu(*size)); - } - offset = fdt_path_offset(fdtp, "/rtas"); - if (offset > 0) { - const uint32_t *base, *size; - base = fdt_getprop(fdtp, offset, "linux,rtas-base", &len); - size = fdt_getprop(fdtp, offset, "rtas-size", &len); - if (base != NULL && size != NULL) - fdt_add_mem_rsv(fdtp, fdt32_to_cpu(*base), - fdt32_to_cpu(*size)); - } - - /* - * Patch up /chosen nodes so that the stored handles mean something, - * where possible. - */ - offset = fdt_path_offset(fdtp, "/chosen"); - if (offset > 0) { - fdt_delprop(fdtp, offset, "cpu"); /* This node not meaningful */ - - offset = fdt_path_offset(fdtp, "/chosen"); - prop = fdt_getprop(fdtp, offset, "linux,stdout-package", &len); - if (prop != NULL) { - fdt_setprop(fdtp, offset, "stdout", prop, len); - offset = fdt_path_offset(fdtp, "/chosen"); - fdt_setprop(fdtp, offset, "stdin", prop, len); - } - } -} - int fdt_platform_load_dtb(void) { @@ -158,7 +99,7 @@ fdt_platform_load_dtb(void) fdt_create_empty_tree(buffer, buflen); add_node_to_fdt(buffer, "/proc/device-tree", fdt_path_offset(buffer, "/")); - fdt_linux_fixups(buffer); + fdt_arch_fixups(buffer); fdt_pack(buffer);