From patchwork Thu Feb 27 22:26:40 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Atish Patra X-Patchwork-Id: 11411013 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id D710D17E0 for ; Thu, 27 Feb 2020 22:27:08 +0000 (UTC) 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 mail.kernel.org (Postfix) with ESMTPS id B4F47246A2 for ; Thu, 27 Feb 2020 22:27:08 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="Ajb0lfKB"; dkim=fail reason="signature verification failed" (2048-bit key) header.d=wdc.com header.i=@wdc.com header.b="Aa+3t8Jg" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org B4F47246A2 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=wdc.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-riscv-bounces+patchwork-linux-riscv=patchwork.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id: Content-Transfer-Encoding:MIME-Version:References:In-Reply-To:Message-Id:Date :Subject:To:From:Reply-To:Content-Type:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=FA99i+lXVpH03dKLCB/VNwnyGxUUoHfwSRDfUssXRTY=; b=Ajb0lfKBoRGh76 V5ALK65d/xbbKj7KcL6gTY9WgHyBEjcu52uxz5dtV5tp63OHy3SLQGEILhALVm2i5YBOG+OjbzCP1 rlb28F6JAtNnH5ncwtiUAljiJ9vOjTz7R9rqD/UVcAwE64Dn5H5ixs4niWm5I6oDeyW+bdYvSAej3 log33fU9wQCH2xnMu/kJtyDppWsS16E+BOcf+S6QS2dCLCYyS7pjiDvxyP8exnTgDkc5+44suBkUa 3s5+x19hZa+JNufFFWdOSxzMtyguhzwH9LkbHo+aGb9HDiHYa9kzRg6orCqJhH4DxmcRVzeVZ1f5o ppCzpoxF1mg4cQRikxmg==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1j7RcV-0000eL-K8; Thu, 27 Feb 2020 22:27:03 +0000 Received: from esa6.hgst.iphmx.com ([216.71.154.45]) by bombadil.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1j7RcO-0000Wn-Su for linux-riscv@lists.infradead.org; Thu, 27 Feb 2020 22:26:58 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1582842417; x=1614378417; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=8+bQmOk3su3vFKh2m+lkIXpoSPkei2/BxO2wUo2lbAs=; b=Aa+3t8JgjVcr9PS26ddOdy2QpOitbHMCS6wNIA8T3JqaF7st6D2dE5pm zLIf01DF038IU0+EdO+qHUazwGX2o5+/yKf3o1rzw1S1ASesA0WK6SzFb X0B1AXvDdkiKIzN5603T9UAdW+g4ICn4x5hpKXmDfkZ8l64cCqhdmOGy1 85pKhQ1KdalgnihcoFEWLHZSvhpSZApl5MjE4tEXefO68NHkASe44H4Pf IiiqkhIlD9c49z59wZEyh4QDkap04mSfSmOjScjT3DZxIs7B35DKOJO6B EcbsNQ5h0bGpfJ4cUVUL/k4TsoKMnJ/i5YQ2EGDo3izzFl7w5BmwESIkO g==; IronPort-SDR: RMQ02UV8T/A4lr5JhsYRxSX3FPxJhgPqlFiB8VSffbl446B+Aw/SgFhUFf6ZlEcets4UfxJ0HI Hzcwq3eV49LZRRR5Q90Bn/cBx/yCLI+ufvprEvygSs5d6qHGsUdnh9A+U8pyLdJ8vwWqrwrMG1 2Gyn4E2uCXBIm1c1eDnQDMXNr1auh3JSlgul7rg9KOiGqDHLG6Ewk3iQpBWYkRV/3rcAB5W8I9 7oHsPlI/Z6k5Q29E6RrEXaLUXeJBwU3p1r4hfJSBlvKawzLVlQE741Xp85y5zSa0FI4g/ISlQ9 pnY= X-IronPort-AV: E=Sophos;i="5.70,493,1574092800"; d="scan'208";a="132395341" Received: from uls-op-cesaip02.wdc.com (HELO uls-op-cesaep02.wdc.com) ([199.255.45.15]) by ob1.hgst.iphmx.com with ESMTP; 28 Feb 2020 06:26:50 +0800 IronPort-SDR: fRkY5xxI07W8R7mQKcbalSogblOqZnjqq/0ZUzSlfKG8bGjR4fxXmSh14y+PVwG0fu4AEiWVmi alm/owK1N0tqWT/11ClB9dnCx/GGgrEbwzpSzLmpe2M3nJlNf/kfwjBmYC3ChXeXl5Q3gmhogZ NwGCqu9UihMtkf6zitMHd4IbMbcemzYjLuorsng8lRrQ4U5rT7ZFmEosH4Ggz7O8kTJPJkcna7 K/KdrQlwjZ+zXyhSoxBV6pp+fTv1aN94UNzeqPPsCv32q1FrJKO+hB/IXMZLX3Rrbwp8sVoY9k b0mwwt93AVgGNXRuOf8qlKwH Received: from uls-op-cesaip02.wdc.com ([10.248.3.37]) by uls-op-cesaep02.wdc.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 27 Feb 2020 14:18:49 -0800 IronPort-SDR: doNdtjDyQyTl5eHyB8x3had8Qj7buf7Q0oxV6xcruIObUlvaR3SwBNMXHHv35+bayB4a+jhNLs N5S5SEE1DogcN0LD6KxHe7gBN+8i0ZwIOU5CG4dDQN6k65Vja7f10nvah4Nk9sPUJ5YHrP9ghF fxQGvMEbuEAE9Uv6pwXxYBJyqn0g09Uv3x8uE/2xV2kPrXD0bHt1eNYazxluniZONh8DaRNLAt RZDc0vGNHAjphjPfo66mj6MFLQHy6XiHsRPCWXpdUNSQQNipkQJ6082q5MK4KjDtQn087G0uHP gzA= WDCIronportException: Internal Received: from jedi-01.sdcorp.global.sandisk.com (HELO jedi-01.int.fusionio.com) ([10.11.143.218]) by uls-op-cesaip02.wdc.com with ESMTP; 27 Feb 2020 14:26:49 -0800 From: Atish Patra To: linux-kernel@vger.kernel.org Subject: [v1 PATCH 1/5] efi: Move arm-stub to a common file Date: Thu, 27 Feb 2020 14:26:40 -0800 Message-Id: <20200227222644.9468-2-atish.patra@wdc.com> X-Mailer: git-send-email 2.24.0 In-Reply-To: <20200227222644.9468-1-atish.patra@wdc.com> References: <20200227222644.9468-1-atish.patra@wdc.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20200227_142657_019954_D621BF06 X-CRM114-Status: GOOD ( 15.09 ) X-Spam-Score: -2.5 (--) X-Spam-Report: SpamAssassin version 3.4.3 on bombadil.infradead.org summary: Content analysis details: (-2.5 points) pts rule name description ---- ---------------------- -------------------------------------------------- -2.3 RCVD_IN_DNSWL_MED RBL: Sender listed at https://www.dnswl.org/, medium trust [216.71.154.45 listed in list.dnswl.org] 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record -0.0 SPF_PASS SPF: sender matches SPF record -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid X-BeenThere: linux-riscv@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kate Stewart , linux-efi@vger.kernel.org, Ard Biesheuvel , Catalin Marinas , Linus Walleij , Russell King , Atish Patra , Mauro Carvalho Chehab , linux-riscv@lists.infradead.org, Will Deacon , Ingo Molnar , "Chang, Abner \(HPS SW/FW Technologist\)" , Michal Simek , Mike Rapoport , Greentime Hu , Borislav Petkov , Mao Han , daniel.schaefer@hpe.com, Albert Ou , Kees Cook , Arnd Bergmann , Alexios Zavras , Alexander Graf , Paul Walmsley , Thomas Gleixner , Allison Randal , "leif@nuviainc.com" , Greg Kroah-Hartman , Anup Patel , Palmer Dabbelt , Paolo Bonzini , Andrew Morton Sender: "linux-riscv" Errors-To: linux-riscv-bounces+patchwork-linux-riscv=patchwork.kernel.org@lists.infradead.org Most of the arm-stub code is written in an architecture independent manner. As a result, RISC-V can reuse most of the arm-stub code. Rename the arm-stub.c to efi-stub.c so that ARM, ARM64 and RISC-V can use it. This patch doesn't introduce any functional changes. Signed-off-by: Atish Patra --- arch/arm/Kconfig | 2 +- arch/arm64/Kconfig | 2 +- drivers/firmware/efi/Kconfig | 4 ++-- drivers/firmware/efi/libstub/Makefile | 12 ++++++------ .../firmware/efi/libstub/{arm-stub.c => efi-stub.c} | 0 5 files changed, 10 insertions(+), 10 deletions(-) rename drivers/firmware/efi/libstub/{arm-stub.c => efi-stub.c} (100%) diff --git a/arch/arm/Kconfig b/arch/arm/Kconfig index 97864aabc2a6..cccb9df48055 100644 --- a/arch/arm/Kconfig +++ b/arch/arm/Kconfig @@ -1955,7 +1955,7 @@ config EFI select UCS2_STRING select EFI_PARAMS_FROM_FDT select EFI_STUB - select EFI_ARMSTUB + select EFI_GENERIC_STUB select EFI_RUNTIME_WRAPPERS ---help--- This option provides support for runtime services provided diff --git a/arch/arm64/Kconfig b/arch/arm64/Kconfig index 0b30e884e088..edf955832e55 100644 --- a/arch/arm64/Kconfig +++ b/arch/arm64/Kconfig @@ -1720,7 +1720,7 @@ config EFI select EFI_PARAMS_FROM_FDT select EFI_RUNTIME_WRAPPERS select EFI_STUB - select EFI_ARMSTUB + select EFI_GENERIC_STUB default y help This option provides support for runtime services provided diff --git a/drivers/firmware/efi/Kconfig b/drivers/firmware/efi/Kconfig index ecc83e2f032c..708fe86cc66d 100644 --- a/drivers/firmware/efi/Kconfig +++ b/drivers/firmware/efi/Kconfig @@ -106,12 +106,12 @@ config EFI_PARAMS_FROM_FDT config EFI_RUNTIME_WRAPPERS bool -config EFI_ARMSTUB +config EFI_GENERIC_STUB bool config EFI_ARMSTUB_DTB_LOADER bool "Enable the DTB loader" - depends on EFI_ARMSTUB + depends on EFI_GENERIC_STUB default y help Select this config option to add support for the dtb= command diff --git a/drivers/firmware/efi/libstub/Makefile b/drivers/firmware/efi/libstub/Makefile index 4d6246c6f651..f1d7de1e0d87 100644 --- a/drivers/firmware/efi/libstub/Makefile +++ b/drivers/firmware/efi/libstub/Makefile @@ -22,7 +22,7 @@ cflags-$(CONFIG_ARM) := $(subst $(CC_FLAGS_FTRACE),,$(KBUILD_CFLAGS)) \ -fno-builtin -fpic \ $(call cc-option,-mno-single-pic-base) -cflags-$(CONFIG_EFI_ARMSTUB) += -I$(srctree)/scripts/dtc/libfdt +cflags-$(CONFIG_EFI_GENERIC_STUB) += -I$(srctree)/scripts/dtc/libfdt KBUILD_CFLAGS := $(cflags-y) -DDISABLE_BRANCH_PROFILING \ -include $(srctree)/drivers/firmware/efi/libstub/hidden.h \ @@ -44,13 +44,13 @@ lib-y := efi-stub-helper.o gop.o secureboot.o tpm.o \ skip_spaces.o lib-cmdline.o lib-ctype.o # include the stub's generic dependencies from lib/ when building for ARM/arm64 -arm-deps-y := fdt_rw.c fdt_ro.c fdt_wip.c fdt.c fdt_empty_tree.c fdt_sw.c +efi-deps-y := fdt_rw.c fdt_ro.c fdt_wip.c fdt.c fdt_empty_tree.c fdt_sw.c $(obj)/lib-%.o: $(srctree)/lib/%.c FORCE $(call if_changed_rule,cc_o_c) -lib-$(CONFIG_EFI_ARMSTUB) += arm-stub.o fdt.o string.o \ - $(patsubst %.c,lib-%.o,$(arm-deps-y)) +lib-$(CONFIG_EFI_GENERIC_STUB) += efi-stub.o fdt.o string.o \ + $(patsubst %.c,lib-%.o,$(efi-deps-y)) lib-$(CONFIG_ARM) += arm32-stub.o lib-$(CONFIG_ARM64) += arm64-stub.o @@ -72,8 +72,8 @@ CFLAGS_arm64-stub.o := -DTEXT_OFFSET=$(TEXT_OFFSET) # a verification pass to see if any absolute relocations exist in any of the # object files. # -extra-$(CONFIG_EFI_ARMSTUB) := $(lib-y) -lib-$(CONFIG_EFI_ARMSTUB) := $(patsubst %.o,%.stub.o,$(lib-y)) +extra-$(CONFIG_EFI_GENERIC_STUB) := $(lib-y) +lib-$(CONFIG_EFI_GENERIC_STUB) := $(patsubst %.o,%.stub.o,$(lib-y)) STUBCOPY_FLAGS-$(CONFIG_ARM64) += --prefix-alloc-sections=.init \ --prefix-symbols=__efistub_ diff --git a/drivers/firmware/efi/libstub/arm-stub.c b/drivers/firmware/efi/libstub/efi-stub.c similarity index 100% rename from drivers/firmware/efi/libstub/arm-stub.c rename to drivers/firmware/efi/libstub/efi-stub.c From patchwork Thu Feb 27 22:26:41 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Atish Patra X-Patchwork-Id: 11411011 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 1AB62159A for ; Thu, 27 Feb 2020 22:27:04 +0000 (UTC) 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 mail.kernel.org (Postfix) with ESMTPS id EC8F8246A2 for ; Thu, 27 Feb 2020 22:27:03 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="AGcsPkeC"; dkim=fail reason="signature verification failed" (2048-bit key) header.d=wdc.com header.i=@wdc.com header.b="IynFGIMq" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org EC8F8246A2 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=wdc.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-riscv-bounces+patchwork-linux-riscv=patchwork.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id: Content-Transfer-Encoding:MIME-Version:References:In-Reply-To:Message-Id:Date :Subject:To:From:Reply-To:Content-Type:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=goyVmJe+J57iQdmkUJbsbckf52hUGMFdwPN6KGpPCvA=; b=AGcsPkeCAnvGbk ZbK3zQNJbAK0MCmh67kvHC2uEkR+FNB0jXqh+S2IHOGOEVcwEKHlIPJxG+FJjFI2dptikepcvvOAD s4n1Iav3rlMaRrBmuyVVom5BGVZ3SC1JU/vvbaPrqybfrWJlEyJpgbGqLhHnbNTkd8AOGEm0helHX WNcsoOcivpyYE20IGNBbM8FIVxEg5kHY3lJQrilJnL6fWr7GnShoFZ3eR9xGzMnvn8lbyLKxry15V mUzggcmK+Bm57P4lzhEP7yb+ylyDvtpIolH1mJderGF9CASyAn09qdO4puva6LkzPzv8htC8IBQg8 Co86EbAZXeQGnYpI4ToA==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1j7RcS-0000ai-Hw; Thu, 27 Feb 2020 22:27:00 +0000 Received: from esa6.hgst.iphmx.com ([216.71.154.45]) by bombadil.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1j7RcP-0000Xr-14 for linux-riscv@lists.infradead.org; Thu, 27 Feb 2020 22:26:58 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1582842417; x=1614378417; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=qT9c7eXt7ksLkS8LTzuMlCHOyGGyAUacpIVqI65fctQ=; b=IynFGIMqPAU2L4caSr9K58mQup8xcAN9M8uuIHlXb3mjYvsz5KtOqnXM WQI98tEvWCybuMxehVu4+tc6YTlf3tcbBRKt0z1r6lmK0o5K00Ne3guoY JaJ35hhG9dchvp32sJAH7kvfDuoI0aG7+rBMzI8pWRPlZQxCQPfoTmANW 3XHRbf8E6y6Q4B7dBc75Wx6RogfsagScIauYg6MMeTTP5Jmak2u0b9sxn UWeblAgPiKOlS4asjwn6bEkLz18cVbwAUlkAE9ld0zDOqKBjLwknKju1X xXpcFGlCEfh4TzWuGQScIsRnzYTeQoh0C5hGclKTNMfxECKKqM2UyJdMg w==; IronPort-SDR: 5bEJ/BrdG5OnfEpaC+k+99ybH/va+QLPryKR1eaTjxgT9L220aoRS8xEH+hdr1sdKhDwS9Nxdi 4TTHqh8V/wL8NfKq51kYTq9zZaZ9+2q1D6nWhmePfMMRBV6XTewTLnlFUsCk0jGlBQhkOsXU7y pvqlHy9sIfxI1xr7520qTCyFQPrAJwvuhsm+UzuylZuxB9E4sxjWEFxVlAfF+d9eHrAJLKa/go I1PUVzrWiV4AUKvT8eemsbu7OeaZDTlRIuhfcbdFCKeSsCO07kAqExx40rrS28t6IGpHIkDY2T up8= X-IronPort-AV: E=Sophos;i="5.70,493,1574092800"; d="scan'208";a="132395344" Received: from uls-op-cesaip02.wdc.com (HELO uls-op-cesaep02.wdc.com) ([199.255.45.15]) by ob1.hgst.iphmx.com with ESMTP; 28 Feb 2020 06:26:51 +0800 IronPort-SDR: i5+69ZSe4jUWAIl2ZdfCDEkusFzz2OUQ7J5XYrRMOnQ+4+D1sKmTcZeqB6mKCj2wsfBh5YhPQp njCdoa1+tEgUhfK5c5yvOd2OPSMO7YhE/CLU2HvtadSVpH+Te/Y4wF2B2Yokn1UNcnZpcZCk7v KGstq38aQm6Twg5A6igbFY4KJswgA2/du8zpfxgCMulwmoBeeAt2F3WTY3PyCrSHmMCVpr7TSk zWTIspc5xSPaiyaePNk/g1b6o9tswlQMJBUU7TDTObRHRuXspibq9d80UR9+beXqFiyBh3zy9F 0WPH2QNKyDEdT7eeDcBy8EsN Received: from uls-op-cesaip02.wdc.com ([10.248.3.37]) by uls-op-cesaep02.wdc.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 27 Feb 2020 14:18:50 -0800 IronPort-SDR: Xlu5k3vIok+8Q2sXn3fXcSfzEcT3N+zeXLWP2I3gx6u97u9rC/m5SLI7thhq3D5E0zFJuFq/wd 3X9QzHoTqJ5RKs07wtgL/FfdFEFvqdMRi0tGoLhBNaW3IYXhg5hAa1+13rc9YJ8N+H+L/9ag72 0y429qordRATXOLpQkiVvOfnX4a9cV4wRXhng58/8qRwTjqlqegwFn1P0wtku1IlXlcfbCkQht c5kr6PGJOFNqFVi/FL8f0le4x6oJwiK9WWVnpd7CAquJl7BPVtZoYiKMmpTkVd5dKzdkzfpWUy lQk= WDCIronportException: Internal Received: from jedi-01.sdcorp.global.sandisk.com (HELO jedi-01.int.fusionio.com) ([10.11.143.218]) by uls-op-cesaip02.wdc.com with ESMTP; 27 Feb 2020 14:26:50 -0800 From: Atish Patra To: linux-kernel@vger.kernel.org Subject: [v1 PATCH 2/5] include: pe.h: Add RISC-V related PE definition Date: Thu, 27 Feb 2020 14:26:41 -0800 Message-Id: <20200227222644.9468-3-atish.patra@wdc.com> X-Mailer: git-send-email 2.24.0 In-Reply-To: <20200227222644.9468-1-atish.patra@wdc.com> References: <20200227222644.9468-1-atish.patra@wdc.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20200227_142657_113929_111C4875 X-CRM114-Status: GOOD ( 10.52 ) X-Spam-Score: -2.5 (--) X-Spam-Report: SpamAssassin version 3.4.3 on bombadil.infradead.org summary: Content analysis details: (-2.5 points) pts rule name description ---- ---------------------- -------------------------------------------------- -2.3 RCVD_IN_DNSWL_MED RBL: Sender listed at https://www.dnswl.org/, medium trust [216.71.154.45 listed in list.dnswl.org] 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record -0.0 SPF_PASS SPF: sender matches SPF record -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid X-BeenThere: linux-riscv@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kate Stewart , linux-efi@vger.kernel.org, Ard Biesheuvel , Catalin Marinas , Linus Walleij , Russell King , Atish Patra , Mauro Carvalho Chehab , linux-riscv@lists.infradead.org, Will Deacon , Ingo Molnar , "Chang, Abner \(HPS SW/FW Technologist\)" , Michal Simek , Mike Rapoport , Greentime Hu , Borislav Petkov , Mao Han , daniel.schaefer@hpe.com, Albert Ou , Kees Cook , Arnd Bergmann , Alexios Zavras , Alexander Graf , Paul Walmsley , Thomas Gleixner , Allison Randal , "leif@nuviainc.com" , Greg Kroah-Hartman , Anup Patel , Palmer Dabbelt , Paolo Bonzini , Andrew Morton Sender: "linux-riscv" Errors-To: linux-riscv-bounces+patchwork-linux-riscv=patchwork.kernel.org@lists.infradead.org Define RISC-V related machine types. Signed-off-by: Atish Patra Reviewed-by: Ard Biesheuvel --- include/linux/pe.h | 3 +++ 1 file changed, 3 insertions(+) diff --git a/include/linux/pe.h b/include/linux/pe.h index 8ad71d763a77..daf09ffffe38 100644 --- a/include/linux/pe.h +++ b/include/linux/pe.h @@ -55,6 +55,9 @@ #define IMAGE_FILE_MACHINE_POWERPC 0x01f0 #define IMAGE_FILE_MACHINE_POWERPCFP 0x01f1 #define IMAGE_FILE_MACHINE_R4000 0x0166 +#define IMAGE_FILE_MACHINE_RISCV32 0x5032 +#define IMAGE_FILE_MACHINE_RISCV64 0x5064 +#define IMAGE_FILE_MACHINE_RISCV128 0x5128 #define IMAGE_FILE_MACHINE_SH3 0x01a2 #define IMAGE_FILE_MACHINE_SH3DSP 0x01a3 #define IMAGE_FILE_MACHINE_SH3E 0x01a4 From patchwork Thu Feb 27 22:26:42 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Atish Patra X-Patchwork-Id: 11411015 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 3F3031871 for ; Thu, 27 Feb 2020 22:27:10 +0000 (UTC) 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 mail.kernel.org (Postfix) with ESMTPS id 1D0A2246A2 for ; Thu, 27 Feb 2020 22:27:10 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="CNY8tgpQ"; dkim=fail reason="signature verification failed" (2048-bit key) header.d=wdc.com header.i=@wdc.com header.b="fcoClOgL" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 1D0A2246A2 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=wdc.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-riscv-bounces+patchwork-linux-riscv=patchwork.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id: Content-Transfer-Encoding:MIME-Version:References:In-Reply-To:Message-Id:Date :Subject:To:From:Reply-To:Content-Type:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=sS1zZ4MwtCqm9iYiwROtnVTjPMx9muysW3lROcK3bh4=; b=CNY8tgpQ9X6QAX oyZ3sPPxBPEtluSmJh8mcVyYRCXJcOjAYoJtwbTQgVbJTPB82ZmtEjUmZOHJ8PNw5l+BJG/CvIpnh 6zkiCA0oUj158s2VmcLz3pLEiaaxampbkxJqL8UxN919/1nC65jcwxEZEO0gxZqZ0r9nhXQGoo2jH dD5ddgp5P9TB8cdZgRacznUHcu5VizGf/QbbYwHxyy7ds3/mgQCCdTBEEakkVqWpdoJd/fkXFXmau ZNy682LUl8+DxUruy6/VXQd7MmfViSIcf8v0ityTn5oVBbhdfhSt+rpgRtCk6XTwAxTVo28GX0pGA KqrK+DZW3QHEZndOYVMQ==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1j7RcY-0000i1-4D; Thu, 27 Feb 2020 22:27:06 +0000 Received: from esa6.hgst.iphmx.com ([216.71.154.45]) by bombadil.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1j7RcQ-0000Xr-EP for linux-riscv@lists.infradead.org; Thu, 27 Feb 2020 22:26:59 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1582842419; x=1614378419; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=EHUEM7B8bQdVUOO+XqChXw4fxBDln7t5tGAkDnrQZUI=; b=fcoClOgL8vmNcmD4+LHb2jtuczSB/2tAxf1R5ioIZz4x4dHmmIGr8lcy 1r6xQSfU4PC7DYBVU2GxWcLFuXmPpKzkacXht3JdHMQT0HhOEClGIrxiD OEmj7kZ25SmLgi9yAFBeIwRyy2I/EOVYt+A+E/9fVW5E7sSuhrMGQhm8x 576absiYASdzW5e9zFx+QDvm5msSdyq/bxrP6ftR5dHADA6I54Kd/GKGS akLOplXYHjD5OtjFZu5jTwFqIOwVJKAL60tcfudrsyPkdIdOk7dZuexHu 8mX1GSa/b0OwPbDvoBfDqIHq+DImusknU0AUxmAmk0lZRSQsqZoxsCo2S A==; IronPort-SDR: wLDL8UsqploJgP9TMhuXVLqVr1YGBQ2op4aIryXTbKGlqMZr//iVOtn4AqsP0qa/QpAvlXyDw1 FkuyG4ozUOTPQu1PBKum2HTHI8uC01wBL69qWUS7iFW736lGv3OJwwuesk2Mw8HPjcuG+yzuyb AdAoEU8Rzib95MSyGVkXxi3bwE8qc5i/0hKsZyfHDDhjMTp3+cYtUKdv+/Kn2mttuF5ZHwLLsd I0kxXM5jaAE5n6SGnl4eYGnK6/m5KffgZLV+uMGzlFC5nrUPM94LXSzWMgLARcc2cY2jOQr7c4 jus= X-IronPort-AV: E=Sophos;i="5.70,493,1574092800"; d="scan'208";a="132395349" Received: from uls-op-cesaip02.wdc.com (HELO uls-op-cesaep02.wdc.com) ([199.255.45.15]) by ob1.hgst.iphmx.com with ESMTP; 28 Feb 2020 06:26:51 +0800 IronPort-SDR: sGBlDKi9mYn4ZJcPxUTylnmVruKAKquDF+yReAh+nfbsit9x67O5w9Wn+VQbC79z9MwDiLR50W eUKUC7vQsKnsWUva2ifssacSh0CaFfSrzCsKHsexW9Gq/WeEVaxesh03gVaaVZ2PH972LfZMW6 /LQQOXjpIiT7Ujfh69z5+wrxCgfxqcN6jaayfFaguyBP4sjm5roVqrLIcUJq13S+3KBoDXzOEx EWkh0jE7nESEoIgAZ4obPpgfOm2Q+h5za25kk1N4IR4dOVw/tY9ptdXwj/1pKHQrEHXAspWTEe L1DlzQkyc8VPAF2AhSXjxU1y Received: from uls-op-cesaip02.wdc.com ([10.248.3.37]) by uls-op-cesaep02.wdc.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 27 Feb 2020 14:18:50 -0800 IronPort-SDR: YD6YeGhFTlMMzdBLGRQBddTkJ6fAkSTBalLAPGagkJGff3jvnk7ShMgdkHvtKi9lHv93MiTJbP FV0+/TE0pxagvgx828IfHnvvjOqvC2T8v+6Ty+CgZmCQXQSyiDRddCYok6zWKkRmESGV4x2Fw9 mKVzPNX0rl/ZGJ1gk3abMm6UWic9LMlHkU0O7g25BCdLp9h4g/687VuCmXgx+ZO+Jn1OMi9Fr3 zVwGYMMJ7kONZzI2JEyWWz0rQ6T787ZP9WDvADtR0PbT3QYUvWWcCI9gCmCRK3g2X/LVCoiIV1 ulE= WDCIronportException: Internal Received: from jedi-01.sdcorp.global.sandisk.com (HELO jedi-01.int.fusionio.com) ([10.11.143.218]) by uls-op-cesaip02.wdc.com with ESMTP; 27 Feb 2020 14:26:50 -0800 From: Atish Patra To: linux-kernel@vger.kernel.org Subject: [v1 PATCH 3/5] RISC-V: Define fixmap bindings for generic early ioremap support Date: Thu, 27 Feb 2020 14:26:42 -0800 Message-Id: <20200227222644.9468-4-atish.patra@wdc.com> X-Mailer: git-send-email 2.24.0 In-Reply-To: <20200227222644.9468-1-atish.patra@wdc.com> References: <20200227222644.9468-1-atish.patra@wdc.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20200227_142658_531871_DB38A6DE X-CRM114-Status: GOOD ( 15.19 ) X-Spam-Score: -2.5 (--) X-Spam-Report: SpamAssassin version 3.4.3 on bombadil.infradead.org summary: Content analysis details: (-2.5 points) pts rule name description ---- ---------------------- -------------------------------------------------- -2.3 RCVD_IN_DNSWL_MED RBL: Sender listed at https://www.dnswl.org/, medium trust [216.71.154.45 listed in list.dnswl.org] 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record -0.0 SPF_PASS SPF: sender matches SPF record -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid X-BeenThere: linux-riscv@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kate Stewart , linux-efi@vger.kernel.org, Ard Biesheuvel , Catalin Marinas , Linus Walleij , Russell King , Atish Patra , Mauro Carvalho Chehab , linux-riscv@lists.infradead.org, Will Deacon , Ingo Molnar , "Chang, Abner \(HPS SW/FW Technologist\)" , Michal Simek , Mike Rapoport , Greentime Hu , Borislav Petkov , Mao Han , daniel.schaefer@hpe.com, Albert Ou , Kees Cook , Arnd Bergmann , Alexios Zavras , Alexander Graf , Paul Walmsley , Thomas Gleixner , Allison Randal , "leif@nuviainc.com" , Greg Kroah-Hartman , Anup Patel , Palmer Dabbelt , Paolo Bonzini , Andrew Morton Sender: "linux-riscv" Errors-To: linux-riscv-bounces+patchwork-linux-riscv=patchwork.kernel.org@lists.infradead.org UEFI uses early IO or memory mappings for runtime services before normal ioremap() is usable. This patch only adds minimum necessary fixmap bindings and headers for generic ioremap support to work. Signed-off-by: Atish Patra Acked-by: Ard Biesheuvel --- arch/riscv/Kconfig | 1 + arch/riscv/include/asm/Kbuild | 1 + arch/riscv/include/asm/fixmap.h | 21 ++++++++++++++++++++- arch/riscv/include/asm/io.h | 1 + 4 files changed, 23 insertions(+), 1 deletion(-) diff --git a/arch/riscv/Kconfig b/arch/riscv/Kconfig index 27bfc7947e44..42c122170cfd 100644 --- a/arch/riscv/Kconfig +++ b/arch/riscv/Kconfig @@ -65,6 +65,7 @@ config RISCV select ARCH_HAS_GCOV_PROFILE_ALL select HAVE_COPY_THREAD_TLS select HAVE_ARCH_KASAN if MMU && 64BIT + select GENERIC_EARLY_IOREMAP config ARCH_MMAP_RND_BITS_MIN default 18 if 64BIT diff --git a/arch/riscv/include/asm/Kbuild b/arch/riscv/include/asm/Kbuild index ec0ca8c6ab64..517394390106 100644 --- a/arch/riscv/include/asm/Kbuild +++ b/arch/riscv/include/asm/Kbuild @@ -4,6 +4,7 @@ generic-y += checksum.h generic-y += compat.h generic-y += device.h generic-y += div64.h +generic-y += early_ioremap.h generic-y += extable.h generic-y += flat.h generic-y += dma.h diff --git a/arch/riscv/include/asm/fixmap.h b/arch/riscv/include/asm/fixmap.h index 42d2c42f3cc9..7a4beb7e29a3 100644 --- a/arch/riscv/include/asm/fixmap.h +++ b/arch/riscv/include/asm/fixmap.h @@ -25,9 +25,28 @@ enum fixed_addresses { #define FIX_FDT_SIZE SZ_1M FIX_FDT_END, FIX_FDT = FIX_FDT_END + FIX_FDT_SIZE / PAGE_SIZE - 1, + FIX_EARLYCON_MEM_BASE, + FIX_PTE, FIX_PMD, - FIX_EARLYCON_MEM_BASE, + /* + * Make sure that it is 2MB aligned. + */ +#define NR_FIX_SZ_2M (SZ_2M / PAGE_SIZE) + FIX_THOLE = NR_FIX_SZ_2M - FIX_PMD - 1, + + __end_of_permanent_fixed_addresses, + /* + * Temporary boot-time mappings, used by early_ioremap(), + * before ioremap() is functional. + */ +#define NR_FIX_BTMAPS (SZ_256K / PAGE_SIZE) +#define FIX_BTMAPS_SLOTS 7 +#define TOTAL_FIX_BTMAPS (NR_FIX_BTMAPS * FIX_BTMAPS_SLOTS) + + FIX_BTMAP_END = __end_of_permanent_fixed_addresses, + FIX_BTMAP_BEGIN = FIX_BTMAP_END + TOTAL_FIX_BTMAPS - 1, + __end_of_fixed_addresses }; diff --git a/arch/riscv/include/asm/io.h b/arch/riscv/include/asm/io.h index 0f477206a4ed..047f414b6948 100644 --- a/arch/riscv/include/asm/io.h +++ b/arch/riscv/include/asm/io.h @@ -14,6 +14,7 @@ #include #include #include +#include /* * MMIO access functions are separated out to break dependency cycles From patchwork Thu Feb 27 22:26:43 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Atish Patra X-Patchwork-Id: 11411017 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id DEDFC17E0 for ; Thu, 27 Feb 2020 22:27:11 +0000 (UTC) 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 mail.kernel.org (Postfix) with ESMTPS id B6663246A2 for ; Thu, 27 Feb 2020 22:27:11 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="SpSOTVvs"; dkim=fail reason="signature verification failed" (2048-bit key) header.d=wdc.com header.i=@wdc.com header.b="j8LFku++" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org B6663246A2 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=wdc.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-riscv-bounces+patchwork-linux-riscv=patchwork.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id: Content-Transfer-Encoding:MIME-Version:References:In-Reply-To:Message-Id:Date :Subject:To:From:Reply-To:Content-Type:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=/eqLGRgpLO8JwffrByDWZdFeaqwBYoUK0KZfebKO4qk=; b=SpSOTVvslQOIyw gHVP6SkkKHMhAd+PmjFsX2ki3TF8hsIh+Lu4qo6ZntjtiTqPh7X1/e/v8eOY6mfwpcXBzp8MzLMWY a2/CMsccII8W+jIxgzpfZUf0SECocUs/1565rtxBUWew5H0fi0+aV497SeKo5GbQUrmC6rGs8Xq05 zaVmes9zC6XWBcx0WMxbE24MjSb1sranciXVT2EOe/oewzsD7E3cfzfamPHrBIUENp0k4kEEQ/g2u Bx2xdfoqMUjofIGu+NfgDhIrsxyzvyrqoIYMRr+ANllWiP/0iAyL/A3smIh/WWchb8mVmVQFtZnXX muae3hmRl/jUWbIZjlIQ==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1j7RcZ-0000ky-W2; Thu, 27 Feb 2020 22:27:08 +0000 Received: from esa6.hgst.iphmx.com ([216.71.154.45]) by bombadil.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1j7RcQ-0000Wn-JB for linux-riscv@lists.infradead.org; Thu, 27 Feb 2020 22:27:00 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1582842419; x=1614378419; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=PpzpK1MVif1xfIaQgnJ+kAB5ixaUH4Z0cn+lB5dDc0I=; b=j8LFku++3PQt4A8A80Mr6OHWugceoMiEYkgF8P7eD4KfpUK8HLoPFmyI BUtd2IBVba7h3+rFHb3xxOzozKuixRhjbDNQYSRjxeJLEwNyBGAo/+t+R EJ882M+cKPYYw04V9/ggeA+jI+EvgVgwH+utXvOXRCzo27Ksp87Z9pApG IOqHXttXQ0ugDWdx7ip48HEZwaxq+zatEIlGfMLOuQLt9xO2+tc5Ihsjb ERUJpDSkhWZu7U05juZMs3ZbKcmaXRi3w5srV9YJGc2VXZyAyrxeM/1fF 52s8r5pMf2vBuU5j07IymtZ39XJz+IOg/tXRwFIxx9rxQrZRlL0spoNw+ Q==; IronPort-SDR: U46EeVCFoYL+i6Tb+m+zzMkhsQWyW2wml9+8HJQXkyCHLAPzsT1ve8RRAZlfWOBzGI49TpKtOv NLIQibeAzcO9an2xwdkIye7KKLxFPlO6gL7vTL0BtV6VeQb5V7SqPJaR+RlOvB/HOIH++bBHzb 2q4Oc1Adc3wSUFQSLxCooj8Xwoafwlydn5vwXcSEEgDL/kvIUyHKxzgtdAE5w4lLrTYwzNMhyK 8umP2SeIFIXFIwLkN33B0YZ6ph8aVB34YHMhaILsyU1iOWrfolIIji/fwg6WuGnTMS/aTmMKKs 49E= X-IronPort-AV: E=Sophos;i="5.70,493,1574092800"; d="scan'208";a="132395351" Received: from uls-op-cesaip02.wdc.com (HELO uls-op-cesaep02.wdc.com) ([199.255.45.15]) by ob1.hgst.iphmx.com with ESMTP; 28 Feb 2020 06:26:52 +0800 IronPort-SDR: 6b62Pp246LktNv/gPythsVTa0biQYxrQi4A3may4xh7go10JrAiOzOCgVa5hS4cn0Uha8x7OC/ W9sDYVneCAgTmwv3TY1NsfocdRZducpz4RQhWM9zX5IgMo/A/Zg79BWehMwc6wufbr7soXmVVK 5MtOQjcahcqRt887ddg69BQKiv75hK7DWYDZREjIzgKA0nHw80fql+aVAzbRt5q18lWk0uN1BC L5Vn2uTxxZ1XasfpChofEIu78fo0plM4DuwLPgLh4qTIDPedO/2j1o0IOb7rTfaFs0VVWIdzw2 FmBoT8O9N+C6P2JXCNReUs1F Received: from uls-op-cesaip02.wdc.com ([10.248.3.37]) by uls-op-cesaep02.wdc.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 27 Feb 2020 14:18:51 -0800 IronPort-SDR: yI1YmpcZEO1nm4t58Elbub0Rx7hhTidPkVtdmm3W2lzGLdbrjJxOSZTts0SE5tGEhLfcQu1/WE uADZj8WGD/Ag+ND0X183JQy9XFvL8VO9oQWXufUuX5+EeyYssfD6icZoiwZdmLN8VxNkKSulV1 U3x3fPC0pcMM0ZNYYmeUNrAFc9+xdEdxUxv/A0ePhDwg8YbwKsNYf7doZIKfCXEtKKPENFEUU5 QQU92r/eW1+VX1yOcFgBDBQ/AZe37NaStP5H8Dw6HM06/QCEo5hgNIefDBO02u5BcmBSsF5Xas aaA= WDCIronportException: Internal Received: from jedi-01.sdcorp.global.sandisk.com (HELO jedi-01.int.fusionio.com) ([10.11.143.218]) by uls-op-cesaip02.wdc.com with ESMTP; 27 Feb 2020 14:26:51 -0800 From: Atish Patra To: linux-kernel@vger.kernel.org Subject: [v1 PATCH 4/5] RISC-V: Add PE/COFF header for EFI stub Date: Thu, 27 Feb 2020 14:26:43 -0800 Message-Id: <20200227222644.9468-5-atish.patra@wdc.com> X-Mailer: git-send-email 2.24.0 In-Reply-To: <20200227222644.9468-1-atish.patra@wdc.com> References: <20200227222644.9468-1-atish.patra@wdc.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20200227_142658_724803_AC7F1AB8 X-CRM114-Status: GOOD ( 24.20 ) X-Spam-Score: -2.5 (--) X-Spam-Report: SpamAssassin version 3.4.3 on bombadil.infradead.org summary: Content analysis details: (-2.5 points) pts rule name description ---- ---------------------- -------------------------------------------------- -2.3 RCVD_IN_DNSWL_MED RBL: Sender listed at https://www.dnswl.org/, medium trust [216.71.154.45 listed in list.dnswl.org] 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record -0.0 SPF_PASS SPF: sender matches SPF record -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid X-BeenThere: linux-riscv@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kate Stewart , linux-efi@vger.kernel.org, Ard Biesheuvel , Catalin Marinas , Linus Walleij , Russell King , Atish Patra , Mauro Carvalho Chehab , linux-riscv@lists.infradead.org, Will Deacon , Ingo Molnar , "Chang, Abner \(HPS SW/FW Technologist\)" , Michal Simek , Mike Rapoport , Greentime Hu , Borislav Petkov , Mao Han , daniel.schaefer@hpe.com, Albert Ou , Kees Cook , Arnd Bergmann , Alexios Zavras , Alexander Graf , Paul Walmsley , Thomas Gleixner , Allison Randal , "leif@nuviainc.com" , Greg Kroah-Hartman , Anup Patel , Palmer Dabbelt , Paolo Bonzini , Andrew Morton Sender: "linux-riscv" Errors-To: linux-riscv-bounces+patchwork-linux-riscv=patchwork.kernel.org@lists.infradead.org Linux kernel Image can appear as an EFI application With appropriate PE/COFF header fields in the beginning of the Image header. An EFI application loader can directly load a Linux kernel Image and an EFI stub residing in kernel can boot Linux kernel directly. Add the necessary PE/COFF header. Signed-off-by: Atish Patra --- arch/riscv/include/asm/Kbuild | 1 - arch/riscv/include/asm/sections.h | 13 ++++ arch/riscv/kernel/Makefile | 4 ++ arch/riscv/kernel/efi-header.S | 99 +++++++++++++++++++++++++++++++ arch/riscv/kernel/head.S | 16 +++++ arch/riscv/kernel/image-vars.h | 53 +++++++++++++++++ arch/riscv/kernel/vmlinux.lds.S | 27 +++++++-- 7 files changed, 206 insertions(+), 7 deletions(-) create mode 100644 arch/riscv/include/asm/sections.h create mode 100644 arch/riscv/kernel/efi-header.S create mode 100644 arch/riscv/kernel/image-vars.h diff --git a/arch/riscv/include/asm/Kbuild b/arch/riscv/include/asm/Kbuild index 517394390106..ef797fe44934 100644 --- a/arch/riscv/include/asm/Kbuild +++ b/arch/riscv/include/asm/Kbuild @@ -24,7 +24,6 @@ generic-y += local64.h generic-y += mm-arch-hooks.h generic-y += percpu.h generic-y += preempt.h -generic-y += sections.h generic-y += serial.h generic-y += shmparam.h generic-y += topology.h diff --git a/arch/riscv/include/asm/sections.h b/arch/riscv/include/asm/sections.h new file mode 100644 index 000000000000..3a9971b1210f --- /dev/null +++ b/arch/riscv/include/asm/sections.h @@ -0,0 +1,13 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +/* + * Copyright (C) 2020 Western Digital Corporation or its affiliates. + */ +#ifndef __ASM_SECTIONS_H +#define __ASM_SECTIONS_H + +#include + +extern char _start[]; +extern char _start_kernel[]; + +#endif /* __ASM_SECTIONS_H */ diff --git a/arch/riscv/kernel/Makefile b/arch/riscv/kernel/Makefile index 9601ac907f70..471b1c73f77d 100644 --- a/arch/riscv/kernel/Makefile +++ b/arch/riscv/kernel/Makefile @@ -29,6 +29,10 @@ obj-y += cacheinfo.o obj-$(CONFIG_MMU) += vdso.o vdso/ obj-$(CONFIG_RISCV_M_MODE) += clint.o +OBJCOPYFLAGS := --prefix-symbols=__efistub_ +$(obj)/%.stub.o: $(obj)/%.o FORCE + $(call if_changed,objcopy) + obj-$(CONFIG_FPU) += fpu.o obj-$(CONFIG_SMP) += smpboot.o obj-$(CONFIG_SMP) += smp.o diff --git a/arch/riscv/kernel/efi-header.S b/arch/riscv/kernel/efi-header.S new file mode 100644 index 000000000000..69dde8268527 --- /dev/null +++ b/arch/riscv/kernel/efi-header.S @@ -0,0 +1,99 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +/* + * Copyright (C) 2020 Western Digital Corporation or its affiliates. + * Adapted from arch/arm64/kernel/efi-header.S + */ + +#include +#include + + .macro __EFI_PE_HEADER + .long PE_MAGIC +coff_header: + .short IMAGE_FILE_MACHINE_RISCV64 // Machine + .short section_count // NumberOfSections + .long 0 // TimeDateStamp + .long 0 // PointerToSymbolTable + .long 0 // NumberOfSymbols + .short section_table - optional_header // SizeOfOptionalHeader + .short IMAGE_FILE_DEBUG_STRIPPED | \ + IMAGE_FILE_EXECUTABLE_IMAGE | \ + IMAGE_FILE_LINE_NUMS_STRIPPED // Characteristics + +optional_header: + .short PE_OPT_MAGIC_PE32PLUS // PE32+ format + .byte 0x02 // MajorLinkerVersion + .byte 0x14 // MinorLinkerVersion + .long __text_end - efi_header_end // SizeOfCode + .long _end - __text_end // SizeOfInitializedData + .long 0 // SizeOfUninitializedData + .long __efistub_efi_entry - _start // AddressOfEntryPoint + .long efi_header_end - _start // BaseOfCode + +extra_header_fields: + .quad 0 // ImageBase + .long SZ_4K // SectionAlignment + .long PECOFF_FILE_ALIGNMENT // FileAlignment + .short 0 // MajorOperatingSystemVersion + .short 0 // MinorOperatingSystemVersion + .short LINUX_EFISTUB_MAJOR_VERSION // MajorImageVersion + .short LINUX_EFISTUB_MINOR_VERSION // MinorImageVersion + .short 0 // MajorSubsystemVersion + .short 0 // MinorSubsystemVersion + .long 0 // Win32VersionValue + + .long _end - _start // SizeOfImage + + // Everything before the kernel image is considered part of the header + .long efi_header_end - _start // SizeOfHeaders + .long 0 // CheckSum + .short IMAGE_SUBSYSTEM_EFI_APPLICATION // Subsystem + .short 0 // DllCharacteristics + .quad 0 // SizeOfStackReserve + .quad 0 // SizeOfStackCommit + .quad 0 // SizeOfHeapReserve + .quad 0 // SizeOfHeapCommit + .long 0 // LoaderFlags + .long (section_table - .) / 8 // NumberOfRvaAndSizes + + .quad 0 // ExportTable + .quad 0 // ImportTable + .quad 0 // ResourceTable + .quad 0 // ExceptionTable + .quad 0 // CertificationTable + .quad 0 // BaseRelocationTable + + // Section table +section_table: + .ascii ".text\0\0\0" + .long __text_end - efi_header_end // VirtualSize + .long efi_header_end - _start // VirtualAddress + .long __text_end - efi_header_end // SizeOfRawData + .long efi_header_end - _start // PointerToRawData + + .long 0 // PointerToRelocations + .long 0 // PointerToLineNumbers + .short 0 // NumberOfRelocations + .short 0 // NumberOfLineNumbers + .long IMAGE_SCN_CNT_CODE | \ + IMAGE_SCN_MEM_READ | \ + IMAGE_SCN_MEM_EXECUTE // Characteristics + + .ascii ".data\0\0\0" + .long __data_virt_size // VirtualSize + .long __text_end - _start // VirtualAddress + .long __data_raw_size // SizeOfRawData + .long __text_end - _start // PointerToRawData + + .long 0 // PointerToRelocations + .long 0 // PointerToLineNumbers + .short 0 // NumberOfRelocations + .short 0 // NumberOfLineNumbers + .long IMAGE_SCN_CNT_INITIALIZED_DATA | \ + IMAGE_SCN_MEM_READ | \ + IMAGE_SCN_MEM_WRITE // Characteristics + + .set section_count, (. - section_table) / 40 + +efi_header_end: + .endm diff --git a/arch/riscv/kernel/head.S b/arch/riscv/kernel/head.S index ac5b0e0a02f6..ccec4716b053 100644 --- a/arch/riscv/kernel/head.S +++ b/arch/riscv/kernel/head.S @@ -13,6 +13,7 @@ #include #include #include +#include "efi-header.S" __HEAD ENTRY(_start) @@ -22,10 +23,18 @@ ENTRY(_start) * Do not modify it without modifying the structure and all bootloaders * that expects this header format!! */ +#ifdef CONFIG_EFI + /* + * This instruction decodes to "MZ" ASCII required by UEFI. + */ + li s4,-13 + j _start_kernel +#else /* jump to start kernel */ j _start_kernel /* reserved */ .word 0 +#endif .balign 8 #if __riscv_xlen == 64 /* Image load offset(2MB) from start of RAM */ @@ -43,7 +52,14 @@ ENTRY(_start) .ascii RISCV_IMAGE_MAGIC .balign 4 .ascii RISCV_IMAGE_MAGIC2 +#ifdef CONFIG_EFI + .word pe_head_start - _start +pe_head_start: + + __EFI_PE_HEADER +#else .word 0 +#endif .align 2 #ifdef CONFIG_MMU diff --git a/arch/riscv/kernel/image-vars.h b/arch/riscv/kernel/image-vars.h new file mode 100644 index 000000000000..bd8b764f0ad9 --- /dev/null +++ b/arch/riscv/kernel/image-vars.h @@ -0,0 +1,53 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +/* + * Copyright (C) 2020 Western Digital Corporation or its affiliates. + * Linker script variables to be set after section resolution, as + * ld.lld does not like variables assigned before SECTIONS is processed. + * Based on arch/arm64/kerne/image-vars.h + */ +#ifndef __RISCV_KERNEL_IMAGE_VARS_H +#define __RISCV_KERNEL_IMAGE_VARS_H + +#ifndef LINKER_SCRIPT +#error This file should only be included in vmlinux.lds.S +#endif + +#ifdef CONFIG_EFI + +__efistub_stext_offset = _start_kernel - _start; + +/* + * The EFI stub has its own symbol namespace prefixed by __efistub_, to + * isolate it from the kernel proper. The following symbols are legally + * accessed by the stub, so provide some aliases to make them accessible. + * Only include data symbols here, or text symbols of functions that are + * guaranteed to be safe when executed at another offset than they were + * linked at. The routines below are all implemented in assembler in a + * position independent manner + */ +__efistub_memcmp = memcmp; +__efistub_memchr = memchr; +__efistub_memcpy = memcpy; +__efistub_memmove = memmove; +__efistub_memset = memset; +__efistub_strlen = strlen; +__efistub_strnlen = strnlen; +__efistub_strcmp = strcmp; +__efistub_strncmp = strncmp; +__efistub_strrchr = strrchr; + +#ifdef CONFIG_KASAN +__efistub___memcpy = memcpy; +__efistub___memmove = memmove; +__efistub___memset = memset; +#endif + +__efistub__start = _start; +__efistub__start_kernel = _start_kernel; +__efistub__end = _end; +__efistub__edata = _edata; +__efistub_screen_info = screen_info; + +#endif + +#endif /* __RISCV_KERNEL_IMAGE_VARS_H */ diff --git a/arch/riscv/kernel/vmlinux.lds.S b/arch/riscv/kernel/vmlinux.lds.S index b32640300d07..933b9e9a4b39 100644 --- a/arch/riscv/kernel/vmlinux.lds.S +++ b/arch/riscv/kernel/vmlinux.lds.S @@ -9,6 +9,7 @@ #include #include #include +#include "image-vars.h" #include OUTPUT_ARCH(riscv) @@ -16,6 +17,14 @@ ENTRY(_start) jiffies = jiffies_64; +PECOFF_FILE_ALIGNMENT = 0x200; +#ifdef CONFIG_EFI +#define PECOFF_EDATA_PADDING \ + .pecoff_edata_padding : { BYTE(0); . = ALIGN(PECOFF_FILE_ALIGNMENT); } +#else +#define PECOFF_EDATA_PADDING +#endif + SECTIONS { /* Beginning of code and text segment */ @@ -26,12 +35,15 @@ SECTIONS __init_begin = .; INIT_TEXT_SECTION(PAGE_SIZE) + + /* Start of data section */ INIT_DATA_SECTION(16) /* we have to discard exit text and such at runtime, not link time */ .exit.text : { EXIT_TEXT } + .exit.data : { EXIT_DATA @@ -54,7 +66,8 @@ SECTIONS _etext = .; } - /* Start of data section */ + __text_end = .; + _sdata = .; RO_DATA(L1_CACHE_BYTES) .srodata : { @@ -65,19 +78,21 @@ SECTIONS .sdata : { __global_pointer$ = . + 0x800; *(.sdata*) - /* End of data section */ - _edata = .; *(.sbss*) } - - BSS_SECTION(PAGE_SIZE, PAGE_SIZE, 0) - + PECOFF_EDATA_PADDING + __data_raw_size = ABSOLUTE(. - __text_end); + /* End of data section */ + _edata = .; EXCEPTION_TABLE(0x10) .rel.dyn : { *(.rel.dyn*) } + BSS_SECTION(PAGE_SIZE, PAGE_SIZE, 0) + __data_virt_size = ABSOLUTE(. - __text_end); + _end = .; STABS_DEBUG From patchwork Thu Feb 27 22:26:44 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Atish Patra X-Patchwork-Id: 11411019 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id B91E917E0 for ; Thu, 27 Feb 2020 22:27:12 +0000 (UTC) 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 mail.kernel.org (Postfix) with ESMTPS id 943BF246A6 for ; Thu, 27 Feb 2020 22:27:12 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="eNyOZ5gC"; dkim=fail reason="signature verification failed" (2048-bit key) header.d=wdc.com header.i=@wdc.com header.b="QsMnahyg" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 943BF246A6 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=wdc.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-riscv-bounces+patchwork-linux-riscv=patchwork.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id: Content-Transfer-Encoding:MIME-Version:References:In-Reply-To:Message-Id:Date :Subject:To:From:Reply-To:Content-Type:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=ggWGTaC1SCeCSg6PWii0oTVf4CzKtQoqv/jbfZTud6c=; b=eNyOZ5gCZBMo+w htZ2sLxWhVvywgjKVPaA+ISKxk7ftXdrfwp7lUbVU+4cc3p1o+kgMEuyUrgkEs6Trk2UwdxhrTLER reu6GoYFtVmm0tquqBsz01SZJawehqquaaFJ9NVM0DGIbPiJ+8EyZ87mf5vtaDgM4J/gnb9QKViE2 +B//Nt2sYKablmYAJb7bhH7Jr3wktvfdydTjY4BbvVAZ3mgssJCTVN9QcNIbCzAWWm+UI+zHeK/2g TKquSGKqq54m/251zT7laRpZ1wWcZYIXR3mXDYoCf0Ts5JPwV+i1w7nM6+eA0a3jQjSDzbmmCTrOw mkx7SfsrYLJbjCKX1dRQ==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1j7Rcb-0000og-SR; Thu, 27 Feb 2020 22:27:09 +0000 Received: from esa6.hgst.iphmx.com ([216.71.154.45]) by bombadil.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1j7RcQ-0000YS-LW for linux-riscv@lists.infradead.org; Thu, 27 Feb 2020 22:27:01 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1582842419; x=1614378419; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=Lp215JCY61GERcBhD51PJFsT/l8XetQSivt+pIE2ejw=; b=QsMnahygoAZwNqlbHn/jVXgZTn4bE63ntu2KjC3vttFLLX9Av5i50XUE AjsYtqgTCwDhm0BWOqneHygH5b18ZlaMu8PuEcaUyYWQbrnHsaZvdGdgw AyF42c/DsCsdegFtJ3M1vvYPWi7nStzep1EhnrcG7+r2Z6Qo8oAJG0Oz0 0GTMIRQSrqWIcgkIaLeI4XwohBPVXY5ywHI23XvsX5lvJqnovNERrX2O0 t7Ggcblr/vYT2WYy/zChfyqVmE5LTUbBCV2rzeFl7c1VR2H5twqYk1VYB sJG4zKyTfOYhf12UAOhwikTe8bRxFW9EZYLG6udVPtMuboyqRPf1cjJ1g g==; IronPort-SDR: qm3o7h1ERgweZnC/emP/qphP4Tzwzf4/Rx+M6/BtUYoLWo1UH5GyIcQvDubyIyV+N8QwRUFdIV HumbM+QUXE489Z/s9K2NjtfHrN8/J5YnJgasL22CJ1mZjHnYSrBLsDAUEtnUgzY1Ppk9dge3XC QSNwb8Q8iVduNSHVyB0v2uuc9nPIrVXnlV53AAA5yWy1fmJLwondKkdCYooCV7NXTwh4ulH8XR 4noxgdIns2+aIxqMKDrW29wcpV59lcDhwlFzCMdAJSkSKTp3O9hhOxeGZeSriou8GvDEx9Jauh esg= X-IronPort-AV: E=Sophos;i="5.70,493,1574092800"; d="scan'208";a="132395359" Received: from uls-op-cesaip02.wdc.com (HELO uls-op-cesaep02.wdc.com) ([199.255.45.15]) by ob1.hgst.iphmx.com with ESMTP; 28 Feb 2020 06:26:53 +0800 IronPort-SDR: 9rbYQ1sCTJvhGoHCqecmQeYuq30aRAlN2JiODo4GSfW2fzp5ppvWqZJ2sw6pEwuBHXmsXjn4d0 O/EGWTkdNKIKuPk2camrM3UpIFHo/MOhfepFob1xUOkEkMkWxSHrneFyZ3H9j0oTftIWugEMY5 lp+HBYvpyUklsuOlnedKvIt5sFX008+K0JRnw0Jq0BM6Qv7Nj9CNc1uJj5ULvjVQc/V66UGFs3 4gDZAhyP0cfWZ+MOIaAYZK9xOC242ZLSY6hIeU03jl/oMixYm/SR4GJ1BOLUHom+gxRYDKBup5 bwSBjH3OAB3tVxMAH+CIqzvr Received: from uls-op-cesaip02.wdc.com ([10.248.3.37]) by uls-op-cesaep02.wdc.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 27 Feb 2020 14:18:52 -0800 IronPort-SDR: TFgo6kyhBYlcxQfAS9cp3EBSyPhWTUfAdB7VZqdAfcXz+qbuzONOfSTxJJ6/8yc0QU8P3ZRL61 AI/Ke0or8g1kTcTIb4PRIyemqBGbmc0I8ZA3EBfQT5YFmLea8+f0t2xM09t7VsnG6WZrYgRXJl hkNrKRE2FhT5ybfveJj5lBNBTyM0TdHRIT2W1sO+c8mKp1W5w5X1r3+xkBsLVchXEHU6id7foa J/yHIou09Cdt+pp0EAKWmFu/4JGd0BPaRsKxCDq5GkA1pa5FJla8qQSe6FJHRYSeJ1NkYYkYuq OEA= WDCIronportException: Internal Received: from jedi-01.sdcorp.global.sandisk.com (HELO jedi-01.int.fusionio.com) ([10.11.143.218]) by uls-op-cesaip02.wdc.com with ESMTP; 27 Feb 2020 14:26:51 -0800 From: Atish Patra To: linux-kernel@vger.kernel.org Subject: [v1 PATCH 5/5] RISC-V: Add EFI stub support. Date: Thu, 27 Feb 2020 14:26:44 -0800 Message-Id: <20200227222644.9468-6-atish.patra@wdc.com> X-Mailer: git-send-email 2.24.0 In-Reply-To: <20200227222644.9468-1-atish.patra@wdc.com> References: <20200227222644.9468-1-atish.patra@wdc.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20200227_142658_772563_E2E3906B X-CRM114-Status: GOOD ( 31.22 ) X-Spam-Score: -2.5 (--) X-Spam-Report: SpamAssassin version 3.4.3 on bombadil.infradead.org summary: Content analysis details: (-2.5 points) pts rule name description ---- ---------------------- -------------------------------------------------- -2.3 RCVD_IN_DNSWL_MED RBL: Sender listed at https://www.dnswl.org/, medium trust [216.71.154.45 listed in list.dnswl.org] 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record -0.0 SPF_PASS SPF: sender matches SPF record -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid X-BeenThere: linux-riscv@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kate Stewart , linux-efi@vger.kernel.org, Ard Biesheuvel , Catalin Marinas , Linus Walleij , Russell King , Atish Patra , Mauro Carvalho Chehab , linux-riscv@lists.infradead.org, Will Deacon , Ingo Molnar , "Chang, Abner \(HPS SW/FW Technologist\)" , Michal Simek , Mike Rapoport , Greentime Hu , Borislav Petkov , Mao Han , daniel.schaefer@hpe.com, Albert Ou , Kees Cook , Arnd Bergmann , Alexios Zavras , Alexander Graf , Paul Walmsley , Thomas Gleixner , Allison Randal , "leif@nuviainc.com" , Greg Kroah-Hartman , Anup Patel , Palmer Dabbelt , Paolo Bonzini , Andrew Morton Sender: "linux-riscv" Errors-To: linux-riscv-bounces+patchwork-linux-riscv=patchwork.kernel.org@lists.infradead.org Add a RISC-V architecture specific stub code that actually copies the actual kernel image to a valid address and jump to it after boot services are terminated. Enable UEFI related kernel configs as well for RISC-V. Signed-off-by: Atish Patra --- arch/riscv/Kconfig | 20 ++++ arch/riscv/Makefile | 1 + arch/riscv/configs/defconfig | 1 + arch/riscv/include/asm/efi.h | 59 ++++++++++ drivers/firmware/efi/Kconfig | 2 +- drivers/firmware/efi/libstub/Makefile | 8 ++ drivers/firmware/efi/libstub/riscv-stub.c | 131 ++++++++++++++++++++++ 7 files changed, 221 insertions(+), 1 deletion(-) create mode 100644 arch/riscv/include/asm/efi.h create mode 100644 drivers/firmware/efi/libstub/riscv-stub.c diff --git a/arch/riscv/Kconfig b/arch/riscv/Kconfig index 42c122170cfd..5a49a8117b17 100644 --- a/arch/riscv/Kconfig +++ b/arch/riscv/Kconfig @@ -372,10 +372,30 @@ config CMDLINE_FORCE endchoice +config EFI_STUB + bool + +config EFI + bool "UEFI runtime support" + depends on OF + select LIBFDT + select UCS2_STRING + select EFI_PARAMS_FROM_FDT + select EFI_STUB + select EFI_GENERIC_STUB + default y + help + This option provides support for runtime services provided + by UEFI firmware (such as non-volatile variables, realtime + clock, and platform reset). A UEFI stub is also provided to + allow the kernel to be booted as an EFI application. This + is only useful on systems that have UEFI firmware. + endmenu menu "Power management options" source "kernel/power/Kconfig" +source "drivers/firmware/Kconfig" endmenu diff --git a/arch/riscv/Makefile b/arch/riscv/Makefile index b9009a2fbaf5..0afaa89ba9ad 100644 --- a/arch/riscv/Makefile +++ b/arch/riscv/Makefile @@ -78,6 +78,7 @@ head-y := arch/riscv/kernel/head.o core-y += arch/riscv/ libs-y += arch/riscv/lib/ +core-$(CONFIG_EFI_STUB) += $(objtree)/drivers/firmware/efi/libstub/lib.a PHONY += vdso_install vdso_install: diff --git a/arch/riscv/configs/defconfig b/arch/riscv/configs/defconfig index e2ff95cb3390..0a5d3578f51e 100644 --- a/arch/riscv/configs/defconfig +++ b/arch/riscv/configs/defconfig @@ -125,3 +125,4 @@ CONFIG_DEBUG_BLOCK_EXT_DEVT=y # CONFIG_FTRACE is not set # CONFIG_RUNTIME_TESTING_MENU is not set CONFIG_MEMTEST=y +CONFIG_EFI=y diff --git a/arch/riscv/include/asm/efi.h b/arch/riscv/include/asm/efi.h new file mode 100644 index 000000000000..b3d788bdcb54 --- /dev/null +++ b/arch/riscv/include/asm/efi.h @@ -0,0 +1,59 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* + * Copyright (C) 2020 Western Digital Corporation or its affiliates. + */ +#ifndef _ASM_EFI_H +#define _ASM_EFI_H + +#include +#include +#include +#include + +#define VA_BITS_MIN 39 +/* + * AArch64 requires the DTB to be 8-byte aligned in the first 512MiB from + * start of kernel and may not cross a 2MiB boundary. We set alignment to + * 2MiB so we know it won't cross a 2MiB boundary. + */ +#define EFI_FDT_ALIGN SZ_2M /* used by allocate_new_fdt_and_exit_boot() */ + +/* on arm64, the FDT may be located anywhere in system RAM */ +static inline unsigned long efi_get_max_fdt_addr(unsigned long dram_base) +{ + return ULONG_MAX; +} + +/* + * On arm64, we have to ensure that the initrd ends up in the linear region, + * which is a 1 GB aligned region of size '1UL << (VA_BITS_MIN - 1)' that is + * guaranteed to cover the kernel Image. + * + * Since the EFI stub is part of the kernel Image, we can relax the + * usual requirements in Documentation/arm64/booting.rst, which still + * apply to other bootloaders, and are required for some kernel + * configurations. + */ +static inline unsigned long efi_get_max_initrd_addr(unsigned long dram_base, + unsigned long image_addr) +{ + return (image_addr & ~(SZ_1G - 1UL)) + (1UL << (VA_BITS_MIN - 1)); +} + +#define efi_bs_call(func, ...) efi_system_table()->boottime->func(__VA_ARGS__) +#define efi_rt_call(func, ...) efi_system_table()->runtime->func(__VA_ARGS__) +#define efi_is_native() (true) + +#define efi_table_attr(inst, attr) (inst->attr) + +#define efi_call_proto(inst, func, ...) inst->func(inst, ##__VA_ARGS__) + +#define alloc_screen_info(x...) (&screen_info) +extern char stext_offset[]; + +static inline void free_screen_info(struct screen_info *si) +{ +} +#define EFI_ALLOC_ALIGN SZ_64K + +#endif /* _ASM_EFI_H */ diff --git a/drivers/firmware/efi/Kconfig b/drivers/firmware/efi/Kconfig index 708fe86cc66d..682aece44475 100644 --- a/drivers/firmware/efi/Kconfig +++ b/drivers/firmware/efi/Kconfig @@ -111,7 +111,7 @@ config EFI_GENERIC_STUB config EFI_ARMSTUB_DTB_LOADER bool "Enable the DTB loader" - depends on EFI_GENERIC_STUB + depends on EFI_GENERIC_STUB && !RISCV default y help Select this config option to add support for the dtb= command diff --git a/drivers/firmware/efi/libstub/Makefile b/drivers/firmware/efi/libstub/Makefile index f1d7de1e0d87..e1db7666ad80 100644 --- a/drivers/firmware/efi/libstub/Makefile +++ b/drivers/firmware/efi/libstub/Makefile @@ -21,6 +21,8 @@ cflags-$(CONFIG_ARM64) := $(subst $(CC_FLAGS_FTRACE),,$(KBUILD_CFLAGS)) \ cflags-$(CONFIG_ARM) := $(subst $(CC_FLAGS_FTRACE),,$(KBUILD_CFLAGS)) \ -fno-builtin -fpic \ $(call cc-option,-mno-single-pic-base) +cflags-$(CONFIG_RISCV) := $(subst $(CC_FLAGS_FTRACE),,$(KBUILD_CFLAGS)) \ + -fpic cflags-$(CONFIG_EFI_GENERIC_STUB) += -I$(srctree)/scripts/dtc/libfdt @@ -55,6 +57,7 @@ lib-$(CONFIG_EFI_GENERIC_STUB) += efi-stub.o fdt.o string.o \ lib-$(CONFIG_ARM) += arm32-stub.o lib-$(CONFIG_ARM64) += arm64-stub.o lib-$(CONFIG_X86) += x86-stub.o +lib-$(CONFIG_RISCV) += riscv-stub.o CFLAGS_arm32-stub.o := -DTEXT_OFFSET=$(TEXT_OFFSET) CFLAGS_arm64-stub.o := -DTEXT_OFFSET=$(TEXT_OFFSET) @@ -79,6 +82,11 @@ STUBCOPY_FLAGS-$(CONFIG_ARM64) += --prefix-alloc-sections=.init \ --prefix-symbols=__efistub_ STUBCOPY_RELOC-$(CONFIG_ARM64) := R_AARCH64_ABS +STUBCOPY_FLAGS-$(CONFIG_RISCV) += --prefix-alloc-sections=.init \ + --prefix-symbols=__efistub_ +STUBCOPY_RELOC-$(CONFIG_RISCV) := R_RISCV_HI20 + + $(obj)/%.stub.o: $(obj)/%.o FORCE $(call if_changed,stubcopy) diff --git a/drivers/firmware/efi/libstub/riscv-stub.c b/drivers/firmware/efi/libstub/riscv-stub.c new file mode 100644 index 000000000000..acb69eae187a --- /dev/null +++ b/drivers/firmware/efi/libstub/riscv-stub.c @@ -0,0 +1,131 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * Copyright (C) 2013, 2014 Linaro Ltd; + * Copyright (C) 2020 Western Digital Corporation or its affiliates. + * + * This file implements the EFI boot stub for the RISC-V kernel. + * Adapted from ARM64 version at drivers/firmware/efi/libstub/arm64-stub.c. + */ + +#include +#include +#include +#include +#include + +#include "efistub.h" +/* + * RISCV requires the kernel image to placed TEXT_OFFSET bytes beyond a 2 MB + * aligned base for 64 bit and 4MB for 32 bit. + */ +#ifdef CONFIG_64BIT +#define MIN_KIMG_ALIGN SZ_2M +#else +#define MIN_KIMG_ALIGN SZ_4M +#endif +/* + * TEXT_OFFSET ensures that we don't overwrite the firmware that probably sits + * at the beginning of the DRAM. + */ +#define TEXT_OFFSET MIN_KIMG_ALIGN + +typedef __attribute__((noreturn)) void (*jump_kernel_func)(unsigned int, + unsigned long); +efi_status_t check_platform_features(void) +{ + return EFI_SUCCESS; +} + +static u32 get_boot_hartid_from_fdt(unsigned long fdt) +{ + int chosen_node, len; + const fdt32_t *prop; + + chosen_node = fdt_path_offset((void *)fdt, "/chosen"); + if (chosen_node < 0) + return U32_MAX; + prop = fdt_getprop((void *)fdt, chosen_node, "boot-hartid", &len); + if (!prop || len != sizeof(u32)) + return U32_MAX; + + return fdt32_to_cpu(*prop); +} + +/* + * Jump to real kernel here with following constraints. + * 1. MMU should be disabled. + * 2. a0 should contain hartid + * 3. a1 should DT address + */ +void __noreturn efi_enter_kernel(unsigned long entrypoint, unsigned long fdt, + unsigned long fdt_size) +{ + unsigned long kernel_entry = entrypoint + (unsigned long)stext_offset; + jump_kernel_func jump_kernel = (void (*)(unsigned int, unsigned long))kernel_entry; + u32 hartid = get_boot_hartid_from_fdt(fdt); + + if (hartid == U32_MAX) + /* We can not use panic or BUG at this point */ + __asm__ __volatile__ ("ebreak"); + /* Disable MMU */ + csr_write(CSR_SATP, 0); + jump_kernel(hartid, fdt); +} + +efi_status_t handle_kernel_image(unsigned long *image_addr, + unsigned long *image_size, + unsigned long *reserve_addr, + unsigned long *reserve_size, + unsigned long dram_base, + efi_loaded_image_t *image) +{ + efi_status_t status; + unsigned long kernel_size, kernel_memsize = 0; + unsigned long preferred_offset; + + /* + * The preferred offset of the kernel Image is TEXT_OFFSET bytes beyond + * a KIMG_ALIGN aligned base. + */ + preferred_offset = round_up(dram_base, MIN_KIMG_ALIGN) + TEXT_OFFSET; + + kernel_size = _edata - _start; + kernel_memsize = kernel_size + (_end - _edata); + + /* + * Try a straight allocation at the preferred offset. It will also + * ensure that, on platforms where the [dram_base, dram_base + TEXT_OFFSET) + * interval is partially occupied by the firmware we can still place + * the kernel at the address 'dram_base + TEXT_OFFSET'. If the straight + * allocation fails, efi_low_alloc tries allocate memory from the lowest + * available LOADER_DATA mapped memory as long as address and size meet + * the alignment constraints. + */ + if (*image_addr == preferred_offset) + return EFI_SUCCESS; + + *image_addr = *reserve_addr = preferred_offset; + *reserve_size = round_up(kernel_memsize, EFI_ALLOC_ALIGN); + + status = efi_bs_call(allocate_pages, EFI_ALLOCATE_ADDRESS, + EFI_LOADER_DATA, + *reserve_size / EFI_PAGE_SIZE, + (efi_physical_addr_t *)reserve_addr); + + if (status != EFI_SUCCESS) { + pr_efi("straight allocation failed do a low alloc\n"); + *reserve_size = kernel_memsize + TEXT_OFFSET; + status = efi_low_alloc(*reserve_size, MIN_KIMG_ALIGN, + reserve_addr); + + if (status != EFI_SUCCESS) { + pr_efi_err("Failed to relocate kernel\n"); + *reserve_size = 0; + return status; + } + *image_addr = *reserve_addr + TEXT_OFFSET; + } + memcpy((void *)*image_addr, image->image_base, kernel_size); + + return EFI_SUCCESS; +}