Received: by 2002:a05:6358:45e:b0:b5:b6eb:e1f9 with SMTP id 30csp2819500rwe; Mon, 29 Aug 2022 00:10:12 -0700 (PDT) X-Google-Smtp-Source: AA6agR7D5LEWw8l1TPYhl0RxkAABGLjlocJm3Z8BRr9ZHWIEnO6Nq5q9Dw4XRRggo1YpPea1g2Y6 X-Received: by 2002:a17:907:97d3:b0:73d:8e80:b081 with SMTP id js19-20020a17090797d300b0073d8e80b081mr12595568ejc.590.1661757012569; Mon, 29 Aug 2022 00:10:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1661757012; cv=none; d=google.com; s=arc-20160816; b=z2eeS7wVsoCIUaXy6QbfZgjDoucZ8tTuEc9YAuF3epgm/9f1fkx7yr6ZMQtGltq+qc ZyV/rkAdWNy3Jd/BTT0J5OJg+xCrByF/72FPfIkg5n+1ihCU6+WjmMkwkyL3D31FhcdF uf7eVok3lFNHajFd2TsPNIUtFBGSwl09YW+8D7dTcP1HT8zRu8NpCdvmYC2MOHs2z9vY byLOVFtNTYJ4EPkyAhPRam6OMm07m1qw+cnBQ2CqEe7zPBfIW3+5P8yGRy1eBiQjRS6e pH2crkmrER5dQqygbhRNsthj20X17TFJrAEpwOhJWkK4sh4sfXfLRYFgu4BqOwILoulk eySw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=55VuaBCh3zKQULMorjkhEtdo9YxgKyyc9DWx8OVsrmM=; b=lkKdu60WraNJ4vV5sTzjTuu/7a1o9Rhk4jL+sb+y+6+Z+g/VbkVBkwwb10mgqnXX3Z GY9Hz9bOaAY3+UVLRGz21VZzmztdqFOuB0wHwns0IuSn/sg+IhSfbYUWn3gx5kVVWspf Om5NArWrFyDmelfWe9w90c7TXm5bTxNQExW7H63PYg5vmc5jZ5X92q7HC2YORcUhG5si xfqwN5+NZhvShb69/3rF7+TXwDaTYHnMbjt1wLVLYlv5qVbqd7IgDljw9IfrwDpzAVmG FQ+RMSbb3AQDlrdgIsrdcJ8Dc5cTWGbi1F3EEc7O/x728tQMzp1JabVIGRQsGl+AoYRT AoPg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b="Q9bG4C/l"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id gt17-20020a1709072d9100b0073d7ad9607bsi6695607ejc.551.2022.08.29.00.09.47; Mon, 29 Aug 2022 00:10:12 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b="Q9bG4C/l"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229663AbiH2Gcg (ORCPT + 99 others); Mon, 29 Aug 2022 02:32:36 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42488 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229446AbiH2Gce (ORCPT ); Mon, 29 Aug 2022 02:32:34 -0400 Received: from mail-wm1-x331.google.com (mail-wm1-x331.google.com [IPv6:2a00:1450:4864:20::331]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D9BF52DAB4 for ; Sun, 28 Aug 2022 23:32:32 -0700 (PDT) Received: by mail-wm1-x331.google.com with SMTP id d5so3754003wms.5 for ; Sun, 28 Aug 2022 23:32:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc; bh=55VuaBCh3zKQULMorjkhEtdo9YxgKyyc9DWx8OVsrmM=; b=Q9bG4C/lzqI/HkM4WnO4cpc4zH/UG8bBgrrBbgVdTS7NTL6FoUXymtUtiZUfLhdqlI vNzIoae9pjeuErhoyALL285mDB05G2HivjfavrPWWasdGfZT84ljgH4pYvpcNbsxUcLV Scd56sSMOoZmsJWX4b8B2QQ7QpRU4O5mCvX1JePJi5XRz9byLtTy+mhocyVmrumMRart snYeZv6DRt6CISmR49x82ARa3CCHmCzoPe8R7zutuqybLgFuiDijeQdE+D5jQ0/GP8eh vKOVYCPksydgN4/UL7Wx3rf/xkFtB8GAR3IB1EEAkom5tXbVaajM8S2Cmm7o52/u/r2q SoWA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc; bh=55VuaBCh3zKQULMorjkhEtdo9YxgKyyc9DWx8OVsrmM=; b=fkFLx3g16MY87oD0mYwC2utf1h/qruIh+9PvqqLxUNmK2B3pn8TXNV49WyrEBO1HXK GraKdV7/PBrMS2sfGYpHQTD5kACBIBs7LLElEftoOfkJcNlLc/OwJzHfz6p87Pf/NfG4 76MWidPW8EB6wOywm5MrGY46XHB9C0L9EfYWlRVUhDoFoE0bzPB1kRlUSgn85xWewuXu Biq5tk8aLnv5yM4hiQ525UjlxXwr2qijJDp2o317O2/zxHZG43ctmSVFVaXaRh67Btd6 IlYNpo9jWCjA6z0+SSsMszODBU4rh1PU36aUBv4/tL3+jwMfMSLBlO+FUDjGN4iYZdvQ +UFA== X-Gm-Message-State: ACgBeo0VaHOsZIqlZoW0lm8GCngeDLvHHeH9v319Vsk6DC+vdpWNge7S GvktNsgmn+iQGa15jxq66pnGYSkRZe4= X-Received: by 2002:a05:600c:348f:b0:3a5:e28c:a1d5 with SMTP id a15-20020a05600c348f00b003a5e28ca1d5mr5725442wmq.33.1661754751411; Sun, 28 Aug 2022 23:32:31 -0700 (PDT) Received: from localhost ([2a03:b0c0:1:d0::dee:c001]) by smtp.gmail.com with ESMTPSA id b8-20020adff908000000b00223a50b1be8sm6141149wrr.50.2022.08.28.23.32.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 28 Aug 2022 23:32:30 -0700 (PDT) Date: Mon, 29 Aug 2022 06:32:30 +0000 From: Stafford Horne To: Baoquan He Cc: linux-kernel@vger.kernel.org, linux-mm@kvack.org, akpm@linux-foundation.org, hch@infradead.org, agordeev@linux.ibm.com, wangkefeng.wang@huawei.com, linux-arm-kernel@lists.infradead.org, Jonas Bonn , Stefan Kristiansson , openrisc@lists.librecores.org Subject: Re: [PATCH v2 07/11] openrisc: mm: Convert to GENERIC_IOREMAP Message-ID: References: <20220820003125.353570-1-bhe@redhat.com> <20220820003125.353570-8-bhe@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20220820003125.353570-8-bhe@redhat.com> X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Sat, Aug 20, 2022 at 08:31:21AM +0800, Baoquan He wrote: > Add hooks arch_ioremap() and arch_iounmap() for operisc's special > operation when ioremap() and iounmap. > > Signed-off-by: Baoquan He > Cc: Jonas Bonn > Cc: Stefan Kristiansson > Cc: Stafford Horne > Cc: openrisc@lists.librecores.org > --- > arch/openrisc/Kconfig | 1 + > arch/openrisc/include/asm/io.h | 16 ++++++++--- > arch/openrisc/mm/ioremap.c | 51 +++++++++++----------------------- > 3 files changed, 29 insertions(+), 39 deletions(-) > > diff --git a/arch/openrisc/Kconfig b/arch/openrisc/Kconfig > index c7f282f60f64..fd9bb76a610b 100644 > --- a/arch/openrisc/Kconfig > +++ b/arch/openrisc/Kconfig > @@ -21,6 +21,7 @@ config OPENRISC > select GENERIC_IRQ_PROBE > select GENERIC_IRQ_SHOW > select GENERIC_PCI_IOMAP > + select GENERIC_IOREMAP > select GENERIC_CPU_DEVICES > select HAVE_PCI > select HAVE_UID16 > diff --git a/arch/openrisc/include/asm/io.h b/arch/openrisc/include/asm/io.h > index ee6043a03173..9db67938bfc4 100644 > --- a/arch/openrisc/include/asm/io.h > +++ b/arch/openrisc/include/asm/io.h > @@ -15,6 +15,8 @@ > #define __ASM_OPENRISC_IO_H > > #include > +#include > +#include This seems to cause a compilation issue when building virt_defconig: CC kernel/irq/generic-chip.o In file included from ./include/asm-generic/pgtable-nopud.h:7, from ./include/asm-generic/pgtable-nopmd.h:7, from ./arch/openrisc/include/asm/pgtable.h:24, from ./arch/openrisc/include/asm/io.h:18, from ./include/linux/io.h:13, from kernel/irq/generic-chip.c:7: ./include/asm-generic/pgtable-nop4d.h:9:18: error: unknown type name 'pgd_t' 9 | typedef struct { pgd_t pgd; } p4d_t; | ^~~~~ It works if we swap the order arround: +#include +#include Otherwise we need to add an asm/page.h include to asm/pgtable.h (which is more correct) but means you would touch more files. > /* > * PCI: We do not use IO ports in OpenRISC > @@ -27,11 +29,17 @@ > #define PIO_OFFSET 0 > #define PIO_MASK 0 > > -#define ioremap ioremap > -void __iomem *ioremap(phys_addr_t offset, unsigned long size); > +/* > + * I/O memory mapping functions. > + */ > +void __iomem * > +arch_ioremap(phys_addr_t *paddr, size_t size, unsigned long *prot_val); > +#define arch_ioremap arch_ioremap > + > +int arch_iounmap(void __iomem *addr); > +#define arch_iounmap arch_iounmap > > -#define iounmap iounmap > -extern void iounmap(volatile void __iomem *addr); > +#define _PAGE_IOREMAP (pgprot_val(PAGE_KERNEL) | _PAGE_CI) > > #include > > diff --git a/arch/openrisc/mm/ioremap.c b/arch/openrisc/mm/ioremap.c > index 8ec0dafecf25..bc41660e1fb0 100644 > --- a/arch/openrisc/mm/ioremap.c > +++ b/arch/openrisc/mm/ioremap.c > @@ -24,26 +24,18 @@ extern int mem_init_done; > > static unsigned int fixmaps_used __initdata; > > -/* > - * Remap an arbitrary physical address space into the kernel virtual > - * address space. Needed when the kernel wants to access high addresses > - * directly. > - * > - * NOTE! We need to allow non-page-aligned mappings too: we will obviously > - * have to convert them into an offset in a page-aligned mapping, but the > - * caller shouldn't need to know that small detail. > - */ > -void __iomem *__ref ioremap(phys_addr_t addr, unsigned long size) > +void __iomem * > +arch_ioremap(phys_addr_t *paddr, size_t size, unsigned long *prot_val) > { > phys_addr_t p; > unsigned long v; > - unsigned long offset, last_addr; > - struct vm_struct *area = NULL; > + unsigned long offset, last_addr, addr = *paddr; > + int ret = -EINVAL; > > /* Don't allow wraparound or zero size */ > last_addr = addr + size - 1; > if (!size || last_addr < addr) > - return NULL; > + return IOMEM_ERR_PTR(ret); > > /* > * Mappings have to be page-aligned > @@ -52,32 +44,24 @@ void __iomem *__ref ioremap(phys_addr_t addr, unsigned long size) > p = addr & PAGE_MASK; > size = PAGE_ALIGN(last_addr + 1) - p; > > - if (likely(mem_init_done)) { > - area = get_vm_area(size, VM_IOREMAP); > - if (!area) > - return NULL; > - v = (unsigned long)area->addr; > - } else { > + if (unlikely(!mem_init_done)) { > if ((fixmaps_used + (size >> PAGE_SHIFT)) > FIX_N_IOREMAPS) > - return NULL; > + return IOMEM_ERR_PTR(ret); > v = fix_to_virt(FIX_IOREMAP_BEGIN + fixmaps_used); > fixmaps_used += (size >> PAGE_SHIFT); > - } > > - if (ioremap_page_range(v, v + size, p, > - __pgprot(pgprot_val(PAGE_KERNEL) | _PAGE_CI))) { > - if (likely(mem_init_done)) > - vfree(area->addr); > - else > + if (ioremap_page_range(v, v + size, p, __pgprot(*prot_val))) { > fixmaps_used -= (size >> PAGE_SHIFT); > - return NULL; > + return IOMEM_ERR_PTR(ret); > + } > + > + return (void __iomem *)(offset + (char *)v); > } > > - return (void __iomem *)(offset + (char *)v); > + return NULL; > } > -EXPORT_SYMBOL(ioremap); > > -void iounmap(volatile void __iomem *addr) > +int arch_iounmap(void __iomem *addr) > { > /* If the page is from the fixmap pool then we just clear out > * the fixmap mapping. > @@ -97,13 +81,10 @@ void iounmap(volatile void __iomem *addr) > * ii) invalid accesses to the freed areas aren't made > */ > flush_tlb_all(); > - return; > + return -EINVAL; > } > - > - return vfree((void *)(PAGE_MASK & (unsigned long)addr)); > + return 0; > } > -EXPORT_SYMBOL(iounmap); > - > /** > * OK, this one's a bit tricky... ioremap can get called before memory is > * initialized (early serial console does this) and will want to alloc a page > -- > 2.34.1 Other than that compiler issue, I fixed it and test booted this and it works well. Acked-by: Stafford Horne