cstate.c 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  1. /*
  2. * Copyright (C) 2005 Intel Corporation
  3. * Venkatesh Pallipadi <venkatesh.pallipadi@intel.com>
  4. * - Added _PDC for SMP C-states on Intel CPUs
  5. */
  6. #include <linux/kernel.h>
  7. #include <linux/export.h>
  8. #include <linux/init.h>
  9. #include <linux/acpi.h>
  10. #include <linux/cpu.h>
  11. #include <linux/sched.h>
  12. #include <acpi/processor.h>
  13. #include <asm/acpi.h>
  14. #include <asm/mwait.h>
  15. #include <asm/special_insns.h>
  16. /*
  17. * Initialize bm_flags based on the CPU cache properties
  18. * On SMP it depends on cache configuration
  19. * - When cache is not shared among all CPUs, we flush cache
  20. * before entering C3.
  21. * - When cache is shared among all CPUs, we use bm_check
  22. * mechanism as in UP case
  23. *
  24. * This routine is called only after all the CPUs are online
  25. */
  26. void acpi_processor_power_init_bm_check(struct acpi_processor_flags *flags,
  27. unsigned int cpu)
  28. {
  29. struct cpuinfo_x86 *c = &cpu_data(cpu);
  30. flags->bm_check = 0;
  31. if (num_online_cpus() == 1)
  32. flags->bm_check = 1;
  33. else if (c->x86_vendor == X86_VENDOR_INTEL) {
  34. /*
  35. * Today all MP CPUs that support C3 share cache.
  36. * And caches should not be flushed by software while
  37. * entering C3 type state.
  38. */
  39. flags->bm_check = 1;
  40. }
  41. /*
  42. * On all recent Intel platforms, ARB_DISABLE is a nop.
  43. * So, set bm_control to zero to indicate that ARB_DISABLE
  44. * is not required while entering C3 type state on
  45. * P4, Core and beyond CPUs
  46. */
  47. if (c->x86_vendor == X86_VENDOR_INTEL &&
  48. (c->x86 > 0xf || (c->x86 == 6 && c->x86_model >= 0x0f)))
  49. flags->bm_control = 0;
  50. }
  51. EXPORT_SYMBOL(acpi_processor_power_init_bm_check);
  52. /* The code below handles cstate entry with monitor-mwait pair on Intel*/
  53. struct cstate_entry {
  54. struct {
  55. unsigned int eax;
  56. unsigned int ecx;
  57. } states[ACPI_PROCESSOR_MAX_POWER];
  58. };
  59. static struct cstate_entry __percpu *cpu_cstate_entry; /* per CPU ptr */
  60. static short mwait_supported[ACPI_PROCESSOR_MAX_POWER];
  61. #define NATIVE_CSTATE_BEYOND_HALT (2)
  62. static long acpi_processor_ffh_cstate_probe_cpu(void *_cx)
  63. {
  64. struct acpi_processor_cx *cx = _cx;
  65. long retval;
  66. unsigned int eax, ebx, ecx, edx;
  67. unsigned int edx_part;
  68. unsigned int cstate_type; /* C-state type and not ACPI C-state type */
  69. unsigned int num_cstate_subtype;
  70. cpuid(CPUID_MWAIT_LEAF, &eax, &ebx, &ecx, &edx);
  71. /* Check whether this particular cx_type (in CST) is supported or not */
  72. cstate_type = ((cx->address >> MWAIT_SUBSTATE_SIZE) &
  73. MWAIT_CSTATE_MASK) + 1;
  74. edx_part = edx >> (cstate_type * MWAIT_SUBSTATE_SIZE);
  75. num_cstate_subtype = edx_part & MWAIT_SUBSTATE_MASK;
  76. retval = 0;
  77. /* If the HW does not support any sub-states in this C-state */
  78. if (num_cstate_subtype == 0) {
  79. pr_warn(FW_BUG "ACPI MWAIT C-state 0x%x not supported by HW (0x%x)\n", cx->address, edx_part);
  80. retval = -1;
  81. goto out;
  82. }
  83. /* mwait ecx extensions INTERRUPT_BREAK should be supported for C2/C3 */
  84. if (!(ecx & CPUID5_ECX_EXTENSIONS_SUPPORTED) ||
  85. !(ecx & CPUID5_ECX_INTERRUPT_BREAK)) {
  86. retval = -1;
  87. goto out;
  88. }
  89. if (!mwait_supported[cstate_type]) {
  90. mwait_supported[cstate_type] = 1;
  91. printk(KERN_DEBUG
  92. "Monitor-Mwait will be used to enter C-%d "
  93. "state\n", cx->type);
  94. }
  95. snprintf(cx->desc,
  96. ACPI_CX_DESC_LEN, "ACPI FFH INTEL MWAIT 0x%x",
  97. cx->address);
  98. out:
  99. return retval;
  100. }
  101. int acpi_processor_ffh_cstate_probe(unsigned int cpu,
  102. struct acpi_processor_cx *cx, struct acpi_power_register *reg)
  103. {
  104. struct cstate_entry *percpu_entry;
  105. struct cpuinfo_x86 *c = &cpu_data(cpu);
  106. long retval;
  107. if (!cpu_cstate_entry || c->cpuid_level < CPUID_MWAIT_LEAF)
  108. return -1;
  109. if (reg->bit_offset != NATIVE_CSTATE_BEYOND_HALT)
  110. return -1;
  111. percpu_entry = per_cpu_ptr(cpu_cstate_entry, cpu);
  112. percpu_entry->states[cx->index].eax = 0;
  113. percpu_entry->states[cx->index].ecx = 0;
  114. /* Make sure we are running on right CPU */
  115. retval = work_on_cpu(cpu, acpi_processor_ffh_cstate_probe_cpu, cx);
  116. if (retval == 0) {
  117. /* Use the hint in CST */
  118. percpu_entry->states[cx->index].eax = cx->address;
  119. percpu_entry->states[cx->index].ecx = MWAIT_ECX_INTERRUPT_BREAK;
  120. }
  121. /*
  122. * For _CST FFH on Intel, if GAS.access_size bit 1 is cleared,
  123. * then we should skip checking BM_STS for this C-state.
  124. * ref: "Intel Processor Vendor-Specific ACPI Interface Specification"
  125. */
  126. if ((c->x86_vendor == X86_VENDOR_INTEL) && !(reg->access_size & 0x2))
  127. cx->bm_sts_skip = 1;
  128. return retval;
  129. }
  130. EXPORT_SYMBOL_GPL(acpi_processor_ffh_cstate_probe);
  131. void __cpuidle acpi_processor_ffh_cstate_enter(struct acpi_processor_cx *cx)
  132. {
  133. unsigned int cpu = smp_processor_id();
  134. struct cstate_entry *percpu_entry;
  135. percpu_entry = per_cpu_ptr(cpu_cstate_entry, cpu);
  136. mwait_idle_with_hints(percpu_entry->states[cx->index].eax,
  137. percpu_entry->states[cx->index].ecx);
  138. }
  139. EXPORT_SYMBOL_GPL(acpi_processor_ffh_cstate_enter);
  140. static int __init ffh_cstate_init(void)
  141. {
  142. struct cpuinfo_x86 *c = &boot_cpu_data;
  143. if (c->x86_vendor != X86_VENDOR_INTEL)
  144. return -1;
  145. cpu_cstate_entry = alloc_percpu(struct cstate_entry);
  146. return 0;
  147. }
  148. static void __exit ffh_cstate_exit(void)
  149. {
  150. free_percpu(cpu_cstate_entry);
  151. cpu_cstate_entry = NULL;
  152. }
  153. arch_initcall(ffh_cstate_init);
  154. __exitcall(ffh_cstate_exit);