xref: /openbmc/linux/include/drm/drm_vblank_work.h (revision 5e6c2b4f)
15e6c2b4fSLyude Paul /* SPDX-License-Identifier: MIT */
25e6c2b4fSLyude Paul 
35e6c2b4fSLyude Paul #ifndef _DRM_VBLANK_WORK_H_
45e6c2b4fSLyude Paul #define _DRM_VBLANK_WORK_H_
55e6c2b4fSLyude Paul 
65e6c2b4fSLyude Paul #include <linux/kthread.h>
75e6c2b4fSLyude Paul 
85e6c2b4fSLyude Paul struct drm_crtc;
95e6c2b4fSLyude Paul 
105e6c2b4fSLyude Paul /**
115e6c2b4fSLyude Paul  * struct drm_vblank_work - A delayed work item which delays until a target
125e6c2b4fSLyude Paul  * vblank passes, and then executes at realtime priority outside of IRQ
135e6c2b4fSLyude Paul  * context.
145e6c2b4fSLyude Paul  *
155e6c2b4fSLyude Paul  * See also:
165e6c2b4fSLyude Paul  * drm_vblank_work_schedule()
175e6c2b4fSLyude Paul  * drm_vblank_work_init()
185e6c2b4fSLyude Paul  * drm_vblank_work_cancel_sync()
195e6c2b4fSLyude Paul  * drm_vblank_work_flush()
205e6c2b4fSLyude Paul  */
215e6c2b4fSLyude Paul struct drm_vblank_work {
225e6c2b4fSLyude Paul 	/**
235e6c2b4fSLyude Paul 	 * @base: The base &kthread_work item which will be executed by
245e6c2b4fSLyude Paul 	 * &drm_vblank_crtc.worker. Drivers should not interact with this
255e6c2b4fSLyude Paul 	 * directly, and instead rely on drm_vblank_work_init() to initialize
265e6c2b4fSLyude Paul 	 * this.
275e6c2b4fSLyude Paul 	 */
285e6c2b4fSLyude Paul 	struct kthread_work base;
295e6c2b4fSLyude Paul 
305e6c2b4fSLyude Paul 	/**
315e6c2b4fSLyude Paul 	 * @vblank: A pointer to &drm_vblank_crtc this work item belongs to.
325e6c2b4fSLyude Paul 	 */
335e6c2b4fSLyude Paul 	struct drm_vblank_crtc *vblank;
345e6c2b4fSLyude Paul 
355e6c2b4fSLyude Paul 	/**
365e6c2b4fSLyude Paul 	 * @count: The target vblank this work will execute on. Drivers should
375e6c2b4fSLyude Paul 	 * not modify this value directly, and instead use
385e6c2b4fSLyude Paul 	 * drm_vblank_work_schedule()
395e6c2b4fSLyude Paul 	 */
405e6c2b4fSLyude Paul 	u64 count;
415e6c2b4fSLyude Paul 
425e6c2b4fSLyude Paul 	/**
435e6c2b4fSLyude Paul 	 * @cancelling: The number of drm_vblank_work_cancel_sync() calls that
445e6c2b4fSLyude Paul 	 * are currently running. A work item cannot be rescheduled until all
455e6c2b4fSLyude Paul 	 * calls have finished.
465e6c2b4fSLyude Paul 	 */
475e6c2b4fSLyude Paul 	int cancelling;
485e6c2b4fSLyude Paul 
495e6c2b4fSLyude Paul 	/**
505e6c2b4fSLyude Paul 	 * @node: The position of this work item in
515e6c2b4fSLyude Paul 	 * &drm_vblank_crtc.pending_work.
525e6c2b4fSLyude Paul 	 */
535e6c2b4fSLyude Paul 	struct list_head node;
545e6c2b4fSLyude Paul };
555e6c2b4fSLyude Paul 
565e6c2b4fSLyude Paul /**
575e6c2b4fSLyude Paul  * to_drm_vblank_work - Retrieve the respective &drm_vblank_work item from a
585e6c2b4fSLyude Paul  * &kthread_work
595e6c2b4fSLyude Paul  * @_work: The &kthread_work embedded inside a &drm_vblank_work
605e6c2b4fSLyude Paul  */
615e6c2b4fSLyude Paul #define to_drm_vblank_work(_work) \
625e6c2b4fSLyude Paul 	container_of((_work), struct drm_vblank_work, base)
635e6c2b4fSLyude Paul 
645e6c2b4fSLyude Paul int drm_vblank_work_schedule(struct drm_vblank_work *work,
655e6c2b4fSLyude Paul 			     u64 count, bool nextonmiss);
665e6c2b4fSLyude Paul void drm_vblank_work_init(struct drm_vblank_work *work, struct drm_crtc *crtc,
675e6c2b4fSLyude Paul 			  void (*func)(struct kthread_work *work));
685e6c2b4fSLyude Paul bool drm_vblank_work_cancel_sync(struct drm_vblank_work *work);
695e6c2b4fSLyude Paul void drm_vblank_work_flush(struct drm_vblank_work *work);
705e6c2b4fSLyude Paul 
715e6c2b4fSLyude Paul #endif /* !_DRM_VBLANK_WORK_H_ */
72