From patchwork Thu Jun 25 23:45:06 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Atish Patra X-Patchwork-Id: 11627159 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 C4C4092A for ; Fri, 26 Jun 2020 10:54:19 +0000 (UTC) Received: from merlin.infradead.org (merlin.infradead.org [205.233.59.134]) (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 95502206DD for ; Fri, 26 Jun 2020 10:54:19 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="kSrnHSXo"; dkim=fail reason="signature verification failed" (2048-bit key) header.d=wdc.com header.i=@wdc.com header.b="HCVLpkiX" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 95502206DD 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-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=merlin.20170209; h=Sender:Content-Transfer-Encoding: Content-Type:Cc: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:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=Fv2RutqAVbn7klveVHk+yoxMb7UIebjQWl/jKz29wHM=; b=kSrnHSXohZn+nqoLOQPqAHmVE IXmu5hu/XUT/bHgQnvVgEEkWY9M8G9RdUK+9DlJhdYjhB8DzdjGH/6rSEKsYwHP3IZZ+GAybPDgXI sMlKuG0l3X1uUxZ9xcGZmip8nUZCDgeCi0Y6UCyyr+sveDn1idKQnU7ZOY76qaJI37EUiBcgvEIvL 1O3GhjZhSF57v/xw4g3Rc+ilDS6Zmf7Dqsidv18prHJTYBiWDVgUya16pmzQBO5xbuYeTJ03jEKED PKQlfnjwDsuVmOze73FEmExbCvC8pOzYv8m4IjHcLyFxEB2/Cb4j6MmkMPWpKksKTdzyycC+k9a5B FUclSqf0w==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1joly1-0006O7-1v; Fri, 26 Jun 2020 10:52:21 +0000 Received: from esa2.hgst.iphmx.com ([68.232.143.124]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1jojl1-0002Se-8H; Fri, 26 Jun 2020 08:31:08 +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=1593160252; x=1624696252; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=dZDSjJ3t1MSIr8n8TsrQ491YhsMuw7KafK1O8BitsUU=; b=HCVLpkiXVsGxwUf+YhXywCKruNLprqUA7Ow9xW8VVqf4PS+X96/fRCeb KsxN/ZrNAKYtFtio/IzFbUtLxykTO9FFDZN0xwDps8kY2sV1L11HTJyRa C0kHxkOR1wf+RMoN7rIRMzolVdnBOupFrKf+lZRXNRWhm8UrP2L0xFFJ0 Vbh5M0dcKqVIwwD9uSs5qgaJ1by+A06/N9Z/ZT7Eltp7ahFDyYpF+l57p uh69uwno2S+x9sBhau1iLmuKuaAowOLpvkisdJWxnp28GLEX7gi0sOcKo HiHlizcJ/LSVu5y+abnVaUl99S6kF4QcKTWulT7A5G0dXWAQ6lx/k3jYa Q==; IronPort-SDR: pL+O3ZDy5LErZM5NOZfkr+cnRx6RUv+Bzv7oOuheitmBYy/MhRchVuJv+7BYutMwuv4rKrxNxf J9sNqERP1paUXegwLFuEWnqbbW2bix8IpdkSWC4yWX3p0KxoCgnrwsjci4wuDDH5aq2pljmr9H w0ow5mLLcvZhV+/wjAjE/6JeQvLWqQ8iaH2viU439ILBmJRkvzWV3Fpy2RHhrqAnQ9Y7+/p0Lt BlI4M7FyEhFau/eb2wvNzqMc+JEeYFaUeZuDbCWyWgNPq0kaGRm3Jjcuapu6HsJ1keQeLCPZF7 dXc= X-IronPort-AV: E=Sophos;i="5.75,280,1589212800"; d="scan'208";a="243966111" Received: from h199-255-45-14.hgst.com (HELO uls-op-cesaep01.wdc.com) ([199.255.45.14]) by ob1.hgst.iphmx.com with ESMTP; 26 Jun 2020 07:45:54 +0800 IronPort-SDR: AjJp13nAaT329s672GPo0jcWwEqzRBRfbncQh6diVy2i4nhenp8/XX7RMEWlwIfIY9Uv+ZNTBa oQ3kaf0QfNXDqdZC3ucwnclug+IsEuw6c= Received: from uls-op-cesaip01.wdc.com ([10.248.3.36]) by uls-op-cesaep01.wdc.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 25 Jun 2020 16:34:24 -0700 IronPort-SDR: hEw8ADmFsS1UNhDNRtJDi5RD8kl6Gt14KhsVC7MOMicSCEZm24PLXIM1GWGlN1n4WMslGowcYZ 4BLBjmH2ILnw== WDCIronportException: Internal Received: from 2349pbt5e4f.ad.shared (HELO jedi-01.hgst.com) ([10.86.58.78]) by uls-op-cesaip01.wdc.com with ESMTP; 25 Jun 2020 16:45:24 -0700 From: Atish Patra To: linux-kernel@vger.kernel.org Subject: [RFC PATCH 01/11] efi: Fix gcc error around __umoddi3 for 32 bit builds Date: Thu, 25 Jun 2020 16:45:06 -0700 Message-Id: <20200625234516.31406-2-atish.patra@wdc.com> X-Mailer: git-send-email 2.24.0 In-Reply-To: <20200625234516.31406-1-atish.patra@wdc.com> References: <20200625234516.31406-1-atish.patra@wdc.com> MIME-Version: 1.0 X-Spam-Note: CRM114 invocation failed X-Spam-Score: -2.5 (--) X-Spam-Report: SpamAssassin version 3.4.4 on merlin.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 [68.232.143.124 listed in list.dnswl.org] -0.0 SPF_HELO_PASS SPF: HELO matches 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_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 -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: linux-efi@vger.kernel.org, Heinrich Schuchardt , Masahiro Yamada , Atish Patra , Palmer Dabbelt , linux-riscv@lists.infradead.org, Ard Biesheuvel , linux-arm-kernel@lists.infradead.org Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org 32bit gcc doesn't support modulo operation on 64 bit data. It results in a __umoddi3 error while building EFI for 32 bit. Use bitwise operations instead of modulo operations to fix the issue. Signed-off-by: Atish Patra --- drivers/firmware/efi/libstub/alignedmem.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/firmware/efi/libstub/alignedmem.c b/drivers/firmware/efi/libstub/alignedmem.c index cc89c4d6196f..1de9878ddd3a 100644 --- a/drivers/firmware/efi/libstub/alignedmem.c +++ b/drivers/firmware/efi/libstub/alignedmem.c @@ -44,7 +44,7 @@ efi_status_t efi_allocate_pages_aligned(unsigned long size, unsigned long *addr, *addr = ALIGN((unsigned long)alloc_addr, align); if (slack > 0) { - int l = (alloc_addr % align) / EFI_PAGE_SIZE; + int l = (alloc_addr & (align - 1)) / EFI_PAGE_SIZE; if (l) { efi_bs_call(free_pages, alloc_addr, slack - l + 1); From patchwork Thu Jun 25 23:45:07 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Atish Patra X-Patchwork-Id: 11626981 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 1210E92A for ; Fri, 26 Jun 2020 09:51:26 +0000 (UTC) Received: from merlin.infradead.org (merlin.infradead.org [205.233.59.134]) (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 DC87921531 for ; Fri, 26 Jun 2020 09:51:25 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="xY3AJ9bb"; dkim=fail reason="signature verification failed" (2048-bit key) header.d=wdc.com header.i=@wdc.com header.b="fdQB6Oh0" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org DC87921531 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-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=merlin.20170209; h=Sender:Content-Transfer-Encoding: Content-Type:Cc: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:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=Qx91mbxDSw1cUUEFaNJ9zayg8BettPX44ZydB+cAjOs=; b=xY3AJ9bbvHTYfaCZ6ABLrXG6b oBTH9fddcPNxToRopj17qXyRNoUwA34FswlNLCe2+Cy/tEP6OnlHszJ7HVvVMYzwUgSIkswBBk8fi 3EvrzSE0woxmZnVbjIc9YKH8fNeNa5nSfvuLMq+9/req+h/pwSTbSO1HxAvg29tSMQ+VQZa9H+qb4 xZosimXagV9NDU+oc0Xwj3PP/w+1x1MAOz5Pp5YlKIa6iNgwrnFLfD1u3eW0MbMKsJoX1IDH1m1Mc lGf2ug6joN95EnIAdzan5itBO2aQ3iBcR3+U0dF7WMTXqaksZTt8QqU4R8C82t7HPbMTQLOe1kmfz mSsqU0DDA==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1jokyj-0002HC-VN; Fri, 26 Jun 2020 09:49:02 +0000 Received: from esa2.hgst.iphmx.com ([68.232.143.124]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1jojlM-0002Se-GY; Fri, 26 Jun 2020 08:31:30 +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=1593160284; x=1624696284; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=ihAfLD97lU7TjJORSki+rGBXYnAkG5Afd7XbqxsjX2E=; b=fdQB6Oh0TQJ8WUq94NdKjUhVq1ZPduHpTKrgJmr1hSMvKOiyUukd3P9d ve494ZkjNp/xVQPanxi1DfXXhOgo/qrmXu9IxZoSzryxs2vKa9wee9q8D w8+feYjl4jDcXMkbwZPK1YRzxRwBv+L56a+eNrnOMJfzz19krkxJm1CMW rN6C1QqQtfzSQTqk0g2xWbJIUp2lLEkguxBTSqw7J4pqtHY2tpNxFBGhL y8UeTTiLRaROnSawP2BoydLXqWKbgfQKWxf54oqR/XaPE4jI2D0FvwyhG 1B3TcCmiIi/6ukf3Xcd+Wey8kYVfALmjwc342fj1Day8+Fpfj7Y89gzG9 A==; IronPort-SDR: rfSSMgvfyTgMm6OZn6ofJXz/1aPxbA3YdhD8fTNYLMDbn1CEkjhalXUzTIM+OA2tK6MywRGP0/ gg7JR1/fjhFtA4MQgULde3tLqOOOaVcwIaJNsh/bszHLo47QHrbgw2dmreucYjSkmTz+Zc1P8R GeAdrIwEHTPCKuXLVrHw4+pAoxOB4dz0NgVH3YWYaNPZ/WPaH0SIUOy7ikES3LCH6uctYXpGqx ucBjQD81/AhBjdHxXUhlx4oYdKqiqiog0eKjx/IkTVcrP+QR3QRgHPKhBdmDsq0+nup3gfMqVH MYs= X-IronPort-AV: E=Sophos;i="5.75,280,1589212800"; d="scan'208";a="243966113" Received: from h199-255-45-14.hgst.com (HELO uls-op-cesaep01.wdc.com) ([199.255.45.14]) by ob1.hgst.iphmx.com with ESMTP; 26 Jun 2020 07:45:55 +0800 IronPort-SDR: gEmk8htIxyhlKONKrfB31qul37ANT0KOMlY4FcmQI5gu8h4FPzWiranh0AIUEMSjSpTS/jLUYt tIHgVxbhSU0WzkZAHZeCbzK0pUi0sQ+58= Received: from uls-op-cesaip01.wdc.com ([10.248.3.36]) by uls-op-cesaep01.wdc.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 25 Jun 2020 16:34:24 -0700 IronPort-SDR: XdKBNVU/O42ety0Whagt21NSpSDmF4gQyI7GoUuTMQqteQT1/4HNm3PvjdfucV4L3ZKPI2hZ1I N+hsiIBqSVNg== WDCIronportException: Internal Received: from 2349pbt5e4f.ad.shared (HELO jedi-01.hgst.com) ([10.86.58.78]) by uls-op-cesaip01.wdc.com with ESMTP; 25 Jun 2020 16:45:24 -0700 From: Atish Patra To: linux-kernel@vger.kernel.org Subject: [RFC PATCH 02/11] RISC-V: Move DT mapping outof fixmap Date: Thu, 25 Jun 2020 16:45:07 -0700 Message-Id: <20200625234516.31406-3-atish.patra@wdc.com> X-Mailer: git-send-email 2.24.0 In-Reply-To: <20200625234516.31406-1-atish.patra@wdc.com> References: <20200625234516.31406-1-atish.patra@wdc.com> MIME-Version: 1.0 X-Spam-Note: CRM114 invocation failed X-Spam-Score: -2.5 (--) X-Spam-Report: SpamAssassin version 3.4.4 on merlin.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 [68.232.143.124 listed in list.dnswl.org] -0.0 SPF_HELO_PASS SPF: HELO matches 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_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 -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: linux-efi@vger.kernel.org, Heinrich Schuchardt , Masahiro Yamada , Anup Patel , Atish Patra , Palmer Dabbelt , linux-riscv@lists.infradead.org, Ard Biesheuvel , linux-arm-kernel@lists.infradead.org Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org From: Anup Patel Currently, RISC-V reserves 1MB of fixmap memory for device tree. However, it maps only single PMD (2MB) space for fixmap which leaves only < 1MB space left for other kernel features such as early ioremap which requires fixmap as well. The fixmap size can be increased by another 2MB but it brings additional complexity and changes the virtual memory layout as well. If we require some additional feature requiring fixmap again, it has to be moved again. Technically, DT doesn't need a fixmap as the memory occupied by the DT is only used during boot. Thus, init memory section can be used for the same purpose as well. This simplifies fixmap implementation. Signed-off-by: Anup Patel Signed-off-by: Atish Patra --- arch/riscv/include/asm/fixmap.h | 3 --- arch/riscv/kernel/head.S | 1 - arch/riscv/kernel/head.h | 2 -- arch/riscv/kernel/setup.c | 8 +++----- arch/riscv/mm/init.c | 36 ++++++++++++++------------------- 5 files changed, 18 insertions(+), 32 deletions(-) diff --git a/arch/riscv/include/asm/fixmap.h b/arch/riscv/include/asm/fixmap.h index 1ff075a8dfc7..11613f38228a 100644 --- a/arch/riscv/include/asm/fixmap.h +++ b/arch/riscv/include/asm/fixmap.h @@ -22,9 +22,6 @@ */ enum fixed_addresses { FIX_HOLE, -#define FIX_FDT_SIZE SZ_1M - FIX_FDT_END, - FIX_FDT = FIX_FDT_END + FIX_FDT_SIZE / PAGE_SIZE - 1, FIX_PTE, FIX_PMD, FIX_TEXT_POKE1, diff --git a/arch/riscv/kernel/head.S b/arch/riscv/kernel/head.S index 7ed1b22950fd..c5b529234ad8 100644 --- a/arch/riscv/kernel/head.S +++ b/arch/riscv/kernel/head.S @@ -244,7 +244,6 @@ clear_bss_done: #endif /* Start the kernel */ call soc_early_init - call parse_dtb tail start_kernel .Lsecondary_start: diff --git a/arch/riscv/kernel/head.h b/arch/riscv/kernel/head.h index 105fb0496b24..b48dda3d04f6 100644 --- a/arch/riscv/kernel/head.h +++ b/arch/riscv/kernel/head.h @@ -16,6 +16,4 @@ asmlinkage void __init setup_vm(uintptr_t dtb_pa); extern void *__cpu_up_stack_pointer[]; extern void *__cpu_up_task_pointer[]; -void __init parse_dtb(void); - #endif /* __ASM_HEAD_H */ diff --git a/arch/riscv/kernel/setup.c b/arch/riscv/kernel/setup.c index f04373be54a6..8519a6d29857 100644 --- a/arch/riscv/kernel/setup.c +++ b/arch/riscv/kernel/setup.c @@ -49,8 +49,9 @@ atomic_t hart_lottery __section(.sdata); unsigned long boot_cpu_hartid; static DEFINE_PER_CPU(struct cpu, cpu_devices); -void __init parse_dtb(void) +static void __init parse_dtb(void) { + /* Early scan of device tree from init memory */ if (early_init_dt_scan(dtb_early_va)) return; @@ -63,6 +64,7 @@ void __init parse_dtb(void) void __init setup_arch(char **cmdline_p) { + parse_dtb(); init_mm.start_code = (unsigned long) _stext; init_mm.end_code = (unsigned long) _etext; init_mm.end_data = (unsigned long) _edata; @@ -74,11 +76,7 @@ void __init setup_arch(char **cmdline_p) setup_bootmem(); paging_init(); -#if IS_ENABLED(CONFIG_BUILTIN_DTB) unflatten_and_copy_device_tree(); -#else - unflatten_device_tree(); -#endif clint_init_boot_cpu(); #ifdef CONFIG_SWIOTLB diff --git a/arch/riscv/mm/init.c b/arch/riscv/mm/init.c index f4adb3684f3d..c18c94ab3b23 100644 --- a/arch/riscv/mm/init.c +++ b/arch/riscv/mm/init.c @@ -28,7 +28,6 @@ unsigned long empty_zero_page[PAGE_SIZE / sizeof(unsigned long)] EXPORT_SYMBOL(empty_zero_page); extern char _start[]; -void *dtb_early_va; static void __init zone_sizes_init(void) { @@ -120,8 +119,6 @@ static void __init setup_initrd(void) } #endif /* CONFIG_BLK_DEV_INITRD */ -static phys_addr_t dtb_early_pa __initdata; - void __init setup_bootmem(void) { struct memblock_region *reg; @@ -158,13 +155,9 @@ void __init setup_bootmem(void) setup_initrd(); #endif /* CONFIG_BLK_DEV_INITRD */ - /* - * Avoid using early_init_fdt_reserve_self() since __pa() does - * not work for DTB pointers that are fixmap addresses - */ - memblock_reserve(dtb_early_pa, fdt_totalsize(dtb_early_va)); - + early_init_fdt_reserve_self(); early_init_fdt_scan_reserved_mem(); + memblock_allow_resize(); memblock_dump_all(); @@ -184,6 +177,10 @@ EXPORT_SYMBOL(va_pa_offset); unsigned long pfn_base; EXPORT_SYMBOL(pfn_base); +#define DTB_EARLY_SIZE SZ_1M +static char early_dtb[DTB_EARLY_SIZE] __initdata; +void *dtb_early_va __initdata = early_dtb; + pgd_t swapper_pg_dir[PTRS_PER_PGD] __page_aligned_bss; pgd_t trampoline_pg_dir[PTRS_PER_PGD] __page_aligned_bss; pte_t fixmap_pte[PTRS_PER_PTE] __page_aligned_bss; @@ -375,7 +372,8 @@ static uintptr_t __init best_map_size(phys_addr_t base, phys_addr_t size) asmlinkage void __init setup_vm(uintptr_t dtb_pa) { - uintptr_t va, end_va; + int dtb_size; + uintptr_t va, pa, end_va; uintptr_t load_pa = (uintptr_t)(&_start); uintptr_t load_sz = (uintptr_t)(&_end) - load_pa; uintptr_t map_size = best_map_size(load_pa, MAX_EARLY_MAPPING_SIZE); @@ -424,17 +422,11 @@ asmlinkage void __init setup_vm(uintptr_t dtb_pa) load_pa + (va - PAGE_OFFSET), map_size, PAGE_KERNEL_EXEC); - /* Create fixed mapping for early FDT parsing */ - end_va = __fix_to_virt(FIX_FDT) + FIX_FDT_SIZE; - for (va = __fix_to_virt(FIX_FDT); va < end_va; va += PAGE_SIZE) - create_pte_mapping(fixmap_pte, va, - dtb_pa + (va - __fix_to_virt(FIX_FDT)), - PAGE_SIZE, PAGE_KERNEL); - - /* Save pointer to DTB for early FDT parsing */ - dtb_early_va = (void *)fix_to_virt(FIX_FDT) + (dtb_pa & ~PAGE_MASK); - /* Save physical address for memblock reservation */ - dtb_early_pa = dtb_pa; + /* Copy FDT to init memory for early scan */ + pa = load_pa + ((unsigned long)dtb_early_va - PAGE_OFFSET); + dtb_size = fdt_totalsize((void *)dtb_pa); + dtb_size = (dtb_size > DTB_EARLY_SIZE) ? DTB_EARLY_SIZE : dtb_size; + memcpy((void *)pa, (void *)dtb_pa, dtb_size); } static void __init setup_vm_final(void) @@ -481,6 +473,8 @@ static void __init setup_vm_final(void) local_flush_tlb_all(); } #else +void *dtb_early_va __initdata; + asmlinkage void __init setup_vm(uintptr_t dtb_pa) { #ifdef CONFIG_BUILTIN_DTB From patchwork Thu Jun 25 23:45:08 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Atish Patra X-Patchwork-Id: 11626985 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 8361560D for ; Fri, 26 Jun 2020 09:52:06 +0000 (UTC) Received: from merlin.infradead.org (merlin.infradead.org [205.233.59.134]) (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 2885A21531 for ; Fri, 26 Jun 2020 09:52:06 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="QzA4Ih9z"; dkim=fail reason="signature verification failed" (2048-bit key) header.d=wdc.com header.i=@wdc.com header.b="WwEZpo6I" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 2885A21531 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-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=merlin.20170209; h=Sender:Content-Transfer-Encoding: Content-Type:Cc: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:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=oKJRSB7fFaC7x6UpBvEQ3NddXg7wdhucUerzs98u+ig=; b=QzA4Ih9zbQVCPHw7QCXpQzgub 5nhDlnrSxQuRnJNOH39tYbKbHxU6riHjFDZoItmM0k1dqxqk0MaHo7GeJJAP3yt5yOkQ6yaVk76sK erjFvGkkMIvPcqbBWr8ZujzcI4fQWFiB6bZH9fw7iCk9CII9NHulkYey7RXOCFapaHC5WAFPgOV36 IAFItmxDPC2T24jd2PZ2rYiWj6SKeCsmHnpk4ZH3WD1LErsbwoA+2hWeLElAe1c5abECncZCwm8+G UPRfb/3aDO0+fuy71DkIRYAPp7dTFojP1kQmQUpzkGOsNDiV9lxa1k/3o0oehFyTPqyKb00Hvbq1D NPtXbgKCw==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1jokyr-0002Il-MY; Fri, 26 Jun 2020 09:49:10 +0000 Received: from esa2.hgst.iphmx.com ([68.232.143.124]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1jojlj-0002Se-4o; Fri, 26 Jun 2020 08:31:52 +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=1593160319; x=1624696319; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=M20HiMQD9oL/II9j9nUHwk6euEXhFNaJrLjuGryzaCg=; b=WwEZpo6IDDbEK0ba9AnBys9H2hWvlDjiRbarTG56Ypcc12dEUtQKc7At St5KBsuVnTueyYZL4D2fLddG+Jf3OHyHHiaj5/Y01TYG/nucc6cDNJP6D d21syZGOzvbyDmdf3OnC5z5slHqR4TuskVsA3rSdsnQhqknVTsqDUMh6E l4sty+VF8PQ7cp1mb4tD7N8SuI/SA8wX5oNcAKKsmChUR2mfTNAYDjN4O gJT1Sqx3AJRnVagOygZSO8R4pSgGZiZ87Y7b0WTUyag0YADjo9DpN/zc9 HfXBVwONfeRqxZLKm0HYowuTaH5iUFBfjhNUOrnTwaVC6MP+fB/dqtmQL g==; IronPort-SDR: ldnnOUVhv5g0HxhnaG3UIc7mrEfL4fKoiIPj0ggyownvXEQ8wIyEyJJDU3fxMSKfc1DCs/+pH6 LbTS1kuqXt9UVxuCJN76s+7nmL/fKl6XBR4vEMJGO5IwZls8gU76+0NpvLhuybykOH6wtgcNP7 IbnmOEPBDwtIS8eOiC+e57V6wEtaul807spELn/H5LydTcLKDA17xP/076pT6YywD+m3/BU/5Q pykpeF5tYMYkHTjsDFK0iOHO1qPM3XP90PzCw7BB7di1CPWFDny6pNzm+4lALK34eHXGU1m9Op rfs= X-IronPort-AV: E=Sophos;i="5.75,280,1589212800"; d="scan'208";a="243966114" Received: from h199-255-45-14.hgst.com (HELO uls-op-cesaep01.wdc.com) ([199.255.45.14]) by ob1.hgst.iphmx.com with ESMTP; 26 Jun 2020 07:45:56 +0800 IronPort-SDR: 4ASP1j9ICIDbfEG7WxflWKzcygyCIyqSDviyPXzpY2q45ge6Xk+JRohiOT7swSI5drGc6tl7yR CNfYYGB7Sdh8kELlzZWvTy6id+9hCbHBE= Received: from uls-op-cesaip01.wdc.com ([10.248.3.36]) by uls-op-cesaep01.wdc.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 25 Jun 2020 16:34:25 -0700 IronPort-SDR: khYCqebgabkJ7OmHX9caktKOD4V4TcpsYIxqNzM9dj5nEB94M2b+iarGnwOnVnuCSjRcLYVinX PHvoAzKFAmkw== WDCIronportException: Internal Received: from 2349pbt5e4f.ad.shared (HELO jedi-01.hgst.com) ([10.86.58.78]) by uls-op-cesaip01.wdc.com with ESMTP; 25 Jun 2020 16:45:24 -0700 From: Atish Patra To: linux-kernel@vger.kernel.org Subject: [RFC PATCH 03/11] RISC-V: Setup exception vector early Date: Thu, 25 Jun 2020 16:45:08 -0700 Message-Id: <20200625234516.31406-4-atish.patra@wdc.com> X-Mailer: git-send-email 2.24.0 In-Reply-To: <20200625234516.31406-1-atish.patra@wdc.com> References: <20200625234516.31406-1-atish.patra@wdc.com> MIME-Version: 1.0 X-Spam-Note: CRM114 invocation failed X-Spam-Score: -2.5 (--) X-Spam-Report: SpamAssassin version 3.4.4 on merlin.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 [68.232.143.124 listed in list.dnswl.org] -0.0 SPF_HELO_PASS SPF: HELO matches 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_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 -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: linux-efi@vger.kernel.org, Heinrich Schuchardt , Masahiro Yamada , Atish Patra , Palmer Dabbelt , linux-riscv@lists.infradead.org, Ard Biesheuvel , linux-arm-kernel@lists.infradead.org Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org The trap vector is set only in trap_init which may be too late in some cases. Early ioremap/efi spits many warning messages which may be useful. Setup the trap vector early so that any warning/bug can be handled before generic code invokes trap_init. Signed-off-by: Atish Patra --- arch/riscv/kernel/head.S | 10 ++++++++-- arch/riscv/kernel/smpboot.c | 1 - arch/riscv/kernel/traps.c | 8 +------- 3 files changed, 9 insertions(+), 10 deletions(-) diff --git a/arch/riscv/kernel/head.S b/arch/riscv/kernel/head.S index c5b529234ad8..eb123eda3663 100644 --- a/arch/riscv/kernel/head.S +++ b/arch/riscv/kernel/head.S @@ -77,10 +77,16 @@ relocate: csrw CSR_SATP, a0 .align 2 1: - /* Set trap vector to spin forever to help debug */ - la a0, .Lsecondary_park + /* Set trap vector to exception handler */ + la a0, handle_exception csrw CSR_TVEC, a0 + /* + * Set sup0 scratch register to 0, indicating to exception vector that + * we are presently executing in kernel. + */ + csrw CSR_SCRATCH, zero + /* Reload the global pointer */ .option push .option norelax diff --git a/arch/riscv/kernel/smpboot.c b/arch/riscv/kernel/smpboot.c index 4e9922790f6e..5a9c127a380e 100644 --- a/arch/riscv/kernel/smpboot.c +++ b/arch/riscv/kernel/smpboot.c @@ -154,7 +154,6 @@ asmlinkage __visible void smp_callin(void) mmgrab(mm); current->active_mm = mm; - trap_init(); notify_cpu_starting(smp_processor_id()); update_siblings_masks(smp_processor_id()); set_cpu_online(smp_processor_id(), 1); diff --git a/arch/riscv/kernel/traps.c b/arch/riscv/kernel/traps.c index ecec1778e3a4..fbedf6c018a3 100644 --- a/arch/riscv/kernel/traps.c +++ b/arch/riscv/kernel/traps.c @@ -174,13 +174,7 @@ int is_valid_bugaddr(unsigned long pc) } #endif /* CONFIG_GENERIC_BUG */ +/* stvec & scratch is already set from head.S */ void trap_init(void) { - /* - * Set sup0 scratch register to 0, indicating to exception vector - * that we are presently executing in the kernel - */ - csr_write(CSR_SCRATCH, 0); - /* Set the exception vector address */ - csr_write(CSR_TVEC, &handle_exception); } From patchwork Thu Jun 25 23:45:09 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Atish Patra X-Patchwork-Id: 11627161 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 0548B92A for ; Fri, 26 Jun 2020 10:54:24 +0000 (UTC) Received: from merlin.infradead.org (merlin.infradead.org [205.233.59.134]) (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 D0DDA206DD for ; Fri, 26 Jun 2020 10:54:23 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="ywOCj+Sq"; dkim=fail reason="signature verification failed" (2048-bit key) header.d=wdc.com header.i=@wdc.com header.b="XEJ8NRWh" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org D0DDA206DD 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-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=merlin.20170209; h=Sender:Content-Transfer-Encoding: Content-Type:Cc: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:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=xB0Tu9a7ApykZI/GNMJ3rBf4LwWF9Ihps6vRolrcV5M=; b=ywOCj+SqDdUw6zTjEuyRsTvfR 5DAV4y3rcThRb3oZjacIrY/DDWNUtOtB8VUYNDwC2Eq+akIiARBmJuVBQ/RlWhzU/pjUQRTX+Q8Ca VaQATzVLROgteq/r+4bnqxWNou2og0FPL/R4BUUaVelf7ST/HnVsivBGL9qZKMo1cqqAxemh8zQHy WWHVSJisn9IgnCQBxEoVMo6XvHbd4gjzrN4ndFDsm16uxfdFY12MGQq0sRN9M2ArrLrk3RQSUCEXc IAUwqTlgbRWIG6zE+EsR0UP4xi2KmcJHsbkw3SHOkMMw3Kr6xJLVlApEc85NgVWZprzAQg2iWTsyD iKeRyvEvg==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1joly9-0006SV-IV; Fri, 26 Jun 2020 10:52:30 +0000 Received: from esa2.hgst.iphmx.com ([68.232.143.124]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1jojm4-0002Se-Tx; Fri, 26 Jun 2020 08:32:17 +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=1593160352; x=1624696352; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=nglTD4UGuoe/uqWlZLpzP4BN9AAnND7WFwPf/vb2+9A=; b=XEJ8NRWhybQF1uWAaiLr+7vQ8qpgAZce7UVQ97TnCkJ7oQNpZ6aj7La7 E4otXJvNvQ2/aLFtgIHkOhcTCl5e++VwnO5Q0+OD74G04zsDo8r/X2huw oxVBr3YlMAgQwf2YZD3hCVn7UKkCk9eJz12M2ptspifT8HyQ5KArS03Ze rAt8vj7WUDC7tvXEIdo2YcIxIO2cfEGKnOrYVYFnI2wFSZr+KEWCC4Do/ DDE0KKz3D/eraQAMVmGCrtgU7ZlFoLjuGX1LygUrWTR4PyNoEvylQeBXu fr43pDQO01MJo73aECHc/ZMCpkrGpLgNl3zY2NSx5gqoul3JRrhH22Mkh g==; IronPort-SDR: bRSH5n2CJGHaNn/AHrJqp4g4xC0v3giBHUynPe4I9gZfHrNKfNVHUW4/8rZUGizL5gi1+OTtd5 dYPuLvBbpJUmgxZcALBFYtye1BKAxB0l3KgF8blihWk655O45y8mQpn+m1b17F1LNDmE0tIPm1 0OxM7w+OJUbMFTCZTFG+X/nSRALLfXghdU3q3ZAcmrm9X6W+RfWUBGx4Ux/Q+mpNdMWS9s9/hF ymCAtOUxUEy05mqy5DycFdLCRgOlhk23UksdjWRMSHS1gxT6HmcOIrehjoBx29wmBAKQUaRpw1 ic8= X-IronPort-AV: E=Sophos;i="5.75,280,1589212800"; d="scan'208";a="243966115" Received: from h199-255-45-14.hgst.com (HELO uls-op-cesaep01.wdc.com) ([199.255.45.14]) by ob1.hgst.iphmx.com with ESMTP; 26 Jun 2020 07:45:57 +0800 IronPort-SDR: sijrQrMpmhVeYSVK+ncSroltLT41K2RB5GRqVNmkLPeolXqXJHcQw01DvDOM8noJS9dClWsIWs XetLOeeoW+DO/hHT97Uzsam1y56jVqfbo= Received: from uls-op-cesaip01.wdc.com ([10.248.3.36]) by uls-op-cesaep01.wdc.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 25 Jun 2020 16:34:25 -0700 IronPort-SDR: fe/XELAziUbreMEong29tU4drIjZjt+qnFt/cibHloZAYNzkYSaKE5LEzK2JOYFkM7sdc0IS17 0AQiofyTXRmQ== WDCIronportException: Internal Received: from 2349pbt5e4f.ad.shared (HELO jedi-01.hgst.com) ([10.86.58.78]) by uls-op-cesaip01.wdc.com with ESMTP; 25 Jun 2020 16:45:25 -0700 From: Atish Patra To: linux-kernel@vger.kernel.org Subject: [RFC PATCH 04/11] RISC-V: Add early ioremap support Date: Thu, 25 Jun 2020 16:45:09 -0700 Message-Id: <20200625234516.31406-5-atish.patra@wdc.com> X-Mailer: git-send-email 2.24.0 In-Reply-To: <20200625234516.31406-1-atish.patra@wdc.com> References: <20200625234516.31406-1-atish.patra@wdc.com> MIME-Version: 1.0 X-Spam-Note: CRM114 invocation failed X-Spam-Score: -2.5 (--) X-Spam-Report: SpamAssassin version 3.4.4 on merlin.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 [68.232.143.124 listed in list.dnswl.org] -0.0 SPF_HELO_PASS SPF: HELO matches 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_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 -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: linux-efi@vger.kernel.org, Heinrich Schuchardt , Masahiro Yamada , Atish Patra , Palmer Dabbelt , linux-riscv@lists.infradead.org, Ard Biesheuvel , linux-arm-kernel@lists.infradead.org Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org UEFI uses early IO or memory mappings for runtime services before normal ioremap() is usable. Add the necessary fixmap bindings and pmd mappings for generic ioremap support to work. Signed-off-by: Atish Patra --- arch/riscv/Kconfig | 1 + arch/riscv/include/asm/Kbuild | 1 + arch/riscv/include/asm/fixmap.h | 13 +++++++++++++ arch/riscv/include/asm/io.h | 1 + arch/riscv/kernel/setup.c | 1 + arch/riscv/mm/init.c | 33 +++++++++++++++++++++++++++++++++ 6 files changed, 50 insertions(+) diff --git a/arch/riscv/Kconfig b/arch/riscv/Kconfig index 128192e14ff2..fda90093e588 100644 --- a/arch/riscv/Kconfig +++ b/arch/riscv/Kconfig @@ -32,6 +32,7 @@ config RISCV select GENERIC_ARCH_TOPOLOGY if SMP select GENERIC_ATOMIC64 if !64BIT select GENERIC_CLOCKEVENTS + select GENERIC_EARLY_IOREMAP select GENERIC_GETTIMEOFDAY if HAVE_GENERIC_VDSO select GENERIC_IOREMAP select GENERIC_IRQ_MULTI_HANDLER diff --git a/arch/riscv/include/asm/Kbuild b/arch/riscv/include/asm/Kbuild index 3d9410bb4de0..59dd7be55005 100644 --- a/arch/riscv/include/asm/Kbuild +++ b/arch/riscv/include/asm/Kbuild @@ -1,4 +1,5 @@ # SPDX-License-Identifier: GPL-2.0 +generic-y += early_ioremap.h generic-y += extable.h generic-y += flat.h generic-y += kvm_para.h diff --git a/arch/riscv/include/asm/fixmap.h b/arch/riscv/include/asm/fixmap.h index 11613f38228a..54cbf07fb4e9 100644 --- a/arch/riscv/include/asm/fixmap.h +++ b/arch/riscv/include/asm/fixmap.h @@ -27,6 +27,19 @@ enum fixed_addresses { FIX_TEXT_POKE1, FIX_TEXT_POKE0, FIX_EARLYCON_MEM_BASE, + + __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 3835c3295dc5..c025a746a148 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 diff --git a/arch/riscv/kernel/setup.c b/arch/riscv/kernel/setup.c index 8519a6d29857..1244b433fe7c 100644 --- a/arch/riscv/kernel/setup.c +++ b/arch/riscv/kernel/setup.c @@ -72,6 +72,7 @@ void __init setup_arch(char **cmdline_p) *cmdline_p = boot_command_line; + early_ioremap_setup(); parse_early_param(); setup_bootmem(); diff --git a/arch/riscv/mm/init.c b/arch/riscv/mm/init.c index c18c94ab3b23..bad60686d080 100644 --- a/arch/riscv/mm/init.c +++ b/arch/riscv/mm/init.c @@ -377,6 +377,9 @@ asmlinkage void __init setup_vm(uintptr_t dtb_pa) uintptr_t load_pa = (uintptr_t)(&_start); uintptr_t load_sz = (uintptr_t)(&_end) - load_pa; uintptr_t map_size = best_map_size(load_pa, MAX_EARLY_MAPPING_SIZE); +#ifndef __PAGETABLE_PMD_FOLDED + pmd_t fix_bmap_spmd, fix_bmap_epmd; +#endif va_pa_offset = PAGE_OFFSET - load_pa; pfn_base = PFN_DOWN(load_pa); @@ -427,6 +430,36 @@ asmlinkage void __init setup_vm(uintptr_t dtb_pa) dtb_size = fdt_totalsize((void *)dtb_pa); dtb_size = (dtb_size > DTB_EARLY_SIZE) ? DTB_EARLY_SIZE : dtb_size; memcpy((void *)pa, (void *)dtb_pa, dtb_size); + + /* + * Bootime fixmap only can handle PMD_SIZE mapping. Thus, boot-ioremap + * range can not span multiple pmds. + */ + BUILD_BUG_ON((__fix_to_virt(FIX_BTMAP_BEGIN) >> PMD_SHIFT) + != (__fix_to_virt(FIX_BTMAP_END) >> PMD_SHIFT)); + +#ifndef __PAGETABLE_PMD_FOLDED + /* + * Early ioremap fixmap is already created as it lies within first 2MB + * of fixmap region. We always map PMD_SIZE. Thus, both FIX_BTMAP_END + * FIX_BTMAP_BEGIN should lie in the same pmd. Verify that and warn + * the user if not. + */ + fix_bmap_spmd = fixmap_pmd[pmd_index(__fix_to_virt(FIX_BTMAP_BEGIN))]; + fix_bmap_epmd = fixmap_pmd[pmd_index(__fix_to_virt(FIX_BTMAP_END))]; + if (pmd_val(fix_bmap_spmd) != pmd_val(fix_bmap_epmd)) { + WARN_ON(1); + pr_warn("fixmap btmap start [%08lx] != end [%08lx]\n", + pmd_val(fix_bmap_spmd), pmd_val(fix_bmap_epmd)); + pr_warn("fix_to_virt(FIX_BTMAP_BEGIN): %08lx\n", + fix_to_virt(FIX_BTMAP_BEGIN)); + pr_warn("fix_to_virt(FIX_BTMAP_END): %08lx\n", + fix_to_virt(FIX_BTMAP_END)); + + pr_warn("FIX_BTMAP_END: %d\n", FIX_BTMAP_END); + pr_warn("FIX_BTMAP_BEGIN: %d\n", FIX_BTMAP_BEGIN); + } +#endif } static void __init setup_vm_final(void) From patchwork Thu Jun 25 23:45:10 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Atish Patra X-Patchwork-Id: 11626989 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 7A7E392A for ; Fri, 26 Jun 2020 09:52:35 +0000 (UTC) Received: from merlin.infradead.org (merlin.infradead.org [205.233.59.134]) (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 4E54F21531 for ; Fri, 26 Jun 2020 09:52:35 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="m/QO4nGp"; dkim=fail reason="signature verification failed" (2048-bit key) header.d=wdc.com header.i=@wdc.com header.b="aYrU/9rV" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 4E54F21531 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-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=merlin.20170209; h=Sender:Content-Transfer-Encoding: Content-Type:Cc: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:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=R/zBLKP2v4SY491xWJsmzYgtLRUy0G+uifOUnL4DL4M=; b=m/QO4nGpfSMEH4lZu3s79FU/H ID/BNtQsuDxqGmoyfOiNBGcP7dOGPOUHLwohosdtGlRLuGEfoOOu5b1M2wXkaK39bKXkKvkV7mj2R FYLrWJBO0UtlOfUvGxTgfitSZTlB+RHr8premp7Y9riYU9tGZ8ktAgy03UThIVa6RwHXTLxK/jUid 6KalAezTcgAFz+fujsW6CZwx0dtvR7hQ/Ewh3mcGL75ybAn4J8mFMIxVT84YxYusB4Ti0Bix9XfHw LKdKOk0SNt5yCS5xVEzzPOj1dg2mh1JLJA+0ZiFnIx+KhAVRZKrfF7uWEMAD2EKyqWskE3y6UVaNK w+Geu03jA==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1jol09-0002ih-SY; Fri, 26 Jun 2020 09:50:29 +0000 Received: from esa2.hgst.iphmx.com ([68.232.143.124]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1jojmT-0002Se-Ct; Fri, 26 Jun 2020 08:32:38 +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=1593160339; x=1624696339; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=e1f5tFToh6jF2Fr3c6Bri7MNiVrYpT85jVmyBw2a1o8=; b=aYrU/9rVZ0hMu3SpQhDlPaMyd0HDaP21YSDlQnEwjzR+Yt13uj074FEj KPy2tX8bO91EX5nu18k9vDULWZLEbA+TFoa2roe1R/OEFydNWnxIYcl6r XYlHIrC/AMuJ+S5uXmSxq773XYjigZrdcNRKjmikSHwQKsbCczQ6eg5+/ Mz+6QDrxHqj5LuZh6xC2pWIlNHU5VVba/KB5JNQYv2Wn7Bnew+KMum1Nu 3rPzTRR1DE8WLMhnAeDqP2vRQLb4wKOmiYTSs79pkpRN/UU2EqpdCpIqn Q1o9E5s/DglC2GlBdTwSdWwSbqDqY5X4zBJeEx3BQAEKl8LWbhq9KgO/A Q==; IronPort-SDR: 3C45ie6KGoNNXNnAoh5a7V/Qm+JMg4g+69iGD36qD9Hj50c4lV7LAJURzN+btR3YgZCwulh0bm H8LspNpCeNla9qLonXtAGI0O3UJ89+tiNcWjtOK8Fvp8/A3P4wMHTRuFAFDPbL4wYDkNhhU1Jk 7wBUgxAs+Czlzke7O7YCRwCA0DPdVBLRs7RxOJtNMrt9uDlGPT4LlDj83g/XdtsOK+3XpQGF4l 6DL2+oycGkPKBrHOsxEBRikzkx2MM51FiKnhsduzeQ+jystN29rS+SGrHWZOO4ezmw34gZpIl6 RzY= X-IronPort-AV: E=Sophos;i="5.75,280,1589212800"; d="scan'208";a="243966117" Received: from h199-255-45-14.hgst.com (HELO uls-op-cesaep01.wdc.com) ([199.255.45.14]) by ob1.hgst.iphmx.com with ESMTP; 26 Jun 2020 07:45:58 +0800 IronPort-SDR: 1+rJeBaCAD2XncIQUuMdrCpHQ4Emw1o87TeREXaFO7oEOMvzaFGmTdyKiWsm7QT2aNUfFgoiIJ fhqzuCTAo6pJstegHJWT3Koz43/tr4LC4= Received: from uls-op-cesaip01.wdc.com ([10.248.3.36]) by uls-op-cesaep01.wdc.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 25 Jun 2020 16:34:26 -0700 IronPort-SDR: x27YsbO1KVXuwcO1coWKuCCOUz0CEkeOSTXMxHLCyjOMlyEdoh9s5hWmoxbaG9WTGee2GcC+DR DbQR7vLieVwg== WDCIronportException: Internal Received: from 2349pbt5e4f.ad.shared (HELO jedi-01.hgst.com) ([10.86.58.78]) by uls-op-cesaip01.wdc.com with ESMTP; 25 Jun 2020 16:45:26 -0700 From: Atish Patra To: linux-kernel@vger.kernel.org Subject: [RFC PATCH 05/11] RISC-V: Set maximum number of mapped pages correctly Date: Thu, 25 Jun 2020 16:45:10 -0700 Message-Id: <20200625234516.31406-6-atish.patra@wdc.com> X-Mailer: git-send-email 2.24.0 In-Reply-To: <20200625234516.31406-1-atish.patra@wdc.com> References: <20200625234516.31406-1-atish.patra@wdc.com> MIME-Version: 1.0 X-Spam-Note: CRM114 invocation failed X-Spam-Score: -2.5 (--) X-Spam-Report: SpamAssassin version 3.4.4 on merlin.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 [68.232.143.124 listed in list.dnswl.org] -0.0 SPF_HELO_PASS SPF: HELO matches 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_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 -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: linux-efi@vger.kernel.org, Heinrich Schuchardt , Masahiro Yamada , Atish Patra , Palmer Dabbelt , linux-riscv@lists.infradead.org, Ard Biesheuvel , linux-arm-kernel@lists.infradead.org Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org Currently, maximum number of mapper pages are set to the pfn calculated from the memblock size of the memblock containing kernel. This will work until that memblock spans the entire memory. However, it will be set to a wrong value if there are multiple memblocks defined in kernel (e.g. with efi runtime services). Set the the maximum value to the pfn calculated from dram size. Signed-off-by: Atish Patra --- arch/riscv/mm/init.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/arch/riscv/mm/init.c b/arch/riscv/mm/init.c index bad60686d080..4021706aef81 100644 --- a/arch/riscv/mm/init.c +++ b/arch/riscv/mm/init.c @@ -147,9 +147,9 @@ void __init setup_bootmem(void) /* Reserve from the start of the kernel to the end of the kernel */ memblock_reserve(vmlinux_start, vmlinux_end - vmlinux_start); - set_max_mapnr(PFN_DOWN(mem_size)); max_pfn = PFN_DOWN(memblock_end_of_DRAM()); max_low_pfn = max_pfn; + set_max_mapnr(max_low_pfn); #ifdef CONFIG_BLK_DEV_INITRD setup_initrd(); From patchwork Thu Jun 25 23:45:11 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Atish Patra X-Patchwork-Id: 11626987 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 2D72560D for ; Fri, 26 Jun 2020 09:52:27 +0000 (UTC) Received: from merlin.infradead.org (merlin.infradead.org [205.233.59.134]) (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 0617A21531 for ; Fri, 26 Jun 2020 09:52:27 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="miaZq8b1"; dkim=fail reason="signature verification failed" (2048-bit key) header.d=wdc.com header.i=@wdc.com header.b="GLm930Ii" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 0617A21531 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-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=merlin.20170209; h=Sender:Content-Transfer-Encoding: Content-Type:Cc: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:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=W30GS3hDTMb4WeU4c1ZG5PzTCqEqmLdqeapSQlKHH+o=; b=miaZq8b1cLPI/gHVFVr+Q5Tec ZwFF4+zFQUO4yzD+LSxL9ghsDn27AjYIFKZD+mI7sQGDExTP/Q7GeAU595YZW5W+98zJldhCLcK9C TybPyoiYR1XlLTNy4uv24VKukRT+6NwVPFURwqIaSNw3118jxLsAANvC81M15aiZmqkb98hW6d+Nv riN4NDURLwu/Zt5m2pJ+/TSpXnGBuVnETey2H3Bl9spGOpGUWvG7M8j6mvJaJV1nejvJQv55cWugN 9IhI09mF2cxHGLV3ywAxj5OG29hmx7zGx9w2hI68oY2bcpKyyau1PAXB9k0HFqISKpNBr2zm4Qbqq 8SDj58LUw==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1jol0G-0002kb-UZ; Fri, 26 Jun 2020 09:50:36 +0000 Received: from esa2.hgst.iphmx.com ([68.232.143.124]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1jojmo-0002Se-DN; Fri, 26 Jun 2020 08:33:08 +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=1593160359; x=1624696359; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=YBy5J4GUHkZ0slWQ+5rpmDzLOi4g2OFkey3S0ni3vEo=; b=GLm930IispZf8DTddvvOK0t8b5Rzu/B1JSH83PAFRDZK5krfwyTwA5ca ZKzsqzZdqHG0oZeNrBv8SFsP1zLjjew8y1eVLTN4nGYZn5mal9EdgXbOq ODb4tXrreDdRwsNVMkkv6UrIjyINqbmUMAu84dttYMULoygwqQ5eCGlo6 ODFlg3delzY9Fjv0xcq7fXHRckzSF+uCSoeXmhaVkl4z0WKC2RBcYJ9ck Jh3iUfPUDFkRBQRXJHHFhugxAsjj7KIyb6c6Bt51UdNjIVnOZncpDZ2TH In07MhHu3mN+96kZL1U0laM7FlRMToZqHg2C7nPZJo1stacjs/JVspY5+ A==; IronPort-SDR: LYfo/DshYhqLiVQGwRYSFcpo1g9GGPbuQ9e18TDiqGC0zb0pewNXQ2eLYr+Mw51wK3LRhc49Tc 0tjkry9IFnuoG067LLBNkVi3q8UXqtMTEpBLFO7p/jfVpbOvN89Fjah6X4T2rC/BchcwvmmQDZ 8csYy9ptI5web3BwsGPmv+jjbOHNWdSodS7CREtnAU8w0rukEKhHtA2LEwLucEjAxJkwjgSUgm mdaYZy0itgoXZgLdPCB2h1Ce81T6LzVfNUKGxbj3Emp2MUbj3RIuakgGsLRQXr5UZxHWQZCCP2 Kro= X-IronPort-AV: E=Sophos;i="5.75,280,1589212800"; d="scan'208";a="243966119" Received: from h199-255-45-14.hgst.com (HELO uls-op-cesaep01.wdc.com) ([199.255.45.14]) by ob1.hgst.iphmx.com with ESMTP; 26 Jun 2020 07:45:58 +0800 IronPort-SDR: FtRgoU1Ru7pv0RDCl3f6N1yhy2kUdDASxkpo7Q2mD3uUZfkIQFdzRg5k/qW7alTHx9aWSMw9in x/JYqDVcdBb88bLIM+J/HUAzBUuIvWWoU= Received: from uls-op-cesaip01.wdc.com ([10.248.3.36]) by uls-op-cesaep01.wdc.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 25 Jun 2020 16:34:26 -0700 IronPort-SDR: omPnXbB+TYLoTkN1Npd9t1nvmQHGX5tG5Znu8goYNz213K5CBAQXt/9Te3XTTQppRyp0s8My2s L3qp9Y90whDQ== WDCIronportException: Internal Received: from 2349pbt5e4f.ad.shared (HELO jedi-01.hgst.com) ([10.86.58.78]) by uls-op-cesaip01.wdc.com with ESMTP; 25 Jun 2020 16:45:26 -0700 From: Atish Patra To: linux-kernel@vger.kernel.org Subject: [RFC PATCH 06/11] riscv: Parse all memory blocks to remove unusable memory Date: Thu, 25 Jun 2020 16:45:11 -0700 Message-Id: <20200625234516.31406-7-atish.patra@wdc.com> X-Mailer: git-send-email 2.24.0 In-Reply-To: <20200625234516.31406-1-atish.patra@wdc.com> References: <20200625234516.31406-1-atish.patra@wdc.com> MIME-Version: 1.0 X-Spam-Note: CRM114 invocation failed X-Spam-Score: -2.5 (--) X-Spam-Report: SpamAssassin version 3.4.4 on merlin.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 [68.232.143.124 listed in list.dnswl.org] -0.0 SPF_HELO_PASS SPF: HELO matches 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_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 -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: linux-efi@vger.kernel.org, Heinrich Schuchardt , Masahiro Yamada , Atish Patra , Palmer Dabbelt , linux-riscv@lists.infradead.org, Ard Biesheuvel , linux-arm-kernel@lists.infradead.org Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org Currently, maximum physical memory allowed is equal to -PAGE_OFFSET. That's why we remove any memory blocks spanning beyond that size. However, it is done only for memblock containing linux kernel which will not work if there are multiple memblocks. Process all memory blocks to figure out how much memory needs to be removed and remove at the end instead of updating the memblock list in place. Signed-off-by: Atish Patra --- arch/riscv/mm/init.c | 31 +++++++++++++++++-------------- 1 file changed, 17 insertions(+), 14 deletions(-) diff --git a/arch/riscv/mm/init.c b/arch/riscv/mm/init.c index 4021706aef81..c5268fe6e6de 100644 --- a/arch/riscv/mm/init.c +++ b/arch/riscv/mm/init.c @@ -123,26 +123,29 @@ void __init setup_bootmem(void) { struct memblock_region *reg; phys_addr_t mem_size = 0; + phys_addr_t total_mem = 0; + phys_addr_t mem_start, end = 0; phys_addr_t vmlinux_end = __pa_symbol(&_end); phys_addr_t vmlinux_start = __pa_symbol(&_start); /* Find the memory region containing the kernel */ for_each_memblock(memory, reg) { - phys_addr_t end = reg->base + reg->size; - - if (reg->base <= vmlinux_start && vmlinux_end <= end) { - mem_size = min(reg->size, (phys_addr_t)-PAGE_OFFSET); - - /* - * Remove memblock from the end of usable area to the - * end of region - */ - if (reg->base + mem_size < end) - memblock_remove(reg->base + mem_size, - end - reg->base - mem_size); - } + end = reg->base + reg->size; + if (!total_mem) + mem_start = reg->base; + if (reg->base <= vmlinux_start && vmlinux_end <= end) + BUG_ON(reg->size == 0); + total_mem = total_mem + reg->size; } - BUG_ON(mem_size == 0); + + /* + * Remove memblock from the end of usable area to the + * end of region + */ + mem_size = min(total_mem, (phys_addr_t)-PAGE_OFFSET); + if (mem_start + mem_size < end) + memblock_remove(mem_start + mem_size, + end - mem_start - mem_size); /* Reserve from the start of the kernel to the end of the kernel */ memblock_reserve(vmlinux_start, vmlinux_end - vmlinux_start); From patchwork Thu Jun 25 23:45:12 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Atish Patra X-Patchwork-Id: 11626993 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 9467860D for ; Fri, 26 Jun 2020 09:53:48 +0000 (UTC) Received: from merlin.infradead.org (merlin.infradead.org [205.233.59.134]) (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 55FE721531 for ; Fri, 26 Jun 2020 09:53:48 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="GtiZS3dN"; dkim=fail reason="signature verification failed" (2048-bit key) header.d=wdc.com header.i=@wdc.com header.b="STZouody" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 55FE721531 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-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=merlin.20170209; h=Sender:Content-Transfer-Encoding: Content-Type:Cc: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:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=6C2Q/llwJF2+h76tMQjr68y/7x4+1wRyx+GYUqhdsm8=; b=GtiZS3dN93YbwlxFoj49Xe9rL KL9IGRbftMAWShrVRm5JNmJCtgVDAR8F/TxEe14a17hnslXo6tJUZrdW2SciDgcRS2ZxuwlTnTW9C NvXXF1OMnPalKGz+XLn+PbdONQg6vKzYpjvLEDAGMF0QkdvJ7pvrnmNWPT1MIzX6sIfA7gy32lmkl ySfOzCTWjm7r+MEKkLQj9mQSHjie9Nz1rZwN9+iBNkWnJssPKlvOSOtqu6jOwzLKUX6jcQXL5YjNw mUfFFB/EZz6yO3EbzOpuYU5r3u8CQf9cuXg/mM9bnr7lekub/JhUjepNLOObcoEgS5lQ2QUt2z8O1 Zh8z654gw==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1jol0P-0002nx-Q1; Fri, 26 Jun 2020 09:50:45 +0000 Received: from esa2.hgst.iphmx.com ([68.232.143.124]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1jojnI-0002Se-O1; Fri, 26 Jun 2020 08:33:31 +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=1593160405; x=1624696405; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=M/aLmMoaf+R1cfTR4Mi4doOLt0MJCtDnvFjCl4cVqNk=; b=STZouody1zwMIXI3S2FKaTn9h46bBago7NH3Pdp7J/4I0sbmLmvo+kwx oeLCV6fi+s5FQRTFCGO8Fi5ap5zmonF2SiI5zWzitkD35+qHDeOvs3XeM 8Ypkc18Jrwp2FcwVMr2Zk3E3cVLc51JlFg9DicOGGcrsP/BI2gjF3CX3n dG7iekK+phBPyKqTjmrcxdMrfKJkSv1bdGHX51tOAA6UjjwUWie/NPkxk Q+r25Ul12BAz3C9tIJ3M0Okse/OTp6zazRqgwLvZ4vC8govnrm9ADvSTO CjbzvNmDvMYnvKmV/0hkIHW7cq91CEB/E5nvcIoDnpZw/hTwLiryTwQEh Q==; IronPort-SDR: 3JKjASaZsXLb5USMDrV2CAcxss2JLjtSORhf4ec0FbCbfDlHxNnvLMujS/a/4L3p0xm5xMZjF0 E4nU0zM4jlSS5bTyoFkgCeNZNWB+MDiRhW+AN5zw+iATaC4xLmcW5lzlNJS5QK27B9Q+rbIZFR pfKpwtaf/UXgAk5iJyOU0prsFVVJbhrN00L0+eGONTwE4JstV2Lzjg6OX3Gtoab6/PMJ27SNhu ORWHSbnRSriOVnrd8CNoiwsXy2oWF06XqnX/1x6Brx/7VRmusbqaFhesFLKmTvMLF4pSuRhrC1 6Mo= X-IronPort-AV: E=Sophos;i="5.75,280,1589212800"; d="scan'208";a="243966122" Received: from h199-255-45-14.hgst.com (HELO uls-op-cesaep01.wdc.com) ([199.255.45.14]) by ob1.hgst.iphmx.com with ESMTP; 26 Jun 2020 07:45:59 +0800 IronPort-SDR: OJ4ZZ1wmDZXWhSV5XMzf/hgYCpIL4BI7/8W+asnozef6Zbl8HT9bD9LegxFDzUqdd8NLkaD+vm iHinNe445+xB/TE05zcphDSQ86JsxLOhg= Received: from uls-op-cesaip01.wdc.com ([10.248.3.36]) by uls-op-cesaep01.wdc.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 25 Jun 2020 16:34:27 -0700 IronPort-SDR: rsP8xzULUfBFMDuMCtJGe0TMaOrFxT6DTyZwDjC5tdJA7trEYutCByptrNB4uMfLlWXegYkKzb pktVpb+3JPPA== WDCIronportException: Internal Received: from 2349pbt5e4f.ad.shared (HELO jedi-01.hgst.com) ([10.86.58.78]) by uls-op-cesaip01.wdc.com with ESMTP; 25 Jun 2020 16:45:26 -0700 From: Atish Patra To: linux-kernel@vger.kernel.org Subject: [RFC PATCH 07/11] include: pe.h: Add RISC-V related PE definition Date: Thu, 25 Jun 2020 16:45:12 -0700 Message-Id: <20200625234516.31406-8-atish.patra@wdc.com> X-Mailer: git-send-email 2.24.0 In-Reply-To: <20200625234516.31406-1-atish.patra@wdc.com> References: <20200625234516.31406-1-atish.patra@wdc.com> MIME-Version: 1.0 X-Spam-Note: CRM114 invocation failed X-Spam-Score: -2.5 (--) X-Spam-Report: SpamAssassin version 3.4.4 on merlin.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 [68.232.143.124 listed in list.dnswl.org] -0.0 SPF_HELO_PASS SPF: HELO matches 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_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 -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: linux-efi@vger.kernel.org, Heinrich Schuchardt , Masahiro Yamada , Palmer Dabbelt , Atish Patra , Palmer Dabbelt , linux-riscv@lists.infradead.org, Ard Biesheuvel , linux-arm-kernel@lists.infradead.org Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org Define RISC-V related machine types. Signed-off-by: Atish Patra Reviewed-by: Palmer Dabbelt Link: https://lore.kernel.org/r/20200415195422.19866-3-atish.patra@wdc.com Signed-off-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 Jun 25 23:45:13 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Atish Patra X-Patchwork-Id: 11627339 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 B770E161F for ; Fri, 26 Jun 2020 12:05:27 +0000 (UTC) Received: from merlin.infradead.org (merlin.infradead.org [205.233.59.134]) (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 3F371206A1 for ; Fri, 26 Jun 2020 12:05:27 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="GNZ9ofgf"; dkim=fail reason="signature verification failed" (2048-bit key) header.d=wdc.com header.i=@wdc.com header.b="MS9e6WyZ" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 3F371206A1 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-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=merlin.20170209; h=Sender:Content-Transfer-Encoding: Content-Type:Cc: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:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=HX2fKRm9V4TCmXvenNIzc8gQcLQDUAnVYYevrvk9TnQ=; b=GNZ9ofgfdyVwHJrrp/LFcp53l cqz1lpRZr3sUMC5oMQJzmSA2Eixk76R9tpujnonzPaIErq2uCppJT7N8NScb/yfF80muVEJnCJe+h +2aFyy+ScDTMKCCgd5paNE7BLAlPpUGsWFnMFBBtICX2JDAH7xjVA1NEqSvF241sR3FGGteXMaDvw 0lq22NW5WOYiOhcC1gvHMRAMXQrAjTu7xsvBgMLT9j7Ud3UuN0Yek5dyYkXglU7aZwA9TX2Qcb008 aopzaVGJro9+NoM/ke1SRZhTdScrtLPOJiAwnWGDC6y8qlqgcash3xMsX2vGQwckzQvaRxxmhDfjq ODzgt2Tew==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1jon4P-0002hF-JR; Fri, 26 Jun 2020 12:03:01 +0000 Received: from esa2.hgst.iphmx.com ([68.232.143.124]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1jojnf-0002Se-Vv; Fri, 26 Jun 2020 08:33:54 +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=1593160440; x=1624696440; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=spvJLOrCMG2kB0qB9a2UXS0zgvYoQmwLv54vbaGUmPA=; b=MS9e6WyZM5sy+4WjUCBUjS4frNK3N2uCEKOy0CLRR91umb8HJxIYq1QV 43Jgk4qKcgaDFcBcicsUP0SfIaHVY4A9rGQfX+tycUnGbEnacCpekz6ne BEWO7wgyyr0W+NETwD2Lb4oYgGCKoZZx/ycnYl04UXXcR7lBXXv/nYRKx 5AoiO8FGxz5WU/kMCzZbyQ+CrdMzkNLzY8imnL4aLKBnHAT7kbdGFl04p /OLL9fWb9npUxZc7iXkvnhF9j3ZEFleo9WjDBCvKnZ7DqbxdxEYnbZREL lOocbj3rFjwLkWKVDjuklCmspA1Ayb3/TpU5jWqh+2zYJxRXomK+lewbL w==; IronPort-SDR: RX4Exujo0YnIOcNMicJSv796BJhcVUwtNXWdxRFf67WB3XhctC5a9GYGKPqVMClqYQjXlNGC5J D0e3E8nM375iF5QVDj1ou3wDOoxoM1Ok4ttwNT9GyF40EBQMxPzMemRk0jtxh7WpK8b72MvlkY elLqCxoT+UbdEBJIb8LnNyTTSsGJVyQxrGxymo8spzXr6oy92PGUx9xbddc7hpWk55Z+8Azt+d SQDiHzbM2/xrTfS6czYXAJ8tEBxyzlUeSQ/a1OuZHVBomcSnQ1ctBS/1GkoZk5csEKUKwxgetV JCw= X-IronPort-AV: E=Sophos;i="5.75,280,1589212800"; d="scan'208";a="243966125" Received: from h199-255-45-14.hgst.com (HELO uls-op-cesaep01.wdc.com) ([199.255.45.14]) by ob1.hgst.iphmx.com with ESMTP; 26 Jun 2020 07:46:00 +0800 IronPort-SDR: zPie1YbSltBRPdDdFZtWL+lgw4JRXbyMMap9MPDk8NycX43dXnykfOPLzmtLdmew9aCQds6/8z ElfpChSGxUUbB+GwKCdSyEGIlKbH6fQ4U= Received: from uls-op-cesaip01.wdc.com ([10.248.3.36]) by uls-op-cesaep01.wdc.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 25 Jun 2020 16:34:27 -0700 IronPort-SDR: jHOcJWfPsMX2afFQixABxURxkhz6t+mOGwqtz4yIaLHY9h7fLrTX3jmfm1uO3kV2J2/eUa8V52 Qtn0dEAh6AIQ== WDCIronportException: Internal Received: from 2349pbt5e4f.ad.shared (HELO jedi-01.hgst.com) ([10.86.58.78]) by uls-op-cesaip01.wdc.com with ESMTP; 25 Jun 2020 16:45:27 -0700 From: Atish Patra To: linux-kernel@vger.kernel.org Subject: [RFC PATCH 08/11] RISC-V: Add PE/COFF header for EFI stub Date: Thu, 25 Jun 2020 16:45:13 -0700 Message-Id: <20200625234516.31406-9-atish.patra@wdc.com> X-Mailer: git-send-email 2.24.0 In-Reply-To: <20200625234516.31406-1-atish.patra@wdc.com> References: <20200625234516.31406-1-atish.patra@wdc.com> MIME-Version: 1.0 X-Spam-Note: CRM114 invocation failed X-Spam-Score: -2.5 (--) X-Spam-Report: SpamAssassin version 3.4.4 on merlin.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 [68.232.143.124 listed in list.dnswl.org] -0.0 SPF_HELO_PASS SPF: HELO matches 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_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 -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: linux-efi@vger.kernel.org, Heinrich Schuchardt , Masahiro Yamada , Atish Patra , Palmer Dabbelt , linux-riscv@lists.infradead.org, Ard Biesheuvel , linux-arm-kernel@lists.infradead.org Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=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 Link: https://lore.kernel.org/r/20200421033336.9663-3-atish.patra@wdc.com [ardb: - use C prefix for c.li to ensure the expected opcode is emitted - align all image sections according to PE/COFF section alignment ] Signed-off-by: Ard Biesheuvel --- arch/riscv/include/asm/sections.h | 13 ++++ arch/riscv/kernel/Makefile | 4 ++ arch/riscv/kernel/efi-header.S | 104 ++++++++++++++++++++++++++++++ arch/riscv/kernel/head.S | 16 +++++ arch/riscv/kernel/image-vars.h | 51 +++++++++++++++ arch/riscv/kernel/vmlinux.lds.S | 22 ++++++- 6 files changed, 208 insertions(+), 2 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/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 b355cf485671..6f7a3b3771fd 100644 --- a/arch/riscv/kernel/Makefile +++ b/arch/riscv/kernel/Makefile @@ -32,6 +32,10 @@ obj-y += patch.o obj-$(CONFIG_MMU) += vdso.o vdso/ obj-$(CONFIG_RISCV_M_MODE) += clint.o traps_misaligned.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..822b4c9ff2bb --- /dev/null +++ b/arch/riscv/kernel/efi-header.S @@ -0,0 +1,104 @@ +/* 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: +#ifdef CONFIG_64BIT + .short IMAGE_FILE_MACHINE_RISCV64 // Machine +#else + .short IMAGE_FILE_MACHINE_RISCV32 // Machine +#endif + .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 __pecoff_text_end - efi_header_end // SizeOfCode + .long __pecoff_data_virt_size // SizeOfInitializedData + .long 0 // SizeOfUninitializedData + .long __efistub_efi_pe_entry - _start // AddressOfEntryPoint + .long efi_header_end - _start // BaseOfCode + +extra_header_fields: + .quad 0 // ImageBase + .long PECOFF_SECTION_ALIGNMENT // 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 __pecoff_text_end - efi_header_end // VirtualSize + .long efi_header_end - _start // VirtualAddress + .long __pecoff_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 __pecoff_data_virt_size // VirtualSize + .long __pecoff_text_end - _start // VirtualAddress + .long __pecoff_data_raw_size // SizeOfRawData + .long __pecoff_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 + + .balign 0x1000 +efi_header_end: + .endm diff --git a/arch/riscv/kernel/head.S b/arch/riscv/kernel/head.S index eb123eda3663..3a05a9222b82 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. + */ + c.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..8c212efb37a6 --- /dev/null +++ b/arch/riscv/kernel/image-vars.h @@ -0,0 +1,51 @@ +/* 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 + +/* + * 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 e6f8016b366a..2616230da1e7 100644 --- a/arch/riscv/kernel/vmlinux.lds.S +++ b/arch/riscv/kernel/vmlinux.lds.S @@ -10,6 +10,7 @@ #include #include #include +#include "image-vars.h" #include OUTPUT_ARCH(riscv) @@ -17,6 +18,9 @@ ENTRY(_start) jiffies = jiffies_64; +PECOFF_SECTION_ALIGNMENT = 0x1000; +PECOFF_FILE_ALIGNMENT = 0x200; + SECTIONS { /* Beginning of code and text segment */ @@ -76,6 +80,10 @@ SECTIONS EXCEPTION_TABLE(0x10) +#ifdef CONFIG_EFI + . = ALIGN(PECOFF_SECTION_ALIGNMENT); + __pecoff_text_end = .; +#endif . = ALIGN(SECTION_ALIGN); _data = .; @@ -83,16 +91,26 @@ SECTIONS .sdata : { __global_pointer$ = . + 0x800; *(.sdata*) - /* End of data section */ - _edata = .; } +#ifdef CONFIG_EFI + .pecoff_edata_padding : { BYTE(0); . = ALIGN(PECOFF_FILE_ALIGNMENT); } + __pecoff_data_raw_size = ABSOLUTE(. - __pecoff_text_end); +#endif + + /* End of data section */ + _edata = .; + BSS_SECTION(PAGE_SIZE, PAGE_SIZE, 0) .rel.dyn : { *(.rel.dyn*) } +#ifdef CONFIG_EFI + . = ALIGN(PECOFF_SECTION_ALIGNMENT); + __pecoff_data_virt_size = ABSOLUTE(. - __pecoff_text_end); +#endif _end = .; STABS_DEBUG From patchwork Thu Jun 25 23:45:14 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Atish Patra X-Patchwork-Id: 11626997 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 0950F60D for ; Fri, 26 Jun 2020 09:54:02 +0000 (UTC) Received: from merlin.infradead.org (merlin.infradead.org [205.233.59.134]) (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 B06AF21531 for ; Fri, 26 Jun 2020 09:54:01 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="FCRluZ1b"; dkim=fail reason="signature verification failed" (2048-bit key) header.d=wdc.com header.i=@wdc.com header.b="BGF2Z1BS" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org B06AF21531 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-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=merlin.20170209; h=Sender:Content-Transfer-Encoding: Content-Type:Cc: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:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=+jBnqKbVkcxDVTxh/i1qY8578tetP+VFdlBX4LtV9TM=; b=FCRluZ1b4eUWrNezEpdySCDhf 5+gZx7grx8jwD8fMp+1luxa5G5he1vG/56gER2L4+OB2OTECP/yv82EGJ5td8HblGvNRsaDncJYVQ KXA52UX6/2tq2/usN0bqrpy95uJBMmvkQlQfbiOTUPNPWG1bXBhG51ANFmjUu13FBWXL8KgzdVuvm lrEyY1F+wmnCXtfsCfhldz5Ra6qSxZba2i5PonILdYnRzylN3vIggZ2/Wbk0eiMqeEkP5enVwnqax mREbr+ptFt/en3XrFd0W1ofgdW3Sg9Wlc91FHh3zEzujpdZIGpZIYmvq5buhOZ1xSAhXk/ZhTfQRV tR4vQeJkA==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1jol0X-0002s8-Pt; Fri, 26 Jun 2020 09:50:53 +0000 Received: from esa2.hgst.iphmx.com ([68.232.143.124]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1jojo2-0002Se-U1; Fri, 26 Jun 2020 08:34:20 +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=1593160475; x=1624696475; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=y2VklyNFbvV+zicAHh/HYpABAIKprIO2C92Fm4jaHGM=; b=BGF2Z1BSjppo74jT9rJHwOhUr+KecSomlpChOlhHJloLXuGrKC5DczBc hemp28nJp08nzhW7C43/6PN4V4tnp16nfYxMLpOCHDMtqtLGLigycwuMP cG1pMGGH6aqv0JKOgR6NbDLvD0M5LSYkmpL5SjzyMfP3Am1g393OJpvOa jF3RF29weqn339rPhvKVj0/VeOy/Fviv7kn4yNaIQK1HxRCTSjMBRPNhh 7rTtr8ddGkhMsGVrbiBmUaVHggT5c9d0EfEQSk9y4BaVpuqg+aIlMtY+q MauKyq05mekzKUGb0CtQJsS3muLQqnBA88aJqyF4DggEQLflkBUpzopF/ A==; IronPort-SDR: 4vZlEq4sbG5JfvfbjQ8+LAc52JmTUlzzMZv4YSgH4NCWaBonnKioVditNZ2qT3sYJoCkK2wfNn 7bGhsVSQBDI1I5S8q3y7NIMoFLLOwNyk5OIWPMdKJIxXJB5b8pAabnHneHCIa/VeAQygiVFxbL WufNDFje01IeUgBX8EMrSETWyGbZsq7n7yhWPEb5MMSXpgOaLBJgIhC7d/otm88W8GsK1LcyMw CW66u/OyfgzxkrO3fd3yt0hYggRHJK3aQjd49Do7eGvE1CREES1Atuj9lYimNqhSf//yI+HZJO zP0= X-IronPort-AV: E=Sophos;i="5.75,280,1589212800"; d="scan'208";a="243966126" Received: from h199-255-45-14.hgst.com (HELO uls-op-cesaep01.wdc.com) ([199.255.45.14]) by ob1.hgst.iphmx.com with ESMTP; 26 Jun 2020 07:46:00 +0800 IronPort-SDR: zMNfmPwpMlqP72dokRT97RzSlyiV2JO1dHITdET7O9UxxKNgSiVd347ZCEaAIWfl+kOf5VgAKj wtn3zyUb7NQwZ5rFy4CSQs63ZAWHoYiRY= Received: from uls-op-cesaip01.wdc.com ([10.248.3.36]) by uls-op-cesaep01.wdc.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 25 Jun 2020 16:34:28 -0700 IronPort-SDR: TIagHyxmc1zCY373Yj+weBPwSvTpU7AnW5dwmOVteo4kSzdFCtmy06FaDSbVuONRtuatEO55xP QLtoppEbyDDQ== WDCIronportException: Internal Received: from 2349pbt5e4f.ad.shared (HELO jedi-01.hgst.com) ([10.86.58.78]) by uls-op-cesaip01.wdc.com with ESMTP; 25 Jun 2020 16:45:27 -0700 From: Atish Patra To: linux-kernel@vger.kernel.org Subject: [RFC PATCH 09/11] RISC-V: Add EFI stub support. Date: Thu, 25 Jun 2020 16:45:14 -0700 Message-Id: <20200625234516.31406-10-atish.patra@wdc.com> X-Mailer: git-send-email 2.24.0 In-Reply-To: <20200625234516.31406-1-atish.patra@wdc.com> References: <20200625234516.31406-1-atish.patra@wdc.com> MIME-Version: 1.0 X-Spam-Note: CRM114 invocation failed X-Spam-Score: -2.5 (--) X-Spam-Report: SpamAssassin version 3.4.4 on merlin.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 [68.232.143.124 listed in list.dnswl.org] -0.0 SPF_HELO_PASS SPF: HELO matches 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_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 -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: linux-efi@vger.kernel.org, Heinrich Schuchardt , Masahiro Yamada , Atish Patra , Palmer Dabbelt , linux-riscv@lists.infradead.org, Ard Biesheuvel , linux-arm-kernel@lists.infradead.org Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=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 Link: https://lore.kernel.org/r/20200421033336.9663-4-atish.patra@wdc.com [ardb: - move hartid fetch into check_platform_features() - use image_size not reserve_size - select ISA_C ] Signed-off-by: Ard Biesheuvel --- arch/riscv/Kconfig | 22 +++++ arch/riscv/Makefile | 1 + arch/riscv/configs/defconfig | 1 + arch/riscv/include/asm/efi.h | 36 +++++++ drivers/firmware/efi/Kconfig | 3 +- drivers/firmware/efi/libstub/Makefile | 10 ++ drivers/firmware/efi/libstub/riscv-stub.c | 110 ++++++++++++++++++++++ 7 files changed, 182 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 fda90093e588..a902e98048a1 100644 --- a/arch/riscv/Kconfig +++ b/arch/riscv/Kconfig @@ -388,6 +388,26 @@ 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 + select RISCV_ISA_C + 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 config BUILTIN_DTB @@ -400,3 +420,5 @@ menu "Power management options" source "kernel/power/Kconfig" endmenu + +source "drivers/firmware/Kconfig" diff --git a/arch/riscv/Makefile b/arch/riscv/Makefile index fb6e37db836d..079435804d6d 100644 --- a/arch/riscv/Makefile +++ b/arch/riscv/Makefile @@ -80,6 +80,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 4da4886246a4..ae69e12d306a 100644 --- a/arch/riscv/configs/defconfig +++ b/arch/riscv/configs/defconfig @@ -129,3 +129,4 @@ CONFIG_DEBUG_BLOCK_EXT_DEVT=y # CONFIG_RUNTIME_TESTING_MENU is not set CONFIG_MEMTEST=y # CONFIG_SYSFS_SYSCALL is not set +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..86da231909bb --- /dev/null +++ b/arch/riscv/include/asm/efi.h @@ -0,0 +1,36 @@ +/* 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 + +/* on RISC-V, 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; +} + +/* Load initrd at enough distance from DRAM start */ +static inline unsigned long efi_get_max_initrd_addr(unsigned long dram_base, + unsigned long image_addr) +{ + return dram_base + SZ_256M; +} + +#define alloc_screen_info(x...) (&screen_info) + +static inline void free_screen_info(struct screen_info *si) +{ +} + +static inline void efifb_setup_from_dmi(struct screen_info *si, const char *opt) +{ +} + +#endif /* _ASM_EFI_H */ diff --git a/drivers/firmware/efi/Kconfig b/drivers/firmware/efi/Kconfig index e6fc022bc87e..22a8df95900e 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 @@ -128,6 +128,7 @@ config EFI_GENERIC_STUB_INITRD_CMDLINE_LOADER bool "Enable the command line initrd loader" if !X86 depends on EFI_STUB && (EFI_GENERIC_STUB || X86) default y + depends on !RISCV help Select this config option to add support for the initrd= command line parameter, allowing an initrd that resides on the same volume diff --git a/drivers/firmware/efi/libstub/Makefile b/drivers/firmware/efi/libstub/Makefile index 75daaf20374e..d1564ffcf82f 100644 --- a/drivers/firmware/efi/libstub/Makefile +++ b/drivers/firmware/efi/libstub/Makefile @@ -22,6 +22,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 @@ -63,6 +65,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) @@ -106,6 +109,13 @@ STUBCOPY_FLAGS-$(CONFIG_ARM64) += --prefix-alloc-sections=.init \ --prefix-symbols=__efistub_ STUBCOPY_RELOC-$(CONFIG_ARM64) := R_AARCH64_ABS +# For RISC-V, we don't need anything special other than arm64. Keep all the +# symbols in .init section and make sure that no absolute symbols references +# doesn't exist. +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..77c3fd6f820e --- /dev/null +++ b/drivers/firmware/efi/libstub/riscv-stub.c @@ -0,0 +1,110 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * Copyright (C) 2020 Western Digital Corporation or its affiliates. + */ + +#include +#include + +#include +#include + +#include "efistub.h" + +/* + * RISC-V requires the kernel image to placed 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 + +typedef void __noreturn (*jump_kernel_func)(unsigned int, unsigned long); + +static u32 hartid; + +static u32 get_boot_hartid_from_fdt(void) +{ + const void *fdt; + int chosen_node, len; + const fdt32_t *prop; + + fdt = get_efi_config_table(DEVICE_TREE_GUID); + if (!fdt) + return U32_MAX; + + chosen_node = fdt_path_offset(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); +} + +efi_status_t check_platform_features(void) +{ + hartid = get_boot_hartid_from_fdt(); + if (hartid == U32_MAX) { + efi_err("/chosen/boot-hartid missing or invalid!\n"); + return EFI_UNSUPPORTED; + } + return EFI_SUCCESS; +} + +void __noreturn efi_enter_kernel(unsigned long entrypoint, unsigned long fdt, + unsigned long fdt_size) +{ + unsigned long stext_offset = _start_kernel - _start; + unsigned long kernel_entry = entrypoint + stext_offset; + jump_kernel_func jump_kernel = (jump_kernel_func)kernel_entry; + + /* + * Jump to real kernel here with following constraints. + * 1. MMU should be disabled. + * 2. a0 should contain hartid + * 3. a1 should DT address + */ + 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) +{ + unsigned long kernel_size = 0; + unsigned long preferred_addr; + efi_status_t status; + + kernel_size = _edata - _start; + *image_addr = (unsigned long)_start; + *image_size = kernel_size + (_end - _edata); + + /* + * RISC-V kernel maps PAGE_OFFSET virtual address to the same physical + * address where kernel is booted. That's why kernel should boot from + * as low as possible to avoid wastage of memory. Currently, dram_base + * is occupied by the firmware. So the preferred address for kernel to + * boot is next aligned address. If preferred address is not available, + * relocate_kernel will fall back to efi_low_alloc_above to allocate + * lowest possible memory region as long as the address and size meets + * the alignment constraints. + */ + preferred_addr = round_up(dram_base, MIN_KIMG_ALIGN) + MIN_KIMG_ALIGN; + status = efi_relocate_kernel(image_addr, kernel_size, *image_size, + preferred_addr, MIN_KIMG_ALIGN, dram_base); + + if (status != EFI_SUCCESS) { + efi_err("Failed to relocate kernel\n"); + *image_size = 0; + } + return status; +} From patchwork Thu Jun 25 23:45:15 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Atish Patra X-Patchwork-Id: 11626991 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 DAE4092A for ; Fri, 26 Jun 2020 09:53:13 +0000 (UTC) Received: from merlin.infradead.org (merlin.infradead.org [205.233.59.134]) (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 AFF5B21531 for ; Fri, 26 Jun 2020 09:53:13 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="txT8LmAJ"; dkim=fail reason="signature verification failed" (2048-bit key) header.d=wdc.com header.i=@wdc.com header.b="HzTLooZi" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org AFF5B21531 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-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=merlin.20170209; h=Sender:Content-Transfer-Encoding: Content-Type:Cc: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:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=f2ZsTsl96ZMqJ+QRBIPNM1ujEDL4d3TRjfB5dJaksw8=; b=txT8LmAJYCFnsZtRajsuSBvQD RIlpm6NOkaYnXKfpyK8niMSGHoX9dhZmrT0Kd9qNFCeGFMJ8CFeYNdug5sIXOXmdEPM+whEtz/iZQ iLH+qxdWe16Neiz2L41wZAevHhniwdOP74NZtfNKPLlMy5hvWcOnPQN99fEUuplPK+8mGJ5DN7X+d PmYakJgnnhchc/NkbAq/WRUfDMg0T1ncIRGUQgUEtNQMEYH6/8YUQn6vsyGFWy+MrQxOjXGKN55T5 ivz9LtOPtdpoAJXYaOsfPFS7rtb5uYumr9odf0kudum3J0szgPThR5xjjsTG9DQLuDs8DdhewjsIn rXDXPxsAA==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1jol0g-0002vH-Oq; Fri, 26 Jun 2020 09:51:02 +0000 Received: from esa2.hgst.iphmx.com ([68.232.143.124]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1jojoT-0002Se-8Y; Fri, 26 Jun 2020 08:34:46 +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=1593160470; x=1624696470; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=aWD4YBmJs4KzatxYQf8rnaaoWvjExyC78q596yR2/no=; b=HzTLooZitFsTrdzdW2aAWFGw5xMfP0mrAQNpV2SdYQ1nCCg7gYuJbSWb +4i6a3CGfMzf7Q/fNGN3kBCiJfdv/tsZXP+74dy+z4GOX7r2JEmwOVwMR MkyuVr7MrtBnRS7maBHrEkKAOeW/vhgbbfsCb12OXDQrUl4YtuASGdqGt ryiYysbeIHl5ukpxvajXWEQrW5AXzJbYSgCeqYuB2BSPbLSam/dZnlzNE 3u3Vd3Ty+QUMnrdkjhwWbu1XB4MDEFpMlboEunc72lRLbpK1WVrh11hey fEn3noxMre8nvoGIwhRA2oj26okqv8pMaXtskWvVisx+xYn0b/5lPdkbt Q==; IronPort-SDR: bJsD+CzqMESINk3b4x1j5OPYNP8JjwzdPwmVCd2BObJhad/GwF1QDTWcUIIPDf4/+HOg8G9oVl 5uyXDAh6x57X8pJWatTFklxONQzuFWguVI5ZTey03wenQaZvR4tHflLvRjEQcY/JdHhR29VAm/ KwqN9KMDHSH4WWrO08qMCr3D45spV/4P77hGLnJXQDhIH4Ghv9+gycU+QfbKyukFpS8tMzXPOe 9uUDlxOAM6W01bjhbV92STKnAqJMk/ONMyzIdlXkiW6ASaBICt9bslaUV7C/rlmlHhgSPV806e +fU= X-IronPort-AV: E=Sophos;i="5.75,280,1589212800"; d="scan'208";a="243966127" Received: from h199-255-45-14.hgst.com (HELO uls-op-cesaep01.wdc.com) ([199.255.45.14]) by ob1.hgst.iphmx.com with ESMTP; 26 Jun 2020 07:46:01 +0800 IronPort-SDR: AlMM0FgY2Zd7NKokD8xe6mDr194+ZDAjGHjvJShWgLGSDnDt3bXIKfoqlLADQRFUiw0+emu/F1 TMz6IuF5o260oJTeDI4fhu+V5wyuOKh78= Received: from uls-op-cesaip01.wdc.com ([10.248.3.36]) by uls-op-cesaep01.wdc.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 25 Jun 2020 16:34:28 -0700 IronPort-SDR: qzucKY1oxxKLbrAVAstjJ6LHkYhYSEJngCI+ItcjpIHTI3dmgOGrYo+V24ODpy0uGkhcgytR3B fUSIjAQFVOTQ== WDCIronportException: Internal Received: from 2349pbt5e4f.ad.shared (HELO jedi-01.hgst.com) ([10.86.58.78]) by uls-op-cesaip01.wdc.com with ESMTP; 25 Jun 2020 16:45:28 -0700 From: Atish Patra To: linux-kernel@vger.kernel.org Subject: [RFC PATCH 10/11] efi: Rename arm-init to efi-init common for all arch Date: Thu, 25 Jun 2020 16:45:15 -0700 Message-Id: <20200625234516.31406-11-atish.patra@wdc.com> X-Mailer: git-send-email 2.24.0 In-Reply-To: <20200625234516.31406-1-atish.patra@wdc.com> References: <20200625234516.31406-1-atish.patra@wdc.com> MIME-Version: 1.0 X-Spam-Note: CRM114 invocation failed X-Spam-Score: -2.5 (--) X-Spam-Report: SpamAssassin version 3.4.4 on merlin.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 [68.232.143.124 listed in list.dnswl.org] -0.0 SPF_HELO_PASS SPF: HELO matches 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_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 -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: linux-efi@vger.kernel.org, Heinrich Schuchardt , Masahiro Yamada , Atish Patra , Palmer Dabbelt , linux-riscv@lists.infradead.org, Ard Biesheuvel , linux-arm-kernel@lists.infradead.org Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org arm-init is responsible for setting up efi runtime and doesn't actually do any ARM specific stuff. RISC-V can use the same source code as it is. Rename it to efi-init so that RISC-V can use it. Signed-off-by: Atish Patra --- drivers/firmware/efi/{arm-init.c => efi-init.c} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename drivers/firmware/efi/{arm-init.c => efi-init.c} (100%) diff --git a/drivers/firmware/efi/arm-init.c b/drivers/firmware/efi/efi-init.c similarity index 100% rename from drivers/firmware/efi/arm-init.c rename to drivers/firmware/efi/efi-init.c From patchwork Thu Jun 25 23:45:16 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Atish Patra X-Patchwork-Id: 11627405 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 BEB5A913 for ; Fri, 26 Jun 2020 12:26:30 +0000 (UTC) Received: from merlin.infradead.org (merlin.infradead.org [205.233.59.134]) (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 872D3207E8 for ; Fri, 26 Jun 2020 12:26:30 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="lLZ+0P70"; dkim=fail reason="signature verification failed" (2048-bit key) header.d=wdc.com header.i=@wdc.com header.b="SDqkPprj" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 872D3207E8 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-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=merlin.20170209; h=Sender:Content-Transfer-Encoding: Content-Type:Cc: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:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=foL0etzqxF89j2neNeQDjfe5i8dTdM9ShEl3TfGuOZ0=; b=lLZ+0P70lEjh+05jXKsUXp2Eb ZiU1LPiFRAkB9FrEnJoDC571UCXCaqOvbcJsPtIS2vi3svLnW2zFjq5zkrcTv+fCfO0Tw+kyM+s+O 4+ez6EFD+7S1Hvss0N0v5L5ebO9sIYXtMpOga1gL+AwJITLaF/WLsDa9WaRwcVQjpwm1B+CowsmEQ +/JWqb1WF5EW8Dr/4oLwNRacr4Esgfn2pCgimhtpFgWTUaau4ZWzqcPD7fDxb0LRE8i638h0h6yeW OQLawQ8eirnoq+DpryO509q8tM+z6Z2xmjFYoDOzBOseIYC1A1Le4z+bT859ZgEwrSbUaP3HfJ5Io /7nRYq+Fg==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1jonOS-0004ED-Lk; Fri, 26 Jun 2020 12:23:44 +0000 Received: from esa2.hgst.iphmx.com ([68.232.143.124]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1jojot-0002Se-4q; Fri, 26 Jun 2020 08:35:11 +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=1593160509; x=1624696509; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=HpPgX2DM3YTTnUZPUHGvEF/Cy7COxqR8ZqBTAnCKExs=; b=SDqkPprj6xM7DJD91xJLlpPBYcMukNTaANMRNjfb1M9gSnrrZLuK/S9r HFMb2Zjg9pmyRG98CVLYu/YpSv1xHww7pTQ+2E6jyv49TsjAvQ42VlE6p ucnH5bGBLiDp8eXyRKvMoST+IIoGLSuir7Bm/Vq6bfDux+GGE4JxKAGVA 9j6q2ndpKHoYK689hDLNIEmftTXtUBrCfcwwEvOUEKklQ07UiaRWz4I3s 4XfP1qQj+kQyIUTMnZ1Doie6njPFaHGqakce7g2iaW+3oLWBliXjhT5wE 1tOUqX3lvMsiFM56uvZPvbXLPSrg2VahbvWy2Ss8qUuzqJeW49o7N/CCX g==; IronPort-SDR: T9pfD7JKhYfsKoa3Up+hMTwfph67wk3JOfUbCQgLnyI8SAAi+kn2867BlZ4iETHNoDjP5javs1 L+CduDKhznfGRs55TEcAnO1RiaBmjUKkWkfAfk+81Q0i6hBSzf6ZyY0Nrku+KtSsm2KQ1wm7cv Y3rUtzAZPySHNvbJ96T7irpC3iPFmvM3r5Z52LQXxdE6Tx4YdX98FDkwBE5OaI/Aae5E2S+g7k XlpnTlcPw23TiMENS+egrWbDLCnkJ4PgpvhGB/j8XU7uRHIw/yH2c5JpNgyaecQNj8qXmfHbB+ DiY= X-IronPort-AV: E=Sophos;i="5.75,280,1589212800"; d="scan'208";a="243966130" Received: from h199-255-45-14.hgst.com (HELO uls-op-cesaep01.wdc.com) ([199.255.45.14]) by ob1.hgst.iphmx.com with ESMTP; 26 Jun 2020 07:46:02 +0800 IronPort-SDR: a80O6tQBq+/cjyrj2BqQ56PF/o+D22+OESs+L3GsakHmTiZ5uz1iR2nnkhIxfDWwkZSb2W3umy 4QaKfEmoqtoTBQVpSuJxYDrXJlmX5RS8M= Received: from uls-op-cesaip01.wdc.com ([10.248.3.36]) by uls-op-cesaep01.wdc.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 25 Jun 2020 16:34:29 -0700 IronPort-SDR: EMxaBTxMID8RWmWtIvauBjeCbtNUkoP69MPXDzGHPdXaRAa8zItOAJOiTRBGzgQ1MjMgfH0ZpI EyzrdVT87fqw== WDCIronportException: Internal Received: from 2349pbt5e4f.ad.shared (HELO jedi-01.hgst.com) ([10.86.58.78]) by uls-op-cesaip01.wdc.com with ESMTP; 25 Jun 2020 16:45:28 -0700 From: Atish Patra To: linux-kernel@vger.kernel.org Subject: [RFC PATCH 11/11] RISC-V: Add EFI runtime services Date: Thu, 25 Jun 2020 16:45:16 -0700 Message-Id: <20200625234516.31406-12-atish.patra@wdc.com> X-Mailer: git-send-email 2.24.0 In-Reply-To: <20200625234516.31406-1-atish.patra@wdc.com> References: <20200625234516.31406-1-atish.patra@wdc.com> MIME-Version: 1.0 X-Spam-Note: CRM114 invocation failed X-Spam-Score: -2.5 (--) X-Spam-Report: SpamAssassin version 3.4.4 on merlin.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 [68.232.143.124 listed in list.dnswl.org] -0.0 SPF_HELO_PASS SPF: HELO matches 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_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 -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: linux-efi@vger.kernel.org, Heinrich Schuchardt , Masahiro Yamada , Atish Patra , Palmer Dabbelt , linux-riscv@lists.infradead.org, Ard Biesheuvel , linux-arm-kernel@lists.infradead.org Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org This patch adds EFI runtime service support for RISC-V. Signed-off-by: Atish Patra --- arch/riscv/Kconfig | 2 + arch/riscv/include/asm/efi.h | 20 ++++ arch/riscv/include/asm/mmu.h | 2 + arch/riscv/include/asm/pgalloc.h | 12 ++ arch/riscv/include/asm/pgtable.h | 4 + arch/riscv/kernel/Makefile | 1 + arch/riscv/kernel/efi.c | 106 ++++++++++++++++++ arch/riscv/kernel/setup.c | 7 +- arch/riscv/mm/init.c | 2 +- drivers/firmware/efi/Makefile | 4 +- drivers/firmware/efi/libstub/efi-stub.c | 11 +- drivers/firmware/efi/riscv-runtime.c | 141 ++++++++++++++++++++++++ 12 files changed, 307 insertions(+), 5 deletions(-) create mode 100644 arch/riscv/kernel/efi.c create mode 100644 drivers/firmware/efi/riscv-runtime.c diff --git a/arch/riscv/Kconfig b/arch/riscv/Kconfig index a902e98048a1..601e8b873628 100644 --- a/arch/riscv/Kconfig +++ b/arch/riscv/Kconfig @@ -399,7 +399,9 @@ config EFI select EFI_PARAMS_FROM_FDT select EFI_STUB select EFI_GENERIC_STUB + select EFI_RUNTIME_WRAPPERS select RISCV_ISA_C + depends on MMU default y help This option provides support for runtime services provided diff --git a/arch/riscv/include/asm/efi.h b/arch/riscv/include/asm/efi.h index 86da231909bb..93c305a638f4 100644 --- a/arch/riscv/include/asm/efi.h +++ b/arch/riscv/include/asm/efi.h @@ -5,11 +5,28 @@ #ifndef _ASM_EFI_H #define _ASM_EFI_H +#include #include #include #include #include +#ifdef CONFIG_EFI +extern void efi_init(void); +#else +#define efi_init() +#endif + +int efi_create_mapping(struct mm_struct *mm, efi_memory_desc_t *md); +int efi_set_mapping_permissions(struct mm_struct *mm, efi_memory_desc_t *md); + +#define arch_efi_call_virt_setup() efi_virtmap_load() +#define arch_efi_call_virt_teardown() efi_virtmap_unload() + +#define arch_efi_call_virt(p, f, args...) p->f(args) + +#define ARCH_EFI_IRQ_FLAGS_MASK (SR_IE | SR_SPIE) + /* on RISC-V, the FDT may be located anywhere in system RAM */ static inline unsigned long efi_get_max_fdt_addr(unsigned long dram_base) { @@ -33,4 +50,7 @@ static inline void efifb_setup_from_dmi(struct screen_info *si, const char *opt) { } +void efi_virtmap_load(void); +void efi_virtmap_unload(void); + #endif /* _ASM_EFI_H */ diff --git a/arch/riscv/include/asm/mmu.h b/arch/riscv/include/asm/mmu.h index 967eacb01ab5..dabcf2cfb3dc 100644 --- a/arch/riscv/include/asm/mmu.h +++ b/arch/riscv/include/asm/mmu.h @@ -20,6 +20,8 @@ typedef struct { #endif } mm_context_t; +void __init create_pgd_mapping(pgd_t *pgdp, uintptr_t va, phys_addr_t pa, + phys_addr_t sz, pgprot_t prot); #endif /* __ASSEMBLY__ */ #endif /* _ASM_RISCV_MMU_H */ diff --git a/arch/riscv/include/asm/pgalloc.h b/arch/riscv/include/asm/pgalloc.h index 3f601ee8233f..ad567bf0fb84 100644 --- a/arch/riscv/include/asm/pgalloc.h +++ b/arch/riscv/include/asm/pgalloc.h @@ -40,6 +40,18 @@ static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd) #define pmd_pgtable(pmd) pmd_page(pmd) +static inline pgd_t *pgd_alloc_nomap(struct mm_struct *mm) +{ + pgd_t *pgd; + + pgd = (pgd_t *)__get_free_page(GFP_KERNEL); + if (likely(pgd != NULL)) + memset(pgd, 0, USER_PTRS_PER_PGD * sizeof(pgd_t)); + + return pgd; +} + + static inline pgd_t *pgd_alloc(struct mm_struct *mm) { pgd_t *pgd; diff --git a/arch/riscv/include/asm/pgtable.h b/arch/riscv/include/asm/pgtable.h index eaea1f717010..d53ef48768ae 100644 --- a/arch/riscv/include/asm/pgtable.h +++ b/arch/riscv/include/asm/pgtable.h @@ -100,6 +100,10 @@ #define PAGE_KERNEL __pgprot(_PAGE_KERNEL) #define PAGE_KERNEL_EXEC __pgprot(_PAGE_KERNEL | _PAGE_EXEC) +#define PAGE_KERNEL_READ __pgprot(_PAGE_KERNEL & ~_PAGE_WRITE) +#define PAGE_KERNEL_EXEC __pgprot(_PAGE_KERNEL | _PAGE_EXEC) +#define PAGE_KERNEL_READ_EXEC __pgprot((_PAGE_KERNEL & ~_PAGE_WRITE) \ + | _PAGE_EXEC) #define PAGE_TABLE __pgprot(_PAGE_TABLE) diff --git a/arch/riscv/kernel/Makefile b/arch/riscv/kernel/Makefile index 6f7a3b3771fd..239c44c451b6 100644 --- a/arch/riscv/kernel/Makefile +++ b/arch/riscv/kernel/Makefile @@ -36,6 +36,7 @@ OBJCOPYFLAGS := --prefix-symbols=__efistub_ $(obj)/%.stub.o: $(obj)/%.o FORCE $(call if_changed,objcopy) +obj-$(CONFIG_EFI) += efi.o obj-$(CONFIG_FPU) += fpu.o obj-$(CONFIG_SMP) += smpboot.o obj-$(CONFIG_SMP) += smp.o diff --git a/arch/riscv/kernel/efi.c b/arch/riscv/kernel/efi.c new file mode 100644 index 000000000000..d6c0b733f3d1 --- /dev/null +++ b/arch/riscv/kernel/efi.c @@ -0,0 +1,106 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* + * + * Copyright (C) 2020 Western Digital Corporation or its affiliates. + * Adapted from arch/arm64/kernel/efi.c + */ + +#include +#include + +#include +#include +#include + +/* + * Only regions of type EFI_RUNTIME_SERVICES_CODE need to be + * executable, everything else can be mapped with the XN bits + * set. Also take the new (optional) RO/XP bits into account. + */ +static __init pgprot_t efimem_to_pgprot_map(efi_memory_desc_t *md) +{ + u64 attr = md->attribute; + u32 type = md->type; + + if (type == EFI_MEMORY_MAPPED_IO) + return PAGE_KERNEL; + + if (WARN_ONCE(!PAGE_ALIGNED(md->phys_addr), + "UEFI Runtime regions are not aligned to page size -- buggy firmware?")) + /* + * If the region is not aligned to the page size of the OS, we + * can not use strict permissions, since that would also affect + * the mapping attributes of the adjacent regions. + */ + return PAGE_EXEC; + + /* R-- */ + if ((attr & (EFI_MEMORY_XP | EFI_MEMORY_RO)) == + (EFI_MEMORY_XP | EFI_MEMORY_RO)) + return PAGE_KERNEL_READ; + + /* R-X */ + if (attr & EFI_MEMORY_RO) + return PAGE_KERNEL_READ_EXEC; + + /* RW- */ + if (((attr & (EFI_MEMORY_RP | EFI_MEMORY_WP | EFI_MEMORY_XP)) == + EFI_MEMORY_XP) || + type != EFI_RUNTIME_SERVICES_CODE) + return PAGE_KERNEL; + + /* RWX */ + return PAGE_KERNEL_EXEC; +} + +int __init efi_create_mapping(struct mm_struct *mm, efi_memory_desc_t *md) +{ + pgprot_t prot = __pgprot(pgprot_val(efimem_to_pgprot_map(md)) & + ~(_PAGE_GLOBAL)); + int i; + + /* RISC-V maps one page at a time */ + for (i = 0; i <= md->num_pages; i++) + create_pgd_mapping(mm->pgd, md->virt_addr + i * PAGE_SIZE, + md->phys_addr + i * PAGE_SIZE, + PAGE_SIZE, prot); + return 0; +} + +static int __init set_permissions(pte_t *ptep, unsigned long addr, void *data) +{ + efi_memory_desc_t *md = data; + pte_t pte = READ_ONCE(*ptep); + unsigned long val; + + if (md->attribute & EFI_MEMORY_RO) { + val = pte_val(pte) & ~_PAGE_WRITE; + val = pte_val(pte) | _PAGE_READ; + pte = __pte(val); + } + if (md->attribute & EFI_MEMORY_XP) { + val = pte_val(pte) & ~_PAGE_EXEC; + pte = __pte(val); + } + set_pte(ptep, pte); + + return 0; +} + +int __init efi_set_mapping_permissions(struct mm_struct *mm, + efi_memory_desc_t *md) +{ + BUG_ON(md->type != EFI_RUNTIME_SERVICES_CODE && + md->type != EFI_RUNTIME_SERVICES_DATA); + + /* + * Calling apply_to_page_range() is only safe on regions that are + * guaranteed to be mapped down to pages. Since we are only called + * for regions that have been mapped using efi_create_mapping() above + * (and this is checked by the generic Memory Attributes table parsing + * routines), there is no need to check that again here. + */ + return apply_to_page_range(mm, md->virt_addr, + md->num_pages << EFI_PAGE_SHIFT, + set_permissions, md); +} diff --git a/arch/riscv/kernel/setup.c b/arch/riscv/kernel/setup.c index 1244b433fe7c..0a725bd8d73e 100644 --- a/arch/riscv/kernel/setup.c +++ b/arch/riscv/kernel/setup.c @@ -17,6 +17,7 @@ #include #include #include +#include #include #include @@ -26,11 +27,12 @@ #include #include #include +#include #include "head.h" -#ifdef CONFIG_DUMMY_CONSOLE -struct screen_info screen_info = { +#if defined(CONFIG_DUMMY_CONSOLE) || defined(CONFIG_EFI) +struct screen_info screen_info __section(.data) = { .orig_video_lines = 30, .orig_video_cols = 80, .orig_video_mode = 0, @@ -75,6 +77,7 @@ void __init setup_arch(char **cmdline_p) early_ioremap_setup(); parse_early_param(); + efi_init(); setup_bootmem(); paging_init(); unflatten_and_copy_device_tree(); diff --git a/arch/riscv/mm/init.c b/arch/riscv/mm/init.c index c5268fe6e6de..eab96ed24065 100644 --- a/arch/riscv/mm/init.c +++ b/arch/riscv/mm/init.c @@ -319,7 +319,7 @@ static void __init create_pmd_mapping(pmd_t *pmdp, #define fixmap_pgd_next fixmap_pte #endif -static void __init create_pgd_mapping(pgd_t *pgdp, +void __init create_pgd_mapping(pgd_t *pgdp, uintptr_t va, phys_addr_t pa, phys_addr_t sz, pgprot_t prot) { diff --git a/drivers/firmware/efi/Makefile b/drivers/firmware/efi/Makefile index 7a216984552b..4d628081bb2f 100644 --- a/drivers/firmware/efi/Makefile +++ b/drivers/firmware/efi/Makefile @@ -32,9 +32,11 @@ obj-$(CONFIG_EFI_EMBEDDED_FIRMWARE) += embedded-firmware.o fake_map-y += fake_mem.o fake_map-$(CONFIG_X86) += x86_fake_mem.o -arm-obj-$(CONFIG_EFI) := arm-init.o arm-runtime.o +arm-obj-$(CONFIG_EFI) := efi-init.o arm-runtime.o obj-$(CONFIG_ARM) += $(arm-obj-y) obj-$(CONFIG_ARM64) += $(arm-obj-y) +riscv-obj-$(CONFIG_EFI) := efi-init.o riscv-runtime.o +obj-$(CONFIG_RISCV) += $(riscv-obj-y) obj-$(CONFIG_EFI_CAPSULE_LOADER) += capsule-loader.o obj-$(CONFIG_EFI_EARLYCON) += earlycon.o obj-$(CONFIG_UEFI_CPER_ARM) += cper-arm.o diff --git a/drivers/firmware/efi/libstub/efi-stub.c b/drivers/firmware/efi/libstub/efi-stub.c index e97370bdfdb0..3f7392da135d 100644 --- a/drivers/firmware/efi/libstub/efi-stub.c +++ b/drivers/firmware/efi/libstub/efi-stub.c @@ -17,7 +17,10 @@ /* * This is the base address at which to start allocating virtual memory ranges - * for UEFI Runtime Services. This is in the low TTBR0 range so that we can use + * for UEFI Runtime Services. + * + * For ARM/ARM64: + * This is in the low TTBR0 range so that we can use * any allocation we choose, and eliminate the risk of a conflict after kexec. * The value chosen is the largest non-zero power of 2 suitable for this purpose * both on 32-bit and 64-bit ARM CPUs, to maximize the likelihood that it can @@ -25,6 +28,12 @@ * Since 32-bit ARM could potentially execute with a 1G/3G user/kernel split, * map everything below 1 GB. (512 MB is a reasonable upper bound for the * entire footprint of the UEFI runtime services memory regions) + * + * For RISC-V: + * There is no specific reason for which, this address (512MB) can't be used + * EFI runtime virtual address for RISC-V. It also helps to use EFI runtime + * services on both RV32/RV64. Keep the same runtime virtual address for RISC-V + * as well to minimize the code churn. */ #define EFI_RT_VIRTUAL_BASE SZ_512M #define EFI_RT_VIRTUAL_SIZE SZ_512M diff --git a/drivers/firmware/efi/riscv-runtime.c b/drivers/firmware/efi/riscv-runtime.c new file mode 100644 index 000000000000..3bc48a268f66 --- /dev/null +++ b/drivers/firmware/efi/riscv-runtime.c @@ -0,0 +1,141 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * Extensible Firmware Interface + * + * Based on Extensible Firmware Interface Specification version 2.4 + * + * Copyright (C) 2013, 2014 Linaro Ltd. + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include + +static bool __init efi_virtmap_init(void) +{ + efi_memory_desc_t *md; + + efi_mm.pgd = pgd_alloc_nomap(&efi_mm); + mm_init_cpumask(&efi_mm); + init_new_context(NULL, &efi_mm); + + for_each_efi_memory_desc(md) { + phys_addr_t phys = md->phys_addr; + int ret; + + if (!(md->attribute & EFI_MEMORY_RUNTIME)) + continue; + if (md->virt_addr == 0) + return false; + + ret = efi_create_mapping(&efi_mm, md); + if (ret) { + pr_warn(" EFI remap %pa: failed to create mapping (%d)\n", + &phys, ret); + return false; + } + } + + if (efi_memattr_apply_permissions(&efi_mm, efi_set_mapping_permissions)) + return false; + + return true; +} + +/* + * Enable the UEFI Runtime Services if all prerequisites are in place, i.e., + * non-early mapping of the UEFI system table and virtual mappings for all + * EFI_MEMORY_RUNTIME regions. + */ +static int __init riscv_enable_runtime_services(void) +{ + u64 mapsize; + + if (!efi_enabled(EFI_BOOT)) { + pr_info("EFI services will not be available.\n"); + return 0; + } + + efi_memmap_unmap(); + + mapsize = efi.memmap.desc_size * efi.memmap.nr_map; + + if (efi_memmap_init_late(efi.memmap.phys_map, mapsize)) { + pr_err("Failed to remap EFI memory map\n"); + return 0; + } + + if (efi_soft_reserve_enabled()) { + efi_memory_desc_t *md; + + for_each_efi_memory_desc(md) { + int md_size = md->num_pages << EFI_PAGE_SHIFT; + struct resource *res; + + if (!(md->attribute & EFI_MEMORY_SP)) + continue; + + res = kzalloc(sizeof(*res), GFP_KERNEL); + if (WARN_ON(!res)) + break; + + res->start = md->phys_addr; + res->end = md->phys_addr + md_size - 1; + res->name = "Soft Reserved"; + res->flags = IORESOURCE_MEM; + res->desc = IORES_DESC_SOFT_RESERVED; + + insert_resource(&iomem_resource, res); + } + } + + if (efi_runtime_disabled()) { + pr_info("EFI runtime services will be disabled.\n"); + return 0; + } + + if (efi_enabled(EFI_RUNTIME_SERVICES)) { + pr_info("EFI runtime services access via paravirt.\n"); + return 0; + } + + pr_info("Remapping and enabling EFI services.\n"); + + if (!efi_virtmap_init()) { + pr_err("UEFI virtual mapping missing or invalid -- runtime services will not be available\n"); + return -ENOMEM; + } + + /* Set up runtime services function pointers */ + efi_native_runtime_setup(); + set_bit(EFI_RUNTIME_SERVICES, &efi.flags); + + return 0; +} +early_initcall(riscv_enable_runtime_services); + +void efi_virtmap_load(void) +{ + preempt_disable(); + switch_mm(&efi_mm, current->active_mm, NULL); +} + +void efi_virtmap_unload(void) +{ + switch_mm(current->active_mm, &efi_mm, NULL); + preempt_enable(); +}