This source file includes following definitions.
- drm_flip_work_allocate_task
- drm_flip_work_queue_task
- drm_flip_work_queue
- drm_flip_work_commit
- flip_worker
- drm_flip_work_init
- drm_flip_work_cleanup
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24 #include <linux/slab.h>
25
26 #include <drm/drm_flip_work.h>
27 #include <drm/drm_print.h>
28 #include <drm/drm_util.h>
29
30
31
32
33
34
35
36
37 struct drm_flip_task *drm_flip_work_allocate_task(void *data, gfp_t flags)
38 {
39 struct drm_flip_task *task;
40
41 task = kzalloc(sizeof(*task), flags);
42 if (task)
43 task->data = data;
44
45 return task;
46 }
47 EXPORT_SYMBOL(drm_flip_work_allocate_task);
48
49
50
51
52
53
54
55
56
57 void drm_flip_work_queue_task(struct drm_flip_work *work,
58 struct drm_flip_task *task)
59 {
60 unsigned long flags;
61
62 spin_lock_irqsave(&work->lock, flags);
63 list_add_tail(&task->node, &work->queued);
64 spin_unlock_irqrestore(&work->lock, flags);
65 }
66 EXPORT_SYMBOL(drm_flip_work_queue_task);
67
68
69
70
71
72
73
74
75
76 void drm_flip_work_queue(struct drm_flip_work *work, void *val)
77 {
78 struct drm_flip_task *task;
79
80 task = drm_flip_work_allocate_task(val,
81 drm_can_sleep() ? GFP_KERNEL : GFP_ATOMIC);
82 if (task) {
83 drm_flip_work_queue_task(work, task);
84 } else {
85 DRM_ERROR("%s could not allocate task!\n", work->name);
86 work->func(work, val);
87 }
88 }
89 EXPORT_SYMBOL(drm_flip_work_queue);
90
91
92
93
94
95
96
97
98
99
100
101 void drm_flip_work_commit(struct drm_flip_work *work,
102 struct workqueue_struct *wq)
103 {
104 unsigned long flags;
105
106 spin_lock_irqsave(&work->lock, flags);
107 list_splice_tail(&work->queued, &work->commited);
108 INIT_LIST_HEAD(&work->queued);
109 spin_unlock_irqrestore(&work->lock, flags);
110 queue_work(wq, &work->worker);
111 }
112 EXPORT_SYMBOL(drm_flip_work_commit);
113
114 static void flip_worker(struct work_struct *w)
115 {
116 struct drm_flip_work *work = container_of(w, struct drm_flip_work, worker);
117 struct list_head tasks;
118 unsigned long flags;
119
120 while (1) {
121 struct drm_flip_task *task, *tmp;
122
123 INIT_LIST_HEAD(&tasks);
124 spin_lock_irqsave(&work->lock, flags);
125 list_splice_tail(&work->commited, &tasks);
126 INIT_LIST_HEAD(&work->commited);
127 spin_unlock_irqrestore(&work->lock, flags);
128
129 if (list_empty(&tasks))
130 break;
131
132 list_for_each_entry_safe(task, tmp, &tasks, node) {
133 work->func(work, task->data);
134 kfree(task);
135 }
136 }
137 }
138
139
140
141
142
143
144
145
146
147 void drm_flip_work_init(struct drm_flip_work *work,
148 const char *name, drm_flip_func_t func)
149 {
150 work->name = name;
151 INIT_LIST_HEAD(&work->queued);
152 INIT_LIST_HEAD(&work->commited);
153 spin_lock_init(&work->lock);
154 work->func = func;
155
156 INIT_WORK(&work->worker, flip_worker);
157 }
158 EXPORT_SYMBOL(drm_flip_work_init);
159
160
161
162
163
164
165
166 void drm_flip_work_cleanup(struct drm_flip_work *work)
167 {
168 WARN_ON(!list_empty(&work->queued) || !list_empty(&work->commited));
169 }
170 EXPORT_SYMBOL(drm_flip_work_cleanup);