OSDN Git Service

Remove semaphore wrappers
[android-x86/external-modules-rtl8723au.git] / os_dep / osdep_service.c
index 86bbdab..9d801e7 100644 (file)
 
 #define RT_TAG '1178'
 
-#ifdef DBG_MEMORY_LEAK
-#include <asm/atomic.h>
-atomic_t _malloc_cnt = ATOMIC_INIT(0);
-atomic_t _malloc_size = ATOMIC_INIT(0);
-#endif /* DBG_MEMORY_LEAK */
-
 
 /*
 * Translate the OS dependent @param error_code to OS independent RTW_STATUS_CODE
@@ -52,39 +46,10 @@ inline int RTW_STATUS_CODE(int error_code){
        }
 }
 
-u32 rtw_atoi(u8* s)
-{
-
-       int num=0,flag=0;
-       int i;
-       for(i=0;i<=strlen(s);i++)
-       {
-         if(s[i] >= '0' && s[i] <= '9')
-                num = num * 10 + s[i] -'0';
-         else if(s[0] == '-' && i==0)
-                flag =1;
-         else
-                 break;
-        }
-
-       if(flag == 1)
-          num = num * -1;
-
-        return(num);
-
-}
-
 inline u8* _rtw_vmalloc(u32 sz)
 {
        u8      *pbuf;
        pbuf = vmalloc(sz);
-       
-#ifdef DBG_MEMORY_LEAK
-       if ( pbuf != NULL) {
-               atomic_inc(&_malloc_cnt);
-               atomic_add(sz, &_malloc_size);
-       }
-#endif /* DBG_MEMORY_LEAK */
 
        return pbuf;
 }
@@ -102,11 +67,6 @@ inline u8* _rtw_zvmalloc(u32 sz)
 inline void _rtw_vmfree(u8 *pbuf, u32 sz)
 {
        vfree(pbuf);
-
-#ifdef DBG_MEMORY_LEAK
-       atomic_dec(&_malloc_cnt);
-       atomic_sub(sz, &_malloc_size);
-#endif /* DBG_MEMORY_LEAK */
 }
 
 u8* _rtw_malloc(u32 sz)
@@ -116,15 +76,7 @@ u8* _rtw_malloc(u32 sz)
 
        pbuf = kmalloc(sz,in_interrupt() ? GFP_ATOMIC : GFP_KERNEL);
 
-#ifdef DBG_MEMORY_LEAK
-       if ( pbuf != NULL) {
-               atomic_inc(&_malloc_cnt);
-               atomic_add(sz, &_malloc_size);
-       }
-#endif /* DBG_MEMORY_LEAK */
-
        return pbuf;
-
 }
 
 
@@ -141,264 +93,7 @@ u8* _rtw_zmalloc(u32 sz)
 
 void   _rtw_mfree(u8 *pbuf, u32 sz)
 {
-
        kfree(pbuf);
-       
-#ifdef DBG_MEMORY_LEAK
-       atomic_dec(&_malloc_cnt);
-       atomic_sub(sz, &_malloc_size);
-#endif /* DBG_MEMORY_LEAK */
-
-}
-
-#ifdef DBG_MEM_ALLOC
-
-struct rtw_dbg_mem_stat {
-       ATOMIC_T vir_alloc; // the memory bytes we allocate now
-       ATOMIC_T vir_peak; // the peak memory bytes we allocate
-       ATOMIC_T vir_alloc_err; // the error times we fail to allocate memory
-
-       ATOMIC_T phy_alloc;
-       ATOMIC_T phy_peak;
-       ATOMIC_T phy_alloc_err;
-
-       ATOMIC_T tx_alloc;
-       ATOMIC_T tx_peak;
-       ATOMIC_T tx_alloc_err;
-
-       ATOMIC_T rx_alloc;
-       ATOMIC_T rx_peak;
-       ATOMIC_T rx_alloc_err;
-} rtw_dbg_mem_stat;
-
-void rtw_dump_mem_stat (void)
-{
-       int vir_alloc, vir_peak, vir_alloc_err, phy_alloc, phy_peak, phy_alloc_err;
-       int tx_alloc, tx_peak, tx_alloc_err, rx_alloc, rx_peak, rx_alloc_err;
-
-       vir_alloc=ATOMIC_READ(&rtw_dbg_mem_stat.vir_alloc);
-       vir_peak=ATOMIC_READ(&rtw_dbg_mem_stat.vir_peak);
-       vir_alloc_err=ATOMIC_READ(&rtw_dbg_mem_stat.vir_alloc_err);
-
-       phy_alloc=ATOMIC_READ(&rtw_dbg_mem_stat.phy_alloc);
-       phy_peak=ATOMIC_READ(&rtw_dbg_mem_stat.phy_peak);
-       phy_alloc_err=ATOMIC_READ(&rtw_dbg_mem_stat.phy_alloc_err);
-
-       tx_alloc=ATOMIC_READ(&rtw_dbg_mem_stat.tx_alloc);
-       tx_peak=ATOMIC_READ(&rtw_dbg_mem_stat.tx_peak);
-       tx_alloc_err=ATOMIC_READ(&rtw_dbg_mem_stat.tx_alloc_err);
-
-       rx_alloc=ATOMIC_READ(&rtw_dbg_mem_stat.rx_alloc);
-       rx_peak=ATOMIC_READ(&rtw_dbg_mem_stat.rx_peak);
-       rx_alloc_err=ATOMIC_READ(&rtw_dbg_mem_stat.rx_alloc_err);
-
-       DBG_8723A(      "vir_alloc:%d, vir_peak:%d, vir_alloc_err:%d\n"
-                               "phy_alloc:%d, phy_peak:%d, phy_alloc_err:%d\n"
-                               "tx_alloc:%d, tx_peak:%d, tx_alloc_err:%d\n"
-                               "rx_alloc:%d, rx_peak:%d, rx_alloc_err:%d\n"
-               , vir_alloc, vir_peak, vir_alloc_err
-               , phy_alloc, phy_peak, phy_alloc_err
-               , tx_alloc, tx_peak, tx_alloc_err
-               , rx_alloc, rx_peak, rx_alloc_err
-       );
-}
-
-void rtw_update_mem_stat(u8 flag, u32 sz)
-{
-       static u32 update_time = 0;
-       int peak, alloc;
-
-       if(!update_time) {
-               ATOMIC_SET(&rtw_dbg_mem_stat.vir_alloc,0);
-               ATOMIC_SET(&rtw_dbg_mem_stat.vir_peak,0);
-               ATOMIC_SET(&rtw_dbg_mem_stat.vir_alloc_err,0);
-               ATOMIC_SET(&rtw_dbg_mem_stat.phy_alloc,0);
-               ATOMIC_SET(&rtw_dbg_mem_stat.phy_peak,0);
-               ATOMIC_SET(&rtw_dbg_mem_stat.phy_alloc_err,0);
-       }
-
-       switch(flag) {
-               case MEM_STAT_VIR_ALLOC_SUCCESS:
-                       alloc = ATOMIC_ADD_RETURN(&rtw_dbg_mem_stat.vir_alloc, sz);
-                       peak=ATOMIC_READ(&rtw_dbg_mem_stat.vir_peak);
-                       if (peak<alloc)
-                               ATOMIC_SET(&rtw_dbg_mem_stat.vir_peak, alloc);
-                       break;
-
-               case MEM_STAT_VIR_ALLOC_FAIL:
-                       ATOMIC_INC(&rtw_dbg_mem_stat.vir_alloc_err);
-                       break;
-
-               case MEM_STAT_VIR_FREE:
-                       alloc = ATOMIC_SUB_RETURN(&rtw_dbg_mem_stat.vir_alloc, sz);
-                       break;
-
-               case MEM_STAT_PHY_ALLOC_SUCCESS:
-                       alloc = ATOMIC_ADD_RETURN(&rtw_dbg_mem_stat.phy_alloc, sz);
-                       peak=ATOMIC_READ(&rtw_dbg_mem_stat.phy_peak);
-                       if (peak<alloc)
-                               ATOMIC_SET(&rtw_dbg_mem_stat.phy_peak, alloc);
-                       break;
-
-               case MEM_STAT_PHY_ALLOC_FAIL:
-                       ATOMIC_INC(&rtw_dbg_mem_stat.phy_alloc_err);
-                       break;
-
-               case MEM_STAT_PHY_FREE:
-                       alloc = ATOMIC_SUB_RETURN(&rtw_dbg_mem_stat.phy_alloc, sz);
-                       break;
-
-               case MEM_STAT_TX_ALLOC_SUCCESS:
-                       alloc = ATOMIC_ADD_RETURN(&rtw_dbg_mem_stat.tx_alloc, sz);
-                       peak=ATOMIC_READ(&rtw_dbg_mem_stat.tx_peak);
-                       if (peak<alloc)
-                               ATOMIC_SET(&rtw_dbg_mem_stat.tx_peak, alloc);
-                       break;
-
-               case MEM_STAT_TX_ALLOC_FAIL:
-                       ATOMIC_INC(&rtw_dbg_mem_stat.tx_alloc_err);
-                       break;
-
-               case MEM_STAT_TX_FREE:
-                       alloc = ATOMIC_SUB_RETURN(&rtw_dbg_mem_stat.tx_alloc, sz);
-                       break;
-
-               case MEM_STAT_RX_ALLOC_SUCCESS:
-                       alloc = ATOMIC_ADD_RETURN(&rtw_dbg_mem_stat.rx_alloc, sz);
-                       peak=ATOMIC_READ(&rtw_dbg_mem_stat.rx_peak);
-                       if (peak<alloc)
-                               ATOMIC_SET(&rtw_dbg_mem_stat.rx_peak, alloc);
-                       break;
-
-               case MEM_STAT_RX_ALLOC_FAIL:
-                       ATOMIC_INC(&rtw_dbg_mem_stat.rx_alloc_err);
-                       break;
-
-               case MEM_STAT_RX_FREE:
-                       alloc = ATOMIC_SUB_RETURN(&rtw_dbg_mem_stat.rx_alloc, sz);
-                       break;
-
-       };
-
-       if (rtw_get_passing_time_ms(update_time) > 5000) {
-               rtw_dump_mem_stat();
-               update_time=rtw_get_current_time();
-       }
-
-
-}
-
-
-inline u8* dbg_rtw_vmalloc(u32 sz, const char *func, int line)
-{
-       u8  *p;
-       //DBG_8723A("DBG_MEM_ALLOC %s:%d %s(%d)\n", func,  line, __FUNCTION__, (sz));
-
-       p=_rtw_vmalloc((sz));
-
-       rtw_update_mem_stat(
-               p ? MEM_STAT_VIR_ALLOC_SUCCESS : MEM_STAT_VIR_ALLOC_FAIL
-               , sz
-       );
-
-       return p;
-}
-
-inline u8* dbg_rtw_zvmalloc(u32 sz, const char *func, int line)
-{
-       u8 *p;
-       //DBG_8723A("DBG_MEM_ALLOC %s:%d %s(%d)\n", func, line, __FUNCTION__, (sz));
-
-       p=_rtw_zvmalloc((sz));
-
-       rtw_update_mem_stat(
-               p ? MEM_STAT_VIR_ALLOC_SUCCESS : MEM_STAT_VIR_ALLOC_FAIL
-               , sz
-       );
-
-       return p;
-}
-
-inline void dbg_rtw_vmfree(u8 *pbuf, u32 sz, const char *func, int line)
-{
-       //DBG_8723A("DBG_MEM_ALLOC %s:%d %s(%p,%d)\n",  func, line, __FUNCTION__, (pbuf), (sz));
-
-       _rtw_vmfree((pbuf), (sz));
-
-       rtw_update_mem_stat(
-               MEM_STAT_VIR_FREE
-               , sz
-       );
-
-}
-
-inline u8* dbg_rtw_malloc(u32 sz, const char *func, int line)
-{
-       u8 *p;
-
-       if((sz)>4096)
-               DBG_8723A("DBG_MEM_ALLOC !!!!!!!!!!!!!! %s:%d %s(%d)\n", func, line, __FUNCTION__, (sz));
-
-       p=_rtw_malloc((sz));
-
-       rtw_update_mem_stat(
-               p ? MEM_STAT_PHY_ALLOC_SUCCESS : MEM_STAT_PHY_ALLOC_FAIL
-               , sz
-       );
-
-       return p;
-}
-
-inline u8* dbg_rtw_zmalloc(u32 sz, const char *func, int line)
-{
-       u8 *p;
-
-       if((sz)>4096)
-               DBG_8723A("DBG_MEM_ALLOC !!!!!!!!!!!!!! %s:%d %s(%d)\n", func, line, __FUNCTION__, (sz));
-
-       p = _rtw_zmalloc((sz));
-
-       rtw_update_mem_stat(
-               p ? MEM_STAT_PHY_ALLOC_SUCCESS : MEM_STAT_PHY_ALLOC_FAIL
-               , sz
-       );
-
-       return p;
-
-}
-
-inline void dbg_rtw_mfree(u8 *pbuf, u32 sz, const char *func, int line)
-{
-       if((sz)>4096)
-               DBG_8723A("DBG_MEM_ALLOC !!!!!!!!!!!!!! %s:%d %s(%p,%d)\n", func, line, __FUNCTION__, (pbuf), (sz));
-
-       _rtw_mfree((pbuf), (sz));
-
-       rtw_update_mem_stat(
-               MEM_STAT_PHY_FREE
-               , sz
-       );
-}
-#endif
-
-void _rtw_memcpy(void* dst, void* src, u32 sz)
-{
-       memcpy(dst, src, sz);
-}
-
-int    _rtw_memcmp(void *dst, void *src, u32 sz)
-{
-//under Linux/GNU/GLibc, the return value of memcmp for two same mem. chunk is 0
-
-       if (!(memcmp(dst, src, sz)))
-               return _TRUE;
-       else
-               return _FALSE;
-}
-
-void _rtw_memset(void *pbuf, int c, u32 sz)
-{
-        memset(pbuf, c, sz);
 }
 
 void _rtw_init_listhead(_list *list)
@@ -438,30 +133,6 @@ Caller must check if the list is empty before calling rtw_list_delete
 */
 
 
-void _rtw_init_sema(_sema      *sema, int init_val)
-{
-       sema_init(sema, init_val);
-}
-
-void _rtw_free_sema(_sema      *sema)
-{
-}
-
-void _rtw_up_sema(_sema        *sema)
-{
-       up(sema);
-}
-
-u32 _rtw_down_sema(_sema *sema)
-{
-       if (down_interruptible(sema))
-               return _FAIL;
-       else
-               return _SUCCESS;
-}
-
-
-
 void   _rtw_mutex_init(_mutex *pmutex)
 {
 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,37))
@@ -480,42 +151,11 @@ void      _rtw_mutex_free(_mutex *pmutex)
 #endif
 }
 
-void   _rtw_spinlock_init(_lock *plock)
-{
-       spin_lock_init(plock);
-}
-
-void   _rtw_spinlock_free(_lock *plock)
-{
-}
-
-void   _rtw_spinlock(_lock     *plock)
-{
-       spin_lock(plock);
-}
-
-void   _rtw_spinunlock(_lock *plock)
-{
-       spin_unlock(plock);
-}
-
-
-void   _rtw_spinlock_ex(_lock  *plock)
-{
-       spin_lock(plock);
-}
-
-void   _rtw_spinunlock_ex(_lock *plock)
-{
-       spin_unlock(plock);
-}
-
-
 
 void   _rtw_init_queue(_queue  *pqueue)
 {
        _rtw_init_listhead(&(pqueue->queue));
-       _rtw_spinlock_init(&(pqueue->lock));
+       spin_lock_init(&(pqueue->lock));
 }
 
 u32      _rtw_queue_empty(_queue       *pqueue)
@@ -1075,7 +715,7 @@ int rtw_change_ifname(_adapter *padapter, const char *ifname)
 
        rtw_init_netdev_name(pnetdev, ifname);
 
-       _rtw_memcpy(pnetdev->dev_addr, padapter->eeprompriv.mac_addr, ETH_ALEN);
+       memcpy(pnetdev->dev_addr, padapter->eeprompriv.mac_addr, ETH_ALEN);
 
 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,26))
        if(!rtnl_is_locked())
@@ -1142,7 +782,7 @@ void rtw_buf_update(u8 **buf, u32 *buf_len, u8 *src, u32 src_len)
        dup = rtw_malloc(src_len);
        if (dup) {
                dup_len = src_len;
-               _rtw_memcpy(dup, src, dup_len);
+               memcpy(dup, src, dup_len);
        }
 
 keep_ori: