1bf215546Sopenharmony_ci/*
2bf215546Sopenharmony_ci * Copyright © 2020 Valve Corporation
3bf215546Sopenharmony_ci *
4bf215546Sopenharmony_ci * Permission is hereby granted, free of charge, to any person obtaining a
5bf215546Sopenharmony_ci * copy of this software and associated documentation files (the "Software"),
6bf215546Sopenharmony_ci * to deal in the Software without restriction, including without limitation
7bf215546Sopenharmony_ci * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8bf215546Sopenharmony_ci * and/or sell copies of the Software, and to permit persons to whom the
9bf215546Sopenharmony_ci * Software is furnished to do so, subject to the following conditions:
10bf215546Sopenharmony_ci *
11bf215546Sopenharmony_ci * The above copyright notice and this permission notice (including the next
12bf215546Sopenharmony_ci * paragraph) shall be included in all copies or substantial portions of the
13bf215546Sopenharmony_ci * Software.
14bf215546Sopenharmony_ci *
15bf215546Sopenharmony_ci * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16bf215546Sopenharmony_ci * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17bf215546Sopenharmony_ci * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
18bf215546Sopenharmony_ci * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19bf215546Sopenharmony_ci * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20bf215546Sopenharmony_ci * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
21bf215546Sopenharmony_ci * IN THE SOFTWARE.
22bf215546Sopenharmony_ci *
23bf215546Sopenharmony_ci */
24bf215546Sopenharmony_ci
25bf215546Sopenharmony_ci#ifndef FREEDRENO_DEVICE_INFO_H
26bf215546Sopenharmony_ci#define FREEDRENO_DEVICE_INFO_H
27bf215546Sopenharmony_ci
28bf215546Sopenharmony_ci#include <assert.h>
29bf215546Sopenharmony_ci#include <stdbool.h>
30bf215546Sopenharmony_ci#include <stdint.h>
31bf215546Sopenharmony_ci
32bf215546Sopenharmony_ci#ifdef __cplusplus
33bf215546Sopenharmony_ciextern "C" {
34bf215546Sopenharmony_ci#endif
35bf215546Sopenharmony_ci
36bf215546Sopenharmony_ci/**
37bf215546Sopenharmony_ci * Freedreno hardware description and quirks
38bf215546Sopenharmony_ci */
39bf215546Sopenharmony_ci
40bf215546Sopenharmony_cistruct fd_dev_info {
41bf215546Sopenharmony_ci   /* alignment for size of tiles */
42bf215546Sopenharmony_ci   uint32_t tile_align_w, tile_align_h;
43bf215546Sopenharmony_ci   /* gmem load/store granularity */
44bf215546Sopenharmony_ci   uint32_t gmem_align_w, gmem_align_h;
45bf215546Sopenharmony_ci   /* max tile size */
46bf215546Sopenharmony_ci   uint32_t tile_max_w, tile_max_h;
47bf215546Sopenharmony_ci
48bf215546Sopenharmony_ci   uint32_t num_vsc_pipes;
49bf215546Sopenharmony_ci
50bf215546Sopenharmony_ci   /* number of CCU is always equal to the number of SP */
51bf215546Sopenharmony_ci   union {
52bf215546Sopenharmony_ci      uint32_t num_sp_cores;
53bf215546Sopenharmony_ci      uint32_t num_ccu;
54bf215546Sopenharmony_ci   };
55bf215546Sopenharmony_ci
56bf215546Sopenharmony_ci   union {
57bf215546Sopenharmony_ci      struct {
58bf215546Sopenharmony_ci         /* Information for private memory calculations */
59bf215546Sopenharmony_ci         uint32_t fibers_per_sp;
60bf215546Sopenharmony_ci
61bf215546Sopenharmony_ci         uint32_t reg_size_vec4;
62bf215546Sopenharmony_ci
63bf215546Sopenharmony_ci         /* The size (in instrlen units (128 bytes)) of instruction cache where
64bf215546Sopenharmony_ci          * we preload a shader. Loading more than this could trigger a hang
65bf215546Sopenharmony_ci          * on gen3 and later.
66bf215546Sopenharmony_ci          */
67bf215546Sopenharmony_ci         uint32_t instr_cache_size;
68bf215546Sopenharmony_ci
69bf215546Sopenharmony_ci         /* Whether the PC_MULTIVIEW_MASK register exists. */
70bf215546Sopenharmony_ci         bool supports_multiview_mask;
71bf215546Sopenharmony_ci
72bf215546Sopenharmony_ci         /* info for setting RB_CCU_CNTL */
73bf215546Sopenharmony_ci         bool concurrent_resolve;
74bf215546Sopenharmony_ci         bool has_z24uint_s8uint;
75bf215546Sopenharmony_ci
76bf215546Sopenharmony_ci         bool tess_use_shared;
77bf215546Sopenharmony_ci
78bf215546Sopenharmony_ci         /* Does the hw support GL_QCOM_shading_rate? */
79bf215546Sopenharmony_ci         bool has_shading_rate;
80bf215546Sopenharmony_ci
81bf215546Sopenharmony_ci         /* newer a6xx allows using 16-bit descriptor for both 16-bit
82bf215546Sopenharmony_ci          * and 32-bit access
83bf215546Sopenharmony_ci          */
84bf215546Sopenharmony_ci         bool storage_16bit;
85bf215546Sopenharmony_ci
86bf215546Sopenharmony_ci         /* The latest known a630_sqe.fw fails to wait for WFI before
87bf215546Sopenharmony_ci          * reading the indirect buffer when using CP_DRAW_INDIRECT_MULTI,
88bf215546Sopenharmony_ci          * so we have to fall back to CP_WAIT_FOR_ME except for a650
89bf215546Sopenharmony_ci          * which has a fixed firmware.
90bf215546Sopenharmony_ci          *
91bf215546Sopenharmony_ci          * TODO: There may be newer a630_sqe.fw released in the future
92bf215546Sopenharmony_ci          * which fixes this, if so we should detect it and avoid this
93bf215546Sopenharmony_ci          * workaround.  Once we have uapi to query fw version, we can
94bf215546Sopenharmony_ci          * replace this with minimum fw version.
95bf215546Sopenharmony_ci          */
96bf215546Sopenharmony_ci         bool indirect_draw_wfm_quirk;
97bf215546Sopenharmony_ci
98bf215546Sopenharmony_ci         /* On some GPUs, the depth test needs to be enabled when the
99bf215546Sopenharmony_ci          * depth bounds test is enabled and the depth attachment uses UBWC.
100bf215546Sopenharmony_ci          */
101bf215546Sopenharmony_ci         bool depth_bounds_require_depth_test_quirk;
102bf215546Sopenharmony_ci
103bf215546Sopenharmony_ci         bool has_tex_filter_cubic;
104bf215546Sopenharmony_ci
105bf215546Sopenharmony_ci         bool has_sample_locations;
106bf215546Sopenharmony_ci
107bf215546Sopenharmony_ci         /* The firmware on newer a6xx drops CP_REG_WRITE support as we
108bf215546Sopenharmony_ci          * can now use direct register writes for these regs.
109bf215546Sopenharmony_ci          */
110bf215546Sopenharmony_ci         bool has_cp_reg_write;
111bf215546Sopenharmony_ci
112bf215546Sopenharmony_ci         bool has_8bpp_ubwc;
113bf215546Sopenharmony_ci
114bf215546Sopenharmony_ci         /* a650 seems to be affected by a bug where flushing CCU color into
115bf215546Sopenharmony_ci          * depth or vice-versa requires a WFI. In particular, clearing a
116bf215546Sopenharmony_ci          * depth attachment (which writes to it as a color attachment) then
117bf215546Sopenharmony_ci          * using it as a normal depth attachment requires a WFI in addition
118bf215546Sopenharmony_ci          * to the expected CCU_FLUSH_COLOR + CCU_INVALIDATE_DEPTH, even
119bf215546Sopenharmony_ci          * though all those operations happen in the same stage. As this is
120bf215546Sopenharmony_ci          * usually the only scenario where a CCU flush doesn't require a WFI
121bf215546Sopenharmony_ci          * we just insert a WFI after every CCU flush.
122bf215546Sopenharmony_ci          *
123bf215546Sopenharmony_ci          * Tests affected include
124bf215546Sopenharmony_ci          * dEQP-VK.renderpass.suballocation.formats.d16_unorm.* in sysmem
125bf215546Sopenharmony_ci          * mode (a few tests flake when the entire series is run).
126bf215546Sopenharmony_ci          */
127bf215546Sopenharmony_ci         bool has_ccu_flush_bug;
128bf215546Sopenharmony_ci
129bf215546Sopenharmony_ci         bool has_lpac;
130bf215546Sopenharmony_ci
131bf215546Sopenharmony_ci         bool has_getfiberid;
132bf215546Sopenharmony_ci
133bf215546Sopenharmony_ci         bool has_dp2acc;
134bf215546Sopenharmony_ci         bool has_dp4acc;
135bf215546Sopenharmony_ci
136bf215546Sopenharmony_ci         /* LRZ fast-clear works on all gens, however blob disables it on
137bf215546Sopenharmony_ci          * gen1 and gen2. We also elect to disable fast-clear on these gens
138bf215546Sopenharmony_ci          * because for close to none gains it adds complexity and seem to work
139bf215546Sopenharmony_ci          * a bit differently from gen3+. Which creates at least one edge case:
140bf215546Sopenharmony_ci          * if first draw which uses LRZ fast-clear doesn't lock LRZ direction
141bf215546Sopenharmony_ci          * the fast-clear value is undefined. For details see
142bf215546Sopenharmony_ci          * https://gitlab.freedesktop.org/mesa/mesa/-/issues/6829
143bf215546Sopenharmony_ci          */
144bf215546Sopenharmony_ci         bool enable_lrz_fast_clear;
145bf215546Sopenharmony_ci         bool has_lrz_dir_tracking;
146bf215546Sopenharmony_ci         bool lrz_track_quirk;
147bf215546Sopenharmony_ci
148bf215546Sopenharmony_ci         struct {
149bf215546Sopenharmony_ci            uint32_t RB_UNKNOWN_8E04_blit;
150bf215546Sopenharmony_ci            uint32_t PC_POWER_CNTL;
151bf215546Sopenharmony_ci            uint32_t TPL1_DBG_ECO_CNTL;
152bf215546Sopenharmony_ci         } magic;
153bf215546Sopenharmony_ci      } a6xx;
154bf215546Sopenharmony_ci   };
155bf215546Sopenharmony_ci};
156bf215546Sopenharmony_ci
157bf215546Sopenharmony_cistruct fd_dev_id {
158bf215546Sopenharmony_ci   uint32_t gpu_id;
159bf215546Sopenharmony_ci   uint64_t chip_id;
160bf215546Sopenharmony_ci};
161bf215546Sopenharmony_ci
162bf215546Sopenharmony_ci/**
163bf215546Sopenharmony_ci * Note that gpu-id should be considered deprecated.  For newer a6xx, if
164bf215546Sopenharmony_ci * there is no gpu-id, this attempts to generate one from the chip-id.
165bf215546Sopenharmony_ci * But that may not work forever, so avoid depending on this for newer
166bf215546Sopenharmony_ci * gens
167bf215546Sopenharmony_ci */
168bf215546Sopenharmony_cistatic inline uint32_t
169bf215546Sopenharmony_cifd_dev_gpu_id(const struct fd_dev_id *id)
170bf215546Sopenharmony_ci{
171bf215546Sopenharmony_ci   assert(id->gpu_id || id->chip_id);
172bf215546Sopenharmony_ci   if (!id->gpu_id) {
173bf215546Sopenharmony_ci      return ((id->chip_id >> 24) & 0xff) * 100 +
174bf215546Sopenharmony_ci             ((id->chip_id >> 16) & 0xff) * 10 +
175bf215546Sopenharmony_ci             ((id->chip_id >>  8) & 0xff);
176bf215546Sopenharmony_ci
177bf215546Sopenharmony_ci   }
178bf215546Sopenharmony_ci   return id->gpu_id;
179bf215546Sopenharmony_ci}
180bf215546Sopenharmony_ci
181bf215546Sopenharmony_cistatic uint8_t
182bf215546Sopenharmony_cifd_dev_gen(const struct fd_dev_id *id)
183bf215546Sopenharmony_ci{
184bf215546Sopenharmony_ci   return fd_dev_gpu_id(id) / 100;
185bf215546Sopenharmony_ci}
186bf215546Sopenharmony_ci
187bf215546Sopenharmony_cistatic inline bool
188bf215546Sopenharmony_cifd_dev_64b(const struct fd_dev_id *id)
189bf215546Sopenharmony_ci{
190bf215546Sopenharmony_ci   return fd_dev_gen(id) >= 5;
191bf215546Sopenharmony_ci}
192bf215546Sopenharmony_ci
193bf215546Sopenharmony_ci/* per CCU GMEM amount reserved for depth cache for direct rendering */
194bf215546Sopenharmony_ci#define A6XX_CCU_DEPTH_SIZE (64 * 1024)
195bf215546Sopenharmony_ci/* per CCU GMEM amount reserved for color cache used by GMEM resolves
196bf215546Sopenharmony_ci * which require color cache (non-BLIT event case).
197bf215546Sopenharmony_ci * this is smaller than what is normally used by direct rendering
198bf215546Sopenharmony_ci * (RB_CCU_CNTL.GMEM bit enables this smaller size)
199bf215546Sopenharmony_ci * if a GMEM resolve requires color cache, the driver needs to make sure
200bf215546Sopenharmony_ci * it will not overwrite pixel data in GMEM that is still needed
201bf215546Sopenharmony_ci */
202bf215546Sopenharmony_ci#define A6XX_CCU_GMEM_COLOR_SIZE (16 * 1024)
203bf215546Sopenharmony_ci
204bf215546Sopenharmony_ciconst struct fd_dev_info * fd_dev_info(const struct fd_dev_id *id);
205bf215546Sopenharmony_ciconst char * fd_dev_name(const struct fd_dev_id *id);
206bf215546Sopenharmony_ci
207bf215546Sopenharmony_ci#ifdef __cplusplus
208bf215546Sopenharmony_ci} /* end of extern "C" */
209bf215546Sopenharmony_ci#endif
210bf215546Sopenharmony_ci
211bf215546Sopenharmony_ci#endif /* FREEDRENO_DEVICE_INFO_H */
212