From patchwork Sat Aug 20 00:31:15 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Baoquan He X-Patchwork-Id: 12949411 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 7C481C28D13 for ; Sat, 20 Aug 2022 00:32:54 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 234D78D0005; Fri, 19 Aug 2022 20:32:54 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 1E4638D0002; Fri, 19 Aug 2022 20:32:54 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 0D38A8D0005; Fri, 19 Aug 2022 20:32:54 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id F30AD8D0002 for ; Fri, 19 Aug 2022 20:32:53 -0400 (EDT) Received: from smtpin01.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id C866E16023D for ; Sat, 20 Aug 2022 00:32:53 +0000 (UTC) X-FDA: 79818095826.01.2CC01DB Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by imf27.hostedemail.com (Postfix) with ESMTP id 01CF1400FD for ; Sat, 20 Aug 2022 00:31:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1660955499; 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=D+slbqjopuKAQI4tVcBnBFhXSd2aSoBtTrQroT8A2GE=; b=PQIyoA7CdoubvxjwtrAnTyoMGiRcjTS0/2xbieP4aceSSILPpJaSgrFZBySyMrfzSsFVtE sDFAAOyen65iHpDKPEOL6wvCYI7eIpthrG5qYZVxcpDwPWehqoTzZqX0OmopcBau0riGZj Oth1MuUjCEJjXeLfSqauvrcgHWAvkJI= 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-152-ZNHLqxdzO0uoYpWgRzA5MA-1; Fri, 19 Aug 2022 20:31:37 -0400 X-MC-Unique: ZNHLqxdzO0uoYpWgRzA5MA-1 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.rdu2.redhat.com [10.11.54.2]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 65230185A794; Sat, 20 Aug 2022 00:31:37 +0000 (UTC) Received: from MiWiFi-R3L-srv.redhat.com (ovpn-12-17.pek2.redhat.com [10.72.12.17]) by smtp.corp.redhat.com (Postfix) with ESMTP id 6651040D2827; Sat, 20 Aug 2022 00:31:33 +0000 (UTC) From: Baoquan He To: linux-kernel@vger.kernel.org Cc: linux-mm@kvack.org, akpm@linux-foundation.org, hch@infradead.org, agordeev@linux.ibm.com, wangkefeng.wang@huawei.com, linux-arm-kernel@lists.infradead.org, Baoquan He Subject: [PATCH v2 01/11] mm/ioremap: change the return value of io[re|un]map_allowed and rename Date: Sat, 20 Aug 2022 08:31:15 +0800 Message-Id: <20220820003125.353570-2-bhe@redhat.com> In-Reply-To: <20220820003125.353570-1-bhe@redhat.com> References: <20220820003125.353570-1-bhe@redhat.com> MIME-Version: 1.0 Content-type: text/plain X-Scanned-By: MIMEDefang 2.84 on 10.11.54.2 ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1660955500; a=rsa-sha256; cv=none; b=QxsnWODd4GlDnBoNLT2Ihg7FF2l74bienAeHsmMYTmnB7DE+DfuIUsHVzPwOeL+0iFeSNj CepCZrugwKrgheP9pwQRbEAqZrfOKaqwvCgP+FIZCP1peF7VDDjD9i1ANuGVje2eNarl+L GbCae7r6mWlNjP3zJNj99vLG3t0zDlQ= ARC-Authentication-Results: i=1; imf27.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=PQIyoA7C; spf=pass (imf27.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=1660955500; 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=D+slbqjopuKAQI4tVcBnBFhXSd2aSoBtTrQroT8A2GE=; b=SUk7ECxuq6MXaJv/kGitPJKJ6Df1b+JwopR96YWvDcGbRO55J/m1vFjwGg3vAsbxvEKAP4 OIa9II+D4Cs9mvDgMrDkkAlOzkVYM63Cd92VS+/yxgW/e8bKl6EWClfTk33EOzjJV886pa xKLPDCELr+gAKkC4W8Y74kJRWBr33Cc= X-Rspamd-Server: rspam01 X-Rspamd-Queue-Id: 01CF1400FD X-Rspam-User: Authentication-Results: imf27.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=PQIyoA7C; spf=pass (imf27.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 X-Stat-Signature: kf4a3p6oh7xfwjrm5nx3fifx8jfia33c X-HE-Tag: 1660955499-533303 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: In some architectures, there are ARCH specifici io address mapping handling when calling ioremap() or ioremap_prot(), e.g, arc, ia64, openrisc, s390, sh. In oder to convert them to take GENERIC_IOREMAP method, we need change the return value of hook ioremap_allowed() and iounmap_allowed(). Meanwhile, rename them to arch_ioremap() and arch_iounmap() to reflect their current behaviour. === arch_ioremap() return a bool, - IS_ERR means return an error - NULL means continue to remap - a non-NULL, non-IS_ERR pointer is returned directly arch_iounmap() return a bool, - 0 means continue to vunmap - error code means skip vunmap and return directly This is taken from Kefeng's below old patch. Christoph suggested the return value because he foresaw the doablity of converting to take GENERIC_IOREMAP on more architectures. - [PATCH v3 4/6] mm: ioremap: Add arch_ioremap/iounmap() - https://lore.kernel.org/all/20220519082552.117736-5-wangkefeng.wang@huawei.com/T/#u While at it, the invocation of arch_ioremap() need be moved to the beginning of ioremap_prot() because architectures like sh, openrisc, ia64, need do the ARCH specific io address mapping on the original physical address. And in the later patch, the address fix up code in arch_ioremap() also need be done on the original addre on some architectures. This is preparation for later patch, no functionality change. Signed-off-by: Baoquan He --- arch/arm64/include/asm/io.h | 4 ++-- arch/arm64/mm/ioremap.c | 15 ++++++++++----- include/asm-generic/io.h | 29 +++++++++++++++-------------- mm/ioremap.c | 12 ++++++++---- 4 files changed, 35 insertions(+), 25 deletions(-) diff --git a/arch/arm64/include/asm/io.h b/arch/arm64/include/asm/io.h index 877495a0fd0c..dd7e1c2dc86c 100644 --- a/arch/arm64/include/asm/io.h +++ b/arch/arm64/include/asm/io.h @@ -139,8 +139,8 @@ extern void __memset_io(volatile void __iomem *, int, size_t); * I/O memory mapping functions. */ -bool ioremap_allowed(phys_addr_t phys_addr, size_t size, unsigned long prot); -#define ioremap_allowed ioremap_allowed +void __iomem *arch_ioremap(phys_addr_t phys_addr, size_t size, unsigned long prot); +#define arch_ioremap arch_ioremap #define _PAGE_IOREMAP PROT_DEVICE_nGnRE diff --git a/arch/arm64/mm/ioremap.c b/arch/arm64/mm/ioremap.c index c5af103d4ad4..b0f4cea86f0e 100644 --- a/arch/arm64/mm/ioremap.c +++ b/arch/arm64/mm/ioremap.c @@ -3,19 +3,24 @@ #include #include -bool ioremap_allowed(phys_addr_t phys_addr, size_t size, unsigned long prot) +void __iomem *arch_ioremap(phys_addr_t phys_addr, size_t size, unsigned long prot) { - unsigned long last_addr = phys_addr + size - 1; + unsigned long last_addr, offset; + + offset = phys_addr & (~PAGE_MASK); + phys_addr -= offset; + size = PAGE_ALIGN(size + offset); + last_addr = phys_addr + size - 1; /* Don't allow outside PHYS_MASK */ if (last_addr & ~PHYS_MASK) - return false; + return IOMEM_ERR_PTR(-EINVAL); /* Don't allow RAM to be mapped. */ if (WARN_ON(pfn_is_map_memory(__phys_to_pfn(phys_addr)))) - return false; + return IOMEM_ERR_PTR(-EINVAL); - return true; + return NULL; } /* diff --git a/include/asm-generic/io.h b/include/asm-generic/io.h index a68f8fbf423b..7b6bfb62ef80 100644 --- a/include/asm-generic/io.h +++ b/include/asm-generic/io.h @@ -1049,27 +1049,28 @@ static inline void iounmap(volatile void __iomem *addr) /* * Arch code can implement the following two hooks when using GENERIC_IOREMAP - * ioremap_allowed() return a bool, - * - true means continue to remap - * - false means skip remap and return directly - * iounmap_allowed() return a bool, - * - true means continue to vunmap - * - false means skip vunmap and return directly + * arch_ioremap() return a bool, + * - IS_ERR means return an error + * - NULL means continue to remap + * - a non-NULL, non-IS_ERR pointer is returned directly + * arch_iounmap() return a bool, + * - 0 means continue to vunmap + * - error code means skip vunmap and return directly */ -#ifndef ioremap_allowed -#define ioremap_allowed ioremap_allowed -static inline bool ioremap_allowed(phys_addr_t phys_addr, size_t size, +#ifndef arch_ioremap +#define arch_ioremap arch_ioremap +static inline void __iomem *arch_ioremap(phys_addr_t phys_addr, size_t size, unsigned long prot) { - return true; + return NULL; } #endif -#ifndef iounmap_allowed -#define iounmap_allowed iounmap_allowed -static inline bool iounmap_allowed(void *addr) +#ifndef arch_iounmap +#define arch_iounmap arch_iounmap +static inline int arch_iounmap(void __iomem *addr) { - return true; + return 0; } #endif diff --git a/mm/ioremap.c b/mm/ioremap.c index 8652426282cc..99fde69becc7 100644 --- a/mm/ioremap.c +++ b/mm/ioremap.c @@ -17,6 +17,13 @@ void __iomem *ioremap_prot(phys_addr_t phys_addr, size_t size, unsigned long offset, vaddr; phys_addr_t last_addr; struct vm_struct *area; + void __iomem *ioaddr; + + ioaddr = arch_ioremap(phys_addr, size, prot); + if (IS_ERR(ioaddr)) + return NULL; + else if (ioaddr) + return ioaddr; /* Disallow wrap-around or zero size */ last_addr = phys_addr + size - 1; @@ -28,9 +35,6 @@ 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)) - return NULL; - area = get_vm_area_caller(size, VM_IOREMAP, __builtin_return_address(0)); if (!area) @@ -52,7 +56,7 @@ void iounmap(volatile void __iomem *addr) { void *vaddr = (void *)((unsigned long)addr & PAGE_MASK); - if (!iounmap_allowed(vaddr)) + if (arch_iounmap((void __iomem *)addr)) return; if (is_vmalloc_addr(vaddr)) From patchwork Sat Aug 20 00:31:16 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Baoquan He X-Patchwork-Id: 12949412 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 3550FC28D13 for ; Sat, 20 Aug 2022 00:33:38 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id AC0898D0003; Fri, 19 Aug 2022 20:33:37 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id A70768D0002; Fri, 19 Aug 2022 20:33:37 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 9117B8D0003; Fri, 19 Aug 2022 20:33:37 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id 821AF8D0002 for ; Fri, 19 Aug 2022 20:33:37 -0400 (EDT) Received: from smtpin26.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 581EC140436 for ; Sat, 20 Aug 2022 00:33:37 +0000 (UTC) X-FDA: 79818097674.26.452D1E4 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by imf07.hostedemail.com (Postfix) with ESMTP id 74F3B4004C for ; Sat, 20 Aug 2022 00:31:44 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1660955504; 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=chLY++uUFkS8hC5VhV7WNTHSImYmuTtP4WBhSWyRYLQ=; b=MCzgxoL2Ba6GNkFY/CV+yotVqsX/lsY1vpXD5y9Qp3l6qr4vIAqfIMExEflQV7v1/cZ5cG LtvnCdQh69tSn/ZtV5DPwzGvPmTDvhI+fJK7dHprmObyrjihEk9IyP0yZ5pqyMw4IrUz2c jnxy3fdirnq6hwdSUCLWPUu2Yi2hZ9c= 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-402-6TqZY1enNd6QHQ2ZnS6eDg-1; Fri, 19 Aug 2022 20:31:42 -0400 X-MC-Unique: 6TqZY1enNd6QHQ2ZnS6eDg-1 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.rdu2.redhat.com [10.11.54.2]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id F07D3185A794; Sat, 20 Aug 2022 00:31:41 +0000 (UTC) Received: from MiWiFi-R3L-srv.redhat.com (ovpn-12-17.pek2.redhat.com [10.72.12.17]) by smtp.corp.redhat.com (Postfix) with ESMTP id 2BED74010D2A; Sat, 20 Aug 2022 00:31:37 +0000 (UTC) From: Baoquan He To: linux-kernel@vger.kernel.org Cc: linux-mm@kvack.org, akpm@linux-foundation.org, hch@infradead.org, agordeev@linux.ibm.com, wangkefeng.wang@huawei.com, linux-arm-kernel@lists.infradead.org, Baoquan He Subject: [PATCH v2 02/11] mm: ioremap: fixup the physical address and page prot Date: Sat, 20 Aug 2022 08:31:16 +0800 Message-Id: <20220820003125.353570-3-bhe@redhat.com> In-Reply-To: <20220820003125.353570-1-bhe@redhat.com> References: <20220820003125.353570-1-bhe@redhat.com> MIME-Version: 1.0 Content-type: text/plain X-Scanned-By: MIMEDefang 2.84 on 10.11.54.2 ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1660955504; 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=chLY++uUFkS8hC5VhV7WNTHSImYmuTtP4WBhSWyRYLQ=; b=CVONMh621tcm6B6FEQbnXTPTIGCfdyy9YgvFkcgTNQzSruHdvDr3rmcudtj0n32rjzELlJ ahmghvDd05u8g9nzxPUR/BYD94LKCV6GxbCac5D27d1LEY7s3x/XQpwZr4/1HusNXTmXte Hj3zsL5GGqizurqRo1XaLfmCutP+Pvg= ARC-Authentication-Results: i=1; imf07.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=MCzgxoL2; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf07.hostedemail.com: domain of bhe@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=bhe@redhat.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1660955504; a=rsa-sha256; cv=none; b=yyGQG12BkQXlR1nkGayhw0kDEIom+alMuJ2Y5MPRD43p0C3u2yKqnvYm0d3Y4qXMqTD5O5 YgKu+tu1vPILeJdFJbaqBIDozfqwj0COlQqCp8LsTKrpb1GtxmD9Ybqo99SFuTe0KY6OHv TOLZdoX2Swu1oJT0QqAg4Xa2IGnpmjY= X-Stat-Signature: f97eyxbughupnco614wocub7rbwnwcon X-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: 74F3B4004C Authentication-Results: imf07.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=MCzgxoL2; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf07.hostedemail.com: domain of bhe@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=bhe@redhat.com X-Rspam-User: X-HE-Tag: 1660955504-193744 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: On some architectures, the physical address need be fixed up before doing mapping, e.g, parisc. And on architectures, e.g arc, the parameter 'prot' passed into ioremap_prot() need be adjusted too. In oder to convert them to take GENERIC_IOREMAP method, we need wrap the address fixing up code and page prot adjusting code into arch_ioremap() and pass the new address and 'prot' out for ioremap_prot() handling. This is a preparation patch, no functionality change. Signed-off-by: Baoquan He --- arch/arm64/include/asm/io.h | 3 ++- arch/arm64/mm/ioremap.c | 5 +++-- include/asm-generic/io.h | 4 ++-- mm/ioremap.c | 2 +- 4 files changed, 8 insertions(+), 6 deletions(-) diff --git a/arch/arm64/include/asm/io.h b/arch/arm64/include/asm/io.h index dd7e1c2dc86c..6a5578ddbbf6 100644 --- a/arch/arm64/include/asm/io.h +++ b/arch/arm64/include/asm/io.h @@ -139,7 +139,8 @@ extern void __memset_io(volatile void __iomem *, int, size_t); * I/O memory mapping functions. */ -void __iomem *arch_ioremap(phys_addr_t phys_addr, size_t size, unsigned long prot); +void __iomem * +arch_ioremap(phys_addr_t *paddr, size_t size, unsigned long *prot_val); #define arch_ioremap arch_ioremap #define _PAGE_IOREMAP PROT_DEVICE_nGnRE diff --git a/arch/arm64/mm/ioremap.c b/arch/arm64/mm/ioremap.c index b0f4cea86f0e..ef75ffef4dbc 100644 --- a/arch/arm64/mm/ioremap.c +++ b/arch/arm64/mm/ioremap.c @@ -3,9 +3,10 @@ #include #include -void __iomem *arch_ioremap(phys_addr_t phys_addr, size_t size, unsigned long prot) +void __iomem * +arch_ioremap(phys_addr_t *paddr, size_t size, unsigned long *prot_val) { - unsigned long last_addr, offset; + unsigned long last_addr, offset, phys_addr = *paddr; offset = phys_addr & (~PAGE_MASK); phys_addr -= offset; diff --git a/include/asm-generic/io.h b/include/asm-generic/io.h index 7b6bfb62ef80..fb9bda2be8ed 100644 --- a/include/asm-generic/io.h +++ b/include/asm-generic/io.h @@ -1059,8 +1059,8 @@ static inline void iounmap(volatile void __iomem *addr) */ #ifndef arch_ioremap #define arch_ioremap arch_ioremap -static inline void __iomem *arch_ioremap(phys_addr_t phys_addr, size_t size, - unsigned long prot) +static inline void __iomem *arch_ioremap(phys_addr_t *paddr, size_t size, + unsigned long *prot_val) { return NULL; } diff --git a/mm/ioremap.c b/mm/ioremap.c index 99fde69becc7..7914b5cf5b78 100644 --- a/mm/ioremap.c +++ b/mm/ioremap.c @@ -19,7 +19,7 @@ void __iomem *ioremap_prot(phys_addr_t phys_addr, size_t size, struct vm_struct *area; void __iomem *ioaddr; - ioaddr = arch_ioremap(phys_addr, size, prot); + ioaddr = arch_ioremap(&phys_addr, size, &prot); if (IS_ERR(ioaddr)) return NULL; else if (ioaddr) From patchwork Sat Aug 20 00:31:17 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Baoquan He X-Patchwork-Id: 12949403 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 89CD7C32789 for ; Sat, 20 Aug 2022 00:31:51 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 234528D0005; Fri, 19 Aug 2022 20:31:51 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 1E46B8D0002; Fri, 19 Aug 2022 20:31:51 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 0ACCF8D0005; Fri, 19 Aug 2022 20:31:51 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id F05ED8D0002 for ; Fri, 19 Aug 2022 20:31:50 -0400 (EDT) Received: from smtpin19.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id CEBA28010C for ; Sat, 20 Aug 2022 00:31:50 +0000 (UTC) X-FDA: 79818093180.19.AA9FC86 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by imf28.hostedemail.com (Postfix) with ESMTP id 5D493C0038 for ; Sat, 20 Aug 2022 00:31:50 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1660955510; 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=2eNlfSc2iFa+EOzhxZ962Ulne6tVckemaHbQ1FYiCFw=; b=CP+GSklVgU0g8/F4K6FC+QEh6YsGM3P9uLiziJavMlRf69dlFAHdLCnQRjI/1DBM4Dg/gt lTLlcVU/Bizaut4B9P6WLyNXOxqxBFsSAyHYMEwsXQNSU2c2hlavhHP8S9kJ4GzlVrmrq3 Cgh20Esot7tHuPbgp1F2DtirXkTJQ4g= Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-279-jw71ufJUMG6kmwDKg5AwGw-1; Fri, 19 Aug 2022 20:31:46 -0400 X-MC-Unique: jw71ufJUMG6kmwDKg5AwGw-1 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.rdu2.redhat.com [10.11.54.2]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 4566F3804502; Sat, 20 Aug 2022 00:31:46 +0000 (UTC) Received: from MiWiFi-R3L-srv.redhat.com (ovpn-12-17.pek2.redhat.com [10.72.12.17]) by smtp.corp.redhat.com (Postfix) with ESMTP id 9428B4010D2A; Sat, 20 Aug 2022 00:31:42 +0000 (UTC) From: Baoquan He To: linux-kernel@vger.kernel.org Cc: linux-mm@kvack.org, akpm@linux-foundation.org, hch@infradead.org, agordeev@linux.ibm.com, wangkefeng.wang@huawei.com, linux-arm-kernel@lists.infradead.org, Baoquan He Subject: [PATCH v2 03/11] mm: ioremap: allow ARCH to have its own ioremap definition Date: Sat, 20 Aug 2022 08:31:17 +0800 Message-Id: <20220820003125.353570-4-bhe@redhat.com> In-Reply-To: <20220820003125.353570-1-bhe@redhat.com> References: <20220820003125.353570-1-bhe@redhat.com> MIME-Version: 1.0 Content-type: text/plain X-Scanned-By: MIMEDefang 2.84 on 10.11.54.2 ARC-Authentication-Results: i=1; imf28.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=CP+GSklV; spf=pass (imf28.hostedemail.com: domain of bhe@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=bhe@redhat.com; dmarc=pass (policy=none) header.from=redhat.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1660955510; a=rsa-sha256; cv=none; b=5E65fO34a2vIYC0GnHY/tDrNNDTj+b3JmbJfJSooOtaCzvBp17EX/MRlPOhBeIgpRB5xNT u5buFMKy52wTchZI2ksN4DWtc6zyNL/+N4HYPEdAukFQs7sguFulHCVdbCArbcnI1XkS8X qsLX8H3LTzHSoUaaNBtFBMfKEmUZ4hs= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1660955510; 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=2eNlfSc2iFa+EOzhxZ962Ulne6tVckemaHbQ1FYiCFw=; b=5PDNVfbT60569ByPWb+PAc+fhNzUAcxNR6vdulwWlvtweXiUdKwNtfejOsjLZj2kJs7W+m AaK2yYl9+6OlBPygE79ETpD5OZRPQkuSASmwd11nu4bM8J1fpPJEqds5AlKdQ+wyroqMX+ b+qDSInZHPXRSwLcNU1TpvK5CRqMJuI= X-Rspam-User: Authentication-Results: imf28.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=CP+GSklV; spf=pass (imf28.hostedemail.com: domain of bhe@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=bhe@redhat.com; dmarc=pass (policy=none) header.from=redhat.com X-Rspamd-Server: rspam02 X-Stat-Signature: zoh6yhas1t65oa1dqurna878qy797r6d X-Rspamd-Queue-Id: 5D493C0038 X-HE-Tag: 1660955510-253253 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: Architectures like xtensa, arc, can be converted to GENERIC_IOREMAP, to take standard ioremap_prot() and ioremap_xxx() way. But they have ARCH specific handling for ioremap() method, than standard ioremap() method. In oder to convert them to take GENERIC_IOREMAP method, allow these architecutres to have their own ioremap definition. This is a preparation patch, no functionality change. Signed-off-by: Baoquan He --- include/asm-generic/io.h | 3 +++ 1 file changed, 3 insertions(+) diff --git a/include/asm-generic/io.h b/include/asm-generic/io.h index fb9bda2be8ed..68a8117b30fa 100644 --- a/include/asm-generic/io.h +++ b/include/asm-generic/io.h @@ -1078,11 +1078,14 @@ void __iomem *ioremap_prot(phys_addr_t phys_addr, size_t size, unsigned long prot); void iounmap(volatile void __iomem *addr); +#ifndef ioremap +#define ioremap ioremap static inline void __iomem *ioremap(phys_addr_t addr, size_t size) { /* _PAGE_IOREMAP needs to be supplied by the architecture */ return ioremap_prot(addr, size, _PAGE_IOREMAP); } +#endif #endif /* !CONFIG_MMU || CONFIG_GENERIC_IOREMAP */ #ifndef ioremap_wc From patchwork Sat Aug 20 00:31:18 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Baoquan He X-Patchwork-Id: 12949405 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 45F6BC32789 for ; Sat, 20 Aug 2022 00:31:57 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id A990A8D0006; Fri, 19 Aug 2022 20:31:56 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id A482E8D0002; Fri, 19 Aug 2022 20:31:56 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 910B18D0006; Fri, 19 Aug 2022 20:31:56 -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 8353E8D0002 for ; Fri, 19 Aug 2022 20:31:56 -0400 (EDT) Received: from smtpin11.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id 59B29AC3DB for ; Sat, 20 Aug 2022 00:31:56 +0000 (UTC) X-FDA: 79818093432.11.03681FA Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by imf30.hostedemail.com (Postfix) with ESMTP id F1B338001F for ; Sat, 20 Aug 2022 00:31:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1660955515; 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=Prjexb05+PeJL7mfd5Q9k/PdLDG/qCdG1Ri1UhBrmfs=; b=X3jbTE06DitgORGQhV6WEfJEaW7KBj7XskqKF0/oURDRV5Qup7IkzrQGMWyaponZMvWZ2i 0Q4PgCawco9kNZCrg+N0AnI/2YmdfRkkiS1bjz56207b0UIhvnuKPUKREwhhGSMKREAWaw 6RvZYG0bCpFJxhgBbP3opDgYHQu55OI= Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-564-3DboBJwJNTG8efwnNL7zjw-1; Fri, 19 Aug 2022 20:31:52 -0400 X-MC-Unique: 3DboBJwJNTG8efwnNL7zjw-1 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.rdu2.redhat.com [10.11.54.2]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id C7D0A3804502; Sat, 20 Aug 2022 00:31:51 +0000 (UTC) Received: from MiWiFi-R3L-srv.redhat.com (ovpn-12-17.pek2.redhat.com [10.72.12.17]) by smtp.corp.redhat.com (Postfix) with ESMTP id 164504010D2A; Sat, 20 Aug 2022 00:31:46 +0000 (UTC) From: Baoquan He To: linux-kernel@vger.kernel.org Cc: linux-mm@kvack.org, akpm@linux-foundation.org, hch@infradead.org, agordeev@linux.ibm.com, wangkefeng.wang@huawei.com, linux-arm-kernel@lists.infradead.org, Baoquan He , Vineet Gupta , linux-snps-arc@lists.infradead.org Subject: [PATCH v2 04/11] arc: mm: Convert to GENERIC_IOREMAP Date: Sat, 20 Aug 2022 08:31:18 +0800 Message-Id: <20220820003125.353570-5-bhe@redhat.com> In-Reply-To: <20220820003125.353570-1-bhe@redhat.com> References: <20220820003125.353570-1-bhe@redhat.com> MIME-Version: 1.0 Content-type: text/plain X-Scanned-By: MIMEDefang 2.84 on 10.11.54.2 ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1660955516; 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=Prjexb05+PeJL7mfd5Q9k/PdLDG/qCdG1Ri1UhBrmfs=; b=kbDpLj8PNN978LjScG1gFCDC+5sfm5cIeNK6An2nudAL851ymCrfel2BNN2JDBdirHjZvx pxuFegpUCwMGZ4w0WSVXfBClUKnfLKoab8O5xHhJEcHd96ZLC3W61qz9PCoKWRa1QrCvZa 3SPeA2OHR1iiQTymr0uAJ6jybPEbffA= ARC-Authentication-Results: i=1; imf30.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=X3jbTE06; spf=pass (imf30.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-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1660955516; a=rsa-sha256; cv=none; b=H9pusbGE43GMww5IG06wm2TLF5GSbVNOd+WJDj0XN7VdRCHBdKM+tKbasts55j6JQqQJM+ hDR/vmDxyiIGXLLBkvLz/yF/eKc+Cize8Q83xFUFEZ2LGJykEDWKZfpUzxeQp2+3+zkrmX 8B7PtsG1KP5/vXvrCmBb45WIBbLhM1E= X-Rspam-User: X-Rspamd-Queue-Id: F1B338001F Authentication-Results: imf30.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=X3jbTE06; spf=pass (imf30.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 X-Stat-Signature: z5niwbca6q1q4xpftkyt6kd4xgi5uiz1 X-Rspamd-Server: rspam10 X-HE-Tag: 1660955515-185431 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: Add hooks arch_ioremap() and arch_iounmap() for arc's special operation when ioremap_prot() and iounmap(). Meanwhile define and implement arc's own ioremap() because arc has some special handling in ioremap() than standard ioremap(). Signed-off-by: Baoquan He Cc: Vineet Gupta Cc: linux-snps-arc@lists.infradead.org --- arch/arc/Kconfig | 1 + arch/arc/include/asm/io.h | 19 +++++++++---- arch/arc/mm/ioremap.c | 60 ++++++--------------------------------- 3 files changed, 23 insertions(+), 57 deletions(-) diff --git a/arch/arc/Kconfig b/arch/arc/Kconfig index 9e3653253ef2..a08d2abfaf61 100644 --- a/arch/arc/Kconfig +++ b/arch/arc/Kconfig @@ -26,6 +26,7 @@ config ARC select GENERIC_PENDING_IRQ if SMP select GENERIC_SCHED_CLOCK select GENERIC_SMP_IDLE_THREAD + select GENERIC_IOREMAP select HAVE_ARCH_KGDB select HAVE_ARCH_TRACEHOOK select HAVE_ARCH_TRANSPARENT_HUGEPAGE if ARC_MMU_V4 diff --git a/arch/arc/include/asm/io.h b/arch/arc/include/asm/io.h index 8f777d6441a5..af88a2c5550e 100644 --- a/arch/arc/include/asm/io.h +++ b/arch/arc/include/asm/io.h @@ -20,9 +20,20 @@ #define __iowmb() do { } while (0) #endif -extern void __iomem *ioremap(phys_addr_t paddr, unsigned long size); -extern void __iomem *ioremap_prot(phys_addr_t paddr, unsigned long size, - unsigned long flags); +/* + * I/O memory mapping functions. + */ + +void __iomem * +arch_ioremap(phys_addr_t *paddr, size_t size, unsigned long *prot_val); +#define arch_ioremap arch_ioremap + +int arch_iounmap(void __iomem *addr); +#define arch_iounmap arch_iounmap + +void __iomem *ioremap(phys_addr_t paddr, unsigned long size); +#define ioremap ioremap + static inline void __iomem *ioport_map(unsigned long port, unsigned int nr) { return (void __iomem *)port; @@ -32,8 +43,6 @@ static inline void ioport_unmap(void __iomem *addr) { } -extern void iounmap(const void __iomem *addr); - /* * io{read,write}{16,32}be() macros */ diff --git a/arch/arc/mm/ioremap.c b/arch/arc/mm/ioremap.c index 0ee75aca6e10..72b01da31ea1 100644 --- a/arch/arc/mm/ioremap.c +++ b/arch/arc/mm/ioremap.c @@ -25,13 +25,6 @@ static inline bool arc_uncached_addr_space(phys_addr_t paddr) void __iomem *ioremap(phys_addr_t paddr, unsigned long size) { - phys_addr_t end; - - /* Don't allow wraparound or zero size */ - end = paddr + size - 1; - if (!size || (end < paddr)) - return NULL; - /* * If the region is h/w uncached, MMU mapping can be elided as optim * The cast to u32 is fine as this region can only be inside 4GB @@ -44,62 +37,25 @@ void __iomem *ioremap(phys_addr_t paddr, unsigned long size) } EXPORT_SYMBOL(ioremap); -/* - * ioremap with access flags - * Cache semantics wise it is same as ioremap - "forced" uncached. - * However unlike vanilla ioremap which bypasses ARC MMU for addresses in - * ARC hardware uncached region, this one still goes thru the MMU as caller - * might need finer access control (R/W/X) - */ -void __iomem *ioremap_prot(phys_addr_t paddr, unsigned long size, - unsigned long flags) +void __iomem * +arch_ioremap(phys_addr_t *paddr, size_t size, unsigned long *prot_val) { - unsigned int off; - unsigned long vaddr; - struct vm_struct *area; - phys_addr_t end; - pgprot_t prot = __pgprot(flags); - - /* Don't allow wraparound, zero size */ - end = paddr + size - 1; - if ((!size) || (end < paddr)) - return NULL; - /* An early platform driver might end up here */ if (!slab_is_available()) - return NULL; + return IOMEM_ERR_PTR(-EINVAL); /* force uncached */ - prot = pgprot_noncached(prot); + *prot_val = pgprot_val(pgprot_noncached(__pgprot(*prot_val))); - /* Mappings have to be page-aligned */ - off = paddr & ~PAGE_MASK; - paddr &= PAGE_MASK_PHYS; - size = PAGE_ALIGN(end + 1) - paddr; + return NULL; - /* - * Ok, go for it.. - */ - area = get_vm_area(size, VM_IOREMAP); - if (!area) - return NULL; - area->phys_addr = paddr; - vaddr = (unsigned long)area->addr; - if (ioremap_page_range(vaddr, vaddr + size, paddr, prot)) { - vunmap((void __force *)vaddr); - return NULL; - } - return (void __iomem *)(off + (char __iomem *)vaddr); } -EXPORT_SYMBOL(ioremap_prot); - -void iounmap(const void __iomem *addr) +int arch_iounmap(void __iomem *addr) { /* weird double cast to handle phys_addr_t > 32 bits */ if (arc_uncached_addr_space((phys_addr_t)(u32)addr)) - return; + return -EINVAL; - vfree((void *)(PAGE_MASK & (unsigned long __force)addr)); + return 0; } -EXPORT_SYMBOL(iounmap); From patchwork Sat Aug 20 00:31:19 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Baoquan He X-Patchwork-Id: 12949406 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 387F7C32792 for ; Sat, 20 Aug 2022 00:32:02 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id C47138D0007; Fri, 19 Aug 2022 20:32:01 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id BF6128D0002; Fri, 19 Aug 2022 20:32:01 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id A97B98D0007; Fri, 19 Aug 2022 20:32:01 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id 9C1738D0002 for ; Fri, 19 Aug 2022 20:32:01 -0400 (EDT) Received: from smtpin24.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id 5D8FA1A0457 for ; Sat, 20 Aug 2022 00:32:01 +0000 (UTC) X-FDA: 79818093642.24.29AF154 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by imf24.hostedemail.com (Postfix) with ESMTP id 1656018001D for ; Sat, 20 Aug 2022 00:32:00 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1660955520; 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=CaolBDp29uFoy9EJOCmc+prflA1CqUFRD61xKQq994g=; b=OrEp0HBTHLirN3GRE0i7xDPm1+17gcKr0yYvsfJ06JlI1arQGGJJtVjaJ005fdNw6YLEH8 Nu69gBYF5uiy0Mbrt7s5iTDFjn3wou3QPToenWnJ0H8fwLuAYGlWnGBGq6xPcRdHiJuVjr tFIH7QdsOeU9Fe4AiJGSrokcT8YAyyo= Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-255-y1mA8qUWOsm_-jR1x5dxEQ-1; Fri, 19 Aug 2022 20:31:58 -0400 X-MC-Unique: y1mA8qUWOsm_-jR1x5dxEQ-1 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.rdu2.redhat.com [10.11.54.2]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id B7EB73C025D0; Sat, 20 Aug 2022 00:31:57 +0000 (UTC) Received: from MiWiFi-R3L-srv.redhat.com (ovpn-12-17.pek2.redhat.com [10.72.12.17]) by smtp.corp.redhat.com (Postfix) with ESMTP id 96CC440D2827; Sat, 20 Aug 2022 00:31:52 +0000 (UTC) From: Baoquan He To: linux-kernel@vger.kernel.org Cc: linux-mm@kvack.org, akpm@linux-foundation.org, hch@infradead.org, agordeev@linux.ibm.com, wangkefeng.wang@huawei.com, linux-arm-kernel@lists.infradead.org, Baoquan He , Brian Cain , linux-hexagon@vger.kernel.org Subject: [PATCH v2 05/11] hexagon: mm: Convert to GENERIC_IOREMAP Date: Sat, 20 Aug 2022 08:31:19 +0800 Message-Id: <20220820003125.353570-6-bhe@redhat.com> In-Reply-To: <20220820003125.353570-1-bhe@redhat.com> References: <20220820003125.353570-1-bhe@redhat.com> MIME-Version: 1.0 Content-type: text/plain X-Scanned-By: MIMEDefang 2.84 on 10.11.54.2 ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1660955521; 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=CaolBDp29uFoy9EJOCmc+prflA1CqUFRD61xKQq994g=; b=0ZEBtfNHDDTWcLYXLAavYBKn7RvCmdON1KhfrK5wkUfDbuXlKgiw4icz9Brn/o7BEwDcsx Io7sv3loQLfEc5BdLIkzaASt0sGNg17kSQT8EnZGd1U0vY42IijPiJ7PigpnWlsYSGBu6w YgD6jXEKbpUBMWVErwm83gFsc+rHwIA= ARC-Authentication-Results: i=1; imf24.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=OrEp0HBT; spf=pass (imf24.hostedemail.com: domain of bhe@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=bhe@redhat.com; dmarc=pass (policy=none) header.from=redhat.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1660955521; a=rsa-sha256; cv=none; b=ibcX/JHwB7ste4C1PjZmmBmZaZA/3MmuknPTQT2BXlLgoAzoKb+VmrHSe+7LVAgnGsupCq FL3JvnBHGutfd3+4jVWtI7JWV7hhWCC5ZmH9ZwazompytAm9a8rlifomzZpjqbn2iS/4fs vvcT3Da2GgUC3PB0GrvMQNUsmdDWxnI= X-Rspam-User: X-Rspamd-Queue-Id: 1656018001D Authentication-Results: imf24.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=OrEp0HBT; spf=pass (imf24.hostedemail.com: domain of bhe@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=bhe@redhat.com; dmarc=pass (policy=none) header.from=redhat.com X-Stat-Signature: wzfamq79b4gpca1bykwk6ytemj9445h7 X-Rspamd-Server: rspam10 X-HE-Tag: 1660955520-122222 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: With it, the old ioremap() and iounmap() can be perfectly removed since they are duplicated with the standard functions. Signed-off-by: Baoquan He Cc: Brian Cain Cc: linux-hexagon@vger.kernel.org Acked-by: Brian Cain --- arch/hexagon/Kconfig | 1 + arch/hexagon/include/asm/io.h | 9 +++++-- arch/hexagon/mm/ioremap.c | 44 ----------------------------------- 3 files changed, 8 insertions(+), 46 deletions(-) delete mode 100644 arch/hexagon/mm/ioremap.c diff --git a/arch/hexagon/Kconfig b/arch/hexagon/Kconfig index 54eadf265178..17afffde1a7f 100644 --- a/arch/hexagon/Kconfig +++ b/arch/hexagon/Kconfig @@ -25,6 +25,7 @@ config HEXAGON select NEED_SG_DMA_LENGTH select NO_IOPORT_MAP select GENERIC_IOMAP + select GENERIC_IOREMAP select GENERIC_SMP_IDLE_THREAD select STACKTRACE_SUPPORT select GENERIC_CLOCKEVENTS_BROADCAST diff --git a/arch/hexagon/include/asm/io.h b/arch/hexagon/include/asm/io.h index c33241425a5c..e2d3091ec9d6 100644 --- a/arch/hexagon/include/asm/io.h +++ b/arch/hexagon/include/asm/io.h @@ -170,8 +170,13 @@ static inline void writel(u32 data, volatile void __iomem *addr) #define writew_relaxed __raw_writew #define writel_relaxed __raw_writel -void __iomem *ioremap(unsigned long phys_addr, unsigned long size); -#define ioremap_uc(X, Y) ioremap((X), (Y)) +/* + * I/O memory mapping functions. + */ +#define _PAGE_IOREMAP (_PAGE_PRESENT | _PAGE_READ | _PAGE_WRITE | \ + (__HEXAGON_C_DEV << 6)) + +#define ioremap_uc(addr, size) ioremap((addr), (size)) #define __raw_writel writel diff --git a/arch/hexagon/mm/ioremap.c b/arch/hexagon/mm/ioremap.c deleted file mode 100644 index 255c5b1ee1a7..000000000000 --- a/arch/hexagon/mm/ioremap.c +++ /dev/null @@ -1,44 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0-only -/* - * I/O remap functions for Hexagon - * - * Copyright (c) 2010-2011, The Linux Foundation. All rights reserved. - */ - -#include -#include -#include - -void __iomem *ioremap(unsigned long phys_addr, unsigned long size) -{ - unsigned long last_addr, addr; - unsigned long offset = phys_addr & ~PAGE_MASK; - struct vm_struct *area; - - pgprot_t prot = __pgprot(_PAGE_PRESENT|_PAGE_READ|_PAGE_WRITE - |(__HEXAGON_C_DEV << 6)); - - last_addr = phys_addr + size - 1; - - /* Wrapping not allowed */ - if (!size || (last_addr < phys_addr)) - return NULL; - - /* Rounds up to next page size, including whole-page offset */ - size = PAGE_ALIGN(offset + size); - - area = get_vm_area(size, VM_IOREMAP); - addr = (unsigned long)area->addr; - - if (ioremap_page_range(addr, addr+size, phys_addr, prot)) { - vunmap((void *)addr); - return NULL; - } - - return (void __iomem *) (offset + addr); -} - -void iounmap(const volatile void __iomem *addr) -{ - vunmap((void *) ((unsigned long) addr & PAGE_MASK)); -} From patchwork Sat Aug 20 00:31:20 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Baoquan He X-Patchwork-Id: 12949407 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 1B733C32792 for ; Sat, 20 Aug 2022 00:32:07 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id A98E98D0008; Fri, 19 Aug 2022 20:32:06 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id A484F8D0002; Fri, 19 Aug 2022 20:32:06 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 910C98D0008; Fri, 19 Aug 2022 20:32:06 -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 81B9C8D0002 for ; Fri, 19 Aug 2022 20:32:06 -0400 (EDT) Received: from smtpin12.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id 6029B1C5C13 for ; Sat, 20 Aug 2022 00:32:06 +0000 (UTC) X-FDA: 79818093852.12.8D30034 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by imf02.hostedemail.com (Postfix) with ESMTP id E993580014 for ; Sat, 20 Aug 2022 00:32:05 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1660955525; 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=Dh+PWmIZNKVOdS1VsEMPeNAUNQbcLyXNRAVVz00b5KY=; b=UuVgw1fYMMF1u8fgN381Q4w+uODCoU/VRn1LlJL9H11G+DIQLRJv/XFtvNgKntZu7rMAkT 4UxS77p5noMGzw+Z+VflXJmjvxzfe+dLYOgOey/hRBztlS3R5U9H2/BOYL6Sp68GH3XDQt aGRuLlYDjdU2yMU28iA6VLIVuhYxGcs= 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-646-s332wpH9M8q5qGNK9vpMAA-1; Fri, 19 Aug 2022 20:32:03 -0400 X-MC-Unique: s332wpH9M8q5qGNK9vpMAA-1 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.rdu2.redhat.com [10.11.54.2]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 0047F101A54E; Sat, 20 Aug 2022 00:32:03 +0000 (UTC) Received: from MiWiFi-R3L-srv.redhat.com (ovpn-12-17.pek2.redhat.com [10.72.12.17]) by smtp.corp.redhat.com (Postfix) with ESMTP id A0F8F4010E3C; Sat, 20 Aug 2022 00:31:58 +0000 (UTC) From: Baoquan He To: linux-kernel@vger.kernel.org Cc: linux-mm@kvack.org, akpm@linux-foundation.org, hch@infradead.org, agordeev@linux.ibm.com, wangkefeng.wang@huawei.com, linux-arm-kernel@lists.infradead.org, Baoquan He , linux-ia64@vger.kernel.org Subject: [PATCH v2 06/11] ia64: mm: Convert to GENERIC_IOREMAP Date: Sat, 20 Aug 2022 08:31:20 +0800 Message-Id: <20220820003125.353570-7-bhe@redhat.com> In-Reply-To: <20220820003125.353570-1-bhe@redhat.com> References: <20220820003125.353570-1-bhe@redhat.com> MIME-Version: 1.0 Content-type: text/plain X-Scanned-By: MIMEDefang 2.84 on 10.11.54.2 ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1660955525; a=rsa-sha256; cv=none; b=dqIPo9OLtGuiCNHOh/JCPjfg4mgWdZItCqIa5BasbmFFmDt+3cuUiGIVzT78q4qhF74amt lK9edwrOaMTV4p0SiYMFGIdAZnMNpmW+51+CkwZeiZqGu8Qj7AiSlCQYAvXItqVlj67AjS npvOhbbkJvgQoXBrLzAzZrOIM7osOkI= ARC-Authentication-Results: i=1; imf02.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=UuVgw1fY; spf=pass (imf02.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=1660955525; 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=Dh+PWmIZNKVOdS1VsEMPeNAUNQbcLyXNRAVVz00b5KY=; b=tMswRV7Q2KI/XiGyAoqvUoH5oKmCgO1mOu1wzF6TvuyIuG1HLYZZWjZEtCybFVScI7rukQ BjTy8BsoAeVMnP8TuShzUoB4ZYYCKqaPZ6cjIioCuXgSzqBbmdPehXmfcBmUNr27Ag3XvJ +rmoT5f1xkoZ63gF6Lky+cnbxNXMyxI= X-Rspamd-Server: rspam01 X-Rspamd-Queue-Id: E993580014 X-Rspam-User: Authentication-Results: imf02.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=UuVgw1fY; spf=pass (imf02.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 X-Stat-Signature: t5eim4ya9g6hb9kkbsgytf647cs5jnuw X-HE-Tag: 1660955525-154711 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: Add hooks arch_ioremap() and arch_iounmap() for ia64's special operation when ioremap() and iounmap(), then ioremap_cache() is converted to use ioremap_prot() from GENERIC_IOREMAP. The old ioremap_uc() is kept and add its macro definittion. Signed-off-by: Baoquan He Cc: linux-ia64@vger.kernel.org --- arch/ia64/Kconfig | 1 + arch/ia64/include/asm/io.h | 26 ++++++++++++-------- arch/ia64/mm/ioremap.c | 50 +++++++++----------------------------- 3 files changed, 28 insertions(+), 49 deletions(-) diff --git a/arch/ia64/Kconfig b/arch/ia64/Kconfig index 26ac8ea15a9e..1ca18be5dc30 100644 --- a/arch/ia64/Kconfig +++ b/arch/ia64/Kconfig @@ -45,6 +45,7 @@ config IA64 select GENERIC_IRQ_LEGACY select ARCH_HAVE_NMI_SAFE_CMPXCHG select GENERIC_IOMAP + select GENERIC_IOREMAP select GENERIC_SMP_IDLE_THREAD select ARCH_TASK_STRUCT_ON_STACK select ARCH_TASK_STRUCT_ALLOCATOR diff --git a/arch/ia64/include/asm/io.h b/arch/ia64/include/asm/io.h index ce66dfc0e719..d90a4c551de2 100644 --- a/arch/ia64/include/asm/io.h +++ b/arch/ia64/include/asm/io.h @@ -247,17 +247,23 @@ static inline void outsl(unsigned long port, const void *src, # ifdef __KERNEL__ -extern void __iomem * ioremap(unsigned long offset, unsigned long size); -extern void __iomem * ioremap_uc(unsigned long offset, unsigned long size); -extern void iounmap (volatile void __iomem *addr); -static inline void __iomem * ioremap_cache (unsigned long phys_addr, unsigned long size) -{ - return ioremap(phys_addr, size); -} -#define ioremap ioremap -#define ioremap_cache ioremap_cache +/* + * I/O memory mapping functions. + */ +void __iomem * +arch_ioremap(phys_addr_t *paddr, size_t size, unsigned long *prot_val); +#define arch_ioremap arch_ioremap + +int arch_iounmap(void __iomem *addr); +#define arch_iounmap arch_iounmap + +#define _PAGE_IOREMAP pgprot_val(PAGE_KERNEL) + +#define ioremap_cache(addr, size) \ + ioremap_prot((addr), (size), pgprot_val(PAGE_KERNEL)) + +void __iomem *ioremap_uc(unsigned long offset, unsigned long size); #define ioremap_uc ioremap_uc -#define iounmap iounmap /* * String version of IO memory access ops: diff --git a/arch/ia64/mm/ioremap.c b/arch/ia64/mm/ioremap.c index 55fd3eb753ff..8a085fc660e3 100644 --- a/arch/ia64/mm/ioremap.c +++ b/arch/ia64/mm/ioremap.c @@ -30,15 +30,12 @@ early_ioremap (unsigned long phys_addr, unsigned long size) } void __iomem * -ioremap (unsigned long phys_addr, unsigned long size) +arch_ioremap(phys_addr_t *paddr, size_t size, unsigned long *prot_val) { - void __iomem *addr; - struct vm_struct *area; - unsigned long offset; - pgprot_t prot; - u64 attr; + phys_addr_t phys_addr = *paddr; unsigned long gran_base, gran_size; unsigned long page_base; + u64 attr; /* * For things in kern_memmap, we must use the same attribute @@ -69,35 +66,18 @@ ioremap (unsigned long phys_addr, unsigned long size) page_base = phys_addr & PAGE_MASK; size = PAGE_ALIGN(phys_addr + size) - page_base; if (efi_mem_attribute(page_base, size) & EFI_MEMORY_WB) { - prot = PAGE_KERNEL; - - /* - * Mappings have to be page-aligned - */ - offset = phys_addr & ~PAGE_MASK; - phys_addr &= PAGE_MASK; - - /* - * Ok, go for it.. - */ - area = get_vm_area(size, VM_IOREMAP); - if (!area) - return NULL; - - area->phys_addr = phys_addr; - addr = (void __iomem *) area->addr; - if (ioremap_page_range((unsigned long) addr, - (unsigned long) addr + size, phys_addr, prot)) { - vunmap((void __force *) addr); - return NULL; - } - - return (void __iomem *) (offset + (char __iomem *)addr); + return NULL; } return __ioremap_uc(phys_addr); } -EXPORT_SYMBOL(ioremap); + +int arch_iounmap(void __iomem *addr) +{ + if (REGION_NUMBER(addr) != RGN_GATE) + return -EINVAL; + return 0; +} void __iomem * ioremap_uc(unsigned long phys_addr, unsigned long size) @@ -113,11 +93,3 @@ void early_iounmap (volatile void __iomem *addr, unsigned long size) { } - -void -iounmap (volatile void __iomem *addr) -{ - if (REGION_NUMBER(addr) == RGN_GATE) - vunmap((void *) ((unsigned long) addr & PAGE_MASK)); -} -EXPORT_SYMBOL(iounmap); From patchwork Sat Aug 20 00:31:21 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Baoquan He X-Patchwork-Id: 12949408 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 49F0CC32792 for ; Sat, 20 Aug 2022 00:32:16 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id DCDA68D0005; Fri, 19 Aug 2022 20:32:15 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id D7CB78D0002; Fri, 19 Aug 2022 20:32:15 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id C1E7D8D0005; Fri, 19 Aug 2022 20:32:15 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id B1D0D8D0002 for ; Fri, 19 Aug 2022 20:32:15 -0400 (EDT) Received: from smtpin12.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id 8CB5280108 for ; Sat, 20 Aug 2022 00:32:15 +0000 (UTC) X-FDA: 79818094230.12.95953FE Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by imf25.hostedemail.com (Postfix) with ESMTP id 288A6A0030 for ; Sat, 20 Aug 2022 00:32:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1660955534; 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=GbVQC9n5EHI3Q19oreTxvS1jwCRKlt1Xm2HiNn8Pbvw=; b=gRdIjJk3HfsYgTm6HbPim+ZM0hvHn7l77xQdorZgcQKTMaY4Hj61wxYsL6toJBIBH+Vzs1 m5+OeIjg29XE2lsVr8854tFfTfZpABiEYB1Ik/GKvZ4KP5oV6N9oUAtinMb6JqLKTjBqqi HZ7wCxSRpp+Zpjhr5BGUONkvD+VWSCM= 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-79-JXbmH_XLOMqZeo5PESKY-Q-1; Fri, 19 Aug 2022 20:32:10 -0400 X-MC-Unique: JXbmH_XLOMqZeo5PESKY-Q-1 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.rdu2.redhat.com [10.11.54.2]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 848C980231E; Sat, 20 Aug 2022 00:32:09 +0000 (UTC) Received: from MiWiFi-R3L-srv.redhat.com (ovpn-12-17.pek2.redhat.com [10.72.12.17]) by smtp.corp.redhat.com (Postfix) with ESMTP id A5A324010D2A; Sat, 20 Aug 2022 00:32:03 +0000 (UTC) From: Baoquan He To: linux-kernel@vger.kernel.org Cc: linux-mm@kvack.org, akpm@linux-foundation.org, hch@infradead.org, agordeev@linux.ibm.com, wangkefeng.wang@huawei.com, linux-arm-kernel@lists.infradead.org, Baoquan He , Jonas Bonn , Stefan Kristiansson , Stafford Horne , openrisc@lists.librecores.org Subject: [PATCH v2 07/11] openrisc: mm: Convert to GENERIC_IOREMAP Date: Sat, 20 Aug 2022 08:31:21 +0800 Message-Id: <20220820003125.353570-8-bhe@redhat.com> In-Reply-To: <20220820003125.353570-1-bhe@redhat.com> References: <20220820003125.353570-1-bhe@redhat.com> MIME-Version: 1.0 Content-type: text/plain X-Scanned-By: MIMEDefang 2.84 on 10.11.54.2 ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1660955535; 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=GbVQC9n5EHI3Q19oreTxvS1jwCRKlt1Xm2HiNn8Pbvw=; b=ukshTKGfK3Ar/NlNWjiu9wCnRHxmmCJr5oF9Vv1SSF6DGU8KyoajTTUJd2r2mHak24gAHa lBbU8ZHn3zmxpMoCD6mORxFdI/eF5KMbX4e3mJgj6JEpy6rufe/w4/hWVJ9ZYqfPLPZalb rjvloXyaob6qkpBFt7lelpjNpnwtrmU= ARC-Authentication-Results: i=1; imf25.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=gRdIjJk3; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf25.hostedemail.com: domain of bhe@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=bhe@redhat.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1660955535; a=rsa-sha256; cv=none; b=Xn3R/hcDfW/9aEt2RNgrZCaPvtd6jEoRa92YKsL0A6AfRAOfeAvkTf8b0bsEqhnp/INhCm eHI8cveArJQlrcKuWKfI/ApXtvkKYNHjeHSG9wnp74LJkfuRgFBfOp1DUiivP4vRMxfFeG pMcFVNaGvMIwHlYp7OYbShqHAg9t8Pc= X-Stat-Signature: ucnkrybm57yjc87zi44op6swtea1mgby X-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: 288A6A0030 Authentication-Results: imf25.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=gRdIjJk3; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf25.hostedemail.com: domain of bhe@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=bhe@redhat.com X-Rspam-User: X-HE-Tag: 1660955535-997934 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: Add hooks arch_ioremap() and arch_iounmap() for operisc's special operation when ioremap() and iounmap. Signed-off-by: Baoquan He Cc: Jonas Bonn Cc: Stefan Kristiansson Cc: Stafford Horne Cc: openrisc@lists.librecores.org Acked-by: Stafford Horne --- arch/openrisc/Kconfig | 1 + arch/openrisc/include/asm/io.h | 16 ++++++++--- arch/openrisc/mm/ioremap.c | 51 +++++++++++----------------------- 3 files changed, 29 insertions(+), 39 deletions(-) diff --git a/arch/openrisc/Kconfig b/arch/openrisc/Kconfig index c7f282f60f64..fd9bb76a610b 100644 --- a/arch/openrisc/Kconfig +++ b/arch/openrisc/Kconfig @@ -21,6 +21,7 @@ config OPENRISC select GENERIC_IRQ_PROBE select GENERIC_IRQ_SHOW select GENERIC_PCI_IOMAP + select GENERIC_IOREMAP select GENERIC_CPU_DEVICES select HAVE_PCI select HAVE_UID16 diff --git a/arch/openrisc/include/asm/io.h b/arch/openrisc/include/asm/io.h index ee6043a03173..9db67938bfc4 100644 --- a/arch/openrisc/include/asm/io.h +++ b/arch/openrisc/include/asm/io.h @@ -15,6 +15,8 @@ #define __ASM_OPENRISC_IO_H #include +#include +#include /* * PCI: We do not use IO ports in OpenRISC @@ -27,11 +29,17 @@ #define PIO_OFFSET 0 #define PIO_MASK 0 -#define ioremap ioremap -void __iomem *ioremap(phys_addr_t offset, unsigned long size); +/* + * I/O memory mapping functions. + */ +void __iomem * +arch_ioremap(phys_addr_t *paddr, size_t size, unsigned long *prot_val); +#define arch_ioremap arch_ioremap + +int arch_iounmap(void __iomem *addr); +#define arch_iounmap arch_iounmap -#define iounmap iounmap -extern void iounmap(volatile void __iomem *addr); +#define _PAGE_IOREMAP (pgprot_val(PAGE_KERNEL) | _PAGE_CI) #include diff --git a/arch/openrisc/mm/ioremap.c b/arch/openrisc/mm/ioremap.c index 8ec0dafecf25..bc41660e1fb0 100644 --- a/arch/openrisc/mm/ioremap.c +++ b/arch/openrisc/mm/ioremap.c @@ -24,26 +24,18 @@ extern int mem_init_done; static unsigned int fixmaps_used __initdata; -/* - * Remap an arbitrary physical address space into the kernel virtual - * address space. Needed when the kernel wants to access high addresses - * directly. - * - * NOTE! We need to allow non-page-aligned mappings too: we will obviously - * have to convert them into an offset in a page-aligned mapping, but the - * caller shouldn't need to know that small detail. - */ -void __iomem *__ref ioremap(phys_addr_t addr, unsigned long size) +void __iomem * +arch_ioremap(phys_addr_t *paddr, size_t size, unsigned long *prot_val) { phys_addr_t p; unsigned long v; - unsigned long offset, last_addr; - struct vm_struct *area = NULL; + unsigned long offset, last_addr, addr = *paddr; + int ret = -EINVAL; /* Don't allow wraparound or zero size */ last_addr = addr + size - 1; if (!size || last_addr < addr) - return NULL; + return IOMEM_ERR_PTR(ret); /* * Mappings have to be page-aligned @@ -52,32 +44,24 @@ void __iomem *__ref ioremap(phys_addr_t addr, unsigned long size) p = addr & PAGE_MASK; size = PAGE_ALIGN(last_addr + 1) - p; - if (likely(mem_init_done)) { - area = get_vm_area(size, VM_IOREMAP); - if (!area) - return NULL; - v = (unsigned long)area->addr; - } else { + if (unlikely(!mem_init_done)) { if ((fixmaps_used + (size >> PAGE_SHIFT)) > FIX_N_IOREMAPS) - return NULL; + return IOMEM_ERR_PTR(ret); v = fix_to_virt(FIX_IOREMAP_BEGIN + fixmaps_used); fixmaps_used += (size >> PAGE_SHIFT); - } - if (ioremap_page_range(v, v + size, p, - __pgprot(pgprot_val(PAGE_KERNEL) | _PAGE_CI))) { - if (likely(mem_init_done)) - vfree(area->addr); - else + if (ioremap_page_range(v, v + size, p, __pgprot(*prot_val))) { fixmaps_used -= (size >> PAGE_SHIFT); - return NULL; + return IOMEM_ERR_PTR(ret); + } + + return (void __iomem *)(offset + (char *)v); } - return (void __iomem *)(offset + (char *)v); + return NULL; } -EXPORT_SYMBOL(ioremap); -void iounmap(volatile void __iomem *addr) +int arch_iounmap(void __iomem *addr) { /* If the page is from the fixmap pool then we just clear out * the fixmap mapping. @@ -97,13 +81,10 @@ void iounmap(volatile void __iomem *addr) * ii) invalid accesses to the freed areas aren't made */ flush_tlb_all(); - return; + return -EINVAL; } - - return vfree((void *)(PAGE_MASK & (unsigned long)addr)); + return 0; } -EXPORT_SYMBOL(iounmap); - /** * OK, this one's a bit tricky... ioremap can get called before memory is * initialized (early serial console does this) and will want to alloc a page From patchwork Sat Aug 20 00:31:22 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Baoquan He X-Patchwork-Id: 12949414 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 C67B0C32789 for ; Sat, 20 Aug 2022 00:34:18 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 67C4A8D0006; Fri, 19 Aug 2022 20:34:18 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 62AA98D0002; Fri, 19 Aug 2022 20:34:18 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 3E2098D0006; Fri, 19 Aug 2022 20:34:18 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id 2EA668D0002 for ; Fri, 19 Aug 2022 20:34:18 -0400 (EDT) Received: from smtpin30.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id 06F9240418 for ; Sat, 20 Aug 2022 00:34:18 +0000 (UTC) X-FDA: 79818099396.30.EB866CF Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by imf21.hostedemail.com (Postfix) with ESMTP id 1E16C1C00E3 for ; Sat, 20 Aug 2022 00:32:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1660955539; 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=nLr2YHSkl4TYF2OfhT4AaOM1UnBcFcPBR9I5Nw8Jroc=; b=LvAoHdDjYlCcIHnJa1Ost3HumDDBE27YuOFdYtgBYL6fK+6B7pfz6lVc0gRmeyGFYcGPn6 PBYlH1H8qEf4ixVXoVGrXhJJUAcbsTke2JEhxT1pyGKBZ7XXDyEE41EA+P2tBQHaNh/hv+ 1xAMh62wrTUdPYNd9zH3vZzhx2tTdkM= 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-363-NdrpkDDiNHmDYjYGweXesw-1; Fri, 19 Aug 2022 20:32:16 -0400 X-MC-Unique: NdrpkDDiNHmDYjYGweXesw-1 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.rdu2.redhat.com [10.11.54.2]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 61106811E81; Sat, 20 Aug 2022 00:32:15 +0000 (UTC) Received: from MiWiFi-R3L-srv.redhat.com (ovpn-12-17.pek2.redhat.com [10.72.12.17]) by smtp.corp.redhat.com (Postfix) with ESMTP id 3DE8F4010D2A; Sat, 20 Aug 2022 00:32:09 +0000 (UTC) From: Baoquan He To: linux-kernel@vger.kernel.org Cc: linux-mm@kvack.org, akpm@linux-foundation.org, hch@infradead.org, agordeev@linux.ibm.com, wangkefeng.wang@huawei.com, linux-arm-kernel@lists.infradead.org, Baoquan He , "James E.J. Bottomley" , Helge Deller , linux-parisc@vger.kernel.org Subject: [PATCH v2 08/11] parisc: mm: Convert to GENERIC_IOREMAP Date: Sat, 20 Aug 2022 08:31:22 +0800 Message-Id: <20220820003125.353570-9-bhe@redhat.com> In-Reply-To: <20220820003125.353570-1-bhe@redhat.com> References: <20220820003125.353570-1-bhe@redhat.com> MIME-Version: 1.0 Content-type: text/plain X-Scanned-By: MIMEDefang 2.84 on 10.11.54.2 ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1660955540; 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=nLr2YHSkl4TYF2OfhT4AaOM1UnBcFcPBR9I5Nw8Jroc=; b=rGWtDQVvmaERCje6cSGMdvw5Nzq+WEYsh4ZdmXO2zjSsh3k9GMiDo5FdCGJdsdNP3thwlr 5lh3DI0s6KXdYDcCAEx1FvS7GnjGAeDl1PQIK71FNOQK7LffgpuLPHLdaw5r7nY9QEiF9U HnuCqb/60LTuqXdqYhtxxxjOIaF7Y6k= ARC-Authentication-Results: i=1; imf21.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=LvAoHdDj; spf=pass (imf21.hostedemail.com: domain of bhe@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=bhe@redhat.com; dmarc=pass (policy=none) header.from=redhat.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1660955540; a=rsa-sha256; cv=none; b=Ox5EDtt2aKj0i2FuGY357Bgi0rkS52mAMpGpztPHJ43j01ImSaNrdcisgb0ynDsUdfvXzE x6uBUsCr2W9h1PuJo4CTK7ye+E4vCV2JRHynoGf0Kgnv+gSlfVc6Sh4wzb0e9KrkcVKbbz uXWRKZG5GvtSZ3zgf5ZV3tgMrtJyDLI= X-Rspam-User: X-Rspamd-Queue-Id: 1E16C1C00E3 Authentication-Results: imf21.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=LvAoHdDj; spf=pass (imf21.hostedemail.com: domain of bhe@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=bhe@redhat.com; dmarc=pass (policy=none) header.from=redhat.com X-Stat-Signature: fry65mwzj96cke6yb7fks7kx87ztubop X-Rspamd-Server: rspam10 X-HE-Tag: 1660955539-497210 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: Add hook arch_ioremap() for parisc's special operation when ioremap(), then ioremap_[wc|uc]() are converted to use ioremap_prot() from GENERIC_IOREMAP. Signed-off-by: Baoquan He Cc: "James E.J. Bottomley" Cc: Helge Deller Cc: linux-parisc@vger.kernel.org Reported-by: kernel test robot --- arch/parisc/Kconfig | 1 + arch/parisc/include/asm/io.h | 16 ++++++--- arch/parisc/mm/ioremap.c | 65 ++++-------------------------------- 3 files changed, 18 insertions(+), 64 deletions(-) diff --git a/arch/parisc/Kconfig b/arch/parisc/Kconfig index 7f059cd1196a..5fed465c9b83 100644 --- a/arch/parisc/Kconfig +++ b/arch/parisc/Kconfig @@ -36,6 +36,7 @@ config PARISC select GENERIC_ATOMIC64 if !64BIT select GENERIC_IRQ_PROBE select GENERIC_PCI_IOMAP + select GENERIC_IOREMAP select ARCH_HAVE_NMI_SAFE_CMPXCHG select GENERIC_SMP_IDLE_THREAD select GENERIC_ARCH_TOPOLOGY if SMP diff --git a/arch/parisc/include/asm/io.h b/arch/parisc/include/asm/io.h index 42ffb60a6ea9..614e21d9749f 100644 --- a/arch/parisc/include/asm/io.h +++ b/arch/parisc/include/asm/io.h @@ -123,13 +123,19 @@ static inline void gsc_writeq(unsigned long long val, unsigned long addr) } /* - * The standard PCI ioremap interfaces + * I/O memory mapping functions. */ -void __iomem *ioremap(unsigned long offset, unsigned long size); -#define ioremap_wc ioremap -#define ioremap_uc ioremap +void __iomem * +arch_ioremap(phys_addr_t *paddr, size_t size, unsigned long prot); +#define arch_ioremap arch_ioremap -extern void iounmap(const volatile void __iomem *addr); +#define _PAGE_IOREMAP (_PAGE_PRESENT | _PAGE_RW | _PAGE_DIRTY | \ + _PAGE_ACCESSED | _PAGE_NO_CACHE) + +#define ioremap_wc(addr, size) \ + ioremap_prot((addr), (size), _PAGE_IOREMAP) +#define ioremap_uc(addr, size) \ + ioremap_prot((addr), (size), _PAGE_IOREMAP) static inline unsigned char __raw_readb(const volatile void __iomem *addr) { diff --git a/arch/parisc/mm/ioremap.c b/arch/parisc/mm/ioremap.c index 345ff0b66499..28884757fad0 100644 --- a/arch/parisc/mm/ioremap.c +++ b/arch/parisc/mm/ioremap.c @@ -13,38 +13,19 @@ #include #include -/* - * Generic mapping function (not visible outside): - */ - -/* - * Remap an arbitrary physical address space into the kernel virtual - * address space. - * - * NOTE! We need to allow non-page-aligned mappings too: we will obviously - * have to convert them into an offset in a page-aligned mapping, but the - * caller shouldn't need to know that small detail. - */ -void __iomem *ioremap(unsigned long phys_addr, unsigned long size) +void __iomem * +arch_ioremap(phys_addr_t *paddr, size_t size, unsigned long *prot_val) { - void __iomem *addr; - struct vm_struct *area; - unsigned long offset, last_addr; - pgprot_t pgprot; + phys_addr_t phys_addr = *paddr; #ifdef CONFIG_EISA unsigned long end = phys_addr + size - 1; /* Support EISA addresses */ if ((phys_addr >= 0x00080000 && end < 0x000fffff) || (phys_addr >= 0x00500000 && end < 0x03bfffff)) - phys_addr |= F_EXTEND(0xfc000000); + *paddr = phys_addr |= F_EXTEND(0xfc000000); #endif - /* Don't allow wraparound or zero size */ - last_addr = phys_addr + size - 1; - if (!size || last_addr < phys_addr) - return NULL; - /* * Don't allow anybody to remap normal RAM that we're using.. */ @@ -58,43 +39,9 @@ void __iomem *ioremap(unsigned long phys_addr, unsigned long size) for (page = virt_to_page(t_addr); page <= virt_to_page(t_end); page++) { if(!PageReserved(page)) - return NULL; + return IOMEM_ERR_PTR(-EINVAL); } } - pgprot = __pgprot(_PAGE_PRESENT | _PAGE_RW | _PAGE_DIRTY | - _PAGE_ACCESSED | _PAGE_NO_CACHE); - - /* - * Mappings have to be page-aligned - */ - offset = phys_addr & ~PAGE_MASK; - phys_addr &= PAGE_MASK; - size = PAGE_ALIGN(last_addr + 1) - phys_addr; - - /* - * Ok, go for it.. - */ - area = get_vm_area(size, VM_IOREMAP); - if (!area) - return NULL; - - addr = (void __iomem *) area->addr; - if (ioremap_page_range((unsigned long)addr, (unsigned long)addr + size, - phys_addr, pgprot)) { - vunmap(addr); - return NULL; - } - - return (void __iomem *) (offset + (char __iomem *)addr); -} -EXPORT_SYMBOL(ioremap); - -void iounmap(const volatile void __iomem *io_addr) -{ - unsigned long addr = (unsigned long)io_addr & PAGE_MASK; - - if (is_vmalloc_addr((void *)addr)) - vunmap((void *)addr); + return NULL; } -EXPORT_SYMBOL(iounmap); From patchwork Sat Aug 20 00:31:23 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Baoquan He X-Patchwork-Id: 12949409 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 7DEADC32792 for ; Sat, 20 Aug 2022 00:32:26 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id E44778D0008; Fri, 19 Aug 2022 20:32:25 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id DF4988D0002; Fri, 19 Aug 2022 20:32:25 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id C93B08D0008; Fri, 19 Aug 2022 20:32:25 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id BAD768D0002 for ; Fri, 19 Aug 2022 20:32:25 -0400 (EDT) Received: from smtpin23.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id 8D9E81A01BF for ; Sat, 20 Aug 2022 00:32:25 +0000 (UTC) X-FDA: 79818094650.23.296816C Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by imf02.hostedemail.com (Postfix) with ESMTP id 3E48380002 for ; Sat, 20 Aug 2022 00:32:25 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1660955544; 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=5SHN8uljMwgOES67u9nTa1xL6WhEjv8MuhsMkmhS9fE=; b=Y228TdJCJg49IoYM1mBA+0kDtxXvimgUbr+U10lYyk64pIgCiBmelFfgOavLR/93Zw72qx +83Nr/Jz9T6M1QZKKMZbPkSsRDAMfh+rutl1JvlGCODFttMfTIBZpdL3bswPET2vBXQgOj LEb7LjXMrlpH1XpFa9OlGbSnMrhNGEk= 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-608-hpYxoUSSMG6Qw-fSYp5coA-1; Fri, 19 Aug 2022 20:32:22 -0400 X-MC-Unique: hpYxoUSSMG6Qw-fSYp5coA-1 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.rdu2.redhat.com [10.11.54.2]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 37F51185A79C; Sat, 20 Aug 2022 00:32:22 +0000 (UTC) Received: from MiWiFi-R3L-srv.redhat.com (ovpn-12-17.pek2.redhat.com [10.72.12.17]) by smtp.corp.redhat.com (Postfix) with ESMTP id 14E644010E3C; Sat, 20 Aug 2022 00:32:15 +0000 (UTC) From: Baoquan He To: linux-kernel@vger.kernel.org Cc: linux-mm@kvack.org, akpm@linux-foundation.org, hch@infradead.org, agordeev@linux.ibm.com, wangkefeng.wang@huawei.com, linux-arm-kernel@lists.infradead.org, Baoquan He , Heiko Carstens , Vasily Gorbik , Christian Borntraeger , Sven Schnelle , linux-s390@vger.kernel.org Subject: [PATCH v2 09/11] s390: mm: Convert to GENERIC_IOREMAP Date: Sat, 20 Aug 2022 08:31:23 +0800 Message-Id: <20220820003125.353570-10-bhe@redhat.com> In-Reply-To: <20220820003125.353570-1-bhe@redhat.com> References: <20220820003125.353570-1-bhe@redhat.com> MIME-Version: 1.0 Content-type: text/plain X-Scanned-By: MIMEDefang 2.84 on 10.11.54.2 ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1660955545; 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=5SHN8uljMwgOES67u9nTa1xL6WhEjv8MuhsMkmhS9fE=; b=HZv1LptCIa1eG1jWYlUB8thhToE6201KWGpuL0bBTH03kjXgrFPD+GYxhcCYZX731ZvgSn /jNwoDYih4QpPUBvUkmtt5Aa7M+qJc58tfJV4A96NDAn9g9zaH0eCvsyALtP7idbXcsX+3 v/+XC4a/JQukT038QBrKcizLb3Jx0ec= ARC-Authentication-Results: i=1; imf02.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=Y228TdJC; spf=pass (imf02.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-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1660955545; a=rsa-sha256; cv=none; b=gh7QtQtdGa/SDinmmNP/8s+FPRE/59bt1cE8d5RiJux/bpi4X93p6MGD/EiO+BrUQwdTP/ WHXP8ZxYkpT3F0YC6/GOHoakI3X5SXj3ZdkiNp1RGRNyAtgJQHnaHjAqbNkU7sE+HAFfkO lpB0NL8JPNtSKWPBBuN0ISoguN6rjDA= Authentication-Results: imf02.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=Y228TdJC; spf=pass (imf02.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 X-Rspamd-Server: rspam05 X-Rspamd-Queue-Id: 3E48380002 X-Stat-Signature: 313ndi5xwdtcum9935sn9tboacetecoy X-Rspam-User: X-HE-Tag: 1660955545-374598 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: Add hooks arch_ioremap() and arch_iounmap() for s390's special operation when ioremap() and iounmap(), then ioremap_[wc|wt]() are converted to use ioremap_prot() from GENERIC_IOREMAP. Signed-off-by: Baoquan He Cc: Heiko Carstens Cc: Vasily Gorbik Cc: Alexander Gordeev Cc: Christian Borntraeger Cc: Sven Schnelle Cc: linux-s390@vger.kernel.org Tested-by: Niklas Schnelle Acked-by: Niklas Schnelle --- arch/s390/Kconfig | 1 + arch/s390/include/asm/io.h | 26 +++++++++++------ arch/s390/pci/pci.c | 60 +++++--------------------------------- 3 files changed, 26 insertions(+), 61 deletions(-) diff --git a/arch/s390/Kconfig b/arch/s390/Kconfig index 318fce77601d..c59e1b25f59d 100644 --- a/arch/s390/Kconfig +++ b/arch/s390/Kconfig @@ -135,6 +135,7 @@ config S390 select GENERIC_SMP_IDLE_THREAD select GENERIC_TIME_VSYSCALL select GENERIC_VDSO_TIME_NS + select GENERIC_IOREMAP select HAVE_ALIGNED_STRUCT_PAGE if SLUB select HAVE_ARCH_AUDITSYSCALL select HAVE_ARCH_JUMP_LABEL diff --git a/arch/s390/include/asm/io.h b/arch/s390/include/asm/io.h index e3882b012bfa..f837e20b7bbd 100644 --- a/arch/s390/include/asm/io.h +++ b/arch/s390/include/asm/io.h @@ -22,11 +22,23 @@ void unxlate_dev_mem_ptr(phys_addr_t phys, void *addr); #define IO_SPACE_LIMIT 0 -void __iomem *ioremap_prot(phys_addr_t addr, size_t size, unsigned long prot); -void __iomem *ioremap(phys_addr_t addr, size_t size); -void __iomem *ioremap_wc(phys_addr_t addr, size_t size); -void __iomem *ioremap_wt(phys_addr_t addr, size_t size); -void iounmap(volatile void __iomem *addr); + +/* + * I/O memory mapping functions. + */ +void __iomem * +arch_ioremap(phys_addr_t *paddr, size_t size, unsigned long *prot_val); +#define arch_ioremap arch_ioremap + +int arch_iounmap(void __iomem *addr); +#define arch_iounmap arch_iounmap + +#define _PAGE_IOREMAP pgprot_val(PAGE_KERNEL) + +#define ioremap_wc(addr, size) \ + ioremap_prot((addr), (size), pgprot_val(pgprot_writecombine(PAGE_KERNEL))) +#define ioremap_wt(addr, size) \ + ioremap_prot((addr), (size), pgprot_val(pgprot_writethrough(PAGE_KERNEL))) static inline void __iomem *ioport_map(unsigned long port, unsigned int nr) { @@ -51,10 +63,6 @@ static inline void ioport_unmap(void __iomem *p) #define pci_iomap_wc pci_iomap_wc #define pci_iomap_wc_range pci_iomap_wc_range -#define ioremap ioremap -#define ioremap_wt ioremap_wt -#define ioremap_wc ioremap_wc - #define memcpy_fromio(dst, src, count) zpci_memcpy_fromio(dst, src, count) #define memcpy_toio(dst, src, count) zpci_memcpy_toio(dst, src, count) #define memset_io(dst, val, count) zpci_memset_io(dst, val, count) diff --git a/arch/s390/pci/pci.c b/arch/s390/pci/pci.c index 73cdc5539384..984cad9cd5a1 100644 --- a/arch/s390/pci/pci.c +++ b/arch/s390/pci/pci.c @@ -244,64 +244,20 @@ void __iowrite64_copy(void __iomem *to, const void *from, size_t count) zpci_memcpy_toio(to, from, count); } -static void __iomem *__ioremap(phys_addr_t addr, size_t size, pgprot_t prot) +void __iomem * +arch_ioremap(phys_addr_t *paddr, size_t size, unsigned long *prot_val) { - unsigned long offset, vaddr; - struct vm_struct *area; - phys_addr_t last_addr; - - last_addr = addr + size - 1; - if (!size || last_addr < addr) - return NULL; - if (!static_branch_unlikely(&have_mio)) - return (void __iomem *) addr; - - offset = addr & ~PAGE_MASK; - addr &= PAGE_MASK; - size = PAGE_ALIGN(size + offset); - area = get_vm_area(size, VM_IOREMAP); - if (!area) - return NULL; - - vaddr = (unsigned long) area->addr; - if (ioremap_page_range(vaddr, vaddr + size, addr, prot)) { - free_vm_area(area); - return NULL; - } - return (void __iomem *) ((unsigned long) area->addr + offset); -} - -void __iomem *ioremap_prot(phys_addr_t addr, size_t size, unsigned long prot) -{ - return __ioremap(addr, size, __pgprot(prot)); + return (void __iomem *) *paddr; + return NULL; } -EXPORT_SYMBOL(ioremap_prot); -void __iomem *ioremap(phys_addr_t addr, size_t size) +int arch_iounmap(void __iomem *addr) { - return __ioremap(addr, size, PAGE_KERNEL); -} -EXPORT_SYMBOL(ioremap); - -void __iomem *ioremap_wc(phys_addr_t addr, size_t size) -{ - return __ioremap(addr, size, pgprot_writecombine(PAGE_KERNEL)); -} -EXPORT_SYMBOL(ioremap_wc); - -void __iomem *ioremap_wt(phys_addr_t addr, size_t size) -{ - return __ioremap(addr, size, pgprot_writethrough(PAGE_KERNEL)); -} -EXPORT_SYMBOL(ioremap_wt); - -void iounmap(volatile void __iomem *addr) -{ - if (static_branch_likely(&have_mio)) - vunmap((__force void *) ((unsigned long) addr & PAGE_MASK)); + if (!static_branch_likely(&have_mio)) + return -EINVAL; + return 0; } -EXPORT_SYMBOL(iounmap); /* Create a virtual mapping cookie for a PCI BAR */ static void __iomem *pci_iomap_range_fh(struct pci_dev *pdev, int bar, From patchwork Sat Aug 20 00:31:24 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Baoquan He X-Patchwork-Id: 12949413 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 41F4AC28D13 for ; Sat, 20 Aug 2022 00:34:17 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id BFA948D0005; Fri, 19 Aug 2022 20:34:16 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id BA96C8D0002; Fri, 19 Aug 2022 20:34:16 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id A4A948D0005; Fri, 19 Aug 2022 20:34:16 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id 96BE18D0002 for ; Fri, 19 Aug 2022 20:34:16 -0400 (EDT) Received: from smtpin07.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 70393140436 for ; Sat, 20 Aug 2022 00:34:16 +0000 (UTC) X-FDA: 79818099312.07.2CE794B Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by imf31.hostedemail.com (Postfix) with ESMTP id 789B22003F for ; Sat, 20 Aug 2022 00:32:32 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1660955551; 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=KqPWS9gGxOeL/ZhwRsPXano6Rhd9t79hH4to3Fvy2dA=; b=SarzMmr/Gj0z0FLBl7WPwSWB7oGXaqFvt+0x8Stw4mVKpi2Ej+VwbIpumMeeXt6n8KVGNm eBsfFaW9FYR+hyY1XILsFAASPTVpdUmDir2up7AN6ukLvRO+L4IC02KixMikJqgQHmC9kS IjK6YZ3hFP2embUVrxJishufBSM8NGw= 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-632-1btemdQ7NeSIPbzJZZhjng-1; Fri, 19 Aug 2022 20:32:28 -0400 X-MC-Unique: 1btemdQ7NeSIPbzJZZhjng-1 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.rdu2.redhat.com [10.11.54.2]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 28B8F101A586; Sat, 20 Aug 2022 00:32:28 +0000 (UTC) Received: from MiWiFi-R3L-srv.redhat.com (ovpn-12-17.pek2.redhat.com [10.72.12.17]) by smtp.corp.redhat.com (Postfix) with ESMTP id 08CDF4010D2A; Sat, 20 Aug 2022 00:32:22 +0000 (UTC) From: Baoquan He To: linux-kernel@vger.kernel.org Cc: linux-mm@kvack.org, akpm@linux-foundation.org, hch@infradead.org, agordeev@linux.ibm.com, wangkefeng.wang@huawei.com, linux-arm-kernel@lists.infradead.org, Baoquan He , Yoshinori Sato , Rich Felker , linux-sh@vger.kernel.org Subject: [PATCH v2 10/11] sh: mm: Convert to GENERIC_IOREMAP Date: Sat, 20 Aug 2022 08:31:24 +0800 Message-Id: <20220820003125.353570-11-bhe@redhat.com> In-Reply-To: <20220820003125.353570-1-bhe@redhat.com> References: <20220820003125.353570-1-bhe@redhat.com> MIME-Version: 1.0 Content-type: text/plain X-Scanned-By: MIMEDefang 2.84 on 10.11.54.2 ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1660955552; a=rsa-sha256; cv=none; b=mSoWLnPKPKyRxfksM1CStsuA/t7gEZBfumNoA9OTtSkEGpofyaIIbCP0kIR4tQEuEaVQSo kz3e142hmDMgD9Axwy45QRxa67IB0ARYqpIUVHcOMnhsESN81HayGyDBYoIBpf/8zFpkz1 TEh/XVNarrjxev+o6sumUbtUlcUJbL8= ARC-Authentication-Results: i=1; imf31.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b="SarzMmr/"; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf31.hostedemail.com: domain of bhe@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=bhe@redhat.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1660955552; 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=KqPWS9gGxOeL/ZhwRsPXano6Rhd9t79hH4to3Fvy2dA=; b=1Wvo036hpZP/AWF5E6nR8Ah0I1c9aYsvL4526YWjpmwea7o54VawwLcTkUzSaWJKgLbrMv q+djjhQJJQ5DV6oITHwQTYiBGS3/KoTeZ738Ua89Hb0ovKnFI+o6mmEkUsRmeRH+eI5ejk 7GBWt+VxXsSzf3TS/RzT4EK4n/kfyps= X-Stat-Signature: tkd5piy63xp6m4a8i8ig1aue3kaargae X-Rspamd-Queue-Id: 789B22003F X-Rspam-User: Authentication-Results: imf31.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b="SarzMmr/"; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf31.hostedemail.com: domain of bhe@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=bhe@redhat.com X-Rspamd-Server: rspam11 X-HE-Tag: 1660955552-796909 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: Add hook arch_ioremap() and arch_iounmap for sh's special operation when ioremap() and iounmap(), then ioremap_cache() is converted to use ioremap_prot() from GENERIC_IOREMAP. Signed-off-by: Baoquan He Cc: Yoshinori Sato Cc: Rich Felker Cc: linux-sh@vger.kernel.org Reported-by: kernel test robot --- arch/sh/Kconfig | 1 + arch/sh/include/asm/io.h | 47 +++++++++---------------------- arch/sh/mm/ioremap.c | 61 ++++++++-------------------------------- 3 files changed, 26 insertions(+), 83 deletions(-) diff --git a/arch/sh/Kconfig b/arch/sh/Kconfig index 5f220e903e5a..b63ad4698cf8 100644 --- a/arch/sh/Kconfig +++ b/arch/sh/Kconfig @@ -25,6 +25,7 @@ config SUPERH select GENERIC_SCHED_CLOCK select GENERIC_SMP_IDLE_THREAD select GUP_GET_PTE_LOW_HIGH if X2TLB + select GENERIC_IOREMAP if MMU select HAVE_ARCH_AUDITSYSCALL select HAVE_ARCH_KGDB select HAVE_ARCH_SECCOMP_FILTER diff --git a/arch/sh/include/asm/io.h b/arch/sh/include/asm/io.h index fba90e670ed4..3c5ff82a511a 100644 --- a/arch/sh/include/asm/io.h +++ b/arch/sh/include/asm/io.h @@ -242,45 +242,26 @@ unsigned long long poke_real_address_q(unsigned long long addr, #define phys_to_virt(address) (__va(address)) #endif -#ifdef CONFIG_MMU -void iounmap(void __iomem *addr); -void __iomem *__ioremap_caller(phys_addr_t offset, unsigned long size, - pgprot_t prot, void *caller); - -static inline void __iomem *ioremap(phys_addr_t offset, unsigned long size) -{ - return __ioremap_caller(offset, size, PAGE_KERNEL_NOCACHE, - __builtin_return_address(0)); -} - -static inline void __iomem * -ioremap_cache(phys_addr_t offset, unsigned long size) -{ - return __ioremap_caller(offset, size, PAGE_KERNEL, - __builtin_return_address(0)); -} -#define ioremap_cache ioremap_cache +/* + * I/O memory mapping functions. + */ +void __iomem * +arch_ioremap(phys_addr_t *paddr, size_t size, unsigned long *prot_val); +#define arch_ioremap arch_ioremap -#ifdef CONFIG_HAVE_IOREMAP_PROT -static inline void __iomem *ioremap_prot(phys_addr_t offset, unsigned long size, - unsigned long flags) -{ - return __ioremap_caller(offset, size, __pgprot(flags), - __builtin_return_address(0)); -} -#endif /* CONFIG_HAVE_IOREMAP_PROT */ +int arch_iounmap(void __iomem *addr); +#define arch_iounmap arch_iounmap -#else /* CONFIG_MMU */ -static inline void __iomem *ioremap(phys_addr_t offset, size_t size) -{ - return (void __iomem *)(unsigned long)offset; -} +#define _PAGE_IOREMAP pgprot_val(PAGE_KERNEL_NOCACHE) -static inline void iounmap(volatile void __iomem *addr) { } -#endif /* CONFIG_MMU */ +#define ioremap_cache(addr, size) \ + ioremap_prot((addr), (size), pgprot_val(PAGE_KERNEL)) +#define ioremap_cache ioremap_cache #define ioremap_uc ioremap +#include + /* * Convert a physical pointer to a virtual kernel pointer for /dev/mem * access diff --git a/arch/sh/mm/ioremap.c b/arch/sh/mm/ioremap.c index 21342581144d..720a9186b06b 100644 --- a/arch/sh/mm/ioremap.c +++ b/arch/sh/mm/ioremap.c @@ -72,22 +72,12 @@ __ioremap_29bit(phys_addr_t offset, unsigned long size, pgprot_t prot) #define __ioremap_29bit(offset, size, prot) NULL #endif /* CONFIG_29BIT */ -/* - * Remap an arbitrary physical address space into the kernel virtual - * address space. Needed when the kernel wants to access high addresses - * directly. - * - * NOTE! We need to allow non-page-aligned mappings too: we will obviously - * have to convert them into an offset in a page-aligned mapping, but the - * caller shouldn't need to know that small detail. - */ -void __iomem * __ref -__ioremap_caller(phys_addr_t phys_addr, unsigned long size, - pgprot_t pgprot, void *caller) +void __iomem * +arch_ioremap(phys_addr_t *paddr, size_t size, unsigned long *prot_val) { - struct vm_struct *area; - unsigned long offset, last_addr, addr, orig_addr; + unsigned long last_addr, phys_addr = *paddr; void __iomem *mapped; + pgprot_t pgprot = __pgprot(*prot_val); mapped = __ioremap_trapped(phys_addr, size); if (mapped) @@ -100,7 +90,7 @@ __ioremap_caller(phys_addr_t phys_addr, unsigned long size, /* Don't allow wraparound or zero size */ last_addr = phys_addr + size - 1; if (!size || last_addr < phys_addr) - return NULL; + return IOMEM_ERR_PTR(-EINVAL); /* * If we can't yet use the regular approach, go the fixmap route. @@ -116,30 +106,8 @@ __ioremap_caller(phys_addr_t phys_addr, unsigned long size, if (mapped && !IS_ERR(mapped)) return mapped; - /* - * Mappings have to be page-aligned - */ - offset = phys_addr & ~PAGE_MASK; - phys_addr &= PAGE_MASK; - size = PAGE_ALIGN(last_addr+1) - phys_addr; - - /* - * Ok, go for it.. - */ - area = get_vm_area_caller(size, VM_IOREMAP, caller); - if (!area) - return NULL; - area->phys_addr = phys_addr; - orig_addr = addr = (unsigned long)area->addr; - - if (ioremap_page_range(addr, addr + size, phys_addr, pgprot)) { - vunmap((void *)orig_addr); - return NULL; - } - - return (void __iomem *)(offset + (char *)orig_addr); + return NULL; } -EXPORT_SYMBOL(__ioremap_caller); /* * Simple checks for non-translatable mappings. @@ -158,7 +126,7 @@ static inline int iomapping_nontranslatable(unsigned long offset) return 0; } -void iounmap(void __iomem *addr) +int arch_iounmap(void __iomem *addr) { unsigned long vaddr = (unsigned long __force)addr; struct vm_struct *p; @@ -167,26 +135,19 @@ void iounmap(void __iomem *addr) * Nothing to do if there is no translatable mapping. */ if (iomapping_nontranslatable(vaddr)) - return; + return -EINVAL; /* * There's no VMA if it's from an early fixed mapping. */ if (iounmap_fixed(addr) == 0) - return; + return -EINVAL; /* * If the PMB handled it, there's nothing else to do. */ if (pmb_unmap(addr) == 0) - return; + return -EINVAL; - p = remove_vm_area((void *)(vaddr & PAGE_MASK)); - if (!p) { - printk(KERN_ERR "%s: bad address %p\n", __func__, addr); - return; - } - - kfree(p); + return 0; } -EXPORT_SYMBOL(iounmap); From patchwork Sat Aug 20 00:31:25 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Baoquan He X-Patchwork-Id: 12949410 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 5B7F6C28D13 for ; Sat, 20 Aug 2022 00:32:38 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id E6A4D8D0003; Fri, 19 Aug 2022 20:32:37 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id E19678D0002; Fri, 19 Aug 2022 20:32:37 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id CBA8A8D0003; Fri, 19 Aug 2022 20:32:37 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id BDB848D0002 for ; Fri, 19 Aug 2022 20:32:37 -0400 (EDT) Received: from smtpin20.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id 8DD5712044B for ; Sat, 20 Aug 2022 00:32:37 +0000 (UTC) X-FDA: 79818095154.20.C823D9E 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 4B99918001D for ; Sat, 20 Aug 2022 00:32:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1660955556; 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=FMjDgiCjdNo3qKQdbhNe2varvevMFaQqgjlmVIuUXJM=; b=PyV9DACdh/NPj5cevtRmd1a9SyElUF2mIaLFCvm53lySDuo1Mbmm2w5WS3b4DYOdGscHLB kMfGENYt9L1OwG1WOq9jrXGj3WnlfnUErSTbU8UN1oyxKjzQi8rjA6N7mtlLsgLM5a03mT /jOo/4P/MeKwMBx4lp3nYPhbtGRyiY4= Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-120-m2l-eYInOt6faNznRRzA4A-1; Fri, 19 Aug 2022 20:32:34 -0400 X-MC-Unique: m2l-eYInOt6faNznRRzA4A-1 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.rdu2.redhat.com [10.11.54.2]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id DCEF83804502; Sat, 20 Aug 2022 00:32:33 +0000 (UTC) Received: from MiWiFi-R3L-srv.redhat.com (ovpn-12-17.pek2.redhat.com [10.72.12.17]) by smtp.corp.redhat.com (Postfix) with ESMTP id D4B164010D2A; Sat, 20 Aug 2022 00:32:28 +0000 (UTC) From: Baoquan He To: linux-kernel@vger.kernel.org Cc: linux-mm@kvack.org, akpm@linux-foundation.org, hch@infradead.org, agordeev@linux.ibm.com, wangkefeng.wang@huawei.com, linux-arm-kernel@lists.infradead.org, Baoquan He , Chris Zankel , Max Filippov , linux-xtensa@linux-xtensa.org Subject: [PATCH v2 11/11] xtensa: mm: Convert to GENERIC_IOREMAP Date: Sat, 20 Aug 2022 08:31:25 +0800 Message-Id: <20220820003125.353570-12-bhe@redhat.com> In-Reply-To: <20220820003125.353570-1-bhe@redhat.com> References: <20220820003125.353570-1-bhe@redhat.com> MIME-Version: 1.0 Content-type: text/plain X-Scanned-By: MIMEDefang 2.84 on 10.11.54.2 ARC-Authentication-Results: i=1; imf24.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=PyV9DACd; 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-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1660955557; a=rsa-sha256; cv=none; b=PpM3eef4gsHOMBQuwJ//k3SIrEcLnIfeKw+klZM1jpmwLpwhUieTiicx9ha78TFD/Wq8pn 5ItApRBtZeOh8rsP+88cGTwUtvQ9WZPdt49cqBtNqE+1yqzQ7G+ryOQ0aDksJq3P7POAbY qD19A7hd4eMnfWDEUHTt57yQ3H2mjhY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1660955557; 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=FMjDgiCjdNo3qKQdbhNe2varvevMFaQqgjlmVIuUXJM=; b=nroQ5mTcJpumpxF4MQJi4nQ89RiFALJ9uSZrUsK9WFL/lc5JEaIf55fX4rUzqsBP7ums/H oicaCbIpZCozg6fAm8AgFpOQAMTzHxRUZvwGX/sCjE6XetOUwRLLgROMFI9+E9QHmBTlBP VU/069Gz9RRwCIfOXdCcJFlpZW2ciLs= X-Rspam-User: Authentication-Results: imf24.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=PyV9DACd; 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 X-Rspamd-Server: rspam02 X-Stat-Signature: sw68aimmt1nz9x6fkhxrtgkdk3ht8997 X-Rspamd-Queue-Id: 4B99918001D X-HE-Tag: 1660955557-767321 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: Add hooks arch_ioremap() and arch_iounmap() for xtensa's special operation when ioremap() and iounmap(). Then define and implement its own ioremap() and ioremap_cache(). Signed-off-by: Baoquan He Cc: Chris Zankel Cc: Max Filippov Cc: linux-xtensa@linux-xtensa.org --- arch/xtensa/Kconfig | 1 + arch/xtensa/include/asm/io.h | 39 +++++++++++-------------- arch/xtensa/mm/ioremap.c | 56 +++++++++--------------------------- 3 files changed, 31 insertions(+), 65 deletions(-) diff --git a/arch/xtensa/Kconfig b/arch/xtensa/Kconfig index 12ac277282ba..ee3a638f5458 100644 --- a/arch/xtensa/Kconfig +++ b/arch/xtensa/Kconfig @@ -29,6 +29,7 @@ config XTENSA select GENERIC_LIB_UCMPDI2 select GENERIC_PCI_IOMAP select GENERIC_SCHED_CLOCK + select GENERIC_IOREMAP if MMU select HAVE_ARCH_AUDITSYSCALL select HAVE_ARCH_JUMP_LABEL if !XIP_KERNEL select HAVE_ARCH_KASAN if MMU && !XIP_KERNEL diff --git a/arch/xtensa/include/asm/io.h b/arch/xtensa/include/asm/io.h index a5b707e1c0f4..04dfc0dc936b 100644 --- a/arch/xtensa/include/asm/io.h +++ b/arch/xtensa/include/asm/io.h @@ -16,6 +16,7 @@ #include #include #include +#include #include @@ -23,23 +24,29 @@ #define IO_SPACE_LIMIT ~0 #define PCI_IOBASE ((void __iomem *)XCHAL_KIO_BYPASS_VADDR) -#ifdef CONFIG_MMU - -void __iomem *xtensa_ioremap_nocache(unsigned long addr, unsigned long size); -void __iomem *xtensa_ioremap_cache(unsigned long addr, unsigned long size); -void xtensa_iounmap(volatile void __iomem *addr); - /* - * Return the virtual address for the specified bus memory. + * I/O memory mapping functions. */ +void __iomem * +arch_ioremap(phys_addr_t *paddr, size_t size, unsigned long *prot_val); +#define arch_ioremap arch_ioremap + +int arch_iounmap(void __iomem *addr); +#define arch_iounmap arch_iounmap + +void __iomem *ioremap_prot(phys_addr_t paddr, size_t size, + unsigned long prot); + static inline void __iomem *ioremap(unsigned long offset, unsigned long size) { if (offset >= XCHAL_KIO_PADDR && offset - XCHAL_KIO_PADDR < XCHAL_KIO_SIZE) return (void*)(offset-XCHAL_KIO_PADDR+XCHAL_KIO_BYPASS_VADDR); else - return xtensa_ioremap_nocache(offset, size); + return ioremap_prot(offset, size, + pgprot_val(pgprot_noncached(PAGE_KERNEL))); } +#define ioremap ioremap static inline void __iomem *ioremap_cache(unsigned long offset, unsigned long size) @@ -48,22 +55,10 @@ static inline void __iomem *ioremap_cache(unsigned long offset, && offset - XCHAL_KIO_PADDR < XCHAL_KIO_SIZE) return (void*)(offset-XCHAL_KIO_PADDR+XCHAL_KIO_CACHED_VADDR); else - return xtensa_ioremap_cache(offset, size); -} -#define ioremap_cache ioremap_cache - -static inline void iounmap(volatile void __iomem *addr) -{ - unsigned long va = (unsigned long) addr; + return ioremap_prot(offset, size, pgprot_val(PAGE_KERNEL)); - if (!(va >= XCHAL_KIO_CACHED_VADDR && - va - XCHAL_KIO_CACHED_VADDR < XCHAL_KIO_SIZE) && - !(va >= XCHAL_KIO_BYPASS_VADDR && - va - XCHAL_KIO_BYPASS_VADDR < XCHAL_KIO_SIZE)) - xtensa_iounmap(addr); } - -#endif /* CONFIG_MMU */ +#define ioremap_cache ioremap_cache #include diff --git a/arch/xtensa/mm/ioremap.c b/arch/xtensa/mm/ioremap.c index a400188c16b9..0508448d767a 100644 --- a/arch/xtensa/mm/ioremap.c +++ b/arch/xtensa/mm/ioremap.c @@ -6,60 +6,30 @@ */ #include -#include #include #include #include -static void __iomem *xtensa_ioremap(unsigned long paddr, unsigned long size, - pgprot_t prot) +void __iomem * +arch_ioremap(phys_addr_t *paddr, size_t size, unsigned long *prot_val) { - unsigned long offset = paddr & ~PAGE_MASK; - unsigned long pfn = __phys_to_pfn(paddr); - struct vm_struct *area; - unsigned long vaddr; - int err; - - paddr &= PAGE_MASK; + unsigned long phys_addr = *paddr; + unsigned long pfn = __phys_to_pfn(phys_addr); WARN_ON(pfn_valid(pfn)); - size = PAGE_ALIGN(offset + size); - - area = get_vm_area(size, VM_IOREMAP); - if (!area) - return NULL; - - vaddr = (unsigned long)area->addr; - area->phys_addr = paddr; - - err = ioremap_page_range(vaddr, vaddr + size, paddr, prot); - - if (err) { - vunmap((void *)vaddr); - return NULL; - } - - flush_cache_vmap(vaddr, vaddr + size); - return (void __iomem *)(offset + vaddr); + return NULL; } -void __iomem *xtensa_ioremap_nocache(unsigned long addr, unsigned long size) +int arch_iounmap(void __iomem *addr) { - return xtensa_ioremap(addr, size, pgprot_noncached(PAGE_KERNEL)); -} -EXPORT_SYMBOL(xtensa_ioremap_nocache); + unsigned long va = (unsigned long) addr; -void __iomem *xtensa_ioremap_cache(unsigned long addr, unsigned long size) -{ - return xtensa_ioremap(addr, size, PAGE_KERNEL); -} -EXPORT_SYMBOL(xtensa_ioremap_cache); - -void xtensa_iounmap(volatile void __iomem *io_addr) -{ - void *addr = (void *)(PAGE_MASK & (unsigned long)io_addr); + if ((va >= XCHAL_KIO_CACHED_VADDR && + va - XCHAL_KIO_CACHED_VADDR < XCHAL_KIO_SIZE) || + (va >= XCHAL_KIO_BYPASS_VADDR && + va - XCHAL_KIO_BYPASS_VADDR < XCHAL_KIO_SIZE)) + return -EINVAL; - vunmap(addr); + return 0; } -EXPORT_SYMBOL(xtensa_iounmap);