Received: by 2002:a25:e74b:0:0:0:0:0 with SMTP id e72csp1577597ybh; Thu, 16 Jul 2020 16:41:51 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwlQDUxe4+cwvwUKVxVjeUD5tXi04gGSM1EMrl0pCfQK2Y57kl8zg/xUj8FpCXo5QfXOgb6 X-Received: by 2002:a50:f413:: with SMTP id r19mr6974457edm.17.1594942910990; Thu, 16 Jul 2020 16:41:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1594942910; cv=none; d=google.com; s=arc-20160816; b=MJvcDUAWbGsFpdykT+PV2a9WpNu5F9LbzPigH8q/t7K2py9NkmQny1UdaUwTuI6V3p 5QMnQAiHNanplU3YJXn7ulZEFOZn+pfM2t1XFj4I51ukIczvxP+Vv0xleQJ4y1KHHb0u lO2UO0zqjSOveogcrCVsd37s7En3HOOiKnE0MWLjLFlhLH2Be/Os8ZD9JRTj479y1C6x tamGSf5TrWnwswsWmPKabsdgbeGQDNUrKRBjfjb9pG91pbr0Q/4M6e/5Dg3RU+YosEi3 sJ+lB2CDC1dLaCpMIeDzVCAQA+gc+zxxJp7g/x57KtrA2nAsZDfF+rmqg+9hJg8LcgAP EReQ== 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=014Pd4zypNBTf7ziBBAENTNxOizNv6SJfUzRc7/oets=; b=iMHrR1qUbaJWecAP/VtN0rRJbfsJj1CbKnK9PhvQyQG97W1r6L2uBVhBP5aqMuhiDD ScaCVfmPmmNIsTM9BqReYglcqp/FDHhQOYUxRwyVw9UcIjuccF1vSzFAUEbXP4Zr0Ci9 itAgx5RBOJjmMl1GcajGt8VAFH/isOMjhXfZZYmvlzDu9CS6bwVeTlrqg3Mb3/udlbUj PA514V45DruL6q1XqBwtu3B6q9glc8yAI1efn5FLe00UoAm74gIm1LGDu8vPN9vvtLYs CFqqZ8FwrD1oZteNTT4ELM/T4rUjWL433mgEGACqH9DfVmmBYFRv29efr8CAD8Nbp57S Lqow== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@wdc.com header.s=dkim.wdc.com header.b=PG50fNwJ; 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 v20si4035078ejj.365.2020.07.16.16.41.28; Thu, 16 Jul 2020 16:41:50 -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=PG50fNwJ; 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 S1726710AbgGPXlT (ORCPT + 99 others); Thu, 16 Jul 2020 19:41:19 -0400 Received: from esa1.hgst.iphmx.com ([68.232.141.245]:7103 "EHLO esa1.hgst.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726525AbgGPXlQ (ORCPT ); Thu, 16 Jul 2020 19:41:16 -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=1594942875; x=1626478875; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=qPX9w03TDCYp7bNgQz0FtRslpyDBjDFxb0GnLRnufaQ=; b=PG50fNwJ7HPor8UlgMVLINB0Dqmd5WeD/WcsY1BEjVrfhwPyeutAdt/O RBD/iKDUEju6JY3kWxVyBpQm8XUQ2kK7DCnzQgJ/4SclIxK+TrNb2GrAV aJtCJqkFm7PbF3sfylzMuV8cEBnIXXbuvGWGBvl2iZbWp0pZxuo9wnrc8 n6zT4V1NDiTMoMrhdb44nKKVvDSX+54M7uoUIGXnMnEOnBFlvSmU4JvvV RCEwCUSR98PyvQff5+Sj+QDK7j9PDd+mcdvEZNeO/SHqym5xCkAk9PF/p lpzFyeyYxo24OcpKOS27FS7NIDhkFURxHjQ0Lah3XFcvKf409jb8WMaIV g==; IronPort-SDR: q64N6C7EtLB+PEQsb3z75+pqdBQAykb2CRh9h8BHFv3umsZ4XHGswXNzuqXaJXgoRmnXihjK1M kRih+g96J0mmJTHZC9w/3YaMz0fXxuAFZbJgt/aDfKC6jdU9iZQgra1OW3+HK2G7ZbMOL1HoAK CQuif2ov/vVebEeGh3GN2fsSxejOlL/zk9s+qQjNpOq7HRjlzT85JIKuH5iN+5Qw/1kv0wGDsc fFFUiucbAQh8gbp98SHUAzSXJ9AS4WGv0UuFLTH7D6GOTkSRnd8OqUNVit3/P8aVo+8k551k0R +yA= X-IronPort-AV: E=Sophos;i="5.75,360,1589212800"; d="scan'208";a="251923197" 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; 17 Jul 2020 07:41:15 +0800 IronPort-SDR: Vof4SdbcI7igjszK2/KduYZArNzwUGMxnepnJhD2NVi5K2073tELMQXJ+e7NZKNiGLrO8gcQr6 7MuDg14CqF9SMMMItJr0X2WkITXUNZ5to= Received: from uls-op-cesaip02.wdc.com ([10.248.3.37]) by uls-op-cesaep01.wdc.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 16 Jul 2020 16:29:38 -0700 IronPort-SDR: 1UshUQNcXTNsprKeRtIsDqnTeMiI0w4SfIFZKKNnMH/qjkqzAg8SSedlw515LvZ0cVKy0u6QxP uEX1mYyKMT7g== WDCIronportException: Internal Received: from phd004806.ad.shared (HELO jedi-01.hgst.com) ([10.86.58.54]) by uls-op-cesaip02.wdc.com with ESMTP; 16 Jul 2020 16:41:14 -0700 From: Atish Patra To: linux-kernel@vger.kernel.org Cc: Atish Patra , Anup Patel , Ard Biesheuvel , Arnd Bergmann , Greentime Hu , Kees Cook , linux-efi@vger.kernel.org, linux-riscv@lists.infradead.org, Mark Rutland , Masahiro Yamada , Mike Rapoport , Palmer Dabbelt , Paul Walmsley , Will Deacon , Zong Li , Heinrich Schuchardt , linux-arm-kernel@lists.infradead.org Subject: [RFT PATCH v3 2/9] RISC-V: Add early ioremap support Date: Thu, 16 Jul 2020 16:40:57 -0700 Message-Id: <20200716234104.29049-3-atish.patra@wdc.com> X-Mailer: git-send-email 2.24.0 In-Reply-To: <20200716234104.29049-1-atish.patra@wdc.com> References: <20200716234104.29049-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 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 5e9328fa635b..62c90161765f 100644 --- a/arch/riscv/mm/init.c +++ b/arch/riscv/mm/init.c @@ -401,6 +401,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); @@ -451,6 +454,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) -- 2.24.0