Received: by 2002:a6b:500f:0:0:0:0:0 with SMTP id e15csp1449286iob; Thu, 19 May 2022 06:57:50 -0700 (PDT) X-Google-Smtp-Source: ABdhPJySM7/exicB380V8S6cbkv5XqTX15ATEuMY3lUR6YtPKqmasRxNRg7JHZrHOxFCuBbkyCmA X-Received: by 2002:a50:f69c:0:b0:42a:b933:d1d with SMTP id d28-20020a50f69c000000b0042ab9330d1dmr5287461edn.365.1652968670519; Thu, 19 May 2022 06:57:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1652968670; cv=none; d=google.com; s=arc-20160816; b=qhmkPtcf9hz/E3mM4R1ScKcqpucyZFaUjDTpwbD/KcwYwCh8wsTbn5hbXqbefm2FMq oZUl5hRC78gquShm20VE87obmwhgEFgCUI5CacN4p1SmiK6qQk+cdYI4XPIMbbMKWGj4 zMvHbKIINdTUKwmB57WL880ha59mq41nRSKvk69Gn19viAe21vCrnvKqBq0zsZiIY45H xSCmJO9Lges5fupAbw2bGQvObvuwtNr3frjmHP8MslBOgvetik8PcyaZSyNx55JOSMCw fdaZQBRxDmVAZyt9o28Ciz7NABKp0VYL6SD4wvwn+W42wmv7pmwq76F5HF6AnUxRmiCJ 5GbQ== 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=kL+xwlNKMlXq44C5yIEIWTatMQVZlH5jYQbPfkFeBGg=; b=qQwgNIs+PBmIW2YAmNndYATPWZD3UDYN5uC3yY/6NF1CFWE7Cb5qZepx6ii10Hvi3Z nDpprzgbsikH7oDJu2C5SprPDFKELP5t23IrmaR7X9XL3RVn6QLOya201F2/QWPLp9x5 C+diNrv0kUYx3ItR6q5Ts8OKjGNG5ebHQ4Ey8uXRmydVYgv0cibGEwyl/cKviOcSA4PH g8dtIiPhT43cAnIngoz/l/39tnVp/8yL31H9zDVdbDBs1IJs/prCT54sM/sTwPReTH7s 2V2De2oqYiFwEnQrF4IAjQ8k0vLHapsbmfJsbGl9aBDEkMv8JFvzvHmwb6AB/Q/lVPHr 6f7Q== ARC-Authentication-Results: i=1; mx.google.com; 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=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id n16-20020a056402061000b0042a9fd16b58si4910457edv.167.2022.05.19.06.57.24; Thu, 19 May 2022 06:57:50 -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; 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=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231191AbiESISw (ORCPT + 99 others); Thu, 19 May 2022 04:18:52 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43500 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235318AbiESIRJ (ORCPT ); Thu, 19 May 2022 04:17:09 -0400 Received: from szxga03-in.huawei.com (szxga03-in.huawei.com [45.249.212.189]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4F3DD65D03 for ; Thu, 19 May 2022 01:17:08 -0700 (PDT) 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 Content-Transfer-Encoding: 7BIT Content-Type: text/plain; charset=US-ASCII 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-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE 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 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 --- 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); -- 2.35.3