From patchwork Wed Dec 20 10:34:28 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: yunhui cui X-Patchwork-Id: 181607 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:24d3:b0:fb:cd0c:d3e with SMTP id r19csp2545086dyi; Wed, 20 Dec 2023 02:35:00 -0800 (PST) X-Google-Smtp-Source: AGHT+IGpDu+qUZLKmTF7htT+Ahs717wVxbVMDyTDUxHBhw9VW6uLnk1FSJYGv14KilqSWTXSbzR0 X-Received: by 2002:a50:9517:0:b0:553:6a5b:c61f with SMTP id u23-20020a509517000000b005536a5bc61fmr2279010eda.0.1703068500215; Wed, 20 Dec 2023 02:35:00 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1703068500; cv=none; d=google.com; s=arc-20160816; b=KjRzRj2TJ5r9nq5aCz4j7fxMHKF2o7xXU/QV/Fz9DrbdY0qLAu9sGjETL56eLrg9Jv aNHHYLVZlp5T9zA2NIPcF/IvX9aKjTqsNt8RXqHQnlcUQ9Lc81nczrpufreGAbjB+GWb +q5BI/bF0uUpaKGRShXPpCNjpGQaHlCceLjzKxWlYZ1vHVb7NtJt/TfPOHv5JFQYwlGy uYB6AS519w77X0biXj0RctnDKJQOTtowSfwz/iXs2prujBFMJv3QGBRcICBbO4dPTQvI yRXEo/3LSzaX2sAzSLjOIed7phbkIA/zI3t690Hcdir8BSYMQk4SuseH0ibkS+Y5iPN4 SquA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:message-id:date:subject:to:from :dkim-signature; bh=ZFWsnBzn58gm3ZPzcT2FNSYLm3tXrViiUU3720enkpQ=; fh=jl+6d5Rj39VtLkaNNUwLxQJy34HvNPl71UAlhqoEeUs=; b=rHd6WKk4VpYsxSgVriUGUWalWLN0p+lrqX7oZrhm3gs+3mNf6IIsYzi6eMiKWs4pcB CzVlmBKXQMZPNQtNbGv7ttrSKHfAD+FDXiqyDiDxlIOGd0pa8CBKu3DLAvbR7erXCWKE qZrX1vMS3lkCxmFi1lE0ZmM/Anow7MsiReaxuJkQysBc6gX5qbhwh8aMLEX8W/qk2V/m qiyFo2E5uCI+Or+jfY1bvQalQCahciiRBN4r0CTgzAqHtH/tTAgZkLsa2jWWchvZYsx+ OfC29ao16sc4kpCYpGodlrjboazedNENq/2RQ/mcCFGEAZZeQzGmmSjS1wBpSLXkBLUy C8SQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@bytedance.com header.s=google header.b=OTmQ2Fwg; spf=pass (google.com: domain of linux-kernel+bounces-6752-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-6752-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=bytedance.com Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id x30-20020a50d61e000000b0055358b7c067si2443333edi.156.2023.12.20.02.35.00 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 20 Dec 2023 02:35:00 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-6752-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; dkim=pass header.i=@bytedance.com header.s=google header.b=OTmQ2Fwg; spf=pass (google.com: domain of linux-kernel+bounces-6752-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-6752-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=bytedance.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id D13E31F216DA for ; Wed, 20 Dec 2023 10:34:59 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id D381E20B2E; Wed, 20 Dec 2023 10:34:42 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=bytedance.com header.i=@bytedance.com header.b="OTmQ2Fwg" X-Original-To: linux-kernel@vger.kernel.org Received: from mail-pl1-f175.google.com (mail-pl1-f175.google.com [209.85.214.175]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 27AD0208C9 for ; Wed, 20 Dec 2023 10:34:37 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=bytedance.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=bytedance.com Received: by mail-pl1-f175.google.com with SMTP id d9443c01a7336-1d3b8184a84so15625425ad.1 for ; Wed, 20 Dec 2023 02:34:37 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1703068477; x=1703673277; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:message-id:date:subject:to :from:from:to:cc:subject:date:message-id:reply-to; bh=ZFWsnBzn58gm3ZPzcT2FNSYLm3tXrViiUU3720enkpQ=; b=OTmQ2Fwg1qyh9GoELCa4DASmueGFyVWb5oCaKZimOIladaaCYiegXwTxJyyKgW+OHL +VCVpcb9s38jCtKrit+L5LItvVJMnDM2tw8ldqL5ylx3y2yOSDELLtXLG+mXSNGoiyCw R1JKw6HiOTotOrig2sUJaDs0hJKcbNIo8oo0YD893RGOgRlI92mDc2xVyqJUjmh+Mnj6 I3WKwC5X96krDM++8jpt7OM0G2R/LlUo5s+4L9NW1kkpw56bZesHbVsBY6J346w7yWTu Yi8d/RVEQrhc0KKX0D28zxiFdHGR7dkuH1SdTWY/vWC6efStzHwKVAW5tZo6fAEBBBYh +XCg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1703068477; x=1703673277; h=content-transfer-encoding:mime-version:message-id:date:subject:to :from:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=ZFWsnBzn58gm3ZPzcT2FNSYLm3tXrViiUU3720enkpQ=; b=nYZWvz0EDqAsyiXIJ77sKXd8zU/e7TMnO9eoogKXKI1a0aNu7BI33ULR7fYO0wb1rC azMIfAkQx8wRd8vVuGe8+L9lBJGnIqCkAMoWrMR0tYWPPC1MJUvrRM6AOcICaSOEEQB7 5XEAtGdGcnSNO0ISsBw05Kp6mE1+V86v3AwX9NpKBAlT3WCJQkXFbH1j6qeXawuHSajk cXmf1ofBXftGXOiUfZQ/vNU1FThqM6ZJEzr5zVGOYS0B2iPq8UtF/DTIHkhjwyLTxG6W t9eXgR1Dibf6qpTgJu+ic9X6pwyronafGOvErsMNL/A/2h5Bw270r1dvNTN+lDfdQYvT LDUw== X-Gm-Message-State: AOJu0YzeZSSbLyLU+oRK/x78otgTsDpD9CdfYj5e3cPT61spNGkH8dq2 cKGBzRJI0U7Ku4jx7cszVm2itg== X-Received: by 2002:a17:903:904:b0:1d3:7c0b:d4ca with SMTP id ll4-20020a170903090400b001d37c0bd4camr6996259plb.73.1703068477268; Wed, 20 Dec 2023 02:34:37 -0800 (PST) Received: from L6YN4KR4K9.bytedance.net ([61.213.176.10]) by smtp.gmail.com with ESMTPSA id c16-20020a170903235000b001d337b8c0b2sm15525089plh.7.2023.12.20.02.34.33 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Wed, 20 Dec 2023 02:34:36 -0800 (PST) From: Yunhui Cui To: paul.walmsley@sifive.com, palmer@dabbelt.com, aou@eecs.berkeley.edu, ajones@ventanamicro.com, alexghiti@rivosinc.com, anup@brainfault.org, samitolvanen@google.com, rppt@kernel.org, panqinglin2020@iscas.ac.cn, cuiyunhui@bytedance.com, linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org Subject: [PATCH] riscv: put va_kernel_xip_pa_offset into CONFIG_XIP_KERNEL Date: Wed, 20 Dec 2023 18:34:28 +0800 Message-Id: <20231220103428.61758-1-cuiyunhui@bytedance.com> X-Mailer: git-send-email 2.39.2 (Apple Git-143) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1785796755933090552 X-GMAIL-MSGID: 1785796755933090552 opitmize the kernel_mapping_pa_to_va() and kernel_mapping_va_to_pa(). Signed-off-by: Yunhui Cui --- arch/riscv/include/asm/page.h | 33 ++++++++++++++++++++------------- 1 file changed, 20 insertions(+), 13 deletions(-) diff --git a/arch/riscv/include/asm/page.h b/arch/riscv/include/asm/page.h index 5488ecc337b6..0d2b479d02cd 100644 --- a/arch/riscv/include/asm/page.h +++ b/arch/riscv/include/asm/page.h @@ -113,8 +113,8 @@ struct kernel_mapping { unsigned long va_pa_offset; /* Offset between kernel mapping virtual address and kernel load address */ unsigned long va_kernel_pa_offset; - unsigned long va_kernel_xip_pa_offset; #ifdef CONFIG_XIP_KERNEL + unsigned long va_kernel_xip_pa_offset; uintptr_t xiprom; uintptr_t xiprom_sz; #endif @@ -134,12 +134,25 @@ extern phys_addr_t phys_ram_base; #else void *linear_mapping_pa_to_va(unsigned long x); #endif -#define kernel_mapping_pa_to_va(y) ({ \ - unsigned long _y = (unsigned long)(y); \ - (IS_ENABLED(CONFIG_XIP_KERNEL) && _y < phys_ram_base) ? \ - (void *)(_y + kernel_map.va_kernel_xip_pa_offset) : \ - (void *)(_y + kernel_map.va_kernel_pa_offset + XIP_OFFSET); \ - }) + +#ifdef CONFIG_XIP_KERNEL +#define kernel_mapping_pa_to_va(y) \ + (((unsigned long)(y) < phys_ram_base) ? \ + (void *)((unsigned long)(y) + kernel_map.va_kernel_xip_pa_offset) : \ + (void *)((unsigned long)(y) + kernel_map.va_kernel_pa_offset + XIP_OFFSET)) + +#define kernel_mapping_va_to_pa(y) \ + (((unsigned long)(y) < kernel_map.virt_addr + XIP_OFFSET) ? \ + ((unsigned long)(y) - kernel_map.va_kernel_xip_pa_offset) : \ + ((unsigned long)(y) - kernel_map.va_kernel_pa_offset - XIP_OFFSET)) +#else +#define kernel_mapping_pa_to_va(y) \ + ((void *)((unsigned long)(y) + kernel_map.va_kernel_pa_offset + XIP_OFFSET)) + +#define kernel_mapping_va_to_pa(y) \ + ((unsigned long)(y) - kernel_map.va_kernel_pa_offset - XIP_OFFSET) +#endif + #define __pa_to_va_nodebug(x) linear_mapping_pa_to_va(x) #ifndef CONFIG_DEBUG_VIRTUAL @@ -147,12 +160,6 @@ void *linear_mapping_pa_to_va(unsigned long x); #else phys_addr_t linear_mapping_va_to_pa(unsigned long x); #endif -#define kernel_mapping_va_to_pa(y) ({ \ - unsigned long _y = (unsigned long)(y); \ - (IS_ENABLED(CONFIG_XIP_KERNEL) && _y < kernel_map.virt_addr + XIP_OFFSET) ? \ - (_y - kernel_map.va_kernel_xip_pa_offset) : \ - (_y - kernel_map.va_kernel_pa_offset - XIP_OFFSET); \ - }) #define __va_to_pa_nodebug(x) ({ \ unsigned long _x = x; \