From patchwork Thu May 19 08:25:50 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kefeng Wang X-Patchwork-Id: 12854631 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 kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 3394DC4332F for ; Thu, 19 May 2022 08:17:16 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 228D18D0005; Thu, 19 May 2022 04:17:14 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 0C3606B0078; Thu, 19 May 2022 04:17:14 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id E599B8D0005; Thu, 19 May 2022 04:17:13 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id BE9FE6B0075 for ; Thu, 19 May 2022 04:17:13 -0400 (EDT) Received: from smtpin11.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id A3F3F20B74 for ; Thu, 19 May 2022 08:17:13 +0000 (UTC) X-FDA: 79481787546.11.4F198C3 Received: from szxga03-in.huawei.com (szxga03-in.huawei.com [45.249.212.189]) by imf31.hostedemail.com (Postfix) with ESMTP id 1B7AB200B7 for ; Thu, 19 May 2022 08:16:42 +0000 (UTC) Received: from dggpemm500020.china.huawei.com (unknown [172.30.72.56]) by szxga03-in.huawei.com (SkyGuard) with ESMTP id 4L3jJB3WPwzCssb; Thu, 19 May 2022 16:12:10 +0800 (CST) Received: from dggpemm500001.china.huawei.com (7.185.36.107) by dggpemm500020.china.huawei.com (7.185.36.49) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.24; Thu, 19 May 2022 16:17:06 +0800 Received: from localhost.localdomain.localdomain (10.175.113.25) by dggpemm500001.china.huawei.com (7.185.36.107) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.24; Thu, 19 May 2022 16:17:05 +0800 From: Kefeng Wang To: , , , , CC: , , , , Kefeng Wang Subject: [PATCH v3 4/6] mm: ioremap: Add arch_ioremap/iounmap() Date: Thu, 19 May 2022 16:25:50 +0800 Message-ID: <20220519082552.117736-5-wangkefeng.wang@huawei.com> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20220519082552.117736-1-wangkefeng.wang@huawei.com> References: <20220519082552.117736-1-wangkefeng.wang@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.175.113.25] X-ClientProxiedBy: dggems705-chm.china.huawei.com (10.3.19.182) To dggpemm500001.china.huawei.com (7.185.36.107) X-CFilter-Loop: Reflected X-Rspam-User: X-Rspamd-Server: rspam11 X-Rspamd-Queue-Id: 1B7AB200B7 X-Stat-Signature: 4fmzofwkd1todcnr5jdtigumb5q6braw Authentication-Results: imf31.hostedemail.com; dkim=none; dmarc=pass (policy=quarantine) header.from=huawei.com; spf=pass (imf31.hostedemail.com: domain of wangkefeng.wang@huawei.com designates 45.249.212.189 as permitted sender) smtp.mailfrom=wangkefeng.wang@huawei.com X-HE-Tag: 1652948202-24248 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: Add special hook for architecture to verify or setup addr, size or prot when ioremap() or iounmap(), which will make the generic ioremap more useful. arch_ioremap() return a pointer, - IS_ERR means return an error - NULL means continue to remap - a non-NULL, non-IS_ERR pointer is directly returned arch_iounmap() return a int value, - 0 means continue to vunmap - error code means skip vunmap and return directly Signed-off-by: Kefeng Wang Acked-by: Andrew Morton Reported-by: kernel test robot --- include/asm-generic/io.h | 24 ++++++++++++++++++++++++ mm/ioremap.c | 17 ++++++++++++++--- 2 files changed, 38 insertions(+), 3 deletions(-) diff --git a/include/asm-generic/io.h b/include/asm-generic/io.h index e6ffa2519f08..b60f7151e1d6 100644 --- a/include/asm-generic/io.h +++ b/include/asm-generic/io.h @@ -964,6 +964,30 @@ static inline void iounmap(volatile void __iomem *addr) #elif defined(CONFIG_GENERIC_IOREMAP) #include +/* + * Arch code can implement the following two special hooks when using GENERIC_IOREMAP + * arch_ioremap() return a pointer, + * - IS_ERR means return an error + * - NULL means continue to remap + * - a non-NULL, non-IS_ERR pointer is returned directly + * arch_iounmap() return a int, + * - 0 means continue to vunmap + * - error code means skip vunmap and return directly + */ +#ifndef arch_ioremap +static inline void __iomem *arch_ioremap(phys_addr_t phys_addr, size_t size, unsigned long prot) +{ + return NULL; +} +#endif + +#ifndef arch_iounmap +static inline int arch_iounmap(void __iomem *addr) +{ + return 0; +} +#endif + void __iomem *ioremap_prot(phys_addr_t phys_addr, size_t size, unsigned long prot); void iounmap(volatile void __iomem *addr); diff --git a/mm/ioremap.c b/mm/ioremap.c index 7cb9996b0c12..fac7f23b8c4b 100644 --- a/mm/ioremap.c +++ b/mm/ioremap.c @@ -16,6 +16,7 @@ void __iomem *ioremap_prot(phys_addr_t phys_addr, size_t size, unsigned long pro unsigned long offset, vaddr; phys_addr_t last_addr; struct vm_struct *area; + void __iomem *base; /* Disallow wrap-around or zero size */ last_addr = phys_addr + size - 1; @@ -27,8 +28,13 @@ void __iomem *ioremap_prot(phys_addr_t phys_addr, size_t size, unsigned long pro phys_addr -= offset; size = PAGE_ALIGN(size + offset); - area = get_vm_area_caller(size, VM_IOREMAP, - __builtin_return_address(0)); + base = arch_ioremap(phys_addr, size, prot); + if (IS_ERR(base)) + return NULL; + else if (base) + return base; + + area = get_vm_area_caller(size, VM_IOREMAP, __builtin_return_address(0)); if (!area) return NULL; vaddr = (unsigned long)area->addr; @@ -45,6 +51,11 @@ EXPORT_SYMBOL(ioremap_prot); void iounmap(volatile void __iomem *addr) { - vunmap((void *)((unsigned long)addr & PAGE_MASK)); + void __iomem *vaddr = (void __iomem *)((unsigned long)addr & PAGE_MASK); + + if (arch_iounmap(vaddr)) + return; + + vunmap(vaddr); } EXPORT_SYMBOL(iounmap);