All of lore.kernel.org
 help / color / mirror / Atom feed
From: Simon Glass <sjg@chromium.org>
To: Mark Kettenis <kettenis@openbsd.org>
Cc: "U-Boot Mailing List" <u-boot@lists.denx.de>,
	"Bharat Gooty" <bharat.gooty@broadcom.com>,
	"Rayagonda Kokatanur" <rayagonda.kokatanur@broadcom.com>,
	"Andre Przywara" <andre.przywara@arm.com>,
	"Fabio Estevam" <festevam@gmail.com>,
	"Jagan Teki" <jagan@amarulasolutions.com>,
	"Kever Yang" <kever.yang@rock-chips.com>,
	"Priyanka Jain" <priyanka.jain@nxp.com>,
	"Peter Robinson" <pbrobinson@gmail.com>,
	"Tim Harvey" <tharvey@gateworks.com>,
	"Konstantin Porotchkin" <kostap@marvell.com>,
	"Heiko Schocher" <hs@denx.de>,
	"Lokesh Vutla" <lokeshvutla@ti.com>,
	"Bin Meng" <bmeng.cn@gmail.com>,
	"Dario Binacchi" <dariobin@libero.it>,
	"Neil Armstrong" <narmstrong@baylibre.com>,
	"Sean Anderson" <sean.anderson@seco.com>,
	"Nandor Han" <nandor.han@vaisala.com>,
	"Heinrich Schuchardt" <xypron.glpk@gmx.de>,
	"Claudiu Manoil" <claudiu.manoil@nxp.com>,
	"Jean-Jacques Hiblot" <jjhiblot@ti.com>,
	"Michael Walle" <michael@walle.cc>,
	"Patrick Delaunay" <patrick.delaunay@foss.st.com>,
	"Joe Hershberger" <joe.hershberger@ni.com>,
	"Matthias Brugger" <mbrugger@suse.com>,
	"Frédéric Danis" <frederic.danis@collabora.com>,
	"AKASHI Takahiro" <takahiro.akashi@linaro.org>,
	"Wasim Khan" <wasim.khan@nxp.com>,
	"Alexandru Gagniuc" <mr.nuke.me@gmail.com>,
	"Pratyush Yadav" <p.yadav@ti.com>,
	"Steffen Jaeckel" <jaeckel-floss@eyet-services.de>,
	"Nicolas Saenz Julienne" <nsaenz@kernel.org>,
	"Asherah Connor" <ashe@kivikakk.ee>,
	"Oliver Graute" <oliver.graute@kococonnector.com>,
	"Tianrui Wei" <tianrui-wei@outlook.com>,
	"Padmarao Begari" <padmarao.begari@microchip.com>,
	"Stephan Gerhold" <stephan@gerhold.net>,
	"Masami Hiramatsu" <masami.hiramatsu@linaro.org>,
	"Kishon Vijay Abraham I" <kishon@ti.com>,
	"Kunihiko Hayashi" <hayashi.kunihiko@socionext.com>,
	"Philippe Reynes" <philippe.reynes@softathome.com>,
	"Stefan Roese" <sr@denx.de>,
	"Michal Simek" <michal.simek@xilinx.com>,
	"Weijie Gao" <weijie.gao@mediatek.com>,
	"Marek Behún" <marek.behun@nic.cz>,
	"Vabhav Sharma" <vabhav.sharma@nxp.com>,
	"Andy Shevchenko" <andriy.shevchenko@linux.intel.com>
Subject: Re: [PATCH v2 1/7] iommu: Add IOMMU uclass
Date: Mon, 11 Oct 2021 11:00:34 -0600	[thread overview]
Message-ID: <CAPnjgZ0ijbyvqz_kT1vmi2U=vNu6f49Vfea6ry3E5tSaUxRf3A@mail.gmail.com> (raw)
In-Reply-To: <20211003183050.67925-2-kettenis@openbsd.org>

Hi Mark,

On Sun, 3 Oct 2021 at 12:31, Mark Kettenis <kettenis@openbsd.org> wrote:
>
> 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 <kettenis@openbsd.org>
> ---
>  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 <dm/uclass.h>
>  #include <dm/uclass-internal.h>
>  #include <dm/util.h>
> +#include <iommu.h>
>  #include <linux/err.h>
>  #include <linux/list.h>
>  #include <power-domain.h>
> @@ -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.

Need at least three lines. What is an IOMMU? How does it relate to
other 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 <kettenis@openbsd.org>
> + */
> +
> +#define LOG_CATEGORY UCLASS_IOMMU
> +
> +#include <common.h>
> +#include <dm.h>
> +
> +#if (CONFIG_IS_ENABLED(OF_CONTROL) && !CONFIG_IS_ENABLED(OF_PLATDATA))
> +int dev_iommu_probe(struct udevice *dev)

Can we rename to dev_iommus_enable()? I like to keep probe for use by
DM itself so it is confusing to talk about probing in a context other
than probing a single device.

> +{
> +       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);

Do you have a binding file you can add to docs/device-tree-bindings ?

> +       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
>

Regards,
Simon

  reply	other threads:[~2021-10-11 17:04 UTC|newest]

Thread overview: 32+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-10-03 18:30 [PATCH v2 0/7] Apple M1 Support Mark Kettenis
2021-10-03 18:30 ` [PATCH v2 1/7] iommu: Add IOMMU uclass Mark Kettenis
2021-10-11 17:00   ` Simon Glass [this message]
2021-10-14 19:34     ` Mark Kettenis
2021-10-14 20:20       ` Simon Glass
2021-10-14 20:51         ` Mark Kettenis
2021-10-14 20:55           ` Simon Glass
2021-10-14 21:11             ` Mark Kettenis
2021-10-15  0:40               ` Simon Glass
2021-10-03 18:30 ` [PATCH v2 2/7] test: Add tests for " Mark Kettenis
2021-10-11 17:00   ` Simon Glass
2021-10-14 19:50     ` Mark Kettenis
2021-10-14 20:43       ` Simon Glass
2021-10-03 18:30 ` [PATCH v2 3/7] arm: apple: Add initial support for Apple's M1 SoC Mark Kettenis
2021-10-11 17:00   ` Simon Glass
2021-10-03 18:30 ` [PATCH v2 4/7] serial: s5p: Add Apple M1 support Mark Kettenis
2021-10-11 17:00   ` Simon Glass
2021-10-14 19:57     ` Mark Kettenis
2021-10-03 18:30 ` [PATCH v2 5/7] iommu: Add Apple DART driver Mark Kettenis
2021-10-11 17:00   ` Simon Glass
2021-10-03 18:30 ` [PATCH v2 6/7] arm: dts: apple: Add preliminary device trees Mark Kettenis
2021-10-11 17:00   ` Simon Glass
2021-10-11 18:36   ` Rob Herring
2021-10-11 18:55     ` Simon Glass
2021-10-11 19:00     ` Mark Kettenis
2021-10-11 19:48       ` Rob Herring
2021-10-11 20:00         ` Simon Glass
2021-10-11 20:30           ` Tom Rini
2021-10-14 20:33         ` Mark Kettenis
2021-10-03 18:30 ` [PATCH v2 7/7] doc: board: apple: Add Apple M1 documentation Mark Kettenis
2021-10-11 17:00   ` Simon Glass
2021-10-11 17:00 ` [PATCH v2 0/7] Apple M1 Support Simon Glass

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='CAPnjgZ0ijbyvqz_kT1vmi2U=vNu6f49Vfea6ry3E5tSaUxRf3A@mail.gmail.com' \
    --to=sjg@chromium.org \
    --cc=andre.przywara@arm.com \
    --cc=andriy.shevchenko@linux.intel.com \
    --cc=ashe@kivikakk.ee \
    --cc=bharat.gooty@broadcom.com \
    --cc=bmeng.cn@gmail.com \
    --cc=claudiu.manoil@nxp.com \
    --cc=dariobin@libero.it \
    --cc=festevam@gmail.com \
    --cc=frederic.danis@collabora.com \
    --cc=hayashi.kunihiko@socionext.com \
    --cc=hs@denx.de \
    --cc=jaeckel-floss@eyet-services.de \
    --cc=jagan@amarulasolutions.com \
    --cc=jjhiblot@ti.com \
    --cc=joe.hershberger@ni.com \
    --cc=kettenis@openbsd.org \
    --cc=kever.yang@rock-chips.com \
    --cc=kishon@ti.com \
    --cc=kostap@marvell.com \
    --cc=lokeshvutla@ti.com \
    --cc=marek.behun@nic.cz \
    --cc=masami.hiramatsu@linaro.org \
    --cc=mbrugger@suse.com \
    --cc=michael@walle.cc \
    --cc=michal.simek@xilinx.com \
    --cc=mr.nuke.me@gmail.com \
    --cc=nandor.han@vaisala.com \
    --cc=narmstrong@baylibre.com \
    --cc=nsaenz@kernel.org \
    --cc=oliver.graute@kococonnector.com \
    --cc=p.yadav@ti.com \
    --cc=padmarao.begari@microchip.com \
    --cc=patrick.delaunay@foss.st.com \
    --cc=pbrobinson@gmail.com \
    --cc=philippe.reynes@softathome.com \
    --cc=priyanka.jain@nxp.com \
    --cc=rayagonda.kokatanur@broadcom.com \
    --cc=sean.anderson@seco.com \
    --cc=sr@denx.de \
    --cc=stephan@gerhold.net \
    --cc=takahiro.akashi@linaro.org \
    --cc=tharvey@gateworks.com \
    --cc=tianrui-wei@outlook.com \
    --cc=u-boot@lists.denx.de \
    --cc=vabhav.sharma@nxp.com \
    --cc=wasim.khan@nxp.com \
    --cc=weijie.gao@mediatek.com \
    --cc=xypron.glpk@gmx.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.