xref: /netbsd-src/sys/external/bsd/drm2/dist/include/drm/drm_flip_work.h (revision c3c58f2da45f1b7b13b221f2ce9a43cec3159539)
1 /*	$NetBSD: drm_flip_work.h,v 1.4 2021/12/19 09:47:52 riastradh Exp $	*/
2 
3 /*
4  * Copyright (C) 2013 Red Hat
5  *
6  * Permission is hereby granted, free of charge, to any person obtaining a
7  * copy of this software and associated documentation files (the "Software"),
8  * to deal in the Software without restriction, including without limitation
9  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
10  * and/or sell copies of the Software, and to permit persons to whom the
11  * Software is furnished to do so, subject to the following conditions:
12  *
13  * The above copyright notice and this permission notice (including the next
14  * paragraph) shall be included in all copies or substantial portions of the
15  * Software.
16  *
17  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
20  * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23  * SOFTWARE.
24  */
25 
26 #ifndef DRM_FLIP_WORK_H
27 #define DRM_FLIP_WORK_H
28 
29 #include <linux/bug.h>
30 #include <linux/list.h>
31 #include <linux/kfifo.h>
32 #include <linux/spinlock.h>
33 #include <linux/workqueue.h>
34 
35 /**
36  * DOC: flip utils
37  *
38  * Util to queue up work to run from work-queue context after flip/vblank.
39  * Typically this can be used to defer unref of framebuffer's, cursor
40  * bo's, etc until after vblank.  The APIs are all thread-safe.
41  * Moreover, drm_flip_work_queue_task and drm_flip_work_queue can be called
42  * in atomic context.
43  */
44 
45 struct drm_flip_work;
46 
47 /*
48  * drm_flip_func_t - callback function
49  *
50  * @work: the flip work
51  * @val: value queued via drm_flip_work_queue()
52  *
53  * Callback function to be called for each of the  queue'd work items after
54  * drm_flip_work_commit() is called.
55  */
56 typedef void (*drm_flip_func_t)(struct drm_flip_work *work, void *val);
57 
58 /**
59  * struct drm_flip_task - flip work task
60  * @node: list entry element
61  * @data: data to pass to &drm_flip_work.func
62  */
63 struct drm_flip_task {
64 	struct list_head node;
65 	void *data;
66 };
67 
68 /**
69  * struct drm_flip_work - flip work queue
70  * @name: debug name
71  * @func: callback fxn called for each committed item
72  * @worker: worker which calls @func
73  * @queued: queued tasks
74  * @commited: commited tasks
75  * @lock: lock to access queued and commited lists
76  */
77 struct drm_flip_work {
78 	const char *name;
79 	drm_flip_func_t func;
80 	struct work_struct worker;
81 	struct list_head queued;
82 	struct list_head commited;
83 	spinlock_t lock;
84 };
85 
86 struct drm_flip_task *drm_flip_work_allocate_task(void *data, gfp_t flags);
87 void drm_flip_work_queue_task(struct drm_flip_work *work,
88 			      struct drm_flip_task *task);
89 void drm_flip_work_queue(struct drm_flip_work *work, void *val);
90 void drm_flip_work_commit(struct drm_flip_work *work,
91 		struct workqueue_struct *wq);
92 void drm_flip_work_init(struct drm_flip_work *work,
93 		const char *name, drm_flip_func_t func);
94 void drm_flip_work_cleanup(struct drm_flip_work *work);
95 
96 #endif  /* DRM_FLIP_WORK_H */
97