Merge back other thermal control material for 6.3.
authorRafael J. Wysocki <rafael.j.wysocki@intel.com>
Tue, 24 Jan 2023 20:12:49 +0000 (21:12 +0100)
committerRafael J. Wysocki <rafael.j.wysocki@intel.com>
Tue, 24 Jan 2023 20:12:49 +0000 (21:12 +0100)
* thermal: (734 commits)
  thermal: core: call put_device() only after device_register() fails
  Linux 6.2-rc4
  kbuild: Fix CFI hash randomization with KASAN
  firmware: coreboot: Check size of table entry and use flex-array
  kallsyms: Fix scheduling with interrupts disabled in self-test
  ata: pata_cs5535: Don't build on UML
  lockref: stop doing cpu_relax in the cmpxchg loop
  x86/pci: Treat EfiMemoryMappedIO as reservation of ECAM space
  efi: tpm: Avoid READ_ONCE() for accessing the event log
  io_uring: lock overflowing for IOPOLL
  ALSA: pcm: Move rwsem lock inside snd_ctl_elem_read to prevent UAF
  iommu/mediatek-v1: Fix an error handling path in mtk_iommu_v1_probe()
  iommu/iova: Fix alloc iova overflows issue
  iommu: Fix refcount leak in iommu_device_claim_dma_owner
  iommu/arm-smmu-v3: Don't unregister on shutdown
  iommu/arm-smmu: Don't unregister on shutdown
  iommu/arm-smmu: Report IOMMU_CAP_CACHE_COHERENCY even betterer
  platform/x86: thinkpad_acpi: Fix profile mode display in AMT mode
  ALSA: usb-audio: Fix possible NULL pointer dereference in snd_usb_pcm_has_fixed_rate()
  platform/x86: int3472/discrete: Ensure the clk/power enable pins are in output mode
  ...

1  2 
drivers/thermal/intel/int340x_thermal/processor_thermal_device.c
drivers/thermal/intel/x86_pkg_temp_thermal.c

index a2ea22f2bffd5732b23a337ef0f27b4260bbb271,317703027ce98505417fa98182e3d66d303de0cd..a1dc18be76097347955eecece9267058c08238ff
@@@ -118,22 -174,39 +118,18 @@@ static int proc_thermal_get_zone_temp(s
        *temp = 0;
  
        for_each_online_cpu(cpu) {
 -              err = rdmsr_safe_on_cpu(cpu, MSR_IA32_THERM_STATUS, &eax,
 -                                      &edx);
 -              if (err)
 -                      goto err_ret;
 -              else {
 -                      if (eax & 0x80000000) {
 -                              curr_temp_off = (eax >> 16) & 0x7f;
 -                              if (!*temp || curr_temp_off < *temp)
 -                                      *temp = curr_temp_off;
 -                      } else {
 -                              err = -EINVAL;
 -                              goto err_ret;
 -                      }
 -              }
 +              curr_temp = intel_tcc_get_temp(cpu, false);
 +              if (curr_temp < 0)
 +                      return curr_temp;
 +              if (!*temp || curr_temp > *temp)
 +                      *temp = curr_temp;
        }
  
 -      return 0;
 -err_ret:
 -      return err;
 -}
 -
 -static int proc_thermal_get_zone_temp(struct thermal_zone_device *zone,
 -                                       int *temp)
 -{
 -      int ret;
 -
 -      ret = read_temp_msr(temp);
 -      if (!ret)
 -              *temp = (stored_tjmax - *temp) * 1000;
 +      *temp *= 1000;
  
 -      return ret;
 +      return 0;
  }
  
- static struct thermal_zone_device_ops proc_thermal_local_ops = {
-       .get_temp       = proc_thermal_get_zone_temp,
- };
  static int proc_thermal_read_ppcc(struct proc_thermal_device *proc_priv)
  {
        int i;
@@@ -225,11 -298,12 +221,11 @@@ int proc_thermal_add(struct device *dev
        status = acpi_evaluate_integer(adev->handle, "_TMP", NULL, &tmp);
        if (ACPI_FAILURE(status)) {
                /* there is no _TMP method, add local method */
 -              stored_tjmax = get_tjmax();
 -              if (stored_tjmax > 0)
 +              if (intel_tcc_get_tjmax(-1) > 0)
-                       ops = &proc_thermal_local_ops;
+                       get_temp = proc_thermal_get_zone_temp;
        }
  
-       proc_priv->int340x_zone = int340x_thermal_zone_add(adev, ops);
+       proc_priv->int340x_zone = int340x_thermal_zone_add(adev, get_temp);
        if (IS_ERR(proc_priv->int340x_zone)) {
                return PTR_ERR(proc_priv->int340x_zone);
        } else
index 9e08d8c8f5fb848f4025a70e14937cc842f6b426,494f25250c2de2403eb9612bf910debdbfb42cce..1c2de84742dfb51db7bbf09b83558d396a9c7a05
@@@ -107,56 -108,37 +108,17 @@@ static struct zone_device *pkg_temp_the
  static int sys_get_curr_temp(struct thermal_zone_device *tzd, int *temp)
  {
        struct zone_device *zonedev = tzd->devdata;
 -      u32 eax, edx;
 +      int val;
  
 -      rdmsr_on_cpu(zonedev->cpu, MSR_IA32_PACKAGE_THERM_STATUS,
 -                      &eax, &edx);
 -      if (eax & 0x80000000) {
 -              *temp = zonedev->tj_max - ((eax >> 16) & 0x7f) * 1000;
 -              pr_debug("sys_get_curr_temp %d\n", *temp);
 -              return 0;
 -      }
 -      return -EINVAL;
 +      val = intel_tcc_get_temp(zonedev->cpu, true);
 +      if (val < 0)
 +              return val;
 +
 +      *temp = val * 1000;
 +      pr_debug("sys_get_curr_temp %d\n", *temp);
 +      return 0;
  }
  
- static int sys_get_trip_temp(struct thermal_zone_device *tzd,
-                            int trip, int *temp)
- {
-       struct zone_device *zonedev = tzd->devdata;
-       unsigned long thres_reg_value;
-       u32 mask, shift, eax, edx;
-       int tj_max, ret;
-       if (trip >= MAX_NUMBER_OF_TRIPS)
-               return -EINVAL;
-       if (trip) {
-               mask = THERM_MASK_THRESHOLD1;
-               shift = THERM_SHIFT_THRESHOLD1;
-       } else {
-               mask = THERM_MASK_THRESHOLD0;
-               shift = THERM_SHIFT_THRESHOLD0;
-       }
-       tj_max = intel_tcc_get_tjmax(zonedev->cpu);
-       if (tj_max < 0)
-               return tj_max;
-       tj_max *= 1000;
-       ret = rdmsr_on_cpu(zonedev->cpu, MSR_IA32_PACKAGE_THERM_INTERRUPT,
-                          &eax, &edx);
-       if (ret < 0)
-               return ret;
-       thres_reg_value = (eax & mask) >> shift;
-       if (thres_reg_value)
-               *temp = tj_max - thres_reg_value * 1000;
-       else
-               *temp = THERMAL_TEMP_INVALID;
-       pr_debug("sys_get_trip_temp %d\n", *temp);
-       return 0;
- }
  static int
  sys_set_trip_temp(struct thermal_zone_device *tzd, int trip, int temp)
  {
@@@ -316,9 -326,9 +311,10 @@@ static struct thermal_trip *pkg_temp_th
  static int pkg_temp_thermal_device_add(unsigned int cpu)
  {
        int id = topology_logical_die_id(cpu);
 -      u32 tj_max, eax, ebx, ecx, edx;
 +      u32 eax, ebx, ecx, edx;
        struct zone_device *zonedev;
        int thres_count, err;
++      int tj_max;
  
        if (id >= max_id)
                return -ENOMEM;
  
        thres_count = clamp_val(thres_count, 0, MAX_NUMBER_OF_TRIPS);
  
-       err = intel_tcc_get_tjmax(cpu);
-       if (err < 0)
 -      err = get_tj_max(cpu, &tj_max);
 -      if (err)
--              return err;
++      tj_max = intel_tcc_get_tjmax(cpu);
++      if (tj_max < 0)
++              return tj_max;
  
        zonedev = kzalloc(sizeof(*zonedev), GFP_KERNEL);
        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);
+               goto out_kfree_zonedev;
+       }
        INIT_DELAYED_WORK(&zonedev->work, pkg_temp_thermal_threshold_work_fn);
        zonedev->cpu = cpu;
-       zonedev->tzone = thermal_zone_device_register("x86_pkg_temp",
-                       thres_count,
 -      zonedev->tj_max = tj_max;
+       zonedev->tzone = thermal_zone_device_register_with_trips("x86_pkg_temp",
+                       zonedev->trips, thres_count,
                        (thres_count == MAX_NUMBER_OF_TRIPS) ? 0x03 : 0x01,
                        zonedev, &tzone_ops, &pkg_temp_tz_params, 0, 0);
        if (IS_ERR(zonedev->tzone)) {