1 /* SPDX-License-Identifier: GPL-2.0 */ 2 /* 3 * Copyright 2020-2021 NXP 4 */ 5 6 #ifndef _AMPHION_VPU_HELPERS_H 7 #define _AMPHION_VPU_HELPERS_H 8 9 struct vpu_pair { 10 u32 src; 11 u32 dst; 12 }; 13 14 int vpu_helper_find_in_array_u8(const u8 *array, u32 size, u32 x); 15 bool vpu_helper_check_type(struct vpu_inst *inst, u32 type); 16 const struct vpu_format *vpu_helper_find_format(struct vpu_inst *inst, u32 type, u32 pixelfmt); 17 const struct vpu_format *vpu_helper_enum_format(struct vpu_inst *inst, u32 type, int index); 18 u32 vpu_helper_valid_frame_width(struct vpu_inst *inst, u32 width); 19 u32 vpu_helper_valid_frame_height(struct vpu_inst *inst, u32 height); 20 u32 vpu_helper_get_plane_size(u32 fmt, u32 width, u32 height, int plane_no, 21 u32 stride, u32 interlaced, u32 *pbl); 22 int vpu_helper_copy_from_stream_buffer(struct vpu_buffer *stream_buffer, 23 u32 *rptr, u32 size, void *dst); 24 int vpu_helper_copy_to_stream_buffer(struct vpu_buffer *stream_buffer, 25 u32 *wptr, u32 size, void *src); 26 int vpu_helper_memset_stream_buffer(struct vpu_buffer *stream_buffer, 27 u32 *wptr, u8 val, u32 size); 28 u32 vpu_helper_get_free_space(struct vpu_inst *inst); 29 u32 vpu_helper_get_used_space(struct vpu_inst *inst); 30 int vpu_helper_g_volatile_ctrl(struct v4l2_ctrl *ctrl); 31 void vpu_helper_get_kmp_next(const u8 *pattern, int *next, int size); 32 int vpu_helper_kmp_search(u8 *s, int s_len, const u8 *p, int p_len, int *next); 33 int vpu_helper_kmp_search_in_stream_buffer(struct vpu_buffer *stream_buffer, 34 u32 offset, int bytesused, 35 const u8 *p, int p_len, int *next); 36 int vpu_helper_find_startcode(struct vpu_buffer *stream_buffer, 37 u32 pixelformat, u32 offset, u32 bytesused); 38 39 static inline u32 vpu_helper_step_walk(struct vpu_buffer *stream_buffer, u32 pos, u32 step) 40 { 41 pos += step; 42 if (pos > stream_buffer->phys + stream_buffer->length) 43 pos -= stream_buffer->length; 44 45 return pos; 46 } 47 48 static inline u8 vpu_helper_read_byte(struct vpu_buffer *stream_buffer, u32 pos) 49 { 50 u8 *pdata = (u8 *)stream_buffer->virt; 51 52 return pdata[pos % stream_buffer->length]; 53 } 54 55 int vpu_color_check_primaries(u32 primaries); 56 int vpu_color_check_transfers(u32 transfers); 57 int vpu_color_check_matrix(u32 matrix); 58 int vpu_color_check_full_range(u32 full_range); 59 u32 vpu_color_cvrt_primaries_v2i(u32 primaries); 60 u32 vpu_color_cvrt_primaries_i2v(u32 primaries); 61 u32 vpu_color_cvrt_transfers_v2i(u32 transfers); 62 u32 vpu_color_cvrt_transfers_i2v(u32 transfers); 63 u32 vpu_color_cvrt_matrix_v2i(u32 matrix); 64 u32 vpu_color_cvrt_matrix_i2v(u32 matrix); 65 u32 vpu_color_cvrt_full_range_v2i(u32 full_range); 66 u32 vpu_color_cvrt_full_range_i2v(u32 full_range); 67 int vpu_color_get_default(u32 primaries, u32 *ptransfers, u32 *pmatrix, u32 *pfull_range); 68 69 int vpu_find_dst_by_src(struct vpu_pair *pairs, u32 cnt, u32 src); 70 int vpu_find_src_by_dst(struct vpu_pair *pairs, u32 cnt, u32 dst); 71 #endif 72