processor_pdc.c 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203
  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. return !invalid_logical_cpuid(cpuid);
  47. }
  48. static void acpi_set_pdc_bits(u32 *buf)
  49. {
  50. buf[0] = ACPI_PDC_REVISION_ID;
  51. buf[1] = 1;
  52. /* Enable coordination with firmware's _TSD info */
  53. buf[2] = ACPI_PDC_SMP_T_SWCOORD;
  54. /* Twiddle arch-specific bits needed for _PDC */
  55. arch_acpi_set_pdc_bits(buf);
  56. }
  57. static struct acpi_object_list *acpi_processor_alloc_pdc(void)
  58. {
  59. struct acpi_object_list *obj_list;
  60. union acpi_object *obj;
  61. u32 *buf;
  62. /* allocate and initialize pdc. It will be used later. */
  63. obj_list = kmalloc(sizeof(struct acpi_object_list), GFP_KERNEL);
  64. if (!obj_list)
  65. goto out;
  66. obj = kmalloc(sizeof(union acpi_object), GFP_KERNEL);
  67. if (!obj) {
  68. kfree(obj_list);
  69. goto out;
  70. }
  71. buf = kmalloc(12, GFP_KERNEL);
  72. if (!buf) {
  73. kfree(obj);
  74. kfree(obj_list);
  75. goto out;
  76. }
  77. acpi_set_pdc_bits(buf);
  78. obj->type = ACPI_TYPE_BUFFER;
  79. obj->buffer.length = 12;
  80. obj->buffer.pointer = (u8 *) buf;
  81. obj_list->count = 1;
  82. obj_list->pointer = obj;
  83. return obj_list;
  84. out:
  85. pr_err("Memory allocation error\n");
  86. return NULL;
  87. }
  88. /*
  89. * _PDC is required for a BIOS-OS handshake for most of the newer
  90. * ACPI processor features.
  91. */
  92. static acpi_status
  93. acpi_processor_eval_pdc(acpi_handle handle, struct acpi_object_list *pdc_in)
  94. {
  95. acpi_status status = AE_OK;
  96. if (boot_option_idle_override == IDLE_NOMWAIT) {
  97. /*
  98. * If mwait is disabled for CPU C-states, the C2C3_FFH access
  99. * mode will be disabled in the parameter of _PDC object.
  100. * Of course C1_FFH access mode will also be disabled.
  101. */
  102. union acpi_object *obj;
  103. u32 *buffer = NULL;
  104. obj = pdc_in->pointer;
  105. buffer = (u32 *)(obj->buffer.pointer);
  106. buffer[2] &= ~(ACPI_PDC_C_C2C3_FFH | ACPI_PDC_C_C1_FFH);
  107. }
  108. status = acpi_evaluate_object(handle, "_PDC", pdc_in, NULL);
  109. if (ACPI_FAILURE(status))
  110. ACPI_DEBUG_PRINT((ACPI_DB_INFO,
  111. "Could not evaluate _PDC, using legacy perf. control.\n"));
  112. return status;
  113. }
  114. void acpi_processor_set_pdc(acpi_handle handle)
  115. {
  116. struct acpi_object_list *obj_list;
  117. if (arch_has_acpi_pdc() == false)
  118. return;
  119. obj_list = acpi_processor_alloc_pdc();
  120. if (!obj_list)
  121. return;
  122. acpi_processor_eval_pdc(handle, obj_list);
  123. kfree(obj_list->pointer->buffer.pointer);
  124. kfree(obj_list->pointer);
  125. kfree(obj_list);
  126. }
  127. static acpi_status __init
  128. early_init_pdc(acpi_handle handle, u32 lvl, void *context, void **rv)
  129. {
  130. if (processor_physically_present(handle) == false)
  131. return AE_OK;
  132. acpi_processor_set_pdc(handle);
  133. return AE_OK;
  134. }
  135. static int __init set_no_mwait(const struct dmi_system_id *id)
  136. {
  137. pr_notice("%s detected - disabling mwait for CPU C-states\n",
  138. id->ident);
  139. boot_option_idle_override = IDLE_NOMWAIT;
  140. return 0;
  141. }
  142. static struct dmi_system_id processor_idle_dmi_table[] __initdata = {
  143. {
  144. set_no_mwait, "Extensa 5220", {
  145. DMI_MATCH(DMI_BIOS_VENDOR, "Phoenix Technologies LTD"),
  146. DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
  147. DMI_MATCH(DMI_PRODUCT_VERSION, "0100"),
  148. DMI_MATCH(DMI_BOARD_NAME, "Columbia") }, NULL},
  149. {},
  150. };
  151. static void __init processor_dmi_check(void)
  152. {
  153. /*
  154. * Check whether the system is DMI table. If yes, OSPM
  155. * should not use mwait for CPU-states.
  156. */
  157. dmi_check_system(processor_idle_dmi_table);
  158. }
  159. void __init acpi_early_processor_set_pdc(void)
  160. {
  161. processor_dmi_check();
  162. acpi_walk_namespace(ACPI_TYPE_PROCESSOR, ACPI_ROOT_OBJECT,
  163. ACPI_UINT32_MAX,
  164. early_init_pdc, NULL, NULL, NULL);
  165. acpi_get_devices(ACPI_PROCESSOR_DEVICE_HID, early_init_pdc, NULL, NULL);
  166. }