From 3e80c2de11cf75fef3304ab68c2a0099005459f2 Mon Sep 17 00:00:00 2001 From: Tinku Mannan Date: Fri, 21 Nov 2014 14:52:10 -0500 Subject: [PATCH] Incorporate comments from team porting Linaro ODP to MCSDK3.x --- ti/runtime/hplib/.gitignore | 6 +++ ti/runtime/hplib/hplib_cache.h | 9 ++++ ti/runtime/hplib/hplib_shm.h | 4 +- ti/runtime/hplib/hplib_vm.h | 17 +++++- ti/runtime/hplib/module/.gitignore | 6 +++ ti/runtime/hplib/src/hplib_shm.c | 16 +++--- ti/runtime/hplib/src/hplib_util.c | 4 +- ti/runtime/hplib/src/osal.c | 82 +++++++++++++++++++++++++++++ ti/runtime/hplib/test/bmAllocTest.c | 4 +- ti/runtime/hplib/test/shmtest.c | 2 +- 10 files changed, 133 insertions(+), 17 deletions(-) create mode 100644 ti/runtime/hplib/.gitignore mode change 100755 => 100644 ti/runtime/hplib/hplib_cache.h mode change 100755 => 100644 ti/runtime/hplib/hplib_shm.h mode change 100755 => 100644 ti/runtime/hplib/hplib_vm.h create mode 100644 ti/runtime/hplib/module/.gitignore mode change 100755 => 100644 ti/runtime/hplib/src/hplib_shm.c mode change 100755 => 100644 ti/runtime/hplib/src/hplib_util.c mode change 100755 => 100644 ti/runtime/hplib/src/osal.c mode change 100755 => 100644 ti/runtime/hplib/test/bmAllocTest.c mode change 100755 => 100644 ti/runtime/hplib/test/shmtest.c diff --git a/ti/runtime/hplib/.gitignore b/ti/runtime/hplib/.gitignore new file mode 100644 index 0000000..463121b --- /dev/null +++ b/ti/runtime/hplib/.gitignore @@ -0,0 +1,6 @@ +*.o +*.a +*.so +*.so.* +.created +/bin diff --git a/ti/runtime/hplib/hplib_cache.h b/ti/runtime/hplib/hplib_cache.h old mode 100755 new mode 100644 index ddd1a06..88618ae --- a/ti/runtime/hplib/hplib_cache.h +++ b/ti/runtime/hplib/hplib_cache.h @@ -115,6 +115,9 @@ static inline hplib_RetValue hplib_cacheWb(void *ptr, size_t size) { return hplib_FAILURE; } +#else + (void)ptr; + (void)size; #endif return hplib_OK; } @@ -144,6 +147,9 @@ static inline hplib_RetValue hplib_cacheWbInv(void *ptr, size_t size) if (ioctl(hplib_mod_fd, HPLIBMOD_IOCCACHEWBINV | HPLIBMOD_IOCMAGIC, &block) == -1) { return hplib_FAILURE; } +#else + (void)ptr; + (void)size; #endif return hplib_OK; } @@ -172,6 +178,9 @@ static inline hplib_RetValue hplib_cacheInv(void *ptr, size_t size) if (ioctl(hplib_mod_fd, HPLIBMOD_IOCCACHEINV | HPLIBMOD_IOCMAGIC, &block) == -1) { return hplib_FAILURE; } +#else + (void)ptr; + (void)size; #endif return hplib_OK; } diff --git a/ti/runtime/hplib/hplib_shm.h b/ti/runtime/hplib/hplib_shm.h old mode 100755 new mode 100644 index a36c52a..5ee6086 --- a/ti/runtime/hplib/hplib_shm.h +++ b/ti/runtime/hplib/hplib_shm.h @@ -137,7 +137,7 @@ void* hplib_shmCreate(int size); * @retval * void* base address of the shared memory segment, NULL on error */ -void* hplib_shmOpen(); +void* hplib_shmOpen(void); /** * @b Description @@ -146,7 +146,7 @@ void* hplib_shmOpen(); * @retval * hplib_RetValue, @ref hplib_RetValue */ -hplib_RetValue hplib_shmDelete(); +hplib_RetValue hplib_shmDelete(void); /** * @b Description diff --git a/ti/runtime/hplib/hplib_vm.h b/ti/runtime/hplib/hplib_vm.h old mode 100755 new mode 100644 index 4cba899..1f5a3e9 --- a/ti/runtime/hplib/hplib_vm.h +++ b/ti/runtime/hplib/hplib_vm.h @@ -313,9 +313,10 @@ static inline void* hplib_mVMVirtToPhy (void *ptr) */ static inline void * hplib_mVMPhyToVirtPoolId (void *ptr, uint8_t pool_id) { - if (pool_id > (HPLIB_MAX_MEM_POOLS -1)); + if (pool_id > (HPLIB_MAX_MEM_POOLS -1)) return (void *) hplib_OK; - if (!ptr) return (void *) hplib_OK; + if (!ptr) return + (void *) hplib_OK; if (((uint8_t *)ptr memPoolAddr[pool_id].memEndPhy)) return (void *) hplib_OK; @@ -501,6 +502,18 @@ hplib_RetValue hplib_initMallocArea(int pool_id); */ hplib_RetValue hplib_checkMallocArea(int pool_id); +/** + * @b Description + * @n + * The function API is used to map the given physical address + * to virtual memory space. + * @param[in] addr + * Physical address pointer of memory space + * @param[in] size size of memory to be mapped + * @retval + * Virtual address pointer of mapped memory space + */ +void *hplib_VM_MemMap(void* addr, uint32_t size); #ifdef __cplusplus } diff --git a/ti/runtime/hplib/module/.gitignore b/ti/runtime/hplib/module/.gitignore new file mode 100644 index 0000000..94dbfb9 --- /dev/null +++ b/ti/runtime/hplib/module/.gitignore @@ -0,0 +1,6 @@ +*.ko +.*.cmd +*.mod.c +modules.order +Module.symvers +.tmp_versions diff --git a/ti/runtime/hplib/src/hplib_shm.c b/ti/runtime/hplib/src/hplib_shm.c old mode 100755 new mode 100644 index 038ae03..f6834ab --- a/ti/runtime/hplib/src/hplib_shm.c +++ b/ti/runtime/hplib/src/hplib_shm.c @@ -77,14 +77,14 @@ void* hplib_shmCreate(int size) if (shm_id < 0) { - printf("hplib_shmCreate: shmget error\n"); + hplib_Log("hplib_shmCreate: shmget error\n"); return NULL; } else { pBase = (hplib_shmInfo_T*)shmat(shm_id, 0,0); if (pBase == (hplib_shmInfo_T*)-1) - printf("hplib_shmCreate: shmat error\n"); + hplib_Log("hplib_shmCreate: shmat error\n"); else { pBase->size = size; @@ -108,7 +108,7 @@ void* hplib_shmOpen(void) shm_id = shmget(shm_key, 0, 0666 ); if (shm_id < 0) { - printf("hplib_shmOpen: shmget error\n"); + hplib_Log("hplib_shmOpen: shmget error\n"); return NULL; } else @@ -122,7 +122,7 @@ void* hplib_shmOpen(void) pBase = (hplib_shmInfo_T*)shmat(shm_id, 0,0); if (pBase == (hplib_shmInfo_T*)-1) { - printf("hplib_shmOpen: shmat error\n"); + hplib_Log("hplib_shmOpen: shmat error\n"); return NULL; } @@ -133,12 +133,12 @@ void* hplib_shmOpen(void) /************************************************************************** * FUNCTION PURPOSE: Delete Shared Memory Segment **************************************************************************/ -hplib_RetValue hplib_shmDelete() +hplib_RetValue hplib_shmDelete(void) { shm_id = shmget(shm_key, 0, 0666 ); if (shm_id < 0) { - printf("hplib_shmOpen: shmget error\n"); + hplib_Log("hplib_shmOpen: shmget error\n"); return hplib_FAILURE; } else @@ -146,7 +146,7 @@ hplib_RetValue hplib_shmDelete() int err=shmctl(shm_id, IPC_RMID, 0); if(err<0) { - printf("hplib_shmDelete: shmctl failed\n"); + hplib_Log("hplib_shmDelete: shmctl failed\n"); return hplib_FAILURE; } } @@ -162,7 +162,7 @@ hplib_RetValue hplib_shmAddEntry(void* base, int size, hplib_shmEntryId_E entryI if ((pBase->free_offset + size) > pBase->size) { - printf("hplib_shmAddEntry: insufficient memory request, size %d\n", size); + hplib_Log("hplib_shmAddEntry: insufficient memory request, size %d\n", size); return hplib_ERR_NOMEM; } diff --git a/ti/runtime/hplib/src/hplib_util.c b/ti/runtime/hplib/src/hplib_util.c old mode 100755 new mode 100644 index 751a5c6..872a035 --- a/ti/runtime/hplib/src/hplib_util.c +++ b/ti/runtime/hplib/src/hplib_util.c @@ -86,7 +86,7 @@ int hplib_utilModOpen(void) if (hplib_mod_fd == -1) { - printf("hplib_utilModOpen error\n"); + hplib_Log("hplib_utilModOpen error\n"); return -1; } return hplib_mod_fd; @@ -177,7 +177,7 @@ hplib_RetValue hplib_utilSetupThread(int threadId, { hplib_utilModOpen(); } - if (sched_setaffinity( gettid(), sizeof( cpu_set_t ), pSet )) + if (pSet && sched_setaffinity( gettid(), sizeof( cpu_set_t ), pSet )) { return hplib_FAILURE; } diff --git a/ti/runtime/hplib/src/osal.c b/ti/runtime/hplib/src/osal.c old mode 100755 new mode 100644 index 9d80c28..4d8fd4e --- a/ti/runtime/hplib/src/osal.c +++ b/ti/runtime/hplib/src/osal.c @@ -46,6 +46,8 @@ #include #include +#include +#include #include "hplib.h" #include @@ -60,6 +62,7 @@ #include "hplibmod.h" #include #include +#include typedef struct osal_shm_Tag { @@ -69,6 +72,7 @@ typedef struct osal_shm_Tag hplib_spinLock_T cppi_lock; hplib_spinLock_T sa_lock; hplib_spinLock_T pktlib_lock; + hplib_spinLock_T rm_lock; int init_done; } osal_shm_T; @@ -82,6 +86,8 @@ uint32_t Osal_cppi_FreeCounter =0; static __thread int our_core = 0; static __thread HPLIB_SPINLOCK_IF_T* p_lock_if; +uint32_t Osal_rm_MallocCounter = 0; +uint32_t Osal_rm_FreeCounter = 0; void* Osal_saGetSCPhyAddr(void* vaddr); @@ -144,6 +150,7 @@ hplib_RetValue hplib_utilOsalCreate() posalShm->cppi_lock = hplib_spinLock_UNLOCKED_INITIALIZER; posalShm->sa_lock = hplib_spinLock_UNLOCKED_INITIALIZER; posalShm->pktlib_lock = hplib_spinLock_UNLOCKED_INITIALIZER; + posalShm->rm_lock = hplib_spinLock_UNLOCKED_INITIALIZER; posalShm->init_done = 1; return retVal; @@ -514,6 +521,81 @@ void Osal_stubCsExit (void *CsHandle) return; } +void *Osal_rmMalloc (uint32_t num_bytes) +{ + /* Increment the allocation counter. */ + Osal_rm_MallocCounter++; + + /* Allocate memory. */ + return calloc(1, num_bytes); +} + +void Osal_rmFree (void *ptr, uint32_t size) +{ + /* Increment the free counter. */ + Osal_rm_FreeCounter++; + free(ptr); +} + +void *Osal_rmCsEnter(void) +{ + return NULL; +} + +void Osal_rmCsExit(void *CsHandle) +{ + +} + +void Osal_rmBeginMemAccess(void *ptr, uint32_t size) +{ + return; +} + +void Osal_rmEndMemAccess(void *ptr, uint32_t size) +{ + return; +} + +void *Osal_rmTaskBlockCreate(void) +{ + return(NULL); +} + +void Osal_rmTaskBlock(void *handle) +{ + +} + +void Osal_rmTaskUnblock(void *handle) +{ + +} + +void Osal_rmTaskBlockDelete(void *handle) +{ + +} + +void Osal_rmLog (char *fmt, ... ) +{ + va_list ap; + + va_start(ap, fmt); + vprintf(fmt, ap); + va_end(ap); +} + +void *Osal_rmMtCsEnter(void *mtSemObj) +{ + return NULL; +} + + +void Osal_rmMtCsExit(void *mtSemObj, void *CsHandle) +{ + +} /* Internal Function used by hplib */ void* Osal_hplibCsEnter (void) { diff --git a/ti/runtime/hplib/test/bmAllocTest.c b/ti/runtime/hplib/test/bmAllocTest.c old mode 100755 new mode 100644 index 0ec6eaa..d305450 --- a/ti/runtime/hplib/test/bmAllocTest.c +++ b/ti/runtime/hplib/test/bmAllocTest.c @@ -117,7 +117,7 @@ static void* thread_routineP(void* arg) cpu_set_t cpu_set; hplib_VirtMemPoolheader_T *poolHdr; - pShmBase = hplib_shmOpen(SHM_SIZE); + pShmBase = hplib_shmOpen(); if(pShmBase == NULL) { printf("main: hplib_shmCreate failed\n"); @@ -247,7 +247,7 @@ main(int argc, char * argv[]) break; case(2): /* Shutdown */ - hplib_shmDelete(p); + hplib_shmDelete(); hplib_mod_fd=hplib_utilModOpen(); if (hplib_mod_fd == -1) { diff --git a/ti/runtime/hplib/test/shmtest.c b/ti/runtime/hplib/test/shmtest.c old mode 100755 new mode 100644 index e4e5adb..1d9ff83 --- a/ti/runtime/hplib/test/shmtest.c +++ b/ti/runtime/hplib/test/shmtest.c @@ -102,7 +102,7 @@ main(int argc, char * argv[]) case(2): /* delete */ //fd = shmget(key, SHM_SIZE, 0666 ); - hplib_shmDelete(p); + hplib_shmDelete(); hplib_mod_fd=hplib_utilModOpen(); if (hplib_mod_fd == -1) { -- 2.39.2