amdgpu_semaphore.c 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. /*
  2. * Copyright 2011 Christian König.
  3. * All Rights Reserved.
  4. *
  5. * Permission is hereby granted, free of charge, to any person obtaining a
  6. * copy of this software and associated documentation files (the
  7. * "Software"), to deal in the Software without restriction, including
  8. * without limitation the rights to use, copy, modify, merge, publish,
  9. * distribute, sub license, and/or sell copies of the Software, and to
  10. * permit persons to whom the Software is furnished to do so, subject to
  11. * the following conditions:
  12. *
  13. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  14. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  15. * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
  16. * THE COPYRIGHT HOLDERS, AUTHORS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM,
  17. * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
  18. * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
  19. * USE OR OTHER DEALINGS IN THE SOFTWARE.
  20. *
  21. * The above copyright notice and this permission notice (including the
  22. * next paragraph) shall be included in all copies or substantial portions
  23. * of the Software.
  24. *
  25. */
  26. /*
  27. * Authors:
  28. * Christian König <deathsimple@vodafone.de>
  29. */
  30. #include <drm/drmP.h>
  31. #include "amdgpu.h"
  32. #include "amdgpu_trace.h"
  33. int amdgpu_semaphore_create(struct amdgpu_device *adev,
  34. struct amdgpu_semaphore **semaphore)
  35. {
  36. int r;
  37. *semaphore = kmalloc(sizeof(struct amdgpu_semaphore), GFP_KERNEL);
  38. if (*semaphore == NULL) {
  39. return -ENOMEM;
  40. }
  41. r = amdgpu_sa_bo_new(&adev->ring_tmp_bo,
  42. &(*semaphore)->sa_bo, 8, 8);
  43. if (r) {
  44. kfree(*semaphore);
  45. *semaphore = NULL;
  46. return r;
  47. }
  48. (*semaphore)->waiters = 0;
  49. (*semaphore)->gpu_addr = amdgpu_sa_bo_gpu_addr((*semaphore)->sa_bo);
  50. *((uint64_t *)amdgpu_sa_bo_cpu_addr((*semaphore)->sa_bo)) = 0;
  51. return 0;
  52. }
  53. bool amdgpu_semaphore_emit_signal(struct amdgpu_ring *ring,
  54. struct amdgpu_semaphore *semaphore)
  55. {
  56. trace_amdgpu_semaphore_signale(ring->idx, semaphore);
  57. if (amdgpu_ring_emit_semaphore(ring, semaphore, false)) {
  58. --semaphore->waiters;
  59. /* for debugging lockup only, used by sysfs debug files */
  60. ring->last_semaphore_signal_addr = semaphore->gpu_addr;
  61. return true;
  62. }
  63. return false;
  64. }
  65. bool amdgpu_semaphore_emit_wait(struct amdgpu_ring *ring,
  66. struct amdgpu_semaphore *semaphore)
  67. {
  68. trace_amdgpu_semaphore_wait(ring->idx, semaphore);
  69. if (amdgpu_ring_emit_semaphore(ring, semaphore, true)) {
  70. ++semaphore->waiters;
  71. /* for debugging lockup only, used by sysfs debug files */
  72. ring->last_semaphore_wait_addr = semaphore->gpu_addr;
  73. return true;
  74. }
  75. return false;
  76. }
  77. void amdgpu_semaphore_free(struct amdgpu_device *adev,
  78. struct amdgpu_semaphore **semaphore,
  79. struct fence *fence)
  80. {
  81. if (semaphore == NULL || *semaphore == NULL) {
  82. return;
  83. }
  84. if ((*semaphore)->waiters > 0) {
  85. dev_err(adev->dev, "semaphore %p has more waiters than signalers,"
  86. " hardware lockup imminent!\n", *semaphore);
  87. }
  88. amdgpu_sa_bo_free(adev, &(*semaphore)->sa_bo, fence);
  89. kfree(*semaphore);
  90. *semaphore = NULL;
  91. }