xref: /rockchip-linux_mpp/mpp/hal/vpu/mpg4d/hal_m4vd_api.c (revision 437bfbeb9567cca9cd9080e3f6954aa9d6a94f18)
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_m4vd_api"
18 
19 #include <stdio.h>
20 #include <stdlib.h>
21 #include <string.h>
22 #include <dlfcn.h>
23 #include <unistd.h>
24 
25 #include "mpp_err.h"
26 #include "mpp_mem.h"
27 #include "mpp_env.h"
28 #include "mpp_debug.h"
29 #include "mpp_platform.h"
30 
31 #include "hal_mpg4d_api.h"
32 #include "hal_m4vd_com.h"
33 
34 #include "hal_m4vd_vdpu1.h"
35 #include "hal_m4vd_vdpu2.h"
36 
37 RK_U32 hal_mpg4d_debug = 1;
38 
39 /*!
40 ***********************************************************************
41 * \brief
42 *    init
43 ***********************************************************************
44 */
45 //extern "C"
hal_vpu_mpg4d_init(void * hal,MppHalCfg * cfg)46 static MPP_RET hal_vpu_mpg4d_init(void *hal, MppHalCfg *cfg)
47 {
48     hal_mpg4_ctx *p_hal = (hal_mpg4_ctx *)hal;
49     MppHalApi *p_api = NULL;
50     VpuHwMode hw_mode = MODE_NULL;
51     RK_U32 hw_flag = 0;
52 
53     if (NULL == p_hal)
54         return MPP_ERR_VALUE;
55 
56     memset(p_hal, 0, sizeof(hal_mpg4_ctx));
57     p_api = &p_hal->hal_api;
58 
59     hw_flag = mpp_get_vcodec_type();
60     mpp_assert(hw_flag & (HAVE_VDPU2 | HAVE_VDPU1));
61 
62     if (hw_flag & HAVE_VDPU2)
63         hw_mode = VDPU2_MODE;
64     if (hw_flag & HAVE_VDPU1)
65         hw_mode = VDPU1_MODE;
66 
67     switch (hw_mode) {
68     case VDPU2_MODE:
69         p_api->init = vdpu2_mpg4d_init;
70         p_api->deinit = vdpu2_mpg4d_deinit;
71         p_api->reg_gen = vdpu2_mpg4d_gen_regs;
72         p_api->start = vdpu2_mpg4d_start;
73         p_api->wait = vdpu2_mpg4d_wait;
74         p_api->reset = NULL;
75         p_api->flush = NULL;
76         p_api->control = NULL;
77         break;
78     case VDPU1_MODE:
79         p_api->init = vdpu1_mpg4d_init;
80         p_api->deinit = vdpu1_mpg4d_deinit;
81         p_api->reg_gen = vdpu1_mpg4d_gen_regs;
82         p_api->start = vdpu1_mpg4d_start;
83         p_api->wait = vdpu1_mpg4d_wait;
84         p_api->reset = NULL;
85         p_api->flush = NULL;
86         p_api->control = NULL;
87         break;
88     default:
89         return MPP_ERR_INIT;
90         break;
91     }
92 
93     return p_api->init (hal, cfg);
94 }
95 
96 /*!
97 ***********************************************************************
98 * \brief
99 *    deinit
100 ***********************************************************************
101 */
102 //extern "C"
hal_vpu_mpg4d_deinit(void * hal)103 static MPP_RET hal_vpu_mpg4d_deinit(void *hal)
104 {
105     hal_mpg4_ctx *p_hal = (hal_mpg4_ctx *)hal;
106 
107     return p_hal->hal_api.deinit(hal);
108 }
109 
110 /*!
111 ***********************************************************************
112 * \brief
113 *    generate register
114 ***********************************************************************
115 */
116 //extern "C"
hal_vpu_mpg4d_gen_regs(void * hal,HalTaskInfo * task)117 static MPP_RET hal_vpu_mpg4d_gen_regs(void *hal, HalTaskInfo *task)
118 {
119     hal_mpg4_ctx *p_hal = (hal_mpg4_ctx *)hal;
120 
121     return p_hal->hal_api.reg_gen(hal, task);
122 }
123 
124 /*!
125 ***********************************************************************
126 * \brief h
127 *    start hard
128 ***********************************************************************
129 */
130 //extern "C"
hal_vpu_mpg4d_start(void * hal,HalTaskInfo * task)131 static MPP_RET hal_vpu_mpg4d_start(void *hal, HalTaskInfo *task)
132 {
133     hal_mpg4_ctx *p_hal = (hal_mpg4_ctx *)hal;
134 
135     return p_hal->hal_api.start(hal, task);
136 }
137 
138 /*!
139 ***********************************************************************
140 * \brief
141 *    wait hard
142 ***********************************************************************
143 */
144 //extern "C"
hal_vpu_mpg4d_wait(void * hal,HalTaskInfo * task)145 static MPP_RET hal_vpu_mpg4d_wait(void *hal, HalTaskInfo *task)
146 {
147     hal_mpg4_ctx *p_hal = (hal_mpg4_ctx *)hal;
148 
149     return p_hal->hal_api.wait(hal, task);
150 }
151 
152 const MppHalApi hal_api_mpg4d = {
153     .name = "mpg4d_vpu",
154     .type = MPP_CTX_DEC,
155     .coding = MPP_VIDEO_CodingMPEG4,
156     .ctx_size = sizeof(hal_mpg4_ctx),
157     .flag = 0,
158     .init = hal_vpu_mpg4d_init,
159     .deinit = hal_vpu_mpg4d_deinit,
160     .reg_gen = hal_vpu_mpg4d_gen_regs,
161     .start = hal_vpu_mpg4d_start,
162     .wait = hal_vpu_mpg4d_wait,
163     .reset = NULL,
164     .flush = NULL,
165     .control = NULL,
166 };
167