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