Received: by 2002:a05:6902:102b:0:0:0:0 with SMTP id x11csp125185ybt; Thu, 25 Jun 2020 17:07:53 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyR+x6+bNRdaG97Qx9/k4K0c1q9WMviG8m5SNo+NRcAP5L0TY/5kXF9XhW0mg0hPBXo7ma/ X-Received: by 2002:aa7:df08:: with SMTP id c8mr761493edy.372.1593130073469; Thu, 25 Jun 2020 17:07:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1593130073; cv=none; d=google.com; s=arc-20160816; b=smHN5f73RJJs0lkIAT9J/3Hm4qVAVgGUB1aY8UcMWc4hMVG1E9/kAglOen9hfuBCvi TGh78xOTpqltWqJZzIKv2MWK1ja1XPevEAtyjB/mbmRbMaD8nzUem/QXGm857rnT/nP2 tZyO764/iKeu5VfaUzqu4bt4Jz0PXczbhZnAmonVMDu4dDunEzu2aW5cnHRxvIxf/7Jz S7gVucqq+oEV9ixYDgytVkeDBmMoh933I/9njs/JgdALZ1yseGTMoEROKZE9C/fyjCWY PT1tdkM2Iq3x5q0b4wEQHIus/ggm9HAUc+ZkgDNGe7pQEoyFfQ0nGW6Z9mx6oeXUlqDw 3FlA== 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=55yuYx6eogYMHl1KV9bFlRzEqA7d7czojvYe6BptN6A=; b=t4fes3MjgAP1HYS92FAl7tMnngFCOw8KfBrcOJOqQxpgpHwlLvlnEHKBAr792xQRJR LhjgRcXEdWYkd7FA0bjIqOdcc53YciOq+4Jti5yOXDX5oYCiN9LlUcNY8kSV4QZC/sTj ogRq9eSj7NNlGLMX7xjVuL17G7DDLGF0AaR6QTxIgxVYt5ym4wzi4p1I7NVs5BQWEgU1 kI9xafvreFw4TpgA3i6pjb1knOuYVhf7XEw0tp98ZxMic9vYfWfMAO+iqlDvfb6x7GFR Q0pTa/4s/8w9C4XXdCyxFCXOM/JXObX4L+rP7bkDhkmTXBJ0cWecxjL5VYiUHxwdqap1 7S6Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@wdc.com header.s=dkim.wdc.com header.b=b9j81LX6; 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 b22si11220806edt.334.2020.06.25.17.07.28; Thu, 25 Jun 2020 17:07:53 -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=b9j81LX6; 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 S1726474AbgFYXp3 (ORCPT + 99 others); Thu, 25 Jun 2020 19:45:29 -0400 Received: from esa4.hgst.iphmx.com ([216.71.154.42]:4093 "EHLO esa4.hgst.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726451AbgFYXp1 (ORCPT ); Thu, 25 Jun 2020 19:45:27 -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=1593128727; x=1624664727; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=nglTD4UGuoe/uqWlZLpzP4BN9AAnND7WFwPf/vb2+9A=; b=b9j81LX6zaKAwa2S1mqU5r43IoNfymu/Ic9TVhhlBcbZEniMU2iMKZBe 1MKKHaV/orqwq2aqmcCQgsK7+CX1N9TRebUmKr7opnsevBMoIgOZCJPZX RBlnFFP24K10sveTrIEFW+dhE8tFztL2InJ7alI9AIr+J0yq3hMwIRQN/ imEijYmP4zs/UWkigKsA/yJ53uY6/mqUV/jOqXlbVvkcZQoYivd7aXDuQ /mesfUnQgAornKwBo1+sWtDatcAHppSObtcjkS/Uqlqx+GffJ9eoMwIv7 89ZE0zM+KboqwN7TQI9sJ86TrPKk7s8wllKtH2efs66SnnwIrRMv6RTdj A==; IronPort-SDR: OX/KidRhOVCqbhdDbRqfHk5BLkGHTo693/NcAWKSTDOgptO1ECIVMbeJZPnlI3OKHY1cToyfhs c07Yk9JVz5GhswDKgyDoWVSMWaEeTBHQ4ohHgQFps7ACkAarr2w9La+eZ8Z5CUNuVwiE3gjg2V 3U5B67V/DvsmK4mwEHybwkrBhzVezuVHhLIQNLA5OvLvIlLnO7d3z9r9JSFreT0oeLw8TCiN31 qJm4K6OE79VzB4o9Auad3kQ3vtHFkkX0c0WAa7sGpKpcvojghgNS6x5d/AIbaxuJRfYQWMNixw pCk= X-IronPort-AV: E=Sophos;i="5.75,280,1589212800"; d="scan'208";a="140953457" Received: from uls-op-cesaip01.wdc.com (HELO uls-op-cesaep01.wdc.com) ([199.255.45.14]) by ob1.hgst.iphmx.com with ESMTP; 26 Jun 2020 07:45:25 +0800 IronPort-SDR: 5VeXbu4O1+wxTPk4Kn+tDl9SXOE9u+dlaZXmD8bc5oVhRpu8/3bYIknYA0yicVaQiR61lI52h0 DJo4rI/gefUqRnpE599M1ZalF+ZKog7ek= 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 Cc: Atish Patra , Ard Biesheuvel , linux-efi@vger.kernel.org, linux-riscv@lists.infradead.org, Masahiro Yamada , Palmer Dabbelt , Heinrich Schuchardt , linux-arm-kernel@lists.infradead.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 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 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) -- 2.24.0