xref: /openbmc/linux/include/drm/drm_vblank_work.h (revision 29c37341)
1 /* SPDX-License-Identifier: MIT */
2 
3 #ifndef _DRM_VBLANK_WORK_H_
4 #define _DRM_VBLANK_WORK_H_
5 
6 #include <linux/kthread.h>
7 
8 struct drm_crtc;
9 
10 /**
11  * struct drm_vblank_work - A delayed work item which delays until a target
12  * vblank passes, and then executes at realtime priority outside of IRQ
13  * context.
14  *
15  * See also:
16  * drm_vblank_work_schedule()
17  * drm_vblank_work_init()
18  * drm_vblank_work_cancel_sync()
19  * drm_vblank_work_flush()
20  */
21 struct drm_vblank_work {
22 	/**
23 	 * @base: The base &kthread_work item which will be executed by
24 	 * &drm_vblank_crtc.worker. Drivers should not interact with this
25 	 * directly, and instead rely on drm_vblank_work_init() to initialize
26 	 * this.
27 	 */
28 	struct kthread_work base;
29 
30 	/**
31 	 * @vblank: A pointer to &drm_vblank_crtc this work item belongs to.
32 	 */
33 	struct drm_vblank_crtc *vblank;
34 
35 	/**
36 	 * @count: The target vblank this work will execute on. Drivers should
37 	 * not modify this value directly, and instead use
38 	 * drm_vblank_work_schedule()
39 	 */
40 	u64 count;
41 
42 	/**
43 	 * @cancelling: The number of drm_vblank_work_cancel_sync() calls that
44 	 * are currently running. A work item cannot be rescheduled until all
45 	 * calls have finished.
46 	 */
47 	int cancelling;
48 
49 	/**
50 	 * @node: The position of this work item in
51 	 * &drm_vblank_crtc.pending_work.
52 	 */
53 	struct list_head node;
54 };
55 
56 /**
57  * to_drm_vblank_work - Retrieve the respective &drm_vblank_work item from a
58  * &kthread_work
59  * @_work: The &kthread_work embedded inside a &drm_vblank_work
60  */
61 #define to_drm_vblank_work(_work) \
62 	container_of((_work), struct drm_vblank_work, base)
63 
64 int drm_vblank_work_schedule(struct drm_vblank_work *work,
65 			     u64 count, bool nextonmiss);
66 void drm_vblank_work_init(struct drm_vblank_work *work, struct drm_crtc *crtc,
67 			  void (*func)(struct kthread_work *work));
68 bool drm_vblank_work_cancel_sync(struct drm_vblank_work *work);
69 void drm_vblank_work_flush(struct drm_vblank_work *work);
70 
71 #endif /* !_DRM_VBLANK_WORK_H_ */
72