From patchwork Tue Aug 8 08:40:58 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Walleij X-Patchwork-Id: 132674 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:c44e:0:b0:3f2:4152:657d with SMTP id w14csp2308513vqr; Tue, 8 Aug 2023 11:17:15 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGdFKD56ZBEyAu7voQBtlshUzWqiOtMI0tXTs8NjjDFUrSYBUQ3VOqBRbQZR5DJ8EiuhUoA X-Received: by 2002:a17:902:a518:b0:1bc:48dc:d880 with SMTP id s24-20020a170902a51800b001bc48dcd880mr494031plq.13.1691518635333; Tue, 08 Aug 2023 11:17:15 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1691518635; cv=none; d=google.com; s=arc-20160816; b=UhXS/V6Mr1rQFrSrHXDXyVbkHOKd6RG9HceahWG5TU7umt6DcRQZVKjd7zgf4A11ID l6abJqmqMG8Ss/uQancwr5nmqaLXAYGfAti2wyYonVD/VKEMg768Vdmr4u0X8avjVdmL 8nMVsdn+Q/TQ2VXUgIDsxyxhMv/tOwMOXqhxB+TaBonvohxEzU3JXReAb4cGN+I1R/pt 0h9CcHjpbd5LqKolLNWp6/gZW4eNyRBpuGXlvCBOgmeVd/YBXxBraCE8I33nbR5+dBcy gXgdyEypoxuR+vZNayg1nVL/SzVKNQAvUpjqEqYCqzHn1Dh8tFEf0VeVavJ/dzwZnGWG sleQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:message-id:content-transfer-encoding :mime-version:subject:date:from:dkim-signature; bh=aLgiueEbzobtzFNNJX0j8sjbY7XP7Xp1Qtkd3nfwoTQ=; fh=8rt/Zp/SquziV2ibY7tGcIxtw5go2QQwkmZOshU3DDw=; b=bksqHAZitiMDAgxYTeliSGswnm2lA0YKgfdtsK7hJDiXA3EzW3TtAEW6dbkT9TB3YC kOMGGjUvqh1NkA1hoMUKuOAyNnQVbQtxic7WDTaJ5t2qMY1nWwyyaikM9VOZODf2AjTq EHHbiBZ2WrQI5nWaFbxmKfMOuCPtV/CemUJhE+QX+vRwMYjrOV1Vcu/MUGLKrIqn21rc fYD/gh1Ul0TvRHh/2CMpGcL2TEmIWmT8+fjWXqj/EawaHxWOU5H/X6/ht9w0t4eaHWSZ oF1bvxEPcHcN0oCuE0u6EoGD1ilCexREG6PKYKIkqB4Z8kQdiN137kPFlygRba52lR1g UpeQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=onsVEaUa; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id t6-20020a170902bc4600b001bbbbb61c71si7702635plz.399.2023.08.08.11.17.02; Tue, 08 Aug 2023 11:17:15 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=onsVEaUa; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230061AbjHHRwX (ORCPT + 99 others); Tue, 8 Aug 2023 13:52:23 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33442 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235077AbjHHRvT (ORCPT ); Tue, 8 Aug 2023 13:51:19 -0400 Received: from mail-ed1-x52f.google.com (mail-ed1-x52f.google.com [IPv6:2a00:1450:4864:20::52f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 677779EDB for ; Tue, 8 Aug 2023 09:23:01 -0700 (PDT) Received: by mail-ed1-x52f.google.com with SMTP id 4fb4d7f45d1cf-5230f8da574so3345914a12.3 for ; Tue, 08 Aug 2023 09:23:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1691511764; x=1692116564; h=cc:to:message-id:content-transfer-encoding:mime-version:subject :date:from:from:to:cc:subject:date:message-id:reply-to; bh=aLgiueEbzobtzFNNJX0j8sjbY7XP7Xp1Qtkd3nfwoTQ=; b=onsVEaUaP10UOYReNFOX0pIw9Z10L/wk/AgW570MTXMwplc4ITtz90qKdJgoxCbEXQ WuuHKEwQiMw+SbQX1oE79FH4WGb+7k+j11nYS0wny1XAMNNbH11KC453d23dBszkjq6y mNYWHlmUuGyb64iQvw9fj/djB9IBNGMb3TmIMKB6XcbnvJXmqiKMJt5Raxtgfp77dJIK rabwFX79CcdYCMu+mLgd24b0CzzedGa6mHuq8U0O8MDKKs3yllmyC2SRzb5czmJkAOMK jbIW633o2MV6J7AL+cb7x1ra8TVEtWB2pBRY5VgStLmg/lzq+pEQDPNhAo4Df30Aa7F+ r80w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1691511764; x=1692116564; h=cc:to:message-id:content-transfer-encoding:mime-version:subject :date:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=aLgiueEbzobtzFNNJX0j8sjbY7XP7Xp1Qtkd3nfwoTQ=; b=GrCk2qwdstZgk45bCKDqvupxKE8QMlfEeI5iTpTfL1TdNCoYtMjQcH6Y7w0ywbpznD J+tvJHY6h547S6Qtr+IB9qmvXbbIpbLjDftDLfqP+RpmWkiUHSUHHm0br/Gy1ido8ciW wKe/gRLJsGvsCuhYdzK6aSu6U0O6ycfVhWyWWA3cYlyOyYOc3xVNCZJRiOLD7Pon1Lsp +PsuM34bod/TwPTbr9bGeAuU28tOOWJr2ZSiwlwn1aDQ5i9+UP/UAvIwSg/8QeYYKy1X ufjWVLmAUVh+G9ClrzUpVBMfaTgojfYxW46x+FDXt/kf2JxcffJjL11pHFYKfXVcX1fq NoGw== X-Gm-Message-State: AOJu0YzR1hy138hKMgcW5ILAs7plbY1dO7gSG8GFPnIM611A2e2C4iXA NT3eotXIZv9C+Hb3JTmY5EcV6W4/0YSm3vwYvnY= X-Received: by 2002:a05:6512:32d1:b0:4fe:c53:1824 with SMTP id f17-20020a05651232d100b004fe0c531824mr7666076lfg.40.1691484059954; Tue, 08 Aug 2023 01:40:59 -0700 (PDT) Received: from [127.0.1.1] ([85.235.12.238]) by smtp.gmail.com with ESMTPSA id q15-20020ac2528f000000b004fbab80ecefsm1806634lfm.145.2023.08.08.01.40.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 08 Aug 2023 01:40:59 -0700 (PDT) From: Linus Walleij Date: Tue, 08 Aug 2023 10:40:58 +0200 Subject: [PATCH] microblaze: Make virt_to_pfn() a static inline MIME-Version: 1.0 Message-Id: <20230808-virt-to-phys-microblaze-v1-1-e6df710fe0a1@linaro.org> X-B4-Tracking: v=1; b=H4sIAJn/0WQC/x3MTQ5AMBBA4avIrE1SJYKriEXVlElQmYr4ibtrL L/Few8EEqYATfKA0MGB/RqRpQnYyawjIQ/RoJXOVaUqPFh23D1u0xVwYSu+n81NWBg3ON1bV5c WYr0JOT7/c9u97wf8si/5aQAAAA== To: Michal Simek Cc: linux-kernel@vger.kernel.org, Linus Walleij X-Mailer: b4 0.12.3 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1773685844412868339 X-GMAIL-MSGID: 1773685844412868339 Making virt_to_pfn() a static inline taking a strongly typed (const void *) makes the contract of a passing a pointer of that type to the function explicit and exposes any misuse of the macro virt_to_pfn() acting polymorphic and accepting many types such as (void *), (unitptr_t) or (unsigned long) as arguments without warnings. Move the function down in the file so __pa() exists in our scope, and it compiles. This in turn requires moving __pa() as it depends on __virt_to_phys() that was below. (Lazy macro evaluation conflicts with strict function ordering.) Make a symmetric change to pfn_to_virt() so we have type checking both ways. Due to this the file being included into some assembly files, some further inclusion guards are needed to make sure assembly keeps compiling. Signed-off-by: Linus Walleij --- arch/microblaze/include/asm/page.h | 27 +++++++++++++++++++-------- 1 file changed, 19 insertions(+), 8 deletions(-) --- base-commit: 06c2afb862f9da8dc5efa4b6076a0e48c3fbaaa5 change-id: 20230808-virt-to-phys-microblaze-4afdf2bcf96c Best regards, diff --git a/arch/microblaze/include/asm/page.h b/arch/microblaze/include/asm/page.h index 337f23eabc71..86a4ce07c192 100644 --- a/arch/microblaze/include/asm/page.h +++ b/arch/microblaze/include/asm/page.h @@ -99,9 +99,6 @@ extern int page_is_ram(unsigned long pfn); # define phys_to_pfn(phys) (PFN_DOWN(phys)) # define pfn_to_phys(pfn) (PFN_PHYS(pfn)) -# define virt_to_pfn(vaddr) (phys_to_pfn((__pa(vaddr)))) -# define pfn_to_virt(pfn) __va(pfn_to_phys((pfn))) - # define virt_to_page(kaddr) (pfn_to_page(__pa(kaddr) >> PAGE_SHIFT)) # define page_to_virt(page) __va(page_to_pfn(page) << PAGE_SHIFT) # define page_to_phys(page) (page_to_pfn(page) << PAGE_SHIFT) @@ -109,11 +106,6 @@ extern int page_is_ram(unsigned long pfn); # define ARCH_PFN_OFFSET (memory_start >> PAGE_SHIFT) # endif /* __ASSEMBLY__ */ -#define virt_addr_valid(vaddr) (pfn_valid(virt_to_pfn(vaddr))) - -# define __pa(x) __virt_to_phys((unsigned long)(x)) -# define __va(x) ((void *)__phys_to_virt((unsigned long)(x))) - /* Convert between virtual and physical address for MMU. */ /* Handle MicroBlaze processor with virtual memory. */ #define __virt_to_phys(addr) \ @@ -125,6 +117,25 @@ extern int page_is_ram(unsigned long pfn); #define tovirt(rd, rs) \ addik rd, rs, (CONFIG_KERNEL_START - CONFIG_KERNEL_BASE_ADDR) +#ifndef __ASSEMBLY__ + +# define __pa(x) __virt_to_phys((unsigned long)(x)) +# define __va(x) ((void *)__phys_to_virt((unsigned long)(x))) + +static inline unsigned long virt_to_pfn(const void *vaddr) +{ + return phys_to_pfn(__pa(vaddr)); +} + +static inline const void *pfn_to_virt(unsigned long pfn) +{ + return __va(pfn_to_phys((pfn))); +} + +#define virt_addr_valid(vaddr) (pfn_valid(virt_to_pfn(vaddr))) + +#endif /* __ASSEMBLY__ */ + #define TOPHYS(addr) __virt_to_phys(addr) #endif /* __KERNEL__ */