Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp1737776rwd; Fri, 9 Jun 2023 01:07:35 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ4QxTv2c25jVQMevL/3X6ThIcqXZ12sK/jiZeYPLUxwV2ZZTqtOVYAu5LnDWT4v7tlBuiEq X-Received: by 2002:a05:6a20:6a26:b0:10b:60c1:2999 with SMTP id p38-20020a056a206a2600b0010b60c12999mr1359186pzk.22.1686298054712; Fri, 09 Jun 2023 01:07:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1686298054; cv=none; d=google.com; s=arc-20160816; b=AIsqJLRJ2Vi0eVC9lyPETuueLCLJPp6uENFR4rrwDG7DoIljkAoRkrdOVUwvJP9u0o 7J+fPECxhE1PqXpURVAsJZk3YvtMKUTbsUxbCOA4wrpigyME7Isx9FsuFAATLpmW7CQP e4expN+YFvYvJvqjzMXC5WfNEsIYm5DKcYbx7cOHqwMT0ovaWsDAWGvfM854zgUv9YNr khkAqv5u3p2u+jJdTbGkjc4VThmHeu0A9XnrNAmR2kE76IHJx86fuPHSFk2Jh+bTQEYq /0NeqyTV6q/s93s/PQH0Ks+c1yRq+rnj6jP18GHf9yb26YgBCidTWqqXRGpHLrWYDIq0 wMrQ== 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 :dkim-signature; bh=X3bCqAOghUMsrFt01sdBss+0xjEFSAaHuAsd0sFdmyw=; b=JgT3xgNi1ZdEadcLKRID1l7vRdrhA3WAzP/azQWi5bF3ymXJUrZZnZMbeWb12j0ME3 VmZT3ApJRBU0DYHgN7dunx/IoTKFM49zyOdaC2TlPhnfKPDwPrqHHwRj2cgk4XVKlpU2 wSZEdmjKUdyP6yUQ0CHFhO5DZXUqVmSAZClKO2wUFGyOWXI9/GXf98LIDLy1VVWADDOo vw0pyNG1PSAAYZGc4UBFQlGMGjgufVYNu2hAzMLNm1BGWM91IfjHuPbbsT7Z2XuJaBhg 5SNoAx1QKETtnhkdSqOltuJ5f55aUlas1792uNi4mcpM7DlZptiddZTRrAIo5CJ1QtJi XU7g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=aFdx9+R6; 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=redhat.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id e1-20020a636901000000b005440b9f013csi2269530pgc.899.2023.06.09.01.07.20; Fri, 09 Jun 2023 01:07:34 -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=@redhat.com header.s=mimecast20190719 header.b=aFdx9+R6; 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=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239061AbjFIH55 (ORCPT + 99 others); Fri, 9 Jun 2023 03:57:57 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34024 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239478AbjFIH53 (ORCPT ); Fri, 9 Jun 2023 03:57:29 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1AFBC3AAE for ; Fri, 9 Jun 2023 00:56:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1686297377; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=X3bCqAOghUMsrFt01sdBss+0xjEFSAaHuAsd0sFdmyw=; b=aFdx9+R6+0PGOjZBcELs4mHXfv7BGXhe29O3/WP99QZHni81TGxF/FUL2xIpMvyKx8uL/B 2OIRLLTa/tKG691bSiktdmwi1kUbd5MiANGTLfLMlYQ9TA6CLHEljiMNH1BsTxSad+7smm enEacumaBeC3o/QF4W9Zn5PbhKEbsuk= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-138-GRetf83ANGaLxKsxo5bctQ-1; Fri, 09 Jun 2023 03:56:08 -0400 X-MC-Unique: GRetf83ANGaLxKsxo5bctQ-1 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 8AF8385A5A8; Fri, 9 Jun 2023 07:56:07 +0000 (UTC) Received: from MiWiFi-R3L-srv.redhat.com (ovpn-12-92.pek2.redhat.com [10.72.12.92]) by smtp.corp.redhat.com (Postfix) with ESMTP id 6EFCF20268C6; Fri, 9 Jun 2023 07:56:01 +0000 (UTC) From: Baoquan He To: linux-kernel@vger.kernel.org Cc: linux-arch@vger.kernel.org, linux-mm@kvack.org, arnd@arndb.de, christophe.leroy@csgroup.eu, hch@lst.de, rppt@kernel.org, willy@infradead.org, agordeev@linux.ibm.com, wangkefeng.wang@huawei.com, schnelle@linux.ibm.com, David.Laight@ACULAB.COM, shorne@gmail.com, deller@gmx.de, Baoquan He Subject: [PATCH v6 04/19] mm/ioremap: Define generic_ioremap_prot() and generic_iounmap() Date: Fri, 9 Jun 2023 15:55:13 +0800 Message-Id: <20230609075528.9390-5-bhe@redhat.com> In-Reply-To: <20230609075528.9390-1-bhe@redhat.com> References: <20230609075528.9390-1-bhe@redhat.com> MIME-Version: 1.0 Content-type: text/plain Content-Transfer-Encoding: 8bit X-Scanned-By: MIMEDefang 3.1 on 10.11.54.4 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H5,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE,SPF_NONE, T_SCC_BODY_TEXT_LINE autolearn=unavailable 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 From: Christophe Leroy Define a generic version of ioremap_prot() and iounmap() that architectures can call after they have performed the necessary alteration to parameters and/or necessary verifications. Signed-off-by: Christophe Leroy Signed-off-by: Baoquan He Reviewed-by: Christoph Hellwig Reviewed-by: Kefeng Wang Reviewed-by: Mike Rapoport (IBM) --- include/asm-generic/io.h | 4 ++++ mm/ioremap.c | 22 ++++++++++++++++------ 2 files changed, 20 insertions(+), 6 deletions(-) diff --git a/include/asm-generic/io.h b/include/asm-generic/io.h index 587e7e9b9a37..a7ca2099ba19 100644 --- a/include/asm-generic/io.h +++ b/include/asm-generic/io.h @@ -1073,9 +1073,13 @@ static inline bool iounmap_allowed(void *addr) } #endif +void __iomem *generic_ioremap_prot(phys_addr_t phys_addr, size_t size, + pgprot_t prot); + void __iomem *ioremap_prot(phys_addr_t phys_addr, size_t size, unsigned long prot); void iounmap(volatile void __iomem *addr); +void generic_iounmap(volatile void __iomem *addr); static inline void __iomem *ioremap(phys_addr_t addr, size_t size) { diff --git a/mm/ioremap.c b/mm/ioremap.c index 8652426282cc..db6234b9db59 100644 --- a/mm/ioremap.c +++ b/mm/ioremap.c @@ -11,8 +11,8 @@ #include #include -void __iomem *ioremap_prot(phys_addr_t phys_addr, size_t size, - unsigned long prot) +void __iomem *generic_ioremap_prot(phys_addr_t phys_addr, size_t size, + pgprot_t prot) { unsigned long offset, vaddr; phys_addr_t last_addr; @@ -28,7 +28,7 @@ void __iomem *ioremap_prot(phys_addr_t phys_addr, size_t size, phys_addr -= offset; size = PAGE_ALIGN(size + offset); - if (!ioremap_allowed(phys_addr, size, prot)) + if (!ioremap_allowed(phys_addr, size, pgprot_val(prot))) return NULL; area = get_vm_area_caller(size, VM_IOREMAP, @@ -38,17 +38,22 @@ void __iomem *ioremap_prot(phys_addr_t phys_addr, size_t size, vaddr = (unsigned long)area->addr; area->phys_addr = phys_addr; - if (ioremap_page_range(vaddr, vaddr + size, phys_addr, - __pgprot(prot))) { + if (ioremap_page_range(vaddr, vaddr + size, phys_addr, prot)) { free_vm_area(area); return NULL; } return (void __iomem *)(vaddr + offset); } + +void __iomem *ioremap_prot(phys_addr_t phys_addr, size_t size, + unsigned long prot) +{ + return generic_ioremap_prot(phys_addr, size, __pgprot(prot)); +} EXPORT_SYMBOL(ioremap_prot); -void iounmap(volatile void __iomem *addr) +void generic_iounmap(volatile void __iomem *addr) { void *vaddr = (void *)((unsigned long)addr & PAGE_MASK); @@ -58,4 +63,9 @@ void iounmap(volatile void __iomem *addr) if (is_vmalloc_addr(vaddr)) vunmap(vaddr); } + +void iounmap(volatile void __iomem *addr) +{ + generic_iounmap(addr); +} EXPORT_SYMBOL(iounmap); -- 2.34.1