@@ -1808,15 +1808,19 @@ static int vcn_v4_0_limit_sched(struct amdgpu_cs_parser *p,
18081808 struct amdgpu_job * job )
18091809{
18101810 struct drm_gpu_scheduler * * scheds ;
1811-
1812- /* The create msg must be in the first IB submitted */
1813- if (atomic_read (& job -> base .entity -> fence_seq ))
1814- return - EINVAL ;
1811+ struct dma_fence * fence ;
18151812
18161813 /* if VCN0 is harvested, we can't support AV1 */
18171814 if (p -> adev -> vcn .harvest_config & AMDGPU_VCN_HARVEST_VCN0 )
18181815 return - EINVAL ;
18191816
1817+ /* wait for all jobs to finish before switching to instance 0 */
1818+ fence = amdgpu_ctx_get_fence (p -> ctx , job -> base .entity , ~0ull );
1819+ if (fence ) {
1820+ dma_fence_wait (fence , false);
1821+ dma_fence_put (fence );
1822+ }
1823+
18201824 scheds = p -> adev -> gpu_sched [AMDGPU_HW_IP_VCN_ENC ]
18211825 [AMDGPU_RING_PRIO_0 ].sched ;
18221826 drm_sched_entity_modify_sched (job -> base .entity , scheds , 1 );
@@ -1907,22 +1911,16 @@ static int vcn_v4_0_dec_msg(struct amdgpu_cs_parser *p, struct amdgpu_job *job,
19071911
19081912#define RADEON_VCN_ENGINE_TYPE_ENCODE (0x00000002)
19091913#define RADEON_VCN_ENGINE_TYPE_DECODE (0x00000003)
1910-
19111914#define RADEON_VCN_ENGINE_INFO (0x30000001)
1912- #define RADEON_VCN_ENGINE_INFO_MAX_OFFSET 16
1913-
19141915#define RENCODE_ENCODE_STANDARD_AV1 2
19151916#define RENCODE_IB_PARAM_SESSION_INIT 0x00000003
1916- #define RENCODE_IB_PARAM_SESSION_INIT_MAX_OFFSET 64
19171917
1918- /* return the offset in ib if id is found, -1 otherwise
1919- * to speed up the searching we only search upto max_offset
1920- */
1921- static int vcn_v4_0_enc_find_ib_param (struct amdgpu_ib * ib , uint32_t id , int max_offset )
1918+ /* return the offset in ib if id is found, -1 otherwise */
1919+ static int vcn_v4_0_enc_find_ib_param (struct amdgpu_ib * ib , uint32_t id , int start )
19221920{
19231921 int i ;
19241922
1925- for (i = 0 ; i < ib -> length_dw && i < max_offset && ib -> ptr [i ] >= 8 ; i += ib -> ptr [i ]/ 4 ) {
1923+ for (i = start ; i < ib -> length_dw && ib -> ptr [i ] >= 8 ; i += ib -> ptr [i ] / 4 ) {
19261924 if (ib -> ptr [i + 1 ] == id )
19271925 return i ;
19281926 }
@@ -1937,33 +1935,29 @@ static int vcn_v4_0_ring_patch_cs_in_place(struct amdgpu_cs_parser *p,
19371935 struct amdgpu_vcn_decode_buffer * decode_buffer ;
19381936 uint64_t addr ;
19391937 uint32_t val ;
1940- int idx ;
1938+ int idx = 0 , sidx ;
19411939
19421940 /* The first instance can decode anything */
19431941 if (!ring -> me )
19441942 return 0 ;
19451943
1946- /* RADEON_VCN_ENGINE_INFO is at the top of ib block */
1947- idx = vcn_v4_0_enc_find_ib_param (ib , RADEON_VCN_ENGINE_INFO ,
1948- RADEON_VCN_ENGINE_INFO_MAX_OFFSET );
1949- if (idx < 0 ) /* engine info is missing */
1950- return 0 ;
1951-
1952- val = amdgpu_ib_get_value (ib , idx + 2 ); /* RADEON_VCN_ENGINE_TYPE */
1953- if (val == RADEON_VCN_ENGINE_TYPE_DECODE ) {
1954- decode_buffer = (struct amdgpu_vcn_decode_buffer * )& ib -> ptr [idx + 6 ];
1955-
1956- if (!(decode_buffer -> valid_buf_flag & 0x1 ))
1957- return 0 ;
1958-
1959- addr = ((u64 )decode_buffer -> msg_buffer_address_hi ) << 32 |
1960- decode_buffer -> msg_buffer_address_lo ;
1961- return vcn_v4_0_dec_msg (p , job , addr );
1962- } else if (val == RADEON_VCN_ENGINE_TYPE_ENCODE ) {
1963- idx = vcn_v4_0_enc_find_ib_param (ib , RENCODE_IB_PARAM_SESSION_INIT ,
1964- RENCODE_IB_PARAM_SESSION_INIT_MAX_OFFSET );
1965- if (idx >= 0 && ib -> ptr [idx + 2 ] == RENCODE_ENCODE_STANDARD_AV1 )
1966- return vcn_v4_0_limit_sched (p , job );
1944+ while ((idx = vcn_v4_0_enc_find_ib_param (ib , RADEON_VCN_ENGINE_INFO , idx )) >= 0 ) {
1945+ val = amdgpu_ib_get_value (ib , idx + 2 ); /* RADEON_VCN_ENGINE_TYPE */
1946+ if (val == RADEON_VCN_ENGINE_TYPE_DECODE ) {
1947+ decode_buffer = (struct amdgpu_vcn_decode_buffer * )& ib -> ptr [idx + 6 ];
1948+
1949+ if (!(decode_buffer -> valid_buf_flag & 0x1 ))
1950+ return 0 ;
1951+
1952+ addr = ((u64 )decode_buffer -> msg_buffer_address_hi ) << 32 |
1953+ decode_buffer -> msg_buffer_address_lo ;
1954+ return vcn_v4_0_dec_msg (p , job , addr );
1955+ } else if (val == RADEON_VCN_ENGINE_TYPE_ENCODE ) {
1956+ sidx = vcn_v4_0_enc_find_ib_param (ib , RENCODE_IB_PARAM_SESSION_INIT , idx );
1957+ if (sidx >= 0 && ib -> ptr [sidx + 2 ] == RENCODE_ENCODE_STANDARD_AV1 )
1958+ return vcn_v4_0_limit_sched (p , job );
1959+ }
1960+ idx += ib -> ptr [idx ] / 4 ;
19671961 }
19681962 return 0 ;
19691963}
0 commit comments