| 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_transfer.h" |
| 25 |
|
| 26 |
#include "util/os_file.h" |
| 27 |
|
| 28 |
#include "vk_log.h" |
| 29 |
#include "vk_util.h" |
| 30 |
|
| 31 |
#include "fw-api/pvr_rogue_fwif.h" |
| 32 |
|
| 33 |
#include "pvr_csb.h" |
| 34 |
#include "pvr_device_info.h" |
| 35 |
#include "pvr_srv.h" |
| 36 |
#include "pvr_srv_bridge.h" |
| 37 |
|
| 38 |
static void |
| 39 |
srv_transfer_cmd_stream_load(struct rogue_fwif_cmd_transfer *const cmd, |
| 40 |
const uint8_t *const stream, |
| 41 |
const uint32_t stream_len, |
| 42 |
const struct pvr_device_info *const dev_info) |
| 43 |
{ |
| 44 |
const uint32_t *stream_ptr = (const uint32_t *)stream; |
| 45 |
struct rogue_fwif_transfer_regs *const regs = &cmd->regs; |
| 46 |
uint32_t main_stream_len = |
| 47 |
pvr_csb_unpack((uint64_t *)stream_ptr, KMD_STREAM_HDR).length; |
| 48 |
|
| 49 |
stream_ptr += pvr_cmd_length(KMD_STREAM_HDR); |
| 50 |
|
| 51 |
memcpy(®s->pds_bgnd0_base, stream_ptr, sizeof(regs->pds_bgnd0_base)); |
| 52 |
stream_ptr += pvr_cmd_length(CR_PDS_BGRND0_BASE); |
| 53 |
|
| 54 |
memcpy(®s->pds_bgnd1_base, stream_ptr, sizeof(regs->pds_bgnd1_base)); |
| 55 |
stream_ptr += pvr_cmd_length(CR_PDS_BGRND1_BASE); |
| 56 |
|
| 57 |
memcpy(®s->pds_bgnd3_sizeinfo, |
| 58 |
stream_ptr, |
| 59 |
sizeof(regs->pds_bgnd3_sizeinfo)); |
| 60 |
stream_ptr += pvr_cmd_length(CR_PDS_BGRND3_SIZEINFO); |
| 61 |
|
| 62 |
memcpy(®s->isp_mtile_base, stream_ptr, sizeof(regs->isp_mtile_base)); |
| 63 |
stream_ptr += pvr_cmd_length(CR_ISP_MTILE_BASE); |
| 64 |
|
| 65 |
STATIC_ASSERT(ARRAY_SIZE(regs->pbe_wordx_mrty) == 9U); |
| 66 |
STATIC_ASSERT(sizeof(regs->pbe_wordx_mrty[0]) == sizeof(uint64_t)); |
| 67 |
memcpy(regs->pbe_wordx_mrty, stream_ptr, sizeof(regs->pbe_wordx_mrty)); |
| 68 |
stream_ptr += 9U * 2U; |
| 69 |
|
| 70 |
regs->isp_bgobjvals = *stream_ptr; |
| 71 |
stream_ptr += pvr_cmd_length(CR_ISP_BGOBJVALS); |
| 72 |
|
| 73 |
regs->usc_pixel_output_ctrl = *stream_ptr; |
| 74 |
stream_ptr += pvr_cmd_length(CR_USC_PIXEL_OUTPUT_CTRL); |
| 75 |
|
| 76 |
regs->usc_clear_register0 = *stream_ptr; |
| 77 |
stream_ptr += pvr_cmd_length(CR_USC_CLEAR_REGISTER); |
| 78 |
|
| 79 |
regs->usc_clear_register1 = *stream_ptr; |
| 80 |
stream_ptr += pvr_cmd_length(CR_USC_CLEAR_REGISTER); |
| 81 |
|
| 82 |
regs->usc_clear_register2 = *stream_ptr; |
| 83 |
stream_ptr += pvr_cmd_length(CR_USC_CLEAR_REGISTER); |
| 84 |
|
| 85 |
regs->usc_clear_register3 = *stream_ptr; |
| 86 |
stream_ptr += pvr_cmd_length(CR_USC_CLEAR_REGISTER); |
| 87 |
|
| 88 |
regs->isp_mtile_size = *stream_ptr; |
| 89 |
stream_ptr += pvr_cmd_length(CR_ISP_MTILE_SIZE); |
| 90 |
|
| 91 |
regs->isp_render_origin = *stream_ptr; |
| 92 |
stream_ptr += pvr_cmd_length(CR_ISP_RENDER_ORIGIN); |
| 93 |
|
| 94 |
regs->isp_ctl = *stream_ptr; |
| 95 |
stream_ptr += pvr_cmd_length(CR_ISP_CTL); |
| 96 |
|
| 97 |
regs->isp_aa = *stream_ptr; |
| 98 |
stream_ptr += pvr_cmd_length(CR_ISP_AA); |
| 99 |
|
| 100 |
regs->event_pixel_pds_info = *stream_ptr; |
| 101 |
stream_ptr += pvr_cmd_length(CR_EVENT_PIXEL_PDS_INFO); |
| 102 |
|
| 103 |
regs->event_pixel_pds_code = *stream_ptr; |
| 104 |
stream_ptr += pvr_cmd_length(CR_EVENT_PIXEL_PDS_CODE); |
| 105 |
|
| 106 |
regs->event_pixel_pds_data = *stream_ptr; |
| 107 |
stream_ptr += pvr_cmd_length(CR_EVENT_PIXEL_PDS_DATA); |
| 108 |
|
| 109 |
regs->isp_render = *stream_ptr; |
| 110 |
stream_ptr += pvr_cmd_length(CR_ISP_RENDER); |
| 111 |
|
| 112 |
regs->isp_rgn = *stream_ptr; |
| 113 |
stream_ptr++; |
| 114 |
|
| 115 |
if (PVR_HAS_FEATURE(dev_info, gpu_multicore_support)) { |
| 116 |
regs->frag_screen = *stream_ptr; |
| 117 |
stream_ptr++; |
| 118 |
} |
| 119 |
|
| 120 |
assert((const uint8_t *)stream_ptr - stream == stream_len); |
| 121 |
assert((const uint8_t *)stream_ptr - stream == main_stream_len); |
| 122 |
} |
| 123 |
|
| 124 |
static void pvr_srv_transfer_cmds_init( |
| 125 |
const struct pvr_winsys_transfer_submit_info *submit_info, |
| 126 |
struct rogue_fwif_cmd_transfer *cmds, |
| 127 |
uint32_t cmd_count, |
| 128 |
const struct pvr_device_info *const dev_info) |
| 129 |
{ |
| 130 |
memset(cmds, 0, sizeof(*cmds) * submit_info->cmd_count); |
| 131 |
|
| 132 |
for (uint32_t i = 0; i < cmd_count; i++) { |
| 133 |
const struct pvr_winsys_transfer_cmd *submit_cmd = &submit_info->cmds[i]; |
| 134 |
struct rogue_fwif_cmd_transfer *cmd = &cmds[i]; |
| 135 |
|
| 136 |
cmd->cmn.frame_num = submit_info->frame_num; |
| 137 |
|
| 138 |
srv_transfer_cmd_stream_load(cmd, |
| 139 |
submit_cmd->fw_stream, |
| 140 |
submit_cmd->fw_stream_len, |
| 141 |
dev_info); |
| 142 |
|
| 143 |
if (submit_info->cmds[i].flags.use_single_core) |
| 144 |
cmd->flags |= ROGUE_FWIF_CMDTRANSFER_SINGLE_CORE; |
| 145 |
} |
| 146 |
} |
| 147 |
|
| 148 |
VkResult PVR_PER_ARCH(srv_winsys_transfer_submit)( |
| 149 |
const struct pvr_winsys_transfer_ctx *ctx, |
| 150 |
const struct pvr_winsys_transfer_submit_info *submit_info, |
| 151 |
const struct pvr_device_info *const dev_info, |
| 152 |
struct vk_sync *signal_sync) |
| 153 |
{ |
| 154 |
const struct pvr_srv_winsys_transfer_ctx *srv_ctx = |
| 155 |
to_pvr_srv_winsys_transfer_ctx(ctx); |
| 156 |
const struct pvr_srv_winsys *srv_ws = to_pvr_srv_winsys(ctx->ws); |
| 157 |
|
| 158 |
struct rogue_fwif_cmd_transfer |
| 159 |
*cmds_ptr_arr[PVR_TRANSFER_MAX_PREPARES_PER_SUBMIT]; |
| 160 |
uint32_t *update_sync_offsets[PVR_TRANSFER_MAX_PREPARES_PER_SUBMIT] = { 0 }; |
| 161 |
uint32_t client_update_count[PVR_TRANSFER_MAX_PREPARES_PER_SUBMIT] = { 0 }; |
| 162 |
void **update_ufo_syc_prims[PVR_TRANSFER_MAX_PREPARES_PER_SUBMIT] = { 0 }; |
| 163 |
uint32_t *update_values[PVR_TRANSFER_MAX_PREPARES_PER_SUBMIT] = { 0 }; |
| 164 |
uint32_t cmd_flags[PVR_TRANSFER_MAX_PREPARES_PER_SUBMIT] = { 0 }; |
| 165 |
uint32_t cmd_sizes[PVR_TRANSFER_MAX_PREPARES_PER_SUBMIT]; |
| 166 |
|
| 167 |
struct pvr_srv_sync *srv_signal_sync; |
| 168 |
uint32_t job_num; |
| 169 |
VkResult result; |
| 170 |
int in_fd = -1; |
| 171 |
int fence; |
| 172 |
|
| 173 |
STACK_ARRAY(struct rogue_fwif_cmd_transfer, |
| 174 |
transfer_cmds, |
| 175 |
submit_info->cmd_count); |
| 176 |
if (!transfer_cmds) |
| 177 |
return vk_error(NULL, VK_ERROR_OUT_OF_HOST_MEMORY); |
| 178 |
|
| 179 |
pvr_srv_transfer_cmds_init(submit_info, |
| 180 |
transfer_cmds, |
| 181 |
submit_info->cmd_count, |
| 182 |
dev_info); |
| 183 |
|
| 184 |
for (uint32_t i = 0U; i < submit_info->cmd_count; i++) { |
| 185 |
cmd_sizes[i] = sizeof(**cmds_ptr_arr); |
| 186 |
cmds_ptr_arr[i] = &transfer_cmds[i]; |
| 187 |
} |
| 188 |
|
| 189 |
if (submit_info->wait) { |
| 190 |
struct pvr_srv_sync *srv_wait_sync = to_srv_sync(submit_info->wait); |
| 191 |
|
| 192 |
if (srv_wait_sync->fd >= 0) { |
| 193 |
in_fd = os_dupfd_cloexec(srv_wait_sync->fd); |
| 194 |
if (in_fd == -1) { |
| 195 |
return vk_errorf(NULL, |
| 196 |
VK_ERROR_OUT_OF_HOST_MEMORY, |
| 197 |
"dup called on wait sync failed, Errno: %s", |
| 198 |
strerror(errno)); |
| 199 |
} |
| 200 |
} |
| 201 |
} |
| 202 |
|
| 203 |
job_num = submit_info->job_num; |
| 204 |
|
| 205 |
do { |
| 206 |
result = pvr_srv_rgx_submit_transfer2(srv_ws->base.render_fd, |
| 207 |
srv_ctx->handle, |
| 208 |
submit_info->cmd_count, |
| 209 |
client_update_count, |
| 210 |
update_ufo_syc_prims, |
| 211 |
update_sync_offsets, |
| 212 |
update_values, |
| 213 |
in_fd, |
| 214 |
-1, |
| 215 |
srv_ctx->timeline_3d, |
| 216 |
"TRANSFER", |
| 217 |
cmd_sizes, |
| 218 |
(uint8_t **)cmds_ptr_arr, |
| 219 |
cmd_flags, |
| 220 |
job_num, |
| 221 |
0U, |
| 222 |
NULL, |
| 223 |
NULL, |
| 224 |
NULL, |
| 225 |
&fence); |
| 226 |
} while (result == VK_NOT_READY); |
| 227 |
|
| 228 |
if (result != VK_SUCCESS) |
| 229 |
goto end_close_in_fd; |
| 230 |
|
| 231 |
if (signal_sync) { |
| 232 |
srv_signal_sync = to_srv_sync(signal_sync); |
| 233 |
pvr_srv_set_sync_payload(srv_signal_sync, fence); |
| 234 |
} else if (fence != -1) { |
| 235 |
close(fence); |
| 236 |
} |
| 237 |
|
| 238 |
end_close_in_fd: |
| 239 |
if (in_fd >= 0) |
| 240 |
close(in_fd); |
| 241 |
|
| 242 |
STACK_ARRAY_FINISH(transfer_cmds); |
| 243 |
|
| 244 |
return result; |
| 245 |
} |