Received: by 2002:a05:6a10:1287:0:0:0:0 with SMTP id d7csp5850473pxv; Wed, 28 Jul 2021 23:21:12 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzQzkRxKbjAY1+aA5c97tZE5enVh53lexm/cd5q50x8HAej38dQaLxKDpfP5baDuI0FmGoV X-Received: by 2002:aa7:c588:: with SMTP id g8mr4187860edq.33.1627539671810; Wed, 28 Jul 2021 23:21:11 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1627539671; cv=none; d=google.com; s=arc-20160816; b=NGIQesGHP4PUou1/XVva5XndW1eYGRtbkUBkwqShWjB3XfpDlpcQmJhXslHzFdAXLF NKAJWZL8398OFHGW8O7M0NI+jZHW1Q6IiJwxmePf9Itcowa7Bx419AgCTeo7Mqe4bGYX 3GynZvBM+fpcBtPB1rDmQILRi9B1JqPhK4AGRrQT9H1ILBjiS4LH7Tq/qTDkiZO6ld3/ eA51qXh+0NUdqeqg91aTf612H/dMePmg09oCTXQE9GEmgHByRXOfqJxhQm7B/UtCLuBF FjU8ZlFtUhfQK2WFwfldY6cuYLd75vwgyhMOdLcrZ3yp2aF/E12LHNeaB9tDV26rO9kq Bv6w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=2As2r29cAjix27xM0IHixqdDs9tV7d/JgCTxvY6wJ7E=; b=AtYgFog0PATkq705FQo0KBQyOVUFtNVqRC//F9SQa5kpcC9bcT0ZreGZtIKHDdaUrf QUkBDLaXz/feyHZ0aV7Lm9WDCTiZ7GEUbIlzlS5bAz/mQBL1rIo6xcZejqWnAaW9Gj6u vPtWgoqOPQvzZBarOWL+cdgWdfgPQmqbaanPRcO4UFqQWQ6+VaEsvE3FNJ8Uz6dSpUJv JWQuETWvobt+b7M6WKJKAfYCRMlJYx384v/3egHkIS5fmU2atknJvjJ6DPMgRTq9BiBC UfsR1mjB1cIq3EqDsv+2t3pjuzVoSmO82NHnH3kiPghgsWXcfVwmYqFCZ+wz9X8rO4Gb /lnw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@atishpatra.org header.s=google header.b=KQsHUXDo; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id l3si2220677ejo.634.2021.07.28.23.20.48; Wed, 28 Jul 2021 23:21:11 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@atishpatra.org header.s=google header.b=KQsHUXDo; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234125AbhG2GT1 (ORCPT + 99 others); Thu, 29 Jul 2021 02:19:27 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57062 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234019AbhG2GT0 (ORCPT ); Thu, 29 Jul 2021 02:19:26 -0400 Received: from mail-yb1-xb32.google.com (mail-yb1-xb32.google.com [IPv6:2607:f8b0:4864:20::b32]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 521ADC061757 for ; Wed, 28 Jul 2021 23:19:24 -0700 (PDT) Received: by mail-yb1-xb32.google.com with SMTP id w17so8328184ybl.11 for ; Wed, 28 Jul 2021 23:19:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=atishpatra.org; s=google; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=2As2r29cAjix27xM0IHixqdDs9tV7d/JgCTxvY6wJ7E=; b=KQsHUXDo2JrnQKFkkEgufBVnAN8WtqG1UWGG9LepXJZoQvRxaunb1wCc2QVyHgzWId LbNxXs0YbMox683wCNfz4NqD+U9iy1W2EONV8vNczyxbM+UEoN5kPBxLTZHXJ6ydcUUc 94ngrdaDgUTsq80cFrn3O2RbjR5KbLhruPTDE= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=2As2r29cAjix27xM0IHixqdDs9tV7d/JgCTxvY6wJ7E=; b=jH+aerdtoJwmYDoqbDhVCU83eynZRqHNmNO4pMZAWrfjPOi/P7HeUudcvomJsp/7N+ NsX7mr9MjLzagjI/RNli3OsBObVaHqMwcK0kANC540JR4epZDViBTUJDe5noJcUqtExK 8DseZZ/mVdAxQb2Ao8t7e8CMIY9Ki/Dgs9NH2ODjMmSbGca8k84k8dDDn7wMJ4F8k93D GQhaXk3vOWUTRaA2ltNV42pnn23Lhhxqyr4LQ1L7QL5fjT9AJQFCFMLz6yV6NFvqlcOr ep2I8I5CyUamYHOKsV5tw7pnLcGu7R2VqHutUR312HoJ26tnF7lv4mAAdA1ySI7LDNdH o3gg== X-Gm-Message-State: AOAM533UDnVJCxskh+QMKRag3djvi/aLfbt6klm3QsQGtlyCLCWKLCcy 7Q+fK7FxMHasP8/cH6iXpGUbrgIipXJoZ6UZnr/Q X-Received: by 2002:a05:6902:1142:: with SMTP id p2mr4291303ybu.147.1627539563639; Wed, 28 Jul 2021 23:19:23 -0700 (PDT) MIME-Version: 1.0 References: <20210723214031.3251801-1-atish.patra@wdc.com> In-Reply-To: From: Atish Patra Date: Wed, 28 Jul 2021 23:19:12 -0700 Message-ID: Subject: Re: [RFC 0/5] Support non-coherent DMA on RISC-V using a global pool To: Palmer Dabbelt Cc: Atish Patra , "linux-kernel@vger.kernel.org List" , Albert Ou , Christoph Hellwig , devicetree , Dmitry Vyukov , Frank Rowand , Guo Ren , iommu@lists.linux-foundation.org, linux-riscv , Marek Szyprowski , Paul Walmsley , Rob Herring , Robin Murphy , Tobias Klauser Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Jul 28, 2021 at 9:30 PM Palmer Dabbelt wrote: > > On Fri, 23 Jul 2021 14:40:26 PDT (-0700), Atish Patra wrote: > > RISC-V privilege specification doesn't define an IOMMU or any method modify > > PMA attributes or PTE entries to allow non-coherent mappings yet. In > > the beginning, this approach was adopted assuming that most of the RISC-V > > platforms would support full cache-coherent IO. Here is excerpt from the > > priv spec section 3.6.5 > > > > "In RISC-V platforms, the use of hardware-incoherent regions is discouraged > > due to software complexity, performance, and energy impacts." > > > > While some of the RISC-V platforms adhere to the above suggestion, not all > > platforms can afford to build to fully cache-coherent I/O devices. To > > address DMA for non-coherent I/O devices, we need to mark a region of memory > > as non-cacheable. Some of the platforms rely on a fixed region of uncached > > memory that is remapped to the system memory while some other modify > > the PTE entries to achieve that. > > > > The patch3 solves the issue for the fist use case by using a global > > pool of memory that is reserved for DMA. The device access the reserved area > > of the region while corresponding CPU address will be from uncached region > > As the uncached region is remapped to the beginning of the system ram, both > > CPU and device get the same view. > > > > To facilitate streaming DMA APIs, patch 1 introduces a set of generic > > cache operations. Any platform can use the generic ops to provide platform > > specific cache management operations. Once the standard RISC-V CMO extension > > is available, it will also use these generic ops. > > > > To address the second use case, Page Based Memory Attribute (PBMT) extension > > is proposed. Once the extension is in good shape, we can leverage that > > using CONFIG_DIRECT_REMAP. Currently, it is selected via a compile time config > > option. We will probably need another arch specific hooks to know if the > > platform supports direct remap at runtime. For RISC-V, it will check the > > presence of PBMT extension while other arch function will simply return true > > IIUC this is another extension that's not yet frozen or implemented in > hardware? Is this one compatible with what's in the c906, or is it > doing things its own way? Hi Palmer, This series doesn't implement the PBMT extension which is still in discussion. It simply reuse the existing non-coherent dma mapping support in upstream kernel and enable it for RISC-V. The current version uses a non-coherent global pool. I will update it to use arch_set_uncached as per Christoph's suggestion. It solves the non-coherent DMA problem for beagleV and not c906. I briefly mentioned the PBMT extension just to provide an idea how the RISC-V Linux kernel can support both unached window and PBMT extension. PBMT extension is planned to be frozen by the end of this year and none of the hardware has implemented it. The implementation in c906 is a non-standard one and will not be supported by the default PBMT extension implementation. > > > if DIRECT_REMAP is enabled. This is required as arious different config > > (DIRECT_REMAP, GLOBAL_POOL) will be enabled in the defconfig so that a > > unified kernel image can boot on all RISC-V platforms. > > > > This patch series depends on Christoph's global pool support series[1]. > > Tested on Qemu, HiFive unleashed and beagleV. This series is also available > > at [2]. > > This series also solves the non-coherent DMA support on beagleV but requires > > additional beagleV specific patches[3] which will be upstreamed soon. > > > > > > [1] https://lists.linuxfoundation.org/pipermail/iommu/2021-July/057266.html > > [2] https://github.com/atishp04/linux/tree/riscv_nc_global_pool > > [3] https://github.com/atishp04/linux/tree/wip_beaglev_dma_nc_global > > > > Atish Patra (5): > > RISC-V: Implement arch_sync_dma* functions > > of: Move of_dma_get_range to of_address.h > > dma-mapping: Enable global non-coherent pool support for RISC-V > > dma-direct: Allocate dma pages directly if global pool allocation > > fails > > RISC-V: Support a new config option for non-coherent DMA > > > > arch/riscv/Kconfig | 8 +++ > > arch/riscv/include/asm/dma-noncoherent.h | 19 +++++++ > > arch/riscv/mm/Makefile | 1 + > > arch/riscv/mm/dma-noncoherent.c | 66 ++++++++++++++++++++++++ > > drivers/of/of_private.h | 10 ---- > > include/linux/of_address.h | 12 +++++ > > kernel/dma/coherent.c | 49 +++++++++++++++--- > > kernel/dma/direct.c | 7 ++- > > 8 files changed, 152 insertions(+), 20 deletions(-) > > create mode 100644 arch/riscv/include/asm/dma-noncoherent.h > > create mode 100644 arch/riscv/mm/dma-noncoherent.c > > Can you guys please make up your minds about how this is going to be > supported at the ISA level? I get a different answer every day here: > sometimes it's that these systems are not compliant, sometimes that > Linux is the compliance suite, sometimes that we're doing an ISA > extension, and sometimes that we're doing the SBI stuff. > I am not sure whom you have talked to. I would be happy to set up a meeting so that everybody is on the same page if you are getting different answers every time. > I don't really care all that much about what the decision is, but it's > impossible to move forward without some semblance of a plan. > > _______________________________________________ > linux-riscv mailing list > linux-riscv@lists.infradead.org > http://lists.infradead.org/mailman/listinfo/linux-riscv -- Regards, Atish