From patchwork Tue Jun 20 13:13:41 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Baoquan He X-Patchwork-Id: 13285828 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 0DF08EB64D8 for ; Tue, 20 Jun 2023 13:15:09 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 94B448D0007; Tue, 20 Jun 2023 09:15:08 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 8FBBC8D0001; Tue, 20 Jun 2023 09:15:08 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 79D2D8D0007; Tue, 20 Jun 2023 09:15:08 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id 6D05D8D0001 for ; Tue, 20 Jun 2023 09:15:08 -0400 (EDT) Received: from smtpin27.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id 2022880F1F for ; Tue, 20 Jun 2023 13:15:08 +0000 (UTC) X-FDA: 80923171896.27.AE9B34D Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by imf24.hostedemail.com (Postfix) with ESMTP id 1A2A7180024 for ; Tue, 20 Jun 2023 13:15:05 +0000 (UTC) Authentication-Results: imf24.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=fOIAtCqa; spf=pass (imf24.hostedemail.com: domain of bhe@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=bhe@redhat.com; dmarc=pass (policy=none) header.from=redhat.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1687266906; h=from:from:sender: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:dkim-signature; bh=X3bCqAOghUMsrFt01sdBss+0xjEFSAaHuAsd0sFdmyw=; b=a2A8b5Q8UkAuPp0o/nhyNCqf+BN+li+sgcJBzOeBCOh/p9LDuR6SspbWJg+On3QDgFzJSJ vFfHSSKF/rEZtZeXqHR4I1mN4NYqbmGhygYnTbOPzWyDljQgjj+DdYW+x+MVyQCirKInry KQKp5UHKf0iCq2BLoXsONfWeHcWgV64= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1687266906; a=rsa-sha256; cv=none; b=Of8j9oxuJrJfWMl6CZJAZ9+b5X2z0cZEGK9CgTO/sQ8eDsShAUZlrpvgjGcIuxtiTakjKF CC7gobB4VWC1k4lfqNHhEZbKf8cAor0YFq90xDvpa9cWs5Iav01FpDkIIcPkjWoqyM3PoF lqc5KQ4IW8pWCVPjofk45AxAHUluS24= ARC-Authentication-Results: i=1; imf24.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=fOIAtCqa; spf=pass (imf24.hostedemail.com: domain of bhe@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=bhe@redhat.com; dmarc=pass (policy=none) header.from=redhat.com 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 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.8 X-Rspamd-Queue-Id: 1A2A7180024 X-Rspam-User: X-Rspamd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tjr1xLyy6ymHynwPhh/5mJauN6ffPZcB1ilREXD5DRjW48IN3M/Xi7jK7Yz4m2gZyrRRp+AAk0M/+ctni7W1u1ZOZZjvt8A60PkWNWvq+LAAgJCLDQMAZ2uvAnGUg00/0SctOHlF5s8YSOG+1/Xc6dMieEtlyIfbz/NEFkAGWdgfzQXgfKXuJrHK7KGjMiWNg5QzmgaCGC/smrnbW8KwRUIFQFKAnynQ9U+Sg8q8Y5kniKQpaCD2RvMAbu0R/iWhzV+HvQHkEKS8ovLYhMlSLcEkZM3PXTDo+bHhivhdcq+iPkzdzyLOS4xE/PnpsYB/v8DhQR7ydlfzRDQ2PHOUenMic= 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: 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);