drm_flip_work.h 2.7 KB

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