Skip to content

Commit d306788

Browse files
committed
drm/etnaviv: allocate unique ID per drm_file
Allows to easily track if several fd are pointing to the same execution context due to being dup'ed. Signed-off-by: Lucas Stach <[email protected]> Reviewed-by: Philipp Zabel <[email protected]>
1 parent df62272 commit d306788

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed

drivers/gpu/drm/etnaviv/etnaviv_drv.c

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,11 @@ static int etnaviv_open(struct drm_device *dev, struct drm_file *file)
5656
if (!ctx)
5757
return -ENOMEM;
5858

59+
ret = xa_alloc_cyclic(&priv->active_contexts, &ctx->id, ctx,
60+
xa_limit_32b, &priv->next_context_id, GFP_KERNEL);
61+
if (ret < 0)
62+
goto out_free;
63+
5964
ctx->mmu = etnaviv_iommu_context_init(priv->mmu_global,
6065
priv->cmdbuf_suballoc);
6166
if (!ctx->mmu) {
@@ -99,6 +104,8 @@ static void etnaviv_postclose(struct drm_device *dev, struct drm_file *file)
99104

100105
etnaviv_iommu_context_put(ctx->mmu);
101106

107+
xa_erase(&priv->active_contexts, ctx->id);
108+
102109
kfree(ctx);
103110
}
104111

@@ -514,6 +521,8 @@ static int etnaviv_bind(struct device *dev)
514521

515522
dma_set_max_seg_size(dev, SZ_2G);
516523

524+
xa_init_flags(&priv->active_contexts, XA_FLAGS_ALLOC);
525+
517526
mutex_init(&priv->gem_lock);
518527
INIT_LIST_HEAD(&priv->gem_list);
519528
priv->num_gpus = 0;
@@ -563,6 +572,8 @@ static void etnaviv_unbind(struct device *dev)
563572

564573
etnaviv_cmdbuf_suballoc_destroy(priv->cmdbuf_suballoc);
565574

575+
xa_destroy(&priv->active_contexts);
576+
566577
drm->dev_private = NULL;
567578
kfree(priv);
568579

drivers/gpu/drm/etnaviv/etnaviv_drv.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ struct etnaviv_iommu_global;
2929
#define ETNAVIV_SOFTPIN_START_ADDRESS SZ_4M /* must be >= SUBALLOC_SIZE */
3030

3131
struct etnaviv_file_private {
32+
int id;
3233
struct etnaviv_iommu_context *mmu;
3334
struct drm_sched_entity sched_entity[ETNA_MAX_PIPES];
3435
};
@@ -41,6 +42,9 @@ struct etnaviv_drm_private {
4142
struct etnaviv_cmdbuf_suballoc *cmdbuf_suballoc;
4243
struct etnaviv_iommu_global *mmu_global;
4344

45+
struct xarray active_contexts;
46+
u32 next_context_id;
47+
4448
/* list of GEM objects: */
4549
struct mutex gem_lock;
4650
struct list_head gem_list;

0 commit comments

Comments
 (0)