Merge tag 'thermal-6.9-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/rafael...
[linux-2.6-microblaze.git] / drivers / thermal / intel / x86_pkg_temp_thermal.c
index f6c2e59..c0ca8e3 100644 (file)
@@ -53,7 +53,6 @@ struct zone_device {
        u32                             msr_pkg_therm_high;
        struct delayed_work             work;
        struct thermal_zone_device      *tzone;
-       struct thermal_trip             *trips;
        struct cpumask                  cpumask;
 };
 
@@ -108,11 +107,11 @@ static struct zone_device *pkg_temp_thermal_get_dev(unsigned int cpu)
 static int sys_get_curr_temp(struct thermal_zone_device *tzd, int *temp)
 {
        struct zone_device *zonedev = thermal_zone_device_priv(tzd);
-       int val;
+       int val, ret;
 
-       val = intel_tcc_get_temp(zonedev->cpu, true);
-       if (val < 0)
-               return val;
+       ret = intel_tcc_get_temp(zonedev->cpu, &val, true);
+       if (ret < 0)
+               return ret;
 
        *temp = val * 1000;
        pr_debug("sys_get_curr_temp %d\n", *temp);
@@ -167,7 +166,7 @@ sys_set_trip_temp(struct thermal_zone_device *tzd, int trip, int temp)
 }
 
 /* Thermal zone callback registry */
-static struct thermal_zone_device_ops tzone_ops = {
+static const struct thermal_zone_device_ops tzone_ops = {
        .get_temp = sys_get_curr_temp,
        .set_trip_temp = sys_set_trip_temp,
 };
@@ -268,17 +267,13 @@ static int pkg_thermal_notify(u64 msr_val)
        return 0;
 }
 
-static struct thermal_trip *pkg_temp_thermal_trips_init(int cpu, int tj_max, int num_trips)
+static int pkg_temp_thermal_trips_init(int cpu, int tj_max,
+                                      struct thermal_trip *trips, int num_trips)
 {
-       struct thermal_trip *trips;
        unsigned long thres_reg_value;
        u32 mask, shift, eax, edx;
        int ret, i;
 
-       trips = kzalloc(sizeof(*trips) * num_trips, GFP_KERNEL);
-       if (!trips)
-               return ERR_PTR(-ENOMEM);
-
        for (i = 0; i < num_trips; i++) {
 
                if (i) {
@@ -291,10 +286,8 @@ static struct thermal_trip *pkg_temp_thermal_trips_init(int cpu, int tj_max, int
 
                ret = rdmsr_on_cpu(cpu, MSR_IA32_PACKAGE_THERM_INTERRUPT,
                                   &eax, &edx);
-               if (ret < 0) {
-                       kfree(trips);
-                       return ERR_PTR(ret);
-               }
+               if (ret < 0)
+                       return ret;
 
                thres_reg_value = (eax & mask) >> shift;
 
@@ -302,16 +295,18 @@ static struct thermal_trip *pkg_temp_thermal_trips_init(int cpu, int tj_max, int
                        tj_max - thres_reg_value * 1000 : THERMAL_TEMP_INVALID;
 
                trips[i].type = THERMAL_TRIP_PASSIVE;
+               trips[i].flags |= THERMAL_TRIP_FLAG_RW_TEMP;
 
                pr_debug("%s: cpu=%d, trip=%d, temp=%d\n",
                         __func__, cpu, i, trips[i].temperature);
        }
 
-       return trips;
+       return 0;
 }
 
 static int pkg_temp_thermal_device_add(unsigned int cpu)
 {
+       struct thermal_trip trips[MAX_NUMBER_OF_TRIPS] = { 0 };
        int id = topology_logical_die_id(cpu);
        u32 eax, ebx, ecx, edx;
        struct zone_device *zonedev;
@@ -336,21 +331,18 @@ static int pkg_temp_thermal_device_add(unsigned int cpu)
        if (!zonedev)
                return -ENOMEM;
 
-       zonedev->trips = pkg_temp_thermal_trips_init(cpu, tj_max, thres_count);
-       if (IS_ERR(zonedev->trips)) {
-               err = PTR_ERR(zonedev->trips);
+       err = pkg_temp_thermal_trips_init(cpu, tj_max, trips, thres_count);
+       if (err)
                goto out_kfree_zonedev;
-       }
 
        INIT_DELAYED_WORK(&zonedev->work, pkg_temp_thermal_threshold_work_fn);
        zonedev->cpu = cpu;
        zonedev->tzone = thermal_zone_device_register_with_trips("x86_pkg_temp",
-                       zonedev->trips, thres_count,
-                       (thres_count == MAX_NUMBER_OF_TRIPS) ? 0x03 : 0x01,
+                       trips, thres_count,
                        zonedev, &tzone_ops, &pkg_temp_tz_params, 0, 0);
        if (IS_ERR(zonedev->tzone)) {
                err = PTR_ERR(zonedev->tzone);
-               goto out_kfree_trips;
+               goto out_kfree_zonedev;
        }
        err = thermal_zone_device_enable(zonedev->tzone);
        if (err)
@@ -369,8 +361,6 @@ static int pkg_temp_thermal_device_add(unsigned int cpu)
 
 out_unregister_tz:
        thermal_zone_device_unregister(zonedev->tzone);
-out_kfree_trips:
-       kfree(zonedev->trips);
 out_kfree_zonedev:
        kfree(zonedev);
        return err;
@@ -457,10 +447,9 @@ static int pkg_thermal_cpu_offline(unsigned int cpu)
        raw_spin_unlock_irq(&pkg_temp_lock);
 
        /* Final cleanup if this is the last cpu */
-       if (lastcpu) {
-               kfree(zonedev->trips);
+       if (lastcpu)
                kfree(zonedev);
-       }
+
        return 0;
 }