| 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 <errno.h> |
| 25 |
#include <fcntl.h> |
| 26 |
#include <limits.h> |
| 27 |
#include <stddef.h> |
| 28 |
#include <stdint.h> |
| 29 |
#include <string.h> |
| 30 |
#include <unistd.h> |
| 31 |
#include <vulkan/vulkan.h> |
| 32 |
|
| 33 |
#include "fw-api/pvr_rogue_fwif.h" |
| 34 |
#include "fw-api/pvr_rogue_fwif_rf.h" |
| 35 |
#include "pvr_device_info.h" |
| 36 |
#include "pvr_srv.h" |
| 37 |
#include "pvr_srv_bridge.h" |
| 38 |
#include "pvr_srv_job_common.h" |
| 39 |
#include "pvr_srv_job_compute.h" |
| 40 |
#include "pvr_srv_sync.h" |
| 41 |
#include "pvr_winsys.h" |
| 42 |
#include "util/macros.h" |
| 43 |
#include "util/os_file.h" |
| 44 |
#include "vk_alloc.h" |
| 45 |
#include "vk_log.h" |
| 46 |
|
| 47 |
VkResult pvr_srv_winsys_compute_ctx_create( |
| 48 |
struct pvr_winsys *ws, |
| 49 |
const struct pvr_winsys_compute_ctx_create_info *create_info, |
| 50 |
const struct pvr_device_info *dev_info, |
| 51 |
struct pvr_winsys_compute_ctx **const ctx_out) |
| 52 |
{ |
| 53 |
/* TODO: handle non-rogue GPUs */ |
| 54 |
assert(dev_info->ident.arch == PVR_DEVICE_ARCH_ROGUE); |
| 55 |
const struct pvr_rogue_winsys_compute_ctx_static_state *rogue_state = |
| 56 |
&create_info->static_state.rogue; |
| 57 |
|
| 58 |
struct rogue_fwif_static_computecontext_state static_state = { |
| 59 |
.ctx_switch_regs = { |
| 60 |
.cdm_context_pds0 = rogue_state->cdm_ctx_store_pds0, |
| 61 |
.cdm_context_pds0_b = rogue_state->cdm_ctx_store_pds0_b, |
| 62 |
.cdm_context_pds1 = rogue_state->cdm_ctx_store_pds1, |
| 63 |
|
| 64 |
.cdm_terminate_pds = rogue_state->cdm_ctx_terminate_pds, |
| 65 |
.cdm_terminate_pds1 = rogue_state->cdm_ctx_terminate_pds1, |
| 66 |
|
| 67 |
.cdm_resume_pds0 = rogue_state->cdm_ctx_resume_pds0, |
| 68 |
.cdm_resume_pds0_b = rogue_state->cdm_ctx_resume_pds0_b, |
| 69 |
}, |
| 70 |
}; |
| 71 |
|
| 72 |
struct rogue_fwif_rf_cmd reset_cmd = { 0 }; |
| 73 |
|
| 74 |
struct pvr_srv_winsys *srv_ws = to_pvr_srv_winsys(ws); |
| 75 |
struct pvr_srv_winsys_compute_ctx *srv_ctx; |
| 76 |
VkResult result; |
| 77 |
|
| 78 |
srv_ctx = vk_alloc(ws->alloc, |
| 79 |
sizeof(*srv_ctx), |
| 80 |
8U, |
| 81 |
VK_SYSTEM_ALLOCATION_SCOPE_DEVICE); |
| 82 |
if (!srv_ctx) |
| 83 |
return vk_error(NULL, VK_ERROR_OUT_OF_HOST_MEMORY); |
| 84 |
|
| 85 |
result = pvr_srv_create_timeline(ws->render_fd, &srv_ctx->timeline); |
| 86 |
if (result != VK_SUCCESS) |
| 87 |
goto err_free_srv_ctx; |
| 88 |
|
| 89 |
/* TODO: Add support for reset framework. Currently we subtract |
| 90 |
* reset_cmd.regs size from reset_cmd size to only pass empty flags field. |
| 91 |
*/ |
| 92 |
result = pvr_srv_rgx_create_compute_context( |
| 93 |
ws->render_fd, |
| 94 |
pvr_srv_from_winsys_priority(create_info->priority), |
| 95 |
sizeof(reset_cmd) - sizeof(reset_cmd.regs), |
| 96 |
(uint8_t *)&reset_cmd, |
| 97 |
srv_ws->server_memctx_data, |
| 98 |
sizeof(static_state), |
| 99 |
(uint8_t *)&static_state, |
| 100 |
0U, |
| 101 |
RGX_CONTEXT_FLAG_DISABLESLR, |
| 102 |
0U, |
| 103 |
UINT_MAX, |
| 104 |
&srv_ctx->handle); |
| 105 |
if (result != VK_SUCCESS) |
| 106 |
goto err_close_timeline; |
| 107 |
|
| 108 |
srv_ctx->base.ws = ws; |
| 109 |
|
| 110 |
*ctx_out = &srv_ctx->base; |
| 111 |
|
| 112 |
return VK_SUCCESS; |
| 113 |
|
| 114 |
err_close_timeline: |
| 115 |
close(srv_ctx->timeline); |
| 116 |
|
| 117 |
err_free_srv_ctx: |
| 118 |
vk_free(ws->alloc, srv_ctx); |
| 119 |
|
| 120 |
return result; |
| 121 |
} |
| 122 |
|
| 123 |
void pvr_srv_winsys_compute_ctx_destroy(struct pvr_winsys_compute_ctx *ctx) |
| 124 |
{ |
| 125 |
struct pvr_srv_winsys *srv_ws = to_pvr_srv_winsys(ctx->ws); |
| 126 |
struct pvr_srv_winsys_compute_ctx *srv_ctx = |
| 127 |
to_pvr_srv_winsys_compute_ctx(ctx); |
| 128 |
|
| 129 |
pvr_srv_rgx_destroy_compute_context(srv_ws->base.render_fd, srv_ctx->handle); |
| 130 |
close(srv_ctx->timeline); |
| 131 |
vk_free(srv_ws->base.alloc, srv_ctx); |
| 132 |
} |