drm_flip_work.h 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  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/spinlock.h>
  27. #include <linux/workqueue.h>
  28. /**
  29. * DOC: flip utils
  30. *
  31. * Util to queue up work to run from work-queue context after flip/vblank.
  32. * Typically this can be used to defer unref of framebuffer's, cursor
  33. * bo's, etc until after vblank. The APIs are all thread-safe.
  34. * Moreover, drm_flip_work_queue_task and drm_flip_work_queue can be called
  35. * in atomic context.
  36. */
  37. struct drm_flip_work;
  38. /*
  39. * drm_flip_func_t - callback function
  40. *
  41. * @work: the flip work
  42. * @val: value queued via drm_flip_work_queue()
  43. *
  44. * Callback function to be called for each of the queue'd work items after
  45. * drm_flip_work_commit() is called.
  46. */
  47. typedef void (*drm_flip_func_t)(struct drm_flip_work *work, void *val);
  48. /**
  49. * struct drm_flip_task - flip work task
  50. * @node: list entry element
  51. * @data: data to pass to work->func
  52. */
  53. struct drm_flip_task {
  54. struct list_head node;
  55. void *data;
  56. };
  57. /**
  58. * struct drm_flip_work - flip work queue
  59. * @name: debug name
  60. * @func: callback fxn called for each committed item
  61. * @worker: worker which calls @func
  62. * @queued: queued tasks
  63. * @commited: commited tasks
  64. * @lock: lock to access queued and commited lists
  65. */
  66. struct drm_flip_work {
  67. const char *name;
  68. drm_flip_func_t func;
  69. struct work_struct worker;
  70. struct list_head queued;
  71. struct list_head commited;
  72. spinlock_t lock;
  73. };
  74. struct drm_flip_task *drm_flip_work_allocate_task(void *data, gfp_t flags);
  75. void drm_flip_work_queue_task(struct drm_flip_work *work,
  76. struct drm_flip_task *task);
  77. void drm_flip_work_queue(struct drm_flip_work *work, void *val);
  78. void drm_flip_work_commit(struct drm_flip_work *work,
  79. struct workqueue_struct *wq);
  80. void drm_flip_work_init(struct drm_flip_work *work,
  81. const char *name, drm_flip_func_t func);
  82. void drm_flip_work_cleanup(struct drm_flip_work *work);
  83. #endif /* DRM_FLIP_WORK_H */