Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id E9F77C433EF for ; Sun, 3 Oct 2021 18:35:00 +0000 (UTC) Received: from phobos.denx.de (phobos.denx.de [85.214.62.61]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 2AB3D619E0 for ; Sun, 3 Oct 2021 18:35:00 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 2AB3D619E0 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=openbsd.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=lists.denx.de Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 2118383436; Sun, 3 Oct 2021 20:34:45 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=none (p=none dis=none) header.from=openbsd.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Received: by phobos.denx.de (Postfix, from userid 109) id C931882EE0; Sun, 3 Oct 2021 20:31:37 +0200 (CEST) Received: from lb3-smtp-cloud7.xs4all.net (lb3-smtp-cloud7.xs4all.net [194.109.24.31]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id 3EAFF83124 for ; Sun, 3 Oct 2021 20:31:33 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=none (p=none dis=none) header.from=openbsd.org Authentication-Results: phobos.denx.de; spf=fail smtp.mailfrom=kettenis@openbsd.org Received: from cust-df1d398c ([IPv6:fc0c:c1f5:9ac0:c45f:1583:5c5b:91fa:2436]) by smtp-cloud7.xs4all.net with ESMTPA id X6GJmiwcM3tiGX6GqmelUk; Sun, 03 Oct 2021 20:31:33 +0200 From: Mark Kettenis To: u-boot@lists.denx.de Cc: Mark Kettenis , Bharat Gooty , Rayagonda Kokatanur , Simon Glass , Andre Przywara , Fabio Estevam , Jagan Teki , Kever Yang , Priyanka Jain , Peter Robinson , Tim Harvey , Konstantin Porotchkin , Heiko Schocher , Lokesh Vutla , Bin Meng , Dario Binacchi , Neil Armstrong , Sean Anderson , Nandor Han , Heinrich Schuchardt , Claudiu Manoil , Jean-Jacques Hiblot , Michael Walle , Patrick Delaunay , Joe Hershberger , Matthias Brugger , =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20Danis?= , AKASHI Takahiro , Wasim Khan , Alexandru Gagniuc , Pratyush Yadav , Steffen Jaeckel , Nicolas Saenz Julienne , Asherah Connor , Oliver Graute , Tianrui Wei , Padmarao Begari , Stephan Gerhold , Masami Hiramatsu , Kishon Vijay Abraham I , Kunihiko Hayashi , Philippe Reynes , Stefan Roese , Michal Simek , Weijie Gao , =?UTF-8?q?Marek=20Beh=C3=BAn?= , Vabhav Sharma , Andy Shevchenko Subject: [PATCH v2 1/7] iommu: Add IOMMU uclass Date: Sun, 3 Oct 2021 20:30:27 +0200 Message-Id: <20211003183050.67925-2-kettenis@openbsd.org> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20211003183050.67925-1-kettenis@openbsd.org> References: <20211003183050.67925-1-kettenis@openbsd.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-CMAE-Envelope: MS4xfOflqEQar13J7ojXJ3FqriTD7YS+tB0saE4ixPJ7digU2g+EganzOvwx+VLqEz/Z+dP7cOqua8dL6vVCABScBQRKboGxEW+QuIzm3gLbNmzDhbvxfYl/ cGqOv5tbEPCku8xj28m/9tVOvYQDr8m5LjjiufWGXSLiqihz+ofq1dY/zcmn3t1yJH1UGK130e0dRrDtxiwpJrByk/lJXXspd111rUMQjp4QpE4BoZJPuXf9 ItlRSDMiEeAQpsNucQnEHatsG1kMIjFkXoJe5c5E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lLN4zFwlPVn+/N/6eL7JaNLx5AeDQ2X1FhTJGhqaTRVaUSdUXAIbHTiq7Hvj/q7CS13QrhOxWHaxZ5Cx2LzAWZQ1Gl5t+J 61890xC8GrDESKafwgImk2ESH/T8WKnu0h/AARVKasaNoIm+6fEic8XBzkZAko3zUShcdLdzJJR8iQResuGBm/qlIozJR7gPyax+M+Z6qc+uUJKOrZxbuoMD +rKB/uRP1kmm2lD6MKTonnB3ZH2BAIXQyN5qtJcq8y9m3m0YuV5OV5NF51Fjwb53A7yVkbYmQQgiT7m4IqiyAEn+LggYRP0sOzBXuJK6WSvKIwK64U+e2x7R T94ATcvuIJiQJl5yDFxkHGr/iELlrM/VGT/NTGkFY1eW4tz+GIK/1+4untd+2Vypvn/NyXp0p0Z0cANggpU5cgHGvs3DyJRGdFD5gR2AH40m8AvIK5U++kIO 4pIm/8V6/t1W+EQS9RC9bSZxqeHjMnXkg3yGM0C/Qfrhtm6YpFwsyoNnpvaFxw== X-Mailman-Approved-At: Sun, 03 Oct 2021 20:34:39 +0200 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.34 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.103.2 at phobos.denx.de X-Virus-Status: Clean This uclass is intended to manage IOMMUs on systems where the IOMMUs are not in bypass mode by default. In that case U-Boot cannot ignore the IOMMUs if it wants to use devices that need to do DMA and sit behind such an IOMMU. This initial IOMMU uclass implementation does not implement and device ops and is intended for IOMMUs that have a bypass mode that does not require address translation. Support for IOMMUs that do require address translation is planned and device ops will be defined when support for such IOMMUs will be added. Signed-off-by: Mark Kettenis --- drivers/Kconfig | 2 ++ drivers/Makefile | 1 + drivers/core/device.c | 8 +++++++ drivers/iommu/Kconfig | 13 +++++++++++ drivers/iommu/Makefile | 3 +++ drivers/iommu/iommu-uclass.c | 45 ++++++++++++++++++++++++++++++++++++ include/dm/uclass-id.h | 1 + include/iommu.h | 16 +++++++++++++ 8 files changed, 89 insertions(+) create mode 100644 drivers/iommu/Kconfig create mode 100644 drivers/iommu/Makefile create mode 100644 drivers/iommu/iommu-uclass.c create mode 100644 include/iommu.h diff --git a/drivers/Kconfig b/drivers/Kconfig index 417d6f88c2..b26ca8cf70 100644 --- a/drivers/Kconfig +++ b/drivers/Kconfig @@ -50,6 +50,8 @@ source "drivers/i2c/Kconfig" source "drivers/input/Kconfig" +source "drivers/iommu/Kconfig" + source "drivers/led/Kconfig" source "drivers/mailbox/Kconfig" diff --git a/drivers/Makefile b/drivers/Makefile index fd218c9056..166aeb9817 100644 --- a/drivers/Makefile +++ b/drivers/Makefile @@ -109,6 +109,7 @@ obj-y += mtd/ obj-y += pwm/ obj-y += reset/ obj-y += input/ +obj-y += iommu/ # SOC specific infrastructure drivers. obj-y += smem/ obj-y += thermal/ diff --git a/drivers/core/device.c b/drivers/core/device.c index 29668f6fb3..5f480ad443 100644 --- a/drivers/core/device.c +++ b/drivers/core/device.c @@ -28,6 +28,7 @@ #include #include #include +#include #include #include #include @@ -543,6 +544,13 @@ int device_probe(struct udevice *dev) goto fail; } + if (CONFIG_IS_ENABLED(IOMMU) && dev->parent && + (device_get_uclass_id(dev) != UCLASS_IOMMU)) { + ret = dev_iommu_probe(dev); + if (ret) + goto fail; + } + ret = device_get_dma_constraints(dev); if (ret) goto fail; diff --git a/drivers/iommu/Kconfig b/drivers/iommu/Kconfig new file mode 100644 index 0000000000..8cb377560e --- /dev/null +++ b/drivers/iommu/Kconfig @@ -0,0 +1,13 @@ +# +# IOMMU devices +# + +menu "IOMMU device drivers" + +config IOMMU + bool "Enable Driver Model for IOMMU drivers" + depends on DM + help + Enable driver model for IOMMU devices. + +endmenu diff --git a/drivers/iommu/Makefile b/drivers/iommu/Makefile new file mode 100644 index 0000000000..f1ceb10150 --- /dev/null +++ b/drivers/iommu/Makefile @@ -0,0 +1,3 @@ +# SPDX-License-Identifier: GPL-2.0+ + +obj-$(CONFIG_IOMMU) += iommu-uclass.o diff --git a/drivers/iommu/iommu-uclass.c b/drivers/iommu/iommu-uclass.c new file mode 100644 index 0000000000..5c55df3066 --- /dev/null +++ b/drivers/iommu/iommu-uclass.c @@ -0,0 +1,45 @@ +// SPDX-License-Identifier: GPL-2.0+ +/* + * Copyright (C) 2021 Mark Kettenis + */ + +#define LOG_CATEGORY UCLASS_IOMMU + +#include +#include + +#if (CONFIG_IS_ENABLED(OF_CONTROL) && !CONFIG_IS_ENABLED(OF_PLATDATA)) +int dev_iommu_probe(struct udevice *dev) +{ + struct ofnode_phandle_args args; + struct udevice *dev_iommu; + int i, count, ret = 0; + + count = dev_count_phandle_with_args(dev, "iommus", + "#iommu-cells", 0); + for (i = 0; i < count; i++) { + ret = dev_read_phandle_with_args(dev, "iommus", + "#iommu-cells", 0, i, &args); + if (ret) { + debug("%s: dev_read_phandle_with_args failed: %d\n", + __func__, ret); + return ret; + } + + ret = uclass_get_device_by_ofnode(UCLASS_IOMMU, args.node, + &dev_iommu); + if (ret) { + debug("%s: uclass_get_device_by_ofnode failed: %d\n", + __func__, ret); + return ret; + } + } + + return 0; +} +#endif + +UCLASS_DRIVER(iommu) = { + .id = UCLASS_IOMMU, + .name = "iommu", +}; diff --git a/include/dm/uclass-id.h b/include/dm/uclass-id.h index e7edd409f3..56aa981613 100644 --- a/include/dm/uclass-id.h +++ b/include/dm/uclass-id.h @@ -61,6 +61,7 @@ enum uclass_id { UCLASS_I2C_MUX, /* I2C multiplexer */ UCLASS_I2S, /* I2S bus */ UCLASS_IDE, /* IDE device */ + UCLASS_IOMMU, /* IOMMU */ UCLASS_IRQ, /* Interrupt controller */ UCLASS_KEYBOARD, /* Keyboard input device */ UCLASS_LED, /* Light-emitting diode (LED) */ diff --git a/include/iommu.h b/include/iommu.h new file mode 100644 index 0000000000..d17a06a6f3 --- /dev/null +++ b/include/iommu.h @@ -0,0 +1,16 @@ +#ifndef _IOMMU_H +#define _IOMMU_H + +struct udevice; + +#if (CONFIG_IS_ENABLED(OF_CONTROL) && !CONFIG_IS_ENABLED(OF_PLATDATA)) && \ + CONFIG_IS_ENABLED(IOMMU) +int dev_iommu_probe(struct udevice *dev); +#else +static inline int dev_iommu_probe(struct udevice *dev) +{ + return 0; +} +#endif + +#endif -- 2.33.0