11dedbd3bSFrançois Tigeot /* 21dedbd3bSFrançois Tigeot * Copyright (C) 2013 Red Hat 31dedbd3bSFrançois Tigeot * 41dedbd3bSFrançois Tigeot * Permission is hereby granted, free of charge, to any person obtaining a 51dedbd3bSFrançois Tigeot * copy of this software and associated documentation files (the "Software"), 61dedbd3bSFrançois Tigeot * to deal in the Software without restriction, including without limitation 71dedbd3bSFrançois Tigeot * the rights to use, copy, modify, merge, publish, distribute, sublicense, 81dedbd3bSFrançois Tigeot * and/or sell copies of the Software, and to permit persons to whom the 91dedbd3bSFrançois Tigeot * Software is furnished to do so, subject to the following conditions: 101dedbd3bSFrançois Tigeot * 111dedbd3bSFrançois Tigeot * The above copyright notice and this permission notice (including the next 121dedbd3bSFrançois Tigeot * paragraph) shall be included in all copies or substantial portions of the 131dedbd3bSFrançois Tigeot * Software. 141dedbd3bSFrançois Tigeot * 151dedbd3bSFrançois Tigeot * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 161dedbd3bSFrançois Tigeot * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 171dedbd3bSFrançois Tigeot * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 181dedbd3bSFrançois Tigeot * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 191dedbd3bSFrançois Tigeot * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 201dedbd3bSFrançois Tigeot * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 211dedbd3bSFrançois Tigeot * SOFTWARE. 221dedbd3bSFrançois Tigeot */ 231dedbd3bSFrançois Tigeot 241dedbd3bSFrançois Tigeot #ifndef DRM_FLIP_WORK_H 251dedbd3bSFrançois Tigeot #define DRM_FLIP_WORK_H 261dedbd3bSFrançois Tigeot 271dedbd3bSFrançois Tigeot #include <linux/kfifo.h> 281dedbd3bSFrançois Tigeot #include <linux/spinlock.h> 291dedbd3bSFrançois Tigeot #include <linux/workqueue.h> 301dedbd3bSFrançois Tigeot 311dedbd3bSFrançois Tigeot /** 321dedbd3bSFrançois Tigeot * DOC: flip utils 331dedbd3bSFrançois Tigeot * 341dedbd3bSFrançois Tigeot * Util to queue up work to run from work-queue context after flip/vblank. 351dedbd3bSFrançois Tigeot * Typically this can be used to defer unref of framebuffer's, cursor 361dedbd3bSFrançois Tigeot * bo's, etc until after vblank. The APIs are all thread-safe. 371dedbd3bSFrançois Tigeot * Moreover, drm_flip_work_queue_task and drm_flip_work_queue can be called 381dedbd3bSFrançois Tigeot * in atomic context. 391dedbd3bSFrançois Tigeot */ 401dedbd3bSFrançois Tigeot 411dedbd3bSFrançois Tigeot struct drm_flip_work; 421dedbd3bSFrançois Tigeot 431dedbd3bSFrançois Tigeot /* 441dedbd3bSFrançois Tigeot * drm_flip_func_t - callback function 451dedbd3bSFrançois Tigeot * 461dedbd3bSFrançois Tigeot * @work: the flip work 471dedbd3bSFrançois Tigeot * @val: value queued via drm_flip_work_queue() 481dedbd3bSFrançois Tigeot * 491dedbd3bSFrançois Tigeot * Callback function to be called for each of the queue'd work items after 501dedbd3bSFrançois Tigeot * drm_flip_work_commit() is called. 511dedbd3bSFrançois Tigeot */ 521dedbd3bSFrançois Tigeot typedef void (*drm_flip_func_t)(struct drm_flip_work *work, void *val); 531dedbd3bSFrançois Tigeot 541dedbd3bSFrançois Tigeot /** 551dedbd3bSFrançois Tigeot * struct drm_flip_task - flip work task 561dedbd3bSFrançois Tigeot * @node: list entry element 57*a85cb24fSFrançois Tigeot * @data: data to pass to &drm_flip_work.func 581dedbd3bSFrançois Tigeot */ 591dedbd3bSFrançois Tigeot struct drm_flip_task { 601dedbd3bSFrançois Tigeot struct list_head node; 611dedbd3bSFrançois Tigeot void *data; 621dedbd3bSFrançois Tigeot }; 631dedbd3bSFrançois Tigeot 641dedbd3bSFrançois Tigeot /** 651dedbd3bSFrançois Tigeot * struct drm_flip_work - flip work queue 661dedbd3bSFrançois Tigeot * @name: debug name 671dedbd3bSFrançois Tigeot * @func: callback fxn called for each committed item 681dedbd3bSFrançois Tigeot * @worker: worker which calls @func 691dedbd3bSFrançois Tigeot * @queued: queued tasks 701dedbd3bSFrançois Tigeot * @commited: commited tasks 711dedbd3bSFrançois Tigeot * @lock: lock to access queued and commited lists 721dedbd3bSFrançois Tigeot */ 731dedbd3bSFrançois Tigeot struct drm_flip_work { 741dedbd3bSFrançois Tigeot const char *name; 751dedbd3bSFrançois Tigeot drm_flip_func_t func; 761dedbd3bSFrançois Tigeot struct work_struct worker; 771dedbd3bSFrançois Tigeot struct list_head queued; 781dedbd3bSFrançois Tigeot struct list_head commited; 791dedbd3bSFrançois Tigeot spinlock_t lock; 801dedbd3bSFrançois Tigeot }; 811dedbd3bSFrançois Tigeot 821dedbd3bSFrançois Tigeot struct drm_flip_task *drm_flip_work_allocate_task(void *data, gfp_t flags); 831dedbd3bSFrançois Tigeot void drm_flip_work_queue_task(struct drm_flip_work *work, 841dedbd3bSFrançois Tigeot struct drm_flip_task *task); 851dedbd3bSFrançois Tigeot void drm_flip_work_queue(struct drm_flip_work *work, void *val); 861dedbd3bSFrançois Tigeot void drm_flip_work_commit(struct drm_flip_work *work, 871dedbd3bSFrançois Tigeot struct workqueue_struct *wq); 881dedbd3bSFrançois Tigeot void drm_flip_work_init(struct drm_flip_work *work, 891dedbd3bSFrançois Tigeot const char *name, drm_flip_func_t func); 901dedbd3bSFrançois Tigeot void drm_flip_work_cleanup(struct drm_flip_work *work); 911dedbd3bSFrançois Tigeot 921dedbd3bSFrançois Tigeot #endif /* DRM_FLIP_WORK_H */ 93