xref: /dpdk/drivers/power/cppc/cppc_cpufreq.h (revision 6f987b594fa6751b49769755fe1d1bf9f9d15ac4)
1*6f987b59SSivaprasad Tummala /* SPDX-License-Identifier: BSD-3-Clause
2*6f987b59SSivaprasad Tummala  * Copyright(c) 2010-2021 Intel Corporation
3*6f987b59SSivaprasad Tummala  * Copyright(c) 2021 Arm Limited
4*6f987b59SSivaprasad Tummala  */
5*6f987b59SSivaprasad Tummala 
6*6f987b59SSivaprasad Tummala #ifndef CPPC_CPUFREQ_H
7*6f987b59SSivaprasad Tummala #define CPPC_CPUFREQ_H
8*6f987b59SSivaprasad Tummala 
9*6f987b59SSivaprasad Tummala /**
10*6f987b59SSivaprasad Tummala  * @file
11*6f987b59SSivaprasad Tummala  * Power Management via userspace CPPC cpufreq
12*6f987b59SSivaprasad Tummala  */
13*6f987b59SSivaprasad Tummala 
14*6f987b59SSivaprasad Tummala #include "power_cpufreq.h"
15*6f987b59SSivaprasad Tummala 
16*6f987b59SSivaprasad Tummala /**
17*6f987b59SSivaprasad Tummala  * Check if CPPC power management is supported.
18*6f987b59SSivaprasad Tummala  *
19*6f987b59SSivaprasad Tummala  * @return
20*6f987b59SSivaprasad Tummala  *   - 1 if supported
21*6f987b59SSivaprasad Tummala  *   - 0 if unsupported
22*6f987b59SSivaprasad Tummala  *   - -1 if error, with rte_errno indicating reason for error.
23*6f987b59SSivaprasad Tummala  */
24*6f987b59SSivaprasad Tummala int power_cppc_cpufreq_check_supported(void);
25*6f987b59SSivaprasad Tummala 
26*6f987b59SSivaprasad Tummala /**
27*6f987b59SSivaprasad Tummala  * Initialize power management for a specific lcore. It will check and set the
28*6f987b59SSivaprasad Tummala  * governor to userspace for the lcore, get the available frequencies, and
29*6f987b59SSivaprasad Tummala  * prepare to set new lcore frequency.
30*6f987b59SSivaprasad Tummala  *
31*6f987b59SSivaprasad Tummala  * @param lcore_id
32*6f987b59SSivaprasad Tummala  *  lcore id.
33*6f987b59SSivaprasad Tummala  *
34*6f987b59SSivaprasad Tummala  * @return
35*6f987b59SSivaprasad Tummala  *  - 0 on success.
36*6f987b59SSivaprasad Tummala  *  - Negative on error.
37*6f987b59SSivaprasad Tummala  */
38*6f987b59SSivaprasad Tummala int power_cppc_cpufreq_init(unsigned int lcore_id);
39*6f987b59SSivaprasad Tummala 
40*6f987b59SSivaprasad Tummala /**
41*6f987b59SSivaprasad Tummala  * Exit power management on a specific lcore. It will set the governor to which
42*6f987b59SSivaprasad Tummala  * is before initialized.
43*6f987b59SSivaprasad Tummala  *
44*6f987b59SSivaprasad Tummala  * @param lcore_id
45*6f987b59SSivaprasad Tummala  *  lcore id.
46*6f987b59SSivaprasad Tummala  *
47*6f987b59SSivaprasad Tummala  * @return
48*6f987b59SSivaprasad Tummala  *  - 0 on success.
49*6f987b59SSivaprasad Tummala  *  - Negative on error.
50*6f987b59SSivaprasad Tummala  */
51*6f987b59SSivaprasad Tummala int power_cppc_cpufreq_exit(unsigned int lcore_id);
52*6f987b59SSivaprasad Tummala 
53*6f987b59SSivaprasad Tummala /**
54*6f987b59SSivaprasad Tummala  * Get the available frequencies of a specific lcore. The return value will be
55*6f987b59SSivaprasad Tummala  * the minimal one of the total number of available frequencies and the number
56*6f987b59SSivaprasad Tummala  * of buffer. The index of available frequencies used in other interfaces
57*6f987b59SSivaprasad Tummala  * should be in the range of 0 to this return value.
58*6f987b59SSivaprasad Tummala  * It should be protected outside of this function for threadsafe.
59*6f987b59SSivaprasad Tummala  *
60*6f987b59SSivaprasad Tummala  * @param lcore_id
61*6f987b59SSivaprasad Tummala  *  lcore id.
62*6f987b59SSivaprasad Tummala  * @param freqs
63*6f987b59SSivaprasad Tummala  *  The buffer array to save the frequencies.
64*6f987b59SSivaprasad Tummala  * @param num
65*6f987b59SSivaprasad Tummala  *  The number of frequencies to get.
66*6f987b59SSivaprasad Tummala  *
67*6f987b59SSivaprasad Tummala  * @return
68*6f987b59SSivaprasad Tummala  *  The number of available frequencies.
69*6f987b59SSivaprasad Tummala  */
70*6f987b59SSivaprasad Tummala uint32_t power_cppc_cpufreq_freqs(unsigned int lcore_id, uint32_t *freqs,
71*6f987b59SSivaprasad Tummala 		uint32_t num);
72*6f987b59SSivaprasad Tummala 
73*6f987b59SSivaprasad Tummala /**
74*6f987b59SSivaprasad Tummala  * Return the current index of available frequencies of a specific lcore. It
75*6f987b59SSivaprasad Tummala  * will return 'RTE_POWER_INVALID_FREQ_INDEX = (~0)' if error.
76*6f987b59SSivaprasad Tummala  * It should be protected outside of this function for threadsafe.
77*6f987b59SSivaprasad Tummala  *
78*6f987b59SSivaprasad Tummala  * @param lcore_id
79*6f987b59SSivaprasad Tummala  *  lcore id.
80*6f987b59SSivaprasad Tummala  *
81*6f987b59SSivaprasad Tummala  * @return
82*6f987b59SSivaprasad Tummala  *  The current index of available frequencies.
83*6f987b59SSivaprasad Tummala  */
84*6f987b59SSivaprasad Tummala uint32_t power_cppc_cpufreq_get_freq(unsigned int lcore_id);
85*6f987b59SSivaprasad Tummala 
86*6f987b59SSivaprasad Tummala /**
87*6f987b59SSivaprasad Tummala  * Set the new frequency for a specific lcore by indicating the index of
88*6f987b59SSivaprasad Tummala  * available frequencies.
89*6f987b59SSivaprasad Tummala  * It should be protected outside of this function for threadsafe.
90*6f987b59SSivaprasad Tummala  *
91*6f987b59SSivaprasad Tummala  * @param lcore_id
92*6f987b59SSivaprasad Tummala  *  lcore id.
93*6f987b59SSivaprasad Tummala  * @param index
94*6f987b59SSivaprasad Tummala  *  The index of available frequencies.
95*6f987b59SSivaprasad Tummala  *
96*6f987b59SSivaprasad Tummala  * @return
97*6f987b59SSivaprasad Tummala  *  - 1 on success with frequency changed.
98*6f987b59SSivaprasad Tummala  *  - 0 on success without frequency changed.
99*6f987b59SSivaprasad Tummala  *  - Negative on error.
100*6f987b59SSivaprasad Tummala  */
101*6f987b59SSivaprasad Tummala int power_cppc_cpufreq_set_freq(unsigned int lcore_id, uint32_t index);
102*6f987b59SSivaprasad Tummala 
103*6f987b59SSivaprasad Tummala /**
104*6f987b59SSivaprasad Tummala  * Scale up the frequency of a specific lcore according to the available
105*6f987b59SSivaprasad Tummala  * frequencies.
106*6f987b59SSivaprasad Tummala  * It should be protected outside of this function for threadsafe.
107*6f987b59SSivaprasad Tummala  *
108*6f987b59SSivaprasad Tummala  * @param lcore_id
109*6f987b59SSivaprasad Tummala  *  lcore id.
110*6f987b59SSivaprasad Tummala  *
111*6f987b59SSivaprasad Tummala  * @return
112*6f987b59SSivaprasad Tummala  *  - 1 on success with frequency changed.
113*6f987b59SSivaprasad Tummala  *  - 0 on success without frequency changed.
114*6f987b59SSivaprasad Tummala  *  - Negative on error.
115*6f987b59SSivaprasad Tummala  */
116*6f987b59SSivaprasad Tummala int power_cppc_cpufreq_freq_up(unsigned int lcore_id);
117*6f987b59SSivaprasad Tummala 
118*6f987b59SSivaprasad Tummala /**
119*6f987b59SSivaprasad Tummala  * Scale down the frequency of a specific lcore according to the available
120*6f987b59SSivaprasad Tummala  * frequencies.
121*6f987b59SSivaprasad Tummala  * It should be protected outside of this function for threadsafe.
122*6f987b59SSivaprasad Tummala  *
123*6f987b59SSivaprasad Tummala  * @param lcore_id
124*6f987b59SSivaprasad Tummala  *  lcore id.
125*6f987b59SSivaprasad Tummala  *
126*6f987b59SSivaprasad Tummala  * @return
127*6f987b59SSivaprasad Tummala  *  - 1 on success with frequency changed.
128*6f987b59SSivaprasad Tummala  *  - 0 on success without frequency changed.
129*6f987b59SSivaprasad Tummala  *  - Negative on error.
130*6f987b59SSivaprasad Tummala  */
131*6f987b59SSivaprasad Tummala int power_cppc_cpufreq_freq_down(unsigned int lcore_id);
132*6f987b59SSivaprasad Tummala 
133*6f987b59SSivaprasad Tummala /**
134*6f987b59SSivaprasad Tummala  * Scale up the frequency of a specific lcore to the highest according to the
135*6f987b59SSivaprasad Tummala  * available frequencies.
136*6f987b59SSivaprasad Tummala  * It should be protected outside of this function for threadsafe.
137*6f987b59SSivaprasad Tummala  *
138*6f987b59SSivaprasad Tummala  * @param lcore_id
139*6f987b59SSivaprasad Tummala  *  lcore id.
140*6f987b59SSivaprasad Tummala  *
141*6f987b59SSivaprasad Tummala  * @return
142*6f987b59SSivaprasad Tummala  *  - 1 on success with frequency changed.
143*6f987b59SSivaprasad Tummala  *  - 0 on success without frequency changed.
144*6f987b59SSivaprasad Tummala  *  - Negative on error.
145*6f987b59SSivaprasad Tummala  */
146*6f987b59SSivaprasad Tummala int power_cppc_cpufreq_freq_max(unsigned int lcore_id);
147*6f987b59SSivaprasad Tummala 
148*6f987b59SSivaprasad Tummala /**
149*6f987b59SSivaprasad Tummala  * Scale down the frequency of a specific lcore to the lowest according to the
150*6f987b59SSivaprasad Tummala  * available frequencies.
151*6f987b59SSivaprasad Tummala  * It should be protected outside of this function for threadsafe.
152*6f987b59SSivaprasad Tummala  *
153*6f987b59SSivaprasad Tummala  * @param lcore_id
154*6f987b59SSivaprasad Tummala  *  lcore id.
155*6f987b59SSivaprasad Tummala  *
156*6f987b59SSivaprasad Tummala  * @return
157*6f987b59SSivaprasad Tummala  *  - 1 on success with frequency changed.
158*6f987b59SSivaprasad Tummala  *  - 0 on success without frequency changed.
159*6f987b59SSivaprasad Tummala  *  - Negative on error.
160*6f987b59SSivaprasad Tummala  */
161*6f987b59SSivaprasad Tummala int power_cppc_cpufreq_freq_min(unsigned int lcore_id);
162*6f987b59SSivaprasad Tummala 
163*6f987b59SSivaprasad Tummala /**
164*6f987b59SSivaprasad Tummala  * Get the turbo status of a specific lcore.
165*6f987b59SSivaprasad Tummala  * It should be protected outside of this function for threadsafe.
166*6f987b59SSivaprasad Tummala  *
167*6f987b59SSivaprasad Tummala  * @param lcore_id
168*6f987b59SSivaprasad Tummala  *  lcore id.
169*6f987b59SSivaprasad Tummala  *
170*6f987b59SSivaprasad Tummala  * @return
171*6f987b59SSivaprasad Tummala  *  - 1 Turbo Boost is enabled on this lcore.
172*6f987b59SSivaprasad Tummala  *  - 0 Turbo Boost is disabled on this lcore.
173*6f987b59SSivaprasad Tummala  *  - Negative on error.
174*6f987b59SSivaprasad Tummala  */
175*6f987b59SSivaprasad Tummala int power_cppc_turbo_status(unsigned int lcore_id);
176*6f987b59SSivaprasad Tummala 
177*6f987b59SSivaprasad Tummala /**
178*6f987b59SSivaprasad Tummala  * Enable Turbo Boost on a specific lcore.
179*6f987b59SSivaprasad Tummala  * It should be protected outside of this function for threadsafe.
180*6f987b59SSivaprasad Tummala  *
181*6f987b59SSivaprasad Tummala  * @param lcore_id
182*6f987b59SSivaprasad Tummala  *  lcore id.
183*6f987b59SSivaprasad Tummala  *
184*6f987b59SSivaprasad Tummala  * @return
185*6f987b59SSivaprasad Tummala  *  - 0 Turbo Boost is enabled successfully on this lcore.
186*6f987b59SSivaprasad Tummala  *  - Negative on error.
187*6f987b59SSivaprasad Tummala  */
188*6f987b59SSivaprasad Tummala int power_cppc_enable_turbo(unsigned int lcore_id);
189*6f987b59SSivaprasad Tummala 
190*6f987b59SSivaprasad Tummala /**
191*6f987b59SSivaprasad Tummala  * Disable Turbo Boost on a specific lcore.
192*6f987b59SSivaprasad Tummala  * It should be protected outside of this function for threadsafe.
193*6f987b59SSivaprasad Tummala  *
194*6f987b59SSivaprasad Tummala  * @param lcore_id
195*6f987b59SSivaprasad Tummala  *  lcore id.
196*6f987b59SSivaprasad Tummala  *
197*6f987b59SSivaprasad Tummala  * @return
198*6f987b59SSivaprasad Tummala  *  - 0 Turbo Boost disabled successfully on this lcore.
199*6f987b59SSivaprasad Tummala  *  - Negative on error.
200*6f987b59SSivaprasad Tummala  */
201*6f987b59SSivaprasad Tummala int power_cppc_disable_turbo(unsigned int lcore_id);
202*6f987b59SSivaprasad Tummala 
203*6f987b59SSivaprasad Tummala /**
204*6f987b59SSivaprasad Tummala  * Returns power capabilities for a specific lcore.
205*6f987b59SSivaprasad Tummala  *
206*6f987b59SSivaprasad Tummala  * @param lcore_id
207*6f987b59SSivaprasad Tummala  *  lcore id.
208*6f987b59SSivaprasad Tummala  * @param caps
209*6f987b59SSivaprasad Tummala  *  pointer to rte_power_core_capabilities object.
210*6f987b59SSivaprasad Tummala  *
211*6f987b59SSivaprasad Tummala  * @return
212*6f987b59SSivaprasad Tummala  *  - 0 on success.
213*6f987b59SSivaprasad Tummala  *  - Negative on error.
214*6f987b59SSivaprasad Tummala  */
215*6f987b59SSivaprasad Tummala int power_cppc_get_capabilities(unsigned int lcore_id,
216*6f987b59SSivaprasad Tummala 		struct rte_power_core_capabilities *caps);
217*6f987b59SSivaprasad Tummala 
218*6f987b59SSivaprasad Tummala #endif /* CPPC_CPUFREQ_H */
219