Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp30660308rwd; Thu, 6 Jul 2023 08:56:39 -0700 (PDT) X-Google-Smtp-Source: APBJJlG4RrN5RGZfLEg6SuenM0B6TJkkFLKzAqKwp6wdGbW0R8SgOmQrA9rpeoyImZcfpW4itiEZ X-Received: by 2002:a17:90a:d258:b0:25e:fb6d:ce68 with SMTP id o24-20020a17090ad25800b0025efb6dce68mr3768340pjw.6.1688658999310; Thu, 06 Jul 2023 08:56:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1688658999; cv=none; d=google.com; s=arc-20160816; b=gF2pzgC+7eOyatwayxWcicFgLRDqL6nMX91EDmHKaQ7eE+rS0PCqQAsRdvR53iU+1F YRhVTTQYuqByauS72zVrf9qhSpOGY6OZ/EA68M4oJmwi+sYIQgBTzOgOJaSOphJ1+b14 HRQCHIEpH2srg2JgTX60hR0qQ/z4aDKnOqJsQ3G6x2/0RjxlSTysAoTJzAYaB2Wy/a97 qd3gl3boGbrZoG+23AqArVGyyK2fuDpU077/lefADCM5hTo7lYqfTTQAHKhivTw7SrJY pT95JNV6Rfdd1qHzMzoCxVe186EVOmbZvvIfvKwaU34TuJGOZ8pp5shRuEKAwwgTcL32 GPqA== 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=; fh=MRqAqm0/X6LLHlLdJym4NBXwcTEGRfSmsWs7mgX78Dg=; b=PUT27LKnPqPPSgJcEtybmz59xVeABgK1tMisTfdKYuUj5XybMjtne9ah+o0MPwe+UA UvPYiqQLoj08QAxslgR0NwIpRYmG/AKxSqSUX1OUQpjl+rK3tDphRp73iggC1uPbL/b0 NdwS7HtBJ3sTfgljkfqmJ1c8UdmTMPP8XgAnpybVcCkvqrIr5AB2gT3+VoiKhsKhX1NZ yERqidIaIQJYt8KX4lS52J7aGTIZ3SYW36H04RlIOYqII39aDWTnIiawNTWnsl28+fAT Y6p5ArUj/4qcACckN1T9NFiqXRONCtSGqfNAl/J8oLTKhZK+19kD5Bfhh/i949qnNBIv YT/g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=IF8fGozy; 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 bv128-20020a632e86000000b0055b4886e130si1646814pgb.236.2023.07.06.08.56.26; Thu, 06 Jul 2023 08:56:39 -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=IF8fGozy; 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 S231929AbjGFPrH (ORCPT + 99 others); Thu, 6 Jul 2023 11:47:07 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44884 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229996AbjGFPrF (ORCPT ); Thu, 6 Jul 2023 11:47:05 -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 AEE7C19B2 for ; Thu, 6 Jul 2023 08:46:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1688658375; 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=IF8fGozyH5BdhjFxzK679BBw/9Vjxcr92sKiIfGmtl0lb1z2ND3p3nw7u8zP60y/6b6t5H XF0ZR+nPuKwVR9NCJWzEsB7Am+lui6QbiJ5o9YuxeI5FVi7cAFLi76ZEwbj0kBcv+mYPaE v8i8fgkSGS04+aGinf+iFgKFYO2tXuQ= 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-556-7eAVe7wZPSC4sGD6Lhz-8w-1; Thu, 06 Jul 2023 11:46:10 -0400 X-MC-Unique: 7eAVe7wZPSC4sGD6Lhz-8w-1 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id EC4E6185A792; Thu, 6 Jul 2023 15:46:08 +0000 (UTC) Received: from MiWiFi-R3L-srv.redhat.com (ovpn-12-39.pek2.redhat.com [10.72.12.39]) by smtp.corp.redhat.com (Postfix) with ESMTP id 2D76AF5CF0; Thu, 6 Jul 2023 15:46:00 +0000 (UTC) From: Baoquan He To: linux-kernel@vger.kernel.org Cc: akpm@linux-foundation.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, shorne@gmail.com, David.Laight@ACULAB.COM, deller@gmx.de, nathan@kernel.org, glaubitz@physik.fu-berlin.de, Baoquan He Subject: [PATCH v8 04/19] mm/ioremap: Define generic_ioremap_prot() and generic_iounmap() Date: Thu, 6 Jul 2023 23:45:05 +0800 Message-Id: <20230706154520.11257-5-bhe@redhat.com> In-Reply-To: <20230706154520.11257-1-bhe@redhat.com> References: <20230706154520.11257-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.5 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_H4,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