summaryrefslogtreecommitdiff
path: root/drivers/staging/nmf-cm/cm/engine/os_adaptation_layer/inc/os_adaptation_layer.h
blob: c9ec864795f7bccd6d334f89f7ceb3d9ff9d8ee6 (plain)
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
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
/*
 * Copyright (C) ST-Ericsson SA 2010
 * Author: Jean-Philippe FASSINO <jean-philippe.fassino@stericsson.com> for ST-Ericsson.
 * License terms: GNU General Public License (GPL) version 2.
 */
/*!
 * \brief OS Adaptation Layer API
 *
 * \defgroup CM_ENGINE_OSAL_API CM Engine OSAL (Operating System Abstraction Layer) API
 * \ingroup CM_ENGINE_MODULE
 */
#ifndef __INC_CM_OSAL_H
#define __INC_CM_OSAL_H

#include <cm/inc/cm_type.h>
#include <cm/engine/communication/inc/communication_type.h>
#include <cm/engine/component/inc/instance.h>

/*!
 * \brief Identifier of a trace channel (id in [0..255])
 * \ingroup CM_ENGINE_OSAL_API
 */
typedef t_uint8 t_nmf_trace_channel;

/*!
 * \brief Identifier of lock create by OSAL
 * \ingroup CM_ENGINE_OSAL_API
 */
typedef t_uint32 t_nmf_osal_sync_handle;

/*!
 * \brief Identifier of semaphore create by OSAL
 * \ingroup CM_ENGINE_OSAL_API
 */
typedef t_uint32 t_nmf_osal_sem_handle;

/*!
 * \brief Identifier of semaphore wait error return by semaphore OSAL API
 * \ingroup CM_ENGINE_OSAL_API
 */
typedef t_uint8 t_nmf_osal_sync_error;
#define SYNC_ERROR_TIMEOUT      ((t_nmf_osal_sync_error)-1)
#define SYNC_OK                 ((t_nmf_osal_sync_error)0)
#define SEM_TIMEOUT_NORMAL      3000
#define SEM_TIMEOUT_DEBUG       300000

/*!
 * \brief Operations used to support additionnal OS-specific debug feature
 * \ingroup CM_ENGINE_OSAL_API
 */
struct osal_debug_operations {
	void (*component_create)(t_component_instance *component);
	void (*component_destroy)(t_component_instance *component);
	void (*domain_create)(t_cm_domain_id id);
	void (*domain_destroy)(t_cm_domain_id id);
};

extern struct osal_debug_operations osal_debug_ops;

/*!
 * \brief Description of the Scheduling part of the OS Adaptation Layer
 *
 * <B>Goal:</B> Support of uplink communication path (from Media Processors to Host (ARM))
 *
 * Post a function call outside of Host CPU Interrupt mode in order to minimize ISR execution time
 * \param[in] upLayerTHIS : this one provided by user when calling CM_ENGINE_BindComponentToCMCore() (first field of the interface context) \n
 * \param[in] methodIndex : index method to be called  \n
 * \param[in] anyPtr : internal NMF marshaled parameters block (to be passed as second parameter when calling the previous pSkeleton method) \n
 * \param[in] ptrSize : size of anyPtr in bytes \n
 *
 * Called by:
 *  - CM_ProcessMpcEvent() call (shall be bound by OS integrator to HSEM IRQ)
 *
 * \ingroup CM_ENGINE_OSAL_API
 */

PUBLIC void OSAL_PostDfc(
        t_nmf_mpc2host_handle   upLayerTHIS,
        t_uint32                    methodIndex,
        t_event_params_handle       anyPtr,
        t_uint32                    ptrSize);


/*!
 * \brief Description of the Synchronization part of the OS Adaptation Layer
 *
 * <B>Goal:</B> Use by CM to protect global variable against multiple call. Interrupt and scheduler function are use when
 *       we take hardware/local semaphore. Scheduler lock functions can have empty implementation but this may
 *       impact performance (dsp waiting semaphore because host thread was preempted whereas it has already take semaphore
 *       but not yet release it).
 *
 * \return handle of the Mutex created
 *
 * Called by:
 *  - any CM API call
 *
 * \ingroup CM_ENGINE_OSAL_API
 */
PUBLIC t_nmf_osal_sync_handle OSAL_CreateLock(void);

/*!
 * \brief Description of the Synchronization part of the OS Adaptation Layer
 *
 * <B>Goal:</B> Use by CM to protect global variable against multiple call. Interrupt and scheduler function are use when
 *       we take hardware/local semaphore. Scheduler lock functions can have empty implementation but this may
 *       impact performance (dsp waiting semaphore because host thread was preempted whereas it has already take semaphore
 *       but not yet release it).
 *
 * \param[in] handle handle of the Mutex to be locked
 *
 * Called by:
 *  - any CM API call
 *
 * \ingroup CM_ENGINE_OSAL_API
 */
PUBLIC void OSAL_Lock(
        t_nmf_osal_sync_handle handle);

/*!
 * \brief Description of the Synchronization part of the OS Adaptation Layer
 *
 * <B>Goal:</B> Use by CM to protect global variable against multiple call. Interrupt and scheduler function are use when
 *       we take hardware/local semaphore. Scheduler lock functions can have empty implementation but this may
 *       impact performance (dsp waiting semaphore because host thread was preempted whereas it has already take semaphore
 *       but not yet release it).
 *
 * \param[in] handle handle of the Mutex to be unlocked
 *
 * Called by:
 *  - any CM API call
 *
 * \ingroup CM_ENGINE_OSAL_API
 */
PUBLIC void OSAL_Unlock(
        t_nmf_osal_sync_handle handle);

/*!
 * \brief Description of the Synchronization part of the OS Adaptation Layer
 *
 * <B>Goal:</B> Use by CM to protect global variable against multiple call. Interrupt and scheduler function are use when
 *       we take hardware/local semaphore. Scheduler lock functions can have empty implementation but this may
 *       impact performance (dsp waiting semaphore because host thread was preempted whereas it has already take semaphore
 *       but not yet release it).
 *
 * \param[in] handle handle of the Mutex to be destroyed
 *
 * Called by:
 *  - any CM API call
 *
 * \ingroup CM_ENGINE_OSAL_API
 */
PUBLIC void OSAL_DestroyLock(
        t_nmf_osal_sync_handle handle);

/*!
 * \brief Description of the Synchronization part of the OS Adaptation Layer
 *
 * <B>Goal:</B> Use by CM to allow to synchronize with code running on mpc side.
 *
 * \param[in] value : Initial value of semaphore.
 *
 * \return handle of the Semaphore created
 *
 * Called by:
 *  - any CM API call
 *
 * \ingroup CM_ENGINE_OSAL_API
 */
PUBLIC t_nmf_osal_sem_handle OSAL_CreateSemaphore(
        t_uint32 value);

/*!
 * \brief Description of the Synchronization part of the OS Adaptation Layer
 *
 * <B>Goal:</B> Use by CM to allow to synchronize with code running on mpc side. This function can be call under
 *       Irq context by CM.
 *
 * \param[in] handle handle of the Semaphore for which we increase value and so potentially wake up thread.
 *
 * \param[in] aCtx is a hint to indicate to os that we are in a none normal context (e.g under interruption).
 *
 * Called by:
 *  - any CM API call
 *
 * \ingroup CM_ENGINE_OSAL_API
 */
PUBLIC void OSAL_SemaphorePost(
        t_nmf_osal_sem_handle handle,
        t_uint8 aCtx);

/*!
 * \brief Description of the Synchronization part of the OS Adaptation Layer
 *
 * <B>Goal:</B> Use by CM to allow to synchronize with code running on mpc side.
 *
 * \param[in] handle of the Semaphore for which we decrease value and so potentially block current thread.
 *
 * \param[in] timeOutInMs maximun time in ms after which the block thread is wake up. In this case function return SYNC_ERROR_TIMEOUT value.
 *
 * \return error number: SYNC_ERROR_TIMEOUT in case semaphore is not release withing timeOutInMs.
 *
 * Called by:
 *  - any CM API call
 *
 * \ingroup CM_ENGINE_OSAL_API
 */
PUBLIC t_nmf_osal_sync_error OSAL_SemaphoreWaitTimed(
        t_nmf_osal_sem_handle handle,
        t_uint32 timeOutInMs);

/*!
 * \brief Description of the Synchronization part of the OS Adaptation Layer
 *
 * <B>Goal:</B> Use by CM to allow to synchronize with code running on mpc side.
 *
 * \param[in] handle handle of the Semaphore to be destroyed
 *
 * Called by:
 *  - any CM API call
 *
 * \ingroup CM_ENGINE_OSAL_API
 */
PUBLIC void OSAL_DestroySemaphore(
        t_nmf_osal_sem_handle handle);

/*!
 * \brief Description of the System Memory Allocator part of the OS Adaptation Layer
 *
 * <B>Goal:</B> Allocate CM some cacheable and bufferable memory (SDRAM) for internal usage \n
 * This memory will be accessed only by Host CPU (ARM)
 *
 * This function provide a simple, general-purpose  memory  allocation. The
 * OSAL_Alloc macro returns a pointer to a block of at least size bytes
 * suitably aligned for any use. If there  is  no  available  memory, this
 * function returns a null pointer.
 *
 * \param[in] size   size in bytes, of memory to be allocated
 * \return pointer on the beginning of the allocated memory
 *
 * Called by:
 *  - any CM API call
 *
 * \ingroup CM_ENGINE_OSAL_API
 */
PUBLIC void* OSAL_Alloc(
        t_cm_size size);

/*!
 * \brief Description of the System Memory Allocator part of the OS Adaptation Layer with memory set to zero
 *
 * Compare to \see OSAL_Alloc, same allocation is done but memory is set with zero before returning.
 *
 * \ingroup CM_ENGINE_OSAL_API
 */
PUBLIC void* OSAL_Alloc_Zero(
        t_cm_size size);

/*!
 * \brief Description of the System Memory Allocator part of the OS Adaptation Layer
 *
 * <B>Goal:</B> Free CM some cacheable and bufferable memory (SDRAM) for internal usage \n
 * This memory will be accessed only by Host CPU (ARM)
 *
 * \param[in] pHandle  pointer on the begining of the memory previously allocated
 *
 * Called by:
 *  - any CM API call
 *
 * \ingroup CM_ENGINE_OSAL_API
 */
PUBLIC void  OSAL_Free(
        void *pHandle);

/*!
 * \brief Clean data cache in DDR in order to be accessible from peripheral.
 *
 * This method must be synchronized with MMDSP Code cache attribute.
 *   Strongly Ordered -> nothing
 *   Shared device -> dsb + L2 Write buffer drain
 *   Non cacheable, Bufferable -> dsb + L2 Write buffer drain
 *   WT or WB -> Flush cache range + dsb + L2 Write buffer drain
 *
 * \ingroup CM_ENGINE_OSAL_API
 */
PUBLIC void OSAL_CleanDCache(
        t_uint32                startAddr,          //!< [in] Start data address of range to clean
        t_uint32                Size                //!< [in] Size of range to clean
        );

/*!
 * \brief Flush write buffer.
 *
 * This method must be synchronized with MMDSP Data cache attribute.
 *   Strongly Ordered -> nothing
 *   Shared device -> dsb + L2 Write buffer drain
 *   Non cacheable, Bufferable -> dsb + L2 Write buffer drain
 *
 * \ingroup CM_ENGINE_OSAL_API
 */
PUBLIC void OSAL_mb(void);

/*!
 * \brief Description of the System Memory part of the OS Adaptation Layer
 *
 * <B>Goal:</B> Copy some cacheable and bufferable memory (SDRAM) provided by a client to\n
 * internal memory.
 *
 * \param[in] dst  : pointer on the begining of the internal memory previously allocated
 * \param[in] src  : pointer on the begining of the client's memory
 * \param[in] size : The size of the data to copy
 *
 * Called by:
 *  - CM_ENGINE_PushComponent()
 *
 * \note This API is mainly provided for the OS were the client application does execute in the same
 *       address space as the CM.
 *       For example in Linux or Symbian, the client's address space is userland but the CM execute in
 *       kernel space. Thus, 'dst' is supposed to be a kernel address but src is supposed to be a user
 *       space address
 *
 * \ingroup CM_ENGINE_OSAL_API
 */
PUBLIC t_cm_error OSAL_Copy(
        void *dst,
	const void *src,
	t_cm_size size);

/*!
 * \brief Description of the internal log traces configuration of the Component Manager
 * \ingroup CM_ENGINE_OSAL_API
 */
PUBLIC void OSAL_Log(
        const char *format,
        int param1,
        int param2,
        int param3,
        int param4,
        int param5,
        int param6);

/*!
 * \brief Generate an OS-Panic. Called in from CM_ASSERT().
 * \ingroup CM_ENGINE_OSAL_API
 */
PUBLIC void OSAL_Panic(void);

/*!
 * \brief Description of the configuration of the trace features
 *
 * (trace output itself is provided by user through his custom implementation of the generic APIs)
 *
 * \ingroup CM_ENGINE_OSAL_API
 */
PUBLIC void OSAL_Write64(
        t_nmf_trace_channel channel,
        t_uint8 isTimestamped,
        t_uint64 value);

/*!
 * \brief Power enabling/disabling commands description.
 *
 * \ingroup CM_ENGINE_OSAL_API
 */
typedef enum
{
    CM_OSAL_POWER_SxA_CLOCK,     //!< SxA Power & Clock, firstParam contains Core ID
    CM_OSAL_POWER_SxA_AUTOIDLE,  //!< SxA AutoIdle, firstParam contains Core ID
    CM_OSAL_POWER_SxA_HARDWARE,  //!< SxA Hardware Power, firstParam contains Core ID
    CM_OSAL_POWER_HSEM,          //!< HSEM Power
    CM_OSAL_POWER_SDRAM,         //!< SDRAM memory, firstParam contains physical resource address, secondParam contains size
    CM_OSAL_POWER_ESRAM          //!< ESRAM memory, firstParam contains physical resource address, secondParam contains size
} t_nmf_power_resource;

/*!
 * \brief Description of the Power Management part of the OS Adaptation Layer
 *
 * Use by CM engine to disable a logical power domain  (see \ref t_nmf_power_resource)
 *
 * \ingroup CM_ENGINE_OSAL_API
 */
PUBLIC void OSAL_DisablePwrRessource(
        t_nmf_power_resource    resource,           //!< [in] Describe the domain which must be disabled
        t_uint32                firstParam,         //!< [in] Eventual first parameter to power to disable
        t_uint32                secondParam         //!< [in] Eventual second parameter to power to disable
        );

/*!
 * \brief Description of the Power Management part of the OS Adaptation Layer
 *
 * Use by CM engine to enable a logical power domain  (see \ref t_nmf_power_resource)
 *
 * \return
 *   - \ref CM_OK
 *   - \ref CM_PWR_NOT_AVAILABLE A specified power domain is not managed (see returned value in aPowerMask)
 *
 * Called by:
 *  - any CM API call
 *
 * \ingroup CM_ENGINE_OSAL_API
 */
PUBLIC t_cm_error OSAL_EnablePwrRessource(
        t_nmf_power_resource    resource,           //!< [in] Describing the domains which must be enabled
        t_uint32                firstParam,         //!< [in] Eventual first parameter to power to disable
        t_uint32                secondParam         //!< [in] Eventual second parameter to power to disable
        );


/*!
 * \brief return prcmu timer value.
 *
 * This is need for perfmeter api  (see \ref t_nmf_power_resource)
 *
 * \ingroup CM_ENGINE_OSAL_API
 */
PUBLIC t_uint64 OSAL_GetPrcmuTimer(void);

/*!
 * \brief Disable the service message handling (panic, etc)
 *
 * It must disable the handling of all service messages
 * If a service message is currently handled, it must wait till the end
 * of its managment before returning.
 *
 * \ingroup CM_ENGINE_OSAL_API
 */
PUBLIC void OSAL_DisableServiceMessages(void);

/*!
 * \brief Enable the service message handling (panic, etc)
 *
 * It enables the handling of all service messages
 *
 * \ingroup CM_ENGINE_OSAL_API
 */
PUBLIC void OSAL_EnableServiceMessages(void);

/*!
 * \brief Generate 'software' panic due to dsp crash
 *
 * We request that the os part generate a panic to notify cm users
*  that a problem occur but not dsp panic has been sent (for example
*  a dsp crash)
 *
 * \param[in] t_nmf_core_id  : core_id is the id of dsp for which we need to generate a panic.
 * \param[in] reason  : additional information. Today only 0 is valid.
 *
 * \ingroup CM_ENGINE_OSAL_API
 */
PUBLIC void OSAL_GeneratePanic(t_nmf_core_id coreId, t_uint32 reason);

extern /*const*/ t_nmf_osal_sync_handle lockHandleApi;
extern /*const*/ t_nmf_osal_sync_handle lockHandleCom;
extern /*const*/ t_nmf_osal_sem_handle semHandle;

/*!
 * \brief Take a lock before entering critical section. Can suspend current thread if lock already taken. \n
 *        Use this macro in api function. For com function use OSAL_LOCK_COM.
 *
 * \ingroup CM_ENGINE_OSAL_API
 */
#define OSAL_LOCK_API() OSAL_Lock(lockHandleApi)

/*!
 * \brief Release lock before leaving critical section.
 *
 * \ingroup CM_ENGINE_OSAL_API
 */
#define OSAL_UNLOCK_API() OSAL_Unlock((lockHandleApi))

/*!
 * \brief Take a lock before entering critical section. Can suspend current thread if lock already taken. \n
 *        Use this macro in com function. For com function use OSAL_LOCK_API.
 *
 * \ingroup CM_ENGINE_OSAL_API
 */
#define OSAL_LOCK_COM() OSAL_Lock(lockHandleCom)

/*!
 * \brief Release lock before leaving critical section.
 *
 * \ingroup CM_ENGINE_OSAL_API
 */
#define OSAL_UNLOCK_COM() OSAL_Unlock((lockHandleCom))

/*!
 * \brief Go to sleep untill post done on semaphore or timeout expire. In that case SYNC_ERROR_TIMEOUT is return.
 *
 * \ingroup CM_ENGINE_OSAL_API
 */
#define OSAL_SEMAPHORE_WAIT_TIMEOUT(semHandle) OSAL_SemaphoreWaitTimed(semHandle, (cm_PWR_GetMode() == NORMAL_PWR_MODE)?SEM_TIMEOUT_NORMAL:SEM_TIMEOUT_DEBUG)

/****************/
/* Generic part */
/****************/
t_cm_error cm_OSAL_Init(void);
void cm_OSAL_Destroy(void);

#endif /* __INC_CM_OSAL_H */