.. | .. |
---|
| 1 | +// SPDX-License-Identifier: GPL-2.0-or-later |
---|
1 | 2 | /* |
---|
2 | 3 | * pmi backend for the cbe_cpufreq driver |
---|
3 | 4 | * |
---|
4 | 5 | * (C) Copyright IBM Deutschland Entwicklung GmbH 2005-2007 |
---|
5 | 6 | * |
---|
6 | 7 | * Author: Christian Krafft <krafft@de.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 | | - * |
---|
18 | | - * You should have received a copy of the GNU General Public License |
---|
19 | | - * along with this program; if not, write to the Free Software |
---|
20 | | - * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
---|
21 | 8 | */ |
---|
22 | 9 | |
---|
23 | 10 | #include <linux/kernel.h> |
---|
.. | .. |
---|
25 | 12 | #include <linux/timer.h> |
---|
26 | 13 | #include <linux/init.h> |
---|
27 | 14 | #include <linux/of_platform.h> |
---|
| 15 | +#include <linux/pm_qos.h> |
---|
28 | 16 | |
---|
29 | 17 | #include <asm/processor.h> |
---|
30 | 18 | #include <asm/prom.h> |
---|
.. | .. |
---|
36 | 24 | #endif |
---|
37 | 25 | |
---|
38 | 26 | #include "ppc_cbe_cpufreq.h" |
---|
39 | | - |
---|
40 | | -static u8 pmi_slow_mode_limit[MAX_CBE]; |
---|
41 | 27 | |
---|
42 | 28 | bool cbe_cpufreq_has_pmi = false; |
---|
43 | 29 | EXPORT_SYMBOL_GPL(cbe_cpufreq_has_pmi); |
---|
.. | .. |
---|
78 | 64 | |
---|
79 | 65 | static void cbe_cpufreq_handle_pmi(pmi_message_t pmi_msg) |
---|
80 | 66 | { |
---|
| 67 | + struct cpufreq_policy *policy; |
---|
| 68 | + struct freq_qos_request *req; |
---|
81 | 69 | u8 node, slow_mode; |
---|
| 70 | + int cpu, ret; |
---|
82 | 71 | |
---|
83 | 72 | BUG_ON(pmi_msg.type != PMI_TYPE_FREQ_CHANGE); |
---|
84 | 73 | |
---|
85 | 74 | node = pmi_msg.data1; |
---|
86 | 75 | slow_mode = pmi_msg.data2; |
---|
87 | 76 | |
---|
88 | | - pmi_slow_mode_limit[node] = slow_mode; |
---|
| 77 | + cpu = cbe_node_to_cpu(node); |
---|
89 | 78 | |
---|
90 | 79 | pr_debug("cbe_handle_pmi: node: %d max_freq: %d\n", node, slow_mode); |
---|
91 | | -} |
---|
92 | 80 | |
---|
93 | | -static int pmi_notifier(struct notifier_block *nb, |
---|
94 | | - unsigned long event, void *data) |
---|
95 | | -{ |
---|
96 | | - struct cpufreq_policy *policy = data; |
---|
97 | | - struct cpufreq_frequency_table *cbe_freqs = policy->freq_table; |
---|
98 | | - u8 node; |
---|
99 | | - |
---|
100 | | - /* Should this really be called for CPUFREQ_ADJUST and CPUFREQ_NOTIFY |
---|
101 | | - * policy events?) |
---|
102 | | - */ |
---|
103 | | - node = cbe_cpu_to_node(policy->cpu); |
---|
104 | | - |
---|
105 | | - pr_debug("got notified, event=%lu, node=%u\n", event, node); |
---|
106 | | - |
---|
107 | | - if (pmi_slow_mode_limit[node] != 0) { |
---|
108 | | - pr_debug("limiting node %d to slow mode %d\n", |
---|
109 | | - node, pmi_slow_mode_limit[node]); |
---|
110 | | - |
---|
111 | | - cpufreq_verify_within_limits(policy, 0, |
---|
112 | | - |
---|
113 | | - cbe_freqs[pmi_slow_mode_limit[node]].frequency); |
---|
| 81 | + policy = cpufreq_cpu_get(cpu); |
---|
| 82 | + if (!policy) { |
---|
| 83 | + pr_warn("cpufreq policy not found cpu%d\n", cpu); |
---|
| 84 | + return; |
---|
114 | 85 | } |
---|
115 | 86 | |
---|
116 | | - return 0; |
---|
117 | | -} |
---|
| 87 | + req = policy->driver_data; |
---|
118 | 88 | |
---|
119 | | -static struct notifier_block pmi_notifier_block = { |
---|
120 | | - .notifier_call = pmi_notifier, |
---|
121 | | -}; |
---|
| 89 | + ret = freq_qos_update_request(req, |
---|
| 90 | + policy->freq_table[slow_mode].frequency); |
---|
| 91 | + if (ret < 0) |
---|
| 92 | + pr_warn("Failed to update freq constraint: %d\n", ret); |
---|
| 93 | + else |
---|
| 94 | + pr_debug("limiting node %d to slow mode %d\n", node, slow_mode); |
---|
| 95 | + |
---|
| 96 | + cpufreq_cpu_put(policy); |
---|
| 97 | +} |
---|
122 | 98 | |
---|
123 | 99 | static struct pmi_handler cbe_pmi_handler = { |
---|
124 | 100 | .type = PMI_TYPE_FREQ_CHANGE, |
---|
125 | 101 | .handle_pmi_message = cbe_cpufreq_handle_pmi, |
---|
126 | 102 | }; |
---|
127 | 103 | |
---|
128 | | - |
---|
129 | | - |
---|
130 | | -static int __init cbe_cpufreq_pmi_init(void) |
---|
| 104 | +void cbe_cpufreq_pmi_policy_init(struct cpufreq_policy *policy) |
---|
131 | 105 | { |
---|
132 | | - cbe_cpufreq_has_pmi = pmi_register_handler(&cbe_pmi_handler) == 0; |
---|
| 106 | + struct freq_qos_request *req; |
---|
| 107 | + int ret; |
---|
133 | 108 | |
---|
134 | 109 | if (!cbe_cpufreq_has_pmi) |
---|
135 | | - return -ENODEV; |
---|
| 110 | + return; |
---|
136 | 111 | |
---|
137 | | - cpufreq_register_notifier(&pmi_notifier_block, CPUFREQ_POLICY_NOTIFIER); |
---|
| 112 | + req = kzalloc(sizeof(*req), GFP_KERNEL); |
---|
| 113 | + if (!req) |
---|
| 114 | + return; |
---|
138 | 115 | |
---|
139 | | - return 0; |
---|
| 116 | + ret = freq_qos_add_request(&policy->constraints, req, FREQ_QOS_MAX, |
---|
| 117 | + policy->freq_table[0].frequency); |
---|
| 118 | + if (ret < 0) { |
---|
| 119 | + pr_err("Failed to add freq constraint (%d)\n", ret); |
---|
| 120 | + kfree(req); |
---|
| 121 | + return; |
---|
| 122 | + } |
---|
| 123 | + |
---|
| 124 | + policy->driver_data = req; |
---|
140 | 125 | } |
---|
141 | | -device_initcall(cbe_cpufreq_pmi_init); |
---|
| 126 | +EXPORT_SYMBOL_GPL(cbe_cpufreq_pmi_policy_init); |
---|
| 127 | + |
---|
| 128 | +void cbe_cpufreq_pmi_policy_exit(struct cpufreq_policy *policy) |
---|
| 129 | +{ |
---|
| 130 | + struct freq_qos_request *req = policy->driver_data; |
---|
| 131 | + |
---|
| 132 | + if (cbe_cpufreq_has_pmi) { |
---|
| 133 | + freq_qos_remove_request(req); |
---|
| 134 | + kfree(req); |
---|
| 135 | + } |
---|
| 136 | +} |
---|
| 137 | +EXPORT_SYMBOL_GPL(cbe_cpufreq_pmi_policy_exit); |
---|
| 138 | + |
---|
| 139 | +void cbe_cpufreq_pmi_init(void) |
---|
| 140 | +{ |
---|
| 141 | + if (!pmi_register_handler(&cbe_pmi_handler)) |
---|
| 142 | + cbe_cpufreq_has_pmi = true; |
---|
| 143 | +} |
---|
| 144 | +EXPORT_SYMBOL_GPL(cbe_cpufreq_pmi_init); |
---|
| 145 | + |
---|
| 146 | +void cbe_cpufreq_pmi_exit(void) |
---|
| 147 | +{ |
---|
| 148 | + pmi_unregister_handler(&cbe_pmi_handler); |
---|
| 149 | + cbe_cpufreq_has_pmi = false; |
---|
| 150 | +} |
---|
| 151 | +EXPORT_SYMBOL_GPL(cbe_cpufreq_pmi_exit); |
---|