mirror of
git://nv-tegra.nvidia.com/linux-nv-oot.git
synced 2025-12-24 02:01:36 +03:00
drm/tegra: Support context isolation
For engines that support context isolation, allocate a context when opening a channel, and set up stream ID offset and context fields when submitting a job. As of this commit, the stream ID offset and fallback stream ID are not used when context isolation is disabled. However, with upcoming patches that enable a full featured job opcode sequence, these will be necessary. Bug 3724727 Signed-off-by: Mikko Perttunen <mperttunen@nvidia.com> Change-Id: Ic57b04d8240ef19a1b82361e5ca8d07119f08652
This commit is contained in:
committed by
Laxman Dewangan
parent
250d164381
commit
f3b009a8e6
@@ -33,6 +33,9 @@ static void tegra_drm_channel_context_close(struct tegra_drm_context *context)
|
||||
struct tegra_drm_mapping *mapping;
|
||||
unsigned long id;
|
||||
|
||||
if (context->memory_context)
|
||||
host1x_memory_context_put(context->memory_context);
|
||||
|
||||
xa_for_each(&context->mappings, id, mapping)
|
||||
tegra_drm_mapping_put(mapping);
|
||||
|
||||
@@ -72,6 +75,7 @@ static struct tegra_drm_client *tegra_drm_find_client(struct tegra_drm *tegra, u
|
||||
|
||||
int tegra_drm_ioctl_channel_open(struct drm_device *drm, void *data, struct drm_file *file)
|
||||
{
|
||||
struct host1x *host = tegra_drm_to_host1x(drm->dev_private);
|
||||
struct tegra_drm_file *fpriv = file->driver_priv;
|
||||
struct tegra_drm *tegra = drm->dev_private;
|
||||
struct drm_tegra_channel_open *args = data;
|
||||
@@ -102,10 +106,36 @@ int tegra_drm_ioctl_channel_open(struct drm_device *drm, void *data, struct drm_
|
||||
}
|
||||
}
|
||||
|
||||
/* Only allocate context if the engine supports context isolation. */
|
||||
if (device_iommu_mapped(client->base.dev) && client->ops->can_use_memory_ctx) {
|
||||
bool supported;
|
||||
|
||||
err = client->ops->can_use_memory_ctx(client, &supported);
|
||||
if (err)
|
||||
goto put_channel;
|
||||
|
||||
if (supported)
|
||||
context->memory_context = host1x_memory_context_alloc(
|
||||
host, get_task_pid(current, PIDTYPE_TGID));
|
||||
|
||||
if (IS_ERR(context->memory_context)) {
|
||||
if (PTR_ERR(context->memory_context) != -EOPNOTSUPP) {
|
||||
err = PTR_ERR(context->memory_context);
|
||||
goto put_channel;
|
||||
} else {
|
||||
/*
|
||||
* OK, HW does not support contexts or contexts
|
||||
* are disabled.
|
||||
*/
|
||||
context->memory_context = NULL;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
err = xa_alloc(&fpriv->contexts, &args->context, context, XA_LIMIT(1, U32_MAX),
|
||||
GFP_KERNEL);
|
||||
if (err < 0)
|
||||
goto put_channel;
|
||||
goto put_memctx;
|
||||
|
||||
context->client = client;
|
||||
xa_init_flags(&context->mappings, XA_FLAGS_ALLOC1);
|
||||
@@ -118,6 +148,9 @@ int tegra_drm_ioctl_channel_open(struct drm_device *drm, void *data, struct drm_
|
||||
|
||||
return 0;
|
||||
|
||||
put_memctx:
|
||||
if (context->memory_context)
|
||||
host1x_memory_context_put(context->memory_context);
|
||||
put_channel:
|
||||
host1x_channel_put(context->channel);
|
||||
free:
|
||||
@@ -156,6 +189,7 @@ int tegra_drm_ioctl_channel_map(struct drm_device *drm, void *data, struct drm_f
|
||||
struct tegra_drm_mapping *mapping;
|
||||
struct tegra_drm_context *context;
|
||||
enum dma_data_direction direction;
|
||||
struct device *mapping_dev;
|
||||
int err = 0;
|
||||
|
||||
if (args->flags & ~DRM_TEGRA_CHANNEL_MAP_READ_WRITE)
|
||||
@@ -177,6 +211,11 @@ 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;
|
||||
else
|
||||
mapping_dev = context->client->base.dev;
|
||||
|
||||
mapping->bo = tegra_gem_lookup(file, args->handle);
|
||||
if (!mapping->bo) {
|
||||
err = -EINVAL;
|
||||
@@ -201,7 +240,7 @@ int tegra_drm_ioctl_channel_map(struct drm_device *drm, void *data, struct drm_f
|
||||
goto put_gem;
|
||||
}
|
||||
|
||||
mapping->map = host1x_bo_pin(context->client->base.dev, mapping->bo, direction, NULL);
|
||||
mapping->map = host1x_bo_pin(mapping_dev, mapping->bo, direction, NULL);
|
||||
if (IS_ERR(mapping->map)) {
|
||||
err = PTR_ERR(mapping->map);
|
||||
goto put_gem;
|
||||
|
||||
Reference in New Issue
Block a user