aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/acpi
diff options
context:
space:
mode:
authorAlex Chiang <achiang@hp.com>2010-02-22 14:11:24 -0500
committerLen Brown <len.brown@intel.com>2010-03-14 21:17:19 -0400
commit78ed8bd2944b6400f742306e5fe9d1b9b6bf18ba (patch)
tree1dee7eaa89340e8ee03517da5589d033537e836d /drivers/acpi
parent2e9d5e4efa0beeca03ad550bda28027826e83e42 (diff)
ACPI: processor: move acpi_get_cpuid into processor_core.c
Enumerating processors (via MADT/_MAT) belongs in the processor core, which is always built-in, rather than living in the processor driver which may not be built. Acked-by: Venkatesh Pallipadi <venkatesh.pallipadi@intel.com> Signed-off-by: Alex Chiang <achiang@hp.com> Signed-off-by: Len Brown <len.brown@intel.com>
Diffstat (limited to 'drivers/acpi')
-rw-r--r--drivers/acpi/processor_core.c160
-rw-r--r--drivers/acpi/processor_driver.c159
2 files changed, 160 insertions, 159 deletions
diff --git a/drivers/acpi/processor_core.c b/drivers/acpi/processor_core.c
index 6f376bf42904..9ae5cc21f258 100644
--- a/drivers/acpi/processor_core.c
+++ b/drivers/acpi/processor_core.c
@@ -42,6 +42,159 @@ static struct dmi_system_id __cpuinitdata processor_idle_dmi_table[] = {
42 {}, 42 {},
43}; 43};
44 44
45#ifdef CONFIG_SMP
46static struct acpi_table_madt *madt;
47
48static int map_lapic_id(struct acpi_subtable_header *entry,
49 u32 acpi_id, int *apic_id)
50{
51 struct acpi_madt_local_apic *lapic =
52 (struct acpi_madt_local_apic *)entry;
53 if ((lapic->lapic_flags & ACPI_MADT_ENABLED) &&
54 lapic->processor_id == acpi_id) {
55 *apic_id = lapic->id;
56 return 1;
57 }
58 return 0;
59}
60
61static int map_x2apic_id(struct acpi_subtable_header *entry,
62 int device_declaration, u32 acpi_id, int *apic_id)
63{
64 struct acpi_madt_local_x2apic *apic =
65 (struct acpi_madt_local_x2apic *)entry;
66 u32 tmp = apic->local_apic_id;
67
68 /* Only check enabled APICs*/
69 if (!(apic->lapic_flags & ACPI_MADT_ENABLED))
70 return 0;
71
72 /* Device statement declaration type */
73 if (device_declaration) {
74 if (apic->uid == acpi_id)
75 goto found;
76 }
77
78 return 0;
79found:
80 *apic_id = tmp;
81 return 1;
82}
83
84static int map_lsapic_id(struct acpi_subtable_header *entry,
85 int device_declaration, u32 acpi_id, int *apic_id)
86{
87 struct acpi_madt_local_sapic *lsapic =
88 (struct acpi_madt_local_sapic *)entry;
89 u32 tmp = (lsapic->id << 8) | lsapic->eid;
90
91 /* Only check enabled APICs*/
92 if (!(lsapic->lapic_flags & ACPI_MADT_ENABLED))
93 return 0;
94
95 /* Device statement declaration type */
96 if (device_declaration) {
97 if (entry->length < 16)
98 printk(KERN_ERR PREFIX
99 "Invalid LSAPIC with Device type processor (SAPIC ID %#x)\n",
100 tmp);
101 else if (lsapic->uid == acpi_id)
102 goto found;
103 /* Processor statement declaration type */
104 } else if (lsapic->processor_id == acpi_id)
105 goto found;
106
107 return 0;
108found:
109 *apic_id = tmp;
110 return 1;
111}
112
113static int map_madt_entry(int type, u32 acpi_id)
114{
115 unsigned long madt_end, entry;
116 int apic_id = -1;
117
118 if (!madt)
119 return apic_id;
120
121 entry = (unsigned long)madt;
122 madt_end = entry + madt->header.length;
123
124 /* Parse all entries looking for a match. */
125
126 entry += sizeof(struct acpi_table_madt);
127 while (entry + sizeof(struct acpi_subtable_header) < madt_end) {
128 struct acpi_subtable_header *header =
129 (struct acpi_subtable_header *)entry;
130 if (header->type == ACPI_MADT_TYPE_LOCAL_APIC) {
131 if (map_lapic_id(header, acpi_id, &apic_id))
132 break;
133 } else if (header->type == ACPI_MADT_TYPE_LOCAL_X2APIC) {
134 if (map_x2apic_id(header, type, acpi_id, &apic_id))
135 break;
136 } else if (header->type == ACPI_MADT_TYPE_LOCAL_SAPIC) {
137 if (map_lsapic_id(header, type, acpi_id, &apic_id))
138 break;
139 }
140 entry += header->length;
141 }
142 return apic_id;
143}
144
145static int map_mat_entry(acpi_handle handle, int type, u32 acpi_id)
146{
147 struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL };
148 union acpi_object *obj;
149 struct acpi_subtable_header *header;
150 int apic_id = -1;
151
152 if (ACPI_FAILURE(acpi_evaluate_object(handle, "_MAT", NULL, &buffer)))
153 goto exit;
154
155 if (!buffer.length || !buffer.pointer)
156 goto exit;
157
158 obj = buffer.pointer;
159 if (obj->type != ACPI_TYPE_BUFFER ||
160 obj->buffer.length < sizeof(struct acpi_subtable_header)) {
161 goto exit;
162 }
163
164 header = (struct acpi_subtable_header *)obj->buffer.pointer;
165 if (header->type == ACPI_MADT_TYPE_LOCAL_APIC) {
166 map_lapic_id(header, acpi_id, &apic_id);
167 } else if (header->type == ACPI_MADT_TYPE_LOCAL_SAPIC) {
168 map_lsapic_id(header, type, acpi_id, &apic_id);
169 }
170
171exit:
172 if (buffer.pointer)
173 kfree(buffer.pointer);
174 return apic_id;
175}
176
177int acpi_get_cpuid(acpi_handle handle, int type, u32 acpi_id)
178{
179 int i;
180 int apic_id = -1;
181
182 apic_id = map_mat_entry(handle, type, acpi_id);
183 if (apic_id == -1)
184 apic_id = map_madt_entry(type, acpi_id);
185 if (apic_id == -1)
186 return apic_id;
187
188 for_each_possible_cpu(i) {
189 if (cpu_physical_id(i) == apic_id)
190 return i;
191 }
192 return -1;
193}
194EXPORT_SYMBOL_GPL(acpi_get_cpuid);
195#endif
196
197
45static void acpi_set_pdc_bits(u32 *buf) 198static void acpi_set_pdc_bits(u32 *buf)
46{ 199{
47 buf[0] = ACPI_PDC_REVISION_ID; 200 buf[0] = ACPI_PDC_REVISION_ID;
@@ -188,6 +341,13 @@ early_init_pdc(acpi_handle handle, u32 lvl, void *context, void **rv)
188 341
189void __init acpi_early_processor_set_pdc(void) 342void __init acpi_early_processor_set_pdc(void)
190{ 343{
344
345#ifdef CONFIG_SMP
346 if (ACPI_FAILURE(acpi_get_table(ACPI_SIG_MADT, 0,
347 (struct acpi_table_header **)&madt)))
348 madt = NULL;
349#endif
350
191 /* 351 /*
192 * Check whether the system is DMI table. If yes, OSPM 352 * Check whether the system is DMI table. If yes, OSPM
193 * should not use mwait for CPU-states. 353 * should not use mwait for CPU-states.
diff --git a/drivers/acpi/processor_driver.c b/drivers/acpi/processor_driver.c
index 98358251ce23..7eedf7475f4e 100644
--- a/drivers/acpi/processor_driver.c
+++ b/drivers/acpi/processor_driver.c
@@ -359,160 +359,6 @@ static inline int acpi_processor_remove_fs(struct acpi_device *device)
359} 359}
360#endif 360#endif
361 361
362/* Use the acpiid in MADT to map cpus in case of SMP */
363
364#ifdef CONFIG_SMP
365static struct acpi_table_madt *madt;
366
367static int map_lapic_id(struct acpi_subtable_header *entry,
368 u32 acpi_id, int *apic_id)
369{
370 struct acpi_madt_local_apic *lapic =
371 (struct acpi_madt_local_apic *)entry;
372 if ((lapic->lapic_flags & ACPI_MADT_ENABLED) &&
373 lapic->processor_id == acpi_id) {
374 *apic_id = lapic->id;
375 return 1;
376 }
377 return 0;
378}
379
380static int map_x2apic_id(struct acpi_subtable_header *entry,
381 int device_declaration, u32 acpi_id, int *apic_id)
382{
383 struct acpi_madt_local_x2apic *apic =
384 (struct acpi_madt_local_x2apic *)entry;
385 u32 tmp = apic->local_apic_id;
386
387 /* Only check enabled APICs*/
388 if (!(apic->lapic_flags & ACPI_MADT_ENABLED))
389 return 0;
390
391 /* Device statement declaration type */
392 if (device_declaration) {
393 if (apic->uid == acpi_id)
394 goto found;
395 }
396
397 return 0;
398found:
399 *apic_id = tmp;
400 return 1;
401}
402
403static int map_lsapic_id(struct acpi_subtable_header *entry,
404 int device_declaration, u32 acpi_id, int *apic_id)
405{
406 struct acpi_madt_local_sapic *lsapic =
407 (struct acpi_madt_local_sapic *)entry;
408 u32 tmp = (lsapic->id << 8) | lsapic->eid;
409
410 /* Only check enabled APICs*/
411 if (!(lsapic->lapic_flags & ACPI_MADT_ENABLED))
412 return 0;
413
414 /* Device statement declaration type */
415 if (device_declaration) {
416 if (entry->length < 16)
417 printk(KERN_ERR PREFIX
418 "Invalid LSAPIC with Device type processor (SAPIC ID %#x)\n",
419 tmp);
420 else if (lsapic->uid == acpi_id)
421 goto found;
422 /* Processor statement declaration type */
423 } else if (lsapic->processor_id == acpi_id)
424 goto found;
425
426 return 0;
427found:
428 *apic_id = tmp;
429 return 1;
430}
431
432static int map_madt_entry(int type, u32 acpi_id)
433{
434 unsigned long madt_end, entry;
435 int apic_id = -1;
436
437 if (!madt)
438 return apic_id;
439
440 entry = (unsigned long)madt;
441 madt_end = entry + madt->header.length;
442
443 /* Parse all entries looking for a match. */
444
445 entry += sizeof(struct acpi_table_madt);
446 while (entry + sizeof(struct acpi_subtable_header) < madt_end) {
447 struct acpi_subtable_header *header =
448 (struct acpi_subtable_header *)entry;
449 if (header->type == ACPI_MADT_TYPE_LOCAL_APIC) {
450 if (map_lapic_id(header, acpi_id, &apic_id))
451 break;
452 } else if (header->type == ACPI_MADT_TYPE_LOCAL_X2APIC) {
453 if (map_x2apic_id(header, type, acpi_id, &apic_id))
454 break;
455 } else if (header->type == ACPI_MADT_TYPE_LOCAL_SAPIC) {
456 if (map_lsapic_id(header, type, acpi_id, &apic_id))
457 break;
458 }
459 entry += header->length;
460 }
461 return apic_id;
462}
463
464static int map_mat_entry(acpi_handle handle, int type, u32 acpi_id)
465{
466 struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL };
467 union acpi_object *obj;
468 struct acpi_subtable_header *header;
469 int apic_id = -1;
470
471 if (ACPI_FAILURE(acpi_evaluate_object(handle, "_MAT", NULL, &buffer)))
472 goto exit;
473
474 if (!buffer.length || !buffer.pointer)
475 goto exit;
476
477 obj = buffer.pointer;
478 if (obj->type != ACPI_TYPE_BUFFER ||
479 obj->buffer.length < sizeof(struct acpi_subtable_header)) {
480 goto exit;
481 }
482
483 header = (struct acpi_subtable_header *)obj->buffer.pointer;
484 if (header->type == ACPI_MADT_TYPE_LOCAL_APIC) {
485 map_lapic_id(header, acpi_id, &apic_id);
486 } else if (header->type == ACPI_MADT_TYPE_LOCAL_SAPIC) {
487 map_lsapic_id(header, type, acpi_id, &apic_id);
488 }
489
490exit:
491 if (buffer.pointer)
492 kfree(buffer.pointer);
493 return apic_id;
494}
495
496int acpi_get_cpuid(acpi_handle handle, int type, u32 acpi_id)
497{
498 int i;
499 int apic_id = -1;
500
501 apic_id = map_mat_entry(handle, type, acpi_id);
502 if (apic_id == -1)
503 apic_id = map_madt_entry(type, acpi_id);
504 if (apic_id == -1)
505 return apic_id;
506
507 for_each_possible_cpu(i) {
508 if (cpu_physical_id(i) == apic_id)
509 return i;
510 }
511 return -1;
512}
513EXPORT_SYMBOL_GPL(acpi_get_cpuid);
514#endif
515
516/* -------------------------------------------------------------------------- 362/* --------------------------------------------------------------------------
517 Driver Interface 363 Driver Interface
518 -------------------------------------------------------------------------- */ 364 -------------------------------------------------------------------------- */
@@ -1071,11 +917,6 @@ static int __init acpi_processor_init(void)
1071 917
1072 memset(&errata, 0, sizeof(errata)); 918 memset(&errata, 0, sizeof(errata));
1073 919
1074#ifdef CONFIG_SMP
1075 if (ACPI_FAILURE(acpi_get_table(ACPI_SIG_MADT, 0,
1076 (struct acpi_table_header **)&madt)))
1077 madt = NULL;
1078#endif
1079#ifdef CONFIG_ACPI_PROCFS 920#ifdef CONFIG_ACPI_PROCFS
1080 acpi_processor_dir = proc_mkdir(ACPI_PROCESSOR_CLASS, acpi_root_dir); 921 acpi_processor_dir = proc_mkdir(ACPI_PROCESSOR_CLASS, acpi_root_dir);
1081 if (!acpi_processor_dir) 922 if (!acpi_processor_dir)