processor_pdc.c 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206
  1. /*
  2. * Copyright (C) 2005 Intel Corporation
  3. * Copyright (C) 2009 Hewlett-Packard Development Company, L.P.
  4. *
  5. * Venkatesh Pallipadi <venkatesh.pallipadi@intel.com>
  6. * - Added _PDC for platforms with Intel CPUs
  7. */
  8. #define pr_fmt(fmt) "ACPI: " fmt
  9. #include <linux/dmi.h>
  10. #include <linux/slab.h>
  11. #include <linux/acpi.h>
  12. #include <acpi/processor.h>
  13. #include "internal.h"
  14. #define _COMPONENT ACPI_PROCESSOR_COMPONENT
  15. ACPI_MODULE_NAME("processor_pdc");
  16. static bool __init processor_physically_present(acpi_handle handle)
  17. {
  18. int cpuid, type;
  19. u32 acpi_id;
  20. acpi_status status;
  21. acpi_object_type acpi_type;
  22. unsigned long long tmp;
  23. union acpi_object object = { 0 };
  24. struct acpi_buffer buffer = { sizeof(union acpi_object), &object };
  25. status = acpi_get_type(handle, &acpi_type);
  26. if (ACPI_FAILURE(status))
  27. return false;
  28. switch (acpi_type) {
  29. case ACPI_TYPE_PROCESSOR:
  30. status = acpi_evaluate_object(handle, NULL, NULL, &buffer);
  31. if (ACPI_FAILURE(status))
  32. return false;
  33. acpi_id = object.processor.proc_id;
  34. break;
  35. case ACPI_TYPE_DEVICE:
  36. status = acpi_evaluate_integer(handle, "_UID", NULL, &tmp);
  37. if (ACPI_FAILURE(status))
  38. return false;
  39. acpi_id = tmp;
  40. break;
  41. default:
  42. return false;
  43. }
  44. type = (acpi_type == ACPI_TYPE_DEVICE) ? 1 : 0;
  45. cpuid = acpi_get_cpuid(handle, type, acpi_id);
  46. if (cpuid == -1)
  47. return false;
  48. return true;
  49. }
  50. static void acpi_set_pdc_bits(u32 *buf)
  51. {
  52. buf[0] = ACPI_PDC_REVISION_ID;
  53. buf[1] = 1;
  54. /* Enable coordination with firmware's _TSD info */
  55. buf[2] = ACPI_PDC_SMP_T_SWCOORD;
  56. /* Twiddle arch-specific bits needed for _PDC */
  57. arch_acpi_set_pdc_bits(buf);
  58. }
  59. static struct acpi_object_list *acpi_processor_alloc_pdc(void)
  60. {
  61. struct acpi_object_list *obj_list;
  62. union acpi_object *obj;
  63. u32 *buf;
  64. /* allocate and initialize pdc. It will be used later. */
  65. obj_list = kmalloc(sizeof(struct acpi_object_list), GFP_KERNEL);
  66. if (!obj_list)
  67. goto out;
  68. obj = kmalloc(sizeof(union acpi_object), GFP_KERNEL);
  69. if (!obj) {
  70. kfree(obj_list);
  71. goto out;
  72. }
  73. buf = kmalloc(12, GFP_KERNEL);
  74. if (!buf) {
  75. kfree(obj);
  76. kfree(obj_list);
  77. goto out;
  78. }
  79. acpi_set_pdc_bits(buf);
  80. obj->type = ACPI_TYPE_BUFFER;
  81. obj->buffer.length = 12;
  82. obj->buffer.pointer = (u8 *) buf;
  83. obj_list->count = 1;
  84. obj_list->pointer = obj;
  85. return obj_list;
  86. out:
  87. pr_err("Memory allocation error\n");
  88. return NULL;
  89. }
  90. /*
  91. * _PDC is required for a BIOS-OS handshake for most of the newer
  92. * ACPI processor features.
  93. */
  94. static acpi_status
  95. acpi_processor_eval_pdc(acpi_handle handle, struct acpi_object_list *pdc_in)
  96. {
  97. acpi_status status = AE_OK;
  98. if (boot_option_idle_override == IDLE_NOMWAIT) {
  99. /*
  100. * If mwait is disabled for CPU C-states, the C2C3_FFH access
  101. * mode will be disabled in the parameter of _PDC object.
  102. * Of course C1_FFH access mode will also be disabled.
  103. */
  104. union acpi_object *obj;
  105. u32 *buffer = NULL;
  106. obj = pdc_in->pointer;
  107. buffer = (u32 *)(obj->buffer.pointer);
  108. buffer[2] &= ~(ACPI_PDC_C_C2C3_FFH | ACPI_PDC_C_C1_FFH);
  109. }
  110. status = acpi_evaluate_object(handle, "_PDC", pdc_in, NULL);
  111. if (ACPI_FAILURE(status))
  112. ACPI_DEBUG_PRINT((ACPI_DB_INFO,
  113. "Could not evaluate _PDC, using legacy perf. control.\n"));
  114. return status;
  115. }
  116. void acpi_processor_set_pdc(acpi_handle handle)
  117. {
  118. struct acpi_object_list *obj_list;
  119. if (arch_has_acpi_pdc() == false)
  120. return;
  121. obj_list = acpi_processor_alloc_pdc();
  122. if (!obj_list)
  123. return;
  124. acpi_processor_eval_pdc(handle, obj_list);
  125. kfree(obj_list->pointer->buffer.pointer);
  126. kfree(obj_list->pointer);
  127. kfree(obj_list);
  128. }
  129. static acpi_status __init
  130. early_init_pdc(acpi_handle handle, u32 lvl, void *context, void **rv)
  131. {
  132. if (processor_physically_present(handle) == false)
  133. return AE_OK;
  134. acpi_processor_set_pdc(handle);
  135. return AE_OK;
  136. }
  137. static int __init set_no_mwait(const struct dmi_system_id *id)
  138. {
  139. pr_notice("%s detected - disabling mwait for CPU C-states\n",
  140. id->ident);
  141. boot_option_idle_override = IDLE_NOMWAIT;
  142. return 0;
  143. }
  144. static struct dmi_system_id processor_idle_dmi_table[] __initdata = {
  145. {
  146. set_no_mwait, "Extensa 5220", {
  147. DMI_MATCH(DMI_BIOS_VENDOR, "Phoenix Technologies LTD"),
  148. DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
  149. DMI_MATCH(DMI_PRODUCT_VERSION, "0100"),
  150. DMI_MATCH(DMI_BOARD_NAME, "Columbia") }, NULL},
  151. {},
  152. };
  153. static void __init processor_dmi_check(void)
  154. {
  155. /*
  156. * Check whether the system is DMI table. If yes, OSPM
  157. * should not use mwait for CPU-states.
  158. */
  159. dmi_check_system(processor_idle_dmi_table);
  160. }
  161. void __init acpi_early_processor_set_pdc(void)
  162. {
  163. processor_dmi_check();
  164. acpi_walk_namespace(ACPI_TYPE_PROCESSOR, ACPI_ROOT_OBJECT,
  165. ACPI_UINT32_MAX,
  166. early_init_pdc, NULL, NULL, NULL);
  167. acpi_get_devices(ACPI_PROCESSOR_DEVICE_HID, early_init_pdc, NULL, NULL);
  168. }