From patchwork Wed Oct 12 10:09:44 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christophe Leroy X-Patchwork-Id: 13004935 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 2F4AEC433FE for ; Wed, 12 Oct 2022 10:10:33 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id B96E3900007; Wed, 12 Oct 2022 06:10:32 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id B1F81900005; Wed, 12 Oct 2022 06:10:32 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 971BB900007; Wed, 12 Oct 2022 06:10:32 -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 870F6900005 for ; Wed, 12 Oct 2022 06:10:32 -0400 (EDT) Received: from smtpin07.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id 2BA1AAB926 for ; Wed, 12 Oct 2022 10:10:32 +0000 (UTC) X-FDA: 80011877904.07.8D43D12 Received: from pegase2.c-s.fr (pegase2.c-s.fr [93.17.235.10]) by imf01.hostedemail.com (Postfix) with ESMTP id 804954003B for ; Wed, 12 Oct 2022 10:10:31 +0000 (UTC) Received: from localhost (mailhub3.si.c-s.fr [172.26.127.67]) by localhost (Postfix) with ESMTP id 4MnT101Hfzz9sn6; Wed, 12 Oct 2022 12:10:12 +0200 (CEST) X-Virus-Scanned: amavisd-new at c-s.fr Received: from pegase2.c-s.fr ([172.26.127.65]) by localhost (pegase2.c-s.fr [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 9T1QHTvMy9SO; Wed, 12 Oct 2022 12:10:12 +0200 (CEST) Received: from messagerie.si.c-s.fr (messagerie.si.c-s.fr [192.168.25.192]) by pegase2.c-s.fr (Postfix) with ESMTP id 4MnT0w60dFz9sn7; Wed, 12 Oct 2022 12:10:08 +0200 (CEST) Received: from localhost (localhost [127.0.0.1]) by messagerie.si.c-s.fr (Postfix) with ESMTP id B39E98B774; Wed, 12 Oct 2022 12:10:08 +0200 (CEST) X-Virus-Scanned: amavisd-new at c-s.fr Received: from messagerie.si.c-s.fr ([127.0.0.1]) by localhost (messagerie.si.c-s.fr [127.0.0.1]) (amavisd-new, port 10023) with ESMTP id MUxHFGu1wiym; Wed, 12 Oct 2022 12:10:08 +0200 (CEST) Received: from PO20335.IDSI0.si.c-s.fr (unknown [192.168.232.127]) by messagerie.si.c-s.fr (Postfix) with ESMTP id 0297A8B775; Wed, 12 Oct 2022 12:10:07 +0200 (CEST) Received: from PO20335.IDSI0.si.c-s.fr (localhost [127.0.0.1]) by PO20335.IDSI0.si.c-s.fr (8.17.1/8.16.1) with ESMTPS id 29CAA0VU1165808 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Wed, 12 Oct 2022 12:10:00 +0200 Received: (from chleroy@localhost) by PO20335.IDSI0.si.c-s.fr (8.17.1/8.17.1/Submit) id 29CAA0Ci1165807; Wed, 12 Oct 2022 12:10:00 +0200 X-Authentication-Warning: PO20335.IDSI0.si.c-s.fr: chleroy set sender to christophe.leroy@csgroup.eu using -f From: Christophe Leroy To: Baoquan He Cc: Christophe Leroy , linux-mm@kvack.org, linux-kernel@vger.kernel.org, linux-arch@vger.kernel.org, akpm@linux-foundation.org, hch@infradead.org, agordeev@linux.ibm.com, wangkefeng.wang@huawei.com, schnelle@linux.ibm.com, David.Laight@ACULAB.COM, shorne@gmail.com Subject: [RFC PATCH 8/8] powerpc: mm: Convert to GENERIC_IOREMAP Date: Wed, 12 Oct 2022 12:09:44 +0200 Message-Id: <1436b584c39e714a2e3fb58ca24ee782c6274648.1665568707.git.christophe.leroy@csgroup.eu> X-Mailer: git-send-email 2.37.1 In-Reply-To: References: MIME-Version: 1.0 X-Developer-Signature: v=1; a=ed25519-sha256; t=1665569382; l=6439; s=20211009; h=from:subject:message-id; bh=Xp852WfeLXaJsSr0XAj+ZSuVjsTe5bETwxm8dI7ATNs=; b=5nwfvPK9Nguk9Et5VTmhtmg+6DuGmT9LxCKWAAvz/6qHUXiYR3v8zK7JXKmRzwyvjq8P7YR0J/BM Y/bH5BEZA9+eRvS4SmOrefbS3YyhE2TN506m+/7ssam7lmMrVO35 X-Developer-Key: i=christophe.leroy@csgroup.eu; a=ed25519; pk=HIzTzUj91asvincQGOFx6+ZF5AoUuP9GdOtQChs7Mm0= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1665569431; a=rsa-sha256; cv=none; b=TI972j/2bJTLzm/5tpgrlN5BvjHuXh27MC4BDxCk7DqhTc88FxY8V+/Xvp3rDpF/iH+LtJ DC0pCUET1S2Go0rPmdfIMV6LAkodxN8zL3RCJ6b1xUXjE/np53rFNVcv12thMRbdKxGJsN nZ6fJz9ZfhZJVV0SL20DNEIvcrnlKG4= ARC-Authentication-Results: i=1; imf01.hostedemail.com; dkim=none; spf=pass (imf01.hostedemail.com: domain of christophe.leroy@csgroup.eu designates 93.17.235.10 as permitted sender) smtp.mailfrom=christophe.leroy@csgroup.eu; dmarc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1665569431; 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-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=oYiZciX3icn2Yb5o3CMpTbuzkJzSpiDmvzz9LCqzC1k=; b=DbxBNPnF/71EwOmj8P5Gv3bRfDv2Sl/1c9g21ixZG3x4LL/nsGOygCYTIyLxvJ4foF3Z+h 5RBiR9FAyhhS7Tqj0wvZJIzu0BY6Vehznu4ymUW7X+dENPZFFCRPI5E08C36eribuQl3p+ HGUSxfD4maMVswjWqumNs3Wor484n9Q= X-Stat-Signature: ys8e83zyykurx473qhu6h3gxw64wrdxd X-Rspamd-Queue-Id: 804954003B X-Rspam-User: X-Rspamd-Server: rspam08 Authentication-Results: imf01.hostedemail.com; dkim=none; spf=pass (imf01.hostedemail.com: domain of christophe.leroy@csgroup.eu designates 93.17.235.10 as permitted sender) smtp.mailfrom=christophe.leroy@csgroup.eu; dmarc=none X-HE-Tag: 1665569431-395573 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: Signed-off-by: Christophe Leroy --- arch/powerpc/Kconfig | 1 + arch/powerpc/include/asm/io.h | 11 ++++++++--- arch/powerpc/mm/ioremap.c | 26 +------------------------- arch/powerpc/mm/ioremap_32.c | 25 ++++++++++--------------- arch/powerpc/mm/ioremap_64.c | 22 +++++++++------------- 5 files changed, 29 insertions(+), 56 deletions(-) diff --git a/arch/powerpc/Kconfig b/arch/powerpc/Kconfig index 81c9f895d690..c8704933ae5a 100644 --- a/arch/powerpc/Kconfig +++ b/arch/powerpc/Kconfig @@ -179,6 +179,7 @@ config PPC select GENERIC_CPU_VULNERABILITIES if PPC_BARRIER_NOSPEC select GENERIC_EARLY_IOREMAP select GENERIC_GETTIMEOFDAY + select GENERIC_IOREMAP select GENERIC_IRQ_SHOW select GENERIC_IRQ_SHOW_LEVEL select GENERIC_PCI_IOMAP if PCI diff --git a/arch/powerpc/include/asm/io.h b/arch/powerpc/include/asm/io.h index fc112a91d0c2..3d38f46ade16 100644 --- a/arch/powerpc/include/asm/io.h +++ b/arch/powerpc/include/asm/io.h @@ -859,8 +859,8 @@ static inline void iosync(void) * */ extern void __iomem *ioremap(phys_addr_t address, unsigned long size); -extern void __iomem *ioremap_prot(phys_addr_t address, unsigned long size, - unsigned long flags); +#define ioremap ioremap +#define ioremap_prot ioremap_prot extern void __iomem *ioremap_wc(phys_addr_t address, unsigned long size); #define ioremap_wc ioremap_wc @@ -874,7 +874,12 @@ void __iomem *ioremap_coherent(phys_addr_t address, unsigned long size); #define ioremap_cache(addr, size) \ ioremap_prot((addr), (size), pgprot_val(PAGE_KERNEL)) -extern void iounmap(volatile void __iomem *addr); +#ifdef CONFIG_PPC_INDIRECT_MMIO +#define iounmap iounmap +#endif + +bool iounmap_allowed(void *addr); +#define iounmap_allowed iounmap_allowed void __iomem *ioremap_phb(phys_addr_t paddr, unsigned long size); diff --git a/arch/powerpc/mm/ioremap.c b/arch/powerpc/mm/ioremap.c index 4f12504fb405..705e8e8ffde4 100644 --- a/arch/powerpc/mm/ioremap.c +++ b/arch/powerpc/mm/ioremap.c @@ -41,7 +41,7 @@ void __iomem *ioremap_coherent(phys_addr_t addr, unsigned long size) return __ioremap_caller(addr, size, prot, caller); } -void __iomem *ioremap_prot(phys_addr_t addr, unsigned long size, unsigned long flags) +void __iomem *ioremap_prot(phys_addr_t addr, size_t size, unsigned long flags) { pte_t pte = __pte(flags); void *caller = __builtin_return_address(0); @@ -74,27 +74,3 @@ int early_ioremap_range(unsigned long ea, phys_addr_t pa, return 0; } - -void __iomem *do_ioremap(phys_addr_t pa, phys_addr_t offset, unsigned long size, - pgprot_t prot, void *caller) -{ - struct vm_struct *area; - int ret; - unsigned long va; - - area = __get_vm_area_caller(size, VM_IOREMAP, IOREMAP_START, IOREMAP_END, caller); - if (area == NULL) - return NULL; - - area->phys_addr = pa; - va = (unsigned long)area->addr; - - ret = ioremap_page_range(va, va + size, pa, prot); - if (!ret) - return (void __iomem *)area->addr + offset; - - vunmap_range(va, va + size); - free_vm_area(area); - - return NULL; -} diff --git a/arch/powerpc/mm/ioremap_32.c b/arch/powerpc/mm/ioremap_32.c index 9d13143b8be4..e9a60ddfd6b3 100644 --- a/arch/powerpc/mm/ioremap_32.c +++ b/arch/powerpc/mm/ioremap_32.c @@ -21,6 +21,13 @@ __ioremap_caller(phys_addr_t addr, unsigned long size, pgprot_t prot, void *call phys_addr_t p, offset; int err; + /* + * If the address lies within the first 16 MB, assume it's in ISA + * memory space + */ + if (addr < SZ_16M) + addr += _ISA_MEM_BASE; + /* * Choose an address to map it to. * Once the vmalloc system is running, we use it. @@ -31,13 +38,6 @@ __ioremap_caller(phys_addr_t addr, unsigned long size, pgprot_t prot, void *call offset = addr & ~PAGE_MASK; size = PAGE_ALIGN(addr + size) - p; - /* - * If the address lies within the first 16 MB, assume it's in ISA - * memory space - */ - if (p < 16 * 1024 * 1024) - p += _ISA_MEM_BASE; - #ifndef CONFIG_CRASH_DUMP /* * Don't allow anybody to remap normal RAM that we're using. @@ -63,7 +63,7 @@ __ioremap_caller(phys_addr_t addr, unsigned long size, pgprot_t prot, void *call return (void __iomem *)v + offset; if (slab_is_available()) - return do_ioremap(p, offset, size, prot, caller); + return generic_ioremap_prot(addr, size, prot); /* * Should check if it is a candidate for a BAT mapping @@ -78,16 +78,11 @@ __ioremap_caller(phys_addr_t addr, unsigned long size, pgprot_t prot, void *call return (void __iomem *)ioremap_bot + offset; } -void iounmap(volatile void __iomem *addr) +bool iounmap_allowed(void *addr) { /* * If mapped by BATs then there is nothing to do. * Calling vfree() generates a benign warning. */ - if (v_block_mapped((unsigned long)addr)) - return; - - if (addr > high_memory && (unsigned long)addr < ioremap_bot) - vunmap((void *)(PAGE_MASK & (unsigned long)addr)); + return !v_block_mapped((unsigned long)addr); } -EXPORT_SYMBOL(iounmap); diff --git a/arch/powerpc/mm/ioremap_64.c b/arch/powerpc/mm/ioremap_64.c index 3acece00b33e..a319d40253e5 100644 --- a/arch/powerpc/mm/ioremap_64.c +++ b/arch/powerpc/mm/ioremap_64.c @@ -29,7 +29,7 @@ void __iomem *__ioremap_caller(phys_addr_t addr, unsigned long size, return NULL; if (slab_is_available()) - return do_ioremap(paligned, offset, size, prot, caller); + return generic_ioremap_prot(addr, size, prot); pr_warn("ioremap() called early from %pS. Use early_ioremap() instead\n", caller); @@ -47,19 +47,15 @@ void __iomem *__ioremap_caller(phys_addr_t addr, unsigned long size, * Unmap an IO region and remove it from vmalloc'd list. * Access to IO memory should be serialized by driver. */ -void iounmap(volatile void __iomem *token) +bool iounmap_allowed(void *addr) { - void *addr; - - if (!slab_is_available()) - return; - - addr = (void *)((unsigned long __force)PCI_FIX_ADDR(token) & PAGE_MASK); + return slab_is_available(); +} - if ((unsigned long)addr < ioremap_bot) { - pr_warn("Attempt to iounmap early bolted mapping at 0x%p\n", addr); - return; - } - vunmap(addr); +#ifdef CONFIG_PPC_INDIRECT_MMIO +void iounmap(volatile void __iomem *token) +{ + generic_iounmap(PCI_FIX_ADDR(token)); } EXPORT_SYMBOL(iounmap); +#endif