processor_core.c 8.9 KB

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