| 1 |
/* |
| 2 |
* Copyright © 2022 Imagination Technologies Ltd. |
| 3 |
* |
| 4 |
* Permission is hereby granted, free of charge, to any person obtaining a copy |
| 5 |
* of this software and associated documentation files (the "Software"), to deal |
| 6 |
* in the Software without restriction, including without limitation the rights |
| 7 |
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
| 8 |
* copies of the Software, and to permit persons to whom the Software is |
| 9 |
* furnished to do so, subject to the following conditions: |
| 10 |
* |
| 11 |
* The above copyright notice and this permission notice (including the next |
| 12 |
* paragraph) shall be included in all copies or substantial portions of the |
| 13 |
* Software. |
| 14 |
* |
| 15 |
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 16 |
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 17 |
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
| 18 |
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 19 |
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
| 20 |
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
| 21 |
* SOFTWARE. |
| 22 |
*/ |
| 23 |
|
| 24 |
#include "pvr_srv_job_compute.h" |
| 25 |
|
| 26 |
#include "util/os_file.h" |
| 27 |
|
| 28 |
#include "vk_log.h" |
| 29 |
|
| 30 |
#include "fw-api/pvr_rogue_fwif.h" |
| 31 |
|
| 32 |
#include "pvr_csb.h" |
| 33 |
#include "pvr_device_info.h" |
| 34 |
#include "pvr_srv.h" |
| 35 |
#include "pvr_srv_bridge.h" |
| 36 |
|
| 37 |
static uint32_t |
| 38 |
pvr_srv_compute_cmd_stream_load(struct rogue_fwif_cmd_compute *const cmd, |
| 39 |
const uint8_t *const stream, |
| 40 |
const uint32_t stream_len, |
| 41 |
const struct pvr_device_info *const dev_info) |
| 42 |
{ |
| 43 |
const uint32_t *stream_ptr = (const uint32_t *)stream; |
| 44 |
struct rogue_fwif_cdm_regs *const regs = &cmd->regs; |
| 45 |
uint32_t main_stream_len = |
| 46 |
pvr_csb_unpack((uint64_t *)stream_ptr, KMD_STREAM_HDR).length; |
| 47 |
|
| 48 |
stream_ptr += pvr_cmd_length(KMD_STREAM_HDR); |
| 49 |
|
| 50 |
regs->tpu_border_colour_table = *(const uint64_t *)stream_ptr; |
| 51 |
stream_ptr += pvr_cmd_length(CR_TPU_BORDER_COLOUR_TABLE_CDM); |
| 52 |
|
| 53 |
regs->cdm_ctrl_stream_base = *(const uint64_t *)stream_ptr; |
| 54 |
stream_ptr += pvr_cmd_length(CR_CDM_CTRL_STREAM_BASE); |
| 55 |
|
| 56 |
regs->cdm_context_state_base_addr = *(const uint64_t *)stream_ptr; |
| 57 |
stream_ptr += pvr_cmd_length(CR_CDM_CONTEXT_STATE_BASE); |
| 58 |
|
| 59 |
regs->cdm_resume_pds1 = *stream_ptr; |
| 60 |
stream_ptr += pvr_cmd_length(CR_CDM_CONTEXT_PDS1); |
| 61 |
|
| 62 |
if (PVR_HAS_FEATURE(dev_info, compute_morton_capable)) { |
| 63 |
regs->cdm_item = *stream_ptr; |
| 64 |
stream_ptr += pvr_cmd_length(CR_CDM_ITEM); |
| 65 |
} |
| 66 |
|
| 67 |
if (PVR_HAS_FEATURE(dev_info, cluster_grouping)) { |
| 68 |
regs->compute_cluster = *stream_ptr; |
| 69 |
stream_ptr += pvr_cmd_length(CR_COMPUTE_CLUSTER); |
| 70 |
} |
| 71 |
|
| 72 |
if (PVR_HAS_FEATURE(dev_info, tpu_dm_global_registers)) { |
| 73 |
regs->tpu_tag_cdm_ctrl = *stream_ptr; |
| 74 |
stream_ptr++; |
| 75 |
} |
| 76 |
|
| 77 |
if (PVR_HAS_FEATURE(dev_info, gpu_multicore_support)) { |
| 78 |
cmd->execute_count = *stream_ptr; |
| 79 |
stream_ptr++; |
| 80 |
} |
| 81 |
|
| 82 |
assert((const uint8_t *)stream_ptr - stream <= stream_len); |
| 83 |
assert((const uint8_t *)stream_ptr - stream == main_stream_len); |
| 84 |
|
| 85 |
return main_stream_len; |
| 86 |
} |
| 87 |
|
| 88 |
static void pvr_srv_compute_cmd_ext_stream_load( |
| 89 |
struct rogue_fwif_cmd_compute *const cmd, |
| 90 |
const uint8_t *const stream, |
| 91 |
const uint32_t stream_len, |
| 92 |
const uint32_t ext_stream_offset, |
| 93 |
const struct pvr_device_info *const dev_info) |
| 94 |
{ |
| 95 |
const uint32_t *ext_stream_ptr = |
| 96 |
(const uint32_t *)((uint8_t *)stream + ext_stream_offset); |
| 97 |
struct rogue_fwif_cdm_regs *const regs = &cmd->regs; |
| 98 |
|
| 99 |
struct ROGUE_KMD_STREAM_EXTHDR_COMPUTE0 header0; |
| 100 |
|
| 101 |
header0 = pvr_csb_unpack(ext_stream_ptr, KMD_STREAM_EXTHDR_COMPUTE0); |
| 102 |
ext_stream_ptr += pvr_cmd_length(KMD_STREAM_EXTHDR_COMPUTE0); |
| 103 |
|
| 104 |
assert(PVR_HAS_QUIRK(dev_info, 49927) == header0.has_brn49927); |
| 105 |
if (header0.has_brn49927) { |
| 106 |
regs->tpu = *ext_stream_ptr; |
| 107 |
ext_stream_ptr += pvr_cmd_length(CR_TPU); |
| 108 |
} |
| 109 |
|
| 110 |
assert((const uint8_t *)ext_stream_ptr - stream == stream_len); |
| 111 |
} |
| 112 |
|
| 113 |
static void |
| 114 |
srv_compute_cmd_init(const struct pvr_winsys_compute_submit_info *submit_info, |
| 115 |
struct rogue_fwif_cmd_compute *cmd, |
| 116 |
const struct pvr_device_info *const dev_info) |
| 117 |
{ |
| 118 |
uint32_t ext_stream_offset; |
| 119 |
|
| 120 |
memset(cmd, 0, sizeof(*cmd)); |
| 121 |
|
| 122 |
cmd->cmn.frame_num = submit_info->frame_num; |
| 123 |
|
| 124 |
ext_stream_offset = |
| 125 |
pvr_srv_compute_cmd_stream_load(cmd, |
| 126 |
submit_info->fw_stream, |
| 127 |
submit_info->fw_stream_len, |
| 128 |
dev_info); |
| 129 |
|
| 130 |
if (ext_stream_offset < submit_info->fw_stream_len) { |
| 131 |
pvr_srv_compute_cmd_ext_stream_load(cmd, |
| 132 |
submit_info->fw_stream, |
| 133 |
submit_info->fw_stream_len, |
| 134 |
ext_stream_offset, |
| 135 |
dev_info); |
| 136 |
} |
| 137 |
|
| 138 |
if (submit_info->flags.prevent_all_overlap) |
| 139 |
cmd->flags |= ROGUE_FWIF_COMPUTE_FLAG_PREVENT_ALL_OVERLAP; |
| 140 |
|
| 141 |
if (submit_info->flags.use_single_core) |
| 142 |
cmd->flags |= ROGUE_FWIF_COMPUTE_FLAG_SINGLE_CORE; |
| 143 |
} |
| 144 |
|
| 145 |
VkResult PVR_PER_ARCH(srv_winsys_compute_submit)( |
| 146 |
const struct pvr_winsys_compute_ctx *ctx, |
| 147 |
const struct pvr_winsys_compute_submit_info *submit_info, |
| 148 |
const struct pvr_device_info *const dev_info, |
| 149 |
struct vk_sync *signal_sync) |
| 150 |
{ |
| 151 |
const struct pvr_srv_winsys_compute_ctx *srv_ctx = |
| 152 |
to_pvr_srv_winsys_compute_ctx(ctx); |
| 153 |
const struct pvr_srv_winsys *srv_ws = to_pvr_srv_winsys(ctx->ws); |
| 154 |
struct rogue_fwif_cmd_compute compute_cmd; |
| 155 |
struct pvr_srv_sync *srv_signal_sync; |
| 156 |
VkResult result; |
| 157 |
int in_fd = -1; |
| 158 |
int fence; |
| 159 |
|
| 160 |
srv_compute_cmd_init(submit_info, &compute_cmd, dev_info); |
| 161 |
|
| 162 |
if (submit_info->wait) { |
| 163 |
struct pvr_srv_sync *srv_wait_sync = to_srv_sync(submit_info->wait); |
| 164 |
|
| 165 |
if (srv_wait_sync->fd >= 0) { |
| 166 |
in_fd = os_dupfd_cloexec(srv_wait_sync->fd); |
| 167 |
if (in_fd == -1) { |
| 168 |
return vk_errorf(NULL, |
| 169 |
VK_ERROR_OUT_OF_HOST_MEMORY, |
| 170 |
"dup called on wait sync failed, Errno: %s", |
| 171 |
strerror(errno)); |
| 172 |
} |
| 173 |
} |
| 174 |
} |
| 175 |
|
| 176 |
do { |
| 177 |
result = pvr_srv_rgx_kick_compute2(srv_ws->base.render_fd, |
| 178 |
srv_ctx->handle, |
| 179 |
0U, |
| 180 |
NULL, |
| 181 |
NULL, |
| 182 |
NULL, |
| 183 |
in_fd, |
| 184 |
srv_ctx->timeline, |
| 185 |
sizeof(compute_cmd), |
| 186 |
(uint8_t *)&compute_cmd, |
| 187 |
submit_info->job_num, |
| 188 |
0, |
| 189 |
NULL, |
| 190 |
NULL, |
| 191 |
0U, |
| 192 |
0U, |
| 193 |
0U, |
| 194 |
0U, |
| 195 |
"COMPUTE", |
| 196 |
&fence); |
| 197 |
} while (result == VK_NOT_READY); |
| 198 |
|
| 199 |
if (result != VK_SUCCESS) |
| 200 |
goto end_close_in_fd; |
| 201 |
|
| 202 |
if (signal_sync) { |
| 203 |
srv_signal_sync = to_srv_sync(signal_sync); |
| 204 |
pvr_srv_set_sync_payload(srv_signal_sync, fence); |
| 205 |
} else if (fence != -1) { |
| 206 |
close(fence); |
| 207 |
} |
| 208 |
|
| 209 |
end_close_in_fd: |
| 210 |
if (in_fd >= 0) |
| 211 |
close(in_fd); |
| 212 |
|
| 213 |
return result; |
| 214 |
} |