xref: /openbmc/linux/include/drm/drm_flip_work.h (revision 0337966d121ebebf73a1c346123e8112796e684e)
1cabaafc7SRob Clark /*
2cabaafc7SRob Clark  * Copyright (C) 2013 Red Hat
3cabaafc7SRob Clark  *
4cabaafc7SRob Clark  * Permission is hereby granted, free of charge, to any person obtaining a
5cabaafc7SRob Clark  * copy of this software and associated documentation files (the "Software"),
6cabaafc7SRob Clark  * to deal in the Software without restriction, including without limitation
7cabaafc7SRob Clark  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8cabaafc7SRob Clark  * and/or sell copies of the Software, and to permit persons to whom the
9cabaafc7SRob Clark  * Software is furnished to do so, subject to the following conditions:
10cabaafc7SRob Clark  *
11cabaafc7SRob Clark  * The above copyright notice and this permission notice (including the next
12cabaafc7SRob Clark  * paragraph) shall be included in all copies or substantial portions of the
13cabaafc7SRob Clark  * Software.
14cabaafc7SRob Clark  *
15cabaafc7SRob Clark  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16cabaafc7SRob Clark  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17cabaafc7SRob Clark  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
18cabaafc7SRob Clark  * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19cabaafc7SRob Clark  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20cabaafc7SRob Clark  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21cabaafc7SRob Clark  * SOFTWARE.
22cabaafc7SRob Clark  */
23cabaafc7SRob Clark 
24cabaafc7SRob Clark #ifndef DRM_FLIP_WORK_H
25cabaafc7SRob Clark #define DRM_FLIP_WORK_H
26cabaafc7SRob Clark 
27cabaafc7SRob Clark #include <linux/kfifo.h>
288bd4ae20SBoris BREZILLON #include <linux/spinlock.h>
29cabaafc7SRob Clark #include <linux/workqueue.h>
30cabaafc7SRob Clark 
31cabaafc7SRob Clark /**
32cabaafc7SRob Clark  * DOC: flip utils
33cabaafc7SRob Clark  *
34cabaafc7SRob Clark  * Util to queue up work to run from work-queue context after flip/vblank.
35cabaafc7SRob Clark  * Typically this can be used to defer unref of framebuffer's, cursor
368bd4ae20SBoris BREZILLON  * bo's, etc until after vblank.  The APIs are all thread-safe.
378bd4ae20SBoris BREZILLON  * Moreover, drm_flip_work_queue_task and drm_flip_work_queue can be called
388bd4ae20SBoris BREZILLON  * in atomic context.
39cabaafc7SRob Clark  */
40cabaafc7SRob Clark 
41cabaafc7SRob Clark struct drm_flip_work;
42cabaafc7SRob Clark 
43cabaafc7SRob Clark /*
44cabaafc7SRob Clark  * drm_flip_func_t - callback function
45cabaafc7SRob Clark  *
46cabaafc7SRob Clark  * @work: the flip work
47cabaafc7SRob Clark  * @val: value queued via drm_flip_work_queue()
48cabaafc7SRob Clark  *
49cabaafc7SRob Clark  * Callback function to be called for each of the  queue'd work items after
50cabaafc7SRob Clark  * drm_flip_work_commit() is called.
51cabaafc7SRob Clark  */
52cabaafc7SRob Clark typedef void (*drm_flip_func_t)(struct drm_flip_work *work, void *val);
53cabaafc7SRob Clark 
54cabaafc7SRob Clark /**
558bd4ae20SBoris BREZILLON  * struct drm_flip_task - flip work task
568bd4ae20SBoris BREZILLON  * @node: list entry element
57*6806cdf9SDaniel Vetter  * @data: data to pass to &drm_flip_work.func
588bd4ae20SBoris BREZILLON  */
598bd4ae20SBoris BREZILLON struct drm_flip_task {
608bd4ae20SBoris BREZILLON 	struct list_head node;
618bd4ae20SBoris BREZILLON 	void *data;
628bd4ae20SBoris BREZILLON };
638bd4ae20SBoris BREZILLON 
648bd4ae20SBoris BREZILLON /**
65cabaafc7SRob Clark  * struct drm_flip_work - flip work queue
66cabaafc7SRob Clark  * @name: debug name
67cabaafc7SRob Clark  * @func: callback fxn called for each committed item
68cabaafc7SRob Clark  * @worker: worker which calls @func
698bd4ae20SBoris BREZILLON  * @queued: queued tasks
708bd4ae20SBoris BREZILLON  * @commited: commited tasks
718bd4ae20SBoris BREZILLON  * @lock: lock to access queued and commited lists
72cabaafc7SRob Clark  */
73cabaafc7SRob Clark struct drm_flip_work {
74cabaafc7SRob Clark 	const char *name;
75cabaafc7SRob Clark 	drm_flip_func_t func;
76cabaafc7SRob Clark 	struct work_struct worker;
778bd4ae20SBoris BREZILLON 	struct list_head queued;
788bd4ae20SBoris BREZILLON 	struct list_head commited;
798bd4ae20SBoris BREZILLON 	spinlock_t lock;
80cabaafc7SRob Clark };
81cabaafc7SRob Clark 
828bd4ae20SBoris BREZILLON struct drm_flip_task *drm_flip_work_allocate_task(void *data, gfp_t flags);
838bd4ae20SBoris BREZILLON void drm_flip_work_queue_task(struct drm_flip_work *work,
848bd4ae20SBoris BREZILLON 			      struct drm_flip_task *task);
85cabaafc7SRob Clark void drm_flip_work_queue(struct drm_flip_work *work, void *val);
86cabaafc7SRob Clark void drm_flip_work_commit(struct drm_flip_work *work,
87cabaafc7SRob Clark 		struct workqueue_struct *wq);
88d7f8db53SBoris BREZILLON void drm_flip_work_init(struct drm_flip_work *work,
89cabaafc7SRob Clark 		const char *name, drm_flip_func_t func);
90cabaafc7SRob Clark void drm_flip_work_cleanup(struct drm_flip_work *work);
91cabaafc7SRob Clark 
92cabaafc7SRob Clark #endif  /* DRM_FLIP_WORK_H */
93