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