[PATCH v2 03/13] gpu: host1x: Migrate to generic dma context bus

Vishnu Reddy
2026-04-23T13:30:27Z

From: Ekansh Gupta <ekansh.gupta@oss.qualcomm.com>

The host1x driver creates context bank devices to map IOMMU contexts
for memory isolation. Previously, this required a host1x-specific bus
type with its own device setup and IOMMU configuration logic.

A generic "dma-context-bus" is now available in the driver core that
handles this for any driver. Replace the host1x-specific bus with this
shared generic bus. This removes the private bus registration, device
setup, and of_dma_configure_id() from host1x, as the generic bus handles
all of this internally.

The IOMMU subsystem is also updated to reference the generic bus instead
of the host1x-specific one.

Signed-off-by: Ekansh Gupta <ekansh.gupta@oss.qualcomm.com>
Signed-off-by: Vishnu Reddy <busanna.reddy@oss.qualcomm.com>
---
drivers/gpu/drm/tegra/uapi.c | 2 +-
drivers/gpu/host1x/Kconfig | 5 +---
drivers/gpu/host1x/Makefile | 1 -
drivers/gpu/host1x/context.c | 47 ++++++++++++--------------------------
drivers/gpu/host1x/context.h | 3 +--
drivers/gpu/host1x/context_bus.c | 26 ---------------------
drivers/iommu/iommu.c | 6 ++---
include/linux/host1x.h | 2 +-
include/linux/host1x_context_bus.h | 15 ------------
9 files changed, 21 insertions(+), 86 deletions(-)

diff --git a/drivers/gpu/drm/tegra/uapi.c b/drivers/gpu/drm/tegra/uapi.c
index c0ac6b45f2d7..9547725a6c3c 100644
--- a/drivers/gpu/drm/tegra/uapi.c
+++ b/drivers/gpu/drm/tegra/uapi.c
@@ -215,7 +215,7 @@ int tegra_drm_ioctl_channel_map(struct drm_device *drm, void *data, struct drm_f
kref_init(&mapping->ref);

if (context->memory_context)
- mapping_dev = &context->memory_context->dev;
+ mapping_dev = context->memory_context->dev;
else
mapping_dev = context->client->base.dev;

diff --git a/drivers/gpu/host1x/Kconfig b/drivers/gpu/host1x/Kconfig
index e6c78ae2003a..0539ff057a51 100644
--- a/drivers/gpu/host1x/Kconfig
+++ b/drivers/gpu/host1x/Kconfig
@@ -1,13 +1,10 @@
# SPDX-License-Identifier: GPL-2.0-only

-config TEGRA_HOST1X_CONTEXT_BUS
- bool
-
config TEGRA_HOST1X
tristate "NVIDIA Tegra host1x driver"
depends on ARCH_TEGRA || COMPILE_TEST
select DMA_SHARED_BUFFER
- select TEGRA_HOST1X_CONTEXT_BUS
+ select DMA_CONTEXT_BUS
select IOMMU_IOVA
help
Driver for the NVIDIA Tegra host1x hardware.
diff --git a/drivers/gpu/host1x/Makefile b/drivers/gpu/host1x/Makefile
index fead483af0b4..2ccd9a5f1c65 100644
--- a/drivers/gpu/host1x/Makefile
+++ b/drivers/gpu/host1x/Makefile
@@ -23,4 +23,3 @@ host1x-$(CONFIG_IOMMU_API) += \
context.o

obj-$(CONFIG_TEGRA_HOST1X) += host1x.o
-obj-$(CONFIG_TEGRA_HOST1X_CONTEXT_BUS) += context_bus.o
diff --git a/drivers/gpu/host1x/context.c b/drivers/gpu/host1x/context.c
index d50d41c20561..ab7b156ab002 100644
--- a/drivers/gpu/host1x/context.c
+++ b/drivers/gpu/host1x/context.c
@@ -13,16 +13,12 @@
#include "context.h"
#include "dev.h"

-static void host1x_memory_context_release(struct device *dev)
-{
- /* context device is freed in host1x_memory_context_list_free() */
-}
-
int host1x_memory_context_list_init(struct host1x *host1x)
{
struct host1x_memory_context_list *cdl = &host1x->context_list;
struct device_node *node = host1x->dev->of_node;
struct host1x_memory_context *ctx;
+ struct device *dev;
unsigned int i;
int err;

@@ -44,42 +40,27 @@ int host1x_memory_context_list_init(struct host1x *host1x)

ctx->host = host1x;

- device_initialize(&ctx->dev);
-
/*
* Due to an issue with T194 NVENC, only 38 bits can be used.
* Anyway, 256GiB of IOVA ought to be enough for anyone.
*/
ctx->dma_mask = DMA_BIT_MASK(38);
- ctx->dev.dma_mask = &ctx->dma_mask;
- ctx->dev.coherent_dma_mask = ctx->dma_mask;
- dev_set_name(&ctx->dev, "host1x-ctx.%d", i);
- ctx->dev.bus = &host1x_context_device_bus_type;
- ctx->dev.parent = host1x->dev;
- ctx->dev.release = host1x_memory_context_release;
-
- ctx->dev.dma_parms = &ctx->dma_parms;
- dma_set_max_seg_size(&ctx->dev, UINT_MAX);
-
- err = device_add(&ctx->dev);
- if (err) {
+
+ dev = create_dma_context_bus_device(host1x->dev, NULL, ctx->dma_mask, &i);
+ if (IS_ERR(dev)) {
+ err = PTR_ERR(dev);
dev_err(host1x->dev, "could not add context device %d: %d\n", i, err);
- put_device(&ctx->dev);
goto unreg_devices;
}

- err = of_dma_configure_id(&ctx->dev, node, true, &i);
- if (err) {
- dev_err(host1x->dev, "IOMMU configuration failed for context device %d: %d\n",
- i, err);
- device_unregister(&ctx->dev);
- goto unreg_devices;
- }
+ ctx->dev = dev;
+ ctx->dev->dma_parms = &ctx->dma_parms;
+ dma_set_max_seg_size(ctx->dev, UINT_MAX);

- if (!tegra_dev_iommu_get_stream_id(&ctx->dev, &ctx->stream_id) ||
- !device_iommu_mapped(&ctx->dev)) {
+ if (!tegra_dev_iommu_get_stream_id(ctx->dev, &ctx->stream_id) ||
+ !device_iommu_mapped(ctx->dev)) {
dev_err(host1x->dev, "Context device %d has no IOMMU!\n", i);
- device_unregister(&ctx->dev);
+ device_unregister(ctx->dev);

/*
* This means that if IOMMU is disabled but context devices
@@ -96,7 +77,7 @@ int host1x_memory_context_list_init(struct host1x *host1x)

unreg_devices:
while (i--)
- device_unregister(&cdl->devs[i].dev);
+ device_unregister(cdl->devs[i].dev);

kfree(cdl->devs);
cdl->devs = NULL;
@@ -110,7 +91,7 @@ void host1x_memory_context_list_free(struct host1x_memory_context_list *cdl)
unsigned int i;

for (i = 0; i < cdl->len; i++)
- device_unregister(&cdl->devs[i].dev);
+ device_unregister(cdl->devs[i].dev);

kfree(cdl->devs);
cdl->len = 0;
@@ -132,7 +113,7 @@ struct host1x_memory_context *host1x_memory_context_alloc(struct host1x *host1x,
for (i = 0; i < cdl->len; i++) {
struct host1x_memory_context *cd = &cdl->devs[i];

- if (cd->dev.iommu->iommu_dev != dev->iommu->iommu_dev)
+ if (cd->dev->iommu->iommu_dev != dev->iommu->iommu_dev)
continue;

if (cd->owner == pid) {
diff --git a/drivers/gpu/host1x/context.h b/drivers/gpu/host1x/context.h
index 3e03bc1d3bac..558638c457d6 100644
--- a/drivers/gpu/host1x/context.h
+++ b/drivers/gpu/host1x/context.h
@@ -8,13 +8,12 @@
#ifndef __HOST1X_CONTEXT_H
#define __HOST1X_CONTEXT_H

+#include <linux/dma_context_bus.h>
#include <linux/mutex.h>
#include <linux/refcount.h>

struct host1x;

-extern struct bus_type host1x_context_device_bus_type;
-
struct host1x_memory_context_list {
struct mutex lock;
struct host1x_memory_context *devs;
diff --git a/drivers/gpu/host1x/context_bus.c b/drivers/gpu/host1x/context_bus.c
deleted file mode 100644
index 7cd0e1a5edd1..000000000000
--- a/drivers/gpu/host1x/context_bus.c
+++ /dev/null
@@ -1,26 +0,0 @@
-// SPDX-License-Identifier: GPL-2.0-only
-/*
- * Copyright (c) 2021, NVIDIA Corporation.
- */
-
-#include <linux/device.h>
-#include <linux/of.h>
-
-const struct bus_type host1x_context_device_bus_type = {
- .name = "host1x-context",
-};
-EXPORT_SYMBOL_GPL(host1x_context_device_bus_type);
-
-static int __init host1x_context_device_bus_init(void)
-{
- int err;
-
- err = bus_register(&host1x_context_device_bus_type);
- if (err < 0) {
- pr_err("bus type registration failed: %d\n", err);
- return err;
- }
-
- return 0;
-}
-postcore_initcall(host1x_context_device_bus_init);
diff --git a/drivers/iommu/iommu.c b/drivers/iommu/iommu.c
index 61c12ba78206..5d0fad1402eb 100644
--- a/drivers/iommu/iommu.c
+++ b/drivers/iommu/iommu.c
@@ -16,7 +16,7 @@
#include <linux/export.h>
#include <linux/slab.h>
#include <linux/errno.h>
-#include <linux/host1x_context_bus.h>
+#include <linux/dma_context_bus.h>
#include <linux/iommu.h>
#include <linux/iommufd.h>
#include <linux/idr.h>
@@ -173,8 +173,8 @@ static const struct bus_type * const iommu_buses[] = {
#ifdef CONFIG_FSL_MC_BUS
&fsl_mc_bus_type,
#endif
-#ifdef CONFIG_TEGRA_HOST1X_CONTEXT_BUS
- &host1x_context_device_bus_type,
+#ifdef CONFIG_DMA_CONTEXT_BUS
+ &dma_context_bus_type,
#endif
#ifdef CONFIG_CDX_BUS
&cdx_bus_type,
diff --git a/include/linux/host1x.h b/include/linux/host1x.h
index 1f5f55917d1c..30dbb3a71828 100644
--- a/include/linux/host1x.h
+++ b/include/linux/host1x.h
@@ -462,7 +462,7 @@ struct host1x_memory_context {
struct pid *owner;

struct device_dma_parameters dma_parms;
- struct device dev;
+ struct device *dev;
u64 dma_mask;
u32 stream_id;
};
diff --git a/include/linux/host1x_context_bus.h b/include/linux/host1x_context_bus.h
deleted file mode 100644
index c928cb432680..000000000000
--- a/include/linux/host1x_context_bus.h
+++ /dev/null
@@ -1,15 +0,0 @@
-/* SPDX-License-Identifier: GPL-2.0-or-later */
-/*
- * Copyright (c) 2021, NVIDIA Corporation. All rights reserved.
- */
-
-#ifndef __LINUX_HOST1X_CONTEXT_BUS_H
-#define __LINUX_HOST1X_CONTEXT_BUS_H
-
-#include <linux/device.h>
-
-#ifdef CONFIG_TEGRA_HOST1X_CONTEXT_BUS
-extern const struct bus_type host1x_context_device_bus_type;
-#endif
-
-#endif

--
2.34.1