Received: by 2002:a05:6a10:f3d0:0:0:0:0 with SMTP id a16csp337094pxv; Thu, 24 Jun 2021 09:00:54 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwwubeQMWFIQ04Va4HvQBTEYrtkKD8xrpvx0EklYDxxUVTsfzoKPuk+q9UPthtO2sJBzrzI X-Received: by 2002:a05:6402:1655:: with SMTP id s21mr8234994edx.295.1624550454024; Thu, 24 Jun 2021 09:00:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1624550454; cv=none; d=google.com; s=arc-20160816; b=oY1GEttIo1RLfmJVOFn2AMH/Rcgd4sPkjIeGOgYvqehOgmhtGnDaRuOg2rGlC69+xL kJHmGlvq+M6u6n7oCwqwKlF6BZD3GJ1qI/zmm7Xbzo2iKOOUHh2reCleNl6YnpLhaJf2 68xERaZmXoSygwFs0YkVqMpUOq8rron8oDfqAZ4GlegPd/6aXmzx3obpJzXLowYvee9x qAkLa4eAyF+vP7Z0ejsooEZb/bUUrlbk58ydGc66YN6qHMMHa2PEcOC9YGNHJijlr465 0UQbkeFv9/vpQsirh9adNnkBgEmm1WK4lD/X0M5lkqgBICLMH3rsykpNtQEwxCyDroed Ln3A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=xfRvKXXPDGozL9xpkc2RXgCWY6OxEYfQN41+lxoFnvY=; b=JWzW8x53ttYWTHU6PUzEepJAZxNWVvIQCmT54ljqKnthiX21Msi0wDObM/IeNkpiyM oMJiB+zFpREE83e8weYws9Bp8xkH+xgOd600ic0xp7yDaowfsqcPNICNS8wEaOBTp0+C Hfrge14UwbUXfxlW3QD1zAW3rAPO0YXKMFgJd6I8MBSyqf25iLt85eFP8H+70871ULeR fo9AfOCHLxAqC78HOOCX9Odtqzbe0ZzvSpmF2rESXqZ7WcQ0lRNQvgOU87sacS/iTPtp U/fZ1xjiw8MGdRd3gNhPVOZ1sEBWPLhXxYICV+9m5gSRssvfNm5ecSFC2T6VjQQXh2U7 0gIg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=kEshnj7M; 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 e23si2917935ejm.173.2021.06.24.09.00.29; Thu, 24 Jun 2021 09:00:54 -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=@chromium.org header.s=google header.b=kEshnj7M; 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 S232596AbhFXP7t (ORCPT + 99 others); Thu, 24 Jun 2021 11:59:49 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36328 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232600AbhFXP7r (ORCPT ); Thu, 24 Jun 2021 11:59:47 -0400 Received: from mail-pj1-x102e.google.com (mail-pj1-x102e.google.com [IPv6:2607:f8b0:4864:20::102e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6FA76C06175F for ; Thu, 24 Jun 2021 08:57:28 -0700 (PDT) Received: by mail-pj1-x102e.google.com with SMTP id h23so3747012pjv.2 for ; Thu, 24 Jun 2021 08:57:28 -0700 (PDT) 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=xfRvKXXPDGozL9xpkc2RXgCWY6OxEYfQN41+lxoFnvY=; b=kEshnj7M08k1T5XsbOYdzjZbq7nVnmjng6eJnfjl4lHMzaAZWk6m94BUgoAkO9vE9h LGUHt/CR+GHi3cdJm3u8om1RbudjT01C0RCIVYBXBb3iKIFLf6Hz/aFd03GLLTot9C9q is4g5Rc9w98QwWpmpTahpJ12S/0U2a21x3Eus= 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=xfRvKXXPDGozL9xpkc2RXgCWY6OxEYfQN41+lxoFnvY=; b=f1T0HnFBZmAKCFyiDC9UHn+wDGdmJaqpuFOlwduvEF3Ubdp/ENP7xTJ6oV0G9tEdyY C6oxKN8KOS55S0rYkrzmYtY9pLxksR6SMpbYKfYA4shGR/jOxKZ5D3JRX0gegykEty+q sh8gBHkP8Ea3IMDw9GU3aCrjF1YO80/OGoQsNB2ePBqw3oo0jAR1wgdcmf0OSqKeDVYY TVfTGXUZ8+oVuUXoS+yh8Ga5bQIbILbXkbjB0bFCKUYWM7LU8jzH43YbwK+CRpT8PgfO 2OtQEVclXTKYgkRMSNFJDAHakYGE1iiZygH9YsSzIH6W+KHOVyUMwY0CiauODd53Uimr KBow== X-Gm-Message-State: AOAM5300kTgMs5mNIqT6g+QKLUDBe0Uz3HL9zkqr7iGwka2CYLv9pHTo HKJ+QF4Bktgm7mJuHYtJwipn1w== X-Received: by 2002:a17:90b:2282:: with SMTP id kx2mr5939882pjb.60.1624550248050; Thu, 24 Jun 2021 08:57:28 -0700 (PDT) Received: from localhost ([2401:fa00:95:205:165a:99ec:42d5:d8b]) by smtp.gmail.com with UTF8SMTPSA id n6sm2862924pgt.7.2021.06.24.08.57.20 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 24 Jun 2021 08:57:27 -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, thomas.lendacky@amd.com, quic_qiancai@quicinc.com Subject: [PATCH v15 12/12] of: Add plumbing for restricted DMA pool Date: Thu, 24 Jun 2021 23:55:26 +0800 Message-Id: <20210624155526.2775863-13-tientzu@chromium.org> X-Mailer: git-send-email 2.32.0.288.g62a8d224e6-goog In-Reply-To: <20210624155526.2775863-1-tientzu@chromium.org> References: <20210624155526.2775863-1-tientzu@chromium.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 Tested-by: Stefano Stabellini Tested-by: Will Deacon --- 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 struct bus_dma_region **map) of_node_put(node); return ret; } + +int of_dma_set_restricted_buffer(struct device *dev, struct device_node *np) +{ + struct device_node *node, *of_node = dev->of_node; + int count, i; + + count = 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 <= 0) { + of_node = np; + count = of_property_count_elems_of_size( + of_node, "memory-region", sizeof(u32)); + } + + for (i = 0; i < count; i++) { + node = 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 */ /** 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 device_node *np, arch_setup_dma_ops(dev, dma_start, size, iommu, coherent); + 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 *np); #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 #endif /* _LINUX_OF_PRIVATE_H */ -- 2.32.0.288.g62a8d224e6-goog