1 /* SPDX-License-Identifier: GPL-2.0 */ 2 /* 3 * Rockchip video decoder h264 common functions 4 * 5 * Copyright (C) 2025 Collabora, Ltd. 6 * Detlev Casanova <detlev.casanova@collabora.com> 7 * 8 * Copyright (C) 2019 Collabora, Ltd. 9 * Boris Brezillon <boris.brezillon@collabora.com> 10 * 11 * Copyright (C) 2016 Rockchip Electronics Co., Ltd. 12 * Jeffy Chen <jeffy.chen@rock-chips.com> 13 */ 14 15 #include <media/v4l2-h264.h> 16 #include <media/v4l2-mem2mem.h> 17 18 #include "rkvdec.h" 19 20 struct rkvdec_h264_scaling_list { 21 u8 scaling_list_4x4[6][16]; 22 u8 scaling_list_8x8[6][64]; 23 u8 padding[128]; 24 }; 25 26 struct rkvdec_h264_reflists { 27 struct v4l2_h264_reference p[V4L2_H264_REF_LIST_LEN]; 28 struct v4l2_h264_reference b0[V4L2_H264_REF_LIST_LEN]; 29 struct v4l2_h264_reference b1[V4L2_H264_REF_LIST_LEN]; 30 }; 31 32 struct rkvdec_h264_run { 33 struct rkvdec_run base; 34 const struct v4l2_ctrl_h264_decode_params *decode_params; 35 const struct v4l2_ctrl_h264_sps *sps; 36 const struct v4l2_ctrl_h264_pps *pps; 37 const struct v4l2_ctrl_h264_scaling_matrix *scaling_matrix; 38 struct vb2_buffer *ref_buf[V4L2_H264_NUM_DPB_ENTRIES]; 39 }; 40 41 struct rkvdec_rps_entry { 42 u32 dpb_info0: 5; 43 u32 bottom_flag0: 1; 44 u32 view_index_off0: 1; 45 u32 dpb_info1: 5; 46 u32 bottom_flag1: 1; 47 u32 view_index_off1: 1; 48 u32 dpb_info2: 5; 49 u32 bottom_flag2: 1; 50 u32 view_index_off2: 1; 51 u32 dpb_info3: 5; 52 u32 bottom_flag3: 1; 53 u32 view_index_off3: 1; 54 u32 dpb_info4: 5; 55 u32 bottom_flag4: 1; 56 u32 view_index_off4: 1; 57 u32 dpb_info5: 5; 58 u32 bottom_flag5: 1; 59 u32 view_index_off5: 1; 60 u32 dpb_info6: 5; 61 u32 bottom_flag6: 1; 62 u32 view_index_off6: 1; 63 u32 dpb_info7: 5; 64 u32 bottom_flag7: 1; 65 u32 view_index_off7: 1; 66 } __packed; 67 68 struct rkvdec_rps { 69 u16 frame_num[16]; 70 u32 reserved0; 71 struct rkvdec_rps_entry entries[12]; 72 u32 reserved1[66]; 73 } __packed; 74 75 void lookup_ref_buf_idx(struct rkvdec_ctx *ctx, struct rkvdec_h264_run *run); 76 void assemble_hw_rps(struct v4l2_h264_reflist_builder *builder, 77 struct rkvdec_h264_run *run, 78 struct rkvdec_h264_reflists *reflists, 79 struct rkvdec_rps *hw_rps); 80 void assemble_hw_scaling_list(struct rkvdec_h264_run *run, 81 struct rkvdec_h264_scaling_list *scaling_list); 82 int rkvdec_h264_adjust_fmt(struct rkvdec_ctx *ctx, struct v4l2_format *f); 83 enum rkvdec_image_fmt rkvdec_h264_get_image_fmt(struct rkvdec_ctx *ctx, struct v4l2_ctrl *ctrl); 84 int rkvdec_h264_validate_sps(struct rkvdec_ctx *ctx, const struct v4l2_ctrl_h264_sps *sps); 85 void rkvdec_h264_run_preamble(struct rkvdec_ctx *ctx, struct rkvdec_h264_run *run); 86