blob: accc032c103fd3f846f2b57e6da4de8c693c5d1e [file] [log] [blame]
Alex Deucher27849042010-09-09 11:31:13 -04001/*
2 * Copyright 2009 Advanced Micro Devices, Inc.
3 * Copyright 2009 Red Hat Inc.
4 *
5 * Permission is hereby granted, free of charge, to any person obtaining a
6 * copy of this software and associated documentation files (the "Software"),
7 * to deal in the Software without restriction, including without limitation
8 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
9 * and/or sell copies of the Software, and to permit persons to whom the
10 * Software is furnished to do so, subject to the following conditions:
11 *
12 * The above copyright notice and this permission notice (including the next
13 * paragraph) shall be included in all copies or substantial portions of the
14 * Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19 * THE COPYRIGHT HOLDER(S) AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
20 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
21 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
22 * DEALINGS IN THE SOFTWARE.
23 *
24 */
25
Jerome Glisse3ce0a232009-09-08 10:10:24 +100026#include "drmP.h"
27#include "drm.h"
28#include "radeon_drm.h"
29#include "radeon.h"
30
31#include "r600d.h"
32#include "r600_blit_shaders.h"
33
34#define DI_PT_RECTLIST 0x11
35#define DI_INDEX_SIZE_16_BIT 0x0
36#define DI_SRC_SEL_AUTO_INDEX 0x2
37
38#define FMT_8 0x1
39#define FMT_5_6_5 0x8
40#define FMT_8_8_8_8 0x1a
41#define COLOR_8 0x1
42#define COLOR_5_6_5 0x8
43#define COLOR_8_8_8_8 0x1a
44
Alex Deucher7dbf41d2011-05-17 05:09:43 -040045#define RECT_UNIT_H 32
46#define RECT_UNIT_W (RADEON_GPU_PAGE_SIZE / 4 / RECT_UNIT_H)
Alex Deucher7dbf41d2011-05-17 05:09:43 -040047
Jerome Glisse3ce0a232009-09-08 10:10:24 +100048/* emits 21 on rv770+, 23 on r600 */
49static void
50set_render_target(struct radeon_device *rdev, int format,
51 int w, int h, u64 gpu_addr)
52{
Christian Könige32eb502011-10-23 12:56:27 +020053 struct radeon_ring *ring = &rdev->ring[RADEON_RING_TYPE_GFX_INDEX];
Jerome Glisse3ce0a232009-09-08 10:10:24 +100054 u32 cb_color_info;
55 int pitch, slice;
56
Matt Turnerd964fc52010-02-25 04:23:31 +000057 h = ALIGN(h, 8);
Jerome Glisse3ce0a232009-09-08 10:10:24 +100058 if (h < 8)
59 h = 8;
60
Ilija Hadzic3a386122011-10-12 23:29:37 -040061 cb_color_info = CB_FORMAT(format) |
62 CB_SOURCE_FORMAT(CB_SF_EXPORT_NORM) |
63 CB_ARRAY_MODE(ARRAY_1D_TILED_THIN1);
Jerome Glisse3ce0a232009-09-08 10:10:24 +100064 pitch = (w / 8) - 1;
65 slice = ((w * h) / 64) - 1;
66
Christian Könige32eb502011-10-23 12:56:27 +020067 radeon_ring_write(ring, PACKET3(PACKET3_SET_CONTEXT_REG, 1));
68 radeon_ring_write(ring, (CB_COLOR0_BASE - PACKET3_SET_CONTEXT_REG_OFFSET) >> 2);
69 radeon_ring_write(ring, gpu_addr >> 8);
Jerome Glisse3ce0a232009-09-08 10:10:24 +100070
71 if (rdev->family > CHIP_R600 && rdev->family < CHIP_RV770) {
Christian Könige32eb502011-10-23 12:56:27 +020072 radeon_ring_write(ring, PACKET3(PACKET3_SURFACE_BASE_UPDATE, 0));
73 radeon_ring_write(ring, 2 << 0);
Jerome Glisse3ce0a232009-09-08 10:10:24 +100074 }
75
Christian Könige32eb502011-10-23 12:56:27 +020076 radeon_ring_write(ring, PACKET3(PACKET3_SET_CONTEXT_REG, 1));
77 radeon_ring_write(ring, (CB_COLOR0_SIZE - PACKET3_SET_CONTEXT_REG_OFFSET) >> 2);
78 radeon_ring_write(ring, (pitch << 0) | (slice << 10));
Jerome Glisse3ce0a232009-09-08 10:10:24 +100079
Christian Könige32eb502011-10-23 12:56:27 +020080 radeon_ring_write(ring, PACKET3(PACKET3_SET_CONTEXT_REG, 1));
81 radeon_ring_write(ring, (CB_COLOR0_VIEW - PACKET3_SET_CONTEXT_REG_OFFSET) >> 2);
82 radeon_ring_write(ring, 0);
Jerome Glisse3ce0a232009-09-08 10:10:24 +100083
Christian Könige32eb502011-10-23 12:56:27 +020084 radeon_ring_write(ring, PACKET3(PACKET3_SET_CONTEXT_REG, 1));
85 radeon_ring_write(ring, (CB_COLOR0_INFO - PACKET3_SET_CONTEXT_REG_OFFSET) >> 2);
86 radeon_ring_write(ring, cb_color_info);
Jerome Glisse3ce0a232009-09-08 10:10:24 +100087
Christian Könige32eb502011-10-23 12:56:27 +020088 radeon_ring_write(ring, PACKET3(PACKET3_SET_CONTEXT_REG, 1));
89 radeon_ring_write(ring, (CB_COLOR0_TILE - PACKET3_SET_CONTEXT_REG_OFFSET) >> 2);
90 radeon_ring_write(ring, 0);
Jerome Glisse3ce0a232009-09-08 10:10:24 +100091
Christian Könige32eb502011-10-23 12:56:27 +020092 radeon_ring_write(ring, PACKET3(PACKET3_SET_CONTEXT_REG, 1));
93 radeon_ring_write(ring, (CB_COLOR0_FRAG - PACKET3_SET_CONTEXT_REG_OFFSET) >> 2);
94 radeon_ring_write(ring, 0);
Jerome Glisse3ce0a232009-09-08 10:10:24 +100095
Christian Könige32eb502011-10-23 12:56:27 +020096 radeon_ring_write(ring, PACKET3(PACKET3_SET_CONTEXT_REG, 1));
97 radeon_ring_write(ring, (CB_COLOR0_MASK - PACKET3_SET_CONTEXT_REG_OFFSET) >> 2);
98 radeon_ring_write(ring, 0);
Jerome Glisse3ce0a232009-09-08 10:10:24 +100099}
100
101/* emits 5dw */
102static void
103cp_set_surface_sync(struct radeon_device *rdev,
104 u32 sync_type, u32 size,
105 u64 mc_addr)
106{
Christian Könige32eb502011-10-23 12:56:27 +0200107 struct radeon_ring *ring = &rdev->ring[RADEON_RING_TYPE_GFX_INDEX];
Jerome Glisse3ce0a232009-09-08 10:10:24 +1000108 u32 cp_coher_size;
109
110 if (size == 0xffffffff)
111 cp_coher_size = 0xffffffff;
112 else
113 cp_coher_size = ((size + 255) >> 8);
114
Christian Könige32eb502011-10-23 12:56:27 +0200115 radeon_ring_write(ring, PACKET3(PACKET3_SURFACE_SYNC, 3));
116 radeon_ring_write(ring, sync_type);
117 radeon_ring_write(ring, cp_coher_size);
118 radeon_ring_write(ring, mc_addr >> 8);
119 radeon_ring_write(ring, 10); /* poll interval */
Jerome Glisse3ce0a232009-09-08 10:10:24 +1000120}
121
122/* emits 21dw + 1 surface sync = 26dw */
123static void
124set_shaders(struct radeon_device *rdev)
125{
Christian Könige32eb502011-10-23 12:56:27 +0200126 struct radeon_ring *ring = &rdev->ring[RADEON_RING_TYPE_GFX_INDEX];
Jerome Glisse3ce0a232009-09-08 10:10:24 +1000127 u64 gpu_addr;
128 u32 sq_pgm_resources;
129
130 /* setup shader regs */
131 sq_pgm_resources = (1 << 0);
132
133 /* VS */
134 gpu_addr = rdev->r600_blit.shader_gpu_addr + rdev->r600_blit.vs_offset;
Christian Könige32eb502011-10-23 12:56:27 +0200135 radeon_ring_write(ring, PACKET3(PACKET3_SET_CONTEXT_REG, 1));
136 radeon_ring_write(ring, (SQ_PGM_START_VS - PACKET3_SET_CONTEXT_REG_OFFSET) >> 2);
137 radeon_ring_write(ring, gpu_addr >> 8);
Jerome Glisse3ce0a232009-09-08 10:10:24 +1000138
Christian Könige32eb502011-10-23 12:56:27 +0200139 radeon_ring_write(ring, PACKET3(PACKET3_SET_CONTEXT_REG, 1));
140 radeon_ring_write(ring, (SQ_PGM_RESOURCES_VS - PACKET3_SET_CONTEXT_REG_OFFSET) >> 2);
141 radeon_ring_write(ring, sq_pgm_resources);
Jerome Glisse3ce0a232009-09-08 10:10:24 +1000142
Christian Könige32eb502011-10-23 12:56:27 +0200143 radeon_ring_write(ring, PACKET3(PACKET3_SET_CONTEXT_REG, 1));
144 radeon_ring_write(ring, (SQ_PGM_CF_OFFSET_VS - PACKET3_SET_CONTEXT_REG_OFFSET) >> 2);
145 radeon_ring_write(ring, 0);
Jerome Glisse3ce0a232009-09-08 10:10:24 +1000146
147 /* PS */
148 gpu_addr = rdev->r600_blit.shader_gpu_addr + rdev->r600_blit.ps_offset;
Christian Könige32eb502011-10-23 12:56:27 +0200149 radeon_ring_write(ring, PACKET3(PACKET3_SET_CONTEXT_REG, 1));
150 radeon_ring_write(ring, (SQ_PGM_START_PS - PACKET3_SET_CONTEXT_REG_OFFSET) >> 2);
151 radeon_ring_write(ring, gpu_addr >> 8);
Jerome Glisse3ce0a232009-09-08 10:10:24 +1000152
Christian Könige32eb502011-10-23 12:56:27 +0200153 radeon_ring_write(ring, PACKET3(PACKET3_SET_CONTEXT_REG, 1));
154 radeon_ring_write(ring, (SQ_PGM_RESOURCES_PS - PACKET3_SET_CONTEXT_REG_OFFSET) >> 2);
155 radeon_ring_write(ring, sq_pgm_resources | (1 << 28));
Jerome Glisse3ce0a232009-09-08 10:10:24 +1000156
Christian Könige32eb502011-10-23 12:56:27 +0200157 radeon_ring_write(ring, PACKET3(PACKET3_SET_CONTEXT_REG, 1));
158 radeon_ring_write(ring, (SQ_PGM_EXPORTS_PS - PACKET3_SET_CONTEXT_REG_OFFSET) >> 2);
159 radeon_ring_write(ring, 2);
Jerome Glisse3ce0a232009-09-08 10:10:24 +1000160
Christian Könige32eb502011-10-23 12:56:27 +0200161 radeon_ring_write(ring, PACKET3(PACKET3_SET_CONTEXT_REG, 1));
162 radeon_ring_write(ring, (SQ_PGM_CF_OFFSET_PS - PACKET3_SET_CONTEXT_REG_OFFSET) >> 2);
163 radeon_ring_write(ring, 0);
Jerome Glisse3ce0a232009-09-08 10:10:24 +1000164
Alex Deucher119e20d2009-09-10 02:53:50 -0400165 gpu_addr = rdev->r600_blit.shader_gpu_addr + rdev->r600_blit.vs_offset;
Jerome Glisse3ce0a232009-09-08 10:10:24 +1000166 cp_set_surface_sync(rdev, PACKET3_SH_ACTION_ENA, 512, gpu_addr);
167}
168
169/* emits 9 + 1 sync (5) = 14*/
170static void
171set_vtx_resource(struct radeon_device *rdev, u64 gpu_addr)
172{
Christian Könige32eb502011-10-23 12:56:27 +0200173 struct radeon_ring *ring = &rdev->ring[RADEON_RING_TYPE_GFX_INDEX];
Jerome Glisse3ce0a232009-09-08 10:10:24 +1000174 u32 sq_vtx_constant_word2;
175
Ilija Hadzic3a386122011-10-12 23:29:37 -0400176 sq_vtx_constant_word2 = SQ_VTXC_BASE_ADDR_HI(upper_32_bits(gpu_addr) & 0xff) |
177 SQ_VTXC_STRIDE(16);
Cédric Cano4eace7f2011-02-11 19:45:38 -0500178#ifdef __BIG_ENDIAN
Ilija Hadzic3a386122011-10-12 23:29:37 -0400179 sq_vtx_constant_word2 |= SQ_VTXC_ENDIAN_SWAP(SQ_ENDIAN_8IN32);
Cédric Cano4eace7f2011-02-11 19:45:38 -0500180#endif
Jerome Glisse3ce0a232009-09-08 10:10:24 +1000181
Christian Könige32eb502011-10-23 12:56:27 +0200182 radeon_ring_write(ring, PACKET3(PACKET3_SET_RESOURCE, 7));
183 radeon_ring_write(ring, 0x460);
184 radeon_ring_write(ring, gpu_addr & 0xffffffff);
185 radeon_ring_write(ring, 48 - 1);
186 radeon_ring_write(ring, sq_vtx_constant_word2);
187 radeon_ring_write(ring, 1 << 0);
188 radeon_ring_write(ring, 0);
189 radeon_ring_write(ring, 0);
190 radeon_ring_write(ring, SQ_TEX_VTX_VALID_BUFFER << 30);
Jerome Glisse3ce0a232009-09-08 10:10:24 +1000191
192 if ((rdev->family == CHIP_RV610) ||
193 (rdev->family == CHIP_RV620) ||
194 (rdev->family == CHIP_RS780) ||
195 (rdev->family == CHIP_RS880) ||
196 (rdev->family == CHIP_RV710))
197 cp_set_surface_sync(rdev,
198 PACKET3_TC_ACTION_ENA, 48, gpu_addr);
199 else
200 cp_set_surface_sync(rdev,
201 PACKET3_VC_ACTION_ENA, 48, gpu_addr);
202}
203
204/* emits 9 */
205static void
206set_tex_resource(struct radeon_device *rdev,
207 int format, int w, int h, int pitch,
Alex Deucher9bb77032011-10-22 10:07:09 -0400208 u64 gpu_addr, u32 size)
Jerome Glisse3ce0a232009-09-08 10:10:24 +1000209{
Christian Könige32eb502011-10-23 12:56:27 +0200210 struct radeon_ring *ring = &rdev->ring[RADEON_RING_TYPE_GFX_INDEX];
Jerome Glisse3ce0a232009-09-08 10:10:24 +1000211 uint32_t sq_tex_resource_word0, sq_tex_resource_word1, sq_tex_resource_word4;
212
213 if (h < 1)
214 h = 1;
215
Ilija Hadzic3a386122011-10-12 23:29:37 -0400216 sq_tex_resource_word0 = S_038000_DIM(V_038000_SQ_TEX_DIM_2D) |
217 S_038000_TILE_MODE(V_038000_ARRAY_1D_TILED_THIN1);
218 sq_tex_resource_word0 |= S_038000_PITCH((pitch >> 3) - 1) |
219 S_038000_TEX_WIDTH(w - 1);
Jerome Glisse3ce0a232009-09-08 10:10:24 +1000220
Ilija Hadzic3a386122011-10-12 23:29:37 -0400221 sq_tex_resource_word1 = S_038004_DATA_FORMAT(format);
222 sq_tex_resource_word1 |= S_038004_TEX_HEIGHT(h - 1);
Jerome Glisse3ce0a232009-09-08 10:10:24 +1000223
Ilija Hadzic3a386122011-10-12 23:29:37 -0400224 sq_tex_resource_word4 = S_038010_REQUEST_SIZE(1) |
225 S_038010_DST_SEL_X(SQ_SEL_X) |
226 S_038010_DST_SEL_Y(SQ_SEL_Y) |
227 S_038010_DST_SEL_Z(SQ_SEL_Z) |
228 S_038010_DST_SEL_W(SQ_SEL_W);
Jerome Glisse3ce0a232009-09-08 10:10:24 +1000229
Alex Deucher9bb77032011-10-22 10:07:09 -0400230 cp_set_surface_sync(rdev,
231 PACKET3_TC_ACTION_ENA, size, gpu_addr);
232
Christian Könige32eb502011-10-23 12:56:27 +0200233 radeon_ring_write(ring, PACKET3(PACKET3_SET_RESOURCE, 7));
234 radeon_ring_write(ring, 0);
235 radeon_ring_write(ring, sq_tex_resource_word0);
236 radeon_ring_write(ring, sq_tex_resource_word1);
237 radeon_ring_write(ring, gpu_addr >> 8);
238 radeon_ring_write(ring, gpu_addr >> 8);
239 radeon_ring_write(ring, sq_tex_resource_word4);
240 radeon_ring_write(ring, 0);
241 radeon_ring_write(ring, SQ_TEX_VTX_VALID_TEXTURE << 30);
Jerome Glisse3ce0a232009-09-08 10:10:24 +1000242}
243
244/* emits 12 */
245static void
246set_scissors(struct radeon_device *rdev, int x1, int y1,
247 int x2, int y2)
248{
Christian Könige32eb502011-10-23 12:56:27 +0200249 struct radeon_ring *ring = &rdev->ring[RADEON_RING_TYPE_GFX_INDEX];
250 radeon_ring_write(ring, PACKET3(PACKET3_SET_CONTEXT_REG, 2));
251 radeon_ring_write(ring, (PA_SC_SCREEN_SCISSOR_TL - PACKET3_SET_CONTEXT_REG_OFFSET) >> 2);
252 radeon_ring_write(ring, (x1 << 0) | (y1 << 16));
253 radeon_ring_write(ring, (x2 << 0) | (y2 << 16));
Jerome Glisse3ce0a232009-09-08 10:10:24 +1000254
Christian Könige32eb502011-10-23 12:56:27 +0200255 radeon_ring_write(ring, PACKET3(PACKET3_SET_CONTEXT_REG, 2));
256 radeon_ring_write(ring, (PA_SC_GENERIC_SCISSOR_TL - PACKET3_SET_CONTEXT_REG_OFFSET) >> 2);
257 radeon_ring_write(ring, (x1 << 0) | (y1 << 16) | (1 << 31));
258 radeon_ring_write(ring, (x2 << 0) | (y2 << 16));
Jerome Glisse3ce0a232009-09-08 10:10:24 +1000259
Christian Könige32eb502011-10-23 12:56:27 +0200260 radeon_ring_write(ring, PACKET3(PACKET3_SET_CONTEXT_REG, 2));
261 radeon_ring_write(ring, (PA_SC_WINDOW_SCISSOR_TL - PACKET3_SET_CONTEXT_REG_OFFSET) >> 2);
262 radeon_ring_write(ring, (x1 << 0) | (y1 << 16) | (1 << 31));
263 radeon_ring_write(ring, (x2 << 0) | (y2 << 16));
Jerome Glisse3ce0a232009-09-08 10:10:24 +1000264}
265
266/* emits 10 */
267static void
268draw_auto(struct radeon_device *rdev)
269{
Christian Könige32eb502011-10-23 12:56:27 +0200270 struct radeon_ring *ring = &rdev->ring[RADEON_RING_TYPE_GFX_INDEX];
271 radeon_ring_write(ring, PACKET3(PACKET3_SET_CONFIG_REG, 1));
272 radeon_ring_write(ring, (VGT_PRIMITIVE_TYPE - PACKET3_SET_CONFIG_REG_OFFSET) >> 2);
273 radeon_ring_write(ring, DI_PT_RECTLIST);
Jerome Glisse3ce0a232009-09-08 10:10:24 +1000274
Christian Könige32eb502011-10-23 12:56:27 +0200275 radeon_ring_write(ring, PACKET3(PACKET3_INDEX_TYPE, 0));
276 radeon_ring_write(ring,
Cédric Cano4eace7f2011-02-11 19:45:38 -0500277#ifdef __BIG_ENDIAN
278 (2 << 2) |
279#endif
280 DI_INDEX_SIZE_16_BIT);
Jerome Glisse3ce0a232009-09-08 10:10:24 +1000281
Christian Könige32eb502011-10-23 12:56:27 +0200282 radeon_ring_write(ring, PACKET3(PACKET3_NUM_INSTANCES, 0));
283 radeon_ring_write(ring, 1);
Jerome Glisse3ce0a232009-09-08 10:10:24 +1000284
Christian Könige32eb502011-10-23 12:56:27 +0200285 radeon_ring_write(ring, PACKET3(PACKET3_DRAW_INDEX_AUTO, 1));
286 radeon_ring_write(ring, 3);
287 radeon_ring_write(ring, DI_SRC_SEL_AUTO_INDEX);
Jerome Glisse3ce0a232009-09-08 10:10:24 +1000288
289}
290
291/* emits 14 */
292static void
293set_default_state(struct radeon_device *rdev)
294{
Christian Könige32eb502011-10-23 12:56:27 +0200295 struct radeon_ring *ring = &rdev->ring[RADEON_RING_TYPE_GFX_INDEX];
Jerome Glisse3ce0a232009-09-08 10:10:24 +1000296 u32 sq_config, sq_gpr_resource_mgmt_1, sq_gpr_resource_mgmt_2;
297 u32 sq_thread_resource_mgmt, sq_stack_resource_mgmt_1, sq_stack_resource_mgmt_2;
298 int num_ps_gprs, num_vs_gprs, num_temp_gprs, num_gs_gprs, num_es_gprs;
299 int num_ps_threads, num_vs_threads, num_gs_threads, num_es_threads;
300 int num_ps_stack_entries, num_vs_stack_entries, num_gs_stack_entries, num_es_stack_entries;
301 u64 gpu_addr;
Alex Deucher119e20d2009-09-10 02:53:50 -0400302 int dwords;
Jerome Glisse3ce0a232009-09-08 10:10:24 +1000303
304 switch (rdev->family) {
305 case CHIP_R600:
306 num_ps_gprs = 192;
307 num_vs_gprs = 56;
308 num_temp_gprs = 4;
309 num_gs_gprs = 0;
310 num_es_gprs = 0;
311 num_ps_threads = 136;
312 num_vs_threads = 48;
313 num_gs_threads = 4;
314 num_es_threads = 4;
315 num_ps_stack_entries = 128;
316 num_vs_stack_entries = 128;
317 num_gs_stack_entries = 0;
318 num_es_stack_entries = 0;
319 break;
320 case CHIP_RV630:
321 case CHIP_RV635:
322 num_ps_gprs = 84;
323 num_vs_gprs = 36;
324 num_temp_gprs = 4;
325 num_gs_gprs = 0;
326 num_es_gprs = 0;
327 num_ps_threads = 144;
328 num_vs_threads = 40;
329 num_gs_threads = 4;
330 num_es_threads = 4;
331 num_ps_stack_entries = 40;
332 num_vs_stack_entries = 40;
333 num_gs_stack_entries = 32;
334 num_es_stack_entries = 16;
335 break;
336 case CHIP_RV610:
337 case CHIP_RV620:
338 case CHIP_RS780:
339 case CHIP_RS880:
340 default:
341 num_ps_gprs = 84;
342 num_vs_gprs = 36;
343 num_temp_gprs = 4;
344 num_gs_gprs = 0;
345 num_es_gprs = 0;
346 num_ps_threads = 136;
347 num_vs_threads = 48;
348 num_gs_threads = 4;
349 num_es_threads = 4;
350 num_ps_stack_entries = 40;
351 num_vs_stack_entries = 40;
352 num_gs_stack_entries = 32;
353 num_es_stack_entries = 16;
354 break;
355 case CHIP_RV670:
356 num_ps_gprs = 144;
357 num_vs_gprs = 40;
358 num_temp_gprs = 4;
359 num_gs_gprs = 0;
360 num_es_gprs = 0;
361 num_ps_threads = 136;
362 num_vs_threads = 48;
363 num_gs_threads = 4;
364 num_es_threads = 4;
365 num_ps_stack_entries = 40;
366 num_vs_stack_entries = 40;
367 num_gs_stack_entries = 32;
368 num_es_stack_entries = 16;
369 break;
370 case CHIP_RV770:
371 num_ps_gprs = 192;
372 num_vs_gprs = 56;
373 num_temp_gprs = 4;
374 num_gs_gprs = 0;
375 num_es_gprs = 0;
376 num_ps_threads = 188;
377 num_vs_threads = 60;
378 num_gs_threads = 0;
379 num_es_threads = 0;
380 num_ps_stack_entries = 256;
381 num_vs_stack_entries = 256;
382 num_gs_stack_entries = 0;
383 num_es_stack_entries = 0;
384 break;
385 case CHIP_RV730:
386 case CHIP_RV740:
387 num_ps_gprs = 84;
388 num_vs_gprs = 36;
389 num_temp_gprs = 4;
390 num_gs_gprs = 0;
391 num_es_gprs = 0;
392 num_ps_threads = 188;
393 num_vs_threads = 60;
394 num_gs_threads = 0;
395 num_es_threads = 0;
396 num_ps_stack_entries = 128;
397 num_vs_stack_entries = 128;
398 num_gs_stack_entries = 0;
399 num_es_stack_entries = 0;
400 break;
401 case CHIP_RV710:
402 num_ps_gprs = 192;
403 num_vs_gprs = 56;
404 num_temp_gprs = 4;
405 num_gs_gprs = 0;
406 num_es_gprs = 0;
407 num_ps_threads = 144;
408 num_vs_threads = 48;
409 num_gs_threads = 0;
410 num_es_threads = 0;
411 num_ps_stack_entries = 128;
412 num_vs_stack_entries = 128;
413 num_gs_stack_entries = 0;
414 num_es_stack_entries = 0;
415 break;
416 }
417
418 if ((rdev->family == CHIP_RV610) ||
419 (rdev->family == CHIP_RV620) ||
420 (rdev->family == CHIP_RS780) ||
Alex Deucheree59f2b2009-11-05 13:11:46 -0500421 (rdev->family == CHIP_RS880) ||
Jerome Glisse3ce0a232009-09-08 10:10:24 +1000422 (rdev->family == CHIP_RV710))
423 sq_config = 0;
424 else
425 sq_config = VC_ENABLE;
426
427 sq_config |= (DX9_CONSTS |
428 ALU_INST_PREFER_VECTOR |
429 PS_PRIO(0) |
430 VS_PRIO(1) |
431 GS_PRIO(2) |
432 ES_PRIO(3));
433
434 sq_gpr_resource_mgmt_1 = (NUM_PS_GPRS(num_ps_gprs) |
435 NUM_VS_GPRS(num_vs_gprs) |
436 NUM_CLAUSE_TEMP_GPRS(num_temp_gprs));
437 sq_gpr_resource_mgmt_2 = (NUM_GS_GPRS(num_gs_gprs) |
438 NUM_ES_GPRS(num_es_gprs));
439 sq_thread_resource_mgmt = (NUM_PS_THREADS(num_ps_threads) |
440 NUM_VS_THREADS(num_vs_threads) |
441 NUM_GS_THREADS(num_gs_threads) |
442 NUM_ES_THREADS(num_es_threads));
443 sq_stack_resource_mgmt_1 = (NUM_PS_STACK_ENTRIES(num_ps_stack_entries) |
444 NUM_VS_STACK_ENTRIES(num_vs_stack_entries));
445 sq_stack_resource_mgmt_2 = (NUM_GS_STACK_ENTRIES(num_gs_stack_entries) |
446 NUM_ES_STACK_ENTRIES(num_es_stack_entries));
447
448 /* emit an IB pointing at default state */
Matt Turnerd964fc52010-02-25 04:23:31 +0000449 dwords = ALIGN(rdev->r600_blit.state_len, 0x10);
Jerome Glisse3ce0a232009-09-08 10:10:24 +1000450 gpu_addr = rdev->r600_blit.shader_gpu_addr + rdev->r600_blit.state_offset;
Christian Könige32eb502011-10-23 12:56:27 +0200451 radeon_ring_write(ring, PACKET3(PACKET3_INDIRECT_BUFFER, 2));
452 radeon_ring_write(ring,
Cédric Cano4eace7f2011-02-11 19:45:38 -0500453#ifdef __BIG_ENDIAN
454 (2 << 0) |
455#endif
456 (gpu_addr & 0xFFFFFFFC));
Christian Könige32eb502011-10-23 12:56:27 +0200457 radeon_ring_write(ring, upper_32_bits(gpu_addr) & 0xFF);
458 radeon_ring_write(ring, dwords);
Jerome Glisse3ce0a232009-09-08 10:10:24 +1000459
Jerome Glisse3ce0a232009-09-08 10:10:24 +1000460 /* SQ config */
Christian Könige32eb502011-10-23 12:56:27 +0200461 radeon_ring_write(ring, PACKET3(PACKET3_SET_CONFIG_REG, 6));
462 radeon_ring_write(ring, (SQ_CONFIG - PACKET3_SET_CONFIG_REG_OFFSET) >> 2);
463 radeon_ring_write(ring, sq_config);
464 radeon_ring_write(ring, sq_gpr_resource_mgmt_1);
465 radeon_ring_write(ring, sq_gpr_resource_mgmt_2);
466 radeon_ring_write(ring, sq_thread_resource_mgmt);
467 radeon_ring_write(ring, sq_stack_resource_mgmt_1);
468 radeon_ring_write(ring, sq_stack_resource_mgmt_2);
Jerome Glisse3ce0a232009-09-08 10:10:24 +1000469}
470
Ilija Hadzic52b53a02012-02-02 10:26:24 -0500471#define I2F_MAX_BITS 15
472#define I2F_MAX_INPUT ((1 << I2F_MAX_BITS) - 1)
473#define I2F_SHIFT (24 - I2F_MAX_BITS)
474
475/*
476 * Converts unsigned integer into 32-bit IEEE floating point representation.
477 * Conversion is not universal and only works for the range from 0
478 * to 2^I2F_MAX_BITS-1. Currently we only use it with inputs between
479 * 0 and 16384 (inclusive), so I2F_MAX_BITS=15 is enough. If necessary,
480 * I2F_MAX_BITS can be increased, but that will add to the loop iterations
481 * and slow us down. Conversion is done by shifting the input and counting
482 * down until the first 1 reaches bit position 23. The resulting counter
483 * and the shifted input are, respectively, the exponent and the fraction.
484 * The sign is always zero.
485 */
Andi Kleence580fa2011-10-13 16:08:47 -0700486static uint32_t i2f(uint32_t input)
Jerome Glisse3ce0a232009-09-08 10:10:24 +1000487{
488 u32 result, i, exponent, fraction;
489
Ilija Hadzic52b53a02012-02-02 10:26:24 -0500490 WARN_ON_ONCE(input > I2F_MAX_INPUT);
491
492 if ((input & I2F_MAX_INPUT) == 0)
493 result = 0;
Jerome Glisse3ce0a232009-09-08 10:10:24 +1000494 else {
Ilija Hadzic52b53a02012-02-02 10:26:24 -0500495 exponent = 126 + I2F_MAX_BITS;
496 fraction = (input & I2F_MAX_INPUT) << I2F_SHIFT;
497
498 for (i = 0; i < I2F_MAX_BITS; i++) {
Jerome Glisse3ce0a232009-09-08 10:10:24 +1000499 if (fraction & 0x800000)
500 break;
501 else {
Ilija Hadzic52b53a02012-02-02 10:26:24 -0500502 fraction = fraction << 1;
Jerome Glisse3ce0a232009-09-08 10:10:24 +1000503 exponent = exponent - 1;
504 }
505 }
Ilija Hadzic52b53a02012-02-02 10:26:24 -0500506 result = exponent << 23 | (fraction & 0x7fffff);
Jerome Glisse3ce0a232009-09-08 10:10:24 +1000507 }
508 return result;
509}
510
511int r600_blit_init(struct radeon_device *rdev)
512{
513 u32 obj_size;
Cédric Cano4eace7f2011-02-11 19:45:38 -0500514 int i, r, dwords;
Jerome Glisse3ce0a232009-09-08 10:10:24 +1000515 void *ptr;
Alex Deucher119e20d2009-09-10 02:53:50 -0400516 u32 packet2s[16];
517 int num_packet2s = 0;
Jerome Glisse3ce0a232009-09-08 10:10:24 +1000518
Ilija Hadzic8eec9d62011-10-12 23:29:40 -0400519 rdev->r600_blit.primitives.set_render_target = set_render_target;
520 rdev->r600_blit.primitives.cp_set_surface_sync = cp_set_surface_sync;
521 rdev->r600_blit.primitives.set_shaders = set_shaders;
522 rdev->r600_blit.primitives.set_vtx_resource = set_vtx_resource;
523 rdev->r600_blit.primitives.set_tex_resource = set_tex_resource;
524 rdev->r600_blit.primitives.set_scissors = set_scissors;
525 rdev->r600_blit.primitives.draw_auto = draw_auto;
526 rdev->r600_blit.primitives.set_default_state = set_default_state;
527
528 rdev->r600_blit.ring_size_common = 40; /* shaders + def state */
Jerome Glisse77b1bad2011-10-26 11:41:22 -0400529 rdev->r600_blit.ring_size_common += 16; /* fence emit for VB IB */
Ilija Hadzic8eec9d62011-10-12 23:29:40 -0400530 rdev->r600_blit.ring_size_common += 5; /* done copy */
Jerome Glisse77b1bad2011-10-26 11:41:22 -0400531 rdev->r600_blit.ring_size_common += 16; /* fence emit for done copy */
Ilija Hadzic8eec9d62011-10-12 23:29:40 -0400532
533 rdev->r600_blit.ring_size_per_loop = 76;
534 /* set_render_target emits 2 extra dwords on rv6xx */
535 if (rdev->family > CHIP_R600 && rdev->family < CHIP_RV770)
536 rdev->r600_blit.ring_size_per_loop += 2;
537
538 rdev->r600_blit.max_dim = 8192;
539
Alex Deucherb70d6bb2010-08-06 21:36:58 -0400540 /* pin copy shader into vram if already initialized */
Jerome Glisse90aca4d2010-03-09 14:45:12 +0000541 if (rdev->r600_blit.shader_obj)
Alex Deucherb70d6bb2010-08-06 21:36:58 -0400542 goto done;
543
Jerome Glisseff82f052010-01-22 15:19:00 +0100544 mutex_init(&rdev->r600_blit.mutex);
Jerome Glisse3ce0a232009-09-08 10:10:24 +1000545 rdev->r600_blit.state_offset = 0;
546
547 if (rdev->family >= CHIP_RV770)
Alex Deucher119e20d2009-09-10 02:53:50 -0400548 rdev->r600_blit.state_len = r7xx_default_size;
Jerome Glisse3ce0a232009-09-08 10:10:24 +1000549 else
Alex Deucher119e20d2009-09-10 02:53:50 -0400550 rdev->r600_blit.state_len = r6xx_default_size;
Jerome Glisse3ce0a232009-09-08 10:10:24 +1000551
Alex Deucher119e20d2009-09-10 02:53:50 -0400552 dwords = rdev->r600_blit.state_len;
553 while (dwords & 0xf) {
Cédric Cano4eace7f2011-02-11 19:45:38 -0500554 packet2s[num_packet2s++] = cpu_to_le32(PACKET2(0));
Alex Deucher119e20d2009-09-10 02:53:50 -0400555 dwords++;
556 }
557
558 obj_size = dwords * 4;
Jerome Glisse3ce0a232009-09-08 10:10:24 +1000559 obj_size = ALIGN(obj_size, 256);
560
561 rdev->r600_blit.vs_offset = obj_size;
562 obj_size += r6xx_vs_size * 4;
563 obj_size = ALIGN(obj_size, 256);
564
565 rdev->r600_blit.ps_offset = obj_size;
566 obj_size += r6xx_ps_size * 4;
567 obj_size = ALIGN(obj_size, 256);
568
Daniel Vetter441921d2011-02-18 17:59:16 +0100569 r = radeon_bo_create(rdev, obj_size, PAGE_SIZE, true, RADEON_GEM_DOMAIN_VRAM,
Jerome Glisse4c788672009-11-20 14:29:23 +0100570 &rdev->r600_blit.shader_obj);
Jerome Glisse3ce0a232009-09-08 10:10:24 +1000571 if (r) {
572 DRM_ERROR("r600 failed to allocate shader\n");
573 return r;
574 }
575
Dave Airliebc1a6312009-09-15 11:07:52 +1000576 DRM_DEBUG("r6xx blit allocated bo %08x vs %08x ps %08x\n",
577 obj_size,
Jerome Glisse3ce0a232009-09-08 10:10:24 +1000578 rdev->r600_blit.vs_offset, rdev->r600_blit.ps_offset);
579
Jerome Glisse4c788672009-11-20 14:29:23 +0100580 r = radeon_bo_reserve(rdev->r600_blit.shader_obj, false);
581 if (unlikely(r != 0))
582 return r;
583 r = radeon_bo_kmap(rdev->r600_blit.shader_obj, &ptr);
Jerome Glisse3ce0a232009-09-08 10:10:24 +1000584 if (r) {
585 DRM_ERROR("failed to map blit object %d\n", r);
586 return r;
587 }
Jerome Glisse3ce0a232009-09-08 10:10:24 +1000588 if (rdev->family >= CHIP_RV770)
Alex Deucher119e20d2009-09-10 02:53:50 -0400589 memcpy_toio(ptr + rdev->r600_blit.state_offset,
590 r7xx_default_state, rdev->r600_blit.state_len * 4);
Jerome Glisse3ce0a232009-09-08 10:10:24 +1000591 else
Alex Deucher119e20d2009-09-10 02:53:50 -0400592 memcpy_toio(ptr + rdev->r600_blit.state_offset,
593 r6xx_default_state, rdev->r600_blit.state_len * 4);
594 if (num_packet2s)
595 memcpy_toio(ptr + rdev->r600_blit.state_offset + (rdev->r600_blit.state_len * 4),
596 packet2s, num_packet2s * 4);
Cédric Cano4eace7f2011-02-11 19:45:38 -0500597 for (i = 0; i < r6xx_vs_size; i++)
598 *(u32 *)((unsigned long)ptr + rdev->r600_blit.vs_offset + i * 4) = cpu_to_le32(r6xx_vs[i]);
599 for (i = 0; i < r6xx_ps_size; i++)
600 *(u32 *)((unsigned long)ptr + rdev->r600_blit.ps_offset + i * 4) = cpu_to_le32(r6xx_ps[i]);
Jerome Glisse4c788672009-11-20 14:29:23 +0100601 radeon_bo_kunmap(rdev->r600_blit.shader_obj);
602 radeon_bo_unreserve(rdev->r600_blit.shader_obj);
Alex Deucherb70d6bb2010-08-06 21:36:58 -0400603
604done:
605 r = radeon_bo_reserve(rdev->r600_blit.shader_obj, false);
606 if (unlikely(r != 0))
607 return r;
608 r = radeon_bo_pin(rdev->r600_blit.shader_obj, RADEON_GEM_DOMAIN_VRAM,
609 &rdev->r600_blit.shader_gpu_addr);
610 radeon_bo_unreserve(rdev->r600_blit.shader_obj);
611 if (r) {
612 dev_err(rdev->dev, "(%d) pin blit object failed\n", r);
613 return r;
614 }
Dave Airlie53595332011-03-14 09:47:24 +1000615 radeon_ttm_set_active_vram_size(rdev, rdev->mc.real_vram_size);
Jerome Glisse3ce0a232009-09-08 10:10:24 +1000616 return 0;
617}
618
619void r600_blit_fini(struct radeon_device *rdev)
620{
Jerome Glisse4c788672009-11-20 14:29:23 +0100621 int r;
622
Dave Airlie53595332011-03-14 09:47:24 +1000623 radeon_ttm_set_active_vram_size(rdev, rdev->mc.visible_vram_size);
Jerome Glisse30d2d9a2010-01-13 10:29:27 +0100624 if (rdev->r600_blit.shader_obj == NULL)
625 return;
626 /* If we can't reserve the bo, unref should be enough to destroy
627 * it when it becomes idle.
628 */
Jerome Glisse4c788672009-11-20 14:29:23 +0100629 r = radeon_bo_reserve(rdev->r600_blit.shader_obj, false);
Jerome Glisse30d2d9a2010-01-13 10:29:27 +0100630 if (!r) {
631 radeon_bo_unpin(rdev->r600_blit.shader_obj);
632 radeon_bo_unreserve(rdev->r600_blit.shader_obj);
Jerome Glisse4c788672009-11-20 14:29:23 +0100633 }
Jerome Glisse4c788672009-11-20 14:29:23 +0100634 radeon_bo_unref(&rdev->r600_blit.shader_obj);
Jerome Glisse3ce0a232009-09-08 10:10:24 +1000635}
636
Jerome Glisse69e130a2011-12-21 12:13:46 -0500637static int r600_vb_ib_get(struct radeon_device *rdev, unsigned size)
Jerome Glisse3ce0a232009-09-08 10:10:24 +1000638{
639 int r;
Jerome Glisse69e130a2011-12-21 12:13:46 -0500640 r = radeon_ib_get(rdev, RADEON_RING_TYPE_GFX_INDEX,
641 &rdev->r600_blit.vb_ib, size);
Jerome Glisse3ce0a232009-09-08 10:10:24 +1000642 if (r) {
643 DRM_ERROR("failed to get IB for vertex buffer\n");
644 return r;
645 }
646
Jerome Glisse69e130a2011-12-21 12:13:46 -0500647 rdev->r600_blit.vb_total = size;
Jerome Glisse3ce0a232009-09-08 10:10:24 +1000648 rdev->r600_blit.vb_used = 0;
649 return 0;
650}
651
Alex Deucherd7ccd8f2010-09-09 11:33:36 -0400652static void r600_vb_ib_put(struct radeon_device *rdev)
Jerome Glisse3ce0a232009-09-08 10:10:24 +1000653{
Jerome Glisse3ce0a232009-09-08 10:10:24 +1000654 radeon_fence_emit(rdev, rdev->r600_blit.vb_ib->fence);
Jerome Glisse3ce0a232009-09-08 10:10:24 +1000655 radeon_ib_free(rdev, &rdev->r600_blit.vb_ib);
656}
657
Ilija Hadzicb3530962011-10-12 23:29:42 -0400658static unsigned r600_blit_create_rect(unsigned num_gpu_pages,
Ilija Hadzic8eec9d62011-10-12 23:29:40 -0400659 int *width, int *height, int max_dim)
Alex Deucher7dbf41d2011-05-17 05:09:43 -0400660{
661 unsigned max_pages;
Ilija Hadzicb3530962011-10-12 23:29:42 -0400662 unsigned pages = num_gpu_pages;
Alex Deucher7dbf41d2011-05-17 05:09:43 -0400663 int w, h;
664
Ilija Hadzicb3530962011-10-12 23:29:42 -0400665 if (num_gpu_pages == 0) {
Alex Deucher7dbf41d2011-05-17 05:09:43 -0400666 /* not supposed to be called with no pages, but just in case */
667 h = 0;
668 w = 0;
669 pages = 0;
670 WARN_ON(1);
671 } else {
672 int rect_order = 2;
673 h = RECT_UNIT_H;
Ilija Hadzicb3530962011-10-12 23:29:42 -0400674 while (num_gpu_pages / rect_order) {
Alex Deucher7dbf41d2011-05-17 05:09:43 -0400675 h *= 2;
676 rect_order *= 4;
Ilija Hadzic8eec9d62011-10-12 23:29:40 -0400677 if (h >= max_dim) {
678 h = max_dim;
Alex Deucher7dbf41d2011-05-17 05:09:43 -0400679 break;
680 }
681 }
Ilija Hadzic8eec9d62011-10-12 23:29:40 -0400682 max_pages = (max_dim * h) / (RECT_UNIT_W * RECT_UNIT_H);
Alex Deucher7dbf41d2011-05-17 05:09:43 -0400683 if (pages > max_pages)
684 pages = max_pages;
685 w = (pages * RECT_UNIT_W * RECT_UNIT_H) / h;
686 w = (w / RECT_UNIT_W) * RECT_UNIT_W;
687 pages = (w * h) / (RECT_UNIT_W * RECT_UNIT_H);
688 BUG_ON(pages == 0);
689 }
690
691
692 DRM_DEBUG("blit_rectangle: h=%d, w=%d, pages=%d\n", h, w, pages);
693
694 /* return width and height only of the caller wants it */
695 if (height)
696 *height = h;
697 if (width)
698 *width = w;
699
700 return pages;
701}
702
703
Ilija Hadzicb3530962011-10-12 23:29:42 -0400704int r600_blit_prepare_copy(struct radeon_device *rdev, unsigned num_gpu_pages)
Jerome Glisse3ce0a232009-09-08 10:10:24 +1000705{
Christian Könige32eb502011-10-23 12:56:27 +0200706 struct radeon_ring *ring = &rdev->ring[RADEON_RING_TYPE_GFX_INDEX];
Jerome Glisse3ce0a232009-09-08 10:10:24 +1000707 int r;
Alex Deucher7dbf41d2011-05-17 05:09:43 -0400708 int ring_size;
Ilija Hadzic8eec9d62011-10-12 23:29:40 -0400709 int num_loops = 0;
710 int dwords_per_loop = rdev->r600_blit.ring_size_per_loop;
Dave Airlie7cbb3552009-09-17 16:11:31 +1000711
Alex Deucher7dbf41d2011-05-17 05:09:43 -0400712 /* num loops */
Ilija Hadzicb3530962011-10-12 23:29:42 -0400713 while (num_gpu_pages) {
714 num_gpu_pages -=
715 r600_blit_create_rect(num_gpu_pages, NULL, NULL,
716 rdev->r600_blit.max_dim);
Alex Deucher7dbf41d2011-05-17 05:09:43 -0400717 num_loops++;
718 }
Jerome Glisse3ce0a232009-09-08 10:10:24 +1000719
Jerome Glisse69e130a2011-12-21 12:13:46 -0500720 /* 48 bytes for vertex per loop */
721 r = r600_vb_ib_get(rdev, (num_loops*48)+256);
722 if (r)
723 return r;
724
Dave Airlie7cbb3552009-09-17 16:11:31 +1000725 /* calculate number of loops correctly */
726 ring_size = num_loops * dwords_per_loop;
Ilija Hadzic8eec9d62011-10-12 23:29:40 -0400727 ring_size += rdev->r600_blit.ring_size_common;
Christian Könige32eb502011-10-23 12:56:27 +0200728 r = radeon_ring_lock(rdev, ring, ring_size);
Jerome Glisseff82f052010-01-22 15:19:00 +0100729 if (r)
730 return r;
Jerome Glisse3ce0a232009-09-08 10:10:24 +1000731
Ilija Hadzic8eec9d62011-10-12 23:29:40 -0400732 rdev->r600_blit.primitives.set_default_state(rdev);
733 rdev->r600_blit.primitives.set_shaders(rdev);
Jerome Glisse3ce0a232009-09-08 10:10:24 +1000734 return 0;
735}
736
737void r600_blit_done_copy(struct radeon_device *rdev, struct radeon_fence *fence)
738{
739 int r;
740
Jerome Glisse3ce0a232009-09-08 10:10:24 +1000741 if (rdev->r600_blit.vb_ib)
742 r600_vb_ib_put(rdev);
743
744 if (fence)
745 r = radeon_fence_emit(rdev, fence);
746
Christian Könige32eb502011-10-23 12:56:27 +0200747 radeon_ring_unlock_commit(rdev, &rdev->ring[RADEON_RING_TYPE_GFX_INDEX]);
Jerome Glisse3ce0a232009-09-08 10:10:24 +1000748}
749
750void r600_kms_blit_copy(struct radeon_device *rdev,
751 u64 src_gpu_addr, u64 dst_gpu_addr,
Ilija Hadzicb3530962011-10-12 23:29:42 -0400752 unsigned num_gpu_pages)
Jerome Glisse3ce0a232009-09-08 10:10:24 +1000753{
Jerome Glisse3ce0a232009-09-08 10:10:24 +1000754 u64 vb_gpu_addr;
755 u32 *vb;
756
Ilija Hadzic8eec9d62011-10-12 23:29:40 -0400757 DRM_DEBUG("emitting copy %16llx %16llx %d %d\n",
758 src_gpu_addr, dst_gpu_addr,
Ilija Hadzicb3530962011-10-12 23:29:42 -0400759 num_gpu_pages, rdev->r600_blit.vb_used);
Dave Airlieceeb5022009-10-12 13:54:10 +1000760 vb = (u32 *)(rdev->r600_blit.vb_ib->ptr + rdev->r600_blit.vb_used);
Jerome Glisse3ce0a232009-09-08 10:10:24 +1000761
Ilija Hadzicb3530962011-10-12 23:29:42 -0400762 while (num_gpu_pages) {
Alex Deucher7dbf41d2011-05-17 05:09:43 -0400763 int w, h;
764 unsigned size_in_bytes;
Ilija Hadzic8eec9d62011-10-12 23:29:40 -0400765 unsigned pages_per_loop =
Ilija Hadzicb3530962011-10-12 23:29:42 -0400766 r600_blit_create_rect(num_gpu_pages, &w, &h,
Ilija Hadzic8eec9d62011-10-12 23:29:40 -0400767 rdev->r600_blit.max_dim);
Jerome Glisse3ce0a232009-09-08 10:10:24 +1000768
Alex Deucher7dbf41d2011-05-17 05:09:43 -0400769 size_in_bytes = pages_per_loop * RADEON_GPU_PAGE_SIZE;
770 DRM_DEBUG("rectangle w=%d h=%d\n", w, h);
Jerome Glisse3ce0a232009-09-08 10:10:24 +1000771
Alex Deucher7dbf41d2011-05-17 05:09:43 -0400772 if ((rdev->r600_blit.vb_used + 48) > rdev->r600_blit.vb_total) {
773 WARN_ON(1);
Jerome Glisse3ce0a232009-09-08 10:10:24 +1000774 }
Jerome Glisse3ce0a232009-09-08 10:10:24 +1000775
Alex Deucher7dbf41d2011-05-17 05:09:43 -0400776 vb[0] = 0;
777 vb[1] = 0;
778 vb[2] = 0;
779 vb[3] = 0;
Jerome Glisse3ce0a232009-09-08 10:10:24 +1000780
Alex Deucher7dbf41d2011-05-17 05:09:43 -0400781 vb[4] = 0;
782 vb[5] = i2f(h);
783 vb[6] = 0;
784 vb[7] = i2f(h);
Jerome Glisse3ce0a232009-09-08 10:10:24 +1000785
Alex Deucher7dbf41d2011-05-17 05:09:43 -0400786 vb[8] = i2f(w);
787 vb[9] = i2f(h);
788 vb[10] = i2f(w);
789 vb[11] = i2f(h);
Jerome Glisse3ce0a232009-09-08 10:10:24 +1000790
Ilija Hadzic8eec9d62011-10-12 23:29:40 -0400791 rdev->r600_blit.primitives.set_tex_resource(rdev, FMT_8_8_8_8,
Alex Deucher9bb77032011-10-22 10:07:09 -0400792 w, h, w, src_gpu_addr, size_in_bytes);
Ilija Hadzic8eec9d62011-10-12 23:29:40 -0400793 rdev->r600_blit.primitives.set_render_target(rdev, COLOR_8_8_8_8,
794 w, h, dst_gpu_addr);
795 rdev->r600_blit.primitives.set_scissors(rdev, 0, 0, w, h);
Alex Deucher7dbf41d2011-05-17 05:09:43 -0400796 vb_gpu_addr = rdev->r600_blit.vb_ib->gpu_addr + rdev->r600_blit.vb_used;
Ilija Hadzic8eec9d62011-10-12 23:29:40 -0400797 rdev->r600_blit.primitives.set_vtx_resource(rdev, vb_gpu_addr);
798 rdev->r600_blit.primitives.draw_auto(rdev);
799 rdev->r600_blit.primitives.cp_set_surface_sync(rdev,
Alex Deucher7dbf41d2011-05-17 05:09:43 -0400800 PACKET3_CB_ACTION_ENA | PACKET3_CB0_DEST_BASE_ENA,
801 size_in_bytes, dst_gpu_addr);
Jerome Glisse3ce0a232009-09-08 10:10:24 +1000802
Alex Deucher7dbf41d2011-05-17 05:09:43 -0400803 vb += 12;
804 rdev->r600_blit.vb_used += 4*12;
805 src_gpu_addr += size_in_bytes;
806 dst_gpu_addr += size_in_bytes;
Ilija Hadzicb3530962011-10-12 23:29:42 -0400807 num_gpu_pages -= pages_per_loop;
Jerome Glisse3ce0a232009-09-08 10:10:24 +1000808 }
809}