From patchwork Wed Mar 1 03:42:34 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Baoquan He X-Patchwork-Id: 62739 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:5915:0:0:0:0:0 with SMTP id v21csp3410488wrd; Tue, 28 Feb 2023 19:46:06 -0800 (PST) X-Google-Smtp-Source: AK7set8ybe4wweWjaWNcvYOHtsqBqXs8bG6jnQzeKv/7WsCJHSNSxrVNwcDxG3nrNX0TfU9IHgKv X-Received: by 2002:a05:6a20:4413:b0:cc:8ac6:90ca with SMTP id ce19-20020a056a20441300b000cc8ac690camr7441723pzb.27.1677642365746; Tue, 28 Feb 2023 19:46:05 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1677642365; cv=none; d=google.com; s=arc-20160816; b=XWAxTFAAWc2GGi/vT5B3UHHWFt8NAu43Y4UGOOo4gWgyJ6cO+2gIMAmHXL1P4wkOtD G3Eafnbn/MGohEsAZcXj7U7a4zrBlKIAeW3FgD/d7GNGmi6ci6bbhV+DgpxpNAofo80v sxY+XEwKC831FjtoOIjogaE17JyAbvvGnBTBdN8eCR5o5ya+pXkWq4rv94vLjKqudZiS ePKgkIRiQx43L/zduDul7YYTvVxm+2r0cwG49fqAceI+i9fPBtCT+QmRN9kOQI56QHLA XCVIceDPGj2JsvN7fBDxzWsAJTMV1BMBpu4+WblYaAD2QnESox40pAWJgaPpL0FEOn0N rBuw== 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=wmaPlT6qa/hIBp/Pd8+V5Z2lcUnUfL5T/RFM1vmlHuE=; b=OYnqcQhkeRA0k7u17RK+sSrt5p3U+hVUqpX3ssf4OhD32Q9iNdeRVqruYPCXKCNf36 DtAVZ84y3WA+LFHtE8YnFmmmnpJ/Jg000epJnEnMqs8tEDb2iy7mCTuEqJ7iaSsrGhz3 I4zro1LQDaJ8iYRJfCseKGiMX5jJGHM1X9ijM6lyZDYkAF34kZZe7oKvxeMGjWEFiIfY 0AR2AH7m9RPb3X+/ldT4PyuyTqvay5XQzThuoaZ2qO7WDE37TND0sGg/BahGW/bJLLrK Ej/EKe6Qk4VtS6k3l9zvfjaAi8wZ9E/at0+LwY7aSNTUJBCk+bANs0jfapk+8TPG/gQa JuNg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=Cm4kqQ3I; 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: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id v190-20020a6389c7000000b00502d6f5fb2dsi11064808pgd.805.2023.02.28.19.45.52; Tue, 28 Feb 2023 19:46:05 -0800 (PST) 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=Cm4kqQ3I; 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 S229949AbjCADoU (ORCPT + 99 others); Tue, 28 Feb 2023 22:44:20 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44806 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229718AbjCADoK (ORCPT ); Tue, 28 Feb 2023 22:44:10 -0500 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 55EF330E8A for ; Tue, 28 Feb 2023 19:43:28 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1677642207; 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=wmaPlT6qa/hIBp/Pd8+V5Z2lcUnUfL5T/RFM1vmlHuE=; b=Cm4kqQ3I2P7MTFFYgz7IHSKWdGpvMEvJnXBxOMC47ULhCXqQakwYxrj2G75M3yw+BRL1TM 71Pe7aSjNbKXJ86gFWp4ikghHFmRToZSF0OSB73iV651XWkvJy4Zs6QpHD4265rQ7CWfKa fOlak8T5HW55whGthJ3UvEPVos1iVP8= 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-14-OuyqYOYqMTWa64-MIQw-oA-1; Tue, 28 Feb 2023 22:43:23 -0500 X-MC-Unique: OuyqYOYqMTWa64-MIQw-oA-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 2BCAC101A52E; Wed, 1 Mar 2023 03:43:23 +0000 (UTC) Received: from MiWiFi-R3L-srv.redhat.com (ovpn-13-180.pek2.redhat.com [10.72.13.180]) by smtp.corp.redhat.com (Postfix) with ESMTP id 9EC34C15BAD; Wed, 1 Mar 2023 03:43:18 +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, Baoquan He Subject: [PATCH v5 04/17] mm/ioremap: Define generic_ioremap_prot() and generic_iounmap() Date: Wed, 1 Mar 2023 11:42:34 +0800 Message-Id: <20230301034247.136007-5-bhe@redhat.com> In-Reply-To: <20230301034247.136007-1-bhe@redhat.com> References: <20230301034247.136007-1-bhe@redhat.com> MIME-Version: 1.0 Content-type: text/plain 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_H2,SPF_HELO_NONE,SPF_NONE 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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1759135521386741056?= X-GMAIL-MSGID: =?utf-8?q?1759135521386741056?= 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 4c44a29b5e8e..5a9cf16ee0c2 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);