2 * Copyright 2009 Advanced Micro Devices, Inc.
3 * Copyright 2009 Red Hat Inc.
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:
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
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.
28 #include "radeon_drm.h"
32 #include "r600_blit_shaders.h"
34 #define DI_PT_RECTLIST 0x11
35 #define DI_INDEX_SIZE_16_BIT 0x0
36 #define DI_SRC_SEL_AUTO_INDEX 0x2
40 #define FMT_8_8_8_8 0x1a
42 #define COLOR_5_6_5 0x8
43 #define COLOR_8_8_8_8 0x1a
45 #define RECT_UNIT_H 32
46 #define RECT_UNIT_W (RADEON_GPU_PAGE_SIZE / 4 / RECT_UNIT_H)
48 /* emits 21 on rv770+, 23 on r600 */
50 set_render_target(struct radeon_device
*rdev
, int format
,
51 int w
, int h
, u64 gpu_addr
)
60 cb_color_info
= CB_FORMAT(format
) |
61 CB_SOURCE_FORMAT(CB_SF_EXPORT_NORM
) |
62 CB_ARRAY_MODE(ARRAY_1D_TILED_THIN1
);
64 slice
= ((w
* h
) / 64) - 1;
66 radeon_ring_write(rdev
, PACKET3(PACKET3_SET_CONTEXT_REG
, 1));
67 radeon_ring_write(rdev
, (CB_COLOR0_BASE
- PACKET3_SET_CONTEXT_REG_OFFSET
) >> 2);
68 radeon_ring_write(rdev
, gpu_addr
>> 8);
70 if (rdev
->family
> CHIP_R600
&& rdev
->family
< CHIP_RV770
) {
71 radeon_ring_write(rdev
, PACKET3(PACKET3_SURFACE_BASE_UPDATE
, 0));
72 radeon_ring_write(rdev
, 2 << 0);
75 radeon_ring_write(rdev
, PACKET3(PACKET3_SET_CONTEXT_REG
, 1));
76 radeon_ring_write(rdev
, (CB_COLOR0_SIZE
- PACKET3_SET_CONTEXT_REG_OFFSET
) >> 2);
77 radeon_ring_write(rdev
, (pitch
<< 0) | (slice
<< 10));
79 radeon_ring_write(rdev
, PACKET3(PACKET3_SET_CONTEXT_REG
, 1));
80 radeon_ring_write(rdev
, (CB_COLOR0_VIEW
- PACKET3_SET_CONTEXT_REG_OFFSET
) >> 2);
81 radeon_ring_write(rdev
, 0);
83 radeon_ring_write(rdev
, PACKET3(PACKET3_SET_CONTEXT_REG
, 1));
84 radeon_ring_write(rdev
, (CB_COLOR0_INFO
- PACKET3_SET_CONTEXT_REG_OFFSET
) >> 2);
85 radeon_ring_write(rdev
, cb_color_info
);
87 radeon_ring_write(rdev
, PACKET3(PACKET3_SET_CONTEXT_REG
, 1));
88 radeon_ring_write(rdev
, (CB_COLOR0_TILE
- PACKET3_SET_CONTEXT_REG_OFFSET
) >> 2);
89 radeon_ring_write(rdev
, 0);
91 radeon_ring_write(rdev
, PACKET3(PACKET3_SET_CONTEXT_REG
, 1));
92 radeon_ring_write(rdev
, (CB_COLOR0_FRAG
- PACKET3_SET_CONTEXT_REG_OFFSET
) >> 2);
93 radeon_ring_write(rdev
, 0);
95 radeon_ring_write(rdev
, PACKET3(PACKET3_SET_CONTEXT_REG
, 1));
96 radeon_ring_write(rdev
, (CB_COLOR0_MASK
- PACKET3_SET_CONTEXT_REG_OFFSET
) >> 2);
97 radeon_ring_write(rdev
, 0);
102 cp_set_surface_sync(struct radeon_device
*rdev
,
103 u32 sync_type
, u32 size
,
108 if (size
== 0xffffffff)
109 cp_coher_size
= 0xffffffff;
111 cp_coher_size
= ((size
+ 255) >> 8);
113 radeon_ring_write(rdev
, PACKET3(PACKET3_SURFACE_SYNC
, 3));
114 radeon_ring_write(rdev
, sync_type
);
115 radeon_ring_write(rdev
, cp_coher_size
);
116 radeon_ring_write(rdev
, mc_addr
>> 8);
117 radeon_ring_write(rdev
, 10); /* poll interval */
120 /* emits 21dw + 1 surface sync = 26dw */
122 set_shaders(struct radeon_device
*rdev
)
125 u32 sq_pgm_resources
;
127 /* setup shader regs */
128 sq_pgm_resources
= (1 << 0);
131 gpu_addr
= rdev
->r600_blit
.shader_gpu_addr
+ rdev
->r600_blit
.vs_offset
;
132 radeon_ring_write(rdev
, PACKET3(PACKET3_SET_CONTEXT_REG
, 1));
133 radeon_ring_write(rdev
, (SQ_PGM_START_VS
- PACKET3_SET_CONTEXT_REG_OFFSET
) >> 2);
134 radeon_ring_write(rdev
, gpu_addr
>> 8);
136 radeon_ring_write(rdev
, PACKET3(PACKET3_SET_CONTEXT_REG
, 1));
137 radeon_ring_write(rdev
, (SQ_PGM_RESOURCES_VS
- PACKET3_SET_CONTEXT_REG_OFFSET
) >> 2);
138 radeon_ring_write(rdev
, sq_pgm_resources
);
140 radeon_ring_write(rdev
, PACKET3(PACKET3_SET_CONTEXT_REG
, 1));
141 radeon_ring_write(rdev
, (SQ_PGM_CF_OFFSET_VS
- PACKET3_SET_CONTEXT_REG_OFFSET
) >> 2);
142 radeon_ring_write(rdev
, 0);
145 gpu_addr
= rdev
->r600_blit
.shader_gpu_addr
+ rdev
->r600_blit
.ps_offset
;
146 radeon_ring_write(rdev
, PACKET3(PACKET3_SET_CONTEXT_REG
, 1));
147 radeon_ring_write(rdev
, (SQ_PGM_START_PS
- PACKET3_SET_CONTEXT_REG_OFFSET
) >> 2);
148 radeon_ring_write(rdev
, gpu_addr
>> 8);
150 radeon_ring_write(rdev
, PACKET3(PACKET3_SET_CONTEXT_REG
, 1));
151 radeon_ring_write(rdev
, (SQ_PGM_RESOURCES_PS
- PACKET3_SET_CONTEXT_REG_OFFSET
) >> 2);
152 radeon_ring_write(rdev
, sq_pgm_resources
| (1 << 28));
154 radeon_ring_write(rdev
, PACKET3(PACKET3_SET_CONTEXT_REG
, 1));
155 radeon_ring_write(rdev
, (SQ_PGM_EXPORTS_PS
- PACKET3_SET_CONTEXT_REG_OFFSET
) >> 2);
156 radeon_ring_write(rdev
, 2);
158 radeon_ring_write(rdev
, PACKET3(PACKET3_SET_CONTEXT_REG
, 1));
159 radeon_ring_write(rdev
, (SQ_PGM_CF_OFFSET_PS
- PACKET3_SET_CONTEXT_REG_OFFSET
) >> 2);
160 radeon_ring_write(rdev
, 0);
162 gpu_addr
= rdev
->r600_blit
.shader_gpu_addr
+ rdev
->r600_blit
.vs_offset
;
163 cp_set_surface_sync(rdev
, PACKET3_SH_ACTION_ENA
, 512, gpu_addr
);
166 /* emits 9 + 1 sync (5) = 14*/
168 set_vtx_resource(struct radeon_device
*rdev
, u64 gpu_addr
)
170 u32 sq_vtx_constant_word2
;
172 sq_vtx_constant_word2
= SQ_VTXC_BASE_ADDR_HI(upper_32_bits(gpu_addr
) & 0xff) |
175 sq_vtx_constant_word2
|= SQ_VTXC_ENDIAN_SWAP(SQ_ENDIAN_8IN32
);
178 radeon_ring_write(rdev
, PACKET3(PACKET3_SET_RESOURCE
, 7));
179 radeon_ring_write(rdev
, 0x460);
180 radeon_ring_write(rdev
, gpu_addr
& 0xffffffff);
181 radeon_ring_write(rdev
, 48 - 1);
182 radeon_ring_write(rdev
, sq_vtx_constant_word2
);
183 radeon_ring_write(rdev
, 1 << 0);
184 radeon_ring_write(rdev
, 0);
185 radeon_ring_write(rdev
, 0);
186 radeon_ring_write(rdev
, SQ_TEX_VTX_VALID_BUFFER
<< 30);
188 if ((rdev
->family
== CHIP_RV610
) ||
189 (rdev
->family
== CHIP_RV620
) ||
190 (rdev
->family
== CHIP_RS780
) ||
191 (rdev
->family
== CHIP_RS880
) ||
192 (rdev
->family
== CHIP_RV710
))
193 cp_set_surface_sync(rdev
,
194 PACKET3_TC_ACTION_ENA
, 48, gpu_addr
);
196 cp_set_surface_sync(rdev
,
197 PACKET3_VC_ACTION_ENA
, 48, gpu_addr
);
202 set_tex_resource(struct radeon_device
*rdev
,
203 int format
, int w
, int h
, int pitch
,
206 uint32_t sq_tex_resource_word0
, sq_tex_resource_word1
, sq_tex_resource_word4
;
211 sq_tex_resource_word0
= S_038000_DIM(V_038000_SQ_TEX_DIM_2D
) |
212 S_038000_TILE_MODE(V_038000_ARRAY_1D_TILED_THIN1
);
213 sq_tex_resource_word0
|= S_038000_PITCH((pitch
>> 3) - 1) |
214 S_038000_TEX_WIDTH(w
- 1);
216 sq_tex_resource_word1
= S_038004_DATA_FORMAT(format
);
217 sq_tex_resource_word1
|= S_038004_TEX_HEIGHT(h
- 1);
219 sq_tex_resource_word4
= S_038010_REQUEST_SIZE(1) |
220 S_038010_DST_SEL_X(SQ_SEL_X
) |
221 S_038010_DST_SEL_Y(SQ_SEL_Y
) |
222 S_038010_DST_SEL_Z(SQ_SEL_Z
) |
223 S_038010_DST_SEL_W(SQ_SEL_W
);
225 radeon_ring_write(rdev
, PACKET3(PACKET3_SET_RESOURCE
, 7));
226 radeon_ring_write(rdev
, 0);
227 radeon_ring_write(rdev
, sq_tex_resource_word0
);
228 radeon_ring_write(rdev
, sq_tex_resource_word1
);
229 radeon_ring_write(rdev
, gpu_addr
>> 8);
230 radeon_ring_write(rdev
, gpu_addr
>> 8);
231 radeon_ring_write(rdev
, sq_tex_resource_word4
);
232 radeon_ring_write(rdev
, 0);
233 radeon_ring_write(rdev
, SQ_TEX_VTX_VALID_TEXTURE
<< 30);
238 set_scissors(struct radeon_device
*rdev
, int x1
, int y1
,
241 radeon_ring_write(rdev
, PACKET3(PACKET3_SET_CONTEXT_REG
, 2));
242 radeon_ring_write(rdev
, (PA_SC_SCREEN_SCISSOR_TL
- PACKET3_SET_CONTEXT_REG_OFFSET
) >> 2);
243 radeon_ring_write(rdev
, (x1
<< 0) | (y1
<< 16));
244 radeon_ring_write(rdev
, (x2
<< 0) | (y2
<< 16));
246 radeon_ring_write(rdev
, PACKET3(PACKET3_SET_CONTEXT_REG
, 2));
247 radeon_ring_write(rdev
, (PA_SC_GENERIC_SCISSOR_TL
- PACKET3_SET_CONTEXT_REG_OFFSET
) >> 2);
248 radeon_ring_write(rdev
, (x1
<< 0) | (y1
<< 16) | (1 << 31));
249 radeon_ring_write(rdev
, (x2
<< 0) | (y2
<< 16));
251 radeon_ring_write(rdev
, PACKET3(PACKET3_SET_CONTEXT_REG
, 2));
252 radeon_ring_write(rdev
, (PA_SC_WINDOW_SCISSOR_TL
- PACKET3_SET_CONTEXT_REG_OFFSET
) >> 2);
253 radeon_ring_write(rdev
, (x1
<< 0) | (y1
<< 16) | (1 << 31));
254 radeon_ring_write(rdev
, (x2
<< 0) | (y2
<< 16));
259 draw_auto(struct radeon_device
*rdev
)
261 radeon_ring_write(rdev
, PACKET3(PACKET3_SET_CONFIG_REG
, 1));
262 radeon_ring_write(rdev
, (VGT_PRIMITIVE_TYPE
- PACKET3_SET_CONFIG_REG_OFFSET
) >> 2);
263 radeon_ring_write(rdev
, DI_PT_RECTLIST
);
265 radeon_ring_write(rdev
, PACKET3(PACKET3_INDEX_TYPE
, 0));
266 radeon_ring_write(rdev
,
270 DI_INDEX_SIZE_16_BIT
);
272 radeon_ring_write(rdev
, PACKET3(PACKET3_NUM_INSTANCES
, 0));
273 radeon_ring_write(rdev
, 1);
275 radeon_ring_write(rdev
, PACKET3(PACKET3_DRAW_INDEX_AUTO
, 1));
276 radeon_ring_write(rdev
, 3);
277 radeon_ring_write(rdev
, DI_SRC_SEL_AUTO_INDEX
);
283 set_default_state(struct radeon_device
*rdev
)
285 u32 sq_config
, sq_gpr_resource_mgmt_1
, sq_gpr_resource_mgmt_2
;
286 u32 sq_thread_resource_mgmt
, sq_stack_resource_mgmt_1
, sq_stack_resource_mgmt_2
;
287 int num_ps_gprs
, num_vs_gprs
, num_temp_gprs
, num_gs_gprs
, num_es_gprs
;
288 int num_ps_threads
, num_vs_threads
, num_gs_threads
, num_es_threads
;
289 int num_ps_stack_entries
, num_vs_stack_entries
, num_gs_stack_entries
, num_es_stack_entries
;
293 switch (rdev
->family
) {
300 num_ps_threads
= 136;
304 num_ps_stack_entries
= 128;
305 num_vs_stack_entries
= 128;
306 num_gs_stack_entries
= 0;
307 num_es_stack_entries
= 0;
316 num_ps_threads
= 144;
320 num_ps_stack_entries
= 40;
321 num_vs_stack_entries
= 40;
322 num_gs_stack_entries
= 32;
323 num_es_stack_entries
= 16;
335 num_ps_threads
= 136;
339 num_ps_stack_entries
= 40;
340 num_vs_stack_entries
= 40;
341 num_gs_stack_entries
= 32;
342 num_es_stack_entries
= 16;
350 num_ps_threads
= 136;
354 num_ps_stack_entries
= 40;
355 num_vs_stack_entries
= 40;
356 num_gs_stack_entries
= 32;
357 num_es_stack_entries
= 16;
365 num_ps_threads
= 188;
369 num_ps_stack_entries
= 256;
370 num_vs_stack_entries
= 256;
371 num_gs_stack_entries
= 0;
372 num_es_stack_entries
= 0;
381 num_ps_threads
= 188;
385 num_ps_stack_entries
= 128;
386 num_vs_stack_entries
= 128;
387 num_gs_stack_entries
= 0;
388 num_es_stack_entries
= 0;
396 num_ps_threads
= 144;
400 num_ps_stack_entries
= 128;
401 num_vs_stack_entries
= 128;
402 num_gs_stack_entries
= 0;
403 num_es_stack_entries
= 0;
407 if ((rdev
->family
== CHIP_RV610
) ||
408 (rdev
->family
== CHIP_RV620
) ||
409 (rdev
->family
== CHIP_RS780
) ||
410 (rdev
->family
== CHIP_RS880
) ||
411 (rdev
->family
== CHIP_RV710
))
414 sq_config
= VC_ENABLE
;
416 sq_config
|= (DX9_CONSTS
|
417 ALU_INST_PREFER_VECTOR
|
423 sq_gpr_resource_mgmt_1
= (NUM_PS_GPRS(num_ps_gprs
) |
424 NUM_VS_GPRS(num_vs_gprs
) |
425 NUM_CLAUSE_TEMP_GPRS(num_temp_gprs
));
426 sq_gpr_resource_mgmt_2
= (NUM_GS_GPRS(num_gs_gprs
) |
427 NUM_ES_GPRS(num_es_gprs
));
428 sq_thread_resource_mgmt
= (NUM_PS_THREADS(num_ps_threads
) |
429 NUM_VS_THREADS(num_vs_threads
) |
430 NUM_GS_THREADS(num_gs_threads
) |
431 NUM_ES_THREADS(num_es_threads
));
432 sq_stack_resource_mgmt_1
= (NUM_PS_STACK_ENTRIES(num_ps_stack_entries
) |
433 NUM_VS_STACK_ENTRIES(num_vs_stack_entries
));
434 sq_stack_resource_mgmt_2
= (NUM_GS_STACK_ENTRIES(num_gs_stack_entries
) |
435 NUM_ES_STACK_ENTRIES(num_es_stack_entries
));
437 /* emit an IB pointing at default state */
438 dwords
= ALIGN(rdev
->r600_blit
.state_len
, 0x10);
439 gpu_addr
= rdev
->r600_blit
.shader_gpu_addr
+ rdev
->r600_blit
.state_offset
;
440 radeon_ring_write(rdev
, PACKET3(PACKET3_INDIRECT_BUFFER
, 2));
441 radeon_ring_write(rdev
,
445 (gpu_addr
& 0xFFFFFFFC));
446 radeon_ring_write(rdev
, upper_32_bits(gpu_addr
) & 0xFF);
447 radeon_ring_write(rdev
, dwords
);
450 radeon_ring_write(rdev
, PACKET3(PACKET3_SET_CONFIG_REG
, 6));
451 radeon_ring_write(rdev
, (SQ_CONFIG
- PACKET3_SET_CONFIG_REG_OFFSET
) >> 2);
452 radeon_ring_write(rdev
, sq_config
);
453 radeon_ring_write(rdev
, sq_gpr_resource_mgmt_1
);
454 radeon_ring_write(rdev
, sq_gpr_resource_mgmt_2
);
455 radeon_ring_write(rdev
, sq_thread_resource_mgmt
);
456 radeon_ring_write(rdev
, sq_stack_resource_mgmt_1
);
457 radeon_ring_write(rdev
, sq_stack_resource_mgmt_2
);
460 static uint32_t i2f(uint32_t input
)
462 u32 result
, i
, exponent
, fraction
;
464 if ((input
& 0x3fff) == 0)
465 result
= 0; /* 0 is a special case */
467 exponent
= 140; /* exponent biased by 127; */
468 fraction
= (input
& 0x3fff) << 10; /* cheat and only
469 handle numbers below 2^^15 */
470 for (i
= 0; i
< 14; i
++) {
471 if (fraction
& 0x800000)
474 fraction
= fraction
<< 1; /* keep
475 shifting left until top bit = 1 */
476 exponent
= exponent
- 1;
479 result
= exponent
<< 23 | (fraction
& 0x7fffff); /* mask
480 off top bit; assumed 1 */
485 int r600_blit_init(struct radeon_device
*rdev
)
491 int num_packet2s
= 0;
493 rdev
->r600_blit
.primitives
.set_render_target
= set_render_target
;
494 rdev
->r600_blit
.primitives
.cp_set_surface_sync
= cp_set_surface_sync
;
495 rdev
->r600_blit
.primitives
.set_shaders
= set_shaders
;
496 rdev
->r600_blit
.primitives
.set_vtx_resource
= set_vtx_resource
;
497 rdev
->r600_blit
.primitives
.set_tex_resource
= set_tex_resource
;
498 rdev
->r600_blit
.primitives
.set_scissors
= set_scissors
;
499 rdev
->r600_blit
.primitives
.draw_auto
= draw_auto
;
500 rdev
->r600_blit
.primitives
.set_default_state
= set_default_state
;
502 rdev
->r600_blit
.ring_size_common
= 40; /* shaders + def state */
503 rdev
->r600_blit
.ring_size_common
+= 10; /* fence emit for VB IB */
504 rdev
->r600_blit
.ring_size_common
+= 5; /* done copy */
505 rdev
->r600_blit
.ring_size_common
+= 10; /* fence emit for done copy */
507 rdev
->r600_blit
.ring_size_per_loop
= 76;
508 /* set_render_target emits 2 extra dwords on rv6xx */
509 if (rdev
->family
> CHIP_R600
&& rdev
->family
< CHIP_RV770
)
510 rdev
->r600_blit
.ring_size_per_loop
+= 2;
512 rdev
->r600_blit
.max_dim
= 8192;
514 /* pin copy shader into vram if already initialized */
515 if (rdev
->r600_blit
.shader_obj
)
518 mutex_init(&rdev
->r600_blit
.mutex
);
519 rdev
->r600_blit
.state_offset
= 0;
521 if (rdev
->family
>= CHIP_RV770
)
522 rdev
->r600_blit
.state_len
= r7xx_default_size
;
524 rdev
->r600_blit
.state_len
= r6xx_default_size
;
526 dwords
= rdev
->r600_blit
.state_len
;
527 while (dwords
& 0xf) {
528 packet2s
[num_packet2s
++] = cpu_to_le32(PACKET2(0));
532 obj_size
= dwords
* 4;
533 obj_size
= ALIGN(obj_size
, 256);
535 rdev
->r600_blit
.vs_offset
= obj_size
;
536 obj_size
+= r6xx_vs_size
* 4;
537 obj_size
= ALIGN(obj_size
, 256);
539 rdev
->r600_blit
.ps_offset
= obj_size
;
540 obj_size
+= r6xx_ps_size
* 4;
541 obj_size
= ALIGN(obj_size
, 256);
543 r
= radeon_bo_create(rdev
, obj_size
, PAGE_SIZE
, true, RADEON_GEM_DOMAIN_VRAM
,
544 &rdev
->r600_blit
.shader_obj
);
546 DRM_ERROR("r600 failed to allocate shader\n");
550 DRM_DEBUG("r6xx blit allocated bo %08x vs %08x ps %08x\n",
552 rdev
->r600_blit
.vs_offset
, rdev
->r600_blit
.ps_offset
);
554 r
= radeon_bo_reserve(rdev
->r600_blit
.shader_obj
, false);
555 if (unlikely(r
!= 0))
557 r
= radeon_bo_kmap(rdev
->r600_blit
.shader_obj
, &ptr
);
559 DRM_ERROR("failed to map blit object %d\n", r
);
562 if (rdev
->family
>= CHIP_RV770
)
563 memcpy_toio(ptr
+ rdev
->r600_blit
.state_offset
,
564 r7xx_default_state
, rdev
->r600_blit
.state_len
* 4);
566 memcpy_toio(ptr
+ rdev
->r600_blit
.state_offset
,
567 r6xx_default_state
, rdev
->r600_blit
.state_len
* 4);
569 memcpy_toio(ptr
+ rdev
->r600_blit
.state_offset
+ (rdev
->r600_blit
.state_len
* 4),
570 packet2s
, num_packet2s
* 4);
571 for (i
= 0; i
< r6xx_vs_size
; i
++)
572 *(u32
*)((unsigned long)ptr
+ rdev
->r600_blit
.vs_offset
+ i
* 4) = cpu_to_le32(r6xx_vs
[i
]);
573 for (i
= 0; i
< r6xx_ps_size
; i
++)
574 *(u32
*)((unsigned long)ptr
+ rdev
->r600_blit
.ps_offset
+ i
* 4) = cpu_to_le32(r6xx_ps
[i
]);
575 radeon_bo_kunmap(rdev
->r600_blit
.shader_obj
);
576 radeon_bo_unreserve(rdev
->r600_blit
.shader_obj
);
579 r
= radeon_bo_reserve(rdev
->r600_blit
.shader_obj
, false);
580 if (unlikely(r
!= 0))
582 r
= radeon_bo_pin(rdev
->r600_blit
.shader_obj
, RADEON_GEM_DOMAIN_VRAM
,
583 &rdev
->r600_blit
.shader_gpu_addr
);
584 radeon_bo_unreserve(rdev
->r600_blit
.shader_obj
);
586 dev_err(rdev
->dev
, "(%d) pin blit object failed\n", r
);
589 radeon_ttm_set_active_vram_size(rdev
, rdev
->mc
.real_vram_size
);
593 void r600_blit_fini(struct radeon_device
*rdev
)
597 radeon_ttm_set_active_vram_size(rdev
, rdev
->mc
.visible_vram_size
);
598 if (rdev
->r600_blit
.shader_obj
== NULL
)
600 /* If we can't reserve the bo, unref should be enough to destroy
601 * it when it becomes idle.
603 r
= radeon_bo_reserve(rdev
->r600_blit
.shader_obj
, false);
605 radeon_bo_unpin(rdev
->r600_blit
.shader_obj
);
606 radeon_bo_unreserve(rdev
->r600_blit
.shader_obj
);
608 radeon_bo_unref(&rdev
->r600_blit
.shader_obj
);
611 static int r600_vb_ib_get(struct radeon_device
*rdev
)
614 r
= radeon_ib_get(rdev
, &rdev
->r600_blit
.vb_ib
);
616 DRM_ERROR("failed to get IB for vertex buffer\n");
620 rdev
->r600_blit
.vb_total
= 64*1024;
621 rdev
->r600_blit
.vb_used
= 0;
625 static void r600_vb_ib_put(struct radeon_device
*rdev
)
627 radeon_fence_emit(rdev
, rdev
->r600_blit
.vb_ib
->fence
);
628 radeon_ib_free(rdev
, &rdev
->r600_blit
.vb_ib
);
631 static unsigned r600_blit_create_rect(unsigned num_gpu_pages
,
632 int *width
, int *height
, int max_dim
)
635 unsigned pages
= num_gpu_pages
;
638 if (num_gpu_pages
== 0) {
639 /* not supposed to be called with no pages, but just in case */
647 while (num_gpu_pages
/ rect_order
) {
655 max_pages
= (max_dim
* h
) / (RECT_UNIT_W
* RECT_UNIT_H
);
656 if (pages
> max_pages
)
658 w
= (pages
* RECT_UNIT_W
* RECT_UNIT_H
) / h
;
659 w
= (w
/ RECT_UNIT_W
) * RECT_UNIT_W
;
660 pages
= (w
* h
) / (RECT_UNIT_W
* RECT_UNIT_H
);
665 DRM_DEBUG("blit_rectangle: h=%d, w=%d, pages=%d\n", h
, w
, pages
);
667 /* return width and height only of the caller wants it */
677 int r600_blit_prepare_copy(struct radeon_device
*rdev
, unsigned num_gpu_pages
)
682 int dwords_per_loop
= rdev
->r600_blit
.ring_size_per_loop
;
684 r
= r600_vb_ib_get(rdev
);
689 while (num_gpu_pages
) {
691 r600_blit_create_rect(num_gpu_pages
, NULL
, NULL
,
692 rdev
->r600_blit
.max_dim
);
696 /* calculate number of loops correctly */
697 ring_size
= num_loops
* dwords_per_loop
;
698 ring_size
+= rdev
->r600_blit
.ring_size_common
;
699 r
= radeon_ring_lock(rdev
, ring_size
);
703 rdev
->r600_blit
.primitives
.set_default_state(rdev
);
704 rdev
->r600_blit
.primitives
.set_shaders(rdev
);
708 void r600_blit_done_copy(struct radeon_device
*rdev
, struct radeon_fence
*fence
)
712 if (rdev
->r600_blit
.vb_ib
)
713 r600_vb_ib_put(rdev
);
716 r
= radeon_fence_emit(rdev
, fence
);
718 radeon_ring_unlock_commit(rdev
);
721 void r600_kms_blit_copy(struct radeon_device
*rdev
,
722 u64 src_gpu_addr
, u64 dst_gpu_addr
,
723 unsigned num_gpu_pages
)
728 DRM_DEBUG("emitting copy %16llx %16llx %d %d\n",
729 src_gpu_addr
, dst_gpu_addr
,
730 num_gpu_pages
, rdev
->r600_blit
.vb_used
);
731 vb
= (u32
*)(rdev
->r600_blit
.vb_ib
->ptr
+ rdev
->r600_blit
.vb_used
);
733 while (num_gpu_pages
) {
735 unsigned size_in_bytes
;
736 unsigned pages_per_loop
=
737 r600_blit_create_rect(num_gpu_pages
, &w
, &h
,
738 rdev
->r600_blit
.max_dim
);
740 size_in_bytes
= pages_per_loop
* RADEON_GPU_PAGE_SIZE
;
741 DRM_DEBUG("rectangle w=%d h=%d\n", w
, h
);
743 if ((rdev
->r600_blit
.vb_used
+ 48) > rdev
->r600_blit
.vb_total
) {
762 rdev
->r600_blit
.primitives
.set_tex_resource(rdev
, FMT_8_8_8_8
,
763 w
, h
, w
, src_gpu_addr
);
764 rdev
->r600_blit
.primitives
.cp_set_surface_sync(rdev
,
765 PACKET3_TC_ACTION_ENA
,
766 size_in_bytes
, src_gpu_addr
);
767 rdev
->r600_blit
.primitives
.set_render_target(rdev
, COLOR_8_8_8_8
,
769 rdev
->r600_blit
.primitives
.set_scissors(rdev
, 0, 0, w
, h
);
770 vb_gpu_addr
= rdev
->r600_blit
.vb_ib
->gpu_addr
+ rdev
->r600_blit
.vb_used
;
771 rdev
->r600_blit
.primitives
.set_vtx_resource(rdev
, vb_gpu_addr
);
772 rdev
->r600_blit
.primitives
.draw_auto(rdev
);
773 rdev
->r600_blit
.primitives
.cp_set_surface_sync(rdev
,
774 PACKET3_CB_ACTION_ENA
| PACKET3_CB0_DEST_BASE_ENA
,
775 size_in_bytes
, dst_gpu_addr
);
778 rdev
->r600_blit
.vb_used
+= 4*12;
779 src_gpu_addr
+= size_in_bytes
;
780 dst_gpu_addr
+= size_in_bytes
;
781 num_gpu_pages
-= pages_per_loop
;