Shad Ansari | 2f7f9be | 2017-06-07 13:34:53 -0700 | [diff] [blame^] | 1 | /* |
| 2 | <:copyright-BRCM:2016:DUAL/GPL:standard |
| 3 | |
| 4 | Broadcom Proprietary and Confidential.(c) 2016 Broadcom |
| 5 | All Rights Reserved |
| 6 | |
| 7 | Unless you and Broadcom execute a separate written software license |
| 8 | agreement governing use of this software, this software is licensed |
| 9 | to you under the terms of the GNU General Public License version 2 |
| 10 | (the "GPL"), available at http://www.broadcom.com/licenses/GPLv2.php, |
| 11 | with the following added to such license: |
| 12 | |
| 13 | As a special exception, the copyright holders of this software give |
| 14 | you permission to link this software with independent modules, and |
| 15 | to copy and distribute the resulting executable under terms of your |
| 16 | choice, provided that you also meet, for each linked independent |
| 17 | module, the terms and conditions of the license of that module. |
| 18 | An independent module is a module which is not derived from this |
| 19 | software. The special exception does not apply to any modifications |
| 20 | of the software. |
| 21 | |
| 22 | Not withstanding the above, under no circumstances may you combine |
| 23 | this software in any way with any other Broadcom software provided |
| 24 | under a license other than the GPL, without Broadcom's express prior |
| 25 | written consent. |
| 26 | |
| 27 | :> |
| 28 | */ |
| 29 | |
| 30 | /* |
| 31 | * bcmos_system.h |
| 32 | * Maple System Services |
| 33 | * vxWorks 5.5 port |
| 34 | */ |
| 35 | |
| 36 | #ifndef BCMOS_SYSTEM_H_ |
| 37 | #define BCMOS_SYSTEM_H_ |
| 38 | |
| 39 | #define BCMOS_IRQ_SINGLE 0 |
| 40 | #define BCMOS_IRQ_SHARED 1 |
| 41 | |
| 42 | #define inline __inline |
| 43 | |
| 44 | |
| 45 | #include <stdio.h> |
| 46 | #include <stdlib.h> |
| 47 | #include <string.h> |
| 48 | #include <assert.h> |
| 49 | #include <ctype.h> |
| 50 | #include <time.h> |
| 51 | #include <limits.h> |
| 52 | #include <unistd.h> |
| 53 | #include <sockLib.h> |
| 54 | #include <sys/socket.h> |
| 55 | #include <netinet/in.h> |
| 56 | |
| 57 | /* Re-define GNU typeof as ISO __typeof__ */ |
| 58 | #define typeof __typeof__ |
| 59 | |
| 60 | /* Specify here which system functions are inlined */ |
| 61 | |
| 62 | /* #define BCMOS_FASTLOCK_INLINE */ |
| 63 | /* #define BCMOS_SEM_WAIT_INLINE */ |
| 64 | /* #define BCMOS_SEM_POST_INLINE */ |
| 65 | /* #define BCMOS_USLEEP_INLINE */ |
| 66 | #define BCMOS_TRACE_PRINTF |
| 67 | #define BCMOS_BYTE_POOL_ALLOC_FREE_INLINE |
| 68 | /* #define BCMOS_MALLOC_FREE_INLINE */ |
| 69 | /* #define BCMOS_CALLOC_INLINE */ |
| 70 | /* if Host cpu is MIPS cpu,enable this macro */ |
| 71 | /* Host cpu type will be determined during compile*/ |
| 72 | //#define HOST_CPU_IS_MIPS |
| 73 | //#define HOST_CPU_IS_PPC |
| 74 | /*if the Memory allocated by cacheDmaMalloc/acheDmaFree() is non-cached memory,enable this macro*/ |
| 75 | #define NON_CACHED_MEMORY_CREATED_BY_CACHEDMAMALLOC |
| 76 | /* Uncommentthe following line if h/w supports DMA cache coherency */ |
| 77 | /* #define BCMOS_DMA_CACHE_COHERENCY */ |
| 78 | |
| 79 | static inline void bcmos_int_disable(int irq) |
| 80 | {} |
| 81 | |
| 82 | void _bcmos_backtrace(void); |
| 83 | |
| 84 | #define BUG_ON(_f) do { if (_f) { _bcmos_backtrace(); } } while (0) |
| 85 | #define BUG() BUG_ON(1) |
| 86 | #define BUG_UNLESS(_f) BUG_ON(!(_f)) |
| 87 | |
| 88 | /** Boolean */ |
| 89 | #define BCMOS_BOOLEAN |
| 90 | typedef enum |
| 91 | { |
| 92 | BCMOS_FALSE = 0, |
| 93 | BCMOS_TRUE = 1, |
| 94 | } bcmos_bool; |
| 95 | |
| 96 | #include "bcmos_common.h" |
| 97 | |
| 98 | #define ffs(n) ffsLsb(n) |
| 99 | |
| 100 | /** Semaphore control block */ |
| 101 | struct bcmos_sem |
| 102 | { |
| 103 | uint32_t s; |
| 104 | }; |
| 105 | |
| 106 | |
| 107 | /** Mutex control block */ |
| 108 | struct bcmos_mutex |
| 109 | { |
| 110 | uint32_t m; |
| 111 | }; |
| 112 | |
| 113 | /** Fast lock control block */ |
| 114 | struct bcmos_fastlock |
| 115 | { |
| 116 | uint32_t l; |
| 117 | }; |
| 118 | |
| 119 | /** Fastlock initializer. Can be used instead of calling bcmos_fastlock_init() */ |
| 120 | #define BCMOS_FASTLOCK_INITIALIZER { 0 } |
| 121 | |
| 122 | /** OS-specific task control block extension */ |
| 123 | typedef struct bcmos_sys_task |
| 124 | { |
| 125 | uint32_t t; /**< vxWorks task ID */ |
| 126 | } bcmos_sys_task; |
| 127 | |
| 128 | |
| 129 | /** System timer */ |
| 130 | struct bcmos_sys_timer |
| 131 | { |
| 132 | uint32_t t; /**< VxW timer */ |
| 133 | bcmos_sys_timer_handler handler; /**< Timer handler */ |
| 134 | void *data; /**< Parameter to be passed to the handler */ |
| 135 | }; |
| 136 | |
| 137 | /** Byte memory pool control block */ |
| 138 | struct bcmos_byte_pool |
| 139 | { |
| 140 | bcmos_byte_pool_parm parm; /**< Pool parameters */ |
| 141 | uint32_t allocated; /**< Number of bytes allocated */ |
| 142 | #ifdef BCMOS_MEM_DEBUG |
| 143 | uint32_t magic; /**< magic number */ |
| 144 | #define BCMOS_BYTE_POOL_VALID (('b'<<24) | ('y' << 16) | ('p' << 8) | 'o') |
| 145 | #define BCMOS_BYTE_POOL_DELETED (('b'<<24) | ('y' << 16) | ('p' << 8) | '~') |
| 146 | #endif |
| 147 | }; |
| 148 | |
| 149 | #define bcmos_sys_vprintf(fmt, args) vprintf(fmt, args) |
| 150 | |
| 151 | #define EXPORT_SYMBOL(_sym) |
| 152 | |
| 153 | /* 2nd part of OS-independent declarations */ |
| 154 | #include "bcmos_common2.h" |
| 155 | |
| 156 | void bcm_pci_write32(volatile uint32_t *address, uint32_t value); |
| 157 | uint32_t bcm_pci_read32(const volatile uint32_t *address); |
| 158 | |
| 159 | |
| 160 | /*todo must check validity that the string is numeric, sscanf cannot detect errors, |
| 161 | * if not valid, put (*tailptr) in the first non valid char in string, |
| 162 | if valid, point tailptr in the last char in string (*tailptr=string+strlen(string))*/ |
| 163 | #define strtoull(string,tailptr,base) ({\ |
| 164 | unsigned long long int __a;\ |
| 165 | *(tailptr)=(char*)((string)+strlen(string));\ |
| 166 | sscanf(string, base == 10 ? "%llu" : "%llx", &__a );\ |
| 167 | __a;\ |
| 168 | }) |
| 169 | #define strtoll(string,tailptr,base) ({\ |
| 170 | long long int __a;\ |
| 171 | *(tailptr)=(char*)((string)+strlen(string));\ |
| 172 | sscanf(string,"%lld", &__a );\ |
| 173 | __a;\ |
| 174 | }) |
| 175 | |
| 176 | #define snprintf(s1,n,s2,args...) sprintf(s1, s2,## args) |
| 177 | #define vsnprintf(s1,n,s2,args...) vsprintf(s1, s2,## args) |
| 178 | |
| 179 | |
| 180 | int ffsLsb (UINT32 i); |
| 181 | int ffsll(long long int i); |
| 182 | |
| 183 | |
| 184 | #endif /* BCMOS_SYSTEM_H_ */ |