Skip to content

Commit b0ef514

Browse files
brendan-kingMTCoster
authored andcommitted
drm/imagination: Add a per-file PVR context list
This adds a linked list of VM contexts which is needed for the next patch to be able to correctly track VM contexts for destruction on file close. It is only safe for VM contexts to be removed from the list and destroyed when not in interrupt context. Signed-off-by: Brendan King <[email protected]> Signed-off-by: Matt Coster <[email protected]> Reviewed-by: Frank Binns <[email protected]> Cc: [email protected] Link: https://patchwork.freedesktop.org/patch/msgid/[email protected]
1 parent add4163 commit b0ef514

File tree

4 files changed

+30
-0
lines changed

4 files changed

+30
-0
lines changed

drivers/gpu/drm/imagination/pvr_context.c

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,14 @@
1717

1818
#include <drm/drm_auth.h>
1919
#include <drm/drm_managed.h>
20+
21+
#include <linux/bug.h>
2022
#include <linux/errno.h>
2123
#include <linux/kernel.h>
24+
#include <linux/list.h>
2225
#include <linux/sched.h>
2326
#include <linux/slab.h>
27+
#include <linux/spinlock.h>
2428
#include <linux/string.h>
2529
#include <linux/types.h>
2630
#include <linux/xarray.h>
@@ -354,6 +358,10 @@ int pvr_context_create(struct pvr_file *pvr_file, struct drm_pvr_ioctl_create_co
354358
return err;
355359
}
356360

361+
spin_lock(&pvr_dev->ctx_list_lock);
362+
list_add_tail(&ctx->file_link, &pvr_file->contexts);
363+
spin_unlock(&pvr_dev->ctx_list_lock);
364+
357365
return 0;
358366

359367
err_destroy_fw_obj:
@@ -380,6 +388,11 @@ pvr_context_release(struct kref *ref_count)
380388
container_of(ref_count, struct pvr_context, ref_count);
381389
struct pvr_device *pvr_dev = ctx->pvr_dev;
382390

391+
WARN_ON(in_interrupt());
392+
spin_lock(&pvr_dev->ctx_list_lock);
393+
list_del(&ctx->file_link);
394+
spin_unlock(&pvr_dev->ctx_list_lock);
395+
383396
xa_erase(&pvr_dev->ctx_ids, ctx->ctx_id);
384397
pvr_context_destroy_queues(ctx);
385398
pvr_fw_object_destroy(ctx->fw_obj);
@@ -451,6 +464,7 @@ void pvr_destroy_contexts_for_file(struct pvr_file *pvr_file)
451464
void pvr_context_device_init(struct pvr_device *pvr_dev)
452465
{
453466
xa_init_flags(&pvr_dev->ctx_ids, XA_FLAGS_ALLOC1);
467+
spin_lock_init(&pvr_dev->ctx_list_lock);
454468
}
455469

456470
/**

drivers/gpu/drm/imagination/pvr_context.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,9 @@ struct pvr_context {
8585
/** @compute: Transfer queue. */
8686
struct pvr_queue *transfer;
8787
} queues;
88+
89+
/** @file_link: pvr_file PVR context list link. */
90+
struct list_head file_link;
8891
};
8992

9093
static __always_inline struct pvr_queue *

drivers/gpu/drm/imagination/pvr_device.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
#include <linux/kernel.h>
2424
#include <linux/math.h>
2525
#include <linux/mutex.h>
26+
#include <linux/spinlock_types.h>
2627
#include <linux/timer.h>
2728
#include <linux/types.h>
2829
#include <linux/wait.h>
@@ -293,6 +294,12 @@ struct pvr_device {
293294

294295
/** @sched_wq: Workqueue for schedulers. */
295296
struct workqueue_struct *sched_wq;
297+
298+
/**
299+
* @ctx_list_lock: Lock to be held when accessing the context list in
300+
* struct pvr_file.
301+
*/
302+
spinlock_t ctx_list_lock;
296303
};
297304

298305
/**
@@ -344,6 +351,9 @@ struct pvr_file {
344351
* This array is used to allocate handles returned to userspace.
345352
*/
346353
struct xarray vm_ctx_handles;
354+
355+
/** @contexts: PVR context list. */
356+
struct list_head contexts;
347357
};
348358

349359
/**

drivers/gpu/drm/imagination/pvr_drv.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
#include <linux/export.h>
2929
#include <linux/fs.h>
3030
#include <linux/kernel.h>
31+
#include <linux/list.h>
3132
#include <linux/mod_devicetable.h>
3233
#include <linux/module.h>
3334
#include <linux/moduleparam.h>
@@ -1326,6 +1327,8 @@ pvr_drm_driver_open(struct drm_device *drm_dev, struct drm_file *file)
13261327
*/
13271328
pvr_file->pvr_dev = pvr_dev;
13281329

1330+
INIT_LIST_HEAD(&pvr_file->contexts);
1331+
13291332
xa_init_flags(&pvr_file->ctx_handles, XA_FLAGS_ALLOC1);
13301333
xa_init_flags(&pvr_file->free_list_handles, XA_FLAGS_ALLOC1);
13311334
xa_init_flags(&pvr_file->hwrt_handles, XA_FLAGS_ALLOC1);

0 commit comments

Comments
 (0)