Orange Pi5 kernel

Deprecated Linux kernel 5.10.110 for OrangePi 5/5B/5+ boards

3 Commits   0 Branches   0 Tags
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   1) // SPDX-License-Identifier: GPL-2.0-or-later
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   3)  * processor_driver.c - ACPI Processor Driver
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   4)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   5)  *  Copyright (C) 2001, 2002 Andy Grover <andrew.grover@intel.com>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   6)  *  Copyright (C) 2001, 2002 Paul Diefenbaugh <paul.s.diefenbaugh@intel.com>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   7)  *  Copyright (C) 2004       Dominik Brodowski <linux@brodo.de>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   8)  *  Copyright (C) 2004  Anil S Keshavamurthy <anil.s.keshavamurthy@intel.com>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   9)  *  			- Added processor hotplug support
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  10)  *  Copyright (C) 2013, Intel Corporation
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  11)  *                      Rafael J. Wysocki <rafael.j.wysocki@intel.com>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  12)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  13) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  14) #include <linux/kernel.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  15) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  16) #include <linux/init.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  17) #include <linux/cpufreq.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  18) #include <linux/cpu.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  19) #include <linux/cpuidle.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  20) #include <linux/slab.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  21) #include <linux/acpi.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23) #include <acpi/processor.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25) #include "internal.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  26) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  27) #define ACPI_PROCESSOR_NOTIFY_PERFORMANCE 0x80
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28) #define ACPI_PROCESSOR_NOTIFY_POWER	0x81
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29) #define ACPI_PROCESSOR_NOTIFY_THROTTLING	0x82
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31) #define _COMPONENT		ACPI_PROCESSOR_COMPONENT
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32) ACPI_MODULE_NAME("processor_driver");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34) MODULE_AUTHOR("Paul Diefenbaugh");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  35) MODULE_DESCRIPTION("ACPI Processor Driver");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36) MODULE_LICENSE("GPL");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38) static int acpi_processor_start(struct device *dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39) static int acpi_processor_stop(struct device *dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41) static const struct acpi_device_id processor_device_ids[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42) 	{ACPI_PROCESSOR_OBJECT_HID, 0},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43) 	{ACPI_PROCESSOR_DEVICE_HID, 0},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44) 	{"", 0},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46) MODULE_DEVICE_TABLE(acpi, processor_device_ids);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48) static struct device_driver acpi_processor_driver = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49) 	.name = "processor",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50) 	.bus = &cpu_subsys,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51) 	.acpi_match_table = processor_device_ids,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52) 	.probe = acpi_processor_start,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53) 	.remove = acpi_processor_stop,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56) static void acpi_processor_notify(acpi_handle handle, u32 event, void *data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58) 	struct acpi_device *device = data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59) 	struct acpi_processor *pr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60) 	int saved;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62) 	if (device->handle != handle)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65) 	pr = acpi_driver_data(device);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66) 	if (!pr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69) 	switch (event) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70) 	case ACPI_PROCESSOR_NOTIFY_PERFORMANCE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71) 		saved = pr->performance_platform_limit;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72) 		acpi_processor_ppc_has_changed(pr, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  73) 		if (saved == pr->performance_platform_limit)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  74) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  75) 		acpi_bus_generate_netlink_event(device->pnp.device_class,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  76) 						  dev_name(&device->dev), event,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77) 						  pr->performance_platform_limit);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79) 	case ACPI_PROCESSOR_NOTIFY_POWER:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80) 		acpi_processor_power_state_has_changed(pr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81) 		acpi_bus_generate_netlink_event(device->pnp.device_class,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82) 						  dev_name(&device->dev), event, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84) 	case ACPI_PROCESSOR_NOTIFY_THROTTLING:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85) 		acpi_processor_tstate_has_changed(pr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86) 		acpi_bus_generate_netlink_event(device->pnp.device_class,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87) 						  dev_name(&device->dev), event, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89) 	default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90) 		ACPI_DEBUG_PRINT((ACPI_DB_INFO,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91) 				  "Unsupported event [0x%x]\n", event));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95) 	return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98) static int __acpi_processor_start(struct acpi_device *device);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) static int acpi_soft_cpu_online(unsigned int cpu)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) 	struct acpi_processor *pr = per_cpu(processors, cpu);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) 	struct acpi_device *device;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) 	if (!pr || acpi_bus_get_device(pr->handle, &device))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) 	 * CPU got physically hotplugged and onlined for the first time:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) 	 * Initialize missing things.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) 	if (pr->flags.need_hotplug_init) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) 		int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) 		pr_info("Will online and init hotplugged CPU: %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) 			pr->id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) 		pr->flags.need_hotplug_init = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) 		ret = __acpi_processor_start(device);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) 		WARN(ret, "Failed to start CPU: %d\n", pr->id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) 		/* Normal CPU soft online event. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) 		acpi_processor_ppc_has_changed(pr, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) 		acpi_processor_hotplug(pr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) 		acpi_processor_reevaluate_tstate(pr, false);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) 		acpi_processor_tstate_has_changed(pr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) static int acpi_soft_cpu_dead(unsigned int cpu)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) 	struct acpi_processor *pr = per_cpu(processors, cpu);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) 	struct acpi_device *device;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) 	if (!pr || acpi_bus_get_device(pr->handle, &device))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) 	acpi_processor_reevaluate_tstate(pr, true);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) #ifdef CONFIG_ACPI_CPU_FREQ_PSS
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) static int acpi_pss_perf_init(struct acpi_processor *pr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) 		struct acpi_device *device)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) 	int result = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) 	acpi_processor_ppc_has_changed(pr, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) 	acpi_processor_get_throttling_info(pr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) 	if (pr->flags.throttling)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) 		pr->flags.limit = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) 	pr->cdev = thermal_cooling_device_register("Processor", device,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) 						   &processor_cooling_ops);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) 	if (IS_ERR(pr->cdev)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) 		result = PTR_ERR(pr->cdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) 		return result;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) 	dev_dbg(&device->dev, "registered as cooling_device%d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) 		pr->cdev->id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) 	result = sysfs_create_link(&device->dev.kobj,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) 				   &pr->cdev->device.kobj,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) 				   "thermal_cooling");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) 	if (result) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) 		dev_err(&device->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) 			"Failed to create sysfs link 'thermal_cooling'\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) 		goto err_thermal_unregister;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) 	result = sysfs_create_link(&pr->cdev->device.kobj,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) 				   &device->dev.kobj,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) 				   "device");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) 	if (result) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) 		dev_err(&pr->cdev->device,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) 			"Failed to create sysfs link 'device'\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) 		goto err_remove_sysfs_thermal;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184)  err_remove_sysfs_thermal:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) 	sysfs_remove_link(&device->dev.kobj, "thermal_cooling");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186)  err_thermal_unregister:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) 	thermal_cooling_device_unregister(pr->cdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) 	return result;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) static void acpi_pss_perf_exit(struct acpi_processor *pr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) 		struct acpi_device *device)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) 	if (pr->cdev) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) 		sysfs_remove_link(&device->dev.kobj, "thermal_cooling");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) 		sysfs_remove_link(&pr->cdev->device.kobj, "device");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) 		thermal_cooling_device_unregister(pr->cdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) 		pr->cdev = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) #else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) static inline int acpi_pss_perf_init(struct acpi_processor *pr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) 		struct acpi_device *device)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) static inline void acpi_pss_perf_exit(struct acpi_processor *pr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) 		struct acpi_device *device) {}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) #endif /* CONFIG_ACPI_CPU_FREQ_PSS */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) static int __acpi_processor_start(struct acpi_device *device)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) 	struct acpi_processor *pr = acpi_driver_data(device);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) 	acpi_status status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) 	int result = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) 	if (!pr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) 		return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) 	if (pr->flags.need_hotplug_init)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) 	result = acpi_cppc_processor_probe(pr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) 	if (result && !IS_ENABLED(CONFIG_ACPI_CPU_FREQ_PSS))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) 		dev_dbg(&device->dev, "CPPC data invalid or not present\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) 	if (!cpuidle_get_driver() || cpuidle_get_driver() == &acpi_idle_driver)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) 		acpi_processor_power_init(pr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) 	result = acpi_pss_perf_init(pr, device);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) 	if (result)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) 		goto err_power_exit;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) 	status = acpi_install_notify_handler(device->handle, ACPI_DEVICE_NOTIFY,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) 					     acpi_processor_notify, device);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) 	if (ACPI_SUCCESS(status))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) 	result = -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) 	acpi_pss_perf_exit(pr, device);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) err_power_exit:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) 	acpi_processor_power_exit(pr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) 	return result;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) static int acpi_processor_start(struct device *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) 	struct acpi_device *device = ACPI_COMPANION(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) 	if (!device)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) 		return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) 	/* Protect against concurrent CPU hotplug operations */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) 	cpu_hotplug_disable();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) 	ret = __acpi_processor_start(device);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) 	cpu_hotplug_enable();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) static int acpi_processor_stop(struct device *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) 	struct acpi_device *device = ACPI_COMPANION(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) 	struct acpi_processor *pr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) 	if (!device)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) 	acpi_remove_notify_handler(device->handle, ACPI_DEVICE_NOTIFY,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) 				   acpi_processor_notify);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) 	pr = acpi_driver_data(device);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) 	if (!pr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) 	acpi_processor_power_exit(pr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) 	acpi_pss_perf_exit(pr, device);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) 	acpi_cppc_processor_exit(pr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) bool acpi_processor_cpufreq_init;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) static int acpi_processor_notifier(struct notifier_block *nb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) 				   unsigned long event, void *data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) 	struct cpufreq_policy *policy = data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) 	if (event == CPUFREQ_CREATE_POLICY) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) 		acpi_thermal_cpufreq_init(policy);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) 		acpi_processor_ppc_init(policy);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) 	} else if (event == CPUFREQ_REMOVE_POLICY) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) 		acpi_processor_ppc_exit(policy);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) 		acpi_thermal_cpufreq_exit(policy);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) static struct notifier_block acpi_processor_notifier_block = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) 	.notifier_call = acpi_processor_notifier,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310)  * We keep the driver loaded even when ACPI is not running.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311)  * This is needed for the powernow-k8 driver, that works even without
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312)  * ACPI, but needs symbols from this driver
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) static enum cpuhp_state hp_online;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) static int __init acpi_processor_driver_init(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317) 	int result = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319) 	if (acpi_disabled)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322) 	result = driver_register(&acpi_processor_driver);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323) 	if (result < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324) 		return result;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326) 	result = cpuhp_setup_state_nocalls(CPUHP_AP_ONLINE_DYN,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327) 					   "acpi/cpu-drv:online",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328) 					   acpi_soft_cpu_online, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329) 	if (result < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330) 		goto err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331) 	hp_online = result;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332) 	cpuhp_setup_state_nocalls(CPUHP_ACPI_CPUDRV_DEAD, "acpi/cpu-drv:dead",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333) 				  NULL, acpi_soft_cpu_dead);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335) 	if (!cpufreq_register_notifier(&acpi_processor_notifier_block,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336) 				       CPUFREQ_POLICY_NOTIFIER)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337) 		acpi_processor_cpufreq_init = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338) 		acpi_processor_ignore_ppc_init();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341) 	acpi_processor_throttling_init();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343) err:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344) 	driver_unregister(&acpi_processor_driver);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345) 	return result;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348) static void __exit acpi_processor_driver_exit(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350) 	if (acpi_disabled)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 351) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 352) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 353) 	if (acpi_processor_cpufreq_init) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 354) 		cpufreq_unregister_notifier(&acpi_processor_notifier_block,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 355) 					    CPUFREQ_POLICY_NOTIFIER);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 356) 		acpi_processor_cpufreq_init = false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 357) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 358) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 359) 	cpuhp_remove_state_nocalls(hp_online);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 360) 	cpuhp_remove_state_nocalls(CPUHP_ACPI_CPUDRV_DEAD);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 361) 	driver_unregister(&acpi_processor_driver);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 362) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 363) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 364) module_init(acpi_processor_driver_init);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 365) module_exit(acpi_processor_driver_exit);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 366) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 367) MODULE_ALIAS("processor");