Exemplo n.º 1
0
/* Event handler for events targeted at ALL apps without app registration */
static eEsifError ESIF_CALLCONV EsifAppMgr_EventCallback(
	void *contextPtr,
	UInt8 participantId,
	UInt16 domainId,
	EsifFpcEventPtr fpcEventPtr,
	EsifDataPtr eventDataPtr
	)
{
	eEsifError rc = ESIF_OK;
	EsifAppPtr appPtr = NULL;
	UInt8 i = 0;

	UNREFERENCED_PARAMETER(contextPtr);
	UNREFERENCED_PARAMETER(domainId);
	UNREFERENCED_PARAMETER(eventDataPtr);

	if (NULL == fpcEventPtr) {
		rc = ESIF_E_PARAMETER_IS_NULL;
		goto exit;
	}

	// Only handle at the app level
	if (participantId != 0) {
		goto exit;
	}

	for (i = 0; i < ESIF_MAX_APPS; i++) {
		appPtr = &g_appMgr.fEntries[i];
		if (NULL == appPtr->fHandle) {
			continue;
		}

		switch (fpcEventPtr->esif_event)
		{
		case ESIF_EVENT_PARTICIPANT_SUSPEND:
			ESIF_TRACE_INFO("System suspend event received\n");
			if (NULL != appPtr->fInterface.fAppSuspendFuncPtr) {
				appPtr->fInterface.fAppSuspendFuncPtr(appPtr->fHandle);
			}
			break;

		case ESIF_EVENT_PARTICIPANT_RESUME:
			ESIF_TRACE_INFO("System resume event received\n");
			if (NULL != appPtr->fInterface.fAppResumeFuncPtr) {
				appPtr->fInterface.fAppResumeFuncPtr(appPtr->fHandle);
			}
			break;

		default:
			break;
		}
	}

exit:
	return rc;
}
Exemplo n.º 2
0
static void *ESIF_CALLCONV EsifEventMgr_EventQueueThread(void *ctxPtr)
{
	EsifEventQueueItemPtr queueEventPtr = NULL;

	UNREFERENCED_PARAMETER(ctxPtr);

	while(!g_EsifEventMgr.eventQueueExitFlag) {
		queueEventPtr = esif_queue_pull(g_EsifEventMgr.eventQueuePtr);

		if (NULL == queueEventPtr) {
			continue;
		}

		ESIF_TRACE_INFO("Dequeuing %s event for Part. %u Dom. 0x%04X\n",
			esif_event_type_str(queueEventPtr->eventType),
			queueEventPtr->participantId,
			queueEventPtr->domainId);

		EsifEventMgr_ProcessEvent(queueEventPtr->participantId,
			queueEventPtr->domainId,
			queueEventPtr->eventType,
			&queueEventPtr->eventData);

		esif_ccb_free(queueEventPtr->eventData.buf_ptr);
		esif_ccb_free(queueEventPtr);
	}
	return 0;
}
Exemplo n.º 3
0
static eEsifError EsifApp_RegisterParticipantsWithApp(
	EsifAppPtr self
	)
{
	eEsifError rc = ESIF_OK;
	EsifUpPtr upPtr = NULL;
	UInt8 i = 0;

	ESIF_ASSERT(self != NULL);

	/* Skip 0 ESIF treats this as a participant no one else does :) */
	/* TODO:  Use iterator here.  This function shouldn't know the number of participants */
	for (i = 1; i < MAX_PARTICIPANT_ENTRY; i++) {
		upPtr = EsifUpPm_GetAvailableParticipantByInstance(i);
		if (NULL == upPtr) {
			continue;
		}
		rc = EsifAppCreateParticipant(self, upPtr);
		EsifUp_PutRef(upPtr);
		if (ESIF_OK != rc) {
			break;
		}
	}
	ESIF_TRACE_INFO("Register participants with App, status = %s\n", esif_rc_str(rc));
	return rc;
}
Exemplo n.º 4
0
eEsifError EsifUpManagerRegisterParticipantsWithApp(EsifAppPtr aAppPtr)
{
	eEsifError rc = ESIF_OK;
	UInt8 i = 0;

	if (NULL == aAppPtr) {
		ESIF_TRACE_ERROR("Esif app pointer is NULL\n");
		return ESIF_E_PARAMETER_IS_NULL;
	}

	esif_ccb_read_lock(&g_uppMgr.fLock);

	/* Skip 0 ESIF treats this as a participant no one else does :) */
	for (i = 1; i < MAX_PARTICIPANT_ENTRY; i++) {
		EsifUpPtr up_ptr = g_uppMgr.fEntries[i].fUpPtr;
		if ((NULL != up_ptr) && (g_uppMgr.fEntries[i].fState > ESIF_PM_PARTICIPANT_REMOVED)) {
			rc = EsifAppCreateParticipant(aAppPtr, up_ptr);
			if (ESIF_OK != rc) {
				break;
			}
		}
	}

	esif_ccb_read_unlock(&g_uppMgr.fLock);

	ESIF_TRACE_INFO("Register participants with App, status = %s\n", esif_rc_str(rc));
	return rc;
}
Exemplo n.º 5
0
void EsifAct_DestroyAction(
	EsifActPtr self
	)
{
	if (NULL == self) {
		goto exit;
	}

	self->markedForDelete = ESIF_TRUE;
	EsifAct_PutRef(self);

	ESIF_TRACE_INFO("Destroy action %d : waiting for delete event...\n", self->type);
	esif_ccb_event_wait(&self->deleteEvent);

	EsifAct_UnregisterEvents(self);

	EsifAct_CallIfaceDestroy(self);

	esif_ccb_event_uninit(&self->deleteEvent);
	esif_ccb_lock_uninit(&self->objLock);

	esif_ccb_free(self);
exit:
	return;
}
Exemplo n.º 6
0
/* Build DSP Table From DSP Resources */
static eEsifError esif_dsp_table_build()
{
	eEsifError rc = ESIF_OK;
	ESIF_TRACE_INFO("Build DSP Table");
	rc = esif_dsp_file_scan();
	return rc;
}
Exemplo n.º 7
0
/* This should only be called when shutting down */
static eEsifError EsifUpManagerDestroyParticipants(void)
{
	eEsifError rc = ESIF_OK;
	EsifUpManagerEntryPtr entry_ptr = NULL;
	UInt8 i = 0;

	esif_ccb_write_lock(&g_uppMgr.fLock);

	for (i = 0; i < MAX_PARTICIPANT_ENTRY; i++) {
		entry_ptr = &g_uppMgr.fEntries[i];

		if (entry_ptr->fState > ESIF_PM_PARTICIPANT_REMOVED) {
			g_uppMgr.fEntryCount--;
		}
		entry_ptr->fState = ESIF_PM_PARTICIPANT_STATE_AVAILABLE;

		if (NULL != entry_ptr->fUpPtr) {
			esif_ccb_free(entry_ptr->fUpPtr);
			entry_ptr->fUpPtr = NULL;
		}
	}

	esif_ccb_write_unlock(&g_uppMgr.fLock);

	ESIF_TRACE_INFO("The participants are destroyed in ESIF UF participant manager\n");
	return rc;
}
Exemplo n.º 8
0
/* Initialize manager */
eEsifError EsifUppMgrInit(void)
{
	eEsifError rc = ESIF_OK;
	ESIF_TRACE_INFO("%s: Init Upper Participant Manager (PM)", ESIF_FUNC);

	/* Initialize Lock */
	esif_ccb_lock_init(&g_uppMgr.fLock);

	return rc;
}
Exemplo n.º 9
0
/* Exit manager */
void EsifUppMgrExit(void)
{
	/* Clean up resources */
	EsifUpManagerDestroyParticipants();

	/* Uninitialize Lock */
	esif_ccb_lock_uninit(&g_uppMgr.fLock);

	ESIF_TRACE_INFO("%s: Exit Upper Participant Manager (PM)", ESIF_FUNC);
}
Exemplo n.º 10
0
void esif_dsp_table_destroy()
{
	UInt8 i;
	ESIF_TRACE_INFO("Destroy DSP Table");
	for (i = 0; i < g_dm.dme_count; i++) {
		esif_dsp_destroy(g_dm.dme[i].dsp_ptr);
		esif_ccb_free(g_dm.dme[i].file_ptr);
		esif_ccb_free(g_dm.dme[i].fpc_ptr);
		esif_ccb_memset(&g_dm.dme[i], 0, sizeof(g_dm.dme[i]));
	}
	g_dm.dme_count = 0;
}
Exemplo n.º 11
0
/* Unregister Upper Participant Instance */
eEsifError EsifUpManagerUnregisterParticipant(
	const eEsifParticipantOrigin origin,
	const void *participantHandle
	)
{
	eEsifError rc    = ESIF_OK;
	EsifUpManagerEntryPtr entry_ptr = NULL;
	EsifUpPtr up_ptr = NULL;
	UInt8 instance;

	UNREFERENCED_PARAMETER(origin);

	/* Validate parameters */
	if (NULL == participantHandle) {
		ESIF_TRACE_ERROR("The participant handle pointer is NULL\n");
		ESIF_ASSERT(participantHandle != NULL);
		rc = ESIF_E_PARAMETER_IS_NULL;
		goto exit;
	}

	instance = *(UInt8 *)participantHandle;

	if (instance >= MAX_PARTICIPANT_ENTRY) {
		ESIF_TRACE_ERROR("Instance id %d is out of range\n", instance);
		rc = ESIF_E_PARAMETER_IS_OUT_OF_BOUNDS;
		goto exit;
	}

	esif_ccb_write_lock(&g_uppMgr.fLock);

	entry_ptr = &g_uppMgr.fEntries[instance];
	if (NULL != entry_ptr) {
		up_ptr = entry_ptr->fUpPtr;
		if (NULL != up_ptr) {
			entry_ptr->fState = ESIF_PM_PARTICIPANT_REMOVED;
			g_uppMgr.fEntryCount--;
		}
	}
	esif_ccb_write_unlock(&g_uppMgr.fLock);

	if (NULL != up_ptr) {
		rc = EsifAppMgrDestroyParticipantInAllApps(up_ptr);
	}

	ESIF_TRACE_INFO("Unregister participant, instant id = %d\n", instance);
exit:
	return rc;
}
Exemplo n.º 12
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;
}
Exemplo n.º 13
0
eEsifError EsifUpManagerDestroyParticipantsInApp(EsifAppPtr aAppPtr)
{
	UInt8 i = 0;

	esif_ccb_read_lock(&g_uppMgr.fLock);

	for (i = 0; i < MAX_PARTICIPANT_ENTRY; i++) {
		EsifUpPtr up_ptr = g_uppMgr.fEntries[i].fUpPtr;
		if ((NULL != up_ptr) && (g_uppMgr.fEntries[i].fState > ESIF_PM_PARTICIPANT_REMOVED)) {
			EsifAppDestroyParticipant(aAppPtr, up_ptr);
		}
	}

	esif_ccb_read_unlock(&g_uppMgr.fLock);

	ESIF_TRACE_INFO("Destroy participants in App\n");
	return ESIF_OK;
}
Exemplo n.º 14
0
static eEsifError EsifApp_DestroyParticipants(EsifAppPtr self)
{
	EsifUpPtr upPtr = NULL;
	UInt8 i = 0;

	ESIF_ASSERT(self != NULL);

	/* TODO:  Use iterator here.  This function shouldn't know the number of participants */
	for (i = 0; i < MAX_PARTICIPANT_ENTRY; i++) {
		upPtr = EsifUpPm_GetAvailableParticipantByInstance(i);
		if (NULL == upPtr) {
			continue;
		}
		EsifAppDestroyParticipant(self, upPtr);
		EsifUp_PutRef(upPtr);
	}

	ESIF_TRACE_INFO("Destroy participants in App\n");
	return ESIF_OK;
}
Exemplo n.º 15
0
Bool EsifActIface_IsSupported(
		EsifActIfacePtr self
	)
{
	Bool isSupported = ESIF_TRUE;

	if (NULL == self) {
		isSupported = ESIF_FALSE;
		ESIF_TRACE_ERROR("Interface ptr is NULL\n");
		goto exit;
	}

	if (self->hdr.fIfaceType != eIfaceTypeAction ||
		self->hdr.fIfaceVersion > ESIF_ACT_FACE_VER_MAX ||
		self->hdr.fIfaceSize != EsifActIface_Sizeof(self->hdr.fIfaceVersion)) {
		isSupported = ESIF_FALSE;
		ESIF_TRACE_INFO("The action interface does not meet requirements\n");
	}
exit:
	return isSupported;
}
Exemplo n.º 16
0
/* Create participant */
EsifUpPtr EsifUpManagerCreateParticipant(
	const eEsifParticipantOrigin origin,
	const void *handle,
	const void *metadataPtr
	)
{
	EsifUpPtr up_ptr = NULL;
	EsifUpManagerEntryPtr entry_ptr = NULL;
	UInt8 i = 0;
	UInt8 lpInstance;

	/* Lock manager */
	esif_ccb_write_lock(&g_uppMgr.fLock);

	/* Validate parameters */
	if (NULL == handle || NULL == metadataPtr) {
		ESIF_TRACE_ERROR("Invalid handle or meta data pointer\n");
		goto exit;
	}

	lpInstance = *(UInt8 *)handle;

	/*
	 * Check if a participant has already been created, but was then removed.
	 * In that case, just re-enable the participant.
	 */
	entry_ptr = EsifUpManagerGetParticipantEntryFromMetadata(origin, metadataPtr);
	if (NULL != entry_ptr) {
		up_ptr = entry_ptr->fUpPtr;
		entry_ptr->fState = ESIF_PM_PARTICIPANT_STATE_CREATED;
		g_uppMgr.fEntryCount++;
		goto exit;
	}

	/* Allocate a particpant */
	up_ptr = (EsifUpPtr)esif_ccb_malloc(sizeof(EsifUp));
	if (NULL == up_ptr) {
		ESIF_TRACE_ERROR("Fail to allocate EsifUp\n");
		ESIF_ASSERT(up_ptr != NULL);
		goto exit;
	}

	/*
	**  Find available slot in participant manager table.  Simple Table Lookup For Now.
	**  Scan table and find first empty slot.  Empty slot indicated by AVAILABLE state.
	*/
	for (i = 0; i < MAX_PARTICIPANT_ENTRY; i++) {
		if (ESIF_PM_PARTICIPANT_STATE_AVAILABLE == g_uppMgr.fEntries[i].fState) {
			break;
		}
	}

	/* If no available slots return */
	if (i >= MAX_PARTICIPANT_ENTRY) {
		ESIF_TRACE_ERROR("No available slot in participant manager\n");
		esif_ccb_free(up_ptr);
		up_ptr = NULL;
		goto exit;
	}

	/* Take slot */
	g_uppMgr.fEntries[i].fState = ESIF_PM_PARTICIPANT_STATE_CREATED;
	g_uppMgr.fEntryCount++;

	/* Initialize participant */
	up_ptr->fInstance = i;
	up_ptr->fEnabled  = ESIF_TRUE;

	/* Initialize based on origin */
	switch (origin) {
	case eParticipantOriginLF:
		UpInitializeOriginLF(up_ptr, lpInstance, metadataPtr);
		break;

	case eParticipantOriginUF:
		UpInitializeOriginUF(up_ptr, metadataPtr);
		break;

	default:
		break;
	}

	/* Unlock manager */
	g_uppMgr.fEntries[i].fUpPtr = up_ptr;
	ESIF_TRACE_INFO("The participant data of %s is created in ESIF UF, instance = %d\n", up_ptr->fMetadata.fName, i);

exit:
	esif_ccb_write_unlock(&g_uppMgr.fLock);
	return up_ptr;
}
Exemplo n.º 17
0
// Send DSP
enum esif_rc esif_send_dsp(
    char *filename,
    u8 dstId
)
{
    enum esif_rc rc = ESIF_OK;
    int edpSize = 512;
    int cmdSize = 0;
    struct esif_ipc *ipcPtr = NULL;
    struct esif_ipc_command *commandPtr = NULL;
    struct esif_command_send_dsp *dspCommandPtr = NULL;
    struct edp_dir edpDir;
    size_t bytesRead;
    char *edpName        = 0;
    IOStreamPtr ioPtr    = IOStream_Create();
    EsifDataPtr nameSpace = 0;
    EsifDataPtr key       = 0;
    EsifDataPtr value     = 0;

    if (ioPtr == NULL) {
        ESIF_TRACE_ERROR("Fail to create IOStream\n");
        rc = ESIF_E_NO_MEMORY;
        goto exit;
    }

    //
    // If we have a filename provided use the contents of the file as the CPC
    // note this is opaque it is up to the receiver to verify that this is in fact
    // a CPC.
    //
    if (NULL == filename) {
        ESIF_TRACE_ERROR("Filename is null\n");
        rc = ESIF_E_PARAMETER_IS_NULL;
        goto exit;
    }

    // Use name portion of filename for the DataVault key (C:\path\file.edp = file.edp)
    edpName  = strrchr(filename, *ESIF_PATH_SEP);
    edpName  = (edpName ? ++edpName : filename);
    nameSpace = EsifData_CreateAs(ESIF_DATA_STRING, ESIF_DSP_NAMESPACE, 0, ESIFAUTOLEN);
    key       = EsifData_CreateAs(ESIF_DATA_STRING, edpName, 0, ESIFAUTOLEN);
    value     = EsifData_CreateAs(ESIF_DATA_AUTO, NULL, ESIF_DATA_ALLOCATE, 0);

    if (nameSpace == NULL || key == NULL || value == NULL) {
        rc = ESIF_E_NO_MEMORY;
        goto exit;
    }

    // Look for EDP file on disk first then DataVault (static or file)
    if (!esif_ccb_file_exists(filename) && EsifConfigGet(nameSpace, key, value) == ESIF_OK) {
        filename = edpName;
        IOStream_SetMemory(ioPtr, (BytePtr)value->buf_ptr, value->data_len);
    } else {
        IOStream_SetFile(ioPtr, filename, (char *)"rb");
    }

    /* FIND CPC within EDP file */
    if (IOStream_Open(ioPtr) != 0) {
        ESIF_TRACE_ERROR("File not found (%s)\n", filename);
        rc = ESIF_E_IO_OPEN_FAILED;
        goto exit;
    }
    bytesRead  = IOStream_Read(ioPtr, &edpDir, sizeof(struct edp_dir));
    if (!esif_verify_edp(&edpDir, bytesRead)) {
        ESIF_TRACE_ERROR("Invalid EDP Header: Signature=%4.4s Version=%d\n", (char *)&edpDir.signature, edpDir.version);
        rc = ESIF_E_NOT_SUPPORTED;
        goto exit;
    }
    edpSize = edpDir.fpc_offset - edpDir.cpc_offset;
    IOStream_Seek(ioPtr, edpDir.cpc_offset, SEEK_SET);

    if (edpSize > MAX_EDP_SIZE) {
        ESIF_TRACE_ERROR("The edp size %d is larger than maximum edp size\n", edpSize);
        rc = -ESIF_E_UNSPECIFIED;
        goto exit;
    }

    cmdSize = edpSize + sizeof(*dspCommandPtr);

    ipcPtr = esif_ipc_alloc_command(&commandPtr, cmdSize);
    if (NULL == ipcPtr || NULL == commandPtr) {
        ESIF_TRACE_ERROR("Fail to allocate esif_ipc/esif_ipc_command\n");
        rc = ESIF_E_NO_MEMORY;
        goto exit;
    }

    commandPtr->type = ESIF_COMMAND_TYPE_SEND_DSP;
    commandPtr->req_data_type = ESIF_DATA_STRUCTURE;
    commandPtr->req_data_offset = 0;
    commandPtr->req_data_len = cmdSize;
    commandPtr->rsp_data_type = ESIF_DATA_VOID;
    commandPtr->rsp_data_offset = 0;
    commandPtr->rsp_data_len = 0;

    dspCommandPtr = (struct esif_command_send_dsp *)(commandPtr + 1);
    dspCommandPtr->id = dstId;
    dspCommandPtr->data_len = edpSize;

    bytesRead = IOStream_Read(ioPtr, dspCommandPtr + 1, edpSize);
    ESIF_TRACE_DEBUG("loaded file %s bytes %d\n", filename, (int)bytesRead);

    ESIF_TRACE_INFO("CPC file %s(%d) sent to participant %d\n", filename, edpSize, dstId);

    ipc_execute(ipcPtr);

    if (ESIF_OK != ipcPtr->return_code) {
        ESIF_TRACE_ERROR("ipc error code = %s(%d)\n", esif_rc_str(ipcPtr->return_code), ipcPtr->return_code);
        rc = ipcPtr->return_code;
        goto exit;
    }

    rc = commandPtr->return_code;
    if ((rc != ESIF_OK) && (rc != ESIF_E_DSP_ALREADY_LOADED)) {
        ESIF_TRACE_ERROR("primitive error code = %s(%d)\n", esif_rc_str(commandPtr->return_code), commandPtr->return_code);
        goto exit;
    }
exit:
    if (NULL != ipcPtr) {
        esif_ipc_free(ipcPtr);
    }
    if (NULL != ioPtr) {
        IOStream_Close(ioPtr);
        IOStream_Destroy(ioPtr);
    }
    EsifData_Destroy(nameSpace);
    EsifData_Destroy(key);
    EsifData_Destroy(value);
    return rc;
}
Exemplo n.º 18
0
eEsifError ESIF_CALLCONV EsifEventMgr_SignalEvent(
	UInt8 participantId,
	UInt16 domainId,
	eEsifEventType eventType,
	const EsifDataPtr eventDataPtr
	)
{
	eEsifError rc = ESIF_OK;
	EsifEventQueueItemPtr queueEventPtr = NULL;
	EsifDataPtr queueDataPtr = NULL;

	if (NULL == g_EsifEventMgr.eventQueuePtr) { /* Should never happen */
		rc = ESIF_E_UNSPECIFIED;
		goto exit;
	}

	queueEventPtr = esif_ccb_malloc(sizeof(*queueEventPtr));
	if (NULL == queueEventPtr) {
		rc = ESIF_E_NO_MEMORY;
		goto exit;
	}

	if ((eventDataPtr != NULL) &&
	    (eventDataPtr->buf_ptr != NULL) && 
	    (eventDataPtr->buf_len > 0) &&
	    (eventDataPtr->data_len > 0) &&
	    (eventDataPtr->buf_len >= eventDataPtr->data_len)) {

		queueDataPtr = esif_ccb_malloc(eventDataPtr->data_len);
		if (NULL == queueDataPtr) {
			rc = ESIF_E_NO_MEMORY;
			goto exit;
		}

		esif_ccb_memcpy(queueDataPtr, eventDataPtr->buf_ptr, eventDataPtr->data_len);

		queueEventPtr->eventData.type = eventDataPtr->type;
		queueEventPtr->eventData.buf_ptr = queueDataPtr;
		queueEventPtr->eventData.buf_len = eventDataPtr->data_len;
		queueEventPtr->eventData.data_len = eventDataPtr->data_len;
	}

	queueEventPtr->participantId = participantId;
	queueEventPtr->domainId = domainId;
	queueEventPtr->eventType = eventType;

	ESIF_TRACE_INFO("Queuing %s event for Part. %u Dom. 0x%04X\n",
		esif_event_type_str(eventType),
		participantId,
		domainId);

	rc = esif_queue_enqueue(g_EsifEventMgr.eventQueuePtr, queueEventPtr);
	if (rc != ESIF_OK) {
		goto exit;
	}

exit:
	if (rc != ESIF_OK) {
		esif_ccb_free(queueEventPtr);
		esif_ccb_free(queueDataPtr);

	}
	return rc;
}
Exemplo n.º 19
0
/*
 * Handle ESIF Action "Set" Request
 */
static eEsifError ESIF_CALLCONV ActionSystemSet(
	const void *actionHandle,
	EsifUpPtr upPtr,
	const EsifFpcPrimitivePtr primitivePtr,
	const EsifFpcActionPtr actionPtr,
	const EsifDataPtr requestPtr
	)
{
	eEsifError esifStatus = ESIF_OK;
	EsifData p1 = {0};
	EsifString command = NULL;

	UNREFERENCED_PARAMETER(actionHandle);
	UNREFERENCED_PARAMETER(upPtr);
	UNREFERENCED_PARAMETER(primitivePtr);
	UNREFERENCED_PARAMETER(actionPtr);

	esifStatus = EsifActionGetParamAsEsifData(actionPtr, 0, &p1);
	if (ESIF_OK != esifStatus) {
		goto exit;
	}
	ESIF_ASSERT(NULL != p1.buf_ptr);
	ESIF_ASSERT(ESIF_DATA_STRING == p1.type);

	command = (EsifString)p1.buf_ptr;

	/* Well known/Special Commands magic is used to avoid accidental calls*/
	if (!strcmp("SYSTEM_SLEEP", command)) {
		ESIF_TRACE_INFO("SYSTEM_SLEEP command received - system suspend...\n");
		esif_ccb_suspend();

	} else if (!strcmp("SYSTEM_SHUTDOWN", command)) {
		UInt32 temperature = 0;
		UInt32 tripPointTemperature = 0;
		if (requestPtr && requestPtr->buf_ptr && ESIF_DATA_STRUCTURE == requestPtr->type) {
			/*
			** Thermal shutdown data was provided with request
			*/
			struct esif_data_complex_shutdown *shutdown_data =
				(struct esif_data_complex_shutdown *)requestPtr->buf_ptr;
			temperature = shutdown_data->temperature;
			tripPointTemperature = shutdown_data->tripPointTemperature;
		}
		ESIF_TRACE_INFO("SYSTEM_SHUTDOWN command received - temperature = %d, trip point = %d\n", temperature, tripPointTemperature);
		esif_ccb_shutdown(temperature, tripPointTemperature);

	} else if (!strcmp("SYSTEM_HIBERNATE", command)) {
		ESIF_TRACE_INFO("SYSTEM_HIBERNATE command received - system hibernate...\n");
		esif_ccb_hibernate();

	} else if (!strcmp("SYSTEM_REBOOT", command)) {
		ESIF_TRACE_INFO("SYSTEM_REBOOT command received - system reboot...\n");
		esif_ccb_reboot();

	} else if (!strcmp("SYSTEM_REM_PWRSETTING", command)) {
		esifStatus = esif_ccb_remove_power_setting(requestPtr);
		
	} else if (!strcmp("SYSTEM_CTDPCLR", command)) {
		esifStatus = system_clear_ctdp_names();

	} else if (!strcmp("SYSTEM_SET_CTDPNAME0", command)) {
		esifStatus = system_set_ctdp_name(requestPtr, 0);

	} else if (!strcmp("SYSTEM_SET_CTDPNAME1", command)) {
		esifStatus = system_set_ctdp_name(requestPtr, 1);

	} else if (!strcmp("SYSTEM_SET_CTDPNAME2", command)) {
		esifStatus = system_set_ctdp_name(requestPtr, 2);

	} else if (!strcmp("SYSTEM_ENA_PWRSETTING", command)) {
		esifStatus = esif_ccb_enable_power_setting(requestPtr);

	} else if (!strcmp("SYSTEM_DIS_PWRSETTING", command)) {
		esifStatus = esif_ccb_disable_power_setting(requestPtr);

	} else {
		system(command);
	}
exit:
	return esifStatus;
}
Exemplo n.º 20
0
static eEsifError ESIF_CALLCONV ActionDelegateSet(
	esif_context_t actCtx,
	EsifUpPtr upPtr,
	const EsifFpcPrimitivePtr primitivePtr,
	const EsifFpcActionPtr fpcActionPtr,
	EsifDataPtr requestPtr
	)
{
	eEsifError rc = ESIF_OK;
	EsifData p1 = {0};
	UInt32 method;
	EsifUpDomainPtr domainPtr = NULL;

	UNREFERENCED_PARAMETER(actCtx);
	UNREFERENCED_PARAMETER(upPtr);

	ESIF_ASSERT(NULL != requestPtr);
	ESIF_ASSERT(NULL != requestPtr->buf_ptr);
	ESIF_ASSERT(NULL != primitivePtr);
	ESIF_ASSERT(NULL != fpcActionPtr);
	
	domainPtr = EsifUp_GetDomainById(upPtr, primitivePtr->tuple.domain);
	if (NULL == domainPtr) {
		ESIF_TRACE_ERROR("Unable to get domain\n");
		rc = ESIF_E_PARAMETER_IS_OUT_OF_BOUNDS;
		goto exit;
	}

	rc = EsifFpcAction_GetParamAsEsifData(fpcActionPtr, 0, &p1);
	if ((ESIF_OK != rc) || (NULL == p1.buf_ptr)) {
		ESIF_TRACE_ERROR("Unable to get parameters\n");
		goto exit;
	}

	method = *((UInt32 *)p1.buf_ptr);

	switch (method) {
	
	/* Set Temperature Trip Points */
	case '0TAP':	/* PAT0 */
		ESIF_TRACE_INFO("PAT0 received\n");
		rc = EsifSetActionDelegatePat0(domainPtr, requestPtr);
		break;

	case '1TAP':	/* PAT1 */
		ESIF_TRACE_INFO("PAT1 received\n");
		rc = EsifSetActionDelegatePat1(domainPtr, requestPtr);
		break;

	case 'BSPS':	/* SPSB: Set Participant Sample Behavior */
		ESIF_TRACE_INFO("Set Sample Behavior received\n");
		rc = EsifSetActionDelegateSampleBehavior(domainPtr, requestPtr);
		break;

	case 'PMTV':	/* VTMP: Virtual Temperature */
		ESIF_TRACE_INFO("Set Virtual Temperature received\n");
		rc = EsifSetActionDelegateVirtualTemperature(domainPtr, requestPtr);
		break;

	case 'BHPS':	/* SPHB: Set Participant Hysteresis Behavior */
		ESIF_TRACE_INFO("Set Participant Hysteresis Behavior received\n");
		rc = EsifSetActionDelegateSphb(domainPtr, requestPtr);
		break;

	case 'CSPS':    /* SPSC: Set Platform State Of Charge */
		ESIF_TRACE_INFO("Set OS Battery Percentage received\n");
		rc = EsifSetActionDelegateToSignalOSEvent(domainPtr, requestPtr, ESIF_EVENT_OS_BATTERY_PERCENT_CHANGED);
		break;

	case 'SPPS':    /* SPPS: Set Platform Power Source */
		ESIF_TRACE_INFO("Set Platform Power Source received\n");
		rc = EsifSetActionDelegateToSignalOSEvent(domainPtr, requestPtr, ESIF_EVENT_OS_POWER_SOURCE_CHANGED);
		break;

	case 'OPDS':    /* SDPO: Set Display Orientation */
		ESIF_TRACE_INFO("Set Display Orientation received\n");
		rc = EsifSetActionDelegateToSignalOSEvent(domainPtr, requestPtr, ESIF_EVENT_DISPLAY_ORIENTATION_CHANGED);
		break;

	case 'OVDS':    /* SDVO: Set Device Orientation */
		ESIF_TRACE_INFO("Set Device Orientation received\n");
		rc = EsifSetActionDelegateToSignalOSEvent(domainPtr, requestPtr, ESIF_EVENT_DEVICE_ORIENTATION_CHANGED);
		break;

	case 'COMS':    /* SMOC: Set Motion Changed */
		ESIF_TRACE_INFO("Set Motion Changed received\n");
		rc = EsifSetActionDelegateToSignalOSEvent(domainPtr, requestPtr, ESIF_EVENT_MOTION_CHANGED);
		break;

	case 'MKDS':    /* SDKM: Set Dock Mode */
		ESIF_TRACE_INFO("Set Dock Mode received\n");
		rc = EsifSetActionDelegateToSignalOSEvent(domainPtr, requestPtr, ESIF_EVENT_OS_DOCK_MODE_CHANGED);
		break;

	case 'MLCS':    /* SCLM: Set Cooling Mode */
		ESIF_TRACE_INFO("Set Cooling Mode received\n");
		rc = EsifSetActionDelegateToSignalOSEvent(domainPtr, requestPtr, ESIF_EVENT_SYSTEM_COOLING_POLICY_CHANGED);
		break;

	case 'TSLS':    /* SLST: Set Lid State */
		ESIF_TRACE_INFO("Set Lid State received\n");
		rc = EsifSetActionDelegateToSignalOSEvent(domainPtr, requestPtr, ESIF_EVENT_OS_LID_STATE_CHANGED);
		break;

	case 'TFPS':    /* SPFT: Set Platform Type */
		ESIF_TRACE_INFO("Set Platform Type received\n");
		rc = EsifSetActionDelegateToSignalOSEvent(domainPtr, requestPtr, ESIF_EVENT_OS_PLATFORM_TYPE_CHANGED);
		break;

	case 'AGFS':    /* SFGA: Set Foreground Application */
		ESIF_TRACE_INFO("Set Foreground Application received\n");
		rc = EsifSetActionDelegateToSignalForegroundAppChanged(domainPtr, requestPtr);
		break;

	case 'NOMS':    /* SMON: Set Mobile Notification */
		ESIF_TRACE_INFO("Set Mobile Notification request received\n");
		rc = EsifSetActionDelegateToSignalOSEvent(domainPtr, requestPtr, ESIF_EVENT_OS_MOBILE_NOTIFICATION);
		break;

	case 'TESR':    /* RSET: Reset Override */
		ESIF_TRACE_INFO("Reset Override request received\n");
		rc = EsifSetActionDelegateRset(domainPtr, requestPtr);
		break;

	case 'LAVE':    /* EVAL: Re-evaluate participant capabilities */
		ESIF_TRACE_INFO("Re-evaluate participant capabilities request received\n");
		rc = EsifSetActionDelegateEvaluateParticipantCaps(domainPtr, requestPtr);
		break;

	case 'CPPA':    /* APPC: Application Control  */
		ESIF_TRACE_INFO("Application Control\n");
		rc = EsifSetActionDelegateAppc(domainPtr, requestPtr, fpcActionPtr);
		break;

	case 'PASS':	/* SSAP: Specific Action Primitive execution */
		rc = EsifSetActionDelegateSsap(upPtr, requestPtr);
		break;

	default:
		rc = ESIF_E_NOT_IMPLEMENTED;
		break;
	}
exit:
	return rc;
}
Exemplo n.º 21
0
/* Add DSP Entry */
static eEsifError esif_dsp_entry_create(struct esif_ccb_file *file_ptr)
{
	eEsifError rc  = ESIF_E_UNSPECIFIED;
	EsifDspPtr dspPtr = NULL;
	EsifFpcPtr fpcPtr    = NULL;
	UInt32 fpcIsStatic = ESIF_FALSE;
	UInt8 i = 0;
	char path[MAX_PATH]={0};
	UInt32 fpcSize = 0;
	UInt32 edpSize = 0;
	size_t numFpcBytesRead = 0;
	struct edp_dir edp_dir;
	EsifDataPtr nameSpace = 0;
	EsifDataPtr key = 0;
	EsifDataPtr value = 0;
	IOStreamPtr ioPtr = IOStream_Create();

	if ((NULL == file_ptr) || (NULL == ioPtr)) {
		ESIF_TRACE_ERROR("The file pointer or IO stream is NULL\n");
		goto exit;
	}
	nameSpace = EsifData_CreateAs(ESIF_DATA_STRING, ESIF_DSP_NAMESPACE, 0, ESIFAUTOLEN);
	key       = EsifData_CreateAs(ESIF_DATA_STRING, file_ptr->filename, 0, ESIFAUTOLEN);
	value     = EsifData_CreateAs(ESIF_DATA_AUTO, NULL, ESIF_DATA_ALLOCATE, 0);

	if (nameSpace == NULL || key == NULL || value == NULL) {
		rc = ESIF_E_NO_MEMORY;
		goto exit;
	}

	ESIF_TRACE_DEBUG("Filename: %s", file_ptr->filename);

	dspPtr = esif_dsp_create();
	if (NULL == dspPtr) {
		ESIF_TRACE_ERROR("Fail to allocate dsp entry\n");
		goto exit;
	}

	// Look for EDP file on disk first then in DataVault (static or file)
	esif_build_path(path, sizeof(path), ESIF_PATHTYPE_DSP, file_ptr->filename, NULL);
	if (!esif_ccb_file_exists(path) && EsifConfigGet(nameSpace, key, value) == ESIF_OK) {
		esif_ccb_strcpy(path, file_ptr->filename, MAX_PATH);
		IOStream_SetMemory(ioPtr, StoreReadOnly, (BytePtr)value->buf_ptr, value->data_len);
	} else {
		IOStream_SetFile(ioPtr, StoreReadOnly, path, "rb");
	}
	ESIF_TRACE_DEBUG("Fullpath: %s", path);

	if (IOStream_Open(ioPtr) != 0) {
		ESIF_TRACE_ERROR("File not found (%s)", path);
		goto exit;
	}

	/* Read FPC From EDP File */
	if (esif_ccb_strstr(&path[0], ".edp")) {
		/* EDP - Only Read The FPC Part */
		edpSize = (UInt32)IOStream_GetSize(ioPtr);
		if (!edpSize) {
			goto exit;
		}
		numFpcBytesRead = IOStream_Read(ioPtr, &edp_dir, sizeof(edp_dir));
		if (!esif_verify_edp(&edp_dir, numFpcBytesRead)) {
			ESIF_TRACE_ERROR("Invalid EDP Header: Signature=%4.4s Version=%d\n", (char *)&edp_dir.signature, edp_dir.version);
			goto exit;
		}
		if (edpSize > MAX_EDP_SIZE || edp_dir.fpc_offset > MAX_FPC_SIZE || edp_dir.fpc_offset > edpSize) {
			ESIF_TRACE_ERROR("The edp or fpc file size is larger than maximum\n");
			goto exit;
		}
		fpcSize = edpSize - edp_dir.fpc_offset;
		IOStream_Seek(ioPtr, edp_dir.fpc_offset, SEEK_SET);
		ESIF_TRACE_DEBUG("File found (%s) size %u, FPC size %u from offset %u", path, edpSize, fpcSize, edp_dir.fpc_offset);
	} else {
		ESIF_TRACE_DEBUG("File %s does not have .fpc and .edp format!", path);
	}

	// use static DataVault buffer (if available), otherwise allocate space for our FPC file contents (which will not be freed)
	if (IOStream_GetType(ioPtr) == StreamMemory && value->buf_len == 0) {
		fpcPtr = (EsifFpcPtr)IOStream_GetMemoryBuffer(ioPtr); 
		if (NULL == fpcPtr) {
			ESIF_TRACE_ERROR("NULL buffer");
			goto exit;
		}
		fpcPtr  = (EsifFpcPtr) (((BytePtr) fpcPtr) + IOStream_GetOffset(ioPtr));
		numFpcBytesRead = fpcSize;
		ESIF_TRACE_DEBUG("Static vault size %u buf_ptr=0x%p\n", (int)numFpcBytesRead, fpcPtr);
		fpcIsStatic = ESIF_TRUE;
	} else {
		fpcPtr = (EsifFpcPtr)esif_ccb_malloc(fpcSize);
		if (NULL == fpcPtr) {
			ESIF_TRACE_ERROR("malloc failed to allocate %u bytes\n", fpcSize);
			goto exit;
		}
		ESIF_TRACE_DEBUG("File malloc size %u", fpcSize);

		// read file contents
		numFpcBytesRead = IOStream_Read(ioPtr, fpcPtr, fpcSize);
		if (numFpcBytesRead < fpcSize) {
			ESIF_TRACE_ERROR("Read short received %u of %u bytes\n", (int)numFpcBytesRead, fpcSize);
			goto exit;
		}

		ESIF_TRACE_DEBUG("File read size %u", (int)numFpcBytesRead);
	}
	ESIF_TRACE_DEBUG("\nDecode Length:  %u", fpcPtr->size);
	ESIF_TRACE_DEBUG("Code:           %s", fpcPtr->header.code);
	ESIF_TRACE_DEBUG("Ver Major:      %u", fpcPtr->header.ver_major);
	ESIF_TRACE_DEBUG("Ver Minor:      %u", fpcPtr->header.ver_minor);
	ESIF_TRACE_DEBUG("Name:           %s", fpcPtr->header.name);
	ESIF_TRACE_DEBUG("Description:    %s", fpcPtr->header.description);
	ESIF_TRACE_DEBUG("Type:           %s", fpcPtr->header.type);
	ESIF_TRACE_DEBUG("Bus Enumerator: %u", fpcPtr->header.bus_enum);
	ESIF_TRACE_DEBUG("ACPI Device:    %s", fpcPtr->header.acpi_device);
	ESIF_TRACE_DEBUG("ACPI Scope:     %s", fpcPtr->header.acpi_scope);
	ESIF_TRACE_DEBUG("ACPI Type:      %s", fpcPtr->header.acpi_type);
	ESIF_TRACE_DEBUG("ACPI UID:       %s", fpcPtr->header.acpi_UID);
	ESIF_TRACE_DEBUG("PCI Vendor ID:  %s", fpcPtr->header.pci_vendor_id);
	ESIF_TRACE_DEBUG("PCI Device ID:  %s", fpcPtr->header.pci_device_id);
	ESIF_TRACE_DEBUG("PCI Bus:        %s", fpcPtr->header.pci_bus);
	ESIF_TRACE_DEBUG("PCI Device:     %s", fpcPtr->header.pci_device);
	ESIF_TRACE_DEBUG("PCI Function:   %s", fpcPtr->header.pci_function);

	dspPtr->code_ptr = (EsifString)fpcPtr->header.name;
	dspPtr->bus_enum = (UInt8 *)&fpcPtr->header.bus_enum;
	dspPtr->type     = (EsifString)fpcPtr->header.type;
	dspPtr->ver_major_ptr  = (UInt8 *)&fpcPtr->header.ver_major;
	dspPtr->ver_minor_ptr  = (UInt8 *)&fpcPtr->header.ver_minor;
	dspPtr->acpi_device    = (EsifString)fpcPtr->header.acpi_device;
	dspPtr->acpi_scope     = (EsifString)fpcPtr->header.acpi_scope;
	dspPtr->acpi_type      = (EsifString)fpcPtr->header.acpi_type;
	dspPtr->acpi_uid       = (EsifString)fpcPtr->header.acpi_UID;
	dspPtr->vendor_id      = (EsifString)fpcPtr->header.pci_vendor_id;
	dspPtr->device_id      = (EsifString)fpcPtr->header.pci_device_id;
	dspPtr->pci_bus		= (EsifString)&fpcPtr->header.pci_bus;
	dspPtr->pci_bus_device = (EsifString)&fpcPtr->header.pci_device;
	dspPtr->pci_function   = (EsifString)&fpcPtr->header.pci_function;

	/* Assign Function Pointers */
	dspPtr->get_code = get_code;
	dspPtr->get_ver_minor     = get_ver_minor;
	dspPtr->get_ver_major     = get_ver_major;
	dspPtr->get_temp_tc1      = get_temp_c1;
	dspPtr->get_percent_xform      = get_percent_xform;

	dspPtr->insert_primitive  = insert_primitive;
	dspPtr->insert_algorithm  = insert_algorithm;
	dspPtr->insert_domain     = insert_domain;
	dspPtr->insert_event      = insert_event;
	dspPtr->get_primitive     = get_primitive;
	dspPtr->get_action = get_action;
	dspPtr->get_algorithm     = get_algorithm;
	dspPtr->get_domain = get_domain;
	dspPtr->get_event_by_type = get_event_by_type;
	dspPtr->get_event_by_guid = get_event_by_guid;
	dspPtr->init_fpc_iterator = init_fpc_iterator;
	dspPtr->get_next_fpc_domain = get_next_fpc_domain;


	dspPtr->get_domain_count = get_domain_count;

	rc = esif_fpc_load(fpcPtr, dspPtr);
	if (ESIF_OK == rc) {
		ESIF_TRACE_DEBUG("FPC %s load successfully", path);
	} else {
		ESIF_TRACE_DEBUG("Unable to load FPC %s, rc %s", path, esif_rc_str(rc));
		goto exit;
	}

	/* Lock DSP Manager */
	esif_ccb_write_lock(&g_dm.lock);

	/* Simple Table Lookup For Now. Scan Table And Find First Empty Slot */
	/* Empty slot indicated by AVAILABLE state                           */
	for (i = 0; i < MAX_DSP_MANAGER_ENTRY; i++) {
		if (NULL == g_dm.dme[i].dsp_ptr) {
			break;
		}
	}

	/* If No Available Slots Return */
	if (i >= MAX_DSP_MANAGER_ENTRY) {
		esif_ccb_write_unlock(&g_dm.lock);
		ESIF_TRACE_ERROR("No free dsp manager entry is available for %s\n", file_ptr->filename);
		goto exit;
	}

	/*
	** Take Slot
	*/
	g_dm.dme[i].dsp_ptr  = dspPtr;
	g_dm.dme[i].file_ptr = file_ptr;
	g_dm.dme[i].fpc_ptr  = (fpcIsStatic ? 0 : fpcPtr);
	g_dm.dme_count++;
	dspPtr = NULL;	// Prevent deallocate on exit
	fpcPtr = NULL;	// Prevent deallocate on exit

	esif_ccb_write_unlock(&g_dm.lock);
	rc = ESIF_OK;
	ESIF_TRACE_INFO("Create entry in dsp manager successfully for %s\n", file_ptr->filename);

exit:
	IOStream_Destroy(ioPtr);
	EsifData_Destroy(nameSpace);
	EsifData_Destroy(key);
	EsifData_Destroy(value);
	esif_dsp_destroy(dspPtr);
	if (!fpcIsStatic) {
		esif_ccb_free(fpcPtr);
	}
	return rc;
}
Exemplo n.º 22
0
static eEsifError EsifGetActionDelegateCnfg(
	const EsifUpDomainPtr domainPtr,
	const EsifDataPtr requestPtr,
	EsifDataPtr responsePtr
	)
{
	extern int g_shell_enabled; // ESIF Shell Enabled Flag
	extern Bool g_ws_restricted;// Web Server Restricted Mode Flag
	eEsifError rc = ESIF_OK;
	EsifPrimitiveTuple dcfgTuple = { GET_CONFIG_ACCESS_CONTROL_SUR, 0, 255 };
	EsifPrimitiveTuple gddvTuple = { GET_CONFIG_DATAVAULT_SUR, 0, 255 };
	EsifData dcfgData = { ESIF_DATA_UINT32, NULL, ESIF_DATA_ALLOCATE, 0 };
	EsifData gddvData = { ESIF_DATA_AUTO, NULL, ESIF_DATA_ALLOCATE, 0 };

	ESIF_ASSERT(NULL != domainPtr);
	ESIF_ASSERT(NULL != requestPtr);

	UNREFERENCED_PARAMETER(responsePtr); // Not currently used by DPTF

	dcfgTuple.domain = domainPtr->domain;
	gddvTuple.domain = domainPtr->domain;

	// Execute DCFG to read Access Control List Bitmask from BIOS, if it exists
	rc = EsifUp_ExecutePrimitive(domainPtr->upPtr, &dcfgTuple, requestPtr, &dcfgData);
	if (rc == ESIF_OK && dcfgData.buf_ptr != NULL && dcfgData.buf_len >= sizeof(UInt32)) {
		DCfgOptions newmask = { .asU32 = *(UInt32 *)dcfgData.buf_ptr };
		DCfg_Set(newmask);

		ESIF_TRACE_INFO("DCFG Loaded: 0x%08X\n", newmask.asU32);

		// Disable ESIF Shell if Access Control forbids it
		if (DCfg_Get().opt.ShellAccessControl) {
			g_shell_enabled = 0;
		}

		// Stop Web Server (if Started) if Restricted or Generic Access Control forbids it
		if (EsifWebIsStarted() && 
			((!g_ws_restricted && DCfg_Get().opt.GenericUIAccessControl)|| 
			 (g_ws_restricted && DCfg_Get().opt.RestrictedUIAccessControl)) ) {
			EsifWebStop();
		}
	}

	// Execute GDDV to read DataVault from BIOS, if it exists
	rc = EsifUp_ExecutePrimitive(domainPtr->upPtr, &gddvTuple, requestPtr, &gddvData);
	if (rc != ESIF_OK) {
		// Always Return OK if no ESIF_LF or GDDV object in BIOS
		if (rc == ESIF_E_NO_LOWER_FRAMEWORK || rc == ESIF_E_ACPI_OBJECT_NOT_FOUND) {
			rc = ESIF_OK;
		}
	}
	else {
		char *dv_name = "__merge"; // Temporary DV Name
		DataVaultPtr DB = DataBank_GetNameSpace(g_DataBankMgr, dv_name);
		if (DB != NULL) {
			DataBank_CloseNameSpace(g_DataBankMgr, dv_name);
		}
		DB = DataBank_OpenNameSpace(g_DataBankMgr, dv_name);

		// Load Datavault into temporary namespace. DV may or may not be preceded by a variant
		if (DB) {
			u32 skipbytes = 0;
			void *buffer = NULL;

			//
			// This is in place to resolve a static code analysis issue.
			// This should never happen if EsifUp_ExecutePrimitive is successful above.
			//
			if (NULL == gddvData.buf_ptr) {
				DataBank_CloseNameSpace(g_DataBankMgr, dv_name);
				ESIF_TRACE_DEBUG("No data returned for BIOS datavault.\n");
				goto exit;
			}

			skipbytes = (memcmp(gddvData.buf_ptr, "\xE5\x1F", 2) == 0 ? 0 : sizeof(union esif_data_variant));
			buffer = esif_ccb_malloc(gddvData.data_len);
			if (NULL == buffer) {
				DataBank_CloseNameSpace(g_DataBankMgr, dv_name);
				ESIF_TRACE_DEBUG("Unable to allocate memory\n");
				rc = ESIF_E_NO_MEMORY;
				goto exit;
			}

			esif_ccb_memcpy(buffer, (u8*)gddvData.buf_ptr + skipbytes, gddvData.data_len - skipbytes);
			IOStream_SetMemory(DB->stream, buffer, gddvData.data_len - skipbytes);

			if ((rc = DataVault_ReadVault(DB)) != ESIF_OK) {
				DataBank_CloseNameSpace(g_DataBankMgr, dv_name);
				ESIF_TRACE_DEBUG("Unable to Open DataVault: %s\n", esif_rc_str(rc));
				rc = ESIF_OK;
			}
			else {
				EsifDataPtr data_nspace = NULL;
				EsifDataPtr data_key = NULL;
				EsifDataPtr data_targetdv = NULL;
				esif_flags_t options = 0; // NOPERSIST
				esif_string keyspec = "*"; // Merge All Keys
				esif_string targetdv = g_DataVaultDefault;

				DB->flags |= (ESIF_SERVICE_CONFIG_READONLY);

				// Merge Contents into Default DataVault
				data_nspace = EsifData_CreateAs(ESIF_DATA_STRING, dv_name, 0, ESIFAUTOLEN);
				data_targetdv = EsifData_CreateAs(ESIF_DATA_STRING, targetdv, 0, ESIFAUTOLEN);
				data_key = EsifData_CreateAs(ESIF_DATA_STRING, keyspec, 0, ESIFAUTOLEN);
				if (data_nspace == NULL || data_key == NULL || data_targetdv == NULL) {
					rc = ESIF_E_NO_MEMORY;
				}
				else {
					rc = EsifConfigCopy(data_nspace, data_targetdv, data_key, options, ESIF_FALSE, NULL);
				}

				ESIF_TRACE_INFO("GDDV Loaded: %d bytes, %d keys => %s.dv [%s]\n",
					(int)IOStream_GetSize(DB->stream),
					DataCache_GetCount(DB->cache),
					targetdv,
					esif_rc_str(rc));

				EsifData_Destroy(data_nspace);
				EsifData_Destroy(data_key);
				EsifData_Destroy(data_targetdv);
				DataBank_CloseNameSpace(g_DataBankMgr, dv_name);
			}
			esif_ccb_free(buffer);
		}
	}
exit:
	esif_ccb_free(dcfgData.buf_ptr);
	esif_ccb_free(gddvData.buf_ptr);
	return rc;
}
Exemplo n.º 23
0
/* 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;
}
Exemplo n.º 24
0
static eEsifError RegisterParticipant(const EsifParticipantIfacePtr piPtr)
{
	eEsifError rc    = ESIF_OK;
	EsifUpPtr up_ptr = NULL;
	UInt8 temp = 0;
	char guid_str[ESIF_GUID_PRINT_SIZE];
	EsifString dsp_code = "";

	UNREFERENCED_PARAMETER(guid_str);

	ESIF_ASSERT(piPtr != NULL);
	ESIF_TRACE_INFO(
		"\n"
		"=======================================================\n"
		"ESIF CREATE CONJURE PARTICIPANT:\n"
		"=======================================================\n"
		"Version:        %d\n"
		"Class:          %s\n"
		"Enumerator:     %s(%u)\n"
		"Flags:          0x%08x\n"
		"Name:           %s\n"
		"Description:    %s\n"
		"Driver Name:    %s\n"
		"Device Name:    %s\n"
		"Device Path:    %s\n"
		"Object ID:      %s\n\n",
		piPtr->version,
		esif_guid_print(&piPtr->class_guid, guid_str),
		esif_participant_enum_str(piPtr->enumerator),
		piPtr->enumerator,
		piPtr->flags,
		piPtr->name,
		piPtr->desc,
		piPtr->driver_name,
		piPtr->device_name,
		piPtr->device_path,
		piPtr->object_id);

	if (EsifUpManagerDoesAvailableParticipantExistByName(piPtr->name)) {
		ESIF_TRACE_WARN("Participant %s has already existed in upper framework\n", piPtr->name);
		rc     = ESIF_E_UNSPECIFIED;
		up_ptr = NULL;
		goto exit;
	}

	ESIF_TRACE_DEBUG("Create Participant\n");
	up_ptr = EsifUpManagerCreateParticipant(eParticipantOriginUF, &temp, piPtr);
	ESIF_TRACE_DEBUG("Create Participant up_ptr %p\n", up_ptr);

	/* Assign DSP Now */
	if (NULL == up_ptr) {
		rc = ESIF_E_NO_MEMORY;
		goto exit;
	}

	dsp_code = esif_uf_dm_select_dsp(eParticipantOriginUF, piPtr);
	if (NULL == dsp_code) {
		ESIF_TRACE_ERROR("Unknown dsp name %s\n", piPtr->name);
		rc = ESIF_E_NEED_DSP;
		goto exit;
	}
	ESIF_TRACE_DEBUG("dsp_code %s\n", dsp_code);

	up_ptr->fDspPtr = esif_uf_dm_select_dsp_by_code(dsp_code);
	if (NULL == up_ptr->fDspPtr) {
		ESIF_TRACE_ERROR("Missed DSP Lookup %s\n", dsp_code);
		rc = ESIF_E_NEED_DSP;
		goto exit;
	}
	/* Report the participant to the apps */
	EsifAppMgrCreateCreateParticipantInAllApps(up_ptr);

	ESIF_TRACE_DEBUG("Hit DSP Lookup %s\n", up_ptr->fDspPtr->code_ptr);
	up_ptr = NULL;	/* Indicate the participant should not be destroyed. */

exit:

	/*
	 * If up_ptr is non-NULL at this point, indicates a failure and the
	 * participant must be disabled in the manager.  If everything is
	 * successful, up_ptr will be set to NULL above.
	 */
	if (up_ptr != NULL) {
		ESIF_TRACE_WARN("Unregister participant in UP manager due to participant data creation failure\n");
		EsifUpManagerUnregisterParticipant(eParticipantOriginUF, up_ptr);
	}
	return rc;
}