From patchwork Wed Oct 12 10:09:41 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christophe Leroy X-Patchwork-Id: 13004933 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 712D6C4332F for ; Wed, 12 Oct 2022 10:10:26 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 0E7E86B0073; Wed, 12 Oct 2022 06:10:26 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 098B3900005; Wed, 12 Oct 2022 06:10:26 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id E7AC36B0075; Wed, 12 Oct 2022 06:10:25 -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 D702A6B0073 for ; Wed, 12 Oct 2022 06:10:25 -0400 (EDT) Received: from smtpin23.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id AA7891A0417 for ; Wed, 12 Oct 2022 10:10:25 +0000 (UTC) X-FDA: 80011877610.23.5CB00FE Received: from pegase2.c-s.fr (pegase2.c-s.fr [93.17.235.10]) by imf26.hostedemail.com (Postfix) with ESMTP id 00F58140031 for ; Wed, 12 Oct 2022 10:10:23 +0000 (UTC) Received: from localhost (mailhub3.si.c-s.fr [172.26.127.67]) by localhost (Postfix) with ESMTP id 4MnT0y36Nhz9sml; Wed, 12 Oct 2022 12:10:10 +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 YNbwy0pJcXy2; Wed, 12 Oct 2022 12:10:10 +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 4MnT0w5v3Sz9sn4; 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 B12248B77B; 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 xrrLdeQbkJz9; 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 EE2178B763; 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 29CA9xsV1165795 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Wed, 12 Oct 2022 12:09:59 +0200 Received: (from chleroy@localhost) by PO20335.IDSI0.si.c-s.fr (8.17.1/8.17.1/Submit) id 29CA9xQ31165794; Wed, 12 Oct 2022 12:09:59 +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, Vineet Gupta , linux-snps-arc@lists.infradead.org Subject: [RFC PATCH 5/8] arc: mm: Convert to GENERIC_IOREMAP Date: Wed, 12 Oct 2022 12:09:41 +0200 Message-Id: <75718e9104633bad3c71e0c7a9e931864f59dee0.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=4421; i=christophe.leroy@csgroup.eu; s=20211009; h=from:subject:message-id; bh=I9YpOCQ8Zh4nRQnIk0k/uARdifFzSigtDi071xtQNOY=; b=fTxFGL4T5gFnKWBLwOouOC5OXfC/s0hbcSCg9/Nk032xr85dN+aJ6fKtMjsMmH2dJ6K15+lAaO0S +hIjyilZA3MP8yPD0CexQfIM6+HNo7k4X+ivB6QE/Hm7Kow6qsMc X-Developer-Key: i=christophe.leroy@csgroup.eu; a=ed25519; pk=HIzTzUj91asvincQGOFx6+ZF5AoUuP9GdOtQChs7Mm0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1665569424; 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=c5RKFHB9/R9buqoT9IzvvjAEUsOcdS2XlOduPr6Wv14=; b=aga6LeFpvW0Pdfb3ZMAuq62fzt9YCcMMtOcpwQSv3erlmTmKGf2YbRx6lZc0OcIWgpUi1z O1Q0R+RQRgAFwrgRxrYTfvQ0m0rGGYw1Kw7O+a7BW8C/Bz7DgOLXMkPM1zi5HRHl68OSXr MXrFi3WLY19xENN8qNT7dA5bi+UA2IM= ARC-Authentication-Results: i=1; imf26.hostedemail.com; dkim=none; spf=pass (imf26.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-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1665569424; a=rsa-sha256; cv=none; b=C90BiV2WDWb37kR/j8VLsltN+JRUxQMBE8ZOe4qqR82RemubAa7aLtSVFJVM5J3a2fkHeQ hZdsDQQ7Frmb9nURkGPTRDWrc4fRCfoYdbGcxT92l+XY6Natz1gG3sQ0bieo8bqijMVrkT mK7BNzqAMP/gRBcEBRW/Qc0BPT8s+uY= X-Rspam-User: X-Rspamd-Queue-Id: 00F58140031 X-Stat-Signature: bwnjmutpcnmyfsykiug4cgbngphna3qh Authentication-Results: imf26.hostedemail.com; dkim=none; spf=pass (imf26.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-Rspamd-Server: rspam10 X-HE-Tag: 1665569423-480304 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: From: Baoquan He 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 Signed-off-by: Christophe Leroy --- arch/arc/Kconfig | 1 + arch/arc/include/asm/io.h | 7 +++--- arch/arc/mm/ioremap.c | 46 +++------------------------------------ 3 files changed, 8 insertions(+), 46 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..53b0f1e4f276 100644 --- a/arch/arc/include/asm/io.h +++ b/arch/arc/include/asm/io.h @@ -21,8 +21,8 @@ #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); +#define ioremap ioremap +#define ioremap_prot ioremap_prot static inline void __iomem *ioport_map(unsigned long port, unsigned int nr) { return (void __iomem *)port; @@ -32,7 +32,8 @@ static inline void ioport_unmap(void __iomem *addr) { } -extern void iounmap(const void __iomem *addr); +bool iounmap_allowed(void *addr); +#define iounmap_allowed iounmap_allowed /* * io{read,write}{16,32}be() macros diff --git a/arch/arc/mm/ioremap.c b/arch/arc/mm/ioremap.c index 0ee75aca6e10..02b750abccee 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 @@ -54,52 +47,19 @@ EXPORT_SYMBOL(ioremap); void __iomem *ioremap_prot(phys_addr_t paddr, unsigned long size, unsigned long flags) { - 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; /* force uncached */ - prot = pgprot_noncached(prot); - - /* Mappings have to be page-aligned */ - off = paddr & ~PAGE_MASK; - paddr &= PAGE_MASK_PHYS; - size = PAGE_ALIGN(end + 1) - paddr; - - /* - * 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); + return generic_ioremap_prot(paddr, size, pgprot_noncached(prot)); } EXPORT_SYMBOL(ioremap_prot); - -void iounmap(const void __iomem *addr) +bool iounmap_allowed(void *addr) { /* weird double cast to handle phys_addr_t > 32 bits */ - if (arc_uncached_addr_space((phys_addr_t)(u32)addr)) - return; - - vfree((void *)(PAGE_MASK & (unsigned long __force)addr)); + return !arc_uncached_addr_space((phys_addr_t)(u32)addr); } -EXPORT_SYMBOL(iounmap);