1 /*
2 * Copyright 2020 Rockchip Electronics Co. LTD
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17 #define MODULE_TAG "hal_vp9d_api"
18
19 #include <string.h>
20
21 #include "mpp_env.h"
22
23 #include "hal_vp9d_debug.h"
24 #include "hal_vp9d_api.h"
25 #include "hal_vp9d_ctx.h"
26 #include "hal_vp9d_rkv.h"
27 #include "hal_vp9d_vdpu34x.h"
28 #include "hal_vp9d_vdpu382.h"
29 #include "hal_vp9d_vdpu383.h"
30
31 RK_U32 hal_vp9d_debug = 0;
32
hal_vp9d_init(void * ctx,MppHalCfg * cfg)33 MPP_RET hal_vp9d_init(void *ctx, MppHalCfg *cfg)
34 {
35 MPP_RET ret = MPP_NOK;
36 HalVp9dCtx *p = (HalVp9dCtx *)ctx;
37 MppClientType client_type = VPU_CLIENT_RKVDEC;
38 RK_U32 hw_id = 0;
39
40 ret = mpp_dev_init(&cfg->dev, client_type);
41 if (ret) {
42 mpp_err("mpp_dev_init failed ret: %d\n", ret);
43 return ret;
44 }
45 cfg->hw_info = mpp_get_dec_hw_info_by_client_type(client_type);
46 p->hw_info = cfg->hw_info;
47
48 hw_id = mpp_get_client_hw_id(client_type);
49 p->dev = cfg->dev;
50 p->hw_id = hw_id;
51 p->client_type = client_type;
52 if (hw_id == HWID_VDPU383) {
53 p->api = &hal_vp9d_vdpu383;
54 cfg->support_fast_mode = 1;
55 } else if (hw_id == HWID_VDPU382_RK3528 || hw_id == HWID_VDPU382_RK3562) {
56 p->api = &hal_vp9d_vdpu382;
57 cfg->support_fast_mode = 1;
58 } else if (hw_id == HWID_VDPU34X || hw_id == HWID_VDPU38X) {
59 p->api = &hal_vp9d_vdpu34x;
60 cfg->support_fast_mode = 1;
61 if (mpp_get_soc_type() == ROCKCHIP_SOC_RK3588)
62 cfg->support_fast_mode = 0;
63 } else {
64 p->api = &hal_vp9d_rkv;
65 cfg->support_fast_mode = 0;
66 }
67
68
69 p->slots = cfg->frame_slots;
70 p->dec_cb = cfg->dec_cb;
71 p->fast_mode = cfg->cfg->base.fast_parse && cfg->support_fast_mode;
72 p->packet_slots = cfg->packet_slots;
73
74 mpp_env_get_u32("hal_vp9d_debug", &hal_vp9d_debug, 0);
75
76 ret = p->api->init(ctx, cfg);
77
78 return ret;
79 }
80
hal_vp9d_deinit(void * ctx)81 MPP_RET hal_vp9d_deinit(void *ctx)
82 {
83 MPP_RET ret = MPP_NOK;
84 HalVp9dCtx *p = (HalVp9dCtx *)ctx;
85
86 if (p && p->api && p->api->deinit)
87 ret = p->api->deinit(ctx);
88
89 if (p->dev) {
90 mpp_dev_deinit(p->dev);
91 p->dev = NULL;
92 }
93
94 return ret;
95 }
96
hal_vp9d_gen_regs(void * ctx,HalTaskInfo * task)97 MPP_RET hal_vp9d_gen_regs(void *ctx, HalTaskInfo *task)
98 {
99 MPP_RET ret = MPP_NOK;
100 HalVp9dCtx *p = (HalVp9dCtx *)ctx;
101
102 if (p && p->api && p->api->reg_gen)
103 ret = p->api->reg_gen(ctx, task);
104
105 return ret;
106 }
107
hal_vp9d_start(void * ctx,HalTaskInfo * task)108 MPP_RET hal_vp9d_start(void *ctx, HalTaskInfo *task)
109 {
110 MPP_RET ret = MPP_NOK;
111 HalVp9dCtx *p = (HalVp9dCtx *)ctx;
112
113 if (p && p->api && p->api->start)
114 ret = p->api->start(ctx, task);
115
116 return ret;
117 }
118
hal_vp9d_wait(void * ctx,HalTaskInfo * task)119 MPP_RET hal_vp9d_wait(void *ctx, HalTaskInfo *task)
120 {
121 MPP_RET ret = MPP_NOK;
122 HalVp9dCtx *p = (HalVp9dCtx *)ctx;
123
124 if (p && p->api && p->api->wait)
125 ret = p->api->wait(ctx, task);
126
127 return ret;
128 }
129
hal_vp9d_reset(void * ctx)130 MPP_RET hal_vp9d_reset(void *ctx)
131 {
132 MPP_RET ret = MPP_NOK;
133 HalVp9dCtx *p = (HalVp9dCtx *)ctx;
134
135 if (p && p->api && p->api->reset)
136 ret = p->api->reset(ctx);
137
138 return ret;
139 }
140
hal_vp9d_flush(void * ctx)141 MPP_RET hal_vp9d_flush(void *ctx)
142 {
143 MPP_RET ret = MPP_NOK;
144 HalVp9dCtx *p = (HalVp9dCtx *)ctx;
145
146 if (p && p->api && p->api->flush)
147 ret = p->api->flush(ctx);
148
149 return ret;
150 }
151
hal_vp9d_control(void * ctx,MpiCmd cmd,void * param)152 MPP_RET hal_vp9d_control(void *ctx, MpiCmd cmd, void *param)
153 {
154 MPP_RET ret = MPP_NOK;
155 HalVp9dCtx *p = (HalVp9dCtx *)ctx;
156
157 if (p && p->api && p->api->control)
158 ret = p->api->control(ctx, cmd, param);
159
160 return ret;
161 }
162
163 const MppHalApi hal_api_vp9d = {
164 .name = "vp9d_rkdec",
165 .type = MPP_CTX_DEC,
166 .coding = MPP_VIDEO_CodingVP9,
167 .ctx_size = sizeof(HalVp9dCtx),
168 .flag = 0,
169 .init = hal_vp9d_init,
170 .deinit = hal_vp9d_deinit,
171 .reg_gen = hal_vp9d_gen_regs,
172 .start = hal_vp9d_start,
173 .wait = hal_vp9d_wait,
174 .reset = hal_vp9d_reset,
175 .flush = hal_vp9d_flush,
176 .control = hal_vp9d_control,
177 };
178