hc
2024-02-20 102a0743326a03cd1a1202ceda21e175b7d3575c
kernel/drivers/acpi/processor_driver.c
....@@ -1,3 +1,4 @@
1
+// SPDX-License-Identifier: GPL-2.0-or-later
12 /*
23 * processor_driver.c - ACPI Processor Driver
34 *
....@@ -8,20 +9,6 @@
89 * - Added processor hotplug support
910 * Copyright (C) 2013, Intel Corporation
1011 * Rafael J. Wysocki <rafael.j.wysocki@intel.com>
11
- *
12
- * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
13
- *
14
- * This program is free software; you can redistribute it and/or modify
15
- * it under the terms of the GNU General Public License as published by
16
- * the Free Software Foundation; either version 2 of the License, or (at
17
- * your option) any later version.
18
- *
19
- * This program is distributed in the hope that it will be useful, but
20
- * WITHOUT ANY WARRANTY; without even the implied warranty of
21
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
22
- * General Public License for more details.
23
- *
24
- * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
2512 */
2613
2714 #include <linux/kernel.h>
....@@ -297,6 +284,28 @@
297284 return 0;
298285 }
299286
287
+bool acpi_processor_cpufreq_init;
288
+
289
+static int acpi_processor_notifier(struct notifier_block *nb,
290
+ unsigned long event, void *data)
291
+{
292
+ struct cpufreq_policy *policy = data;
293
+
294
+ if (event == CPUFREQ_CREATE_POLICY) {
295
+ acpi_thermal_cpufreq_init(policy);
296
+ acpi_processor_ppc_init(policy);
297
+ } else if (event == CPUFREQ_REMOVE_POLICY) {
298
+ acpi_processor_ppc_exit(policy);
299
+ acpi_thermal_cpufreq_exit(policy);
300
+ }
301
+
302
+ return 0;
303
+}
304
+
305
+static struct notifier_block acpi_processor_notifier_block = {
306
+ .notifier_call = acpi_processor_notifier,
307
+};
308
+
300309 /*
301310 * We keep the driver loaded even when ACPI is not running.
302311 * This is needed for the powernow-k8 driver, that works even without
....@@ -323,8 +332,12 @@
323332 cpuhp_setup_state_nocalls(CPUHP_ACPI_CPUDRV_DEAD, "acpi/cpu-drv:dead",
324333 NULL, acpi_soft_cpu_dead);
325334
326
- acpi_thermal_cpufreq_init();
327
- acpi_processor_ppc_init();
335
+ if (!cpufreq_register_notifier(&acpi_processor_notifier_block,
336
+ CPUFREQ_POLICY_NOTIFIER)) {
337
+ acpi_processor_cpufreq_init = true;
338
+ acpi_processor_ignore_ppc_init();
339
+ }
340
+
328341 acpi_processor_throttling_init();
329342 return 0;
330343 err:
....@@ -337,8 +350,12 @@
337350 if (acpi_disabled)
338351 return;
339352
340
- acpi_processor_ppc_exit();
341
- acpi_thermal_cpufreq_exit();
353
+ if (acpi_processor_cpufreq_init) {
354
+ cpufreq_unregister_notifier(&acpi_processor_notifier_block,
355
+ CPUFREQ_POLICY_NOTIFIER);
356
+ acpi_processor_cpufreq_init = false;
357
+ }
358
+
342359 cpuhp_remove_state_nocalls(hp_online);
343360 cpuhp_remove_state_nocalls(CPUHP_ACPI_CPUDRV_DEAD);
344361 driver_unregister(&acpi_processor_driver);