18c2ecf20Sopenharmony_ci/*
28c2ecf20Sopenharmony_ci * Copyright (C) 2013 Red Hat
38c2ecf20Sopenharmony_ci *
48c2ecf20Sopenharmony_ci * Permission is hereby granted, free of charge, to any person obtaining a
58c2ecf20Sopenharmony_ci * copy of this software and associated documentation files (the "Software"),
68c2ecf20Sopenharmony_ci * to deal in the Software without restriction, including without limitation
78c2ecf20Sopenharmony_ci * the rights to use, copy, modify, merge, publish, distribute, sublicense,
88c2ecf20Sopenharmony_ci * and/or sell copies of the Software, and to permit persons to whom the
98c2ecf20Sopenharmony_ci * Software is furnished to do so, subject to the following conditions:
108c2ecf20Sopenharmony_ci *
118c2ecf20Sopenharmony_ci * The above copyright notice and this permission notice (including the next
128c2ecf20Sopenharmony_ci * paragraph) shall be included in all copies or substantial portions of the
138c2ecf20Sopenharmony_ci * Software.
148c2ecf20Sopenharmony_ci *
158c2ecf20Sopenharmony_ci * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
168c2ecf20Sopenharmony_ci * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
178c2ecf20Sopenharmony_ci * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
188c2ecf20Sopenharmony_ci * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
198c2ecf20Sopenharmony_ci * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
208c2ecf20Sopenharmony_ci * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
218c2ecf20Sopenharmony_ci * SOFTWARE.
228c2ecf20Sopenharmony_ci */
238c2ecf20Sopenharmony_ci
248c2ecf20Sopenharmony_ci#ifndef DRM_FLIP_WORK_H
258c2ecf20Sopenharmony_ci#define DRM_FLIP_WORK_H
268c2ecf20Sopenharmony_ci
278c2ecf20Sopenharmony_ci#include <linux/kfifo.h>
288c2ecf20Sopenharmony_ci#include <linux/spinlock.h>
298c2ecf20Sopenharmony_ci#include <linux/workqueue.h>
308c2ecf20Sopenharmony_ci
318c2ecf20Sopenharmony_ci/**
328c2ecf20Sopenharmony_ci * DOC: flip utils
338c2ecf20Sopenharmony_ci *
348c2ecf20Sopenharmony_ci * Util to queue up work to run from work-queue context after flip/vblank.
358c2ecf20Sopenharmony_ci * Typically this can be used to defer unref of framebuffer's, cursor
368c2ecf20Sopenharmony_ci * bo's, etc until after vblank.  The APIs are all thread-safe.
378c2ecf20Sopenharmony_ci * Moreover, drm_flip_work_queue_task and drm_flip_work_queue can be called
388c2ecf20Sopenharmony_ci * in atomic context.
398c2ecf20Sopenharmony_ci */
408c2ecf20Sopenharmony_ci
418c2ecf20Sopenharmony_cistruct drm_flip_work;
428c2ecf20Sopenharmony_ci
438c2ecf20Sopenharmony_ci/*
448c2ecf20Sopenharmony_ci * drm_flip_func_t - callback function
458c2ecf20Sopenharmony_ci *
468c2ecf20Sopenharmony_ci * @work: the flip work
478c2ecf20Sopenharmony_ci * @val: value queued via drm_flip_work_queue()
488c2ecf20Sopenharmony_ci *
498c2ecf20Sopenharmony_ci * Callback function to be called for each of the  queue'd work items after
508c2ecf20Sopenharmony_ci * drm_flip_work_commit() is called.
518c2ecf20Sopenharmony_ci */
528c2ecf20Sopenharmony_citypedef void (*drm_flip_func_t)(struct drm_flip_work *work, void *val);
538c2ecf20Sopenharmony_ci
548c2ecf20Sopenharmony_ci/**
558c2ecf20Sopenharmony_ci * struct drm_flip_task - flip work task
568c2ecf20Sopenharmony_ci * @node: list entry element
578c2ecf20Sopenharmony_ci * @data: data to pass to &drm_flip_work.func
588c2ecf20Sopenharmony_ci */
598c2ecf20Sopenharmony_cistruct drm_flip_task {
608c2ecf20Sopenharmony_ci	struct list_head node;
618c2ecf20Sopenharmony_ci	void *data;
628c2ecf20Sopenharmony_ci};
638c2ecf20Sopenharmony_ci
648c2ecf20Sopenharmony_ci/**
658c2ecf20Sopenharmony_ci * struct drm_flip_work - flip work queue
668c2ecf20Sopenharmony_ci * @name: debug name
678c2ecf20Sopenharmony_ci * @func: callback fxn called for each committed item
688c2ecf20Sopenharmony_ci * @worker: worker which calls @func
698c2ecf20Sopenharmony_ci * @queued: queued tasks
708c2ecf20Sopenharmony_ci * @commited: commited tasks
718c2ecf20Sopenharmony_ci * @lock: lock to access queued and commited lists
728c2ecf20Sopenharmony_ci */
738c2ecf20Sopenharmony_cistruct drm_flip_work {
748c2ecf20Sopenharmony_ci	const char *name;
758c2ecf20Sopenharmony_ci	drm_flip_func_t func;
768c2ecf20Sopenharmony_ci	struct work_struct worker;
778c2ecf20Sopenharmony_ci	struct list_head queued;
788c2ecf20Sopenharmony_ci	struct list_head commited;
798c2ecf20Sopenharmony_ci	spinlock_t lock;
808c2ecf20Sopenharmony_ci};
818c2ecf20Sopenharmony_ci
828c2ecf20Sopenharmony_cistruct drm_flip_task *drm_flip_work_allocate_task(void *data, gfp_t flags);
838c2ecf20Sopenharmony_civoid drm_flip_work_queue_task(struct drm_flip_work *work,
848c2ecf20Sopenharmony_ci			      struct drm_flip_task *task);
858c2ecf20Sopenharmony_civoid drm_flip_work_queue(struct drm_flip_work *work, void *val);
868c2ecf20Sopenharmony_civoid drm_flip_work_commit(struct drm_flip_work *work,
878c2ecf20Sopenharmony_ci		struct workqueue_struct *wq);
888c2ecf20Sopenharmony_civoid drm_flip_work_init(struct drm_flip_work *work,
898c2ecf20Sopenharmony_ci		const char *name, drm_flip_func_t func);
908c2ecf20Sopenharmony_civoid drm_flip_work_cleanup(struct drm_flip_work *work);
918c2ecf20Sopenharmony_ci
928c2ecf20Sopenharmony_ci#endif  /* DRM_FLIP_WORK_H */
93