PageRenderTime 45ms CodeModel.GetById 18ms RepoModel.GetById 1ms app.codeStats 0ms

/drivers/acpi/processor_core.c

https://bitbucket.org/wisechild/galaxy-nexus
C | 355 lines | 265 code | 63 blank | 27 comment | 67 complexity | ffa57dc1a98d758d196d861e2bb4fed0 MD5 | raw file
Possible License(s): GPL-2.0, LGPL-2.0, AGPL-1.0
  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. return apic_id;
  146. #ifdef CONFIG_SMP
  147. for_each_possible_cpu(i) {
  148. if (cpu_physical_id(i) == apic_id)
  149. return i;
  150. }
  151. #else
  152. /* In UP kernel, only processor 0 is valid */
  153. if (apic_id == 0)
  154. return apic_id;
  155. #endif
  156. return -1;
  157. }
  158. EXPORT_SYMBOL_GPL(acpi_get_cpuid);
  159. static bool __init 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)
  190. return false;
  191. return true;
  192. }
  193. static void __cpuinit 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 *__cpuinit 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 __cpuinit
  239. acpi_processor_eval_pdc(acpi_handle handle, struct acpi_object_list *pdc_in)
  240. {
  241. acpi_status status = AE_OK;
  242. if (boot_option_idle_override == 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 __cpuinit 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. static acpi_status __init
  274. early_init_pdc(acpi_handle handle, u32 lvl, void *context, void **rv)
  275. {
  276. if (processor_physically_present(handle) == false)
  277. return AE_OK;
  278. acpi_processor_set_pdc(handle);
  279. return AE_OK;
  280. }
  281. void __init acpi_early_processor_set_pdc(void)
  282. {
  283. /*
  284. * Check whether the system is DMI table. If yes, OSPM
  285. * should not use mwait for CPU-states.
  286. */
  287. dmi_check_system(processor_idle_dmi_table);
  288. acpi_walk_namespace(ACPI_TYPE_PROCESSOR, ACPI_ROOT_OBJECT,
  289. ACPI_UINT32_MAX,
  290. early_init_pdc, NULL, NULL, NULL);
  291. acpi_get_devices("ACPI0007", early_init_pdc, NULL, NULL);
  292. }