Debian Codegraph @

src/imagination/common/pvr_device_info.h

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 #ifndef PVR_DEVICE_INFO_H
25 #define PVR_DEVICE_INFO_H
26
27 /* TODO: This file is currently hand-maintained. However, the intention is to
28 * auto-generate it in the future based on the hwdefs.
29 */
30
31 #include <assert.h>
32 #include <errno.h>
33 #include <stdbool.h>
34 #include <stdint.h>
35
36 #include "util/log.h"
37 #include "util/macros.h"
38
39 #define PVR_BVNC_PACK_SHIFT_B 48
40 #define PVR_BVNC_PACK_SHIFT_V 32
41 #define PVR_BVNC_PACK_SHIFT_N 16
42 #define PVR_BVNC_PACK_SHIFT_C 0
43
44 #define PVR_BVNC_PACK_MASK_B UINT64_C(0xFFFF000000000000)
45 #define PVR_BVNC_PACK_MASK_V UINT64_C(0x0000FFFF00000000)
46 #define PVR_BVNC_PACK_MASK_N UINT64_C(0x00000000FFFF0000)
47 #define PVR_BVNC_PACK_MASK_C UINT64_C(0x000000000000FFFF)
48
49 enum pvr_device_arch {
50 PVR_DEVICE_ARCH_ROGUE,
51 };
52
53 /**
54 * Packs B, V, N and C values into a 64-bit unsigned integer.
55 *
56 * The packed layout is as follows:
57 *
58 * \verbatim
59 * +--------+--------+--------+-------+
60 * | 63..48 | 47..32 | 31..16 | 15..0 |
61 * +========+========+========+=======+
62 * | B | V | N | C |
63 * +--------+--------+--------+-------+
64 * \endverbatim
65 *
66 * #pvr_get_packed_bvnc() should be used instead of this macro when a
67 * #pvr_device_information is available in order to ensure proper type checking.
68 *
69 * \param b Branch ID.
70 * \param v Version ID.
71 * \param n Number of scalable units.
72 * \param c Config ID.
73 * \return Packed BVNC.
74 *
75 * \sa #pvr_get_packed_bvnc(), #PVR_BVNC_UNPACK_B(), #PVR_BVNC_UNPACK_V(),
76 * #PVR_BVNC_UNPACK_N() and #PVR_BVNC_UNPACK_C()
77 */
78 #define PVR_BVNC_PACK(b, v, n, c) \
79 ((((uint64_t)(b) << PVR_BVNC_PACK_SHIFT_B) & PVR_BVNC_PACK_MASK_B) | \
80 (((uint64_t)(v) << PVR_BVNC_PACK_SHIFT_V) & PVR_BVNC_PACK_MASK_V) | \
81 (((uint64_t)(n) << PVR_BVNC_PACK_SHIFT_N) & PVR_BVNC_PACK_MASK_N) | \
82 (((uint64_t)(c) << PVR_BVNC_PACK_SHIFT_C) & PVR_BVNC_PACK_MASK_C))
83
84 /**
85 * Unpacks B value (branch ID) from packed BVNC.
86 *
87 * \param bvnc Packed BVNC.
88 * \return Branch ID.
89 *
90 * \sa #PVR_BVNC_UNPACK_V(), #PVR_BVNC_UNPACK_N(), #PVR_BVNC_UNPACK_C(),
91 * #pvr_get_packed_bvnc() and #PVR_BVNC_PACK()
92 */
93 #define PVR_BVNC_UNPACK_B(bvnc) \
94 ((uint16_t)(((bvnc) & PVR_BVNC_PACK_MASK_B) >> PVR_BVNC_PACK_SHIFT_B))
95
96 /**
97 * Unpacks V value (version ID) from packed BVNC.
98 *
99 * \param bvnc Packed BVNC.
100 * \return Version ID.
101 *
102 * \sa #PVR_BVNC_UNPACK_B(), #PVR_BVNC_UNPACK_N(), #PVR_BVNC_UNPACK_C(),
103 * #pvr_get_packed_bvnc() and #PVR_BVNC_PACK()
104 */
105 #define PVR_BVNC_UNPACK_V(bvnc) \
106 ((uint16_t)(((bvnc) & PVR_BVNC_PACK_MASK_V) >> PVR_BVNC_PACK_SHIFT_V))
107
108 /**
109 * Unpacks N value (number of scalable units) from packed BVNC.
110 *
111 * \param bvnc Packed BVNC.
112 * \return Number of scalable units.
113 *
114 * \sa #PVR_BVNC_UNPACK_B(), #PVR_BVNC_UNPACK_V(), #PVR_BVNC_UNPACK_C(),
115 * #pvr_get_packed_bvnc() and #PVR_BVNC_PACK()
116 */
117 #define PVR_BVNC_UNPACK_N(bvnc) \
118 ((uint16_t)(((bvnc) & PVR_BVNC_PACK_MASK_N) >> PVR_BVNC_PACK_SHIFT_N))
119
120 /**
121 * Unpacks C value (config ID) from packed BVNC.
122 *
123 * \param bvnc Packed BVNC.
124 * \return Config ID.
125 *
126 * \sa #PVR_BVNC_UNPACK_B(), #PVR_BVNC_UNPACK_V(), #PVR_BVNC_UNPACK_N(),
127 * #pvr_get_packed_bvnc() and #PVR_BVNC_PACK()
128 */
129 #define PVR_BVNC_UNPACK_C(bvnc) \
130 ((uint16_t)(((bvnc) & PVR_BVNC_PACK_MASK_C) >> PVR_BVNC_PACK_SHIFT_C))
131
132 /**
133 * Tests whether a physical device has a given feature.
134 *
135 * Feature names are derived from those found in #pvr_device_features by
136 * dropping the 'has_' prefix, which is applied by this macro.
137 *
138 * \param dev_info #pvr_device_info object associated with the target physical
139 * device.
140 * \param feature Device feature name.
141 *
142 * \return
143 * * true if the named feature is present in the hardware.
144 * * false if the named feature is not present in the hardware.
145 *
146 * \sa #PVR_FEATURE_VALUE() and #PVR_GET_FEATURE_VALUE()
147 */
148 #define PVR_HAS_FEATURE(dev_info, feature) ((dev_info)->features.has_##feature)
149
150 /**
151 * Gets a physical device feature value if feature is supported.
152 *
153 * Feature names are derived from those found in #pvr_device_features by
154 * dropping the 'has_' prefix.
155 *
156 * This macro should be used in preference to #PVR_GET_FEATURE_VALUE() as it has
157 * proper error handling.
158 *
159 * \param dev_info #pvr_device_info object associated with the target physical
160 * device.
161 * \param feature Feature name.
162 * \param value_out Feature value.
163 *
164 * \return
165 * * 0 on success, or
166 * * -%EINVAL if the named feature is not present in the hardware.
167 *
168 * \sa #PVR_HAS_FEATURE() and #PVR_GET_FEATURE_VALUE()
169 */
170 #define PVR_FEATURE_VALUE(dev_info, feature, value_out) \
171 ({ \
172 const struct pvr_device_info *__dev_info = dev_info; \
173 int __ret = -EINVAL; \
174 if (__dev_info->features.has_##feature) { \
175 *(value_out) = __dev_info->features.feature; \
176 __ret = 0; \
177 } \
178 __ret; \
179 })
180
181 /**
182 * Gets a physical device feature value if supported, but otherwise returns a
183 * default value.
184 *
185 * Feature names are derived from those found in #pvr_device_features by
186 * dropping the 'has_' prefix.
187 *
188 * #PVR_FEATURE_VALUE() should be used in preference to this macro when errors
189 * can be returned by the caller. This macro is intended for cases where errors
190 * can't be returned.
191 *
192 * \param dev_info #pvr_device_info object associated with the target
193 * physical device.
194 * \param feature Feature name.
195 * \param default_value Default feature value.
196 *
197 * \return Feature value.
198 *
199 * \sa #PVR_HAS_FEATURE() and #PVR_FEATURE_VALUE()
200 */
201 #define PVR_GET_FEATURE_VALUE(dev_info, feature, default_value) \
202 ({ \
203 const struct pvr_device_info *__dev_info = dev_info; \
204 __typeof__(default_value) __ret = default_value; \
205 if (__dev_info->features.has_##feature) { \
206 __ret = __dev_info->features.feature; \
207 } else { \
208 mesa_logw("Missing " #feature \
209 " feature (defaulting to: " #default_value ")"); \
210 assert(0); \
211 } \
212 __ret; \
213 })
214
215 /**
216 * Tests whether a physical device has a given enhancement.
217 *
218 * Enhancement numbers are derived from those found in #pvr_device_enhancements
219 * by dropping the 'has_ern' prefix, which is applied by this macro.
220 *
221 * \param dev_info #pvr_device_info object associated with the target physical
222 * device.
223 * \param number Enhancement number.
224 *
225 * \return
226 * * true if the enhancement is present in the hardware.
227 * * false if the enhancement is not present in the hardware.
228 */
229 #define PVR_HAS_ENHANCEMENT(dev_info, number) \
230 ((dev_info)->enhancements.has_ern##number)
231
232 /**
233 * Tests whether a physical device has a given quirk.
234 *
235 * Quirk numbers are derived from those found in #pvr_device_quirks by
236 * dropping the 'has_brn' prefix, which is applied by this macro.
237 *
238 * \param dev_info #pvr_device_info object associated with the target physical
239 * device.
240 * \param number Quirk number.
241 *
242 * \return
243 * * true if the quirk is present in the hardware.
244 * * false if the quirk is not present in the hardware.
245 */
246 #define PVR_HAS_QUIRK(dev_info, number) ((dev_info)->quirks.has_brn##number)
247
248 struct pvr_device_ident {
249 enum pvr_device_arch arch;
250 uint16_t b, v, n, c;
251 uint32_t device_id;
252 const char *series_name;
253 const char *public_name;
254 };
255
256 struct pvr_device_features {
257 bool has_astc : 1;
258 bool has_cluster_grouping : 1;
259 bool has_common_store_size_in_dwords : 1;
260 bool has_compute : 1;
261 bool has_compute_morton_capable : 1;
262 bool has_compute_overlap : 1;
263 bool has_eight_output_registers : 1;
264 bool has_fb_cdc_v4 : 1;
265 bool has_fbcdc_algorithm : 1;
266 bool has_gpu_multicore_support : 1;
267 bool has_gs_rta_support : 1;
268 bool has_ipf_creq_pf : 1;
269 bool has_isp_max_tiles_in_flight : 1;
270 bool has_isp_samples_per_pixel : 1;
271 bool has_max_instances_per_pds_task : 1;
272 bool has_max_multisample : 1;
273 bool has_max_partitions : 1;
274 bool has_max_usc_tasks : 1;
275 bool has_num_clusters : 1;
276 bool has_num_raster_pipes : 1;
277 bool has_paired_tiles : 1;
278 bool has_pbe2_in_xe : 1;
279 bool has_pbe_filterable_f16 : 1;
280 bool has_pbe_stride_align_1pixel : 1;
281 bool has_pbe_yuv : 1;
282 bool has_pds_ddmadt : 1;
283 bool has_roguexe : 1;
284 bool has_screen_size8K : 1;
285 bool has_simple_internal_parameter_format : 1;
286 bool has_simple_internal_parameter_format_v1 : 1;
287 bool has_simple_internal_parameter_format_v2 : 1;
288 bool has_simple_parameter_format_version : 1;
289 bool has_slc_cache_line_size_bits : 1;
290 bool has_slc_mcu_cache_controls : 1;
291 bool has_tf_bicubic_filter : 1;
292 bool has_tile_per_usc : 1;
293 bool has_tile_size_16x16 : 1;
294 bool has_tile_size_x : 1;
295 bool has_tile_size_y : 1;
296 bool has_tpu_array_textures : 1;
297 bool has_tpu_border_colour_enhanced : 1;
298 bool has_tpu_dm_global_registers : 1;
299 bool has_tpu_extended_integer_lookup : 1;
300 bool has_tpu_image_state_v2 : 1;
301 bool has_tpu_parallel_instances : 1;
302 bool has_unified_store_depth : 1;
303 bool has_usc_alu_roundingmode_rne : 1;
304 bool has_usc_f16sop_u8 : 1;
305 bool has_usc_itrsmp : 1;
306 bool has_usc_itrsmp_enhanced : 1;
307 bool has_usc_itr_parallel_instances : 1;
308 bool has_usc_min_output_registers_per_pix : 1;
309 bool has_usc_pixel_partition_mask : 1;
310 bool has_usc_slots : 1;
311 bool has_uvs_banks : 1;
312 bool has_uvs_pba_entries : 1;
313 bool has_uvs_vtx_entries : 1;
314 bool has_vdm_cam_size : 1;
315 bool has_vdm_degenerate_culling : 1;
316 bool has_xpu_max_slaves : 1;
317 bool has_xt_top_infrastructure : 1;
318 bool has_zls_subtile : 1;
319
320 uint32_t common_store_size_in_dwords;
321 uint32_t fbcdc_algorithm;
322 uint32_t isp_max_tiles_in_flight;
323 uint32_t isp_samples_per_pixel;
324 uint32_t max_instances_per_pds_task;
325 uint32_t max_multisample;
326 uint32_t max_partitions;
327 uint32_t max_usc_tasks;
328 uint32_t num_clusters;
329 uint32_t num_raster_pipes;
330 uint32_t simple_parameter_format_version;
331 uint32_t slc_cache_line_size_bits;
332 uint32_t tile_size_x;
333 uint32_t tile_size_y;
334 uint32_t tpu_parallel_instances;
335 uint32_t unified_store_depth;
336 uint32_t usc_itr_parallel_instances;
337 uint32_t usc_min_output_registers_per_pix;
338 uint32_t usc_slots;
339 uint32_t uvs_banks;
340 uint32_t uvs_pba_entries;
341 uint32_t uvs_vtx_entries;
342 uint32_t vdm_cam_size;
343 uint32_t xpu_max_slaves;
344
345 /* Derived features. */
346 bool has_requires_fb_cdc_zls_setup : 1;
347 bool has_s8xe : 1;
348 };
349
350 struct pvr_device_enhancements {
351 bool has_ern35421 : 1;
352 bool has_ern38020 : 1;
353 bool has_ern38748 : 1;
354 bool has_ern42064 : 1;
355 bool has_ern42307 : 1;
356 bool has_ern45493 : 1;
357 };
358
359 struct pvr_device_quirks {
360 bool has_brn44079 : 1;
361 bool has_brn47727 : 1;
362 bool has_brn48492 : 1;
363 bool has_brn48545 : 1;
364 bool has_brn49032 : 1;
365 bool has_brn49927 : 1;
366 bool has_brn51025 : 1;
367 bool has_brn51210 : 1;
368 bool has_brn51764 : 1;
369 bool has_brn52354 : 1;
370 bool has_brn52942 : 1;
371 bool has_brn58839 : 1;
372 bool has_brn62269 : 1;
373 bool has_brn66011 : 1;
374 bool has_brn70165 : 1;
375 bool has_brn72168 : 1;
376 bool has_brn72463 : 1;
377 bool has_brn74056 : 1;
378 };
379
380 struct pvr_device_info {
381 struct pvr_device_ident ident;
382 struct pvr_device_features features;
383 struct pvr_device_enhancements enhancements;
384 struct pvr_device_quirks quirks;
385 };
386
387 struct pvr_device_runtime_info {
388 uint64_t min_free_list_size;
389 uint64_t max_free_list_size;
390 uint64_t reserved_shared_size;
391 uint64_t total_reserved_partition_size;
392 uint64_t num_phantoms;
393 uint64_t max_coeffs;
394 uint64_t cdm_max_local_mem_size_regs;
395 uint32_t core_count;
396 };
397
398 /**
399 * Packs B, V, N and C values into a 64-bit unsigned integer.
400 *
401 * The packed layout is as follows:
402 *
403 * \verbatim
404 * +--------+--------+--------+-------+
405 * | 63..48 | 47..32 | 31..16 | 15..0 |
406 * +========+========+========+=======+
407 * | B | V | N | C |
408 * +--------+--------+--------+-------+
409 * \endverbatim
410 *
411 * This should be used in preference to #PVR_BVNC_PACK() when a
412 * #pvr_device_info is available in order to ensure proper type checking.
413 *
414 * \param dev_info Device information.
415 * \return Packed BVNC.
416 */
417 static ALWAYS_INLINE uint64_t
418 pvr_get_packed_bvnc(const struct pvr_device_info *dev_info)
419 {
420 return PVR_BVNC_PACK(dev_info->ident.b,
421 dev_info->ident.v,
422 dev_info->ident.n,
423 dev_info->ident.c);
424 }
425
426 int pvr_device_info_init(struct pvr_device_info *info, uint64_t bvnc);
427
428 bool pvr_device_info_init_public_name(struct pvr_device_info *info,
429 const char *public_name);
430
431 #endif /* PVR_DEVICE_INFO_H */