Received: by 2002:a05:6a10:2785:0:0:0:0 with SMTP id ia5csp127995pxb; Thu, 14 Jan 2021 21:47:34 -0800 (PST) X-Google-Smtp-Source: ABdhPJxNjRZN00iSOCWnJ2cf1h2MBk6BP8+G9vdU0m4r87189RE+xJjubJpXX3ELFETPk7zdl5O0 X-Received: by 2002:a05:6402:78f:: with SMTP id d15mr448126edy.362.1610689654150; Thu, 14 Jan 2021 21:47:34 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1610689654; cv=none; d=google.com; s=arc-20160816; b=uQd+U9M+PBaBcBxI6Kv9usZEYCfkySqRGrtMLGBjsMTiD0sjjXufqQ38VYvv6bIhhX YPgahn6M7rufEAUaF3WP6vzckptMHyrIwONBMSxll7hL5KYaiJOIgsYG0QAzve8P+1zU dBnsRZ20GIbq+S9KbxL+mUPyHSsJ65/NUoFMZQgWIjd7wOHmBDIB3pmTw6Q5yNPKecA2 a6Q9mHnWa5Vpl83bGvrq4+eB/Wrb51cVgC3HzJLwUSV6aC7VQDRwZZUBaUP6fSDD45QJ vOBsci9fmHcI3ZHogQKIJMR56lOVZXE/8r/DJ7QrgCT9u7uT9s0DOZkdOAvJfERULQQs ww5A== 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=Zn/E5DSPd3qJg+DTv9IwC7Z6z2pECZsgPkasFqGe2mo=; b=WwzGN1w0zZaTCP+8LWWedhdUy2/CbGas24m+oE0sT5er9IbjmFIf370t+G0415Wp8S VmePjHgzqkREfIy5b1EZ7D53K1S41hoFKwRq/F/xVMy/FQ9+5eQ03HD/HWFQXdHy3fEe WmatRIXFTNgQlC7eU401G6n2KOyxY8WqkJ3TrWOPhGyyDhR8YkmRD6lR6mJpYuT6WrIA DOpYCFY6Lq/gYasxvmWyJJwn4D1sRU2yAKpLrhMnPCslyj9QbTbEcNYjjymzEX0mn74/ M9CYFflXbcc3RUNK1itijr4AHqVRmSmgXGzGIjlxiFsvswcaUacOTLeZOa0zhqK15rXE 6lTw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=SlbAB2R2; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id ch5si3199365ejb.407.2021.01.14.21.47.10; Thu, 14 Jan 2021 21:47:34 -0800 (PST) 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=@chromium.org header.s=google header.b=SlbAB2R2; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732726AbhAODxw (ORCPT + 99 others); Thu, 14 Jan 2021 22:53:52 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40554 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730909AbhAODxw (ORCPT ); Thu, 14 Jan 2021 22:53:52 -0500 Received: from mail-io1-xd2e.google.com (mail-io1-xd2e.google.com [IPv6:2607:f8b0:4864:20::d2e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 947E0C061575 for ; Thu, 14 Jan 2021 19:53:11 -0800 (PST) Received: by mail-io1-xd2e.google.com with SMTP id q2so14058823iow.13 for ; Thu, 14 Jan 2021 19:53:11 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=Zn/E5DSPd3qJg+DTv9IwC7Z6z2pECZsgPkasFqGe2mo=; b=SlbAB2R28TVOPw4dT3y4+YKxnBvZIXRjddrKEDVYjmW3vvG3MDP0dEXICbitCBjDsh shg/YaDMPSBJC8TmtKZMEExrMsM7sLlrF7dj4kE9P1DHob7nRhpZZQNoE756taUh2vVw OwHAOHom27x10XansCH8DvCa2BNXVtylJjjRk= 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=Zn/E5DSPd3qJg+DTv9IwC7Z6z2pECZsgPkasFqGe2mo=; b=RC/cf5m1m2d+i3wquUaghWWT4nohzTF9l+L0bX0bwTJeZDeq3bIOI7hmxrZZNwpCX+ w44d8vPmIUUB7LG1E7W4atyWbJ5jlJMAEEOIxMVOECO4UHaMpWUQsTjcEOkYPqo5Qgvg eMIz/rGi58p5ki4c2UTE9DX+I//tQaQwgbFN5kvW4ewdGw7oG/ak1esCpcIhVLn98KoN mABr0YOTYJhsZkF47iw/tmMzrbcIWSv/PY8ZAL7b1UGRHeMiC1CSKpDbpNojqb8pUtre 15X2F85C3hnTLvpEs3bm52DJaT0nXfJaFQ96bh66VJmiu0CQk9jSujEb0k9oU747YktB 46Bg== X-Gm-Message-State: AOAM5304YkLcv4QoXhfyl9rlQJsCRsPhB1bAMWFWjS5jO3YbiN/e41/E k5f2LHeqfyWxahbTPvxd9RH1k6PZeQ82XA== X-Received: by 2002:a92:b60a:: with SMTP id s10mr9304713ili.135.1610682790762; Thu, 14 Jan 2021 19:53:10 -0800 (PST) Received: from mail-io1-f42.google.com (mail-io1-f42.google.com. [209.85.166.42]) by smtp.gmail.com with ESMTPSA id p25sm3496257ioj.21.2021.01.14.19.53.10 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 14 Jan 2021 19:53:10 -0800 (PST) Received: by mail-io1-f42.google.com with SMTP id d81so570597iof.3 for ; Thu, 14 Jan 2021 19:53:10 -0800 (PST) X-Received: by 2002:a5d:9588:: with SMTP id a8mr2906589ioo.34.1610682391276; Thu, 14 Jan 2021 19:46:31 -0800 (PST) MIME-Version: 1.0 References: <20210106034124.30560-1-tientzu@chromium.org> <20210106034124.30560-7-tientzu@chromium.org> <95e6dd76-5e18-e445-c351-19fba18f36de@gmail.com> <5f276678-3ab2-ddc8-640c-6dbbe173463c@gmail.com> In-Reply-To: <5f276678-3ab2-ddc8-640c-6dbbe173463c@gmail.com> From: Claire Chang Date: Fri, 15 Jan 2021 11:46:20 +0800 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [RFC PATCH v3 6/6] of: Add plumbing for restricted DMA pool To: Florian Fainelli Cc: Rob Herring , mpe@ellerman.id.au, benh@kernel.crashing.org, paulus@samba.org, "list@263.net:IOMMU DRIVERS" , Joerg Roedel , will@kernel.org, Frank Rowand , Konrad Rzeszutek Wilk , boris.ostrovsky@oracle.com, jgross@suse.com, sstabellini@kernel.org, Christoph Hellwig , Marek Szyprowski , Robin Murphy , grant.likely@arm.com, xypron.glpk@gmx.de, Thierry Reding , mingo@kernel.org, bauerman@linux.ibm.com, peterz@infradead.org, Greg KH , Saravana Kannan , rafael.j.wysocki@intel.com, heikki.krogerus@linux.intel.com, Andy Shevchenko , rdunlap@infradead.org, dan.j.williams@intel.com, Bartosz Golaszewski , linux-devicetree , lkml , linuxppc-dev@lists.ozlabs.org, xen-devel@lists.xenproject.org, Tomasz Figa , Nicolas Boichat Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Jan 15, 2021 at 2:52 AM Florian Fainelli wrote: > > On 1/14/21 1:08 AM, Claire Chang wrote: > > On Wed, Jan 13, 2021 at 7:48 AM Florian Fainelli wrote: > >> > >> On 1/5/21 7:41 PM, Claire Chang wrote: > >>> If a device is not behind an IOMMU, we look up the device node and set > >>> up the restricted DMA when the restricted-dma-pool is presented. > >>> > >>> Signed-off-by: Claire Chang > >>> --- > >> > >> [snip] > >> > >>> +int of_dma_set_restricted_buffer(struct device *dev) > >>> +{ > >>> + struct device_node *node; > >>> + int count, i; > >>> + > >>> + if (!dev->of_node) > >>> + return 0; > >>> + > >>> + count = of_property_count_elems_of_size(dev->of_node, "memory-region", > >>> + sizeof(phandle)); > >> > >> You could have an early check for count < 0, along with an error > >> message, if that is deemed useful. > >> > >>> + for (i = 0; i < count; i++) { > >>> + node = of_parse_phandle(dev->of_node, "memory-region", i); > >>> + if (of_device_is_compatible(node, "restricted-dma-pool")) > >> > >> And you may want to add here an of_device_is_available(node). A platform > >> that provides the Device Tree firmware and try to support multiple > >> different SoCs may try to determine if an IOMMU is present, and if it > >> is, it could be marking the restriced-dma-pool region with a 'status = > >> "disabled"' property, or any variant of that scheme. > > > > This function is called only when there is no IOMMU present (check in > > drivers/of/device.c). I can still add of_device_is_available(node) > > here if you think it's helpful. > > I believe it is, since boot loader can have a shared Device Tree blob > skeleton and do various adaptations based on the chip (that's what we > do) and adding a status property is much simpler than insertion new > nodes are run time. > > > > >> > >>> + return of_reserved_mem_device_init_by_idx( > >>> + dev, dev->of_node, i); > >> > >> This does not seem to be supporting more than one memory region, did not > >> you want something like instead: > >> > >> ret = of_reserved_mem_device_init_by_idx(...); > >> if (ret) > >> return ret; > >> > > > > Yes. This implement only supports one restriced-dma-pool memory region > > with the assumption that there is only one memory region with the > > compatible string, restricted-dma-pool, in the dts. IIUC, it's similar > > to shared-dma-pool. > > Then if here is such a known limitation it should be both documented and > enforced here, you shouldn ot be iterating over all of the phandles that > you find, stop at the first one and issue a warning if count > 1? What I have in mind is there might be multiple memory regions, but only one is for restriced-dma-pool. Say, if you want a separated region for coherent DMA and only do streaming DMA in this restriced-dma-pool region, you can add another reserved-memory node with shared-dma-pool in dts and the current implementation will try to allocate the memory via dma_alloc_from_dev_coherent() first (see dma_alloc_attrs() in /kernel/dma/mapping.c). Or if you have vendor specific memory region, you can still set up restriced-dma-pool by adding another reserved-memory node in dts. Dose this make sense to you? I'll document this for sure. > -- > Florian