xref: /linux/drivers/media/platform/amphion/vpu_helpers.h (revision b4ada0618eed0fbd1b1630f73deb048c592b06a1)
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 #include "vpu_defs.h"
10 
11 struct vpu_pair {
12 	u32 src;
13 	u32 dst;
14 };
15 
16 int vpu_helper_find_in_array_u8(const u8 *array, u32 size, u32 x);
17 bool vpu_helper_check_type(struct vpu_inst *inst, u32 type);
18 const struct vpu_format *vpu_helper_find_format(struct vpu_inst *inst, u32 type, u32 pixelfmt);
19 const struct vpu_format *vpu_helper_find_sibling(struct vpu_inst *inst, u32 type, u32 pixelfmt);
20 bool vpu_helper_match_format(struct vpu_inst *inst, u32 type, u32 fmta, u32 fmtb);
21 const struct vpu_format *vpu_helper_enum_format(struct vpu_inst *inst, u32 type, int index);
22 u32 vpu_helper_valid_frame_width(struct vpu_inst *inst, u32 width);
23 u32 vpu_helper_valid_frame_height(struct vpu_inst *inst, u32 height);
24 u32 vpu_helper_get_plane_size(u32 fmt, u32 width, u32 height, int plane_no,
25 			      u32 stride, u32 interlaced, u32 *pbl);
26 int vpu_helper_copy_from_stream_buffer(struct vpu_buffer *stream_buffer,
27 				       u32 *rptr, u32 size, void *dst);
28 int vpu_helper_copy_to_stream_buffer(struct vpu_buffer *stream_buffer,
29 				     u32 *wptr, u32 size, void *src);
30 int vpu_helper_memset_stream_buffer(struct vpu_buffer *stream_buffer,
31 				    u32 *wptr, u8 val, u32 size);
32 u32 vpu_helper_get_free_space(struct vpu_inst *inst);
33 u32 vpu_helper_get_used_space(struct vpu_inst *inst);
34 int vpu_helper_g_volatile_ctrl(struct v4l2_ctrl *ctrl);
35 void vpu_helper_get_kmp_next(const u8 *pattern, int *next, int size);
36 int vpu_helper_kmp_search(u8 *s, int s_len, const u8 *p, int p_len, int *next);
37 int vpu_helper_kmp_search_in_stream_buffer(struct vpu_buffer *stream_buffer,
38 					   u32 offset, int bytesused,
39 					   const u8 *p, int p_len, int *next);
40 int vpu_helper_find_startcode(struct vpu_buffer *stream_buffer,
41 			      u32 pixelformat, u32 offset, u32 bytesused);
42 
43 static inline u32 vpu_helper_step_walk(struct vpu_buffer *stream_buffer, u32 pos, u32 step)
44 {
45 	pos += step;
46 	if (pos > stream_buffer->phys + stream_buffer->length)
47 		pos -= stream_buffer->length;
48 
49 	return pos;
50 }
51 
52 static inline u8 vpu_helper_read_byte(struct vpu_buffer *stream_buffer, u32 pos)
53 {
54 	u8 *pdata = (u8 *)stream_buffer->virt;
55 
56 	return pdata[pos % stream_buffer->length];
57 }
58 
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 
68 int vpu_find_dst_by_src(struct vpu_pair *pairs, u32 cnt, u32 src);
69 int vpu_find_src_by_dst(struct vpu_pair *pairs, u32 cnt, u32 dst);
70 
71 u32 vpu_get_h264_v4l2_profile(struct vpu_dec_codec_info *hdr);
72 u32 vpu_get_h264_v4l2_level(struct vpu_dec_codec_info *hdr);
73 u32 vpu_get_hevc_v4l2_profile(struct vpu_dec_codec_info *hdr);
74 u32 vpu_get_hevc_v4l2_level(struct vpu_dec_codec_info *hdr);
75 #endif
76