processor_pdc.c 4.7 KB

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