processor_core.c 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354
  1. /*
  2. * Copyright (C) 2005 Intel Corporation
  3. * Copyright (C) 2009 Hewlett-Packard Development Company, L.P.
  4. *
  5. * Alex Chiang <achiang@hp.com>
  6. * - Unified x86/ia64 implementations
  7. * Venkatesh Pallipadi <venkatesh.pallipadi@intel.com>
  8. * - Added _PDC for platforms with Intel CPUs
  9. */
  10. #include <linux/dmi.h>
  11. #include <acpi/acpi_drivers.h>
  12. #include <acpi/processor.h>
  13. #include "internal.h"
  14. #define PREFIX "ACPI: "
  15. #define _COMPONENT ACPI_PROCESSOR_COMPONENT
  16. ACPI_MODULE_NAME("processor_core");
  17. static int set_no_mwait(const struct dmi_system_id *id)
  18. {
  19. printk(KERN_NOTICE PREFIX "%s detected - "
  20. "disabling mwait for CPU C-states\n", id->ident);
  21. idle_nomwait = 1;
  22. return 0;
  23. }
  24. static struct dmi_system_id __cpuinitdata processor_idle_dmi_table[] = {
  25. {
  26. set_no_mwait, "IFL91 board", {
  27. DMI_MATCH(DMI_BIOS_VENDOR, "COMPAL"),
  28. DMI_MATCH(DMI_SYS_VENDOR, "ZEPTO"),
  29. DMI_MATCH(DMI_PRODUCT_VERSION, "3215W"),
  30. DMI_MATCH(DMI_BOARD_NAME, "IFL91") }, NULL},
  31. {
  32. set_no_mwait, "Extensa 5220", {
  33. DMI_MATCH(DMI_BIOS_VENDOR, "Phoenix Technologies LTD"),
  34. DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
  35. DMI_MATCH(DMI_PRODUCT_VERSION, "0100"),
  36. DMI_MATCH(DMI_BOARD_NAME, "Columbia") }, NULL},
  37. {},
  38. };
  39. #ifdef CONFIG_SMP
  40. static struct acpi_table_madt *madt;
  41. static int map_lapic_id(struct acpi_subtable_header *entry,
  42. u32 acpi_id, int *apic_id)
  43. {
  44. struct acpi_madt_local_apic *lapic =
  45. (struct acpi_madt_local_apic *)entry;
  46. if (!(lapic->lapic_flags & ACPI_MADT_ENABLED))
  47. return 0;
  48. if (lapic->processor_id != acpi_id)
  49. return 0;
  50. *apic_id = lapic->id;
  51. return 1;
  52. }
  53. static int map_x2apic_id(struct acpi_subtable_header *entry,
  54. int device_declaration, u32 acpi_id, int *apic_id)
  55. {
  56. struct acpi_madt_local_x2apic *apic =
  57. (struct acpi_madt_local_x2apic *)entry;
  58. if (!(apic->lapic_flags & ACPI_MADT_ENABLED))
  59. return 0;
  60. if (device_declaration && (apic->uid == acpi_id)) {
  61. *apic_id = apic->local_apic_id;
  62. return 1;
  63. }
  64. return 0;
  65. }
  66. static int map_lsapic_id(struct acpi_subtable_header *entry,
  67. int device_declaration, u32 acpi_id, int *apic_id)
  68. {
  69. struct acpi_madt_local_sapic *lsapic =
  70. (struct acpi_madt_local_sapic *)entry;
  71. if (!(lsapic->lapic_flags & ACPI_MADT_ENABLED))
  72. return 0;
  73. if (device_declaration) {
  74. if ((entry->length < 16) || (lsapic->uid != acpi_id))
  75. return 0;
  76. } else if (lsapic->processor_id != acpi_id)
  77. return 0;
  78. *apic_id = (lsapic->id << 8) | lsapic->eid;
  79. return 1;
  80. }
  81. static int map_madt_entry(int type, u32 acpi_id)
  82. {
  83. unsigned long madt_end, entry;
  84. int apic_id = -1;
  85. if (!madt)
  86. return apic_id;
  87. entry = (unsigned long)madt;
  88. madt_end = entry + madt->header.length;
  89. /* Parse all entries looking for a match. */
  90. entry += sizeof(struct acpi_table_madt);
  91. while (entry + sizeof(struct acpi_subtable_header) < madt_end) {
  92. struct acpi_subtable_header *header =
  93. (struct acpi_subtable_header *)entry;
  94. if (header->type == ACPI_MADT_TYPE_LOCAL_APIC) {
  95. if (map_lapic_id(header, acpi_id, &apic_id))
  96. break;
  97. } else if (header->type == ACPI_MADT_TYPE_LOCAL_X2APIC) {
  98. if (map_x2apic_id(header, type, acpi_id, &apic_id))
  99. break;
  100. } else if (header->type == ACPI_MADT_TYPE_LOCAL_SAPIC) {
  101. if (map_lsapic_id(header, type, acpi_id, &apic_id))
  102. break;
  103. }
  104. entry += header->length;
  105. }
  106. return apic_id;
  107. }
  108. static int map_mat_entry(acpi_handle handle, int type, u32 acpi_id)
  109. {
  110. struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL };
  111. union acpi_object *obj;
  112. struct acpi_subtable_header *header;
  113. int apic_id = -1;
  114. if (ACPI_FAILURE(acpi_evaluate_object(handle, "_MAT", NULL, &buffer)))
  115. goto exit;
  116. if (!buffer.length || !buffer.pointer)
  117. goto exit;
  118. obj = buffer.pointer;
  119. if (obj->type != ACPI_TYPE_BUFFER ||
  120. obj->buffer.length < sizeof(struct acpi_subtable_header)) {
  121. goto exit;
  122. }
  123. header = (struct acpi_subtable_header *)obj->buffer.pointer;
  124. if (header->type == ACPI_MADT_TYPE_LOCAL_APIC) {
  125. map_lapic_id(header, acpi_id, &apic_id);
  126. } else if (header->type == ACPI_MADT_TYPE_LOCAL_SAPIC) {
  127. map_lsapic_id(header, type, acpi_id, &apic_id);
  128. }
  129. exit:
  130. if (buffer.pointer)
  131. kfree(buffer.pointer);
  132. return apic_id;
  133. }
  134. int acpi_get_cpuid(acpi_handle handle, int type, u32 acpi_id)
  135. {
  136. int i;
  137. int apic_id = -1;
  138. apic_id = map_mat_entry(handle, type, acpi_id);
  139. if (apic_id == -1)
  140. apic_id = map_madt_entry(type, acpi_id);
  141. if (apic_id == -1)
  142. return apic_id;
  143. for_each_possible_cpu(i) {
  144. if (cpu_physical_id(i) == apic_id)
  145. return i;
  146. }
  147. return -1;
  148. }
  149. EXPORT_SYMBOL_GPL(acpi_get_cpuid);
  150. #endif
  151. static bool processor_physically_present(acpi_handle handle)
  152. {
  153. int cpuid, type;
  154. u32 acpi_id;
  155. acpi_status status;
  156. acpi_object_type acpi_type;
  157. unsigned long long tmp;
  158. union acpi_object object = { 0 };
  159. struct acpi_buffer buffer = { sizeof(union acpi_object), &object };
  160. status = acpi_get_type(handle, &acpi_type);
  161. if (ACPI_FAILURE(status))
  162. return false;
  163. switch (acpi_type) {
  164. case ACPI_TYPE_PROCESSOR:
  165. status = acpi_evaluate_object(handle, NULL, NULL, &buffer);
  166. if (ACPI_FAILURE(status))
  167. return false;
  168. acpi_id = object.processor.proc_id;
  169. break;
  170. case ACPI_TYPE_DEVICE:
  171. status = acpi_evaluate_integer(handle, "_UID", NULL, &tmp);
  172. if (ACPI_FAILURE(status))
  173. return false;
  174. acpi_id = tmp;
  175. break;
  176. default:
  177. return false;
  178. }
  179. type = (acpi_type == ACPI_TYPE_DEVICE) ? 1 : 0;
  180. cpuid = acpi_get_cpuid(handle, type, acpi_id);
  181. if (cpuid == -1)
  182. return false;
  183. return true;
  184. }
  185. static void acpi_set_pdc_bits(u32 *buf)
  186. {
  187. buf[0] = ACPI_PDC_REVISION_ID;
  188. buf[1] = 1;
  189. /* Enable coordination with firmware's _TSD info */
  190. buf[2] = ACPI_PDC_SMP_T_SWCOORD;
  191. /* Twiddle arch-specific bits needed for _PDC */
  192. arch_acpi_set_pdc_bits(buf);
  193. }
  194. static struct acpi_object_list *acpi_processor_alloc_pdc(void)
  195. {
  196. struct acpi_object_list *obj_list;
  197. union acpi_object *obj;
  198. u32 *buf;
  199. /* allocate and initialize pdc. It will be used later. */
  200. obj_list = kmalloc(sizeof(struct acpi_object_list), GFP_KERNEL);
  201. if (!obj_list) {
  202. printk(KERN_ERR "Memory allocation error\n");
  203. return NULL;
  204. }
  205. obj = kmalloc(sizeof(union acpi_object), GFP_KERNEL);
  206. if (!obj) {
  207. printk(KERN_ERR "Memory allocation error\n");
  208. kfree(obj_list);
  209. return NULL;
  210. }
  211. buf = kmalloc(12, GFP_KERNEL);
  212. if (!buf) {
  213. printk(KERN_ERR "Memory allocation error\n");
  214. kfree(obj);
  215. kfree(obj_list);
  216. return NULL;
  217. }
  218. acpi_set_pdc_bits(buf);
  219. obj->type = ACPI_TYPE_BUFFER;
  220. obj->buffer.length = 12;
  221. obj->buffer.pointer = (u8 *) buf;
  222. obj_list->count = 1;
  223. obj_list->pointer = obj;
  224. return obj_list;
  225. }
  226. /*
  227. * _PDC is required for a BIOS-OS handshake for most of the newer
  228. * ACPI processor features.
  229. */
  230. static int
  231. acpi_processor_eval_pdc(acpi_handle handle, struct acpi_object_list *pdc_in)
  232. {
  233. acpi_status status = AE_OK;
  234. if (idle_nomwait) {
  235. /*
  236. * If mwait is disabled for CPU C-states, the C2C3_FFH access
  237. * mode will be disabled in the parameter of _PDC object.
  238. * Of course C1_FFH access mode will also be disabled.
  239. */
  240. union acpi_object *obj;
  241. u32 *buffer = NULL;
  242. obj = pdc_in->pointer;
  243. buffer = (u32 *)(obj->buffer.pointer);
  244. buffer[2] &= ~(ACPI_PDC_C_C2C3_FFH | ACPI_PDC_C_C1_FFH);
  245. }
  246. status = acpi_evaluate_object(handle, "_PDC", pdc_in, NULL);
  247. if (ACPI_FAILURE(status))
  248. ACPI_DEBUG_PRINT((ACPI_DB_INFO,
  249. "Could not evaluate _PDC, using legacy perf. control.\n"));
  250. return status;
  251. }
  252. void acpi_processor_set_pdc(acpi_handle handle)
  253. {
  254. struct acpi_object_list *obj_list;
  255. if (arch_has_acpi_pdc() == false)
  256. return;
  257. obj_list = acpi_processor_alloc_pdc();
  258. if (!obj_list)
  259. return;
  260. acpi_processor_eval_pdc(handle, obj_list);
  261. kfree(obj_list->pointer->buffer.pointer);
  262. kfree(obj_list->pointer);
  263. kfree(obj_list);
  264. }
  265. EXPORT_SYMBOL_GPL(acpi_processor_set_pdc);
  266. static acpi_status
  267. early_init_pdc(acpi_handle handle, u32 lvl, void *context, void **rv)
  268. {
  269. if (processor_physically_present(handle) == false)
  270. return AE_OK;
  271. acpi_processor_set_pdc(handle);
  272. return AE_OK;
  273. }
  274. void __init acpi_early_processor_set_pdc(void)
  275. {
  276. #ifdef CONFIG_SMP
  277. if (ACPI_FAILURE(acpi_get_table(ACPI_SIG_MADT, 0,
  278. (struct acpi_table_header **)&madt)))
  279. madt = NULL;
  280. #endif
  281. /*
  282. * Check whether the system is DMI table. If yes, OSPM
  283. * should not use mwait for CPU-states.
  284. */
  285. dmi_check_system(processor_idle_dmi_table);
  286. acpi_walk_namespace(ACPI_TYPE_PROCESSOR, ACPI_ROOT_OBJECT,
  287. ACPI_UINT32_MAX,
  288. early_init_pdc, NULL, NULL, NULL);
  289. }