Received: by 2002:a05:6a10:2785:0:0:0:0 with SMTP id ia5csp116529pxb; Thu, 14 Jan 2021 01:10:41 -0800 (PST) X-Google-Smtp-Source: ABdhPJzmOpAz7leHASVx3pg9FUEi5sjudg+r+P5CKo0iDBt0FoM9BSylBCTZnICevspbZniFgpyg X-Received: by 2002:a17:907:546:: with SMTP id wk6mr4449673ejb.238.1610615441595; Thu, 14 Jan 2021 01:10:41 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1610615441; cv=none; d=google.com; s=arc-20160816; b=SjuRqHuqr4bL4mj2z3jM83BF64I9nvn7umr7W08MH6+MJgVPgKoUqTwfy3iaLl70It DoOrmpjNdv1q9RYuIFJ+L2qCohBb9TZN0cZl4PnvyeGFHT+uTzHMJzBHTn69DcSddcly f/96by0WfLQr4IeG+9o869NUnJu5s1lRGfWJ+h7S+YoWB1pUxn2roKA2VElUMI8g4RAN iKHwYbotxKnenB5mcBZxaxvmiPJHK3KVvwXtbn9Il5NYtDS5AcjMVxBvqFyIqVOvQawa YTQPyxpfQ1LM6lmnScpzHEVoSe8IzXZGuxXeSUGpxPeGIB9mkyUZ8hpERJ64/AbYIwkA Dc6w== 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=XoX/j54i0jG8qEsxZKby76Lqj61QzippjPHzsTsj+5Y=; b=U6ZQYuSBObYwqm5348cByEdyzjw59YeBWyYEyNcjouRduoR2iXdnjNG4o1GhNo9cOF 6jMtZOjqfzkvX8X8bVrGIzCpWOk66r6OQPMPR3xVSQ32nS4Im60GH4Znqs8p3vJj9M4J 3bUnxTGWchJawzTu2KTjvng0qyiwiojMts+JtmLZ9URZyMskU2eRdtLtZ7ROkcmw7ag7 92vnpfaYmFYCuhwJxJyPzkxgJUNnl3Ywm2iZRGuIrctL1roC3hRQOq+pMsxtvmxC7B6b ZHCV20DUHYihj8DfoBPLFID2tM6VXX6L9D6rzrj9Kq6Lmdp4XqvTiVIMj6khQu45s2BA NEWg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=nY1GnsLl; 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 f15si2300752ejh.394.2021.01.14.01.10.18; Thu, 14 Jan 2021 01:10:41 -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=nY1GnsLl; 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 S1727668AbhANJJV (ORCPT + 99 others); Thu, 14 Jan 2021 04:09:21 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52368 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727258AbhANJJT (ORCPT ); Thu, 14 Jan 2021 04:09:19 -0500 Received: from mail-io1-xd35.google.com (mail-io1-xd35.google.com [IPv6:2607:f8b0:4864:20::d35]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 01800C061786 for ; Thu, 14 Jan 2021 01:08:39 -0800 (PST) Received: by mail-io1-xd35.google.com with SMTP id b19so7242629ioa.9 for ; Thu, 14 Jan 2021 01:08:38 -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=XoX/j54i0jG8qEsxZKby76Lqj61QzippjPHzsTsj+5Y=; b=nY1GnsLlZi0Sxxm+zSGIGaqKpSxx6JueftrzPps7oTAcG91/bM9YfHLXW3YxSFcLzK y6cH1olpZ/FXA0Mp0cE9+mqoheJMPU0KT0091/GVtf67wUxU6MGGIWncH2X6oPgNN5KO QvrKMhyV8u8UB5lLj67P7d++Su0Uyq/z5gAtg= 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=XoX/j54i0jG8qEsxZKby76Lqj61QzippjPHzsTsj+5Y=; b=D8qocMZzSaFnU5+EbkzDa8MBOyHlbI1c6Zz/WWMlicEKFYZu8sKsCWBVgJqjIBEqTJ Up82mDsNg8h/uBB2gXeoU0+Y8y0ZzyM8wER9k/g+3FirraalYnfbDX4Icu9foXbnfC5F dqdJTxQ+9rrDE0mASNXqXYvjTE79DpIi4NwRBmTZ+Vw5AzruzBfvTpE27xbeygWDch81 zurof5Y6T++vXnuvyu7JFh/0MtW/mVtOyXkEKKcfpM1UrosJD8GmmkbZ5F2IxdrsyTJP bNsHZbRXjsF3BIm9xPRUAbgyEiHvyDM5PbEng8chybstNfWbI8xmh0ndSw9Mn4n1Bs75 S5zA== X-Gm-Message-State: AOAM531S7H7G10vGcv2MZb7qO3NVP7gpb2b+QXTNcoI3OZeF961Il3Fh qLH9Sxdhl5umRaqGuQJigBlL6vM/hLVXpA== X-Received: by 2002:a92:9153:: with SMTP id t80mr5800284ild.216.1610615318053; Thu, 14 Jan 2021 01:08:38 -0800 (PST) Received: from mail-io1-f41.google.com (mail-io1-f41.google.com. [209.85.166.41]) by smtp.gmail.com with ESMTPSA id s4sm2478973ioc.33.2021.01.14.01.08.36 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 14 Jan 2021 01:08:37 -0800 (PST) Received: by mail-io1-f41.google.com with SMTP id z5so9704061iob.11 for ; Thu, 14 Jan 2021 01:08:36 -0800 (PST) X-Received: by 2002:a92:c206:: with SMTP id j6mr5789564ilo.189.1610615314989; Thu, 14 Jan 2021 01:08:34 -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> In-Reply-To: <95e6dd76-5e18-e445-c351-19fba18f36de@gmail.com> From: Claire Chang Date: Thu, 14 Jan 2021 17:08:24 +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, "list@263.net:IOMMU DRIVERS , Joerg Roedel ," , 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 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. > > > + 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. > > + } > > + > > + return 0; > > +} > > diff --git a/drivers/of/device.c b/drivers/of/device.c > > index aedfaaafd3e7..e2c7409956ab 100644 > > --- a/drivers/of/device.c > > +++ b/drivers/of/device.c > > @@ -182,6 +182,10 @@ int of_dma_configure_id(struct device *dev, struct device_node *np, > > arch_setup_dma_ops(dev, dma_start, size, iommu, coherent); > > > > dev->dma_range_map = map; > > + > > + if (!iommu) > > + return of_dma_set_restricted_buffer(dev); > > + > > return 0; > > } > > EXPORT_SYMBOL_GPL(of_dma_configure_id); > > diff --git a/drivers/of/of_private.h b/drivers/of/of_private.h > > index d9e6a324de0a..28a2dfa197ba 100644 > > --- a/drivers/of/of_private.h > > +++ b/drivers/of/of_private.h > > @@ -161,12 +161,17 @@ struct bus_dma_region; > > #if defined(CONFIG_OF_ADDRESS) && defined(CONFIG_HAS_DMA) > > int of_dma_get_range(struct device_node *np, > > const struct bus_dma_region **map); > > +int of_dma_set_restricted_buffer(struct device *dev); > > #else > > static inline int of_dma_get_range(struct device_node *np, > > const struct bus_dma_region **map) > > { > > return -ENODEV; > > } > > +static inline int of_dma_get_restricted_buffer(struct device *dev) > > +{ > > + return -ENODEV; > > +} > > #endif > > > > #endif /* _LINUX_OF_PRIVATE_H */ > > > > > -- > Florian