]> Gitweb @ Texas Instruments - Open Source Git Repositories - git.TI.com/gitweb - keystone-rtos/netapi.git/blobdiff - ti/runtime/netapi/src/osal.c
Additional changes to integrate with highperf-lib
[keystone-rtos/netapi.git] / ti / runtime / netapi / src / osal.c
index ddf22d0c5cf65661369b185f44c0d9523b5a8c37..77c7720c2cf5be5e42ace328dcf85a66e12cb584 100755 (executable)
@@ -50,8 +50,7 @@
 #include <stdio.h>
 
 #include "netapi_tune.h"
-#include "netapi_vm.h"
-#include "netapi_timer.h"
+#include "hplib.h"
 #include <unistd.h>
 #include <sys/mman.h>
 #include <sys/types.h>
@@ -61,7 +60,9 @@
 #include <errno.h>
 #include <string.h>
 #include "netapi_util.h"
-#include "tools/module/netapimod.h"
+#include "hplibmod.h"
+#include <ti/drv/sa/sa_osal.h>
+#include <ti/runtime/pktlib/pktlib.h>
 #define System_printf   printf
 
 uint32_t              Osal_qmss_MallocCounter =0;
@@ -112,117 +113,6 @@ static inline void nwalTest_osalLeaveCS()
 }
 
 #endif
-
-
-
-/**********USE SPACE ACCESS TO KERNEL MEMORY SERVICES*************/
-static int netapi_fd;
-
-/***init **/
-int netapi_utilModInit(void)
-{
-    netapi_fd = open("/dev/netapi", O_RDWR);
-
-    if (netapi_fd == -1) {
-        return -1;
-    }
-    return netapi_fd;
-}
-
-/***close **/
-void netapi_utilModClose(void)
-{
-    close(netapi_fd);
-}
-
-/* return physical address of region kernel module has allocated for us */
-unsigned long netapi_utilGetPhysOfBufferArea(void)
-{
-    unsigned long physp;
-
-    if (ioctl(netapi_fd, NETAPIMOD_IOCGETPHYS | NETAPIMOD_IOCMAGIC, &physp) == -1) {
-        return 0;
-    }
-    return physp;
-}
-
-/* return the size of that region */
-unsigned long netapi_utilGetSizeOfBufferArea(void)
-{
-    unsigned long size;
-
-    if (ioctl(netapi_fd, NETAPIMOD_IOCGETSIZE | NETAPIMOD_IOCMAGIC, &size) == -1) {
-        return 0;
-    }
-    return size;
-}
-
-//*****for the actual wb, inv cache ops, call the osal_xxx version, not these directly
-// (so make inline)
-/** write back operation on block */
-static inline int _netapi_utilCacheWb(void *ptr, size_t size)
-{
-    struct netapimod_block block;
-
-    block.addr = (unsigned long)ptr;
-    block.size = size;
-
-    if (ioctl(netapi_fd, NETAPIMOD_IOCCACHEWB | NETAPIMOD_IOCMAGIC, &block) == -1) {
-        return -1;
-    }
-    return 0;
-}
-int netapi_utilCacheWb(void *ptr, size_t size) {return _netapi_utilCacheWb(ptr,size);}
-
-/** write back & invalidate **/
-static inline int _netapi_utilCacheWbInv(void *ptr, size_t size)
-{
-    struct netapimod_block block;
-
-    block.addr = (unsigned long)ptr;
-    block.size = size;
-
-    if (ioctl(netapi_fd, NETAPIMOD_IOCCACHEWBINV | NETAPIMOD_IOCMAGIC, &block) == -1) {
-        return -1;
-    }
-    return 0;
-}
-
-int netapi_utilCacheWbInv(void *ptr, size_t size) {return _netapi_utilCacheWbInv(ptr,size);}
-/** just invalidate **/
-static inline int _netapi_utilCacheInv(void *ptr, size_t size)
-{
-    struct netapimod_block block;
-
-    block.addr = (unsigned long)ptr;
-    block.size = size;
-
-    if (ioctl(netapi_fd, NETAPIMOD_IOCCACHEINV | NETAPIMOD_IOCMAGIC, &block) == -1) {
-        return -1;
-    }
-    return 0;
-}
-int netapi_utilCacheInv(void *ptr, size_t size) {return _netapi_utilCacheInv(ptr,size);}
-
-//***mmap the block into our user space process memory map.  */
-unsigned long netapi_utilGetVaOfBufferArea(unsigned int offset, unsigned int size)
-{
-    void *userp;
-
-    /* Map the physical address to user space */
-    userp = mmap(0,                       // Preferred start address
-                 size,            // Length to be mapped
-                 PROT_WRITE | PROT_READ,  // Read and write access
-                 MAP_SHARED,              // Shared memory
-                 netapi_fd,               // File descriptor
-                 offset);                      // The byte offset from fd
-
-    if (userp == MAP_FAILED) {
-        return 0;
-    }
-    return (unsigned long)userp;
-}
-
 static unsigned int cache_op_cycles=0;
 static unsigned int n_cache_op_cycles=0;
 void Osal_cache_op_measure_reset(void) { cache_op_cycles=0; n_cache_op_cycles=0;}
@@ -237,10 +127,10 @@ static inline void Osal_invalidateCache (void *blockPtr, uint32_t size)
     register unsigned int v1;
     register unsigned int v2;
      
-    v1= netapi_timing_stop();
-    if ((blockPtr <netapi_VM_mem_start)||( blockPtr>netapi_VM_mem_end)) return;
-    _netapi_utilCacheInv(blockPtr, size);
-    v2= netapi_timing_stop();
+    v1= hplib_mUtil_GetTickCount();
+    if ((blockPtr <hplib_VM_mem_start)||( blockPtr>hplib_VM_mem_end)) return;
+    hplib_CacheInv(blockPtr, size);
+    v2= hplib_mUtil_GetTickCount();
     cache_op_cycles += (v2-v1); 
     n_cache_op_cycles+=1;
 #endif
@@ -263,22 +153,26 @@ static inline void Osal_writeBackCache (void *blockPtr, uint32_t size)
     register unsigned int v1;
     register unsigned int v2;
      
-    v1= netapi_timing_stop();
-    if (((uint8_t*)blockPtr <netapi_VM_mem_start)||( (uint8_t*)blockPtr>netapi_VM_mem_end)) return;
-    _netapi_utilCacheWb(blockPtr, size);
-    v2= netapi_timing_stop();
+    v1= hplib_mUtil_GetTickCount();
+    if (((uint8_t*)blockPtr <hplib_VM_mem_start)||( (uint8_t*)blockPtr>hplib_VM_mem_end)) return;
+    hplib_CacheWb(blockPtr, size);
+    v2= hplib_mUtil_GetTickCount();
     cache_op_cycles += (v2-v1); 
     n_cache_op_cycles+=1;
 #endif
     return;
 }
 
+static HPLIB_SPINLOCK_T qmss_lock = HPLIB_SPINLOCK_UNLOCKED_INITIALIZER;
+static HPLIB_SPINLOCK_T nwal_lock = HPLIB_SPINLOCK_UNLOCKED_INITIALIZER;
+static HPLIB_SPINLOCK_T hplib_lock = HPLIB_SPINLOCK_UNLOCKED_INITIALIZER;
 
 void *  Osal_qmssMtCsEnter()
 {
     /* Stub Function. TBD: Would need to handle when for multi proc access 
      * To be handled once infrastructure is available from Kernel
      */
+     //hplib_spinlock_lock(&qmss_lock)
     return NULL;
 }
 
@@ -288,6 +182,7 @@ void Osal_qmssMtCsExit(void *key)
     /* Stub Function. TBD: Would need to handle when for multi proc access 
      * To be handled once infrastructure is available from Kernel
      */
+      //hplib_spinlock_unlock(&qmss_lock)
     return;
 }
 
@@ -485,7 +380,7 @@ uint64_t Osal_nwalGetTimeStamp(void)
 {
     /* Stub function to return timestamp
      */
-    return netapi_getTimestamp();
+    return hplib_mUtil_GetTimestamp();
 }
 
 uint16_t Osal_saGetProcId (void )
@@ -499,7 +394,7 @@ void* Osal_saGetSCPhyAddr(void* vaddr)
     {
         return NULL;
     }
-    return (void *)(netapi_VM_mem_start_phy + ((uint8_t*) vaddr - netapi_VM_mem_start));
+    return (void *)(hplib_VM_mem_start_phy + ((uint8_t*) vaddr - hplib_VM_mem_start));
 
 }
 
@@ -562,7 +457,14 @@ void Osal_saEndMemAccess (void *blockPtr, uint32_t size)
     return;
 }
 
-
+int   Osal_saGetSysEndianMode(void)
+{
+#if defined( _BIG_ENDIAN ) 
+    return((int)sa_SYS_ENDIAN_MODE_BIG);
+#else
+    return((int)sa_SYS_ENDIAN_MODE_LITTLE);
+#endif
+}
 
 void Osal_pktLibBeginMemAccess(void* ptr, uint32_t size)
 {
@@ -623,17 +525,17 @@ void  Osal_pktLibExitCriticalSection(Pktlib_HeapHandle heapHandle, void* csHandl
 
 void* Osal_pktLibPhyToVirt(void *ptr)
 {
-    return(_Osal_qmssPhyToVirt(ptr));
+    return(hplib_mVM_PhyToVirt(ptr));
 }
 
 void* Osal_qmssVirtToPhy (void *ptr)
 {
-    return _Osal_qmssVirtToPhy(ptr);
+    return hplib_mVM_VirtToPhy(ptr);
 }
 
 void * Osal_qmssPhyToVirt (void *ptr)
 {
-    return _Osal_qmssPhyToVirt(ptr);
+    return hplib_mVM_PhyToVirt(ptr);
 }
 
 /******************************************************************************
@@ -644,106 +546,16 @@ void * Osal_qmssPhyToVirt (void *ptr)
                                   //define and just host will be assumed (more efficient)
 void* Osal_qmssConvertDescVirtToPhy(void *descAddr)
 {
-    if (!descAddr) return (void *)0;
-#ifdef ASSUME_ALL_DESCRIPTOR 
-    if (Cppi_getDescType((Cppi_Desc *)QMSS_DESC_PTR(descAddr)) == Cppi_DescType_HOST)
-#endif
-    {
-        Cppi_HostDesc *nextBDPtr = (Cppi_HostDesc *)QMSS_DESC_PTR(descAddr);
-        Cppi_HostDesc *prevBDPtr = 0;
-        while (nextBDPtr)
-        {
-            void *buffPtr=NULL;
-            if (nextBDPtr->buffPtr)
-            {
-                buffPtr = (void *)nextBDPtr->buffPtr;
-                nextBDPtr->buffPtr = (uint32_t)_Osal_qmssVirtToPhy((void *)(nextBDPtr->buffPtr));
-                if (!(nextBDPtr->buffPtr)) return (void *)0;
-                Osal_writeBackCache(buffPtr, nextBDPtr->buffLen);          
-            }
-
-            if (nextBDPtr->origBuffPtr)
-            {
-                nextBDPtr->origBuffPtr = (uint32_t)_Osal_qmssVirtToPhy((void *)(nextBDPtr->origBuffPtr));
-                if (!(nextBDPtr->origBuffPtr)) return (void *)0;
-            }
-
-            prevBDPtr = nextBDPtr;
-            nextBDPtr = (Cppi_HostDesc *)QMSS_DESC_PTR((nextBDPtr->nextBDPtr));
-            if (prevBDPtr->nextBDPtr)
-            {
-                prevBDPtr->nextBDPtr = (uint32_t)_Osal_qmssVirtToPhy((void *)(prevBDPtr->nextBDPtr));
-                if (!(prevBDPtr->nextBDPtr)) return (void *)0;
-            }
-
-            Osal_writeBackCache(prevBDPtr, TUNE_NETAPI_DESC_SIZE);
-        }
-        descAddr = _Osal_qmssVirtToPhy(descAddr);
-        if (!descAddr) return (void *)0;
-    }
-#ifdef ASSUME_ALL_DESCRIPTOR 
-    else if (Cppi_getDescType((Cppi_Desc *)QMSS_DESC_PTR(descAddr)) == Cppi_DescType_MONOLITHIC)
-    {
-        Osal_writeBackCache(descAddr, TUNE_NETAPI_DESC_SIZE);
-        descAddr = _Osal_qmssVirtToPhy(descAddr);
-        if (!descAddr) return (void *)0;
-    }
-#endif
-    return descAddr;
-
+       hplib_Util_ConvertDescVirtToPhy(descAddr);
 }
-
-
 /******************************************************************************
 * Function to traverse a CPPI descriptor and convert all address references
 * from physical to virtual.
 ******************************************************************************/
 void* Osal_qmssConvertDescPhyToVirt(void *descAddr)
 {
-    if (!descAddr) return (void *)0;
-    descAddr = _Osal_qmssPhyToVirt(descAddr);
-
-#ifdef ASSUME_ALL_DESCRIPTOR 
-    if (Cppi_getDescType((Cppi_Desc *)QMSS_DESC_PTR(descAddr)) == Cppi_DescType_HOST)
-#endif
-    {
-        Cppi_HostDesc *nextBDPtr = (Cppi_HostDesc *)QMSS_DESC_PTR(descAddr);
-        while (nextBDPtr)
-        {
-            Osal_invalidateCache(nextBDPtr, TUNE_NETAPI_DESC_SIZE);
-            if (nextBDPtr->buffPtr)
-            {
-                nextBDPtr->buffPtr = (uint32_t)_Osal_qmssPhyToVirt((void *)(nextBDPtr->buffPtr));
-                if (!(nextBDPtr->buffPtr)) return (void *)0;
-                Osal_invalidateCache((void *)(nextBDPtr->buffPtr), nextBDPtr->buffLen);
-            }
-
-            if (nextBDPtr->origBuffPtr)
-            {
-                nextBDPtr->origBuffPtr = (uint32_t)_Osal_qmssPhyToVirt((void *)(nextBDPtr->origBuffPtr));
-                if (!(nextBDPtr->origBuffPtr)) return (void *)0;
-            }
-
-            if (nextBDPtr->nextBDPtr)
-            {
-                nextBDPtr->nextBDPtr = (uint32_t)_Osal_qmssPhyToVirt((void *)(nextBDPtr->nextBDPtr));
-                if (!(nextBDPtr->nextBDPtr)) return (void *)0;
-            }
-
-            nextBDPtr = (void *)QMSS_DESC_PTR((nextBDPtr->nextBDPtr));
-        }
-    }
-#ifdef ASSUME_ALL_DESCRIPTOR 
-    else if (Cppi_getDescType((Cppi_Desc *)QMSS_DESC_PTR(descAddr)) == Cppi_DescType_MONOLITHIC)
-    {
-        descAddr = _Osal_qmssPhyToVirt(descAddr);
-        if (!descAddr) return (void *)0;
-        Osal_invalidateCache(descAddr, TUNE_NETAPI_DESC_SIZE);
-    }
-#endif
-    return descAddr;
+       hplib_Util_ConvertDescPhyToVirt(descAddr);
 }
-
 void* Osal_stubCsEnter (void)
 {
 
@@ -756,4 +568,15 @@ void Osal_stubCsExit (void *CsHandle)
 
     return;
 }
+void* Osal_hplibCsEnter (void)
+{
 
+       hplib_mSpinlockLock(&hplib_lock);
+
+}
+void Osal_hplibCsExit (void *CsHandle)
+{
+   hplib_mSpinlockUnlock(&hplib_lock);
+
+    return;
+}