1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
|
/**
* @file
* val.c
*
* @par Project:
* MFlexVideo
*
* @par Description:
* Video Abstraction Layer API implementations
*
* @par Author:
* Jackal Chen (mtk02532)
*
* @par $Revision: #2 $
* @par $Modtime:$
* @par $Log:$
*
*/
/*=============================================================================
* Include Files
*===========================================================================*/
#include "val_types_private.h"
#include "val_api_private.h"
#include "val_log.h"
//#include "mfv_reg.h"
//#include "mfv_config.h"
#include <linux/jiffies.h>
#include <linux/sched.h>
#include <linux/wait.h>
#include <linux/time.h>
#include <linux/mm.h>
#include <linux/slab.h>
#include <linux/semaphore.h>
/*
#define MFV_LOG printk
#define MFV_LOGE printk
#define MFV_LOGD printk
*/
#define MAX_HEAP_SIZE (0x1000000)
#ifdef _6573_FPGA
#define GMC 0xC8000000
#else /* _6573_REAL_CHIP E1 address */
#define GMC 0x40000000
#endif
/*=============================================================================
* Function Body
*===========================================================================*/
VAL_RESULT_T eVideoMemAlloc(
VAL_MEMORY_T *a_prParam,
VAL_UINT32_T a_u4ParamSize
)
{
return VAL_RESULT_NO_ERROR;
}
VAL_RESULT_T eVideoMemFree(
VAL_MEMORY_T *a_prParam,
VAL_UINT32_T a_u4ParamSize
)
{
//MFV_LOGD("!!Free Mem Size:%d!!\n",a_prParam->u4MemSize);
return VAL_RESULT_NO_ERROR;
}
//mimic internal memory buffer, 128K bytes.
VAL_RESULT_T eVideoIntMemUsed(
VAL_INTMEM_T *a_prParam,
VAL_UINT32_T a_u4ParamSize
)
{
return VAL_RESULT_NO_ERROR;
}
//mimic internal memory buffer, 128K bytes.
VAL_RESULT_T eVideoIntMemAlloc(
VAL_INTMEM_T *a_prParam,
VAL_UINT32_T a_u4ParamSize
)
{
return VAL_RESULT_NO_ERROR;
}
//mimic internal memory buffer, 128K bytes.
VAL_RESULT_T eVideoIntMemFree(
VAL_INTMEM_T *a_prParam,
VAL_UINT32_T a_u4ParamSize
)
{
return VAL_RESULT_NO_ERROR;
}
VAL_RESULT_T eVideoCreateEvent(
VAL_EVENT_T *a_prParam,
VAL_UINT32_T a_u4ParamSize
)
{
wait_queue_head_t *pWaitQueue;
VAL_UINT8_T *pFlag;
pWaitQueue = (wait_queue_head_t *)kmalloc(sizeof(wait_queue_head_t), GFP_ATOMIC);
pFlag = (VAL_UINT8_T *)kmalloc(sizeof(VAL_UINT8_T), GFP_ATOMIC);
if (pWaitQueue != VAL_NULL)
{
init_waitqueue_head(pWaitQueue);
a_prParam->pvWaitQueue = (VAL_VOID_T *)pWaitQueue;
}
else
{
MFV_LOGE("[VCODEC][ERROR] Event wait Queue failed to create\n");
}
if (pFlag != VAL_NULL)
{
a_prParam->pvReserved = (VAL_VOID_T *)pFlag;
*((VAL_UINT8_T *)a_prParam->pvReserved) = VAL_FALSE;
}
else
{
MFV_LOGE("[VCODEC][ERROR] Event flag failed to create\n");
}
return VAL_RESULT_NO_ERROR;
}
VAL_RESULT_T eVideoCloseEvent(
VAL_EVENT_T *a_prParam,
VAL_UINT32_T a_u4ParamSize
)
{
wait_queue_head_t *pWaitQueue;
VAL_UINT8_T *pFlag;
pWaitQueue = (wait_queue_head_t *)a_prParam->pvWaitQueue;
pFlag = (VAL_UINT8_T *)a_prParam->pvReserved;
if (pWaitQueue)
{
kfree(pWaitQueue);
}
if (pFlag)
{
kfree(pFlag);
}
a_prParam->pvWaitQueue = VAL_NULL;
a_prParam->pvReserved = VAL_NULL;
return VAL_RESULT_NO_ERROR;
}
VAL_RESULT_T eVideoWaitEvent(
VAL_EVENT_T *a_prParam,
VAL_UINT32_T a_u4ParamSize
)
{
wait_queue_head_t *pWaitQueue;
long timeout_jiff, i4Ret;
VAL_RESULT_T status;
pWaitQueue = (wait_queue_head_t *)a_prParam->pvWaitQueue;
timeout_jiff = (a_prParam->u4TimeoutMs) * HZ / 1000;
//MFV_LOGD("[MFV]eVideoWaitEvent,a_prParam->u4TimeoutMs=%d, timeout = %ld\n",a_prParam->u4TimeoutMs,timeout_jiff);
i4Ret = wait_event_interruptible_timeout(*pWaitQueue, *((VAL_UINT8_T *)a_prParam->pvReserved)/*g_mflexvideo_interrupt_handler*/, timeout_jiff);
if (0 == i4Ret)
{
status = VAL_RESULT_INVALID_ISR;//timeout
}
else if (-ERESTARTSYS == i4Ret)
{
MFV_LOGE("[VCODEC] eVideoWaitEvent wake up by ERESTARTSYS");
status = VAL_RESULT_RESTARTSYS;
}
else if (i4Ret > 0)
{
status = VAL_RESULT_NO_ERROR;
}
else
{
MFV_LOGE("[VCODEC] eVideoWaitEvent wake up by %ld", i4Ret);
status = VAL_RESULT_NO_ERROR;
}
*((VAL_UINT8_T *)a_prParam->pvReserved) = VAL_FALSE;
return status;
}
VAL_RESULT_T eVideoSetEvent(
VAL_EVENT_T *a_prParam,
VAL_UINT32_T a_u4ParamSize
)
{
wait_queue_head_t *pWaitQueue;
//MFV_LOGD("[MFV]eVideoSetEvent\n");
pWaitQueue = (wait_queue_head_t *)a_prParam->pvWaitQueue;
if (a_prParam->pvReserved != VAL_NULL)
{
*((VAL_UINT8_T *)a_prParam->pvReserved) = VAL_TRUE;
}
else
{
MFV_LOGE("[VCODEC][ERROR]Event flag should not be null\n");
}
if (pWaitQueue != VAL_NULL)
{
wake_up_interruptible(pWaitQueue);
}
else
{
MFV_LOGE("[VCODEC][ERROR]Wait Queue should not be null\n");
}
return VAL_RESULT_NO_ERROR;
}
VAL_RESULT_T eVideoCreateMutex(
VAL_MUTEX_T *a_prParam,
VAL_UINT32_T a_u4ParamSize
)
{
struct semaphore *pLock;
pLock = (struct semaphore *)kmalloc(sizeof(struct semaphore), GFP_ATOMIC);
if (pLock != VAL_NULL)
{
a_prParam->pvMutex = (VAL_VOID_T *)pLock;
}
else
{
MFV_LOGE("[VCODEC][ERROR]Enable to create mutex!\n");
}
//init_MUTEX(pLock);
sema_init(pLock, 1);
return VAL_RESULT_NO_ERROR;
}
VAL_RESULT_T eVideoCloseMutex(
VAL_MUTEX_T *a_prParam,
VAL_UINT32_T a_u4ParamSize
)
{
if (a_prParam->pvMutex != VAL_NULL)
{
kfree(a_prParam->pvMutex);
}
a_prParam->pvMutex = VAL_NULL;
return VAL_RESULT_NO_ERROR;
}
VAL_RESULT_T eVideoWaitMutex(
VAL_MUTEX_T *a_prParam,
VAL_UINT32_T a_u4ParamSize
)
{
struct semaphore *pLock;
pLock = (struct semaphore *)a_prParam->pvMutex;
down(pLock);
return VAL_RESULT_NO_ERROR;
}
VAL_RESULT_T eVideoReleaseMutex(
VAL_MUTEX_T *a_prParam,
VAL_UINT32_T a_u4ParamSize
)
{
struct semaphore *pLock;
pLock = (struct semaphore *)a_prParam->pvMutex;
up(pLock);
return VAL_RESULT_NO_ERROR;
}
VAL_RESULT_T eVideoMemSet(
VAL_MEMORY_T *a_prParam,
VAL_UINT32_T a_u4ParamSize,
VAL_INT32_T a_u4Value,
VAL_UINT32_T a_u4Size
)
{
return VAL_RESULT_NO_ERROR;
}
VAL_RESULT_T eVideoMemCpy(
VAL_MEMORY_T *a_prParamDst,
VAL_UINT32_T a_u4ParamDstSize,
VAL_MEMORY_T *a_prParamSrc,
VAL_UINT32_T a_u4ParamSrcSize,
VAL_UINT32_T a_u4Size
)
{
return VAL_RESULT_NO_ERROR;
}
VAL_RESULT_T eVideoMemCmp(
VAL_MEMORY_T *a_prParamSrc1,
VAL_UINT32_T a_u4ParamSrc1Size,
VAL_MEMORY_T *a_prParamSrc2,
VAL_UINT32_T a_u4ParamSrc2Size,
VAL_UINT32_T a_u4Size
)
{
return VAL_RESULT_NO_ERROR;
}
VAL_RESULT_T eVideoGetTimeOfDay(
VAL_TIME_T *a_prParam,
VAL_UINT32_T a_u4ParamSize
)
{
struct timeval t1;
do_gettimeofday(&t1);
a_prParam->u4Sec = t1.tv_sec;
a_prParam->u4uSec = t1.tv_usec;
return VAL_RESULT_NO_ERROR;
}
|