processor_pdc.c 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212
  1. // SPDX-License-Identifier: GPL-2.0
  2. /*
  3. * Copyright (C) 2005 Intel Corporation
  4. * Copyright (C) 2009 Hewlett-Packard Development Company, L.P.
  5. *
  6. * Venkatesh Pallipadi <[email protected]>
  7. * - Added _PDC for platforms with Intel CPUs
  8. */
  9. #define pr_fmt(fmt) "ACPI: " fmt
  10. #include <linux/dmi.h>
  11. #include <linux/slab.h>
  12. #include <linux/acpi.h>
  13. #include <acpi/processor.h>
  14. #include <xen/xen.h>
  15. #include "internal.h"
  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. if (xen_initial_domain())
  45. /*
  46. * When running as a Xen dom0 the number of processors Linux
  47. * sees can be different from the real number of processors on
  48. * the system, and we still need to execute _PDC for all of
  49. * them.
  50. */
  51. return xen_processor_present(acpi_id);
  52. type = (acpi_type == ACPI_TYPE_DEVICE) ? 1 : 0;
  53. cpuid = acpi_get_cpuid(handle, type, acpi_id);
  54. return !invalid_logical_cpuid(cpuid);
  55. }
  56. static void acpi_set_pdc_bits(u32 *buf)
  57. {
  58. buf[0] = ACPI_PDC_REVISION_ID;
  59. buf[1] = 1;
  60. /* Enable coordination with firmware's _TSD info */
  61. buf[2] = ACPI_PDC_SMP_T_SWCOORD;
  62. /* Twiddle arch-specific bits needed for _PDC */
  63. arch_acpi_set_pdc_bits(buf);
  64. }
  65. static struct acpi_object_list *acpi_processor_alloc_pdc(void)
  66. {
  67. struct acpi_object_list *obj_list;
  68. union acpi_object *obj;
  69. u32 *buf;
  70. /* allocate and initialize pdc. It will be used later. */
  71. obj_list = kmalloc(sizeof(struct acpi_object_list), GFP_KERNEL);
  72. if (!obj_list)
  73. goto out;
  74. obj = kmalloc(sizeof(union acpi_object), GFP_KERNEL);
  75. if (!obj) {
  76. kfree(obj_list);
  77. goto out;
  78. }
  79. buf = kmalloc(12, GFP_KERNEL);
  80. if (!buf) {
  81. kfree(obj);
  82. kfree(obj_list);
  83. goto out;
  84. }
  85. acpi_set_pdc_bits(buf);
  86. obj->type = ACPI_TYPE_BUFFER;
  87. obj->buffer.length = 12;
  88. obj->buffer.pointer = (u8 *) buf;
  89. obj_list->count = 1;
  90. obj_list->pointer = obj;
  91. return obj_list;
  92. out:
  93. pr_err("Memory allocation error\n");
  94. return NULL;
  95. }
  96. /*
  97. * _PDC is required for a BIOS-OS handshake for most of the newer
  98. * ACPI processor features.
  99. */
  100. static acpi_status
  101. acpi_processor_eval_pdc(acpi_handle handle, struct acpi_object_list *pdc_in)
  102. {
  103. acpi_status status = AE_OK;
  104. if (boot_option_idle_override == IDLE_NOMWAIT) {
  105. /*
  106. * If mwait is disabled for CPU C-states, the C2C3_FFH access
  107. * mode will be disabled in the parameter of _PDC object.
  108. * Of course C1_FFH access mode will also be disabled.
  109. */
  110. union acpi_object *obj;
  111. u32 *buffer = NULL;
  112. obj = pdc_in->pointer;
  113. buffer = (u32 *)(obj->buffer.pointer);
  114. buffer[2] &= ~(ACPI_PDC_C_C2C3_FFH | ACPI_PDC_C_C1_FFH);
  115. }
  116. status = acpi_evaluate_object(handle, "_PDC", pdc_in, NULL);
  117. if (ACPI_FAILURE(status))
  118. acpi_handle_debug(handle,
  119. "Could not evaluate _PDC, using legacy perf control\n");
  120. return status;
  121. }
  122. void acpi_processor_set_pdc(acpi_handle handle)
  123. {
  124. struct acpi_object_list *obj_list;
  125. if (arch_has_acpi_pdc() == false)
  126. return;
  127. obj_list = acpi_processor_alloc_pdc();
  128. if (!obj_list)
  129. return;
  130. acpi_processor_eval_pdc(handle, obj_list);
  131. kfree(obj_list->pointer->buffer.pointer);
  132. kfree(obj_list->pointer);
  133. kfree(obj_list);
  134. }
  135. static acpi_status __init
  136. early_init_pdc(acpi_handle handle, u32 lvl, void *context, void **rv)
  137. {
  138. if (processor_physically_present(handle) == false)
  139. return AE_OK;
  140. acpi_processor_set_pdc(handle);
  141. return AE_OK;
  142. }
  143. static int __init set_no_mwait(const struct dmi_system_id *id)
  144. {
  145. pr_notice("%s detected - disabling mwait for CPU C-states\n",
  146. id->ident);
  147. boot_option_idle_override = IDLE_NOMWAIT;
  148. return 0;
  149. }
  150. static const struct dmi_system_id processor_idle_dmi_table[] __initconst = {
  151. {
  152. set_no_mwait, "Extensa 5220", {
  153. DMI_MATCH(DMI_BIOS_VENDOR, "Phoenix Technologies LTD"),
  154. DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
  155. DMI_MATCH(DMI_PRODUCT_VERSION, "0100"),
  156. DMI_MATCH(DMI_BOARD_NAME, "Columbia") }, NULL},
  157. {},
  158. };
  159. static void __init processor_dmi_check(void)
  160. {
  161. /*
  162. * Check whether the system is DMI table. If yes, OSPM
  163. * should not use mwait for CPU-states.
  164. */
  165. dmi_check_system(processor_idle_dmi_table);
  166. }
  167. void __init acpi_early_processor_set_pdc(void)
  168. {
  169. processor_dmi_check();
  170. acpi_walk_namespace(ACPI_TYPE_PROCESSOR, ACPI_ROOT_OBJECT,
  171. ACPI_UINT32_MAX,
  172. early_init_pdc, NULL, NULL, NULL);
  173. acpi_get_devices(ACPI_PROCESSOR_DEVICE_HID, early_init_pdc, NULL, NULL);
  174. }