processor_core.c 8.3 KB

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