Commit 8079a4bd authored by Thomas Gleixner's avatar Thomas Gleixner Committed by Zhang Rui

thermal/x86_pkg_temp: Cleanup code some more

Coding style fixups and replacement of overly complex constructs and random
error codes instead of returning the real ones. This mess makes the eyes bleeding.
Signed-off-by: default avatarThomas Gleixner <tglx@linutronix.de>
Tested-by: default avatarSrinivas Pandruvada <srinivas.pandruvada@linux.intel.com>
Signed-off-by: default avatarZhang Rui <rui.zhang@intel.com>
parent 3883a64e
...@@ -139,27 +139,17 @@ static struct pkg_device *pkg_temp_thermal_get_dev(unsigned int cpu) ...@@ -139,27 +139,17 @@ static struct pkg_device *pkg_temp_thermal_get_dev(unsigned int cpu)
*/ */
static int get_tj_max(int cpu, u32 *tj_max) static int get_tj_max(int cpu, u32 *tj_max)
{ {
u32 eax, edx; u32 eax, edx, val;
u32 val;
int err; int err;
err = rdmsr_safe_on_cpu(cpu, MSR_IA32_TEMPERATURE_TARGET, &eax, &edx); err = rdmsr_safe_on_cpu(cpu, MSR_IA32_TEMPERATURE_TARGET, &eax, &edx);
if (err) if (err)
goto err_ret; return err;
else {
val = (eax >> 16) & 0xff;
if (val)
*tj_max = val * 1000;
else {
err = -EINVAL;
goto err_ret;
}
}
return 0; val = (eax >> 16) & 0xff;
err_ret: *tj_max = val * 1000;
*tj_max = 0;
return err; return val ? 0 : -EINVAL;
} }
static int sys_get_curr_temp(struct thermal_zone_device *tzd, int *temp) static int sys_get_curr_temp(struct thermal_zone_device *tzd, int *temp)
...@@ -198,7 +188,7 @@ static int sys_get_trip_temp(struct thermal_zone_device *tzd, ...@@ -198,7 +188,7 @@ static int sys_get_trip_temp(struct thermal_zone_device *tzd,
ret = rdmsr_on_cpu(pkgdev->cpu, MSR_IA32_PACKAGE_THERM_INTERRUPT, ret = rdmsr_on_cpu(pkgdev->cpu, MSR_IA32_PACKAGE_THERM_INTERRUPT,
&eax, &edx); &eax, &edx);
if (ret < 0) if (ret < 0)
return -EINVAL; return ret;
thres_reg_value = (eax & mask) >> shift; thres_reg_value = (eax & mask) >> shift;
if (thres_reg_value) if (thres_reg_value)
...@@ -223,7 +213,7 @@ sys_set_trip_temp(struct thermal_zone_device *tzd, int trip, int temp) ...@@ -223,7 +213,7 @@ sys_set_trip_temp(struct thermal_zone_device *tzd, int trip, int temp)
ret = rdmsr_on_cpu(pkgdev->cpu, MSR_IA32_PACKAGE_THERM_INTERRUPT, ret = rdmsr_on_cpu(pkgdev->cpu, MSR_IA32_PACKAGE_THERM_INTERRUPT,
&l, &h); &l, &h);
if (ret < 0) if (ret < 0)
return -EINVAL; return ret;
if (trip) { if (trip) {
mask = THERM_MASK_THRESHOLD1; mask = THERM_MASK_THRESHOLD1;
...@@ -252,9 +242,7 @@ sys_set_trip_temp(struct thermal_zone_device *tzd, int trip, int temp) ...@@ -252,9 +242,7 @@ sys_set_trip_temp(struct thermal_zone_device *tzd, int trip, int temp)
static int sys_get_trip_type(struct thermal_zone_device *thermal, int trip, static int sys_get_trip_type(struct thermal_zone_device *thermal, int trip,
enum thermal_trip_type *type) enum thermal_trip_type *type)
{ {
*type = THERMAL_TRIP_PASSIVE; *type = THERMAL_TRIP_PASSIVE;
return 0; return 0;
} }
...@@ -274,8 +262,8 @@ static bool pkg_thermal_rate_control(void) ...@@ -274,8 +262,8 @@ static bool pkg_thermal_rate_control(void)
/* Enable threshold interrupt on local package/cpu */ /* Enable threshold interrupt on local package/cpu */
static inline void enable_pkg_thres_interrupt(void) static inline void enable_pkg_thres_interrupt(void)
{ {
u32 l, h;
u8 thres_0, thres_1; u8 thres_0, thres_1;
u32 l, h;
rdmsr(MSR_IA32_PACKAGE_THERM_INTERRUPT, l, h); rdmsr(MSR_IA32_PACKAGE_THERM_INTERRUPT, l, h);
/* only enable/disable if it had valid threshold value */ /* only enable/disable if it had valid threshold value */
...@@ -292,20 +280,21 @@ static inline void enable_pkg_thres_interrupt(void) ...@@ -292,20 +280,21 @@ static inline void enable_pkg_thres_interrupt(void)
static inline void disable_pkg_thres_interrupt(void) static inline void disable_pkg_thres_interrupt(void)
{ {
u32 l, h; u32 l, h;
rdmsr(MSR_IA32_PACKAGE_THERM_INTERRUPT, l, h); rdmsr(MSR_IA32_PACKAGE_THERM_INTERRUPT, l, h);
wrmsr(MSR_IA32_PACKAGE_THERM_INTERRUPT,
l & (~THERM_INT_THRESHOLD0_ENABLE) & l &= ~(THERM_INT_THRESHOLD0_ENABLE | THERM_INT_THRESHOLD1_ENABLE);
(~THERM_INT_THRESHOLD1_ENABLE), h); wrmsr(MSR_IA32_PACKAGE_THERM_INTERRUPT, l, h);
} }
static void pkg_temp_thermal_threshold_work_fn(struct work_struct *work) static void pkg_temp_thermal_threshold_work_fn(struct work_struct *work)
{ {
__u64 msr_val;
int cpu = smp_processor_id(); int cpu = smp_processor_id();
int phy_id = topology_physical_package_id(cpu);
struct pkg_device *pkgdev = pkg_temp_thermal_get_dev(cpu); struct pkg_device *pkgdev = pkg_temp_thermal_get_dev(cpu);
int phy_id = topology_physical_package_id(cpu);
bool notify = false; bool notify = false;
unsigned long flags; unsigned long flags;
u64 msr_val, wr_val;
if (!pkgdev) if (!pkgdev)
return; return;
...@@ -320,14 +309,9 @@ static void pkg_temp_thermal_threshold_work_fn(struct work_struct *work) ...@@ -320,14 +309,9 @@ static void pkg_temp_thermal_threshold_work_fn(struct work_struct *work)
spin_unlock_irqrestore(&pkg_work_lock, flags); spin_unlock_irqrestore(&pkg_work_lock, flags);
rdmsrl(MSR_IA32_PACKAGE_THERM_STATUS, msr_val); rdmsrl(MSR_IA32_PACKAGE_THERM_STATUS, msr_val);
if (msr_val & THERM_LOG_THRESHOLD0) { wr_val = msr_val & ~(THERM_LOG_THRESHOLD0 | THERM_LOG_THRESHOLD1);
wrmsrl(MSR_IA32_PACKAGE_THERM_STATUS, if (wr_val != msr_val) {
msr_val & ~THERM_LOG_THRESHOLD0); wrmsrl(MSR_IA32_PACKAGE_THERM_STATUS, wr_val);
notify = true;
}
if (msr_val & THERM_LOG_THRESHOLD1) {
wrmsrl(MSR_IA32_PACKAGE_THERM_STATUS,
msr_val & ~THERM_LOG_THRESHOLD1);
notify = true; notify = true;
} }
...@@ -340,11 +324,11 @@ static void pkg_temp_thermal_threshold_work_fn(struct work_struct *work) ...@@ -340,11 +324,11 @@ static void pkg_temp_thermal_threshold_work_fn(struct work_struct *work)
} }
} }
static int pkg_thermal_notify(__u64 msr_val) static int pkg_thermal_notify(u64 msr_val)
{ {
unsigned long flags;
int cpu = smp_processor_id(); int cpu = smp_processor_id();
int phy_id = topology_physical_package_id(cpu); int phy_id = topology_physical_package_id(cpu);
unsigned long flags;
/* /*
* When a package is in interrupted state, all CPU's in that package * When a package is in interrupted state, all CPU's in that package
...@@ -483,21 +467,17 @@ static int get_core_online(unsigned int cpu) ...@@ -483,21 +467,17 @@ static int get_core_online(unsigned int cpu)
struct pkg_device *pkgdev = pkg_temp_thermal_get_dev(cpu); struct pkg_device *pkgdev = pkg_temp_thermal_get_dev(cpu);
struct cpuinfo_x86 *c = &cpu_data(cpu); struct cpuinfo_x86 *c = &cpu_data(cpu);
/* Check if there is already an instance for this package */ /* Paranoia check */
if (!pkgdev) { if (!cpu_has(c, X86_FEATURE_DTHERM) || !cpu_has(c, X86_FEATURE_PTS))
if (!cpu_has(c, X86_FEATURE_DTHERM) || return -ENODEV;
!cpu_has(c, X86_FEATURE_PTS))
return -ENODEV;
if (pkg_temp_thermal_device_add(cpu))
return -ENODEV;
}
INIT_DELAYED_WORK(&per_cpu(pkg_temp_thermal_threshold_work, cpu), INIT_DELAYED_WORK(&per_cpu(pkg_temp_thermal_threshold_work, cpu),
pkg_temp_thermal_threshold_work_fn); pkg_temp_thermal_threshold_work_fn);
pr_debug("get_core_online: cpu %d successful\n", cpu); /* If the package exists, nothing to do */
if (pkgdev)
return 0; return 0;
return pkg_temp_thermal_device_add(cpu);
} }
static void put_core_offline(unsigned int cpu) static void put_core_offline(unsigned int cpu)
...@@ -555,8 +535,8 @@ static int __init pkg_temp_thermal_init(void) ...@@ -555,8 +535,8 @@ static int __init pkg_temp_thermal_init(void)
platform_thermal_package_notify = pkg_thermal_notify; platform_thermal_package_notify = pkg_thermal_notify;
platform_thermal_package_rate_control = pkg_thermal_rate_control; platform_thermal_package_rate_control = pkg_thermal_rate_control;
pkg_temp_debugfs_init(); /* Don't care if fails */ /* Don't care if it fails */
pkg_temp_debugfs_init();
return 0; return 0;
err_ret: err_ret:
...@@ -566,6 +546,7 @@ static int __init pkg_temp_thermal_init(void) ...@@ -566,6 +546,7 @@ static int __init pkg_temp_thermal_init(void)
kfree(pkg_work_scheduled); kfree(pkg_work_scheduled);
return -ENODEV; return -ENODEV;
} }
module_init(pkg_temp_thermal_init)
static void __exit pkg_temp_thermal_exit(void) static void __exit pkg_temp_thermal_exit(void)
{ {
...@@ -597,8 +578,6 @@ static void __exit pkg_temp_thermal_exit(void) ...@@ -597,8 +578,6 @@ static void __exit pkg_temp_thermal_exit(void)
debugfs_remove_recursive(debugfs); debugfs_remove_recursive(debugfs);
} }
module_init(pkg_temp_thermal_init)
module_exit(pkg_temp_thermal_exit) module_exit(pkg_temp_thermal_exit)
MODULE_DESCRIPTION("X86 PKG TEMP Thermal Driver"); MODULE_DESCRIPTION("X86 PKG TEMP Thermal Driver");
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment