blob: 1e96bd458cfddbbdd0bad76824f0cecb6aa8fdfb [file] [log] [blame]
Alex Deucherd7ccd8f2010-09-09 11:33:36 -04001/*
2 * Copyright 2010 Advanced Micro Devices, Inc.
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is 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
18 * THE COPYRIGHT HOLDER(S) AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
19 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
20 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
21 * DEALINGS IN THE SOFTWARE.
22 *
23 * Authors:
24 * Alex Deucher <alexander.deucher@amd.com>
25 */
26
27#include "drmP.h"
28#include "drm.h"
29#include "radeon_drm.h"
30#include "radeon.h"
31
32#include "evergreend.h"
33#include "evergreen_blit_shaders.h"
Alex Deuchercb92d452011-05-25 16:39:00 -040034#include "cayman_blit_shaders.h"
Ilija Hadzic86a4d692012-02-01 11:42:38 -050035#include "radeon_blit_common.h"
Alex Deucherd7ccd8f2010-09-09 11:33:36 -040036
37/* emits 17 */
38static void
39set_render_target(struct radeon_device *rdev, int format,
40 int w, int h, u64 gpu_addr)
41{
Christian Könige32eb502011-10-23 12:56:27 +020042 struct radeon_ring *ring = &rdev->ring[RADEON_RING_TYPE_GFX_INDEX];
Alex Deucherd7ccd8f2010-09-09 11:33:36 -040043 u32 cb_color_info;
44 int pitch, slice;
45
46 h = ALIGN(h, 8);
47 if (h < 8)
48 h = 8;
49
Ilija Hadzic6018faf2011-10-12 23:29:36 -040050 cb_color_info = CB_FORMAT(format) |
51 CB_SOURCE_FORMAT(CB_SF_EXPORT_NORM) |
52 CB_ARRAY_MODE(ARRAY_1D_TILED_THIN1);
Alex Deucherd7ccd8f2010-09-09 11:33:36 -040053 pitch = (w / 8) - 1;
54 slice = ((w * h) / 64) - 1;
55
Christian Könige32eb502011-10-23 12:56:27 +020056 radeon_ring_write(ring, PACKET3(PACKET3_SET_CONTEXT_REG, 15));
57 radeon_ring_write(ring, (CB_COLOR0_BASE - PACKET3_SET_CONTEXT_REG_START) >> 2);
58 radeon_ring_write(ring, gpu_addr >> 8);
59 radeon_ring_write(ring, pitch);
60 radeon_ring_write(ring, slice);
61 radeon_ring_write(ring, 0);
62 radeon_ring_write(ring, cb_color_info);
63 radeon_ring_write(ring, 0);
64 radeon_ring_write(ring, (w - 1) | ((h - 1) << 16));
65 radeon_ring_write(ring, 0);
66 radeon_ring_write(ring, 0);
67 radeon_ring_write(ring, 0);
68 radeon_ring_write(ring, 0);
69 radeon_ring_write(ring, 0);
70 radeon_ring_write(ring, 0);
71 radeon_ring_write(ring, 0);
72 radeon_ring_write(ring, 0);
Alex Deucherd7ccd8f2010-09-09 11:33:36 -040073}
74
75/* emits 5dw */
76static void
77cp_set_surface_sync(struct radeon_device *rdev,
78 u32 sync_type, u32 size,
79 u64 mc_addr)
80{
Christian Könige32eb502011-10-23 12:56:27 +020081 struct radeon_ring *ring = &rdev->ring[RADEON_RING_TYPE_GFX_INDEX];
Alex Deucherd7ccd8f2010-09-09 11:33:36 -040082 u32 cp_coher_size;
83
84 if (size == 0xffffffff)
85 cp_coher_size = 0xffffffff;
86 else
87 cp_coher_size = ((size + 255) >> 8);
88
Alex Deucher06c9c232011-10-24 12:57:57 -040089 if (rdev->family >= CHIP_CAYMAN) {
90 /* CP_COHER_CNTL2 has to be set manually when submitting a surface_sync
91 * to the RB directly. For IBs, the CP programs this as part of the
92 * surface_sync packet.
93 */
Christian Könige32eb502011-10-23 12:56:27 +020094 radeon_ring_write(ring, PACKET3(PACKET3_SET_CONFIG_REG, 1));
95 radeon_ring_write(ring, (0x85e8 - PACKET3_SET_CONFIG_REG_START) >> 2);
96 radeon_ring_write(ring, 0); /* CP_COHER_CNTL2 */
Alex Deucher06c9c232011-10-24 12:57:57 -040097 }
Christian Könige32eb502011-10-23 12:56:27 +020098 radeon_ring_write(ring, PACKET3(PACKET3_SURFACE_SYNC, 3));
99 radeon_ring_write(ring, sync_type);
100 radeon_ring_write(ring, cp_coher_size);
101 radeon_ring_write(ring, mc_addr >> 8);
102 radeon_ring_write(ring, 10); /* poll interval */
Alex Deucherd7ccd8f2010-09-09 11:33:36 -0400103}
104
105/* emits 11dw + 1 surface sync = 16dw */
106static void
107set_shaders(struct radeon_device *rdev)
108{
Christian Könige32eb502011-10-23 12:56:27 +0200109 struct radeon_ring *ring = &rdev->ring[RADEON_RING_TYPE_GFX_INDEX];
Alex Deucherd7ccd8f2010-09-09 11:33:36 -0400110 u64 gpu_addr;
111
112 /* VS */
113 gpu_addr = rdev->r600_blit.shader_gpu_addr + rdev->r600_blit.vs_offset;
Christian Könige32eb502011-10-23 12:56:27 +0200114 radeon_ring_write(ring, PACKET3(PACKET3_SET_CONTEXT_REG, 3));
115 radeon_ring_write(ring, (SQ_PGM_START_VS - PACKET3_SET_CONTEXT_REG_START) >> 2);
116 radeon_ring_write(ring, gpu_addr >> 8);
117 radeon_ring_write(ring, 2);
118 radeon_ring_write(ring, 0);
Alex Deucherd7ccd8f2010-09-09 11:33:36 -0400119
120 /* PS */
121 gpu_addr = rdev->r600_blit.shader_gpu_addr + rdev->r600_blit.ps_offset;
Christian Könige32eb502011-10-23 12:56:27 +0200122 radeon_ring_write(ring, PACKET3(PACKET3_SET_CONTEXT_REG, 4));
123 radeon_ring_write(ring, (SQ_PGM_START_PS - PACKET3_SET_CONTEXT_REG_START) >> 2);
124 radeon_ring_write(ring, gpu_addr >> 8);
125 radeon_ring_write(ring, 1);
126 radeon_ring_write(ring, 0);
127 radeon_ring_write(ring, 2);
Alex Deucherd7ccd8f2010-09-09 11:33:36 -0400128
129 gpu_addr = rdev->r600_blit.shader_gpu_addr + rdev->r600_blit.vs_offset;
130 cp_set_surface_sync(rdev, PACKET3_SH_ACTION_ENA, 512, gpu_addr);
131}
132
133/* emits 10 + 1 sync (5) = 15 */
134static void
135set_vtx_resource(struct radeon_device *rdev, u64 gpu_addr)
136{
Christian Könige32eb502011-10-23 12:56:27 +0200137 struct radeon_ring *ring = &rdev->ring[RADEON_RING_TYPE_GFX_INDEX];
Alex Deucherd7ccd8f2010-09-09 11:33:36 -0400138 u32 sq_vtx_constant_word2, sq_vtx_constant_word3;
139
140 /* high addr, stride */
Ilija Hadzic6018faf2011-10-12 23:29:36 -0400141 sq_vtx_constant_word2 = SQ_VTXC_BASE_ADDR_HI(upper_32_bits(gpu_addr) & 0xff) |
142 SQ_VTXC_STRIDE(16);
Alex Deucher0f234f5f2011-02-13 19:06:33 -0500143#ifdef __BIG_ENDIAN
Ilija Hadzic6018faf2011-10-12 23:29:36 -0400144 sq_vtx_constant_word2 |= SQ_VTXC_ENDIAN_SWAP(SQ_ENDIAN_8IN32);
Alex Deucher0f234f5f2011-02-13 19:06:33 -0500145#endif
Alex Deucherd7ccd8f2010-09-09 11:33:36 -0400146 /* xyzw swizzles */
Ilija Hadzic6018faf2011-10-12 23:29:36 -0400147 sq_vtx_constant_word3 = SQ_VTCX_SEL_X(SQ_SEL_X) |
148 SQ_VTCX_SEL_Y(SQ_SEL_Y) |
149 SQ_VTCX_SEL_Z(SQ_SEL_Z) |
150 SQ_VTCX_SEL_W(SQ_SEL_W);
Alex Deucherd7ccd8f2010-09-09 11:33:36 -0400151
Christian Könige32eb502011-10-23 12:56:27 +0200152 radeon_ring_write(ring, PACKET3(PACKET3_SET_RESOURCE, 8));
153 radeon_ring_write(ring, 0x580);
154 radeon_ring_write(ring, gpu_addr & 0xffffffff);
155 radeon_ring_write(ring, 48 - 1); /* size */
156 radeon_ring_write(ring, sq_vtx_constant_word2);
157 radeon_ring_write(ring, sq_vtx_constant_word3);
158 radeon_ring_write(ring, 0);
159 radeon_ring_write(ring, 0);
160 radeon_ring_write(ring, 0);
161 radeon_ring_write(ring, S__SQ_CONSTANT_TYPE(SQ_TEX_VTX_VALID_BUFFER));
Alex Deucherd7ccd8f2010-09-09 11:33:36 -0400162
Alex Deuchere719ebd2010-11-22 17:56:33 -0500163 if ((rdev->family == CHIP_CEDAR) ||
Alex Deucherff5b8562011-01-06 21:19:28 -0500164 (rdev->family == CHIP_PALM) ||
Alex Deucherd5c5a722011-05-31 15:42:48 -0400165 (rdev->family == CHIP_SUMO) ||
166 (rdev->family == CHIP_SUMO2) ||
Alex Deucherff5b8562011-01-06 21:19:28 -0500167 (rdev->family == CHIP_CAICOS))
Alex Deucherd7ccd8f2010-09-09 11:33:36 -0400168 cp_set_surface_sync(rdev,
169 PACKET3_TC_ACTION_ENA, 48, gpu_addr);
170 else
171 cp_set_surface_sync(rdev,
172 PACKET3_VC_ACTION_ENA, 48, gpu_addr);
173
174}
175
176/* emits 10 */
177static void
178set_tex_resource(struct radeon_device *rdev,
179 int format, int w, int h, int pitch,
Alex Deucher9bb77032011-10-22 10:07:09 -0400180 u64 gpu_addr, u32 size)
Alex Deucherd7ccd8f2010-09-09 11:33:36 -0400181{
Christian Könige32eb502011-10-23 12:56:27 +0200182 struct radeon_ring *ring = &rdev->ring[RADEON_RING_TYPE_GFX_INDEX];
Alex Deucherd7ccd8f2010-09-09 11:33:36 -0400183 u32 sq_tex_resource_word0, sq_tex_resource_word1;
184 u32 sq_tex_resource_word4, sq_tex_resource_word7;
185
186 if (h < 1)
187 h = 1;
188
Ilija Hadzic6018faf2011-10-12 23:29:36 -0400189 sq_tex_resource_word0 = TEX_DIM(SQ_TEX_DIM_2D);
Alex Deucherd7ccd8f2010-09-09 11:33:36 -0400190 sq_tex_resource_word0 |= ((((pitch >> 3) - 1) << 6) |
191 ((w - 1) << 18));
Ilija Hadzic6018faf2011-10-12 23:29:36 -0400192 sq_tex_resource_word1 = ((h - 1) << 0) |
193 TEX_ARRAY_MODE(ARRAY_1D_TILED_THIN1);
Alex Deucherd7ccd8f2010-09-09 11:33:36 -0400194 /* xyzw swizzles */
Ilija Hadzic6018faf2011-10-12 23:29:36 -0400195 sq_tex_resource_word4 = TEX_DST_SEL_X(SQ_SEL_X) |
196 TEX_DST_SEL_Y(SQ_SEL_Y) |
197 TEX_DST_SEL_Z(SQ_SEL_Z) |
198 TEX_DST_SEL_W(SQ_SEL_W);
Alex Deucherd7ccd8f2010-09-09 11:33:36 -0400199
Ilija Hadzic6018faf2011-10-12 23:29:36 -0400200 sq_tex_resource_word7 = format |
201 S__SQ_CONSTANT_TYPE(SQ_TEX_VTX_VALID_TEXTURE);
Alex Deucherd7ccd8f2010-09-09 11:33:36 -0400202
Alex Deucher9bb77032011-10-22 10:07:09 -0400203 cp_set_surface_sync(rdev,
204 PACKET3_TC_ACTION_ENA, size, gpu_addr);
205
Christian Könige32eb502011-10-23 12:56:27 +0200206 radeon_ring_write(ring, PACKET3(PACKET3_SET_RESOURCE, 8));
207 radeon_ring_write(ring, 0);
208 radeon_ring_write(ring, sq_tex_resource_word0);
209 radeon_ring_write(ring, sq_tex_resource_word1);
210 radeon_ring_write(ring, gpu_addr >> 8);
211 radeon_ring_write(ring, gpu_addr >> 8);
212 radeon_ring_write(ring, sq_tex_resource_word4);
213 radeon_ring_write(ring, 0);
214 radeon_ring_write(ring, 0);
215 radeon_ring_write(ring, sq_tex_resource_word7);
Alex Deucherd7ccd8f2010-09-09 11:33:36 -0400216}
217
218/* emits 12 */
219static void
220set_scissors(struct radeon_device *rdev, int x1, int y1,
221 int x2, int y2)
222{
Christian Könige32eb502011-10-23 12:56:27 +0200223 struct radeon_ring *ring = &rdev->ring[RADEON_RING_TYPE_GFX_INDEX];
Alex Deucherac10f812011-05-25 01:00:45 -0400224 /* workaround some hw bugs */
225 if (x2 == 0)
226 x1 = 1;
227 if (y2 == 0)
228 y1 = 1;
Alex Deucher7b76e472012-03-20 17:18:36 -0400229 if (rdev->family >= CHIP_CAYMAN) {
Alex Deucherac10f812011-05-25 01:00:45 -0400230 if ((x2 == 1) && (y2 == 1))
231 x2 = 2;
232 }
233
Christian Könige32eb502011-10-23 12:56:27 +0200234 radeon_ring_write(ring, PACKET3(PACKET3_SET_CONTEXT_REG, 2));
235 radeon_ring_write(ring, (PA_SC_SCREEN_SCISSOR_TL - PACKET3_SET_CONTEXT_REG_START) >> 2);
236 radeon_ring_write(ring, (x1 << 0) | (y1 << 16));
237 radeon_ring_write(ring, (x2 << 0) | (y2 << 16));
Alex Deucherd7ccd8f2010-09-09 11:33:36 -0400238
Christian Könige32eb502011-10-23 12:56:27 +0200239 radeon_ring_write(ring, PACKET3(PACKET3_SET_CONTEXT_REG, 2));
240 radeon_ring_write(ring, (PA_SC_GENERIC_SCISSOR_TL - PACKET3_SET_CONTEXT_REG_START) >> 2);
241 radeon_ring_write(ring, (x1 << 0) | (y1 << 16) | (1 << 31));
242 radeon_ring_write(ring, (x2 << 0) | (y2 << 16));
Alex Deucherd7ccd8f2010-09-09 11:33:36 -0400243
Christian Könige32eb502011-10-23 12:56:27 +0200244 radeon_ring_write(ring, PACKET3(PACKET3_SET_CONTEXT_REG, 2));
245 radeon_ring_write(ring, (PA_SC_WINDOW_SCISSOR_TL - PACKET3_SET_CONTEXT_REG_START) >> 2);
246 radeon_ring_write(ring, (x1 << 0) | (y1 << 16) | (1 << 31));
247 radeon_ring_write(ring, (x2 << 0) | (y2 << 16));
Alex Deucherd7ccd8f2010-09-09 11:33:36 -0400248}
249
250/* emits 10 */
251static void
252draw_auto(struct radeon_device *rdev)
253{
Christian Könige32eb502011-10-23 12:56:27 +0200254 struct radeon_ring *ring = &rdev->ring[RADEON_RING_TYPE_GFX_INDEX];
255 radeon_ring_write(ring, PACKET3(PACKET3_SET_CONFIG_REG, 1));
256 radeon_ring_write(ring, (VGT_PRIMITIVE_TYPE - PACKET3_SET_CONFIG_REG_START) >> 2);
257 radeon_ring_write(ring, DI_PT_RECTLIST);
Alex Deucherd7ccd8f2010-09-09 11:33:36 -0400258
Christian Könige32eb502011-10-23 12:56:27 +0200259 radeon_ring_write(ring, PACKET3(PACKET3_INDEX_TYPE, 0));
260 radeon_ring_write(ring,
Alex Deucher0f234f5f2011-02-13 19:06:33 -0500261#ifdef __BIG_ENDIAN
262 (2 << 2) |
263#endif
264 DI_INDEX_SIZE_16_BIT);
Alex Deucherd7ccd8f2010-09-09 11:33:36 -0400265
Christian Könige32eb502011-10-23 12:56:27 +0200266 radeon_ring_write(ring, PACKET3(PACKET3_NUM_INSTANCES, 0));
267 radeon_ring_write(ring, 1);
Alex Deucherd7ccd8f2010-09-09 11:33:36 -0400268
Christian Könige32eb502011-10-23 12:56:27 +0200269 radeon_ring_write(ring, PACKET3(PACKET3_DRAW_INDEX_AUTO, 1));
270 radeon_ring_write(ring, 3);
271 radeon_ring_write(ring, DI_SRC_SEL_AUTO_INDEX);
Alex Deucherd7ccd8f2010-09-09 11:33:36 -0400272
273}
274
Alex Deucherc61d0af2011-07-12 11:53:23 -0400275/* emits 39 */
Alex Deucherd7ccd8f2010-09-09 11:33:36 -0400276static void
277set_default_state(struct radeon_device *rdev)
278{
Christian Könige32eb502011-10-23 12:56:27 +0200279 struct radeon_ring *ring = &rdev->ring[RADEON_RING_TYPE_GFX_INDEX];
Alex Deucherd7ccd8f2010-09-09 11:33:36 -0400280 u32 sq_config, sq_gpr_resource_mgmt_1, sq_gpr_resource_mgmt_2, sq_gpr_resource_mgmt_3;
281 u32 sq_thread_resource_mgmt, sq_thread_resource_mgmt_2;
282 u32 sq_stack_resource_mgmt_1, sq_stack_resource_mgmt_2, sq_stack_resource_mgmt_3;
283 int num_ps_gprs, num_vs_gprs, num_temp_gprs;
284 int num_gs_gprs, num_es_gprs, num_hs_gprs, num_ls_gprs;
285 int num_ps_threads, num_vs_threads, num_gs_threads, num_es_threads;
286 int num_hs_threads, num_ls_threads;
287 int num_ps_stack_entries, num_vs_stack_entries, num_gs_stack_entries, num_es_stack_entries;
288 int num_hs_stack_entries, num_ls_stack_entries;
Alex Deucher1e644d62011-01-27 17:01:52 -0500289 u64 gpu_addr;
290 int dwords;
Alex Deucherd7ccd8f2010-09-09 11:33:36 -0400291
Alex Deucher2281a372010-10-21 13:31:38 -0400292 /* set clear context state */
Christian Könige32eb502011-10-23 12:56:27 +0200293 radeon_ring_write(ring, PACKET3(PACKET3_CLEAR_STATE, 0));
294 radeon_ring_write(ring, 0);
Alex Deucherd7ccd8f2010-09-09 11:33:36 -0400295
Alex Deuchercb92d452011-05-25 16:39:00 -0400296 if (rdev->family < CHIP_CAYMAN) {
297 switch (rdev->family) {
298 case CHIP_CEDAR:
299 default:
300 num_ps_gprs = 93;
301 num_vs_gprs = 46;
302 num_temp_gprs = 4;
303 num_gs_gprs = 31;
304 num_es_gprs = 31;
305 num_hs_gprs = 23;
306 num_ls_gprs = 23;
307 num_ps_threads = 96;
308 num_vs_threads = 16;
309 num_gs_threads = 16;
310 num_es_threads = 16;
311 num_hs_threads = 16;
312 num_ls_threads = 16;
313 num_ps_stack_entries = 42;
314 num_vs_stack_entries = 42;
315 num_gs_stack_entries = 42;
316 num_es_stack_entries = 42;
317 num_hs_stack_entries = 42;
318 num_ls_stack_entries = 42;
319 break;
320 case CHIP_REDWOOD:
321 num_ps_gprs = 93;
322 num_vs_gprs = 46;
323 num_temp_gprs = 4;
324 num_gs_gprs = 31;
325 num_es_gprs = 31;
326 num_hs_gprs = 23;
327 num_ls_gprs = 23;
328 num_ps_threads = 128;
329 num_vs_threads = 20;
330 num_gs_threads = 20;
331 num_es_threads = 20;
332 num_hs_threads = 20;
333 num_ls_threads = 20;
334 num_ps_stack_entries = 42;
335 num_vs_stack_entries = 42;
336 num_gs_stack_entries = 42;
337 num_es_stack_entries = 42;
338 num_hs_stack_entries = 42;
339 num_ls_stack_entries = 42;
340 break;
341 case CHIP_JUNIPER:
342 num_ps_gprs = 93;
343 num_vs_gprs = 46;
344 num_temp_gprs = 4;
345 num_gs_gprs = 31;
346 num_es_gprs = 31;
347 num_hs_gprs = 23;
348 num_ls_gprs = 23;
349 num_ps_threads = 128;
350 num_vs_threads = 20;
351 num_gs_threads = 20;
352 num_es_threads = 20;
353 num_hs_threads = 20;
354 num_ls_threads = 20;
355 num_ps_stack_entries = 85;
356 num_vs_stack_entries = 85;
357 num_gs_stack_entries = 85;
358 num_es_stack_entries = 85;
359 num_hs_stack_entries = 85;
360 num_ls_stack_entries = 85;
361 break;
362 case CHIP_CYPRESS:
363 case CHIP_HEMLOCK:
364 num_ps_gprs = 93;
365 num_vs_gprs = 46;
366 num_temp_gprs = 4;
367 num_gs_gprs = 31;
368 num_es_gprs = 31;
369 num_hs_gprs = 23;
370 num_ls_gprs = 23;
371 num_ps_threads = 128;
372 num_vs_threads = 20;
373 num_gs_threads = 20;
374 num_es_threads = 20;
375 num_hs_threads = 20;
376 num_ls_threads = 20;
377 num_ps_stack_entries = 85;
378 num_vs_stack_entries = 85;
379 num_gs_stack_entries = 85;
380 num_es_stack_entries = 85;
381 num_hs_stack_entries = 85;
382 num_ls_stack_entries = 85;
383 break;
384 case CHIP_PALM:
385 num_ps_gprs = 93;
386 num_vs_gprs = 46;
387 num_temp_gprs = 4;
388 num_gs_gprs = 31;
389 num_es_gprs = 31;
390 num_hs_gprs = 23;
391 num_ls_gprs = 23;
392 num_ps_threads = 96;
393 num_vs_threads = 16;
394 num_gs_threads = 16;
395 num_es_threads = 16;
396 num_hs_threads = 16;
397 num_ls_threads = 16;
398 num_ps_stack_entries = 42;
399 num_vs_stack_entries = 42;
400 num_gs_stack_entries = 42;
401 num_es_stack_entries = 42;
402 num_hs_stack_entries = 42;
403 num_ls_stack_entries = 42;
404 break;
Alex Deucherd5c5a722011-05-31 15:42:48 -0400405 case CHIP_SUMO:
406 num_ps_gprs = 93;
407 num_vs_gprs = 46;
408 num_temp_gprs = 4;
409 num_gs_gprs = 31;
410 num_es_gprs = 31;
411 num_hs_gprs = 23;
412 num_ls_gprs = 23;
413 num_ps_threads = 96;
414 num_vs_threads = 25;
415 num_gs_threads = 25;
416 num_es_threads = 25;
417 num_hs_threads = 25;
418 num_ls_threads = 25;
419 num_ps_stack_entries = 42;
420 num_vs_stack_entries = 42;
421 num_gs_stack_entries = 42;
422 num_es_stack_entries = 42;
423 num_hs_stack_entries = 42;
424 num_ls_stack_entries = 42;
425 break;
426 case CHIP_SUMO2:
427 num_ps_gprs = 93;
428 num_vs_gprs = 46;
429 num_temp_gprs = 4;
430 num_gs_gprs = 31;
431 num_es_gprs = 31;
432 num_hs_gprs = 23;
433 num_ls_gprs = 23;
434 num_ps_threads = 96;
435 num_vs_threads = 25;
436 num_gs_threads = 25;
437 num_es_threads = 25;
438 num_hs_threads = 25;
439 num_ls_threads = 25;
440 num_ps_stack_entries = 85;
441 num_vs_stack_entries = 85;
442 num_gs_stack_entries = 85;
443 num_es_stack_entries = 85;
444 num_hs_stack_entries = 85;
445 num_ls_stack_entries = 85;
446 break;
Alex Deuchercb92d452011-05-25 16:39:00 -0400447 case CHIP_BARTS:
448 num_ps_gprs = 93;
449 num_vs_gprs = 46;
450 num_temp_gprs = 4;
451 num_gs_gprs = 31;
452 num_es_gprs = 31;
453 num_hs_gprs = 23;
454 num_ls_gprs = 23;
455 num_ps_threads = 128;
456 num_vs_threads = 20;
457 num_gs_threads = 20;
458 num_es_threads = 20;
459 num_hs_threads = 20;
460 num_ls_threads = 20;
461 num_ps_stack_entries = 85;
462 num_vs_stack_entries = 85;
463 num_gs_stack_entries = 85;
464 num_es_stack_entries = 85;
465 num_hs_stack_entries = 85;
466 num_ls_stack_entries = 85;
467 break;
468 case CHIP_TURKS:
469 num_ps_gprs = 93;
470 num_vs_gprs = 46;
471 num_temp_gprs = 4;
472 num_gs_gprs = 31;
473 num_es_gprs = 31;
474 num_hs_gprs = 23;
475 num_ls_gprs = 23;
476 num_ps_threads = 128;
477 num_vs_threads = 20;
478 num_gs_threads = 20;
479 num_es_threads = 20;
480 num_hs_threads = 20;
481 num_ls_threads = 20;
482 num_ps_stack_entries = 42;
483 num_vs_stack_entries = 42;
484 num_gs_stack_entries = 42;
485 num_es_stack_entries = 42;
486 num_hs_stack_entries = 42;
487 num_ls_stack_entries = 42;
488 break;
489 case CHIP_CAICOS:
490 num_ps_gprs = 93;
491 num_vs_gprs = 46;
492 num_temp_gprs = 4;
493 num_gs_gprs = 31;
494 num_es_gprs = 31;
495 num_hs_gprs = 23;
496 num_ls_gprs = 23;
497 num_ps_threads = 128;
498 num_vs_threads = 10;
499 num_gs_threads = 10;
500 num_es_threads = 10;
501 num_hs_threads = 10;
502 num_ls_threads = 10;
503 num_ps_stack_entries = 42;
504 num_vs_stack_entries = 42;
505 num_gs_stack_entries = 42;
506 num_es_stack_entries = 42;
507 num_hs_stack_entries = 42;
508 num_ls_stack_entries = 42;
509 break;
510 }
Alex Deucherd7ccd8f2010-09-09 11:33:36 -0400511
Alex Deuchercb92d452011-05-25 16:39:00 -0400512 if ((rdev->family == CHIP_CEDAR) ||
513 (rdev->family == CHIP_PALM) ||
Alex Deucherd5c5a722011-05-31 15:42:48 -0400514 (rdev->family == CHIP_SUMO) ||
515 (rdev->family == CHIP_SUMO2) ||
Alex Deuchercb92d452011-05-25 16:39:00 -0400516 (rdev->family == CHIP_CAICOS))
517 sq_config = 0;
518 else
519 sq_config = VC_ENABLE;
520
521 sq_config |= (EXPORT_SRC_C |
522 CS_PRIO(0) |
523 LS_PRIO(0) |
524 HS_PRIO(0) |
525 PS_PRIO(0) |
526 VS_PRIO(1) |
527 GS_PRIO(2) |
528 ES_PRIO(3));
529
530 sq_gpr_resource_mgmt_1 = (NUM_PS_GPRS(num_ps_gprs) |
531 NUM_VS_GPRS(num_vs_gprs) |
532 NUM_CLAUSE_TEMP_GPRS(num_temp_gprs));
533 sq_gpr_resource_mgmt_2 = (NUM_GS_GPRS(num_gs_gprs) |
534 NUM_ES_GPRS(num_es_gprs));
535 sq_gpr_resource_mgmt_3 = (NUM_HS_GPRS(num_hs_gprs) |
536 NUM_LS_GPRS(num_ls_gprs));
537 sq_thread_resource_mgmt = (NUM_PS_THREADS(num_ps_threads) |
538 NUM_VS_THREADS(num_vs_threads) |
539 NUM_GS_THREADS(num_gs_threads) |
540 NUM_ES_THREADS(num_es_threads));
541 sq_thread_resource_mgmt_2 = (NUM_HS_THREADS(num_hs_threads) |
542 NUM_LS_THREADS(num_ls_threads));
543 sq_stack_resource_mgmt_1 = (NUM_PS_STACK_ENTRIES(num_ps_stack_entries) |
544 NUM_VS_STACK_ENTRIES(num_vs_stack_entries));
545 sq_stack_resource_mgmt_2 = (NUM_GS_STACK_ENTRIES(num_gs_stack_entries) |
546 NUM_ES_STACK_ENTRIES(num_es_stack_entries));
547 sq_stack_resource_mgmt_3 = (NUM_HS_STACK_ENTRIES(num_hs_stack_entries) |
548 NUM_LS_STACK_ENTRIES(num_ls_stack_entries));
549
550 /* disable dyn gprs */
Christian Könige32eb502011-10-23 12:56:27 +0200551 radeon_ring_write(ring, PACKET3(PACKET3_SET_CONFIG_REG, 1));
552 radeon_ring_write(ring, (SQ_DYN_GPR_CNTL_PS_FLUSH_REQ - PACKET3_SET_CONFIG_REG_START) >> 2);
553 radeon_ring_write(ring, 0);
Alex Deuchercb92d452011-05-25 16:39:00 -0400554
Alex Deucherc61d0af2011-07-12 11:53:23 -0400555 /* setup LDS */
Christian Könige32eb502011-10-23 12:56:27 +0200556 radeon_ring_write(ring, PACKET3(PACKET3_SET_CONFIG_REG, 1));
557 radeon_ring_write(ring, (SQ_LDS_RESOURCE_MGMT - PACKET3_SET_CONFIG_REG_START) >> 2);
558 radeon_ring_write(ring, 0x10001000);
Alex Deucherc61d0af2011-07-12 11:53:23 -0400559
Alex Deuchercb92d452011-05-25 16:39:00 -0400560 /* SQ config */
Christian Könige32eb502011-10-23 12:56:27 +0200561 radeon_ring_write(ring, PACKET3(PACKET3_SET_CONFIG_REG, 11));
562 radeon_ring_write(ring, (SQ_CONFIG - PACKET3_SET_CONFIG_REG_START) >> 2);
563 radeon_ring_write(ring, sq_config);
564 radeon_ring_write(ring, sq_gpr_resource_mgmt_1);
565 radeon_ring_write(ring, sq_gpr_resource_mgmt_2);
566 radeon_ring_write(ring, sq_gpr_resource_mgmt_3);
567 radeon_ring_write(ring, 0);
568 radeon_ring_write(ring, 0);
569 radeon_ring_write(ring, sq_thread_resource_mgmt);
570 radeon_ring_write(ring, sq_thread_resource_mgmt_2);
571 radeon_ring_write(ring, sq_stack_resource_mgmt_1);
572 radeon_ring_write(ring, sq_stack_resource_mgmt_2);
573 radeon_ring_write(ring, sq_stack_resource_mgmt_3);
Alex Deuchercb92d452011-05-25 16:39:00 -0400574 }
Alex Deucher2281a372010-10-21 13:31:38 -0400575
576 /* CONTEXT_CONTROL */
Christian Könige32eb502011-10-23 12:56:27 +0200577 radeon_ring_write(ring, 0xc0012800);
578 radeon_ring_write(ring, 0x80000000);
579 radeon_ring_write(ring, 0x80000000);
Alex Deucher2281a372010-10-21 13:31:38 -0400580
581 /* SQ_VTX_BASE_VTX_LOC */
Christian Könige32eb502011-10-23 12:56:27 +0200582 radeon_ring_write(ring, 0xc0026f00);
583 radeon_ring_write(ring, 0x00000000);
584 radeon_ring_write(ring, 0x00000000);
585 radeon_ring_write(ring, 0x00000000);
Alex Deucher2281a372010-10-21 13:31:38 -0400586
587 /* SET_SAMPLER */
Christian Könige32eb502011-10-23 12:56:27 +0200588 radeon_ring_write(ring, 0xc0036e00);
589 radeon_ring_write(ring, 0x00000000);
590 radeon_ring_write(ring, 0x00000012);
591 radeon_ring_write(ring, 0x00000000);
592 radeon_ring_write(ring, 0x00000000);
Alex Deucher2281a372010-10-21 13:31:38 -0400593
Alex Deucher12920592011-02-02 12:37:40 -0500594 /* set to DX10/11 mode */
Christian Könige32eb502011-10-23 12:56:27 +0200595 radeon_ring_write(ring, PACKET3(PACKET3_MODE_CONTROL, 0));
596 radeon_ring_write(ring, 1);
Alex Deucher12920592011-02-02 12:37:40 -0500597
Alex Deucher1e644d62011-01-27 17:01:52 -0500598 /* emit an IB pointing at default state */
599 dwords = ALIGN(rdev->r600_blit.state_len, 0x10);
600 gpu_addr = rdev->r600_blit.shader_gpu_addr + rdev->r600_blit.state_offset;
Christian Könige32eb502011-10-23 12:56:27 +0200601 radeon_ring_write(ring, PACKET3(PACKET3_INDIRECT_BUFFER, 2));
602 radeon_ring_write(ring, gpu_addr & 0xFFFFFFFC);
603 radeon_ring_write(ring, upper_32_bits(gpu_addr) & 0xFF);
604 radeon_ring_write(ring, dwords);
Alex Deucher1e644d62011-01-27 17:01:52 -0500605
Alex Deucherd7ccd8f2010-09-09 11:33:36 -0400606}
607
Alex Deucherd7ccd8f2010-09-09 11:33:36 -0400608int evergreen_blit_init(struct radeon_device *rdev)
609{
610 u32 obj_size;
Alex Deucher0f234f5f2011-02-13 19:06:33 -0500611 int i, r, dwords;
Alex Deucherd7ccd8f2010-09-09 11:33:36 -0400612 void *ptr;
Alex Deucher1e644d62011-01-27 17:01:52 -0500613 u32 packet2s[16];
614 int num_packet2s = 0;
Alex Deucherd7ccd8f2010-09-09 11:33:36 -0400615
Ilija Hadzicfb3d9e92011-10-12 23:29:41 -0400616 rdev->r600_blit.primitives.set_render_target = set_render_target;
617 rdev->r600_blit.primitives.cp_set_surface_sync = cp_set_surface_sync;
618 rdev->r600_blit.primitives.set_shaders = set_shaders;
619 rdev->r600_blit.primitives.set_vtx_resource = set_vtx_resource;
620 rdev->r600_blit.primitives.set_tex_resource = set_tex_resource;
621 rdev->r600_blit.primitives.set_scissors = set_scissors;
622 rdev->r600_blit.primitives.draw_auto = draw_auto;
623 rdev->r600_blit.primitives.set_default_state = set_default_state;
624
625 rdev->r600_blit.ring_size_common = 55; /* shaders + def state */
Jerome Glisse77b1bad2011-10-26 11:41:22 -0400626 rdev->r600_blit.ring_size_common += 16; /* fence emit for VB IB */
Ilija Hadzicfb3d9e92011-10-12 23:29:41 -0400627 rdev->r600_blit.ring_size_common += 5; /* done copy */
Jerome Glisse77b1bad2011-10-26 11:41:22 -0400628 rdev->r600_blit.ring_size_common += 16; /* fence emit for done copy */
Ilija Hadzicfb3d9e92011-10-12 23:29:41 -0400629
630 rdev->r600_blit.ring_size_per_loop = 74;
Alex Deucher06c9c232011-10-24 12:57:57 -0400631 if (rdev->family >= CHIP_CAYMAN)
632 rdev->r600_blit.ring_size_per_loop += 9; /* additional DWs for surface sync */
Ilija Hadzicfb3d9e92011-10-12 23:29:41 -0400633
634 rdev->r600_blit.max_dim = 16384;
635
Alex Deucherd7ccd8f2010-09-09 11:33:36 -0400636 /* pin copy shader into vram if already initialized */
637 if (rdev->r600_blit.shader_obj)
638 goto done;
639
Alex Deucherd7ccd8f2010-09-09 11:33:36 -0400640 rdev->r600_blit.state_offset = 0;
Alex Deucher1e644d62011-01-27 17:01:52 -0500641
Alex Deuchercb92d452011-05-25 16:39:00 -0400642 if (rdev->family < CHIP_CAYMAN)
643 rdev->r600_blit.state_len = evergreen_default_size;
644 else
645 rdev->r600_blit.state_len = cayman_default_size;
Alex Deucher1e644d62011-01-27 17:01:52 -0500646
647 dwords = rdev->r600_blit.state_len;
648 while (dwords & 0xf) {
Alex Deucher0f234f5f2011-02-13 19:06:33 -0500649 packet2s[num_packet2s++] = cpu_to_le32(PACKET2(0));
Alex Deucher1e644d62011-01-27 17:01:52 -0500650 dwords++;
651 }
652
653 obj_size = dwords * 4;
654 obj_size = ALIGN(obj_size, 256);
Alex Deucherd7ccd8f2010-09-09 11:33:36 -0400655
656 rdev->r600_blit.vs_offset = obj_size;
Alex Deuchercb92d452011-05-25 16:39:00 -0400657 if (rdev->family < CHIP_CAYMAN)
658 obj_size += evergreen_vs_size * 4;
659 else
660 obj_size += cayman_vs_size * 4;
Alex Deucherd7ccd8f2010-09-09 11:33:36 -0400661 obj_size = ALIGN(obj_size, 256);
662
663 rdev->r600_blit.ps_offset = obj_size;
Alex Deuchercb92d452011-05-25 16:39:00 -0400664 if (rdev->family < CHIP_CAYMAN)
665 obj_size += evergreen_ps_size * 4;
666 else
667 obj_size += cayman_ps_size * 4;
Alex Deucherd7ccd8f2010-09-09 11:33:36 -0400668 obj_size = ALIGN(obj_size, 256);
669
Daniel Vetter441921d2011-02-18 17:59:16 +0100670 r = radeon_bo_create(rdev, obj_size, PAGE_SIZE, true, RADEON_GEM_DOMAIN_VRAM,
Alex Deucher40f5cf92012-05-10 18:33:13 -0400671 NULL, &rdev->r600_blit.shader_obj);
Alex Deucherd7ccd8f2010-09-09 11:33:36 -0400672 if (r) {
673 DRM_ERROR("evergreen failed to allocate shader\n");
674 return r;
675 }
676
677 DRM_DEBUG("evergreen blit allocated bo %08x vs %08x ps %08x\n",
678 obj_size,
679 rdev->r600_blit.vs_offset, rdev->r600_blit.ps_offset);
680
681 r = radeon_bo_reserve(rdev->r600_blit.shader_obj, false);
682 if (unlikely(r != 0))
683 return r;
684 r = radeon_bo_kmap(rdev->r600_blit.shader_obj, &ptr);
685 if (r) {
686 DRM_ERROR("failed to map blit object %d\n", r);
687 return r;
688 }
689
Alex Deuchercb92d452011-05-25 16:39:00 -0400690 if (rdev->family < CHIP_CAYMAN) {
691 memcpy_toio(ptr + rdev->r600_blit.state_offset,
692 evergreen_default_state, rdev->r600_blit.state_len * 4);
Alex Deucher1e644d62011-01-27 17:01:52 -0500693
Alex Deuchercb92d452011-05-25 16:39:00 -0400694 if (num_packet2s)
695 memcpy_toio(ptr + rdev->r600_blit.state_offset + (rdev->r600_blit.state_len * 4),
696 packet2s, num_packet2s * 4);
697 for (i = 0; i < evergreen_vs_size; i++)
698 *(u32 *)((unsigned long)ptr + rdev->r600_blit.vs_offset + i * 4) = cpu_to_le32(evergreen_vs[i]);
699 for (i = 0; i < evergreen_ps_size; i++)
700 *(u32 *)((unsigned long)ptr + rdev->r600_blit.ps_offset + i * 4) = cpu_to_le32(evergreen_ps[i]);
701 } else {
702 memcpy_toio(ptr + rdev->r600_blit.state_offset,
703 cayman_default_state, rdev->r600_blit.state_len * 4);
704
705 if (num_packet2s)
706 memcpy_toio(ptr + rdev->r600_blit.state_offset + (rdev->r600_blit.state_len * 4),
707 packet2s, num_packet2s * 4);
708 for (i = 0; i < cayman_vs_size; i++)
709 *(u32 *)((unsigned long)ptr + rdev->r600_blit.vs_offset + i * 4) = cpu_to_le32(cayman_vs[i]);
710 for (i = 0; i < cayman_ps_size; i++)
711 *(u32 *)((unsigned long)ptr + rdev->r600_blit.ps_offset + i * 4) = cpu_to_le32(cayman_ps[i]);
712 }
Alex Deucherd7ccd8f2010-09-09 11:33:36 -0400713 radeon_bo_kunmap(rdev->r600_blit.shader_obj);
714 radeon_bo_unreserve(rdev->r600_blit.shader_obj);
715
716done:
717 r = radeon_bo_reserve(rdev->r600_blit.shader_obj, false);
718 if (unlikely(r != 0))
719 return r;
720 r = radeon_bo_pin(rdev->r600_blit.shader_obj, RADEON_GEM_DOMAIN_VRAM,
721 &rdev->r600_blit.shader_gpu_addr);
722 radeon_bo_unreserve(rdev->r600_blit.shader_obj);
723 if (r) {
724 dev_err(rdev->dev, "(%d) pin blit object failed\n", r);
725 return r;
726 }
Dave Airlie53595332011-03-14 09:47:24 +1000727 radeon_ttm_set_active_vram_size(rdev, rdev->mc.real_vram_size);
Alex Deucherd7ccd8f2010-09-09 11:33:36 -0400728 return 0;
729}