162306a36Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0 */ 262306a36Sopenharmony_ci/* 362306a36Sopenharmony_ci * Copyright 2020-2021 NXP 462306a36Sopenharmony_ci */ 562306a36Sopenharmony_ci 662306a36Sopenharmony_ci#ifndef _AMPHION_VPU_HELPERS_H 762306a36Sopenharmony_ci#define _AMPHION_VPU_HELPERS_H 862306a36Sopenharmony_ci 962306a36Sopenharmony_cistruct vpu_pair { 1062306a36Sopenharmony_ci u32 src; 1162306a36Sopenharmony_ci u32 dst; 1262306a36Sopenharmony_ci}; 1362306a36Sopenharmony_ci 1462306a36Sopenharmony_ciint vpu_helper_find_in_array_u8(const u8 *array, u32 size, u32 x); 1562306a36Sopenharmony_cibool vpu_helper_check_type(struct vpu_inst *inst, u32 type); 1662306a36Sopenharmony_ciconst struct vpu_format *vpu_helper_find_format(struct vpu_inst *inst, u32 type, u32 pixelfmt); 1762306a36Sopenharmony_ciconst struct vpu_format *vpu_helper_find_sibling(struct vpu_inst *inst, u32 type, u32 pixelfmt); 1862306a36Sopenharmony_cibool vpu_helper_match_format(struct vpu_inst *inst, u32 type, u32 fmta, u32 fmtb); 1962306a36Sopenharmony_ciconst struct vpu_format *vpu_helper_enum_format(struct vpu_inst *inst, u32 type, int index); 2062306a36Sopenharmony_ciu32 vpu_helper_valid_frame_width(struct vpu_inst *inst, u32 width); 2162306a36Sopenharmony_ciu32 vpu_helper_valid_frame_height(struct vpu_inst *inst, u32 height); 2262306a36Sopenharmony_ciu32 vpu_helper_get_plane_size(u32 fmt, u32 width, u32 height, int plane_no, 2362306a36Sopenharmony_ci u32 stride, u32 interlaced, u32 *pbl); 2462306a36Sopenharmony_ciint vpu_helper_copy_from_stream_buffer(struct vpu_buffer *stream_buffer, 2562306a36Sopenharmony_ci u32 *rptr, u32 size, void *dst); 2662306a36Sopenharmony_ciint vpu_helper_copy_to_stream_buffer(struct vpu_buffer *stream_buffer, 2762306a36Sopenharmony_ci u32 *wptr, u32 size, void *src); 2862306a36Sopenharmony_ciint vpu_helper_memset_stream_buffer(struct vpu_buffer *stream_buffer, 2962306a36Sopenharmony_ci u32 *wptr, u8 val, u32 size); 3062306a36Sopenharmony_ciu32 vpu_helper_get_free_space(struct vpu_inst *inst); 3162306a36Sopenharmony_ciu32 vpu_helper_get_used_space(struct vpu_inst *inst); 3262306a36Sopenharmony_ciint vpu_helper_g_volatile_ctrl(struct v4l2_ctrl *ctrl); 3362306a36Sopenharmony_civoid vpu_helper_get_kmp_next(const u8 *pattern, int *next, int size); 3462306a36Sopenharmony_ciint vpu_helper_kmp_search(u8 *s, int s_len, const u8 *p, int p_len, int *next); 3562306a36Sopenharmony_ciint vpu_helper_kmp_search_in_stream_buffer(struct vpu_buffer *stream_buffer, 3662306a36Sopenharmony_ci u32 offset, int bytesused, 3762306a36Sopenharmony_ci const u8 *p, int p_len, int *next); 3862306a36Sopenharmony_ciint vpu_helper_find_startcode(struct vpu_buffer *stream_buffer, 3962306a36Sopenharmony_ci u32 pixelformat, u32 offset, u32 bytesused); 4062306a36Sopenharmony_ci 4162306a36Sopenharmony_cistatic inline u32 vpu_helper_step_walk(struct vpu_buffer *stream_buffer, u32 pos, u32 step) 4262306a36Sopenharmony_ci{ 4362306a36Sopenharmony_ci pos += step; 4462306a36Sopenharmony_ci if (pos > stream_buffer->phys + stream_buffer->length) 4562306a36Sopenharmony_ci pos -= stream_buffer->length; 4662306a36Sopenharmony_ci 4762306a36Sopenharmony_ci return pos; 4862306a36Sopenharmony_ci} 4962306a36Sopenharmony_ci 5062306a36Sopenharmony_cistatic inline u8 vpu_helper_read_byte(struct vpu_buffer *stream_buffer, u32 pos) 5162306a36Sopenharmony_ci{ 5262306a36Sopenharmony_ci u8 *pdata = (u8 *)stream_buffer->virt; 5362306a36Sopenharmony_ci 5462306a36Sopenharmony_ci return pdata[pos % stream_buffer->length]; 5562306a36Sopenharmony_ci} 5662306a36Sopenharmony_ci 5762306a36Sopenharmony_ciint vpu_color_check_primaries(u32 primaries); 5862306a36Sopenharmony_ciint vpu_color_check_transfers(u32 transfers); 5962306a36Sopenharmony_ciint vpu_color_check_matrix(u32 matrix); 6062306a36Sopenharmony_ciint vpu_color_check_full_range(u32 full_range); 6162306a36Sopenharmony_ciu32 vpu_color_cvrt_primaries_v2i(u32 primaries); 6262306a36Sopenharmony_ciu32 vpu_color_cvrt_primaries_i2v(u32 primaries); 6362306a36Sopenharmony_ciu32 vpu_color_cvrt_transfers_v2i(u32 transfers); 6462306a36Sopenharmony_ciu32 vpu_color_cvrt_transfers_i2v(u32 transfers); 6562306a36Sopenharmony_ciu32 vpu_color_cvrt_matrix_v2i(u32 matrix); 6662306a36Sopenharmony_ciu32 vpu_color_cvrt_matrix_i2v(u32 matrix); 6762306a36Sopenharmony_ciu32 vpu_color_cvrt_full_range_v2i(u32 full_range); 6862306a36Sopenharmony_ciu32 vpu_color_cvrt_full_range_i2v(u32 full_range); 6962306a36Sopenharmony_ciint vpu_color_get_default(u32 primaries, u32 *ptransfers, u32 *pmatrix, u32 *pfull_range); 7062306a36Sopenharmony_ci 7162306a36Sopenharmony_ciint vpu_find_dst_by_src(struct vpu_pair *pairs, u32 cnt, u32 src); 7262306a36Sopenharmony_ciint vpu_find_src_by_dst(struct vpu_pair *pairs, u32 cnt, u32 dst); 7362306a36Sopenharmony_ci#endif 74