xref: /OK3568_Linux_fs/external/mpp/mpp/hal/rkdec/vp9d/hal_vp9d_api.c (revision 4882a59341e53eb6f0b4789bf948001014eff981)
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 
30 RK_U32 hal_vp9d_debug = 0;
31 
hal_vp9d_init(void * ctx,MppHalCfg * cfg)32 MPP_RET hal_vp9d_init(void *ctx, MppHalCfg *cfg)
33 {
34     MPP_RET ret = MPP_NOK;
35     HalVp9dCtx *p = (HalVp9dCtx *)ctx;
36     MppClientType client_type = VPU_CLIENT_RKVDEC;
37     RK_U32 hw_id = 0;
38 
39     ret = mpp_dev_init(&cfg->dev, client_type);
40     if (ret) {
41         mpp_err("mpp_dev_init failed ret: %d\n", ret);
42         return ret;
43     }
44 
45     hw_id = mpp_get_client_hw_id(client_type);
46     p->dev = cfg->dev;
47     p->hw_id = hw_id;
48     p->client_type = client_type;
49     if (hw_id == HWID_VDPU382_RK3528 || hw_id == HWID_VDPU382_RK3562) {
50         p->api = &hal_vp9d_vdpu382;
51         cfg->support_fast_mode = 1;
52     } else if (hw_id == HWID_VDPU34X || hw_id == HWID_VDPU38X) {
53         p->api = &hal_vp9d_vdpu34x;
54         cfg->support_fast_mode = 1;
55         if (mpp_get_soc_type() == ROCKCHIP_SOC_RK3588)
56             cfg->cfg->status.hal_task_count = 2;
57     } else {
58         p->api = &hal_vp9d_rkv;
59         cfg->support_fast_mode = 0;
60     }
61 
62 
63     p->slots = cfg->frame_slots;
64     p->dec_cb = cfg->dec_cb;
65     p->fast_mode = cfg->cfg->base.fast_parse && cfg->support_fast_mode;
66     p->packet_slots = cfg->packet_slots;
67 
68     mpp_env_get_u32("hal_vp9d_debug", &hal_vp9d_debug, 0);
69 
70     ret = p->api->init(ctx, cfg);
71 
72     return ret;
73 }
74 
hal_vp9d_deinit(void * ctx)75 MPP_RET hal_vp9d_deinit(void *ctx)
76 {
77     MPP_RET ret = MPP_NOK;
78     HalVp9dCtx *p = (HalVp9dCtx *)ctx;
79 
80     if (p && p->api && p->api->deinit)
81         ret = p->api->deinit(ctx);
82 
83     if (p->dev) {
84         mpp_dev_deinit(p->dev);
85         p->dev = NULL;
86     }
87 
88     return ret;
89 }
90 
hal_vp9d_gen_regs(void * ctx,HalTaskInfo * task)91 MPP_RET hal_vp9d_gen_regs(void *ctx, HalTaskInfo *task)
92 {
93     MPP_RET ret = MPP_NOK;
94     HalVp9dCtx *p = (HalVp9dCtx *)ctx;
95 
96     if (p && p->api && p->api->reg_gen)
97         ret = p->api->reg_gen(ctx, task);
98 
99     return ret;
100 }
101 
hal_vp9d_start(void * ctx,HalTaskInfo * task)102 MPP_RET hal_vp9d_start(void *ctx, HalTaskInfo *task)
103 {
104     MPP_RET ret = MPP_NOK;
105     HalVp9dCtx *p = (HalVp9dCtx *)ctx;
106 
107     if (p && p->api && p->api->start)
108         ret = p->api->start(ctx, task);
109 
110     return ret;
111 }
112 
hal_vp9d_wait(void * ctx,HalTaskInfo * task)113 MPP_RET hal_vp9d_wait(void *ctx, HalTaskInfo *task)
114 {
115     MPP_RET ret = MPP_NOK;
116     HalVp9dCtx *p = (HalVp9dCtx *)ctx;
117 
118     if (p && p->api && p->api->wait)
119         ret = p->api->wait(ctx, task);
120 
121     return ret;
122 }
123 
hal_vp9d_reset(void * ctx)124 MPP_RET hal_vp9d_reset(void *ctx)
125 {
126     MPP_RET ret = MPP_NOK;
127     HalVp9dCtx *p = (HalVp9dCtx *)ctx;
128 
129     if (p && p->api && p->api->reset)
130         ret = p->api->reset(ctx);
131 
132     return ret;
133 }
134 
hal_vp9d_flush(void * ctx)135 MPP_RET hal_vp9d_flush(void *ctx)
136 {
137     MPP_RET ret = MPP_NOK;
138     HalVp9dCtx *p = (HalVp9dCtx *)ctx;
139 
140     if (p && p->api && p->api->flush)
141         ret = p->api->flush(ctx);
142 
143     return ret;
144 }
145 
hal_vp9d_control(void * ctx,MpiCmd cmd,void * param)146 MPP_RET hal_vp9d_control(void *ctx, MpiCmd cmd, void *param)
147 {
148     MPP_RET ret = MPP_NOK;
149     HalVp9dCtx *p = (HalVp9dCtx *)ctx;
150 
151     if (p && p->api && p->api->control)
152         ret = p->api->control(ctx, cmd, param);
153 
154     return ret;
155 }
156 
157 const MppHalApi hal_api_vp9d = {
158     .name = "vp9d_rkdec",
159     .type = MPP_CTX_DEC,
160     .coding = MPP_VIDEO_CodingVP9,
161     .ctx_size = sizeof(HalVp9dCtx),
162     .flag = 0,
163     .init = hal_vp9d_init,
164     .deinit = hal_vp9d_deinit,
165     .reg_gen = hal_vp9d_gen_regs,
166     .start = hal_vp9d_start,
167     .wait = hal_vp9d_wait,
168     .reset = hal_vp9d_reset,
169     .flush = hal_vp9d_flush,
170     .control = hal_vp9d_control,
171 };
172