mtk_sync.c 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. /*
  2. * Copyright (C) 2011-2014 MediaTek Inc.
  3. *
  4. * This program is free software: you can redistribute it and/or modify it under the terms of the
  5. * GNU General Public License version 2 as published by the Free Software Foundation.
  6. *
  7. * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
  8. * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  9. * See the GNU General Public License for more details.
  10. *
  11. * You should have received a copy of the GNU General Public License along with this program.
  12. * If not, see <http://www.gnu.org/licenses/>.
  13. */
  14. #include <linux/debugfs.h>
  15. #include <linux/export.h>
  16. #include <linux/seq_file.h>
  17. #include <linux/file.h>
  18. #include <linux/kthread.h>
  19. /* #include <linux/xlog.h> */
  20. #include <linux/delay.h>
  21. #include "mtk_sync.h"
  22. /* -------------------------------------------------------------------------- */
  23. struct sw_sync_timeline *timeline_create(const char *name)
  24. {
  25. return sw_sync_timeline_create(name);
  26. }
  27. EXPORT_SYMBOL(timeline_create);
  28. void timeline_destroy(struct sw_sync_timeline *obj)
  29. {
  30. sync_timeline_destroy(&obj->obj);
  31. }
  32. EXPORT_SYMBOL(timeline_destroy);
  33. void timeline_inc(struct sw_sync_timeline *obj, u32 value)
  34. {
  35. sw_sync_timeline_inc(obj, value);
  36. }
  37. EXPORT_SYMBOL(timeline_inc);
  38. int fence_create(struct sw_sync_timeline *obj, struct fence_data *data)
  39. {
  40. int fd = get_unused_fd();
  41. int err;
  42. struct sync_pt *pt;
  43. struct sync_fence *fence;
  44. if (fd < 0)
  45. return fd;
  46. pt = sw_sync_pt_create(obj, data->value);
  47. if (pt == NULL) {
  48. err = -ENOMEM;
  49. goto err;
  50. }
  51. data->name[sizeof(data->name) - 1] = '\0';
  52. fence = sync_fence_create(data->name, pt);
  53. if (fence == NULL) {
  54. sync_pt_free(pt);
  55. err = -ENOMEM;
  56. goto err;
  57. }
  58. data->fence = fd;
  59. sync_fence_install(fence, fd);
  60. return 0;
  61. err:
  62. put_unused_fd(fd);
  63. return err;
  64. }
  65. EXPORT_SYMBOL(fence_create);
  66. int fence_merge(char *const name, int fd1, int fd2)
  67. {
  68. int fd = get_unused_fd();
  69. int err;
  70. struct sync_fence *fence1, *fence2, *fence3;
  71. if (fd < 0)
  72. return fd;
  73. fence1 = sync_fence_fdget(fd1);
  74. if (NULL == fence1) {
  75. err = -ENOENT;
  76. goto err_put_fd;
  77. }
  78. fence2 = sync_fence_fdget(fd2);
  79. if (NULL == fence2) {
  80. err = -ENOENT;
  81. goto err_put_fence1;
  82. }
  83. name[sizeof(name) - 1] = '\0';
  84. fence3 = sync_fence_merge(name, fence1, fence2);
  85. if (fence3 == NULL) {
  86. err = -ENOMEM;
  87. goto err_put_fence2;
  88. }
  89. sync_fence_install(fence3, fd);
  90. sync_fence_put(fence2);
  91. sync_fence_put(fence1);
  92. return fd;
  93. err_put_fence2:
  94. sync_fence_put(fence2);
  95. err_put_fence1:
  96. sync_fence_put(fence1);
  97. err_put_fd:
  98. put_unused_fd(fd);
  99. return err;
  100. }
  101. EXPORT_SYMBOL(fence_merge);