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