Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp1046003pxj; Fri, 4 Jun 2021 04:56:13 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyquPOxqy+GoWPNSqRK024aH9eSQWyzpaEEWU7NkNiB4VdBzg7Tp3Vu08mAuDWMFvfIEnZQ X-Received: by 2002:a17:906:128e:: with SMTP id k14mr3765186ejb.485.1622807773331; Fri, 04 Jun 2021 04:56:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1622807773; cv=none; d=google.com; s=arc-20160816; b=g1A21HFlZA+fhQgYYKyIdDkMgzQ3OCxb73FH6St8X2Z0cRL2RwXH/65S/6HbujKhab 3cE+eg0zMhDWOPENYM85klwxUKqC77snLq9FO1cILpeYy+zvNrLMXUi3THoZTTbQCbYS Ts0zxjAtrbED0e5XDSI1rf2g3j1bs3KT1mug8TCNAaVk2CXiDjjO054vfkpqzUucsX6Z Xk5c3KldJYujAhHa/El9cHjk59wHNvxU3dCKHHNHS9mufPXyR3iUD/pxTFf4ke3t9pJZ CqZqB604M4vUHO+zcUkn6pArroOIngk/1AVOgtECAaeVwXktcYt7utQqPjolMOxAMwN5 j7hw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=1h/ej24WpdzdrhhurcV1lA6NHHRCd10x8R/XG+srfRc=; b=movDiilbb3EGt66A5bnesYNidpMqGKKIG3ymHp2XMp4aLnW87b9pXVtKNTqB8Rc99n 4OT1P+isVG2Tnaa9ocDxj4QCqLfnFiiHo65L3yrDmAsm8jQzg12rokrmbKBnFU1OXi7k 3OHbrqY1qhsl8vEwLIGP5ypFrs8FtfcI3gh6hvw2lPMPjar2CjLHe2dUdH0WUNyHWJme +u47tt58mpC2QdIP03802oQyjv5/oTgZpRiD3AN2qcG0d8tUo5vPX0/QLdrbDlUE0/Z7 8t/sM0gJ1qkDO8D+0lLQtr3XcGcu2AeciemC2EE/MEFkSsZloBYhZuhZns1ua36U1ps8 6rQg== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id h11si4071109edw.427.2021.06.04.04.55.50; Fri, 04 Jun 2021 04:56:13 -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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230252AbhFDLxy (ORCPT + 99 others); Fri, 4 Jun 2021 07:53:54 -0400 Received: from relay10.mail.gandi.net ([217.70.178.230]:36185 "EHLO relay10.mail.gandi.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230241AbhFDLxx (ORCPT ); Fri, 4 Jun 2021 07:53:53 -0400 Received: (Authenticated sender: alex@ghiti.fr) by relay10.mail.gandi.net (Postfix) with ESMTPSA id A0A78240007; Fri, 4 Jun 2021 11:52:03 +0000 (UTC) From: Alexandre Ghiti To: Paul Walmsley , Palmer Dabbelt , Albert Ou , Jisheng Zhang , Christoph Hellwig , Zong Li , Anup Patel , linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org Cc: Alexandre Ghiti Subject: [PATCH v4 2/4] riscv: Simplify xip and !xip kernel address conversion macros Date: Fri, 4 Jun 2021 13:49:48 +0200 Message-Id: <20210604114950.1446390-3-alex@ghiti.fr> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210604114950.1446390-1-alex@ghiti.fr> References: <20210604114950.1446390-1-alex@ghiti.fr> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org To simplify the kernel address conversion code, make the same definition of kernel_mapping_pa_to_va and kernel_mapping_va_to_pa compatible for both xip and !xip kernel by defining XIP_OFFSET to 0 in !xip kernel. Signed-off-by: Alexandre Ghiti Reviewed-by: Anup Patel --- arch/riscv/include/asm/page.h | 14 +++----------- arch/riscv/include/asm/pgtable.h | 2 ++ 2 files changed, 5 insertions(+), 11 deletions(-) diff --git a/arch/riscv/include/asm/page.h b/arch/riscv/include/asm/page.h index 6a7761c86ec2..6e004d8fda4d 100644 --- a/arch/riscv/include/asm/page.h +++ b/arch/riscv/include/asm/page.h @@ -93,9 +93,7 @@ extern unsigned long va_pa_offset; #ifdef CONFIG_64BIT extern unsigned long va_kernel_pa_offset; #endif -#ifdef CONFIG_XIP_KERNEL extern unsigned long va_kernel_xip_pa_offset; -#endif extern unsigned long pfn_base; #define ARCH_PFN_OFFSET (pfn_base) #else @@ -103,6 +101,7 @@ extern unsigned long pfn_base; #ifdef CONFIG_64BIT #define va_kernel_pa_offset 0 #endif +#define va_kernel_xip_pa_offset 0 #define ARCH_PFN_OFFSET (PAGE_OFFSET >> PAGE_SHIFT) #endif /* CONFIG_MMU */ @@ -110,29 +109,22 @@ extern unsigned long kernel_virt_addr; #ifdef CONFIG_64BIT #define linear_mapping_pa_to_va(x) ((void *)((unsigned long)(x) + va_pa_offset)) -#ifdef CONFIG_XIP_KERNEL #define kernel_mapping_pa_to_va(y) ({ \ unsigned long _y = y; \ (_y >= CONFIG_PHYS_RAM_BASE) ? \ (void *)((unsigned long)(_y) + va_kernel_pa_offset + XIP_OFFSET) : \ (void *)((unsigned long)(_y) + va_kernel_xip_pa_offset); \ }) -#else -#define kernel_mapping_pa_to_va(x) ((void *)((unsigned long)(x) + va_kernel_pa_offset)) -#endif #define __pa_to_va_nodebug(x) linear_mapping_pa_to_va(x) #define linear_mapping_va_to_pa(x) ((unsigned long)(x) - va_pa_offset) -#ifdef CONFIG_XIP_KERNEL #define kernel_mapping_va_to_pa(y) ({ \ unsigned long _y = y; \ (_y < kernel_virt_addr + XIP_OFFSET) ? \ ((unsigned long)(_y) - va_kernel_xip_pa_offset) : \ ((unsigned long)(_y) - va_kernel_pa_offset - XIP_OFFSET); \ }) -#else -#define kernel_mapping_va_to_pa(x) ((unsigned long)(x) - va_kernel_pa_offset) -#endif + #define __va_to_pa_nodebug(x) ({ \ unsigned long _x = x; \ (_x < kernel_virt_addr) ? \ @@ -141,7 +133,7 @@ extern unsigned long kernel_virt_addr; #else #define __pa_to_va_nodebug(x) ((void *)((unsigned long) (x) + va_pa_offset)) #define __va_to_pa_nodebug(x) ((unsigned long)(x) - va_pa_offset) -#endif +#endif /* CONFIG_64BIT */ #ifdef CONFIG_DEBUG_VIRTUAL extern phys_addr_t __virt_to_phys(unsigned long x); diff --git a/arch/riscv/include/asm/pgtable.h b/arch/riscv/include/asm/pgtable.h index bde8ce3bfe7c..d98e931a31e5 100644 --- a/arch/riscv/include/asm/pgtable.h +++ b/arch/riscv/include/asm/pgtable.h @@ -77,6 +77,8 @@ #ifdef CONFIG_XIP_KERNEL #define XIP_OFFSET SZ_8M +#else +#define XIP_OFFSET 0 #endif #ifndef __ASSEMBLY__ -- 2.30.2