mtk_sync.h 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. /*
  2. * Copyright (C) 2019 MediaTek Inc.
  3. *
  4. * This program is free software: you can redistribute it and/or modify
  5. * it under the terms of the GNU General Public License version 2 as
  6. * published by the Free Software Foundation.
  7. *
  8. * This program is distributed in the hope that it will be useful,
  9. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. * GNU General Public License for more details.
  12. */
  13. #ifndef _MTK_SYNC_H
  14. #define _MTK_SYNC_H
  15. /*
  16. * TIMEOUT_NEVER may be passed to the wait method to indicate that it
  17. * should wait indefinitely for the fence to signal.
  18. */
  19. #define TIMEOUT_NEVER -1
  20. /* ---------------------------------------------------------------------------
  21. */
  22. #ifdef __KERNEL__
  23. #include <linux/version.h>
  24. #include <linux/dma-fence.h>
  25. /**
  26. * struct sync_timeline - sync object
  27. * @kref: reference count on fence.
  28. * @name: name of the sync_timeline. Useful for debugging
  29. * @lock: lock protecting @pt_list and @value
  30. * @pt_tree: rbtree of active (unsignaled/errored) sync_pts
  31. * @pt_list: list of active (unsignaled/errored) sync_pts
  32. * @sync_timeline_list: membership in global sync_timeline_list
  33. */
  34. struct sync_timeline {
  35. struct kref kref;
  36. char name[32];
  37. /* protected by lock */
  38. u64 context;
  39. int value;
  40. struct rb_root pt_tree;
  41. struct list_head pt_list;
  42. spinlock_t lock;
  43. struct list_head sync_timeline_list;
  44. };
  45. /**
  46. * struct sync_pt - sync_pt object
  47. * @base: base fence object
  48. * @link: link on the sync timeline's list
  49. * @node: node in the sync timeline's tree
  50. */
  51. struct sync_pt {
  52. struct dma_fence base;
  53. struct list_head link;
  54. struct rb_node node;
  55. };
  56. /*
  57. * sync_timeline, sync_fence data structure
  58. */
  59. struct fence_data {
  60. __u32 value;
  61. char name[32];
  62. __s32 fence; /* fd of new fence */
  63. };
  64. /*
  65. * sync_timeline, sync_fence API
  66. */
  67. /**
  68. * mtk_sync_timeline_create() - creates a sync object
  69. * @name: sync_timeline name
  70. *
  71. * The mtk_sync_timeline_create() function creates a sync object named @name,
  72. * which represents a 32-bit monotonically increasing counter.
  73. */
  74. struct sync_timeline *mtk_sync_timeline_create(const char *name);
  75. /**
  76. * mtk_sync_timeline_destroy() - releases a sync object
  77. * @obj: sync_timeline obj
  78. *
  79. * The mtk_sync_timeline_destroy() function releases a sync object.
  80. * The remaining active points would be put into signaled list,
  81. * and their statuses are set to VENOENT.
  82. */
  83. void mtk_sync_timeline_destroy(struct sync_timeline *obj);
  84. /**
  85. * mtk_sync_timeline_inc() - increases timeline
  86. * @obj: sync_timeline obj
  87. * @value: the increment to a sync object
  88. *
  89. * The mtk_sync_timeline_inc() function increase the counter of @obj by @value
  90. * Each sync point contains a value. A sync point on a parent timeline transits
  91. * from active to signaled status when the counter of a timeline reaches
  92. * to that of a sync point.
  93. */
  94. void mtk_sync_timeline_inc(struct sync_timeline *obj, u32 value);
  95. /**
  96. * mtk_sync_fence_create() - create a fence
  97. * @obj: sync_timeline obj
  98. * @data: fence struct with its name and the number a sync point bears
  99. *
  100. * The mtk_sync_fence_create() function creates a new sync point with
  101. * @data->value,
  102. * and assign the sync point to a newly created fence named @data->name.
  103. * A file descriptor binded with the fence is stored in @data->fence.
  104. */
  105. int mtk_sync_fence_create(struct sync_timeline *obj, struct fence_data *data);
  106. #endif /* __KERNEL __ */
  107. #endif /* _MTK_SYNC_H */