From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.8 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, URIBL_BLOCKED autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id D85B7C433B4 for ; Fri, 23 Apr 2021 02:53:35 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id B69F261452 for ; Fri, 23 Apr 2021 02:53:35 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231727AbhDWCyA (ORCPT ); Thu, 22 Apr 2021 22:54:00 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59052 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229574AbhDWCx7 (ORCPT ); Thu, 22 Apr 2021 22:53:59 -0400 Received: from mail-pg1-x535.google.com (mail-pg1-x535.google.com [IPv6:2607:f8b0:4864:20::535]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4A726C061574 for ; Thu, 22 Apr 2021 19:53:22 -0700 (PDT) Received: by mail-pg1-x535.google.com with SMTP id s22so13134762pgk.6 for ; Thu, 22 Apr 2021 19:53:22 -0700 (PDT) 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=40nhsz+kltJTf7tq6pLLkes92lT1dy5Rll207DlKzWM=; b=HdsQJQRkixDre+dpQSVR58nl8K7T4MbrI4XmlnSivkYb875qGKmhwngqhS/XX43exh bg5Ne9Oub0puKLH8FRaSSn/FCuQxwpgf1ynisAFuTF4Wvjhe+t5iF+WotV6g96hB8Oro fWaQA0hAXWZxawu4WTORJsnwcVbFEg+0cCZO8= 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=40nhsz+kltJTf7tq6pLLkes92lT1dy5Rll207DlKzWM=; b=hiELbji2vn9hNPBGdLjtQwA0J3R7tY2t5e/VP0pVk1jZwgizNb/lWTTl/SuMpa48W1 RWk4RlcPpgcjh//atqa9zTWux0oPiddsv5bgpzN2YjBENi7cGGf95A5ozt0k/w+TSkFz nTpwk8yL/izU8ZP60TkIgjosOa6Q7PTUsJjj4ZAd8JvVECcVfpVMKM/g5liMPwGBugQb dG+lKj9N7XwvjzH8KJ4EtXMbTyqkXaBbAtPeFYL1zUlBRQ7UUBVWyOdJGEv0i3GGazNu gTkM2vtPF9/rFh/6UY+weaUDJnbwfuu2iLkoc5UaR3C0Hhm++F/7KQDqqCnlfR0ayqNJ QPHA== X-Gm-Message-State: AOAM530Y9l4uvhDSicqsJYnyI9j9slTn6DThPVhBY7rLg3DSunUq7+3K Ee6eZbarxmXrQbR+EeNvyZX3F32qIMFS/Q== X-Google-Smtp-Source: ABdhPJzGrbrHRpf0k6Hl3pIvgyrjYnnZ7cBXhfEdj5Sht5N2GEgTVGZPytOhrVmHb/c69A2lXUvNaQ== X-Received: by 2002:a62:1409:0:b029:25a:4158:1c9 with SMTP id 9-20020a6214090000b029025a415801c9mr1735217pfu.61.1619146401020; Thu, 22 Apr 2021 19:53:21 -0700 (PDT) Received: from mail-pg1-f180.google.com (mail-pg1-f180.google.com. [209.85.215.180]) by smtp.gmail.com with ESMTPSA id c21sm3211106pfo.91.2021.04.22.19.53.20 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 22 Apr 2021 19:53:20 -0700 (PDT) Received: by mail-pg1-f180.google.com with SMTP id m12so13515433pgr.9 for ; Thu, 22 Apr 2021 19:53:20 -0700 (PDT) X-Received: by 2002:a6b:c913:: with SMTP id z19mr1627785iof.50.1619146389385; Thu, 22 Apr 2021 19:53:09 -0700 (PDT) MIME-Version: 1.0 References: <20210422081508.3942748-1-tientzu@chromium.org> <20210422081508.3942748-17-tientzu@chromium.org> In-Reply-To: <20210422081508.3942748-17-tientzu@chromium.org> From: Claire Chang Date: Fri, 23 Apr 2021 10:52:58 +0800 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH v5 16/16] of: Add plumbing for restricted DMA pool To: Joerg Roedel , Will Deacon , Frank Rowand , Konrad Rzeszutek Wilk , boris.ostrovsky@oracle.com, jgross@suse.com, Christoph Hellwig , Marek Szyprowski Cc: benh@kernel.crashing.org, paulus@samba.org, "list@263.net:IOMMU DRIVERS" , sstabellini@kernel.org, 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" , heikki.krogerus@linux.intel.com, Andy Shevchenko , Randy Dunlap , Dan Williams , Bartosz Golaszewski , linux-devicetree , lkml , linuxppc-dev@lists.ozlabs.org, xen-devel@lists.xenproject.org, Nicolas Boichat , Jim Quinlan , Tomasz Figa , bskeggs@redhat.com, bhelgaas@google.com, chris@chris-wilson.co.uk, daniel@ffwll.ch, airlied@linux.ie, dri-devel@lists.freedesktop.org, intel-gfx@lists.freedesktop.org, jani.nikula@linux.intel.com, jxgao@google.com, joonas.lahtinen@linux.intel.com, linux-pci@vger.kernel.org, maarten.lankhorst@linux.intel.com, matthew.auld@intel.com, nouveau@lists.freedesktop.org, rodrigo.vivi@intel.com, thomas.hellstrom@linux.intel.com Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Apr 22, 2021 at 4:17 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 > --- > drivers/of/address.c | 25 +++++++++++++++++++++++++ > drivers/of/device.c | 3 +++ > drivers/of/of_private.h | 5 +++++ > 3 files changed, 33 insertions(+) > > diff --git a/drivers/of/address.c b/drivers/of/address.c > index 54f221dde267..fff3adfe4986 100644 > --- a/drivers/of/address.c > +++ b/drivers/of/address.c > @@ -8,6 +8,7 @@ > #include > #include > #include > +#include > #include > #include > #include > @@ -1109,6 +1110,30 @@ bool of_dma_is_coherent(struct device_node *np) > } > EXPORT_SYMBOL_GPL(of_dma_is_coherent); > > +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)); > + for (i = 0; i < count; i++) { > + node = of_parse_phandle(dev->of_node, "memory-region", i); > + /* There might be multiple memory regions, but only one > + * restriced-dma-pool region is allowed. > + */ > + if (of_device_is_compatible(node, "restricted-dma-pool") && > + of_device_is_available(node)) > + return of_reserved_mem_device_init_by_idx( > + dev, dev->of_node, i); > + } > + > + return 0; > +} > + > /** > * of_mmio_is_nonposted - Check if device uses non-posted MMIO > * @np: device node > diff --git a/drivers/of/device.c b/drivers/of/device.c > index c5a9473a5fb1..d8d865223e51 100644 > --- a/drivers/of/device.c > +++ b/drivers/of/device.c > @@ -165,6 +165,9 @@ int of_dma_configure_id(struct device *dev, struct device_node *np, > > arch_setup_dma_ops(dev, dma_start, size, iommu, coherent); > > + 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 d717efbd637d..e9237f5eff48 100644 > --- a/drivers/of/of_private.h > +++ b/drivers/of/of_private.h > @@ -163,12 +163,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) This one should be of_dma_set_restricted_buffer. Sorry for the typo. > +{ > + return -ENODEV; > +} > #endif > > #endif /* _LINUX_OF_PRIVATE_H */ > -- > 2.31.1.368.gbe11c130af-goog > From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-13.6 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 72F9FC433B4 for ; Fri, 23 Apr 2021 02:53:58 +0000 (UTC) Received: from lists.ozlabs.org (lists.ozlabs.org [112.213.38.117]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 939E8613DB for ; Fri, 23 Apr 2021 02:53:57 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 939E8613DB Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=chromium.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=linuxppc-dev-bounces+linuxppc-dev=archiver.kernel.org@lists.ozlabs.org Received: from boromir.ozlabs.org (localhost [IPv6:::1]) by lists.ozlabs.org (Postfix) with ESMTP id 4FRJlR5RDSz30CX for ; Fri, 23 Apr 2021 12:53:55 +1000 (AEST) Authentication-Results: lists.ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=chromium.org header.i=@chromium.org header.a=rsa-sha256 header.s=google header.b=HdsQJQRk; dkim-atps=neutral Authentication-Results: lists.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=chromium.org (client-ip=2607:f8b0:4864:20::1035; helo=mail-pj1-x1035.google.com; envelope-from=tientzu@chromium.org; receiver=) Authentication-Results: lists.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=chromium.org header.i=@chromium.org header.a=rsa-sha256 header.s=google header.b=HdsQJQRk; dkim-atps=neutral Received: from mail-pj1-x1035.google.com (mail-pj1-x1035.google.com [IPv6:2607:f8b0:4864:20::1035]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 4FRJkw4zh9z2xZs for ; Fri, 23 Apr 2021 12:53:25 +1000 (AEST) Received: by mail-pj1-x1035.google.com with SMTP id f11-20020a17090a638bb02901524d3a3d48so416988pjj.3 for ; Thu, 22 Apr 2021 19:53:25 -0700 (PDT) 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=40nhsz+kltJTf7tq6pLLkes92lT1dy5Rll207DlKzWM=; b=HdsQJQRkixDre+dpQSVR58nl8K7T4MbrI4XmlnSivkYb875qGKmhwngqhS/XX43exh bg5Ne9Oub0puKLH8FRaSSn/FCuQxwpgf1ynisAFuTF4Wvjhe+t5iF+WotV6g96hB8Oro fWaQA0hAXWZxawu4WTORJsnwcVbFEg+0cCZO8= 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=40nhsz+kltJTf7tq6pLLkes92lT1dy5Rll207DlKzWM=; b=EGTBnV8Nubl18vZompn4yMUapZpbQQATd8zJIe1I5EmkHq1EgGUdvCA4V6UGMwFHgl b2Os0ciGil9/plMujJTXwuyQ3+lDo0Qt1rIL6J/WQcP/9s6P/MJUfFd6ACMS4pP+ucRR HWJEg2DsYyIn2RT180v5qUMX6CE14ZTSq3fgABGGfHYcAXJ1vkI2DUelO+2wijbFX9GD HXJqLDx0Hiqo3u7FwH4GyTAOJWCgNlMF+c0F2dDIIksp/u31IvgE/yMlfBMtFkOy+kHm wCA0WZzI8LoIMtbPyNe3aofk5TXSar+aBUSx9FnD5evPuGqax2nZEsgYxfL13KIFpn2B HkZw== X-Gm-Message-State: AOAM531UDwMvox1e5mqdBgAU7a+X6cchH9Dmc95pu7IVveEEgJSdAWul eTNJBywd6hriF0Sgjh2LAnwijMXQHmKaWg== X-Google-Smtp-Source: ABdhPJynVnhaX5HfrTopCAvx8ISH4T7TsOizJVXalp8K0AoYziNYcsGA9gjZKA3O6Ux2BrKdz2oDwg== X-Received: by 2002:a17:90a:f2d7:: with SMTP id gt23mr3224926pjb.199.1619146400883; Thu, 22 Apr 2021 19:53:20 -0700 (PDT) Received: from mail-pf1-f181.google.com (mail-pf1-f181.google.com. [209.85.210.181]) by smtp.gmail.com with ESMTPSA id ne22sm6106272pjb.5.2021.04.22.19.53.20 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 22 Apr 2021 19:53:20 -0700 (PDT) Received: by mail-pf1-f181.google.com with SMTP id y62so480691pfg.4 for ; Thu, 22 Apr 2021 19:53:20 -0700 (PDT) X-Received: by 2002:a6b:c913:: with SMTP id z19mr1627785iof.50.1619146389385; Thu, 22 Apr 2021 19:53:09 -0700 (PDT) MIME-Version: 1.0 References: <20210422081508.3942748-1-tientzu@chromium.org> <20210422081508.3942748-17-tientzu@chromium.org> In-Reply-To: <20210422081508.3942748-17-tientzu@chromium.org> From: Claire Chang Date: Fri, 23 Apr 2021 10:52:58 +0800 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH v5 16/16] of: Add plumbing for restricted DMA pool To: Joerg Roedel , Will Deacon , Frank Rowand , Konrad Rzeszutek Wilk , boris.ostrovsky@oracle.com, jgross@suse.com, Christoph Hellwig , Marek Szyprowski Content-Type: text/plain; charset="UTF-8" X-BeenThere: linuxppc-dev@lists.ozlabs.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Linux on PowerPC Developers Mail List List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: heikki.krogerus@linux.intel.com, thomas.hellstrom@linux.intel.com, peterz@infradead.org, joonas.lahtinen@linux.intel.com, dri-devel@lists.freedesktop.org, chris@chris-wilson.co.uk, grant.likely@arm.com, paulus@samba.org, mingo@kernel.org, jxgao@google.com, sstabellini@kernel.org, Saravana Kannan , xypron.glpk@gmx.de, "Rafael J . Wysocki" , Bartosz Golaszewski , bskeggs@redhat.com, linux-pci@vger.kernel.org, xen-devel@lists.xenproject.org, Thierry Reding , intel-gfx@lists.freedesktop.org, matthew.auld@intel.com, linux-devicetree , daniel@ffwll.ch, airlied@linux.ie, maarten.lankhorst@linux.intel.com, linuxppc-dev@lists.ozlabs.org, jani.nikula@linux.intel.com, Nicolas Boichat , rodrigo.vivi@intel.com, bhelgaas@google.com, Dan Williams , Andy Shevchenko , nouveau@lists.freedesktop.org, Greg KH , Randy Dunlap , lkml , Tomasz Figa , "list@263.net:IOMMU DRIVERS" , Jim Quinlan , Robin Murphy , bauerman@linux.ibm.com Errors-To: linuxppc-dev-bounces+linuxppc-dev=archiver.kernel.org@lists.ozlabs.org Sender: "Linuxppc-dev" On Thu, Apr 22, 2021 at 4:17 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 > --- > drivers/of/address.c | 25 +++++++++++++++++++++++++ > drivers/of/device.c | 3 +++ > drivers/of/of_private.h | 5 +++++ > 3 files changed, 33 insertions(+) > > diff --git a/drivers/of/address.c b/drivers/of/address.c > index 54f221dde267..fff3adfe4986 100644 > --- a/drivers/of/address.c > +++ b/drivers/of/address.c > @@ -8,6 +8,7 @@ > #include > #include > #include > +#include > #include > #include > #include > @@ -1109,6 +1110,30 @@ bool of_dma_is_coherent(struct device_node *np) > } > EXPORT_SYMBOL_GPL(of_dma_is_coherent); > > +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)); > + for (i = 0; i < count; i++) { > + node = of_parse_phandle(dev->of_node, "memory-region", i); > + /* There might be multiple memory regions, but only one > + * restriced-dma-pool region is allowed. > + */ > + if (of_device_is_compatible(node, "restricted-dma-pool") && > + of_device_is_available(node)) > + return of_reserved_mem_device_init_by_idx( > + dev, dev->of_node, i); > + } > + > + return 0; > +} > + > /** > * of_mmio_is_nonposted - Check if device uses non-posted MMIO > * @np: device node > diff --git a/drivers/of/device.c b/drivers/of/device.c > index c5a9473a5fb1..d8d865223e51 100644 > --- a/drivers/of/device.c > +++ b/drivers/of/device.c > @@ -165,6 +165,9 @@ int of_dma_configure_id(struct device *dev, struct device_node *np, > > arch_setup_dma_ops(dev, dma_start, size, iommu, coherent); > > + 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 d717efbd637d..e9237f5eff48 100644 > --- a/drivers/of/of_private.h > +++ b/drivers/of/of_private.h > @@ -163,12 +163,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) This one should be of_dma_set_restricted_buffer. Sorry for the typo. > +{ > + return -ENODEV; > +} > #endif > > #endif /* _LINUX_OF_PRIVATE_H */ > -- > 2.31.1.368.gbe11c130af-goog > From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-13.5 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 77B05C43460 for ; Fri, 23 Apr 2021 15:20:36 +0000 (UTC) Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 2188161445 for ; Fri, 23 Apr 2021 15:20:36 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 2188161445 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=chromium.org Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=nouveau-bounces@lists.freedesktop.org Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 443236EC05; Fri, 23 Apr 2021 15:20:31 +0000 (UTC) Received: from mail-pf1-x42d.google.com (mail-pf1-x42d.google.com [IPv6:2607:f8b0:4864:20::42d]) by gabe.freedesktop.org (Postfix) with ESMTPS id AD9C96E069 for ; Fri, 23 Apr 2021 02:53:21 +0000 (UTC) Received: by mail-pf1-x42d.google.com with SMTP id 10so24233632pfl.1 for ; Thu, 22 Apr 2021 19:53:21 -0700 (PDT) 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=40nhsz+kltJTf7tq6pLLkes92lT1dy5Rll207DlKzWM=; b=HdsQJQRkixDre+dpQSVR58nl8K7T4MbrI4XmlnSivkYb875qGKmhwngqhS/XX43exh bg5Ne9Oub0puKLH8FRaSSn/FCuQxwpgf1ynisAFuTF4Wvjhe+t5iF+WotV6g96hB8Oro fWaQA0hAXWZxawu4WTORJsnwcVbFEg+0cCZO8= 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=40nhsz+kltJTf7tq6pLLkes92lT1dy5Rll207DlKzWM=; b=MlrUG6l/FM2a88UxXZOoe7PdPxYwp5AWhI+IK8SICrCdQahXLPjJVVNH+28U5mvw8a AOGwEwqjYNUxfC4Mwsg5r24Tw6wx8HaWwFoAXbQ7XNxxI1NHZwMUbGXd05FNXcVWAeop q8Dd8UKfRZ2DeueQCgIJZhcHZaugqkCooAPuPDc9RXEcRz69JK8obFMeEFaqQgy3FxD7 ExS2hB+xXrC2Nds3zF6UtdhghNopwKsTma0ZajWphhaYee2I3uF5S70jfZsMSJl7faO6 e1w5I/neAEv+lK0tuNgaKLp+7L0YP1pnV7oC0NgfG8+cdPPtv850zNDYATP8IXXihkS8 VdxA== X-Gm-Message-State: AOAM531gaElQ1w/g6zIR46bYn95CpwEheK21EfUwgQGv3GoAq4M8weHx wYQyWUcNruOKNx03CAANlcbbw7RSmQgEIg== X-Google-Smtp-Source: ABdhPJwJq7aqLByyg7+kdPTmjwt6OPUMfPyAJh539UKIxi2Zm35FLokuhS+gds0YbWL96XJ64iEwGQ== X-Received: by 2002:a62:dd53:0:b029:25f:ba3c:9cbe with SMTP id w80-20020a62dd530000b029025fba3c9cbemr1927125pff.64.1619146400847; Thu, 22 Apr 2021 19:53:20 -0700 (PDT) Received: from mail-pg1-f172.google.com (mail-pg1-f172.google.com. [209.85.215.172]) by smtp.gmail.com with ESMTPSA id w23sm3338147pgi.63.2021.04.22.19.53.20 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 22 Apr 2021 19:53:20 -0700 (PDT) Received: by mail-pg1-f172.google.com with SMTP id z16so34230965pga.1 for ; Thu, 22 Apr 2021 19:53:20 -0700 (PDT) X-Received: by 2002:a6b:c913:: with SMTP id z19mr1627785iof.50.1619146389385; Thu, 22 Apr 2021 19:53:09 -0700 (PDT) MIME-Version: 1.0 References: <20210422081508.3942748-1-tientzu@chromium.org> <20210422081508.3942748-17-tientzu@chromium.org> In-Reply-To: <20210422081508.3942748-17-tientzu@chromium.org> From: Claire Chang Date: Fri, 23 Apr 2021 10:52:58 +0800 X-Gmail-Original-Message-ID: Message-ID: To: Joerg Roedel , Will Deacon , Frank Rowand , Konrad Rzeszutek Wilk , boris.ostrovsky@oracle.com, jgross@suse.com, Christoph Hellwig , Marek Szyprowski X-Mailman-Approved-At: Fri, 23 Apr 2021 15:20:27 +0000 Subject: Re: [Nouveau] [PATCH v5 16/16] of: Add plumbing for restricted DMA pool X-BeenThere: nouveau@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Nouveau development list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: heikki.krogerus@linux.intel.com, thomas.hellstrom@linux.intel.com, peterz@infradead.org, benh@kernel.crashing.org, joonas.lahtinen@linux.intel.com, dri-devel@lists.freedesktop.org, chris@chris-wilson.co.uk, grant.likely@arm.com, paulus@samba.org, mingo@kernel.org, jxgao@google.com, sstabellini@kernel.org, Saravana Kannan , xypron.glpk@gmx.de, "Rafael J . Wysocki" , Bartosz Golaszewski , bskeggs@redhat.com, linux-pci@vger.kernel.org, xen-devel@lists.xenproject.org, Thierry Reding , intel-gfx@lists.freedesktop.org, matthew.auld@intel.com, linux-devicetree , daniel@ffwll.ch, airlied@linux.ie, maarten.lankhorst@linux.intel.com, Robin Murphy , jani.nikula@linux.intel.com, Nicolas Boichat , rodrigo.vivi@intel.com, bhelgaas@google.com, Dan Williams , Andy Shevchenko , nouveau@lists.freedesktop.org, Greg KH , Randy Dunlap , lkml , Tomasz Figa , "list@263.net:IOMMU DRIVERS" , Jim Quinlan , linuxppc-dev@lists.ozlabs.org, bauerman@linux.ibm.com Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: nouveau-bounces@lists.freedesktop.org Sender: "Nouveau" On Thu, Apr 22, 2021 at 4:17 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 > --- > drivers/of/address.c | 25 +++++++++++++++++++++++++ > drivers/of/device.c | 3 +++ > drivers/of/of_private.h | 5 +++++ > 3 files changed, 33 insertions(+) > > diff --git a/drivers/of/address.c b/drivers/of/address.c > index 54f221dde267..fff3adfe4986 100644 > --- a/drivers/of/address.c > +++ b/drivers/of/address.c > @@ -8,6 +8,7 @@ > #include > #include > #include > +#include > #include > #include > #include > @@ -1109,6 +1110,30 @@ bool of_dma_is_coherent(struct device_node *np) > } > EXPORT_SYMBOL_GPL(of_dma_is_coherent); > > +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)); > + for (i = 0; i < count; i++) { > + node = of_parse_phandle(dev->of_node, "memory-region", i); > + /* There might be multiple memory regions, but only one > + * restriced-dma-pool region is allowed. > + */ > + if (of_device_is_compatible(node, "restricted-dma-pool") && > + of_device_is_available(node)) > + return of_reserved_mem_device_init_by_idx( > + dev, dev->of_node, i); > + } > + > + return 0; > +} > + > /** > * of_mmio_is_nonposted - Check if device uses non-posted MMIO > * @np: device node > diff --git a/drivers/of/device.c b/drivers/of/device.c > index c5a9473a5fb1..d8d865223e51 100644 > --- a/drivers/of/device.c > +++ b/drivers/of/device.c > @@ -165,6 +165,9 @@ int of_dma_configure_id(struct device *dev, struct device_node *np, > > arch_setup_dma_ops(dev, dma_start, size, iommu, coherent); > > + 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 d717efbd637d..e9237f5eff48 100644 > --- a/drivers/of/of_private.h > +++ b/drivers/of/of_private.h > @@ -163,12 +163,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) This one should be of_dma_set_restricted_buffer. Sorry for the typo. > +{ > + return -ENODEV; > +} > #endif > > #endif /* _LINUX_OF_PRIVATE_H */ > -- > 2.31.1.368.gbe11c130af-goog > _______________________________________________ Nouveau mailing list Nouveau@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/nouveau From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-13.6 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 6B18EC433B4 for ; Fri, 23 Apr 2021 02:53:16 +0000 (UTC) Received: from smtp1.osuosl.org (smtp1.osuosl.org [140.211.166.138]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id CA381613DB for ; Fri, 23 Apr 2021 02:53:15 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org CA381613DB Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=chromium.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=iommu-bounces@lists.linux-foundation.org Received: from localhost (localhost [127.0.0.1]) by smtp1.osuosl.org (Postfix) with ESMTP id 623B6843E3; Fri, 23 Apr 2021 02:53:15 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from smtp1.osuosl.org ([127.0.0.1]) by localhost (smtp1.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 5-M6hrt15VzL; Fri, 23 Apr 2021 02:53:14 +0000 (UTC) Received: from lists.linuxfoundation.org (lf-lists.osuosl.org [IPv6:2605:bc80:3010:104::8cd3:938]) by smtp1.osuosl.org (Postfix) with ESMTP id 513F88438E; Fri, 23 Apr 2021 02:53:14 +0000 (UTC) Received: from lf-lists.osuosl.org (localhost [127.0.0.1]) by lists.linuxfoundation.org (Postfix) with ESMTP id 24EFDC000F; Fri, 23 Apr 2021 02:53:14 +0000 (UTC) Received: from smtp1.osuosl.org (smtp1.osuosl.org [140.211.166.138]) by lists.linuxfoundation.org (Postfix) with ESMTP id 2A843C000B for ; Fri, 23 Apr 2021 02:53:13 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by smtp1.osuosl.org (Postfix) with ESMTP id 1CFD8843B5 for ; Fri, 23 Apr 2021 02:53:13 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from smtp1.osuosl.org ([127.0.0.1]) by localhost (smtp1.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id mV05kHLx1GMi for ; Fri, 23 Apr 2021 02:53:12 +0000 (UTC) X-Greylist: whitelisted by SQLgrey-1.8.0 Received: from mail-il1-x129.google.com (mail-il1-x129.google.com [IPv6:2607:f8b0:4864:20::129]) by smtp1.osuosl.org (Postfix) with ESMTPS id 526228438E for ; Fri, 23 Apr 2021 02:53:12 +0000 (UTC) Received: by mail-il1-x129.google.com with SMTP id r5so940383ilb.2 for ; Thu, 22 Apr 2021 19:53:12 -0700 (PDT) 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=40nhsz+kltJTf7tq6pLLkes92lT1dy5Rll207DlKzWM=; b=HdsQJQRkixDre+dpQSVR58nl8K7T4MbrI4XmlnSivkYb875qGKmhwngqhS/XX43exh bg5Ne9Oub0puKLH8FRaSSn/FCuQxwpgf1ynisAFuTF4Wvjhe+t5iF+WotV6g96hB8Oro fWaQA0hAXWZxawu4WTORJsnwcVbFEg+0cCZO8= 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=40nhsz+kltJTf7tq6pLLkes92lT1dy5Rll207DlKzWM=; b=MxxhHGJ9Xu3G4ykFs1uf2acFIctyj4J1gXjXgMbQk1PO6BfVrCQtDXzJVdlKYTs2rM 5Bw8R736Ygj4CJQNvO7Lm/edOR6AV5dHft6e1Nmn5RG/leVmvD1IGLdCJJSB3nRvyefm ALiSG02KCC2RDUqKrEku0YhAxzyd5mi0JMFSX4pwB+D+QfNLj33Z2RLhCiDHRyZYQeEz vyspaCJ8yqmPGJJknef/72IBYZ3WtChV36qlMyd8w8vh/XyaO1xzPvfikaUg2saxcOmF vumcAV4NY9AiSKQDiHzQIZ+uL4sT3L2UyZ115V1qX26o1gjjY54A8jeJHhmcHRljFJ/g hZLw== X-Gm-Message-State: AOAM531KQXlhAwnYB11gj7tISmS+hiW9ttuQiXH7seuJYx39PHNDVChY YbjuUSRELtYGyefOBNIyLVS+YLtmKdmUkQ== X-Google-Smtp-Source: ABdhPJwVR/56B8kK2AZh1LVSig4ozKmTXOXm9lKjQpncSPNsnuKgFxL3neZdTJNhh7eXBpanlYoJXw== X-Received: by 2002:a92:cf50:: with SMTP id c16mr1259773ilr.2.1619146390998; Thu, 22 Apr 2021 19:53:10 -0700 (PDT) Received: from mail-io1-f51.google.com (mail-io1-f51.google.com. [209.85.166.51]) by smtp.gmail.com with ESMTPSA id f1sm1938655ilu.46.2021.04.22.19.53.09 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 22 Apr 2021 19:53:10 -0700 (PDT) Received: by mail-io1-f51.google.com with SMTP id v123so40742959ioe.10 for ; Thu, 22 Apr 2021 19:53:09 -0700 (PDT) X-Received: by 2002:a6b:c913:: with SMTP id z19mr1627785iof.50.1619146389385; Thu, 22 Apr 2021 19:53:09 -0700 (PDT) MIME-Version: 1.0 References: <20210422081508.3942748-1-tientzu@chromium.org> <20210422081508.3942748-17-tientzu@chromium.org> In-Reply-To: <20210422081508.3942748-17-tientzu@chromium.org> From: Claire Chang Date: Fri, 23 Apr 2021 10:52:58 +0800 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH v5 16/16] of: Add plumbing for restricted DMA pool To: Joerg Roedel , Will Deacon , Frank Rowand , Konrad Rzeszutek Wilk , boris.ostrovsky@oracle.com, jgross@suse.com, Christoph Hellwig , Marek Szyprowski Cc: heikki.krogerus@linux.intel.com, thomas.hellstrom@linux.intel.com, peterz@infradead.org, benh@kernel.crashing.org, joonas.lahtinen@linux.intel.com, dri-devel@lists.freedesktop.org, chris@chris-wilson.co.uk, grant.likely@arm.com, paulus@samba.org, mingo@kernel.org, jxgao@google.com, sstabellini@kernel.org, Saravana Kannan , xypron.glpk@gmx.de, "Rafael J . Wysocki" , Bartosz Golaszewski , bskeggs@redhat.com, linux-pci@vger.kernel.org, xen-devel@lists.xenproject.org, Thierry Reding , intel-gfx@lists.freedesktop.org, matthew.auld@intel.com, linux-devicetree , daniel@ffwll.ch, airlied@linux.ie, maarten.lankhorst@linux.intel.com, linuxppc-dev@lists.ozlabs.org, jani.nikula@linux.intel.com, Nicolas Boichat , rodrigo.vivi@intel.com, bhelgaas@google.com, Dan Williams , Andy Shevchenko , nouveau@lists.freedesktop.org, Greg KH , Randy Dunlap , lkml , "list@263.net:IOMMU DRIVERS" , Jim Quinlan , Robin Murphy , bauerman@linux.ibm.com X-BeenThere: iommu@lists.linux-foundation.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: Development issues for Linux IOMMU support List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: iommu-bounces@lists.linux-foundation.org Sender: "iommu" On Thu, Apr 22, 2021 at 4:17 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 > --- > drivers/of/address.c | 25 +++++++++++++++++++++++++ > drivers/of/device.c | 3 +++ > drivers/of/of_private.h | 5 +++++ > 3 files changed, 33 insertions(+) > > diff --git a/drivers/of/address.c b/drivers/of/address.c > index 54f221dde267..fff3adfe4986 100644 > --- a/drivers/of/address.c > +++ b/drivers/of/address.c > @@ -8,6 +8,7 @@ > #include > #include > #include > +#include > #include > #include > #include > @@ -1109,6 +1110,30 @@ bool of_dma_is_coherent(struct device_node *np) > } > EXPORT_SYMBOL_GPL(of_dma_is_coherent); > > +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)); > + for (i = 0; i < count; i++) { > + node = of_parse_phandle(dev->of_node, "memory-region", i); > + /* There might be multiple memory regions, but only one > + * restriced-dma-pool region is allowed. > + */ > + if (of_device_is_compatible(node, "restricted-dma-pool") && > + of_device_is_available(node)) > + return of_reserved_mem_device_init_by_idx( > + dev, dev->of_node, i); > + } > + > + return 0; > +} > + > /** > * of_mmio_is_nonposted - Check if device uses non-posted MMIO > * @np: device node > diff --git a/drivers/of/device.c b/drivers/of/device.c > index c5a9473a5fb1..d8d865223e51 100644 > --- a/drivers/of/device.c > +++ b/drivers/of/device.c > @@ -165,6 +165,9 @@ int of_dma_configure_id(struct device *dev, struct device_node *np, > > arch_setup_dma_ops(dev, dma_start, size, iommu, coherent); > > + 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 d717efbd637d..e9237f5eff48 100644 > --- a/drivers/of/of_private.h > +++ b/drivers/of/of_private.h > @@ -163,12 +163,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) This one should be of_dma_set_restricted_buffer. Sorry for the typo. > +{ > + return -ENODEV; > +} > #endif > > #endif /* _LINUX_OF_PRIVATE_H */ > -- > 2.31.1.368.gbe11c130af-goog > _______________________________________________ iommu mailing list iommu@lists.linux-foundation.org https://lists.linuxfoundation.org/mailman/listinfo/iommu From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-13.6 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id BEE37C433B4 for ; Fri, 23 Apr 2021 02:58:26 +0000 (UTC) Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 7288E6144D for ; Fri, 23 Apr 2021 02:58:26 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 7288E6144D Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=chromium.org Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=dri-devel-bounces@lists.freedesktop.org Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 9D8856E069; Fri, 23 Apr 2021 02:58:25 +0000 (UTC) Received: from mail-pj1-x1033.google.com (mail-pj1-x1033.google.com [IPv6:2607:f8b0:4864:20::1033]) by gabe.freedesktop.org (Postfix) with ESMTPS id BA43E6E069 for ; Fri, 23 Apr 2021 02:58:24 +0000 (UTC) Received: by mail-pj1-x1033.google.com with SMTP id u11so18714282pjr.0 for ; Thu, 22 Apr 2021 19:58:24 -0700 (PDT) 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=40nhsz+kltJTf7tq6pLLkes92lT1dy5Rll207DlKzWM=; b=HdsQJQRkixDre+dpQSVR58nl8K7T4MbrI4XmlnSivkYb875qGKmhwngqhS/XX43exh bg5Ne9Oub0puKLH8FRaSSn/FCuQxwpgf1ynisAFuTF4Wvjhe+t5iF+WotV6g96hB8Oro fWaQA0hAXWZxawu4WTORJsnwcVbFEg+0cCZO8= 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=40nhsz+kltJTf7tq6pLLkes92lT1dy5Rll207DlKzWM=; b=Huo9HyKkzBVMGE/3yXIncYsEZOJvTFzD13g6+ueB1EAY3U2HzBHwk7aiq6fcNM/ZPn TeNAonzxxpeHvlvHuoQ3m+7Ucm5A0HMpXeuw3enM3y7Hrl5RbGGpoXAq9hl9WZZzVv7I Jv+hPUTl0+zrrn9bVm3WZAk3sPaPgUxjqa6C9ZrCNM6gYmOfFtkQC4pdb+j4wDf3qQn9 jBmwO6vUhHIJAnX+/tOLGhTkddiKSJUakl/PpIlG0+2R0BtQrBuZndsXZC0Wmby5bQLW e68QoZScpPfPTNCJi12dV1qh8pJTXtqcgCW0i+eKWxgAMjoaIYFQuq1fOCIqBaTKbfYs PHLg== X-Gm-Message-State: AOAM532HNJKy/QhfhS+kw74CtpaBDvTHNECPD6wpfm50BkmdQiLTSQ1t OorqfMDZqhXfz7TzQgH3B7qLnF414ivJkg== X-Google-Smtp-Source: ABdhPJyRAiIzWs8AuSBlqrmr3IratesYGzu6KLSm7gpjPIUTjrj4ruqkVp39AcU4CUrd8aM9M6F+Uw== X-Received: by 2002:a17:90a:1b4b:: with SMTP id q69mr3226984pjq.188.1619146704024; Thu, 22 Apr 2021 19:58:24 -0700 (PDT) Received: from mail-pf1-f171.google.com (mail-pf1-f171.google.com. [209.85.210.171]) by smtp.gmail.com with ESMTPSA id v8sm3059143pfu.205.2021.04.22.19.58.23 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 22 Apr 2021 19:58:23 -0700 (PDT) Received: by mail-pf1-f171.google.com with SMTP id q2so1172854pfk.9 for ; Thu, 22 Apr 2021 19:58:23 -0700 (PDT) X-Received: by 2002:a6b:c913:: with SMTP id z19mr1627785iof.50.1619146389385; Thu, 22 Apr 2021 19:53:09 -0700 (PDT) MIME-Version: 1.0 References: <20210422081508.3942748-1-tientzu@chromium.org> <20210422081508.3942748-17-tientzu@chromium.org> In-Reply-To: <20210422081508.3942748-17-tientzu@chromium.org> From: Claire Chang Date: Fri, 23 Apr 2021 10:52:58 +0800 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH v5 16/16] of: Add plumbing for restricted DMA pool To: Joerg Roedel , Will Deacon , Frank Rowand , Konrad Rzeszutek Wilk , boris.ostrovsky@oracle.com, jgross@suse.com, Christoph Hellwig , Marek Szyprowski X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: heikki.krogerus@linux.intel.com, thomas.hellstrom@linux.intel.com, peterz@infradead.org, dri-devel@lists.freedesktop.org, chris@chris-wilson.co.uk, grant.likely@arm.com, paulus@samba.org, mingo@kernel.org, jxgao@google.com, sstabellini@kernel.org, Saravana Kannan , xypron.glpk@gmx.de, "Rafael J . Wysocki" , Bartosz Golaszewski , bskeggs@redhat.com, linux-pci@vger.kernel.org, xen-devel@lists.xenproject.org, Thierry Reding , intel-gfx@lists.freedesktop.org, matthew.auld@intel.com, linux-devicetree , airlied@linux.ie, Robin Murphy , Nicolas Boichat , rodrigo.vivi@intel.com, bhelgaas@google.com, Dan Williams , Andy Shevchenko , nouveau@lists.freedesktop.org, Greg KH , Randy Dunlap , lkml , Tomasz Figa , "list@263.net:IOMMU DRIVERS" , Jim Quinlan , linuxppc-dev@lists.ozlabs.org, bauerman@linux.ibm.com Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" On Thu, Apr 22, 2021 at 4:17 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 > --- > drivers/of/address.c | 25 +++++++++++++++++++++++++ > drivers/of/device.c | 3 +++ > drivers/of/of_private.h | 5 +++++ > 3 files changed, 33 insertions(+) > > diff --git a/drivers/of/address.c b/drivers/of/address.c > index 54f221dde267..fff3adfe4986 100644 > --- a/drivers/of/address.c > +++ b/drivers/of/address.c > @@ -8,6 +8,7 @@ > #include > #include > #include > +#include > #include > #include > #include > @@ -1109,6 +1110,30 @@ bool of_dma_is_coherent(struct device_node *np) > } > EXPORT_SYMBOL_GPL(of_dma_is_coherent); > > +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)); > + for (i = 0; i < count; i++) { > + node = of_parse_phandle(dev->of_node, "memory-region", i); > + /* There might be multiple memory regions, but only one > + * restriced-dma-pool region is allowed. > + */ > + if (of_device_is_compatible(node, "restricted-dma-pool") && > + of_device_is_available(node)) > + return of_reserved_mem_device_init_by_idx( > + dev, dev->of_node, i); > + } > + > + return 0; > +} > + > /** > * of_mmio_is_nonposted - Check if device uses non-posted MMIO > * @np: device node > diff --git a/drivers/of/device.c b/drivers/of/device.c > index c5a9473a5fb1..d8d865223e51 100644 > --- a/drivers/of/device.c > +++ b/drivers/of/device.c > @@ -165,6 +165,9 @@ int of_dma_configure_id(struct device *dev, struct device_node *np, > > arch_setup_dma_ops(dev, dma_start, size, iommu, coherent); > > + 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 d717efbd637d..e9237f5eff48 100644 > --- a/drivers/of/of_private.h > +++ b/drivers/of/of_private.h > @@ -163,12 +163,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) This one should be of_dma_set_restricted_buffer. Sorry for the typo. > +{ > + return -ENODEV; > +} > #endif > > #endif /* _LINUX_OF_PRIVATE_H */ > -- > 2.31.1.368.gbe11c130af-goog > _______________________________________________ dri-devel mailing list dri-devel@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/dri-devel From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-13.6 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 042F8C433ED for ; Fri, 23 Apr 2021 02:53:24 +0000 (UTC) Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id AC2D6610E6 for ; Fri, 23 Apr 2021 02:53:23 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org AC2D6610E6 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=chromium.org Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=intel-gfx-bounces@lists.freedesktop.org Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 209BF6E069; Fri, 23 Apr 2021 02:53:23 +0000 (UTC) Received: from mail-pf1-x42d.google.com (mail-pf1-x42d.google.com [IPv6:2607:f8b0:4864:20::42d]) by gabe.freedesktop.org (Postfix) with ESMTPS id 580146E069 for ; Fri, 23 Apr 2021 02:53:21 +0000 (UTC) Received: by mail-pf1-x42d.google.com with SMTP id d124so33090381pfa.13 for ; Thu, 22 Apr 2021 19:53:21 -0700 (PDT) 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=40nhsz+kltJTf7tq6pLLkes92lT1dy5Rll207DlKzWM=; b=HdsQJQRkixDre+dpQSVR58nl8K7T4MbrI4XmlnSivkYb875qGKmhwngqhS/XX43exh bg5Ne9Oub0puKLH8FRaSSn/FCuQxwpgf1ynisAFuTF4Wvjhe+t5iF+WotV6g96hB8Oro fWaQA0hAXWZxawu4WTORJsnwcVbFEg+0cCZO8= 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=40nhsz+kltJTf7tq6pLLkes92lT1dy5Rll207DlKzWM=; b=bskWV4x8nH8XW1P20pktz3ENlB/FGWjWhi7iYmwdt7XkiWfJ8r2gbMjIDdQuLUs//W 7OH3Ciw8LTf6twdKp9+vy5uJg9gYlY/UaTu1rGL5tiwbDoESXN+rlX1M3z2rCYDS4u/M vFG/IRHSDdtfTATWxct4uqvZhVuOY4ZuiZVFfL3bmH+MOZrG8vsAAUTJ8BUuj9UAGxSU wlcs3l7XllmVqB1ciAYrzJrM24+CkSu0HtzHBmT92vIXY2/lMV/1kaSS0mK3LtZOF8AG hOpWgyPIv5L2BsW4GF2qSUI+p2CK0Ht1biUHj9P+iKZHtkVZIEVA15/gvg0VgfVMCkTD L9jg== X-Gm-Message-State: AOAM530HMOiO1cgJp6XtbEVjhf0JKpebQsqUcC6I0RzndXzV2VY/C4fq lf3MjDjOoAyOaLHXUx0OiGahA/qEurcNrQ== X-Google-Smtp-Source: ABdhPJyybc9ILHIAjKMlHq+meWiuZSMQKLWP08jwxuyC5DCJMaEXQ5KuR3Kf6BZtKZs1tb++Sl0Eaw== X-Received: by 2002:a05:6a00:212b:b029:259:73ac:7217 with SMTP id n11-20020a056a00212bb029025973ac7217mr1842975pfj.20.1619146401000; Thu, 22 Apr 2021 19:53:21 -0700 (PDT) Received: from mail-pg1-f178.google.com (mail-pg1-f178.google.com. [209.85.215.178]) by smtp.gmail.com with ESMTPSA id h9sm3093540pfv.14.2021.04.22.19.53.20 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 22 Apr 2021 19:53:20 -0700 (PDT) Received: by mail-pg1-f178.google.com with SMTP id z16so34230975pga.1 for ; Thu, 22 Apr 2021 19:53:20 -0700 (PDT) X-Received: by 2002:a6b:c913:: with SMTP id z19mr1627785iof.50.1619146389385; Thu, 22 Apr 2021 19:53:09 -0700 (PDT) MIME-Version: 1.0 References: <20210422081508.3942748-1-tientzu@chromium.org> <20210422081508.3942748-17-tientzu@chromium.org> In-Reply-To: <20210422081508.3942748-17-tientzu@chromium.org> From: Claire Chang Date: Fri, 23 Apr 2021 10:52:58 +0800 X-Gmail-Original-Message-ID: Message-ID: To: Joerg Roedel , Will Deacon , Frank Rowand , Konrad Rzeszutek Wilk , boris.ostrovsky@oracle.com, jgross@suse.com, Christoph Hellwig , Marek Szyprowski Subject: Re: [Intel-gfx] [PATCH v5 16/16] of: Add plumbing for restricted DMA pool X-BeenThere: intel-gfx@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Intel graphics driver community testing & development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: heikki.krogerus@linux.intel.com, thomas.hellstrom@linux.intel.com, peterz@infradead.org, benh@kernel.crashing.org, dri-devel@lists.freedesktop.org, chris@chris-wilson.co.uk, grant.likely@arm.com, paulus@samba.org, mingo@kernel.org, jxgao@google.com, sstabellini@kernel.org, Saravana Kannan , xypron.glpk@gmx.de, "Rafael J . Wysocki" , Bartosz Golaszewski , bskeggs@redhat.com, linux-pci@vger.kernel.org, xen-devel@lists.xenproject.org, Thierry Reding , intel-gfx@lists.freedesktop.org, matthew.auld@intel.com, linux-devicetree , airlied@linux.ie, Robin Murphy , Nicolas Boichat , bhelgaas@google.com, Dan Williams , Andy Shevchenko , nouveau@lists.freedesktop.org, Greg KH , Randy Dunlap , lkml , Tomasz Figa , "list@263.net:IOMMU DRIVERS" , Jim Quinlan , linuxppc-dev@lists.ozlabs.org, bauerman@linux.ibm.com Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: intel-gfx-bounces@lists.freedesktop.org Sender: "Intel-gfx" On Thu, Apr 22, 2021 at 4:17 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 > --- > drivers/of/address.c | 25 +++++++++++++++++++++++++ > drivers/of/device.c | 3 +++ > drivers/of/of_private.h | 5 +++++ > 3 files changed, 33 insertions(+) > > diff --git a/drivers/of/address.c b/drivers/of/address.c > index 54f221dde267..fff3adfe4986 100644 > --- a/drivers/of/address.c > +++ b/drivers/of/address.c > @@ -8,6 +8,7 @@ > #include > #include > #include > +#include > #include > #include > #include > @@ -1109,6 +1110,30 @@ bool of_dma_is_coherent(struct device_node *np) > } > EXPORT_SYMBOL_GPL(of_dma_is_coherent); > > +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)); > + for (i = 0; i < count; i++) { > + node = of_parse_phandle(dev->of_node, "memory-region", i); > + /* There might be multiple memory regions, but only one > + * restriced-dma-pool region is allowed. > + */ > + if (of_device_is_compatible(node, "restricted-dma-pool") && > + of_device_is_available(node)) > + return of_reserved_mem_device_init_by_idx( > + dev, dev->of_node, i); > + } > + > + return 0; > +} > + > /** > * of_mmio_is_nonposted - Check if device uses non-posted MMIO > * @np: device node > diff --git a/drivers/of/device.c b/drivers/of/device.c > index c5a9473a5fb1..d8d865223e51 100644 > --- a/drivers/of/device.c > +++ b/drivers/of/device.c > @@ -165,6 +165,9 @@ int of_dma_configure_id(struct device *dev, struct device_node *np, > > arch_setup_dma_ops(dev, dma_start, size, iommu, coherent); > > + 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 d717efbd637d..e9237f5eff48 100644 > --- a/drivers/of/of_private.h > +++ b/drivers/of/of_private.h > @@ -163,12 +163,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) This one should be of_dma_set_restricted_buffer. Sorry for the typo. > +{ > + return -ENODEV; > +} > #endif > > #endif /* _LINUX_OF_PRIVATE_H */ > -- > 2.31.1.368.gbe11c130af-goog > _______________________________________________ Intel-gfx mailing list Intel-gfx@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/intel-gfx From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.8 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, URIBL_BLOCKED autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id F2E84C433ED for ; Fri, 23 Apr 2021 02:53:34 +0000 (UTC) Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 9E2F061452 for ; Fri, 23 Apr 2021 02:53:34 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 9E2F061452 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=chromium.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=xen-devel-bounces@lists.xenproject.org Received: from list by lists.xenproject.org with outflank-mailman.115864.221106 (Exim 4.92) (envelope-from ) id 1lZlwb-00029H-5Y; Fri, 23 Apr 2021 02:53:25 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 115864.221106; Fri, 23 Apr 2021 02:53:25 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1lZlwb-00029A-1I; Fri, 23 Apr 2021 02:53:25 +0000 Received: by outflank-mailman (input) for mailman id 115864; Fri, 23 Apr 2021 02:53:23 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1lZlwZ-000294-2H for xen-devel@lists.xenproject.org; Fri, 23 Apr 2021 02:53:23 +0000 Received: from mail-pj1-x1034.google.com (unknown [2607:f8b0:4864:20::1034]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id 76c447c3-3565-493a-9f5b-bd598b913b0f; Fri, 23 Apr 2021 02:53:22 +0000 (UTC) Received: by mail-pj1-x1034.google.com with SMTP id y22-20020a17090a8b16b0290150ae1a6d2bso493643pjn.0 for ; Thu, 22 Apr 2021 19:53:22 -0700 (PDT) Received: from mail-pg1-f172.google.com (mail-pg1-f172.google.com. [209.85.215.172]) by smtp.gmail.com with ESMTPSA id u12sm6556784pji.45.2021.04.22.19.53.20 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 22 Apr 2021 19:53:20 -0700 (PDT) Received: by mail-pg1-f172.google.com with SMTP id f29so34216405pgm.8 for ; Thu, 22 Apr 2021 19:53:20 -0700 (PDT) X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: 76c447c3-3565-493a-9f5b-bd598b913b0f 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=40nhsz+kltJTf7tq6pLLkes92lT1dy5Rll207DlKzWM=; b=HdsQJQRkixDre+dpQSVR58nl8K7T4MbrI4XmlnSivkYb875qGKmhwngqhS/XX43exh bg5Ne9Oub0puKLH8FRaSSn/FCuQxwpgf1ynisAFuTF4Wvjhe+t5iF+WotV6g96hB8Oro fWaQA0hAXWZxawu4WTORJsnwcVbFEg+0cCZO8= 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=40nhsz+kltJTf7tq6pLLkes92lT1dy5Rll207DlKzWM=; b=MZsZ4pSPJ4dCVZHls6VtxP38cfYfnsQ7Bom6r+3BCIFm4701zGD4ar8Ehysye8QiLR D4md2hTJFvtQL8ULbgsW/2RSz3/00a9eyMPQXozVYffEtm7Yy/sZlcZhRCnMMQ0jZMf5 MH5ksKnaIgYlN7DEM/L+WDuPXcsSOBQjLteVAXbPXVlZ0SsbPOc3oQ60hAA2sBIDX5aE IdWFJ8lDvIEcDUpqgfXbd64zgsaW+SscBAlgbCBOKx51cgLeC/0osLH+fGPUkObn7ZnY 7YQLD0Vzi7zXAgmxaLJT9EOXn67KZI0HsdrBylZMNsL2TVb4DwQz39pKHN5JPLz76txk Gcvg== X-Gm-Message-State: AOAM531mq1IdS6LJmsJts1cuZMkGQD+iwq2wRGCdZyS6/9QfunIOu+Zw kkLBAfLedatjODGVEmZ4s8+9fDNRtZWt4g== X-Google-Smtp-Source: ABdhPJzWnUCvHFfO+w/TiuDRjCZ3wO/0KPZ96zCBEM4eWzT8b7FPGbUB5wyBYDOY8gwW5n4uPwDTbw== X-Received: by 2002:a17:90a:6b4f:: with SMTP id x15mr3272223pjl.227.1619146400919; Thu, 22 Apr 2021 19:53:20 -0700 (PDT) X-Received: by 2002:a6b:c913:: with SMTP id z19mr1627785iof.50.1619146389385; Thu, 22 Apr 2021 19:53:09 -0700 (PDT) MIME-Version: 1.0 References: <20210422081508.3942748-1-tientzu@chromium.org> <20210422081508.3942748-17-tientzu@chromium.org> In-Reply-To: <20210422081508.3942748-17-tientzu@chromium.org> From: Claire Chang Date: Fri, 23 Apr 2021 10:52:58 +0800 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH v5 16/16] of: Add plumbing for restricted DMA pool To: Joerg Roedel , Will Deacon , Frank Rowand , Konrad Rzeszutek Wilk , boris.ostrovsky@oracle.com, jgross@suse.com, Christoph Hellwig , Marek Szyprowski Cc: benh@kernel.crashing.org, paulus@samba.org, "list@263.net:IOMMU DRIVERS" , sstabellini@kernel.org, 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" , heikki.krogerus@linux.intel.com, Andy Shevchenko , Randy Dunlap , Dan Williams , Bartosz Golaszewski , linux-devicetree , lkml , linuxppc-dev@lists.ozlabs.org, xen-devel@lists.xenproject.org, Nicolas Boichat , Jim Quinlan , Tomasz Figa , bskeggs@redhat.com, bhelgaas@google.com, chris@chris-wilson.co.uk, daniel@ffwll.ch, airlied@linux.ie, dri-devel@lists.freedesktop.org, intel-gfx@lists.freedesktop.org, jani.nikula@linux.intel.com, jxgao@google.com, joonas.lahtinen@linux.intel.com, linux-pci@vger.kernel.org, maarten.lankhorst@linux.intel.com, matthew.auld@intel.com, nouveau@lists.freedesktop.org, rodrigo.vivi@intel.com, thomas.hellstrom@linux.intel.com Content-Type: text/plain; charset="UTF-8" On Thu, Apr 22, 2021 at 4:17 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 > --- > drivers/of/address.c | 25 +++++++++++++++++++++++++ > drivers/of/device.c | 3 +++ > drivers/of/of_private.h | 5 +++++ > 3 files changed, 33 insertions(+) > > diff --git a/drivers/of/address.c b/drivers/of/address.c > index 54f221dde267..fff3adfe4986 100644 > --- a/drivers/of/address.c > +++ b/drivers/of/address.c > @@ -8,6 +8,7 @@ > #include > #include > #include > +#include > #include > #include > #include > @@ -1109,6 +1110,30 @@ bool of_dma_is_coherent(struct device_node *np) > } > EXPORT_SYMBOL_GPL(of_dma_is_coherent); > > +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)); > + for (i = 0; i < count; i++) { > + node = of_parse_phandle(dev->of_node, "memory-region", i); > + /* There might be multiple memory regions, but only one > + * restriced-dma-pool region is allowed. > + */ > + if (of_device_is_compatible(node, "restricted-dma-pool") && > + of_device_is_available(node)) > + return of_reserved_mem_device_init_by_idx( > + dev, dev->of_node, i); > + } > + > + return 0; > +} > + > /** > * of_mmio_is_nonposted - Check if device uses non-posted MMIO > * @np: device node > diff --git a/drivers/of/device.c b/drivers/of/device.c > index c5a9473a5fb1..d8d865223e51 100644 > --- a/drivers/of/device.c > +++ b/drivers/of/device.c > @@ -165,6 +165,9 @@ int of_dma_configure_id(struct device *dev, struct device_node *np, > > arch_setup_dma_ops(dev, dma_start, size, iommu, coherent); > > + 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 d717efbd637d..e9237f5eff48 100644 > --- a/drivers/of/of_private.h > +++ b/drivers/of/of_private.h > @@ -163,12 +163,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) This one should be of_dma_set_restricted_buffer. Sorry for the typo. > +{ > + return -ENODEV; > +} > #endif > > #endif /* _LINUX_OF_PRIVATE_H */ > -- > 2.31.1.368.gbe11c130af-goog >