Lines Matching +full:thermal +full:- +full:zones
1 // SPDX-License-Identifier: GPL-2.0-only
19 #include <linux/thermal.h>
42 /* Number of trip points in thermal zone. Currently it can't
67 static struct zone_device **zones; variable
94 * - cpu hotplug: Read serialized by cpu hotplug lock
97 * - Other callsites: Must hold pkg_temp_lock
104 return zones[id]; in pkg_temp_thermal_get_dev()
113 ret = intel_tcc_get_temp(zonedev->cpu, &val, true); in sys_get_curr_temp()
129 tj_max = intel_tcc_get_tjmax(zonedev->cpu); in sys_set_trip_temp()
134 val = (tj_max - temp)/1000; in sys_set_trip_temp()
137 return -EINVAL; in sys_set_trip_temp()
139 ret = rdmsr_on_cpu(zonedev->cpu, MSR_IA32_PACKAGE_THERM_INTERRUPT, in sys_set_trip_temp()
165 return wrmsr_on_cpu(zonedev->cpu, MSR_IA32_PACKAGE_THERM_INTERRUPT, in sys_set_trip_temp()
169 /* Thermal zone callback registry */
224 zonedev->work_scheduled = false; in pkg_temp_thermal_threshold_work_fn()
227 tzone = zonedev->tzone; in pkg_temp_thermal_threshold_work_fn()
262 if (zonedev && !zonedev->work_scheduled) { in pkg_thermal_notify()
263 zonedev->work_scheduled = true; in pkg_thermal_notify()
264 pkg_thermal_schedule_work(zonedev->cpu, &zonedev->work); in pkg_thermal_notify()
280 return ERR_PTR(-ENOMEM); in pkg_temp_thermal_trips_init()
302 tj_max - thres_reg_value * 1000 : THERMAL_TEMP_INVALID; in pkg_temp_thermal_trips_init()
322 return -ENOMEM; in pkg_temp_thermal_device_add()
327 return -ENODEV; in pkg_temp_thermal_device_add()
337 return -ENOMEM; in pkg_temp_thermal_device_add()
339 zonedev->trips = pkg_temp_thermal_trips_init(cpu, tj_max, thres_count); in pkg_temp_thermal_device_add()
340 if (IS_ERR(zonedev->trips)) { in pkg_temp_thermal_device_add()
341 err = PTR_ERR(zonedev->trips); in pkg_temp_thermal_device_add()
345 INIT_DELAYED_WORK(&zonedev->work, pkg_temp_thermal_threshold_work_fn); in pkg_temp_thermal_device_add()
346 zonedev->cpu = cpu; in pkg_temp_thermal_device_add()
347 zonedev->tzone = thermal_zone_device_register_with_trips("x86_pkg_temp", in pkg_temp_thermal_device_add()
348 zonedev->trips, thres_count, in pkg_temp_thermal_device_add()
351 if (IS_ERR(zonedev->tzone)) { in pkg_temp_thermal_device_add()
352 err = PTR_ERR(zonedev->tzone); in pkg_temp_thermal_device_add()
355 err = thermal_zone_device_enable(zonedev->tzone); in pkg_temp_thermal_device_add()
359 /* Store MSR value for package thermal interrupt, to restore at exit */ in pkg_temp_thermal_device_add()
360 rdmsr(MSR_IA32_PACKAGE_THERM_INTERRUPT, zonedev->msr_pkg_therm_low, in pkg_temp_thermal_device_add()
361 zonedev->msr_pkg_therm_high); in pkg_temp_thermal_device_add()
363 cpumask_set_cpu(cpu, &zonedev->cpumask); in pkg_temp_thermal_device_add()
365 zones[id] = zonedev; in pkg_temp_thermal_device_add()
371 thermal_zone_device_unregister(zonedev->tzone); in pkg_temp_thermal_device_add()
373 kfree(zonedev->trips); in pkg_temp_thermal_device_add()
388 target = cpumask_any_but(&zonedev->cpumask, cpu); in pkg_thermal_cpu_offline()
389 cpumask_clear_cpu(cpu, &zonedev->cpumask); in pkg_thermal_cpu_offline()
396 struct thermal_zone_device *tzone = zonedev->tzone; in pkg_thermal_cpu_offline()
405 zonedev->tzone = NULL; in pkg_thermal_cpu_offline()
419 was_target = zonedev->cpu == cpu; in pkg_thermal_cpu_offline()
420 zonedev->cpu = target; in pkg_thermal_cpu_offline()
429 zones[topology_logical_die_id(cpu)] = NULL; in pkg_thermal_cpu_offline()
432 zonedev->msr_pkg_therm_low, zonedev->msr_pkg_therm_high); in pkg_thermal_cpu_offline()
439 if (zonedev->work_scheduled && was_target) { in pkg_thermal_cpu_offline()
445 cancel_delayed_work_sync(&zonedev->work); in pkg_thermal_cpu_offline()
453 if (!lastcpu && zonedev->work_scheduled) in pkg_thermal_cpu_offline()
454 pkg_thermal_schedule_work(target, &zonedev->work); in pkg_thermal_cpu_offline()
461 kfree(zonedev->trips); in pkg_thermal_cpu_offline()
474 return -ENODEV; in pkg_thermal_cpu_online()
478 cpumask_set_cpu(cpu, &zonedev->cpumask); in pkg_thermal_cpu_online()
495 return -ENODEV; in pkg_temp_thermal_init()
498 zones = kcalloc(max_id, sizeof(struct zone_device *), in pkg_temp_thermal_init()
500 if (!zones) in pkg_temp_thermal_init()
501 return -ENOMEM; in pkg_temp_thermal_init()
503 ret = cpuhp_setup_state(CPUHP_AP_ONLINE_DYN, "thermal/x86_pkg:online", in pkg_temp_thermal_init()
519 kfree(zones); in pkg_temp_thermal_init()
531 kfree(zones); in module_init()
536 MODULE_DESCRIPTION("X86 PKG TEMP Thermal Driver");