amdgpu_userq.c 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. /*
  2. * Copyright 2024 Advanced Micro Devices, Inc.
  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. */
  23. #include <string.h>
  24. #include <errno.h>
  25. #include "xf86drm.h"
  26. #include "amdgpu_drm.h"
  27. #include "amdgpu_internal.h"
  28. drm_public int
  29. amdgpu_create_userqueue(amdgpu_device_handle dev,
  30. uint32_t ip_type,
  31. uint32_t doorbell_handle,
  32. uint32_t doorbell_offset,
  33. uint64_t queue_va,
  34. uint64_t queue_size,
  35. uint64_t wptr_va,
  36. uint64_t rptr_va,
  37. void *mqd_in,
  38. uint32_t flags,
  39. uint32_t *queue_id)
  40. {
  41. int ret;
  42. union drm_amdgpu_userq userq;
  43. uint64_t mqd_size;
  44. if (!dev)
  45. return -EINVAL;
  46. switch (ip_type) {
  47. case AMDGPU_HW_IP_GFX:
  48. mqd_size = sizeof(struct drm_amdgpu_userq_mqd_gfx11);
  49. break;
  50. case AMDGPU_HW_IP_DMA:
  51. mqd_size = sizeof(struct drm_amdgpu_userq_mqd_sdma_gfx11);
  52. break;
  53. case AMDGPU_HW_IP_COMPUTE:
  54. mqd_size = sizeof(struct drm_amdgpu_userq_mqd_compute_gfx11);
  55. break;
  56. default:
  57. return -EINVAL;
  58. }
  59. memset(&userq, 0, sizeof(userq));
  60. userq.in.op = AMDGPU_USERQ_OP_CREATE;
  61. userq.in.ip_type = ip_type;
  62. userq.in.doorbell_handle = doorbell_handle;
  63. userq.in.doorbell_offset = doorbell_offset;
  64. userq.in.queue_va = queue_va;
  65. userq.in.queue_size = queue_size;
  66. userq.in.wptr_va = wptr_va;
  67. userq.in.rptr_va = rptr_va;
  68. userq.in.mqd = (uint64_t)mqd_in;
  69. userq.in.mqd_size = mqd_size;
  70. userq.in.flags = flags;
  71. ret = drmCommandWriteRead(dev->fd, DRM_AMDGPU_USERQ,
  72. &userq, sizeof(userq));
  73. *queue_id = userq.out.queue_id;
  74. return ret;
  75. }
  76. drm_public int
  77. amdgpu_free_userqueue(amdgpu_device_handle dev, uint32_t queue_id)
  78. {
  79. union drm_amdgpu_userq userq;
  80. memset(&userq, 0, sizeof(userq));
  81. userq.in.op = AMDGPU_USERQ_OP_FREE;
  82. userq.in.queue_id = queue_id;
  83. return drmCommandWriteRead(dev->fd, DRM_AMDGPU_USERQ,
  84. &userq, sizeof(userq));
  85. }
  86. drm_public int
  87. amdgpu_userq_signal(amdgpu_device_handle dev,
  88. struct drm_amdgpu_userq_signal *signal_data)
  89. {
  90. int r;
  91. r = drmCommandWriteRead(dev->fd, DRM_AMDGPU_USERQ_SIGNAL,
  92. signal_data, sizeof(struct drm_amdgpu_userq_signal));
  93. return r;
  94. }
  95. drm_public int
  96. amdgpu_userq_wait(amdgpu_device_handle dev,
  97. struct drm_amdgpu_userq_wait *wait_data)
  98. {
  99. int r;
  100. r = drmCommandWriteRead(dev->fd, DRM_AMDGPU_USERQ_WAIT,
  101. wait_data, sizeof(struct drm_amdgpu_userq_wait));
  102. return r;
  103. }