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> |
| 28 | #include <linux/workqueue.h> |
| 29 | |
| 30 | /** |
| 31 | * DOC: flip utils |
| 32 | * |
| 33 | * Util to queue up work to run from work-queue context after flip/vblank. |
| 34 | * Typically this can be used to defer unref of framebuffer's, cursor |
| 35 | * bo's, etc until after vblank. The APIs are all safe (and lockless) |
| 36 | * for up to one producer and once consumer at a time. The single-consumer |
| 37 | * aspect is ensured by committing the queued work to a single work-queue. |
| 38 | */ |
| 39 | |
| 40 | struct drm_flip_work; |
| 41 | |
| 42 | /* |
| 43 | * drm_flip_func_t - callback function |
| 44 | * |
| 45 | * @work: the flip work |
| 46 | * @val: value queued via drm_flip_work_queue() |
| 47 | * |
| 48 | * Callback function to be called for each of the queue'd work items after |
| 49 | * drm_flip_work_commit() is called. |
| 50 | */ |
| 51 | typedef void (*drm_flip_func_t)(struct drm_flip_work *work, void *val); |
| 52 | |
| 53 | /** |
| 54 | * struct drm_flip_work - flip work queue |
| 55 | * @name: debug name |
| 56 | * @pending: number of queued but not committed items |
| 57 | * @count: number of committed items |
| 58 | * @func: callback fxn called for each committed item |
| 59 | * @worker: worker which calls @func |
Thierry Reding | 73dbd77 | 2014-04-29 11:44:36 +0200 | [diff] [blame] | 60 | * @fifo: queue of committed items |
Rob Clark | cabaafc | 2013-08-07 14:41:54 -0400 | [diff] [blame] | 61 | */ |
| 62 | struct drm_flip_work { |
| 63 | const char *name; |
| 64 | atomic_t pending, count; |
| 65 | drm_flip_func_t func; |
| 66 | struct work_struct worker; |
| 67 | DECLARE_KFIFO_PTR(fifo, void *); |
| 68 | }; |
| 69 | |
| 70 | void drm_flip_work_queue(struct drm_flip_work *work, void *val); |
| 71 | void drm_flip_work_commit(struct drm_flip_work *work, |
| 72 | struct workqueue_struct *wq); |
| 73 | int drm_flip_work_init(struct drm_flip_work *work, int size, |
| 74 | const char *name, drm_flip_func_t func); |
| 75 | void drm_flip_work_cleanup(struct drm_flip_work *work); |
| 76 | |
| 77 | #endif /* DRM_FLIP_WORK_H */ |