processor_core.c 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381
  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 returns 0 for the processor
  162. * handle with acpi id 0 if nr_cpu_ids is 1.
  163. * This should be the case if SMP tables are not found.
  164. * Return -1 for other CPU's handle.
  165. */
  166. if (nr_cpu_ids <= 1 && acpi_id == 0)
  167. return acpi_id;
  168. else
  169. return apic_id;
  170. }
  171. #ifdef CONFIG_SMP
  172. for_each_possible_cpu(i) {
  173. if (cpu_physical_id(i) == apic_id)
  174. return i;
  175. }
  176. #else
  177. /* In UP kernel, only processor 0 is valid */
  178. if (apic_id == 0)
  179. return apic_id;
  180. #endif
  181. return -1;
  182. }
  183. EXPORT_SYMBOL_GPL(acpi_get_cpuid);
  184. static bool __init processor_physically_present(acpi_handle handle)
  185. {
  186. int cpuid, type;
  187. u32 acpi_id;
  188. acpi_status status;
  189. acpi_object_type acpi_type;
  190. unsigned long long tmp;
  191. union acpi_object object = { 0 };
  192. struct acpi_buffer buffer = { sizeof(union acpi_object), &object };
  193. status = acpi_get_type(handle, &acpi_type);
  194. if (ACPI_FAILURE(status))
  195. return false;
  196. switch (acpi_type) {
  197. case ACPI_TYPE_PROCESSOR:
  198. status = acpi_evaluate_object(handle, NULL, NULL, &buffer);
  199. if (ACPI_FAILURE(status))
  200. return false;
  201. acpi_id = object.processor.proc_id;
  202. break;
  203. case ACPI_TYPE_DEVICE:
  204. status = acpi_evaluate_integer(handle, "_UID", NULL, &tmp);
  205. if (ACPI_FAILURE(status))
  206. return false;
  207. acpi_id = tmp;
  208. break;
  209. default:
  210. return false;
  211. }
  212. type = (acpi_type == ACPI_TYPE_DEVICE) ? 1 : 0;
  213. cpuid = acpi_get_cpuid(handle, type, acpi_id);
  214. if (cpuid == -1)
  215. return false;
  216. return true;
  217. }
  218. static void __cpuinit acpi_set_pdc_bits(u32 *buf)
  219. {
  220. buf[0] = ACPI_PDC_REVISION_ID;
  221. buf[1] = 1;
  222. /* Enable coordination with firmware's _TSD info */
  223. buf[2] = ACPI_PDC_SMP_T_SWCOORD;
  224. /* Twiddle arch-specific bits needed for _PDC */
  225. arch_acpi_set_pdc_bits(buf);
  226. }
  227. static struct acpi_object_list *__cpuinit acpi_processor_alloc_pdc(void)
  228. {
  229. struct acpi_object_list *obj_list;
  230. union acpi_object *obj;
  231. u32 *buf;
  232. /* allocate and initialize pdc. It will be used later. */
  233. obj_list = kmalloc(sizeof(struct acpi_object_list), GFP_KERNEL);
  234. if (!obj_list) {
  235. printk(KERN_ERR "Memory allocation error\n");
  236. return NULL;
  237. }
  238. obj = kmalloc(sizeof(union acpi_object), GFP_KERNEL);
  239. if (!obj) {
  240. printk(KERN_ERR "Memory allocation error\n");
  241. kfree(obj_list);
  242. return NULL;
  243. }
  244. buf = kmalloc(12, GFP_KERNEL);
  245. if (!buf) {
  246. printk(KERN_ERR "Memory allocation error\n");
  247. kfree(obj);
  248. kfree(obj_list);
  249. return NULL;
  250. }
  251. acpi_set_pdc_bits(buf);
  252. obj->type = ACPI_TYPE_BUFFER;
  253. obj->buffer.length = 12;
  254. obj->buffer.pointer = (u8 *) buf;
  255. obj_list->count = 1;
  256. obj_list->pointer = obj;
  257. return obj_list;
  258. }
  259. /*
  260. * _PDC is required for a BIOS-OS handshake for most of the newer
  261. * ACPI processor features.
  262. */
  263. static int __cpuinit
  264. acpi_processor_eval_pdc(acpi_handle handle, struct acpi_object_list *pdc_in)
  265. {
  266. acpi_status status = AE_OK;
  267. if (boot_option_idle_override == IDLE_NOMWAIT) {
  268. /*
  269. * If mwait is disabled for CPU C-states, the C2C3_FFH access
  270. * mode will be disabled in the parameter of _PDC object.
  271. * Of course C1_FFH access mode will also be disabled.
  272. */
  273. union acpi_object *obj;
  274. u32 *buffer = NULL;
  275. obj = pdc_in->pointer;
  276. buffer = (u32 *)(obj->buffer.pointer);
  277. buffer[2] &= ~(ACPI_PDC_C_C2C3_FFH | ACPI_PDC_C_C1_FFH);
  278. }
  279. status = acpi_evaluate_object(handle, "_PDC", pdc_in, NULL);
  280. if (ACPI_FAILURE(status))
  281. ACPI_DEBUG_PRINT((ACPI_DB_INFO,
  282. "Could not evaluate _PDC, using legacy perf. control.\n"));
  283. return status;
  284. }
  285. void __cpuinit acpi_processor_set_pdc(acpi_handle handle)
  286. {
  287. struct acpi_object_list *obj_list;
  288. if (arch_has_acpi_pdc() == false)
  289. return;
  290. obj_list = acpi_processor_alloc_pdc();
  291. if (!obj_list)
  292. return;
  293. acpi_processor_eval_pdc(handle, obj_list);
  294. kfree(obj_list->pointer->buffer.pointer);
  295. kfree(obj_list->pointer);
  296. kfree(obj_list);
  297. }
  298. static acpi_status __init
  299. early_init_pdc(acpi_handle handle, u32 lvl, void *context, void **rv)
  300. {
  301. if (processor_physically_present(handle) == false)
  302. return AE_OK;
  303. acpi_processor_set_pdc(handle);
  304. return AE_OK;
  305. }
  306. void __init acpi_early_processor_set_pdc(void)
  307. {
  308. /*
  309. * Check whether the system is DMI table. If yes, OSPM
  310. * should not use mwait for CPU-states.
  311. */
  312. dmi_check_system(processor_idle_dmi_table);
  313. acpi_walk_namespace(ACPI_TYPE_PROCESSOR, ACPI_ROOT_OBJECT,
  314. ACPI_UINT32_MAX,
  315. early_init_pdc, NULL, NULL, NULL);
  316. acpi_get_devices("ACPI0007", early_init_pdc, NULL, NULL);
  317. }