xref: /OK3568_Linux_fs/external/mpp/mpp/hal/vpu/jpegd/hal_jpegd_api.c (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1 /*
2  * Copyright 2017 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_jpegd_api"
18 
19 #include <string.h>
20 
21 #include "mpp_env.h"
22 #include "mpp_debug.h"
23 #include "mpp_common.h"
24 #include "osal_2str.h"
25 
26 #include "mpp_hal.h"
27 #include "mpp_platform.h"
28 #include "hal_jpegd_base.h"
29 #include "hal_jpegd_vdpu2.h"
30 #include "hal_jpegd_vdpu1.h"
31 #include "hal_jpegd_rkv.h"
32 
hal_jpegd_reg_gen(void * hal,HalTaskInfo * task)33 static MPP_RET hal_jpegd_reg_gen(void *hal, HalTaskInfo *task)
34 {
35     JpegdHalCtx *self = (JpegdHalCtx *)hal;
36     return self->hal_api.reg_gen (hal, task);
37 }
38 
hal_jpegd_start(void * hal,HalTaskInfo * task)39 static MPP_RET hal_jpegd_start(void *hal, HalTaskInfo *task)
40 {
41     JpegdHalCtx *self = (JpegdHalCtx *)hal;
42     return self->hal_api.start (hal, task);
43 }
44 
hal_jpegd_wait(void * hal,HalTaskInfo * task)45 static MPP_RET hal_jpegd_wait(void *hal, HalTaskInfo *task)
46 {
47     JpegdHalCtx *self = (JpegdHalCtx *)hal;
48     return self->hal_api.wait (hal, task);
49 }
50 
hal_jpegd_reset(void * hal)51 static MPP_RET hal_jpegd_reset(void *hal)
52 {
53     JpegdHalCtx *self = (JpegdHalCtx *)hal;
54     return self->hal_api.reset (hal);
55 }
56 
hal_jpegd_flush(void * hal)57 static MPP_RET hal_jpegd_flush(void *hal)
58 {
59     JpegdHalCtx *self = (JpegdHalCtx *)hal;
60     return self->hal_api.flush (hal);
61 }
62 
hal_jpegd_control(void * hal,MpiCmd cmd_type,void * param)63 static MPP_RET hal_jpegd_control(void *hal, MpiCmd cmd_type, void *param)
64 {
65     JpegdHalCtx *self = (JpegdHalCtx *)hal;
66     return self->hal_api.control (hal, cmd_type, param);
67 }
68 
hal_jpegd_deinit(void * hal)69 static MPP_RET hal_jpegd_deinit(void *hal)
70 {
71     JpegdHalCtx *self = (JpegdHalCtx *)hal;
72     return self->hal_api.deinit (hal);
73 }
74 
hal_jpegd_init(void * hal,MppHalCfg * cfg)75 static MPP_RET hal_jpegd_init(void *hal, MppHalCfg *cfg)
76 {
77     JpegdHalCtx *self = (JpegdHalCtx *)hal;
78     MppHalApi *p_api = NULL;
79     MppClientType client_type = VPU_CLIENT_BUTT;
80     MppDecBaseCfg *base = &cfg->cfg->base;
81     RK_S32 hw_type = -1;
82     RK_U32 hw_flag = 0;
83 
84     if (NULL == self)
85         return MPP_ERR_VALUE;
86 
87     memset(self, 0, sizeof(JpegdHalCtx));
88 
89     p_api = &self->hal_api;
90 
91     hw_flag = mpp_get_vcodec_type();
92 
93     if (mpp_check_soc_cap(base->type, base->coding))
94         hw_type = base->hw_type;
95 
96     if (hw_type > 0) {
97         if (hw_flag & (1 << hw_type)) {
98             mpp_log("init with %s hw\n", strof_client_type(hw_type));
99             client_type = hw_type;
100         } else
101             mpp_err_f("invalid hw_type %d with vcodec_type %08x\n",
102                       hw_type, hw_flag);
103     }
104 
105     if (client_type == VPU_CLIENT_BUTT) {
106         if (hw_flag & HAVE_VDPU2)
107             client_type = VPU_CLIENT_VDPU2;
108         if (hw_flag & HAVE_VDPU1)
109             client_type = VPU_CLIENT_VDPU1;
110         if (hw_flag & HAVE_JPEG_DEC)
111             client_type = VPU_CLIENT_JPEG_DEC;
112     }
113 
114     mpp_env_get_u32("jpegd_mode", &client_type, client_type);
115 
116     switch (client_type) {
117     case VPU_CLIENT_VDPU2 :
118     case VPU_CLIENT_VDPU2_PP : {
119         p_api->init = hal_jpegd_vdpu2_init;
120         p_api->deinit = hal_jpegd_vdpu2_deinit;
121         p_api->reg_gen = hal_jpegd_vdpu2_gen_regs;
122         p_api->start = hal_jpegd_vdpu2_start;
123         p_api->wait = hal_jpegd_vdpu2_wait;
124         p_api->reset = hal_jpegd_vdpu2_reset;
125         p_api->flush = hal_jpegd_vdpu2_flush;
126         p_api->control = hal_jpegd_vdpu2_control;
127     } break;
128     case VPU_CLIENT_VDPU1 :
129     case VPU_CLIENT_VDPU1_PP : {
130         p_api->init = hal_jpegd_vdpu1_init;
131         p_api->deinit = hal_jpegd_vdpu1_deinit;
132         p_api->reg_gen = hal_jpegd_vdpu1_gen_regs;
133         p_api->start = hal_jpegd_vdpu1_start;
134         p_api->wait = hal_jpegd_vdpu1_wait;
135         p_api->reset = hal_jpegd_vdpu1_reset;
136         p_api->flush = hal_jpegd_vdpu1_flush;
137         p_api->control = hal_jpegd_vdpu1_control;
138     } break;
139     case VPU_CLIENT_JPEG_DEC : {
140         p_api->init = hal_jpegd_rkv_init;
141         p_api->deinit = hal_jpegd_rkv_deinit;
142         p_api->reg_gen = hal_jpegd_rkv_gen_regs;
143         p_api->start = hal_jpegd_rkv_start;
144         p_api->wait = hal_jpegd_rkv_wait;
145         p_api->reset = NULL;
146         p_api->flush = NULL;
147         p_api->control = hal_jpegd_rkv_control;
148     } break;
149     default : {
150         return MPP_ERR_INIT;
151     } break;
152     }
153 
154     {
155         // report hw_info to parser
156         const MppSocInfo *info = mpp_get_soc_info();
157         RK_U32 i;
158 
159         for (i = 0; i < MPP_ARRAY_ELEMS(info->dec_caps); i++) {
160             if (info->dec_caps[i] && info->dec_caps[i]->type == client_type) {
161                 cfg->hw_info = info->dec_caps[i];
162                 break;
163             }
164         }
165     }
166 
167     return p_api->init(hal, cfg);
168 }
169 
170 const MppHalApi hal_api_jpegd = {
171     .name = "jpegd",
172     .type = MPP_CTX_DEC,
173     .coding = MPP_VIDEO_CodingMJPEG,
174     .ctx_size = sizeof(JpegdHalCtx),
175     .flag = 0,
176     .init = hal_jpegd_init,
177     .deinit = hal_jpegd_deinit,
178     .reg_gen = hal_jpegd_reg_gen,
179     .start = hal_jpegd_start,
180     .wait = hal_jpegd_wait,
181     .reset = hal_jpegd_reset,
182     .flush = hal_jpegd_flush,
183     .control = hal_jpegd_control,
184 };
185