Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp7793615rwd; Tue, 20 Jun 2023 06:23:38 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ5hC1cRM/PF2ma6P9K0Cco4GoKj6+mHHlNRycMGRHP+8Ltk+qHkGSIa/KaPR2N3MoodeSul X-Received: by 2002:a05:6a00:98b:b0:668:7fb2:d991 with SMTP id u11-20020a056a00098b00b006687fb2d991mr6684310pfg.1.1687267418172; Tue, 20 Jun 2023 06:23:38 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1687267418; cv=none; d=google.com; s=arc-20160816; b=rZTb3T9DIh3cK/GzXlxWq5dkm0eAEmP5RuSTS/1Xy8H5mF2kt1SfQq8W66syQaRnIy +4U6RKaTm0lR3Rbo4AhHtED4e+awKyYUJimRL3EOzfnvlF5xcB6jDq8YUMsb8/ut1E6v X6J02/ttKVqTOi8ilJw4xNiCmY14pkAGOsrUDDoyTbbIxGjZ3TDtcirNxkGUf8lL7a5C aHAHtqfeO4bMt1Gw8udt1+8xfFt+DMfi3iPsXin+eB6Zn5XZwIIoE8B5oyS7pivZRqEy 3HSd7gHueA75TrKerh7N2Q6tarmf1DGC+VQvMHQRqoLIz7ovb3ny0qJfJNNne8U5kRPp g6Uw== 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=hnnEh8NZsQS53u40WRTjHYlydV9aWMO6ng2YtiMotMIY6H/5yoxXUDOAO8Z3UPFZ0o b9XiRSTUVDhZNoXADjBnTCtMg068HwcE3tsy+1ABAo7SLzSr3yJqrb0X4pc6rUlQsHBv OZAyi9EmL9ezrwE+zpANymMR3kr/D/Y+qx1TJOl5TaTjSwu3K4apRv4fqFT1CiJW6cYX YAsNSsqS2M4ePl0wyPq5sNqCdmoh2PQ15IalyVhA/DAvWbQRwRFvjb/m7ZmxsYJVuvCT Cvc/vN1BvCGkQURVfl1mmgeGsr3kE5z2DKP+xpKVTffXTvx1DSKc7cWfw83GdguemJ35 0XJw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=fOIAtCqa; 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 h14-20020aa79f4e000000b00666e5fec17esi1662360pfr.87.2023.06.20.06.23.23; Tue, 20 Jun 2023 06:23:38 -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=fOIAtCqa; 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 S232692AbjFTNQG (ORCPT + 99 others); Tue, 20 Jun 2023 09:16:06 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48354 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231535AbjFTNPt (ORCPT ); Tue, 20 Jun 2023 09:15:49 -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 DA7771708 for ; Tue, 20 Jun 2023 06:15:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1687266905; 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=fOIAtCqaabDvbGlJUKbk2booH1tpM19iwlaX47BZxsh5oTTkH933/Sqw9VTsIFVM2AwDHl K2qyRL7zP6LhRY0GRaR0VI/HeK5X9FvSz6ChEajvHU4pEja3dy3Red3ycUy5ePjN1zwHUX nER41E5EiPDKdKLHs8d8HOVVVxU7bhs= 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-482-epsWYn-1OK2OdZZzg18BLg-1; Tue, 20 Jun 2023 09:15:00 -0400 X-MC-Unique: epsWYn-1OK2OdZZzg18BLg-1 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.rdu2.redhat.com [10.11.54.8]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id DD04C8631DB; Tue, 20 Jun 2023 13:14:45 +0000 (UTC) Received: from MiWiFi-R3L-srv.redhat.com (ovpn-12-166.pek2.redhat.com [10.72.12.166]) by smtp.corp.redhat.com (Postfix) with ESMTP id 0019EC478C6; Tue, 20 Jun 2023 13:14:37 +0000 (UTC) From: Baoquan He To: linux-kernel@vger.kernel.org Cc: linux-arch@vger.kernel.org, linux-mm@kvack.org, arnd@arndb.de, hch@lst.de, christophe.leroy@csgroup.eu, 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, nathan@kernel.org, glaubitz@physik.fu-berlin.de, Baoquan He Subject: [PATCH v7 04/19] mm/ioremap: Define generic_ioremap_prot() and generic_iounmap() Date: Tue, 20 Jun 2023 21:13:41 +0800 Message-Id: <20230620131356.25440-5-bhe@redhat.com> In-Reply-To: <20230620131356.25440-1-bhe@redhat.com> References: <20230620131356.25440-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.8 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=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 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