From patchwork Sun Jul 2 09:57:32 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yunhui Cui X-Patchwork-Id: 13299166 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 bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 85E89EB64DD for ; Sun, 2 Jul 2023 09:58:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:Message-Id:Date:Subject:To :From:Reply-To:Cc:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References: List-Owner; bh=rQelPd+74zYn/UN51gf7BwdJVDJTxICUL8qTMof8/ZU=; b=1kZVinWYPqPa6e Jwt1VLGobEWrF5wtTEdOGzBCapk2r0myE2LmgOuM78BlF9nPMu+TAT8Fy+2/S0ofpz3CgsuFTFNou JnudigCourg6tyqAiliy00flRgMbsJIqsZtgMehIVlRUzBM1EKv1TcZN7t6BxBnA0NX3RtRRUvNN6 ++xCUhTV3h1pZ8CPsX7Zb670X6EG20FO53uL8KW6f6FsObVILzZtffdMj72LWRvojs0cGtB+HLkK/ e2Vm4EJGUnAkf9BwSqmC7GFB+cBlpOjdWh0bKFIXCq/bueNdK/rMnFq5VTag0YKSh9Y6EUOCX36yI ba1rchNxLcsyg0v+C0Mw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1qFtqM-007Wbv-1P; Sun, 02 Jul 2023 09:58:10 +0000 Received: from mail-pg1-x532.google.com ([2607:f8b0:4864:20::532]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1qFtqI-007Wah-1Z for linux-riscv@lists.infradead.org; Sun, 02 Jul 2023 09:58:08 +0000 Received: by mail-pg1-x532.google.com with SMTP id 41be03b00d2f7-55ac628e3cfso1781257a12.3 for ; Sun, 02 Jul 2023 02:57:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1688291875; x=1690883875; h=content-transfer-encoding:mime-version:message-id:date:subject:to :from:from:to:cc:subject:date:message-id:reply-to; bh=XF2+x8StAqIQZEEXXA77vQxRC4bKZrb2UmGw9jTVMxg=; b=C8mJIVmo9Gt8KrJx133l1TXUl96CjQQdawYTJqjV0B/dmrVnXbEotILm4dSXCEO+LE 9Ej+UK5HJQrDCB7aDdtABsSPT1gpEHjUABBtbOKkrTOnXS+OtygyvUJnmMUti2fldsuk LYuM+dNsVpvyn4VRdWlnqWoLRubroBSgNcRzK3Loq3wizKTdyajAHSbzjtTG5BPh00Ys njN7jgXWvlJfMrw1ZFIIR4kvKAqQ5TCf94B/vkUVxpiDCWmI5J515CPvcj5cOBDrNX7x 20EwZMgumErRPjsjQPjjzOdyrCNEI6qDtDdu0oda8rhwk1EFVuDeKFlL8tHtqbgJrxlX tV2g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1688291875; x=1690883875; h=content-transfer-encoding:mime-version:message-id:date:subject:to :from:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=XF2+x8StAqIQZEEXXA77vQxRC4bKZrb2UmGw9jTVMxg=; b=bcdNDWGPDlWfUKSP8IvXkYge6l9a1XNnpqPol5HTI2NRnxCqVqDg548e9sm6jPZZiD udZ60ceMePCZfZw7AiULw5amXJFcRLmwP6dsiHPo/N8TMoo9XBnpeIUj8ahIm5DUSckK tMfubLmcgfKUFkHwfVzCJP+aJK5PBytJ6G1xEUieKJr/DfVztaW3EME35OPGiq3jXD1t KWGfPRQnBcT9f2p7y51KpyDNtpApXRGy7jWUazbAJZRNeBQ+aGQWltN1dfzEq4CCjCJ1 NqZNj1bFlKPBeLNot75z0+sOlXGsK6sFAeXq0BWOL+1qVbIIyLrWnTGPXo1uAxKsWSyc po5w== X-Gm-Message-State: ABy/qLaz/G0bvxE5a76Dtd2FHO4Jiwpl3Fht2RLQIEo7GlGPjlFDDrDU gnFv98WcunicSx7jpnLJAWCYmQ== X-Google-Smtp-Source: APBJJlF4yLaj8jr7OTR8FcXH/r/O+yqMJrHgHcjvBx+h67R5YAj78AaIxs+XMdOOaBezarVJelvXvA== X-Received: by 2002:a05:6a20:3257:b0:12c:1193:a563 with SMTP id hm23-20020a056a20325700b0012c1193a563mr5325675pzc.58.1688291875230; Sun, 02 Jul 2023 02:57:55 -0700 (PDT) Received: from PF2E59YH-BKX.inc.bytedance.com ([139.177.225.251]) by smtp.gmail.com with ESMTPSA id u26-20020a62ed1a000000b006827d86ca0csm1605095pfh.55.2023.07.02.02.57.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 02 Jul 2023 02:57:54 -0700 (PDT) From: Yunhui Cui To: 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 v2 1/3] riscv: obtain ACPI RSDP from FFI. Date: Sun, 2 Jul 2023 17:57:32 +0800 Message-Id: <20230702095735.860-1-cuiyunhui@bytedance.com> X-Mailer: git-send-email 2.37.3.windows.1 MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230702_025806_677216_7127E56B X-CRM114-Status: GOOD ( 18.98 ) X-BeenThere: linux-riscv@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-riscv" Errors-To: linux-riscv-bounces+linux-riscv=archiver.kernel.org@lists.infradead.org 1. We need to enable the ACPI function on RISC-V. When booting with Coreboot, we encounter two problems: a. Coreboot does not support EFI b. On RISC-V, only the DTS channel can be used. 2. Based on this, we have added an interface for obtaining firmware information transfer through FDT, named FFI. 3. We not only use FFI to pass ACPI RSDP, but also pass other firmware information as an extension. Signed-off-by: Yunhui Cui --- MAINTAINERS | 6 ++++++ arch/riscv/Kconfig | 10 ++++++++++ arch/riscv/include/asm/acpi.h | 9 +++++++++ arch/riscv/include/asm/ffi.h | 9 +++++++++ arch/riscv/kernel/Makefile | 1 + arch/riscv/kernel/ffi.c | 37 +++++++++++++++++++++++++++++++++++ arch/riscv/kernel/setup.c | 2 ++ 7 files changed, 74 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/Kconfig b/arch/riscv/Kconfig index b49793cf34eb..2e1c40fb2300 100644 --- a/arch/riscv/Kconfig +++ b/arch/riscv/Kconfig @@ -785,6 +785,16 @@ config EFI allow the kernel to be booted as an EFI application. This is only useful on systems that have UEFI firmware. +config FFI + bool "Fdt firmware interface" + depends on OF + default y + help + Added an interface to obtain firmware information transfer + through FDT, named FFI. Some bootloaders do not support EFI, + such as coreboot. + We can pass firmware information through FFI, such as ACPI. + config CC_HAVE_STACKPROTECTOR_TLS def_bool $(cc-option,-mstack-protector-guard=tls -mstack-protector-guard-reg=tp -mstack-protector-guard-offset=0) diff --git a/arch/riscv/include/asm/acpi.h b/arch/riscv/include/asm/acpi.h index f71ce21ff684..f9d1625dd159 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 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..847af02abd87 --- /dev/null +++ b/arch/riscv/include/asm/ffi.h @@ -0,0 +1,9 @@ +/* SPDX-License-Identifier: GPL-2.0 */ + +#ifndef _ASM_FFI_H +#define _ASM_FFI_H + +extern u64 acpi_rsdp; +extern void ffi_init(void); + +#endif /* _ASM_FFI_H */ diff --git a/arch/riscv/kernel/Makefile b/arch/riscv/kernel/Makefile index 506cc4a9a45a..274e06f4da33 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_FFI) += 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..c5ac2b5d9148 --- /dev/null +++ b/arch/riscv/kernel/ffi.c @@ -0,0 +1,37 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* + * ffi.c - FDT FIRMWARE INTERFACE + */ + +#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt + +#include +#include +#include + +u64 acpi_rsdp; + +void __init ffi_acpi_root_pointer(void) +{ + int cfgtbl, len; + fdt64_t *prop; + + cfgtbl = fdt_path_offset(initial_boot_params, "/cfgtables"); + if (cfgtbl < 0) { + pr_info("firmware table not found.\n"); + return; + } + + prop = fdt_getprop_w(initial_boot_params, cfgtbl, "acpi_phy_ptr", &len); + if (!prop || len != sizeof(u64)) + pr_info("acpi_rsdp not found.\n"); + else + acpi_rsdp = fdt64_to_cpu(*prop); + + pr_debug("acpi rsdp: %llx\n", 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 Sun Jul 2 09:57:33 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yunhui Cui X-Patchwork-Id: 13299168 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 bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 64CF3C001B0 for ; Sun, 2 Jul 2023 09:58:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:To:From:Reply-To:Cc:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=WOmFuxYYwBidJmlcv0tEX06eePCbFU4iTiK/RxEQIgU=; b=RJuIiyNmJagi18 rhFHpQlUwh0PTsyp8PEdz634ZqvjRSke0yFZOZzo+ieghmrtZm2Ioc1pwzpUySZHo5PPTfZSr6NQN KWMHtxMibYHCIYn2UpeyS3DZV+jW3wjQ7VerQ3bPsaN856c63JHhmJLssOI8e78f6+7s5B5Hf9xD6 ZOLCjfRFHGw4riF32HTMbO2UXw8QhzTFfqk5qzzP5OUrrnz9QN92H59YwJXGcrQWUVA4fY2ce87Pm ESueL0ppR5N5S2n2g/QzA0qQOQp8Boa2YolA232PKbm19UkUaE3wqTR65QMqmE3+8P/InF9rqYF3T CDNz7szuMsgvAOTOKUJg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1qFtqP-007WcJ-0J; Sun, 02 Jul 2023 09:58:14 +0000 Received: from mail-pg1-x52b.google.com ([2607:f8b0:4864:20::52b]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1qFtqJ-007Way-1n for linux-riscv@lists.infradead.org; Sun, 02 Jul 2023 09:58:09 +0000 Received: by mail-pg1-x52b.google.com with SMTP id 41be03b00d2f7-517ab9a4a13so2419633a12.1 for ; Sun, 02 Jul 2023 02:58:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1688291883; x=1690883883; 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=HYya50tJlu2Jrm7C5TXSsOJP4LQItfiIbIJ4JgEwpvU=; b=dzNuDndr8OWQUYpcU4HBzRoL+dFRpF38ULyIKffCwwmFwEkqZUg68qO63QTl2NQyjm l2xUZLlLcqNHMuPSoLs1p4guToErWKm36lUkbve/lgDYYHao3X9Dtr3t+FJS7J3UAf0A zOfPjY2zeKIkh5UNg9OhPcRuECi0coMOY4qxPoOtIywALalB/NB/IOm8Lnv2hF/GRXN/ Gywkv9Pe7pmsqYQYqbbGPfgz2HidIpRStPKtO1uoYCvht0hi0HbBi3EZz192GmZ5vnCC Q9aBUBY8238CSLdJntuG4ABygKt3itorUNa5c6juQBqnAQ5NMA9GApqvXEYJlSclb5yI ePvQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1688291883; x=1690883883; 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=HYya50tJlu2Jrm7C5TXSsOJP4LQItfiIbIJ4JgEwpvU=; b=bOVu14kt8aZUl3BqXCAHnhDRp2yKuAKAp7VBWmhJ2mk+xeRGOW+stnmg3WSkIuu9Hr 5cNVWlp1IOvRDWxzrE91MDN3vFED4FHsyMvjnuDYKOZ3q+lHcVIWGuf56AdkOZJEs6Bz Ufi+xd44HTOPMi/SZUKcqIiPbpp50NyNpk4DRgCQR1A+DRe9Tr7W6HpYde/WdpBLhqhm RHAFxCeNlKmlaEkWZACVp7P1wRPMUqA30B9ctQmMN1WY20tBTNRHtENObmYVvFU7coxy nTM2Hopjrl2OsboDRsGJsVGqZ+e04IOkxy+0VP6xj39SNDx3m0Y8RsI3CbpOZQRfmKbB pIkw== X-Gm-Message-State: ABy/qLYwCja91QBFnSxnOZwLeXaGJ+0LcOvandN56vaTzSbh+iD/lD+G pLtPZDu8buIgMQ71GSo3zFk4Lg== X-Google-Smtp-Source: APBJJlFlQxumS1ONslw4qPitjTJdc8b7vX961ozrSCLVfevwcHg41jW+SnpRdwMB5I70RzXkqLlreA== X-Received: by 2002:a05:6a20:6a22:b0:12e:6ba3:1f6f with SMTP id p34-20020a056a206a2200b0012e6ba31f6fmr963985pzk.23.1688291882787; Sun, 02 Jul 2023 02:58:02 -0700 (PDT) Received: from PF2E59YH-BKX.inc.bytedance.com ([139.177.225.251]) by smtp.gmail.com with ESMTPSA id u26-20020a62ed1a000000b006827d86ca0csm1605095pfh.55.2023.07.02.02.57.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 02 Jul 2023 02:58:02 -0700 (PDT) From: Yunhui Cui To: 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 v2 2/3] firmware: introduce FFI for SMBIOS entry. Date: Sun, 2 Jul 2023 17:57:33 +0800 Message-Id: <20230702095735.860-2-cuiyunhui@bytedance.com> X-Mailer: git-send-email 2.37.3.windows.1 In-Reply-To: <20230702095735.860-1-cuiyunhui@bytedance.com> References: <20230702095735.860-1-cuiyunhui@bytedance.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230702_025807_597174_B1C20E62 X-CRM114-Status: GOOD ( 34.93 ) X-BeenThere: linux-riscv@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-riscv" Errors-To: linux-riscv-bounces+linux-riscv=archiver.kernel.org@lists.infradead.org 1. Some bootloaders do not support EFI, and the transfer of firmware information can only be done through DTS, such as Coreboot. 2. Some arches do not have a reserved address segment that can be used to pass firmware parameters like x86. 3. Based on this, we have added an interface to obtain firmware information through FDT, named FFI. 4. We not only use FFI to pass SMBIOS entry, but also pass other firmware information as an extension. Signed-off-by: Yunhui Cui --- MAINTAINERS | 6 ++ drivers/firmware/Kconfig | 11 ++++ drivers/firmware/Makefile | 1 + drivers/firmware/dmi_scan.c | 128 +++++++++++++++++------------------- drivers/firmware/ffi.c | 36 ++++++++++ include/linux/ffi.h | 15 +++++ 6 files changed, 128 insertions(+), 69 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..ea0149fb4683 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 + When some bootloaders do not support EFI, and the arch does not + support SMBIOS_ENTRY_POINT_SCAN_START, then you can enable this option + to support the transfer of firmware information, such as smbios tables. + + Say Y here if you want to pass 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..64c1ceffe373 100644 --- a/drivers/firmware/dmi_scan.c +++ b/drivers/firmware/dmi_scan.c @@ -6,6 +6,7 @@ #include #include #include +#include #include #include #include @@ -628,31 +629,56 @@ static int __init dmi_present(const u8 *buf) } /* - * Check for the SMBIOS 3.0 64-bit entry point signature. Unlike the legacy - * 32-bit entry point, there is no embedded DMI header (_DMI_) in here. + * 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_smbios3_present(const u8 *buf) +static int __init dmi_sacn_smbios(unsigned long smbios3, unsigned long smbios) { - if (memcmp(buf, "_SM3_", 5) == 0 && - buf[6] >= 24 && buf[6] <= 32 && - dmi_checksum(buf, buf[6])) { - dmi_ver = get_unaligned_be24(buf + 7); - dmi_num = 0; /* No longer specified */ - dmi_len = get_unaligned_le32(buf + 12); - dmi_base = get_unaligned_le64(buf + 16); - smbios_entry_point_size = buf[6]; - memcpy(smbios_entry_point, buf, smbios_entry_point_size); + char __iomem *p; + char buf[32]; + #define INVALID_TABLE_ADDR (~0UL) - if (dmi_walk_early(dmi_decode) == 0) { - pr_info("SMBIOS %d.%d.%d present.\n", - dmi_ver >> 16, (dmi_ver >> 8) & 0xFF, - dmi_ver & 0xFF); - dmi_format_ids(dmi_ids_string, sizeof(dmi_ids_string)); - pr_info("DMI: %s\n", dmi_ids_string); + if (smbios3 != INVALID_TABLE_ADDR) { + p = dmi_early_remap(smbios3, 32); + if (p == NULL) + return -1; + memcpy_fromio(buf, p, 32); + dmi_early_unmap(p, 32); + + if (!dmi_smbios3_present(buf)) { + dmi_available = 1; return 0; } } - return 1; + + 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) @@ -660,58 +686,22 @@ static void __init dmi_scan_machine(void) char __iomem *p, *q; char buf[32]; +#ifdef CONFIG_FDT_FW_INTERFACE + if (dmi_sacn_smbios(ffi.smbios3, ffi.smbios)) + goto error; +#endif 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) + if (dmi_sacn_smbios(efi.smbios3, efi.smbios)) 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); - if (p == NULL) - goto error; - memcpy_fromio(buf, p, 32); - dmi_early_unmap(p, 32); - - if (!dmi_present(buf)) { - dmi_available = 1; - return; - } } else if (IS_ENABLED(CONFIG_DMI_SCAN_MACHINE_NON_EFI_FALLBACK)) { p = dmi_early_remap(SMBIOS_ENTRY_POINT_SCAN_START, 0x10000); if (p == NULL) goto error; /* - * Same logic as above, look for a 64-bit entry point - * first, and if not found, fall back to 32-bit entry point. - */ + * Same logic as above, look for a 64-bit entry point + * first, and if not found, fall back to 32-bit entry point. + */ memcpy_fromio(buf, p, 16); for (q = p + 16; q < p + 0x10000; q += 16) { memcpy_fromio(buf + 16, q, 16); @@ -724,12 +714,12 @@ static void __init dmi_scan_machine(void) } /* - * Iterate over all possible DMI header addresses q. - * Maintain the 32 bytes around q in buf. On the - * first iteration, substitute zero for the - * out-of-range bytes so there is no chance of falsely - * detecting an SMBIOS header. - */ + * Iterate over all possible DMI header addresses q. + * Maintain the 32 bytes around q in buf. On the + * first iteration, substitute zero for the + * out-of-range bytes so there is no chance of falsely + * detecting an SMBIOS header. + */ memset(buf, 0, 16); for (q = p; q < p + 0x10000; q += 16) { memcpy_fromio(buf + 16, q, 16); diff --git a/drivers/firmware/ffi.c b/drivers/firmware/ffi.c new file mode 100644 index 000000000000..169802b4a7a8 --- /dev/null +++ b/drivers/firmware/ffi.c @@ -0,0 +1,36 @@ +// 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, +}; +EXPORT_SYMBOL(ffi); + +void __init ffi_smbios_root_pointer(void) +{ + int cfgtbl, len; + fdt64_t *prop; + + cfgtbl = fdt_path_offset(initial_boot_params, "/cfgtables"); + if (cfgtbl < 0) { + pr_info("firmware table not found.\n"); + return; + } + prop = fdt_getprop_w(initial_boot_params, cfgtbl, "smbios_phy_ptr", &len); + if (!prop || len != sizeof(u64)) + pr_info("smbios entry point not found.\n"); + else + ffi.smbios = fdt64_to_cpu(*prop); + + pr_info("smbios root pointer: %lx\n", ffi.smbios); +} + diff --git a/include/linux/ffi.h b/include/linux/ffi.h new file mode 100644 index 000000000000..95298a805222 --- /dev/null +++ b/include/linux/ffi.h @@ -0,0 +1,15 @@ +/* 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; + +void ffi_smbios_root_pointer(void); + +#endif /* _LINUX_FFI_H */ From patchwork Sun Jul 2 09:57:34 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yunhui Cui X-Patchwork-Id: 13299167 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 bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 54252EB64DA for ; Sun, 2 Jul 2023 09:58:25 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:To:From:Reply-To:Cc:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=r2691DZ/AsdxRCF3c9r+U8kqpHPALLPC9A2W2bpOdt0=; b=dWyZukp7EjTxE2 fwIqtqUPw5bLyXMnvfGLslarp7QEAodvcP7HfPqHE1O8UClaTXZ4rKwyN8HA//eBqKa3NBV2mCZzM K0bZgX9ztAxppR1u2uSNCHBgFp+XT/FU8S+GlKBTIzxf4rrFtdtWeeSMwkj2SHgkntfo5l6NAsOwD hHC8IAJpA5xhXZy2c8B5qYr880NTLIosMAsrPa4tLhZjqek8pqeiTrkeZKkWDX7o6hvYOsYi6vNh5 gDP3E0zM/Bp4vlDR9hIjY/8/yc7liiHg+nJHstnuEKNyGhr0ah7Cf4n7ef00PHy3Ki/omOvRQ/TWj BN9J0hj7zvncJzRbxfqw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1qFtqW-007Wd8-1v; Sun, 02 Jul 2023 09:58:20 +0000 Received: from mail-pf1-x42c.google.com ([2607:f8b0:4864:20::42c]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1qFtqN-007Wbz-2D for linux-riscv@lists.infradead.org; Sun, 02 Jul 2023 09:58:13 +0000 Received: by mail-pf1-x42c.google.com with SMTP id d2e1a72fcca58-676f16e0bc4so1706582b3a.0 for ; Sun, 02 Jul 2023 02:58:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1688291890; x=1690883890; 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=kkAY8od4kopgBrvcbw1hFpjzgJzWLikggNI5ytXC3Uk=; b=loY2CFs4lCMCrbHrZ0yHjXW0d09bE4yUX16zdqny9IfQYSrLVevitIgjVjuraQ1Gi1 WAmfNin9IKUl2GQp00jw/CWIWhYqGbAHp8jvoeWHdW2tcmtEKvfGCCrVB8hx6Q4Sjqqf HIaVcB+YtGA+M3GO+XfmBpZplhMaqD7hiiyflwP4RFdvBAZ38PNOqc3mzDurTK86p+je M1nxappZcfZ3mae9G8be5IBvNUlyRsR6sVYEV+W25NJWKZ4q+aoamrJnQ3X1ZRNQGXL6 Qmj/bbGQGyhVgTzIthLGGC/bHbI5sBzTGrTmwXacCHk2kbdGKz+PNnTZBecgIiHh5zI9 UFTg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1688291890; x=1690883890; 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=kkAY8od4kopgBrvcbw1hFpjzgJzWLikggNI5ytXC3Uk=; b=fpB4rv38gbUFAylVHCuq9LK2EZ1PsYPDOxxRLMQlWhOp+gri7bjAsNfMLgNz0in7Gy BKrukzrRmD7Tk/poENuQcmhG63aJUGFwj9OeKCCTN5Rg3EGyBNDMUum9H3cDxBC8IOR6 /h24hxoEpEFEKTEssxSyVYwdF+3svdgZL/XWZYWLvyeVs/jnaLDa1ehJatEKZ1kB5wyT ddo3W7SX9XSm5i9idQeHR6IOFsVfVWn9yBjOqIm4RQ69WZTYCbTXM4EfZ9jUT1Goq8lF D0NpQLL+F18icEN1DekF5mAT4sZzXJ42vwi/G9uQDUEsLWRVOxXW1+zd6Gm/m2Qd0hsZ orPA== X-Gm-Message-State: ABy/qLYbBOEKQYRHMb32FYsuejnqDgr8j4WPYP3a18EYGVWP2eW1XpS0 rq3WUVWFza0/aRmHZ+oyt7LvJw== X-Google-Smtp-Source: APBJJlEXSgBPi382cT8u7InSOCN1bAAjdhLBtHtZTpazMFigPk1oiVbNh/c+TMlLCxgtWsKVe0Y3jA== X-Received: by 2002:a05:6a00:2d87:b0:682:4de1:adcc with SMTP id fb7-20020a056a002d8700b006824de1adccmr7473435pfb.12.1688291890230; Sun, 02 Jul 2023 02:58:10 -0700 (PDT) Received: from PF2E59YH-BKX.inc.bytedance.com ([139.177.225.251]) by smtp.gmail.com with ESMTPSA id u26-20020a62ed1a000000b006827d86ca0csm1605095pfh.55.2023.07.02.02.58.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 02 Jul 2023 02:58:09 -0700 (PDT) From: Yunhui Cui To: 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 v2 3/3] riscv: obtain SMBIOS entry from FFI. Date: Sun, 2 Jul 2023 17:57:34 +0800 Message-Id: <20230702095735.860-3-cuiyunhui@bytedance.com> X-Mailer: git-send-email 2.37.3.windows.1 In-Reply-To: <20230702095735.860-1-cuiyunhui@bytedance.com> References: <20230702095735.860-1-cuiyunhui@bytedance.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230702_025812_433552_15FD1A96 X-CRM114-Status: UNSURE ( 8.60 ) X-CRM114-Notice: Please train this message. X-BeenThere: linux-riscv@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-riscv" Errors-To: linux-riscv-bounces+linux-riscv=archiver.kernel.org@lists.infradead.org When we bringup with coreboot on riscv, we need to obtain the entry address of SMBIOS through the FFI scheme. Signed-off-by: Yunhui Cui --- arch/riscv/kernel/ffi.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/arch/riscv/kernel/ffi.c b/arch/riscv/kernel/ffi.c index c5ac2b5d9148..c44f943a1cb5 100644 --- a/arch/riscv/kernel/ffi.c +++ b/arch/riscv/kernel/ffi.c @@ -8,6 +8,7 @@ #include #include #include +#include u64 acpi_rsdp; @@ -34,4 +35,7 @@ void __init ffi_acpi_root_pointer(void) void __init ffi_init(void) { ffi_acpi_root_pointer(); +#if CONFIG_FDT_FW_INTERFACE + ffi_smbios_root_pointer(); +#endif }