Files
2026-07-30 11:19:44 +05:30

304 lines
8.1 KiB
C

/*
******************************************************************************
* SOURCE FILE
*
* Document no: @(#) $Name: VXWORKS_ITER40_2019102207 $ $RCSfile: xx.c,v $ $Revision: 1.7 $
* $Source: /home/interpeak/CVSRoot/ipfreescale/sec4/xx.c,v $
* $Author: dhessing $
* $State: Exp $ $Locker: $
*
* INTERPEAK_COPYRIGHT_STRING
******************************************************************************
*/
/*
****************************************************************************
* 1 DESCRIPTION
****************************************************************************
*/
/******************************************************************************
� 1995-2003, 2004, 2005-2010 Freescale Semiconductor, Inc.
All rights reserved.
This is proprietary source code of Freescale Semiconductor Inc.,
and its use is subject to the NetComm Device Drivers EULA.
The copyright notice above does not evidence any actual or intended
publication of such source code.
**************************************************************************/
#include <memLib.h> /* For memalign */
#include <intLib.h>
#include <stdlib.h>
#include <stdarg.h>
#include <stdio.h>
#include <spinLockLib.h>
#include "error_ext.h"
/*#include "xx.h"*/
#include <Sec4Driver.h>
#ifdef _WRS_CONFIG_WRHV_GUEST
#include <ipcom_shared_mem.h> /* TODO Should not have ipcom stuff here */
#include <ipcom_vxworks_p4080_forwarder.h>
#include <wrhv/vbi.h>
/* If we are on top of a Hypervisor we need to map physical to virtual addresses */
SEC4_GLOBAL physAddress_t sec4VirtualOffset;
SEC4_GLOBAL physAddress_t sec4VirtualOffsetPackets;
SEC4_GLOBAL physAddress_t sec4VirtualOffsetShDesc;
SEC4_GLOBAL physAddress_t sec4PacketsBase;
SEC4_GLOBAL physAddress_t sec4ShDescBase;
#endif
#ifdef DEBUG_XX_MALLOC
/*****************************************************************************/
void * XX_MallocDebug(uint32_t size, char *fname, int line)
{
void *p;
p = malloc(size);
XX_Print("XX_MallocDebug: p=0x%x, size=%d, %s, [%d]\n",
p,
size,
fname,
line);
return p;
}
/*****************************************************************************/
void * XX_MallocSmartDebug(uint32_t size,
int partitionId,
uint32_t alignment,
char *fname,
int line)
{
void *p;
p = memalign((unsigned) alignment, (unsigned) size);
XX_Print("XX_MallocSmartDebug: p=0x%x, size=%d, align=%d, (partId=%d(unused)), %s, [%d]\n",
p,
size,
alignment,
partitionId,
fname,
line);
return p;
}
/*****************************************************************************/
void XX_Free(void *p_Memory)
{
free(p_Memory);
}
#else /* not DEBUG_XX_MALLOC */
/*****************************************************************************/
void * XX_Malloc(uint32_t size)
{
return malloc(size);
}
/*****************************************************************************/
void * XX_MallocSmart(uint32_t size, int partitionId, uint32_t alignment)
{
void *p;
switch(partitionId)
{
case 0:
p = memalign(alignment, size);
break;
#ifdef _WRS_CONFIG_WRHV_GUEST
case 1:
p = ipcom_shm_alloc_aligned(alignment, size);
break;
#endif
default:
/* Not valid partition ID */
p = NULL;
}
return p;
}
/*****************************************************************************/
void XX_Free(void *p_Memory)
{
free(p_Memory);
}
#endif /* not DEBUG_XX_MALLOC */
/*****************************************************************************/
void XX_FreeSmart(void *p_Memory)
{
#ifdef _WRS_CONFIG_WRHV_GUEST
if(p_Memory > (void *)sec4VirtualOffsetPackets) /* TODO: Clean this up */
ipcom_shm_free(p_Memory);
else
#endif
XX_Free(p_Memory);
}
/*****************************************************************************/
t_Error XX_SetIntr(int irq, t_Isr *f_Isr, t_Handle handle)
{
#ifdef DEBUG
XX_Print("XX_SetIntr() :: Assigning interrupt irq=%d, handler=0x%x, handle=0x%x\n", irq, f_Isr, handle);
#endif
if(intConnect(INUM_TO_IVEC(irq), (VOIDFUNCPTR)f_Isr, (int) handle) == ERROR)
return E_INVALID_INTR_QUEUE;
return E_OK;
}
/*****************************************************************************/
t_Error XX_EnableIntr(int irq)
{
#ifdef DEBUG
XX_Print("XX_EnableIntr() :: Enabling interrupt irq=%d\n", irq);
#endif
if(intEnable(irq)==ERROR)
return E_NOT_AVAILABLE;
return E_OK;
}
/*****************************************************************************/
uint32_t XX_DisableAllIntr(void)
{
return (uint32_t) intCpuLock();
}
/*****************************************************************************/
void XX_RestoreAllIntr(uint32_t flags)
{
intCpuUnlock((int)flags);
}
/*****************************************************************************/
void XX_Exit(int status)
{
#ifdef DEBUG
XX_Print("XX_Exit() called.\n");
#endif
exit(EXIT_FAILURE);
}
/*****************************************************************************/
physAddress_t XX_VirtToPhys(void *addr)
{
#ifdef _WRS_CONFIG_WRHV_GUEST
/* If we are running on top of a hypervisor, translation is needed */
/* TODO: Make this a more generic solution not based on any implicit knowledge
* This implies that packets are at lower address than private memory
* and that area for shared descriptors > packet area */
physAddress_t p;
if((physAddress_t)addr > (physAddress_t)sec4ShDescBase)
{
p = (physAddress_t) ((physAddress_t)addr - (physAddress_t)sec4VirtualOffsetShDesc);
}
else if((physAddress_t)addr > (physAddress_t)sec4PacketsBase)
{
p = (physAddress_t) ((physAddress_t)addr - (physAddress_t)sec4VirtualOffsetPackets);
}
else
{
p = (physAddress_t) ((physAddress_t)addr + (physAddress_t)sec4VirtualOffset);
}
return p;
#else
return (physAddress_t) addr;
#endif
}
/*****************************************************************************/
void * XX_PhysToVirt(physAddress_t addr)
{
#ifdef _WRS_CONFIG_WRHV_GUEST
/* If we are running on top of a hypervisor, translation is needed */
/* TODO: Make this a more generic solution not based on hard coded address.
* Now each NAE has 4000000 of physical memory. */
if(addr < 0x4000000UL)
if(addr < 0x1000000UL) /* TODO */
return (void *) (addr + sec4VirtualOffsetPackets);
else
return (void *) (addr + sec4VirtualOffsetShDesc);
else
return (void *) (addr - sec4VirtualOffset);
#else
return (void *) (uint32_t) addr;
#endif
}
#define BUF_SIZE 1024
/*****************************************************************************/
void XX_Print(char *format, ...)
{
va_list args;
char tmpBuf[BUF_SIZE];
va_start(args, format);
vsnprintf (tmpBuf, BUF_SIZE, format, args);
va_end(args);
#ifdef _WRS_CONFIG_WRHV_GUEST
ipcom_hv_printf(tmpBuf);
#else
printf(tmpBuf);
#endif
}
/*****************************************************************************/
char XX_GetChar(void)
{
return getc(stdin);
}
/*****************************************************************************/
/* Spinlock Service Routines */
/*****************************************************************************/
t_Handle XX_InitSpinlock(void)
{
spinlockIsr_t *spinlock;
spinlock = (spinlockIsr_t *)XX_Malloc(sizeof(spinlockIsr_t));
SPIN_LOCK_ISR_INIT(spinlock, 0);
return (t_Handle) spinlock;
}
void XX_FreeSpinlock(t_Handle h_Spinlock)
{
if (h_Spinlock)
XX_Free(h_Spinlock);
}
void XX_LockSpinlock(t_Handle h_Spinlock)
{
SPIN_LOCK_ISR_TAKE((spinlockIsr_t *) h_Spinlock);
}
void XX_UnlockSpinlock(t_Handle h_Spinlock)
{
SPIN_LOCK_ISR_GIVE((spinlockIsr_t *) h_Spinlock);
}
uint32_t XX_LockIntrSpinlock(t_Handle h_Spinlock)
{
SPIN_LOCK_ISR_TAKE((spinlockIsr_t *) h_Spinlock);
return 0;
}
void XX_UnlockIntrSpinlock(t_Handle h_Spinlock, uint32_t intrFlags)
{
UNUSED(intrFlags);
SPIN_LOCK_ISR_GIVE((spinlockIsr_t *) h_Spinlock);
}