Commit d306788b authored by Lucas Stach's avatar Lucas Stach

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: default avatarLucas Stach <l.stach@pengutronix.de>
Reviewed-by: default avatarPhilipp Zabel <p.zabel@pengutronix.de>
parent df622729
...@@ -56,6 +56,11 @@ static int etnaviv_open(struct drm_device *dev, struct drm_file *file) ...@@ -56,6 +56,11 @@ static int etnaviv_open(struct drm_device *dev, struct drm_file *file)
if (!ctx) if (!ctx)
return -ENOMEM; return -ENOMEM;
ret = xa_alloc_cyclic(&priv->active_contexts, &ctx->id, ctx,
xa_limit_32b, &priv->next_context_id, GFP_KERNEL);
if (ret < 0)
goto out_free;
ctx->mmu = etnaviv_iommu_context_init(priv->mmu_global, ctx->mmu = etnaviv_iommu_context_init(priv->mmu_global,
priv->cmdbuf_suballoc); priv->cmdbuf_suballoc);
if (!ctx->mmu) { if (!ctx->mmu) {
...@@ -99,6 +104,8 @@ static void etnaviv_postclose(struct drm_device *dev, struct drm_file *file) ...@@ -99,6 +104,8 @@ static void etnaviv_postclose(struct drm_device *dev, struct drm_file *file)
etnaviv_iommu_context_put(ctx->mmu); etnaviv_iommu_context_put(ctx->mmu);
xa_erase(&priv->active_contexts, ctx->id);
kfree(ctx); kfree(ctx);
} }
...@@ -514,6 +521,8 @@ static int etnaviv_bind(struct device *dev) ...@@ -514,6 +521,8 @@ static int etnaviv_bind(struct device *dev)
dma_set_max_seg_size(dev, SZ_2G); dma_set_max_seg_size(dev, SZ_2G);
xa_init_flags(&priv->active_contexts, XA_FLAGS_ALLOC);
mutex_init(&priv->gem_lock); mutex_init(&priv->gem_lock);
INIT_LIST_HEAD(&priv->gem_list); INIT_LIST_HEAD(&priv->gem_list);
priv->num_gpus = 0; priv->num_gpus = 0;
...@@ -563,6 +572,8 @@ static void etnaviv_unbind(struct device *dev) ...@@ -563,6 +572,8 @@ static void etnaviv_unbind(struct device *dev)
etnaviv_cmdbuf_suballoc_destroy(priv->cmdbuf_suballoc); etnaviv_cmdbuf_suballoc_destroy(priv->cmdbuf_suballoc);
xa_destroy(&priv->active_contexts);
drm->dev_private = NULL; drm->dev_private = NULL;
kfree(priv); kfree(priv);
......
...@@ -29,6 +29,7 @@ struct etnaviv_iommu_global; ...@@ -29,6 +29,7 @@ struct etnaviv_iommu_global;
#define ETNAVIV_SOFTPIN_START_ADDRESS SZ_4M /* must be >= SUBALLOC_SIZE */ #define ETNAVIV_SOFTPIN_START_ADDRESS SZ_4M /* must be >= SUBALLOC_SIZE */
struct etnaviv_file_private { struct etnaviv_file_private {
int id;
struct etnaviv_iommu_context *mmu; struct etnaviv_iommu_context *mmu;
struct drm_sched_entity sched_entity[ETNA_MAX_PIPES]; struct drm_sched_entity sched_entity[ETNA_MAX_PIPES];
}; };
...@@ -41,6 +42,9 @@ struct etnaviv_drm_private { ...@@ -41,6 +42,9 @@ struct etnaviv_drm_private {
struct etnaviv_cmdbuf_suballoc *cmdbuf_suballoc; struct etnaviv_cmdbuf_suballoc *cmdbuf_suballoc;
struct etnaviv_iommu_global *mmu_global; struct etnaviv_iommu_global *mmu_global;
struct xarray active_contexts;
u32 next_context_id;
/* list of GEM objects: */ /* list of GEM objects: */
struct mutex gem_lock; struct mutex gem_lock;
struct list_head gem_list; struct list_head gem_list;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment