xref: /OK3568_Linux_fs/external/mpp/mpp/hal/vpu/vp8d/hal_vp8d_api.c (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1 /*
2 *
3 * Copyright 2015 Rockchip Electronics Co. LTD
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
8 *
9 *      http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 */
17 #define MODULE_TAG "hal_vp8d_api"
18 
19 #include <string.h>
20 
21 #include "rk_type.h"
22 #include "mpp_hal.h"
23 #include "mpp_platform.h"
24 #include "hal_vp8d_vdpu1.h"
25 #include "hal_vp8d_vdpu2.h"
26 
hal_vp8d_reg_gen(void * hal,HalTaskInfo * task)27 static MPP_RET hal_vp8d_reg_gen (void *hal, HalTaskInfo *task)
28 {
29     VP8DHalContext_t *self = (VP8DHalContext_t *)hal;
30 
31     if (!self->hal_api.reg_gen)
32         return MPP_OK;
33 
34     return self->hal_api.reg_gen(hal, task);
35 }
36 
hal_vp8d_start(void * hal,HalTaskInfo * task)37 static MPP_RET hal_vp8d_start (void *hal, HalTaskInfo *task)
38 {
39     VP8DHalContext_t *self = (VP8DHalContext_t *)hal;
40 
41     if (!self->hal_api.start)
42         return MPP_OK;
43 
44     return self->hal_api.start(hal, task);
45 }
46 
hal_vp8d_wait(void * hal,HalTaskInfo * task)47 static MPP_RET hal_vp8d_wait (void *hal, HalTaskInfo *task)
48 {
49     VP8DHalContext_t *self = (VP8DHalContext_t *)hal;
50 
51     if (!self->hal_api.wait)
52         return MPP_OK;
53 
54     return self->hal_api.wait(hal, task);
55 }
56 
hal_vp8d_reset(void * hal)57 static MPP_RET hal_vp8d_reset (void *hal)
58 {
59     VP8DHalContext_t *self = (VP8DHalContext_t *)hal;
60 
61     if (!self->hal_api.reset)
62         return MPP_OK;
63 
64     return self->hal_api.reset(hal);;
65 }
66 
hal_vp8d_flush(void * hal)67 static MPP_RET hal_vp8d_flush (void *hal)
68 {
69     VP8DHalContext_t *self = (VP8DHalContext_t *)hal;
70 
71     if (!self->hal_api.flush)
72         return MPP_OK;
73 
74     return self->hal_api.flush(hal);
75 }
76 
hal_vp8d_control(void * hal,MpiCmd cmd_type,void * param)77 static MPP_RET hal_vp8d_control (void *hal, MpiCmd cmd_type, void *param)
78 {
79     VP8DHalContext_t *self = (VP8DHalContext_t *)hal;
80 
81     if (!self->hal_api.control)
82         return MPP_OK;
83 
84     return self->hal_api.control(hal, cmd_type, param);
85 }
86 
hal_vp8d_deinit(void * hal)87 static MPP_RET hal_vp8d_deinit (void *hal)
88 {
89     VP8DHalContext_t *self = (VP8DHalContext_t *)hal;
90 
91     if (!self->hal_api.deinit)
92         return MPP_OK;
93 
94     return self->hal_api.deinit(hal);
95 }
96 
hal_vp8d_init(void * hal,MppHalCfg * cfg)97 static MPP_RET hal_vp8d_init (void *hal, MppHalCfg *cfg)
98 {
99     VP8DHalContext_t *self = (VP8DHalContext_t *)hal;
100     MppHalApi *p_api = NULL;
101     VpuHwMode hw_mode = MODE_NULL;
102     RK_U32 hw_flag = 0;
103 
104     if (NULL == self)
105         return MPP_ERR_VALUE;
106     memset(self, 0, sizeof(VP8DHalContext_t));
107 
108     p_api = &self->hal_api;
109 
110     hw_flag = mpp_get_vcodec_type();
111     if (hw_flag & HAVE_VDPU1)
112         hw_mode = VDPU1_MODE;
113     if (hw_flag & HAVE_VDPU2)
114         hw_mode = VDPU2_MODE;
115 
116     switch (hw_mode) {
117     case VDPU2_MODE:
118         p_api->init = hal_vp8d_vdpu2_init;
119         p_api->deinit = hal_vp8d_vdpu2_deinit;
120         p_api->reg_gen = hal_vp8d_vdpu2_gen_regs;
121         p_api->start = hal_vp8d_vdpu2_start;
122         p_api->wait = hal_vp8d_vdpu2_wait;
123         p_api->reset = NULL;
124         p_api->flush = NULL;
125         p_api->control = NULL;
126         break;
127     case VDPU1_MODE:
128         p_api->init = hal_vp8d_vdpu1_init;
129         p_api->deinit = hal_vp8d_vdpu1_deinit;
130         p_api->reg_gen = hal_vp8d_vdpu1_gen_regs;
131         p_api->start = hal_vp8d_vdpu1_start;
132         p_api->wait = hal_vp8d_vdpu1_wait;
133         p_api->reset = NULL;
134         p_api->flush = NULL;
135         p_api->control = NULL;
136         break;
137     default:
138         return MPP_ERR_INIT;
139         break;
140     }
141 
142     return p_api->init (hal, cfg);
143 }
144 
145 
146 const MppHalApi hal_api_vp8d = {
147     .name = "vp8d_rkdec",
148     .type = MPP_CTX_DEC,
149     .coding = MPP_VIDEO_CodingVP8,
150     .ctx_size = sizeof(VP8DHalContext_t),
151     .flag = 0,
152     .init = hal_vp8d_init,
153     .deinit = hal_vp8d_deinit,
154     .reg_gen = hal_vp8d_reg_gen,
155     .start = hal_vp8d_start,
156     .wait = hal_vp8d_wait,
157     .reset = hal_vp8d_reset,
158     .flush = hal_vp8d_flush,
159     .control = hal_vp8d_control,
160 };
161