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