⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 tz.c

📁 该文件是rt_linux
💻 C
📖 第 1 页 / 共 2 页
字号:
 * * FUNCTION:    tz_add_device * ****************************************************************************/acpi_statustz_add_device (	BM_HANDLE               device_handle,	void                    **context){	acpi_status             status = AE_OK;	TZ_CONTEXT              *tz = NULL;	BM_DEVICE		*device = NULL;	acpi_handle             tmp_handle = NULL;	static u32		zone_count = 0;	FUNCTION_TRACE("tz_add_device");	ACPI_DEBUG_PRINT ((ACPI_DB_INFO, "Adding thermal zone [%02x].\n", device_handle));	if (!context || *context) {		ACPI_DEBUG_PRINT ((ACPI_DB_WARN, "Invalid context for device [%02x].\n", device_handle));		return_ACPI_STATUS(AE_BAD_PARAMETER);	}	/*	 * Get information on this device.	 */	status = bm_get_device_info(device_handle, &device);	if (ACPI_FAILURE(status)) {		return_ACPI_STATUS(status);	}	/*	 * Allocate a new Thermal Zone device.	 */	tz = acpi_os_callocate(sizeof(TZ_CONTEXT));	if (!tz) {		return_ACPI_STATUS(AE_NO_MEMORY);	}	tz->device_handle = device->handle;	tz->acpi_handle = device->acpi_handle;	/* TBD: How to manage 'uid' when zones are Pn_p? */	sprintf(tz->uid, "%d", zone_count++);	/*	 * Temperature:	 * ------------	 * Make sure we can read the zone's current temperature (_TMP).	 * If we can't, there's no use in doing any policy (abort).	 */	status = tz_get_temperature(tz);	if (ACPI_FAILURE(status))		goto end;	/*	 * Polling Frequency:	 * ------------------	 * If _TZP doesn't exist use the OS default polling frequency.	 */	status = bm_evaluate_simple_integer(tz->acpi_handle, "_TZP", &(tz->policy.polling_freq));	if (ACPI_FAILURE(status)) {		tz->policy.polling_freq = TZP;	}	status = AE_OK;	/*	 * Cooling Preference:	 * -------------------	 * Default to ACTIVE (noisy) cooling until policy decides otherwise.	 * Note that _SCP is optional.	 */	tz_set_cooling_preference(tz, TZ_COOLING_MODE_ACTIVE);	/*	 * Start Policy:	 * -------------	 * Thermal policy is included in the kernel (this driver) because	 * of the critical role it plays in avoiding nuclear meltdown. =O	 */	status = tz_policy_add_device(tz);	if (ACPI_FAILURE(status))		goto end;	status = tz_osl_add_device(tz);	if (ACPI_FAILURE(status))		goto end;	*context = tz;	tz_print(tz);end:	if (ACPI_FAILURE(status))		acpi_os_free(tz);	return_ACPI_STATUS(status);}/**************************************************************************** * * FUNCTION:    tz_remove_device * ****************************************************************************/acpi_statustz_remove_device (	void			**context){	acpi_status		status = AE_OK;	TZ_CONTEXT		*tz = NULL;	FUNCTION_TRACE("tz_remove_device");	if (!context || !*context) {		return_ACPI_STATUS(AE_BAD_PARAMETER);	}	tz = (TZ_CONTEXT*)(*context);	ACPI_DEBUG_PRINT ((ACPI_DB_INFO, "Removing thermal zone [%02x].\n", tz->device_handle));	status = tz_osl_remove_device(tz);	/*	 * Remove Policy:	 * --------------	 * TBD: Move all thermal zone policy to user-mode daemon...	 */	status = tz_policy_remove_device(tz);	if (ACPI_FAILURE(status)) {		return_ACPI_STATUS(status);	}	acpi_os_free(tz);	return_ACPI_STATUS(status);}/**************************************************************************** *                            External Functions ****************************************************************************//**************************************************************************** * * FUNCTION:    tz_initialize * ****************************************************************************/acpi_statustz_initialize (void){	acpi_status             status = AE_OK;	BM_DEVICE_ID		criteria;	BM_DRIVER		driver;	FUNCTION_TRACE("tz_initialize");	memset(&criteria, 0, sizeof(BM_DEVICE_ID));	memset(&driver, 0, sizeof(BM_DRIVER));	/*	 * Register driver for thermal zone devices.	 */	criteria.type = BM_TYPE_THERMAL_ZONE;	driver.notify = &tz_notify;	driver.request = &tz_request;	status = bm_register_driver(&criteria, &driver);	return_ACPI_STATUS(status);}/**************************************************************************** * * FUNCTION:    tz_terminate * ****************************************************************************/acpi_statustz_terminate (void){	acpi_status             status = AE_OK;	BM_DEVICE_ID		criteria;	BM_DRIVER		driver;	FUNCTION_TRACE("tz_terminate");	memset(&criteria, 0, sizeof(BM_DEVICE_ID));	memset(&driver, 0, sizeof(BM_DRIVER));	/*	 * Unregister driver for thermal zone devices.	 */	criteria.type = BM_TYPE_THERMAL_ZONE;	driver.notify = &tz_notify;	driver.request = &tz_request;	status = bm_unregister_driver(&criteria, &driver);	return_ACPI_STATUS(status);}/**************************************************************************** * * FUNCTION:    tz_notify * ****************************************************************************/acpi_statustz_notify (	BM_NOTIFY               notify_type,	BM_HANDLE               device_handle,	void                    **context){	acpi_status             status = AE_OK;	TZ_CONTEXT		*tz = NULL;	FUNCTION_TRACE("tz_notify");	if (!context) {		return_ACPI_STATUS(AE_BAD_PARAMETER);	}	tz = (TZ_CONTEXT*)*context;	switch (notify_type) {	case BM_NOTIFY_DEVICE_ADDED:		status = tz_add_device(device_handle, context);		break;	case BM_NOTIFY_DEVICE_REMOVED:		status = tz_remove_device(context);		break;	case TZ_NOTIFY_TEMPERATURE_CHANGE:		ACPI_DEBUG_PRINT ((ACPI_DB_INFO, "Temperature (_TMP) change event detected.\n"));		tz_policy_check(*context);		status = tz_get_temperature(tz);		if (ACPI_SUCCESS(status)) {			status = tz_osl_generate_event(notify_type, tz);		}		break;	case TZ_NOTIFY_THRESHOLD_CHANGE:		ACPI_DEBUG_PRINT ((ACPI_DB_INFO, "Threshold (_SCP) change event detected.\n"));		status = tz_policy_remove_device(tz);		if (ACPI_SUCCESS(status)) {			status = tz_policy_add_device(tz);		}		status = tz_osl_generate_event(notify_type, tz);		break;	case TZ_NOTIFY_DEVICE_LISTS_CHANGE:		ACPI_DEBUG_PRINT ((ACPI_DB_INFO, "Device lists (_ALx, _PSL, _TZD) change event detected.\n"));		status = tz_policy_remove_device(tz);		if (ACPI_SUCCESS(status)) {			status = tz_policy_add_device(tz);		}		status = tz_osl_generate_event(notify_type, tz);		break;	default:		status = AE_SUPPORT;		break;	}	return_ACPI_STATUS(status);}/**************************************************************************** * * FUNCTION:    tz_request * ****************************************************************************/acpi_statustz_request (	BM_REQUEST		*request,	void                    *context){	acpi_status             status = AE_OK;	TZ_CONTEXT              *tz = NULL;	FUNCTION_TRACE("tz_request");	/*	 * Must have a valid request structure and context.	 */	if (!request || !context) {		return_ACPI_STATUS(AE_BAD_PARAMETER);	}	tz = (TZ_CONTEXT*)context;	/*	 * Handle request:	 * ---------------	 */	switch (request->command) {	default:		status = AE_SUPPORT;		break;	}	request->status = status;	return_ACPI_STATUS(status);}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -