From patchwork Fri Mar 24 15:54:19 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexandre Ghiti X-Patchwork-Id: 13186978 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 9ACF8C6FD20 for ; Fri, 24 Mar 2023 15:55:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=q8mDaPTH5FP0KljysdEm3P7xSzsLqgoEln0z/v0unrg=; b=45fZqPo9+yZIgN dXws1KxFvDHhGmelmvarV6xr69C6nwtRwv4iwSO2vRwNmBW2Sf8icfxc+lAJWF91lkdmkuVsAqbL4 sqfXr7ENdA6FAy1y0J4yT8fLzl7JOwXbN0R3F2E/BsFiTJUTnI4/JwkAFMGPCtXJmSMt0Gj4U6fL8 mZ6L0SUFgnN+b3sy5AM8riutQkWgW9wFfJpUsYgOx7/X63cpw0vesNd3m1Bi1jxA3kOFSuY0p89Z+ Jv/mQDO20I4pDxhhB9EmetIrhZC/vXnDcMkn4zJWzsY1J9imAt+D7YGJwIe2sSBmTjsUM5aJ5oSCo 3lHDlvZqNWpuMDUYCHrw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1pfjlP-004v9O-0i; Fri, 24 Mar 2023 15:55:35 +0000 Received: from mail-wr1-x42d.google.com ([2a00:1450:4864:20::42d]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1pfjlM-004v8J-2O for linux-riscv@lists.infradead.org; Fri, 24 Mar 2023 15:55:34 +0000 Received: by mail-wr1-x42d.google.com with SMTP id r11so2286651wrr.12 for ; Fri, 24 Mar 2023 08:55:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20210112.gappssmtp.com; s=20210112; t=1679673330; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=Tp3HoPN4Gc82+RijS+v6sxY9JgB+vr3DxCDQErkACNI=; b=ZWNhHoXsX43350iih+wD2VNFUpSmPZg3GoR5+pdNWLoUbl7wO5tfkt7YCB3poRYl8m QKSnyLjo+RRmDEJN3/k3T0mFwzkstsnUrvxIbT4zvwl2sHXeUOWBGBxGM6CCneBRAH8h hInUCCtT4YIpqv1pG3b1V7EMYdJI+JHKt+HkFcEiECEXJJ7Eac3jDBUEciRtu5JnJ9P2 3TQpRwkH2qpr9pW05hvbeHJLEoYl76Gd8emmbghk/tOJF2k3L8T45BKZZ36DMpuM/iRo hEy9lrCMYSMC1vVFvsPgI289oVnGc80AOZvfRdGJURQiohqSFW+zGiatqjGAAD8L8js3 Mv5w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1679673330; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=Tp3HoPN4Gc82+RijS+v6sxY9JgB+vr3DxCDQErkACNI=; b=gRYOg5SU7SA82LOGNKVlaP04OUxHXuJ8/cUvFfjPq5WvwBOPw2xgr1hl8kbjeoSloo UOE605ZtK7y/Njb0jpb3hoIPzoucPQ//gDpxhQkAmCuCmhljLv47KdDpsBErwhDed7PR zKoYdcJFI4NG7Bjv6XawtfeEEvsRVvzrGgogFadmGpXUzjBWv8FeCN4/pPHyyJGLl6i+ IcX/e3d/el1NmA8G+R34Hf1e4Idm4JC2poMThm2hl0FYgAGXP4qVEjnq5hWxSf4fHRvn BIHAZqpv0TgNUg2HrQ6zFaFEzEWzRz9xl+ZeVOXDUPxyiMC5xxJ24sGeSYK10+NMidBm lXDA== X-Gm-Message-State: AAQBX9fGayjKhJAJYCyizQts2uRHhmRc5lj7EvIOcNXHCURK2SLmHzr/ 1Z/3XtGFpLDCiwjGKoFvddLDmg== X-Google-Smtp-Source: AKy350ak7ygxOxi4tYX8LpUVbV5mkgHWSgSVhi5JP6SXzo1OaZPV4mcFr7AfECSFJWF0WAqOGrpbnw== X-Received: by 2002:a5d:4809:0:b0:2ce:ae4c:c424 with SMTP id l9-20020a5d4809000000b002ceae4cc424mr3047287wrq.4.1679673330170; Fri, 24 Mar 2023 08:55:30 -0700 (PDT) Received: from alex-rivos.home (amontpellier-656-1-456-62.w92-145.abo.wanadoo.fr. [92.145.124.62]) by smtp.gmail.com with ESMTPSA id m8-20020a5d4a08000000b002c3f03d8851sm18571070wrq.16.2023.03.24.08.55.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 24 Mar 2023 08:55:29 -0700 (PDT) From: Alexandre Ghiti To: Paul Walmsley , Palmer Dabbelt , Albert Ou , Rob Herring , Frank Rowand , Andrew Jones , Anup Patel , linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org, devicetree@vger.kernel.org Cc: Alexandre Ghiti Subject: [PATCH v9 1/3] riscv: Get rid of riscv_pfn_base variable Date: Fri, 24 Mar 2023 16:54:19 +0100 Message-Id: <20230324155421.271544-2-alexghiti@rivosinc.com> X-Mailer: git-send-email 2.37.2 In-Reply-To: <20230324155421.271544-1-alexghiti@rivosinc.com> References: <20230324155421.271544-1-alexghiti@rivosinc.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230324_085532_781163_6DC88A70 X-CRM114-Status: GOOD ( 15.96 ) X-BeenThere: linux-riscv@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-riscv" Errors-To: linux-riscv-bounces+linux-riscv=archiver.kernel.org@lists.infradead.org Use directly phys_ram_base instead, riscv_pfn_base is just the pfn of the address contained in phys_ram_base. Even if there is no functional change intended in this patch, actually setting phys_ram_base that early changes the behaviour of kernel_mapping_pa_to_va during the early boot: phys_ram_base used to be zero before this patch and now it is set to the physical start address of the kernel. But it does not break the conversion of a kernel physical address into a virtual address since kernel_mapping_pa_to_va should only be used on kernel physical addresses, i.e. addresses greater than the physical start address of the kernel. Signed-off-by: Alexandre Ghiti Reviewed-by: Andrew Jones Reviewed-by: Anup Patel Tested-by: Anup Patel --- arch/riscv/include/asm/page.h | 3 +-- arch/riscv/mm/init.c | 6 +----- 2 files changed, 2 insertions(+), 7 deletions(-) diff --git a/arch/riscv/include/asm/page.h b/arch/riscv/include/asm/page.h index 7fed7c431928..8dc686f549b6 100644 --- a/arch/riscv/include/asm/page.h +++ b/arch/riscv/include/asm/page.h @@ -91,8 +91,7 @@ typedef struct page *pgtable_t; #endif #ifdef CONFIG_MMU -extern unsigned long riscv_pfn_base; -#define ARCH_PFN_OFFSET (riscv_pfn_base) +#define ARCH_PFN_OFFSET (PFN_DOWN((unsigned long)phys_ram_base)) #else #define ARCH_PFN_OFFSET (PAGE_OFFSET >> PAGE_SHIFT) #endif /* CONFIG_MMU */ diff --git a/arch/riscv/mm/init.c b/arch/riscv/mm/init.c index 87f6a5d475a6..cc558d94559a 100644 --- a/arch/riscv/mm/init.c +++ b/arch/riscv/mm/init.c @@ -271,9 +271,6 @@ static void __init setup_bootmem(void) #ifdef CONFIG_MMU struct pt_alloc_ops pt_ops __initdata; -unsigned long riscv_pfn_base __ro_after_init; -EXPORT_SYMBOL(riscv_pfn_base); - pgd_t swapper_pg_dir[PTRS_PER_PGD] __page_aligned_bss; pgd_t trampoline_pg_dir[PTRS_PER_PGD] __page_aligned_bss; static pte_t fixmap_pte[PTRS_PER_PTE] __page_aligned_bss; @@ -285,7 +282,6 @@ static pmd_t __maybe_unused early_dtb_pmd[PTRS_PER_PMD] __initdata __aligned(PAG #ifdef CONFIG_XIP_KERNEL #define pt_ops (*(struct pt_alloc_ops *)XIP_FIXUP(&pt_ops)) -#define riscv_pfn_base (*(unsigned long *)XIP_FIXUP(&riscv_pfn_base)) #define trampoline_pg_dir ((pgd_t *)XIP_FIXUP(trampoline_pg_dir)) #define fixmap_pte ((pte_t *)XIP_FIXUP(fixmap_pte)) #define early_pg_dir ((pgd_t *)XIP_FIXUP(early_pg_dir)) @@ -985,7 +981,7 @@ asmlinkage void __init setup_vm(uintptr_t dtb_pa) kernel_map.va_pa_offset = PAGE_OFFSET - kernel_map.phys_addr; kernel_map.va_kernel_pa_offset = kernel_map.virt_addr - kernel_map.phys_addr; - riscv_pfn_base = PFN_DOWN(kernel_map.phys_addr); + phys_ram_base = kernel_map.phys_addr; /* * The default maximal physical memory size is KERN_VIRT_SIZE for 32-bit