From nobody Tue Feb 10 15:46:39 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass(p=none dis=none) header.from=chromium.org ARC-Seal: i=1; a=rsa-sha256; t=1623825131; cv=none; d=zohomail.com; s=zohoarc; b=Kc3oDkhbDqyeqP1dX5N0sROf+t8ylAtsgeNS4njCj8WRJnXjwsvhgGkJSaKInKPldIHDRX3I5BFk1hbMSOivOeHMbWK+0rJeMlFs/6xatjhgqm7Pk4acPHOqC6DM3o7TuMyg9pyESL4jgUYHdQ9vJCGSHJi16irfu+9mng26O3g= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1623825131; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=4psftO+uH/TVnoki1qOI27Xe5kV3FYGMoE+zQAlSb7o=; b=HsWDklizbb+9PiW295j7p7S4YHFQZ2m9Xz7AuFFbcc4cr9ykjnVWOTrbSu4T88LOUXdNj3Auu2kjJHJkZyTp9RbpyUj8RMLWBKbXhdR/vYB+uyeVIPG+9vK9OBc/dpEqOkxHHNryW/U9w6ADuSZ/QLFLKcI648l3OF6iXLNOZqk= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1623825131946545.6102111798923; Tue, 15 Jun 2021 23:32:11 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.142678.263216 (Exim 4.92) (envelope-from ) id 1ltP5h-0005LZ-7S; Wed, 16 Jun 2021 06:31:57 +0000 Received: by outflank-mailman (output) from mailman id 142678.263216; Wed, 16 Jun 2021 06:31:57 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1ltP5h-0005Kp-4K; Wed, 16 Jun 2021 06:31:57 +0000 Received: by outflank-mailman (input) for mailman id 142678; Wed, 16 Jun 2021 06:31:55 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1ltOy8-0007gS-JC for xen-devel@lists.xenproject.org; Wed, 16 Jun 2021 06:24:08 +0000 Received: from mail-pf1-x435.google.com (unknown [2607:f8b0:4864:20::435]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id 6b1491c1-09a5-4755-8e83-7151d1949dba; Wed, 16 Jun 2021 06:23:53 +0000 (UTC) Received: by mail-pf1-x435.google.com with SMTP id h12so1364045pfe.2 for ; Tue, 15 Jun 2021 23:23:53 -0700 (PDT) Received: from localhost ([2401:fa00:95:205:3d52:f252:7393:1992]) by smtp.gmail.com with UTF8SMTPSA id j13sm1144475pgp.29.2021.06.15.23.23.45 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 15 Jun 2021 23:23:51 -0700 (PDT) X-Outflank-Mailman: Message body and most headers restored to incoming version 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: 6b1491c1-09a5-4755-8e83-7151d1949dba DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=4psftO+uH/TVnoki1qOI27Xe5kV3FYGMoE+zQAlSb7o=; b=V/ahoq2vs8tTy7w+Y5OEwDE5hShbh8znTC5ewffraAkNPn/O4nZhX/k5O/Q4vn+BYw sVVqtxW5hQdZQN9GpVNrLf5hjnu+aW1hXGdh6T0neJbe4VzN1V/QXoB+hgAnMu1VsF+r sglWPBXIWMNhL2qZeTlT+lltwdWi+fBX8GceE= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=4psftO+uH/TVnoki1qOI27Xe5kV3FYGMoE+zQAlSb7o=; b=T9a7k/fArYc7db8jismCo8ZfdIYWi1h6jF5NYjL6cJS4DKQkIlIGgmjbKdPHamBxJF 2MKid/S/DpCnLRrekcBOax+p3peGmBzkbGMqZdNZrOqcHAmD+PMNcmoaJ0bdqyilxBgX w+DKF2/OUnfmjcKL3ve5cOTiiqUF9fJ1KpGV7ilUAAUhLKo8syr+H5Nu55qVMBCyqzlv 0N/eUkjfJ9jPA6xPz/qAfg+e939+vv8IpbzkHBs3te7lNP+yOAMwvJx7gWYyzmmzSoHh fcrWIjNS/7PJ2jzQbVECMxrRoBfA0CLoBhiWkfX8Ezr6Bc0jadhilUqKmaSJvqmBSGxX 3psw== X-Gm-Message-State: AOAM530zx047OZmtwOI0XrH8fQ7ZmozitofZpifemDzebqkxfZWAI/pa SKg4o31Pe6G1xtn/ffEGNw7cMw== X-Google-Smtp-Source: ABdhPJzGZYWYJboxtRbRv1n6aZlIOVWrHtwOTnE26briGp5Jug1JkMDb00dOZitCigU2dddBDVGa/Q== X-Received: by 2002:a62:ae03:0:b029:2f8:b04f:c012 with SMTP id q3-20020a62ae030000b02902f8b04fc012mr8079076pff.62.1623824632264; Tue, 15 Jun 2021 23:23:52 -0700 (PDT) From: Claire Chang To: Rob Herring , mpe@ellerman.id.au, 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 , tfiga@chromium.org, bskeggs@redhat.com, bhelgaas@google.com, chris@chris-wilson.co.uk, tientzu@chromium.org, 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, rodrigo.vivi@intel.com, thomas.hellstrom@linux.intel.com Subject: [PATCH v12 12/12] of: Add plumbing for restricted DMA pool Date: Wed, 16 Jun 2021 14:21:57 +0800 Message-Id: <20210616062157.953777-13-tientzu@chromium.org> X-Mailer: git-send-email 2.32.0.272.g935e593368-goog In-Reply-To: <20210616062157.953777-1-tientzu@chromium.org> References: <20210616062157.953777-1-tientzu@chromium.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @chromium.org) Content-Type: text/plain; charset="utf-8" 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 | 33 +++++++++++++++++++++++++++++++++ drivers/of/device.c | 3 +++ drivers/of/of_private.h | 6 ++++++ 3 files changed, 42 insertions(+) diff --git a/drivers/of/address.c b/drivers/of/address.c index 73ddf2540f3f..cdf700fba5c4 100644 --- a/drivers/of/address.c +++ b/drivers/of/address.c @@ -8,6 +8,7 @@ #include #include #include +#include #include #include #include @@ -1022,6 +1023,38 @@ int of_dma_get_range(struct device_node *np, const s= truct bus_dma_region **map) of_node_put(node); return ret; } + +int of_dma_set_restricted_buffer(struct device *dev, struct device_node *n= p) +{ + struct device_node *node, *of_node =3D dev->of_node; + int count, i; + + count =3D of_property_count_elems_of_size(of_node, "memory-region", + sizeof(u32)); + /* + * If dev->of_node doesn't exist or doesn't contain memory-region, try + * the OF node having DMA configuration. + */ + if (count <=3D 0) { + of_node =3D np; + count =3D of_property_count_elems_of_size( + of_node, "memory-region", sizeof(u32)); + } + + for (i =3D 0; i < count; i++) { + node =3D of_parse_phandle(of_node, "memory-region", i); + /* + * There might be multiple memory regions, but only one + * restricted-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, of_node, + i); + } + + return 0; +} #endif /* CONFIG_HAS_DMA */ =20 /** diff --git a/drivers/of/device.c b/drivers/of/device.c index 6cb86de404f1..e68316836a7a 100644 --- a/drivers/of/device.c +++ b/drivers/of/device.c @@ -165,6 +165,9 @@ int of_dma_configure_id(struct device *dev, struct devi= ce_node *np, =20 arch_setup_dma_ops(dev, dma_start, size, iommu, coherent); =20 + if (!iommu) + return of_dma_set_restricted_buffer(dev, np); + 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..25cebbed5f02 100644 --- a/drivers/of/of_private.h +++ b/drivers/of/of_private.h @@ -161,12 +161,18 @@ 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, struct device_node *n= p); #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_set_restricted_buffer(struct device *dev, + struct device_node *np) +{ + return -ENODEV; +} #endif =20 #endif /* _LINUX_OF_PRIVATE_H */ --=20 2.32.0.272.g935e593368-goog