1 /****************************************************************************** 2 * 3 * Copyright (C) 1999-2012 Broadcom Corporation 4 * 5 * Licensed under the Apache License, Version 2.0 (the "License"); 6 * you may not use this file except in compliance with the License. 7 * You may obtain a copy of the License at: 8 * 9 * http://www.apache.org/licenses/LICENSE-2.0 10 * 11 * Unless required by applicable law or agreed to in writing, software 12 * distributed under the License is distributed on an "AS IS" BASIS, 13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 * See the License for the specific language governing permissions and 15 * limitations under the License. 16 * 17 ******************************************************************************/ 18 #ifndef GKI_COMMON_H 19 #define GKI_COMMON_H 20 21 #include "gki.h" 22 23 /* Task States: (For OSRdyTbl) */ 24 #define TASK_DEAD 0 /* b0000 */ 25 #define TASK_READY 1 /* b0001 */ 26 27 /******************************************************************** 28 ** Internal Error codes 29 *********************************************************************/ 30 #define GKI_ERROR_BUF_CORRUPTED 0xFFFF 31 #define GKI_ERROR_NOT_BUF_OWNER 0xFFFE 32 #define GKI_ERROR_FREEBUF_BAD_QID 0xFFFD 33 #define GKI_ERROR_FREEBUF_BUF_LINKED 0xFFFC 34 #define GKI_ERROR_SEND_MSG_BAD_DEST 0xFFFB 35 #define GKI_ERROR_SEND_MSG_BUF_LINKED 0xFFFA 36 #define GKI_ERROR_ENQUEUE_BUF_LINKED 0xFFF9 37 #define GKI_ERROR_DELETE_POOL_BAD_QID 0xFFF8 38 #define GKI_ERROR_BUF_SIZE_TOOBIG 0xFFF7 39 #define GKI_ERROR_BUF_SIZE_ZERO 0xFFF6 40 41 /******************************************************************** 42 ** Misc constants 43 *********************************************************************/ 44 45 #define GKI_MAX_INT32 (0x7fffffffL) 46 47 /******************************************************************** 48 ** Buffer Management Data Structures 49 *********************************************************************/ 50 51 typedef struct _buffer_hdr { 52 struct _buffer_hdr* p_next; /* next buffer in the queue */ 53 uint8_t q_id; /* id of the queue */ 54 uint8_t task_id; /* task which allocated the buffer*/ 55 uint8_t status; /* FREE, UNLINKED or QUEUED */ 56 uint8_t Type; 57 #if defined(DYN_ALLOC) || defined(FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION) 58 uint16_t size; 59 #endif 60 } BUFFER_HDR_T; 61 62 typedef struct _free_queue { 63 BUFFER_HDR_T* p_first; /* first buffer in the queue */ 64 BUFFER_HDR_T* p_last; /* last buffer in the queue */ 65 uint16_t size; /* size of the buffers in the pool */ 66 uint16_t total; /* toatal number of buffers */ 67 uint16_t cur_cnt; /* number of buffers currently allocated */ 68 uint16_t max_cnt; /* maximum number of buffers allocated at any time */ 69 } FREE_QUEUE_T; 70 71 /* Buffer related defines */ 72 #define ALIGN_POOL(pl_size) \ 73 ((((pl_size) + 3) / sizeof(uint32_t)) * sizeof(uint32_t)) 74 /* Offset past header */ 75 #define BUFFER_HDR_SIZE (sizeof(BUFFER_HDR_T)) 76 /* Header + Magic Number */ 77 #define BUFFER_PADDING_SIZE (sizeof(BUFFER_HDR_T) + sizeof(uint32_t)) 78 /* pool size must allow for header */ 79 #define MAX_USER_BUF_SIZE ((uint16_t)0xffff - BUFFER_PADDING_SIZE) 80 #define MAGIC_NO 0xDDBADDBA 81 82 #define BUF_STATUS_FREE 0 83 #define BUF_STATUS_UNLINKED 1 84 #define BUF_STATUS_QUEUED 2 85 86 /* Put all GKI variables into one control block */ 87 typedef struct { 88 /* Task management variables */ 89 /* The stack and stack size are not used on Windows */ 90 91 #if (GKI_NUM_FIXED_BUF_POOLS > 0) 92 uint8_t bufpool0[(ALIGN_POOL(GKI_BUF0_SIZE) + BUFFER_PADDING_SIZE) * 93 GKI_BUF0_MAX]; 94 #endif 95 96 #if (GKI_NUM_FIXED_BUF_POOLS > 1) 97 uint8_t bufpool1[(ALIGN_POOL(GKI_BUF1_SIZE) + BUFFER_PADDING_SIZE) * 98 GKI_BUF1_MAX]; 99 #endif 100 101 #if (GKI_NUM_FIXED_BUF_POOLS > 2) 102 uint8_t bufpool2[(ALIGN_POOL(GKI_BUF2_SIZE) + BUFFER_PADDING_SIZE) * 103 GKI_BUF2_MAX]; 104 #endif 105 106 #if (GKI_NUM_FIXED_BUF_POOLS > 3) 107 uint8_t bufpool3[(ALIGN_POOL(GKI_BUF3_SIZE) + BUFFER_PADDING_SIZE) * 108 GKI_BUF3_MAX]; 109 #endif 110 111 #if (GKI_NUM_FIXED_BUF_POOLS > 4) 112 uint8_t bufpool4[(ALIGN_POOL(GKI_BUF4_SIZE) + BUFFER_PADDING_SIZE) * 113 GKI_BUF4_MAX]; 114 #endif 115 116 #if (GKI_NUM_FIXED_BUF_POOLS > 5) 117 uint8_t bufpool5[(ALIGN_POOL(GKI_BUF5_SIZE) + BUFFER_PADDING_SIZE) * 118 GKI_BUF5_MAX]; 119 #endif 120 121 #if (GKI_NUM_FIXED_BUF_POOLS > 6) 122 uint8_t bufpool6[(ALIGN_POOL(GKI_BUF6_SIZE) + BUFFER_PADDING_SIZE) * 123 GKI_BUF6_MAX]; 124 #endif 125 126 #if (GKI_NUM_FIXED_BUF_POOLS > 7) 127 uint8_t bufpool7[(ALIGN_POOL(GKI_BUF7_SIZE) + BUFFER_PADDING_SIZE) * 128 GKI_BUF7_MAX]; 129 #endif 130 131 #if (GKI_NUM_FIXED_BUF_POOLS > 8) 132 uint8_t bufpool8[(ALIGN_POOL(GKI_BUF8_SIZE) + BUFFER_PADDING_SIZE) * 133 GKI_BUF8_MAX]; 134 #endif 135 136 #if (GKI_NUM_FIXED_BUF_POOLS > 9) 137 uint8_t bufpool9[(ALIGN_POOL(GKI_BUF9_SIZE) + BUFFER_PADDING_SIZE) * 138 GKI_BUF9_MAX]; 139 #endif 140 141 #if (GKI_NUM_FIXED_BUF_POOLS > 10) 142 uint8_t bufpool10[(ALIGN_POOL(GKI_BUF10_SIZE) + BUFFER_PADDING_SIZE) * 143 GKI_BUF10_MAX]; 144 #endif 145 146 #if (GKI_NUM_FIXED_BUF_POOLS > 11) 147 uint8_t bufpool11[(ALIGN_POOL(GKI_BUF11_SIZE) + BUFFER_PADDING_SIZE) * 148 GKI_BUF11_MAX]; 149 #endif 150 151 #if (GKI_NUM_FIXED_BUF_POOLS > 12) 152 uint8_t bufpool12[(ALIGN_POOL(GKI_BUF12_SIZE) + BUFFER_PADDING_SIZE) * 153 GKI_BUF12_MAX]; 154 #endif 155 156 #if (GKI_NUM_FIXED_BUF_POOLS > 13) 157 uint8_t bufpool13[(ALIGN_POOL(GKI_BUF13_SIZE) + BUFFER_PADDING_SIZE) * 158 GKI_BUF13_MAX]; 159 #endif 160 161 #if (GKI_NUM_FIXED_BUF_POOLS > 14) 162 uint8_t bufpool14[(ALIGN_POOL(GKI_BUF14_SIZE) + BUFFER_PADDING_SIZE) * 163 GKI_BUF14_MAX]; 164 #endif 165 166 #if (GKI_NUM_FIXED_BUF_POOLS > 15) 167 uint8_t bufpool15[(ALIGN_POOL(GKI_BUF15_SIZE) + BUFFER_PADDING_SIZE) * 168 GKI_BUF15_MAX]; 169 #endif 170 171 uint8_t* OSStack[GKI_MAX_TASKS]; /* pointer to beginning of stack */ 172 uint16_t OSStackSize[GKI_MAX_TASKS]; /* stack size available to each task */ 173 174 int8_t* OSTName[GKI_MAX_TASKS]; /* name of the task */ 175 176 uint8_t OSRdyTbl[GKI_MAX_TASKS]; /* current state of the task */ 177 uint16_t OSWaitEvt[GKI_MAX_TASKS]; /* events that have to be processed by the 178 task */ 179 uint16_t OSWaitForEvt[GKI_MAX_TASKS]; /* events the task is waiting for*/ 180 181 uint32_t OSTicks; /* system ticks from start */ 182 uint32_t OSIdleCnt; /* idle counter */ 183 int16_t 184 OSDisableNesting; /* counter to keep track of interrupt disable nesting */ 185 int16_t OSLockNesting; /* counter to keep track of sched lock nesting */ 186 int16_t OSIntNesting; /* counter to keep track of interrupt nesting */ 187 188 /* Timer related variables */ 189 int32_t OSTicksTilExp; /* Number of ticks till next timer expires */ 190 #if (GKI_DELAY_STOP_SYS_TICK > 0) 191 uint32_t OSTicksTilStop; /* inactivity delay timer; OS Ticks till stopping 192 system tick */ 193 #endif 194 int32_t OSNumOrigTicks; /* Number of ticks between last timer expiration to 195 the next one */ 196 197 int32_t OSWaitTmr[GKI_MAX_TASKS]; /* ticks the task has to wait, for specific 198 events */ 199 200 /* Only take up space timers used in the system (GKI_NUM_TIMERS defined in 201 * target.h) */ 202 #if (GKI_NUM_TIMERS > 0) 203 int32_t OSTaskTmr0[GKI_MAX_TASKS]; 204 int32_t OSTaskTmr0R[GKI_MAX_TASKS]; 205 #endif 206 207 #if (GKI_NUM_TIMERS > 1) 208 int32_t OSTaskTmr1[GKI_MAX_TASKS]; 209 int32_t OSTaskTmr1R[GKI_MAX_TASKS]; 210 #endif 211 212 #if (GKI_NUM_TIMERS > 2) 213 int32_t OSTaskTmr2[GKI_MAX_TASKS]; 214 int32_t OSTaskTmr2R[GKI_MAX_TASKS]; 215 #endif 216 217 #if (GKI_NUM_TIMERS > 3) 218 int32_t OSTaskTmr3[GKI_MAX_TASKS]; 219 int32_t OSTaskTmr3R[GKI_MAX_TASKS]; 220 #endif 221 222 /* Buffer related variables */ 223 BUFFER_HDR_T* OSTaskQFirst[GKI_MAX_TASKS] 224 [NUM_TASK_MBOX]; /* array of pointers to the first 225 event in the task mailbox */ 226 BUFFER_HDR_T* OSTaskQLast[GKI_MAX_TASKS] 227 [NUM_TASK_MBOX]; /* array of pointers to the last 228 event in the task mailbox */ 229 230 /* Define the buffer pool management variables */ 231 FREE_QUEUE_T freeq[GKI_NUM_TOTAL_BUF_POOLS]; 232 233 uint16_t pool_buf_size[GKI_NUM_TOTAL_BUF_POOLS]; 234 uint16_t pool_max_count[GKI_NUM_TOTAL_BUF_POOLS]; 235 uint16_t pool_additions[GKI_NUM_TOTAL_BUF_POOLS]; 236 237 /* Define the buffer pool start addresses */ 238 uint8_t* pool_start[GKI_NUM_TOTAL_BUF_POOLS]; /* array of pointers to the 239 start of each buffer pool */ 240 uint8_t* pool_end[GKI_NUM_TOTAL_BUF_POOLS]; /* array of pointers to the end of 241 each buffer pool */ 242 uint16_t pool_size[GKI_NUM_TOTAL_BUF_POOLS]; /* actual size of the buffers in 243 a pool */ 244 245 /* Define the buffer pool access control variables */ 246 void* p_user_mempool; /* User O/S memory pool */ 247 uint16_t pool_access_mask; /* Bits are set if the corresponding buffer pool is 248 a restricted pool */ 249 uint8_t pool_list[GKI_NUM_TOTAL_BUF_POOLS]; /* buffer pools arranged in the 250 order of size */ 251 uint8_t curr_total_no_of_pools; /* number of fixed buf pools + current number 252 of dynamic pools */ 253 254 bool timer_nesting; /* flag to prevent timer interrupt nesting */ 255 256 /* Time queue arrays */ 257 TIMER_LIST_Q* timer_queues[GKI_MAX_TIMER_QUEUES]; 258 /* System tick callback */ 259 SYSTEM_TICK_CBACK* p_tick_cb; 260 bool system_tick_running; /* TRUE if system tick is running. Valid only if 261 p_tick_cb is not NULL */ 262 263 } tGKI_COM_CB; 264 265 /* Internal GKI function prototypes */ 266 extern bool gki_chk_buf_damage(void*); 267 extern bool gki_chk_buf_owner(void*); 268 extern void gki_buffer_init(void); 269 extern void gki_timers_init(void); 270 extern void gki_adjust_timer_count(int32_t); 271 272 #endif 273