hc
2023-12-11 d2ccde1c8e90d38cee87a1b0309ad2827f3fd30d
kernel/drivers/cpufreq/powernv-cpufreq.c
....@@ -1,20 +1,10 @@
1
+// SPDX-License-Identifier: GPL-2.0-or-later
12 /*
23 * POWERNV cpufreq driver for the IBM POWER processors
34 *
45 * (C) Copyright IBM 2014
56 *
67 * Author: Vaidyanathan Srinivasan <svaidy at linux.vnet.ibm.com>
7
- *
8
- * This program is free software; you can redistribute it and/or modify
9
- * it under the terms of the GNU General Public License as published by
10
- * the Free Software Foundation; either version 2, or (at your option)
11
- * any later version.
12
- *
13
- * This program is distributed in the hope that it will be useful,
14
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
15
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16
- * GNU General Public License for more details.
17
- *
188 */
199
2010 #define pr_fmt(fmt) "powernv-cpufreq: " fmt
....@@ -75,13 +65,14 @@
7565 * highest_lpstate_idx
7666 * @last_sampled_time: Time from boot in ms when global pstates were
7767 * last set
78
- * @last_lpstate_idx, Last set value of local pstate and global
79
- * last_gpstate_idx pstate in terms of cpufreq table index
68
+ * @last_lpstate_idx: Last set value of local pstate and global
69
+ * @last_gpstate_idx: pstate in terms of cpufreq table index
8070 * @timer: Is used for ramping down if cpu goes idle for
8171 * a long time with global pstate held high
8272 * @gpstate_lock: A spinlock to maintain synchronization between
8373 * routines called by the timer handler and
8474 * governer's target_index calls
75
+ * @policy: Associated CPUFreq policy
8576 */
8677 struct global_pstate_info {
8778 int highest_lpstate_idx;
....@@ -96,7 +87,7 @@
9687
9788 static struct cpufreq_frequency_table powernv_freqs[POWERNV_MAX_PSTATES+1];
9889
99
-DEFINE_HASHTABLE(pstate_revmap, POWERNV_MAX_PSTATES_ORDER);
90
+static DEFINE_HASHTABLE(pstate_revmap, POWERNV_MAX_PSTATES_ORDER);
10091 /**
10192 * struct pstate_idx_revmap_data: Entry in the hashmap pstate_revmap
10293 * indexed by a function of pstate id.
....@@ -181,7 +172,7 @@
181172
182173 /* Use following functions for conversions between pstate_id and index */
183174
184
-/**
175
+/*
185176 * idx_to_pstate : Returns the pstate id corresponding to the
186177 * frequency in the cpufreq frequency table
187178 * powernv_freqs indexed by @i.
....@@ -199,7 +190,7 @@
199190 return powernv_freqs[i].driver_data;
200191 }
201192
202
-/**
193
+/*
203194 * pstate_to_idx : Returns the index in the cpufreq frequencytable
204195 * powernv_freqs for the frequency whose corresponding
205196 * pstate id is @pstate.
....@@ -245,6 +236,7 @@
245236 u32 len_ids, len_freqs;
246237 u32 pstate_min, pstate_max, pstate_nominal;
247238 u32 pstate_turbo, pstate_ultra_turbo;
239
+ int rc = -ENODEV;
248240
249241 power_mgt = of_find_node_by_path("/ibm,opal/power-mgt");
250242 if (!power_mgt) {
....@@ -254,18 +246,18 @@
254246
255247 if (of_property_read_u32(power_mgt, "ibm,pstate-min", &pstate_min)) {
256248 pr_warn("ibm,pstate-min node not found\n");
257
- return -ENODEV;
249
+ goto out;
258250 }
259251
260252 if (of_property_read_u32(power_mgt, "ibm,pstate-max", &pstate_max)) {
261253 pr_warn("ibm,pstate-max node not found\n");
262
- return -ENODEV;
254
+ goto out;
263255 }
264256
265257 if (of_property_read_u32(power_mgt, "ibm,pstate-nominal",
266258 &pstate_nominal)) {
267259 pr_warn("ibm,pstate-nominal not found\n");
268
- return -ENODEV;
260
+ goto out;
269261 }
270262
271263 if (of_property_read_u32(power_mgt, "ibm,pstate-ultra-turbo",
....@@ -294,14 +286,14 @@
294286 pstate_ids = of_get_property(power_mgt, "ibm,pstate-ids", &len_ids);
295287 if (!pstate_ids) {
296288 pr_warn("ibm,pstate-ids not found\n");
297
- return -ENODEV;
289
+ goto out;
298290 }
299291
300292 pstate_freqs = of_get_property(power_mgt, "ibm,pstate-frequencies-mhz",
301293 &len_freqs);
302294 if (!pstate_freqs) {
303295 pr_warn("ibm,pstate-frequencies-mhz not found\n");
304
- return -ENODEV;
296
+ goto out;
305297 }
306298
307299 if (len_ids != len_freqs) {
....@@ -312,7 +304,7 @@
312304 nr_pstates = min(len_ids, len_freqs) / sizeof(u32);
313305 if (!nr_pstates) {
314306 pr_warn("No PStates found\n");
315
- return -ENODEV;
307
+ goto out;
316308 }
317309
318310 powernv_pstate_info.nr_pstates = nr_pstates;
....@@ -328,8 +320,11 @@
328320 powernv_freqs[i].frequency = freq * 1000; /* kHz */
329321 powernv_freqs[i].driver_data = id & 0xFF;
330322
331
- revmap_data = (struct pstate_idx_revmap_data *)
332
- kmalloc(sizeof(*revmap_data), GFP_KERNEL);
323
+ revmap_data = kmalloc(sizeof(*revmap_data), GFP_KERNEL);
324
+ if (!revmap_data) {
325
+ rc = -ENOMEM;
326
+ goto out;
327
+ }
333328
334329 revmap_data->pstate_id = id & 0xFF;
335330 revmap_data->cpufreq_table_idx = i;
....@@ -353,7 +348,12 @@
353348
354349 /* End of list marker entry */
355350 powernv_freqs[i].frequency = CPUFREQ_TABLE_END;
351
+
352
+ of_node_put(power_mgt);
356353 return 0;
354
+out:
355
+ of_node_put(power_mgt);
356
+ return rc;
357357 }
358358
359359 /* Returns the CPU frequency corresponding to the pstate_id. */
....@@ -382,7 +382,7 @@
382382 powernv_freqs[powernv_pstate_info.nominal].frequency);
383383 }
384384
385
-struct freq_attr cpufreq_freq_attr_cpuinfo_nominal_freq =
385
+static struct freq_attr cpufreq_freq_attr_cpuinfo_nominal_freq =
386386 __ATTR_RO(cpuinfo_nominal_freq);
387387
388388 #define SCALING_BOOST_FREQS_ATTR_INDEX 2
....@@ -662,13 +662,13 @@
662662 /**
663663 * gpstate_timer_handler
664664 *
665
- * @data: pointer to cpufreq_policy on which timer was queued
665
+ * @t: Timer context used to fetch global pstate info struct
666666 *
667667 * This handler brings down the global pstate closer to the local pstate
668668 * according quadratic equation. Queues a new timer if it is still not equal
669669 * to local pstate
670670 */
671
-void gpstate_timer_handler(struct timer_list *t)
671
+static void gpstate_timer_handler(struct timer_list *t)
672672 {
673673 struct global_pstate_info *gpstates = from_timer(gpstates, t, timer);
674674 struct cpufreq_policy *policy = gpstates->policy;
....@@ -904,7 +904,7 @@
904904 .notifier_call = powernv_cpufreq_reboot_notifier,
905905 };
906906
907
-void powernv_cpufreq_work_fn(struct work_struct *work)
907
+static void powernv_cpufreq_work_fn(struct work_struct *work)
908908 {
909909 struct chip *chip = container_of(work, struct chip, throttle);
910910 struct cpufreq_policy *policy;
....@@ -1133,9 +1133,6 @@
11331133 if (rc)
11341134 goto out;
11351135
1136
- register_reboot_notifier(&powernv_cpufreq_reboot_nb);
1137
- opal_message_notifier_register(OPAL_MSG_OCC, &powernv_cpufreq_opal_nb);
1138
-
11391136 if (powernv_pstate_info.wof_enabled)
11401137 powernv_cpufreq_driver.boost_enabled = true;
11411138 else
....@@ -1144,15 +1141,17 @@
11441141 rc = cpufreq_register_driver(&powernv_cpufreq_driver);
11451142 if (rc) {
11461143 pr_info("Failed to register the cpufreq driver (%d)\n", rc);
1147
- goto cleanup_notifiers;
1144
+ goto cleanup;
11481145 }
11491146
11501147 if (powernv_pstate_info.wof_enabled)
11511148 cpufreq_enable_boost_support();
11521149
1150
+ register_reboot_notifier(&powernv_cpufreq_reboot_nb);
1151
+ opal_message_notifier_register(OPAL_MSG_OCC, &powernv_cpufreq_opal_nb);
1152
+
11531153 return 0;
1154
-cleanup_notifiers:
1155
- unregister_all_notifiers();
1154
+cleanup:
11561155 clean_chip_info();
11571156 out:
11581157 pr_info("Platform driver disabled. System does not support PState control\n");