patch-2.4.14 linux/drivers/acpi/ospm/thermal/tzpolicy.c

Next file: linux/drivers/acpi/parser/psargs.c
Previous file: linux/drivers/acpi/ospm/thermal/tz_osl.c
Back to the patch index
Back to the overall index

diff -u --recursive --new-file v2.4.13/linux/drivers/acpi/ospm/thermal/tzpolicy.c linux/drivers/acpi/ospm/thermal/tzpolicy.c
@@ -1,7 +1,7 @@
 /****************************************************************************
  *
  * Module Name: tzpolicy.c -
- *   $Revision: 28 $
+ *   $Revision: 30 $
  *
  ****************************************************************************/
 
@@ -24,13 +24,10 @@
  */
 
 /*
- * TBD: 1. Move to user-space!
- *	2. Support ACPI 2.0 items (e.g. _TZD, _HOT).
- *      3. Support performance-limit control for non-processor devices
+ * TBD: 1. Support performance-limit control for non-processor devices
  *         (those listed in _TZD, e.g. graphics).
  */
 
-/* TBD: Linux specific */
 #include <linux/proc_fs.h>
 #include <linux/sysctl.h>
 #include <linux/pm.h>
@@ -48,8 +45,6 @@
  *                                  Globals
  ****************************************************************************/
 
-extern int TZP;
-
 void
 tz_policy_run (
 	unsigned long           data);
@@ -75,12 +70,10 @@
 
 	status = bm_request(&request);
 
-	if (ACPI_FAILURE(status)) {
+	if (ACPI_FAILURE(status))
 		return status;
-	}
-	else {
+	else
 		return request.status;
-	}
 }
 
 
@@ -102,14 +95,44 @@
 {
 	FUNCTION_TRACE("tz_policy_critical");
 
-	if (!tz || !tz->policy.critical.threshold) {
+	if (!tz) {
 		return_ACPI_STATUS(AE_BAD_PARAMETER);
 	}
 
-	if (tz->policy.temperature >=
-		tz->policy.critical.threshold->temperature) {
-		ACPI_DEBUG_PRINT ((ACPI_DB_WARN, "Critical threshold reached - shutting down system.\n"));
-		/* TBD:	Need method for calling 'halt' - OSL function? */
+	if (tz->policy.temperature >= tz->policy.thresholds.critical.temperature) {
+		ACPI_DEBUG_PRINT ((ACPI_DB_WARN, "Critical (S5) threshold reached.\n"));
+		/* TBD:	Need method for shutting down system. */
+	}
+
+	return_ACPI_STATUS(AE_OK);
+}
+
+
+/****************************************************************************
+ *
+ * FUNCTION:    tz_policy_hot
+ *
+ * PARAMETERS:
+ *
+ * RETURN:
+ *
+ * DESCRIPTION:
+ *
+ ****************************************************************************/
+
+acpi_status
+tz_policy_hot(
+	TZ_CONTEXT		*tz)
+{
+	FUNCTION_TRACE("tz_policy_hot");
+
+	if (!tz || !tz->policy.thresholds.hot.is_valid) {
+		return_ACPI_STATUS(AE_BAD_PARAMETER);
+	}
+
+	if (tz->policy.temperature >= tz->policy.thresholds.hot.temperature) {
+		ACPI_DEBUG_PRINT ((ACPI_DB_WARN, "Critical (S4) threshold reached.\n"));
+		/* TBD:	Need method for invoking OS-level critical suspend. */
 	}
 
 	return_ACPI_STATUS(AE_OK);
@@ -132,20 +155,20 @@
 tz_policy_passive(
 	TZ_CONTEXT		*tz)
 {
-	TZ_PASSIVE_POLICY	*passive = NULL;
+	TZ_PASSIVE_THRESHOLD	*passive = NULL;
 	static u32		last_temperature = 0;
 	s32			trend = 0;
 	u32			i = 0;
 
 	FUNCTION_TRACE("tz_policy_passive");
 
-	if (!tz || !tz->policy.passive.threshold) {
+	if (!tz || !tz->policy.thresholds.passive.is_valid) {
 		return_ACPI_STATUS(AE_BAD_PARAMETER);
 	}
 
-	passive = &(tz->policy.passive);
+	passive = &(tz->policy.thresholds.passive);
 
-	if (tz->policy.temperature >= passive->threshold->temperature) {
+	if (tz->policy.temperature >= passive->temperature) {
 		/*
 		 * Thermal trend?
 		 * --------------
@@ -153,15 +176,8 @@
 		 * Specification), calculate the current thermal trend
 		 * (a.k.a. performance delta).
 		 */
-		trend = passive->tc1 *
-			(tz->policy.temperature - last_temperature) +
-			passive->tc2 *
-			(tz->policy.temperature - passive->threshold->temperature);
-
-		ACPI_DEBUG_PRINT ((ACPI_DB_INFO, "trend[%d] = TC1[%d]*(temp[%d]-last[%d]) + TC2[%d]*(temp[%d]-passive[%d])\n",
-			trend, passive->tc1, tz->policy.temperature,
-			last_temperature, passive->tc2, tz->policy.temperature,
-			passive->threshold->temperature));
+		trend = passive->tc1 * (tz->policy.temperature - last_temperature) + passive->tc2 * (tz->policy.temperature - passive->temperature);
+		ACPI_DEBUG_PRINT ((ACPI_DB_INFO, "trend[%d] = TC1[%d]*(temp[%d]-last[%d]) + TC2[%d]*(temp[%d]-passive[%d])\n", trend, passive->tc1, tz->policy.temperature, last_temperature, passive->tc2, tz->policy.temperature, passive->temperature));
 
 		last_temperature = tz->policy.temperature;
 
@@ -172,11 +188,8 @@
 		 * cooling devices (processors).
 		 */
 		if (trend > 0) {
-			for (i=0; i<passive->threshold->cooling_devices.count; i++) {
-				set_performance_limit(
-					passive->threshold->cooling_devices.handles[i],
-					PR_PERF_DEC);
-			}
+			for (i=0; i<passive->devices.count; i++)
+				set_performance_limit(passive->devices.handles[i], PR_PERF_DEC);
 		}
 		/*
 		 * Cooling Off?
@@ -185,11 +198,8 @@
 		 * cooling devices (processors).
 		 */
 		else if (trend < 0) {
-			for (i=0; i<passive->threshold->cooling_devices.count; i++) {
-				set_performance_limit(
-					passive->threshold->cooling_devices.handles[i],
-					PR_PERF_INC);
-			}
+			for (i=0; i<passive->devices.count; i++)
+				set_performance_limit(passive->devices.handles[i], PR_PERF_INC);
 		}
 	}
 
@@ -214,21 +224,20 @@
 	TZ_CONTEXT              *tz)
 {
 	acpi_status             status = AE_OK;
-	TZ_THRESHOLD            *active = NULL;
+	TZ_ACTIVE_THRESHOLD	*active = NULL;
 	u32                     i,j = 0;
 
 	FUNCTION_TRACE("tz_policy_active");
 
-	if (!tz || !tz->policy.active.threshold) {
+	if (!tz || !tz->policy.thresholds.active[0].is_valid) {
 		return_ACPI_STATUS(AE_BAD_PARAMETER);
 	}
 
-	for (i = 0; i < TZ_MAX_ACTIVE_THRESHOLDS; i++) {
+	for (i=0; i<TZ_MAX_ACTIVE_THRESHOLDS; i++) {
 
-		active = tz->policy.active.threshold[i];
-		if (!active) {
+		active = &(tz->policy.thresholds.active[i]);
+		if (!active || !active->is_valid)
 			break;
-		}
 
 		/*
 		 * Above Threshold?
@@ -236,24 +245,17 @@
 		 * If not already enabled, turn ON all cooling devices
 		 * associated with this active threshold.
 		 */
-		if ((tz->policy.temperature >= active->temperature) &&
-			(active->cooling_state != TZ_COOLING_ENABLED)) {
-
-			for (j = 0; j < active->cooling_devices.count; j++) {
-
-				status = bm_set_device_power_state(
-					active->cooling_devices.handles[j],
-					ACPI_STATE_D0);
-
+		if ((tz->policy.temperature >= active->temperature) && (active->cooling_state != TZ_COOLING_ENABLED)) {
+			for (j = 0; j < active->devices.count; j++) {
+				status = bm_set_device_power_state(active->devices.handles[j], ACPI_STATE_D0);
 				if (ACPI_SUCCESS(status)) {
-					ACPI_DEBUG_PRINT ((ACPI_DB_INFO, "Cooling device [%02x] now ON.\n", active->cooling_devices.handles[j]));
+					ACPI_DEBUG_PRINT ((ACPI_DB_INFO, "Cooling device [%02x] now ON.\n", active->devices.handles[j]));
 				}
 				else {
-					ACPI_DEBUG_PRINT ((ACPI_DB_WARN, "Unable to turn ON cooling device [%02x].\n", active->cooling_devices.handles[j]));
+					ACPI_DEBUG_PRINT ((ACPI_DB_WARN, "Unable to turn ON cooling device [%02x].\n", active->devices.handles[j]));
 				}
 			}
-
-			active->cooling_state = TZ_COOLING_ENABLED;
+  			active->cooling_state = TZ_COOLING_ENABLED;
 		}
 		/*
 		 * Below Threshold?
@@ -265,21 +267,15 @@
 		 * during the first pass.
 		 */
 		else if (active->cooling_state != TZ_COOLING_DISABLED) {
-
-			for (j = 0; j < active->cooling_devices.count; j++) {
-
-				status = bm_set_device_power_state(
-					active->cooling_devices.handles[j],
-					ACPI_STATE_D3);
-
+			for (j = 0; j < active->devices.count; j++) {
+				status = bm_set_device_power_state(active->devices.handles[j], ACPI_STATE_D3);
 				if (ACPI_SUCCESS(status)) {
-					ACPI_DEBUG_PRINT ((ACPI_DB_INFO, "Cooling device [%02x] now OFF.\n", active->cooling_devices.handles[j]));
+					ACPI_DEBUG_PRINT ((ACPI_DB_INFO, "Cooling device [%02x] now OFF.\n", active->devices.handles[j]));
 				}
 				else {
-					ACPI_DEBUG_PRINT ((ACPI_DB_INFO, "Unable to turn OFF cooling device [%02x].\n", active->cooling_devices.handles[j]));
+					ACPI_DEBUG_PRINT ((ACPI_DB_INFO, "Unable to turn OFF cooling device [%02x].\n", active->devices.handles[j]));
 				}
 			}
-
 			active->cooling_state = TZ_COOLING_DISABLED;
 		}
 	}
@@ -308,6 +304,8 @@
 {
 	acpi_status             status = AE_OK;
 	TZ_CONTEXT              *tz = NULL;
+	TZ_POLICY		*policy = NULL;
+	TZ_THRESHOLDS		*thresholds = NULL;
 	u32                     previous_temperature = 0;
 	u32                     previous_state = 0;
 	u32                     active_index = 0;
@@ -322,6 +320,8 @@
 	}
 
 	tz = (TZ_CONTEXT*)context;
+	policy = &(tz->policy);
+	thresholds = &(tz->policy.thresholds);
 
 	/*
 	 * Preserve Previous State:
@@ -334,7 +334,7 @@
 	 * Get Temperature:
 	 * ----------------
 	 */
-	status = tz_get_temperature(tz, &(tz->policy.temperature));
+	status = tz_get_temperature(tz);
 	if (ACPI_FAILURE(status)) {
 		return_VOID;
 	}
@@ -343,32 +343,30 @@
 	 * Calculate State:
 	 * ----------------
 	 */
-	tz->policy.state = TZ_STATE_OK;
+	policy->state = TZ_STATE_OK;
 
 	/* Critical? */
-	if ((tz->policy.critical.threshold) &&
-		(tz->policy.temperature >= tz->policy.critical.threshold->temperature)) {
-		tz->policy.state |= TZ_STATE_CRITICAL;
-	}
+	if (policy->temperature >= thresholds->critical.temperature)
+		policy->state |= TZ_STATE_CRITICAL;
+
+	/* Hot? */
+	if ((thresholds->hot.is_valid) &&  (policy->temperature >= thresholds->hot.temperature))
+		policy->state |= TZ_STATE_CRITICAL;
 
 	/* Passive? */
-	if ((tz->policy.passive.threshold) &&
-		(tz->policy.temperature >= tz->policy.passive.threshold->temperature)) {
-		tz->policy.state |= TZ_STATE_PASSIVE;
-	}
+	if ((thresholds->passive.is_valid) && (policy->temperature >= thresholds->passive.temperature))
+		policy->state |= TZ_STATE_PASSIVE;
 
 	/* Active? */
-	if (tz->policy.active.threshold[0]) {
-		for (i=0; i<tz->policy.active.threshold_count; i++) {
-			if ((tz->policy.active.threshold[i]) &&
-				(tz->policy.temperature >= tz->policy.active.threshold[i]->temperature)) {
-			    tz->policy.state |= TZ_STATE_ACTIVE;
-			    if (tz->policy.active.threshold[i]->index > active_index) {
-				    active_index = tz->policy.active.threshold[i]->index;
-			    }
+	if (thresholds->active[0].is_valid) {
+		for (i=0; i<TZ_MAX_ACTIVE_THRESHOLDS; i++) {
+			if ((thresholds->active[i].is_valid) && (policy->temperature >= thresholds->active[i].temperature)) {
+				policy->state |= TZ_STATE_ACTIVE;
+				if (i > active_index)
+					active_index = i;
 			}
 		}
-		tz->policy.state |= active_index;
+		policy->state |= active_index;
 	}
 
 	/*
@@ -379,17 +377,14 @@
 	 * out of' a policy state (e.g. to allow fans to be turned off);
 	 * thus we must preserve the previous state.
 	 */
-	if (tz->policy.state & TZ_STATE_CRITICAL) {
+	if (policy->state & TZ_STATE_CRITICAL)
 		tz_policy_critical(tz);
-	}
-	if ((tz->policy.state & TZ_STATE_PASSIVE) ||
-		(previous_state & TZ_STATE_PASSIVE)) {
+	if (policy->state & TZ_STATE_HOT)
+		tz_policy_hot(tz);
+	if ((policy->state & TZ_STATE_PASSIVE) || (previous_state & TZ_STATE_PASSIVE))
 		tz_policy_passive(tz);
-	}
-	if ((tz->policy.state & TZ_STATE_ACTIVE) ||
-		(previous_state & TZ_STATE_ACTIVE)) {
+	if ((policy->state & TZ_STATE_ACTIVE) || (previous_state & TZ_STATE_ACTIVE))
 		tz_policy_active(tz);
-	}
 
 	/*
 	 * Calculate Sleep Time:
@@ -400,42 +395,33 @@
 	 * a thermal event occurs -- e.g. never poll).  Note that _TSP
 	 * and _TZD values are given in 1/10th seconds.
 	 */
-	if (tz->policy.state & TZ_STATE_PASSIVE) {
-		sleep_time = tz->policy.passive.tsp * 100;
-	}
-	else if (tz->policy.polling_freq > 0) {
-		sleep_time = tz->policy.polling_freq * 100;
-	}
-	else {
+	if (policy->state & TZ_STATE_PASSIVE)
+		sleep_time = thresholds->passive.tsp * 100;
+	else if (policy->polling_freq > 0)
+		sleep_time = policy->polling_freq * 100;
+	else
 		sleep_time = WAIT_FOREVER;
-	}
 
-#ifdef ACPI_DEBUG
-	ACPI_DEBUG_PRINT ((ACPI_DB_INFO, "Thermal_zone[%02x]: temperature[%d] state[%08x]\n", tz->device_handle, tz->policy.temperature, tz->policy.state));
+	ACPI_DEBUG_PRINT ((ACPI_DB_INFO, "Thermal_zone[%02x]: temperature[%d] state[%08x]\n", tz->device_handle, policy->temperature, policy->state));
 	ACPI_DEBUG_PRINT ((ACPI_DB_INFO, "Scheduling next poll in [%d]ms.\n", sleep_time));
-#endif /*ACPI_DEBUG*/
 
 	/*
 	 * Schedule Next Poll:
 	 * -------------------
 	 */
 	if (sleep_time < WAIT_FOREVER) {
-		if (timer_pending(&(tz->policy.timer))) {
-			mod_timer(&(tz->policy.timer),
-				(HZ*sleep_time)/1000);
-		}
+		if (timer_pending(&(policy->timer)))
+			mod_timer(&(policy->timer), (HZ*sleep_time)/1000);
 		else {
-			tz->policy.timer.data = (u32)tz;
-			tz->policy.timer.function = tz_policy_run;
-			tz->policy.timer.expires =
-				jiffies + (HZ*sleep_time)/1000;
-			add_timer(&(tz->policy.timer));
+			policy->timer.data = (u32)tz;
+			policy->timer.function = tz_policy_run;
+			policy->timer.expires = jiffies + (HZ*sleep_time)/1000;
+			add_timer(&(policy->timer));
 		}
 	}
 	else {
-		if (timer_pending(&(tz->policy.timer))) {
-			del_timer(&(tz->policy.timer));
-		}
+		if (timer_pending(&(policy->timer)))
+			del_timer(&(policy->timer));
 	}
 
 	return_VOID;
@@ -454,6 +440,7 @@
  *
  ****************************************************************************/
 
+
 void
 tz_policy_run (
 	unsigned long           data)
@@ -472,8 +459,7 @@
 	 * -----------------------------
 	 * Note that all Linux kernel timers run at interrupt-level (ack!).
 	 */
-	status = acpi_os_queue_for_execution(OSD_PRIORITY_GPE,
-		tz_policy_check, (void*)data);
+	status = acpi_os_queue_for_execution(OSD_PRIORITY_GPE,  tz_policy_check, (void*)data);
 	if (ACPI_FAILURE(status)) {
 		ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, "Error invoking thermal policy.\n"));
 	}
@@ -499,7 +485,7 @@
 	TZ_CONTEXT		*tz)
 {
 	acpi_status             status = AE_OK;
-	TZ_THRESHOLD            *threshold = NULL;
+	TZ_THRESHOLDS           *thresholds = NULL;
 	u32                     i,j = 0;
 
 	FUNCTION_TRACE("tz_policy_add_device");
@@ -511,36 +497,10 @@
 	ACPI_DEBUG_PRINT ((ACPI_DB_INFO, "Adding policy for thermal zone [%02x].\n", tz->device_handle));
 
 	/*
-	 * 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, &(tz->policy.temperature));
-	if (ACPI_FAILURE(status)) {
-		return_ACPI_STATUS(status);
-	}
-
-	/*
-	 * Polling Frequency:
-	 * ------------------
-	 * If a _TZP object 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;
-
-	/*
 	 * Get Thresholds:
 	 * ---------------
-	 * Get all of the zone's thresholds, parse, and organize for
-	 * later use.
 	 */
-	status = tz_get_thresholds(tz, &(tz->policy.threshold_list));
+	status = tz_get_thresholds(tz);
 	if (ACPI_FAILURE(status)) {
 		return_ACPI_STATUS(status);
 	}
@@ -549,70 +509,17 @@
 	 * Initialize Policies:
 	 * --------------------
 	 */
-	for (i = 0; i < tz->policy.threshold_list.count; i++) {
-
-		threshold = &(tz->policy.threshold_list.thresholds[i]);
-
-		switch (threshold->type) {
-
-		case TZ_THRESHOLD_CRITICAL:
-			tz->policy.critical.threshold = threshold;
-			break;
-
-		case TZ_THRESHOLD_PASSIVE:
-
-			/*
-			 * Set thermal performance limit on all processors
-			 * to max.
-			 */
-			for (j=0; j<threshold->cooling_devices.count; j++) {
-				set_performance_limit(
-					threshold->cooling_devices.handles[j],
-					PR_PERF_MAX);
-			}
-
-			/*
-			 * Get passive cooling constants.
-			 */
-			status = bm_evaluate_simple_integer(tz->acpi_handle,
-				"_TC1", &(tz->policy.passive.tc1));
-			if (ACPI_FAILURE(status)) {
-				break;
-			}
-
-			status = bm_evaluate_simple_integer(tz->acpi_handle,
-				"_TC2", &(tz->policy.passive.tc2));
-			if (ACPI_FAILURE(status)) {
-				break;
-			}
-
-			status = bm_evaluate_simple_integer(tz->acpi_handle,
-				"_TSP", &(tz->policy.passive.tsp));
-			if (ACPI_FAILURE(status)) {
-				break;
-			}
-
-			tz->policy.passive.threshold = threshold;
-
-			tz_policy_passive(tz);
-
-			break;
-
-		case TZ_THRESHOLD_ACTIVE:
-			tz->policy.active.threshold[threshold->index] = threshold;
-			tz_policy_active(tz);
-			break;
-		}
-	}
-
-	if (ACPI_FAILURE(status)) {
-		return_ACPI_STATUS(status);
+	if (tz->policy.thresholds.passive.is_valid) {
+		for (i=0; i<tz->policy.thresholds.passive.devices.count; i++)
+			set_performance_limit(tz->policy.thresholds.passive.devices.handles[i], PR_PERF_MAX);
+		tz_policy_passive(tz);
 	}
+	if (tz->policy.thresholds.active[0].is_valid)
+		tz_policy_active(tz);
 
 	/*
 	 * Initialize Policy Timer:
 	 * ------------------------
-	 * TBD: Linux-specific - remove when policy moves to user-space.
 	 */
 	init_timer(&(tz->policy.timer));
 
@@ -623,7 +530,7 @@
 	 */
 	tz_policy_check(tz);
 
-	return_ACPI_STATUS(status);
+	return_ACPI_STATUS(AE_OK);
 }
 
 
@@ -656,19 +563,15 @@
 	/*
 	 * Delete the thermal zone policy timer entry, if exists.
 	 */
-	if (timer_pending(&(tz->policy.timer))) {
+	if (timer_pending(&(tz->policy.timer)))
 		del_timer(&(tz->policy.timer));
-	}
 
 	/*
 	 * Reset thermal performance limit on all processors back to max.
 	 */
-	if (tz->policy.passive.threshold) {
-		for (i=0; i<tz->policy.passive.threshold->cooling_devices.count; i++) {
-			set_performance_limit(
-				tz->policy.passive.threshold->cooling_devices.handles[i],
-				PR_PERF_MAX);
-		}
+	if (tz->policy.thresholds.passive.is_valid) {
+		for (i=0; i<tz->policy.thresholds.passive.devices.count; i++)
+			set_performance_limit(tz->policy.thresholds.passive.devices.handles[i], PR_PERF_MAX);
 	}
 
 	return_ACPI_STATUS(AE_OK);

FUNET's LINUX-ADM group, linux-adm@nic.funet.fi
TCL-scripts by Sam Shen (who was at: slshen@lbl.gov)