shithub: hantro9

Download patch

ref: 3296f28705a08bd9daff92a677b0fa76098941dd
parent: 0223e82f5d691ea45acb32f70dfa7987ab68c369
author: Sigrid Solveig Haflínudóttir <sigrid@ftrv.se>
date: Tue May 2 10:25:17 EDT 2023

moving to the kernel

--- a/hantest.c
+++ b/hantest.c
@@ -3,145 +3,7 @@
 #include "g1regs.h"
 #include "vpuctx.h"
 
-enum {
-	DecodeH264,
-
-	Baseline = 66,
-	High = 100,
-};
-
-static u32int *g1, *g2;
-
-static void
-g1load(VPUctx *c)
-{
-	g1[2] = 16 << SW_DEC_MAX_BURST | /* AXI burst length = 16 */
-		1 << SW_DEC_STRSWAP32_E | 1 << SW_DEC_STRENDIAN_E | /* 64bit / little endian */
-		1 << SW_DEC_INSWAP32_E | 1 << SW_DEC_OUTSWAP32_E |
-		1 << SW_DEC_IN_ENDIAN | 1 << SW_DEC_OUT_ENDIAN |
-		1 << SW_DEC_TIMEOUT_E;  /* timeout interrupt */
-
-	g1[3] = (c->sps.frame_mbs_only_flag == 0 &&
-	         (c->sps.mb_adaptive_frame_field_flag || c->sh.field_pic_flag)) << SW_PIC_INTERLACE_E |
-		(c->sps.frame_mbs_only_flag == 0 && c->sh.field_pic_flag) << SW_PIC_FIELDMODE_E |
-		(c->sps.frame_mbs_only_flag == 0 && c->sh.bottom_field_flag == 0) << SW_PIC_TOPFIELD_E |
-		(c->sps.profile_idc > Baseline && c->nal_ref_idc != 0) << SW_WRITE_MVS_E |
-		c->sps.mb_adaptive_frame_field_flag << SW_SEQ_MBAFF_E |
-		(c->sps.profile_idc > Baseline) << SW_PICORD_COUNT_E |
-		0xff << SW_DEC_AXI_WR_ID;
-
-	g1[4] = (c->sps.pic_width_in_mbs_minus1 + 1) << SW_PIC_MB_WIDTH |
-		(c->sps.pic_height_in_map_units_minus1 + 1) << SW_PIC_MB_HEIGHT_P |
-		c->sps.max_num_ref_frames << SW_REF_FRAMES;
-
-	g1[5] = 0 << SW_STRM_START_BIT |
-		c->pps.pic_scaling_matrix_present_flag << SW_SCALING_LIST_E |
-		(c->pps.chroma_qp_index_offset & ((1<<5)-1)) << SW_CH_QP_OFFSET |
-		(c->pps.second_chroma_qp_index_offset & ((1<<5)-1)) << SW_CH_QP_OFFSET2 |
-		(c->sps.frame_mbs_only_flag == 0) << SW_FIELDPIC_FLAG_E;
-
-	g1[6] = 1 << SW_START_CODE_E |
-		(c->pps.pic_init_qp_minus26 + 26) << SW_INIT_QP |
-		c->slen << SW_STREAM_LEN;
-
-	g1[7] = c->pps.entropy_coding_mode_flag << SW_CABAC_E |
-		(c->sps.chroma_format_idc == 0 && c->sps.profile_idc >= High) << SW_BLACKWHITE_E |
-		c->sps.direct_8x8_inference_flag << SW_DIR_8X8_INFER_E |
-		c->pps.weighted_pred_flag << SW_WEIGHT_PRED_E |
-		c->pps.weighted_bipred_idc << SW_WEIGHT_BIPR_IDC |
-		(c->sps.log2_max_frame_num_minus4 + 4) << SW_FRAMENUM_LEN |
-		c->sh.frame_num << SW_FRAMENUM;
-
-	g1[8] = c->pps.constrained_intra_pred_flag << SW_CONST_INTRA_E |
-		c->pps.deblocking_filter_control_present_flag << SW_FILT_CTRL_PRES |
-		c->pps.redundant_pic_cnt_present_flag << SW_RDPIC_CNT_PRES |
-		c->pps.transform_8x8_mode_flag << SW_8X8TRANS_FLAG_E |
-		(c->nal_ref_idc != 0 ? c->sh.size_dec_ref_pic_marking : 0) << SW_REFPIC_MK_LEN |
-		(c->nal_unit_type == 5) << SW_IDR_PIC_E |
-		c->sh.idr_pic_id << SW_IDR_PIC_ID;
-
-	g1[9] = c->pps.pic_parameter_set_id << SW_PPS_ID |
-		(c->pps.num_ref_idx_l1_default_active_minus1 + 1) << SW_REFIDX1_ACTIVE |
-		(c->pps.num_ref_idx_l0_default_active_minus1 + 1) << SW_REFIDX0_ACTIVE |
-		(c->sh.size_pic_order_cnt_lsb + c->sh.size_delta_pic_order_cnt_bottom +
-		 c->sh.size_delta_pic_order_cnt0 + c->sh.size_delta_pic_order_cnt1) << SW_POC_LENGTH;
-
-	/* fixed 6-tap filter values (1 -5 20) */
-	g1[49] = 1 << SW_PRED_BC_TAP_0_0 |
-		(-5 & ((1<<(SW_PRED_BC_TAP_0_0-SW_PRED_BC_TAP_0_1))-1)) << SW_PRED_BC_TAP_0_1 |
-		20 << SW_PRED_BC_TAP_0_2;
-}
-
-static int
-parsecmd(VPUctx *c, char *s)
-{
-	char *a[4];
-	int n, x;
-
-	if((n = tokenize(s, a, nelem(a))) < 2)
-		return -1;
-
-#define value(name, field, min, max) \
-	if(strcmp(a[1], name) == 0){ \
-		if(x < (min) || x > (max)){ \
-			werrstr("%s: out of range [%d, %d]", a[1], (min), (max)); \
-			return -1; \
-		} \
-		field = x; \
-		return 0; \
-	}
-
-	if(strcmp(a[0], "decode") == 0){
-		if(n == 2 && strcmp(a[1], "h.264") == 0){
-			c->process = DecodeH264;
-			return 0;
-		}
-	}else if(c->process == DecodeH264 && n == 3){
-		x = atoi(a[2]);
-		if(strcmp(a[0], "sps") == 0){
-			value("pic_height_in_map_units_minus1", c->sps.pic_height_in_map_units_minus1, 0, 0xff);
-			value("pic_width_in_mbs_minus1", c->sps.pic_width_in_mbs_minus1, 0, 0xff);
-			value("chroma_format_idc", c->sps.chroma_format_idc, 0, 3);
-			value("log2_max_frame_num_minus4", c->sps.log2_max_frame_num_minus4, 0, 12);
-			value("max_num_ref_frames", c->sps.max_num_ref_frames, 0, 16);
-			value("nal_ref_idc", c->nal_ref_idc, 0, 3);
-			value("profile_idc", c->sps.profile_idc, 0, 0xff);
-			value("direct_8x8_inference_flag", c->sps.direct_8x8_inference_flag, 0, 1);
-			value("frame_mbs_only_flag", c->sps.frame_mbs_only_flag, 0, 1);
-			value("mb_adaptive_frame_field_flag", c->sps.mb_adaptive_frame_field_flag, 0, 1);
-			value("seq_scaling_matrix_present_flag", c->sps.seq_scaling_matrix_present_flag, 0, 1);
-		}else if(strcmp(a[0], "pps") == 0){
-			value("chroma_qp_index_offset", c->pps.chroma_qp_index_offset, -12, 12);
-			value("pic_init_qp_minus26", c->pps.pic_init_qp_minus26, -26, 25);
-			value("second_chroma_qp_index_offset", c->pps.second_chroma_qp_index_offset, -12, 12);
-			value("weighted_bipred_idc", c->pps.weighted_bipred_idc, 0, 2);
-			value("pic_parameter_set_id", c->pps.pic_parameter_set_id, 0, 0xff);
-			value("num_ref_idx_l0_default_active_minus1", c->pps.num_ref_idx_l0_default_active_minus1, 0, 31);
-			value("num_ref_idx_l1_default_active_minus1", c->pps.num_ref_idx_l1_default_active_minus1, 0, 31);
-			value("constrained_intra_pred_flag", c->pps.constrained_intra_pred_flag, 0, 1);
-			value("deblocking_filter_control_present_flag", c->pps.deblocking_filter_control_present_flag, 0, 1);
-			value("entropy_coding_mode_flag", c->pps.entropy_coding_mode_flag, 0, 1);
-			value("pic_scaling_matrix_present_flag", c->pps.pic_scaling_matrix_present_flag, 0, 1);
-			value("redundant_pic_cnt_present_flag", c->pps.redundant_pic_cnt_present_flag, 0, 1);
-			value("transform_8x8_mode_flag", c->pps.transform_8x8_mode_flag, 0, 1);
-			value("weighted_pred_flag", c->pps.weighted_pred_flag, 0, 1);
-		}else if(strcmp(a[0], "sh") == 0){
-			value("frame_num", c->sh.frame_num, 0, 0xffff);
-			value("idr_pic_id", c->sh.idr_pic_id, 0, 0xffff);
-			value("nal_unit_type", c->nal_unit_type, 0, 0xff);
-			value("size_dec_ref_pic_marking", c->sh.size_dec_ref_pic_marking, 0, 0x1ffff);
-			value("size_pic_order_cnt_lsb", c->sh.size_pic_order_cnt_lsb, 0, 0xff);
-			value("size_delta_pic_order_cnt_bottom", c->sh.size_delta_pic_order_cnt_bottom, 0, 0xff);
-			value("size_delta_pic_order_cnt0", c->sh.size_delta_pic_order_cnt0, 0, 0xff);
-			value("size_delta_pic_order_cnt1", c->sh.size_delta_pic_order_cnt1, 0, 0xff);
-			value("field_pic_flag", c->sh.field_pic_flag, 0, 1);
-			value("bottom_field_flag", c->sh.bottom_field_flag, 0, 1);
-		}
-	}
-#undef value
-
-	return -1;
-}
+static u32int *g1;
 
 void
 main(int argc, char **argv)
--- a/vpuctx.h
+++ b/vpuctx.h
@@ -10,7 +10,6 @@
 			/* FIXME userspace */
 			u32int useDefaultScalingMatrixFlag;
 			int PicSizeInMapUnits;
-			u8int IdrPicFlag;
 			u8int sl4x4[6*16];
 			u8int sl8x8[6*64];
 			struct {
@@ -34,8 +33,8 @@
 				u8int separate_colour_plane_flag;
 
 				/* FIXME userspace */
-				u8int log2_max_pic_order_cnt_lsb_minus4; /* FIXME correct type? */
-				u8int pic_order_cnt_type; /* FIXME correct type? */
+				u8int log2_max_pic_order_cnt_lsb_minus4; /* 0-12 */
+				u8int pic_order_cnt_type; /* 0-2 */
 				u8int delta_pic_order_always_zero_flag;
 			}sps;
 			struct {