From patchwork Sun Oct 9 10:31:04 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Baoquan He X-Patchwork-Id: 13001965 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 11533C433FE for ; Sun, 9 Oct 2022 10:31:40 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 7B632900002; Sun, 9 Oct 2022 06:31:39 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 73E386B0074; Sun, 9 Oct 2022 06:31:39 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 59148900002; Sun, 9 Oct 2022 06:31:39 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id 412066B0073 for ; Sun, 9 Oct 2022 06:31:39 -0400 (EDT) Received: from smtpin07.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id 11F5F160AA7 for ; Sun, 9 Oct 2022 10:31:39 +0000 (UTC) X-FDA: 80001044718.07.1AE1168 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by imf16.hostedemail.com (Postfix) with ESMTP id 9BC91180010 for ; Sun, 9 Oct 2022 10:31:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1665311496; 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=+shEiQhHXH9NvLeUIkuIHtH61AWuIik634uQg6vXtDM=; b=hjocEZB9s5WOEqZYc9GvLy+vP9j5wQB2TW/ro+HWFRC/uliWVHLsC+wV6xrDU1XD7T2gLJ +2EGkak3tmYnVvVTbVX8xY4KUB5PXlFja0cIsCbjuS0abLCi4PvPMcUxnBSSkO4VyaYaEo UO1DfnD0eVyFWtEKvuBSml0n3K8ABQI= 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-103-OTdYuyZvM66icShuEcJGmw-1; Sun, 09 Oct 2022 06:31:32 -0400 X-MC-Unique: OTdYuyZvM66icShuEcJGmw-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 7F6853C0257E; Sun, 9 Oct 2022 10:31:31 +0000 (UTC) Received: from MiWiFi-R3L-srv.redhat.com (ovpn-12-36.pek2.redhat.com [10.72.12.36]) by smtp.corp.redhat.com (Postfix) with ESMTP id 8351740D298B; Sun, 9 Oct 2022 10:31:24 +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, christophe.leroy@csgroup.eu, schnelle@linux.ibm.com, David.Laight@ACULAB.COM, shorne@gmail.com, bhe@redhat.com, Brian Cain , Mark Brown , Linus Walleij , linux-hexagon@vger.kernel.org Subject: [PATCH v3 01/11] hexagon: mm: Convert to GENERIC_IOREMAP Date: Sun, 9 Oct 2022 18:31:04 +0800 Message-Id: <20221009103114.149036-2-bhe@redhat.com> In-Reply-To: <20221009103114.149036-1-bhe@redhat.com> References: <20221009103114.149036-1-bhe@redhat.com> MIME-Version: 1.0 Content-type: text/plain X-Scanned-By: MIMEDefang 3.1 on 10.11.54.2 ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1665311497; a=rsa-sha256; cv=none; b=k08jqokt/bKzLXDZCz3n4bSYx2075FmQs1oqsb3laUaQGLrL/qpd9UFjrecLM2Iq2ZzhK9 1YUxS02Lp15aUf+NmBzZAtzM30p5BgIg+D5ZwAcJpqk0vroN71E98p3f1TnQ6WF52CaDnN l26Qn5QR57vuAKjuBydLxwYO52lBKG4= ARC-Authentication-Results: i=1; imf16.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=hjocEZB9; spf=pass (imf16.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-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1665311497; 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=+shEiQhHXH9NvLeUIkuIHtH61AWuIik634uQg6vXtDM=; b=NGOZdYBiqeIKQlKZj0LX1lK1TaaTNCHOpUL5ctO5KUDGIBLxDcTUwCetr61kjWTcGevocn +sg3Z3mYjcnRjIhMwP2Gc4XvSJGyLK+vVNSGzQ3Vc8yS0F3JsfmNPrMvpua7kgis5klDDJ 0/Q3u+NM3/4MMEDYUrvcEX1lgHlmUxU= Authentication-Results: imf16.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=hjocEZB9; spf=pass (imf16.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: tt9aa3ixye68cqehfb4gmtzpn8fdts17 X-Rspamd-Queue-Id: 9BC91180010 X-Rspam-User: X-Rspamd-Server: rspam05 X-HE-Tag: 1665311497-23664 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: By taking GENERIC_IOREMAP method, the generic ioremap_prot() and iounmap() are visible and available to arch. Arch only needs to provide implementation of arch_ioremap() or arch_iounmap() if there's arch specific handling needed in its ioremap() or iounmap(). This change will simplify implementation by removing duplicated codes with generic ioremap() and iounmap(), and has the equivalent functioality. For hexagon, the current ioremap() and iounmap() are the same as generic version. After taking GENERIC_IOREMAP way, the old ioremap() and iounmap() can be completely removed. Signed-off-by: Baoquan He Cc: Brian Cain Cc: Mark Brown Cc: Linus Walleij Cc: linux-hexagon@vger.kernel.org --- v2->v3: Rewrite patch log. Put it at the beginning of patchset since it doesn't introduce new arch_ioremap()/arch_iounmap(). 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 46a099de85b7..dcd9cbbf5934 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 Sun Oct 9 10:31:05 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Baoquan He X-Patchwork-Id: 13001966 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 72376C433F5 for ; Sun, 9 Oct 2022 10:31:49 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 0D7B1900003; Sun, 9 Oct 2022 06:31:49 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 0604B6B0075; Sun, 9 Oct 2022 06:31:48 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id E25DB900003; Sun, 9 Oct 2022 06:31:48 -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 C89236B0074 for ; Sun, 9 Oct 2022 06:31:48 -0400 (EDT) Received: from smtpin06.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id 87B5B120A03 for ; Sun, 9 Oct 2022 10:31:48 +0000 (UTC) X-FDA: 80001045096.06.6B18E11 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by imf11.hostedemail.com (Postfix) with ESMTP id 34CE540021 for ; Sun, 9 Oct 2022 10:31:47 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1665311506; 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=1cXjxLGfG1GBa+cjM88n4B6gIxUK4HiTfwhhDRLHWsM=; b=GxiPIcGzWH2e8QCiQZ4XiJda192eEx4cXFL7ObQ80K1c3w3nGp9j09EJ5UXITBVhw+DkSX LWEL1QOdRMvhWh+42MbenbiIXbZNY3sfZbFg/AfDbyFO/heVnwSoaKjbK1YB/Nd84aOM4Z s/Lp5bb7sEeSh93MMyOyjda63114qeA= 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-504-w7Wzcy9xPomMLPYFG8YXMQ-1; Sun, 09 Oct 2022 06:31:41 -0400 X-MC-Unique: w7Wzcy9xPomMLPYFG8YXMQ-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 A426029AB3FB; Sun, 9 Oct 2022 10:31:40 +0000 (UTC) Received: from MiWiFi-R3L-srv.redhat.com (ovpn-12-36.pek2.redhat.com [10.72.12.36]) by smtp.corp.redhat.com (Postfix) with ESMTP id 4E55940D298B; Sun, 9 Oct 2022 10:31:31 +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, christophe.leroy@csgroup.eu, schnelle@linux.ibm.com, David.Laight@ACULAB.COM, shorne@gmail.com, bhe@redhat.com, Jonas Bonn , Stefan Kristiansson , openrisc@lists.librecores.org Subject: [PATCH v3 02/11] openrisc: mm: remove unneeded early ioremap code Date: Sun, 9 Oct 2022 18:31:05 +0800 Message-Id: <20221009103114.149036-3-bhe@redhat.com> In-Reply-To: <20221009103114.149036-1-bhe@redhat.com> References: <20221009103114.149036-1-bhe@redhat.com> MIME-Version: 1.0 Content-type: text/plain X-Scanned-By: MIMEDefang 3.1 on 10.11.54.2 ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1665311507; 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=1cXjxLGfG1GBa+cjM88n4B6gIxUK4HiTfwhhDRLHWsM=; b=aLAG7ACWLtlcaSCIaicvCuvzu/BTeQjRVYn5ExcqX05ssokzrN3tm7Yd1lbMgn+vmi8Ux3 52eOLTRCcK296f43ZVY6bBUyDoDCA4hGtDFEI5dLxADLIN09uiNzCSBd1U76un7S8NgOFK zX8CSkk4XYWrfWHbksX76dfqIf2zqt4= ARC-Authentication-Results: i=1; imf11.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=GxiPIcGz; spf=pass (imf11.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=1665311507; a=rsa-sha256; cv=none; b=A8J3uubEpVYVPHAzujnfLF/Zb/J97Pny6M4FEQIjvfs6jMdBQxPXet0bJZWmBiT61Loab0 yAjnOwRtzaQKqKsDNGlGqV2oKXv0rQvFqshVxKL1M61MX9Io+3yCCShAbjsszu2sovZMxz mxJentQPLhpHsex7pq4sgDdO/FuSHew= Authentication-Results: imf11.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=GxiPIcGz; spf=pass (imf11.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-Rspam-User: X-Stat-Signature: 86bwjzd8px9quq5prg8j8mismankz6za X-Rspamd-Queue-Id: 34CE540021 X-Rspamd-Server: rspam01 X-HE-Tag: 1665311507-20237 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: Under arch/openrisc, there isn't any place where ioremap() is called. It means that there isn't early ioremap handling needed in openrisc, So the early ioremap handling code in ioremap() of arch/openrisc/mm/ioremap.c is unnecessary and can be removed. Signed-off-by: Baoquan He Cc: Jonas Bonn Cc: Stefan Kristiansson Cc: Stafford Horne Cc: openrisc@lists.librecores.org --- arch/openrisc/mm/ioremap.c | 22 +++++----------------- 1 file changed, 5 insertions(+), 17 deletions(-) diff --git a/arch/openrisc/mm/ioremap.c b/arch/openrisc/mm/ioremap.c index 8ec0dafecf25..90b59bc53c8c 100644 --- a/arch/openrisc/mm/ioremap.c +++ b/arch/openrisc/mm/ioremap.c @@ -22,8 +22,6 @@ 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 @@ -52,24 +50,14 @@ 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 ((fixmaps_used + (size >> PAGE_SHIFT)) > FIX_N_IOREMAPS) - return NULL; - v = fix_to_virt(FIX_IOREMAP_BEGIN + fixmaps_used); - fixmaps_used += (size >> PAGE_SHIFT); - } + area = get_vm_area(size, VM_IOREMAP); + if (!area) + return NULL; + v = (unsigned long)area->addr; if (ioremap_page_range(v, v + size, p, __pgprot(pgprot_val(PAGE_KERNEL) | _PAGE_CI))) { - if (likely(mem_init_done)) - vfree(area->addr); - else - fixmaps_used -= (size >> PAGE_SHIFT); + vfree(area->addr); return NULL; } From patchwork Sun Oct 9 10:31:06 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Baoquan He X-Patchwork-Id: 13001967 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 3812CC433F5 for ; Sun, 9 Oct 2022 10:31:56 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id B5EA780007; Sun, 9 Oct 2022 06:31:55 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id AE7306B0075; Sun, 9 Oct 2022 06:31:55 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 93A0580007; Sun, 9 Oct 2022 06:31:55 -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 796BE6B0074 for ; Sun, 9 Oct 2022 06:31:55 -0400 (EDT) Received: from smtpin29.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id 52970C0428 for ; Sun, 9 Oct 2022 10:31:55 +0000 (UTC) X-FDA: 80001045390.29.FFA203A 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 C3783A001E for ; Sun, 9 Oct 2022 10:31:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1665311514; 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=DPWSMu71Jh93HhZeuwwaVa4hpm9QyiaP2xITx3CuaM8=; b=iw72dNJO5lKfJOfslk4D6n4UnGRbZq0eVok5Pk9bWmQJx5lLuri/aDnwc/MYKMdNStyIa0 +0C2wbqZPwkyBnD27Z47cGt/44gUSqVOtz7O+xxrIKVPZcq54B79m93CuvUgbmUkUIQEOH IYBGB+Wn28FzxU3+xLOQfIL9aJUgJQ4= 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-107--7vpRcU5OhOnjty4Oj6YjQ-1; Sun, 09 Oct 2022 06:31:49 -0400 X-MC-Unique: -7vpRcU5OhOnjty4Oj6YjQ-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 339C4185A794; Sun, 9 Oct 2022 10:31:48 +0000 (UTC) Received: from MiWiFi-R3L-srv.redhat.com (ovpn-12-36.pek2.redhat.com [10.72.12.36]) by smtp.corp.redhat.com (Postfix) with ESMTP id 8BF2940D298B; Sun, 9 Oct 2022 10:31:40 +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, christophe.leroy@csgroup.eu, schnelle@linux.ibm.com, David.Laight@ACULAB.COM, shorne@gmail.com, bhe@redhat.com, Arnd Bergmann , linux-arch@vger.kernel.org, linux-arm-kernel@lists.infradead.org Subject: [PATCH v3 03/11] mm/ioremap: change the return value of io[re|un]map_allowed and rename Date: Sun, 9 Oct 2022 18:31:06 +0800 Message-Id: <20221009103114.149036-4-bhe@redhat.com> In-Reply-To: <20221009103114.149036-1-bhe@redhat.com> References: <20221009103114.149036-1-bhe@redhat.com> MIME-Version: 1.0 Content-type: text/plain X-Scanned-By: MIMEDefang 3.1 on 10.11.54.2 ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1665311514; a=rsa-sha256; cv=none; b=w1oJo0KZhmKfz3WwI+WyZVf9ged67ctbKSyJBuvBVFAZ6LAt70zKbM54jMYXfifx8LkvLx UyVBGVd5kzRlMMDAeVj4SAlnBaj1/+9Uc6C383rDZ8heqVlzwo7Z44MNwcd5azSKMsGyCh dtHD8MuG3nwlaHBYQ6rPUR4BzFcwxbs= ARC-Authentication-Results: i=1; imf25.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=iw72dNJO; 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-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1665311514; 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=DPWSMu71Jh93HhZeuwwaVa4hpm9QyiaP2xITx3CuaM8=; b=cqlNQlgeLGhj4xqjszF9lKeI4pVig+oW7L0hFK/GQmHTiU+3YFmyQCRhgiAbnjZv/9OHtY XyKVkDZcoEBKXe0INC54mWdvh7UhBqsNkG3cYRRTSvysvp+lWr6AJVSyKtfZh/Ba1hYBu/ fTDkTZiuYaVgxf65a5xjBalYzzJfDpQ= X-Stat-Signature: ixihfww5a3bwt59kfcufk3ctww7mn96q X-Rspamd-Queue-Id: C3783A001E Authentication-Results: imf25.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=iw72dNJO; 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-Rspamd-Server: rspam03 X-HE-Tag: 1665311514-35895 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: Currently, hooks ioremap_allowed() and iounmap_allowed() are used to check if it's qualified to do ioremap, and now this is done on ARM64. However, in oder to convert more architectures to take GENERIC_IOREMAP method, several more things need be done in those two hooks: 1) The io address mapping need be handled specifically on architectures, e.g arc, ia64, s390; 2) The original physical address passed into ioremap_prot() need be fixed up, e.g arc; 3) The 'prot' passed into ioremap_prot() need be adjusted, e.g on arc and xtensa. To handle these three issues, 1) Rename ioremap_allowed() and iounmap_allowed() to arch_ioremap() and arch_iounmap() since the old name can't reflect their functionality after change; 2) Change the return value of arch_ioremap() so that arch can add specifical io address mapping handling inside and return the maped address. Now their returned value means: === arch_ioremap() return a bool, - IS_ERR means return an error - 0 means continue to remap - a non-zero, non-IS_ERR pointer is returned directly arch_iounmap() return a bool, - true means continue to vunmap - false means skip vunmap and return directly 3) change the interface of arch_ioremap() so that the mapped address and adjusted 'prot' flag can be passed out. 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. Signed-off-by: Baoquan He Cc: Arnd Bergmann Cc: linux-arch@vger.kernel.org Cc: Kefeng Wang Cc: linux-arm-kernel@lists.infradead.org --- arch/arm64/include/asm/io.h | 5 +++-- arch/arm64/mm/ioremap.c | 16 +++++++++++----- include/asm-generic/io.h | 27 ++++++++++++++------------- mm/ioremap.c | 13 +++++++++---- 4 files changed, 37 insertions(+), 24 deletions(-) diff --git a/arch/arm64/include/asm/io.h b/arch/arm64/include/asm/io.h index 877495a0fd0c..6a5578ddbbf6 100644 --- a/arch/arm64/include/asm/io.h +++ b/arch/arm64/include/asm/io.h @@ -139,8 +139,9 @@ 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 *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 c5af103d4ad4..ef75ffef4dbc 100644 --- a/arch/arm64/mm/ioremap.c +++ b/arch/arm64/mm/ioremap.c @@ -3,19 +3,25 @@ #include #include -bool ioremap_allowed(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 = phys_addr + size - 1; + unsigned long last_addr, offset, phys_addr = *paddr; + + 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..2ae16906f3be 100644 --- a/include/asm-generic/io.h +++ b/include/asm-generic/io.h @@ -1049,25 +1049,26 @@ 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, + * 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, * - true means continue to vunmap - * - false means skip vunmap and return directly + * - false 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, - unsigned long prot) +#ifndef arch_ioremap +#define arch_ioremap arch_ioremap +static inline void __iomem *arch_ioremap(phys_addr_t *paddr, size_t size, + unsigned long *prot_val) { - 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 bool arch_iounmap(void __iomem *addr) { return true; } diff --git a/mm/ioremap.c b/mm/ioremap.c index 8652426282cc..fd1f0b33f4fd 100644 --- a/mm/ioremap.c +++ b/mm/ioremap.c @@ -17,6 +17,14 @@ 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; + + if (ioaddr) + return ioaddr; /* Disallow wrap-around or zero size */ last_addr = phys_addr + size - 1; @@ -28,9 +36,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 +57,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 Sun Oct 9 10:31:07 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Baoquan He X-Patchwork-Id: 13001969 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 DB456C4332F for ; Sun, 9 Oct 2022 10:32:18 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 78EA780008; Sun, 9 Oct 2022 06:32:18 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 716DC6B0075; Sun, 9 Oct 2022 06:32:18 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 5908780008; Sun, 9 Oct 2022 06:32: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 452AD6B0074 for ; Sun, 9 Oct 2022 06:32:18 -0400 (EDT) Received: from smtpin29.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id 0B1E380992 for ; Sun, 9 Oct 2022 10:32:18 +0000 (UTC) X-FDA: 80001046356.29.A5656B8 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 A9FF3180020 for ; Sun, 9 Oct 2022 10:32:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1665311537; 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=h0wz1H1leA7CuWV687C4HqKWq96HEonICKC1esEFR0M=; b=UVwZlw4WqXhp9BksWl3tKN+S0tc7nYRn0rDC7AQ3ZaIw64UNEO6Srj+s2ullmlSFIyFVrg 4z7kzd4TQ/sdXKuwiPeo2FKnkCyOWZX5qwOqi8HBbesG9SsD2cMtDhg/dllVJH0VEuUIFn HAYes5OKz+XIcAQoAi0HoiSJ2yrtiFk= 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-271-HV8un_y7MuqyqxHBgOZLEg-1; Sun, 09 Oct 2022 06:32:12 -0400 X-MC-Unique: HV8un_y7MuqyqxHBgOZLEg-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 5265729AB3FD; Sun, 9 Oct 2022 10:32:11 +0000 (UTC) Received: from MiWiFi-R3L-srv.redhat.com (ovpn-12-36.pek2.redhat.com [10.72.12.36]) by smtp.corp.redhat.com (Postfix) with ESMTP id 1B8D640D298B; Sun, 9 Oct 2022 10:31:48 +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, christophe.leroy@csgroup.eu, schnelle@linux.ibm.com, David.Laight@ACULAB.COM, shorne@gmail.com, bhe@redhat.com, Arnd Bergmann , linux-arch@vger.kernel.org Subject: [PATCH v3 04/11] mm: ioremap: allow ARCH to have its own ioremap definition Date: Sun, 9 Oct 2022 18:31:07 +0800 Message-Id: <20221009103114.149036-5-bhe@redhat.com> In-Reply-To: <20221009103114.149036-1-bhe@redhat.com> References: <20221009103114.149036-1-bhe@redhat.com> MIME-Version: 1.0 Content-type: text/plain X-Scanned-By: MIMEDefang 3.1 on 10.11.54.2 ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1665311537; 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=h0wz1H1leA7CuWV687C4HqKWq96HEonICKC1esEFR0M=; b=qeneita65pngql6ks8m0EqWj/ElRtJaIpBl242zjWbKYIRzXy0b1aRA6SFCEyZxoUZrjhr oVP2AceR6L8yvnGc8NrpLRl4Ez7Dh9IznpaNdGhQ88I6bKoDWW74yzR93N/u4sFwP+skOz Rq2i+5wnEveWP2U9vWOg4gbtp8vXm4Q= ARC-Authentication-Results: i=1; imf24.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=UVwZlw4W; 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=1665311537; a=rsa-sha256; cv=none; b=RjyEhML3AnC2UE5fxN6BpKWb6DMl61tgvEHkK7yKOiRLXSPV1JMWvepsZ6q5JcNm5jwyQF xseN7PZnUxyEfDEbJfMkhLPeQX/mZ8pES31nD+g2/Vvt7pBTWfKS2WgEbqIIPycww0flQo CzRFP+WfIE+sOlv9EjBQogVkst8C7kU= Authentication-Results: imf24.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=UVwZlw4W; 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-Rspam-User: X-Rspamd-Server: rspam04 X-Stat-Signature: id6k4eze3c9gcde9bxhsxu741wzrb7nb X-Rspamd-Queue-Id: A9FF3180020 X-HE-Tag: 1665311537-333750 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 Cc: Arnd Bergmann Cc: linux-arch@vger.kernel.org Cc: Kefeng Wang --- 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 2ae16906f3be..8878914579d8 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 Sun Oct 9 10:31:08 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Baoquan He X-Patchwork-Id: 13001970 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 7FFA0C433FE for ; Sun, 9 Oct 2022 10:32:23 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 0FE8380009; Sun, 9 Oct 2022 06:32:23 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 0601D6B0075; Sun, 9 Oct 2022 06:32:23 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id E1C5A80009; Sun, 9 Oct 2022 06:32:22 -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 CD4926B0074 for ; Sun, 9 Oct 2022 06:32:22 -0400 (EDT) Received: from smtpin16.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id A81CE160510 for ; Sun, 9 Oct 2022 10:32:22 +0000 (UTC) X-FDA: 80001046524.16.286F418 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by imf01.hostedemail.com (Postfix) with ESMTP id 5BA704002F for ; Sun, 9 Oct 2022 10:32:22 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1665311541; 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=HaQPeJxptHMyV1ztVt0VW5rhVl6/g1wDewqhu9GeM3I=; b=bxnqD2nzVox2IlyQfpwBW5EHH6gl14rS5Wc3TMF8Z5GY6z/h237YEQbbZIhxbS4Q1KjNU/ /5NrVDVMdAF3OA5Yh449G2sBUMKf5JSx/oIh0OdVQNeBgUpEYZkbrezzVUW677OiH8h8G+ rV860KQpROEArrkhY1HogrMfeiq6wys= 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-253-9rDO8_alNHa97RVOw_ynxw-1; Sun, 09 Oct 2022 06:32:18 -0400 X-MC-Unique: 9rDO8_alNHa97RVOw_ynxw-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 E7BA285A583; Sun, 9 Oct 2022 10:32:17 +0000 (UTC) Received: from MiWiFi-R3L-srv.redhat.com (ovpn-12-36.pek2.redhat.com [10.72.12.36]) by smtp.corp.redhat.com (Postfix) with ESMTP id 2656D40D298B; Sun, 9 Oct 2022 10:32:11 +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, christophe.leroy@csgroup.eu, schnelle@linux.ibm.com, David.Laight@ACULAB.COM, shorne@gmail.com, bhe@redhat.com, Vineet Gupta , linux-snps-arc@lists.infradead.org Subject: [PATCH v3 05/11] arc: mm: Convert to GENERIC_IOREMAP Date: Sun, 9 Oct 2022 18:31:08 +0800 Message-Id: <20221009103114.149036-6-bhe@redhat.com> In-Reply-To: <20221009103114.149036-1-bhe@redhat.com> References: <20221009103114.149036-1-bhe@redhat.com> MIME-Version: 1.0 Content-type: text/plain X-Scanned-By: MIMEDefang 3.1 on 10.11.54.2 ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1665311542; 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=HaQPeJxptHMyV1ztVt0VW5rhVl6/g1wDewqhu9GeM3I=; b=C5rWc5qRv6ErzMKvYxj14ZE5F/oIjFde9bXkxCJInCYqKNcWDMcKTPybrEd2Cny2vvTVrz 3PUpz8EB2+Lb9lkFsM83g/3eqfiShBAJJNZ4X+Alp9UA8sYrcWbdB6rXAsZig3SYGGTiKa Oq6BKrreJjlPg7JV0bCUDIIJtxtCqmI= ARC-Authentication-Results: i=1; imf01.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=bxnqD2nz; spf=pass (imf01.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=1665311542; a=rsa-sha256; cv=none; b=cg+0c7YUoxkFj6e+goWuhm1Y66lfX+fzTW2ijrnaMPKV2/bltyEFheo/rQk3RNw7Gag2fv 7rDAmDOP/ZYlQwzOvQLCdaoJDd45s2oYsuZVFBjRoL5VDf0/XCwKBlRluNPly6mhWgN6uv tzMbC1UilkH977f6v1rzEbP8XnQ+PlQ= Authentication-Results: imf01.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=bxnqD2nz; spf=pass (imf01.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-Rspam-User: X-Stat-Signature: d6isqbajnu6sfxpur1b8ztxoezfinpdk X-Rspamd-Queue-Id: 5BA704002F X-Rspamd-Server: rspam01 X-HE-Tag: 1665311542-595456 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: By taking GENERIC_IOREMAP method, the generic ioremap_prot() and iounmap() are visible and available to arch. Arch only needs to provide implementation of arch_ioremap() or arch_iounmap() if there's arch specific handling needed in its ioremap() or iounmap(). This change will simplify implementation by removing duplicated codes with generic ioremap() and iounmap(), and has the equivalent functioality as before. Here, 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..41a317567920 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 + +bool 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..c2dcacd56aca 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) +bool 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 false; - vfree((void *)(PAGE_MASK & (unsigned long __force)addr)); + return true; } -EXPORT_SYMBOL(iounmap); From patchwork Sun Oct 9 10:31:09 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Baoquan He X-Patchwork-Id: 13001972 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 F1685C433F5 for ; Sun, 9 Oct 2022 10:32:37 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 4D1D56B0075; Sun, 9 Oct 2022 06:32:37 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 4317F8000B; Sun, 9 Oct 2022 06:32:37 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 25C898000A; Sun, 9 Oct 2022 06:32:37 -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 069A76B0075 for ; Sun, 9 Oct 2022 06:32:37 -0400 (EDT) Received: from smtpin14.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id A2DA81C63EF for ; Sun, 9 Oct 2022 10:32:36 +0000 (UTC) X-FDA: 80001047112.14.2C22577 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by imf15.hostedemail.com (Postfix) with ESMTP id 60B9CA001B for ; Sun, 9 Oct 2022 10:32:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1665311555; 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=UIibfMEWzx8qbt+G+E/4sdi5Hq+zAkJYVe3xl5xYLl4=; b=V57gjTgm7i27xswPjlSfOf96jsPpF1zG/dIGdE17ewV8ylNMwY1/gvDBNql10jVAG3vTHg N2Jd7U7dv5PNWTEZH5iw6KVH06g07NffgbdgIq322wNtnINsPu6YF6hP7V49eMKA1xoR2d IUJUSRxQJoQJqfSF+8UfJr8+dP7XKAY= 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-342-bIPd6-M9PcePbJcxMLGtEQ-1; Sun, 09 Oct 2022 06:32:24 -0400 X-MC-Unique: bIPd6-M9PcePbJcxMLGtEQ-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 3DCCA380673A; Sun, 9 Oct 2022 10:32:24 +0000 (UTC) Received: from MiWiFi-R3L-srv.redhat.com (ovpn-12-36.pek2.redhat.com [10.72.12.36]) by smtp.corp.redhat.com (Postfix) with ESMTP id 9DA8F40D298B; Sun, 9 Oct 2022 10:32:18 +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, christophe.leroy@csgroup.eu, schnelle@linux.ibm.com, David.Laight@ACULAB.COM, shorne@gmail.com, bhe@redhat.com, linux-ia64@vger.kernel.org Subject: [PATCH v3 06/11] ia64: mm: Convert to GENERIC_IOREMAP Date: Sun, 9 Oct 2022 18:31:09 +0800 Message-Id: <20221009103114.149036-7-bhe@redhat.com> In-Reply-To: <20221009103114.149036-1-bhe@redhat.com> References: <20221009103114.149036-1-bhe@redhat.com> MIME-Version: 1.0 Content-type: text/plain X-Scanned-By: MIMEDefang 3.1 on 10.11.54.2 ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1665311556; a=rsa-sha256; cv=none; b=KLN9ufvtLISQo0nFax1HmNcFWy6YkT8qM5JY9ryxLJpqg+k/RDFVp0FqUrg3FcxWRl13ua e/x7/lDc+qw9Gew65Xg3NpAYOHZ2LnBkWXfxtOez8XQ0ybB7mNOb4V4d1h5Tt4MhR9YT4m InarytFEiFJHm6jzorjvrrO8K/zblYI= ARC-Authentication-Results: i=1; imf15.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=V57gjTgm; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf15.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=1665311556; 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=UIibfMEWzx8qbt+G+E/4sdi5Hq+zAkJYVe3xl5xYLl4=; b=vgNHz5XX7paCfFsfyCYkSmLM1SNY3OiVoSx4riApa4Jf4fiUkUrt51CQ8vLmtDjtf5Xt1w K2mJpBIlXFfJF9w2vHLlDxb8e0djMHIUyKGv/Rdy1GpCGQkzbG7WPRIMeLSbNDkQAo167f NyJKa6dUq40+Sj1qB9ff5G3z4MMqMK4= X-Stat-Signature: tqh3i1xq84wer865qkqq1py1apujk1oa X-Rspamd-Queue-Id: 60B9CA001B Authentication-Results: imf15.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=V57gjTgm; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf15.hostedemail.com: domain of bhe@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=bhe@redhat.com X-Rspam-User: X-Rspamd-Server: rspam03 X-HE-Tag: 1665311556-322741 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: By taking GENERIC_IOREMAP method, the generic ioremap_prot() and iounmap() are visible and available to arch. Arch only needs to provide implementation of arch_ioremap() or arch_iounmap() if there's arch specific handling needed in its ioremap() or iounmap(). This change will simplify implementation by removing duplicated codes with generic ioremap() and iounmap(), and has the equivalent functioality as before. Here 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..54378cea4b36 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 + +bool 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..a290c7dc7f1e 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); + +bool arch_iounmap(void __iomem *addr) +{ + if (REGION_NUMBER(addr) != RGN_GATE) + return false; + return true; +} 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 Sun Oct 9 10:31:10 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Baoquan He X-Patchwork-Id: 13001971 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 5A27DC433FE for ; Sun, 9 Oct 2022 10:32:37 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id E44666B0074; Sun, 9 Oct 2022 06:32:36 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id DCDFF8000B; Sun, 9 Oct 2022 06:32:36 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id C209A8000A; Sun, 9 Oct 2022 06:32:36 -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 ADBB26B0074 for ; Sun, 9 Oct 2022 06:32:36 -0400 (EDT) Received: from smtpin17.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id 863F91208EE for ; Sun, 9 Oct 2022 10:32:36 +0000 (UTC) X-FDA: 80001047112.17.6591E0A Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by imf14.hostedemail.com (Postfix) with ESMTP id 12752100017 for ; Sun, 9 Oct 2022 10:32:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1665311555; 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=KxegBGCY4AqOzRwM7tNubdONObE84AmZTumb3T1RzAM=; b=bzUZ1rNXD/c+aBQk1tIuoC1kqf8+WMFQpB09eIDFFrzlsCo1C064GSSA9Zd4PI9SibvlUC WV9W2F5sJQDzY0Yr55KVlp/UjuiG27HsCJJ3ojiSHPB+uAXiBafzV71QggZEW9kYfnQcyJ Z4cQcO2pe0Gt+Xlx33gtW5HO/3s11q4= 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-102-HH8FxDx4OlGuEkOaYzjZFw-1; Sun, 09 Oct 2022 06:32:32 -0400 X-MC-Unique: HH8FxDx4OlGuEkOaYzjZFw-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 9CD85800186; Sun, 9 Oct 2022 10:32:31 +0000 (UTC) Received: from MiWiFi-R3L-srv.redhat.com (ovpn-12-36.pek2.redhat.com [10.72.12.36]) by smtp.corp.redhat.com (Postfix) with ESMTP id 113DB40D298B; Sun, 9 Oct 2022 10:32:24 +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, christophe.leroy@csgroup.eu, schnelle@linux.ibm.com, David.Laight@ACULAB.COM, shorne@gmail.com, bhe@redhat.com, Jonas Bonn , Stefan Kristiansson , openrisc@lists.librecores.org Subject: [PATCH v3 07/11] openrisc: mm: Convert to GENERIC_IOREMAP Date: Sun, 9 Oct 2022 18:31:10 +0800 Message-Id: <20221009103114.149036-8-bhe@redhat.com> In-Reply-To: <20221009103114.149036-1-bhe@redhat.com> References: <20221009103114.149036-1-bhe@redhat.com> MIME-Version: 1.0 Content-type: text/plain X-Scanned-By: MIMEDefang 3.1 on 10.11.54.2 ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1665311556; 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=KxegBGCY4AqOzRwM7tNubdONObE84AmZTumb3T1RzAM=; b=KtfcYUAHmq87a1tN7flewHu02a8NOfk3ZoJVBcXPga0YlKXCIa1FIb25V/eBRhvNAPEmLv JzmnSg78jtylYxQg3nhbVPRiJCzsjArU8ky0Vldg4SV0dH1B0ATFkvuGP/uWezyHch2Zpo 5Yk7yGRGxALM7H7EOXISaCQjtgyS+f8= ARC-Authentication-Results: i=1; imf14.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=bzUZ1rNX; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf14.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=1665311556; a=rsa-sha256; cv=none; b=YbsPc1gLTzazhNzT2ashNGhtfe3Z9sN/R0AiyDjZ62J3jjTpI9mfna2BsvHF4H9HlYJTOt qBXPTUaOaZttyb5OzUSPFFh5tB/YhtZOzo+Cf8nu4oXeRSRBbDmEUEi5vClsmhbKDvFsjo QPhZ++t6jgJ7lAJ9fzLWtwjNITGV+rU= Authentication-Results: imf14.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=bzUZ1rNX; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf14.hostedemail.com: domain of bhe@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=bhe@redhat.com X-Stat-Signature: 19k5qyizutmqhbugh6sunfchk7b38xtu X-Rspamd-Queue-Id: 12752100017 X-Rspam-User: X-Rspamd-Server: rspam06 X-HE-Tag: 1665311555-145566 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: By taking GENERIC_IOREMAP method, the generic ioremap_prot() and iounmap() are visible and available to arch. Arch only needs to provide implementation of arch_ioremap() or arch_iounmap() if there's arch specific handling needed in its ioremap() or iounmap(). This change will simplify implementation by removing duplicated codes with generic ioremap() and iounmap(), and has the equivalent functioality as before. For openrisc, the duplicated ioremap() can be perfectly removed, and no arch_ioremap() is needed. Add arch_iounmap() to openrisc's special operation when iounmap(). Signed-off-by: Baoquan He Cc: Stafford Horne Cc: Jonas Bonn Cc: Stefan Kristiansson Cc: openrisc@lists.librecores.org --- v2->v3: - Remove the early ioremap handling code in previous patch as Christoph and Stafford suggested. With this, arch_ioremap() is not needed in v3 post. - adjust the order of including and in , this fix an compiling error of virt_defconig building, Stafford suggested this. arch/openrisc/Kconfig | 1 + arch/openrisc/include/asm/io.h | 12 +++++--- arch/openrisc/mm/ioremap.c | 50 ++-------------------------------- 3 files changed, 12 insertions(+), 51 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..c2df089a10c4 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,13 @@ #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. + */ +bool 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 90b59bc53c8c..bac2348b1737 100644 --- a/arch/openrisc/mm/ioremap.c +++ b/arch/openrisc/mm/ioremap.c @@ -22,50 +22,7 @@ extern int mem_init_done; -/* - * 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) -{ - phys_addr_t p; - unsigned long v; - unsigned long offset, last_addr; - struct vm_struct *area = NULL; - - /* Don't allow wraparound or zero size */ - last_addr = addr + size - 1; - if (!size || last_addr < addr) - return NULL; - - /* - * Mappings have to be page-aligned - */ - offset = addr & ~PAGE_MASK; - p = addr & PAGE_MASK; - size = PAGE_ALIGN(last_addr + 1) - p; - - area = get_vm_area(size, VM_IOREMAP); - if (!area) - return NULL; - v = (unsigned long)area->addr; - - if (ioremap_page_range(v, v + size, p, - __pgprot(pgprot_val(PAGE_KERNEL) | _PAGE_CI))) { - vfree(area->addr); - return NULL; - } - - return (void __iomem *)(offset + (char *)v); -} -EXPORT_SYMBOL(ioremap); - -void iounmap(volatile void __iomem *addr) +bool arch_iounmap(void __iomem *addr) { /* If the page is from the fixmap pool then we just clear out * the fixmap mapping. @@ -85,12 +42,11 @@ void iounmap(volatile void __iomem *addr) * ii) invalid accesses to the freed areas aren't made */ flush_tlb_all(); - return; + return false; } - return vfree((void *)(PAGE_MASK & (unsigned long)addr)); + return true; } -EXPORT_SYMBOL(iounmap); /** * OK, this one's a bit tricky... ioremap can get called before memory is From patchwork Sun Oct 9 10:31:11 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Baoquan He X-Patchwork-Id: 13001973 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 5572FC4332F for ; Sun, 9 Oct 2022 10:32:49 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id BFB06900003; Sun, 9 Oct 2022 06:32:48 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id BAA446B007B; Sun, 9 Oct 2022 06:32:48 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id A2412900003; Sun, 9 Oct 2022 06:32:48 -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 7FA926B0078 for ; Sun, 9 Oct 2022 06:32:48 -0400 (EDT) Received: from smtpin13.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id 2721140215 for ; Sun, 9 Oct 2022 10:32:48 +0000 (UTC) X-FDA: 80001047616.13.CA4E7A4 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by imf08.hostedemail.com (Postfix) with ESMTP id BE91F160025 for ; Sun, 9 Oct 2022 10:32:47 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1665311567; 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=VQufd3pNtB/ZLIfwfMxxAYrIBPOZ+D7pL2gacb9OT3o=; b=QTG7kKcPcNlOoO7nphXZ6RwMgNH8uI+daZWWpqwfymoehXYrq8G4PGs06B5CpvjKp7lOGl VkKfnHLd0J53GcjLS2zcNceBB9KmeLjOq0pt818cw/2RhmoEfaCTN4ZIV19krjBvrOgTvo S9/PacSEtHjoq6nhAttGjr133DrBcj0= 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-16-oye7IdRbOhqO2CIsuNzMQQ-1; Sun, 09 Oct 2022 06:32:39 -0400 X-MC-Unique: oye7IdRbOhqO2CIsuNzMQQ-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 17304380673B; Sun, 9 Oct 2022 10:32:39 +0000 (UTC) Received: from MiWiFi-R3L-srv.redhat.com (ovpn-12-36.pek2.redhat.com [10.72.12.36]) by smtp.corp.redhat.com (Postfix) with ESMTP id 6C6AF40D298B; Sun, 9 Oct 2022 10:32:32 +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, christophe.leroy@csgroup.eu, schnelle@linux.ibm.com, David.Laight@ACULAB.COM, shorne@gmail.com, bhe@redhat.com, "James E.J. Bottomley" , Helge Deller , linux-parisc@vger.kernel.org Subject: [PATCH v3 08/11] parisc: mm: Convert to GENERIC_IOREMAP Date: Sun, 9 Oct 2022 18:31:11 +0800 Message-Id: <20221009103114.149036-9-bhe@redhat.com> In-Reply-To: <20221009103114.149036-1-bhe@redhat.com> References: <20221009103114.149036-1-bhe@redhat.com> MIME-Version: 1.0 Content-type: text/plain X-Scanned-By: MIMEDefang 3.1 on 10.11.54.2 ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1665311567; a=rsa-sha256; cv=none; b=lBuh/P0Pk6CBh2jH+qG6+TXdfH8W6PyLZEWZ17nT4LN0ioo2V484fVtWRHcAv+p/odQr/a fjSRCsRbQ4MOhrUonKX3o2+ZmBz/P2YY+EIuuSZY3fmNL+KwSKbFIWQr15X3e/Ggm1hEaO qPxbxj3FY/tQXi/BstJKj8SzAH9k/WM= ARC-Authentication-Results: i=1; imf08.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=QTG7kKcP; spf=pass (imf08.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=1665311567; 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=VQufd3pNtB/ZLIfwfMxxAYrIBPOZ+D7pL2gacb9OT3o=; b=0Wuq4rG+smCw3g5gK8mSZ7kQO8+ddXOjiUhWwPU0VNN2BoEsHnl7eYu2O3V14zzVsWBvNd zvTu24gPCf+4Bq3Ke/wXNl4XcKb9/qjQkLRXsgWJ6ozF6YxSwElh1BH1Gvfl3Ioq67FL81 b4DZA7LV6E3JzVO5GAsfJoUJULKPN7E= Authentication-Results: imf08.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=QTG7kKcP; spf=pass (imf08.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: 3abzdfaqbnqt45hcdiom9i4qkw7synkz X-Rspamd-Server: rspam08 X-Rspamd-Queue-Id: BE91F160025 X-Rspam-User: X-HE-Tag: 1665311567-928267 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: By taking GENERIC_IOREMAP method, the generic ioremap_prot() and iounmap() are visible and available to arch. Arch only needs to provide implementation of arch_ioremap() or arch_iounmap() if there's arch specific handling needed in its ioremap() or iounmap(). This change will simplify implementation by removing duplicated codes with generic ioremap() and iounmap(), and has the equivalent functioality as before. For parisc, add hook arch_ioremap() for parisc's special operation when ioremap(), then ioremap_[wc|uc]() are converted to use ioremap_prot() from GENERIC_IOREMAP. Meanwhile, add macro ARCH_HAS_IOREMAP_WC since the added ioremap_wc() will conflict with the one in include/asm-generic/iomap.h, then an compiling error is seen: ./include/asm-generic/iomap.h:97: warning: "ioremap_wc" redefined 97 | #define ioremap_wc ioremap And benefit from the commit 437b6b35362b ("parisc: Use the generic IO helpers"), those macros don't need be added any more. Signed-off-by: Baoquan He Cc: "James E.J. Bottomley" Cc: Helge Deller Cc: linux-parisc@vger.kernel.org --- v2->v3: - Fix compiling error by adding macro definition, ARCH_HAS_IOREMAP_WC. - Benefit from commit 437b6b35362b ("parisc: Use the generic IO helpers"), those tons of port/mem io operation macro definitions are not needed after rebasing to the latest upstream. arch/parisc/Kconfig | 1 + arch/parisc/include/asm/io.h | 19 ++++++++--- arch/parisc/mm/ioremap.c | 65 ++++-------------------------------- 3 files changed, 21 insertions(+), 64 deletions(-) diff --git a/arch/parisc/Kconfig b/arch/parisc/Kconfig index a98940e64243..0ed18e673aba 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 c05e781be2f5..1c54f83d4f78 100644 --- a/arch/parisc/include/asm/io.h +++ b/arch/parisc/include/asm/io.h @@ -2,6 +2,8 @@ #ifndef _ASM_IO_H #define _ASM_IO_H +#define ARCH_HAS_IOREMAP_WC + #include #include @@ -125,12 +127,19 @@ static inline void gsc_writeq(unsigned long long val, unsigned long addr) /* * The standard PCI ioremap interfaces */ -void __iomem *ioremap(unsigned long offset, unsigned long size); -#define ioremap_wc ioremap -#define ioremap_uc ioremap -#define pci_iounmap pci_iounmap +void __iomem * +arch_ioremap(phys_addr_t *paddr, size_t size, unsigned long *prot_val); +#define arch_ioremap arch_ioremap + +#define _PAGE_IOREMAP (_PAGE_PRESENT | _PAGE_RW | _PAGE_DIRTY | \ + _PAGE_ACCESSED | _PAGE_NO_CACHE) -extern void iounmap(const volatile void __iomem *addr); +#define ioremap_wc(addr, size) \ + ioremap_prot((addr), (size), _PAGE_IOREMAP) +#define ioremap_uc(addr, size) \ + ioremap_prot((addr), (size), _PAGE_IOREMAP) + +#define pci_iounmap pci_iounmap void memset_io(volatile void __iomem *addr, unsigned char val, int count); void memcpy_fromio(void *dst, const volatile void __iomem *src, int count); 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 Sun Oct 9 10:31:12 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Baoquan He X-Patchwork-Id: 13001974 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 1B3CEC433FE for ; Sun, 9 Oct 2022 10:32:54 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id A4D206B0071; Sun, 9 Oct 2022 06:32:53 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 9D5786B0075; Sun, 9 Oct 2022 06:32:53 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 875C96B0078; Sun, 9 Oct 2022 06:32:53 -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 6F0A86B0071 for ; Sun, 9 Oct 2022 06:32:53 -0400 (EDT) Received: from smtpin30.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id 34A3AC08C0 for ; Sun, 9 Oct 2022 10:32:53 +0000 (UTC) X-FDA: 80001047826.30.69215AD Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by imf17.hostedemail.com (Postfix) with ESMTP id E096A4001F for ; Sun, 9 Oct 2022 10:32:52 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1665311572; 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=mD+OV9utzSXcQXCMPz81MaGlLSG9OvOonsw4fX7OiAw=; b=GL5T1UbG7dkiFDaXAQslURxEAqkAj1ydDQ7YBx5WpDWZ0xCZHlOkWrBQXZtgBrdrKgwvIF KkZH4HTRyK4H8hjEtFGCoAtLCyrP/8EkWY/zfF4lZ2mftuHDbyy8EXsitXcS1YYv/Rb1LQ /bt8vxcThMqUfgZxFQ2GG/phVVYeomA= 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-589-2CCG0gViNsW6llkrjImSmQ-1; Sun, 09 Oct 2022 06:32:48 -0400 X-MC-Unique: 2CCG0gViNsW6llkrjImSmQ-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 2CB52101A52A; Sun, 9 Oct 2022 10:32:47 +0000 (UTC) Received: from MiWiFi-R3L-srv.redhat.com (ovpn-12-36.pek2.redhat.com [10.72.12.36]) by smtp.corp.redhat.com (Postfix) with ESMTP id DB32740D298D; Sun, 9 Oct 2022 10:32:39 +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, christophe.leroy@csgroup.eu, schnelle@linux.ibm.com, David.Laight@ACULAB.COM, shorne@gmail.com, bhe@redhat.com, Gerald Schaefer , Heiko Carstens , Vasily Gorbik , Christian Borntraeger , Sven Schnelle , linux-s390@vger.kernel.org Subject: [PATCH v3 09/11] s390: mm: Convert to GENERIC_IOREMAP Date: Sun, 9 Oct 2022 18:31:12 +0800 Message-Id: <20221009103114.149036-10-bhe@redhat.com> In-Reply-To: <20221009103114.149036-1-bhe@redhat.com> References: <20221009103114.149036-1-bhe@redhat.com> MIME-Version: 1.0 Content-type: text/plain X-Scanned-By: MIMEDefang 3.1 on 10.11.54.2 ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1665311572; a=rsa-sha256; cv=none; b=Ejs5SNHcDpCm4/tC/PahHxvU3mxpEjYF6JH4Ikf+PACsmrhW8vitMdPopvn03YZg6fHcGF BA8inv83H+YVXJYU+UjKS5zMIfUS2WA3II7hGoKNNLJ8cuHRxWBwb2duwxuerWtmzLR9jp P/4915T6HinvOI6DGh1Bf9US9o8yGBI= ARC-Authentication-Results: i=1; imf17.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=GL5T1UbG; spf=pass (imf17.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-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1665311572; 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=mD+OV9utzSXcQXCMPz81MaGlLSG9OvOonsw4fX7OiAw=; b=0R/xDUk2FdW8W1viIMA2eECR+o7Xpdjdj+h987TTurldgvo61TU7FJIYni+4xMM3YQorcI 0CDTxri/EhX6g6QkNpSDcE9rj9yLscDZbpPon1j87qPgfTB3LW0YAXxv26BZORU5leRtpS aMGxgEc1jWwZ0SALD5XD5QuYN1PH0lk= Authentication-Results: imf17.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=GL5T1UbG; spf=pass (imf17.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: ikeqs4i4hsthfppkfbjqs6c8bhxj3ikp X-Rspamd-Server: rspam12 X-Rspamd-Queue-Id: E096A4001F X-Rspam-User: X-HE-Tag: 1665311572-533148 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: By taking GENERIC_IOREMAP method, the generic ioremap_prot() and iounmap() are visible and available to arch. Arch only needs to provide implementation of arch_ioremap() or arch_iounmap() if there's arch specific handling needed in its ioremap() or iounmap(). This change will simplify implementation by removing duplicated codes with generic ioremap() and iounmap(), and has the equivalent functioality as before. For s390, 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: Niklas Schnelle Cc: Gerald Schaefer Cc: Heiko Carstens Cc: Vasily Gorbik Cc: Alexander Gordeev Cc: Christian Borntraeger Cc: Sven Schnelle Cc: linux-s390@vger.kernel.org Signed-off-by: Baoquan He Tested-by: Niklas Reviewed-by: Niklas Schnelle --- v2->v3: - Add code comment inside arch_ioremap() to help uderstand the obsucre code. Christoph suggested this, Niklas provided the paragraph of text. arch/s390/Kconfig | 1 + arch/s390/include/asm/io.h | 25 +++++++++------ arch/s390/pci/pci.c | 65 ++++++++------------------------------ 3 files changed, 30 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..db201563baa6 100644 --- a/arch/s390/include/asm/io.h +++ b/arch/s390/include/asm/io.h @@ -22,11 +22,22 @@ 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 + +bool 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 +62,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..3c00dc7d79bc 100644 --- a/arch/s390/pci/pci.c +++ b/arch/s390/pci/pci.c @@ -244,64 +244,25 @@ 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; - + /* + * When PCI MIO instructions are unavailable the "physical" address + * encodes a hint for accessing the PCI memory space it represents. + * Just pass it unchanged such that ioread/iowrite can decode it. + */ 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); + return (void __iomem *) *paddr; + return NULL; } -void __iomem *ioremap_prot(phys_addr_t addr, size_t size, unsigned long prot) +bool arch_iounmap(void __iomem *addr) { - return __ioremap(addr, size, __pgprot(prot)); -} -EXPORT_SYMBOL(ioremap_prot); - -void __iomem *ioremap(phys_addr_t addr, size_t size) -{ - 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 false; + return true; } -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 Sun Oct 9 10:31:13 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Baoquan He X-Patchwork-Id: 13001975 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 9B76BC433FE for ; Sun, 9 Oct 2022 10:33:02 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 2FAFA900003; Sun, 9 Oct 2022 06:33:02 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 2826E6B0078; Sun, 9 Oct 2022 06:33:02 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 0FC60900003; Sun, 9 Oct 2022 06:33:02 -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 E890E6B0075 for ; Sun, 9 Oct 2022 06:33:01 -0400 (EDT) Received: from smtpin15.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id C11D81405F3 for ; Sun, 9 Oct 2022 10:33:01 +0000 (UTC) X-FDA: 80001048162.15.74FD8BA 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 41557A001D for ; Sun, 9 Oct 2022 10:33:01 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1665311580; 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=YuJ+1Xe1BzAEJqVi/zbdjMFVaN6W30y1eIWszmfiEjg=; b=iMZe0Oep178WjOolJjK4ek7I1gHpif+lSHYuwbHACFx3IXj2pGKZR06BkqzNpuDoMMQ1GK Ea0iJ0eKKRXJTXTVl0XrYJny/0/LtGnd7LqOwZ37/VGNlxZiQI/zhYGgmNwwcbqqKBUxIN GYkjWMvXwDUIqCco02MUaoFc50B3+Fg= 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-119-0M_-V7gkMQ2bbubuyOOQ_Q-1; Sun, 09 Oct 2022 06:32:55 -0400 X-MC-Unique: 0M_-V7gkMQ2bbubuyOOQ_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 710E495D681; Sun, 9 Oct 2022 10:32:54 +0000 (UTC) Received: from MiWiFi-R3L-srv.redhat.com (ovpn-12-36.pek2.redhat.com [10.72.12.36]) by smtp.corp.redhat.com (Postfix) with ESMTP id F0D7440D298B; Sun, 9 Oct 2022 10:32:47 +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, christophe.leroy@csgroup.eu, schnelle@linux.ibm.com, David.Laight@ACULAB.COM, shorne@gmail.com, bhe@redhat.com, Yoshinori Sato , Rich Felker , linux-sh@vger.kernel.org Subject: [PATCH v3 10/11] sh: mm: Convert to GENERIC_IOREMAP Date: Sun, 9 Oct 2022 18:31:13 +0800 Message-Id: <20221009103114.149036-11-bhe@redhat.com> In-Reply-To: <20221009103114.149036-1-bhe@redhat.com> References: <20221009103114.149036-1-bhe@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.2 ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1665311581; 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=YuJ+1Xe1BzAEJqVi/zbdjMFVaN6W30y1eIWszmfiEjg=; b=h8zP1eX+hdP9rtSjmGVSTTf6/Bd2bh5WkN9VTpp3BYIjhIG1Ksr2XnHx9MKgPN2MDo/nMN akT23d8/tY1/1uLYryx/6rx8kcKYvWZPVp2J51nBBU2ZLnLq6jfbG/cBvhaWmLe6/Mt/iC qZqyKM3GS+vA+Qq70uaJrKfCAWJ606c= ARC-Authentication-Results: i=1; imf25.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=iMZe0Oep; 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=1665311581; a=rsa-sha256; cv=none; b=VoyfDkgbJEiAOi5Lx4Fw+Ye0e1JLHuB2+Qr1Uvm8wHBXBzWRKTcLD/fZHdvxjmk5iu67wF dI6DfJ1NRV3Aus5Aow6GIngP1xDq/NW2AMD6m+/BRvGnhPmRECZvBADuudO30RVfKCku6K EQBApbCeeZ+fxPOxziM/6NtyaX8ShSc= X-Stat-Signature: ujyetnnobupzd5jufiwoibpciexxtg5k X-Rspamd-Server: rspam09 X-Rspam-User: Authentication-Results: imf25.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=iMZe0Oep; 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-Rspamd-Queue-Id: 41557A001D X-HE-Tag: 1665311581-25489 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: By taking GENERIC_IOREMAP method, the generic ioremap_prot() and iounmap() are visible and available to arch. Arch only needs to provide implementation of arch_ioremap() or arch_iounmap() if there's arch specific handling needed in its ioremap() or iounmap(). This change will simplify implementation by removing duplicated codes with generic ioremap() and iounmap(), and has the equivalent functioality as before. For SuperH, 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. Meanwhile, add macro definitions for port|mm io functions since SuperH has its own implementation in arch/sh/kernel/iomap.c and arch/sh/include/asm/io_noioport.h. These will conflict with the port|mm io function definitions in include/asm-generic/io.h to cause compiling errors like below: ==== CC arch/sh/kernel/asm-offsets.s In file included from ./arch/sh/include/asm/io.h:294, from ./include/linux/io.h:13, ...... from arch/sh/kernel/asm-offsets.c:16: ./include/asm-generic/io.h:792:17: error: conflicting types for ‘ioread8’ 792 | #define ioread8 ioread8 | ^~~~~~~ ./include/asm-generic/io.h:793:18: note: in expansion of macro ‘ioread8’ 793 | static inline u8 ioread8(const volatile void __iomem *addr) | ^~~~~~~ In file included from ./arch/sh/include/asm/io.h:22, from ./include/linux/io.h:13, ...... from arch/sh/kernel/asm-offsets.c:16: ./include/asm-generic/iomap.h:29:21: note: previous declaration of ‘ioread8’ was here 29 | extern unsigned int ioread8(const void __iomem *); ==== Signed-off-by: Baoquan He Cc: Yoshinori Sato Cc: Rich Felker Cc: linux-sh@vger.kernel.org --- v2->v3: - Add macro definitions for mem io operations to avoid the repeated definitions of them in include/asm-generic/io.h. arch/sh/Kconfig | 1 + arch/sh/include/asm/io.h | 67 +++++++++++++++++-------------- arch/sh/include/asm/io_noioport.h | 7 ++++ arch/sh/mm/ioremap.c | 63 ++++++----------------------- 4 files changed, 56 insertions(+), 82 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..f3edd92a8869 100644 --- a/arch/sh/include/asm/io.h +++ b/arch/sh/include/asm/io.h @@ -119,6 +119,26 @@ void __raw_readsl(const void __iomem *addr, void *data, int longlen); __BUILD_MEMORY_STRING(__raw_, q, u64) +#define ioread8 ioread8 +#define ioread16 ioread16 +#define ioread16be ioread16be +#define ioread32 ioread32 +#define ioread32be ioread32be + +#define iowrite8 iowrite8 +#define iowrite16 iowrite16 +#define iowrite16be iowrite16be +#define iowrite32 iowrite32 +#define iowrite32be iowrite32be + +#define ioread8_rep ioread8_rep +#define ioread16_rep ioread16_rep +#define ioread32_rep ioread32_rep + +#define iowrite8_rep iowrite8_rep +#define iowrite16_rep iowrite16_rep +#define iowrite32_rep iowrite32_rep + #ifdef CONFIG_HAS_IOPORT_MAP /* @@ -225,6 +245,9 @@ __BUILD_IOPORT_STRING(q, u64) #define IO_SPACE_LIMIT 0xffffffff /* We really want to try and get these to memcpy etc */ +#define memset_io memset_io +#define memcpy_fromio memcpy_fromio +#define memcpy_toio memcpy_toio void memcpy_fromio(void *, const volatile void __iomem *, unsigned long); void memcpy_toio(volatile void __iomem *, const void *, unsigned long); void memset_io(volatile void __iomem *, int, unsigned long); @@ -243,40 +266,20 @@ unsigned long long poke_real_address_q(unsigned long long addr, #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 */ +bool 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) { } +#define ioremap_cache(addr, size) \ + ioremap_prot((addr), (size), pgprot_val(PAGE_KERNEL)) #endif /* CONFIG_MMU */ #define ioremap_uc ioremap @@ -287,6 +290,8 @@ static inline void iounmap(volatile void __iomem *addr) { } */ #define xlate_dev_mem_ptr(p) __va(p) +#include + #define ARCH_HAS_VALID_PHYS_ADDR_RANGE int valid_phys_addr_range(phys_addr_t addr, size_t size); int valid_mmap_phys_addr_range(unsigned long pfn, size_t size); diff --git a/arch/sh/include/asm/io_noioport.h b/arch/sh/include/asm/io_noioport.h index f7938fe0f911..5ba4116b4265 100644 --- a/arch/sh/include/asm/io_noioport.h +++ b/arch/sh/include/asm/io_noioport.h @@ -53,6 +53,13 @@ static inline void ioport_unmap(void __iomem *addr) #define outw_p(x, addr) outw((x), (addr)) #define outl_p(x, addr) outl((x), (addr)) +#define insb insb +#define insw insw +#define insl insl +#define outsb outsb +#define outsw outsw +#define outsl outsl + static inline void insb(unsigned long port, void *dst, unsigned long count) { BUG(); diff --git a/arch/sh/mm/ioremap.c b/arch/sh/mm/ioremap.c index 21342581144d..4b20f00a3ca3 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) +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. @@ -112,34 +102,13 @@ __ioremap_caller(phys_addr_t phys_addr, unsigned long size, * First try to remap through the PMB. * PMB entries are all pre-faulted. */ - mapped = pmb_remap_caller(phys_addr, size, pgprot, caller); + mapped = pmb_remap_caller(phys_addr, size, pgprot, + __builtin_return_address(0)); 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,35 +127,27 @@ static inline int iomapping_nontranslatable(unsigned long offset) return 0; } -void iounmap(void __iomem *addr) +bool arch_iounmap(void __iomem *addr) { unsigned long vaddr = (unsigned long __force)addr; - struct vm_struct *p; /* * Nothing to do if there is no translatable mapping. */ if (iomapping_nontranslatable(vaddr)) - return; + return false; /* * There's no VMA if it's from an early fixed mapping. */ if (iounmap_fixed(addr) == 0) - return; + return false; /* * If the PMB handled it, there's nothing else to do. */ if (pmb_unmap(addr) == 0) - return; - - p = remove_vm_area((void *)(vaddr & PAGE_MASK)); - if (!p) { - printk(KERN_ERR "%s: bad address %p\n", __func__, addr); - return; - } + return false; - kfree(p); + return true; } -EXPORT_SYMBOL(iounmap); From patchwork Sun Oct 9 10:31:14 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Baoquan He X-Patchwork-Id: 13001976 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 DBCB7C433FE for ; Sun, 9 Oct 2022 10:33:12 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 717DA6B0075; Sun, 9 Oct 2022 06:33:12 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 6A1DD80008; Sun, 9 Oct 2022 06:33:12 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 4F3CD80007; Sun, 9 Oct 2022 06:33:12 -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 39AF76B0075 for ; Sun, 9 Oct 2022 06:33:12 -0400 (EDT) Received: from smtpin29.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id 09B581C63E7 for ; Sun, 9 Oct 2022 10:33:12 +0000 (UTC) X-FDA: 80001048624.29.033689B Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by imf03.hostedemail.com (Postfix) with ESMTP id A3ECE20014 for ; Sun, 9 Oct 2022 10:33:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1665311591; 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=bqIEJNY7OTuGnBXiHmFCBXJop9TGsVbIeh9U19Nxyck=; b=cuj+0jWHSWHA7D496ze4ZkMa101LP8NafICJV/K1H4xxOJKbUoAllYzJap7njdO0tmhiK4 6nrGPdMGbneYRPZrrpEXfq4lZ6iW6JHfm02lal6MZSYi546AX/4yG5Fibg3nnnhVKrpvZ7 AE3ENO0l6aRA9hS/TpxGkjzH1B6d7no= 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-669-RYSyp31wMciz2Sp9b4WCaQ-1; Sun, 09 Oct 2022 06:33:03 -0400 X-MC-Unique: RYSyp31wMciz2Sp9b4WCaQ-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 9D8B3101A5DE; Sun, 9 Oct 2022 10:33:02 +0000 (UTC) Received: from MiWiFi-R3L-srv.redhat.com (ovpn-12-36.pek2.redhat.com [10.72.12.36]) by smtp.corp.redhat.com (Postfix) with ESMTP id 17EF540D298B; Sun, 9 Oct 2022 10:32:54 +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, christophe.leroy@csgroup.eu, schnelle@linux.ibm.com, David.Laight@ACULAB.COM, shorne@gmail.com, bhe@redhat.com, Chris Zankel , Max Filippov , linux-xtensa@linux-xtensa.org Subject: [PATCH v3 11/11] xtensa: mm: Convert to GENERIC_IOREMAP Date: Sun, 9 Oct 2022 18:31:14 +0800 Message-Id: <20221009103114.149036-12-bhe@redhat.com> In-Reply-To: <20221009103114.149036-1-bhe@redhat.com> References: <20221009103114.149036-1-bhe@redhat.com> MIME-Version: 1.0 Content-type: text/plain X-Scanned-By: MIMEDefang 3.1 on 10.11.54.2 ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1665311591; 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=bqIEJNY7OTuGnBXiHmFCBXJop9TGsVbIeh9U19Nxyck=; b=VjleOuV6qc5oYveHzAJ025zGM2FY+tOdGktXc5wqDSxQmHCxgmLxuKotZXoZMnmvGk+9s7 QGHTgI111whQzlPy7RA+ZdgQezd8yU2rGrW2zYFRMX0SsoiSCZyp0kfUnv7g6Tr8ask18R pNf3z9KGs4pKYh1tU1JwPzK069C4OII= ARC-Authentication-Results: i=1; imf03.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=cuj+0jWH; spf=pass (imf03.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=1665311591; a=rsa-sha256; cv=none; b=opJdy5yISUQxZ7+8klz3y/qjBtadaMXnzU0Nz1Vc57elLCd+k8JSA1dB2v5QSLocluPrXK WkJGl+W93In2TAr2TQuL+AHtJvfSYOhEZQn5f3qGR8MtH3je8dQGnQBwIPPjCjBF7YGVhF rwmZfkzW+EdZe4NTRI9bVLsLy+fMhDA= Authentication-Results: imf03.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=cuj+0jWH; spf=pass (imf03.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-Rspam-User: X-Stat-Signature: dec6bbu45yfcb9aux7nr5p6rjcosurez X-Rspamd-Queue-Id: A3ECE20014 X-Rspamd-Server: rspam01 X-HE-Tag: 1665311591-534339 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: By taking GENERIC_IOREMAP method, the generic ioremap_prot() and iounmap() are visible and available to arch. Arch only needs to provide implementation of arch_ioremap() or arch_iounmap() if there's arch specific handling needed in its ioremap() or iounmap(). This change will simplify implementation by removing duplicated codes with generic ioremap() and iounmap(), and has the equivalent functioality as before. For xtensa, 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() via ioremap_prot(). Signed-off-by: Baoquan He Cc: Chris Zankel Cc: Max Filippov Cc: linux-xtensa@linux-xtensa.org Signed-off-by: Baoquan He Reported-by: kernel test robot --- arch/xtensa/Kconfig | 1 + arch/xtensa/include/asm/io.h | 39 +++++++++++-------------- arch/xtensa/mm/ioremap.c | 56 ++++++++---------------------------- 3 files changed, 30 insertions(+), 66 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..126af8de5722 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 + +bool 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..b76c3f264f6f 100644 --- a/arch/xtensa/mm/ioremap.c +++ b/arch/xtensa/mm/ioremap.c @@ -6,60 +6,28 @@ */ #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 pfn = __phys_to_pfn((*paddr)); 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); -} - -void __iomem *xtensa_ioremap_nocache(unsigned long addr, unsigned long size) -{ - return xtensa_ioremap(addr, size, pgprot_noncached(PAGE_KERNEL)); + return NULL; } -EXPORT_SYMBOL(xtensa_ioremap_nocache); -void __iomem *xtensa_ioremap_cache(unsigned long addr, unsigned long size) +bool arch_iounmap(void __iomem *addr) { - return xtensa_ioremap(addr, size, PAGE_KERNEL); -} -EXPORT_SYMBOL(xtensa_ioremap_cache); + unsigned long va = (unsigned long) addr; -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 false; - vunmap(addr); + return true; } -EXPORT_SYMBOL(xtensa_iounmap);