2 * Copyright 2016 Advanced Micro Devices, Inc.
5 * Permission is hereby granted, free of charge, to any person obtaining a
6 * copy of this software and associated documentation files (the
7 * "Software"), to deal in the Software without restriction, including
8 * without limitation the rights to use, copy, modify, merge, publish,
9 * distribute, sub license, and/or sell copies of the Software, and to
10 * permit persons to whom the Software is furnished to do so, subject to
11 * the following conditions:
13 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15 * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
16 * THE COPYRIGHT HOLDERS, AUTHORS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM,
17 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
18 * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
19 * USE OR OTHER DEALINGS IN THE SOFTWARE.
21 * The above copyright notice and this permission notice (including the
22 * next paragraph) shall be included in all copies or substantial portions
27 #include <linux/firmware.h>
28 #include <linux/module.h>
33 #include "amdgpu_pm.h"
34 #include "amdgpu_vcn.h"
36 #include "soc15_common.h"
38 #include "vcn/vcn_1_0_offset.h"
39 #include "vcn/vcn_1_0_sh_mask.h"
41 /* 1 second timeout */
42 #define VCN_IDLE_TIMEOUT msecs_to_jiffies(1000)
45 #define FIRMWARE_RAVEN "amdgpu/raven_vcn.bin"
46 #define FIRMWARE_PICASSO "amdgpu/picasso_vcn.bin"
47 #define FIRMWARE_RAVEN2 "amdgpu/raven2_vcn.bin"
49 MODULE_FIRMWARE(FIRMWARE_RAVEN
);
50 MODULE_FIRMWARE(FIRMWARE_PICASSO
);
51 MODULE_FIRMWARE(FIRMWARE_RAVEN2
);
53 static void amdgpu_vcn_idle_work_handler(struct work_struct
*work
);
55 int amdgpu_vcn_sw_init(struct amdgpu_device
*adev
)
57 unsigned long bo_size
;
59 const struct common_firmware_header
*hdr
;
60 unsigned char fw_check
;
63 INIT_DELAYED_WORK(&adev
->vcn
.idle_work
, amdgpu_vcn_idle_work_handler
);
65 switch (adev
->asic_type
) {
67 if (adev
->rev_id
>= 8)
68 fw_name
= FIRMWARE_RAVEN2
;
69 else if (adev
->pdev
->device
== 0x15d8)
70 fw_name
= FIRMWARE_PICASSO
;
72 fw_name
= FIRMWARE_RAVEN
;
78 r
= request_firmware(&adev
->vcn
.fw
, fw_name
, adev
->dev
);
80 dev_err(adev
->dev
, "amdgpu_vcn: Can't load firmware \"%s\"\n",
85 r
= amdgpu_ucode_validate(adev
->vcn
.fw
);
87 dev_err(adev
->dev
, "amdgpu_vcn: Can't validate firmware \"%s\"\n",
89 release_firmware(adev
->vcn
.fw
);
94 hdr
= (const struct common_firmware_header
*)adev
->vcn
.fw
->data
;
95 adev
->vcn
.fw_version
= le32_to_cpu(hdr
->ucode_version
);
97 /* Bit 20-23, it is encode major and non-zero for new naming convention.
98 * This field is part of version minor and DRM_DISABLED_FLAG in old naming
99 * convention. Since the l:wq!atest version minor is 0x5B and DRM_DISABLED_FLAG
100 * is zero in old naming convention, this field is always zero so far.
101 * These four bits are used to tell which naming convention is present.
103 fw_check
= (le32_to_cpu(hdr
->ucode_version
) >> 20) & 0xf;
105 unsigned int dec_ver
, enc_major
, enc_minor
, vep
, fw_rev
;
107 fw_rev
= le32_to_cpu(hdr
->ucode_version
) & 0xfff;
108 enc_minor
= (le32_to_cpu(hdr
->ucode_version
) >> 12) & 0xff;
109 enc_major
= fw_check
;
110 dec_ver
= (le32_to_cpu(hdr
->ucode_version
) >> 24) & 0xf;
111 vep
= (le32_to_cpu(hdr
->ucode_version
) >> 28) & 0xf;
112 DRM_INFO("Found VCN firmware Version ENC: %hu.%hu DEC: %hu VEP: %hu Revision: %hu\n",
113 enc_major
, enc_minor
, dec_ver
, vep
, fw_rev
);
115 unsigned int version_major
, version_minor
, family_id
;
117 family_id
= le32_to_cpu(hdr
->ucode_version
) & 0xff;
118 version_major
= (le32_to_cpu(hdr
->ucode_version
) >> 24) & 0xff;
119 version_minor
= (le32_to_cpu(hdr
->ucode_version
) >> 8) & 0xff;
120 DRM_INFO("Found VCN firmware Version: %hu.%hu Family ID: %hu\n",
121 version_major
, version_minor
, family_id
);
124 bo_size
= AMDGPU_VCN_STACK_SIZE
+ AMDGPU_VCN_CONTEXT_SIZE
;
125 if (adev
->firmware
.load_type
!= AMDGPU_FW_LOAD_PSP
)
126 bo_size
+= AMDGPU_GPU_PAGE_ALIGN(le32_to_cpu(hdr
->ucode_size_bytes
) + 8);
127 r
= amdgpu_bo_create_kernel(adev
, bo_size
, PAGE_SIZE
,
128 AMDGPU_GEM_DOMAIN_VRAM
, &adev
->vcn
.vcpu_bo
,
129 &adev
->vcn
.gpu_addr
, &adev
->vcn
.cpu_addr
);
131 dev_err(adev
->dev
, "(%d) failed to allocate vcn bo\n", r
);
138 int amdgpu_vcn_sw_fini(struct amdgpu_device
*adev
)
142 kvfree(adev
->vcn
.saved_bo
);
144 amdgpu_bo_free_kernel(&adev
->vcn
.vcpu_bo
,
146 (void **)&adev
->vcn
.cpu_addr
);
148 amdgpu_ring_fini(&adev
->vcn
.ring_dec
);
150 for (i
= 0; i
< adev
->vcn
.num_enc_rings
; ++i
)
151 amdgpu_ring_fini(&adev
->vcn
.ring_enc
[i
]);
153 amdgpu_ring_fini(&adev
->vcn
.ring_jpeg
);
155 release_firmware(adev
->vcn
.fw
);
160 int amdgpu_vcn_suspend(struct amdgpu_device
*adev
)
165 cancel_delayed_work_sync(&adev
->vcn
.idle_work
);
167 if (adev
->vcn
.vcpu_bo
== NULL
)
170 size
= amdgpu_bo_size(adev
->vcn
.vcpu_bo
);
171 ptr
= adev
->vcn
.cpu_addr
;
173 adev
->vcn
.saved_bo
= kvmalloc(size
, GFP_KERNEL
);
174 if (!adev
->vcn
.saved_bo
)
177 memcpy_fromio(adev
->vcn
.saved_bo
, ptr
, size
);
182 int amdgpu_vcn_resume(struct amdgpu_device
*adev
)
187 if (adev
->vcn
.vcpu_bo
== NULL
)
190 size
= amdgpu_bo_size(adev
->vcn
.vcpu_bo
);
191 ptr
= adev
->vcn
.cpu_addr
;
193 if (adev
->vcn
.saved_bo
!= NULL
) {
194 memcpy_toio(ptr
, adev
->vcn
.saved_bo
, size
);
195 kvfree(adev
->vcn
.saved_bo
);
196 adev
->vcn
.saved_bo
= NULL
;
198 const struct common_firmware_header
*hdr
;
201 hdr
= (const struct common_firmware_header
*)adev
->vcn
.fw
->data
;
202 if (adev
->firmware
.load_type
!= AMDGPU_FW_LOAD_PSP
) {
203 offset
= le32_to_cpu(hdr
->ucode_array_offset_bytes
);
204 memcpy_toio(adev
->vcn
.cpu_addr
, adev
->vcn
.fw
->data
+ offset
,
205 le32_to_cpu(hdr
->ucode_size_bytes
));
206 size
-= le32_to_cpu(hdr
->ucode_size_bytes
);
207 ptr
+= le32_to_cpu(hdr
->ucode_size_bytes
);
209 memset_io(ptr
, 0, size
);
215 static int amdgpu_vcn_pause_dpg_mode(struct amdgpu_device
*adev
,
216 struct dpg_pause_state
*new_state
)
219 uint32_t reg_data
= 0;
220 uint32_t reg_data2
= 0;
221 struct amdgpu_ring
*ring
;
223 /* pause/unpause if state is changed */
224 if (adev
->vcn
.pause_state
.fw_based
!= new_state
->fw_based
) {
225 DRM_DEBUG("dpg pause state changed %d:%d -> %d:%d",
226 adev
->vcn
.pause_state
.fw_based
, adev
->vcn
.pause_state
.jpeg
,
227 new_state
->fw_based
, new_state
->jpeg
);
229 reg_data
= RREG32_SOC15(UVD
, 0, mmUVD_DPG_PAUSE
) &
230 (~UVD_DPG_PAUSE__NJ_PAUSE_DPG_ACK_MASK
);
232 if (new_state
->fw_based
== VCN_DPG_STATE__PAUSE
) {
235 if (!(reg_data
& UVD_DPG_PAUSE__JPEG_PAUSE_DPG_ACK_MASK
))
236 SOC15_WAIT_ON_RREG(UVD
, 0, mmUVD_POWER_STATUS
,
237 UVD_POWER_STATUS__UVD_POWER_STATUS_TILES_OFF
,
238 UVD_POWER_STATUS__UVD_POWER_STATUS_MASK
, ret_code
);
241 /* pause DPG non-jpeg */
242 reg_data
|= UVD_DPG_PAUSE__NJ_PAUSE_DPG_REQ_MASK
;
243 WREG32_SOC15(UVD
, 0, mmUVD_DPG_PAUSE
, reg_data
);
244 SOC15_WAIT_ON_RREG(UVD
, 0, mmUVD_DPG_PAUSE
,
245 UVD_DPG_PAUSE__NJ_PAUSE_DPG_ACK_MASK
,
246 UVD_DPG_PAUSE__NJ_PAUSE_DPG_ACK_MASK
, ret_code
);
249 ring
= &adev
->vcn
.ring_enc
[0];
250 WREG32_SOC15(UVD
, 0, mmUVD_RB_BASE_LO
, ring
->gpu_addr
);
251 WREG32_SOC15(UVD
, 0, mmUVD_RB_BASE_HI
, upper_32_bits(ring
->gpu_addr
));
252 WREG32_SOC15(UVD
, 0, mmUVD_RB_SIZE
, ring
->ring_size
/ 4);
253 WREG32_SOC15(UVD
, 0, mmUVD_RB_RPTR
, lower_32_bits(ring
->wptr
));
254 WREG32_SOC15(UVD
, 0, mmUVD_RB_WPTR
, lower_32_bits(ring
->wptr
));
256 ring
= &adev
->vcn
.ring_enc
[1];
257 WREG32_SOC15(UVD
, 0, mmUVD_RB_BASE_LO2
, ring
->gpu_addr
);
258 WREG32_SOC15(UVD
, 0, mmUVD_RB_BASE_HI2
, upper_32_bits(ring
->gpu_addr
));
259 WREG32_SOC15(UVD
, 0, mmUVD_RB_SIZE2
, ring
->ring_size
/ 4);
260 WREG32_SOC15(UVD
, 0, mmUVD_RB_RPTR2
, lower_32_bits(ring
->wptr
));
261 WREG32_SOC15(UVD
, 0, mmUVD_RB_WPTR2
, lower_32_bits(ring
->wptr
));
263 ring
= &adev
->vcn
.ring_dec
;
264 WREG32_SOC15(UVD
, 0, mmUVD_RBC_RB_WPTR
,
265 RREG32_SOC15(UVD
, 0, mmUVD_SCRATCH2
) & 0x7FFFFFFF);
266 SOC15_WAIT_ON_RREG(UVD
, 0, mmUVD_POWER_STATUS
,
267 UVD_PGFSM_CONFIG__UVDM_UVDU_PWR_ON
,
268 UVD_POWER_STATUS__UVD_POWER_STATUS_MASK
, ret_code
);
271 /* unpause dpg non-jpeg, no need to wait */
272 reg_data
&= ~UVD_DPG_PAUSE__NJ_PAUSE_DPG_REQ_MASK
;
273 WREG32_SOC15(UVD
, 0, mmUVD_DPG_PAUSE
, reg_data
);
275 adev
->vcn
.pause_state
.fw_based
= new_state
->fw_based
;
278 /* pause/unpause if state is changed */
279 if (adev
->vcn
.pause_state
.jpeg
!= new_state
->jpeg
) {
280 DRM_DEBUG("dpg pause state changed %d:%d -> %d:%d",
281 adev
->vcn
.pause_state
.fw_based
, adev
->vcn
.pause_state
.jpeg
,
282 new_state
->fw_based
, new_state
->jpeg
);
284 reg_data
= RREG32_SOC15(UVD
, 0, mmUVD_DPG_PAUSE
) &
285 (~UVD_DPG_PAUSE__JPEG_PAUSE_DPG_ACK_MASK
);
287 if (new_state
->jpeg
== VCN_DPG_STATE__PAUSE
) {
290 if (!(reg_data
& UVD_DPG_PAUSE__NJ_PAUSE_DPG_ACK_MASK
))
291 SOC15_WAIT_ON_RREG(UVD
, 0, mmUVD_POWER_STATUS
,
292 UVD_POWER_STATUS__UVD_POWER_STATUS_TILES_OFF
,
293 UVD_POWER_STATUS__UVD_POWER_STATUS_MASK
, ret_code
);
296 /* Make sure JPRG Snoop is disabled before sending the pause */
297 reg_data2
= RREG32_SOC15(UVD
, 0, mmUVD_POWER_STATUS
);
298 reg_data2
|= UVD_POWER_STATUS__JRBC_SNOOP_DIS_MASK
;
299 WREG32_SOC15(UVD
, 0, mmUVD_POWER_STATUS
, reg_data2
);
302 reg_data
|= UVD_DPG_PAUSE__JPEG_PAUSE_DPG_REQ_MASK
;
303 WREG32_SOC15(UVD
, 0, mmUVD_DPG_PAUSE
, reg_data
);
304 SOC15_WAIT_ON_RREG(UVD
, 0, mmUVD_DPG_PAUSE
,
305 UVD_DPG_PAUSE__JPEG_PAUSE_DPG_ACK_MASK
,
306 UVD_DPG_PAUSE__JPEG_PAUSE_DPG_ACK_MASK
, ret_code
);
309 ring
= &adev
->vcn
.ring_jpeg
;
310 WREG32_SOC15(UVD
, 0, mmUVD_LMI_JRBC_RB_VMID
, 0);
311 WREG32_SOC15(UVD
, 0, mmUVD_JRBC_RB_CNTL
,
312 UVD_JRBC_RB_CNTL__RB_NO_FETCH_MASK
|
313 UVD_JRBC_RB_CNTL__RB_RPTR_WR_EN_MASK
);
314 WREG32_SOC15(UVD
, 0, mmUVD_LMI_JRBC_RB_64BIT_BAR_LOW
,
315 lower_32_bits(ring
->gpu_addr
));
316 WREG32_SOC15(UVD
, 0, mmUVD_LMI_JRBC_RB_64BIT_BAR_HIGH
,
317 upper_32_bits(ring
->gpu_addr
));
318 WREG32_SOC15(UVD
, 0, mmUVD_JRBC_RB_RPTR
, ring
->wptr
);
319 WREG32_SOC15(UVD
, 0, mmUVD_JRBC_RB_WPTR
, ring
->wptr
);
320 WREG32_SOC15(UVD
, 0, mmUVD_JRBC_RB_CNTL
,
321 UVD_JRBC_RB_CNTL__RB_RPTR_WR_EN_MASK
);
323 ring
= &adev
->vcn
.ring_dec
;
324 WREG32_SOC15(UVD
, 0, mmUVD_RBC_RB_WPTR
,
325 RREG32_SOC15(UVD
, 0, mmUVD_SCRATCH2
) & 0x7FFFFFFF);
326 SOC15_WAIT_ON_RREG(UVD
, 0, mmUVD_POWER_STATUS
,
327 UVD_PGFSM_CONFIG__UVDM_UVDU_PWR_ON
,
328 UVD_POWER_STATUS__UVD_POWER_STATUS_MASK
, ret_code
);
331 /* unpause dpg jpeg, no need to wait */
332 reg_data
&= ~UVD_DPG_PAUSE__JPEG_PAUSE_DPG_REQ_MASK
;
333 WREG32_SOC15(UVD
, 0, mmUVD_DPG_PAUSE
, reg_data
);
335 adev
->vcn
.pause_state
.jpeg
= new_state
->jpeg
;
341 static void amdgpu_vcn_idle_work_handler(struct work_struct
*work
)
343 struct amdgpu_device
*adev
=
344 container_of(work
, struct amdgpu_device
, vcn
.idle_work
.work
);
345 unsigned int fences
= 0;
348 for (i
= 0; i
< adev
->vcn
.num_enc_rings
; ++i
) {
349 fences
+= amdgpu_fence_count_emitted(&adev
->vcn
.ring_enc
[i
]);
352 if (adev
->pg_flags
& AMD_PG_SUPPORT_VCN_DPG
) {
353 struct dpg_pause_state new_state
;
356 new_state
.fw_based
= VCN_DPG_STATE__PAUSE
;
358 new_state
.fw_based
= VCN_DPG_STATE__UNPAUSE
;
360 if (amdgpu_fence_count_emitted(&adev
->vcn
.ring_jpeg
))
361 new_state
.jpeg
= VCN_DPG_STATE__PAUSE
;
363 new_state
.jpeg
= VCN_DPG_STATE__UNPAUSE
;
365 amdgpu_vcn_pause_dpg_mode(adev
, &new_state
);
368 fences
+= amdgpu_fence_count_emitted(&adev
->vcn
.ring_jpeg
);
369 fences
+= amdgpu_fence_count_emitted(&adev
->vcn
.ring_dec
);
372 amdgpu_gfx_off_ctrl(adev
, true);
373 if (adev
->pm
.dpm_enabled
)
374 amdgpu_dpm_enable_uvd(adev
, false);
376 amdgpu_device_ip_set_powergating_state(adev
, AMD_IP_BLOCK_TYPE_VCN
,
379 schedule_delayed_work(&adev
->vcn
.idle_work
, VCN_IDLE_TIMEOUT
);
383 void amdgpu_vcn_ring_begin_use(struct amdgpu_ring
*ring
)
385 struct amdgpu_device
*adev
= ring
->adev
;
386 bool set_clocks
= !cancel_delayed_work_sync(&adev
->vcn
.idle_work
);
389 amdgpu_gfx_off_ctrl(adev
, false);
390 if (adev
->pm
.dpm_enabled
)
391 amdgpu_dpm_enable_uvd(adev
, true);
393 amdgpu_device_ip_set_powergating_state(adev
, AMD_IP_BLOCK_TYPE_VCN
,
394 AMD_PG_STATE_UNGATE
);
397 if (adev
->pg_flags
& AMD_PG_SUPPORT_VCN_DPG
) {
398 struct dpg_pause_state new_state
;
399 unsigned int fences
= 0;
402 for (i
= 0; i
< adev
->vcn
.num_enc_rings
; ++i
) {
403 fences
+= amdgpu_fence_count_emitted(&adev
->vcn
.ring_enc
[i
]);
406 new_state
.fw_based
= VCN_DPG_STATE__PAUSE
;
408 new_state
.fw_based
= VCN_DPG_STATE__UNPAUSE
;
410 if (amdgpu_fence_count_emitted(&adev
->vcn
.ring_jpeg
))
411 new_state
.jpeg
= VCN_DPG_STATE__PAUSE
;
413 new_state
.jpeg
= VCN_DPG_STATE__UNPAUSE
;
415 if (ring
->funcs
->type
== AMDGPU_RING_TYPE_VCN_ENC
)
416 new_state
.fw_based
= VCN_DPG_STATE__PAUSE
;
417 else if (ring
->funcs
->type
== AMDGPU_RING_TYPE_VCN_JPEG
)
418 new_state
.jpeg
= VCN_DPG_STATE__PAUSE
;
420 amdgpu_vcn_pause_dpg_mode(adev
, &new_state
);
424 void amdgpu_vcn_ring_end_use(struct amdgpu_ring
*ring
)
426 schedule_delayed_work(&ring
->adev
->vcn
.idle_work
, VCN_IDLE_TIMEOUT
);
429 int amdgpu_vcn_dec_ring_test_ring(struct amdgpu_ring
*ring
)
431 struct amdgpu_device
*adev
= ring
->adev
;
436 WREG32(SOC15_REG_OFFSET(UVD
, 0, mmUVD_SCRATCH9
), 0xCAFEDEAD);
437 r
= amdgpu_ring_alloc(ring
, 3);
441 amdgpu_ring_write(ring
,
442 PACKET0(SOC15_REG_OFFSET(UVD
, 0, mmUVD_SCRATCH9
), 0));
443 amdgpu_ring_write(ring
, 0xDEADBEEF);
444 amdgpu_ring_commit(ring
);
445 for (i
= 0; i
< adev
->usec_timeout
; i
++) {
446 tmp
= RREG32(SOC15_REG_OFFSET(UVD
, 0, mmUVD_SCRATCH9
));
447 if (tmp
== 0xDEADBEEF)
452 if (i
>= adev
->usec_timeout
)
458 static int amdgpu_vcn_dec_send_msg(struct amdgpu_ring
*ring
,
459 struct amdgpu_bo
*bo
,
460 struct dma_fence
**fence
)
462 struct amdgpu_device
*adev
= ring
->adev
;
463 struct dma_fence
*f
= NULL
;
464 struct amdgpu_job
*job
;
465 struct amdgpu_ib
*ib
;
469 r
= amdgpu_job_alloc_with_ib(adev
, 64, &job
);
474 addr
= amdgpu_bo_gpu_offset(bo
);
475 ib
->ptr
[0] = PACKET0(SOC15_REG_OFFSET(UVD
, 0, mmUVD_GPCOM_VCPU_DATA0
), 0);
477 ib
->ptr
[2] = PACKET0(SOC15_REG_OFFSET(UVD
, 0, mmUVD_GPCOM_VCPU_DATA1
), 0);
478 ib
->ptr
[3] = addr
>> 32;
479 ib
->ptr
[4] = PACKET0(SOC15_REG_OFFSET(UVD
, 0, mmUVD_GPCOM_VCPU_CMD
), 0);
481 for (i
= 6; i
< 16; i
+= 2) {
482 ib
->ptr
[i
] = PACKET0(SOC15_REG_OFFSET(UVD
, 0, mmUVD_NO_OP
), 0);
487 r
= amdgpu_job_submit_direct(job
, ring
, &f
);
491 amdgpu_bo_fence(bo
, f
, false);
492 amdgpu_bo_unreserve(bo
);
493 amdgpu_bo_unref(&bo
);
496 *fence
= dma_fence_get(f
);
502 amdgpu_job_free(job
);
505 amdgpu_bo_unreserve(bo
);
506 amdgpu_bo_unref(&bo
);
510 static int amdgpu_vcn_dec_get_create_msg(struct amdgpu_ring
*ring
, uint32_t handle
,
511 struct dma_fence
**fence
)
513 struct amdgpu_device
*adev
= ring
->adev
;
514 struct amdgpu_bo
*bo
= NULL
;
518 r
= amdgpu_bo_create_reserved(adev
, 1024, PAGE_SIZE
,
519 AMDGPU_GEM_DOMAIN_VRAM
,
520 &bo
, NULL
, (void **)&msg
);
524 msg
[0] = cpu_to_le32(0x00000028);
525 msg
[1] = cpu_to_le32(0x00000038);
526 msg
[2] = cpu_to_le32(0x00000001);
527 msg
[3] = cpu_to_le32(0x00000000);
528 msg
[4] = cpu_to_le32(handle
);
529 msg
[5] = cpu_to_le32(0x00000000);
530 msg
[6] = cpu_to_le32(0x00000001);
531 msg
[7] = cpu_to_le32(0x00000028);
532 msg
[8] = cpu_to_le32(0x00000010);
533 msg
[9] = cpu_to_le32(0x00000000);
534 msg
[10] = cpu_to_le32(0x00000007);
535 msg
[11] = cpu_to_le32(0x00000000);
536 msg
[12] = cpu_to_le32(0x00000780);
537 msg
[13] = cpu_to_le32(0x00000440);
538 for (i
= 14; i
< 1024; ++i
)
539 msg
[i
] = cpu_to_le32(0x0);
541 return amdgpu_vcn_dec_send_msg(ring
, bo
, fence
);
544 static int amdgpu_vcn_dec_get_destroy_msg(struct amdgpu_ring
*ring
, uint32_t handle
,
545 struct dma_fence
**fence
)
547 struct amdgpu_device
*adev
= ring
->adev
;
548 struct amdgpu_bo
*bo
= NULL
;
552 r
= amdgpu_bo_create_reserved(adev
, 1024, PAGE_SIZE
,
553 AMDGPU_GEM_DOMAIN_VRAM
,
554 &bo
, NULL
, (void **)&msg
);
558 msg
[0] = cpu_to_le32(0x00000028);
559 msg
[1] = cpu_to_le32(0x00000018);
560 msg
[2] = cpu_to_le32(0x00000000);
561 msg
[3] = cpu_to_le32(0x00000002);
562 msg
[4] = cpu_to_le32(handle
);
563 msg
[5] = cpu_to_le32(0x00000000);
564 for (i
= 6; i
< 1024; ++i
)
565 msg
[i
] = cpu_to_le32(0x0);
567 return amdgpu_vcn_dec_send_msg(ring
, bo
, fence
);
570 int amdgpu_vcn_dec_ring_test_ib(struct amdgpu_ring
*ring
, long timeout
)
572 struct dma_fence
*fence
;
575 r
= amdgpu_vcn_dec_get_create_msg(ring
, 1, NULL
);
579 r
= amdgpu_vcn_dec_get_destroy_msg(ring
, 1, &fence
);
583 r
= dma_fence_wait_timeout(fence
, false, timeout
);
589 dma_fence_put(fence
);
594 int amdgpu_vcn_enc_ring_test_ring(struct amdgpu_ring
*ring
)
596 struct amdgpu_device
*adev
= ring
->adev
;
597 uint32_t rptr
= amdgpu_ring_get_rptr(ring
);
601 r
= amdgpu_ring_alloc(ring
, 16);
605 amdgpu_ring_write(ring
, VCN_ENC_CMD_END
);
606 amdgpu_ring_commit(ring
);
608 for (i
= 0; i
< adev
->usec_timeout
; i
++) {
609 if (amdgpu_ring_get_rptr(ring
) != rptr
)
614 if (i
>= adev
->usec_timeout
)
620 static int amdgpu_vcn_enc_get_create_msg(struct amdgpu_ring
*ring
, uint32_t handle
,
621 struct dma_fence
**fence
)
623 const unsigned ib_size_dw
= 16;
624 struct amdgpu_job
*job
;
625 struct amdgpu_ib
*ib
;
626 struct dma_fence
*f
= NULL
;
630 r
= amdgpu_job_alloc_with_ib(ring
->adev
, ib_size_dw
* 4, &job
);
635 dummy
= ib
->gpu_addr
+ 1024;
638 ib
->ptr
[ib
->length_dw
++] = 0x00000018;
639 ib
->ptr
[ib
->length_dw
++] = 0x00000001; /* session info */
640 ib
->ptr
[ib
->length_dw
++] = handle
;
641 ib
->ptr
[ib
->length_dw
++] = upper_32_bits(dummy
);
642 ib
->ptr
[ib
->length_dw
++] = dummy
;
643 ib
->ptr
[ib
->length_dw
++] = 0x0000000b;
645 ib
->ptr
[ib
->length_dw
++] = 0x00000014;
646 ib
->ptr
[ib
->length_dw
++] = 0x00000002; /* task info */
647 ib
->ptr
[ib
->length_dw
++] = 0x0000001c;
648 ib
->ptr
[ib
->length_dw
++] = 0x00000000;
649 ib
->ptr
[ib
->length_dw
++] = 0x00000000;
651 ib
->ptr
[ib
->length_dw
++] = 0x00000008;
652 ib
->ptr
[ib
->length_dw
++] = 0x08000001; /* op initialize */
654 for (i
= ib
->length_dw
; i
< ib_size_dw
; ++i
)
657 r
= amdgpu_job_submit_direct(job
, ring
, &f
);
662 *fence
= dma_fence_get(f
);
668 amdgpu_job_free(job
);
672 static int amdgpu_vcn_enc_get_destroy_msg(struct amdgpu_ring
*ring
, uint32_t handle
,
673 struct dma_fence
**fence
)
675 const unsigned ib_size_dw
= 16;
676 struct amdgpu_job
*job
;
677 struct amdgpu_ib
*ib
;
678 struct dma_fence
*f
= NULL
;
682 r
= amdgpu_job_alloc_with_ib(ring
->adev
, ib_size_dw
* 4, &job
);
687 dummy
= ib
->gpu_addr
+ 1024;
690 ib
->ptr
[ib
->length_dw
++] = 0x00000018;
691 ib
->ptr
[ib
->length_dw
++] = 0x00000001;
692 ib
->ptr
[ib
->length_dw
++] = handle
;
693 ib
->ptr
[ib
->length_dw
++] = upper_32_bits(dummy
);
694 ib
->ptr
[ib
->length_dw
++] = dummy
;
695 ib
->ptr
[ib
->length_dw
++] = 0x0000000b;
697 ib
->ptr
[ib
->length_dw
++] = 0x00000014;
698 ib
->ptr
[ib
->length_dw
++] = 0x00000002;
699 ib
->ptr
[ib
->length_dw
++] = 0x0000001c;
700 ib
->ptr
[ib
->length_dw
++] = 0x00000000;
701 ib
->ptr
[ib
->length_dw
++] = 0x00000000;
703 ib
->ptr
[ib
->length_dw
++] = 0x00000008;
704 ib
->ptr
[ib
->length_dw
++] = 0x08000002; /* op close session */
706 for (i
= ib
->length_dw
; i
< ib_size_dw
; ++i
)
709 r
= amdgpu_job_submit_direct(job
, ring
, &f
);
714 *fence
= dma_fence_get(f
);
720 amdgpu_job_free(job
);
724 int amdgpu_vcn_enc_ring_test_ib(struct amdgpu_ring
*ring
, long timeout
)
726 struct dma_fence
*fence
= NULL
;
729 r
= amdgpu_vcn_enc_get_create_msg(ring
, 1, NULL
);
733 r
= amdgpu_vcn_enc_get_destroy_msg(ring
, 1, &fence
);
737 r
= dma_fence_wait_timeout(fence
, false, timeout
);
744 dma_fence_put(fence
);
748 int amdgpu_vcn_jpeg_ring_test_ring(struct amdgpu_ring
*ring
)
750 struct amdgpu_device
*adev
= ring
->adev
;
755 WREG32(SOC15_REG_OFFSET(UVD
, 0, mmUVD_SCRATCH9
), 0xCAFEDEAD);
756 r
= amdgpu_ring_alloc(ring
, 3);
761 amdgpu_ring_write(ring
,
762 PACKETJ(SOC15_REG_OFFSET(UVD
, 0, mmUVD_SCRATCH9
), 0, 0, 0));
763 amdgpu_ring_write(ring
, 0xDEADBEEF);
764 amdgpu_ring_commit(ring
);
766 for (i
= 0; i
< adev
->usec_timeout
; i
++) {
767 tmp
= RREG32(SOC15_REG_OFFSET(UVD
, 0, mmUVD_SCRATCH9
));
768 if (tmp
== 0xDEADBEEF)
773 if (i
>= adev
->usec_timeout
)
779 static int amdgpu_vcn_jpeg_set_reg(struct amdgpu_ring
*ring
, uint32_t handle
,
780 struct dma_fence
**fence
)
782 struct amdgpu_device
*adev
= ring
->adev
;
783 struct amdgpu_job
*job
;
784 struct amdgpu_ib
*ib
;
785 struct dma_fence
*f
= NULL
;
786 const unsigned ib_size_dw
= 16;
789 r
= amdgpu_job_alloc_with_ib(ring
->adev
, ib_size_dw
* 4, &job
);
795 ib
->ptr
[0] = PACKETJ(SOC15_REG_OFFSET(UVD
, 0, mmUVD_SCRATCH9
), 0, 0, PACKETJ_TYPE0
);
796 ib
->ptr
[1] = 0xDEADBEEF;
797 for (i
= 2; i
< 16; i
+= 2) {
798 ib
->ptr
[i
] = PACKETJ(0, 0, 0, PACKETJ_TYPE6
);
803 r
= amdgpu_job_submit_direct(job
, ring
, &f
);
808 *fence
= dma_fence_get(f
);
814 amdgpu_job_free(job
);
818 int amdgpu_vcn_jpeg_ring_test_ib(struct amdgpu_ring
*ring
, long timeout
)
820 struct amdgpu_device
*adev
= ring
->adev
;
823 struct dma_fence
*fence
= NULL
;
826 r
= amdgpu_vcn_jpeg_set_reg(ring
, 1, &fence
);
830 r
= dma_fence_wait_timeout(fence
, false, timeout
);
840 for (i
= 0; i
< adev
->usec_timeout
; i
++) {
841 tmp
= RREG32(SOC15_REG_OFFSET(UVD
, 0, mmUVD_SCRATCH9
));
842 if (tmp
== 0xDEADBEEF)
847 if (i
>= adev
->usec_timeout
)
850 dma_fence_put(fence
);