1 /* SPDX-License-Identifier: Apache-2.0 OR MIT */
2 /*
3 * Copyright (c) 2024 Rockchip Electronics Co., Ltd.
4 */
5
6 #include "mpp_soc.h"
7 #include "mpp_mem.h"
8
9 #include "vdpp_api.h"
10 #include "vdpp.h"
11 #include "vdpp2.h"
12
rockchip_vdpp_api_alloc_ctx(void)13 vdpp_com_ctx *rockchip_vdpp_api_alloc_ctx(void)
14 {
15 vdpp_com_ctx *com_ctx = mpp_calloc(vdpp_com_ctx, 1);
16 vdpp_com_ops *ops = mpp_calloc(vdpp_com_ops, 1);
17 VdppCtx ctx = NULL;
18
19 if (NULL == com_ctx || NULL == ops) {
20 mpp_err_f("failed to calloc com_ctx %p ops %p\n", com_ctx, ops);
21 goto __ERR;
22 }
23
24 if (mpp_get_soc_type() == ROCKCHIP_SOC_RK3576) {
25 ops->init = vdpp2_init;
26 ops->deinit = vdpp2_deinit;
27 ops->control = vdpp2_control;
28 ops->check_cap = vdpp2_check_cap;
29
30 ctx = mpp_calloc(struct vdpp2_api_ctx, 1);
31 } else {
32 ops->init = vdpp_init;
33 ops->deinit = vdpp_deinit;
34 ops->control = vdpp_control;
35 ops->check_cap = vdpp_check_cap;
36
37 ctx = mpp_calloc(struct vdpp_api_ctx, 1);
38 }
39
40 if (NULL == ctx) {
41 mpp_err_f("failed to calloc vdpp_api_ctx %p\n", ctx);
42 goto __ERR;
43 }
44
45 com_ctx->ops = ops;
46 com_ctx->priv = ctx;
47
48 return com_ctx;
49
50 __ERR:
51 MPP_FREE(com_ctx);
52 MPP_FREE(ops);
53 MPP_FREE(ctx);
54 return NULL;
55 }
56
rockchip_vdpp_api_release_ctx(vdpp_com_ctx * com_ctx)57 void rockchip_vdpp_api_release_ctx(vdpp_com_ctx *com_ctx)
58 {
59 if (NULL == com_ctx)
60 return;
61
62 MPP_FREE(com_ctx->ops);
63 MPP_FREE(com_ctx->priv);
64 MPP_FREE(com_ctx);
65 }
66
dci_hist_info_parser(RK_U8 * p_pack_hist_addr,RK_U32 * p_hist_local,RK_U32 * p_hist_global)67 MPP_RET dci_hist_info_parser(RK_U8* p_pack_hist_addr, RK_U32* p_hist_local, RK_U32* p_hist_global)
68 {
69 RK_U32 hw_hist_idx = 0;
70 RK_U32 idx;
71
72 if (NULL == p_pack_hist_addr || NULL == p_hist_local || NULL == p_hist_global) {
73 mpp_err_f("found NULL ptr, pack_hist %p hist_local %p hist_global %p\n", p_pack_hist_addr, p_hist_local, p_hist_global);
74 return MPP_ERR_NULL_PTR;
75 }
76
77 /* Hist packed (10240 byte) -> unpacked (local: 16 * 16 * 16 * U32 + global: 256 * U32) */
78 for (idx = 0; idx < RKVOP_PQ_PREPROCESS_HIST_SIZE_VERI * RKVOP_PQ_PREPROCESS_HIST_SIZE_HORI * RKVOP_PQ_PREPROCESS_LOCAL_HIST_BIN_NUMS; idx = idx + 4) {
79 RK_U32 tmp0_u18, tmp1_u18, tmp2_u18, tmp3_u18;
80 RK_U32 tmp0_u8, tmp1_u8, tmp2_u8, tmp3_u8, tmp4_u8, tmp5_u8, tmp6_u8, tmp7_u8, tmp8_u8;
81
82 tmp0_u8 = *(p_pack_hist_addr + hw_hist_idx + 0);
83 tmp1_u8 = *(p_pack_hist_addr + hw_hist_idx + 1);
84 tmp2_u8 = *(p_pack_hist_addr + hw_hist_idx + 2);
85 tmp3_u8 = *(p_pack_hist_addr + hw_hist_idx + 3);
86 tmp4_u8 = *(p_pack_hist_addr + hw_hist_idx + 4);
87 tmp5_u8 = *(p_pack_hist_addr + hw_hist_idx + 5);
88 tmp6_u8 = *(p_pack_hist_addr + hw_hist_idx + 6);
89 tmp7_u8 = *(p_pack_hist_addr + hw_hist_idx + 7);
90 tmp8_u8 = *(p_pack_hist_addr + hw_hist_idx + 8);
91
92 tmp0_u18 = ((tmp2_u8 & ((1 << 2) - 1)) << 16) + (tmp1_u8 << 8) + tmp0_u8;
93 tmp1_u18 = ((tmp4_u8 & ((1 << 4) - 1)) << 14) + (tmp3_u8 << 6) + (tmp2_u8 >> 2);
94 tmp2_u18 = ((tmp6_u8 & ((1 << 6) - 1)) << 12) + (tmp5_u8 << 4) + (tmp4_u8 >> 4);
95 tmp3_u18 = (tmp8_u8 << 10) + (tmp7_u8 << 2) + (tmp6_u8 >> 6);
96
97 *(p_hist_local + idx + 0) = tmp0_u18;
98 *(p_hist_local + idx + 1) = tmp1_u18;
99 *(p_hist_local + idx + 2) = tmp2_u18;
100 *(p_hist_local + idx + 3) = tmp3_u18;
101 hw_hist_idx += 9;
102 }
103
104 for (idx = 0; idx < RKVOP_PQ_PREPROCESS_GLOBAL_HIST_BIN_NUMS; idx++) {
105 RK_U32 tmp0_u8, tmp1_u8, tmp2_u8, tmp3_u8;
106 RK_U32 tmp_u32;
107
108 tmp0_u8 = *(p_pack_hist_addr + hw_hist_idx + 0);
109 tmp1_u8 = *(p_pack_hist_addr + hw_hist_idx + 1);
110 tmp2_u8 = *(p_pack_hist_addr + hw_hist_idx + 2);
111 tmp3_u8 = *(p_pack_hist_addr + hw_hist_idx + 3);
112
113 tmp_u32 = (tmp3_u8 << 24) + (tmp2_u8 << 16) + (tmp1_u8 << 8) + tmp0_u8;
114 *(p_hist_global + idx + 0) = tmp_u32;
115 hw_hist_idx += 4;
116 }
117
118 return MPP_OK;
119 }
120