Debian Codegraph @

src/imagination/vulkan/winsys/pvr_winsys.h

raw
1 /*
2 * Copyright © 2022 Imagination Technologies Ltd.
3 *
4 * Based on radv_radeon_winsys.h which is:
5 * Copyright © 2016 Red Hat.
6 * Copyright © 2016 Bas Nieuwenhuizen
7 *
8 * Permission is hereby granted, free of charge, to any person obtaining a copy
9 * of this software and associated documentation files (the "Software"), to deal
10 * in the Software without restriction, including without limitation the rights
11 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12 * copies of the Software, and to permit persons to whom the Software is
13 * furnished to do so, subject to the following conditions:
14 *
15 * The above copyright notice and this permission notice (including the next
16 * paragraph) shall be included in all copies or substantial portions of the
17 * Software.
18 *
19 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
25 * SOFTWARE.
26 */
27
28 #ifndef PVR_WINSYS_H
29 #define PVR_WINSYS_H
30
31 #include <pthread.h>
32 #include <inttypes.h>
33 #include <stdbool.h>
34 #include <stdint.h>
35 #include <vulkan/vulkan.h>
36
37 #include "hwdef/rogue_hw_defs.h"
38 #include "pvr_limits.h"
39 #include "pvr_rogue_fw.h"
40 #include "pvr_types.h"
41 #include "util/macros.h"
42 #include "util/vma.h"
43 #include "vk_sync.h"
44 #include "vk_sync_timeline.h"
45
46 #define PVR_DRM_DRIVER_NAME "powervr"
47 #define PVR_SRV_DRIVER_NAME "pvr"
48
49 struct pvr_device_info;
50 struct pvr_device_runtime_info;
51
52 struct pvr_winsys_heaps {
53 struct pvr_winsys_heap *general_heap;
54 struct pvr_winsys_heap *pds_heap;
55 struct pvr_winsys_heap *rgn_hdr_heap;
56 struct pvr_winsys_heap *transfer_frag_heap;
57 struct pvr_winsys_heap *usc_heap;
58 struct pvr_winsys_heap *vis_test_heap;
59 };
60
61 struct pvr_winsys_static_data_offsets {
62 uint64_t eot;
63 uint64_t fence;
64 uint64_t vdm_sync;
65 uint64_t yuv_csc;
66 };
67
68 struct pvr_winsys_heap {
69 struct pvr_winsys *ws;
70
71 pvr_dev_addr_t base_addr;
72 pvr_dev_addr_t static_data_carveout_addr;
73
74 uint64_t size;
75 uint64_t static_data_carveout_size;
76
77 uint32_t page_size;
78 uint32_t log2_page_size;
79
80 struct util_vma_heap vma_heap;
81 int ref_count;
82 pthread_mutex_t lock;
83
84 /* These are the offsets from the base at which static data might be
85 * uploaded. Some of these might be invalid since the kernel might not
86 * return all of these offsets per each heap as they might not be
87 * applicable.
88 * You should know which to use beforehand. There should be no need to check
89 * whether an offset is valid or invalid.
90 */
91 struct pvr_winsys_static_data_offsets static_data_offsets;
92 };
93
94 enum pvr_winsys_bo_type {
95 PVR_WINSYS_BO_TYPE_GPU = 0,
96 PVR_WINSYS_BO_TYPE_DISPLAY = 1,
97 };
98
99 /**
100 * \brief Flag passed to #pvr_winsys_ops.buffer_create to indicate that the
101 * buffer should be CPU accessible. This is required in order to map the buffer
102 * using #pvr_winsys_ops.buffer_map.
103 */
104 #define PVR_WINSYS_BO_FLAG_CPU_ACCESS BITFIELD_BIT(0U)
105 /**
106 * \brief Flag passed to #pvr_winsys_ops.buffer_create to indicate that, when
107 * the buffer is mapped to the GPU using #pvr_winsys.vma_map, it should be
108 * mapped uncached.
109 */
110 #define PVR_WINSYS_BO_FLAG_GPU_UNCACHED BITFIELD_BIT(1U)
111 /**
112 * \brief Flag passed to #pvr_winsys_ops.buffer_create to indicate that, when
113 * the buffer is mapped to the GPU using #pvr_winsys.vma_map, it should only be
114 * accessible to the Parameter Manager unit and firmware processor.
115 */
116 #define PVR_WINSYS_BO_FLAG_PM_FW_PROTECT BITFIELD_BIT(2U)
117
118 struct pvr_winsys_bo {
119 struct pvr_winsys *ws;
120 void *map;
121 uint64_t size;
122
123 bool is_imported;
124
125 #if defined(HAVE_VALGRIND)
126 char *vbits;
127 #endif /* defined(HAVE_VALGRIND) */
128 };
129
130 struct pvr_winsys_vma {
131 struct pvr_winsys_heap *heap;
132
133 /* Buffer and offset this vma is bound to. */
134 struct pvr_winsys_bo *bo;
135 VkDeviceSize bo_offset;
136
137 pvr_dev_addr_t dev_addr;
138 uint64_t size;
139 uint64_t mapped_size;
140 };
141
142 struct pvr_winsys_free_list {
143 struct pvr_winsys *ws;
144 };
145
146 struct pvr_winsys_rt_dataset_create_info {
147 /* Local freelist */
148 struct pvr_winsys_free_list *local_free_list;
149
150 uint32_t width;
151 uint32_t height;
152 uint32_t samples;
153 uint16_t layers;
154
155 /* ISP register values */
156 uint32_t isp_merge_lower_x;
157 uint32_t isp_merge_lower_y;
158 uint32_t isp_merge_scale_x;
159 uint32_t isp_merge_scale_y;
160 uint32_t isp_merge_upper_x;
161 uint32_t isp_merge_upper_y;
162
163 /* Allocations and associated information */
164 pvr_dev_addr_t vheap_table_dev_addr;
165 pvr_dev_addr_t rtc_dev_addr;
166
167 pvr_dev_addr_t tpc_dev_addr;
168 uint32_t tpc_stride;
169 uint32_t tpc_size;
170
171 struct {
172 pvr_dev_addr_t pm_mlist_dev_addr;
173 pvr_dev_addr_t macrotile_array_dev_addr;
174 pvr_dev_addr_t rgn_header_dev_addr;
175 } rt_datas[ROGUE_NUM_RTDATAS];
176 uint64_t rgn_header_size;
177 };
178
179 struct pvr_winsys_rt_dataset {
180 struct pvr_winsys *ws;
181 };
182
183 enum pvr_winsys_ctx_priority {
184 PVR_WINSYS_CTX_PRIORITY_LOW,
185 PVR_WINSYS_CTX_PRIORITY_MEDIUM,
186 PVR_WINSYS_CTX_PRIORITY_HIGH,
187 };
188
189 struct pvr_winsys_render_ctx_create_info {
190 enum pvr_winsys_ctx_priority priority;
191 pvr_dev_addr_t vdm_callstack_addr;
192
193 union {
194 struct pvr_rogue_winsys_render_ctx_static_state {
195 uint64_t vdm_ctx_state_base_addr;
196 uint64_t geom_ctx_state_base_addr;
197
198 struct {
199 uint64_t vdm_ctx_store_task0;
200 uint32_t vdm_ctx_store_task1;
201 uint64_t vdm_ctx_store_task2;
202
203 uint64_t vdm_ctx_resume_task0;
204 uint32_t vdm_ctx_resume_task1;
205 uint64_t vdm_ctx_resume_task2;
206 } geom_state[2];
207 } rogue;
208 } static_state;
209 };
210
211 struct pvr_winsys_render_ctx {
212 struct pvr_winsys *ws;
213 };
214
215 struct pvr_winsys_compute_ctx_create_info {
216 enum pvr_winsys_ctx_priority priority;
217
218 union {
219 struct pvr_rogue_winsys_compute_ctx_static_state {
220 uint64_t cdm_ctx_store_pds0;
221 uint64_t cdm_ctx_store_pds0_b;
222 uint32_t cdm_ctx_store_pds1;
223
224 uint64_t cdm_ctx_terminate_pds;
225 uint32_t cdm_ctx_terminate_pds1;
226
227 uint64_t cdm_ctx_resume_pds0;
228 uint64_t cdm_ctx_resume_pds0_b;
229 } rogue;
230 } static_state;
231 };
232
233 struct pvr_winsys_compute_ctx {
234 struct pvr_winsys *ws;
235 };
236
237 struct pvr_winsys_transfer_ctx_create_info {
238 enum pvr_winsys_ctx_priority priority;
239 };
240
241 struct pvr_winsys_transfer_ctx {
242 struct pvr_winsys *ws;
243 };
244
245 #define PVR_TRANSFER_MAX_PREPARES_PER_SUBMIT 16U
246 #define PVR_TRANSFER_MAX_RENDER_TARGETS 3U
247
248 struct pvr_winsys_transfer_regs {
249 uint32_t event_pixel_pds_code;
250 uint32_t event_pixel_pds_data;
251 uint32_t event_pixel_pds_info;
252 uint32_t frag_screen;
253 uint32_t isp_aa;
254 uint32_t isp_bgobjvals;
255 uint32_t isp_ctl;
256 uint64_t isp_mtile_base;
257 uint32_t isp_mtile_size;
258 uint32_t isp_render;
259 uint32_t isp_render_origin;
260 uint32_t isp_rgn;
261 uint64_t pbe_wordx_mrty[PVR_TRANSFER_MAX_RENDER_TARGETS *
262 ROGUE_NUM_PBESTATE_REG_WORDS];
263 uint64_t pds_bgnd0_base;
264 uint64_t pds_bgnd1_base;
265 uint64_t pds_bgnd3_sizeinfo;
266 uint32_t usc_clear_register0;
267 uint32_t usc_clear_register1;
268 uint32_t usc_clear_register2;
269 uint32_t usc_clear_register3;
270 uint32_t usc_pixel_output_ctrl;
271 };
272
273 struct pvr_winsys_transfer_cmd {
274 /* Firmware stream buffer. This is the maximum possible size taking into
275 * consideration all HW features, quirks and enhancements.
276 */
277 uint8_t fw_stream[176];
278 uint32_t fw_stream_len;
279
280 struct pvr_winsys_transfer_cmd_flags {
281 bool use_single_core : 1;
282 } flags;
283 };
284
285 struct pvr_winsys_transfer_submit_info {
286 uint32_t frame_num;
287 uint32_t job_num;
288
289 struct vk_sync *wait;
290
291 uint32_t cmd_count;
292 struct pvr_winsys_transfer_cmd cmds[PVR_TRANSFER_MAX_PREPARES_PER_SUBMIT];
293 };
294
295 struct pvr_winsys_compute_submit_info {
296 uint32_t frame_num;
297 uint32_t job_num;
298
299 struct vk_sync *wait;
300
301 /* Firmware stream buffer. This is the maximum possible size taking into
302 * consideration all HW features, quirks and enhancements.
303 */
304 uint8_t fw_stream[100];
305 uint32_t fw_stream_len;
306
307 struct pvr_winsys_compute_submit_flags {
308 bool prevent_all_overlap : 1;
309 bool use_single_core : 1;
310 } flags;
311 };
312
313 struct pvr_winsys_render_submit_info {
314 struct pvr_winsys_rt_dataset *rt_dataset;
315 uint8_t rt_data_idx;
316
317 uint32_t frame_num;
318 uint32_t job_num;
319 bool has_fragment_job;
320
321 struct pvr_winsys_geometry_state {
322 /* Firmware stream buffer. This is the maximum possible size taking into
323 * consideration all HW features, quirks and enhancements.
324 */
325 uint8_t fw_stream[64];
326 uint32_t fw_stream_len;
327
328 struct pvr_winsys_geometry_state_flags {
329 bool is_first_geometry : 1;
330 bool is_last_geometry : 1;
331 bool use_single_core : 1;
332 } flags;
333
334 struct vk_sync *wait;
335 } geometry;
336
337 struct pvr_winsys_fragment_state {
338 /* Firmware stream buffer. This is the maximum possible size taking into
339 * consideration all HW features, quirks and enhancements.
340 */
341 uint8_t fw_stream[440];
342 uint32_t fw_stream_len;
343
344 struct pvr_winsys_fragment_state_flags {
345 bool has_depth_buffer : 1;
346 bool has_stencil_buffer : 1;
347 bool prevent_cdm_overlap : 1;
348 bool use_single_core : 1;
349 bool get_vis_results : 1;
350 bool has_spm_scratch_buffer : 1;
351 bool disable_pixel_merging : 1;
352 } flags;
353
354 struct vk_sync *wait;
355 } fragment, fragment_pr;
356 };
357
358 struct pvr_winsys_ops {
359 void (*destroy)(struct pvr_winsys *ws);
360 VkResult (*device_info_init)(struct pvr_winsys *ws,
361 struct pvr_device_info *dev_info,
362 struct pvr_device_runtime_info *runtime_info);
363 void (*get_heaps_info)(struct pvr_winsys *ws,
364 struct pvr_winsys_heaps *heaps);
365
366 VkResult (*buffer_create)(struct pvr_winsys *ws,
367 uint64_t size,
368 uint64_t alignment,
369 enum pvr_winsys_bo_type type,
370 uint32_t flags,
371 struct pvr_winsys_bo **const bo_out);
372 VkResult (*buffer_create_from_fd)(struct pvr_winsys *ws,
373 int fd,
374 struct pvr_winsys_bo **const bo_out);
375 void (*buffer_destroy)(struct pvr_winsys_bo *bo);
376
377 VkResult (*buffer_get_fd)(struct pvr_winsys_bo *bo, int *const fd_out);
378
379 VkResult (*buffer_map)(struct pvr_winsys_bo *bo, void *addr);
380 VkResult (*buffer_unmap)(struct pvr_winsys_bo *bo, bool reserve);
381
382 VkResult (*heap_alloc)(struct pvr_winsys_heap *heap,
383 uint64_t size,
384 uint64_t alignment,
385 struct pvr_winsys_vma **vma_out);
386 void (*heap_free)(struct pvr_winsys_vma *vma);
387
388 VkResult (*vma_map)(struct pvr_winsys_vma *vma,
389 struct pvr_winsys_bo *bo,
390 uint64_t offset,
391 uint64_t size,
392 pvr_dev_addr_t *dev_addr_out);
393 void (*vma_unmap)(struct pvr_winsys_vma *vma);
394
395 VkResult (*free_list_create)(
396 struct pvr_winsys *ws,
397 struct pvr_winsys_vma *free_list_vma,
398 uint32_t initial_num_pages,
399 uint32_t max_num_pages,
400 uint32_t grow_num_pages,
401 uint32_t grow_threshold,
402 struct pvr_winsys_free_list *parent_free_list,
403 struct pvr_winsys_free_list **const free_list_out);
404 void (*free_list_destroy)(struct pvr_winsys_free_list *free_list);
405
406 VkResult (*render_target_dataset_create)(
407 struct pvr_winsys *ws,
408 const struct pvr_winsys_rt_dataset_create_info *create_info,
409 const struct pvr_device_info *dev_info,
410 struct pvr_winsys_rt_dataset **const rt_dataset_out);
411 void (*render_target_dataset_destroy)(
412 struct pvr_winsys_rt_dataset *rt_dataset);
413
414 VkResult (*render_ctx_create)(
415 struct pvr_winsys *ws,
416 struct pvr_winsys_render_ctx_create_info *create_info,
417 const struct pvr_device_info *dev_info,
418 struct pvr_winsys_render_ctx **const ctx_out);
419 void (*render_ctx_destroy)(struct pvr_winsys_render_ctx *ctx);
420 VkResult (*render_submit)(
421 const struct pvr_winsys_render_ctx *ctx,
422 const struct pvr_winsys_render_submit_info *submit_info,
423 const struct pvr_device_info *dev_info,
424 struct vk_sync *signal_sync_geom,
425 struct vk_sync *signal_sync_frag);
426
427 VkResult (*compute_ctx_create)(
428 struct pvr_winsys *ws,
429 const struct pvr_winsys_compute_ctx_create_info *create_info,
430 const struct pvr_device_info *dev_info,
431 struct pvr_winsys_compute_ctx **const ctx_out);
432 void (*compute_ctx_destroy)(struct pvr_winsys_compute_ctx *ctx);
433 VkResult (*compute_submit)(
434 const struct pvr_winsys_compute_ctx *ctx,
435 const struct pvr_winsys_compute_submit_info *submit_info,
436 const struct pvr_device_info *dev_info,
437 struct vk_sync *signal_sync);
438
439 VkResult (*transfer_ctx_create)(
440 struct pvr_winsys *ws,
441 const struct pvr_winsys_transfer_ctx_create_info *create_info,
442 struct pvr_winsys_transfer_ctx **const ctx_out);
443 void (*transfer_ctx_destroy)(struct pvr_winsys_transfer_ctx *ctx);
444 VkResult (*transfer_submit)(
445 const struct pvr_winsys_transfer_ctx *ctx,
446 const struct pvr_winsys_transfer_submit_info *submit_info,
447 const struct pvr_device_info *dev_info,
448 struct vk_sync *signal_sync);
449
450 VkResult (*null_job_submit)(struct pvr_winsys *ws,
451 struct vk_sync_wait *waits,
452 uint32_t wait_count,
453 struct vk_sync_signal *signal_sync);
454 };
455
456 struct pvr_winsys {
457 uint64_t page_size;
458 uint32_t log2_page_size;
459
460 const struct vk_sync_type *sync_types[3];
461 struct vk_sync_type syncobj_type;
462 struct vk_sync_timeline_type timeline_syncobj_type;
463
464 int render_fd;
465 int display_fd;
466
467 const VkAllocationCallbacks *alloc;
468
469 struct {
470 bool supports_threaded_submit : 1;
471 } features;
472
473 const struct pvr_winsys_ops *ops;
474 };
475
476 void pvr_winsys_destroy(struct pvr_winsys *ws);
477 VkResult pvr_winsys_create(const char *render_path,
478 const char *display_path,
479 bool keep_display_master,
480 const VkAllocationCallbacks *alloc,
481 struct pvr_winsys **ws_out);
482
483 #endif /* PVR_WINSYS_H */