~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

TOMOYO Linux Cross Reference
Linux/Documentation/cpu-freq/cpu-drivers.rst

Version: ~ [ linux-6.11.5 ] ~ [ linux-6.10.14 ] ~ [ linux-6.9.12 ] ~ [ linux-6.8.12 ] ~ [ linux-6.7.12 ] ~ [ linux-6.6.58 ] ~ [ linux-6.5.13 ] ~ [ linux-6.4.16 ] ~ [ linux-6.3.13 ] ~ [ linux-6.2.16 ] ~ [ linux-6.1.114 ] ~ [ linux-6.0.19 ] ~ [ linux-5.19.17 ] ~ [ linux-5.18.19 ] ~ [ linux-5.17.15 ] ~ [ linux-5.16.20 ] ~ [ linux-5.15.169 ] ~ [ linux-5.14.21 ] ~ [ linux-5.13.19 ] ~ [ linux-5.12.19 ] ~ [ linux-5.11.22 ] ~ [ linux-5.10.228 ] ~ [ linux-5.9.16 ] ~ [ linux-5.8.18 ] ~ [ linux-5.7.19 ] ~ [ linux-5.6.19 ] ~ [ linux-5.5.19 ] ~ [ linux-5.4.284 ] ~ [ linux-5.3.18 ] ~ [ linux-5.2.21 ] ~ [ linux-5.1.21 ] ~ [ linux-5.0.21 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.322 ] ~ [ linux-4.18.20 ] ~ [ linux-4.17.19 ] ~ [ linux-4.16.18 ] ~ [ linux-4.15.18 ] ~ [ linux-4.14.336 ] ~ [ linux-4.13.16 ] ~ [ linux-4.12.14 ] ~ [ linux-4.11.12 ] ~ [ linux-4.10.17 ] ~ [ linux-4.9.337 ] ~ [ linux-4.4.302 ] ~ [ linux-3.10.108 ] ~ [ linux-2.6.32.71 ] ~ [ linux-2.6.0 ] ~ [ linux-2.4.37.11 ] ~ [ unix-v6-master ] ~ [ ccs-tools-1.8.9 ] ~ [ policy-sample ] ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

Diff markup

Differences between /Documentation/cpu-freq/cpu-drivers.rst (Version linux-6.11.5) and /Documentation/cpu-freq/cpu-drivers.rst (Version linux-5.13.19)


  1 .. SPDX-License-Identifier: GPL-2.0                 1 .. SPDX-License-Identifier: GPL-2.0
  2                                                     2 
  3 ==============================================      3 ===============================================
  4 How to Implement a new CPUFreq Processor Drive      4 How to Implement a new CPUFreq Processor Driver
  5 ==============================================      5 ===============================================
  6                                                     6 
  7 Authors:                                            7 Authors:
  8                                                     8 
  9                                                     9 
 10         - Dominik Brodowski  <linux@brodo.de>       10         - Dominik Brodowski  <linux@brodo.de>
 11         - Rafael J. Wysocki <rafael.j.wysocki@i     11         - Rafael J. Wysocki <rafael.j.wysocki@intel.com>
 12         - Viresh Kumar <viresh.kumar@linaro.org     12         - Viresh Kumar <viresh.kumar@linaro.org>
 13                                                    13 
 14 .. Contents                                        14 .. Contents
 15                                                    15 
 16    1.   What To Do?                                16    1.   What To Do?
 17    1.1  Initialization                             17    1.1  Initialization
 18    1.2  Per-CPU Initialization                     18    1.2  Per-CPU Initialization
 19    1.3  verify                                     19    1.3  verify
 20    1.4  target/target_index or setpolicy?          20    1.4  target/target_index or setpolicy?
 21    1.5  target/target_index                        21    1.5  target/target_index
 22    1.6  setpolicy                                  22    1.6  setpolicy
 23    1.7  get_intermediate and target_intermedia     23    1.7  get_intermediate and target_intermediate
 24    2.   Frequency Table Helpers                    24    2.   Frequency Table Helpers
 25                                                    25 
 26                                                    26 
 27                                                    27 
 28 1. What To Do?                                     28 1. What To Do?
 29 ==============                                     29 ==============
 30                                                    30 
 31 So, you just got a brand-new CPU / chipset wit     31 So, you just got a brand-new CPU / chipset with datasheets and want to
 32 add cpufreq support for this CPU / chipset? Gr     32 add cpufreq support for this CPU / chipset? Great. Here are some hints
 33 on what is necessary:                              33 on what is necessary:
 34                                                    34 
 35                                                    35 
 36 1.1 Initialization                                 36 1.1 Initialization
 37 ------------------                                 37 ------------------
 38                                                    38 
 39 First of all, in an __initcall level 7 (module     39 First of all, in an __initcall level 7 (module_init()) or later
 40 function check whether this kernel runs on the     40 function check whether this kernel runs on the right CPU and the right
 41 chipset. If so, register a struct cpufreq_driv     41 chipset. If so, register a struct cpufreq_driver with the CPUfreq core
 42 using cpufreq_register_driver()                    42 using cpufreq_register_driver()
 43                                                    43 
 44 What shall this struct cpufreq_driver contain?     44 What shall this struct cpufreq_driver contain?
 45                                                    45 
 46  .name - The name of this driver.                  46  .name - The name of this driver.
 47                                                    47 
 48  .init - A pointer to the per-policy initializ     48  .init - A pointer to the per-policy initialization function.
 49                                                    49 
 50  .verify - A pointer to a "verification" funct     50  .verify - A pointer to a "verification" function.
 51                                                    51 
 52  .setpolicy _or_ .fast_switch _or_ .target _or     52  .setpolicy _or_ .fast_switch _or_ .target _or_ .target_index - See
 53  below on the differences.                         53  below on the differences.
 54                                                    54 
 55 And optionally                                     55 And optionally
 56                                                    56 
 57  .flags - Hints for the cpufreq core.              57  .flags - Hints for the cpufreq core.
 58                                                    58 
 59  .driver_data - cpufreq driver specific data.      59  .driver_data - cpufreq driver specific data.
 60                                                    60 
                                                   >>  61  .resolve_freq - Returns the most appropriate frequency for a target
                                                   >>  62  frequency. Doesn't change the frequency though.
                                                   >>  63 
 61  .get_intermediate and target_intermediate - U     64  .get_intermediate and target_intermediate - Used to switch to stable
 62  frequency while changing CPU frequency.           65  frequency while changing CPU frequency.
 63                                                    66 
 64  .get - Returns current frequency of the CPU.      67  .get - Returns current frequency of the CPU.
 65                                                    68 
 66  .bios_limit - Returns HW/BIOS max frequency l     69  .bios_limit - Returns HW/BIOS max frequency limitations for the CPU.
 67                                                    70 
 68  .exit - A pointer to a per-policy cleanup fun     71  .exit - A pointer to a per-policy cleanup function called during
 69  CPU_POST_DEAD phase of cpu hotplug process.       72  CPU_POST_DEAD phase of cpu hotplug process.
                                                   >>  73 
                                                   >>  74  .stop_cpu - A pointer to a per-policy stop function called during
                                                   >>  75  CPU_DOWN_PREPARE phase of cpu hotplug process.
 70                                                    76 
 71  .suspend - A pointer to a per-policy suspend      77  .suspend - A pointer to a per-policy suspend function which is called
 72  with interrupts disabled and _after_ the gove     78  with interrupts disabled and _after_ the governor is stopped for the
 73  policy.                                           79  policy.
 74                                                    80 
 75  .resume - A pointer to a per-policy resume fu     81  .resume - A pointer to a per-policy resume function which is called
 76  with interrupts disabled and _before_ the gov     82  with interrupts disabled and _before_ the governor is started again.
 77                                                    83 
 78  .ready - A pointer to a per-policy ready func     84  .ready - A pointer to a per-policy ready function which is called after
 79  the policy is fully initialized.                  85  the policy is fully initialized.
 80                                                    86 
 81  .attr - A pointer to a NULL-terminated list o     87  .attr - A pointer to a NULL-terminated list of "struct freq_attr" which
 82  allow to export values to sysfs.                  88  allow to export values to sysfs.
 83                                                    89 
 84  .boost_enabled - If set, boost frequencies ar     90  .boost_enabled - If set, boost frequencies are enabled.
 85                                                    91 
 86  .set_boost - A pointer to a per-policy functi     92  .set_boost - A pointer to a per-policy function to enable/disable boost
 87  frequencies.                                      93  frequencies.
 88                                                    94 
 89                                                    95 
 90 1.2 Per-CPU Initialization                         96 1.2 Per-CPU Initialization
 91 --------------------------                         97 --------------------------
 92                                                    98 
 93 Whenever a new CPU is registered with the devi     99 Whenever a new CPU is registered with the device model, or after the
 94 cpufreq driver registers itself, the per-polic    100 cpufreq driver registers itself, the per-policy initialization function
 95 cpufreq_driver.init is called if no cpufreq po    101 cpufreq_driver.init is called if no cpufreq policy existed for the CPU.
 96 Note that the .init() and .exit() routines are    102 Note that the .init() and .exit() routines are called only once for the
 97 policy and not for each CPU managed by the pol    103 policy and not for each CPU managed by the policy. It takes a ``struct
 98 cpufreq_policy *policy`` as argument. What to     104 cpufreq_policy *policy`` as argument. What to do now?
 99                                                   105 
100 If necessary, activate the CPUfreq support on     106 If necessary, activate the CPUfreq support on your CPU.
101                                                   107 
102 Then, the driver must fill in the following va    108 Then, the driver must fill in the following values:
103                                                   109 
104 +-----------------------------------+---------    110 +-----------------------------------+--------------------------------------+
105 |policy->cpuinfo.min_freq _and_     |             111 |policy->cpuinfo.min_freq _and_     |                                      |
106 |policy->cpuinfo.max_freq           | the mini    112 |policy->cpuinfo.max_freq           | the minimum and maximum frequency    |
107 |                                   | (in kHz)    113 |                                   | (in kHz) which is supported by       |
108 |                                   | this CPU    114 |                                   | this CPU                             |
109 +-----------------------------------+---------    115 +-----------------------------------+--------------------------------------+
110 |policy->cpuinfo.transition_latency | the time    116 |policy->cpuinfo.transition_latency | the time it takes on this CPU to     |
111 |                                   | switch b    117 |                                   | switch between two frequencies in    |
112 |                                   | nanoseco    118 |                                   | nanoseconds (if appropriate, else    |
113 |                                   | specify     119 |                                   | specify CPUFREQ_ETERNAL)             |
114 +-----------------------------------+---------    120 +-----------------------------------+--------------------------------------+
115 |policy->cur                        | The curr    121 |policy->cur                        | The current operating frequency of   |
116 |                                   | this CPU    122 |                                   | this CPU (if appropriate)            |
117 +-----------------------------------+---------    123 +-----------------------------------+--------------------------------------+
118 |policy->min,                       |             124 |policy->min,                       |                                      |
119 |policy->max,                       |             125 |policy->max,                       |                                      |
120 |policy->policy and, if necessary,  |             126 |policy->policy and, if necessary,  |                                      |
121 |policy->governor                   | must con    127 |policy->governor                   | must contain the "default policy" for|
122 |                                   | this CPU    128 |                                   | this CPU. A few moments later,       |
123 |                                   | cpufreq_    129 |                                   | cpufreq_driver.verify and either     |
124 |                                   | cpufreq_    130 |                                   | cpufreq_driver.setpolicy or          |
125 |                                   | cpufreq_    131 |                                   | cpufreq_driver.target/target_index is|
126 |                                   | called w    132 |                                   | called with these values.            |
127 +-----------------------------------+---------    133 +-----------------------------------+--------------------------------------+
128 |policy->cpus                       | Update t    134 |policy->cpus                       | Update this with the masks of the    |
129 |                                   | (online     135 |                                   | (online + offline) CPUs that do DVFS |
130 |                                   | along wi    136 |                                   | along with this CPU (i.e.  that share|
131 |                                   | clock/vo    137 |                                   | clock/voltage rails with it).        |
132 +-----------------------------------+---------    138 +-----------------------------------+--------------------------------------+
133                                                   139 
134 For setting some of these values (cpuinfo.min[    140 For setting some of these values (cpuinfo.min[max]_freq, policy->min[max]), the
135 frequency table helpers might be helpful. See     141 frequency table helpers might be helpful. See the section 2 for more information
136 on them.                                          142 on them.
137                                                   143 
138                                                   144 
139 1.3 verify                                        145 1.3 verify
140 ----------                                        146 ----------
141                                                   147 
142 When the user decides a new policy (consisting    148 When the user decides a new policy (consisting of
143 "policy,governor,min,max") shall be set, this     149 "policy,governor,min,max") shall be set, this policy must be validated
144 so that incompatible values can be corrected.     150 so that incompatible values can be corrected. For verifying these
145 values cpufreq_verify_within_limits(``struct c    151 values cpufreq_verify_within_limits(``struct cpufreq_policy *policy``,
146 ``unsigned int min_freq``, ``unsigned int max_    152 ``unsigned int min_freq``, ``unsigned int max_freq``) function might be helpful.
147 See section 2 for details on frequency table h    153 See section 2 for details on frequency table helpers.
148                                                   154 
149 You need to make sure that at least one valid     155 You need to make sure that at least one valid frequency (or operating
150 range) is within policy->min and policy->max.     156 range) is within policy->min and policy->max. If necessary, increase
151 policy->max first, and only if this is no solu    157 policy->max first, and only if this is no solution, decrease policy->min.
152                                                   158 
153                                                   159 
154 1.4 target or target_index or setpolicy or fas    160 1.4 target or target_index or setpolicy or fast_switch?
155 ----------------------------------------------    161 -------------------------------------------------------
156                                                   162 
157 Most cpufreq drivers or even most cpu frequenc    163 Most cpufreq drivers or even most cpu frequency scaling algorithms
158 only allow the CPU frequency to be set to pred    164 only allow the CPU frequency to be set to predefined fixed values. For
159 these, you use the ->target(), ->target_index(    165 these, you use the ->target(), ->target_index() or ->fast_switch()
160 callbacks.                                        166 callbacks.
161                                                   167 
162 Some cpufreq capable processors switch the fre    168 Some cpufreq capable processors switch the frequency between certain
163 limits on their own. These shall use the ->set    169 limits on their own. These shall use the ->setpolicy() callback.
164                                                   170 
165                                                   171 
166 1.5. target/target_index                          172 1.5. target/target_index
167 ------------------------                          173 ------------------------
168                                                   174 
169 The target_index call has two arguments: ``str    175 The target_index call has two arguments: ``struct cpufreq_policy *policy``,
170 and ``unsigned int`` index (into the exposed f    176 and ``unsigned int`` index (into the exposed frequency table).
171                                                   177 
172 The CPUfreq driver must set the new frequency     178 The CPUfreq driver must set the new frequency when called here. The
173 actual frequency must be determined by freq_ta    179 actual frequency must be determined by freq_table[index].frequency.
174                                                   180 
175 It should always restore to earlier frequency     181 It should always restore to earlier frequency (i.e. policy->restore_freq) in
176 case of errors, even if we switched to interme    182 case of errors, even if we switched to intermediate frequency earlier.
177                                                   183 
178 Deprecated                                        184 Deprecated
179 ----------                                        185 ----------
180 The target call has three arguments: ``struct     186 The target call has three arguments: ``struct cpufreq_policy *policy``,
181 unsigned int target_frequency, unsigned int re    187 unsigned int target_frequency, unsigned int relation.
182                                                   188 
183 The CPUfreq driver must set the new frequency     189 The CPUfreq driver must set the new frequency when called here. The
184 actual frequency must be determined using the     190 actual frequency must be determined using the following rules:
185                                                   191 
186 - keep close to "target_freq"                     192 - keep close to "target_freq"
187 - policy->min <= new_freq <= policy->max (THIS    193 - policy->min <= new_freq <= policy->max (THIS MUST BE VALID!!!)
188 - if relation==CPUFREQ_REL_L, try to select a     194 - if relation==CPUFREQ_REL_L, try to select a new_freq higher than or equal
189   target_freq. ("L for lowest, but no lower th    195   target_freq. ("L for lowest, but no lower than")
190 - if relation==CPUFREQ_REL_H, try to select a     196 - if relation==CPUFREQ_REL_H, try to select a new_freq lower than or equal
191   target_freq. ("H for highest, but no higher     197   target_freq. ("H for highest, but no higher than")
192                                                   198 
193 Here again the frequency table helper might as    199 Here again the frequency table helper might assist you - see section 2
194 for details.                                      200 for details.
195                                                   201 
196 1.6. fast_switch                                  202 1.6. fast_switch
197 ----------------                                  203 ----------------
198                                                   204 
199 This function is used for frequency switching     205 This function is used for frequency switching from scheduler's context.
200 Not all drivers are expected to implement it,     206 Not all drivers are expected to implement it, as sleeping from within
201 this callback isn't allowed. This callback mus    207 this callback isn't allowed. This callback must be highly optimized to
202 do switching as fast as possible.                 208 do switching as fast as possible.
203                                                   209 
204 This function has two arguments: ``struct cpuf    210 This function has two arguments: ``struct cpufreq_policy *policy`` and
205 ``unsigned int target_frequency``.                211 ``unsigned int target_frequency``.
206                                                   212 
207                                                   213 
208 1.7 setpolicy                                     214 1.7 setpolicy
209 -------------                                     215 -------------
210                                                   216 
211 The setpolicy call only takes a ``struct cpufr    217 The setpolicy call only takes a ``struct cpufreq_policy *policy`` as
212 argument. You need to set the lower limit of t    218 argument. You need to set the lower limit of the in-processor or
213 in-chipset dynamic frequency switching to poli    219 in-chipset dynamic frequency switching to policy->min, the upper limit
214 to policy->max, and -if supported- select a pe    220 to policy->max, and -if supported- select a performance-oriented
215 setting when policy->policy is CPUFREQ_POLICY_    221 setting when policy->policy is CPUFREQ_POLICY_PERFORMANCE, and a
216 powersaving-oriented setting when CPUFREQ_POLI    222 powersaving-oriented setting when CPUFREQ_POLICY_POWERSAVE. Also check
217 the reference implementation in drivers/cpufre    223 the reference implementation in drivers/cpufreq/longrun.c
218                                                   224 
219 1.8 get_intermediate and target_intermediate      225 1.8 get_intermediate and target_intermediate
220 --------------------------------------------      226 --------------------------------------------
221                                                   227 
222 Only for drivers with target_index() and CPUFR    228 Only for drivers with target_index() and CPUFREQ_ASYNC_NOTIFICATION unset.
223                                                   229 
224 get_intermediate should return a stable interm    230 get_intermediate should return a stable intermediate frequency platform wants to
225 switch to, and target_intermediate() should se    231 switch to, and target_intermediate() should set CPU to that frequency, before
226 jumping to the frequency corresponding to 'ind    232 jumping to the frequency corresponding to 'index'. Core will take care of
227 sending notifications and driver doesn't have     233 sending notifications and driver doesn't have to handle them in
228 target_intermediate() or target_index().          234 target_intermediate() or target_index().
229                                                   235 
230 Drivers can return '0' from get_intermediate()    236 Drivers can return '0' from get_intermediate() in case they don't wish to switch
231 to intermediate frequency for some target freq    237 to intermediate frequency for some target frequency. In that case core will
232 directly call ->target_index().                   238 directly call ->target_index().
233                                                   239 
234 NOTE: ->target_index() should restore to polic    240 NOTE: ->target_index() should restore to policy->restore_freq in case of
235 failures as core would send notifications for     241 failures as core would send notifications for that.
236                                                   242 
237                                                   243 
238 2. Frequency Table Helpers                        244 2. Frequency Table Helpers
239 ==========================                        245 ==========================
240                                                   246 
241 As most cpufreq processors only allow for bein    247 As most cpufreq processors only allow for being set to a few specific
242 frequencies, a "frequency table" with some fun    248 frequencies, a "frequency table" with some functions might assist in
243 some work of the processor driver. Such a "fre    249 some work of the processor driver. Such a "frequency table" consists of
244 an array of struct cpufreq_frequency_table ent    250 an array of struct cpufreq_frequency_table entries, with driver specific
245 values in "driver_data", the corresponding fre    251 values in "driver_data", the corresponding frequency in "frequency" and
246 flags set. At the end of the table, you need t    252 flags set. At the end of the table, you need to add a
247 cpufreq_frequency_table entry with frequency s    253 cpufreq_frequency_table entry with frequency set to CPUFREQ_TABLE_END.
248 And if you want to skip one entry in the table    254 And if you want to skip one entry in the table, set the frequency to
249 CPUFREQ_ENTRY_INVALID. The entries don't need     255 CPUFREQ_ENTRY_INVALID. The entries don't need to be in sorted in any
250 particular order, but if they are cpufreq core    256 particular order, but if they are cpufreq core will do DVFS a bit
251 quickly for them as search for best match is f    257 quickly for them as search for best match is faster.
252                                                   258 
253 The cpufreq table is verified automatically by    259 The cpufreq table is verified automatically by the core if the policy contains a
254 valid pointer in its policy->freq_table field.    260 valid pointer in its policy->freq_table field.
255                                                   261 
256 cpufreq_frequency_table_verify() assures that     262 cpufreq_frequency_table_verify() assures that at least one valid
257 frequency is within policy->min and policy->ma    263 frequency is within policy->min and policy->max, and all other criteria
258 are met. This is helpful for the ->verify call    264 are met. This is helpful for the ->verify call.
259                                                   265 
260 cpufreq_frequency_table_target() is the corres    266 cpufreq_frequency_table_target() is the corresponding frequency table
261 helper for the ->target stage. Just pass the v    267 helper for the ->target stage. Just pass the values to this function,
262 and this function returns the of the frequency    268 and this function returns the of the frequency table entry which
263 contains the frequency the CPU shall be set to    269 contains the frequency the CPU shall be set to.
264                                                   270 
265 The following macros can be used as iterators     271 The following macros can be used as iterators over cpufreq_frequency_table:
266                                                   272 
267 cpufreq_for_each_entry(pos, table) - iterates     273 cpufreq_for_each_entry(pos, table) - iterates over all entries of frequency
268 table.                                            274 table.
269                                                   275 
270 cpufreq_for_each_valid_entry(pos, table) - ite    276 cpufreq_for_each_valid_entry(pos, table) - iterates over all entries,
271 excluding CPUFREQ_ENTRY_INVALID frequencies.      277 excluding CPUFREQ_ENTRY_INVALID frequencies.
272 Use arguments "pos" - a ``cpufreq_frequency_ta    278 Use arguments "pos" - a ``cpufreq_frequency_table *`` as a loop cursor and
273 "table" - the ``cpufreq_frequency_table *`` yo    279 "table" - the ``cpufreq_frequency_table *`` you want to iterate over.
274                                                   280 
275 For example::                                     281 For example::
276                                                   282 
277         struct cpufreq_frequency_table *pos, *    283         struct cpufreq_frequency_table *pos, *driver_freq_table;
278                                                   284 
279         cpufreq_for_each_entry(pos, driver_fre    285         cpufreq_for_each_entry(pos, driver_freq_table) {
280                 /* Do something with pos */       286                 /* Do something with pos */
281                 pos->frequency = ...              287                 pos->frequency = ...
282         }                                         288         }
283                                                   289 
284 If you need to work with the position of pos w    290 If you need to work with the position of pos within driver_freq_table,
285 do not subtract the pointers, as it is quite c    291 do not subtract the pointers, as it is quite costly. Instead, use the
286 macros cpufreq_for_each_entry_idx() and cpufre    292 macros cpufreq_for_each_entry_idx() and cpufreq_for_each_valid_entry_idx().
                                                      

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

kernel.org | git.kernel.org | LWN.net | Project Home | SVN repository | Mail admin

Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.

sflogo.php