seqno-fence.c 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. /*
  2. * seqno-fence, using a dma-buf to synchronize fencing
  3. *
  4. * Copyright (C) 2012 Texas Instruments
  5. * Copyright (C) 2012-2014 Canonical Ltd
  6. * Authors:
  7. * Rob Clark <robdclark@gmail.com>
  8. * Maarten Lankhorst <maarten.lankhorst@canonical.com>
  9. *
  10. * This program is free software; you can redistribute it and/or modify it
  11. * under the terms of the GNU General Public License version 2 as published by
  12. * the Free Software Foundation.
  13. *
  14. * This program is distributed in the hope that it will be useful, but WITHOUT
  15. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  16. * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
  17. * more details.
  18. */
  19. #include <linux/slab.h>
  20. #include <linux/export.h>
  21. #include <linux/seqno-fence.h>
  22. static const char *seqno_fence_get_driver_name(struct fence *fence)
  23. {
  24. struct seqno_fence *seqno_fence = to_seqno_fence(fence);
  25. return seqno_fence->ops->get_driver_name(fence);
  26. }
  27. static const char *seqno_fence_get_timeline_name(struct fence *fence)
  28. {
  29. struct seqno_fence *seqno_fence = to_seqno_fence(fence);
  30. return seqno_fence->ops->get_timeline_name(fence);
  31. }
  32. static bool seqno_enable_signaling(struct fence *fence)
  33. {
  34. struct seqno_fence *seqno_fence = to_seqno_fence(fence);
  35. return seqno_fence->ops->enable_signaling(fence);
  36. }
  37. static bool seqno_signaled(struct fence *fence)
  38. {
  39. struct seqno_fence *seqno_fence = to_seqno_fence(fence);
  40. return seqno_fence->ops->signaled && seqno_fence->ops->signaled(fence);
  41. }
  42. static void seqno_release(struct fence *fence)
  43. {
  44. struct seqno_fence *f = to_seqno_fence(fence);
  45. dma_buf_put(f->sync_buf);
  46. if (f->ops->release)
  47. f->ops->release(fence);
  48. else
  49. fence_free(&f->base);
  50. }
  51. static signed long seqno_wait(struct fence *fence, bool intr,
  52. signed long timeout)
  53. {
  54. struct seqno_fence *f = to_seqno_fence(fence);
  55. return f->ops->wait(fence, intr, timeout);
  56. }
  57. const struct fence_ops seqno_fence_ops = {
  58. .get_driver_name = seqno_fence_get_driver_name,
  59. .get_timeline_name = seqno_fence_get_timeline_name,
  60. .enable_signaling = seqno_enable_signaling,
  61. .signaled = seqno_signaled,
  62. .wait = seqno_wait,
  63. .release = seqno_release,
  64. };
  65. EXPORT_SYMBOL(seqno_fence_ops);