Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp1745879rwd; Mon, 15 May 2023 02:22:52 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ5UrRwvxWBNg4V7tsC1RuEv/K/aQPvKxpdkifbQCsi5lVJsu7jg96E8C1tPPLvxDcozyLxC X-Received: by 2002:a05:6a00:298e:b0:63c:b3be:9784 with SMTP id cj14-20020a056a00298e00b0063cb3be9784mr41553528pfb.3.1684142571737; Mon, 15 May 2023 02:22:51 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1684142571; cv=none; d=google.com; s=arc-20160816; b=vt6aG+KjgVsdBpwrobt13y1dAJJpYa6FgMrAwJTXe2Op46uijeNiU1+klpT8xrth9X BPcB7/ZxzKeWG3uReaqhEKvO0SzJ8QBU1+owq1ZVmdIfc/ZDPs6zxNRK5kZIPu8m4InZ wSj9MTZ5G4inPt9RNK6Guc5udUJrjQblqUup7vxfajTWA0jklMsJ2OOjQDvmNFnBPTlg hJrFMYh7geXqD6jU5iZqjxX2G/L0RlH+lqohCyVBUh2qVMWIYJ6g8/MGnFDG83UcvXPZ SU6Oi43g57HHseXZegt/Ja9rGB4ErVgMg40aCraFP/eT7OzpNbEUArBmUWidzajsHTW4 E9lw== 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=GS7DhM1WqHNM9FsA4uYO/JqR1nvbxtBam9rqPSjZvHw=; b=0d/vnNlkdkGEIrzYlLBHyeL1l4YkiTKENpn1QvPaY7153shTtx9470IY1x12oTS24u rBCwPoYf57E79mPqxxNAqZ47aLJKy9KRO2Cpt0AJVlDsYyfsGFQ0rEyiu6De+2MJrszu 7IGnU65ihuFRsRhdAm4Ufj5zgKOFtaQNnaYkBFP/Ovov+pRMlH9x6WisuJAvIo5kumuu ZP7bSdz8mWeKCRto/nDgpqjQ4mlUS6Fc24trjPz7VUv+QK0YKSE2wunMVeC765X1qltj 9rxJI0HV9RH0DfpxPFlzfUVX4jkBQCM4Eo7mgoCNc68MQbmHA32vuSpe5iOurpcKIb0J 1PgA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=P7UXRq21; 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 w5-20020aa79545000000b0063b652ff9cdsi16434292pfq.404.2023.05.15.02.22.39; Mon, 15 May 2023 02:22:51 -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=P7UXRq21; 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 S239788AbjEOJKv (ORCPT + 99 others); Mon, 15 May 2023 05:10:51 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48098 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239442AbjEOJKT (ORCPT ); Mon, 15 May 2023 05:10:19 -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 35371A7 for ; Mon, 15 May 2023 02:09:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1684141775; 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=GS7DhM1WqHNM9FsA4uYO/JqR1nvbxtBam9rqPSjZvHw=; b=P7UXRq21qAUClhCmKrm+c78NG2f4zU3YwS8DgOME/oPO3SgoTsXhm1afi7j/qwEz0/7uvK 87kEmO4/lR1q41XLEy67GiG+aKOlATYZd/jv5oZsDRRVQF2OgTh47xUXEKHwxzpE0RSQTW Q0IEyj9TyDdbIK6ZEOV8yphzqgqvWbg= 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-252-hNrNbfidM3eGdxOGyRRvVA-1; Mon, 15 May 2023 05:09:32 -0400 X-MC-Unique: hNrNbfidM3eGdxOGyRRvVA-1 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.rdu2.redhat.com [10.11.54.1]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 99AC6800047; Mon, 15 May 2023 09:09:31 +0000 (UTC) Received: from MiWiFi-R3L-srv.redhat.com (ovpn-12-32.pek2.redhat.com [10.72.12.32]) by smtp.corp.redhat.com (Postfix) with ESMTP id A2A2440C2063; Mon, 15 May 2023 09:09:25 +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@infradead.org, agordeev@linux.ibm.com, wangkefeng.wang@huawei.com, schnelle@linux.ibm.com, David.Laight@ACULAB.COM, shorne@gmail.com, willy@infradead.org, deller@gmx.de, Baoquan He Subject: [PATCH v5 RESEND 04/17] mm/ioremap: Define generic_ioremap_prot() and generic_iounmap() Date: Mon, 15 May 2023 17:08:35 +0800 Message-Id: <20230515090848.833045-5-bhe@redhat.com> In-Reply-To: <20230515090848.833045-1-bhe@redhat.com> References: <20230515090848.833045-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.1 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_H2,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 --- 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