Received: by 2002:a25:ca44:0:0:0:0:0 with SMTP id a65csp1512889ybg; Wed, 29 Jul 2020 16:40:30 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxJDZE7sJ57Ld4V5URDS2orI9GasCezURM5GY8K14WpJ1JVEiZNkuQdT+EvZ38zmlqAE9Lc X-Received: by 2002:a17:906:cc51:: with SMTP id mm17mr22038ejb.137.1596066030198; Wed, 29 Jul 2020 16:40:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1596066030; cv=none; d=google.com; s=arc-20160816; b=iCufTv4O9Ag9S9Ne1Cq6LuiMPl4r0g62/OdemIW5jUrzhjAa0cHD+v+OCwpA6nxxOK NCVRj+0eQhC388GdiDxPLZG47IYt4gG8iW3TsCXo+IO4SuHGXiw0ulYmgpBXtGgBjgGt 1ZT5binRVOWAaZpHNf7SAc/+PJqZk3mnviyPFKidVda45z0gA1KTJtYmi9CjjuVrWi23 1PldIjLOLvfOlLcONaLbgOZIfYUB9R+B3JYlQ9MlhkgAF0oIwXW0vi73qvBYn8LY8w4I 6h++ogDz19GN1lJ6aSNF2sIcsuw//yz8G8rVucQQYa1oipyNWf1FIuyDih7vkEkablLt jz8w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :wdcironportexception:ironport-sdr:ironport-sdr:ironport-sdr :dkim-signature; bh=ZKeFt3jHHfsC1ZsRdqPaNfmyfIZO+Ds0gSgUmQQYx5A=; b=PsOGjb6GKgrJbiGlZ2918hlp7SjlhcswdpMAqGWPWv4jTrrOxUh9vYyYNvfr9e+SOE 0VNYcNi2feJctar5kV3uJI9SWwrnmHQW5pYM3X9l8wlmW3TV9nkJq4crQ4hzDIeKFC4L 9ktBnMkYy4Q1bX/RCXvA+bxflwj8GV1agRu1qzK154d4/oWZIJRV6DcXl5eELEQI4bJW 7dC89Zz8CQfJz5DfqynxcbW+RKx++4XHbv5/yNunw19t+cLMlSDiv/3f/3U0+F30OEBe 3aBDBYVtQkZqW2tFWlKA75M8ns3uNTwjxSojocFUnhWX+MH2NkDNhHmiU5jBKSWbM35c VD4g== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@wdc.com header.s=dkim.wdc.com header.b=hFjfGLZR; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=wdc.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id lj13si2031246ejb.357.2020.07.29.16.40.07; Wed, 29 Jul 2020 16:40:30 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=fail header.i=@wdc.com header.s=dkim.wdc.com header.b=hFjfGLZR; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=wdc.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728104AbgG2Xgz (ORCPT + 99 others); Wed, 29 Jul 2020 19:36:55 -0400 Received: from esa6.hgst.iphmx.com ([216.71.154.45]:22290 "EHLO esa6.hgst.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727087AbgG2Xgy (ORCPT ); Wed, 29 Jul 2020 19:36:54 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1596065814; x=1627601814; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=FX6d5P98ttKncydey4fpaqPuC2G3OjiVXWjKcDsITLk=; b=hFjfGLZRaxsqgYIpzbaEXUqcLhwMazi3/kUlBpbabXXiDNJafJBINdWY SS9KXm8jj7SYNfP/GuF0HYfyNGcEScKlFPf4EDtY3CAbb9rnahjLRuhkc 9zbwniAXhUok7QvKo8w84RduuKIIMCACRwmVrkSUViEpQRd2oGLM6GlYy A4CwBOPaspQZkguufWGpchke6GCr53O5ETjI9UhRcCQ4RMSPQXP5ZQprI fMiw2zHwbw6AtcrSre9yB2aOyganmdmBV6fdBDpt32LPzvuU16aj6l/99 98u9aCbmBYG+wbuZ3WeUMfBI9TJXElLPdabX2reEpZSR1ZUpBzvkFsgcS A==; IronPort-SDR: raW/1qcKdHAZdMSyVUgmp/qXKAL8YrUQjsmsaO0yL8zejdgtPBPMIm33A0OhSZ1mcOUdr0UzAO +XyVwaJ0twK40F50XULgFWq5Ia95ioUY2+8HtUpYerrVlR0Q9jtt2YqLT35EIBl7K491VMaJ+r P6wNVAqtGT8v4WGGJ8jdNxXYO8m/p/F/oPOO0n7GvBM2NcgkLzkckmqlow6JQC2ZyrPooEW4ZF qp2mWyA1xGRZq476zlQwZqMKwzHxt07shs/ITEHkrt/IwW9reW0DEG0mqxlNuDIln7SZyhkk2J 2Z4= X-IronPort-AV: E=Sophos;i="5.75,412,1589212800"; d="scan'208";a="144951794" 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; 30 Jul 2020 07:36:53 +0800 IronPort-SDR: 5pGJWzMD9R70grFvN8rO/dOG48oZnGJJeAk1ofjNaTHOdPGGDPQshrWg1krlEfYQKmRVn77xP7 sKj1SCbncyrUL/E/tYLXfnvll79N8/1vI= 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; 29 Jul 2020 16:25:01 -0700 IronPort-SDR: oeqQYM7W+leQjBuSIJ5zDkSvwNFMQaSHLJCpUK1gMEg4CqAH9L9Br4XFD6nduhlGKiZDBev7kH B86jS/mJrqow== WDCIronportException: Internal Received: from jpf009043.ad.shared (HELO jedi-01.hgst.com) ([10.86.58.210]) by uls-op-cesaip01.wdc.com with ESMTP; 29 Jul 2020 16:36:53 -0700 From: Atish Patra To: linux-kernel@vger.kernel.org Cc: Atish Patra , Anup Patel , Ard Biesheuvel , Arvind Sankar , Greentime Hu , Ingo Molnar , Kees Cook , linux-efi@vger.kernel.org, linux-riscv@lists.infradead.org, Mark Rutland , Masahiro Yamada , Mike Rapoport , Nick Hu , Palmer Dabbelt , "Paul E. McKenney" , Paul Walmsley , Thomas Gleixner , Will Deacon , Yash Shah , Zong Li Subject: [RFT PATCH v4 2/9] RISC-V: Add early ioremap support Date: Wed, 29 Jul 2020 16:36:28 -0700 Message-Id: <20200729233635.14406-3-atish.patra@wdc.com> X-Mailer: git-send-email 2.24.0 In-Reply-To: <20200729233635.14406-1-atish.patra@wdc.com> References: <20200729233635.14406-1-atish.patra@wdc.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.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 3230c1d48562..e6c1c98a53fb 100644 --- a/arch/riscv/Kconfig +++ b/arch/riscv/Kconfig @@ -34,6 +34,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 6a0ee2405813..c71788e6aff4 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 9c5f3e35adc2..68c608a0e91f 100644 --- a/arch/riscv/mm/init.c +++ b/arch/riscv/mm/init.c @@ -403,6 +403,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); @@ -456,6 +459,36 @@ asmlinkage void __init setup_vm(uintptr_t dtb_pa) pa + PGDIR_SIZE, PGDIR_SIZE, PAGE_KERNEL); dtb_early_va = (void *)DTB_EARLY_BASE_VA + (dtb_pa & (PGDIR_SIZE - 1)); dtb_early_pa = dtb_pa; + + /* + * 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) -- 2.24.0