powernow-k8.h 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197
  1. /*
  2. * (c) 2003, 2004, 2005 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. struct powernow_k8_data {
  8. unsigned int cpu;
  9. u32 numps; /* number of p-states */
  10. u32 batps; /* number of p-states supported on battery */
  11. /* these values are constant when the PSB is used to determine
  12. * vid/fid pairings, but are modified during the ->target() call
  13. * when ACPI is used */
  14. u32 rvo; /* ramp voltage offset */
  15. u32 irt; /* isochronous relief time */
  16. u32 vidmvs; /* usable value calculated from mvs */
  17. u32 vstable; /* voltage stabilization time, units 20 us */
  18. u32 plllock; /* pll lock time, units 1 us */
  19. u32 exttype; /* extended interface = 1 */
  20. /* keep track of the current fid / vid */
  21. u32 currvid, currfid;
  22. /* the powernow_table includes all frequency and vid/fid pairings:
  23. * fid are the lower 8 bits of the index, vid are the upper 8 bits.
  24. * frequency is in kHz */
  25. struct cpufreq_frequency_table *powernow_table;
  26. #ifdef CONFIG_X86_POWERNOW_K8_ACPI
  27. /* the acpi table needs to be kept. it's only available if ACPI was
  28. * used to determine valid frequency/vid/fid states */
  29. struct acpi_processor_performance acpi_data;
  30. #endif
  31. };
  32. /* processor's cpuid instruction support */
  33. #define CPUID_PROCESSOR_SIGNATURE 1 /* function 1 */
  34. #define CPUID_XFAM 0x0ff00000 /* extended family */
  35. #define CPUID_XFAM_K8 0
  36. #define CPUID_XMOD 0x000f0000 /* extended model */
  37. #define CPUID_XMOD_REV_F 0x00040000
  38. #define CPUID_USE_XFAM_XMOD 0x00000f00
  39. #define CPUID_GET_MAX_CAPABILITIES 0x80000000
  40. #define CPUID_FREQ_VOLT_CAPABILITIES 0x80000007
  41. #define P_STATE_TRANSITION_CAPABLE 6
  42. /* Model Specific Registers for p-state transitions. MSRs are 64-bit. For */
  43. /* writes (wrmsr - opcode 0f 30), the register number is placed in ecx, and */
  44. /* the value to write is placed in edx:eax. For reads (rdmsr - opcode 0f 32), */
  45. /* the register number is placed in ecx, and the data is returned in edx:eax. */
  46. #define MSR_FIDVID_CTL 0xc0010041
  47. #define MSR_FIDVID_STATUS 0xc0010042
  48. /* Field definitions within the FID VID Low Control MSR : */
  49. #define MSR_C_LO_INIT_FID_VID 0x00010000
  50. #define MSR_C_LO_NEW_VID 0x00003f00
  51. #define MSR_C_LO_NEW_FID 0x0000003f
  52. #define MSR_C_LO_VID_SHIFT 8
  53. /* Field definitions within the FID VID High Control MSR : */
  54. #define MSR_C_HI_STP_GNT_TO 0x000fffff
  55. /* Field definitions within the FID VID Low Status MSR : */
  56. #define MSR_S_LO_CHANGE_PENDING 0x80000000 /* cleared when completed */
  57. #define MSR_S_LO_MAX_RAMP_VID 0x3f000000
  58. #define MSR_S_LO_MAX_FID 0x003f0000
  59. #define MSR_S_LO_START_FID 0x00003f00
  60. #define MSR_S_LO_CURRENT_FID 0x0000003f
  61. /* Field definitions within the FID VID High Status MSR : */
  62. #define MSR_S_HI_MIN_WORKING_VID 0x3f000000
  63. #define MSR_S_HI_MAX_WORKING_VID 0x003f0000
  64. #define MSR_S_HI_START_VID 0x00003f00
  65. #define MSR_S_HI_CURRENT_VID 0x0000003f
  66. #define MSR_C_HI_STP_GNT_BENIGN 0x00000001
  67. /*
  68. * There are restrictions frequencies have to follow:
  69. * - only 1 entry in the low fid table ( <=1.4GHz )
  70. * - lowest entry in the high fid table must be >= 2 * the entry in the
  71. * low fid table
  72. * - lowest entry in the high fid table must be a <= 200MHz + 2 * the entry
  73. * in the low fid table
  74. * - the parts can only step at 200 MHz intervals, so 1.9 GHz is never valid
  75. * - lowest frequency must be >= interprocessor hypertransport link speed
  76. * (only applies to MP systems obviously)
  77. */
  78. /* fids (frequency identifiers) are arranged in 2 tables - lo and hi */
  79. #define LO_FID_TABLE_TOP 6 /* fid values marking the boundary */
  80. #define HI_FID_TABLE_BOTTOM 8 /* between the low and high tables */
  81. #define LO_VCOFREQ_TABLE_TOP 1400 /* corresponding vco frequency values */
  82. #define HI_VCOFREQ_TABLE_BOTTOM 1600
  83. #define MIN_FREQ_RESOLUTION 200 /* fids jump by 2 matching freq jumps by 200 */
  84. #define MAX_FID 0x2a /* Spec only gives FID values as far as 5 GHz */
  85. #define LEAST_VID 0x3e /* Lowest (numerically highest) useful vid value */
  86. #define MIN_FREQ 800 /* Min and max freqs, per spec */
  87. #define MAX_FREQ 5000
  88. #define INVALID_FID_MASK 0xffffffc1 /* not a valid fid if these bits are set */
  89. #define INVALID_VID_MASK 0xffffffc0 /* not a valid vid if these bits are set */
  90. #define VID_OFF 0x3f
  91. #define STOP_GRANT_5NS 1 /* min poss memory access latency for voltage change */
  92. #define PLL_LOCK_CONVERSION (1000/5) /* ms to ns, then divide by clock period */
  93. #define MAXIMUM_VID_STEPS 1 /* Current cpus only allow a single step of 25mV */
  94. #define VST_UNITS_20US 20 /* Voltage Stabalization Time is in units of 20us */
  95. /*
  96. * Most values of interest are enocoded in a single field of the _PSS
  97. * entries: the "control" value.
  98. */
  99. #define IRT_SHIFT 30
  100. #define RVO_SHIFT 28
  101. #define EXT_TYPE_SHIFT 27
  102. #define PLL_L_SHIFT 20
  103. #define MVS_SHIFT 18
  104. #define VST_SHIFT 11
  105. #define VID_SHIFT 6
  106. #define IRT_MASK 3
  107. #define RVO_MASK 3
  108. #define EXT_TYPE_MASK 1
  109. #define PLL_L_MASK 0x7f
  110. #define MVS_MASK 3
  111. #define VST_MASK 0x7f
  112. #define VID_MASK 0x1f
  113. #define FID_MASK 0x3f
  114. /*
  115. * Version 1.4 of the PSB table. This table is constructed by BIOS and is
  116. * to tell the OS's power management driver which VIDs and FIDs are
  117. * supported by this particular processor.
  118. * If the data in the PSB / PST is wrong, then this driver will program the
  119. * wrong values into hardware, which is very likely to lead to a crash.
  120. */
  121. #define PSB_ID_STRING "AMDK7PNOW!"
  122. #define PSB_ID_STRING_LEN 10
  123. #define PSB_VERSION_1_4 0x14
  124. struct psb_s {
  125. u8 signature[10];
  126. u8 tableversion;
  127. u8 flags1;
  128. u16 vstable;
  129. u8 flags2;
  130. u8 num_tables;
  131. u32 cpuid;
  132. u8 plllocktime;
  133. u8 maxfid;
  134. u8 maxvid;
  135. u8 numps;
  136. };
  137. /* Pairs of fid/vid values are appended to the version 1.4 PSB table. */
  138. struct pst_s {
  139. u8 fid;
  140. u8 vid;
  141. };
  142. #define dprintk(msg...) cpufreq_debug_printk(CPUFREQ_DEBUG_DRIVER, "powernow-k8", msg)
  143. static int core_voltage_pre_transition(struct powernow_k8_data *data, u32 reqvid);
  144. static int core_voltage_post_transition(struct powernow_k8_data *data, u32 reqvid);
  145. static int core_frequency_transition(struct powernow_k8_data *data, u32 reqfid);
  146. static void powernow_k8_acpi_pst_values(struct powernow_k8_data *data, unsigned int index);
  147. #ifndef for_each_cpu_mask
  148. #define for_each_cpu_mask(i,mask) for (i=0;i<1;i++)
  149. #endif
  150. #ifdef CONFIG_SMP
  151. static inline void define_siblings(int cpu, cpumask_t cpu_sharedcore_mask[])
  152. {
  153. }
  154. #else
  155. static inline void define_siblings(int cpu, cpumask_t cpu_sharedcore_mask[])
  156. {
  157. cpu_set(0, cpu_sharedcore_mask[0]);
  158. }
  159. #endif