index 65b291d393dbe64b098795fac74a56cac6a0a70c..9d80c288f55f4fa4d008e94bb91bc6fa779a4bca 100755 (executable)
*
*/
+#ifndef DISABLE_OSAL
+
/* CSL RL includes */
-#include <ti/csl/cslr_device.h>
-#include <ti/csl/csl_pscAux.h>
-#include <ti/csl/csl_semAux.h>
-#include <ti/csl/csl_cacheAux.h>
-#include <ti/csl/csl_xmcAux.h>
+#include <ti/csl/csl_cache.h>
#include <stdlib.h>
#include <stdio.h>
-#include "netapi_tune.h"
#include "hplib.h"
#include <unistd.h>
#include <sys/mman.h>
#include <fcntl.h>
#include <errno.h>
#include <string.h>
-#include "netapi_util.h"
+//#include "netapi_util.h"
#include "hplibmod.h"
#include <ti/drv/sa/sa_osal.h>
#include <ti/runtime/pktlib/pktlib.h>
-#define System_printf printf
+
+typedef struct osal_shm_Tag
+{
+ hplib_spinLock_T qmss_lock;
+ hplib_spinLock_T nwal_lock;
+ hplib_spinLock_T hplib_lock;
+ hplib_spinLock_T cppi_lock;
+ hplib_spinLock_T sa_lock;
+ hplib_spinLock_T pktlib_lock;
+ int init_done;
+} osal_shm_T;
+
+void* pBase = NULL;
+osal_shm_T* posalShm;
uint32_t Osal_qmss_MallocCounter =0;
uint32_t Osal_qmss_FreeCounter =0;
uint32_t Osal_cppi_MallocCounter =0;
uint32_t Osal_cppi_FreeCounter =0;
-void* Osal_saGetSCPhyAddr(void* vaddr);
-
-
-
-/* TODO: */
-#define DNUM 0
+static __thread int our_core = 0;
+static __thread HPLIB_SPINLOCK_IF_T* p_lock_if;
+void* Osal_saGetSCPhyAddr(void* vaddr);
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;}
-unsigned int Osal_cache_op_measure(int * p_n) { *p_n = n_cache_op_cycles; return cache_op_cycles;}
+unsigned int Osal_cache_op_measure(unsigned long long * p_n) { *p_n = n_cache_op_cycles; return cache_op_cycles;}
+
+HPLIB_SPINLOCK_IF_T lock_if_lol =
+{
+ hplib_mSpinLockInit,
+ hplib_mSpinLockTryLock,
+ hplib_mSpinLockIsLocked,
+ hplib_mSpinLockLock,
+ hplib_mSpinLockUnlock,
+ hplib_mRWLockInit,
+ hplib_mRWLockWriteLock,
+ hplib_mRWLockWriteUnlock,
+ hplib_mRWLockReadLock,
+ hplib_mRWLockReadUnlock
+};
+
+HPLIB_SPINLOCK_IF_T lock_if_mp =
+{
+ hplib_mSpinLockInit,
+ hplib_mSpinLockTryLock,
+ hplib_mSpinLockIsLocked,
+ hplib_mSpinLockLockMP,
+ hplib_mSpinLockUnlockMP,
+ hplib_mRWLockInit,
+ hplib_mRWLockWriteLockMP,
+ hplib_mRWLockWriteUnlockMP,
+ hplib_mRWLockReadLockMP,
+ hplib_mRWLockReadUnlockMP
+};
+
+/* This is called 1 Time per system boot by the global master process */
+hplib_RetValue hplib_utilOsalCreate()
+{
+ hplib_RetValue retVal = hplib_OK;
+ pBase = hplib_shmOpen();
+
+ if ((retVal = hplib_shmAddEntry(pBase, sizeof(osal_shm_T), OSAL_ENTRY)) !=
+ hplib_OK)
+ {
+ hplib_Log("hplib_utilOsalCreate: hplib_shmAddEntry failed for OSAL_ENTRY\n");
+ return retVal;
+ }
+ else
+ {
+ posalShm = (osal_shm_T*)hplib_shmGetEntry(pBase, OSAL_ENTRY);
+ posalShm->init_done = 0;
+ }
+
+ posalShm = (osal_shm_T*)hplib_shmGetEntry(pBase, OSAL_ENTRY);
+ posalShm->qmss_lock = hplib_spinLock_UNLOCKED_INITIALIZER;
+ posalShm->nwal_lock = hplib_spinLock_UNLOCKED_INITIALIZER;
+ posalShm->hplib_lock = hplib_spinLock_UNLOCKED_INITIALIZER;
+ posalShm->cppi_lock = hplib_spinLock_UNLOCKED_INITIALIZER;
+ posalShm->sa_lock = hplib_spinLock_UNLOCKED_INITIALIZER;
+ posalShm->pktlib_lock = hplib_spinLock_UNLOCKED_INITIALIZER;
-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;
-static hplib_spinLock_T cppi_lock = hplib_spinLock_UNLOCKED_INITIALIZER;
-static hplib_spinLock_T sa_lock = hplib_spinLock_UNLOCKED_INITIALIZER;
-static hplib_spinLock_T pktlib_lock = hplib_spinLock_UNLOCKED_INITIALIZER;
+ posalShm->init_done = 1;
+ return retVal;
+}
+
+/* This can be called for every other process which is NOT the global master process */
+hplib_RetValue Osal_start(void *pShmBase)
+{
+ if (!pBase)
+ pBase = pShmBase;
+
+ posalShm = (osal_shm_T*)hplib_shmGetEntry(pBase, OSAL_ENTRY);
+ if (posalShm)
+ {
+ if(posalShm->init_done)
+ return hplib_OK;
+ }
+ return hplib_FAILURE;
+}
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_mSpinLockLock(&qmss_lock);
+ p_lock_if->lock(&posalShm->qmss_lock);
return NULL;
}
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_mSpinLockUnlock(&qmss_lock);
+ p_lock_if->unlock(&posalShm->qmss_lock);
return;
}
+void* Osal_qmssAccCsEnter (void)
+{
+ return NULL;
+}
+void Osal_qmssAccCsExit (void *CsHandle)
+{
+ return;
+}
void Osal_nwalCsEnter(uint32_t *key)
{
- hplib_mSpinLockLock(&nwal_lock);
+ p_lock_if->lock(&posalShm->nwal_lock);
}
void Osal_nwalCsExit(uint32_t key)
{
- hplib_mSpinLockUnlock(&nwal_lock);
+ p_lock_if->unlock(&posalShm->nwal_lock);
}
-
void Osal_qmssLog ( String fmt, ... )
{
+ return;
}
void Osal_cppiCsEnter (uint32_t *key)
{
- hplib_mSpinLockLock(&cppi_lock);
+ p_lock_if->lock(&posalShm->cppi_lock);
}
void Osal_cppiCsExit (uint32_t key)
{
- hplib_mSpinLockUnlock(&cppi_lock);
+ p_lock_if->unlock(&posalShm->cppi_lock);
}
void Osal_paBeginMemAccess (Ptr addr, uint32_t size)
{
- /* Stub Function. TBD: Would need to handle when for multi proc access
- * To be handled once infrastructure is available from Kernel
- */
-
+ /*No implementation required for ARM*/
}
void Osal_paEndMemAccess (Ptr addr, uint32_t size)
{
- /* Stub Function. TBD: Would need to handle when for multi proc access
- * To be handled once infrastructure is available from Kernel
- */
+ /*No implementation required for ARM*/
}
void Osal_paMtCsEnter (uint32_t *key)
{
- /* Stub Function. TBD: Would need to handle when for multi proc access
- * To be handled once infrastructure is available from Kernel
- */
+ /*No implementation required for ARM*/
}
void Osal_paMtCsExit (uint32_t key)
{
- /* Stub Function. TBD: Would need to handle when for multi proc access
- * To be handled once infrastructure is available from Kernel
- */
+ /*No implementation required for ARM*/
}
-
void* Osal_qmssCsEnter ()
{
- hplib_mSpinLockLock(&qmss_lock);
+ p_lock_if->lock(&posalShm->qmss_lock);
return NULL;
}
void Osal_qmssCsExit (void * key)
{
- hplib_mSpinLockUnlock(&qmss_lock);
+ p_lock_if->unlock(&posalShm->qmss_lock);
}
Ptr Osal_qmssMalloc (uint32_t num_bytes)
{
Ptr ret;
-
+
Osal_qmss_MallocCounter++;
- ret = malloc (num_bytes);
- if(ret==NULL)
- {
- System_printf("\nERROR! QMSS Malloc failed!\n");
- }
-
+ ret = malloc (num_bytes);
return ret;
}
//num_bytes += (CACHE_L2_LINESIZE-1);
num_bytes += (127);
ret = malloc (num_bytes);
-
- if(ret==NULL)
- {
- System_printf("\nERROR! CPPI Malloc failed!\n");
- }
-
return ret;
}
void Osal_qmssBeginMemAccess (void *blockPtr, uint32_t size)
{
- //Osal_invalidateCache(blockPtr,size);
return;
}
void Osal_qmssEndMemAccess (void *blockPtr, uint32_t size)
{
- //Osal_writeBackCache(blockPtr,size);
return;
}
void Osal_cppiBeginMemAccess (void *blockPtr, uint32_t size)
{
- //Osal_invalidateCache(blockPtr,size);
return;
}
void Osal_cppiEndMemAccess (void *blockPtr, uint32_t size)
{
- //Osal_writeBackCache(blockPtr,size);
return;
}
void Osal_nwalInvalidateCache (void *blockPtr, uint32_t size)
{
- //hplib_cacheInv(blockPtr,size);
return;
}
void Osal_nwalWriteBackCache (void *blockPtr, uint32_t size)
{
- //hplib_cacheWb(blockPtr,size);
return;
}
return x;
}
+
+void Osal_nwalSetProcId (uint16_t core_id )
+{
+ our_core = core_id;
+}
+
+
+
+void Osal_setHplibSpinLockIfType(hplib_spinLock_Type if_type )
+{
+ if (if_type == hplib_spinLock_Type_MP)
+ p_lock_if = &lock_if_mp;
+ else
+ p_lock_if = &lock_if_lol;
+}
uint16_t Osal_nwalGetProcId (void )
{
- return DNUM;
+ return our_core;
}
+
uint64_t Osal_nwalGetTimeStamp(void)
{
- /* Stub function to return timestamp
- */
return hplib_mUtilGetTimestamp();
}
void Osal_saBeginScAccess (void* addr, uint32_t size)
{
- //Osal_invalidateCache(addr,size);
hplib_cacheInv(addr,size);
}
void Osal_saEndScAccess (void* addr, uint32_t size)
{
- //Osal_writeBackCache(addr,size);
hplib_cacheWb(addr,size);
}
void Osal_saCsEnter (uint32_t *key)
{
- hplib_mSpinLockLock(&sa_lock);
+ p_lock_if->lock(&posalShm->sa_lock);
}
void Osal_saCsExit (uint32_t key)
{
- hplib_mSpinLockUnlock(&sa_lock);
+ p_lock_if->unlock(&posalShm->sa_lock);
}
void Osal_saMtCsEnter (uint32_t *key)
{
- hplib_mSpinLockLock(&sa_lock);
+ p_lock_if->lock(&posalShm->sa_lock);
}
void Osal_saMtCsExit (uint32_t key)
{
- hplib_mSpinLockUnlock(&sa_lock);
+ p_lock_if->unlock(&posalShm->sa_lock);
}
void Osal_saBeginMemAccess (void *blockPtr, uint32_t size)
* For NWAL layer no protection required.
*
* For testing we are not doing any of this so we are simply setting it to NOOP */
- hplib_mSpinLockLock(&pktlib_lock);
+ p_lock_if->lock(&posalShm->pktlib_lock);
return NULL;
}
@@ -408,11 +468,10 @@ void Osal_pktLibExitCriticalSection(Pktlib_HeapHandle heapHandle, void* csHandl
* For NWAL layer no protection required..
*
* For testing we are not doing any of this so we are simply setting it to NOOP */
- hplib_mSpinLockUnlock(&pktlib_lock);
- return;
+ p_lock_if->unlock(&posalShm->pktlib_lock);
+ return;
}
-
void* Osal_pktLibPhyToVirt(void *ptr)
{
return(hplib_mVMPhyToVirt(ptr));
******************************************************************************/
//#define ASSUME_ALL_DESCRIPTOR //define this if mono and host descriptors are present, else don't
//define and just host will be assumed (more efficient)
-void* Osal_qmssConvertDescVirtToPhy(void *descAddr)
+void* Osal_qmssConvertDescVirtToPhy(uint32_t QID, void *descAddr)
{
- hplib_utilConvertDescVirtToPhy(descAddr);
+ return hplib_mVMConvertDescVirtToPhy(descAddr);
}
/******************************************************************************
* Function to traverse a CPPI descriptor and convert all address references
* from physical to virtual.
******************************************************************************/
-void* Osal_qmssConvertDescPhyToVirt(void *descAddr)
+void* Osal_qmssConvertDescPhyToVirt(uint32_t QID, void *descAddr)
{
- hplib_utilConvertDescPhyToVirt(descAddr);
+ return hplib_mVMConvertDescPhyToVirt(descAddr);
}
void* Osal_stubCsEnter (void)
{
-
-
+ return NULL;
}
void Osal_stubCsExit (void *CsHandle)
{
- /* Release Semaphore using handle */
-
-
return;
}
+
+/* Internal Function used by hplib */
void* Osal_hplibCsEnter (void)
{
-
- hplib_mSpinLockLock(&hplib_lock);
-
+ p_lock_if->lock(&posalShm->hplib_lock);
+ return NULL;
}
+/* Internal Function used by hplib */
+
void Osal_hplibCsExit (void *CsHandle)
{
- hplib_mSpinLockUnlock(&hplib_lock);
-
+ p_lock_if->unlock(&posalShm->hplib_lock);
return;
}
+#endif