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 #ifndef PVR_SRV_H
25 #define PVR_SRV_H
26
27 #include <stdint.h>
28 #include <pthread.h>
29 #include <vulkan/vulkan.h>
30
31 #include "pvr_winsys.h"
32 #include "util/macros.h"
33 #include "util/vma.h"
34
35 /*******************************************
36 Misc defines
37 *******************************************/
38
39 /* 64KB is MAX anticipated OS page size */
40 #define PVR_SRV_RESERVED_SIZE_GRANULARITY 0x10000
41
42 #define PVR_SRV_DEVMEM_HEAPNAME_MAXLENGTH 160
43
44 #define PVR_SRV_GENERAL_HEAP_IDENT "General"
45 #define PVR_SRV_PDSCODEDATA_HEAP_IDENT "PDS Code and Data"
46 #define PVR_SRV_RGNHDR_BRN_63142_HEAP_IDENT "RgnHdr BRN63142"
47 #define PVR_SRV_TRANSFER_3D_HEAP_IDENT "TQ3DParameters"
48 #define PVR_SRV_USCCODE_HEAP_IDENT "USC Code"
49 #define PVR_SRV_VISIBILITY_TEST_HEAP_IDENT "Visibility Test"
50
51 #define FWIF_PDS_HEAP_TOTAL_BYTES 4096
52 #define FWIF_PDS_HEAP_VDM_SYNC_OFFSET_BYTES 0
53 #define FWIF_PDS_HEAP_EOT_OFFSET_BYTES 128
54 #define FWIF_GENERAL_HEAP_TOTAL_BYTES 4096
55 #define FWIF_USC_HEAP_TOTAL_BYTES 4096
56 #define FWIF_USC_HEAP_VDM_SYNC_OFFSET_BYTES 0
57 #define FWIF_GENERAL_HEAP_YUV_CSC_OFFSET_BYTES 128U
58
59 /*******************************************
60 structure definitions
61 *******************************************/
62 struct pvr_srv_winsys_heap {
63 struct pvr_winsys_heap base;
64
65 void *server_heap;
66 };
67
68 struct pvr_srv_winsys {
69 struct pvr_winsys base;
70
71 int master_fd;
72 int render_fd;
73
74 const VkAllocationCallbacks *alloc;
75
76 /* Packed bvnc */
77 uint64_t bvnc;
78
79 void *server_memctx;
80 void *server_memctx_data;
81
82 /* Required heaps */
83 struct pvr_srv_winsys_heap general_heap;
84 struct pvr_srv_winsys_heap pds_heap;
85 struct pvr_srv_winsys_heap transfer_3d_heap;
86 struct pvr_srv_winsys_heap usc_heap;
87 struct pvr_srv_winsys_heap vis_test_heap;
88
89 /* Optional heaps */
90 bool rgn_hdr_heap_present;
91 struct pvr_srv_winsys_heap rgn_hdr_heap;
92
93 /* vma's for reserved memory regions */
94 struct pvr_winsys_vma *pds_vma;
95 struct pvr_winsys_vma *usc_vma;
96 struct pvr_winsys_vma *general_vma;
97
98 /* Sync block used for allocating sync primitives. */
99 void *sync_block_handle;
100 uint32_t sync_block_size;
101 uint32_t sync_block_fw_addr;
102 uint16_t sync_block_offset;
103 };
104
105 struct pvr_srv_sync_prim {
106 struct pvr_srv_winsys *srv_ws;
107 uint32_t offset;
108 uint32_t value;
109 };
110
111 /*******************************************
112 helper macros
113 *******************************************/
114
115 #define to_pvr_srv_winsys(ws) container_of((ws), struct pvr_srv_winsys, base)
116 #define to_pvr_srv_winsys_heap(heap) \
117 container_of((heap), struct pvr_srv_winsys_heap, base)
118
119 /*******************************************
120 functions
121 *******************************************/
122
123 struct pvr_srv_sync_prim *
124 pvr_srv_sync_prim_alloc(struct pvr_srv_winsys *srv_ws);
125 void pvr_srv_sync_prim_free(struct pvr_srv_sync_prim *sync_prim);
126
127 static inline uint32_t
pvr_srv_sync_prim_get_fw_addr(const struct pvr_srv_sync_prim * const sync_prim)128 pvr_srv_sync_prim_get_fw_addr(const struct pvr_srv_sync_prim *const sync_prim)
129 {
130 return sync_prim->srv_ws->sync_block_fw_addr + sync_prim->offset;
131 }
132
133 #endif /* PVR_SRV_H */
134