bcm_ces_sal.c (7353B)
1 /* 2 * 3 * This license is set out in https://raw.githubusercontent.com/Broadcom-Network-Switching-Software/OpenBCM/master/Legal/LICENSE file. 4 * 5 * Copyright 2007-2019 Broadcom Inc. All rights reserved. 6 * 7 * bcm_ces_sal.c 8 */ 9 10 #include <shared/bsl.h> 11 12 #include <soc/cm.h> 13 #include <soc/defs.h> 14 #include <soc/drv.h> 15 #include <sal/core/alloc.h> 16 #include <sal/core/sync.h> 17 #include <sal/core/libc.h> 18 19 #include "utils/List.h" 20 21 #include <bcm_ces_sal.h> 22 23 #ifdef BCM_CES_SDK 24 /*BCM SDK*/ 25 /*Bcm sal*/ 26 #if defined(SOC_CES_DEBUG) 27 #define CES_SAL_DEBUG(x) LOG_VERBOSE(BSL_LS_SOC_COMMON, x) 28 #else 29 #define CES_SAL_DEBUG(x) 30 #endif 31 32 /*Sync*/ 33 AgResult agos_create_bi_semaphore(AgosBiSemaphoreInfo *sem, AG_CHAR *p_name) 34 { 35 sal_sem_t sal_sem; 36 37 CES_SAL_DEBUG(("%s: %s\n", FUNCTION_NAME(), p_name)); 38 39 if ((sal_sem = sal_sem_create(p_name, sal_sem_BINARY, 1)) == NULL) 40 return AG_E_FAIL; 41 42 sem->sal_sem = sal_sem; 43 CES_SAL_DEBUG(("%s: %s %p\n", FUNCTION_NAME(), p_name, (void*)sal_sem)); 44 45 return AG_S_OK; 46 } 47 48 AgResult agos_get_bi_semaphore(AgosBiSemaphoreInfo *sem, AG_U32 n_timeout) 49 { 50 int timeout; 51 52 if (n_timeout == AGOS_WAIT_FOR_EVER) 53 timeout = sal_sem_FOREVER; 54 else 55 timeout = n_timeout * MILLISECOND_USEC; 56 57 CES_SAL_DEBUG(("%u-%s: %p timeout:%d\n", (uint32)((sal_time_usecs())/1000), FUNCTION_NAME(), (void*)sem->sal_sem, timeout)); 58 59 if (sal_sem_take(sem->sal_sem, timeout) != 0) 60 return AG_E_FAIL; 61 62 return AG_S_OK; 63 } 64 65 AgResult agos_give_bi_semaphore(AgosBiSemaphoreInfo *sem) 66 { 67 CES_SAL_DEBUG(("%u-%s: %p\n", (uint32)((sal_time_usecs())/1000), FUNCTION_NAME(), (void*)sem->sal_sem)); 68 if (sal_sem_give(sem->sal_sem) != 0) 69 return AG_E_FAIL; 70 71 return AG_S_OK; 72 } 73 74 AgResult agos_delete_bi_semaphore(AgosBiSemaphoreInfo *sem) 75 { 76 CES_SAL_DEBUG(("%s: %p\n", FUNCTION_NAME(), (void*)sem->sal_sem)); 77 sal_sem_destroy(sem->sal_sem); 78 return AG_S_OK; 79 } 80 81 82 /*Time*/ 83 void agos_periodic_timer_callback_shell(AgosTimerInfo *timer, AG_U32 *timer_val, void (*p_callback_function)(AG_U32), void *arg, AG_U8 *name) { 84 /* 85 * Reschedule timer 86 */ 87 agos_set_timer(timer, 88 name, 89 p_callback_function, 90 (AG_U32)arg, 91 (AG_U32)timer_val, 92 TRUE); 93 /* 94 * Call func 95 */ 96 p_callback_function((AG_U32)arg); 97 } 98 99 AgResult agos_set_timer(AgosTimerInfo *x_timer, 100 AG_U8 *p_name, 101 void (*p_callback_function)(AG_U32), 102 AG_U32 n_callpack_parameter, 103 AG_U32 n_timer_value, 104 AG_BOOL b_periodic) 105 { 106 if (b_periodic) 107 { 108 /* CES_SAL_DEBUG(("%s: Periodic:%lumS\n", FUNCTION_NAME(), n_timer_value));*/ 109 if (sal_dpc_time(n_timer_value * MILLISECOND_USEC, 110 (sal_dpc_fn_t)agos_periodic_timer_callback_shell, 111 (void*)x_timer, 112 (void*)n_timer_value, 113 p_callback_function, 114 (void*)n_callpack_parameter, 115 (void*)p_name) != 0) { 116 return AG_E_FAIL; 117 } 118 } 119 else 120 CES_SAL_DEBUG(("%s - NOT YET IMPLEMENTED\n", FUNCTION_NAME())); 121 122 return AG_S_OK; 123 } 124 125 AgResult agos_cancel_timer(AgosTimerInfo *x_timer) 126 { 127 sal_dpc_cancel(x_timer); 128 return AG_S_OK; 129 } 130 131 void agos_wake_after(AG_U32 after) 132 { 133 sal_usleep(after * MILLISECOND_USEC); 134 return; 135 } 136 137 AG_U32 ag_get_micro_timestamp(void) 138 { 139 return (AG_U32)sal_time_usecs(); 140 } 141 142 int ag_wait_micro_sec_delay(AG_U32 delay) 143 { 144 sal_usleep(delay); 145 return 0; 146 } 147 148 149 150 /*Events*/ 151 AgResult agos_create_event_group(AgosEventInfo *x_event_group, AG_U8 *p_name) 152 { 153 CES_SAL_DEBUG(("%s: %s\n", FUNCTION_NAME(), p_name)); 154 sal_strcpy(x_event_group->name, (AG_S8*)p_name); 155 x_event_group->events = 0; 156 return AG_S_OK; 157 } 158 159 AgResult agos_set_event(AgosEventInfo *x_event_group, AG_U32 n_flags) 160 { 161 CES_SAL_DEBUG(("%s: flags:0x%08lx\n", FUNCTION_NAME(), n_flags)); 162 x_event_group->events |= n_flags; 163 return AG_S_OK; 164 } 165 166 AgResult agos_wait_on_event(AgosEventInfo *x_event_group, 167 AG_U32 n_requested_flags, 168 AgosEventWaitOperation e_operation, 169 AG_U32 *n_retrieved_flags, 170 AG_U32 n_timeout) 171 { 172 AG_U32 timeleft = n_timeout; 173 CES_SAL_DEBUG(("%s: req_flags:0x%08lx\n", FUNCTION_NAME(), n_requested_flags)); 174 #define AGOS_WAIT_ON_EVENT_POLL_PERIOD 1000 175 176 /* 177 * Make sure that the count is aligned with the tick 178 */ 179 timeleft -= (timeleft % AGOS_WAIT_ON_EVENT_POLL_PERIOD); 180 181 while(1) 182 { 183 if ((((x_event_group->events & n_requested_flags) == n_requested_flags) && 184 (e_operation == AGOS_EVENTS_AND || e_operation == AGOS_EVENTS_AND_CLEARED)) || 185 ((x_event_group->events & n_requested_flags) && 186 (e_operation == AGOS_EVENTS_OR || e_operation == AGOS_EVENTS_OR_CLEARED))) 187 { 188 /* LOG_CLI((BSL_META("%s: Event received\n"), FUNCTION_NAME())); */ 189 190 *n_retrieved_flags = x_event_group->events; 191 192 if (e_operation == AGOS_EVENTS_OR_CLEARED || 193 e_operation == AGOS_EVENTS_AND_CLEARED) 194 x_event_group->events &= ~n_requested_flags; 195 196 return AG_S_OK; 197 } 198 199 sal_usleep(MILLISECOND_USEC * AGOS_WAIT_ON_EVENT_POLL_PERIOD); 200 201 if (n_timeout != 0xffffffff) 202 { 203 timeleft -= AGOS_WAIT_ON_EVENT_POLL_PERIOD; 204 if (timeleft == 0) 205 { 206 *n_retrieved_flags = 0; 207 return AG_E_TIMEOUT; 208 } 209 } 210 } 211 212 return AG_S_OK; 213 } 214 215 AgResult agos_delete_event_group(AgosEventInfo *x_event_group) 216 { 217 return AG_S_OK; 218 } 219 220 AgResult agos_create_task(AgosTaskInfo *x_task_info, 221 AG_U8 *p_name, 222 void (*p_task_entry_function)(AG_U32, void*), 223 AG_U32 n_param, 224 void *p_stack, 225 AG_U32 n_stack_size, 226 AG_U32 n_priority, 227 AG_U32 slice, 228 AG_U32 preempt, 229 AG_U32 start) 230 { 231 CES_SAL_DEBUG(("%s: name:%s priority:%lu\n", FUNCTION_NAME(), p_name, n_priority)); 232 if ((x_task_info->thread = sal_thread_create((AG_S8*)p_name, n_stack_size, (n_priority + 100), (void (*)(void*))p_task_entry_function, (void*)n_param)) == SAL_THREAD_ERROR) 233 { 234 return AG_E_FAIL; 235 } 236 237 return AG_S_OK; 238 } 239 240 241 242 243 /*Log*/ 244 void x_sw_logger_app_info(void){}; 245 void ag_swlog_print_by_level(void){}; 246 247 248 249 250 251 252 /* 253 * Memory 254 */ 255 AgResult agos_calloc(int n_size, void *ptr) 256 { 257 *((void**)ptr) = sal_alloc(n_size, "agos_calloc"); 258 return AG_S_OK; 259 } 260 261 262 AgResult agos_malloc(int n_size, void *ptr) 263 { 264 *((void**)ptr) = sal_alloc(n_size, "agos_malloc"); 265 return AG_S_OK; 266 } 267 268 AgResult agos_free(void *ptr) 269 { 270 sal_free(ptr); 271 return AG_S_OK; 272 } 273 274 void *ag_memset(void *to, AG_S32 c, size_t size) 275 { 276 char *d = (char *)to; 277 size_t count = 0; 278 279 while (count < size) 280 { 281 *d = (char)c; 282 d++; 283 count++; 284 } 285 286 return to; 287 } 288 289 void *ag_memcpy_asm(void * dest, const void * src, size_t len) 290 { 291 memcpy(dest, src, len); 292 return dest; 293 } 294 295 void agos_plat_malloc(void) 296 { 297 /* Currently not used */ 298 CES_SAL_DEBUG(("%s - NOT YET IMPLEMENTED\n", FUNCTION_NAME())); 299 return; 300 } 301 void agos_plat_free(void) 302 { 303 /* Currently not used */ 304 CES_SAL_DEBUG(("%s - NOT YET IMPLEMENTED\n", FUNCTION_NAME())); 305 return; 306 } 307 308 void *memset_word(void *dest, AG_U32 n, size_t size) 309 { 310 AG_U32 *address = (AG_U32*)dest; 311 size_t count = 0; 312 313 /*CES_SAL_DEBUG(("%s: address:%p len:%d data:0x%08lx\n", FUNCTION_NAME(), address, size, n));*/ 314 315 while (count < size) 316 { 317 *address = n; 318 address++; 319 count += 4; /* Size is in bytes so increment by four */ 320 } 321 322 return dest; 323 } 324 325 void memset_qword(void) 326 { 327 CES_SAL_DEBUG(("%s - NOT YET IMPLEMENTED\n", FUNCTION_NAME())); 328 } 329 330 331 #endif /* BCM_CES_SDK */ 332 333 334 335