~ [ 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-4.18.20)


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

~ [ 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