Received: by 2002:a05:6a10:a0d1:0:0:0:0 with SMTP id j17csp795793pxa; Wed, 19 Aug 2020 15:26:03 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwBV1+0pkWnbJp0/bGXdSKJBVsLE5bUR9EkCBBINja8RxUs5hgY8hEtMOdT19FCt635IIAe X-Received: by 2002:a17:906:3b8d:: with SMTP id u13mr477721ejf.205.1597875963372; Wed, 19 Aug 2020 15:26:03 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1597875963; cv=none; d=google.com; s=arc-20160816; b=mEjcY8eXmbiizjDuLmRv5/PNICOq9kdUcVHwJgu4x6o/zgHxLHId2M+YqpjkPClKm7 Qhpai7jnvjSFW/+ENLq07pUgF3RR8SDeL7q89VLWtT61GkmXaBOAlNPdCwx+nDCWPVUj XIOYZd6f5yePURPlnajbZmlU+bJloge/WqmTzS5oa74XB4aHioroZj7BQQjMEt+bXWP2 C2Ya7tFzY6kuaNOxla0ew5RKywZFQsUzxVyD6L3yu8h61yfHgAnzpWV9uYcQ+EbDzSpx ceiLexOW9r825RjGyy2yIU7jexg18ZGOg1+AxUgNUutqaYbAa0fJS7KlQOypR+YO96b4 JYcg== 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=Xt6u+jrS9wrWr3ERFuDCvVezbgM2sN+lwDtcTVEVBhs=; b=hrNDUGBrFSMMRO6M3BdJae0E6Xns3mdlgY6F29pePMv2XlSMAkJyYeoU9ei4bGOlK1 qwTUFj03i35t1wkYfcyRMdoZkTLzg4Jfl146RuqnyRKenzlt9v3G/e7JreCit6GTYoqU ojlh7NkQY/irQcRFBhQYiBt8l/Y863ik90wHCXHJVRQutGkRpSgutJ6W/W7OI/SiS/yI hzYeVHvmxmYqQ/ZZcA5xcSJoRSrKBxGCC5fdoU4Inz599V6kWLmNOzNciuQDiU97joQr dzT/WkfomFbHpLPGE6m9Vbr2793E+L227kzf4Qrfmb4rPsv4Gi7WGBZgLLXtpk0s9w39 4RaQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@wdc.com header.s=dkim.wdc.com header.b=Oyaz9BSP; 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 a20si10338ejf.632.2020.08.19.15.25.39; Wed, 19 Aug 2020 15:26:03 -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=Oyaz9BSP; 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 S1727888AbgHSWYu (ORCPT + 99 others); Wed, 19 Aug 2020 18:24:50 -0400 Received: from esa5.hgst.iphmx.com ([216.71.153.144]:15999 "EHLO esa5.hgst.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726435AbgHSWYc (ORCPT ); Wed, 19 Aug 2020 18:24:32 -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=1597875873; x=1629411873; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=1+exhHvoEzHZuKUfuZMQIx7m97ewKpgJpfZCAp36R5U=; b=Oyaz9BSP5b769Nb8UqFuXbPx5bgNg2BT6XU5V9OUqHt0iSh+ssf0Eltp fN/k1AZSC4NYmiBH2xj+eaqVgbPqymb+/NDqooyo+3T0mRNy5J+gdVryh ueCiHhd7VCC2i+CWcF4lDX7u9AWklIrwNO6Ar3G8GZUufcO155J+GATQ9 HSOURyHBSY1+ttyUOWYP9QqoG38BbKkAbUbmaBwlDcaYOLf4tEJW9UAr8 VnIa7C14Yi1iTuPbSNgFR0Tt4o1pUD1unBNI5lSxenYB+TEfBRWb1CV72 x4331nRcGCKsIR5Na20EVYX4hQj7u/vMRXgQjdt0r9SpNmWDeTl2fYm8G A==; IronPort-SDR: c2Sf10f97zd3zV6j1B/Y4kDW8nfBqq+NuFCPIXVIf69EbnbPTh21xKQwADAgxtrLE2MwNqCsB7 Q77fNsWt1QdhM6qRR2jMymAjmsGoZ9XoM7agE/f/MohB7YGSD/xCSjQZd//AncCQ6k7xpmuZh2 xhxWABXpHx5twFfo3jcDgC3dci8VjBjIT/5NT3yRbMAaw14K2h/Ewlk/SIaCzdFri24oQEAcB1 6OpUFhg3hCIFyh+rGy3S80VQ2q/WMQeKmEqwACWRxMafnmUPgUIMIZMrjCf5WiiCDcvi5LYF+n Jd4= X-IronPort-AV: E=Sophos;i="5.76,332,1592841600"; d="scan'208";a="145373594" Received: from uls-op-cesaip01.wdc.com (HELO uls-op-cesaep01.wdc.com) ([199.255.45.14]) by ob1.hgst.iphmx.com with ESMTP; 20 Aug 2020 06:24:33 +0800 IronPort-SDR: gGbIaWvFsCEipycofEB+wLuXcfkI3jFaGIZxPftSeiEwa25t2p8Im52KCWDmexJDzNSMHeqLsZ sxE7WM6wRFOQ== 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; 19 Aug 2020 15:12:15 -0700 IronPort-SDR: JRXjS/gPJIr4bbIeKh5yMdmXz9KUHTxYXV2rcVSdbupXXAQegWo2Fe4lcvHQa4az/74M0sC0Sn YLHF0OMkLBZQ== WDCIronportException: Internal Received: from 6hj08h2.ad.shared (HELO jedi-01.hgst.com) ([10.86.59.62]) by uls-op-cesaip01.wdc.com with ESMTP; 19 Aug 2020 15:24:32 -0700 From: Atish Patra To: linux-kernel@vger.kernel.org Cc: Atish Patra , Anup Patel , Palmer Dabbelt , Alistair Francis , Anup Patel , Ard Biesheuvel , Arvind Sankar , Damien Le Moal , Greentime Hu , Heiko Carstens , Ingo Molnar , Kees Cook , linux-efi@vger.kernel.org, linux-riscv@lists.infradead.org, Masahiro Yamada , Michal Simek , Mike Rapoport , Nick Desaulniers , Palmer Dabbelt , Paul Walmsley , Steven Price , Waiman Long , Zong Li , Daniel Schaefer , "abner.chang@hpe.com" Subject: [PATCH v6 2/9] RISC-V: Add early ioremap support Date: Wed, 19 Aug 2020 15:24:18 -0700 Message-Id: <20200819222425.30721-3-atish.patra@wdc.com> X-Mailer: git-send-email 2.24.0 In-Reply-To: <20200819222425.30721-1-atish.patra@wdc.com> References: <20200819222425.30721-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 Reviewed-by: Anup Patel Reviewed-by: Palmer Dabbelt --- 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 7b5905529146..15597f5f504f 100644 --- a/arch/riscv/Kconfig +++ b/arch/riscv/Kconfig @@ -37,6 +37,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 2b651f63f5c4..b75ebe8e7a92 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