blob: 8e8aa1ab4104a3a0a7035bde1d1651490b20f5fe [file] [log] [blame]
rjw6c1fd8f2022-11-30 14:33:01 +08001/*****************************************************************************
2* Copyright Statement:
3* --------------------
4* This software is protected by Copyright and the information contained
5* herein is confidential. The software may not be copied and the information
6* contained herein may not be used or disclosed except with the written
7* permission of MediaTek Inc. (C) 2005
8*
9* BY OPENING THIS FILE, BUYER HEREBY UNEQUIVOCALLY ACKNOWLEDGES AND AGREES
10* THAT THE SOFTWARE/FIRMWARE AND ITS DOCUMENTATIONS ("MEDIATEK SOFTWARE")
11* RECEIVED FROM MEDIATEK AND/OR ITS REPRESENTATIVES ARE PROVIDED TO BUYER ON
12* AN "AS-IS" BASIS ONLY. MEDIATEK EXPRESSLY DISCLAIMS ANY AND ALL WARRANTIES,
13* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTIES OF
14* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR NONINFRINGEMENT.
15* NEITHER DOES MEDIATEK PROVIDE ANY WARRANTY WHATSOEVER WITH RESPECT TO THE
16* SOFTWARE OF ANY THIRD PARTY WHICH MAY BE USED BY, INCORPORATED IN, OR
17* SUPPLIED WITH THE MEDIATEK SOFTWARE, AND BUYER AGREES TO LOOK ONLY TO SUCH
18* THIRD PARTY FOR ANY WARRANTY CLAIM RELATING THERETO. MEDIATEK SHALL ALSO
19* NOT BE RESPONSIBLE FOR ANY MEDIATEK SOFTWARE RELEASES MADE TO BUYER'S
20* SPECIFICATION OR TO CONFORM TO A PARTICULAR STANDARD OR OPEN FORUM.
21*
22* BUYER'S SOLE AND EXCLUSIVE REMEDY AND MEDIATEK'S ENTIRE AND CUMULATIVE
23* LIABILITY WITH RESPECT TO THE MEDIATEK SOFTWARE RELEASED HEREUNDER WILL BE,
24* AT MEDIATEK'S OPTION, TO REVISE OR REPLACE THE MEDIATEK SOFTWARE AT ISSUE,
25* OR REFUND ANY SOFTWARE LICENSE FEES OR SERVICE CHARGE PAID BY BUYER TO
26* MEDIATEK FOR SUCH MEDIATEK SOFTWARE AT ISSUE.
27*
28* THE TRANSACTION CONTEMPLATED HEREUNDER SHALL BE CONSTRUED IN ACCORDANCE
29* WITH THE LAWS OF THE STATE OF CALIFORNIA, USA, EXCLUDING ITS CONFLICT OF
30* LAWS PRINCIPLES. ANY DISPUTES, CONTROVERSIES OR CLAIMS ARISING THEREOF AND
31* RELATED THERETO SHALL BE SETTLED BY ARBITRATION IN SAN FRANCISCO, CA, UNDER
32* THE RULES OF THE INTERNATIONAL CHAMBER OF COMMERCE (ICC).
33*
34*****************************************************************************/
35
36/*****************************************************************************
37 *
38 * Filename:
39 * ---------
40 * kal_hrt_api.h
41 *
42 * Project:
43 * --------
44 * Maui_Software
45 *
46 * Description:
47 * ------------
48 * This file provides KAL Hard Realtime Domain API prototypes
49 *
50 * Author:
51 * -------
52 * -------
53 *
54 *============================================================================
55 * HISTORY
56 * Below this line, this part is controlled by PVCS VM. DO NOT MODIFY!!
57 *------------------------------------------------------------------------------
58 * removed!
59 * removed!
60 * removed!
61 *
62 * removed!
63 * removed!
64 * removed!
65 * removed!
66 *
67 * removed!
68 * removed!
69 * removed!
70 *
71 * removed!
72 * removed!
73 * removed!
74 *
75 * removed!
76 * removed!
77 * removed!
78 *
79 * removed!
80 * removed!
81 * removed!
82 * removed!
83 *
84 * removed!
85 * removed!
86 * removed!
87 *
88 * removed!
89 * removed!
90 * removed!
91 *
92****************************************************************************/
93
94#ifndef _KAL_HRT_API_H
95#define _KAL_HRT_API_H
96
97
98#include "kal_general_types.h"
99#include "kal_public_defs.h"
100#include "kal_hrt_defs.h"
101#include "kal_atomic_api.h"
102#include "kal_inline_api.h"
103#include "mips_ia_utils_public.h"
104
105#ifdef __cplusplus
106extern "C" {
107#endif
108
109#if 0
110/* under construction !*/
111/* under construction !*/
112/* under construction !*/
113/* under construction !*/
114/* under construction !*/
115/* under construction !*/
116/* under construction !*/
117/* under construction !*/
118/* under construction !*/
119#endif
120
121/*******************************************************************************
122 * Category 1 : Only Used for HRT Domain
123 * Normal Domain uses following APIs will fatal
124 ******************************************************************************/
125
126/*******************************************************************************
127 * FUNCTION
128 * kal_hrt_tc_create_workqueue
129 * DESCRIPTION
130 * create workqueue for LISR
131 * PARAMETERS
132 * wq_name: [IN] name of workqueue variable
133 * wq_size: [IN] size of workqueue
134 * RETURNS
135 * N/A
136 ******************************************************************************/
137#define kal_hrt_tc_create_workqueue_isrc(wq_name, wq_size) HRT_CQUEUE(wq_name, wq_size)
138
139/*******************************************************************************
140 * FUNCTION
141 * kal_hrt_register_mt_q
142 * DESCRIPTION
143 * register workqueue for LISR
144 * PARAMETERS
145 * irqvector: [IN] irq vector id
146 * wq_id: [IN] KAL_Q0 for common queue (Only for Gen93)
147 * KAL_Q1 for child workqueue of TC2
148 * KAL_Q2 for child workqueue of TC3
149 * wq: [IN] address of workqueue
150 * RETURNS
151 * Failed: fatal error handling.
152 ******************************************************************************/
153void kal_hrt_register_mt_q_isrc(kal_uint32 irqvector, kal_workqueueid wq_id, void *wq);
154
155/*******************************************************************************
156 * FUNCTION
157 * kal_hrt_tc_consume_work
158 * DESCRIPTION
159 * Consume work from workqueue(s) until queue(s) are empty
160 * ONLY parent TC (TC1) can consume work
161 * PARAMETERS
162 * wq_mask: [IN] KAL_Q1_MASK for child workqueue of TC2
163 * KAL_Q2_MASK for child workqueue of TC3
164 * KAL_Q1_Q2_MASK
165 * RETURNS
166 * Failed: fatal error handling.
167 ******************************************************************************/
168void kal_hrt_tc_consume_work(kal_workqueue_mask wq_mask);
169
170/*******************************************************************************
171 * FUNCTION
172 * kal_hrt_tc_dispatch_work
173 * DESCRIPTION
174 * dispatch work to workqueue
175 * PARAMETERS
176 * wq_id: [IN] KAL_Q0 for common queue (Only for Gen93)
177 * KAL_Q1 for child workqueue of TC2
178 * KAL_Q2 for child workqueue of TC3
179 * func_ptr: [IN] function pointer for TC executes
180 * func_param: [IN] function parameter
181 * RETURNS
182 * Failed: fatal error handling.
183 ******************************************************************************/
184void kal_hrt_tc_dispatch_work(kal_workqueueid wq_id, void *func_ptr,
185 void *func_param);
186
187/*******************************************************************************
188 * FUNCTION
189 * kal_hrt_tc_set_queue_nested_irq_shared
190 * DESCRIPTION
191 * set work queue as shared for nesting interrupt
192 * PARAMETERS
193 * wq_id: [IN] KAL_Q1 for child workqueue of TC2
194 * KAL_Q2 for child workqueue of TC3
195 * shared: [IN] shared or not shared
196 * RETURNS
197 * Failed: fatal error handling.
198 * NOTE: If queue is not set back to not shared before IRQ returns, an assert is triggered
199 ******************************************************************************/
200void kal_hrt_tc_set_queue_nested_irq_shared(kal_workqueueid wq_id, kal_bool shared);
201
202/*******************************************************************************
203 * FUNCTION
204 * kal_hrt_tc_dispatch_work
205 * DESCRIPTION
206 * dispatch work to workqueue of irq currently nested
207 * PARAMETERS
208 * wq_id: [IN] KAL_Q0 for common queue (Only for Gen93)
209 * KAL_Q1 for child workqueue of TC2
210 * KAL_Q2 for child workqueue of TC3
211 * func_ptr: [IN] function pointer for TC executes
212 * func_param: [IN] function parameter
213 * irq_id: [IN] irq id of nested irq which queue to dispatch
214 * RETURNS
215 * KAL_TRUE or KAL_FALSE
216 ******************************************************************************/
217kal_bool kal_hrt_tc_dispatch_work_nested_irq(kal_workqueueid wq_id, void *func_ptr,
218 void *func_param, kal_uint32 irq_id);
219
220/*******************************************************************************
221 * FUNCTION
222 * kal_hrt_tc_checkpoint
223 * DESCRIPTION
224 * check whether workqueues are empty, may be blocked or return directly
225 * PARAMETERS
226 * wq_mask: [IN] KAL_Q0_MASK for common queue (Only for Gen93)
227 * KAL_Q1_MASK for child workqueue of TC2
228 * KAL_Q2_MASK for child workqueue of TC3
229 * KAL_Q0_Q1_MASK (Only for Gen93)
230 * KAL_Q0_Q2_MASK (Only for Gen93)
231 * KAL_Q1_Q2_MASK
232 * KAL_Q0_Q1_Q2_MASK (Only for Gen93)
233 * timeout: [IN] KAL_NO_WAIT, KAL_INFINITE_WAIT
234 * RETURNS
235 * [OUT] KAL_Q0_EXECUTE: common queue not finish (Only for Gen93)
236 * KAL_Q1_EXECUTE: child workqueue of TC2 not finish
237 * KAL_Q2_EXECUTE: child workqueue of TC3 not finish
238 * KAL_Q0_Q1_EXECUTE: common queue and child workqueue of TC2 not finish (Only for Gen93)
239 * KAL_Q0_Q2_EXECUTE: common queue and child workqueue of TC3 not finish (Only for Gen93)
240 * KAL_Q1_Q2_EXECUTE: child workqueues of TC2/3 not finish
241 * KAL_ALL_Q_FINISH: all queried workqueues are finish
242 * Failed: fatal error handling.
243 ******************************************************************************/
244kal_uint32 kal_hrt_tc_checkpoint(kal_workqueue_mask wq_mask, kal_uint32 timeout);
245
246/*******************************************************************************
247 * FUNCTION
248 * kal_hrt_activate_hisr_index
249 * DESCRIPTION
250 * activate specified HISR for HRT domain LISR
251 * PARAMETERS
252 * ext_hisr: [IN] HISR index.
253 * RETURNS
254 * N/A
255 ******************************************************************************/
256#if defined(__MTK_TARGET__)
257extern void kal_hrt_activate_hisr_index(kal_hisr ext_hisr) DECLARE_MIPS16;
258#else
259extern void kal_hrt_activate_hisr_index(kal_hisr ext_hisr);
260#endif
261
262/*******************************************************************************
263 * Category 2 : Used for HRT and Normal Domain
264 * Following APIs are designed for HRT Domain used.
265 * Normal Domain uses them won't cause fatal.
266 ******************************************************************************/
267
268/*************************************************************************
269 * FUNCTION
270 * kal_hrt_SaveAndSetIRQMask
271 * DESCRIPTION
272 * This function disables IRQ and returnes the original IRQ setting
273 * PARAMETERS
274 * N/A
275 * RETURNS
276 * the original IRQ setting.
277 *************************************************************************/
278kal_uint32 kal_hrt_SaveAndSetIRQMask(void);
279
280/*************************************************************************
281 * FUNCTION
282 * kal_hrt_RestoreIRQMask
283 * DESCRIPTION
284 * This function restores IRQ without Qbit checking
285 * PARAMETERS
286 * restored IRQ setting.
287 * RETURNS
288 * N/A
289 *************************************************************************/
290void kal_hrt_RestoreIRQMask(kal_uint32 irq);
291
292/*******************************************************************************
293 * FUNCTION
294 * kal_hrt_take_itc_lock
295 * DESCRIPTION
296 * take kal itc lock based on itc id. Will mask interrupts
297 * PARAMETERS
298 * itc_id: itc lock id to be taken
299 * wait_mode: KAL_NO_WAIT or KAL_INFINITE_WAIT
300 * RETURNS
301 * KAL_SUCCESS or KAL_ITC_NOT_AVAILABLE.
302 ******************************************************************************/
303kal_status kal_hrt_take_itc_lock(kal_itc_lock_id itc_id, kal_int32 wait_mode);
304
305/*******************************************************************************
306 * FUNCTION
307 * kal_hrt_give_itc_lock
308 * DESCRIPTION
309 * give kal itc lock based on itc id. Will restore interrupts based on old state
310 * PARAMETERS
311 * itc_id: itc lock id to be given
312 * RETURNS
313 * none
314 ******************************************************************************/
315void kal_hrt_give_itc_lock(kal_itc_lock_id itc_id);
316
317/*******************************************************************************
318 * FUNCTION
319 * kal_hrt_rcu_create
320 * DESCRIPTION
321 * create a RCU from the given memory pool
322 * PARAMETERS
323 * buff_addr: [IN] the address of the memory pool.
324 * allocated_buff_size: [IN] the size of the memory pool.
325 * buff_size: [IN] the size of a block.
326 * reserved: [IN] reserved, fill 0.
327 * RETURNS
328 * Successful: the created RCU id.
329 * Failed: fatal error handling.
330 ******************************************************************************/
331kalcc_rcuid kal_hrt_rcu_create(void *buff_addr, kal_uint32 allocated_buff_size,
332 kal_uint32 buff_size, kal_uint32 reserved);
333
334/*******************************************************************************
335 * FUNCTION
336 * kal_hrt_rcu_get_free_buff
337 * DESCRIPTION
338 * get a free block for updating
339 * PARAMETERS
340 * id: [IN] the target RCU id.
341 * RETURNS
342 * Successful: the address of the free block.
343 * Failed: fatal error handling.
344 ******************************************************************************/
345void *kal_hrt_rcu_get_free_buff(kalcc_rcuid id);
346
347/*******************************************************************************
348 * FUNCTION
349 * kal_hrt_rcu_commit_data
350 * DESCRIPTION
351 * mark this block as latest block ready for ready
352 * PARAMETERS
353 * data: [IN] the address of the updated block.
354 * RETURNS
355 * Successful: KAL_SUCCESS.
356 * Failed: fatal error handling.
357 ******************************************************************************/
358kal_status kal_hrt_rcu_commit_data(void *data);
359
360/*******************************************************************************
361 * FUNCTION
362 * kal_hrt_rcu_get_read_lock
363 * DESCRIPTION
364 * get the latest updated block of the RCU
365 * PARAMETERS
366 * id: [IN] the target RCU id.
367 * RETURNS
368 * Successful: the address of the latest updated block.
369 * Failed: fatal error handling.
370 ******************************************************************************/
371void *kal_hrt_rcu_get_read_lock(kalcc_rcuid id);
372
373/*******************************************************************************
374 * FUNCTION
375 * kal_hrt_rcu_free_read_lock
376 * DESCRIPTION
377 * free the block for writer to update
378 * PARAMETERS
379 * data: [IN] the address of the block.
380 * RETURNS
381 * Successful: KAL_SUCCESS.
382 * Failed: fatal error handling.
383 ******************************************************************************/
384kal_status kal_hrt_rcu_free_read_lock(void *data);
385
386
387/*******************************************************************************
388 * Category 3 : Common with kal_public_api.h
389 ******************************************************************************/
390#if defined(KAL_ON_OSCAR)
391#define kal_snprintf _snprintf
392#else
393#define kal_snprintf snprintf
394#endif
395
396#define kal_sprintf sprintf
397extern kal_char *kal_strtok_r(kal_char *string, const kal_char *seperators,
398 kal_char **ppLast);
399#define kal_toWCHAR(asciiString) L##asciiString
400extern char *kal_itoa(int value, char *str, int radix);
401
402extern int kal_wstrlen(const WCHAR *wstr);
403extern WCHAR *kal_wstrcpy(WCHAR *to, const WCHAR *from);
404extern WCHAR *kal_wstrncpy(WCHAR *to, const WCHAR *from, int n);
405extern int kal_wstrcmp(const WCHAR *s1, const WCHAR *s2);
406extern int kal_wstrncmp(const WCHAR *s1, const WCHAR *s2, int n);
407extern WCHAR *kal_wstrcat(WCHAR *s1, const WCHAR *s2);
408extern WCHAR *kal_wstrncat(WCHAR *s1, const WCHAR *s2, int n);
409extern WCHAR *kal_wstrchr(const WCHAR *s, int c);
410extern WCHAR *kal_wstrrchr(const WCHAR *str, int ch);
411
412extern int kal_dchar_strlen(const char *wstr);
413extern char *kal_dchar_strcpy(char *to, const char *from);
414extern char *kal_dchar_strncpy(char *to, const char *from, int n);
415extern int kal_dchar_strcmp(const char *s1, const char *s2);
416extern int kal_dchar_strncmp(const char *s1, const char *s2, int n);
417extern char *kal_dchar_strcat(char *s1, const char *s2);
418extern char *kal_dchar_strncat(char *s1, const char *s2, int n);
419extern char *kal_dchar_strchr(const char *s, int c);
420extern char *kal_dchar_strrchr(const char *str, int ch);
421extern void kal_dchar2char(WCHAR *outstr, char *tostr);
422extern void kal_wsprintf(WCHAR *outstr, char *fmt, ...);
423
424extern kal_bool kal_query_systemInit(void);
425extern kal_uint32 kal_get_current_lisr_ID(void);
426
427
428/*******************************************************************************
429 * <GROUP Functions>
430 *
431 * FUNCTION
432 * kal_get_curent_domain
433 * DESCRIPTION
434 * return current domain
435 * RETURNS
436 * enum kal_domain: KAL_DOMAIN_NORMAL/KAL_DOMAIN_HRT/KAL_DOMAIN_CHRT
437 ******************************************************************************/
438#if defined(__MTK_TARGET__)
439#if !defined(__kal_get_current_domain__)
440#define __kal_get_current_domain__
441#if defined(__MIPS_I7200__)
442#define kal_get_current_domain() (miu_mfc0(MIU_C0_KSCRATCH4) & 0x3)
443#endif /* defined(__MIPS_I7200__) */
444#endif /* __kal_get_current_domain__ */
445#else /* __MTK_TARGET__ */
446#define kal_get_current_domain() 0
447#endif /* __MTK_TARGET__ */
448
449/*******************************************************************************
450 * <GROUP Functions>
451 *
452 * FUNCTION
453 * kal_if_hrt_domain
454 * DESCRIPTION
455 * Identify if current VPE is HRT domain
456 * PARAMETERS
457 * VPE ID
458 * RETURNS
459 * KAL_TRUE if current VPE is HRT domain
460 ******************************************************************************/
461#if !defined(__MTK_TARGET__)
462#define kal_get_domain(vpe_id) 0
463#define kal_if_hrt_domain(vpe_id) 0
464#endif /* __MTK_TARGET__ */
465
466extern kal_bool kal_if_hisr(void);
467
468#if defined(__MTK_TARGET__)
469#if !defined(__kal_if_lisr__)
470#define __kal_if_lisr__
471#define kal_if_lisr() (miu_mfc0(MIU_C0_USERLOCAL) > 0)
472#endif
473#else
474extern kal_bool kal_if_lisr(void);
475#endif
476
477/* NOTE: this is not public API. DO NOT use it outside kal */
478extern kal_bool kal_hrt_if_lisr_mt(void);
479
480extern kal_uint32 kal_get_systicks(void);
481extern kal_uint32 kal_secs_to_ticks(kal_uint32 secs);
482extern kal_uint32 kal_secs_to_ticks_real(kal_uint32 secs);
483extern kal_uint32 kal_milli_secs_to_ticks(kal_uint32 milli_secs);
484extern kal_uint32 kal_milli_secs_to_ticks_real(kal_uint32 milli_secs);
485extern kal_uint32 kal_ticks_to_secs(kal_uint32 ticks);
486extern kal_uint32 kal_ticks_to_secs_real(kal_uint32 ticks);
487extern kal_uint32 kal_ticks_to_milli_secs(kal_uint32 ticks);
488extern kal_uint32 kal_ticks_to_milli_secs_real(kal_uint32 ticks);
489
490#include "kal_ex_api.h"
491
492#ifdef __cplusplus
493}
494#endif
495
496#endif /* _KAL_HRT_API_H */