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