enum esif_rc EsifActMgrInit () { enum esif_rc rc = ESIF_OK; u8 i = 0; ESIF_TRACE_DEBUG("%s: Init Action Manager (ACTMGR)", ESIF_FUNC); g_actMgr.fActTypes = esif_link_list_create(); if (NULL == g_actMgr.fActTypes) { return ESIF_E_NO_MEMORY; } g_actMgr.GetActType = GetActionType; g_actMgr.GetActFromName = GetActionFromName; g_actMgr.AddActType = AddAction; g_actMgr.RemoveActType = RemoveAction; /* Add static Kernel Entries */ for (i = 0; g_kernelActions[i].fType; i++) g_actMgr.AddActType(&g_actMgr, &g_kernelActions[i]); /* Action manager must be initialized */ EsifActInit(); return rc; }
eEsifError EsifActMgrInit() { eEsifError rc = ESIF_OK; ESIF_TRACE_ENTRY_INFO(); esif_ccb_lock_init(&g_actMgr.fLock); g_actMgr.fActTypes = esif_link_list_create(); if (NULL == g_actMgr.fActTypes) { rc = ESIF_E_NO_MEMORY; goto exit; } g_actMgr.GetActType = GetActionType; g_actMgr.GetActFromName = GetActionFromName; g_actMgr.AddActType = AddAction; g_actMgr.RemoveActType = RemoveAction; /* Action manager must be initialized */ EsifActInit(); exit: ESIF_TRACE_EXIT_INFO_W_STATUS(rc); return rc; }
eEsifError EsifEventMgr_Init(void) { eEsifError rc = ESIF_OK; UInt8 i; ESIF_TRACE_ENTRY_INFO(); esif_ccb_lock_init(&g_EsifEventMgr.listLock); for (i = 0; i < NUM_EVENT_LISTS; i++) { g_EsifEventMgr.observerLists[i] = esif_link_list_create(); if (NULL == g_EsifEventMgr.observerLists[i]) { rc = ESIF_E_NO_MEMORY; goto exit; } } g_EsifEventMgr.eventQueuePtr = esif_queue_create(ESIF_UF_EVENT_QUEUE_SIZE, ESIF_UF_EVENT_QUEUE_NAME, ESIF_UF_EVENT_QUEUE_TIMEOUT); g_EsifEventMgr.garbageList = esif_link_list_create(); if ((NULL == g_EsifEventMgr.eventQueuePtr) || (NULL == g_EsifEventMgr.garbageList)) { rc = ESIF_E_NO_MEMORY; goto exit; } rc = esif_ccb_thread_create(&g_EsifEventMgr.eventQueueThread, EsifEventMgr_EventQueueThread, NULL); if (rc != ESIF_OK) { goto exit; } exit: if (rc != ESIF_OK) { EsifEventMgr_Exit(); } ESIF_TRACE_EXIT_INFO_W_STATUS(rc); return rc; }
/* Every init should have a matching kill */ enum esif_rc esif_ccb_timer_init( esif_ccb_timer_t *timer_ptr, esif_ccb_timer_cb function_ptr, /* Callback when timer fires */ void *context_ptr /* Callback context if any */ ) { enum esif_rc rc = ESIF_OK; struct esif_tmrm_item *tmrm_item_ptr = NULL; if ((NULL == timer_ptr) || (NULL == function_ptr)) { rc = ESIF_E_PARAMETER_IS_NULL; goto exit; } rc = esif_ccb_tmrm_is_ready(); if (rc != ESIF_OK) goto exit; rc = esif_ccb_tmrm_create_tmrm_item(function_ptr, context_ptr, &tmrm_item_ptr); if (rc != ESIF_OK) goto exit; /* Place the handle into the timer being initialized*/ timer_ptr->timer_handle = tmrm_item_ptr->timer_handle; /* * We create the manager list dynamically so that we don't have to call * init/exit functions and can destroy the linked list */ esif_ccb_write_lock(&g_tmrm.mgr_lock); if (NULL == g_tmrm.timer_list_ptr) { g_tmrm.timer_list_ptr = esif_link_list_create(); if(NULL == g_tmrm.timer_list_ptr) { rc = ESIF_E_NO_MEMORY; goto lock_exit; } } rc = esif_link_list_add_at_back(g_tmrm.timer_list_ptr, tmrm_item_ptr); lock_exit: esif_ccb_write_unlock(&g_tmrm.mgr_lock); exit: if (rc != ESIF_OK) esif_ccb_tmrm_destroy_tmrm_item(tmrm_item_ptr); return rc; }
static enum esif_rc esif_ccb_tmrm_create_tmrm_item( const esif_ccb_timer_cb function_ptr, /* Callback when timer fires */ void *context_ptr, /* Callback context if any */ struct esif_tmrm_item **tmrm_item_ptr ) { enum esif_rc rc = ESIF_E_NO_MEMORY; struct esif_tmrm_item *new_item_ptr = NULL; struct esif_timer_obj *timer_obj_ptr = NULL; esif_ccb_timer_handle_t handle = 0; ESIF_ASSERT(tmrm_item_ptr != NULL); ESIF_ASSERT(function_ptr != NULL); new_item_ptr = (struct esif_tmrm_item *) esif_ccb_malloc(sizeof(*new_item_ptr)); if (NULL == new_item_ptr) goto exit; new_item_ptr->destroy_list_ptr = esif_link_list_create(); if (NULL == new_item_ptr->destroy_list_ptr) goto exit; rc = esif_ccb_timer_obj_create(function_ptr, context_ptr, &timer_obj_ptr); if (rc != ESIF_OK) goto exit; new_item_ptr->timer_obj_ptr = timer_obj_ptr; rc = esif_ccb_tmrm_get_next_handle(&handle); if (rc != ESIF_OK) goto exit; new_item_ptr->timer_handle = handle; *tmrm_item_ptr = new_item_ptr; exit: if (rc != ESIF_OK) esif_ccb_tmrm_destroy_tmrm_item(new_item_ptr); return rc; }
/* Create Hash Table */ struct esif_ht * esif_ht_create( u32 size ) { u32 index = 0; struct esif_ht *new_ht_ptr = NULL; new_ht_ptr = (struct esif_ht *) esif_ccb_mempool_zalloc(ESIF_MEMPOOL_TYPE_HASH2); if (NULL == new_ht_ptr) { ESIF_TRACE_ERROR("Cannot allocate mem for hash table\n"); ESIF_ASSERT(ESIF_FALSE); goto exit; } new_ht_ptr->size = size; new_ht_ptr->table = (struct esif_link_list **) esif_ccb_malloc(sizeof(*new_ht_ptr->table) * size); if (new_ht_ptr->table == NULL) { esif_ccb_mempool_free(ESIF_MEMPOOL_TYPE_HASH2, new_ht_ptr); new_ht_ptr = NULL; goto exit; } for (index = 0; index < size; ++index) { ESIF_TRACE_DYN_VERB("Create linked list %d\n", index); new_ht_ptr->table[index] = esif_link_list_create(); if (new_ht_ptr->table[index] == NULL) { ESIF_TRACE_DYN_VERB("Creation failed\n"); esif_ht_destroy(new_ht_ptr, NULL); new_ht_ptr = NULL; goto exit; } } ESIF_TRACE_DYN_VERB("Have hash table %p\n", new_ht_ptr); exit: return new_ht_ptr; }
eEsifError EsifActMgrInit() { eEsifError rc = ESIF_OK; ESIF_TRACE_ENTRY_INFO(); esif_ccb_lock_init(&g_actMgr.mgrLock); g_actMgr.actions = esif_link_list_create(); if (NULL == g_actMgr.actions) { rc = ESIF_E_NO_MEMORY; goto exit; } /* Action manager must be initialized before this call */ EsifActMgr_InitActions(); exit: ESIF_TRACE_EXIT_INFO_W_STATUS(rc); return rc; }
static eEsifError EsifActMgr_CreatePossActList_Locked() { eEsifError rc = ESIF_OK; struct esif_ccb_file curFile = {0}; esif_ccb_file_enum_t fileIter = {0}; char libPath[ESIF_LIBPATH_LEN]; char *dotPtr = NULL; EsifActMgrEntryPtr newPossPtr = NULL; EsifString filePattern = ESIF_UPE_FILE_PREFIX "*" ESIF_LIB_EXT; g_actMgr.possibleActions = esif_link_list_create(); if (NULL == g_actMgr.possibleActions) { rc = ESIF_E_NO_MEMORY; goto exit; } /* Get the loadable action directory path */ esif_build_path(libPath, sizeof(libPath), ESIF_PATHTYPE_DLL, NULL, NULL); fileIter = esif_ccb_file_enum_first(libPath, filePattern, &curFile); if (INVALID_HANDLE_VALUE == fileIter) { goto exit; } do { newPossPtr = esif_ccb_malloc(sizeof(*newPossPtr)); if(NULL == newPossPtr) { break; } dotPtr = esif_ccb_strchr(curFile.filename, '.'); if (dotPtr != NULL) { *dotPtr = '\0'; newPossPtr->libName = (esif_string)esif_ccb_strdup(curFile.filename); esif_link_list_add_at_back(g_actMgr.possibleActions, (void *)newPossPtr); } } while (esif_ccb_file_enum_next(fileIter, filePattern, &curFile)); esif_ccb_file_enum_close(fileIter); exit: return rc; }
eEsifError esif_fpc_load( EsifFpcPtr fpcPtr, EsifDspPtr dspPtr ) { eEsifError rc = ESIF_OK; EsifFpcDomainPtr domainPtr; EsifFpcPrimitivePtr primitivePtr; EsifFpcAlgorithmPtr algoPtr; EsifFpcEventPtr eventPtr; unsigned long offset = 0; UInt8 *basePtr = (UInt8 *)fpcPtr; UInt32 numPrim = 0; UInt32 i; UInt32 j; if ((fpcPtr == NULL) || (dspPtr == NULL)) { ESIF_TRACE_ERROR("The fpc pointer or dsp pointer is NULL\n"); rc = ESIF_E_PARAMETER_IS_NULL; goto exit; } if (fpcPtr->number_of_domains < 1) { ESIF_TRACE_WARN("No domain error, number_of_domain = %d (less than 1)\n", fpcPtr->number_of_domains); rc = ESIF_E_PARAMETER_IS_NULL; goto exit; } dspPtr->domain_count = &fpcPtr->number_of_domains; /* Allocate Hash and List. Hash Size 31 Is Hard-Coded And Chosen By DSP Compiler */ dspPtr->ht_ptr = esif_ht_create(ESIF_DSP_HASHTABLE_SIZE); dspPtr->algo_ptr = esif_link_list_create(); dspPtr->domain_ptr = esif_link_list_create(); dspPtr->cap_ptr = esif_link_list_create(); dspPtr->evt_ptr = esif_link_list_create(); if (!dspPtr->ht_ptr || !dspPtr->algo_ptr || !dspPtr->domain_ptr || !dspPtr->cap_ptr || !dspPtr->evt_ptr) { ESIF_TRACE_ERROR("Fail to allocate linked list or hash table\n"); rc = ESIF_E_NO_MEMORY; goto exit; } ESIF_TRACE_DEBUG("<fpc @ %p> FPC name '%s' ver %x,%x desc '%s' size %u num_domains %d num_algorithms %d num_events %d", fpcPtr, fpcPtr->header.name, fpcPtr->header.ver_major, fpcPtr->header.ver_minor, fpcPtr->header.description, fpcPtr->size, fpcPtr->number_of_domains, fpcPtr->number_of_algorithms, fpcPtr->number_of_events); /* First Domain, Ok To Have Zero Primitive Of A Domain */ domainPtr = (EsifFpcDomainPtr)(fpcPtr + 1); for (i = 0; i < fpcPtr->number_of_domains; i++) { offset = (unsigned long)((UInt8 *)domainPtr - basePtr); ESIF_TRACE_DEBUG("<%04lu> Domain[%d] name %s size %d num_of_primitives %d " "num_of_capabilites %u (0x%x)", offset, i, domainPtr->descriptor.name, domainPtr->size, domainPtr->number_of_primitives, domainPtr->capability_for_domain.number_of_capability_flags, domainPtr->capability_for_domain.capability_flags); /* Insert Domain Into Linked List */ rc = dspPtr->insert_domain(dspPtr, domainPtr); if (ESIF_OK != rc) { ESIF_TRACE_ERROR("Fail to insert domain #%d\n", i); goto exit; } /* Capability */ for (j = 0; j < domainPtr->capability_for_domain.number_of_capability_flags; j++) { offset = (unsigned long)(((UInt8 *)&domainPtr->capability_for_domain) - basePtr); ESIF_TRACE_DEBUG("<%04lu> Capability[%d] 0x%x", offset, j, domainPtr->capability_for_domain.capability_mask[j]); } /* First Primtive */ primitivePtr = (EsifFpcPrimitivePtr)(domainPtr + 1); for (j = 0; j < domainPtr->number_of_primitives; j++, numPrim++) { offset = (unsigned long)(((UInt8 *)primitivePtr) - basePtr); ESIF_TRACE_DEBUG("<%04lu> Primitive[%03d]: size %3d tuple_id <%03u %03u %03u> " "operation %u(%s) req_type %u(%s) res_type %u(%s) num_actions %u", offset, j, primitivePtr->size, primitivePtr->tuple.id, primitivePtr->tuple.domain, primitivePtr->tuple.instance, primitivePtr->operation, esif_primitive_opcode_str(primitivePtr->operation), primitivePtr->request_type, esif_data_type_str(primitivePtr->request_type), primitivePtr->result_type, esif_data_type_str(primitivePtr->result_type), primitivePtr->num_actions); /* Insert Primitive Into Hash */ rc = dspPtr->insert_primitive(dspPtr, primitivePtr); if (ESIF_OK != rc) { ESIF_TRACE_ERROR("Fail to insert primitive (id = %d)\n", primitivePtr->tuple.id); goto exit; } /* Next Primitive */ primitivePtr = (EsifFpcPrimitivePtr)((UInt8 *)primitivePtr + primitivePtr->size); } /* Next Domain */ domainPtr = (EsifFpcDomainPtr)((UInt8 *)domainPtr + domainPtr->size); } /* First Algorithm (Laid After The Last Domain) */ algoPtr = (EsifFpcAlgorithmPtr)domainPtr; for (i = 0; i < fpcPtr->number_of_algorithms; i++) { offset = (unsigned long)((UInt8 *)algoPtr - basePtr); ESIF_TRACE_DEBUG("<%04lu> Algorithm[%03d]: action_type %u(%s) temp_xform %u " "tempC1 %u percent_xform %u size %u", offset, i, algoPtr->action_type, esif_action_type_str(algoPtr->action_type), algoPtr->temp_xform, algoPtr->tempC1, algoPtr->percent_xform, algoPtr->size); /* Insert Algorithm Into Linked List */ rc = dspPtr->insert_algorithm(dspPtr, algoPtr); if (ESIF_OK != rc) { ESIF_TRACE_ERROR("Fail to insert algorithm - %s\n", esif_action_type_str(algoPtr->action_type)); goto exit; } /* Next Algorithm */ algoPtr = (EsifFpcAlgorithmPtr)(algoPtr + 1); } /* First Event (Laid After The Last Algorithm) */ eventPtr = (EsifFpcEventPtr)algoPtr; for (i = 0; i < fpcPtr->number_of_events; i++) { offset = (unsigned long)((UInt8 *)eventPtr - basePtr); ESIF_TRACE_DEBUG("<%04lu> Event [%03d] type %s(%d)\n", offset, i, esif_event_type_str(eventPtr->esif_event), eventPtr->esif_event); /* Insert Algorithm Into Linked List */ rc = dspPtr->insert_event(dspPtr, eventPtr); if (ESIF_OK != rc) { ESIF_TRACE_ERROR("Fail to insert event - %s\n", esif_event_type_str(eventPtr->esif_event)); goto exit; } /* Next Event */ eventPtr = (EsifFpcEventPtr)(eventPtr + 1); } exit: if (fpcPtr != NULL) { ESIF_TRACE_DEBUG("%u domains, %u primitives and %u algorithms %u events inserted! status %s", fpcPtr->number_of_domains, numPrim, fpcPtr->number_of_algorithms, fpcPtr->number_of_events, esif_rc_str(rc)); } return rc; }