Debian Codegraph @

src/imagination/vulkan/winsys/pvrsrvkm/pvr_srv_job_transfer.c

raw
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 <stddef.h>
27 #include <stdint.h>
28 #include <string.h>
29 #include <unistd.h>
30 #include <vulkan/vulkan.h>
31
32 #include "fw-api/pvr_rogue_fwif.h"
33 #include "fw-api/pvr_rogue_fwif_rf.h"
34
35 #include "pvr_device_info.h"
36 #include "pvr_srv.h"
37 #include "pvr_srv_job_common.h"
38 #include "pvr_srv_job_transfer.h"
39 #include "pvr_srv_sync.h"
40 #include "pvr_winsys.h"
41
42 #include "util/macros.h"
43
44 #include "vk_alloc.h"
45 #include "vk_log.h"
46
47 #define PVR_SRV_TRANSFER_CONTEXT_INITIAL_CCB_SIZE_LOG2 16U
48 #define PVR_SRV_TRANSFER_CONTEXT_MAX_CCB_SIZE_LOG2 0U
49
50 VkResult pvr_srv_winsys_transfer_ctx_create(
51 struct pvr_winsys *ws,
52 const struct pvr_winsys_transfer_ctx_create_info *create_info,
53 struct pvr_winsys_transfer_ctx **const ctx_out)
54 {
55 struct pvr_srv_winsys *srv_ws = to_pvr_srv_winsys(ws);
56 struct pvr_srv_winsys_transfer_ctx *srv_ctx;
57 struct rogue_fwif_rf_cmd reset_cmd = { 0 };
58 VkResult result;
59
60 /* First 2 U8s are 2d work load related, and the last 2 are 3d workload
61 * related.
62 */
63 const uint32_t packed_ccb_size =
64 PVR_U8888_TO_U32(PVR_SRV_TRANSFER_CONTEXT_INITIAL_CCB_SIZE_LOG2,
65 PVR_SRV_TRANSFER_CONTEXT_MAX_CCB_SIZE_LOG2,
66 PVR_SRV_TRANSFER_CONTEXT_INITIAL_CCB_SIZE_LOG2,
67 PVR_SRV_TRANSFER_CONTEXT_MAX_CCB_SIZE_LOG2);
68
69 srv_ctx = vk_alloc(ws->alloc,
70 sizeof(*srv_ctx),
71 8U,
72 VK_SYSTEM_ALLOCATION_SCOPE_DEVICE);
73 if (!srv_ctx)
74 return vk_error(NULL, VK_ERROR_OUT_OF_HOST_MEMORY);
75
76 result = pvr_srv_create_timeline(ws->render_fd, &srv_ctx->timeline_3d);
77 if (result != VK_SUCCESS)
78 goto err_free_srv_ctx;
79
80 /* TODO: Add support for reset framework. Currently we subtract
81 * reset_cmd.regs size from reset_cmd size to only pass empty flags field.
82 */
83 result = pvr_srv_rgx_create_transfer_context(
84 ws->render_fd,
85 pvr_srv_from_winsys_priority(create_info->priority),
86 sizeof(reset_cmd) - sizeof(reset_cmd.regs),
87 (uint8_t *)&reset_cmd,
88 srv_ws->server_memctx_data,
89 packed_ccb_size,
90 RGX_CONTEXT_FLAG_DISABLESLR,
91 0U,
92 NULL,
93 NULL,
94 &srv_ctx->handle);
95 if (result != VK_SUCCESS)
96 goto err_close_timeline;
97
98 srv_ctx->base.ws = ws;
99 *ctx_out = &srv_ctx->base;
100
101 return VK_SUCCESS;
102
103 err_close_timeline:
104 close(srv_ctx->timeline_3d);
105
106 err_free_srv_ctx:
107 vk_free(ws->alloc, srv_ctx);
108
109 return result;
110 }
111
112 void pvr_srv_winsys_transfer_ctx_destroy(struct pvr_winsys_transfer_ctx *ctx)
113 {
114 struct pvr_srv_winsys *srv_ws = to_pvr_srv_winsys(ctx->ws);
115 struct pvr_srv_winsys_transfer_ctx *srv_ctx =
116 to_pvr_srv_winsys_transfer_ctx(ctx);
117
118 pvr_srv_rgx_destroy_transfer_context(srv_ws->base.render_fd,
119 srv_ctx->handle);
120 close(srv_ctx->timeline_3d);
121 vk_free(srv_ws->base.alloc, srv_ctx);
122 }