drm_flip_work.h 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  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. * @fifo: queue of committed items
  55. */
  56. struct drm_flip_work {
  57. const char *name;
  58. atomic_t pending, count;
  59. drm_flip_func_t func;
  60. struct work_struct worker;
  61. DECLARE_KFIFO_PTR(fifo, void *);
  62. };
  63. void drm_flip_work_queue(struct drm_flip_work *work, void *val);
  64. void drm_flip_work_commit(struct drm_flip_work *work,
  65. struct workqueue_struct *wq);
  66. int drm_flip_work_init(struct drm_flip_work *work, int size,
  67. const char *name, drm_flip_func_t func);
  68. void drm_flip_work_cleanup(struct drm_flip_work *work);
  69. #endif /* DRM_FLIP_WORK_H */