powernow-k8.h 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239
  1. /*
  2. * (c) 2003-2006 Advanced Micro Devices, Inc.
  3. * Your use of this code is subject to the terms and conditions of the
  4. * GNU general public license version 2. See "COPYING" or
  5. * http://www.gnu.org/licenses/gpl.html
  6. */
  7. enum pstate {
  8. HW_PSTATE_INVALID = 0xff,
  9. HW_PSTATE_0 = 0,
  10. HW_PSTATE_1 = 1,
  11. HW_PSTATE_2 = 2,
  12. HW_PSTATE_3 = 3,
  13. HW_PSTATE_4 = 4,
  14. HW_PSTATE_5 = 5,
  15. HW_PSTATE_6 = 6,
  16. HW_PSTATE_7 = 7,
  17. };
  18. struct powernow_k8_data {
  19. unsigned int cpu;
  20. u32 numps; /* number of p-states */
  21. u32 batps; /* number of p-states supported on battery */
  22. u32 max_hw_pstate; /* maximum legal hardware pstate */
  23. /* these values are constant when the PSB is used to determine
  24. * vid/fid pairings, but are modified during the ->target() call
  25. * when ACPI is used */
  26. u32 rvo; /* ramp voltage offset */
  27. u32 irt; /* isochronous relief time */
  28. u32 vidmvs; /* usable value calculated from mvs */
  29. u32 vstable; /* voltage stabilization time, units 20 us */
  30. u32 plllock; /* pll lock time, units 1 us */
  31. u32 exttype; /* extended interface = 1 */
  32. /* keep track of the current fid / vid or pstate */
  33. u32 currvid;
  34. u32 currfid;
  35. enum pstate currpstate;
  36. /* the powernow_table includes all frequency and vid/fid pairings:
  37. * fid are the lower 8 bits of the index, vid are the upper 8 bits.
  38. * frequency is in kHz */
  39. struct cpufreq_frequency_table *powernow_table;
  40. #ifdef CONFIG_X86_POWERNOW_K8_ACPI
  41. /* the acpi table needs to be kept. it's only available if ACPI was
  42. * used to determine valid frequency/vid/fid states */
  43. struct acpi_processor_performance acpi_data;
  44. #endif
  45. /* we need to keep track of associated cores, but let cpufreq
  46. * handle hotplug events - so just point at cpufreq pol->cpus
  47. * structure */
  48. cpumask_t *available_cores;
  49. };
  50. /* processor's cpuid instruction support */
  51. #define CPUID_PROCESSOR_SIGNATURE 1 /* function 1 */
  52. #define CPUID_XFAM 0x0ff00000 /* extended family */
  53. #define CPUID_XFAM_K8 0
  54. #define CPUID_XMOD 0x000f0000 /* extended model */
  55. #define CPUID_XMOD_REV_MASK 0x000c0000
  56. #define CPUID_XFAM_10H 0x00100000 /* family 0x10 */
  57. #define CPUID_USE_XFAM_XMOD 0x00000f00
  58. #define CPUID_GET_MAX_CAPABILITIES 0x80000000
  59. #define CPUID_FREQ_VOLT_CAPABILITIES 0x80000007
  60. #define P_STATE_TRANSITION_CAPABLE 6
  61. /* Model Specific Registers for p-state transitions. MSRs are 64-bit. For */
  62. /* writes (wrmsr - opcode 0f 30), the register number is placed in ecx, and */
  63. /* the value to write is placed in edx:eax. For reads (rdmsr - opcode 0f 32), */
  64. /* the register number is placed in ecx, and the data is returned in edx:eax. */
  65. #define MSR_FIDVID_CTL 0xc0010041
  66. #define MSR_FIDVID_STATUS 0xc0010042
  67. /* Field definitions within the FID VID Low Control MSR : */
  68. #define MSR_C_LO_INIT_FID_VID 0x00010000
  69. #define MSR_C_LO_NEW_VID 0x00003f00
  70. #define MSR_C_LO_NEW_FID 0x0000003f
  71. #define MSR_C_LO_VID_SHIFT 8
  72. /* Field definitions within the FID VID High Control MSR : */
  73. #define MSR_C_HI_STP_GNT_TO 0x000fffff
  74. /* Field definitions within the FID VID Low Status MSR : */
  75. #define MSR_S_LO_CHANGE_PENDING 0x80000000 /* cleared when completed */
  76. #define MSR_S_LO_MAX_RAMP_VID 0x3f000000
  77. #define MSR_S_LO_MAX_FID 0x003f0000
  78. #define MSR_S_LO_START_FID 0x00003f00
  79. #define MSR_S_LO_CURRENT_FID 0x0000003f
  80. /* Field definitions within the FID VID High Status MSR : */
  81. #define MSR_S_HI_MIN_WORKING_VID 0x3f000000
  82. #define MSR_S_HI_MAX_WORKING_VID 0x003f0000
  83. #define MSR_S_HI_START_VID 0x00003f00
  84. #define MSR_S_HI_CURRENT_VID 0x0000003f
  85. #define MSR_C_HI_STP_GNT_BENIGN 0x00000001
  86. /* Hardware Pstate _PSS and MSR definitions */
  87. #define USE_HW_PSTATE 0x00000080
  88. #define HW_PSTATE_MASK 0x00000007
  89. #define HW_PSTATE_VALID_MASK 0x80000000
  90. #define HW_PSTATE_MAX_MASK 0x000000f0
  91. #define HW_PSTATE_MAX_SHIFT 4
  92. #define MSR_PSTATE_DEF_BASE 0xc0010064 /* base of Pstate MSRs */
  93. #define MSR_PSTATE_STATUS 0xc0010063 /* Pstate Status MSR */
  94. #define MSR_PSTATE_CTRL 0xc0010062 /* Pstate control MSR */
  95. #define MSR_PSTATE_CUR_LIMIT 0xc0010061 /* pstate current limit MSR */
  96. /* define the two driver architectures */
  97. #define CPU_OPTERON 0
  98. #define CPU_HW_PSTATE 1
  99. /*
  100. * There are restrictions frequencies have to follow:
  101. * - only 1 entry in the low fid table ( <=1.4GHz )
  102. * - lowest entry in the high fid table must be >= 2 * the entry in the
  103. * low fid table
  104. * - lowest entry in the high fid table must be a <= 200MHz + 2 * the entry
  105. * in the low fid table
  106. * - the parts can only step at <= 200 MHz intervals, odd fid values are
  107. * supported in revision G and later revisions.
  108. * - lowest frequency must be >= interprocessor hypertransport link speed
  109. * (only applies to MP systems obviously)
  110. */
  111. /* fids (frequency identifiers) are arranged in 2 tables - lo and hi */
  112. #define LO_FID_TABLE_TOP 7 /* fid values marking the boundary */
  113. #define HI_FID_TABLE_BOTTOM 8 /* between the low and high tables */
  114. #define LO_VCOFREQ_TABLE_TOP 1400 /* corresponding vco frequency values */
  115. #define HI_VCOFREQ_TABLE_BOTTOM 1600
  116. #define MIN_FREQ_RESOLUTION 200 /* fids jump by 2 matching freq jumps by 200 */
  117. #define MAX_FID 0x2a /* Spec only gives FID values as far as 5 GHz */
  118. #define LEAST_VID 0x3e /* Lowest (numerically highest) useful vid value */
  119. #define MIN_FREQ 800 /* Min and max freqs, per spec */
  120. #define MAX_FREQ 5000
  121. #define INVALID_FID_MASK 0xffffffc0 /* not a valid fid if these bits are set */
  122. #define INVALID_VID_MASK 0xffffffc0 /* not a valid vid if these bits are set */
  123. #define VID_OFF 0x3f
  124. #define STOP_GRANT_5NS 1 /* min poss memory access latency for voltage change */
  125. #define PLL_LOCK_CONVERSION (1000/5) /* ms to ns, then divide by clock period */
  126. #define MAXIMUM_VID_STEPS 1 /* Current cpus only allow a single step of 25mV */
  127. #define VST_UNITS_20US 20 /* Voltage Stabilization Time is in units of 20us */
  128. /*
  129. * Most values of interest are encoded in a single field of the _PSS
  130. * entries: the "control" value.
  131. */
  132. #define IRT_SHIFT 30
  133. #define RVO_SHIFT 28
  134. #define EXT_TYPE_SHIFT 27
  135. #define PLL_L_SHIFT 20
  136. #define MVS_SHIFT 18
  137. #define VST_SHIFT 11
  138. #define VID_SHIFT 6
  139. #define IRT_MASK 3
  140. #define RVO_MASK 3
  141. #define EXT_TYPE_MASK 1
  142. #define PLL_L_MASK 0x7f
  143. #define MVS_MASK 3
  144. #define VST_MASK 0x7f
  145. #define VID_MASK 0x1f
  146. #define FID_MASK 0x1f
  147. #define EXT_VID_MASK 0x3f
  148. #define EXT_FID_MASK 0x3f
  149. /*
  150. * Version 1.4 of the PSB table. This table is constructed by BIOS and is
  151. * to tell the OS's power management driver which VIDs and FIDs are
  152. * supported by this particular processor.
  153. * If the data in the PSB / PST is wrong, then this driver will program the
  154. * wrong values into hardware, which is very likely to lead to a crash.
  155. */
  156. #define PSB_ID_STRING "AMDK7PNOW!"
  157. #define PSB_ID_STRING_LEN 10
  158. #define PSB_VERSION_1_4 0x14
  159. struct psb_s {
  160. u8 signature[10];
  161. u8 tableversion;
  162. u8 flags1;
  163. u16 vstable;
  164. u8 flags2;
  165. u8 num_tables;
  166. u32 cpuid;
  167. u8 plllocktime;
  168. u8 maxfid;
  169. u8 maxvid;
  170. u8 numps;
  171. };
  172. /* Pairs of fid/vid values are appended to the version 1.4 PSB table. */
  173. struct pst_s {
  174. u8 fid;
  175. u8 vid;
  176. };
  177. #define dprintk(msg...) cpufreq_debug_printk(CPUFREQ_DEBUG_DRIVER, "powernow-k8", msg)
  178. static int core_voltage_pre_transition(struct powernow_k8_data *data, u32 reqvid);
  179. static int core_voltage_post_transition(struct powernow_k8_data *data, u32 reqvid);
  180. static int core_frequency_transition(struct powernow_k8_data *data, u32 reqfid);
  181. static void powernow_k8_acpi_pst_values(struct powernow_k8_data *data, unsigned int index);
  182. #ifdef CONFIG_X86_POWERNOW_K8_ACPI
  183. static int fill_powernow_table_pstate(struct powernow_k8_data *data, struct cpufreq_frequency_table *powernow_table);
  184. static int fill_powernow_table_fidvid(struct powernow_k8_data *data, struct cpufreq_frequency_table *powernow_table);
  185. #endif
  186. #ifdef CONFIG_SMP
  187. static inline void define_siblings(int cpu, cpumask_t cpu_sharedcore_mask[])
  188. {
  189. }
  190. #else
  191. static inline void define_siblings(int cpu, cpumask_t cpu_sharedcore_mask[])
  192. {
  193. cpu_set(0, cpu_sharedcore_mask[0]);
  194. }
  195. #endif