diff options
Diffstat (limited to 'Acceleration/library/icp_utils/OSAL/common/os')
28 files changed, 5777 insertions, 0 deletions
diff --git a/Acceleration/library/icp_utils/OSAL/common/os/linux/include/core/IxOsalOs.h b/Acceleration/library/icp_utils/OSAL/common/os/linux/include/core/IxOsalOs.h new file mode 100644 index 0000000..9651c55 --- /dev/null +++ b/Acceleration/library/icp_utils/OSAL/common/os/linux/include/core/IxOsalOs.h @@ -0,0 +1,191 @@ +/** + * @file IxOsalOs.h + * + * @brief linux-specific defines + * + * Design Notes: + * + * @par + * This file is provided under a dual BSD/GPLv2 license. When using or + * redistributing this file, you may do so under either license. + * + * GPL LICENSE SUMMARY + * + * Copyright(c) 2007,2008,2009 Intel Corporation. All rights reserved. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of version 2 of the GNU General Public License as + * published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA. + * The full GNU General Public License is included in this distribution + * in the file called LICENSE.GPL. + * + * Contact Information: + * Intel Corporation + * + * BSD LICENSE + * + * Copyright(c) 2007,2008,2009 Intel Corporation. All rights reserved. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Intel Corporation nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * + * + */ + +#ifndef IxOsalOs_H +#define IxOsalOs_H + +#ifndef IX_OSAL_CACHED + +#error "Uncached memory not supported in linux environment" + +#endif + +#if KERNEL_VERSION(2,6,0) <= LINUX_VERSION_CODE + +#include <linux/dma-mapping.h> + +#include <asm/io.h> + +#include <linux/pci.h> + +#include <asm/div64.h> + +#else /* ! KERNEL_VERSION 2.6 */ + +#include <linux/cache.h> + +#endif + +#include <linux/mm.h> +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,18) +#include <linux/autoconf.h> +#elif KERNEL_VERSION(2,6,16) >= LINUX_VERSION_CODE +#include <linux/config.h> +#endif + +#include <asm/pgalloc.h> + +/** + * Linux implementations of macros. + */ + +/** + * Protect this with a flag that is valid only for 2.6.X and above + */ +#if KERNEL_VERSION(2,6,0) <= LINUX_VERSION_CODE + +#define IX_OSAL_OS_UDIV64_32(dividend, divisor) \ +({ \ + UINT64 _div = dividend; \ + \ + do_div(_div, divisor); \ + \ + _div; \ +}) + +#define IX_OSAL_OS_UMOD64_32(dividend, divisor) \ +({ \ + UINT64 _div = dividend; \ + \ + do_div(_div, divisor); \ +}) + +#else /* If less than 2.6, then empty macro */ + +#define IX_OSAL_OS_UDIV64_32(dividend, divisor) \ + ixOsalLog(IX_OSAL_LOG_LVL_ERROR, IX_OSAL_LOG_DEV_STDOUT, \ + "UDIV64: Macro not implemented\n", \ + 0,0,0,0,0,0); + +#define IX_OSAL_OS_UMOD64_32(dividend, divisor) \ + ixOsalLog(IX_OSAL_LOG_LVL_ERROR, IX_OSAL_LOG_DEV_STDOUT, \ + "UMOD64: Macro not implemented\n", \ + 0,0,0,0,0,0); + +#endif /* KERNEL_VERSION */ + + +#define IX_OSAL_OS_MMU_VIRT_TO_PHYS(addr) ((addr) ? virt_to_phys((void*)(addr)) : 0) + +#define IX_OSAL_OS_MMU_PHYS_TO_VIRT(addr) ((addr) ? phys_to_virt((unsigned int)(addr)) : 0) + +#ifndef IX_HW_COHERENT_MEMORY + +#if KERNEL_VERSION(2,6,0) <= LINUX_VERSION_CODE + +#define IX_OSAL_OS_CACHE_INVALIDATE(addr, size) \ + (consistent_sync((void*)addr, (size_t) size, DMA_FROM_DEVICE)) + +#define IX_OSAL_OS_CACHE_FLUSH(addr, size) \ + (consistent_sync((void*)addr, (size_t) size, DMA_TO_DEVICE)) + +#else /* !KERNEL_VERSION 2.6 */ + +#define IX_OSAL_OS_CACHE_INVALIDATE(addr, size) \ + (invalidate_dcache_range((__u32)addr, (__u32)addr + size )) + +#define IX_OSAL_OS_CACHE_FLUSH(addr, size) \ + (clean_dcache_range((__u32)addr, (__u32)addr + size)) + +#endif /* KERNEL_VERSION */ + +#else /* IX_HW_COHERENT_MEMORY */ + +/* + * The non-coherent memory region is exposed as uncacheable memory. + * So there is no need for cache invalidation or cache flushing + */ +#define IX_OSAL_OS_CACHE_INVALIDATE(addr, size) do { } while(0); + +#define IX_OSAL_OS_CACHE_FLUSH(addr, size) do { } while(0); + +#endif /* IX_HW_COHERENT_MEMORY */ + +#define OSAL_OS_GET_STRING_LENGTH(str) strlen(str) + +#define IX_OSAL_OS_CACHE_PRELOAD(addr,size) do { } while(0); + +#define IX_OSAL_OS_ATOMIC_INIT(val) ATOMIC_INIT(val) + +/* + * s - memory size + * a - memory alignment + */ +#define IX_OSAL_MEM_PADDING(s, a) ( ( a - (s % a)) % a ) + +#endif /* IxOsalOs_H */ diff --git a/Acceleration/library/icp_utils/OSAL/common/os/linux/include/core/IxOsalOsAssert.h b/Acceleration/library/icp_utils/OSAL/common/os/linux/include/core/IxOsalOsAssert.h new file mode 100644 index 0000000..f6559ea --- /dev/null +++ b/Acceleration/library/icp_utils/OSAL/common/os/linux/include/core/IxOsalOsAssert.h @@ -0,0 +1,88 @@ +/** + * @file IxOsalOsAssert.h + * + * @brief Assert + * + * + * @par + * This file is provided under a dual BSD/GPLv2 license. When using or + * redistributing this file, you may do so under either license. + * + * GPL LICENSE SUMMARY + * + * Copyright(c) 2007,2008,2009 Intel Corporation. All rights reserved. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of version 2 of the GNU General Public License as + * published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA. + * The full GNU General Public License is included in this distribution + * in the file called LICENSE.GPL. + * + * Contact Information: + * Intel Corporation + * + * BSD LICENSE + * + * Copyright(c) 2007,2008,2009 Intel Corporation. All rights reserved. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Intel Corporation nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * + * + */ + +#ifndef IxOsalOsAssert_H +#define IxOsalOsAssert_H +#define IX_OSAL_OS_ASSERT(c) if(!(c)) \ + { \ + ixOsalLog (IX_OSAL_LOG_LVL_ERROR, IX_OSAL_LOG_DEV_STDOUT, "Assertion failure in file %s at line %d \n",(int)__FILE__,(int) __LINE__, 0, 0, 0, 0);\ + BUG(); \ + } + + +#define IX_OSAL_OS_MEM_ASSERT(c) if(!(c)) \ + { \ + ixOsalLog (IX_OSAL_LOG_LVL_ERROR, IX_OSAL_LOG_DEV_STDOUT, "Assertion failure in file %s at line %d \n",(int)__FILE__,(int) __LINE__, 0, 0, 0, 0);\ + BUG(); \ + } + + + +/* + * Place holder. + */ +#endif /* IxOsalOsAssert_H */ diff --git a/Acceleration/library/icp_utils/OSAL/common/os/linux/include/core/IxOsalOsTypes.h b/Acceleration/library/icp_utils/OSAL/common/os/linux/include/core/IxOsalOsTypes.h new file mode 100644 index 0000000..ac00824 --- /dev/null +++ b/Acceleration/library/icp_utils/OSAL/common/os/linux/include/core/IxOsalOsTypes.h @@ -0,0 +1,311 @@ +/** + * @file IxOsalOsTypes.h + * + * @brief Linux-specific data type + * + * + * @par + * This file is provided under a dual BSD/GPLv2 license. When using or + * redistributing this file, you may do so under either license. + * + * GPL LICENSE SUMMARY + * + * Copyright(c) 2007,2008,2009 Intel Corporation. All rights reserved. + * Copyright(c) 2010,2011,2012 Avencall + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of version 2 of the GNU General Public License as + * published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA. + * The full GNU General Public License is included in this distribution + * in the file called LICENSE.GPL. + * + * BSD LICENSE + * + * Copyright(c) 2007,2008,2009 Intel Corporation. All rights reserved. + * All rights reserved. + * Copyright(c) 2010,2011,2012 Avencall + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Intel Corporation nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * + * + */ + +#ifndef IxOsalOsTypes_H +#define IxOsalOsTypes_H + +#include <linux/types.h> +#include <linux/version.h> + +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,18) +#include <linux/autoconf.h> +#elif KERNEL_VERSION(2,6,16) >= LINUX_VERSION_CODE +#include <linux/config.h> +#endif + +#if KERNEL_VERSION(2,6,0) <= LINUX_VERSION_CODE + +#include <linux/sched.h> +#include <linux/kthread.h> + +#endif /* KERNEL_VERSION_2.6 */ + +#ifdef ENABLE_SPINLOCK + +#include <linux/spinlock.h> + +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,18) +#include <linux/interrupt.h> +#endif /*< KERNEL_VERSION(2,6,18*/ + +#endif /* ENABLE_SPINLOCK */ + +#include <asm/atomic.h> +#include <linux/semaphore.h> + +#ifdef USE_NATIVE_OS_TIMER_API +#include <linux/timer.h> +#endif + +#include <linux/wait.h> + +#include "IxOsalUtilitySymbols.h" + +#ifndef __ACTYPES_H__ +typedef u8 UINT8; /**< 8-bit unsigned integer */ +typedef u16 UINT16; /**< 16-bit unsigned integer */ +typedef u32 UINT32; /**< 32-bit unsigned integer */ +typedef u64 UINT64; /**< 64-bit unsigned integer */ +typedef s64 INT64; /**< 64-bit signed integer */ +typedef s16 INT16; /**< 16-bit signed integer */ +typedef s32 INT32; /**< 32-bit signed integer */ +#endif /* __ACTYPES_H__ */ + +typedef s8 INT8; /**< 8-bit signed integer */ +typedef UINT32 ULONG; /**< alias for UINT32 */ +typedef UINT16 USHORT; /**< alias for UINT16 */ +typedef UINT8 UCHAR; /**< alias for UINT8 */ +typedef UINT32 BOOL; /**< alias for UINT32 */ +typedef INT8 CHAR; /**< alias for INT8*/ +typedef void VOID; + + +/* + * Detecting the kernel version that we compiled against. + * We did not lock down specifically to any revision here. + * We do it for some specific revisions now. + */ +#if (KERNEL_VERSION(2,6,0) <= LINUX_VERSION_CODE) && \ + (KERNEL_VERSION(2,7,0) > LINUX_VERSION_CODE) + +#define IX_OSAL_OS_LINUX_VERSION_2_6 1 /* Kernel 2.6 */ +#undef IX_OSAL_OS_LINUX_VERSION_2_4 + +#if (KERNEL_VERSION(2,6,16) == LINUX_VERSION_CODE) +#define IX_OSAL_OS_LINUX_VERSION_2_6_16 1 +#endif + +#if (KERNEL_VERSION(2,6,18) == LINUX_VERSION_CODE) +#define IX_OSAL_OS_LINUX_VERSION_2_6_18 1 +#endif + +#if (KERNEL_VERSION(2,6,20) == LINUX_VERSION_CODE) +#define IX_OSAL_OS_LINUX_VERSION_2_6_20 1 +#endif + +/* Defines for version greater than a specific minor ver number */ +#if (KERNEL_VERSION(2,6,18) <= LINUX_VERSION_CODE) +#define IX_OSAL_OS_LINUX_VER_GT_2_6_18 1 +#endif + +#if (KERNEL_VERSION(2,6,20) <= LINUX_VERSION_CODE) +#define IX_OSAL_OS_LINUX_VER_GT_2_6_20 1 +#endif + +#elif (KERNEL_VERSION(2,4,0) <= LINUX_VERSION_CODE) && \ + (KERNEL_VERSION(2,5,0) > LINUX_VERSION_CODE) + +#define IX_OSAL_OS_LINUX_VERSION_2_4 1 /* Kernel 2.4 */ +#undef IX_OSAL_OS_LINUX_VERSION_2_6 + +#else /* KERNEL_VERSION */ +#error "Non supported Linux kernel version" +#endif /* KERNEL_VERSION */ + + +/* Default stack limit is 10 KB */ +#define IX_OSAL_OS_THREAD_DEFAULT_STACK_SIZE (10240) + +/* Maximum stack limit is 32 MB */ +#define IX_OSAL_OS_THREAD_MAX_STACK_SIZE (33554432) /* 32 MBytes */ + +/* Thread minimum priority */ +#define IX_OSAL_OS_MIN_THREAD_PRIORITY (0) + +/* Default thread priority */ +#define IX_OSAL_OS_DEFAULT_THREAD_PRIORITY (MAX_RT_PRIO-1) + +/* Thread maximum priority (0 - 255). 0 - highest priority */ +#define IX_OSAL_OS_MAX_THREAD_PRIORITY (MAX_PRIO) + +/* Maximum input value for priority */ +#define IX_OSAL_PRIO_SET_MAX_VALID_VAL (255) + +/* Maximum supported priority value in ThreadPrioritySet */ +#define IX_OSAL_PRIO_SET_MAX_VAL (39) + +/* Difference of actual nice value and input value */ +#define IX_OSAL_NICE_VAL_DIFFERENCE (20) + +/* Default scheduling policy */ +#define IX_OSAL_OS_THREAD_DEFAULT_SCHED_POLICY SCHED_RR + +/* Thread scheduling policy - Round Robin */ +#define IX_OSAL_THREAD_SCHED_RR SCHED_RR + +/* Thread scheduling policy - FiFo */ +#define IX_OSAL_THREAD_SCHED_FIFO SCHED_FIFO + + /* Thread scheduling policy - Other */ +#define IX_OSAL_THREAD_SCHED_OTHER SCHED_OTHER + +#define IX_OSAL_OS_WAIT_FOREVER (-1) +#define IX_OSAL_OS_WAIT_NONE 0 +#undef IX_OSAL_ATTRIBUTE_PACKED +#define IX_OSAL_ATTRIBUTE_PACKED __attribute__((__packed__)) + + +#ifdef IX_OSAL_OS_LINUX_VERSION_2_6 + +/* Thread handle is a task_struct pointer */ +typedef struct task_struct *IxOsalOsThread; + +#else /* !KERNEL_VERSION 2.6 */ + +/* Thread handle is an int type */ +typedef int IxOsalOsThread; + +#endif /* IX_OSAL_OS_LINUX_VERSION_2_6 */ + + +/* Semaphore handle */ +typedef struct semaphore *IxOsalOsSemaphore; + +/* Mutex handle */ +typedef struct semaphore *IxOsalOsMutex; + +#ifdef IX_OSAL_OEM_FAST_MUTEX + +typedef int IxOsalOsFastMutex; + +#else /* ! IX_OSAL_OEM_FAST_MUTEX -> Generic */ + +/* + * Fast mutex handle - fast mutex operations are implemented + * using the linux atomic instructions. + */ +typedef atomic_t IxOsalOsFastMutex; + +#endif /* IX_OSAL_OEM_FAST_MUTEX */ + +#ifdef ENABLE_SPINLOCK +typedef spinlock_t IxOsalOsSpinLock; +#endif /* ENABLE_SPINLOCK */ + + +typedef struct +{ + UINT32 msgLen; /* Message Length */ + UINT32 maxNumMsg; /* max number of msg in the queue */ + UINT32 currNumMsg; /* current number of msg in the queue */ + INT8 msgKey; /* key used to generate the queue */ + INT8 queueId; /* queue ID */ + +} IxOsalOsMessageQueue; + +typedef atomic_t IxOsalOsAtomic; + +/* Dummy typedef for OsThreadAttr - This is not used in linux currently. + This needs to be defined appropriately when it is planned to be used */ +typedef int IxOsalOsThreadAttr; + +typedef void (*voidFnVoidPtr) (void *); +typedef void (*voidFnVoid) (void); + +#ifdef USE_NATIVE_OS_TIMER_API +typedef void (*voidFnULongPtr)(unsigned long); + +typedef struct +{ + BOOL inUse; /* status of timer active or cancel */ + BOOL isRepeating; /* Timer is repeating type */ + voidFnVoidPtr callback; /* Function to be called back after period ms */ + UINT32 priority; /* priority */ + void *callbackParam; /* parameter to be passed to callback function*/ + UINT32 period; /* period in mili seconds */ + struct timer_list timer; /* Linux OS timer struct */ +} IxOsalTimerRec; + +typedef IxOsalTimerRec *IxOsalOsTimer; +#endif /* USE_NATIVE_OS_TIMER_API */ + +/* + * On Linux kmalloc can allocat a max of 128 KB + */ +#define IX_OSAL_MAX_KMALLOC_MEM (1024 * 128) + +/* + * linux data struct to store the information on the + * memory allocated. This structure is stored at the beginning of + * the allocated chunck of memory + * size is the no of byte passed to the memory allocation functions + * mSize is the real size of the memory required to the OS + * + * +--------------------------+--------------------------------+ + * | ixOsalMemAllocInfoStruct | memory returned to user (size) | + * +--------------------------+--------------------------------+ + * ^ ^ + * mAllocMemPtr Ptr returned to the caller of MemAlloc* + * + */ +typedef struct _sMemAllocInfo +{ + VOID* mAllocMemPtr; /* memory addr returned by the kernel */ + UINT32 mSize; /* allocated size */ + +} ixOsalMemAllocInfoStruct; + +#endif /* IxOsalOsTypes_H */ diff --git a/Acceleration/library/icp_utils/OSAL/common/os/linux/include/core/IxOsalOsUtilitySymbols.h b/Acceleration/library/icp_utils/OSAL/common/os/linux/include/core/IxOsalOsUtilitySymbols.h new file mode 100644 index 0000000..97aa2b3 --- /dev/null +++ b/Acceleration/library/icp_utils/OSAL/common/os/linux/include/core/IxOsalOsUtilitySymbols.h @@ -0,0 +1,71 @@ +/** + * @file IxOsalOsUtilitySymbols.h + * + * @brief + * + * + * @par + * This file is provided under a dual BSD/GPLv2 license. When using or + * redistributing this file, you may do so under either license. + * + * GPL LICENSE SUMMARY + * + * Copyright(c) 2007,2008,2009 Intel Corporation. All rights reserved. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of version 2 of the GNU General Public License as + * published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA. + * The full GNU General Public License is included in this distribution + * in the file called LICENSE.GPL. + * + * Contact Information: + * Intel Corporation + * + * BSD LICENSE + * + * Copyright(c) 2007,2008,2009 Intel Corporation. All rights reserved. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Intel Corporation nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * + * + */ + +#ifndef IxOsalOsUtilitySymbols_H +#define IxOsalOsUtilitySymbols_H + +#endif /* IxOsalOsUtilitySymbols_H */ diff --git a/Acceleration/library/icp_utils/OSAL/common/os/linux/include/modules/bufferMgt/IxOsalOsBufferMgt.h b/Acceleration/library/icp_utils/OSAL/common/os/linux/include/modules/bufferMgt/IxOsalOsBufferMgt.h new file mode 100644 index 0000000..390e4ed --- /dev/null +++ b/Acceleration/library/icp_utils/OSAL/common/os/linux/include/modules/bufferMgt/IxOsalOsBufferMgt.h @@ -0,0 +1,122 @@ +/** + * @file IxOsalOsBufferMgt.h + * + * @brief os-specific buffer management module definitions. + * + * Design Notes: + * + * @par + * This file is provided under a dual BSD/GPLv2 license. When using or + * redistributing this file, you may do so under either license. + * + * GPL LICENSE SUMMARY + * + * Copyright(c) 2007,2008,2009 Intel Corporation. All rights reserved. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of version 2 of the GNU General Public License as + * published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA. + * The full GNU General Public License is included in this distribution + * in the file called LICENSE.GPL. + * + * Contact Information: + * Intel Corporation + * + * BSD LICENSE + * + * Copyright(c) 2007,2008,2009 Intel Corporation. All rights reserved. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Intel Corporation nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * + * + */ + + +#ifndef IX_OSAL_OS_BUFFER_MGT_H +#define IX_OSAL_OS_BUFFER_MGT_H + +#include <linux/skbuff.h> +/* + * Use the defaul bufferMgt provided by OSAL + * framework. + */ +#define IX_OSAL_USE_DEFAULT_BUFFER_MGT + +#include "IxOsalBufferMgtDefault.h" + +/* Linux choose to allocate buffers + * separately by the defining IX_OSAL_BUFFER_ALLOC_SEPARATELY. + * As it has a relatively small page limit when allocating a + * continuous block. + */ +#define IX_OSAL_BUFFER_ALLOC_SEPARATELY + +/* Define os-specific buffer macros to access subfields */ +#define IX_OSAL_OSBUF_MDATA(osBufPtr) \ + ( ((struct sk_buff *) osBufPtr)->data ) + +#define IX_OSAL_OSBUF_MLEN(osBufPtr) \ + ( ((struct sk_buff *) osBufPtr)->len ) + +/* Conversion utilities for linux-specific buffers */ +#define IX_OSAL_OS_CONVERT_OSBUF_TO_ACPBUF( osBufPtr, acpBufPtr) \ + { \ + IX_OSAL_MBUF_OSBUF_PTR( (IX_OSAL_MBUF *) acpBufPtr) = (void *) osBufPtr; \ + IX_OSAL_MBUF_MDATA((IX_OSAL_MBUF *) acpBufPtr) = IX_OSAL_OSBUF_MDATA(osBufPtr); \ + IX_OSAL_MBUF_PKT_LEN((IX_OSAL_MBUF *) acpBufPtr) = IX_OSAL_OSBUF_MLEN(osBufPtr); \ + IX_OSAL_MBUF_MLEN((IX_OSAL_MBUF *) acpBufPtr) = IX_OSAL_OSBUF_MLEN(osBufPtr); \ + } + +#define IX_OSAL_OS_CONVERT_ACPBUF_TO_OSBUF( acpBufPtr, osBufPtr) \ + { \ + if (acpBufPtr == NULL) \ + { /* Do nothing */ } \ + else \ + { \ + (struct sk_buff *) osBufPtr = (struct sk_buff *) IX_OSAL_MBUF_OSBUF_PTR((IX_OSAL_MBUF *) acpBufPtr); \ + if (osBufPtr == NULL) \ + { /* Do nothing */ } \ + else \ + { \ + IX_OSAL_OSBUF_MLEN(osBufPtr) =IX_OSAL_MBUF_PKT_LEN((IX_OSAL_MBUF *) acpBufPtr); \ + } \ + } \ + } + + +#endif /* #define IX_OSAL_OS_BUFFER_MGT_H */ diff --git a/Acceleration/library/icp_utils/OSAL/common/os/linux/include/modules/ddk/IxOsalOsDdk.h b/Acceleration/library/icp_utils/OSAL/common/os/linux/include/modules/ddk/IxOsalOsDdk.h new file mode 100644 index 0000000..1f6b6e7 --- /dev/null +++ b/Acceleration/library/icp_utils/OSAL/common/os/linux/include/modules/ddk/IxOsalOsDdk.h @@ -0,0 +1,104 @@ +/** + * @file IxOsalOsDdk.h + * + * @brief Linux-specific OS Ddk definitions + * + * Design Notes: + * + * @par + * This file is provided under a dual BSD/GPLv2 license. When using or + * redistributing this file, you may do so under either license. + * + * GPL LICENSE SUMMARY + * + * Copyright(c) 2007,2008,2009 Intel Corporation. All rights reserved. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of version 2 of the GNU General Public License as + * published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA. + * The full GNU General Public License is included in this distribution + * in the file called LICENSE.GPL. + * + * Contact Information: + * Intel Corporation + * + * BSD LICENSE + * + * Copyright(c) 2007,2008,2009 Intel Corporation. All rights reserved. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Intel Corporation nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * + * + */ + +#ifndef IxOsalOsDdk_H +#define IxOsalOsDdk_H + +/* + * Below macros and defines are used for OSAL CacheMMU APIs . + */ + +/* + * Definition of what is deemed a small memory allocation request. + * Memory requests for up to this size are deemed small and are + * handled differently from larger memory requests + */ +#define IX_OSAL_OS_SMALL_MEM_SIZE (512 - 32) + +/* Arbitrary numbers to detect memory corruption */ +#define IX_OSAL_OS_MAGIC_ALLOC_NUMBER (0xBABEFACE) +#define IX_OSAL_OS_MAGIC_DEALLOC_NUMBER (0xCAFEBABE) + +/* Number of information words maintained behind the user buffer */ +#define IX_OSAL_OS_NUM_INFO_WORDS (4) + +/* Number of bytes per word */ +#define IX_OSAL_OS_BYTES_PER_WORD (4) + +/* Index of information words maintained behind user buffer */ +#define IX_OSAL_OS_ORDER_OF_PAGES_INDEX (-4) +#define IX_OSAL_OS_MYPTR_INDEX (-3) +#define IX_OSAL_OS_REQUESTED_SIZE_INDEX (-2) +#define IX_OSAL_OS_MAGIC_NUMBER_INDEX (-1) + +/* Macro to round up a size to a multiple of a cache line */ +#define IX_OSAL_OS_CL_ROUND_UP(s) \ + (((s) + (IX_OSAL_CACHE_LINE_SIZE - 1)) & ~(IX_OSAL_CACHE_LINE_SIZE - 1)) + + +#endif /* IxOsalOsDdk_H */ diff --git a/Acceleration/library/icp_utils/OSAL/common/os/linux/include/modules/ioMem/IxOsalOsIoMem.h b/Acceleration/library/icp_utils/OSAL/common/os/linux/include/modules/ioMem/IxOsalOsIoMem.h new file mode 100644 index 0000000..761e9b5 --- /dev/null +++ b/Acceleration/library/icp_utils/OSAL/common/os/linux/include/modules/ioMem/IxOsalOsIoMem.h @@ -0,0 +1,76 @@ +/** + * @file IxOsalOsIoMem.h + * + * @brief Linux-specific OS IO/Mem definitions + * + * Design Notes: + * + * @par + * This file is provided under a dual BSD/GPLv2 license. When using or + * redistributing this file, you may do so under either license. + * + * GPL LICENSE SUMMARY + * + * Copyright(c) 2007,2008,2009 Intel Corporation. All rights reserved. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of version 2 of the GNU General Public License as + * published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA. + * The full GNU General Public License is included in this distribution + * in the file called LICENSE.GPL. + * + * Contact Information: + * Intel Corporation + * + * BSD LICENSE + * + * Copyright(c) 2007,2008,2009 Intel Corporation. All rights reserved. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Intel Corporation nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * + * + */ + +#ifndef IxOsalOsIoMem_H +#define IxOsalOsIoMem_H + +/* + * Place holder. + */ + +#endif /* IxOsalOsIoMem_H */ diff --git a/Acceleration/library/icp_utils/OSAL/common/os/linux/make/macros.mk b/Acceleration/library/icp_utils/OSAL/common/os/linux/make/macros.mk new file mode 100644 index 0000000..5a20a2e --- /dev/null +++ b/Acceleration/library/icp_utils/OSAL/common/os/linux/make/macros.mk @@ -0,0 +1,106 @@ +# +# Macro definitions for os-specific makefile +# +# +# @par +# This file is provided under a dual BSD/GPLv2 license. When using or +# redistributing this file, you may do so under either license. +# +# GPL LICENSE SUMMARY +# +# Copyright(c) 2007,2008,2009 Intel Corporation. All rights reserved. +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of version 2 of the GNU General Public License as +# published by the Free Software Foundation. +# +# This program is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA. +# The full GNU General Public License is included in this distribution +# in the file called LICENSE.GPL. +# +# Contact Information: +# Intel Corporation +# +# BSD LICENSE +# +# Copyright(c) 2007,2008,2009 Intel Corporation. All rights reserved. +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions +# are met: +# +# * Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# * Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in +# the documentation and/or other materials provided with the +# distribution. +# * Neither the name of Intel Corporation nor the names of its +# contributors may be used to endorse or promote products derived +# from this software without specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +# +# +# +# +# NOTE! +# This file currently depends on the following environment variables: +# - HARDHAT_BASE +# - IX_TARGET +# - linuxbe_KERNEL_DIR or linuxle_KERNEL_DIR + + +##################################################################### +# Determine the build host OS +# +# Only Linux (and partially Cygwin) are currently supported for Linux builds + +IX_OSAL_MK_HOST_OS := $(OSTYPE) + +# If we don't have a valid OS name, try to use the Unix uname command +# to find it. +ifneq ($(IX_OSAL_MK_HOST_OS), linux) + IX_OSAL_MK_HOST_OS := $(shell uname) + IX_OSAL_MK_HOST_OS := $(subst Linux,linux,$(IX_OSAL_MK_HOST_OS)) +# We do not check for 'cygwin' here, as a windows box will often have +# a cygwin "uname" on its PATH even when not running in a true cygwin +# environment. We must rely on the OSTYPE environment variable to tell +# us if we're in a true cygwin environment. +endif + + +################################################################ +# Linux Compiler & linker commands + +LD := $(COMPILE_PREFIX)ld +CC := $(COMPILE_PREFIX)gcc +AR := $(COMPILE_PREFIX)ar + +################################################################ +# Compiler & linker options + +# Compiler flags + +# Linux linker flags +LDFLAGS := -r +MAKE_DEP_FLAG := -M + diff --git a/Acceleration/library/icp_utils/OSAL/common/os/linux/src/component.mk b/Acceleration/library/icp_utils/OSAL/common/os/linux/src/component.mk new file mode 100644 index 0000000..bd85f4b --- /dev/null +++ b/Acceleration/library/icp_utils/OSAL/common/os/linux/src/component.mk @@ -0,0 +1,61 @@ +# @par +# This file is provided under a dual BSD/GPLv2 license. When using or +# redistributing this file, you may do so under either license. +# +# GPL LICENSE SUMMARY +# +# Copyright(c) 2007,2008,2009 Intel Corporation. All rights reserved. +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of version 2 of the GNU General Public License as +# published by the Free Software Foundation. +# +# This program is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA. +# The full GNU General Public License is included in this distribution +# in the file called LICENSE.GPL. +# +# Contact Information: +# Intel Corporation +# +# BSD LICENSE +# +# Copyright(c) 2007,2008,2009 Intel Corporation. All rights reserved. +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions +# are met: +# +# * Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# * Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in +# the documentation and/or other materials provided with the +# distribution. +# * Neither the name of Intel Corporation nor the names of its +# contributors may be used to endorse or promote products derived +# from this software without specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +# +# +# +# Place Holder + diff --git a/Acceleration/library/icp_utils/OSAL/common/os/linux/src/core/IxOsalOsAtomic.c b/Acceleration/library/icp_utils/OSAL/common/os/linux/src/core/IxOsalOsAtomic.c new file mode 100644 index 0000000..674d375 --- /dev/null +++ b/Acceleration/library/icp_utils/OSAL/common/os/linux/src/core/IxOsalOsAtomic.c @@ -0,0 +1,271 @@ +/** + * @file IxOsalOsAtomic.c (linux) + * + * @brief OS-specific Atomic API's implementation. + * + * + * @par + * This file is provided under a dual BSD/GPLv2 license. When using or + * redistributing this file, you may do so under either license. + * + * GPL LICENSE SUMMARY + * + * Copyright(c) 2007,2008,2009 Intel Corporation. All rights reserved. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of version 2 of the GNU General Public License as + * published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA. + * The full GNU General Public License is included in this distribution + * in the file called LICENSE.GPL. + * + * Contact Information: + * Intel Corporation + * + * BSD LICENSE + * + * Copyright(c) 2007,2008,2009 Intel Corporation. All rights reserved. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Intel Corporation nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * + * + */ +#include "IxOsal.h" +#include <asm/atomic.h> + + + +/** + * @ingroup IxOsal + * + * @brief Atomically read the value of atomic variable + * + * @param atomicVar (in) - atomic variable + * + * Atomically reads the value of atomicVar to the outValue + * + * @li Reentrant: yes + * @li IRQ safe: yes + * + * @return atomicVar value + */ + +PUBLIC UINT32 +ixOsalAtomicGet(IxOsalAtomic *atomicVar) +{ + return (( UINT32 )atomic_read( atomicVar )); +} + +/** + * @ingroup IxOsal + * + * @brief Atomically set the value of atomic variable + * + * @param inValue (in) - atomic variable to be set equal to inValue + * + * @param atomicVar (out) - atomic variable + * + * Atomically sets the value of IxOsalAtomicVar to the value given + * + * @li Reentrant: yes + * @li IRQ safe: yes + * + * @return none + */ + +PUBLIC void +ixOsalAtomicSet(UINT32 inValue, IxOsalAtomic *atomicVar) +{ + atomic_set(atomicVar,inValue); +} + +/** + * @ingroup IxOsal + * + * @brief add the value to atomic variable + * + * @param inValue (in) - value to be added to the atomic variable + * + * @param atomicVar (in & out) - atomic variable + * + * Atomically adds the value of inValue to the IxOsalAtomicVar + * + * @li Reentrant: yes + * @li IRQ safe: yes + * + * @return none + */ + +PUBLIC void +ixOsalAtomicAdd(UINT32 inValue, IxOsalAtomic *atomicVar) +{ + atomic_add((int)inValue, atomicVar); +} + +/** + * @ingroup IxOsal + * + * @brief subtract the value from atomic variable + * + * @param inValue (in) - atomic variable value to be subtracted by value + * + * @param atomicVar (in & out) - atomic variable + * + * Atomically subtracts the value of IxOsalAtomicVar by inValue + * + * @li Reentrant: yes + * @li IRQ safe: yes + * + * @return none + */ + +PUBLIC void +ixOsalAtomicSub(UINT32 inValue, IxOsalAtomic *atomicVar) +{ + atomic_sub((int)inValue, atomicVar); +} + +/** + * @ingroup IxOsal + * + * @brief subtract the value from atomic variable and test result + * + * @param inValue (in) - value to be subtracted from the atomic variable + * + * @param atomicVar (in & out) - atomic variable + * + * Atomically subtracts the IxOsalAtomicVar value by inValue and + * test the result. + * + * @li Reentrant: yes + * @li IRQ safe: yes + * + * @return TRUE if the result is zero or FALSE for other cases. + */ + +PUBLIC IX_STATUS +ixOsalAtomicSubAndTest(UINT32 inValue, IxOsalAtomic *atomicVar) +{ + return (IX_STATUS)(atomic_sub_and_test((int)inValue, atomicVar)); +} + +/** + * @ingroup IxOsal + * + * @brief increment value of atomic variable by 1 + * + * @param atomicVar (in & out) - atomic variable + * + * Atomically increments the value of IxOsalAtomicVar by 1. + * + * @li Reentrant: yes + * @li IRQ safe: yes + * + * @return none + */ + +PUBLIC void +ixOsalAtomicInc(IxOsalAtomic *atomicVar) +{ + atomic_inc(atomicVar); +} + +/** + * @ingroup IxOsal + * + * @brief decrement value of atomic variable by 1 + * + * @param atomicVar (out) - atomic variable + * + * Atomically decrements the value of IxOsalAtomicVar by 1. + * + * @li Reentrant: yes + * @li IRQ safe: yes + * + * @return none + */ + +PUBLIC void +ixOsalAtomicDec(IxOsalAtomic *atomicVar) +{ + atomic_dec(atomicVar); +} + +/** + * @ingroup IxOsal + * + * @brief decrement atomic variable value by 1 and test result + * + * @param atomicVar (in & out) - atomic variable + * + * Atomically decrements the value of IxOsalAtomicVar by 1 and test + * result for zero. + * + * @li Reentrant: yes + * @li IRQ safe: yes + * + * @return TRUE if the result is zero or FALSE otherwise + */ + +PUBLIC IX_STATUS +ixOsalAtomicDecAndTest(IxOsalAtomic *atomicVar) +{ + return (IX_STATUS)(atomic_dec_and_test(atomicVar)); +} + +/** + * @ingroup IxOsal + * + * @brief increment atomic variable by 1 and test result + * + * @param atomicVar (in & out) - atomic variable + * + * Atomically increments the value of IxOsalAtomicVar by 1 and test + * result for zero. + * + * @li Reentrant: yes + * @li IRQ safe: yes + * + * @return TRUE if the result is zero or FALSE otherwise + */ + +PUBLIC IX_STATUS +ixOsalAtomicIncAndTest(IxOsalAtomic *atomicVar) +{ + return (IX_STATUS)(atomic_inc_and_test(atomicVar)); +} + diff --git a/Acceleration/library/icp_utils/OSAL/common/os/linux/src/core/IxOsalOsMemBarrier.c b/Acceleration/library/icp_utils/OSAL/common/os/linux/src/core/IxOsalOsMemBarrier.c new file mode 100644 index 0000000..217134f --- /dev/null +++ b/Acceleration/library/icp_utils/OSAL/common/os/linux/src/core/IxOsalOsMemBarrier.c @@ -0,0 +1,135 @@ +/** + * @file IxOsalOsMemBarrier.c (linux) + * + * @brief OS-specific Memory Barrier API's implementation. + * + * + * @par + * This file is provided under a dual BSD/GPLv2 license. When using or + * redistributing this file, you may do so under either license. + * + * GPL LICENSE SUMMARY + * + * Copyright(c) 2007,2008,2009 Intel Corporation. All rights reserved. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of version 2 of the GNU General Public License as + * published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA. + * The full GNU General Public License is included in this distribution + * in the file called LICENSE.GPL. + * + * Contact Information: + * Intel Corporation + * + * BSD LICENSE + * + * Copyright(c) 2007,2008,2009 Intel Corporation. All rights reserved. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Intel Corporation nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * + * + */ +#include "IxOsal.h" + +#include <asm/system.h> + + + +/** + * @ingroup IxOsal + * + * @brief memory barrier which orders both memory read and writes + * + * @param none + * + * memory barrier that orders both memory read and writes + * + * @li Reentrant: yes + * @li IRQ safe: yes + * + * @return none + */ + +PUBLIC void +ixOsalMemBarrier(void) +{ + mb(); +} + +/** + * @ingroup IxOsal + * + * @brief memory barrier which orders memory reads + * + * @param none + * + * memory barrier that orders memory reads + * + * @li Reentrant: yes + * @li IRQ safe: yes + * + * @return none + */ + +PUBLIC void +ixOsalReadMemBarrier(void) +{ + rmb(); +} + +/** + * @ingroup IxOsal + * + * @brief memory barrier which orders memory writes + * + * @param none + * + * memory barrier that orders memory writes + * + * @li Reentrant: yes + * @li IRQ safe: yes + * + * @return none + */ + +PUBLIC void +ixOsalWriteMemBarrier(void) +{ + wmb(); +} + diff --git a/Acceleration/library/icp_utils/OSAL/common/os/linux/src/core/IxOsalOsMsgQ.c b/Acceleration/library/icp_utils/OSAL/common/os/linux/src/core/IxOsalOsMsgQ.c new file mode 100644 index 0000000..22a69bb --- /dev/null +++ b/Acceleration/library/icp_utils/OSAL/common/os/linux/src/core/IxOsalOsMsgQ.c @@ -0,0 +1,143 @@ +/** + * @file IxOsalOsMsgQ.c (linux) + * + * @brief OS-specific Message Queue implementation. + * + * + * @par + * This file is provided under a dual BSD/GPLv2 license. When using or + * redistributing this file, you may do so under either license. + * + * GPL LICENSE SUMMARY + * + * Copyright(c) 2007,2008,2009 Intel Corporation. All rights reserved. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of version 2 of the GNU General Public License as + * published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA. + * The full GNU General Public License is included in this distribution + * in the file called LICENSE.GPL. + * + * Contact Information: + * Intel Corporation + * + * BSD LICENSE + * + * Copyright(c) 2007,2008,2009 Intel Corporation. All rights reserved. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Intel Corporation nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * + * + */ +#include "IxOsal.h" + +#include <linux/linkage.h> +#include <linux/spinlock.h> +#include <linux/ipc.h> +#include <linux/msg.h> +#include <linux/interrupt.h> + + + +/******************************* + * Public functions + *******************************/ +PUBLIC IX_STATUS +ixOsalMessageQueueCreate (IxOsalMessageQueue * queue, + UINT32 msgCount, UINT32 msgLen) +{ + ixOsalLog (IX_OSAL_LOG_LVL_MESSAGE, + IX_OSAL_LOG_DEV_STDOUT, + "ixOsalMessageQueueCreate(): Not implemented in Linux \n", 0, 0, 0, 0, + 0, 0); + return IX_SUCCESS; +} + +PUBLIC IX_STATUS +ixOsalSyncMessageQueueCreate (IxOsalMessageQueue * msgQueue, + UINT32 msgCount, UINT32 msgLen) +{ + ixOsalLog (IX_OSAL_LOG_LVL_MESSAGE, + IX_OSAL_LOG_DEV_STDOUT, + "ixOsalSyncMessageQueueCreate():" + "Not implemented in Linux \n", 0, 0, 0, + 0, 0, 0); + return IX_SUCCESS; +} + +PUBLIC IX_STATUS +ixOsalMessageQueueDelete (IxOsalMessageQueue * queue) +{ + ixOsalLog (IX_OSAL_LOG_LVL_MESSAGE, + IX_OSAL_LOG_DEV_STDOUT, + "ixOsalMessageQueueDelete(): Not implemented in Linux \n", 0, 0, 0, 0, + 0, 0); + return IX_SUCCESS; +} + +PUBLIC IX_STATUS +ixOsalMessageQueueSend (IxOsalMessageQueue * queue, UINT8 * message) +{ + ixOsalLog (IX_OSAL_LOG_LVL_MESSAGE, + IX_OSAL_LOG_DEV_STDOUT, + "ixOsalMessageQueueSend(): Not implemented in Linux \n", 0, 0, 0, 0, + 0, 0); + return IX_SUCCESS; +} + +PUBLIC IX_STATUS +ixOsalMessageQueueReceive (IxOsalMessageQueue * queue, UINT8 * message) +{ + ixOsalLog (IX_OSAL_LOG_LVL_MESSAGE, + IX_OSAL_LOG_DEV_STDOUT, + "ixOsalMessageQueueReceive(): Not implemented in Linux \n", 0, 0, 0, + 0, 0, 0); + return IX_SUCCESS; +} + +PUBLIC IX_STATUS +ixOsalSyncMessageQueueReceive (IxOsalMessageQueue * queue, UINT8 * message, + INT32 timeout) +{ + ixOsalLog (IX_OSAL_LOG_LVL_MESSAGE, + IX_OSAL_LOG_DEV_STDOUT, + "ixOsalSyncMessageQueueReceive():" + "Not implemented in Linux \n", 0, 0, 0, + 0, 0, 0); + return IX_SUCCESS; +} diff --git a/Acceleration/library/icp_utils/OSAL/common/os/linux/src/core/IxOsalOsSemaphore.c b/Acceleration/library/icp_utils/OSAL/common/os/linux/src/core/IxOsalOsSemaphore.c new file mode 100644 index 0000000..5b55a5a --- /dev/null +++ b/Acceleration/library/icp_utils/OSAL/common/os/linux/src/core/IxOsalOsSemaphore.c @@ -0,0 +1,607 @@ +/** + * @file IxOsalOsSemaphore.c (linux) + * + * @brief Implementation for semaphore and mutex. + * + * + * @par + * This file is provided under a dual BSD/GPLv2 license. When using or + * redistributing this file, you may do so under either license. + * + * GPL LICENSE SUMMARY + * + * Copyright(c) 2007,2008,2009 Intel Corporation. All rights reserved. + * Copyright(c) 2010,2011,2012 Avencall + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of version 2 of the GNU General Public License as + * published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA. + * The full GNU General Public License is included in this distribution + * in the file called LICENSE.GPL. + * + * BSD LICENSE + * + * Copyright(c) 2007,2008,2009 Intel Corporation. All rights reserved. + * All rights reserved. + * Copyright(c) 2010,2011,2012 Avencall + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Intel Corporation nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * + * + */ +#include "IxOsal.h" +#include <linux/slab.h> +#include <linux/version.h> +#include <linux/semaphore.h> +#include <asm/atomic.h> + + + +#ifdef IX_OSAL_OS_LINUX_VERSION_2_6 + +#include <linux/hardirq.h> + +#else /* !KERNEL VERSION 2.6 */ + +#include <asm/hardirq.h> + +#endif /* KERNEL_VERSION */ + + +/* Define a large number */ +#define IX_OSAL_MAX_LONG (0x7FFFFFFF) + +/* Max timeout in MS, used to guard against possible overflow */ +#define IX_OSAL_MAX_TIMEOUT_MS (IX_OSAL_MAX_LONG/HZ) + + +PUBLIC IX_STATUS +ixOsalSemaphoreInit (IxOsalSemaphore * sid, UINT32 start_value) +{ + + if (NULL == sid) + { + ixOsalLog (IX_OSAL_LOG_LVL_ERROR, + IX_OSAL_LOG_DEV_STDOUT, + "ixOsalSemaphoreInit: NULL semaphore pointer \n", + 0, 0, 0, 0, 0, 0); + return IX_FAIL; + } + + *sid = kmalloc (sizeof (struct semaphore), GFP_KERNEL); + if (!(*sid)) + { + ixOsalLog (IX_OSAL_LOG_LVL_ERROR, + IX_OSAL_LOG_DEV_STDOUT, + "ixOsalSemaphoreInit: fail to allocate for semaphore \n", + 0, 0, 0, 0, 0, 0); + return IX_FAIL; + } + + sema_init (*sid, start_value); + + return IX_SUCCESS; +} + +/** + * DESCRIPTION: If the semaphore is 'empty', the calling thread is blocked. + * If the semaphore is 'full', it is taken and control is returned + * to the caller. If the time indicated in 'timeout' is reached, + * the thread will unblock and return an error indication. If the + * timeout is set to 'IX_OSAL_WAIT_NONE', the thread will never block; + * if it is set to 'IX_OSAL_WAIT_FOREVER', the thread will block until + * the semaphore is available. + * + * + */ + + +PUBLIC IX_STATUS +ixOsalSemaphoreWait (IxOsalOsSemaphore * sid, INT32 timeout) +{ + + IX_STATUS ixStatus = IX_SUCCESS; + unsigned long timeoutTime; + + if (sid == NULL) + { + ixOsalLog (IX_OSAL_LOG_LVL_ERROR, + IX_OSAL_LOG_DEV_STDOUT, + "ixOsalSemaphoreWait(): NULL semaphore handle \n", + 0, 0, 0, 0, 0, 0); + return IX_FAIL; + } + + /* + * Guard against illegal timeout values + */ + if ((timeout < 0) && (timeout != IX_OSAL_WAIT_FOREVER)) + { + ixOsalLog (IX_OSAL_LOG_LVL_ERROR, + IX_OSAL_LOG_DEV_STDOUT, + "ixOsalSemaphoreWait(): illegal timeout value \n", + 0, 0, 0, 0, 0, 0); + return IX_FAIL; + } + + if (timeout == IX_OSAL_WAIT_FOREVER) + { + down (*sid); + } + else if (timeout == IX_OSAL_WAIT_NONE) + { + if (down_trylock (*sid)) + { + ixStatus = IX_FAIL; + } + } + else if (timeout > IX_OSAL_MAX_TIMEOUT_MS) + { + ixOsalLog (IX_OSAL_LOG_LVL_ERROR, IX_OSAL_LOG_DEV_STDOUT, + "ixOsalSemaphoreWait(): use a smaller timeout value to avoid \ + overflow \n", 0, 0, 0, 0, 0, 0); + return IX_FAIL; + } + else + { + /* Convert timeout in milliseconds to HZ */ + timeoutTime = jiffies + (timeout * HZ) /IX_OSAL_THOUSAND; + while (1) + { + if (!down_trylock (*sid)) + { + break; + } + else + { + if (time_after(jiffies, timeoutTime)) + { + ixStatus = IX_FAIL; + break; + } + } + /* Switch to next running process instantly */ + set_current_state((long)TASK_INTERRUPTIBLE); + schedule_timeout(1); + + } /* End of while loop */ + } /* End of if */ + + return ixStatus; + +} + +/* + * Attempt to get semaphore, return immediately, + * no error info because users expect some failures + * when using this API. + */ +PUBLIC IX_STATUS +ixOsalSemaphoreTryWait (IxOsalSemaphore * sid) +{ + if (sid == NULL) + { + ixOsalLog (IX_OSAL_LOG_LVL_ERROR, + IX_OSAL_LOG_DEV_STDOUT, + "ixOsalSemaphoreTryWait(): NULL semaphore handle \n", + 0, 0, 0, 0, 0, 0); + return IX_FAIL; + } + if (down_trylock (*sid)) + { + return IX_FAIL; + } + return IX_SUCCESS; +} + +/** + * + * DESCRIPTION: This function causes the next available thread in the pend queue + * to be unblocked. If no thread is pending on this semaphore, the + * semaphore becomes 'full'. + */ +PUBLIC IX_STATUS +ixOsalSemaphorePost (IxOsalSemaphore * sid) +{ + if (sid == NULL) + { + ixOsalLog (IX_OSAL_LOG_LVL_ERROR, + IX_OSAL_LOG_DEV_STDOUT, + "ixOsalSemaphorePost(): NULL semaphore handle \n", + 0, 0, 0, 0, 0, 0); + return IX_FAIL; + } + up (*sid); + return IX_SUCCESS; +} + +PUBLIC IX_STATUS +ixOsalSemaphoreDestroy (IxOsalSemaphore * sid) +{ + if (sid == NULL) + { + ixOsalLog (IX_OSAL_LOG_LVL_ERROR, IX_OSAL_LOG_DEV_STDOUT, + "ixOsalSemaphoreDestroy(): NULL semaphore handle \n", + 0, 0, 0, 0, 0, 0); + return IX_FAIL; + } + + kfree (*sid); + *sid = 0; + + return IX_SUCCESS; +} + +/**************************** + * Mutex + ****************************/ + +PUBLIC IX_STATUS +ixOsalMutexInit (IxOsalMutex * mutex) +{ + if (mutex == NULL) + { + ixOsalLog (IX_OSAL_LOG_LVL_ERROR, IX_OSAL_LOG_DEV_STDOUT, + "ixOsalMutexInit(): NULL mutex handle \n", 0, 0, 0, 0, 0, 0); + return IX_FAIL; + } + *mutex =(struct semaphore *) kmalloc(sizeof(struct semaphore), GFP_KERNEL); + if (*mutex == NULL) + { + ixOsalLog (IX_OSAL_LOG_LVL_ERROR, + IX_OSAL_LOG_DEV_STDOUT, + "ixOsalMutexInit(): Fail to allocate for mutex \n", + 0, 0, 0, 0, 0, 0); + return IX_FAIL; + } + + init_MUTEX (*mutex); + return IX_SUCCESS; +} + +PUBLIC IX_STATUS +ixOsalMutexLock (IxOsalMutex * mutex, INT32 timeout) +{ + unsigned long timeoutTime; + + if (mutex == NULL) + { + ixOsalLog (IX_OSAL_LOG_LVL_ERROR, + IX_OSAL_LOG_DEV_STDOUT, + "ixOsalMutexLock(): NULL mutex handle \n", 0, 0, 0, 0, 0, 0); + return IX_FAIL; + } + + if ((timeout < 0) && (timeout != IX_OSAL_WAIT_FOREVER)) + { + ixOsalLog (IX_OSAL_LOG_LVL_ERROR, + IX_OSAL_LOG_DEV_STDOUT, + "ixOsalMutexLock(): Illegal timeout value \n", 0, 0, 0, 0, 0, 0); + return IX_FAIL; + } + + if (timeout == IX_OSAL_WAIT_FOREVER) + { + down (*mutex); + } + else if (timeout == IX_OSAL_WAIT_NONE) + { + if (down_trylock (*mutex)) + { + return IX_FAIL; + } + } + else if (timeout > IX_OSAL_MAX_TIMEOUT_MS) + { + ixOsalLog (IX_OSAL_LOG_LVL_ERROR, + IX_OSAL_LOG_DEV_STDOUT, + "ixOsalMutexLock(): use smaller timeout value to avoid overflow \n", + 0, 0, 0, 0, 0, 0); + return IX_FAIL; + } + else + { + timeoutTime = jiffies + (timeout * HZ) / IX_OSAL_THOUSAND; + while (1) + { + if (!down_trylock (*mutex)) + { + break; + } + else + { + if (time_after(jiffies, timeoutTime)) + { + return IX_FAIL; + } + } + + /* Switch to next running process if not in atomic state */ + if (!in_atomic()) + { + set_current_state((long)TASK_INTERRUPTIBLE); + schedule_timeout(1); + } + } /* End of while loop */ + } /* End of if */ + return IX_SUCCESS; +} + +PUBLIC IX_STATUS +ixOsalMutexUnlock (IxOsalMutex * mutex) +{ + if (mutex == NULL) + { + ixOsalLog (IX_OSAL_LOG_LVL_ERROR, + IX_OSAL_LOG_DEV_STDOUT, + "ixOsalMutexUnlock(): NULL mutex handle \n", 0, 0, 0, 0, 0, 0); + return IX_FAIL; + } + + up (*mutex); + return IX_SUCCESS; +} + +/* + * Attempt to get mutex, return immediately, + * no error info because users expect some failures + * when using this API. + */ +PUBLIC IX_STATUS +ixOsalMutexTryLock (IxOsalMutex * mutex) +{ + if (mutex == NULL) + { + ixOsalLog (IX_OSAL_LOG_LVL_ERROR, + IX_OSAL_LOG_DEV_STDOUT, + "ixOsalMutexTryLock(): NULL mutex handle \n", 0, 0, 0, 0, 0, 0); + return IX_FAIL; + } + + if (down_trylock (*mutex)) + { + return IX_FAIL; + } + + return IX_SUCCESS; +} + +PUBLIC IX_STATUS +ixOsalMutexDestroy (IxOsalMutex * mutex) +{ + if (mutex == NULL) + { + ixOsalLog (IX_OSAL_LOG_LVL_ERROR, + IX_OSAL_LOG_DEV_STDOUT, + "ixOsalMutexDestroy(): NULL mutex handle \n", 0, 0, 0, 0, 0, 0); + return IX_FAIL; + } + kfree (*mutex); + *mutex = 0; + + return IX_SUCCESS; +} + + + +#ifdef IX_OSAL_OEM_FAST_MUTEX + +PUBLIC IX_STATUS +ixOsalFastMutexInit (IxOsalFastMutex * mutex) +{ + return IX_OSAL_OEM_FAST_MUTEX_INIT (mutex); +} + +PUBLIC IX_STATUS +ixOsalFastMutexTryLock(IxOsalFastMutex *mutex) +{ + return IX_OSAL_OEM_FAST_MUTEX_TRYLOCK(mutex); +} + +PUBLIC IX_STATUS +ixOsalFastMutexUnlock (IxOsalFastMutex * mutex) +{ + if (mutex == NULL) + { + ixOsalLog (IX_OSAL_LOG_LVL_ERROR, + IX_OSAL_LOG_DEV_STDOUT, + "ixOsalFastMutexUnlock(): NULL mutex handle \n", + 0, 0, 0, 0, 0, 0); + return IX_FAIL; + } + return IX_OSAL_OEM_FAST_MUTEX_UNLOCK(mutex); +} + +PUBLIC IX_STATUS +ixOsalFastMutexDestroy (IxOsalFastMutex * mutex) +{ + if (mutex == NULL) + { + ixOsalLog (IX_OSAL_LOG_LVL_ERROR, + IX_OSAL_LOG_DEV_STDOUT, + "ixOsalFastMutexDestroy(): NULL mutex handle \n", + 0, 0, 0, 0, 0, 0); + return IX_FAIL; + } + + return IX_OSAL_OEM_FAST_MUTEX_DESTROY(mutex); +} + +#else /* ! OEM_FAST_MUTEX */ + +PUBLIC IX_STATUS +ixOsalFastMutexInit (IxOsalFastMutex * mutex) +{ + if (mutex) + { + atomic_set(mutex,1); + return IX_SUCCESS; + } + else + { + return IX_FAIL; + } +} + +PUBLIC IX_STATUS +ixOsalFastMutexTryLock(IxOsalFastMutex *mutex) +{ + if (atomic_dec_and_test(mutex)) + { + return IX_SUCCESS; + } + else + { + atomic_inc(mutex); + return IX_FAIL; + } +} + +PUBLIC IX_STATUS +ixOsalFastMutexUnlock (IxOsalFastMutex * mutex) +{ + if (mutex) + { + atomic_inc(mutex); + return IX_SUCCESS; + } + else + { + return IX_FAIL; + } +} + +PUBLIC IX_STATUS +ixOsalFastMutexDestroy (IxOsalFastMutex * mutex) +{ + atomic_set(mutex,1); + return IX_SUCCESS; +} + +#endif /* IX_OSAL_OEM_FAST_MUTEX */ + + +PUBLIC +IX_STATUS ixOsalSemaphoreDownTimeout( + IxOsalSemaphore *sid, + INT32 timeout) +{ + IX_STATUS ixStatus; + ixStatus = ixOsalSemaphoreWait (sid, timeout); + return ixStatus; + +} /* ixOsalSemaphoreDownTimeout */ + + + +PUBLIC +IX_STATUS ixOsalSemaphoreWaitInterruptible( + IxOsalSemaphore *sid, + INT32 timeout) +{ + IX_STATUS ixStatus = IX_SUCCESS; + unsigned long timeoutTime; + + if (sid == NULL) + { + ixOsalLog (IX_OSAL_LOG_LVL_ERROR, IX_OSAL_LOG_DEV_STDOUT, + "ixOsalSemaphoreWaitInterruptible(): NULL handle \n", + 0, 0, 0, 0, 0, 0); + return IX_FAIL; + } + + /* + * Guard against illegal timeout values + */ + if ((timeout < 0) && (timeout != IX_OSAL_WAIT_FOREVER)) + { + ixOsalLog (IX_OSAL_LOG_LVL_ERROR, IX_OSAL_LOG_DEV_STDOUT, + "ixOsalSemaphoreWaitInterruptible: illegal timeout value\n", + 0, 0, 0, 0, 0, 0); + return IX_FAIL; + } + + if (timeout == IX_OSAL_WAIT_FOREVER) + { + // stupid morons wrote that code, what can I do? + if (down_interruptible(*sid)) + return IX_FAIL; // well i can do that, this might probably be less harmful than the original "i don't care" + // approach, and less stupid than a busy waiting approach, but anyway i don't really give a + // fuck about that absurd amount of shit + } + else if (timeout == IX_OSAL_WAIT_NONE) + { + if (down_trylock (*sid)) + { + ixStatus = IX_FAIL; + } + } + else if (timeout > IX_OSAL_MAX_TIMEOUT_MS) + { + ixOsalLog (IX_OSAL_LOG_LVL_ERROR, IX_OSAL_LOG_DEV_STDOUT, + "ixOsalSemaphoreWaitInterruptible():use smaller timeout \ + value to avoid overflow \n", 0, 0, 0, 0, 0, 0); + return IX_FAIL; + } + else + { + /* Convert timeout in milliseconds to HZ */ + timeoutTime = jiffies + (timeout * HZ) /IX_OSAL_THOUSAND; + while (1) + { + if (!down_trylock (*sid)) + { + break; + } + else + { + if (time_after(jiffies, timeoutTime)) + { + ixStatus = IX_FAIL; + break; + } + } + /* Switch to next running process instantly */ + set_current_state((long)TASK_INTERRUPTIBLE); + schedule_timeout(1); + + } /* End of while loop */ + } /* End of if */ + + return ixStatus; + +} /* ixOsalSemaphoreWaitInterruptible */ diff --git a/Acceleration/library/icp_utils/OSAL/common/os/linux/src/core/IxOsalOsServices.c b/Acceleration/library/icp_utils/OSAL/common/os/linux/src/core/IxOsalOsServices.c new file mode 100644 index 0000000..db99c48 --- /dev/null +++ b/Acceleration/library/icp_utils/OSAL/common/os/linux/src/core/IxOsalOsServices.c @@ -0,0 +1,586 @@ +/** + * @file IxOsalOsServices.c (linux) + * + * @brief Implementation for Mem and Sleep. + * + * + * @par + * This file is provided under a dual BSD/GPLv2 license. When using or + * redistributing this file, you may do so under either license. + * + * GPL LICENSE SUMMARY + * + * Copyright(c) 2007,2008,2009 Intel Corporation. All rights reserved. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of version 2 of the GNU General Public License as + * published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA. + * The full GNU General Public License is included in this distribution + * in the file called LICENSE.GPL. + * + * Contact Information: + * Intel Corporation + * + * BSD LICENSE + * + * Copyright(c) 2007,2008,2009 Intel Corporation. All rights reserved. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Intel Corporation nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * + * + */ +#include "IxOsal.h" +#include "IxOsalOsTypes.h" + +#include <linux/version.h> + +#include <linux/delay.h> +#include <linux/kernel.h> +#include <linux/time.h> +#include <linux/sched.h> +#include <linux/slab.h> + +#include <linux/mm.h> +#include <linux/mempool.h> +#include <linux/vmalloc.h> + +/* More generic include */ +#include <linux/highmem.h> +#include <asm/pgtable.h> +#include <linux/random.h> + +/* Trace Message Logging Levels */ + +static char *traceHeaders[] = { + "", + "[fatal] ", + "[error] ", + "[warning] ", + "[message] ", + "[debug1] ", + "[debug2] ", + "[debug3] ", + "[all]" +}; + +static CHAR osalModuleName[OSAL_MAX_MODULE_NAME_LENGTH] = ""; + +/* by default trace all but debug message */ +PRIVATE unsigned int ixOsalCurrLogLevel = IX_OSAL_LOG_LVL_MESSAGE; + +#define IS_VMALLOC_ADDR(addr) (((UINT32)(addr) >= VMALLOC_START) && \ + ((UINT32)(addr) < VMALLOC_END)) + +/* Maximum memory (in bytes) that can be allocated using kmalloc. + Beyond this, vmalloc is to be used to allcoate memory */ +#define IX_OSAL_MAX_KMALLOC_MEM (1024 * 128) + + +/********************* + * Log function + *********************/ + +INT32 +ixOsalLog (IxOsalLogLevel level, + IxOsalLogDevice device, + char *format, int arg1, int arg2, int arg3, int arg4, int arg5, int arg6) +{ + /* + * Return -1 for custom display devices + */ + if ((device != IX_OSAL_LOG_DEV_STDOUT) + && (device != IX_OSAL_LOG_DEV_STDERR)) + { + printk + ("ixOsalLog: only IX_OSAL_LOG_DEV_STDOUT and \ + IX_OSAL_LOG_DEV_STDERR are supported \n"); + return (IX_OSAL_LOG_ERROR); + } + + if (level <= ixOsalCurrLogLevel && level != IX_OSAL_LOG_LVL_NONE) + { + INT32 return_val; + int headerByteCount = + (level == + IX_OSAL_LOG_LVL_USER) ? 0 : printk (traceHeaders[level - 1]); + + + if ( OSAL_OS_GET_STRING_LENGTH(osalModuleName) != 0 ) + { + headerByteCount += + printk("%s :",osalModuleName); + } + headerByteCount += + printk (format, + arg1, arg2, arg3, arg4, arg5,arg6); + return_val = (INT32)headerByteCount; + return return_val; + } + else + { + /* + * Return zero byte printed + */ + return (IX_OSAL_NO_LOG); + } +} + +PUBLIC UINT32 +ixOsalLogLevelSet (UINT32 level) +{ + UINT32 oldLevel; + + /* + * Check value first + */ + if ((level < IX_OSAL_LOG_LVL_NONE) || (level > IX_OSAL_LOG_LVL_ALL)) + { + ixOsalLog (IX_OSAL_LOG_LVL_MESSAGE, + IX_OSAL_LOG_DEV_STDOUT, + "ixOsalLogLevelSet: Log Level is between %d and%d \n", + IX_OSAL_LOG_LVL_NONE, IX_OSAL_LOG_LVL_ALL, 0, 0, 0, 0); + return IX_OSAL_LOG_LVL_NONE; + } + oldLevel = ixOsalCurrLogLevel; + + ixOsalCurrLogLevel = level; + + return oldLevel; +} + +/************************************** + * Task services + *************************************/ + +PUBLIC void +ixOsalBusySleep (UINT32 microseconds) +{ + udelay (microseconds); +} + +PUBLIC void +ixOsalSleep (UINT32 milliseconds) +{ + if (milliseconds != 0) + { + set_current_state((long)TASK_INTERRUPTIBLE); + schedule_timeout ((milliseconds * HZ) / IX_OSAL_THOUSAND); + } + else + { + schedule (); + } +} + +/************************************** + * Memory functions + *************************************/ + +void * +ixOsalMemAlloc (UINT32 memsize) +{ + if(memsize > IX_OSAL_MAX_KMALLOC_MEM) + { + return ( vmalloc(memsize) ); + } + + return (kmalloc (memsize, GFP_KERNEL)); +} + +void +ixOsalMemFree (void *ptr) +{ + IX_OSAL_MEM_ASSERT (ptr != NULL); + + if(IS_VMALLOC_ADDR(ptr)) + { + vfree(ptr); + return; + } + + kfree (ptr); +} + +/* + * Copy count bytes from src to dest , + * returns pointer to the dest mem zone. + */ +void * +ixOsalMemCopy (void *dest, const void *src, UINT32 count) +{ + IX_OSAL_MEM_ASSERT (dest != NULL); + IX_OSAL_MEM_ASSERT (src != NULL); + return (memcpy (dest, src, count)); +} + +/* + * Fills a memory zone with a given constant byte, + * returns pointer to the memory zone. + */ +void * +ixOsalMemSet (void *ptr, UINT8 filler, UINT32 count) +{ + IX_OSAL_MEM_ASSERT (ptr != NULL); + return (memset (ptr, filler, count)); +} + +/** + * Compares count bytes from src and dest + * returns IX_SUCCESS/IX_FAIL + */ +PUBLIC IX_STATUS ixOsalMemCmp (void *dest, void *src, UINT32 count) +{ + IX_STATUS status = IX_FAIL; + IX_OSAL_MEM_ASSERT (dest != NULL); + IX_OSAL_MEM_ASSERT (src != NULL); + if( memcmp (dest, src, count) ==0) + { + status=IX_SUCCESS; + } + return status; +} + +/***************************** + * + * Time + * + *****************************/ + +/* Retrieve current system time */ +void +ixOsalTimeGet (IxOsalTimeval * ptime) +{ + /* + * linux struct timeval has subfields: + * -- time_t (type long, second) + * -- suseconds_t ( type long, usecond) + */ + do_gettimeofday ((struct timeval *) ptime); + + /* + * Translate microsecond to nanosecond, + * second field is identical so no translation + * there. + */ + ptime->nsecs *= IX_OSAL_THOUSAND; + +} + + +PUBLIC void +ixOsalYield (void) +{ + schedule (); +} + +PUBLIC IX_STATUS +ixOsalOsNameGet (INT8* osName, INT32 maxSize) +{ + IX_STATUS status = IX_FAIL; + + /* Ensure that the input parameters are valid */ + if (osName == NULL || maxSize <= 0) + { + ixOsalLog (IX_OSAL_LOG_LVL_ERROR, + IX_OSAL_LOG_DEV_STDOUT, + "ixOsalOsNameGet: invalid input parameters\n", + 0, 0, 0, 0, 0, 0); + + return status; + } + + status = IX_OSAL_OEM_OS_NAME_GET(osName, maxSize); + + return status; +} + +PUBLIC IX_STATUS +ixOsalOsVersionGet(INT8* osVersion, INT32 maxSize) +{ + IX_STATUS status = IX_FAIL; + + /* Ensure that the input parameters are valid */ + if (osVersion == NULL || maxSize <= 0) + { + ixOsalLog (IX_OSAL_LOG_LVL_ERROR, IX_OSAL_LOG_DEV_STDOUT, + "ixOsalOsVersionGet: invalid input parameters\n", + 0, 0, 0, 0, 0, 0); + return status; + } + + status = IX_OSAL_OEM_OS_VERSION_GET(osVersion, maxSize); + return status; +} + + +PUBLIC +IX_STATUS ixOsalSleepTick(UINT32 sleeptime_ticks) +{ + if(sleeptime_ticks < 1) + { + schedule(); + return IX_SUCCESS; + } + else + { + set_current_state((long)TASK_UNINTERRUPTIBLE); + schedule_timeout(sleeptime_ticks); + } + + return IX_SUCCESS; +} /* ixOsalSleepTick */ + + +PUBLIC +IX_STATUS ixOsalSleepUninterruptible( + UINT32 sleeptime_ms) +{ + struct timespec value; + + if(sleeptime_ms < 1) + { + schedule(); + return IX_SUCCESS; + } + + value.tv_sec = sleeptime_ms/IX_OSAL_THOUSAND; + { + INT64 ll_sleeptime; + ll_sleeptime = (sleeptime_ms % IX_OSAL_THOUSAND) * IX_OSAL_MILLION; + ixOsalMemCopy(&value.tv_nsec, &ll_sleeptime, sizeof (value.tv_nsec)); + } + /*Block added to remove parasoft issue*/ + { + unsigned long l_sleep_time = timespec_to_jiffies(&value); + ixOsalMemCopy(&sleeptime_ms, &l_sleep_time, sizeof (UINT32)); + } + { + struct task_struct* aTask = current; + aTask->state = (long)TASK_UNINTERRUPTIBLE; + schedule_timeout(sleeptime_ms); + } + return IX_SUCCESS; +} /* ixOsalSleepUninterruptible */ + +/* + * The function allocate a chunck of memory bigger that the required size + * It then calculate the aligned ptr that should be returned to the user. + * In the memory just above the returned chunck, the funcion stores the + * structure with the memory information + * + * +---+-------------------------+------------------------------- +---+ + * |xxx|ixOsalMemAllocInfoStruct | memory returned to user (size) |xxx| + * +---+-------------------------+--------------------------------+---+ + * ^ ^ + * mAllocMemPtr Ptr returned to the caller of MemAlloc + * + */ +PUBLIC VOID * +ixOsalMemAllocAligned(UINT32 space, UINT32 size, UINT32 alignment) +{ + + VOID* ptr = NULL; + UINT32 toPadSize = 0; + UINT32 padding = 0; + VOID* pRet = NULL; + UINT32 alignment_offset = 0; + + ixOsalMemAllocInfoStruct memInfo = {0}; + + if (size == 0 || alignment < 1) + { + ixOsalLog (IX_OSAL_LOG_LVL_MESSAGE, IX_OSAL_LOG_DEV_STDOUT, + "[ixOsalMemAllocAligned] size or alignment are zero \n", + size, alignment, 0, 0, 0, 0); + return NULL; + } + + if (alignment & (alignment-1)) + { + ixOsalLog (IX_OSAL_LOG_LVL_MESSAGE, IX_OSAL_LOG_DEV_STDOUT, + "[ixOsalMemAllocAligned] Expecting alignment of a power " + "of two but did not get one\n", 0, 0, 0, 0, 0, 0); + return NULL; + } + + if (1 == alignment) + { + toPadSize = sizeof(ixOsalMemAllocInfoStruct); + padding = 0; + } + else if (sizeof(ixOsalMemAllocInfoStruct) > alignment) + { + toPadSize = sizeof(ixOsalMemAllocInfoStruct) + alignment; + padding = IX_OSAL_MEM_PADDING(toPadSize, alignment); + } + else + { + toPadSize = alignment; + padding = 0; + } + + memInfo.mSize = size + toPadSize + padding; + + if (memInfo.mSize > IX_OSAL_MAX_KMALLOC_MEM) + { + ixOsalLog (IX_OSAL_LOG_LVL_MESSAGE, IX_OSAL_LOG_DEV_STDOUT, + "[ixOsalMemAllocAligned] Total size needed for this " + "set of size and alignment (%ld) exceeds the OS " + "limit %ld\n", memInfo.mSize, IX_OSAL_MAX_KMALLOC_MEM, + 0, 0, 0, 0); + + + return NULL; + } + + ptr = kmalloc (memInfo.mSize, GFP_KERNEL); + + if (ptr == NULL) + { + ixOsalLog (IX_OSAL_LOG_LVL_MESSAGE, IX_OSAL_LOG_DEV_STDOUT, + "[ixOsalMemAllocAligned] memory allocation " + "failed %ld/%d\n", + size, alignment, 0, 0, 0, 0); + + return NULL; + } + + + alignment_offset = (UINT32)ptr % alignment; + memInfo.mAllocMemPtr = ptr; + + pRet = (VOID*) ((CHAR*)ptr + toPadSize + padding + alignment_offset); + memcpy((VOID*)((CHAR*)pRet - sizeof(ixOsalMemAllocInfoStruct)), + (VOID*)(&memInfo), + sizeof(ixOsalMemAllocInfoStruct)); + + return pRet; + +} + +VOID +ixOsalMemAlignedFree (VOID *ptr, UINT32 size) +{ + ixOsalMemAllocInfoStruct *memInfo = NULL; + + memInfo = (ixOsalMemAllocInfoStruct *)((CHAR *)ptr - + sizeof(ixOsalMemAllocInfoStruct)); + + if (memInfo->mSize == 0 || memInfo->mAllocMemPtr == NULL) + { + ixOsalLog (IX_OSAL_LOG_LVL_MESSAGE, IX_OSAL_LOG_DEV_STDOUT, + "[ixOsalMemAlignedFree] ERROR: Detected the corrupted " + "data: memory leak!! \n", 0, 0, 0, 0, 0, 0); + + return; + } + + kfree (memInfo->mAllocMemPtr); + +} + +PUBLIC VOID +ixOsalGetRandomNum32(UINT32 *num) +{ + get_random_bytes((void *)num, sizeof (UINT32)); +} + +PUBLIC VOID +ixOsalLogSetPrefix(CHAR * moduleName) +{ + UINT8 stringLength; + + if (moduleName == NULL) + { + return; + } + + stringLength = (UINT8)OSAL_OS_GET_STRING_LENGTH(moduleName); + + if (stringLength >= OSAL_MAX_MODULE_NAME_LENGTH) + { + stringLength = OSAL_MAX_MODULE_NAME_LENGTH -1 ; + } + + ixOsalMemCopy(osalModuleName,moduleName,stringLength); + osalModuleName[stringLength] = '\0'; + return; +} + +/** + * @ingroup IxOsal + * + * @brief simple logging function + * + * @param arg_pFmtString - message format, in printk format + * arg1 - argument 1 + * arg2 - argument 2 + * arg3 - argument 3 + * arg4 - argument 4 + * arg5 - argument 5 + * arg6 - argument 6 + * + * Logging function, similar to printk. This provides a barebones logging + * mechanism for users without differing verbosity levels. This interface + * is not quaranteed to be IRQ safe. + * + * @li Reentrant: yes + * @li IRQ safe: no + */ + + +IX_STATUS ixOsalStdLog( + const char* arg_pFmtString, + ... + ) +{ + IX_STATUS err = IX_SUCCESS; + va_list argList; + + va_start(argList, arg_pFmtString); + if ( OSAL_OS_GET_STRING_LENGTH(osalModuleName) != 0 ) + { + printk("%s :",osalModuleName); + } + vprintk(arg_pFmtString, argList); + va_end(argList); + + return err; + +} /* ixOsalStdLog */ + diff --git a/Acceleration/library/icp_utils/OSAL/common/os/linux/src/core/IxOsalOsSpinLock.c b/Acceleration/library/icp_utils/OSAL/common/os/linux/src/core/IxOsalOsSpinLock.c new file mode 100644 index 0000000..531d5ed --- /dev/null +++ b/Acceleration/library/icp_utils/OSAL/common/os/linux/src/core/IxOsalOsSpinLock.c @@ -0,0 +1,507 @@ +/** + * @file IxOsalOsSpinLock.c (linux) + * + * @brief Implementation for spinlocks + * + * + * @par + * This file is provided under a dual BSD/GPLv2 license. When using or + * redistributing this file, you may do so under either license. + * + * GPL LICENSE SUMMARY + * + * Copyright(c) 2007,2008,2009 Intel Corporation. All rights reserved. + * Copyright(c) 2010,2011,2012 Avencall + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of version 2 of the GNU General Public License as + * published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA. + * The full GNU General Public License is included in this distribution + * in the file called LICENSE.GPL. + * + * BSD LICENSE + * + * Copyright(c) 2007,2008,2009 Intel Corporation. All rights reserved. + * All rights reserved. + * Copyright(c) 2010,2011,2012 Avencall + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Intel Corporation nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * + * + */ + +#include "IxOsal.h" + +/** + *********************************************************** + * @function: ixOsalSpinLockInit + * + * @param: slock - IN - pointer to a spinlock_t type + * @param: slockType - IN - not used + * + * @return: IX_STATUS - IX_SUCCESS or IX_FAIL + * + * @brief: Initialize Spin Lock. + *********************************************************** + */ +PUBLIC IX_STATUS +ixOsalSpinLockInit(IxOsalSpinLock *slock, IxOsalSpinLockType slockType) +{ + IX_OSAL_LOCAL_ENSURE(slock, + "ixOsalSpinLockInit(): Null spinlock pointer", + IX_FAIL); + + /* Spinlock type is ignored in case of Linux */ + spin_lock_init (slock); /* Kernel function call */ + + return IX_SUCCESS; +} + +/** + *********************************************************** + * @function: ixOsalSpinLockLock + * + * @param: slock - IN - pointer to a spinlock_t type + * + * @return: IX_STATUS - IX_SUCCESS or IX_FAIL + * + * @brief: Acquire the basic SpinLock + *********************************************************** + */ +PUBLIC IX_STATUS +ixOsalSpinLockLock(IxOsalSpinLock *slock) +{ + IX_OSAL_LOCAL_ENSURE(slock, + "ixOsalSpinLockLock(): Null spinlock pointer", + IX_FAIL); + + spin_lock (slock); /* kernel function call */ + + return IX_SUCCESS; +} + +/** + *********************************************************** + * + * @param: slock - IN - pointer to a spinlock_t type + * + * @return: IX_STATUS - IX_SUCCESS or IX_FAIL + * + * @brief: Release the SpinLock. + *********************************************************** + */ +PUBLIC IX_STATUS +ixOsalSpinLockUnlock(IxOsalSpinLock *slock) +{ + IX_OSAL_LOCAL_ENSURE(slock, + "ixOsalSpinLockUnlock(): Null spinlock pointer", + IX_FAIL); + + spin_unlock (slock); /* kernel function call */ + + return IX_SUCCESS; +} + +/** + *********************************************************** + * @function: ixOsalSpinLockTry + * + * @param: slock - IN - pointer to a spinlock_t type + * + * @return: IX_STATUS - IX_SUCCESS or IX_FAIL + * + * @brief: Try to acquire the SpinLock. + *********************************************************** + */ +PUBLIC IX_STATUS +ixOsalSpinLockTry(IxOsalSpinLock *slock) +{ + IX_OSAL_LOCAL_ENSURE(slock, + "ixOsalSpinLockTry(): Null spinlock pointer", + IX_FAIL); + + /* kernel function call */ + return spin_trylock(slock) ? IX_SUCCESS : IX_FAIL; +} + +/** + *********************************************************** + * @function: ixOsalSpinLockDestroy + * + * @param: slock - IN - pointer to a spinlock_t type + * + * @return: IX_STATUS - IX_SUCCESS or IX_FAIL + * + * @brief: Destroy the SpinLock. This is done by freeing + * the memory allocated to Spinlock. + *********************************************************** + */ +PUBLIC IX_STATUS +ixOsalSpinLockDestroy(IxOsalSpinLock *slock) +{ + IX_OSAL_LOCAL_ENSURE(slock, + "ixOsalSpinLockDestroy(): Null spinlock pointer", + IX_FAIL); + return IX_SUCCESS; +} + +/** + * @ingroup IxOsal + * + * @brief checks whether spinlock can be acquired + * + * @param slock - Spinlock handle + * + * This routine checks whether spinlock available for lock + * + * @li Reentrant: yes + * @li IRQ safe: yes + * + * @return - IX_SUCCESS if spinlock is locked. Returns IX_FAIL if spinlock + * is not locked. + */ + +PUBLIC IX_STATUS ixOsalSpinLockIsLocked(IxOsalSpinLock *slock) +{ + /* SpinLock NULL pointer check. */ + IX_OSAL_LOCAL_ENSURE(slock, + "ixOsalSpinLockIsLocked(): NULL spinlock pointer", + IX_FAIL); + + return spin_is_locked(slock) ? IX_SUCCESS : IX_FAIL; +} + + +/** + * @ingroup IxOsal + * + * @brief Acquires a spinlock + * + * @param slock - Spinlock handle + * + * This routine disables local irqs & then acquires a slock + * + * @li Reentrant: yes + * @li IRQ safe: yes + * + * @usage This API can be used in user context or bottom half when critical + * section is shared between user context or bottom half and the + * irq handler + * + * @return - returns IX_SUCCESS if spinlock is acquired. If the spinlock is not + * available then it busy loops/spins till slock available. If the + * spinlock handle passed is NULL then returns IX_FAIL. + */ + +PUBLIC IX_STATUS ixOsalSpinLockLockIrq(IxOsalSpinLock *slock) +{ + /* SpinLock NULL pointer check. */ + IX_OSAL_LOCAL_ENSURE(slock, + "ixOsalSpinLockLockIrq(): NULL spinlock pointer", + IX_FAIL); + + spin_lock_irq(slock); + return IX_SUCCESS; +} + +/** + * @ingroup IxOsal + * + * @brief Releases the spinlock + * + * @param slock - Spinlock handle + * + * This routine releases the acquired spinlock & enables the local irqs + * + * @li Reentrant: yes + * @li IRQ safe: yes + * + * @usage This API can be used in user context or bottom half when critical + * section is shared between user context or bottom half and + * irq handler + * + * @return - returns IX_SUCCESS if slock is unlocked. Returns IX_FAIL if the + * slock is NULL. + */ +PUBLIC IX_STATUS ixOsalSpinLockUnlockIrq(IxOsalSpinLock *slock) +{ + /* SpinLock NULL pointer check. */ + IX_OSAL_LOCAL_ENSURE(slock, + "ixOsalSpinLockUnlockIrq(): Null spinlock pointer", + IX_FAIL); + + spin_unlock_irq(slock); + return IX_SUCCESS; +} + +/** + * @ingroup IxOsal + * + * @brief Tries to acquire the spinlock + * + * @param slock - Spinlock handle + * + * This routine disables local irq & attempts to acquire a spinlock but + * doesn't block the thread if spinlock not available. + * + * @li Reentrant: yes + * @li IRQ safe: yes + * + * @usage This API can be used in user context or bottom half when critical + * section is shared between user context or bottom half and + * irq handler + * + * @return -If spinlock is available then returns the IX_SUCCESS with + * spinlock locked. If spinlock not available then enables the + * local irqs & returns IX_FAIL + * + */ + +PUBLIC IX_STATUS ixOsalSpinLockTryIrq(IxOsalSpinLock *slock) +{ + /* SpinLock NULL pointer check. */ + IX_OSAL_LOCAL_ENSURE(slock, + "ixOsalSpinLockTryIrq(): Null spinlock pointer", + IX_FAIL); + + return spin_trylock_irq(slock) ? IX_SUCCESS : IX_FAIL; + +} + +/** + * @ingroup IxOsal + * + * @brief Acquires a spinlock + * + * @param slock - Spinlock handle + * + * This routine disables bottom half & then acquires a slock + * + * @li Reentrant: yes + * @li IRQ safe: yes + * + * @usage This API can be used in user context when critical section is + * shared between user context & bottom half handler + * + * @return - returns IX_SUCCESS if spinlock is acquired. If the spinlock is not + * available then it busy loops/spins till slock available. If the + * spinlock handle passed is NULL then returns IX_FAIL. + */ + +PUBLIC IX_STATUS ixOsalSpinLockLockBh(IxOsalSpinLock *slock) +{ + /* SpinLock NULL pointer check. */ + IX_OSAL_LOCAL_ENSURE(slock, + "ixOsalSpinLockLockBh(): Null spinlock pointer", + IX_FAIL); + + spin_lock_bh(slock); + return IX_SUCCESS; + +} + +/** + * @ingroup IxOsal + * + * @brief Releases the spin lock + * + * @param slock - Spinlock handle + * + * This routine releases the acquired spinlock & enables the + * bottom half handler + * + * @li Reentrant: yes + * @li IRQ safe: no + * + * @usage This API can be used in user context when critical section is + * shared between user context & bottom half handler + * + * @return - returns IX_SUCCESS if slock is released or unlocked. + * Returns IX_FAIL if the slock is NULL. + */ +PUBLIC IX_STATUS ixOsalSpinLockUnlockBh(IxOsalSpinLock *slock) +{ + /* SpinLock NULL pointer check. */ + IX_OSAL_LOCAL_ENSURE(slock, + "ixOsalSpinLockUnlockBh(): Null spinlock pointer", + IX_FAIL); + + spin_unlock_bh(slock); + return IX_SUCCESS; +} + +/** + * @ingroup IxOsal + * + * @brief Tries to acquire the spin lock + * + * @param slock - Spinlock handle + * + * This routine disables bottom half handler & attempts to acquire a spinlock + * but doesn't block the thread if spinlock not available. It enables the bh & + * returns IX_FAIL if spinlock not available. + * + * @li Reentrant: yes + * @li IRQ safe: no + * + * @usage This API can be used in user context when critical section is + * shared between user context & bottom half handler + * + * @return -Returns the IX_SUCCESS with spinlock locked if the spinlock is + * available. Enables the local irqs & return IX_FAIL + * if spinlock is not available. + */ +PUBLIC IX_STATUS ixOsalSpinLockTryBh(IxOsalSpinLock *slock) +{ + /* SpinLock NULL pointer check. */ + IX_OSAL_LOCAL_ENSURE(slock, + "ixOsalSpinLockTryBh(): Null spinlock pointer", + IX_FAIL); + + return spin_trylock_bh(slock) ? IX_SUCCESS : IX_FAIL; +} + +/** + * @ingroup IxOsal + * + * @brief Acquires a spinlock + * + * @param slock - Spinlock handle + * @param flags - local irqs saved in flags + * + * @usage This API can be used when critical section is shared between + * irq routines + * + * This routine saves local irqs in flags & then acquires a spinlock + * + * @li Reentrant: yes + * @li IRQ safe: yes + * + * @return - returns IX_SUCCESS if spinlock acquired. If the spinlock is not + * available then it busy loops/spins till slock available. + * If the spinlock handle passed is NULL then returns IX_FAIL. + */ + +PUBLIC IX_STATUS ixOsalSpinLockLockIrqSave(IxOsalSpinLock *slock, + UINT32 *flags) +{ + /* SpinLock NULL pointer check. */ + IX_OSAL_LOCAL_ENSURE(slock, + "ixOsalSpinLockLockIrqSave(): Null spinlock pointer", + IX_FAIL); + + IX_OSAL_LOCAL_ENSURE(flags, + "ixOsalSpinLockLockIrqSave(): Null flags pointer", + IX_FAIL); + + // ugly hack because of ugly source code + spin_lock_irqsave(slock, *((unsigned long *)flags)); + return IX_SUCCESS; +} + +/** + * @ingroup IxOsal + * + * @brief Releases the spin lock + * + * @param slock - Spinlock handle + * @param flags - local irqs saved in flags + * + * @usage This API can be used when critical section is shared between + * irq routines + * + * This routine releases the acquired spin lock & restores irqs in flags + * + * @li Reentrant: yes + * @li IRQ safe: yes + * + * @return - returns IX_SUCCESS if slock is unlocked. Returns IX_FAIL if the + * slock is NULL. + */ +PUBLIC IX_STATUS ixOsalSpinLockUnlockIrqRestore(IxOsalSpinLock *slock, + UINT32 *flags) +{ + /* SpinLock NULL pointer check. */ + IX_OSAL_LOCAL_ENSURE(slock, + "ixOsalSpinLockUnlockIrqRestore(): Null spinlock pointer", + IX_FAIL); + + IX_OSAL_LOCAL_ENSURE(flags, + "ixOsalSpinLockUnlockIrqRestore(): Null flags pointer", + IX_FAIL); + + spin_unlock_irqrestore(slock, *((unsigned long *)flags)); + + return IX_SUCCESS; +} + +/** + * @ingroup IxOsal + * + * @brief Tries to acquire the spinlock + * + * @param slock - Spinlock handle + * @param flags - local irqs saved in flags + * + * This routine saves irq in flags & attempts to acquire a spinlock but + * doesn't block the thread if the spin lock not avialble. If the + * spinlock not available then it restore the irqs & return IX_FAIL + * + * @li Reentrant: yes + * @li IRQ safe: yes + * + * @usage This API can be used when critical section is shared between + * irq routines + * + * @return -Returns the IX_SUCCESS with spinlock locked if the spinlock is + * available. Enables the local irqs & returns IX_FAIL + * if spinlock not available. + */ +PUBLIC IX_STATUS ixOsalSpinLockTryIrqSave(IxOsalSpinLock *slock, UINT32 *flags) +{ + /* SpinLock NULL pointer check. */ + IX_OSAL_LOCAL_ENSURE(slock, + "ixOsalSpinLockTryIrqSave(): Null spinlock pointer", + IX_FAIL); + + IX_OSAL_LOCAL_ENSURE(flags, + "ixOsalSpinLockTryIrqSave(): Null flags pointer", + IX_FAIL); + + return spin_trylock_irqsave(slock, *((unsigned long *)flags)) + ? IX_SUCCESS : IX_FAIL; +} diff --git a/Acceleration/library/icp_utils/OSAL/common/os/linux/src/core/IxOsalOsSymbols.c b/Acceleration/library/icp_utils/OSAL/common/os/linux/src/core/IxOsalOsSymbols.c new file mode 100644 index 0000000..81b9e52 --- /dev/null +++ b/Acceleration/library/icp_utils/OSAL/common/os/linux/src/core/IxOsalOsSymbols.c @@ -0,0 +1,207 @@ +/* + * @file IxOsalOsSymbols.c + * @author Intel Corporation + * @date 25-08-2004 + * + * @brief description goes here + * + * @par + * This file is provided under a dual BSD/GPLv2 license. When using or + * redistributing this file, you may do so under either license. + * + * GPL LICENSE SUMMARY + * + * Copyright(c) 2007,2008,2009 Intel Corporation. All rights reserved. + * Copyright(c) 2010,2011,2012 Avencall + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of version 2 of the GNU General Public License as + * published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA. + * The full GNU General Public License is included in this distribution + * in the file called LICENSE.GPL. + * + * BSD LICENSE + * + * Copyright(c) 2007,2008,2009 Intel Corporation. All rights reserved. + * All rights reserved. + * Copyright(c) 2010,2011,2012 Avencall + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Intel Corporation nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * + * + */ +#include "IxOsal.h" + +#ifdef IX_OSAL_MODULE +#include <linux/init.h> +#include <linux/module.h> +MODULE_LICENSE("Dual BSD/GPL"); +#endif + +#ifdef OSAL_EXPORT_SYMBOLS + +EXPORT_SYMBOL (ixOsalMemAlloc); +EXPORT_SYMBOL (ixOsalMemFree); +EXPORT_SYMBOL (ixOsalMemCopy); +EXPORT_SYMBOL (ixOsalMemSet); +EXPORT_SYMBOL (ixOsalMemCmp); + + +EXPORT_SYMBOL (ixOsalThreadCreate); +EXPORT_SYMBOL (ixOsalThreadStart); +EXPORT_SYMBOL (ixOsalThreadKill); +EXPORT_SYMBOL (ixOsalThreadExit); +EXPORT_SYMBOL (ixOsalThreadPrioritySet); +EXPORT_SYMBOL (ixOsalThreadSuspend); +EXPORT_SYMBOL (ixOsalThreadResume); +EXPORT_SYMBOL (ixOsalThreadGetPolicyAndPriority); + +#ifdef IX_OSAL_THREAD_EXIT_GRACEFULLY +EXPORT_SYMBOL (ixOsalThreadStopCheck); +#endif /* IX_OSAL_THREAD_EXIT_GRACEFULLY */ + +EXPORT_SYMBOL (ixOsalMessageQueueCreate); +EXPORT_SYMBOL (ixOsalMessageQueueDelete); +EXPORT_SYMBOL (ixOsalMessageQueueSend); +EXPORT_SYMBOL (ixOsalMessageQueueReceive); +EXPORT_SYMBOL (ixOsalSyncMessageQueueReceive); +EXPORT_SYMBOL (ixOsalSyncMessageQueueCreate); + +EXPORT_SYMBOL (ixOsalMutexInit); +EXPORT_SYMBOL (ixOsalMutexLock); +EXPORT_SYMBOL (ixOsalMutexUnlock); +EXPORT_SYMBOL (ixOsalMutexTryLock); +EXPORT_SYMBOL (ixOsalMutexDestroy); +EXPORT_SYMBOL (ixOsalFastMutexInit); +EXPORT_SYMBOL (ixOsalFastMutexTryLock); +EXPORT_SYMBOL (ixOsalFastMutexUnlock); +EXPORT_SYMBOL (ixOsalFastMutexDestroy); + +EXPORT_SYMBOL (ixOsalSemaphoreInit); +EXPORT_SYMBOL (ixOsalSemaphorePost); +EXPORT_SYMBOL (ixOsalSemaphoreWait); +EXPORT_SYMBOL (ixOsalSemaphoreTryWait); +EXPORT_SYMBOL (ixOsalSemaphoreDestroy); +EXPORT_SYMBOL (ixOsalSemaphoreWaitInterruptible); +EXPORT_SYMBOL (ixOsalSleepTick); +EXPORT_SYMBOL (ixOsalSleepUninterruptible); +EXPORT_SYMBOL (ixOsalSemaphoreDownTimeout); + +EXPORT_SYMBOL (ixOsalYield); +EXPORT_SYMBOL (ixOsalSleep); +EXPORT_SYMBOL (ixOsalBusySleep); +EXPORT_SYMBOL (ixOsalTimeGet); +EXPORT_SYMBOL (ixOsalTimevalToTicks); +EXPORT_SYMBOL (ixOsalTicksToTimeval); + +EXPORT_SYMBOL (ixOsalLog); +EXPORT_SYMBOL (ixOsalStdLog); +EXPORT_SYMBOL (ixOsalLogLevelSet); +EXPORT_SYMBOL (ixOsalLogSetPrefix); +EXPORT_SYMBOL (ixOsalRepeatingTimerSchedule); +EXPORT_SYMBOL (ixOsalSingleShotTimerSchedule); +EXPORT_SYMBOL (ixOsalTimerCancel); +EXPORT_SYMBOL (ixOsalTimersShow); + +EXPORT_SYMBOL (ixOsalOsNameGet); +EXPORT_SYMBOL (ixOsalOsVersionGet); + +/* New Functions */ +EXPORT_SYMBOL (ixOsalThreadGetId); +EXPORT_SYMBOL (ixOsalThreadSetPolicyAndPriority); + + +#ifdef ENABLE_SPINLOCK + +EXPORT_SYMBOL (ixOsalSpinLockInit); +EXPORT_SYMBOL (ixOsalSpinLockLock); +EXPORT_SYMBOL (ixOsalSpinLockUnlock); +EXPORT_SYMBOL (ixOsalSpinLockTry); +EXPORT_SYMBOL (ixOsalSpinLockDestroy); +EXPORT_SYMBOL (ixOsalSpinLockIsLocked); +EXPORT_SYMBOL (ixOsalSpinLockLockBh); +EXPORT_SYMBOL (ixOsalSpinLockUnlockBh); +EXPORT_SYMBOL (ixOsalSpinLockTryBh); +EXPORT_SYMBOL (ixOsalSpinLockLockIrq); +EXPORT_SYMBOL (ixOsalSpinLockUnlockIrq); +EXPORT_SYMBOL (ixOsalSpinLockTryIrq); +EXPORT_SYMBOL (ixOsalSpinLockLockIrqSave); +EXPORT_SYMBOL (ixOsalSpinLockUnlockIrqRestore); +EXPORT_SYMBOL (ixOsalSpinLockTryIrqSave); + +#endif /* ENABLE_SPINLOCK */ + +EXPORT_SYMBOL (ixOsalAtomicGet); +EXPORT_SYMBOL (ixOsalAtomicSet); +EXPORT_SYMBOL (ixOsalAtomicAdd); +EXPORT_SYMBOL (ixOsalAtomicSub); +EXPORT_SYMBOL (ixOsalAtomicSubAndTest); +EXPORT_SYMBOL (ixOsalAtomicInc); +EXPORT_SYMBOL (ixOsalAtomicDec); +EXPORT_SYMBOL (ixOsalAtomicDecAndTest); +EXPORT_SYMBOL (ixOsalAtomicIncAndTest); + +EXPORT_SYMBOL (ixOsalMemBarrier); +EXPORT_SYMBOL (ixOsalReadMemBarrier); +EXPORT_SYMBOL (ixOsalWriteMemBarrier); + +EXPORT_SYMBOL (ixOsalGetRandomNum32); +EXPORT_SYMBOL (ixOsalMemAllocAtomic); +EXPORT_SYMBOL (ixOsalMemAllocAligned); +EXPORT_SYMBOL (ixOsalMemAlignedFree); + +#endif /* OSAL_EXPORT_SYMBOLS */ + +#ifdef IX_OSAL_MODULE + +static int osal_init( void ) +{ + printk( "Loading OSAL Module ...\n" ) ; + return 0; +} + + +static void osal_exit( void ) +{ + printk("Unloading OSAL Module ...\n" ) ; +} + +module_init(osal_init); +module_exit(osal_exit); + +#endif + diff --git a/Acceleration/library/icp_utils/OSAL/common/os/linux/src/core/IxOsalOsThread.c b/Acceleration/library/icp_utils/OSAL/common/os/linux/src/core/IxOsalOsThread.c new file mode 100644 index 0000000..ceba2ed --- /dev/null +++ b/Acceleration/library/icp_utils/OSAL/common/os/linux/src/core/IxOsalOsThread.c @@ -0,0 +1,467 @@ +/** + * @file IxOsalOsThread.c (linux) + * + * @brief OS-specific thread implementation. + * + * + * @par + * This file is provided under a dual BSD/GPLv2 license. When using or + * redistributing this file, you may do so under either license. + * + * GPL LICENSE SUMMARY + * + * Copyright(c) 2007,2008,2009 Intel Corporation. All rights reserved. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of version 2 of the GNU General Public License as + * published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA. + * The full GNU General Public License is included in this distribution + * in the file called LICENSE.GPL. + * + * Contact Information: + * Intel Corporation + * + * BSD LICENSE + * + * Copyright(c) 2007,2008,2009 Intel Corporation. All rights reserved. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Intel Corporation nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * + * + */ + +#include "IxOsal.h" + +#include <linux/sched.h> + +#ifdef IX_OSAL_OS_LINUX_VERSION_2_6 + +#include <linux/list.h> +#include <linux/kthread.h> +#include <linux/hardirq.h> + +#endif /* IX_OSAL_OS_LINUX_VERSION_2_6 */ + +/* Thread Data structure */ +struct IxOsalOsThreadData +{ + IxOsalVoidFnVoidPtr entryPoint; + void *arg; +}; + +/* declaring mutexes */ +DECLARE_MUTEX (IxOsalThreadMutex); +DECLARE_MUTEX (IxOsalThreadStopMutex); + +#ifndef IX_OSAL_OS_LINUX_VERSION_2_6 /* ! Linux-Kernel Version 2.6 */ + +struct IxOsalOsThreadData thread_data; +struct task_struct *kill_task = NULL; + +#endif + + +#ifdef IX_OSAL_OS_LINUX_VERSION_2_6 /* Linux Kernel Version 2.6 */ + +/* Thread info structure */ +struct IxOsalOsThreadInfo +{ + struct IxOsalOsThreadData data; + IxOsalThread ptid; + struct list_head list; +}; + + +/* Thread attribute is ignored in Create */ + +PUBLIC IX_STATUS +ixOsalThreadCreate (IxOsalThread * ptrTid, + IxOsalThreadAttr * threadAttr, IxOsalVoidFnVoidPtr entryPoint, void *arg) +{ + *ptrTid = kthread_create((void *)entryPoint, arg, "%s", + (NULL != threadAttr && NULL != threadAttr->name) + ? threadAttr->name: "OSAL"); + + return IX_SUCCESS; +} + + +PUBLIC IX_OSAL_INLINE BOOL +ixOsalThreadStopCheck(void) +{ + INT32 err = kthread_should_stop(); + return err ? TRUE : FALSE; +} + +/** + * Start the thread + */ +PUBLIC IX_STATUS +ixOsalThreadStart (IxOsalThread *tId) +{ + if (NULL == *tId) + { + ixOsalLog (IX_OSAL_LOG_LVL_ERROR, IX_OSAL_LOG_DEV_STDOUT, + "ixOsalThreadStart(): Invalid Thread ID!\n", 0, 0, 0, 0, 0, 0); + return IX_FAIL; + } + + wake_up_process(*tId); + return IX_SUCCESS; +} + +#ifdef IX_OSAL_THREAD_EXIT_GRACEFULLY +/* Exit status check is possible only in kernel 2.6.10 and greater */ + +/* + * Kill the kernel thread. This shall not be used if the thread function + * implements do_exit() + */ +PUBLIC IX_STATUS +ixOsalThreadKill (IxOsalThread * tid) +{ + struct task_struct *task = (struct task_struct*)*tid; + + /* Can't kill already defunc thread */ + if (EXIT_DEAD == task->exit_state || EXIT_ZOMBIE == task->exit_state) + { + return IX_FAIL; + } + + if (-EINTR == kthread_stop(task)) + { + ixOsalLog (IX_OSAL_LOG_LVL_ERROR, IX_OSAL_LOG_DEV_STDOUT, + "ixOsalThreadKill(): Failed to kill thread\n", 0, 0, 0, 0, 0, 0); + + return IX_FAIL; + } + + return IX_SUCCESS; +} + +#else /* __! EXIT_GRACEFULLY */ + +PUBLIC IX_STATUS +ixOsalThreadKill (IxOsalThread * tid) +{ + kill_proc ((pid_t)*tid, SIGKILL, 1); + return IX_SUCCESS; +} + +#endif /* IX_OSAL_THREAD_EXIT_GRACEFULLY */ + + + +/******************************************************************** + * UINT32 priority - the value of priority can range from 0 to 39 * + * with 0 being the highest priority. * + * * + * Any value for priority more than 39 will be silently rounded off * + * to 39 in this implementation. Internally, the range is converted * + * to the corresponding nice value that can range from -20 to 19. * + ********************************************************************/ + +PUBLIC IX_STATUS +ixOsalThreadPrioritySet (IxOsalThread * tid, UINT32 priority) +{ + struct task_struct *pTask = (struct task_struct*)*tid; + + IX_OSAL_LOCAL_ENSURE(tid, + "ixOsalThreadPrioritySet(): Null pointer", + IX_FAIL); + + if (priority > IX_OSAL_PRIO_SET_MAX_VALID_VAL) + { + ixOsalLog (IX_OSAL_LOG_LVL_ERROR, IX_OSAL_LOG_DEV_STDERR, + "ixOsalThreadPrioritySet(): FAIL \n", 0, 0, 0, 0, 0, 0); + return IX_FAIL; + } + + if (priority > IX_OSAL_PRIO_SET_MAX_VAL) + { + priority = IX_OSAL_PRIO_SET_MAX_VAL; + } + if (priority < 0) + { + priority = 0; + } + + /* sending the nice equivalent of priority as the parameter */ + set_user_nice ( pTask, priority - IX_OSAL_NICE_VAL_DIFFERENCE ); + + ixOsalLog (IX_OSAL_LOG_LVL_MESSAGE, IX_OSAL_LOG_DEV_STDOUT, + "ixOsalThreadPrioritySet(): Priority changed successfully \n", + 0, 0, 0, 0, 0, 0); + + return IX_SUCCESS; +} + +/** + *********************************************************** + * End of code cleanup section + *********************************************************** + */ + +#else /* ! LINUX_VERSION_2_6 */ + +PUBLIC IX_OSAL_INLINE BOOL +ixOsalThreadStopCheck() +{ + if (current == kill_task) + { + kill_task = NULL; + up(&IxOsalThreadStopMutex); + return TRUE; + } + return FALSE; +} + +static int +thread_internal (void *unused) +{ + IxOsalVoidFnVoidPtr entryPoint = thread_data.entryPoint; + void *arg = thread_data.arg; + static int seq = 0; + + daemonize(); + reparent_to_init (); + exit_files (current); + + snprintf(current->comm, sizeof(current->comm), "IxOsal %d", ++seq); + + up (&IxOsalThreadMutex); + + entryPoint (arg); + return 0; +} + +/* Thread attribute is ignored */ +PUBLIC IX_STATUS +ixOsalThreadCreate (IxOsalThread * ptrTid, + IxOsalThreadAttr * threadAttr, IxOsalVoidFnVoidPtr entryPoint, void *arg) +{ + down (&IxOsalThreadMutex); + thread_data.entryPoint = entryPoint; + thread_data.arg = arg; + + /* + * kernel_thread takes: int (*fn)(void *) as the first input. + */ + *ptrTid = kernel_thread (thread_internal, NULL, CLONE_SIGHAND); + + if (*ptrTid < 0) + { + up (&IxOsalThreadMutex); + ixOsalLog (IX_OSAL_LOG_LVL_ERROR, IX_OSAL_LOG_DEV_STDOUT, + "ixOsalThreadCreate(): fail to generate thread \n", + 0, 0, 0, 0, 0, 0); + return IX_FAIL; + } + + return IX_SUCCESS; + +} + +/* + * Start thread after given its thread handle + */ +PUBLIC IX_STATUS +ixOsalThreadStart (IxOsalThread * tId) +{ + /* Thread already started upon creation */ + ixOsalLog (IX_OSAL_LOG_LVL_MESSAGE, IX_OSAL_LOG_DEV_STDOUT, + "ixOsalThreadStart(): not implemented in linux\n", + 0, 0, 0, 0, 0, 0); + return IX_SUCCESS; +} + + +PUBLIC IX_STATUS +ixOsalThreadKill (IxOsalThread * tid) +{ + down(&IxOsalThreadStopMutex); + kill_task = find_task_by_pid(*tid); + + if (kill_task) + { + wake_up_process(kill_task); + + return IX_SUCCESS; + } + + ixOsalLog (IX_OSAL_LOG_LVL_ERROR, IX_OSAL_LOG_DEV_STDOUT, + "ixOsalThreadKill: Task %d was dead\n", *tid, 0, 0, 0, 0, 0); + + /* Kill failed, remove the mutex */ + up(&IxOsalThreadStopMutex); + return IX_FAIL; +} + +#endif /* IX_OSAL_OS_LINUX_VERSION_2_6 */ + +PUBLIC void +ixOsalThreadExit (void) +{ + ixOsalLog (IX_OSAL_LOG_LVL_MESSAGE, IX_OSAL_LOG_DEV_STDOUT, + "ixOsalThreadExit(): not implemented in linux\n", 0, 0, 0, 0, 0, 0); +} + +PUBLIC IX_STATUS +ixOsalThreadSuspend (IxOsalThread * tId) +{ + ixOsalLog (IX_OSAL_LOG_LVL_WARNING, IX_OSAL_LOG_DEV_STDOUT, + "ixOsalThreadSuspend(): not implemented in linux\n", 0, 0, 0, 0, 0, 0); + return IX_SUCCESS; +} + +PUBLIC IX_STATUS +ixOsalThreadResume (IxOsalThread * tId) +{ + ixOsalLog (IX_OSAL_LOG_LVL_WARNING, IX_OSAL_LOG_DEV_STDOUT, + "ixOsalThreadResume(): not implemented in linux \n", 0, 0, 0, 0, 0, 0); + return IX_SUCCESS; + +} + +IX_STATUS +ixOsalThreadGetId(IxOsalThread *ptrTid) +{ + *ptrTid = (IxOsalThread)current->pid; + + return IX_SUCCESS; + +} /* ixOsalThreadGetId */ + + +IX_STATUS +ixOsalThreadSetPolicyAndPriority( + IxOsalThread *tid, + UINT32 policy, + UINT32 priority) +{ + +#ifdef IX_OSAL_OS_LINUX_VER_GT_2_6_18 + struct task_struct *pTask = (struct task_struct*)*tid; + struct sched_param param1; + INT32 status; + + IX_OSAL_LOCAL_ENSURE(tid, + "ixOsalThreadSetPolicyAndPriority(): Null pointer", + IX_FAIL); + /* set the policy of existing */ + policy = policy; + param1.sched_priority = priority; + status = sched_setscheduler(pTask, policy, ¶m1); + if(status) + { + return IX_FAIL; + } + else + { + return IX_SUCCESS; + } +#else + IX_STATUS err = IX_SUCCESS; + struct task_struct *pTask; + + IX_OSAL_LOCAL_ENSURE(tid, + "ixOsalThreadSetPolicyAndPriority(): Null pointer", + IX_FAIL); + lock_kernel(); + + /* In case of Linux Kernel 2.4: + * pTask = find_task_by_pid(*tid); */ + + /* In case of Kernel 2.6(default for OSSL-Shim) */ + pTask = *tid; + + if(pTask == 0) + { + err = IX_FAIL; + }else{ + pTask->policy = policy; + pTask->rt_priority = priority; + } + + unlock_kernel(); + return err; +#endif /* IX_OSAL_OS_LINUX_VER_BT_2_6_18 */ + +} /* ixOsalThreadSetPolicyAndPriority */ + +PUBLIC IX_STATUS +ixOsalThreadGetPolicyAndPriority( + IxOsalThread *tid, + UINT32 *policy, + UINT32 *priority) +{ +#ifdef IX_OSAL_OS_LINUX_VER_GT_2_6_18 + struct task_struct *pTask = (struct task_struct*)*tid; + + IX_OSAL_ENSURE_RETURN(tid, "Null pointer"); + /* set the policy of existing */ + *policy = pTask->policy; + *priority = pTask->rt_priority; + return IX_SUCCESS; + +#else + IX_STATUS err = IX_SUCCESS; + struct task_struct *pTask; + + IX_OSAL_ENSURE_RETURN(tid, "Null pointer"); + lock_kernel(); + + /* In case of Linux Kernel 2.4: + * pTask = find_task_by_pid(*tid); */ + + pTask = *tid; + + if(pTask == 0) + { + err = IX_FAIL; + }else{ + *policy = pTask->policy; + *priority = pTask->rt_priority; + } + + unlock_kernel(); + return err; +#endif /* IX_OSAL_OS_LINUX_VER_BT_2_6_18 */ + +} + diff --git a/Acceleration/library/icp_utils/OSAL/common/os/linux/src/core/IxOsalOsTimer.c b/Acceleration/library/icp_utils/OSAL/common/os/linux/src/core/IxOsalOsTimer.c new file mode 100644 index 0000000..1171305 --- /dev/null +++ b/Acceleration/library/icp_utils/OSAL/common/os/linux/src/core/IxOsalOsTimer.c @@ -0,0 +1,275 @@ +/** + * @file IxOsalOsTimer.c (linux) + * + * @brief Implementation for Timer API's. + * + * + * @par + * This file is provided under a dual BSD/GPLv2 license. When using or + * redistributing this file, you may do so under either license. + * + * GPL LICENSE SUMMARY + * + * Copyright(c) 2007,2008,2009 Intel Corporation. All rights reserved. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of version 2 of the GNU General Public License as + * published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA. + * The full GNU General Public License is included in this distribution + * in the file called LICENSE.GPL. + * + * Contact Information: + * Intel Corporation + * + * BSD LICENSE + * + * Copyright(c) 2007,2008,2009 Intel Corporation. All rights reserved. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Intel Corporation nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * + * + */ +#include "IxOsal.h" + +#include <linux/timer.h> + + +static void callback_repeat_timer(unsigned long ptr) +{ + IxOsalTimerRec *nTimerPtr; + + nTimerPtr = (IxOsalTimerRec *)ptr; + /* if timer inUse then only reregister the timer */ + if(nTimerPtr->inUse == TRUE) + { + /* call callback function registered by user */ + nTimerPtr->callback(nTimerPtr->callbackParam); + nTimerPtr->timer.expires = jiffies + nTimerPtr->period; + /* add timer to call the callback after period */ + add_timer(&nTimerPtr->timer); + } +} + +/** + * @ingroup IxOsal + * + * @brief Schedules a repeating timer + * + * @param timer - handle of the timer object + * @param period - timer trigger period, in milliseconds + * @param priority - timer priority (0 being the highest) + * @param callback - user callback to invoke when the timer triggers + * @param param - custom parameter passed to the callback + * + * Schedules a timer to be called every period milliseconds. The timer + * will invoke the specified callback function possibly in interrupt + * context, passing the given parameter. If several timers trigger at the + * same time contention issues are dealt according to the specified timer + * priorities. + * + * @li Reentrant: no + * @li IRQ safe: no + * + * @return - IX_SUCCESS/IX_FAIL + */ +PUBLIC IX_STATUS ixOsalRepeatingTimerSchedule (IxOsalTimer *timer, + UINT32 period, + UINT32 priority, + IxOsalVoidFnVoidPtr callback, + void *param) +{ + IxOsalTimerRec *timerPtr; + IX_OSAL_LOCAL_ENSURE(timer, + "ixOsalRepeatingTimerSchedule(): Null IxOsalTimer pointer", + IX_FAIL); + + IX_OSAL_LOCAL_ENSURE(callback, + "ixOsalRepeatingTimerSchedule(): NULL callback function pointer", + IX_FAIL); + + *timer = kmalloc (sizeof (IxOsalTimerRec), GFP_KERNEL); + if (!(*timer)) + { + ixOsalLog (IX_OSAL_LOG_LVL_ERROR, + IX_OSAL_LOG_DEV_STDOUT, + "ixOsalRepeatingTimerSchedule(): " + "Fail to allocate for IxOsalTimer \n", + 0, 0, 0, 0, 0, 0); + return IX_FAIL; + } + + timerPtr = *timer; + timerPtr->inUse = TRUE; + init_timer(&(timerPtr->timer)); + timerPtr->timer.function = callback_repeat_timer; + timerPtr->timer.data = (unsigned long)timerPtr; + timerPtr->timer.expires = jiffies + \ + ((period*HZ)/IX_OSAL_THOUSAND); + + /* store period to call the callback at regular intervals in jiffies*/ + timerPtr->period = ((period*HZ)/IX_OSAL_THOUSAND); + timerPtr->callback = callback; + timerPtr->callbackParam = param; + timerPtr->isRepeating = TRUE; + add_timer(&(timerPtr->timer)); + + return IX_SUCCESS; +} + +/** + * @ingroup IxOsal + * + * @brief Schedules a single-shot timer + * + * @param timer - handle of the timer object + * @param period - timer trigger period, in milliseconds + * @param priority - timer priority (0 being the highest) + * @param callback - user callback to invoke when the timer triggers + * @param param - custom parameter passed to the callback + * + * Schedules a timer to be called after period milliseconds. The timer + * will cease to function past its first trigger. The timer will invoke + * the specified callback function, possibly in interrupt context, passing + * the given parameter. If several timers trigger at the same time contention + * issues are dealt according to the specified timer priorities. + * + * @li Reentrant: no + * @li IRQ safe: no + * + * @return - IX_SUCCESS/IX_FAIL + */ +PUBLIC IX_STATUS +ixOsalSingleShotTimerSchedule (IxOsalTimer *timer, + UINT32 period, + UINT32 priority, + IxOsalVoidFnVoidPtr callback, void *param) +{ + IxOsalTimerRec *timerPtr; + + IX_OSAL_LOCAL_ENSURE(timer, + "ixOsalSingleShotTimerSchedule(): NULL IxOsalTimer pointer", + IX_FAIL); + + IX_OSAL_LOCAL_ENSURE(callback, + "ixOsalSingleShotTimerSchedule(): NULL callback function pointer", + IX_FAIL); + + *timer = kmalloc (sizeof (IxOsalTimerRec), GFP_KERNEL); + if (!(*timer)) + { + ixOsalLog (IX_OSAL_LOG_LVL_ERROR, + IX_OSAL_LOG_DEV_STDOUT, + "ixOsalSingleShotTimerSchedule() Fail to allocate IxOsalTimer \n", + 0, 0, 0, 0, 0, 0); + return IX_FAIL; + } + + timerPtr = *timer; + timerPtr->inUse = TRUE; + init_timer(&timerPtr->timer); + timerPtr->timer.function = (voidFnULongPtr)callback; + timerPtr->timer.data = (unsigned long)param; + timerPtr->timer.expires = jiffies + \ + ((period*HZ)/IX_OSAL_THOUSAND); + timerPtr->isRepeating = FALSE; + add_timer(&timerPtr->timer); + + return IX_SUCCESS; +} + +/** + * @ingroup IxOsal + * + * @brief Cancels a running timer + * + * @param timer - handle of the timer object + * + * Cancels a single-shot or repeating timer. + * + * @li Reentrant: no + * @li IRQ safe: yes + * + * @return - IX_SUCCESS/IX_FAIL + */ +PUBLIC IX_STATUS ixOsalTimerCancel (IxOsalTimer * timer) +{ + IxOsalTimerRec *timerPtr; + IX_OSAL_LOCAL_ENSURE(timer, + "ixOsalTimerCancel(): Null IxOsalTimer pointer\n", + IX_FAIL); + + timerPtr = *timer; + if(timerPtr->inUse == FALSE) + { + ixOsalLog (IX_OSAL_LOG_LVL_ERROR, IX_OSAL_LOG_DEV_STDOUT, + "ixOsalTimerCancel(): Timer is already deleted\n", + 0, 0, 0, 0, 0, 0); + return IX_FAIL; + } + + timerPtr->inUse = FALSE; + /* free & call del_timer in callback fn for repeat timer */ + del_timer(&(timerPtr->timer)); + kfree (*timer); + + return IX_SUCCESS; +} + +/** + * @ingroup IxOsal + * + * @brief displays all the running timers + * + * Displays a list with all the running timers and their parameters (handle, + * period, type, priority, callback and user parameter) + * + * @li Reentrant: no + * @li IRQ safe: no + * + * @return - none + */ +PUBLIC void ixOsalTimersShow (void) +{ + ixOsalLog (IX_OSAL_LOG_LVL_MESSAGE, IX_OSAL_LOG_DEV_STDOUT, + "ixOsalTimersShow not Supported in linux native mode implemenattion\n", + 0, 0, 0, 0, 0, 0); + + return ; +} + + diff --git a/Acceleration/library/icp_utils/OSAL/common/os/linux/src/core/component.mk b/Acceleration/library/icp_utils/OSAL/common/os/linux/src/core/component.mk new file mode 100644 index 0000000..d9d25b8 --- /dev/null +++ b/Acceleration/library/icp_utils/OSAL/common/os/linux/src/core/component.mk @@ -0,0 +1,85 @@ +# +# @par +# This file is provided under a dual BSD/GPLv2 license. When using or +# redistributing this file, you may do so under either license. +# +# GPL LICENSE SUMMARY +# +# Copyright(c) 2007,2008,2009 Intel Corporation. All rights reserved. +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of version 2 of the GNU General Public License as +# published by the Free Software Foundation. +# +# This program is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA. +# The full GNU General Public License is included in this distribution +# in the file called LICENSE.GPL. +# +# Contact Information: +# Intel Corporation +# +# BSD LICENSE +# +# Copyright(c) 2007,2008,2009 Intel Corporation. All rights reserved. +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions +# are met: +# +# * Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# * Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in +# the documentation and/or other materials provided with the +# distribution. +# * Neither the name of Intel Corporation nor the names of its +# contributors may be used to endorse or promote products derived +# from this software without specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +# +# +# + +core_os_OBJ := \ + IxOsalOsThread.o \ + IxOsalOsServices.o \ + IxOsalOsSemaphore.o \ + IxOsalOsSymbols.o \ + IxOsalOsMsgQ.o \ + IxOsalOsAtomic.o \ + IxOsalOsMemBarrier.o + +ifneq (,$(findstring ENABLE_SPINLOCK,$(CFLAGS))) +core_os_OBJ += IxOsalOsSpinLock.o +endif + +ifneq (,$(findstring USE_NATIVE_OS_TIMER_API,$(CFLAGS))) +core_os_OBJ += IxOsalOsTimer.o +endif + +ifneq (,$(findstring IX_OSAL_MODULE,$(CFLAGS))) +core_os_OBJ += IxOsalOsModule.o +endif + +# Add CFLAGS per source file here if needed +core_os_CFLAGS := + diff --git a/Acceleration/library/icp_utils/OSAL/common/os/linux/src/modules/ddk/IxOsalOsDdkCacheMMU.c b/Acceleration/library/icp_utils/OSAL/common/os/linux/src/modules/ddk/IxOsalOsDdkCacheMMU.c new file mode 100644 index 0000000..fd8b61d --- /dev/null +++ b/Acceleration/library/icp_utils/OSAL/common/os/linux/src/modules/ddk/IxOsalOsDdkCacheMMU.c @@ -0,0 +1,226 @@ +/** + * @file IxOsalOsDdkCacheMMU.c (linux) + * + * @brief Cache MemAlloc and MemFree. + * + * + * @par + * This file is provided under a dual BSD/GPLv2 license. When using or + * redistributing this file, you may do so under either license. + * + * GPL LICENSE SUMMARY + * + * Copyright(c) 2007,2008,2009 Intel Corporation. All rights reserved. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of version 2 of the GNU General Public License as + * published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA. + * The full GNU General Public License is included in this distribution + * in the file called LICENSE.GPL. + * + * Contact Information: + * Intel Corporation + * + * BSD LICENSE + * + * Copyright(c) 2007,2008,2009 Intel Corporation. All rights reserved. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Intel Corporation nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * + * + */ +#include "IxOsal.h" +#include <linux/kernel.h> +#include <linux/slab.h> + + + +/* + * Allocate on a cache line boundary (null pointers are + * not affected by this operation). This operation is NOT cache safe. + */ +void * +ixOsalCacheDmaMalloc (UINT32 size) +{ + struct page *page; + UINT32 order; + UINT32 *userPtr; + UINT32 *myPtr; + UINT32 mySize; + + /* The minimum allocation size is 32 */ + if (size < IX_OSAL_CACHE_LINE_SIZE) + { + size = IX_OSAL_CACHE_LINE_SIZE; + } + + /* + * myPtr userPtr end of last cache line + * _________________________________________________________ + * | | | | | | | + * |Or|Ptr|Sz|Ma| USER BUFFER | | + * |__|___|__|__|_________________________________|_________| + * + * myPtr: The pointer returned by kmalloc. This may not be 32 byte aligned + * userPtr: The pointer returned to the user. This is guaranteed + * to be 32 byte aligned + * Or: The order of pages that was allocated. This info is needed + * for deallocating the buffer + * Ma: Arbitrary number 0xBABEFACE that allows to check against + * memory corruption + * Sz: The value of the requested memory allocation size + * Ptr: This 4-byte field records the value of myPtr. This info is + * needed in order to deallocate the buffer + */ + + /* Check whether the request is for a "small" memory chunck */ + if (size <= IX_OSAL_OS_SMALL_MEM_SIZE) + { + /* + * Ensure that the size is rounded up to a multiple of a cache line + * and add to it a cache line for storing internal information + */ + mySize = size + + (IX_OSAL_OS_NUM_INFO_WORDS * IX_OSAL_OS_BYTES_PER_WORD); + mySize = IX_OSAL_OS_CL_ROUND_UP(mySize); + mySize += IX_OSAL_CACHE_LINE_SIZE; + myPtr = (UINT32 *)kmalloc(mySize, GFP_KERNEL); + + IX_OSAL_LOCAL_ENSURE( (NULL != myPtr), + "ixOsalCacheDmaMalloc(): Fail to alloc small memory \n", + NULL); + + /* Pass to the user a pointer that is cache line aligned */ + userPtr = myPtr + IX_OSAL_OS_NUM_INFO_WORDS; + userPtr = (UINT32 *) IX_OSAL_OS_CL_ROUND_UP((UINT32)userPtr); + + /* It is imperative that the user pointer be 32 byte aligned */ + IX_OSAL_LOCAL_ENSURE( + (((UINT32) userPtr % IX_OSAL_CACHE_LINE_SIZE) == 0), + "ixOsalCacheDmaMalloc(): " + "Error memory allocated is not 32 byte aligned\n", + NULL); + } + else + { + /* + * Increase the size by a full cacheline for size information. + */ + { + ULONG temp_size = PAGE_ALIGN (size + IX_OSAL_CACHE_LINE_SIZE); + /*size = PAGE_ALIGN (size + IX_OSAL_CACHE_LINE_SIZE);*/ + ixOsalMemCopy(&size,&temp_size,sizeof(UINT32)); + } + order = (UINT32)get_order (size); + page = alloc_pages (GFP_KERNEL, order); + if (!page) + { + ixOsalLog (IX_OSAL_LOG_LVL_ERROR, IX_OSAL_LOG_DEV_STDOUT, + "ixOsalCacheDmaMalloc(): Fail to alloc page \n", + 0, 0, 0, 0, 0, 0); + return NULL; + } + myPtr = (UINT32 *) page_address (page); + + /* The client's pointer is 32 bytes ahead of my pointer */ + userPtr = (UINT32 *)((UINT32) myPtr + IX_OSAL_CACHE_LINE_SIZE); + /* Store the page order 4 words behind the client's pointer */ + userPtr[IX_OSAL_OS_ORDER_OF_PAGES_INDEX] = order; + } + + /* Store the allocated pointer 3 words behind the client's pointer */ + userPtr[IX_OSAL_OS_MYPTR_INDEX] = (UINT32)myPtr; + /* Store the requested size 2 words behind the client's pointer */ + userPtr[IX_OSAL_OS_REQUESTED_SIZE_INDEX] = size; + /* Store the allocation identifier 1 word behind the client's pointer */ + userPtr[IX_OSAL_OS_MAGIC_NUMBER_INDEX] = IX_OSAL_OS_MAGIC_ALLOC_NUMBER; + + return ((void *)userPtr); +} + +/* + * + * Frees the memory buffer allocated in previous function + */ +void +ixOsalCacheDmaFree (void *ptr) +{ + UINT32 order; + UINT32 *memptr; + UINT32 size; + UINT32 *clientPtr = ptr; + + if ( NULL == ptr) + { + ixOsalLog(IX_OSAL_LOG_LVL_ERROR, IX_OSAL_LOG_DEV_STDOUT, + "ixOsalCacheDmaFree(): NULL Ptr passed \n", + 0, 0, 0, 0, 0, 0); + return; + } + + /* Make sure that the pointer passed in belongs to us */ + if (clientPtr[IX_OSAL_OS_MAGIC_NUMBER_INDEX] + != IX_OSAL_OS_MAGIC_ALLOC_NUMBER) + { + ixOsalLog(IX_OSAL_LOG_LVL_ERROR, IX_OSAL_LOG_DEV_STDOUT, + "ixOsalCacheDmaFree(): Memory being freed is invalid \n", + 0, 0, 0, 0, 0, 0); + return; + } + + /* Detect multiple deallocation */ + clientPtr[IX_OSAL_OS_MAGIC_NUMBER_INDEX] = IX_OSAL_OS_MAGIC_DEALLOC_NUMBER; + + /* Rewind ptr to retrieve requested-size information */ + memptr = (UINT32 *)clientPtr[IX_OSAL_OS_MYPTR_INDEX]; + size = clientPtr[IX_OSAL_OS_REQUESTED_SIZE_INDEX]; + + /* The requested size will determine how the memory will be freed */ + if (size <= IX_OSAL_OS_SMALL_MEM_SIZE) + { + /* Free the "small" page */ + kfree(memptr); + } + else + { + /* Get the order information */ + order = clientPtr[IX_OSAL_OS_ORDER_OF_PAGES_INDEX]; + /* Free the memory page(s) */ + free_pages ((unsigned int) memptr, order); + } +} diff --git a/Acceleration/library/icp_utils/OSAL/common/os/linux/src/modules/ddk/IxOsalOsDdkClk.c b/Acceleration/library/icp_utils/OSAL/common/os/linux/src/modules/ddk/IxOsalOsDdkClk.c new file mode 100644 index 0000000..24548aa --- /dev/null +++ b/Acceleration/library/icp_utils/OSAL/common/os/linux/src/modules/ddk/IxOsalOsDdkClk.c @@ -0,0 +1,94 @@ +/** + * @file IxOsalOsDdkClk.c (linux) + * + * @brief System Clock Rate and TimeStamp functions. + * + * + * @par + * This file is provided under a dual BSD/GPLv2 license. When using or + * redistributing this file, you may do so under either license. + * + * GPL LICENSE SUMMARY + * + * Copyright(c) 2007,2008,2009 Intel Corporation. All rights reserved. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of version 2 of the GNU General Public License as + * published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA. + * The full GNU General Public License is included in this distribution + * in the file called LICENSE.GPL. + * + * Contact Information: + * Intel Corporation + * + * BSD LICENSE + * + * Copyright(c) 2007,2008,2009 Intel Corporation. All rights reserved. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Intel Corporation nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * + * + */ +#include "IxOsal.h" +#include <asm/system.h> +#include <linux/delay.h> +#include <linux/time.h> + + + + +/* TimeStamp is implemented in OEM */ +PUBLIC UINT32 +ixOsalTimestampGet (void) +{ + return IX_OSAL_OEM_TIMESTAMP_GET (); +} + +/* OEM-specific implementation for TimeStamp Resolution */ +PUBLIC UINT32 +ixOsalTimestampResolutionGet (void) +{ + return IX_OSAL_OEM_TIMESTAMP_RESOLUTION_GET (); +} + +/* OEM-specific implementation for System Clock Rate */ +PUBLIC UINT32 +ixOsalSysClockRateGet (void) +{ + return IX_OSAL_OEM_SYS_CLOCK_RATE_GET (); +} diff --git a/Acceleration/library/icp_utils/OSAL/common/os/linux/src/modules/ddk/IxOsalOsDdkIrq.c b/Acceleration/library/icp_utils/OSAL/common/os/linux/src/modules/ddk/IxOsalOsDdkIrq.c new file mode 100644 index 0000000..7295cd2 --- /dev/null +++ b/Acceleration/library/icp_utils/OSAL/common/os/linux/src/modules/ddk/IxOsalOsDdkIrq.c @@ -0,0 +1,388 @@ +/** + * @file IxOsalOsDdkIrq.c (linux) + * + * @brief System Interrupt functions. + * + * + * @par + * This file is provided under a dual BSD/GPLv2 license. When using or + * redistributing this file, you may do so under either license. + * + * GPL LICENSE SUMMARY + * + * Copyright(c) 2007,2008,2009 Intel Corporation. All rights reserved. + * Copyright(c) 2010,2011,2012 Avencall + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of version 2 of the GNU General Public License as + * published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA. + * The full GNU General Public License is included in this distribution + * in the file called LICENSE.GPL. + * + * BSD LICENSE + * + * Copyright(c) 2007,2008,2009 Intel Corporation. All rights reserved. + * All rights reserved. + * Copyright(c) 2010,2011,2012 Avencall + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Intel Corporation nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * + * + */ + +#include "IxOsal.h" + +#include <linux/version.h> +#ifdef IX_OSAL_OS_LINUX_VER_GT_2_6_20 +#include <linux/irq.h> +#endif +#ifdef IX_OSAL_OS_LINUX_VERSION_2_6 +#include <linux/hardirq.h> +#include <linux/interrupt.h> +#endif + +#include <asm/hardirq.h> +#include <asm/system.h> +#include <asm/irq.h> + +#include "IxOsalOsOem.h" +#include "IxOsalOsOemIrq.h" + + + +/* + * Note: being referenced by some release 1.4 linux + * components as global . + */ +/** + * This needs to be moved to IxOsalOem.h file + */ +typedef struct IxOsalInfoType +{ + voidFnVoidPtr routine; + void *parameter; +} IxOsalInfoType; + +static IxOsalInfoType IxOsalInfo[NR_IRQS]; + +/* + * General interrupt handler + */ + +/* + * Private utility function for ixOsalIrqBind to translate IRQ vector number to + * IRQ name. + */ +PRIVATE const char* +ixOsalGetIrqNameByVector(UINT32 vector) +{ + if (unlikely (ARRAY_SIZE(irq_name) <= vector)) + { + return (invalid_irq_name); + } + + return (irq_name[vector]); +} + + +#ifdef IX_OSAL_OS_LINUX_VERSION_2_6 +static irqreturn_t +#else +static void +#endif +/* Definition of request_irq changed for 2.6.20 onwards */ +#ifdef IX_OSAL_OS_LINUX_VER_GT_2_6_20 +ixOsalOsIsrProxy (int irq, void *dev_id) +#else +ixOsalOsIsrProxy (int irq, void *dev_id, struct pt_regs *regs) +#endif +{ + IxOsalInfoType *isr_proxy_info = (IxOsalInfoType *) dev_id; + +#ifdef IX_OSAL_OS_LINUX_VERSION_2_6 + IX_OSAL_LOCAL_ENSURE(isr_proxy_info, + "ixOsalOsIsrProxy: Interrupt used before " + "ixOsalIrqBind was invoked (isr_proxy_info == NULL)\n", + IRQ_NONE); + + IX_OSAL_LOCAL_ENSURE(isr_proxy_info->routine, + "ixOsalOsIsrProxy: Interrupt used before " + "ixOsalIrqBind was invoked (isr_proxy_info->routine == NULL)\n", + IRQ_NONE); +#else + IX_OSAL_ENSURE_JUST_RETURN(isr_proxy_info, + "ixOsalOsIsrProxy: Interrupt used before " + "ixOsalIrqBind was invoked (isr_proxy_info == NULL)\n"); + + IX_OSAL_ENSURE_JUST_RETURN(isr_proxy_info->routine, + "ixOsalOsIsrProxy: Interrupt used before " + "ixOsalIrqBind was invoked (isr_proxy_info->routine == NULL)\n"); +#endif + + isr_proxy_info->routine (isr_proxy_info->parameter); + + +#ifdef IX_OSAL_OS_LINUX_VERSION_2_6 + return IRQ_HANDLED; +#endif + +} + +/* + * Interrupt handler for XScale PMU interrupts + * This handler saves the interrupted Program Counter (PC) + * into a global variable + */ + +/* Definition of request_irq changed for 2.6.20 onwards */ +#ifdef IX_OSAL_OS_LINUX_VER_GT_2_6_20 + +static irqreturn_t + +ixOsalOsIsrProxyWithPC (int irq, void *dev_id) +{ + + IX_OSAL_OEM_SET_INTERRUPTED_PC(get_irq_regs()); + + return ixOsalOsIsrProxy(irq, dev_id); + +} + +/* prior to 2.6.20 */ +#else + +#ifdef IX_OSAL_OS_LINUX_VERSION_2_6 +static irqreturn_t +#else +static void +#endif +ixOsalOsIsrProxyWithPC (int irq, void *dev_id, struct pt_regs *regs) +{ + /** + * The variable to me moved to IxOSalOem.h file + */ + IX_OSAL_OEM_SET_INTERRUPTED_PC(regs); + +#ifdef IX_OSAL_OS_LINUX_VERSION_2_6 + return ixOsalOsIsrProxy(irq, dev_id, regs); +#else + ixOsalOsIsrProxy(irq, dev_id, regs); +#endif + +} + +#endif /*endif prior to 2.6.20 */ + + + + + +/************************************** + * Irq services + *************************************/ + +PUBLIC IX_STATUS +ixOsalIrqBind (UINT32 vector, IxOsalVoidFnVoidPtr routine, void *parameter) +{ + + if (vector >= NR_IRQS) + { + ixOsalLog (IX_OSAL_LOG_LVL_ERROR, IX_OSAL_LOG_DEV_STDOUT, + "ixOsalIrqBind: Invalid Interrupt Number %d \n", vector, \ + 0, 0, 0, 0, 0); + return IX_FAIL; + } + + if (IxOsalInfo[vector].routine) + { + ixOsalLog (IX_OSAL_LOG_LVL_ERROR, + IX_OSAL_LOG_DEV_STDOUT, + /*"ixOsalIrqBind: NULL function routine. \n", 0, 0, 0, 0, 0, 0); */ + "ixOsalIrqBind: interrupt vector %d already binded. \n", + vector, 0, 0, 0, 0, 0); + return IX_FAIL; + } + + IxOsalInfo[vector].routine = routine; + IxOsalInfo[vector].parameter = parameter; + + /* + * The PMU interrupt handler is a special case in the sense + * that it needs to save the address of the interrupted PC + * In the case of the IA/XScale PMU interrupt, the ixOsalOsIsrProxyWithPC + * function is registered + */ + + if (vector == IX_OSAL_OEM_IRQ_PMU) + { + /* + * request_irq will enable interrupt automatically + * A non-zero return value suggest a failure. + */ + if (request_irq (vector, ixOsalOsIsrProxyWithPC, IRQF_SHARED, + ixOsalGetIrqNameByVector(vector), + &IxOsalInfo[vector])) + { + ixOsalLog (IX_OSAL_LOG_LVL_ERROR, IX_OSAL_LOG_DEV_STDOUT, + "ixOsalIrqBind: Fail to request irq. \n", + 0, 0, 0, 0, 0, 0); + return IX_FAIL; + } + } + else + { + /* + * request_irq will enable interrupt automatically + * A non-zero return value suggest a failure. + */ + if (request_irq (vector, ixOsalOsIsrProxy, IRQF_SHARED, + ixOsalGetIrqNameByVector(vector), &IxOsalInfo[vector])) + { + ixOsalLog (IX_OSAL_LOG_LVL_ERROR, IX_OSAL_LOG_DEV_STDOUT, + "ixOsalIrqBind: Fail to request irq. \n", + 0, 0, 0, 0, 0, 0); + return IX_FAIL; + } + } + return IX_SUCCESS; +} + +PUBLIC IX_STATUS +ixOsalIrqUnbind (UINT32 vector) +{ + if (!IxOsalInfo[vector].routine) + { + ixOsalLog (IX_OSAL_LOG_LVL_ERROR, + IX_OSAL_LOG_DEV_STDOUT, + "ixOsalIrqUnbind: NULL function routine. \n", 0, 0, 0, 0, 0, 0); + return IX_FAIL; + } + + free_irq (vector, &IxOsalInfo[vector]); + IxOsalInfo[vector].routine = NULL; + + return IX_SUCCESS; +} + +PUBLIC UINT32 +ixOsalIrqLock (void) +{ + unsigned long flags; +#ifdef IX_OSAL_OS_LINUX_VERSION_2_6 + /* local_irq_save() gives a compilation warning against s32 + * data type. */ + + local_save_flags(flags); + + local_irq_disable(); +#else + + save_flags (flags); + cli (); + +#endif /* LINUX_VERSION */ + + return (UINT32)flags; +} + +/* Enable interrupts and task scheduling, + * input parameter: irqEnable status returned + * by ixOsalIrqLock(). + */ +PUBLIC void +ixOsalIrqUnlock (UINT32 lockKey) +{ +#ifdef IX_OSAL_OS_LINUX_VERSION_2_6 + local_irq_restore((unsigned long)lockKey); +#else + restore_flags (lockKey); +#endif +} + +PUBLIC UINT32 +ixOsalIrqLevelSet (UINT32 level) +{ + /* + * Not supported + */ + ixOsalLog (IX_OSAL_LOG_LVL_MESSAGE, IX_OSAL_LOG_DEV_STDOUT, + "ixOsalIrqLevelSet: not supported \n", 0, 0, 0, 0, 0, 0); + return 0; +} + +PUBLIC void +ixOsalIrqEnable (UINT32 irqLevel) +{ + if (irqLevel < NR_IRQS) + { + enable_irq(irqLevel); + } + else + { + /* + * Not supported + */ + ixOsalLog (IX_OSAL_LOG_LVL_MESSAGE, IX_OSAL_LOG_DEV_STDOUT, + "ixOsalIrqEnable: IRQ %d not supported \n", irqLevel, + 0, 0, 0, 0, 0); + } +} + +PUBLIC void +ixOsalIrqDisable (UINT32 irqLevel) +{ + if (irqLevel < NR_IRQS) + { + disable_irq(irqLevel); + } + else + { + /* + * Not supported + */ + ixOsalLog (IX_OSAL_LOG_LVL_MESSAGE, IX_OSAL_LOG_DEV_STDOUT, + "ixOsalIrqDisable: IRQ %d not supported \n", irqLevel, + 0, 0, 0, 0, 0); + } +} + +void * +ixOsalMemAllocAtomic (UINT32 memsize) +{ + return (kmalloc (memsize, GFP_ATOMIC)); +} + diff --git a/Acceleration/library/icp_utils/OSAL/common/os/linux/src/modules/ddk/IxOsalOsDdkPci.c b/Acceleration/library/icp_utils/OSAL/common/os/linux/src/modules/ddk/IxOsalOsDdkPci.c new file mode 100644 index 0000000..1827315 --- /dev/null +++ b/Acceleration/library/icp_utils/OSAL/common/os/linux/src/modules/ddk/IxOsalOsDdkPci.c @@ -0,0 +1,222 @@ +/** + * @file IxOsalOsDdkPci.c (linux) + * + * @brief Implementation for PCI functionality. + * + * + * @par + * This file is provided under a dual BSD/GPLv2 license. When using or + * redistributing this file, you may do so under either license. + * + * GPL LICENSE SUMMARY + * + * Copyright(c) 2007,2008,2009 Intel Corporation. All rights reserved. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of version 2 of the GNU General Public License as + * published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA. + * The full GNU General Public License is included in this distribution + * in the file called LICENSE.GPL. + * + * Contact Information: + * Intel Corporation + * + * BSD LICENSE + * + * Copyright(c) 2007,2008,2009 Intel Corporation. All rights reserved. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Intel Corporation nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * + * + */ +#include "IxOsal.h" +#include <linux/pci.h> + + + +PUBLIC +IxOsalPciDev ixOsalPciDeviceFind(UINT32 vendor_id,UINT32 device_id,IxOsalPciDev pci_dev) +{ + struct pci_dev *pdev = (struct pci_dev *)pci_dev; + + pdev = pci_get_device(vendor_id, device_id, pdev); + + return (IxOsalPciDev)pdev; +} + +PUBLIC +INT32 ixOsalPciSlotAddress(IxOsalPciDev pci_dev,UINT32 *bus,UINT32 *slot,UINT32 *func) +{ + struct pci_dev *pdev = (struct pci_dev *)pci_dev; + + /* Ensure PCI device handle is not NULL */ + if(!pdev) { + ixOsalLog (IX_OSAL_LOG_LVL_ERROR, + IX_OSAL_LOG_DEV_STDOUT, + "ixOsalPciSlotAddress: Null PCI handle \n", 0, 0, 0, 0, 0, 0); + return IX_FAIL; + } + + if(bus) { + *bus = pdev->bus->number; + } + if(slot) { + *slot = PCI_SLOT(pdev->devfn); + } + if(func) { + *func = PCI_FUNC(pdev->devfn); + } + return IX_SUCCESS; +} + +PUBLIC +INT32 ixOsalPciConfigReadByte(IxOsalPciDev pci_dev,UINT32 offset,UINT8* val) +{ + struct pci_dev *pdev = (struct pci_dev *)pci_dev; + + /* Ensure PCI device handle is not NULL */ + if(!pdev) { + ixOsalLog (IX_OSAL_LOG_LVL_ERROR, + IX_OSAL_LOG_DEV_STDOUT, + "ixOsalPciConfigReadByte: Null PCI handle \n", 0, 0, 0, 0, 0, 0); + return IX_FAIL; + } + + return pci_read_config_byte(pdev, offset, val); +} + +PUBLIC +INT32 ixOsalPciConfigReadShort(IxOsalPciDev pci_dev,UINT32 offset,UINT16* val) +{ + struct pci_dev *pdev = (struct pci_dev *)pci_dev; + + /* Ensure PCI device handle is not NULL */ + if(!pdev) { + ixOsalLog (IX_OSAL_LOG_LVL_ERROR, + IX_OSAL_LOG_DEV_STDOUT, + "ixOsalPciConfigReadShort: Null PCI handle \n", 0, 0, 0, 0, 0, 0); + return IX_FAIL; + } + + return pci_read_config_word(pdev, offset, val); +} + +PUBLIC +INT32 ixOsalPciConfigReadLong(IxOsalPciDev pci_dev,UINT32 offset,UINT32* val) +{ + struct pci_dev *pdev = (struct pci_dev *)pci_dev; + + /* Ensure PCI device handle is not NULL */ + if(!pdev) { + ixOsalLog (IX_OSAL_LOG_LVL_ERROR, + IX_OSAL_LOG_DEV_STDOUT, + "ixOsalPciConfigReadLong: Null PCI handle \n", 0, 0, 0, 0, 0, 0); + return IX_FAIL; + } + + return pci_read_config_dword(pdev, offset, val); +} + +PUBLIC +INT32 ixOsalPciConfigWriteByte(IxOsalPciDev pci_dev,UINT32 offset,UINT8 val) +{ + struct pci_dev *pdev = (struct pci_dev *)pci_dev; + + /* Ensure PCI device handle is not NULL */ + if(!pdev) { + ixOsalLog (IX_OSAL_LOG_LVL_ERROR, + IX_OSAL_LOG_DEV_STDOUT, + "ixOsalPciConfigWriteByte: Null PCI handle \n", 0, 0, 0, 0, 0, 0); + return IX_FAIL; + } + + return pci_write_config_byte(pdev, offset, val); +} + +PUBLIC +INT32 ixOsalPciConfigWriteShort(IxOsalPciDev pci_dev,UINT32 offset,UINT16 val) +{ + struct pci_dev *pdev = (struct pci_dev *)pci_dev; + + /* Ensure PCI device handle is not NULL */ + if(!pdev) { + ixOsalLog (IX_OSAL_LOG_LVL_ERROR, + IX_OSAL_LOG_DEV_STDOUT, + "ixOsalPciConfigWriteShort: Null PCI handle \n", 0, 0, 0, 0, 0, 0); + return IX_FAIL; + } + + return pci_write_config_word(pdev, offset, val); +} + +PUBLIC +INT32 ixOsalPciConfigWriteLong(IxOsalPciDev pci_dev,UINT32 offset,UINT32 val) +{ + struct pci_dev *pdev = (struct pci_dev *)pci_dev; + + /* Ensure PCI device handle is not NULL */ + if(!pdev) { + ixOsalLog (IX_OSAL_LOG_LVL_ERROR, + IX_OSAL_LOG_DEV_STDOUT, + "ixOsalPciConfigWriteLong: Null PCI handle \n", 0, 0, 0, 0, 0, 0); + return IX_FAIL; + } + + return pci_write_config_dword(pdev, offset, val); +} + +PUBLIC +void ixOsalPciDeviceFree(IxOsalPciDev pci_dev) +{ + struct pci_dev *pdev = (struct pci_dev *)pci_dev; + + /* Ensure PCI device handle is not NULL */ + if(!pdev) { + ixOsalLog (IX_OSAL_LOG_LVL_ERROR, + IX_OSAL_LOG_DEV_STDOUT, + "ixOsalPciDeviceFree: Null PCI handle \n", 0, 0, 0, 0, 0, 0); + return; + } + + /* + * this takes care of decrementing reference count so that + * the kernel may free the space when the count becomes + * zero. + */ + pci_dev_put(pdev); +} diff --git a/Acceleration/library/icp_utils/OSAL/common/os/linux/src/modules/ddk/IxOsalOsDdkSymbols.c b/Acceleration/library/icp_utils/OSAL/common/os/linux/src/modules/ddk/IxOsalOsDdkSymbols.c new file mode 100644 index 0000000..389ef28 --- /dev/null +++ b/Acceleration/library/icp_utils/OSAL/common/os/linux/src/modules/ddk/IxOsalOsDdkSymbols.c @@ -0,0 +1,101 @@ +/* + * @file IxOsalOsSymbols.c + * @author Intel Corporation + * @date 25-10-2005 + * + * @brief description goes here + * + * @par + * This file is provided under a dual BSD/GPLv2 license. When using or + * redistributing this file, you may do so under either license. + * + * GPL LICENSE SUMMARY + * + * Copyright(c) 2007,2008,2009 Intel Corporation. All rights reserved. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of version 2 of the GNU General Public License as + * published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA. + * The full GNU General Public License is included in this distribution + * in the file called LICENSE.GPL. + * + * Contact Information: + * Intel Corporation + * + * BSD LICENSE + * + * Copyright(c) 2007,2008,2009 Intel Corporation. All rights reserved. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Intel Corporation nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * + * + */ +#ifdef OSAL_EXPORT_SYMBOLS + +#include "IxOsal.h" +#include <linux/module.h> + + +EXPORT_SYMBOL (ixOsalIrqBind); +EXPORT_SYMBOL (ixOsalIrqUnbind); +EXPORT_SYMBOL (ixOsalIrqLock); +EXPORT_SYMBOL (ixOsalIrqUnlock); +EXPORT_SYMBOL (ixOsalIrqLevelSet); +EXPORT_SYMBOL (ixOsalIrqEnable); +EXPORT_SYMBOL (ixOsalIrqDisable); + +EXPORT_SYMBOL (ixOsalCacheDmaMalloc); +EXPORT_SYMBOL (ixOsalCacheDmaFree); + +EXPORT_SYMBOL (ixOsalTimestampGet); +EXPORT_SYMBOL (ixOsalTimestampResolutionGet); +EXPORT_SYMBOL (ixOsalSysClockRateGet); + +#ifdef ENABLE_PCI +EXPORT_SYMBOL (ixOsalPciDeviceFind); +EXPORT_SYMBOL (ixOsalPciSlotAddress); +EXPORT_SYMBOL (ixOsalPciConfigReadByte); +EXPORT_SYMBOL (ixOsalPciConfigReadShort); +EXPORT_SYMBOL (ixOsalPciConfigReadLong); +EXPORT_SYMBOL (ixOsalPciConfigWriteByte); +EXPORT_SYMBOL (ixOsalPciConfigWriteShort); +EXPORT_SYMBOL (ixOsalPciConfigWriteLong); +EXPORT_SYMBOL (ixOsalPciDeviceFree); +#endif /* ENABLE_PCI */ + +#endif /* OSAL_EXPORT_SYMBOLS */ diff --git a/Acceleration/library/icp_utils/OSAL/common/os/linux/src/modules/ddk/component.mk b/Acceleration/library/icp_utils/OSAL/common/os/linux/src/modules/ddk/component.mk new file mode 100644 index 0000000..db5dd19 --- /dev/null +++ b/Acceleration/library/icp_utils/OSAL/common/os/linux/src/modules/ddk/component.mk @@ -0,0 +1,72 @@ +#@par +# This file is provided under a dual BSD/GPLv2 license. When using or +# redistributing this file, you may do so under either license. +# +# GPL LICENSE SUMMARY +# +# Copyright(c) 2007,2008,2009 Intel Corporation. All rights reserved. +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of version 2 of the GNU General Public License as +# published by the Free Software Foundation. +# +# This program is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA. +# The full GNU General Public License is included in this distribution +# in the file called LICENSE.GPL. +# +# Contact Information: +# Intel Corporation +# +# BSD LICENSE +# +# Copyright(c) 2007,2008,2009 Intel Corporation. All rights reserved. +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions +# are met: +# +# * Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# * Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in +# the documentation and/or other materials provided with the +# distribution. +# * Neither the name of Intel Corporation nor the names of its +# contributors may be used to endorse or promote products derived +# from this software without specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +# +# +# +# Place holder + +ddk_os_CFLAGS := + +ddk_os_OBJ := IxOsalOsDdkCacheMMU.o \ + IxOsalOsDdkClk.o \ + IxOsalOsDdkSymbols.o \ + IxOsalOsDdkIrq.o + +ifneq (,$(findstring ENABLE_PCI,$(CFLAGS))) +ddk_os_OBJ += IxOsalOsDdkPci.o +endif + diff --git a/Acceleration/library/icp_utils/OSAL/common/os/linux/src/modules/ioMem/IxOsalOsIoMem.c b/Acceleration/library/icp_utils/OSAL/common/os/linux/src/modules/ioMem/IxOsalOsIoMem.c new file mode 100644 index 0000000..624bfd0 --- /dev/null +++ b/Acceleration/library/icp_utils/OSAL/common/os/linux/src/modules/ioMem/IxOsalOsIoMem.c @@ -0,0 +1,108 @@ +/** + * @file IsOsalOsIoMem.c + * + * @brief Linux-specific IO/Mem implementation. + * + * + * @par + * This file is provided under a dual BSD/GPLv2 license. When using or + * redistributing this file, you may do so under either license. + * + * GPL LICENSE SUMMARY + * + * Copyright(c) 2007,2008,2009 Intel Corporation. All rights reserved. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of version 2 of the GNU General Public License as + * published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA. + * The full GNU General Public License is included in this distribution + * in the file called LICENSE.GPL. + * + * Contact Information: + * Intel Corporation + * + * BSD LICENSE + * + * Copyright(c) 2007,2008,2009 Intel Corporation. All rights reserved. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Intel Corporation nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * + * + */ + +#include "IxOsal.h" + +#include <linux/version.h> + +#ifdef IX_OSAL_OS_LINUX_VERSION_2_6 + +#include <asm/page.h> + +#endif + +#include <asm/io.h> +#include <linux/ioport.h> + +#include "IxOsal.h" + +/* Linux-specific map/unmap functions to be used with dynamic maps */ +PUBLIC void +ixOsalLinuxMemMap (IxOsalMemoryMap * map) +{ + map->virtualAddress = (UINT32) ioremap (map->physicalAddress, map->size); +} + +PUBLIC void +ixOsalLinuxMemUnmap (IxOsalMemoryMap * map) +{ + iounmap ((void *) map->virtualAddress); + map->virtualAddress = 0; +} + +PUBLIC +UINT32 ixOsalIoRemap (UINT32 physAddr, UINT32 size) +{ + return ((UINT32) ioremap (physAddr, size)); +} + +PUBLIC +void ixOsalIoUnmap (UINT32 virtAddr, UINT32 size) +{ + iounmap ((void *) virtAddr); +} + diff --git a/Acceleration/library/icp_utils/OSAL/common/os/linux/src/modules/ioMem/IxOsalOsIoMemSymbols.c b/Acceleration/library/icp_utils/OSAL/common/os/linux/src/modules/ioMem/IxOsalOsIoMemSymbols.c new file mode 100644 index 0000000..a02142a --- /dev/null +++ b/Acceleration/library/icp_utils/OSAL/common/os/linux/src/modules/ioMem/IxOsalOsIoMemSymbols.c @@ -0,0 +1,87 @@ +/* + * @file IxOsalOsIoMemSymbols.c + * @author Intel Corporation + * @date 25-08-2004 + * + * @brief description goes here + * + * @par + * This file is provided under a dual BSD/GPLv2 license. When using or + * redistributing this file, you may do so under either license. + * + * GPL LICENSE SUMMARY + * + * Copyright(c) 2007,2008,2009 Intel Corporation. All rights reserved. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of version 2 of the GNU General Public License as + * published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA. + * The full GNU General Public License is included in this distribution + * in the file called LICENSE.GPL. + * + * Contact Information: + * Intel Corporation + * + * BSD LICENSE + * + * Copyright(c) 2007,2008,2009 Intel Corporation. All rights reserved. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Intel Corporation nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * + * + */ +#ifdef OSAL_EXPORT_SYMBOLS + +#include "IxOsal.h" +#include <linux/module.h> + + +EXPORT_SYMBOL (ixOsalIoMemMap); +EXPORT_SYMBOL (ixOsalIoMemUnmap); +EXPORT_SYMBOL (ixOsalIoMemVirtToPhys); +EXPORT_SYMBOL (ixOsalIoMemPhysToVirt); +EXPORT_SYMBOL (ixOsalIoRemap); +EXPORT_SYMBOL (ixOsalIoUnmap); + +#ifdef IX_OSAL_MEM_MAP_GLUECODE + +EXPORT_SYMBOL (ixOsalGlueCodeMemoryMapInit); +EXPORT_SYMBOL (ixOsalGlueCodeMemoryMapUnInit); + +#endif /* IX_OSAL_MEM_MAP_GLUECODE */ +#endif /* XPORT_SYMBOLS */ diff --git a/Acceleration/library/icp_utils/OSAL/common/os/linux/src/modules/ioMem/component.mk b/Acceleration/library/icp_utils/OSAL/common/os/linux/src/modules/ioMem/component.mk new file mode 100644 index 0000000..4c585ed --- /dev/null +++ b/Acceleration/library/icp_utils/OSAL/common/os/linux/src/modules/ioMem/component.mk @@ -0,0 +1,66 @@ +# +# @par +# This file is provided under a dual BSD/GPLv2 license. When using or +# redistributing this file, you may do so under either license. +# +# GPL LICENSE SUMMARY +# +# Copyright(c) 2007,2008,2009 Intel Corporation. All rights reserved. +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of version 2 of the GNU General Public License as +# published by the Free Software Foundation. +# +# This program is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA. +# The full GNU General Public License is included in this distribution +# in the file called LICENSE.GPL. +# +# Contact Information: +# Intel Corporation +# +# BSD LICENSE +# +# Copyright(c) 2007,2008,2009 Intel Corporation. All rights reserved. +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions +# are met: +# +# * Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# * Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in +# the documentation and/or other materials provided with the +# distribution. +# * Neither the name of Intel Corporation nor the names of its +# contributors may be used to endorse or promote products derived +# from this software without specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +# +# +# + +ioMem_os_CFLAGS := + +ioMem_os_OBJ := IxOsalOsIoMem.o \ + IxOsalOsIoMemSymbols.o + |