void EsifAppMgrExit() { u8 i = 0; EsifAppPtr a_app_ptr = NULL; ESIF_TRACE_ENTRY_INFO(); EsifEventMgr_UnregisterEventByType(ESIF_EVENT_PARTICIPANT_SUSPEND, EVENT_MGR_MATCH_ANY, EVENT_MGR_DOMAIN_D0, EsifAppMgr_EventCallback, NULL); EsifEventMgr_UnregisterEventByType(ESIF_EVENT_PARTICIPANT_RESUME, EVENT_MGR_MATCH_ANY, EVENT_MGR_DOMAIN_D0, EsifAppMgr_EventCallback, NULL); EsifAppExit(); ESIF_TRACE_DEBUG("Exit Action Manager (APPMGR)"); esif_ccb_read_lock(&g_appMgr.fLock); for (i = 0; i < ESIF_MAX_APPS; i++) { a_app_ptr = &g_appMgr.fEntries[i]; // Attempt to gracefully shutdown App before forcing library unload if (a_app_ptr->fLibNamePtr != NULL) { EsifAppStop(a_app_ptr); } if (a_app_ptr->fLibNamePtr != NULL) { esif_ccb_library_unload(a_app_ptr->fLibHandle); esif_ccb_free(a_app_ptr->fLibNamePtr); esif_ccb_memset(a_app_ptr, 0, sizeof(*a_app_ptr)); } } esif_ccb_read_unlock(&g_appMgr.fLock); esif_ccb_lock_uninit(&g_appMgr.fLock); ESIF_TRACE_EXIT_INFO(); }
// IPC Auto Connect eEsifError ipc_autoconnect(UInt32 max_retries) { eEsifError rc = ESIF_OK; UInt32 connect_retries = 0; ESIF_TRACE_ENTRY_INFO(); if (g_ipc_handle != ESIF_INVALID_HANDLE) { return rc; } // Attempt to connect to LF indefinitely until ESIF exits (unless the LF version is unsupported) while (!g_quit) { rc = ipc_connect(); if (rc == ESIF_OK || rc == ESIF_E_NOT_SUPPORTED) { break; } if (max_retries > 0 && ++connect_retries >= max_retries) { ESIF_TRACE_ERROR("Unable to do an IPC connect\n"); break; } esif_ccb_sleep(1); } ESIF_TRACE_EXIT_INFO_W_STATUS(rc); return rc; }
void EsifEventMgr_Exit(void) { UInt8 i; EsifLinkListPtr listPtr = NULL; ESIF_TRACE_ENTRY_INFO(); /* Remove all listeners */ esif_ccb_write_lock(&g_EsifEventMgr.listLock); for (i = 0; i < NUM_EVENT_LISTS; i++) { listPtr = g_EsifEventMgr.observerLists[i]; esif_link_list_free_data_and_destroy(listPtr, EsifEventMgr_LLEntryDestroyCallback); g_EsifEventMgr.observerLists[i] = NULL; } esif_ccb_write_unlock(&g_EsifEventMgr.listLock); /* Destroy the event thread */ /* Event thread should already be destroyed in the disable func. Destroy the queue */ esif_queue_destroy(g_EsifEventMgr.eventQueuePtr, EsifEventMgr_QueueDestroyCallback); g_EsifEventMgr.eventQueuePtr = NULL; /* Destroy the garbage list */ esif_ccb_write_lock(&g_EsifEventMgr.listLock); esif_link_list_free_data_and_destroy(g_EsifEventMgr.garbageList, EsifEventMgr_LLEntryDestroyCallback); g_EsifEventMgr.garbageList = NULL; esif_ccb_write_unlock(&g_EsifEventMgr.listLock); esif_ccb_lock_uninit(&g_EsifEventMgr.listLock); ESIF_TRACE_EXIT_INFO(); }
void EsifActMgrExit() { u8 i = 0; EsifActPtr a_act_ptr = NULL; ESIF_TRACE_ENTRY_INFO(); /* Call before destroying action manager */ EsifActExit(); if (NULL != g_actMgr.fActTypes) { esif_link_list_destroy(g_actMgr.fActTypes); g_actMgr.fActTypes = NULL; //set to null so that it will be caught if mid-execution } esif_ccb_read_lock(&g_actMgr.fLock); for (i = 0; i < ESIF_MAX_ACTIONS; i++) { a_act_ptr = &g_actMgr.fEnrtries[i]; esif_ccb_free(a_act_ptr->fLibNamePtr); esif_ccb_library_unload(a_act_ptr->fLibHandle); esif_ccb_memset(a_act_ptr, 0, sizeof(*a_act_ptr)); } esif_ccb_read_unlock(&g_actMgr.fLock); esif_ccb_lock_uninit(&g_actMgr.fLock); ESIF_TRACE_EXIT_INFO(); }
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; }
void EsifDspMgrExit(void) { ESIF_TRACE_ENTRY_INFO(); esif_dsp_table_destroy(); esif_ccb_lock_uninit(&g_dm.lock); ESIF_TRACE_EXIT_INFO(); }
static void *ESIF_CALLCONV esif_web_worker_thread(void *ptr) { UNREFERENCED_PARAMETER(ptr); ESIF_TRACE_ENTRY_INFO(); esif_ws_init(); ESIF_TRACE_EXIT_INFO(); return 0; }
eEsifError esif_uf_init() { eEsifError rc = ESIF_OK; ESIF_TRACE_ENTRY_INFO(); #ifdef ESIF_ATTR_SHELL_LOCK esif_ccb_mutex_init(&g_shellLock); #endif ESIF_TRACE_DEBUG("Init Upper Framework (UF)"); esif_ccb_mempool_init_tracking(); // Get Home directory CMD_OUT("Home: %s\n", esif_pathlist_get(ESIF_PATHTYPE_HOME)); /* OS Agnostic */ EsifLogMgrInit(); esif_link_list_init(); esif_ht_init(); esif_ccb_tmrm_init(); EsifCfgMgrInit(); EsifEventMgr_Init(); EsifCnjMgrInit(); EsifUpPm_Init(); EsifDspMgrInit(); EsifActMgrInit(); /* Web Server optionally started by shell scripts in esif_init */ /* OS Specific */ rc = esif_uf_os_init(); if (ESIF_OK != rc) { goto exit; } /* Start App Manager after all dependent components started * This does not actually start any apps. */ EsifAppMgrInit(); #ifdef ESIF_FEAT_OPT_ACTION_SYSFS SysfsRegisterParticipants(); #else ipc_connect(); sync_lf_participants(); #endif exit: ESIF_TRACE_EXIT_INFO_W_STATUS(rc); return rc; }
void EsifEventMgr_Disable(void) { ESIF_TRACE_ENTRY_INFO(); /* Release and destroy the event thread */ g_EsifEventMgr.eventQueueExitFlag = ESIF_TRUE; esif_queue_signal_event(g_EsifEventMgr.eventQueuePtr); esif_ccb_thread_join(&g_EsifEventMgr.eventQueueThread); ESIF_TRACE_EXIT_INFO(); }
// IPC Disconnect void ipc_disconnect() { ESIF_TRACE_ENTRY_INFO(); if (g_ipc_handle != ESIF_INVALID_HANDLE) { esif_ipc_disconnect(g_ipc_handle); g_ipc_handle = ESIF_INVALID_HANDLE; ESIF_TRACE_DEBUG("ESIF IPC Kernel Device Closed\n"); } ESIF_TRACE_EXIT_INFO(); }
eEsifError EsifDspMgrInit(void) { eEsifError rc = ESIF_OK; ESIF_TRACE_ENTRY_INFO(); esif_ccb_lock_init(&g_dm.lock); rc = esif_dsp_table_build(); ESIF_TRACE_EXIT_INFO_W_STATUS(rc); return rc; }
eEsifError EsifAppStart(EsifAppPtr appPtr) { ESIF_TRACE_ENTRY_INFO(); eEsifError rc = ESIF_OK; GetIfaceFuncPtr iface_func_ptr = NULL; esif_string iface_func_name = GET_APPLICATION_INTERFACE_FUNCTION; char libPath[ESIF_LIBPATH_LEN]; ESIF_TRACE_DEBUG("name=%s\n", appPtr->fLibNamePtr); esif_build_path(libPath, ESIF_LIBPATH_LEN, ESIF_PATHTYPE_DLL, appPtr->fLibNamePtr, ESIF_LIB_EXT); appPtr->fLibHandle = esif_ccb_library_load(libPath); if (NULL == appPtr->fLibHandle || NULL == appPtr->fLibHandle->handle) { rc = esif_ccb_library_error(appPtr->fLibHandle); ESIF_TRACE_DEBUG("esif_ccb_library_load() %s failed [%s (%d)]: %s\n", libPath, esif_rc_str(rc), rc, esif_ccb_library_errormsg(appPtr->fLibHandle)); goto exit; } ESIF_TRACE_DEBUG("esif_ccb_library_load() %s completed.\n", libPath); iface_func_ptr = (GetIfaceFuncPtr)esif_ccb_library_get_func(appPtr->fLibHandle, (char*)iface_func_name); if (NULL == iface_func_ptr) { rc = esif_ccb_library_error(appPtr->fLibHandle); ESIF_TRACE_DEBUG("esif_ccb_library_get_func() %s failed [%s (%d)]: %s\n", iface_func_name, esif_rc_str(rc), rc, esif_ccb_library_errormsg(appPtr->fLibHandle)); goto exit; } ESIF_TRACE_DEBUG("esif_ccb_library_get_func() %s completed.\n", iface_func_name); rc = AppCreate(appPtr, iface_func_ptr); if (ESIF_OK != rc) { ESIF_TRACE_DEBUG("AppCreate failed.\n"); goto exit; } ESIF_TRACE_DEBUG("AppCreate completed.\n"); rc = EsifApp_RegisterParticipantsWithApp(appPtr); if (ESIF_OK != rc) { ESIF_TRACE_DEBUG("EsifApp_RegisterParticipantsWithApp failed.\n"); goto exit; } ESIF_TRACE_DEBUG("EsifApp_RegisterParticipantsWithApp completed.\n"); exit: if (ESIF_OK != rc) { esif_ccb_library_unload(appPtr->fLibHandle); appPtr->fLibHandle = NULL; } ESIF_TRACE_EXIT_INFO_W_STATUS(rc); return rc; }
// Event Worker Thread // Processes ESIF Events void *esif_event_worker_thread(void *ptr) { int rc = 0; fd_set rfds = {0}; struct timeval tv = {0}; UNREFERENCED_PARAMETER(ptr); ESIF_TRACE_ENTRY_INFO(); CMD_OUT("Start ESIF Event Thread\n"); // Connect To Kernel IPC with infinite timeout ipc_autoconnect(0); // Run Until Told To Quit while (!g_quit) { #ifdef ESIF_FEAT_OPT_ACTION_SYSFS esif_ccb_sleep_msec(250); #else if (g_ipc_handle == ESIF_INVALID_HANDLE) { break; } if (rc > 0) { EsifEvent_GetAndSignalIpcEvent(); } FD_ZERO(&rfds); FD_SET((esif_ccb_socket_t)g_ipc_handle, &rfds); tv.tv_sec = 0; tv.tv_usec = 50000; /* 50 msec */ #ifdef ESIF_ATTR_OS_LINUX rc = select(g_ipc_handle + 1, &rfds, NULL, NULL, &tv); #endif #ifdef ESIF_ATTR_OS_WINDOWS // Windows does not support select/poll so we simulate here esif_ccb_sleep_msec(50); rc = 1; #endif #endif } if (g_ipc_handle != ESIF_INVALID_HANDLE) { ipc_disconnect(); } ESIF_TRACE_EXIT_INFO(); return 0; }
// IPC Connect eEsifError ipc_connect() { eEsifError rc = ESIF_OK; int check_kernel_version = ESIF_TRUE; ESIF_TRACE_ENTRY_INFO(); // Exit if IPC already connected if (g_ipc_handle != ESIF_INVALID_HANDLE) { return ESIF_OK; } // Connect to LF g_ipc_handle = esif_ipc_connect((char *)SESSION_ID); if (g_ipc_handle == ESIF_INVALID_HANDLE) { ESIF_TRACE_WARN("ESIF LF is not available\n"); rc = ESIF_E_NO_LOWER_FRAMEWORK; } else { char *outbuf = esif_ccb_malloc(OUT_BUF_LEN); char *kern_str = (outbuf != NULL ? esif_cmd_info(outbuf) : NULL); ESIF_TRACE_DEBUG("ESIF IPC Kernel Device Opened\n"); if (NULL != kern_str) { // Extract just the Kernel LF Version from the result string extract_kernel_version(kern_str, OUT_BUF_LEN); // Bypass Kernel Version check for DEBUG builds #if defined(ESIF_ATTR_DEBUG) check_kernel_version = ESIF_FALSE; #endif // Validate Kernel LF version is compatible with UF version if (check_kernel_version == ESIF_FALSE || esif_ccb_strcmp(kern_str, ESIF_VERSION) == 0) { ESIF_TRACE_INFO("Kernel Version: %s\n", kern_str); esif_ccb_sprintf(sizeof(g_esif_kernel_version), g_esif_kernel_version, "%s", kern_str); } else { ESIF_TRACE_ERROR("ESIF_LF Version (%s) Incompatible with ESIF_UF Version (%s)\n", kern_str, ESIF_VERSION); ipc_disconnect(); rc = ESIF_E_NOT_SUPPORTED; } } esif_ccb_free(outbuf); } ESIF_TRACE_EXIT_INFO_W_STATUS(rc); return rc; }
void EsifLogMgrExit(void) { int j; ESIF_TRACE_ENTRY_INFO(); for (j=0; j < MAX_ESIFLOG; j++) { if (g_EsifLogFile[j].handle != NULL) { esif_ccb_fclose(g_EsifLogFile[j].handle); } esif_ccb_free(g_EsifLogFile[j].name); esif_ccb_free(g_EsifLogFile[j].filename); esif_ccb_lock_uninit(&g_EsifLogFile[j].lock); } esif_ccb_memset(g_EsifLogFile, 0, sizeof(g_EsifLogFile)); ESIF_TRACE_EXIT_INFO(); }
eEsifError EsifLogMgrInit(void) { int j; ESIF_TRACE_ENTRY_INFO(); esif_ccb_memset(g_EsifLogFile, 0, sizeof(g_EsifLogFile)); for (j=0; j < MAX_ESIFLOG; j++) { esif_ccb_lock_init(&g_EsifLogFile[j].lock); } g_EsifLogFile[ESIF_LOG_EVENTLOG].name = esif_ccb_strdup("event"); g_EsifLogFile[ESIF_LOG_DEBUGGER].name = esif_ccb_strdup("debug"); g_EsifLogFile[ESIF_LOG_SHELL].name = esif_ccb_strdup("shell"); g_EsifLogFile[ESIF_LOG_TRACE].name = esif_ccb_strdup("trace"); g_EsifLogFile[ESIF_LOG_UI].name = esif_ccb_strdup("ui"); ESIF_TRACE_EXIT_INFO(); return ESIF_OK; }
eEsifError EsifAppMgrInit() { eEsifError rc = ESIF_OK; ESIF_TRACE_ENTRY_INFO(); esif_ccb_lock_init(&g_appMgr.fLock); EsifAppInit(); g_appMgr.GetAppFromName = GetAppFromName; g_appMgr.GetPrompt = GetPrompt; EsifEventMgr_RegisterEventByType(ESIF_EVENT_PARTICIPANT_SUSPEND, EVENT_MGR_MATCH_ANY, EVENT_MGR_DOMAIN_D0, EsifAppMgr_EventCallback, NULL); EsifEventMgr_RegisterEventByType(ESIF_EVENT_PARTICIPANT_RESUME, EVENT_MGR_MATCH_ANY, EVENT_MGR_DOMAIN_D0, EsifAppMgr_EventCallback, NULL); ESIF_TRACE_EXIT_INFO_W_STATUS(rc); return rc; }
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; }
void EsifActMgrExit() { ESIF_TRACE_ENTRY_INFO(); /* Call before destroying action manager */ EsifActMgr_UninitActions(); esif_ccb_write_lock(&g_actMgr.mgrLock); esif_link_list_free_data_and_destroy(g_actMgr.actions, EsifActMgr_LLEntryDestroyCallback); g_actMgr.actions = NULL; esif_link_list_free_data_and_destroy(g_actMgr.possibleActions, EsifActMgr_LLEntryDestroyCallback); g_actMgr.possibleActions = NULL; esif_ccb_write_unlock(&g_actMgr.mgrLock); esif_ccb_lock_uninit(&g_actMgr.mgrLock); ESIF_TRACE_EXIT_INFO(); }
static void *ESIF_CALLCONV EsifDataLogWorkerThread(void *ptr) { eEsifError rc = ESIF_OK; UNREFERENCED_PARAMETER(ptr); ESIF_TRACE_ENTRY_INFO(); while (!g_dataLogQuit) { esif_ccb_time_t msecStart = 0; esif_ccb_time_t msecStop = 0; esif_ccb_time_t msecDif = 0; UInt32 sleepMs = 0; esif_ccb_system_time(&msecStart); EsifDataLogFire(0); esif_ccb_system_time(&msecStop); /* Determine how long processing actually took */ msecDif = msecStop - msecStart; /* Determine next sleep time based on previous processing time*/ sleepMs = g_dataLogInterval - ((int) msecDif); if ((sleepMs < MIN_STATUS_LOG_INTERVAL_ADJUSTED) || (msecDif > g_dataLogInterval)){ sleepMs = MIN_STATUS_LOG_INTERVAL_ADJUSTED; } rc = EsifTimedEventWait(&g_dataLogQuitEvent, sleepMs); if (rc != ESIF_OK) { ESIF_TRACE_ERROR("Error waiting on data log event\n"); goto exit; } } exit: ESIF_TRACE_EXIT_INFO(); return 0; }
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; }
/* Will sync any existing lower framework participatnts */ enum esif_rc sync_lf_participants() { eEsifError rc = ESIF_OK; struct esif_command_get_participants *data_ptr = NULL; const UInt32 data_len = sizeof(struct esif_command_get_participants); struct esif_ipc_command *command_ptr = NULL; UInt8 i = 0; UInt32 count = 0; struct esif_ipc *ipc_ptr = NULL; ESIF_TRACE_ENTRY_INFO(); ipc_ptr = esif_ipc_alloc_command(&command_ptr, data_len); if (NULL == ipc_ptr || NULL == command_ptr) { ESIF_TRACE_ERROR("Fail to allocate esif_ipc/esif_ipc_command\n"); rc = ESIF_E_NO_MEMORY; goto exit; } command_ptr->type = ESIF_COMMAND_TYPE_GET_PARTICIPANTS; command_ptr->req_data_type = ESIF_DATA_VOID; command_ptr->req_data_offset = 0; command_ptr->req_data_len = 0; command_ptr->rsp_data_type = ESIF_DATA_STRUCTURE; command_ptr->rsp_data_offset = 0; command_ptr->rsp_data_len = data_len; rc = ipc_execute(ipc_ptr); if (ESIF_OK != rc) { goto exit; } if (ESIF_OK != ipc_ptr->return_code) { rc = ipc_ptr->return_code; ESIF_TRACE_WARN("ipc_ptr return_code failure - %s\n", esif_rc_str(rc)); goto exit; } if (ESIF_OK != command_ptr->return_code) { rc = command_ptr->return_code; ESIF_TRACE_WARN("command_ptr return_code failure - %s\n", esif_rc_str(rc)); goto exit; } /* Participant Data */ data_ptr = (struct esif_command_get_participants *)(command_ptr + 1); count = data_ptr->count; for (i = 0; i < count; i++) { struct esif_ipc_event_data_create_participant participantData; EsifData esifParticipantData = {ESIF_DATA_BINARY, &participantData, sizeof(participantData), sizeof(participantData)}; rc = get_participant_data(&participantData, i); if (ESIF_OK != rc) { rc = ESIF_OK; /* Ignore RC for get_participant_data */ continue; } EsifEventMgr_SignalEvent(0, EVENT_MGR_DOMAIN_D0, ESIF_EVENT_PARTICIPANT_CREATE, &esifParticipantData); } exit: ESIF_TRACE_INFO("rc = %s(%u)", esif_rc_str(rc), rc); if (NULL != ipc_ptr) { esif_ipc_free(ipc_ptr); } ESIF_TRACE_EXIT_INFO_W_STATUS(rc); return rc; }