From patchwork Wed Jul 5 11:42:48 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: yunhui cui X-Patchwork-Id: 699277 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 784BDEB64DA for ; Wed, 5 Jul 2023 11:44:49 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231213AbjGELos (ORCPT ); Wed, 5 Jul 2023 07:44:48 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48134 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231153AbjGELor (ORCPT ); Wed, 5 Jul 2023 07:44:47 -0400 Received: from mail-oi1-x236.google.com (mail-oi1-x236.google.com [IPv6:2607:f8b0:4864:20::236]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3D56D1730 for ; Wed, 5 Jul 2023 04:44:46 -0700 (PDT) Received: by mail-oi1-x236.google.com with SMTP id 5614622812f47-39ca120c103so4541934b6e.2 for ; Wed, 05 Jul 2023 04:44:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1688557485; x=1691149485; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=t2wHvvnZ9EXs4kZ7PH7ZQmrp8wDzjYqwhR8Lb7Z2dm0=; b=jVG4zai1xG7MtgnncuyhuPAqUUpjFnE9G3irewRE18y6iFyE/sSIGF23/BN9GqjedI zyE5d5WvPIsC2FoCMXz6YBxr+JP9d4N15NZq5ymkBEZQ9f5R/eqSfpU/6bJ9wyhWX0GY CZn7coRHhPZm1IRexWWv9LxGNpN/kk927lkfVslnarGWO0nM7CTFWJ6ITIo3KHTUnDnf FykR8jIUlH6tBDEJwoMXPppRQhPKve5atGYBKA4SFBp23WeY7rXeoIGbL2Lfb9ToKbu8 gEhKKIYhaaWc9JldVwFllp+Ar8BmfPkSiuuXdmcH5Dd5lugkgvKVkJ8u7MiK/YyWjCVd zxew== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1688557485; x=1691149485; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=t2wHvvnZ9EXs4kZ7PH7ZQmrp8wDzjYqwhR8Lb7Z2dm0=; b=gC8Ibc2hxW0LIkHYuJoLze0IHBPuqPaVl4cwOMOFObWOJukp6scbGzJQ1GsA/DOj9x xSfwcV0N+7o1fll5Awq1/ybvKa9lixI/WrDsjeWn7s/ncVTFKuE4l0sDmcjXU9sGQkYs XsqLy5qqus7BYZaWVSXD8/+GqLX3w7kX7YceM89+TXF3fES2awS0B8xfXdQnGtdDKGUV X/zjGrvYV4YBBdbwNxRaqdnlMkoMnb135+gXD0g3Ypau4ECXetxZr7yYzvIqsr7WtMRK XbT/TIclQUxgHO8qfLUoTCelC/5sI4CBy6Oli2j0NGlw0ENBkmKPPDKZnWw3CrhtRpfV dIKA== X-Gm-Message-State: AC+VfDwVvcwJVbgsTVEgwCjMK1thqDa10DeGwPCzclwNGz6D2Z9stGWa ZvfOzxCJDYjeKFFdUbnVNYKuCQ== X-Google-Smtp-Source: ACHHUZ4ap87VDxLx6PJqpSNbm9olTnoBIzaTi9rOfKW8IJ4lqYlS+3MO2AfgOPiU74NZ5qWJSAcOSw== X-Received: by 2002:a05:6808:197:b0:39e:ffc5:c450 with SMTP id w23-20020a056808019700b0039effc5c450mr15121527oic.47.1688557485518; Wed, 05 Jul 2023 04:44:45 -0700 (PDT) Received: from PF2E59YH-BKX.inc.bytedance.com ([61.213.176.5]) by smtp.gmail.com with ESMTPSA id 3-20020a17090a194300b00263f6687690sm1177900pjh.18.2023.07.05.04.44.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 05 Jul 2023 04:44:45 -0700 (PDT) From: Yunhui Cui To: conor@kernel.org, sunilvl@ventanamicro.com, ardb@kernel.org, palmer@dabbelt.com, paul.walmsley@sifive.com, aou@eecs.berkeley.edu, linux-riscv@lists.infradead.org, rminnich@gmail.com, mark.rutland@arm.com, lpieralisi@kernel.org, rafael@kernel.org, lenb@kernel.org, jdelvare@suse.com, yc.hung@mediatek.com, angelogioacchino.delregno@collabora.com, allen-kh.cheng@mediatek.com, pierre-louis.bossart@linux.intel.com, tinghan.shen@mediatek.com, linux-kernel@vger.kernel.org, linux-acpi@vger.kernel.org, geshijian@bytedance.com, weidong.wd@bytedance.com, cuiyunhui@bytedance.com Subject: [PATCH v3 1/4] riscv: obtain ACPI RSDP from devicetree Date: Wed, 5 Jul 2023 19:42:48 +0800 Message-Id: <20230705114251.661-2-cuiyunhui@bytedance.com> X-Mailer: git-send-email 2.37.3.windows.1 In-Reply-To: <20230705114251.661-1-cuiyunhui@bytedance.com> References: <20230705114251.661-1-cuiyunhui@bytedance.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-acpi@vger.kernel.org On RISC-V, Coreboot does not support booting using EFI, only devicetree nor does RISC-V have a reserved address segment. To allow using Coreboot on platforms that require ACPI, the ACPI RSDP needs to be passed to supervisor mode software using devicetree. Add support for parsing the "ffitbl" devicetree node to find the ACPI entry point and use wire up acpi_arch_get_root_pointer(). This feature is known as FDT Firmware Interface (FFI). Signed-off-by: Yunhui Cui --- MAINTAINERS | 6 ++++++ arch/riscv/include/asm/acpi.h | 9 +++++++++ arch/riscv/include/asm/ffi.h | 14 +++++++++++++ arch/riscv/kernel/Makefile | 1 + arch/riscv/kernel/ffi.c | 38 +++++++++++++++++++++++++++++++++++ arch/riscv/kernel/setup.c | 2 ++ 6 files changed, 70 insertions(+) create mode 100644 arch/riscv/include/asm/ffi.h create mode 100644 arch/riscv/kernel/ffi.c diff --git a/MAINTAINERS b/MAINTAINERS index cd5388a33410..e592f489e757 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -18363,6 +18363,12 @@ F: arch/riscv/boot/dts/ X: arch/riscv/boot/dts/allwinner/ X: arch/riscv/boot/dts/renesas/ +RISC-V FDT FIRMWARE INTERFACE (FFI) SUPPORT +M: Yunhui Cui cuiyunhui@bytedance.com +S: Maintained +F: arch/riscv/include/asm/ffi.h +F: arch/riscv/kernel/ffi.c + RISC-V PMU DRIVERS M: Atish Patra R: Anup Patel diff --git a/arch/riscv/include/asm/acpi.h b/arch/riscv/include/asm/acpi.h index f71ce21ff684..5574f9a152f5 100644 --- a/arch/riscv/include/asm/acpi.h +++ b/arch/riscv/include/asm/acpi.h @@ -15,6 +15,8 @@ /* Basic configuration for ACPI */ #ifdef CONFIG_ACPI +#include + typedef u64 phys_cpuid_t; #define PHYS_CPUID_INVALID INVALID_HARTID @@ -66,6 +68,13 @@ int acpi_get_riscv_isa(struct acpi_table_header *table, unsigned int cpu, const char **isa); static inline int acpi_numa_get_nid(unsigned int cpu) { return NUMA_NO_NODE; } + +#define ACPI_HAVE_ARCH_GET_ROOT_POINTER +static inline u64 acpi_arch_get_root_pointer(void) +{ + return riscv_acpi_rsdp(); +} + #else static inline void acpi_init_rintc_map(void) { } static inline struct acpi_madt_rintc *acpi_cpu_get_madt_rintc(int cpu) diff --git a/arch/riscv/include/asm/ffi.h b/arch/riscv/include/asm/ffi.h new file mode 100644 index 000000000000..d5e8309cc06f --- /dev/null +++ b/arch/riscv/include/asm/ffi.h @@ -0,0 +1,14 @@ +/* SPDX-License-Identifier: GPL-2.0 */ + +#ifndef _ASM_FFI_H +#define _ASM_FFI_H + +#ifdef CONFIG_FDT_FW_INTERFACE +extern void ffi_init(void); +extern u64 riscv_acpi_rsdp(void); +#else +#define ffi_init() +static inline u64 riscv_acpi_rsdp(void) { return 0; } +#endif + +#endif /* _ASM_FFI_H */ diff --git a/arch/riscv/kernel/Makefile b/arch/riscv/kernel/Makefile index 506cc4a9a45a..71831cf7f934 100644 --- a/arch/riscv/kernel/Makefile +++ b/arch/riscv/kernel/Makefile @@ -92,6 +92,7 @@ obj-$(CONFIG_CRASH_CORE) += crash_core.o obj-$(CONFIG_JUMP_LABEL) += jump_label.o obj-$(CONFIG_EFI) += efi.o +obj-$(CONFIG_FDT_FW_INTERFACE) += ffi.o obj-$(CONFIG_COMPAT) += compat_syscall_table.o obj-$(CONFIG_COMPAT) += compat_signal.o obj-$(CONFIG_COMPAT) += compat_vdso/ diff --git a/arch/riscv/kernel/ffi.c b/arch/riscv/kernel/ffi.c new file mode 100644 index 000000000000..147d06a5acff --- /dev/null +++ b/arch/riscv/kernel/ffi.c @@ -0,0 +1,38 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* + * ffi.c - FDT FIRMWARE INTERFACE + */ + +#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt + +#include +#include +#include + +static u64 acpi_rsdp; + +void __init ffi_acpi_root_pointer(void) +{ + u32 ffitbl, acpi, len; + fdt64_t *prop; + + ffitbl = fdt_subnode_offset(initial_boot_params, 0, "ffitbl"); + acpi = fdt_subnode_offset(initial_boot_params, ffitbl, "acpi"); + prop = fdt_getprop_w(initial_boot_params, acpi, "entry", &len); + if (!prop || len != sizeof(u64)) { + pr_debug("acpi rsdp not found.\n"); + return; + } + acpi_rsdp = fdt64_to_cpu(*prop); + pr_debug("acpi rsdp: %llx\n", acpi_rsdp); +} + +u64 __init riscv_acpi_rsdp(void) +{ + return acpi_rsdp; +} + +void __init ffi_init(void) +{ + ffi_acpi_root_pointer(); +} diff --git a/arch/riscv/kernel/setup.c b/arch/riscv/kernel/setup.c index 971fe776e2f8..5a933d6b6acb 100644 --- a/arch/riscv/kernel/setup.c +++ b/arch/riscv/kernel/setup.c @@ -36,6 +36,7 @@ #include #include #include +#include #include "head.h" @@ -279,6 +280,7 @@ void __init setup_arch(char **cmdline_p) parse_early_param(); efi_init(); + ffi_init(); paging_init(); /* Parse the ACPI tables for possible boot-time configuration */ From patchwork Wed Jul 5 11:42:49 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: yunhui cui X-Patchwork-Id: 699622 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 540B0EB64DA for ; Wed, 5 Jul 2023 11:45:26 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231669AbjGELpZ (ORCPT ); Wed, 5 Jul 2023 07:45:25 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48254 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231680AbjGELpS (ORCPT ); Wed, 5 Jul 2023 07:45:18 -0400 Received: from mail-pj1-x102d.google.com (mail-pj1-x102d.google.com [IPv6:2607:f8b0:4864:20::102d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BD92F198C for ; Wed, 5 Jul 2023 04:44:53 -0700 (PDT) Received: by mail-pj1-x102d.google.com with SMTP id 98e67ed59e1d1-263253063f9so4748065a91.1 for ; Wed, 05 Jul 2023 04:44:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1688557493; x=1691149493; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=vxuPbxVgF3zfcM/BRF/LLNBZgbT5czHHRuVcSzACvZ4=; b=USieFHEI7eCXkkZlxw91812OEPriTznOhYAAyi2cXQlf49JdMjM71QTNZhPXsv+nhz qj4BRAuXZjJzjZvy0kzeIKh5Hlmy5UmwfmwNgsyAbOWDZkARdCb/7bjGCHW+BaBbgZGt vr9aZZfYLHoDEDPC4mmRW8/GdKX7beelO5Vz4Ex2zA1yD90Qmut/5ZtmWcOo8PTfUPV/ 9wMTOaufrebObZG2kdeeHjoZ4dVZGvqSHK/p3ChlcMXQNJEjW3SUkAXyGAlYSNlUTWhd c9vbIApSePRVpayGJIb4QKHu377JeUxTSSiobs63TsC7Vbfo079dl4/ZzfesOMe4QhJe 4o6A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1688557493; x=1691149493; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=vxuPbxVgF3zfcM/BRF/LLNBZgbT5czHHRuVcSzACvZ4=; b=FC7pfn9DGYqJBLDv/0eOBnDwqQ+apHFf3jiP3lMQViPEn3vACY+vwjEvFqOnjAnrAF tdXh2aHg1prXl2N1wqSitqMjD/Det0QaqT2OEfq2UvixGhFsvYA2xaNc6nsopdTEEQTr zu6S8ilyla36h6Jg8V//o7loq1kHGhyPLWSnntoRQZti9Ba621TbpZHTZ0rUFF/nosdP GVYcRWr4g8BHeuLwGxk1l28xDD5NI6YwFGPcTM63JsjNcidXnkQwsJzABKe3LZUFYjss aWEZ8QxtsnpJMBMcyoIHOjLmwhbsu8sqhQKezLxMDHZ0XkP4uk7lJjWzrrVfCt7QWiD4 KSJw== X-Gm-Message-State: ABy/qLaynlyp8alC2YBATPSCxViHZc0Djuh8uSqeha5JuJszprvR46Tf 0oYQycxeI/HMzo8h86JLUv+VJw== X-Google-Smtp-Source: APBJJlGR3P54rhDcdlAlLclU9MYRdR5Ld0I3S9zquD63eupWzYEBKVWsWxUQA1BhQ1YV526dFMH7KQ== X-Received: by 2002:a17:90a:54:b0:261:113e:50d2 with SMTP id 20-20020a17090a005400b00261113e50d2mr16503592pjb.31.1688557493100; Wed, 05 Jul 2023 04:44:53 -0700 (PDT) Received: from PF2E59YH-BKX.inc.bytedance.com ([61.213.176.5]) by smtp.gmail.com with ESMTPSA id 3-20020a17090a194300b00263f6687690sm1177900pjh.18.2023.07.05.04.44.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 05 Jul 2023 04:44:52 -0700 (PDT) From: Yunhui Cui To: conor@kernel.org, sunilvl@ventanamicro.com, ardb@kernel.org, palmer@dabbelt.com, paul.walmsley@sifive.com, aou@eecs.berkeley.edu, linux-riscv@lists.infradead.org, rminnich@gmail.com, mark.rutland@arm.com, lpieralisi@kernel.org, rafael@kernel.org, lenb@kernel.org, jdelvare@suse.com, yc.hung@mediatek.com, angelogioacchino.delregno@collabora.com, allen-kh.cheng@mediatek.com, pierre-louis.bossart@linux.intel.com, tinghan.shen@mediatek.com, linux-kernel@vger.kernel.org, linux-acpi@vger.kernel.org, geshijian@bytedance.com, weidong.wd@bytedance.com, cuiyunhui@bytedance.com Subject: [PATCH v3 2/4] firmware: introduce FFI for SMBIOS entry Date: Wed, 5 Jul 2023 19:42:49 +0800 Message-Id: <20230705114251.661-3-cuiyunhui@bytedance.com> X-Mailer: git-send-email 2.37.3.windows.1 In-Reply-To: <20230705114251.661-1-cuiyunhui@bytedance.com> References: <20230705114251.661-1-cuiyunhui@bytedance.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-acpi@vger.kernel.org To enable DMI functionality on platforms where the bootloader does not support EFI and the architecture does not support reserved addresses. Add a "ffitbl" device tree node to find the SMBIOS entry point and use wire up dmi_scan_machine().This feature is known as the FDT Firmware Interface (FFI). Signed-off-by: Yunhui Cui --- MAINTAINERS | 6 +++ drivers/firmware/Kconfig | 11 +++++ drivers/firmware/Makefile | 1 + drivers/firmware/dmi_scan.c | 97 ++++++++++++++++++++++--------------- drivers/firmware/ffi.c | 42 ++++++++++++++++ include/linux/ffi.h | 29 +++++++++++ 6 files changed, 146 insertions(+), 40 deletions(-) create mode 100644 drivers/firmware/ffi.c create mode 100644 include/linux/ffi.h diff --git a/MAINTAINERS b/MAINTAINERS index e592f489e757..9b886ef36587 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -7871,6 +7871,12 @@ F: arch/x86/platform/efi/ F: drivers/firmware/efi/ F: include/linux/efi*.h +FDT FIRMWARE INTERFACE (FFI) +M: Yunhui Cui cuiyunhui@bytedance.com +S: Maintained +F: drivers/firmware/ffi.c +F: include/linux/ffi.h + EXTERNAL CONNECTOR SUBSYSTEM (EXTCON) M: MyungJoo Ham M: Chanwoo Choi diff --git a/drivers/firmware/Kconfig b/drivers/firmware/Kconfig index b59e3041fd62..3579d9bc22ff 100644 --- a/drivers/firmware/Kconfig +++ b/drivers/firmware/Kconfig @@ -303,6 +303,17 @@ config TURRIS_MOX_RWTM other manufacturing data and also utilize the Entropy Bit Generator for hardware random number generation. +config FDT_FW_INTERFACE + bool "An interface for passing firmware info through FDT" + depends on OF && OF_FLATTREE + default n + help + Enable this option to support the transfer of firmware information, + such as smbios tables, for bootloaders that do not support EFI, such + as coreboot. + + Say Y here if you want to transfer firmware information by FDT. + source "drivers/firmware/arm_ffa/Kconfig" source "drivers/firmware/broadcom/Kconfig" source "drivers/firmware/cirrus/Kconfig" diff --git a/drivers/firmware/Makefile b/drivers/firmware/Makefile index 28fcddcd688f..3b8b5d0868a6 100644 --- a/drivers/firmware/Makefile +++ b/drivers/firmware/Makefile @@ -33,6 +33,7 @@ obj-y += cirrus/ obj-y += meson/ obj-$(CONFIG_GOOGLE_FIRMWARE) += google/ obj-y += efi/ +obj-$(CONFIG_FDT_FW_INTERFACE) += ffi.o obj-y += imx/ obj-y += psci/ obj-y += smccc/ diff --git a/drivers/firmware/dmi_scan.c b/drivers/firmware/dmi_scan.c index 015c95a825d3..c29ea050b5b9 100644 --- a/drivers/firmware/dmi_scan.c +++ b/drivers/firmware/dmi_scan.c @@ -6,6 +6,7 @@ #include #include #include +#include #include #include #include @@ -655,54 +656,70 @@ static int __init dmi_smbios3_present(const u8 *buf) return 1; } -static void __init dmi_scan_machine(void) +/* + * According to the DMTF SMBIOS reference spec v3.0.0, it is + * allowed to define both the 64-bit entry point (smbios3) and + * the 32-bit entry point (smbios), in which case they should + * either both point to the same SMBIOS structure table, or the + * table pointed to by the 64-bit entry point should contain a + * superset of the table contents pointed to by the 32-bit entry + * point (section 5.2) + * This implies that the 64-bit entry point should have + * precedence if it is defined and supported by the OS. If we + * have the 64-bit entry point, but fail to decode it, fall + * back to the legacy one (if available) + */ +static int __init dmi_sacn_smbios(unsigned long smbios3, unsigned long smbios) { - char __iomem *p, *q; + char __iomem *p; char buf[32]; - - if (efi_enabled(EFI_CONFIG_TABLES)) { - /* - * According to the DMTF SMBIOS reference spec v3.0.0, it is - * allowed to define both the 64-bit entry point (smbios3) and - * the 32-bit entry point (smbios), in which case they should - * either both point to the same SMBIOS structure table, or the - * table pointed to by the 64-bit entry point should contain a - * superset of the table contents pointed to by the 32-bit entry - * point (section 5.2) - * This implies that the 64-bit entry point should have - * precedence if it is defined and supported by the OS. If we - * have the 64-bit entry point, but fail to decode it, fall - * back to the legacy one (if available) - */ - if (efi.smbios3 != EFI_INVALID_TABLE_ADDR) { - p = dmi_early_remap(efi.smbios3, 32); - if (p == NULL) - goto error; - memcpy_fromio(buf, p, 32); - dmi_early_unmap(p, 32); - - if (!dmi_smbios3_present(buf)) { - dmi_available = 1; - return; - } - } - if (efi.smbios == EFI_INVALID_TABLE_ADDR) - goto error; - - /* This is called as a core_initcall() because it isn't - * needed during early boot. This also means we can - * iounmap the space when we're done with it. - */ - p = dmi_early_remap(efi.smbios, 32); + #define INVALID_TABLE_ADDR (~0UL) + if (smbios3 != INVALID_TABLE_ADDR) { + p = dmi_early_remap(smbios3, 32); if (p == NULL) - goto error; + return -1; memcpy_fromio(buf, p, 32); dmi_early_unmap(p, 32); - if (!dmi_present(buf)) { + if (!dmi_smbios3_present(buf)) { dmi_available = 1; - return; + return 0; } + } + if (smbios == INVALID_TABLE_ADDR) + return -1; + /* + * This is called as a core_initcall() because it isn't + * needed during early boot. This also means we can + * iounmap the space when we're done with it. + */ + p = dmi_early_remap(smbios, 32); + if (p == NULL) + return -1; + memcpy_fromio(buf, p, 32); + dmi_early_unmap(p, 32); + + if (!dmi_present(buf)) { + dmi_available = 1; + return 0; + } + + return -1; +} + +static void __init dmi_scan_machine(void) +{ + char __iomem *p, *q; + char buf[32]; + + if (ffi_enabled(FFI_CONFIG_TABLES)) { + if (!dmi_sacn_smbios(ffi.smbios3, ffi.smbios)) + return; + } + + if (efi_enabled(EFI_CONFIG_TABLES)) { + if (dmi_sacn_smbios(efi.smbios3, efi.smbios)) + goto error; } else if (IS_ENABLED(CONFIG_DMI_SCAN_MACHINE_NON_EFI_FALLBACK)) { p = dmi_early_remap(SMBIOS_ENTRY_POINT_SCAN_START, 0x10000); if (p == NULL) diff --git a/drivers/firmware/ffi.c b/drivers/firmware/ffi.c new file mode 100644 index 000000000000..d4994a22438b --- /dev/null +++ b/drivers/firmware/ffi.c @@ -0,0 +1,42 @@ +// SPDX-License-Identifier: GPL-2.0-only + +#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt + +#include +#include +#include +#include + +#define FFI_INVALID_TABLE_ADDR (~0UL) + +struct ffi __read_mostly ffi = { + .smbios = FFI_INVALID_TABLE_ADDR, + .smbios3 = FFI_INVALID_TABLE_ADDR, +}; + +void __init ffi_smbios_root_pointer(void) +{ + u32 ffitbl, smbios, len, ver; + u64 entry; + fdt64_t *prop; + + ffitbl = fdt_subnode_offset(initial_boot_params, 0, "ffitbl"); + smbios = fdt_subnode_offset(initial_boot_params, ffitbl, "smbios"); + prop = fdt_getprop_w(initial_boot_params, smbios, "entry", &len); + if (!prop || len != sizeof(u64)) { + pr_debug("smbios entry not found.\n"); + return; + } + entry = fdt64_to_cpu(*prop); + + prop = fdt_getprop_w(initial_boot_params, smbios, "reg", &len); + if (!prop || len != sizeof(u32)) { + pr_debug("smbios reg not found.\n"); + return; + } + ver = fdt32_to_cpu(*prop); + (ver == 3) ? (ffi.smbios3 = entry) : (ffi.smbios = entry); + set_bit(FFI_CONFIG_TABLES, &ffi.flags); + pr_debug("smbios%d entry: %llx\n", ver, entry); +} + diff --git a/include/linux/ffi.h b/include/linux/ffi.h new file mode 100644 index 000000000000..a99c2a290556 --- /dev/null +++ b/include/linux/ffi.h @@ -0,0 +1,29 @@ +/* SPDX-License-Identifier: GPL-2.0 */ + +#ifndef _LINUX_FFI_H +#define _LINUX_FFI_H + +extern struct ffi { + unsigned long smbios; /* SMBIOS table (32 bit entry point) */ + unsigned long smbios3; /* SMBIOS table (64 bit entry point) */ + unsigned long flags; + +} ffi; + +#define FFI_CONFIG_TABLES 2 /* Can we use FFI config tables? */ + +#ifdef CONFIG_FDT_FW_INTERFACE +extern void ffi_smbios_root_pointer(void); +static inline bool ffi_enabled(int feature) +{ + return test_bit(feature, &ffi.flags) != 0; +} +#else +static inline bool ffi_enabled(int feature) +{ + return false; +} +void ffi_smbios_root_pointer(void) { return; }; +#endif + +#endif /* _LINUX_FFI_H */ From patchwork Wed Jul 5 11:42:50 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: yunhui cui X-Patchwork-Id: 699621 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 8374BEB64DA for ; Wed, 5 Jul 2023 11:45:36 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231569AbjGELpf (ORCPT ); Wed, 5 Jul 2023 07:45:35 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48614 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231630AbjGELpa (ORCPT ); Wed, 5 Jul 2023 07:45:30 -0400 Received: from mail-pl1-x62c.google.com (mail-pl1-x62c.google.com [IPv6:2607:f8b0:4864:20::62c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A69C9198D for ; Wed, 5 Jul 2023 04:45:00 -0700 (PDT) Received: by mail-pl1-x62c.google.com with SMTP id d9443c01a7336-1b89b75dc1cso4279155ad.1 for ; Wed, 05 Jul 2023 04:45:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1688557500; x=1691149500; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=2/7mU7LG0/LoivTbyL8zN+ZBZKcFo4rglaRaqylxhfQ=; b=Ltfa/6PMTzVFKvupHYoIu25JvZQEj8+TG279VMGSVCFID+E3BGc5M/0cOuZAjs8bL2 z9Cgl0L5iCAGnnQ/SuOGo7Tlk2zQTK9bQPleevr+vBadbtzutwf63D4nRPP3IF+qUaFx EvP//jSB2BrpV79rZnIxTxbFyGU2bFXfQ00+rYLUlKKiHn2sM+6/jwg1lRkSLa9Axgpj Txv/dFC2aNPc+fLwMIpNaBCDQ/ZOdivCtVpmurWLgY2ltsQ8x9kA03yypVf4nBnyOGiw Zc7G9su5n0GMnMCvvb8mRkoltS9mmH76Z7KN16SNl20HeoY+KKNBQTu61nHeHB/My8I5 vr4g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1688557500; x=1691149500; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=2/7mU7LG0/LoivTbyL8zN+ZBZKcFo4rglaRaqylxhfQ=; b=kETwbh0/HPMhhAdHfa8pU+rYAxKzNRZE8jof8/ywEZFxPnJB98JDJv3dbAqB6GB6em gHA04cGcdTibUEsHaRiixOsAW96kD7Dfzmm2l4ve1ob5HmAOJK3biao+rfKNIYHNEXAj R7t5deUnkrwFSsk8G3/xeQFsR6TLhVTHA/e5pmOOiyoP3cLkfvKF/P1m2kteoYyXPZzS Tf0ArN2erlsy8KsJUSfnDvv8EVm8HHqmMioI2Ke8E/7qZfd5Mwf0CM3xGDqlbLVNILYk E9UfigKdG7B7R1ai8by7A5g1sKSskjWS4N+wJE3Z//UeUvvDgNA7EIo0isthXCCiWUh2 eI8w== X-Gm-Message-State: ABy/qLbx14Q7S5L2d8u6KCf2XjZLVD95hm2cB8lFiCCDAgAMfGoziO2D 3YfiWQJ048fuNXpt0tpXkBVBWQ== X-Google-Smtp-Source: APBJJlE+p5F5PIvo05kj7fIPA1p9K+VjhFZ7LXhkzaKK45+ZK+JAauB4t1oRak5U+mKJZRNdHuxLkA== X-Received: by 2002:a17:90a:f40a:b0:263:f674:490e with SMTP id ch10-20020a17090af40a00b00263f674490emr1749692pjb.3.1688557499886; Wed, 05 Jul 2023 04:44:59 -0700 (PDT) Received: from PF2E59YH-BKX.inc.bytedance.com ([61.213.176.5]) by smtp.gmail.com with ESMTPSA id 3-20020a17090a194300b00263f6687690sm1177900pjh.18.2023.07.05.04.44.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 05 Jul 2023 04:44:59 -0700 (PDT) From: Yunhui Cui To: conor@kernel.org, sunilvl@ventanamicro.com, ardb@kernel.org, palmer@dabbelt.com, paul.walmsley@sifive.com, aou@eecs.berkeley.edu, linux-riscv@lists.infradead.org, rminnich@gmail.com, mark.rutland@arm.com, lpieralisi@kernel.org, rafael@kernel.org, lenb@kernel.org, jdelvare@suse.com, yc.hung@mediatek.com, angelogioacchino.delregno@collabora.com, allen-kh.cheng@mediatek.com, pierre-louis.bossart@linux.intel.com, tinghan.shen@mediatek.com, linux-kernel@vger.kernel.org, linux-acpi@vger.kernel.org, geshijian@bytedance.com, weidong.wd@bytedance.com, cuiyunhui@bytedance.com Subject: [PATCH v3 3/4] riscv: obtain SMBIOS entry from FFI Date: Wed, 5 Jul 2023 19:42:50 +0800 Message-Id: <20230705114251.661-4-cuiyunhui@bytedance.com> X-Mailer: git-send-email 2.37.3.windows.1 In-Reply-To: <20230705114251.661-1-cuiyunhui@bytedance.com> References: <20230705114251.661-1-cuiyunhui@bytedance.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-acpi@vger.kernel.org On RISC-V, Coreboot does not support EFI booting, only supports devicetree, and RISC-V does not have reserved address segments. To support Coreboot on RISC-V platforms that require DMI functionality, SMBIOS entry need to be passed through FFI. Signed-off-by: Yunhui Cui --- arch/riscv/kernel/ffi.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/arch/riscv/kernel/ffi.c b/arch/riscv/kernel/ffi.c index 147d06a5acff..b959d16fe0b3 100644 --- a/arch/riscv/kernel/ffi.c +++ b/arch/riscv/kernel/ffi.c @@ -8,6 +8,7 @@ #include #include #include +#include static u64 acpi_rsdp; @@ -35,4 +36,5 @@ u64 __init riscv_acpi_rsdp(void) void __init ffi_init(void) { ffi_acpi_root_pointer(); + ffi_smbios_root_pointer(); } From patchwork Wed Jul 5 11:42:51 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: yunhui cui X-Patchwork-Id: 699276 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 77BA4EB64DD for ; Wed, 5 Jul 2023 11:45:34 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231147AbjGELpd (ORCPT ); Wed, 5 Jul 2023 07:45:33 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48850 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231703AbjGELp0 (ORCPT ); Wed, 5 Jul 2023 07:45:26 -0400 Received: from mail-pj1-x1035.google.com (mail-pj1-x1035.google.com [IPv6:2607:f8b0:4864:20::1035]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9EED41BC2 for ; Wed, 5 Jul 2023 04:45:07 -0700 (PDT) Received: by mail-pj1-x1035.google.com with SMTP id 98e67ed59e1d1-262d33fa37cso2976035a91.3 for ; Wed, 05 Jul 2023 04:45:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1688557507; x=1691149507; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=v+ITQvowAXOXD8H4U5Ak65JYD6vo7/xikUkbFThVisc=; b=JdOIUPCcVgRbkHL6lKC2twEROgaAL4yJ8ZwTGhCaGWbZQF9aFGaRYNPGYzOGyghzhg +xgjWXfn01h1SKYk1tCnUwym7zJigY1FB2L5nLJ9K9xF+V96OcBaG8t1Nvd3B2sJD/Ls 4hF63PIb9gGwLm7I9MhvBmuNYQeSd2x4nd+O5gtyCppqbUmkWKDhM+rfZ0oSgKLAnmyh ef/1usAQUA9CcwFdOCMOZiXTJMrJ22ZEPa8whSjBMypJAPO7J2gk5zs4iFCdj7s8Fcrk ie3LhugAEg6iQhA7aaj/0X0A/wWygp1ho0cDLjVJrYds9JfqZ7MvJZbTR5YNypqp+lHX hrow== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1688557507; x=1691149507; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=v+ITQvowAXOXD8H4U5Ak65JYD6vo7/xikUkbFThVisc=; b=NaxfYxyzrPYePRyZ06vQeXsRJAEc4G0iWbmaLEg1iWdcCCjTYtENr1BuzhsOQNqaEq vtoqsb5MvnQ7/mlZPARM5IiZARkVSh1z2qn4zoH1TUdg9fW8OLhJjlsW2Y6SYx8NAkD4 1VPuY5ja3bJu2CAaUp2cGdm0sOMY/VPLbaMTLooEbH8pijU+oW+caYGCay/sjtVViTMf UxjME1i6PC3VIZrgBdQPc6BI2iOLxOEenI+6wwWQHX26seRTncKmlXB52cVc5vUJoAdE lx1kprTet6oQWM4q1HlNrKjZyNad1QYPfLoArlBG1U+fHOuE3af6n+VVRCtQbkCxd9+c dklw== X-Gm-Message-State: ABy/qLaoJp7B4D3/lqJ2NDVkf46TvORsdpJRr3TE0akZBfCRprjfKZqs XQtPSyxlMAzBQeIQ2pzcHVMgZA== X-Google-Smtp-Source: APBJJlFcrKCShSuwPuLAA2ZOXSGBben7z55N7jwvIQjxqZ8xyVRdttDLfGixeJRGpz3xqUvIJ1x13w== X-Received: by 2002:a17:90b:5109:b0:263:5c78:4b63 with SMTP id sc9-20020a17090b510900b002635c784b63mr12763480pjb.45.1688557506871; Wed, 05 Jul 2023 04:45:06 -0700 (PDT) Received: from PF2E59YH-BKX.inc.bytedance.com ([61.213.176.5]) by smtp.gmail.com with ESMTPSA id 3-20020a17090a194300b00263f6687690sm1177900pjh.18.2023.07.05.04.45.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 05 Jul 2023 04:45:06 -0700 (PDT) From: Yunhui Cui To: conor@kernel.org, sunilvl@ventanamicro.com, ardb@kernel.org, palmer@dabbelt.com, paul.walmsley@sifive.com, aou@eecs.berkeley.edu, linux-riscv@lists.infradead.org, rminnich@gmail.com, mark.rutland@arm.com, lpieralisi@kernel.org, rafael@kernel.org, lenb@kernel.org, jdelvare@suse.com, yc.hung@mediatek.com, angelogioacchino.delregno@collabora.com, allen-kh.cheng@mediatek.com, pierre-louis.bossart@linux.intel.com, tinghan.shen@mediatek.com, linux-kernel@vger.kernel.org, linux-acpi@vger.kernel.org, geshijian@bytedance.com, weidong.wd@bytedance.com, cuiyunhui@bytedance.com Subject: [PATCH v3 4/4] dt-bindings: firmware: Document ffitbl binding Date: Wed, 5 Jul 2023 19:42:51 +0800 Message-Id: <20230705114251.661-5-cuiyunhui@bytedance.com> X-Mailer: git-send-email 2.37.3.windows.1 In-Reply-To: <20230705114251.661-1-cuiyunhui@bytedance.com> References: <20230705114251.661-1-cuiyunhui@bytedance.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-acpi@vger.kernel.org Add the description for ffitbl subnode. Signed-off-by: Yunhui Cui --- .../devicetree/bindings/firmware/ffitbl.txt | 27 +++++++++++++++++++ MAINTAINERS | 1 + 2 files changed, 28 insertions(+) create mode 100644 Documentation/devicetree/bindings/firmware/ffitbl.txt diff --git a/Documentation/devicetree/bindings/firmware/ffitbl.txt b/Documentation/devicetree/bindings/firmware/ffitbl.txt new file mode 100644 index 000000000000..c42368626199 --- /dev/null +++ b/Documentation/devicetree/bindings/firmware/ffitbl.txt @@ -0,0 +1,27 @@ +FFI(FDT FIRMWARE INTERFACE) driver + +Required properties: + - entry : acpi or smbios root pointer, u64 + - reg : acpi or smbios version, u32 + +Some bootloaders, such as Coreboot do not support EFI, +only devicetree and some arches do not have a reserved +address segment. Add "ffitbl" subnode to obtain ACPI RSDP +and SMBIOS entry. +This feature is known as FDT Firmware Interface (FFI). + +Example: + ffitbl { + + smbios { + entry = ""; + reg = < 0x03 >; + + } + acpi { + entry = ""; + reg = < 0x06 >; + + } + } + diff --git a/MAINTAINERS b/MAINTAINERS index 9b886ef36587..008257e55062 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -7874,6 +7874,7 @@ F: include/linux/efi*.h FDT FIRMWARE INTERFACE (FFI) M: Yunhui Cui cuiyunhui@bytedance.com S: Maintained +F: Documentation/devicetree/bindings/firmware/ffitbl.txt F: drivers/firmware/ffi.c F: include/linux/ffi.h