summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: a2d1e2f)
raw | patch | inline | side by side (parent: a2d1e2f)
author | Tinku Mannan <tmannan@ti.com> | |
Sat, 20 Jul 2013 12:22:45 +0000 (08:22 -0400) | ||
committer | Tinku Mannan <tmannan@ti.com> | |
Sat, 20 Jul 2013 12:22:45 +0000 (08:22 -0400) |
index a5bbae20d9947c97ee0b70036e8e07289cfbd8e4..1012824e90befeae7bf787fad67f90627100185d 100755 (executable)
extern uint32_t hplib_VM_virt_to_phy_mapping;
extern uint32_t hplib_VM_phy_to_virt_mapping;
extern hplib_virtualMemPoolAddr_T memPoolAddr[];
-extern hplib_vm_shm_T* phplibShm;
/**
@defgroup HPLIB_CACHE_API High Performance Library Cache API's
index 82e00870a6e2204c420808f9115c119bb449b368..8eb22077f70053b1504d330620bc912e3acea847 100755 (executable)
extern uint32_t hplib_VM_virt_to_phy_mapping;
extern uint32_t hplib_VM_phy_to_virt_mapping;
extern hplib_virtualMemPoolAddr_T memPoolAddr[];
-extern hplib_vm_shm_T* phplibShm;
/** @defgroup hplib_memPoolAttr
* @ingroup HPLIB_VM_API
index 0c88dfa445699351bcd0ee57d10a005de7191531..f73272d25f6eddb9f89bb10c86917ae8293b9b82 100755 (executable)
static struct class *hplibmod_class;
static int hplibmod_major;
-static atomic_t reference_count = ATOMIC_INIT(0);
static dma_addr_t dmaAddr; /*physical address of CMA region */
static void * cpuAddr=NULL; /* virtual address for above */
static int hplibmod_open(struct inode *inode, struct file *filp)
{
__D("open: called.\n");
-
- if (atomic_read(&reference_count) > 8) {
- __D("open: device already in use.\n");
- return -EBUSY;
- }
-
- atomic_inc(&reference_count);
return 0;
}
static int hplibmod_release(struct inode *inode, struct file *filp)
{
__D("close: called.\n");
-
- atomic_dec(&reference_count);
return 0;
}
*********************************************************************************/
static void __exit hplibmod_cleanup_module(void)
{
- if (atomic_read(&reference_count)) {
- __D("hplib device still in use");
- }
-
/* Remove netapi device */
device_destroy(hplibmod_class, MKDEV(hplibmod_major, 0));
unregister_chrdev(hplibmod_major, HPLIBMOD_DEVNAME);
index 5d272bbda59d17b1cd8c7a1f926cdaabc6588228..401474ba205f3bea12603c361a7bb9625d1a7587 100755 (executable)
uint32_t hplib_VM_virt_to_phy_mapping;
uint32_t hplib_VM_phy_to_virt_mapping;
} hplib_virtualMemPoolAddr_T;
-typedef struct hplib_vm_shm_Tag
-{
- hplib_virtualMemPoolAddr_T memPoolAddr[HPLIB_MAX_MEM_POOLS];
- uint8_t *hplib_VM_mem_start_phy;
- uint8_t *hplib_VM_mem_start;
- uint8_t *hplib_VM_mem_end;
- uint8_t *hplib_VM_mem_end_phy;
- uint8_t *hplib_VM_mem_alloc_ptr;
- uint32_t hplib_VM_mem_size;
- uint32_t hplib_VM_virt_to_phy_mapping;
- uint32_t hplib_VM_phy_to_virt_mapping;
-} hplib_vm_shm_T;
+
+
+
/************** NON API utility functions *******************/
index 6b4e62d17ba6fc05e3630dabe4eca93b5f9031d0..733932286965ec1016d537ad4601ecdc6c59593e 100755 (executable)
static int shm_key = 100;
//static int shm_size = 8192;
static int shm_id = 0;
-hplib_vm_shm_T global_shm;
/**************************************************************************
index 786e3834f9b106a83c3b16fff6d539ba92222322..163a5db621d0c6c788e5263f4c64d3dab21d344f 100755 (executable)
if (hplib_mod_fd == -1)
{
+ printf("hplib_utilModOpen error\n");
return -1;
}
return hplib_mod_fd;
hplib_RetValue hplib_utilSetupThread(int threadId, cpu_set_t *pSet)
{
- printf("hplib_utilSetupThread (thread: %d): hplib_mod_fd %d\n", threadId, hplib_mod_fd);
if (hplib_mod_fd == -1)
{
- printf("hplib_utilSetupThread (thread: %d): calling mod open\n", threadId);
- hplib_mod_fd=hplib_utilModOpen();
- printf("hplib_utilSetupThread (thread: %d): hplib_mod_fd after mod open %d\n", threadId, hplib_mod_fd);
- if (hplib_mod_fd == -1)
- {
- hplib_Log("hplib_utilSetupThread (thread: %d): failed to open /dev/hplib: '%s'\n",
- threadId, strerror(errno));
- return HPLIB_FALSE;
- }
+ hplib_utilModOpen();
}
+ printf("hplib_utilSetupThread (thread: %d): hplib_mod_fd %d\n", threadId, hplib_mod_fd);
if (sched_setaffinity( gettid(), sizeof( cpu_set_t ), pSet ))
{
return hplib_FAILURE;
}
Osal_nwalSetProcId(threadId);
return (hplib_utilInitProc());
- hplib_utilModClose();
}
index 9f6aeab15bd04f7fdca848810f407b130e14e9e9..d710f970eff6deda66a86c6e1a1411b4870d6101 100755 (executable)
/* Macro to align x to y */
#define align(x,y) ((x + y) & (~y))
-hplib_vm_shm_T* phplibShm = NULL;
hplib_virtualMemPoolAddr_T memPoolAddr[HPLIB_MAX_MEM_POOLS];
uint8_t *hplib_VM_mem_start_phy = (uint8_t*)0;
/* File descriptor for /dev/mem */
static int dev_mem_fd;
-extern int hplib_mod_fd;
-
-#define HPLIB_USE_MODULE_MMAP //we will mmap through hplib kernel module, not /dev/mem
-#ifndef HPLIB_USE_MODULE_MMAP
-static int temp_fd;
-#endif
-
/**************************************************************************
* FUNCTION PURPOSE: Maps the give physical address to virtual memory space
**************************************************************************/
)
{
void *map_base = NULL;
- hplib_VirtMemPoolheader_T *poolHdr;
-
+
/* Set up memory mapping for un-cached memory, this requires physical address and size of memory region to map*/
if ((addr != NULL ) && size)
{
memPoolAddr[i].memPoolHdr = memPoolAddr[i].memStart = map_base;
- poolHdr = (hplib_VirtMemPoolheader_T*) memPoolAddr[i].memStart;
- if (poolHdr->ref_count == 0)
- {
- /* 1st time */
- printf("hplib_VM_MemAllocInit:memStart (firstTime true): 0x%x\n",
- memPoolAddr[i].memStart);
- poolHdr->ref_count++;
- poolHdr->virtMemAllocOffset = sizeof(hplib_VirtMemPoolheader_T);
- }
- else
- {
- /* not 1st time, just bump reference count */
- poolHdr->ref_count++;
- printf("hplib_VM_MemAllocInit:memStart (firstTime false): 0x%x\n",
- memPoolAddr[i].memStart);
- }
-
memPoolAddr[i].memSize = size;
memPoolAddr[i].memEnd = memPoolAddr[i].memStart + size;
memPoolAddr[i].memStartPhy = addr;
{
addr= ( uint8_t *) hplib_utilGetPhysOfBufferArea(); //get address that was allocated for us by kernela module */
size = hplib_utilGetSizeOfBufferArea(); //get the size that was allocated
-#ifdef HPLIB_USE_MODULE_MMAP
map_base = (void *) hplib_utilGetVaOfBufferArea(HPLIBMOD_MMAP_DMA_MEM_OFFSET, size); //mmap into our space, return va
-#endif
memPoolAddr[i].memPoolHdr = memPoolAddr[i].memStart = map_base;
memPoolAddr[i].memSize =size;
memPoolAddr[i].memEnd = memPoolAddr[i].memStart + size;
memPoolAddr[i].memStartPhy = addr;
memPoolAddr[i].memEndPhy = memPoolAddr[i].memStartPhy + memPoolAddr[i].memSize;
- poolHdr = (hplib_VirtMemPoolheader_T*) memPoolAddr[i].memStart;
- if (poolHdr->ref_count == 0)
- {
- /* 1st time */
- printf("hplib_VM_MemAllocInit:memStart (firstTime true): 0x%x\n",
- memPoolAddr[i].memStart);
-
- poolHdr->ref_count++;
- poolHdr->virtMemAllocOffset = sizeof(hplib_VirtMemPoolheader_T);
- }
- else
- {
- /* not 1st time, just bump reference count */
- poolHdr->ref_count++;
- printf("hplib_VM_MemAllocInit:memStart (firstTime false): 0x%x\n",
- memPoolAddr[i].memStart);
- }
-
hplib_Log("hplib_VM_MemAllocInit(cached): Phy Addr %x Memory (%d bytes) mapped at address %p.\n", addr,size, map_base);
hplib_Log("hplib_VM_MemAllocInit(cached): End_phy 0x%x, start_phy: 0x%x\n", memPoolAddr[i].memEndPhy, memPoolAddr[i].memStartPhy);
}
{
hplib_utilModClose();
close(dev_mem_fd);
-#ifndef HPLIB_USE_MODULE_MMAP
- close(temp_fd);
-#endif
}
+
+int hplibp_checkMallocArea(pool_id)
+{
+ hplib_VirtMemPoolheader_T *poolHdr;
+ poolHdr = (hplib_VirtMemPoolheader_T*) memPoolAddr[pool_id].memStart;
+ if(poolHdr->ref_count)
+ return hplib_OK;
+ else
+ return hplib_FAILURE;
+}
+
+
+int hplibp_initMallocArea(int pool_id)
+{
+ hplib_VirtMemPoolheader_T *poolHdr;
+ poolHdr = (hplib_VirtMemPoolheader_T*) memPoolAddr[pool_id].memStart;
+ poolHdr->virtMemAllocOffset = sizeof(hplib_VirtMemPoolheader_T);
+ poolHdr->ref_count++;
+
+}
/********************************************************************
* FUNCTION PURPOSE: Allocate continuous block of cached memory via CMA and
* optionally un-cached memory if specified, maps virtual memory for peripheral registers.
********************************************************************/
hplib_RetValue hplib_vmInit(hplib_virtualAddrInfo_T *hplib_vmaddr, int num_pools, hplib_memPoolAttr_T *mempool_attr)
{
- static int first_time = HPLIB_TRUE;
int i;
- void* pBase = NULL;
- hplib_shmInfo_T* pshmBase;
- if (first_time == HPLIB_TRUE)
- {
- pshmBase = (hplib_shmInfo_T*)hplib_shmOpen();
- if (pshmBase == NULL)
- {
- printf("main: hplib_shmOpen failure\n");
- exit(1);
- }
-
- printf("pshmBase size %d, free %d\n",
- pshmBase->size,
- pshmBase->free_offset);
-
-
- //pBase = hplib_shmOpen();
- hplib_shmAddEntry((void*)pshmBase, sizeof(hplib_vm_shm_T),HPLIB_ENTRY);
- phplibShm = (hplib_vm_shm_T*)hplib_shmGetEntry((void*)pshmBase, HPLIB_ENTRY);
- Osal_create(first_time);
- first_time = HPLIB_FALSE;
- }
- else
- {
- hplib_Log("hplib_vmInit(): already called, returning\n");
- pBase = hplib_shmOpen();
- phplibShm = (hplib_vm_shm_T*)hplib_shmGetEntry(pBase, HPLIB_ENTRY);
- return 1;
- }
-
+
if (num_pools == 0)
{
hplib_Log("hplib_vmInit(): Error, invalid number of pools\n");
@@ -357,15 +298,11 @@ hplib_RetValue hplib_vmInit(hplib_virtualAddrInfo_T *hplib_vmaddr, int num_pools
return HPLIB_FALSE;
}
/* Open kernel module since we need it for PA to VA mappings */
- if (hplib_mod_fd == -1)
- {
- hplib_mod_fd=hplib_utilModOpen();
- if (hplib_mod_fd == -1)
- {
- hplib_Log("hplib_vmInit:: failed to open /dev/netapi: '%s'\n", strerror(errno));
- return HPLIB_FALSE;
- }
+ if (hplib_utilModOpen() == -1)
+ {
+ hplib_Log("hplib_vmInit:: failed to open /dev/netapi: '%s'\n", strerror(errno));
+ return HPLIB_FALSE;
}
for (i=0;i < num_pools; i++)
{
@@ -401,9 +338,7 @@ hplib_RetValue hplib_vmInit(hplib_virtualAddrInfo_T *hplib_vmaddr, int num_pools
(void*)QMSS_CFG_BASE_ADDR, hplib_vmaddr->qmssCfgVaddr);
/*QMSS DATA Regs */
-#ifdef HPLIB_USE_MODULE_MMAP
hplib_vmaddr->qmssDataVaddr = (void *) hplib_utilGetVaOfBufferArea(HPLIBMOD_MMAP_QM_DATA_REG_MEM_OFFSET, QMSS_DATA_BLK_SZ);
-#endif
if (!hplib_vmaddr->qmssDataVaddr)
{
@@ -445,5 +380,3 @@ hplib_RetValue hplib_vmInit(hplib_virtualAddrInfo_T *hplib_vmaddr, int num_pools
}
-
-
index 1006db8076b9fc2794c51f7bb4088ad3ccb0d5a0..0b4ed555c0eed8b5e8ad4e52f34471902c4bc451 100755 (executable)
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;
void Osal_cache_op_measure_reset(void) { cache_op_cycles=0; n_cache_op_cycles=0;}
unsigned int Osal_cache_op_measure(unsigned long long * p_n) { *p_n = n_cache_op_cycles; return cache_op_cycles;}
-#if 0
-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;
-#endif
-int Osal_create(int first_time)
+/* This is called 1 Time per system boot by the global master process */
+int Osal_create()
{
int retVal = hplib_OK;
pBase = hplib_shmOpen();
- if (first_time == HPLIB_TRUE)
- {
- if ((retVal = hplib_shmAddEntry(pBase, sizeof(osal_shm_T), OSAL_ENTRY)) !=
- hplib_OK)
+
+ if ((retVal = hplib_shmAddEntry(pBase, sizeof(osal_shm_T), OSAL_ENTRY)) !=
+ hplib_OK)
{
printf("Osal_create: hplib_shmAddEntry failed for OSAL_ENTRY\n");
return retVal;
}
else
{
+ posalShm = (osal_shm_T*)hplib_shmGetEntry(pBase, OSAL_ENTRY);
+ posalShm->init_done = 0;
printf("Osal_create: hplib_shmAddEntry sucess for OSAL_ENTRY\n");
}
- }
posalShm = (osal_shm_T*)hplib_shmGetEntry(pBase, OSAL_ENTRY);
posalShm->sa_lock = hplib_spinLock_UNLOCKED_INITIALIZER;
posalShm->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 */
+int Osal_start()
+{
+ posalShm = (osal_shm_T*)hplib_shmGetEntry(pBase, OSAL_ENTRY);
+ if (posalShm)
+ {
+ if(posalShm->init_done)
+ return hplib_OK;
+ }
+ return hplib_FAILURE;
+}
+
void * Osal_qmssMtCsEnter()
{
hplib_mSpinLockLock(&posalShm->qmss_lock);
{
return;
}
+
+/* Internal Function used by hplib */
void* Osal_hplibCsEnter (void)
{
hplib_mSpinLockLock(&posalShm->hplib_lock);
return NULL;
}
+/* Internal Function used by hplib */
+
void Osal_hplibCsExit (void *CsHandle)
{
hplib_mSpinLockUnlock(&posalShm->hplib_lock);
index d4918822ec9f112eb14cacd5f1e3ceae69de530f..276ed02b0948e303e968286a8ebf743c621a2a48 100755 (executable)
#define __E(fmt, args...) fprintf(stderr, "HPLIBMODTEST Error: " fmt, ## args)
-static int hplib_mod_fd;
-
+//static int hplib_mod_fd;
+extern int hplib_mod_fd;
int hplibmod_init(void)
{
hplib_mod_fd = open("/dev/hplib", O_RDWR);