syncpt.c 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. /*
  2. * Copyright © 2021 NVIDIA Corporation
  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 shall be included in
  12. * all copies or substantial portions of the Software.
  13. *
  14. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
  17. * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
  18. * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
  19. * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
  20. * OTHER DEALINGS IN THE SOFTWARE.
  21. */
  22. #ifdef HAVE_CONFIG_H
  23. # include "config.h"
  24. #endif
  25. #include <errno.h>
  26. #include <string.h>
  27. #include <sys/ioctl.h>
  28. #include "private.h"
  29. drm_public int
  30. drm_tegra_syncpoint_new(struct drm_tegra *drm,
  31. struct drm_tegra_syncpoint **syncptp)
  32. {
  33. struct drm_tegra_syncpoint_allocate args;
  34. struct drm_tegra_syncpoint *syncpt;
  35. int err;
  36. syncpt = calloc(1, sizeof(*syncpt));
  37. if (!syncpt)
  38. return -ENOMEM;
  39. memset(&args, 0, sizeof(args));
  40. err = ioctl(drm->fd, DRM_IOCTL_TEGRA_SYNCPOINT_ALLOCATE, &args);
  41. if (err < 0) {
  42. free(syncpt);
  43. return -errno;
  44. }
  45. syncpt->drm = drm;
  46. syncpt->id = args.id;
  47. *syncptp = syncpt;
  48. return 0;
  49. }
  50. drm_public int
  51. drm_tegra_syncpoint_free(struct drm_tegra_syncpoint *syncpt)
  52. {
  53. struct drm_tegra_syncpoint_free args;
  54. struct drm_tegra *drm = syncpt->drm;
  55. int err;
  56. if (!syncpt)
  57. return -EINVAL;
  58. memset(&args, 0, sizeof(args));
  59. args.id = syncpt->id;
  60. err = ioctl(drm->fd, DRM_IOCTL_TEGRA_SYNCPOINT_FREE, &args);
  61. if (err < 0)
  62. return -errno;
  63. free(syncpt);
  64. return 0;
  65. }
  66. drm_public int
  67. drm_tegra_fence_wait(struct drm_tegra_fence *fence, unsigned long timeout)
  68. {
  69. struct drm_tegra_syncpoint_wait args;
  70. struct drm_tegra *drm = fence->drm;
  71. int err;
  72. memset(&args, 0, sizeof(args));
  73. args.timeout_ns = 0;
  74. args.id = fence->syncpt;
  75. args.threshold = fence->value;
  76. err = ioctl(drm->fd, DRM_IOCTL_TEGRA_SYNCPOINT_WAIT, &args);
  77. if (err < 0)
  78. return -errno;
  79. return 0;
  80. }