1 /* Copyright Statement:
3 * This software/firmware and related documentation ("MediaTek Software") are
4 * protected under relevant copyright laws. The information contained herein
5 * is confidential and proprietary to MediaTek Inc. and/or its licensors.
6 * Without the prior written permission of MediaTek inc. and/or its licensors,
7 * any reproduction, modification, use or disclosure of MediaTek Software,
8 * and information contained herein, in whole or in part, shall be strictly prohibited.
10 * MediaTek Inc. (C) 2010. All rights reserved.
12 * BY OPENING THIS FILE, RECEIVER HEREBY UNEQUIVOCALLY ACKNOWLEDGES AND AGREES
13 * THAT THE SOFTWARE/FIRMWARE AND ITS DOCUMENTATIONS ("MEDIATEK SOFTWARE")
14 * RECEIVED FROM MEDIATEK AND/OR ITS REPRESENTATIVES ARE PROVIDED TO RECEIVER ON
15 * AN "AS-IS" BASIS ONLY. MEDIATEK EXPRESSLY DISCLAIMS ANY AND ALL WARRANTIES,
16 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTIES OF
17 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR NONINFRINGEMENT.
18 * NEITHER DOES MEDIATEK PROVIDE ANY WARRANTY WHATSOEVER WITH RESPECT TO THE
19 * SOFTWARE OF ANY THIRD PARTY WHICH MAY BE USED BY, INCORPORATED IN, OR
20 * SUPPLIED WITH THE MEDIATEK SOFTWARE, AND RECEIVER AGREES TO LOOK ONLY TO SUCH
21 * THIRD PARTY FOR ANY WARRANTY CLAIM RELATING THERETO. RECEIVER EXPRESSLY ACKNOWLEDGES
22 * THAT IT IS RECEIVER'S SOLE RESPONSIBILITY TO OBTAIN FROM ANY THIRD PARTY ALL PROPER LICENSES
23 * CONTAINED IN MEDIATEK SOFTWARE. MEDIATEK SHALL ALSO NOT BE RESPONSIBLE FOR ANY MEDIATEK
24 * SOFTWARE RELEASES MADE TO RECEIVER'S SPECIFICATION OR TO CONFORM TO A PARTICULAR
25 * STANDARD OR OPEN FORUM. RECEIVER'S SOLE AND EXCLUSIVE REMEDY AND MEDIATEK'S ENTIRE AND
26 * CUMULATIVE LIABILITY WITH RESPECT TO THE MEDIATEK SOFTWARE RELEASED HEREUNDER WILL BE,
27 * AT MEDIATEK'S OPTION, TO REVISE OR REPLACE THE MEDIATEK SOFTWARE AT ISSUE,
28 * OR REFUND ANY SOFTWARE LICENSE FEES OR SERVICE CHARGE PAID BY RECEIVER TO
29 * MEDIATEK FOR SUCH MEDIATEK SOFTWARE AT ISSUE.
31 * The following software/firmware and/or related documentation ("MediaTek Software")
32 * have been modified by MediaTek Inc. All revisions are subject to any receiver's
33 * applicable license agreements with MediaTek Inc.
38 \brief Declaration of library functions
40 Any definitions in this file will be shared among GLUE Layer and internal Driver Stack.
43 /*******************************************************************************
44 * Copyright (c) 2009 MediaTek Inc.
46 * All rights reserved. Copying, compilation, modification, distribution
47 * or any other use whatsoever of this material is strictly prohibited
48 * except in accordance with a Software License Agreement with
50 ********************************************************************************
53 /*******************************************************************************
56 * BY OPENING THIS FILE, BUYER HEREBY UNEQUIVOCALLY ACKNOWLEDGES AND
57 * AGREES THAT THE SOFTWARE/FIRMWARE AND ITS DOCUMENTATIONS ("MEDIATEK
58 * SOFTWARE") RECEIVED FROM MEDIATEK AND/OR ITS REPRESENTATIVES ARE
59 * PROVIDED TO BUYER ON AN "AS-IS" BASIS ONLY. MEDIATEK EXPRESSLY
60 * DISCLAIMS ANY AND ALL WARRANTIES, EXPRESS OR IMPLIED, INCLUDING BUT NOT
61 * LIMITED TO THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
62 * PARTICULAR PURPOSE OR NONINFRINGEMENT. NEITHER DOES MEDIATEK PROVIDE
63 * ANY WARRANTY WHATSOEVER WITH RESPECT TO THE SOFTWARE OF ANY THIRD PARTY
64 * WHICH MAY BE USED BY, INCORPORATED IN, OR SUPPLIED WITH THE MEDIATEK
65 * SOFTWARE, AND BUYER AGREES TO LOOK ONLY TO SUCH THIRD PARTY FOR ANY
66 * WARRANTY CLAIM RELATING THERETO. MEDIATEK SHALL ALSO NOT BE RESPONSIBLE
67 * FOR ANY MEDIATEK SOFTWARE RELEASES MADE TO BUYER'S SPECIFICATION OR TO
68 * CONFORM TO A PARTICULAR STANDARD OR OPEN FORUM.
70 * BUYER'S SOLE AND EXCLUSIVE REMEDY AND MEDIATEK'S ENTIRE AND CUMULATIVE
71 * LIABILITY WITH RESPECT TO THE MEDIATEK SOFTWARE RELEASED HEREUNDER WILL
72 * BE, AT MEDIATEK'S OPTION, TO REVISE OR REPLACE THE MEDIATEK SOFTWARE AT
73 * ISSUE, OR REFUND ANY SOFTWARE LICENSE FEES OR SERVICE CHARGE PAID BY
74 * BUYER TO MEDIATEK FOR SUCH MEDIATEK SOFTWARE AT ISSUE.
76 * THE TRANSACTION CONTEMPLATED HEREUNDER SHALL BE CONSTRUED IN ACCORDANCE
77 * WITH THE LAWS OF THE STATE OF CALIFORNIA, USA, EXCLUDING ITS CONFLICT
78 * OF LAWS PRINCIPLES. ANY DISPUTES, CONTROVERSIES OR CLAIMS ARISING
79 * THEREOF AND RELATED THERETO SHALL BE SETTLED BY ARBITRATION IN SAN
80 * FRANCISCO, CA, UNDER THE RULES OF THE INTERNATIONAL CHAMBER OF COMMERCE
82 ********************************************************************************
86 /*******************************************************************************
87 * C O M P I L E R F L A G S
88 ********************************************************************************
91 /*******************************************************************************
93 ********************************************************************************
98 /*******************************************************************************
99 * E X T E R N A L R E F E R E N C E S
100 ********************************************************************************
102 #include "osal_linux.h"
105 /*******************************************************************************
107 ********************************************************************************
112 /*******************************************************************************
114 ********************************************************************************
120 /*******************************************************************************
121 * P U B L I C D A T A
122 ********************************************************************************
125 /*******************************************************************************
126 * P R I V A T E D A T A
127 ********************************************************************************
134 /*******************************************************************************
135 * F U N C T I O N D E C L A R A T I O N S
136 ********************************************************************************
142 /*******************************************************************************
144 ********************************************************************************
147 /*string operations*/
148 UINT32 osal_strlen(const char *str)
153 INT32 osal_strcmp(const char *dst, const char *src)
155 return strcmp(dst, src);
158 INT32 osal_strncmp(const char *dst, const char *src, UINT32 len)
160 return strncmp(dst, src, len);
163 char * osal_strcpy(char *dst, const char *src)
165 return strcpy(dst, src);
168 char * osal_strncpy(char *dst, const char *src, UINT32 len)
170 return strncpy(dst, src, len);
174 char * osal_strcat(char *dst, const char *src)
176 return strcat(dst, src);
179 char * osal_strncat(char *dst, const char *src, UINT32 len)
181 return strncat(dst, src, len);
184 char * osal_strchr(const char *str, UINT8 c)
186 return strchr(str, c);
190 char * osal_strsep(char **str, const char *c)
192 return strsep(str, c);
196 LONG osal_strtol(const char *str, char **c, UINT32 adecimal)
198 return simple_strtol(str, c, adecimal);
201 INT32 osal_snprintf(char *buf, UINT32 len, const char*fmt, ...)
206 /*va_start(args, fmt);*/
208 /*iRet = snprintf(buf, len, fmt, args);*/// TODO: [FixMe][GeorgeKuo] BUG?
209 iRet = vsnprintf(buf, len, fmt, args);
215 INT32 osal_print(const char *str, ...)
218 char tempString[DBG_LOG_STR_SIZE];
221 vsnprintf(tempString, DBG_LOG_STR_SIZE, str, args);
224 printk("%s",tempString);
230 INT32 osal_dbg_print(const char *str, ...)
233 char tempString[DBG_LOG_STR_SIZE];
236 vsnprintf(tempString, DBG_LOG_STR_SIZE, str, args);
239 printk(KERN_DEBUG "%s",tempString);
244 INT32 osal_err_print(const char *str, ...)
247 char tempString[DBG_LOG_STR_SIZE];
250 vsnprintf(tempString, DBG_LOG_STR_SIZE, str, args);
253 printk(KERN_ERR "%s",tempString);
258 INT32 osal_info_print(const char *str, ...)
261 char tempString[DBG_LOG_STR_SIZE];
264 vsnprintf(tempString, DBG_LOG_STR_SIZE, str, args);
267 printk(KERN_INFO "%s",tempString);
272 INT32 osal_warn_print(const char *str, ...)
275 char tempString[DBG_LOG_STR_SIZE];
278 vsnprintf(tempString, DBG_LOG_STR_SIZE, str, args);
281 printk(KERN_WARNING "%s",tempString);
286 INT32 osal_loud_print(const char *str, ...)
289 char tempString[DBG_LOG_STR_SIZE];
292 vsnprintf(tempString, DBG_LOG_STR_SIZE, str, args);
295 printk(KERN_DEBUG "%s",tempString);
300 EXPORT_SYMBOL(osal_dbg_print);
301 EXPORT_SYMBOL(osal_err_print);
302 EXPORT_SYMBOL(osal_info_print);
303 EXPORT_SYMBOL(osal_warn_print);
304 EXPORT_SYMBOL(osal_loud_print);
307 INT32 osal_dbg_assert(INT32 expr, const char *file, INT32 line)
310 printk("%s (%d)\n", file, line);
312 #ifdef CFG_COMMON_GPIO_DBG_PIN
314 mt_set_gpio_out(GPIO70, GPIO_OUT_ZERO);
315 printk("toggle GPIO70\n");
317 mt_set_gpio_out(GPIO70, GPIO_OUT_ONE);
326 INT32 osal_dbg_assert_aee(const char *module, const char *detail_description){
327 osal_err_print("[WMT-ASSERT]""[E][Module]:%s, [INFO]%s\n", module, detail_description);
337 INT32 osal_sprintf(char *str, const char *format, ...)
342 va_start(args, format);
343 iRet = vsnprintf(str, DBG_LOG_STR_SIZE, format, args);
349 VOID* osal_malloc(UINT32 size)
351 return vmalloc(size);
355 VOID osal_vfree(const VOID *dst)
360 VOID osal_kfree(const VOID *dst)
365 VOID* osal_memset(VOID *buf, INT32 i, UINT32 len)
367 return memset(buf, i, len);
371 VOID* osal_memcpy(VOID *dst, const VOID *src, UINT32 len)
373 return memcpy(dst, src, len);
377 INT32 osal_memcmp(const VOID *buf1, const VOID *buf2, UINT32 len)
379 return memcmp(buf1, buf2, len);
382 VOID* osal_kzalloc_sleep(UINT32 size)
384 return kzalloc(size,GFP_KERNEL);
387 VOID* osal_kzalloc_unsleep(UINT32 size)
389 return kzalloc(size,GFP_ATOMIC);
394 *OSAL layer Thread Opeartion releated APIs
400 P_OSAL_THREAD pThread
403 //pThread->pThread = NULL; /* [FIXME] why? */
406 pThread->pThread = (struct task_struct *)kthread_create(pThread->pThreadFunc,
407 pThread->pThreadData,
408 pThread->threadName);
409 if (NULL == pThread->pThread) {
421 P_OSAL_THREAD pThread
424 if (pThread->pThread) {
425 wake_up_process((struct task_struct *)pThread->pThread);
435 P_OSAL_THREAD pThread
439 if ( (pThread) && (pThread->pThread) ) {
440 iRet = kthread_stop((struct task_struct *)pThread->pThread);
441 //pThread->pThread = NULL;
449 osal_thread_should_stop (
450 P_OSAL_THREAD pThread
453 if ( (pThread) && (pThread->pThread) ) {
454 return kthread_should_stop();
463 osal_thread_wait_for_event (
464 P_OSAL_THREAD pThread,
466 P_OSAL_EVENT_CHECKER pChecker
469 /* P_DEV_WMT pDevWmt;*/
471 if ( (pThread) && (pThread->pThread) && (pEvent) && (pChecker)) {
472 /* pDevWmt = (P_DEV_WMT)(pThread->pThreadData);*/
473 return wait_event_interruptible((*(wait_queue_head_t *)pEvent->pWaitQueue),
474 (/*!RB_EMPTY(&pDevWmt->rActiveOpQ) ||*/ osal_thread_should_stop(pThread) || (*pChecker)(pThread)));
480 osal_thread_destroy (
481 P_OSAL_THREAD pThread
484 if (pThread && (pThread->pThread)) {
485 kthread_stop((struct task_struct *)pThread->pThread);
486 pThread->pThread = NULL;
492 *OSAL layer Signal Opeartion releated APIs
495 *wait for signal timerout
503 P_OSAL_SIGNAL pSignal
507 //pSignal->pComp = NULL;
508 pSignal->pComp = kzalloc(sizeof(struct completion),GFP_KERNEL);
509 if (!pSignal->pComp){
510 osal_info_print("%s:completion memory allocate fail!\n",__func__);
513 init_completion((struct completion *)pSignal->pComp);
522 osal_wait_for_signal (
523 P_OSAL_SIGNAL pSignal
527 wait_for_completion_interruptible((struct completion *)pSignal->pComp);
536 osal_wait_for_signal_timeout (
537 P_OSAL_SIGNAL pSignal
540 /* return wait_for_completion_interruptible_timeout(&pSignal->comp, msecs_to_jiffies(pSignal->timeoutValue));*/
541 /* [ChangeFeature][George] gps driver may be closed by -ERESTARTSYS.
542 * Avoid using *interruptible" version in order to complete our jobs, such
543 * as function off gracefully.
545 return wait_for_completion_timeout((struct completion *)pSignal->pComp, msecs_to_jiffies(pSignal->timeoutValue));
550 P_OSAL_SIGNAL pSignal
553 // TODO:[FixMe][GeorgeKuo]: DO sanity check here!!!
554 if(pSignal && pSignal->pComp){
555 complete((struct completion *)pSignal->pComp);
566 P_OSAL_SIGNAL pSignal
569 // TODO:[FixMe][GeorgeKuo]: DO sanity check here!!!
573 kfree(pSignal->pComp);
574 pSignal->pComp = NULL;
576 pSignal->timeoutValue = 0;
587 *OSAL layer Event Opeartion releated APIs
590 *wait for signal timerout
596 INT32 osal_event_init (
600 //pEvent->pWaitQueue = NULL; /* [FIXME] why? */
601 pEvent->pWaitQueue = kzalloc(sizeof(wait_queue_head_t),GFP_KERNEL);
602 if (!pEvent->pWaitQueue){
603 osal_info_print("%s:waitqueue memory allocate fail!\n",__func__);
606 init_waitqueue_head((wait_queue_head_t *)pEvent->pWaitQueue);
611 INT32 osal_wait_for_event(
613 INT32 (*condition)(PVOID),
617 return wait_event_interruptible((*(wait_queue_head_t *)pEvent->pWaitQueue), condition(cond_pa));
620 INT32 osal_wait_for_event_timeout(
622 INT32 (*condition)(PVOID),
626 return wait_event_interruptible_timeout((*(wait_queue_head_t *)pEvent->pWaitQueue), condition(cond_pa), msecs_to_jiffies(pEvent->timeoutValue));
629 INT32 osal_trigger_event(
634 wake_up_interruptible((wait_queue_head_t *)pEvent->pWaitQueue);
643 if (pEvent->pWaitQueue){
644 kfree(pEvent->pWaitQueue);
645 pEvent->pWaitQueue = NULL;
650 LONG osal_wait_for_event_bit_set(P_OSAL_EVENT pEvent, PULONG pState, UINT32 bitOffset)
652 UINT32 ms = pEvent->timeoutValue;
655 return wait_event_interruptible_timeout((*(wait_queue_head_t *)pEvent->pWaitQueue), test_bit(bitOffset, pState), msecs_to_jiffies(ms));
659 return wait_event_interruptible((*(wait_queue_head_t *)pEvent->pWaitQueue), test_bit(bitOffset, pState));
664 LONG osal_wait_for_event_bit_clr(P_OSAL_EVENT pEvent, PULONG pState, UINT32 bitOffset)
666 UINT32 ms = pEvent->timeoutValue;
669 return wait_event_interruptible_timeout((*(wait_queue_head_t *)pEvent->pWaitQueue), !test_bit(bitOffset, pState), msecs_to_jiffies(ms));
673 return wait_event_interruptible((*(wait_queue_head_t *)pEvent->pWaitQueue), !test_bit(bitOffset, pState));
679 *bit test and set/clear operations APIs
683 #if OS_BIT_OPS_SUPPORT
684 #define osal_bit_op_lock(x)
685 #define osal_bit_op_unlock(x)
688 INT32 osal_bit_op_lock(P_OSAL_UNSLEEPABLE_LOCK pLock)
694 INT32 osal_bit_op_unlock(P_OSAL_UNSLEEPABLE_LOCK pLock)
700 INT32 osal_clear_bit(UINT32 bitOffset, P_OSAL_BIT_OP_VAR pData)
702 osal_bit_op_lock(&(pData->opLock));
703 clear_bit(bitOffset, &pData->data);
704 osal_bit_op_unlock(&(pData->opLock));
708 INT32 osal_set_bit(UINT32 bitOffset, P_OSAL_BIT_OP_VAR pData)
710 osal_bit_op_lock(&(pData->opLock));
711 set_bit(bitOffset, &pData->data);
712 osal_bit_op_unlock(&(pData->opLock));
716 INT32 osal_test_bit(UINT32 bitOffset, P_OSAL_BIT_OP_VAR pData)
719 osal_bit_op_lock(&(pData->opLock));
720 iRet = test_bit(bitOffset, &pData->data);
721 osal_bit_op_unlock(&(pData->opLock));
725 INT32 osal_test_and_clear_bit(UINT32 bitOffset, P_OSAL_BIT_OP_VAR pData)
728 osal_bit_op_lock(&(pData->opLock));
729 iRet = test_and_clear_bit(bitOffset, &pData->data);
730 osal_bit_op_unlock(&(pData->opLock));
735 INT32 osal_test_and_set_bit(UINT32 bitOffset, P_OSAL_BIT_OP_VAR pData)
738 osal_bit_op_lock(&(pData->opLock));
739 iRet = test_and_set_bit(bitOffset, &pData->data);
740 osal_bit_op_unlock(&(pData->opLock));
746 *tiemr operations APIs
755 INT32 osal_timer_create(P_OSAL_TIMER pTimer)
757 struct timer_list *timer = NULL;
758 pTimer->pTimer = kzalloc(sizeof(struct timer_list),GFP_KERNEL);
759 if (!pTimer->pTimer){
760 osal_info_print("%s:timer memory allocate fail!\n",__func__);
763 timer = (struct timer_list *)pTimer->pTimer;
765 timer->function = pTimer->timeoutHandler;
766 timer->data = (unsigned long)pTimer->timeroutHandlerData;
769 INT32 osal_timer_start(P_OSAL_TIMER pTimer, UINT32 ms)
772 struct timer_list *timer = (struct timer_list *)pTimer->pTimer;
773 timer->expires = jiffies + msecs_to_jiffies(ms);
778 INT32 osal_timer_stop(P_OSAL_TIMER pTimer)
780 struct timer_list *timer = (struct timer_list *)pTimer->pTimer;
785 INT32 osal_timer_stop_sync(P_OSAL_TIMER pTimer)
787 struct timer_list *timer = (struct timer_list *)pTimer->pTimer;
788 del_timer_sync(timer);
792 INT32 osal_timer_modify(P_OSAL_TIMER pTimer, UINT32 ms)
794 mod_timer((struct timer_list *)pTimer->pTimer, jiffies + msecs_to_jiffies(ms));
798 INT32 osal_timer_delete(P_OSAL_TIMER pTimer)
801 kfree(pTimer->pTimer);
802 pTimer->pTimer = NULL;
807 INT32 _osal_fifo_init(OSAL_FIFO *pFifo, UINT8 *buf, UINT32 size)
809 struct kfifo *fifo = NULL;
812 if (!pFifo || pFifo->pFifoBody)
814 printk (KERN_ERR "pFifo must be !NULL, pFifo->pFifoBody must be NULL\n");
815 printk (KERN_ERR "pFifo(0x%p), pFifo->pFifoBody(0x%p)\n", pFifo, pFifo->pFifoBody);
819 pFifo->fifoSpinlock = NULL;
821 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2,6,33))
822 pFifo->fifoSpinlock = kzalloc(sizeof(spinlock_t),GFP_ATOMIC);
823 if (!pFifo->fifoSpinlock){
824 osal_info_print("%s:fifo spinlock allocate memory fail!",__func__);
827 spin_lock_init((spinlock_t *)pFifo->fifoSpinlock);
828 fifo = kfifo_alloc(size, /*GFP_KERNEL*/GFP_ATOMIC, (spinlock_t *)pFifo->fifoSpinlock);
838 fifo = kzalloc(sizeof(struct kfifo), GFP_ATOMIC);
841 /*fifo's buffer is not ready, we allocate automatically*/
842 ret = kfifo_alloc(fifo, size, /*GFP_KERNEL*/GFP_ATOMIC);
846 if (is_power_of_2(size))
848 kfifo_init(fifo, buf, size);
859 pFifo->pFifoBody = fifo;
860 return (ret < 0) ? (-1) : (0);
863 INT32 _osal_fifo_deinit(OSAL_FIFO *pFifo)
865 struct kfifo *fifo = NULL;
867 if (!pFifo || !pFifo->pFifoBody)
869 printk("%s:pFifo = NULL or pFifo->pFifoBody = NULL, error\n", __func__);
873 fifo = (struct kfifo *)pFifo->pFifoBody;
880 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2,6,33))
881 if (pFifo->fifoSpinlock)
883 kfree(pFifo->fifoSpinlock);
884 pFifo->fifoSpinlock = NULL;
890 INT32 _osal_fifo_size(OSAL_FIFO *pFifo)
892 struct kfifo *fifo = NULL;
895 if (!pFifo || !pFifo->pFifoBody)
897 printk("%s:pFifo = NULL or pFifo->pFifoBody = NULL, error\n", __func__);
901 fifo = (struct kfifo *)pFifo->pFifoBody;
905 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2,6,33))
908 ret = kfifo_size(fifo);
916 /*returns unused bytes in fifo*/
917 INT32 _osal_fifo_avail_size(OSAL_FIFO *pFifo)
919 struct kfifo *fifo = NULL;
922 if (!pFifo || !pFifo->pFifoBody)
924 printk("%s:pFifo = NULL or pFifo->pFifoBody = NULL, error\n", __func__);
928 fifo = (struct kfifo *)pFifo->pFifoBody;
932 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2,6,33))
933 ret = fifo->size - kfifo_len(fifo);
935 ret = kfifo_avail(fifo);
942 /*returns used bytes in fifo*/
943 INT32 _osal_fifo_len(OSAL_FIFO *pFifo)
945 struct kfifo *fifo = NULL;
948 if (!pFifo || !pFifo->pFifoBody)
950 printk("%s:pFifo = NULL or pFifo->pFifoBody = NULL, error\n", __func__);
954 fifo = (struct kfifo *)pFifo->pFifoBody;
958 ret = kfifo_len(fifo);
964 INT32 _osal_fifo_is_empty(OSAL_FIFO *pFifo)
966 struct kfifo *fifo = NULL;
969 if (!pFifo || !pFifo->pFifoBody)
971 printk("%s:pFifo = NULL or pFifo->pFifoBody = NULL, error\n", __func__);
975 fifo = (struct kfifo *)pFifo->pFifoBody;
979 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2,6,33))
980 ret = (fifo->in == fifo->out);
982 ret = kfifo_is_empty(fifo);
989 INT32 _osal_fifo_is_full(OSAL_FIFO *pFifo)
991 struct kfifo *fifo = NULL;
994 if (!pFifo || !pFifo->pFifoBody)
996 printk("%s:pFifo = NULL or pFifo->pFifoBody = NULL, error\n", __func__);
1000 fifo = (struct kfifo *)pFifo->pFifoBody;
1004 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2,6,33))
1005 ret = (fifo->size == _osal_fifo_len(pFifo));
1007 ret = kfifo_is_full(fifo);
1014 INT32 _osal_fifo_data_in(OSAL_FIFO *pFifo, const VOID *buf, UINT32 len)
1016 struct kfifo *fifo = NULL;
1019 if (!pFifo || !pFifo->pFifoBody)
1021 printk("%s:pFifo = NULL or pFifo->pFifoBody = NULL, error\n", __func__);
1025 fifo = (struct kfifo *)pFifo->pFifoBody;
1027 if (fifo && buf && (len <= _osal_fifo_avail_size(pFifo)))
1029 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2,6,33))
1030 ret = kfifo_put(fifo, buf, len);
1032 ret = kfifo_in(fifo, buf, len);
1038 printk("%s: kfifo_in, error, len = %d, _osal_fifo_avail_size = %d, buf=%p\n",
1039 __func__, len, _osal_fifo_avail_size(pFifo), buf);
1047 INT32 _osal_fifo_data_out(OSAL_FIFO *pFifo, void *buf, UINT32 len)
1049 struct kfifo *fifo = NULL;
1052 if (!pFifo || !pFifo->pFifoBody)
1054 printk("%s:pFifo = NULL or pFifo->pFifoBody = NULL, error\n", __func__);
1058 fifo = (struct kfifo *)pFifo->pFifoBody;
1060 if (fifo && buf && (len <= _osal_fifo_len(pFifo)))
1062 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2,6,33))
1063 ret = kfifo_get(fifo, buf, len);
1065 ret = kfifo_out(fifo, buf, len);
1070 printk("%s: kfifo_out, error, len = %d, osal_fifo_len = %d, buf=%p\n",
1071 __func__, len, _osal_fifo_len(pFifo), buf);
1079 INT32 _osal_fifo_reset(OSAL_FIFO *pFifo)
1081 struct kfifo *fifo = NULL;
1083 if (!pFifo || !pFifo->pFifoBody)
1085 printk("%s:pFifo = NULL or pFifo->pFifoBody = NULL, error\n", __func__);
1089 fifo = (struct kfifo *)pFifo->pFifoBody;
1099 INT32 osal_fifo_init(P_OSAL_FIFO pFifo, UINT8 *buffer, UINT32 size)
1103 printk("%s:pFifo = NULL, error\n", __func__);
1107 pFifo->FifoInit = _osal_fifo_init;
1108 pFifo->FifoDeInit = _osal_fifo_deinit;
1109 pFifo->FifoSz = _osal_fifo_size;
1110 pFifo->FifoAvailSz = _osal_fifo_avail_size;
1111 pFifo->FifoLen = _osal_fifo_len;
1112 pFifo->FifoIsEmpty = _osal_fifo_is_empty;
1113 pFifo->FifoIsFull = _osal_fifo_is_full;
1114 pFifo->FifoDataIn = _osal_fifo_data_in;
1115 pFifo->FifoDataOut = _osal_fifo_data_out;
1116 pFifo->FifoReset = _osal_fifo_reset;
1118 if (NULL != pFifo->pFifoBody)
1120 printk("%s:Becasue pFifo room is avialable, we clear the room and allocate them again.\n", __func__);
1121 pFifo->FifoDeInit(pFifo->pFifoBody);
1122 pFifo->pFifoBody = NULL;
1125 pFifo->FifoInit(pFifo, buffer, size);
1130 VOID osal_fifo_deinit(P_OSAL_FIFO pFifo)
1134 pFifo->FifoDeInit(pFifo);
1138 printk("%s:pFifo = NULL, error\n", __func__);
1140 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2,6,33))
1144 if (pFifo->pFifoBody)
1146 kfree(pFifo->pFifoBody);
1151 INT32 osal_fifo_reset(P_OSAL_FIFO pFifo)
1155 return pFifo->FifoReset(pFifo);
1159 printk("%s:pFifo = NULL, error\n", __func__);
1164 UINT32 osal_fifo_in(P_OSAL_FIFO pFifo, PUINT8 buffer, UINT32 size)
1168 return pFifo->FifoDataIn(pFifo, buffer, size);
1172 printk("%s:pFifo = NULL, error\n", __func__);
1177 UINT32 osal_fifo_out(P_OSAL_FIFO pFifo, PUINT8 buffer, UINT32 size)
1181 return pFifo->FifoDataOut(pFifo, buffer, size);
1185 printk("%s:pFifo = NULL, error\n", __func__);
1190 UINT32 osal_fifo_len(P_OSAL_FIFO pFifo)
1194 return pFifo->FifoLen(pFifo);
1198 printk("%s:pFifo = NULL, error\n", __func__);
1203 UINT32 osal_fifo_sz(P_OSAL_FIFO pFifo)
1207 return pFifo->FifoSz(pFifo);
1211 printk("%s:pFifo = NULL, error\n", __func__);
1216 UINT32 osal_fifo_avail(P_OSAL_FIFO pFifo)
1220 return pFifo->FifoAvailSz(pFifo);
1224 printk("%s:pFifo = NULL, error\n", __func__);
1229 UINT32 osal_fifo_is_empty(P_OSAL_FIFO pFifo)
1233 return pFifo->FifoIsEmpty(pFifo);
1237 printk("%s:pFifo = NULL, error\n", __func__);
1242 UINT32 osal_fifo_is_full(P_OSAL_FIFO pFifo)
1246 return pFifo->FifoIsFull(pFifo);
1250 printk("%s:pFifo = NULL, error\n", __func__);
1255 INT32 osal_wake_lock_init(P_OSAL_WAKE_LOCK pLock)
1263 pLock->pWakeLock = kzalloc(sizeof(struct wake_lock), GFP_KERNEL);
1264 if (!pLock->pWakeLock)
1266 osal_info_print("%s:wake lock memory allocate fail!\n",__func__);
1269 wake_lock_init((struct wake_lock *)pLock->pWakeLock, WAKE_LOCK_SUSPEND, pLock->name);
1275 INT32 osal_wake_lock_deinit(P_OSAL_WAKE_LOCK pLock)
1283 wake_lock_destroy((struct wake_lock *)pLock->pWakeLock);
1284 if (pLock->pWakeLock)
1286 kfree(pLock->pWakeLock);
1287 pLock->pWakeLock = NULL;
1293 INT32 osal_wake_lock(P_OSAL_WAKE_LOCK pLock)
1301 wake_lock((struct wake_lock *)pLock->pWakeLock);
1308 INT32 osal_wake_unlock(P_OSAL_WAKE_LOCK pLock)
1316 wake_unlock((struct wake_lock *)pLock->pWakeLock);
1322 INT32 osal_wake_lock_count(P_OSAL_WAKE_LOCK pLock)
1332 count = wake_lock_active((struct wake_lock *)pLock->pWakeLock);
1338 *sleepable lock operations APIs
1346 INT32 osal_unsleepable_lock_init (P_OSAL_UNSLEEPABLE_LOCK pUSL)
1348 /* sanity check on input parameter */
1349 if (!pUSL || pUSL->pLock) {
1350 printk(KERN_WARNING "ERROR!!pUSL(0x%p)->pLock(0x%p)!\n",
1351 pUSL, (pUSL) ? pUSL->pLock : 0x0);
1355 pUSL->pLock = kzalloc(sizeof(spinlock_t),GFP_ATOMIC);
1357 osal_info_print("%s:spinlock memory allocate fail!\n",__func__);
1361 spin_lock_init((spinlock_t *)pUSL->pLock);
1365 INT32 osal_lock_unsleepable_lock (P_OSAL_UNSLEEPABLE_LOCK pUSL)
1367 /* sanity check on input parameter */
1368 if (!pUSL || !pUSL->pLock) {
1369 printk(KERN_WARNING "ERROR!!pUSL(0x%p)->pLock(0x%p)!\n",
1370 pUSL, (pUSL) ? pUSL->pLock : 0x0);
1374 spin_lock_irqsave((spinlock_t *)pUSL->pLock, pUSL->flag);
1378 INT32 osal_unlock_unsleepable_lock (P_OSAL_UNSLEEPABLE_LOCK pUSL)
1380 /* sanity check on input parameter */
1381 if (!pUSL || !pUSL->pLock) {
1382 printk(KERN_WARNING "ERROR!!pUSL(0x%p)->pLock(0x%p)!\n",
1383 pUSL, (pUSL) ? pUSL->pLock : 0x0);
1387 spin_unlock_irqrestore((spinlock_t *)pUSL->pLock, pUSL->flag);
1391 extern INT32 osal_unsleepable_lock_deinit (P_OSAL_UNSLEEPABLE_LOCK pUSL)
1393 /* sanity check on input parameter */
1394 if (!pUSL || !pUSL->pLock) {
1395 printk(KERN_WARNING "ERROR!!pUSL(0x%p)->pLock(0x%p)!\n",
1396 pUSL, (pUSL) ? pUSL->pLock : 0x0);
1409 *unsleepable operations APIs
1418 INT32 osal_sleepable_lock_init (P_OSAL_SLEEPABLE_LOCK pSL)
1420 /* sanity check on input parameter */
1421 if (!pSL || pSL->pLock) {
1422 printk(KERN_WARNING "ERROR!!pSL(0x%p)->pLock(0x%p)!\n",
1423 pSL, (pSL) ? pSL->pLock : 0x0);
1427 pSL->pLock = kzalloc(sizeof(struct mutex),GFP_KERNEL);
1429 osal_info_print("%s:mutex memory allocate fail!\n",__func__);
1433 mutex_init ((struct mutex *)pSL->pLock);
1437 INT32 osal_lock_sleepable_lock (P_OSAL_SLEEPABLE_LOCK pSL)
1439 /* sanity check on input parameter */
1440 if (!pSL || !pSL->pLock) {
1441 printk(KERN_WARNING "ERROR!!pSL(0x%p)->pLock(0x%p)!\n",
1442 pSL, (pSL) ? pSL->pLock : 0x0);
1446 return mutex_lock_interruptible((struct mutex *)pSL->pLock);
1449 INT32 osal_unlock_sleepable_lock (P_OSAL_SLEEPABLE_LOCK pSL)
1451 /* sanity check on input parameter */
1452 if (!pSL || !pSL->pLock) {
1453 printk(KERN_WARNING "ERROR!!pSL(0x%p)->pLock(0x%p)!\n",
1454 pSL, (pSL) ? pSL->pLock : 0x0);
1458 mutex_unlock((struct mutex *)pSL->pLock);
1463 INT32 osal_sleepable_lock_deinit (P_OSAL_SLEEPABLE_LOCK pSL)
1465 /* sanity check on input parameter */
1466 if (!pSL || !pSL->pLock) {
1467 printk(KERN_WARNING "ERROR!!pSL(0x%p)->pLock(0x%p)!\n",
1468 pSL, (pSL) ? pSL->pLock : 0x0);
1472 mutex_destroy ((struct mutex *)pSL->pLock);
1482 INT32 osal_msleep(UINT32 ms)
1488 INT32 osal_gettimeofday(PINT32 sec, PINT32 usec)
1493 do_gettimeofday(&now);
1501 *usec = now.tv_usec;
1508 INT32 osal_printtimeofday(const PUINT8 prefix)
1514 ret = osal_gettimeofday(&sec, &usec);
1515 ret += osal_dbg_print("%s>sec=%d, usec=%d\n",prefix, sec, usec);
1531 printk("start of dump>[%s] len=%d, limit=%d,", title, len, limit);
1533 dump_len = ((0 != limit) && (len > limit)) ? limit : len;
1537 len = (len > limit)? (limit) : (len);
1541 for (k = 0; k < dump_len ; k++) {
1542 if ((k != 0) && ( k % 16 == 0)) printk("\n");
1543 printk("0x%02x ", buf[k]);
1545 printk("<end of dump\n");
1548 UINT32 osal_op_get_id(P_OSAL_OP pOp)
1550 return (pOp) ? pOp->op.opId : 0xFFFFFFFF;
1553 MTK_WCN_BOOL osal_op_is_wait_for_signal(P_OSAL_OP pOp)
1555 return (pOp && pOp->signal.timeoutValue) ? MTK_WCN_BOOL_TRUE : MTK_WCN_BOOL_FALSE;
1558 VOID osal_op_raise_signal(P_OSAL_OP pOp, INT32 result)
1562 pOp->result = result;
1563 osal_raise_signal(&pOp->signal);