processor_core.c 8.5 KB

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