2 * Copyright © 2016 Red Hat.
3 * Copyright © 2016 Bas Nieuwenhuizen
5 * Based on radeon_winsys.h which is:
6 * Copyright 2008 Corbin Simpson <MostAwesomeDude@gmail.com>
7 * Copyright 2010 Marek Olšák <maraeo@gmail.com>
9 * Permission is hereby granted, free of charge, to any person obtaining a
10 * copy of this software and associated documentation files (the "Software"),
11 * to deal in the Software without restriction, including without limitation
12 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
13 * and/or sell copies of the Software, and to permit persons to whom the
14 * Software is furnished to do so, subject to the following conditions:
16 * The above copyright notice and this permission notice (including the next
17 * paragraph) shall be included in all copies or substantial portions of the
20 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
21 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
22 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
23 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
24 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
25 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
33 #include "main/macros.h"
34 #include "amd_family.h"
36 #define FREE(x) free(x)
38 enum radeon_bo_domain
{ /* bitfield */
39 RADEON_DOMAIN_GTT
= 2,
40 RADEON_DOMAIN_VRAM
= 4,
41 RADEON_DOMAIN_VRAM_GTT
= RADEON_DOMAIN_VRAM
| RADEON_DOMAIN_GTT
44 enum radeon_bo_flag
{ /* bitfield */
45 RADEON_FLAG_GTT_WC
= (1 << 0),
46 RADEON_FLAG_CPU_ACCESS
= (1 << 1),
47 RADEON_FLAG_NO_CPU_ACCESS
= (1 << 2),
50 enum radeon_bo_usage
{ /* bitfield */
51 RADEON_USAGE_READ
= 2,
52 RADEON_USAGE_WRITE
= 4,
53 RADEON_USAGE_READWRITE
= RADEON_USAGE_READ
| RADEON_USAGE_WRITE
65 struct radeon_winsys_cs
{
66 unsigned cdw
; /* Number of used dwords. */
67 unsigned max_dw
; /* Maximum number of dwords. */
68 uint32_t *buf
; /* The base pointer of the chunk. */
72 /* PCI info: domain:bus:dev:func */
80 enum radeon_family family
;
82 enum chip_class chip_class
;
83 uint32_t gart_page_size
;
86 bool has_dedicated_vram
;
87 bool has_virtual_memory
;
88 bool gfx_ib_pad_with_type2
;
91 uint32_t vce_fw_version
;
92 uint32_t vce_harvest_config
;
93 uint32_t clock_crystal_freq
;
96 uint32_t drm_major
; /* version */
98 uint32_t drm_patchlevel
;
102 uint32_t r600_max_quad_pipes
; /* wave size / 16 */
103 uint32_t max_shader_clock
;
104 uint32_t num_good_compute_units
;
105 uint32_t max_se
; /* shader engines */
106 uint32_t max_sh_per_se
; /* shader arrays per shader engine */
108 /* Render backends (color + depth blocks). */
109 uint32_t r300_num_gb_pipes
;
110 uint32_t r300_num_z_pipes
;
111 uint32_t r600_gb_backend_map
; /* R600 harvest config */
112 bool r600_gb_backend_map_valid
;
113 uint32_t r600_num_banks
;
114 uint32_t num_render_backends
;
115 uint32_t num_tile_pipes
; /* pipe count from PIPE_CONFIG */
116 uint32_t pipe_interleave_bytes
;
117 uint32_t enabled_rb_mask
; /* GCN harvest config */
120 uint32_t si_tile_mode_array
[32];
121 uint32_t cik_macrotile_mode_array
[16];
124 #define RADEON_SURF_MAX_LEVEL 32
126 #define RADEON_SURF_TYPE_MASK 0xFF
127 #define RADEON_SURF_TYPE_SHIFT 0
128 #define RADEON_SURF_TYPE_1D 0
129 #define RADEON_SURF_TYPE_2D 1
130 #define RADEON_SURF_TYPE_3D 2
131 #define RADEON_SURF_TYPE_CUBEMAP 3
132 #define RADEON_SURF_TYPE_1D_ARRAY 4
133 #define RADEON_SURF_TYPE_2D_ARRAY 5
134 #define RADEON_SURF_MODE_MASK 0xFF
135 #define RADEON_SURF_MODE_SHIFT 8
136 #define RADEON_SURF_MODE_LINEAR_ALIGNED 1
137 #define RADEON_SURF_MODE_1D 2
138 #define RADEON_SURF_MODE_2D 3
139 #define RADEON_SURF_SCANOUT (1 << 16)
140 #define RADEON_SURF_ZBUFFER (1 << 17)
141 #define RADEON_SURF_SBUFFER (1 << 18)
142 #define RADEON_SURF_Z_OR_SBUFFER (RADEON_SURF_ZBUFFER | RADEON_SURF_SBUFFER)
143 #define RADEON_SURF_HAS_SBUFFER_MIPTREE (1 << 19)
144 #define RADEON_SURF_HAS_TILE_MODE_INDEX (1 << 20)
145 #define RADEON_SURF_FMASK (1 << 21)
146 #define RADEON_SURF_DISABLE_DCC (1 << 22)
148 #define RADEON_SURF_GET(v, field) (((v) >> RADEON_SURF_ ## field ## _SHIFT) & RADEON_SURF_ ## field ## _MASK)
149 #define RADEON_SURF_SET(v, field) (((v) & RADEON_SURF_ ## field ## _MASK) << RADEON_SURF_ ## field ## _SHIFT)
150 #define RADEON_SURF_CLR(v, field) ((v) & ~(RADEON_SURF_ ## field ## _MASK << RADEON_SURF_ ## field ## _SHIFT))
152 struct radeon_surf_level
{
161 uint32_t pitch_bytes
;
164 uint64_t dcc_fast_clear_size
;
169 /* surface defintions from the winsys */
171 /* These are inputs to the calculator. */
184 /* These are return values. Some of them can be set by the caller, but
185 * they will be treated as hints (e.g. bankw, bankh) and might be
186 * changed by the calculator.
189 uint64_t bo_alignment
;
190 /* This applies to EG and later. */
195 uint32_t stencil_tile_split
;
196 uint64_t stencil_offset
;
197 struct radeon_surf_level level
[RADEON_SURF_MAX_LEVEL
];
198 struct radeon_surf_level stencil_level
[RADEON_SURF_MAX_LEVEL
];
199 uint32_t tiling_index
[RADEON_SURF_MAX_LEVEL
];
200 uint32_t stencil_tiling_index
[RADEON_SURF_MAX_LEVEL
];
201 uint32_t pipe_config
;
203 uint32_t macro_tile_index
;
204 uint32_t micro_tile_mode
; /* displayable, thin, depth, rotated */
206 /* Whether the depth miptree or stencil miptree as used by the DB are
207 * adjusted from their TC compatible form to ensure depth/stencil
208 * compatibility. If either is true, the corresponding plane cannot be
212 bool stencil_adjusted
;
215 uint64_t dcc_alignment
;
218 enum radeon_bo_layout
{
219 RADEON_LAYOUT_LINEAR
= 0,
221 RADEON_LAYOUT_SQUARETILED
,
223 RADEON_LAYOUT_UNKNOWN
226 /* Tiling info for display code, DRI sharing, and other data. */
227 struct radeon_bo_metadata
{
228 /* Tiling flags describing the texture layout for display code
231 enum radeon_bo_layout microtile
;
232 enum radeon_bo_layout macrotile
;
233 unsigned pipe_config
;
242 /* Additional metadata associated with the buffer, in bytes.
243 * The maximum size is 64 * 4. This is opaque for the winsys & kernel.
244 * Supported by amdgpu only.
246 uint32_t size_metadata
;
247 uint32_t metadata
[64];
250 struct radeon_winsys_bo
;
251 struct radeon_winsys_fence
;
253 struct radeon_winsys
{
254 void (*destroy
)(struct radeon_winsys
*ws
);
256 void (*query_info
)(struct radeon_winsys
*ws
,
257 struct radeon_info
*info
);
259 struct radeon_winsys_bo
*(*buffer_create
)(struct radeon_winsys
*ws
,
262 enum radeon_bo_domain domain
,
263 enum radeon_bo_flag flags
);
265 void (*buffer_destroy
)(struct radeon_winsys_bo
*bo
);
266 void *(*buffer_map
)(struct radeon_winsys_bo
*bo
);
268 struct radeon_winsys_bo
*(*buffer_from_fd
)(struct radeon_winsys
*ws
,
270 unsigned *stride
, unsigned *offset
);
272 bool (*buffer_get_fd
)(struct radeon_winsys
*ws
,
273 struct radeon_winsys_bo
*bo
,
276 void (*buffer_unmap
)(struct radeon_winsys_bo
*bo
);
278 uint64_t (*buffer_get_va
)(struct radeon_winsys_bo
*bo
);
280 void (*buffer_set_metadata
)(struct radeon_winsys_bo
*bo
,
281 struct radeon_bo_metadata
*md
);
282 struct radeon_winsys_ctx
*(*ctx_create
)(struct radeon_winsys
*ws
);
283 void (*ctx_destroy
)(struct radeon_winsys_ctx
*ctx
);
285 bool (*ctx_wait_idle
)(struct radeon_winsys_ctx
*ctx
);
287 struct radeon_winsys_cs
*(*cs_create
)(struct radeon_winsys
*ws
,
288 enum ring_type ring_type
);
290 void (*cs_destroy
)(struct radeon_winsys_cs
*cs
);
292 void (*cs_reset
)(struct radeon_winsys_cs
*cs
);
294 bool (*cs_finalize
)(struct radeon_winsys_cs
*cs
);
296 void (*cs_grow
)(struct radeon_winsys_cs
* cs
, size_t min_size
);
298 int (*cs_submit
)(struct radeon_winsys_ctx
*ctx
,
299 struct radeon_winsys_cs
**cs_array
,
302 struct radeon_winsys_fence
*fence
);
304 void (*cs_add_buffer
)(struct radeon_winsys_cs
*cs
,
305 struct radeon_winsys_bo
*bo
,
308 void (*cs_execute_secondary
)(struct radeon_winsys_cs
*parent
,
309 struct radeon_winsys_cs
*child
);
311 int (*surface_init
)(struct radeon_winsys
*ws
,
312 struct radeon_surf
*surf
);
314 int (*surface_best
)(struct radeon_winsys
*ws
,
315 struct radeon_surf
*surf
);
317 struct radeon_winsys_fence
*(*create_fence
)();
318 void (*destroy_fence
)(struct radeon_winsys_fence
*fence
);
319 bool (*fence_wait
)(struct radeon_winsys
*ws
,
320 struct radeon_winsys_fence
*fence
,
325 static inline void radeon_emit(struct radeon_winsys_cs
*cs
, uint32_t value
)
327 cs
->buf
[cs
->cdw
++] = value
;
330 static inline void radeon_emit_array(struct radeon_winsys_cs
*cs
,
331 const uint32_t *values
, unsigned count
)
333 memcpy(cs
->buf
+ cs
->cdw
, values
, count
* 4);