vce_tests.c revision 037b3c26
13f012e29Smrg/* 23f012e29Smrg * Copyright 2015 Advanced Micro Devices, Inc. 33f012e29Smrg * 43f012e29Smrg * Permission is hereby granted, free of charge, to any person obtaining a 53f012e29Smrg * copy of this software and associated documentation files (the "Software"), 63f012e29Smrg * to deal in the Software without restriction, including without limitation 73f012e29Smrg * the rights to use, copy, modify, merge, publish, distribute, sublicense, 83f012e29Smrg * and/or sell copies of the Software, and to permit persons to whom the 93f012e29Smrg * Software is furnished to do so, subject to the following conditions: 103f012e29Smrg * 113f012e29Smrg * The above copyright notice and this permission notice shall be included in 123f012e29Smrg * all copies or substantial portions of the Software. 133f012e29Smrg * 143f012e29Smrg * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 153f012e29Smrg * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 163f012e29Smrg * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 173f012e29Smrg * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR 183f012e29Smrg * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 193f012e29Smrg * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 203f012e29Smrg * OTHER DEALINGS IN THE SOFTWARE. 213f012e29Smrg * 223f012e29Smrg*/ 233f012e29Smrg 243f012e29Smrg#ifdef HAVE_CONFIG_H 253f012e29Smrg#include "config.h" 263f012e29Smrg#endif 273f012e29Smrg 283f012e29Smrg#include <stdio.h> 293f012e29Smrg#include <inttypes.h> 303f012e29Smrg 313f012e29Smrg#include "CUnit/Basic.h" 323f012e29Smrg 333f012e29Smrg#include "util_math.h" 343f012e29Smrg 353f012e29Smrg#include "amdgpu_test.h" 363f012e29Smrg#include "amdgpu_drm.h" 373f012e29Smrg#include "amdgpu_internal.h" 383f012e29Smrg 393f012e29Smrg#include "vce_ib.h" 403f012e29Smrg#include "frame.h" 413f012e29Smrg 423f012e29Smrg#define IB_SIZE 4096 433f012e29Smrg#define MAX_RESOURCES 16 443f012e29Smrg 453f012e29Smrgstruct amdgpu_vce_bo { 463f012e29Smrg amdgpu_bo_handle handle; 473f012e29Smrg amdgpu_va_handle va_handle; 483f012e29Smrg uint64_t addr; 493f012e29Smrg uint64_t size; 503f012e29Smrg uint8_t *ptr; 513f012e29Smrg}; 523f012e29Smrg 533f012e29Smrgstruct amdgpu_vce_encode { 543f012e29Smrg unsigned width; 553f012e29Smrg unsigned height; 563f012e29Smrg struct amdgpu_vce_bo vbuf; 573f012e29Smrg struct amdgpu_vce_bo bs[2]; 583f012e29Smrg struct amdgpu_vce_bo fb[2]; 593f012e29Smrg struct amdgpu_vce_bo cpb; 603f012e29Smrg unsigned ib_len; 613f012e29Smrg bool two_instance; 623f012e29Smrg}; 633f012e29Smrg 643f012e29Smrgstatic amdgpu_device_handle device_handle; 653f012e29Smrgstatic uint32_t major_version; 663f012e29Smrgstatic uint32_t minor_version; 673f012e29Smrgstatic uint32_t family_id; 683f012e29Smrgstatic uint32_t vce_harvest_config; 693f012e29Smrg 703f012e29Smrgstatic amdgpu_context_handle context_handle; 713f012e29Smrgstatic amdgpu_bo_handle ib_handle; 723f012e29Smrgstatic amdgpu_va_handle ib_va_handle; 733f012e29Smrgstatic uint64_t ib_mc_address; 743f012e29Smrgstatic uint32_t *ib_cpu; 753f012e29Smrg 763f012e29Smrgstatic struct amdgpu_vce_encode enc; 773f012e29Smrgstatic amdgpu_bo_handle resources[MAX_RESOURCES]; 783f012e29Smrgstatic unsigned num_resources; 793f012e29Smrg 803f012e29Smrgstatic void amdgpu_cs_vce_create(void); 813f012e29Smrgstatic void amdgpu_cs_vce_encode(void); 823f012e29Smrgstatic void amdgpu_cs_vce_destroy(void); 833f012e29Smrg 843f012e29SmrgCU_TestInfo vce_tests[] = { 853f012e29Smrg { "VCE create", amdgpu_cs_vce_create }, 863f012e29Smrg { "VCE encode", amdgpu_cs_vce_encode }, 873f012e29Smrg { "VCE destroy", amdgpu_cs_vce_destroy }, 883f012e29Smrg CU_TEST_INFO_NULL, 893f012e29Smrg}; 903f012e29Smrg 913f012e29Smrgint suite_vce_tests_init(void) 923f012e29Smrg{ 933f012e29Smrg int r; 943f012e29Smrg 953f012e29Smrg r = amdgpu_device_initialize(drm_amdgpu[0], &major_version, 963f012e29Smrg &minor_version, &device_handle); 97037b3c26Smrg if (r) { 98037b3c26Smrg if ((r == -EACCES) && (errno == EACCES)) 99037b3c26Smrg printf("\n\nError:%s. " 100037b3c26Smrg "Hint:Try to run this test program as root.", 101037b3c26Smrg strerror(errno)); 102037b3c26Smrg 1033f012e29Smrg return CUE_SINIT_FAILED; 104037b3c26Smrg } 1053f012e29Smrg 1063f012e29Smrg family_id = device_handle->info.family_id; 1073f012e29Smrg vce_harvest_config = device_handle->info.vce_harvest_config; 1083f012e29Smrg 1093f012e29Smrg r = amdgpu_cs_ctx_create(device_handle, &context_handle); 1103f012e29Smrg if (r) 1113f012e29Smrg return CUE_SINIT_FAILED; 1123f012e29Smrg 1133f012e29Smrg r = amdgpu_bo_alloc_and_map(device_handle, IB_SIZE, 4096, 1143f012e29Smrg AMDGPU_GEM_DOMAIN_GTT, 0, 1153f012e29Smrg &ib_handle, (void**)&ib_cpu, 1163f012e29Smrg &ib_mc_address, &ib_va_handle); 1173f012e29Smrg if (r) 1183f012e29Smrg return CUE_SINIT_FAILED; 1193f012e29Smrg 1203f012e29Smrg memset(&enc, 0, sizeof(struct amdgpu_vce_encode)); 1213f012e29Smrg 1223f012e29Smrg return CUE_SUCCESS; 1233f012e29Smrg} 1243f012e29Smrg 1253f012e29Smrgint suite_vce_tests_clean(void) 1263f012e29Smrg{ 1273f012e29Smrg int r; 1283f012e29Smrg 1293f012e29Smrg r = amdgpu_bo_unmap_and_free(ib_handle, ib_va_handle, 1303f012e29Smrg ib_mc_address, IB_SIZE); 1313f012e29Smrg if (r) 1323f012e29Smrg return CUE_SCLEAN_FAILED; 1333f012e29Smrg 1343f012e29Smrg r = amdgpu_cs_ctx_free(context_handle); 1353f012e29Smrg if (r) 1363f012e29Smrg return CUE_SCLEAN_FAILED; 1373f012e29Smrg 1383f012e29Smrg r = amdgpu_device_deinitialize(device_handle); 1393f012e29Smrg if (r) 1403f012e29Smrg return CUE_SCLEAN_FAILED; 1413f012e29Smrg 1423f012e29Smrg return CUE_SUCCESS; 1433f012e29Smrg} 1443f012e29Smrg 1453f012e29Smrgstatic int submit(unsigned ndw, unsigned ip) 1463f012e29Smrg{ 1473f012e29Smrg struct amdgpu_cs_request ibs_request = {0}; 1483f012e29Smrg struct amdgpu_cs_ib_info ib_info = {0}; 1493f012e29Smrg struct amdgpu_cs_fence fence_status = {0}; 1503f012e29Smrg uint32_t expired; 1513f012e29Smrg int r; 1523f012e29Smrg 1533f012e29Smrg ib_info.ib_mc_address = ib_mc_address; 1543f012e29Smrg ib_info.size = ndw; 1553f012e29Smrg 1563f012e29Smrg ibs_request.ip_type = ip; 1573f012e29Smrg 1583f012e29Smrg r = amdgpu_bo_list_create(device_handle, num_resources, resources, 1593f012e29Smrg NULL, &ibs_request.resources); 1603f012e29Smrg if (r) 1613f012e29Smrg return r; 1623f012e29Smrg 1633f012e29Smrg ibs_request.number_of_ibs = 1; 1643f012e29Smrg ibs_request.ibs = &ib_info; 1653f012e29Smrg ibs_request.fence_info.handle = NULL; 1663f012e29Smrg 1673f012e29Smrg r = amdgpu_cs_submit(context_handle, 0, &ibs_request, 1); 1683f012e29Smrg if (r) 1693f012e29Smrg return r; 1703f012e29Smrg 1713f012e29Smrg r = amdgpu_bo_list_destroy(ibs_request.resources); 1723f012e29Smrg if (r) 1733f012e29Smrg return r; 1743f012e29Smrg 1753f012e29Smrg fence_status.context = context_handle; 1763f012e29Smrg fence_status.ip_type = ip; 1773f012e29Smrg fence_status.fence = ibs_request.seq_no; 1783f012e29Smrg 1793f012e29Smrg r = amdgpu_cs_query_fence_status(&fence_status, 1803f012e29Smrg AMDGPU_TIMEOUT_INFINITE, 1813f012e29Smrg 0, &expired); 1823f012e29Smrg if (r) 1833f012e29Smrg return r; 1843f012e29Smrg 1853f012e29Smrg return 0; 1863f012e29Smrg} 1873f012e29Smrg 1883f012e29Smrgstatic void alloc_resource(struct amdgpu_vce_bo *vce_bo, unsigned size, unsigned domain) 1893f012e29Smrg{ 1903f012e29Smrg struct amdgpu_bo_alloc_request req = {0}; 1913f012e29Smrg amdgpu_bo_handle buf_handle; 1923f012e29Smrg amdgpu_va_handle va_handle; 1933f012e29Smrg uint64_t va = 0; 1943f012e29Smrg int r; 1953f012e29Smrg 1963f012e29Smrg req.alloc_size = ALIGN(size, 4096); 1973f012e29Smrg req.preferred_heap = domain; 1983f012e29Smrg r = amdgpu_bo_alloc(device_handle, &req, &buf_handle); 1993f012e29Smrg CU_ASSERT_EQUAL(r, 0); 2003f012e29Smrg r = amdgpu_va_range_alloc(device_handle, 2013f012e29Smrg amdgpu_gpu_va_range_general, 2023f012e29Smrg req.alloc_size, 1, 0, &va, 2033f012e29Smrg &va_handle, 0); 2043f012e29Smrg CU_ASSERT_EQUAL(r, 0); 2053f012e29Smrg r = amdgpu_bo_va_op(buf_handle, 0, req.alloc_size, va, 0, 2063f012e29Smrg AMDGPU_VA_OP_MAP); 2073f012e29Smrg CU_ASSERT_EQUAL(r, 0); 2083f012e29Smrg vce_bo->addr = va; 2093f012e29Smrg vce_bo->handle = buf_handle; 2103f012e29Smrg vce_bo->size = req.alloc_size; 2113f012e29Smrg vce_bo->va_handle = va_handle; 2123f012e29Smrg r = amdgpu_bo_cpu_map(vce_bo->handle, (void **)&vce_bo->ptr); 2133f012e29Smrg CU_ASSERT_EQUAL(r, 0); 2143f012e29Smrg memset(vce_bo->ptr, 0, size); 2153f012e29Smrg r = amdgpu_bo_cpu_unmap(vce_bo->handle); 2163f012e29Smrg CU_ASSERT_EQUAL(r, 0); 2173f012e29Smrg} 2183f012e29Smrg 2193f012e29Smrgstatic void free_resource(struct amdgpu_vce_bo *vce_bo) 2203f012e29Smrg{ 2213f012e29Smrg int r; 2223f012e29Smrg 2233f012e29Smrg r = amdgpu_bo_va_op(vce_bo->handle, 0, vce_bo->size, 2243f012e29Smrg vce_bo->addr, 0, AMDGPU_VA_OP_UNMAP); 2253f012e29Smrg CU_ASSERT_EQUAL(r, 0); 2263f012e29Smrg 2273f012e29Smrg r = amdgpu_va_range_free(vce_bo->va_handle); 2283f012e29Smrg CU_ASSERT_EQUAL(r, 0); 2293f012e29Smrg 2303f012e29Smrg r = amdgpu_bo_free(vce_bo->handle); 2313f012e29Smrg CU_ASSERT_EQUAL(r, 0); 2323f012e29Smrg memset(vce_bo, 0, sizeof(*vce_bo)); 2333f012e29Smrg} 2343f012e29Smrg 2353f012e29Smrgstatic void amdgpu_cs_vce_create(void) 2363f012e29Smrg{ 2373f012e29Smrg int len, r; 2383f012e29Smrg 2393f012e29Smrg enc.width = vce_create[6]; 2403f012e29Smrg enc.height = vce_create[7]; 2413f012e29Smrg 2423f012e29Smrg num_resources = 0; 2433f012e29Smrg alloc_resource(&enc.fb[0], 4096, AMDGPU_GEM_DOMAIN_GTT); 2443f012e29Smrg resources[num_resources++] = enc.fb[0].handle; 2453f012e29Smrg resources[num_resources++] = ib_handle; 2463f012e29Smrg 2473f012e29Smrg len = 0; 2483f012e29Smrg memcpy(ib_cpu, vce_session, sizeof(vce_session)); 2493f012e29Smrg len += sizeof(vce_session) / 4; 2503f012e29Smrg memcpy((ib_cpu + len), vce_taskinfo, sizeof(vce_taskinfo)); 2513f012e29Smrg len += sizeof(vce_taskinfo) / 4; 2523f012e29Smrg memcpy((ib_cpu + len), vce_create, sizeof(vce_create)); 2533f012e29Smrg len += sizeof(vce_create) / 4; 2543f012e29Smrg memcpy((ib_cpu + len), vce_feedback, sizeof(vce_feedback)); 2553f012e29Smrg ib_cpu[len + 2] = enc.fb[0].addr >> 32; 2563f012e29Smrg ib_cpu[len + 3] = enc.fb[0].addr; 2573f012e29Smrg len += sizeof(vce_feedback) / 4; 2583f012e29Smrg 2593f012e29Smrg r = submit(len, AMDGPU_HW_IP_VCE); 2603f012e29Smrg CU_ASSERT_EQUAL(r, 0); 2613f012e29Smrg 2623f012e29Smrg free_resource(&enc.fb[0]); 2633f012e29Smrg} 2643f012e29Smrg 2653f012e29Smrgstatic void amdgpu_cs_vce_config(void) 2663f012e29Smrg{ 2673f012e29Smrg int len = 0, r; 2683f012e29Smrg 2693f012e29Smrg memcpy((ib_cpu + len), vce_session, sizeof(vce_session)); 2703f012e29Smrg len += sizeof(vce_session) / 4; 2713f012e29Smrg memcpy((ib_cpu + len), vce_taskinfo, sizeof(vce_taskinfo)); 2723f012e29Smrg ib_cpu[len + 3] = 2; 2733f012e29Smrg ib_cpu[len + 6] = 0xffffffff; 2743f012e29Smrg len += sizeof(vce_taskinfo) / 4; 2753f012e29Smrg memcpy((ib_cpu + len), vce_rate_ctrl, sizeof(vce_rate_ctrl)); 2763f012e29Smrg len += sizeof(vce_rate_ctrl) / 4; 2773f012e29Smrg memcpy((ib_cpu + len), vce_config_ext, sizeof(vce_config_ext)); 2783f012e29Smrg len += sizeof(vce_config_ext) / 4; 2793f012e29Smrg memcpy((ib_cpu + len), vce_motion_est, sizeof(vce_motion_est)); 2803f012e29Smrg len += sizeof(vce_motion_est) / 4; 2813f012e29Smrg memcpy((ib_cpu + len), vce_rdo, sizeof(vce_rdo)); 2823f012e29Smrg len += sizeof(vce_rdo) / 4; 2833f012e29Smrg memcpy((ib_cpu + len), vce_pic_ctrl, sizeof(vce_pic_ctrl)); 2843f012e29Smrg len += sizeof(vce_pic_ctrl) / 4; 2853f012e29Smrg 2863f012e29Smrg r = submit(len, AMDGPU_HW_IP_VCE); 2873f012e29Smrg CU_ASSERT_EQUAL(r, 0); 2883f012e29Smrg} 2893f012e29Smrg 2903f012e29Smrgstatic void amdgpu_cs_vce_encode_idr(struct amdgpu_vce_encode *enc) 2913f012e29Smrg{ 2923f012e29Smrg 2933f012e29Smrg uint64_t luma_offset, chroma_offset; 2943f012e29Smrg int len = 0, r; 2953f012e29Smrg 2963f012e29Smrg luma_offset = enc->vbuf.addr; 2973f012e29Smrg chroma_offset = luma_offset + enc->width * enc->height; 2983f012e29Smrg 2993f012e29Smrg memcpy((ib_cpu + len), vce_session, sizeof(vce_session)); 3003f012e29Smrg len += sizeof(vce_session) / 4; 3013f012e29Smrg memcpy((ib_cpu + len), vce_taskinfo, sizeof(vce_taskinfo)); 3023f012e29Smrg len += sizeof(vce_taskinfo) / 4; 3033f012e29Smrg memcpy((ib_cpu + len), vce_bs_buffer, sizeof(vce_bs_buffer)); 3043f012e29Smrg ib_cpu[len + 2] = enc->bs[0].addr >> 32; 3053f012e29Smrg ib_cpu[len + 3] = enc->bs[0].addr; 3063f012e29Smrg len += sizeof(vce_bs_buffer) / 4; 3073f012e29Smrg memcpy((ib_cpu + len), vce_context_buffer, sizeof(vce_context_buffer)); 3083f012e29Smrg ib_cpu[len + 2] = enc->cpb.addr >> 32; 3093f012e29Smrg ib_cpu[len + 3] = enc->cpb.addr; 3103f012e29Smrg len += sizeof(vce_context_buffer) / 4; 3113f012e29Smrg memcpy((ib_cpu + len), vce_aux_buffer, sizeof(vce_aux_buffer)); 3123f012e29Smrg len += sizeof(vce_aux_buffer) / 4; 3133f012e29Smrg memcpy((ib_cpu + len), vce_feedback, sizeof(vce_feedback)); 3143f012e29Smrg ib_cpu[len + 2] = enc->fb[0].addr >> 32; 3153f012e29Smrg ib_cpu[len + 3] = enc->fb[0].addr; 3163f012e29Smrg len += sizeof(vce_feedback) / 4; 3173f012e29Smrg memcpy((ib_cpu + len), vce_encode, sizeof(vce_encode)); 3183f012e29Smrg ib_cpu[len + 9] = luma_offset >> 32; 3193f012e29Smrg ib_cpu[len + 10] = luma_offset; 3203f012e29Smrg ib_cpu[len + 11] = chroma_offset >> 32; 3213f012e29Smrg ib_cpu[len + 12] = chroma_offset; 3223f012e29Smrg ib_cpu[len + 73] = 0x7800; 3233f012e29Smrg ib_cpu[len + 74] = 0x7800 + 0x5000; 3243f012e29Smrg len += sizeof(vce_encode) / 4; 3253f012e29Smrg enc->ib_len = len; 3263f012e29Smrg if (!enc->two_instance) { 3273f012e29Smrg r = submit(len, AMDGPU_HW_IP_VCE); 3283f012e29Smrg CU_ASSERT_EQUAL(r, 0); 3293f012e29Smrg } 3303f012e29Smrg} 3313f012e29Smrg 3323f012e29Smrgstatic void amdgpu_cs_vce_encode_p(struct amdgpu_vce_encode *enc) 3333f012e29Smrg{ 3343f012e29Smrg uint64_t luma_offset, chroma_offset; 3353f012e29Smrg int len, r; 3363f012e29Smrg 3373f012e29Smrg len = (enc->two_instance) ? enc->ib_len : 0; 3383f012e29Smrg luma_offset = enc->vbuf.addr; 3393f012e29Smrg chroma_offset = luma_offset + enc->width * enc->height; 3403f012e29Smrg 3413f012e29Smrg if (!enc->two_instance) { 3423f012e29Smrg memcpy((ib_cpu + len), vce_session, sizeof(vce_session)); 3433f012e29Smrg len += sizeof(vce_session) / 4; 3443f012e29Smrg } 3453f012e29Smrg memcpy((ib_cpu + len), vce_taskinfo, sizeof(vce_taskinfo)); 3463f012e29Smrg len += sizeof(vce_taskinfo) / 4; 3473f012e29Smrg memcpy((ib_cpu + len), vce_bs_buffer, sizeof(vce_bs_buffer)); 3483f012e29Smrg ib_cpu[len + 2] = enc->bs[1].addr >> 32; 3493f012e29Smrg ib_cpu[len + 3] = enc->bs[1].addr; 3503f012e29Smrg len += sizeof(vce_bs_buffer) / 4; 3513f012e29Smrg memcpy((ib_cpu + len), vce_context_buffer, sizeof(vce_context_buffer)); 3523f012e29Smrg ib_cpu[len + 2] = enc->cpb.addr >> 32; 3533f012e29Smrg ib_cpu[len + 3] = enc->cpb.addr; 3543f012e29Smrg len += sizeof(vce_context_buffer) / 4; 3553f012e29Smrg memcpy((ib_cpu + len), vce_aux_buffer, sizeof(vce_aux_buffer)); 3563f012e29Smrg len += sizeof(vce_aux_buffer) / 4; 3573f012e29Smrg memcpy((ib_cpu + len), vce_feedback, sizeof(vce_feedback)); 3583f012e29Smrg ib_cpu[len + 2] = enc->fb[1].addr >> 32; 3593f012e29Smrg ib_cpu[len + 3] = enc->fb[1].addr; 3603f012e29Smrg len += sizeof(vce_feedback) / 4; 3613f012e29Smrg memcpy((ib_cpu + len), vce_encode, sizeof(vce_encode)); 3623f012e29Smrg ib_cpu[len + 2] = 0; 3633f012e29Smrg ib_cpu[len + 9] = luma_offset >> 32; 3643f012e29Smrg ib_cpu[len + 10] = luma_offset; 3653f012e29Smrg ib_cpu[len + 11] = chroma_offset >> 32; 3663f012e29Smrg ib_cpu[len + 12] = chroma_offset; 3673f012e29Smrg ib_cpu[len + 18] = 0; 3683f012e29Smrg ib_cpu[len + 19] = 0; 3693f012e29Smrg ib_cpu[len + 56] = 3; 3703f012e29Smrg ib_cpu[len + 57] = 0; 3713f012e29Smrg ib_cpu[len + 58] = 0; 3723f012e29Smrg ib_cpu[len + 59] = 0x7800; 3733f012e29Smrg ib_cpu[len + 60] = 0x7800 + 0x5000; 3743f012e29Smrg ib_cpu[len + 73] = 0; 3753f012e29Smrg ib_cpu[len + 74] = 0x5000; 3763f012e29Smrg ib_cpu[len + 81] = 1; 3773f012e29Smrg ib_cpu[len + 82] = 1; 3783f012e29Smrg len += sizeof(vce_encode) / 4; 3793f012e29Smrg 3803f012e29Smrg r = submit(len, AMDGPU_HW_IP_VCE); 3813f012e29Smrg CU_ASSERT_EQUAL(r, 0); 3823f012e29Smrg} 3833f012e29Smrg 3843f012e29Smrgstatic void check_result(struct amdgpu_vce_encode *enc) 3853f012e29Smrg{ 3863f012e29Smrg uint64_t sum; 3873f012e29Smrg uint32_t s[2] = {180325, 15946}; 3883f012e29Smrg uint32_t *ptr, size; 3893f012e29Smrg int i, j, r; 3903f012e29Smrg 3913f012e29Smrg for (i = 0; i < 2; ++i) { 3923f012e29Smrg r = amdgpu_bo_cpu_map(enc->fb[i].handle, (void **)&enc->fb[i].ptr); 3933f012e29Smrg CU_ASSERT_EQUAL(r, 0); 3943f012e29Smrg ptr = (uint32_t *)enc->fb[i].ptr; 3953f012e29Smrg size = ptr[4] - ptr[9]; 3963f012e29Smrg r = amdgpu_bo_cpu_unmap(enc->fb[i].handle); 3973f012e29Smrg CU_ASSERT_EQUAL(r, 0); 3983f012e29Smrg r = amdgpu_bo_cpu_map(enc->bs[i].handle, (void **)&enc->bs[i].ptr); 3993f012e29Smrg CU_ASSERT_EQUAL(r, 0); 4003f012e29Smrg for (j = 0, sum = 0; j < size; ++j) 4013f012e29Smrg sum += enc->bs[i].ptr[j]; 4023f012e29Smrg CU_ASSERT_EQUAL(sum, s[i]); 4033f012e29Smrg r = amdgpu_bo_cpu_unmap(enc->bs[i].handle); 4043f012e29Smrg CU_ASSERT_EQUAL(r, 0); 4053f012e29Smrg } 4063f012e29Smrg} 4073f012e29Smrg 4083f012e29Smrgstatic void amdgpu_cs_vce_encode(void) 4093f012e29Smrg{ 4103f012e29Smrg uint32_t vbuf_size, bs_size = 0x154000, cpb_size; 4113f012e29Smrg int r; 4123f012e29Smrg 4133f012e29Smrg vbuf_size = enc.width * enc.height * 1.5; 4143f012e29Smrg cpb_size = vbuf_size * 10; 4153f012e29Smrg num_resources = 0; 4163f012e29Smrg alloc_resource(&enc.fb[0], 4096, AMDGPU_GEM_DOMAIN_GTT); 4173f012e29Smrg resources[num_resources++] = enc.fb[0].handle; 4183f012e29Smrg alloc_resource(&enc.fb[1], 4096, AMDGPU_GEM_DOMAIN_GTT); 4193f012e29Smrg resources[num_resources++] = enc.fb[1].handle; 4203f012e29Smrg alloc_resource(&enc.bs[0], bs_size, AMDGPU_GEM_DOMAIN_GTT); 4213f012e29Smrg resources[num_resources++] = enc.bs[0].handle; 4223f012e29Smrg alloc_resource(&enc.bs[1], bs_size, AMDGPU_GEM_DOMAIN_GTT); 4233f012e29Smrg resources[num_resources++] = enc.bs[1].handle; 4243f012e29Smrg alloc_resource(&enc.vbuf, vbuf_size, AMDGPU_GEM_DOMAIN_VRAM); 4253f012e29Smrg resources[num_resources++] = enc.vbuf.handle; 4263f012e29Smrg alloc_resource(&enc.cpb, cpb_size, AMDGPU_GEM_DOMAIN_VRAM); 4273f012e29Smrg resources[num_resources++] = enc.cpb.handle; 4283f012e29Smrg resources[num_resources++] = ib_handle; 4293f012e29Smrg 4303f012e29Smrg r = amdgpu_bo_cpu_map(enc.vbuf.handle, (void **)&enc.vbuf.ptr); 4313f012e29Smrg CU_ASSERT_EQUAL(r, 0); 4323f012e29Smrg memcpy(enc.vbuf.ptr, frame, sizeof(frame)); 4333f012e29Smrg r = amdgpu_bo_cpu_unmap(enc.vbuf.handle); 4343f012e29Smrg CU_ASSERT_EQUAL(r, 0); 4353f012e29Smrg 4363f012e29Smrg amdgpu_cs_vce_config(); 4373f012e29Smrg 4383f012e29Smrg if (family_id >= AMDGPU_FAMILY_VI) { 4393f012e29Smrg vce_taskinfo[3] = 3; 4403f012e29Smrg amdgpu_cs_vce_encode_idr(&enc); 4413f012e29Smrg amdgpu_cs_vce_encode_p(&enc); 4423f012e29Smrg check_result(&enc); 4433f012e29Smrg 4443f012e29Smrg /* two pipes */ 4453f012e29Smrg vce_encode[16] = 0; 4463f012e29Smrg amdgpu_cs_vce_encode_idr(&enc); 4473f012e29Smrg amdgpu_cs_vce_encode_p(&enc); 4483f012e29Smrg check_result(&enc); 4493f012e29Smrg 4503f012e29Smrg /* two instances */ 4513f012e29Smrg if (vce_harvest_config == 0) { 4523f012e29Smrg enc.two_instance = true; 4533f012e29Smrg vce_taskinfo[2] = 0x83; 4543f012e29Smrg vce_taskinfo[4] = 1; 4553f012e29Smrg amdgpu_cs_vce_encode_idr(&enc); 4563f012e29Smrg vce_taskinfo[2] = 0xffffffff; 4573f012e29Smrg vce_taskinfo[4] = 2; 4583f012e29Smrg amdgpu_cs_vce_encode_p(&enc); 4593f012e29Smrg check_result(&enc); 4603f012e29Smrg } 4613f012e29Smrg } else { 4623f012e29Smrg vce_taskinfo[3] = 3; 4633f012e29Smrg vce_encode[16] = 0; 4643f012e29Smrg amdgpu_cs_vce_encode_idr(&enc); 4653f012e29Smrg amdgpu_cs_vce_encode_p(&enc); 4663f012e29Smrg check_result(&enc); 4673f012e29Smrg } 4683f012e29Smrg 4693f012e29Smrg free_resource(&enc.fb[0]); 4703f012e29Smrg free_resource(&enc.fb[1]); 4713f012e29Smrg free_resource(&enc.bs[0]); 4723f012e29Smrg free_resource(&enc.bs[1]); 4733f012e29Smrg free_resource(&enc.vbuf); 4743f012e29Smrg free_resource(&enc.cpb); 4753f012e29Smrg} 4763f012e29Smrg 4773f012e29Smrgstatic void amdgpu_cs_vce_destroy(void) 4783f012e29Smrg{ 4793f012e29Smrg int len, r; 4803f012e29Smrg 4813f012e29Smrg num_resources = 0; 4823f012e29Smrg alloc_resource(&enc.fb[0], 4096, AMDGPU_GEM_DOMAIN_GTT); 4833f012e29Smrg resources[num_resources++] = enc.fb[0].handle; 4843f012e29Smrg resources[num_resources++] = ib_handle; 4853f012e29Smrg 4863f012e29Smrg len = 0; 4873f012e29Smrg memcpy(ib_cpu, vce_session, sizeof(vce_session)); 4883f012e29Smrg len += sizeof(vce_session) / 4; 4893f012e29Smrg memcpy((ib_cpu + len), vce_taskinfo, sizeof(vce_taskinfo)); 4903f012e29Smrg ib_cpu[len + 3] = 1; 4913f012e29Smrg len += sizeof(vce_taskinfo) / 4; 4923f012e29Smrg memcpy((ib_cpu + len), vce_feedback, sizeof(vce_feedback)); 4933f012e29Smrg ib_cpu[len + 2] = enc.fb[0].addr >> 32; 4943f012e29Smrg ib_cpu[len + 3] = enc.fb[0].addr; 4953f012e29Smrg len += sizeof(vce_feedback) / 4; 4963f012e29Smrg memcpy((ib_cpu + len), vce_destroy, sizeof(vce_destroy)); 4973f012e29Smrg len += sizeof(vce_destroy) / 4; 4983f012e29Smrg 4993f012e29Smrg r = submit(len, AMDGPU_HW_IP_VCE); 5003f012e29Smrg CU_ASSERT_EQUAL(r, 0); 5013f012e29Smrg 5023f012e29Smrg free_resource(&enc.fb[0]); 5033f012e29Smrg} 504