1bf215546Sopenharmony_ci/*
2bf215546Sopenharmony_ci * Copyright © 2017 Advanced Micro Devices, Inc.
3bf215546Sopenharmony_ci *
4bf215546Sopenharmony_ci * Permission is hereby granted, free of charge, to any person obtaining
5bf215546Sopenharmony_ci * a copy of this software and associated documentation files (the
6bf215546Sopenharmony_ci * "Software"), to deal in the Software without restriction, including
7bf215546Sopenharmony_ci * without limitation the rights to use, copy, modify, merge, publish,
8bf215546Sopenharmony_ci * distribute, sub license, and/or sell copies of the Software, and to
9bf215546Sopenharmony_ci * permit persons to whom the Software is furnished to do so, subject to
10bf215546Sopenharmony_ci * the following conditions:
11bf215546Sopenharmony_ci *
12bf215546Sopenharmony_ci * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
13bf215546Sopenharmony_ci * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
14bf215546Sopenharmony_ci * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
15bf215546Sopenharmony_ci * NON-INFRINGEMENT. IN NO EVENT SHALL THE COPYRIGHT HOLDERS, AUTHORS
16bf215546Sopenharmony_ci * AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17bf215546Sopenharmony_ci * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
18bf215546Sopenharmony_ci * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
19bf215546Sopenharmony_ci * USE OR OTHER DEALINGS IN THE SOFTWARE.
20bf215546Sopenharmony_ci *
21bf215546Sopenharmony_ci * The above copyright notice and this permission notice (including the
22bf215546Sopenharmony_ci * next paragraph) shall be included in all copies or substantial portions
23bf215546Sopenharmony_ci * of the Software.
24bf215546Sopenharmony_ci */
25bf215546Sopenharmony_ci
26bf215546Sopenharmony_ci#ifndef AC_GPU_INFO_H
27bf215546Sopenharmony_ci#define AC_GPU_INFO_H
28bf215546Sopenharmony_ci
29bf215546Sopenharmony_ci#include "amd_family.h"
30bf215546Sopenharmony_ci
31bf215546Sopenharmony_ci#include <stdbool.h>
32bf215546Sopenharmony_ci#include <stddef.h>
33bf215546Sopenharmony_ci#include <stdint.h>
34bf215546Sopenharmony_ci#include <stdio.h>
35bf215546Sopenharmony_ci
36bf215546Sopenharmony_ci#ifdef __cplusplus
37bf215546Sopenharmony_ciextern "C" {
38bf215546Sopenharmony_ci#endif
39bf215546Sopenharmony_ci
40bf215546Sopenharmony_ci#define AMD_MAX_SE         8
41bf215546Sopenharmony_ci#define AMD_MAX_SA_PER_SE  2
42bf215546Sopenharmony_ci
43bf215546Sopenharmony_cistruct amdgpu_gpu_info;
44bf215546Sopenharmony_ci
45bf215546Sopenharmony_cistruct amd_ip_info {
46bf215546Sopenharmony_ci   uint8_t ver_major;
47bf215546Sopenharmony_ci   uint8_t ver_minor;
48bf215546Sopenharmony_ci   uint8_t num_queues;
49bf215546Sopenharmony_ci};
50bf215546Sopenharmony_ci
51bf215546Sopenharmony_cistruct radeon_info {
52bf215546Sopenharmony_ci   /* Device info. */
53bf215546Sopenharmony_ci   const char *name;
54bf215546Sopenharmony_ci   char lowercase_name[32];
55bf215546Sopenharmony_ci   const char *marketing_name;
56bf215546Sopenharmony_ci   uint32_t num_se;           /* only enabled SEs */
57bf215546Sopenharmony_ci   uint32_t num_rb;           /* only enabled RBs */
58bf215546Sopenharmony_ci   uint32_t num_cu;           /* only enabled CUs */
59bf215546Sopenharmony_ci   uint32_t max_gpu_freq_mhz; /* also known as the shader clock */
60bf215546Sopenharmony_ci   uint32_t max_gflops;
61bf215546Sopenharmony_ci   uint32_t l1_cache_size;
62bf215546Sopenharmony_ci   uint32_t l2_cache_size;
63bf215546Sopenharmony_ci   uint32_t l3_cache_size_mb;
64bf215546Sopenharmony_ci   uint32_t num_tcc_blocks; /* also the number of memory channels */
65bf215546Sopenharmony_ci   uint32_t memory_freq_mhz;
66bf215546Sopenharmony_ci   uint32_t memory_freq_mhz_effective;
67bf215546Sopenharmony_ci   uint32_t memory_bus_width;
68bf215546Sopenharmony_ci   uint32_t memory_bandwidth_gbps;
69bf215546Sopenharmony_ci   uint32_t clock_crystal_freq;
70bf215546Sopenharmony_ci   struct amd_ip_info ip[AMD_NUM_IP_TYPES];
71bf215546Sopenharmony_ci
72bf215546Sopenharmony_ci   /* Identification. */
73bf215546Sopenharmony_ci   /* PCI info: domain:bus:dev:func */
74bf215546Sopenharmony_ci   uint32_t pci_domain;
75bf215546Sopenharmony_ci   uint32_t pci_bus;
76bf215546Sopenharmony_ci   uint32_t pci_dev;
77bf215546Sopenharmony_ci   uint32_t pci_func;
78bf215546Sopenharmony_ci
79bf215546Sopenharmony_ci   uint32_t pci_id;
80bf215546Sopenharmony_ci   uint32_t pci_rev_id;
81bf215546Sopenharmony_ci   enum radeon_family family;
82bf215546Sopenharmony_ci   enum amd_gfx_level gfx_level;
83bf215546Sopenharmony_ci   uint32_t family_id;
84bf215546Sopenharmony_ci   uint32_t chip_external_rev;
85bf215546Sopenharmony_ci   uint32_t chip_rev; /* 0 = A0, 1 = A1, etc. */
86bf215546Sopenharmony_ci
87bf215546Sopenharmony_ci   /* Flags. */
88bf215546Sopenharmony_ci   bool is_pro_graphics;
89bf215546Sopenharmony_ci   bool has_graphics; /* false if the chip is compute-only */
90bf215546Sopenharmony_ci   uint32_t ib_pad_dw_mask[AMD_NUM_IP_TYPES];
91bf215546Sopenharmony_ci   bool has_clear_state;
92bf215546Sopenharmony_ci   bool has_distributed_tess;
93bf215546Sopenharmony_ci   bool has_dcc_constant_encode;
94bf215546Sopenharmony_ci   bool has_rbplus;     /* if RB+ registers exist */
95bf215546Sopenharmony_ci   bool rbplus_allowed; /* if RB+ is allowed */
96bf215546Sopenharmony_ci   bool has_load_ctx_reg_pkt;
97bf215546Sopenharmony_ci   bool has_out_of_order_rast;
98bf215546Sopenharmony_ci   bool has_packed_math_16bit;
99bf215546Sopenharmony_ci   bool has_accelerated_dot_product;
100bf215546Sopenharmony_ci   bool cpdma_prefetch_writes_memory;
101bf215546Sopenharmony_ci   bool has_gfx9_scissor_bug;
102bf215546Sopenharmony_ci   bool has_tc_compat_zrange_bug;
103bf215546Sopenharmony_ci   bool has_msaa_sample_loc_bug;
104bf215546Sopenharmony_ci   bool has_ls_vgpr_init_bug;
105bf215546Sopenharmony_ci   bool has_zero_index_buffer_bug;
106bf215546Sopenharmony_ci   bool has_image_load_dcc_bug;
107bf215546Sopenharmony_ci   bool has_two_planes_iterate256_bug;
108bf215546Sopenharmony_ci   bool has_vgt_flush_ngg_legacy_bug;
109bf215546Sopenharmony_ci   bool has_cs_regalloc_hang_bug;
110bf215546Sopenharmony_ci   bool has_32bit_predication;
111bf215546Sopenharmony_ci   bool has_3d_cube_border_color_mipmap;
112bf215546Sopenharmony_ci   bool never_stop_sq_perf_counters;
113bf215546Sopenharmony_ci   bool has_sqtt_rb_harvest_bug;
114bf215546Sopenharmony_ci   bool has_sqtt_auto_flush_mode_bug;
115bf215546Sopenharmony_ci   bool never_send_perfcounter_stop;
116bf215546Sopenharmony_ci   bool discardable_allows_big_page;
117bf215546Sopenharmony_ci   bool has_export_conflict_bug;
118bf215546Sopenharmony_ci
119bf215546Sopenharmony_ci   /* Display features. */
120bf215546Sopenharmony_ci   /* There are 2 display DCC codepaths, because display expects unaligned DCC. */
121bf215546Sopenharmony_ci   /* Disable RB and pipe alignment to skip the retile blit. (1 RB chips only) */
122bf215546Sopenharmony_ci   bool use_display_dcc_unaligned;
123bf215546Sopenharmony_ci   /* Allocate both aligned and unaligned DCC and use the retile blit. */
124bf215546Sopenharmony_ci   bool use_display_dcc_with_retile_blit;
125bf215546Sopenharmony_ci
126bf215546Sopenharmony_ci   /* Memory info. */
127bf215546Sopenharmony_ci   uint32_t pte_fragment_size;
128bf215546Sopenharmony_ci   uint32_t gart_page_size;
129bf215546Sopenharmony_ci   uint32_t gart_size_kb;
130bf215546Sopenharmony_ci   uint32_t vram_size_kb;
131bf215546Sopenharmony_ci   uint64_t vram_vis_size_kb;
132bf215546Sopenharmony_ci   uint32_t vram_type;
133bf215546Sopenharmony_ci   uint32_t max_heap_size_kb;
134bf215546Sopenharmony_ci   uint32_t min_alloc_size;
135bf215546Sopenharmony_ci   uint32_t address32_hi;
136bf215546Sopenharmony_ci   bool has_dedicated_vram;
137bf215546Sopenharmony_ci   bool all_vram_visible;
138bf215546Sopenharmony_ci   bool smart_access_memory;
139bf215546Sopenharmony_ci   bool has_l2_uncached;
140bf215546Sopenharmony_ci   bool r600_has_virtual_memory;
141bf215546Sopenharmony_ci   uint32_t max_tcc_blocks;
142bf215546Sopenharmony_ci   uint32_t tcc_cache_line_size;
143bf215546Sopenharmony_ci   bool tcc_rb_non_coherent; /* whether L2 inv is needed for render->texture transitions */
144bf215546Sopenharmony_ci   unsigned pc_lines;
145bf215546Sopenharmony_ci   uint32_t lds_size_per_workgroup;
146bf215546Sopenharmony_ci   uint32_t lds_alloc_granularity;
147bf215546Sopenharmony_ci   uint32_t lds_encode_granularity;
148bf215546Sopenharmony_ci
149bf215546Sopenharmony_ci   /* CP info. */
150bf215546Sopenharmony_ci   bool gfx_ib_pad_with_type2;
151bf215546Sopenharmony_ci   unsigned ib_alignment; /* both start and size alignment */
152bf215546Sopenharmony_ci   uint32_t me_fw_version;
153bf215546Sopenharmony_ci   uint32_t me_fw_feature;
154bf215546Sopenharmony_ci   uint32_t mec_fw_version;
155bf215546Sopenharmony_ci   uint32_t mec_fw_feature;
156bf215546Sopenharmony_ci   uint32_t pfp_fw_version;
157bf215546Sopenharmony_ci   uint32_t pfp_fw_feature;
158bf215546Sopenharmony_ci
159bf215546Sopenharmony_ci   /* Multimedia info. */
160bf215546Sopenharmony_ci   struct {
161bf215546Sopenharmony_ci      bool vcn_decode; /* TODO: remove */
162bf215546Sopenharmony_ci   } has_video_hw;
163bf215546Sopenharmony_ci
164bf215546Sopenharmony_ci   uint32_t uvd_fw_version;
165bf215546Sopenharmony_ci   uint32_t vce_fw_version;
166bf215546Sopenharmony_ci   uint32_t vce_harvest_config;
167bf215546Sopenharmony_ci   struct video_caps_info {
168bf215546Sopenharmony_ci      struct {
169bf215546Sopenharmony_ci         uint32_t valid;
170bf215546Sopenharmony_ci         uint32_t max_width;
171bf215546Sopenharmony_ci         uint32_t max_height;
172bf215546Sopenharmony_ci         uint32_t max_pixels_per_frame;
173bf215546Sopenharmony_ci         uint32_t max_level;
174bf215546Sopenharmony_ci         uint32_t pad;
175bf215546Sopenharmony_ci      } codec_info[8]; /* the number of available codecs */
176bf215546Sopenharmony_ci   } dec_caps, enc_caps;
177bf215546Sopenharmony_ci
178bf215546Sopenharmony_ci   /* Kernel & winsys capabilities. */
179bf215546Sopenharmony_ci   uint32_t drm_major; /* version */
180bf215546Sopenharmony_ci   uint32_t drm_minor;
181bf215546Sopenharmony_ci   uint32_t drm_patchlevel;
182bf215546Sopenharmony_ci   bool is_amdgpu;
183bf215546Sopenharmony_ci   bool has_userptr;
184bf215546Sopenharmony_ci   bool has_syncobj;
185bf215546Sopenharmony_ci   bool has_timeline_syncobj;
186bf215546Sopenharmony_ci   bool has_fence_to_handle;
187bf215546Sopenharmony_ci   bool has_local_buffers;
188bf215546Sopenharmony_ci   bool has_bo_metadata;
189bf215546Sopenharmony_ci   bool has_eqaa_surface_allocator;
190bf215546Sopenharmony_ci   bool has_sparse_vm_mappings;
191bf215546Sopenharmony_ci   bool has_scheduled_fence_dependency;
192bf215546Sopenharmony_ci   bool has_stable_pstate;
193bf215546Sopenharmony_ci   /* Whether SR-IOV is enabled or amdgpu.mcbp=1 was set on the kernel command line. */
194bf215546Sopenharmony_ci   bool mid_command_buffer_preemption_enabled;
195bf215546Sopenharmony_ci   bool has_tmz_support;
196bf215546Sopenharmony_ci   bool kernel_has_modifiers;
197bf215546Sopenharmony_ci
198bf215546Sopenharmony_ci   /* Shader cores. */
199bf215546Sopenharmony_ci   uint32_t cu_mask[AMD_MAX_SE][AMD_MAX_SA_PER_SE];
200bf215546Sopenharmony_ci   uint32_t r600_max_quad_pipes; /* wave size / 16 */
201bf215546Sopenharmony_ci   uint32_t max_good_cu_per_sa;
202bf215546Sopenharmony_ci   uint32_t min_good_cu_per_sa; /* min != max if SAs have different # of CUs */
203bf215546Sopenharmony_ci   uint32_t max_se;             /* number of shader engines incl. disabled ones */
204bf215546Sopenharmony_ci   uint32_t max_sa_per_se;      /* shader arrays per shader engine */
205bf215546Sopenharmony_ci   uint32_t max_wave64_per_simd;
206bf215546Sopenharmony_ci   uint32_t num_physical_sgprs_per_simd;
207bf215546Sopenharmony_ci   uint32_t num_physical_wave64_vgprs_per_simd;
208bf215546Sopenharmony_ci   uint32_t num_simd_per_compute_unit;
209bf215546Sopenharmony_ci   uint32_t min_sgpr_alloc;
210bf215546Sopenharmony_ci   uint32_t max_sgpr_alloc;
211bf215546Sopenharmony_ci   uint32_t sgpr_alloc_granularity;
212bf215546Sopenharmony_ci   uint32_t min_wave64_vgpr_alloc;
213bf215546Sopenharmony_ci   uint32_t max_vgpr_alloc;
214bf215546Sopenharmony_ci   uint32_t wave64_vgpr_alloc_granularity;
215bf215546Sopenharmony_ci   uint32_t max_scratch_waves;
216bf215546Sopenharmony_ci
217bf215546Sopenharmony_ci   /* Render backends (color + depth blocks). */
218bf215546Sopenharmony_ci   uint32_t r300_num_gb_pipes;
219bf215546Sopenharmony_ci   uint32_t r300_num_z_pipes;
220bf215546Sopenharmony_ci   uint32_t r600_gb_backend_map; /* R600 harvest config */
221bf215546Sopenharmony_ci   bool r600_gb_backend_map_valid;
222bf215546Sopenharmony_ci   uint32_t r600_num_banks;
223bf215546Sopenharmony_ci   uint32_t mc_arb_ramcfg;
224bf215546Sopenharmony_ci   uint32_t gb_addr_config;
225bf215546Sopenharmony_ci   uint32_t pa_sc_tile_steering_override; /* CLEAR_STATE also sets this */
226bf215546Sopenharmony_ci   uint32_t max_render_backends;  /* number of render backends incl. disabled ones */
227bf215546Sopenharmony_ci   uint32_t num_tile_pipes; /* pipe count from PIPE_CONFIG */
228bf215546Sopenharmony_ci   uint32_t pipe_interleave_bytes;
229bf215546Sopenharmony_ci   uint32_t enabled_rb_mask; /* GCN harvest config */
230bf215546Sopenharmony_ci   uint64_t max_alignment;   /* from addrlib */
231bf215546Sopenharmony_ci   uint32_t pbb_max_alloc_count;
232bf215546Sopenharmony_ci
233bf215546Sopenharmony_ci   /* Tile modes. */
234bf215546Sopenharmony_ci   uint32_t si_tile_mode_array[32];
235bf215546Sopenharmony_ci   uint32_t cik_macrotile_mode_array[16];
236bf215546Sopenharmony_ci
237bf215546Sopenharmony_ci   /* AMD_CU_MASK environment variable or ~0. */
238bf215546Sopenharmony_ci   bool spi_cu_en_has_effect;
239bf215546Sopenharmony_ci   uint32_t spi_cu_en;
240bf215546Sopenharmony_ci};
241bf215546Sopenharmony_ci
242bf215546Sopenharmony_cibool ac_query_gpu_info(int fd, void *dev_p, struct radeon_info *info);
243bf215546Sopenharmony_ci
244bf215546Sopenharmony_civoid ac_compute_driver_uuid(char *uuid, size_t size);
245bf215546Sopenharmony_ci
246bf215546Sopenharmony_civoid ac_compute_device_uuid(struct radeon_info *info, char *uuid, size_t size);
247bf215546Sopenharmony_civoid ac_print_gpu_info(struct radeon_info *info, FILE *f);
248bf215546Sopenharmony_ciint ac_get_gs_table_depth(enum amd_gfx_level gfx_level, enum radeon_family family);
249bf215546Sopenharmony_civoid ac_get_raster_config(struct radeon_info *info, uint32_t *raster_config_p,
250bf215546Sopenharmony_ci                          uint32_t *raster_config_1_p, uint32_t *se_tile_repeat_p);
251bf215546Sopenharmony_civoid ac_get_harvested_configs(struct radeon_info *info, unsigned raster_config,
252bf215546Sopenharmony_ci                              unsigned *cik_raster_config_1_p, unsigned *raster_config_se);
253bf215546Sopenharmony_ciunsigned ac_get_compute_resource_limits(const struct radeon_info *info,
254bf215546Sopenharmony_ci                                        unsigned waves_per_threadgroup, unsigned max_waves_per_sh,
255bf215546Sopenharmony_ci                                        unsigned threadgroups_per_cu);
256bf215546Sopenharmony_ci
257bf215546Sopenharmony_cistruct ac_hs_info {
258bf215546Sopenharmony_ci   uint32_t tess_offchip_block_dw_size;
259bf215546Sopenharmony_ci   uint32_t max_offchip_buffers;
260bf215546Sopenharmony_ci   uint32_t hs_offchip_param;
261bf215546Sopenharmony_ci   uint32_t tess_factor_ring_size;
262bf215546Sopenharmony_ci   uint32_t tess_offchip_ring_offset;
263bf215546Sopenharmony_ci   uint32_t tess_offchip_ring_size;
264bf215546Sopenharmony_ci};
265bf215546Sopenharmony_ci
266bf215546Sopenharmony_civoid ac_get_hs_info(struct radeon_info *info,
267bf215546Sopenharmony_ci                    struct ac_hs_info *hs);
268bf215546Sopenharmony_ci
269bf215546Sopenharmony_ci/* Task rings BO layout information.
270bf215546Sopenharmony_ci * This BO is shared between GFX and ACE queues so that the ACE and GFX
271bf215546Sopenharmony_ci * firmware can cooperate on task->mesh dispatches and is also used to
272bf215546Sopenharmony_ci * store the task payload which is passed to mesh shaders.
273bf215546Sopenharmony_ci *
274bf215546Sopenharmony_ci * The driver only needs to create this BO once,
275bf215546Sopenharmony_ci * and it will always be able to accomodate the maximum needed
276bf215546Sopenharmony_ci * task payload size.
277bf215546Sopenharmony_ci *
278bf215546Sopenharmony_ci * The following memory layout is used:
279bf215546Sopenharmony_ci * 1. Control buffer: 9 DWORDs, 256 byte aligned
280bf215546Sopenharmony_ci *    Used by the firmware to maintain the current state.
281bf215546Sopenharmony_ci * (padding)
282bf215546Sopenharmony_ci * 2. Draw ring: 4 DWORDs per entry, 256 byte aligned
283bf215546Sopenharmony_ci *    Task shaders store the mesh dispatch size here.
284bf215546Sopenharmony_ci * (padding)
285bf215546Sopenharmony_ci * 3. Payload ring: 16K bytes per entry, 256 byte aligned.
286bf215546Sopenharmony_ci *    This is where task payload is stored by task shaders and
287bf215546Sopenharmony_ci *    read by mesh shaders.
288bf215546Sopenharmony_ci *
289bf215546Sopenharmony_ci */
290bf215546Sopenharmony_cistruct ac_task_info {
291bf215546Sopenharmony_ci   uint32_t draw_ring_offset;
292bf215546Sopenharmony_ci   uint32_t payload_ring_offset;
293bf215546Sopenharmony_ci   uint32_t bo_size_bytes;
294bf215546Sopenharmony_ci   uint16_t num_entries;
295bf215546Sopenharmony_ci};
296bf215546Sopenharmony_ci
297bf215546Sopenharmony_ci/* Size of each payload entry in the task payload ring.
298bf215546Sopenharmony_ci * Spec requires minimum 16K bytes.
299bf215546Sopenharmony_ci */
300bf215546Sopenharmony_ci#define AC_TASK_PAYLOAD_ENTRY_BYTES 16384
301bf215546Sopenharmony_ci
302bf215546Sopenharmony_ci/* Size of each draw entry in the task draw ring.
303bf215546Sopenharmony_ci * 4 DWORDs per entry.
304bf215546Sopenharmony_ci */
305bf215546Sopenharmony_ci#define AC_TASK_DRAW_ENTRY_BYTES 16
306bf215546Sopenharmony_ci
307bf215546Sopenharmony_ci/* Size of the task control buffer. 9 DWORDs. */
308bf215546Sopenharmony_ci#define AC_TASK_CTRLBUF_BYTES 36
309bf215546Sopenharmony_ci
310bf215546Sopenharmony_civoid ac_get_task_info(struct radeon_info *info,
311bf215546Sopenharmony_ci                      struct ac_task_info *task_info);
312bf215546Sopenharmony_ci
313bf215546Sopenharmony_ci#ifdef __cplusplus
314bf215546Sopenharmony_ci}
315bf215546Sopenharmony_ci#endif
316bf215546Sopenharmony_ci
317bf215546Sopenharmony_ci#endif /* AC_GPU_INFO_H */
318