| /* |
| <:copyright-BRCM:2016:DUAL/GPL:standard |
| |
| Broadcom Proprietary and Confidential.(c) 2016 Broadcom |
| All Rights Reserved |
| |
| Unless you and Broadcom execute a separate written software license |
| agreement governing use of this software, this software is licensed |
| to you under the terms of the GNU General Public License version 2 |
| (the "GPL"), available at http://www.broadcom.com/licenses/GPLv2.php, |
| with the following added to such license: |
| |
| As a special exception, the copyright holders of this software give |
| you permission to link this software with independent modules, and |
| to copy and distribute the resulting executable under terms of your |
| choice, provided that you also meet, for each linked independent |
| module, the terms and conditions of the license of that module. |
| An independent module is a module which is not derived from this |
| software. The special exception does not apply to any modifications |
| of the software. |
| |
| Not withstanding the above, under no circumstances may you combine |
| this software in any way with any other Broadcom software provided |
| under a license other than the GPL, without Broadcom's express prior |
| written consent. |
| |
| :> |
| */ |
| |
| /* |
| * bcmos_system.h |
| * Maple System Services |
| * posix port: simulation |
| */ |
| |
| #ifndef BCMOS_SYSTEM_H_ |
| #define BCMOS_SYSTEM_H_ |
| |
| #include <stdlib.h> |
| #include <string.h> |
| #include <strings.h> |
| #include <stdio.h> |
| #include <assert.h> |
| #include <stdint.h> |
| #include <ctype.h> |
| #include <stddef.h> |
| #include <unistd.h> |
| #include <errno.h> |
| #include <pthread.h> |
| #include <semaphore.h> |
| #include <signal.h> |
| #include <execinfo.h> |
| #include <limits.h> |
| #include <stdarg.h> |
| #include <sys/select.h> |
| #include <sys/time.h> |
| #include <sys/types.h> |
| #include <sys/socket.h> |
| #include <netinet/in.h> |
| |
| /* posix port has only been tested in linux user space */ |
| #define LINUX_USER_SPACE |
| |
| /* Re-define GNU typeof as ISO __typeof__ */ |
| #define typeof __typeof__ |
| |
| void _bcmos_backtrace(void); |
| |
| #define BUG_ON_PRINT(condition, fmt, args...) \ |
| do \ |
| { \ |
| if (condition) \ |
| { \ |
| BCMOS_TRACE_ERR(fmt, ##args); \ |
| assert(!(condition)); \ |
| } \ |
| } while (0) |
| |
| #define BUG_ON(condition) BUG_ON_PRINT((condition), "BUG in %s %d!\n", __FUNCTION__, __LINE__) |
| #define BUG() BUG_ON(1) |
| #define BUG_UNLESS(condition) BUG_ON(!(condition)) |
| |
| /* If 'err' is not BCM_ERR_OK, there is a bug in the software - halt and print the specified message */ |
| #define BUG_ON_ERROR(err, fmt, args...) \ |
| BUG_ON_PRINT((err) != BCM_ERR_OK, \ |
| "%s:%d: err=%s (%d): " fmt, \ |
| __FUNCTION__, __LINE__, bcmos_strerror(err), (err), ##args) |
| |
| /* Specify here which system functions are inlined */ |
| |
| #define BCMOS_FASTLOCK_INLINE |
| /* #define BCMOS_SEM_WAIT_INLINE */ |
| #define BCMOS_SEM_POST_INLINE |
| #define BCMOS_TRACE_PRINTF |
| /* #define BCMOS_BYTE_POOL_ALLOC_FREE_INLINE */ |
| /* #define BCMOS_MALLOC_FREE_INLINE */ |
| /* #define BCMOS_CALLOC_INLINE */ |
| #define BCMOS_DMA_ALLOC_FREE_INLINE |
| #define BCMOS_VIRT_TO_PHYS_INLINE |
| #define BCMOS_CACHE_INLINE |
| |
| #include "bcmos_common.h" |
| |
| /* posix-specific stuff */ |
| |
| /* |
| * Synchronization |
| */ |
| |
| /** \addtogroup system_mutex |
| * @{ |
| */ |
| |
| /** Mutex control block */ |
| struct bcmos_mutex |
| { |
| pthread_mutex_t m; /**< pthread mutex */ |
| pthread_mutexattr_t attr; /**< pthread mutex attribute */ |
| }; |
| |
| /** @} system_mutex */ |
| |
| /** \addtogroup system_fastlock |
| * @{ |
| */ |
| |
| /** Fast lock control block */ |
| struct bcmos_fastlock |
| { |
| bcmos_mutex m; |
| }; |
| |
| /** Fastlock initializer. Can be used instead of calling bcmos_fastlock_init() */ |
| #define BCMOS_FASTLOCK_INITIALIZER { { PTHREAD_MUTEX_INITIALIZER } } |
| |
| /* Init fastlock */ |
| static inline void bcmos_fastlock_init(bcmos_fastlock *lock, uint32_t flags) |
| { |
| bcmos_mutex_create(&lock->m, 0, NULL); |
| } |
| |
| /* Take fast lock */ |
| static inline long bcmos_fastlock_lock(bcmos_fastlock *lock) |
| { |
| bcmos_mutex_lock(&lock->m); |
| return 0; |
| } |
| |
| /* Release fast lock */ |
| static inline void bcmos_fastlock_unlock(bcmos_fastlock *lock, long flags) |
| { |
| bcmos_mutex_unlock(&lock->m); |
| } |
| |
| /** @} system_fastlock */ |
| |
| /** \addtogroup system_sem |
| * @{ |
| */ |
| |
| /** Semaphore control block */ |
| struct bcmos_sem |
| { |
| sem_t s; /**< pthread semaphore */ |
| }; |
| |
| /* Increment semaphore counter */ |
| static inline void bcmos_sem_post(bcmos_sem *sem) |
| { |
| sem_post(&sem->s); |
| } |
| |
| /** @} system_sem */ |
| |
| /** \addtogroup system_timer |
| * @{ |
| */ |
| |
| /** System timer */ |
| struct bcmos_sys_timer |
| { |
| timer_t t; /**< librt timer */ |
| bcmos_sys_timer_handler handler; /**< Timer handler */ |
| void *data; /**< Parameter to be passed to the handler */ |
| }; |
| |
| /** @} system_timer */ |
| |
| /** \addtogroup system_task |
| * @{ |
| */ |
| |
| /** OS-specific task control block extension */ |
| typedef struct bcmos_sys_task |
| { |
| pthread_t t; /**< posix pthread */ |
| } bcmos_sys_task; |
| |
| /** @} system_task */ |
| |
| /** \addtogroup byte_pool |
| * @{ |
| */ |
| |
| /** Memory pool control block */ |
| struct bcmos_byte_pool |
| { |
| bcmos_byte_pool_parm parm; /**< Pool parameters */ |
| uint32_t allocated; /**< Number of bytes allocated */ |
| #ifdef BCMOS_MEM_DEBUG |
| uint32_t magic; /**< magic number */ |
| #define BCMOS_BYTE_POOL_VALID (('b'<<24) | ('y' << 16) | ('p' << 8) | 'o') |
| #define BCMOS_BYTE_POOL_DELETED (('b'<<24) | ('y' << 16) | ('p' << 8) | '~') |
| #endif |
| }; |
| |
| /** @} */ |
| |
| /* Print */ |
| #define bcmos_sys_vprintf(fmt, args) vprintf(fmt, args) |
| |
| /* A few macros to enable linux kernel space compilation */ |
| #define EXPORT_SYMBOL(_sym) |
| |
| /* |
| * The following low-level functions are mostly for simulation |
| */ |
| |
| /* |
| * DMA-able memory allocation |
| */ |
| |
| /* Allocate DMA-able memory */ |
| static inline void *bcmos_dma_alloc(uint8_t device, uint32_t size) |
| { |
| return bcmos_alloc(size); |
| } |
| |
| /* Release DMA-able memory */ |
| static inline void bcmos_dma_free(uint8_t device, void *ptr) |
| { |
| bcmos_free(ptr); |
| } |
| |
| /* Convert virtual address to physical address */ |
| static inline unsigned long bcmos_virt_to_phys(void *va) |
| { |
| return (unsigned long)(va); |
| } |
| |
| /* Invalidate address area in data cache. Dirty cache lines content is discarded. */ |
| static inline void bcmos_dcache_inv(void *start, uint32_t size) |
| { |
| } |
| |
| /* Flush address area in data cache. Dirty cache lines are committed to memory. */ |
| static inline void bcmos_dcache_flush(void *start, uint32_t size) |
| { |
| } |
| |
| /* write barrier */ |
| static inline void bcmos_barrier(void) |
| { |
| } |
| |
| static inline void bcm_pci_write32(volatile uint32_t *address, uint32_t value) |
| { |
| } |
| |
| static inline uint32_t bcm_pci_read32(const volatile uint32_t *address) |
| { |
| return -1; |
| } |
| |
| /* Check in-irq status */ |
| static inline bcmos_bool is_irq_mode(void) |
| { |
| return BCMOS_FALSE; |
| } |
| |
| /* Check if interrupts are disabled */ |
| static inline bcmos_bool is_irq_disabled(void) |
| { |
| return BCMOS_FALSE; |
| } |
| |
| /* |
| * Internal (to OS abstraction) functions for messaging over domain and UDP sockets |
| */ |
| #ifdef BCMOS_MSG_QUEUE_DOMAIN_SOCKET |
| bcmos_errno bcmos_sys_msg_queue_domain_socket_open(bcmos_msg_queue *queue); |
| #endif |
| |
| #ifdef BCMOS_MSG_QUEUE_UDP_SOCKET |
| bcmos_errno bcmos_sys_msg_queue_udp_socket_open(bcmos_msg_queue *queue); |
| #endif |
| |
| /* 2nd part of OS-independent declarations */ |
| #include "bcmos_common2.h" |
| |
| #endif /* BCMOS_SYSTEM_H_ */ |