diff options
author | Alex Chiang <achiang@hp.com> | 2010-02-22 14:11:24 -0500 |
---|---|---|
committer | Len Brown <len.brown@intel.com> | 2010-03-14 21:17:19 -0400 |
commit | 78ed8bd2944b6400f742306e5fe9d1b9b6bf18ba (patch) | |
tree | 1dee7eaa89340e8ee03517da5589d033537e836d /drivers/acpi/processor_core.c | |
parent | 2e9d5e4efa0beeca03ad550bda28027826e83e42 (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/processor_core.c')
-rw-r--r-- | drivers/acpi/processor_core.c | 160 |
1 files changed, 160 insertions, 0 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 | ||
46 | static struct acpi_table_madt *madt; | ||
47 | |||
48 | static 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 | |||
61 | static 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; | ||
79 | found: | ||
80 | *apic_id = tmp; | ||
81 | return 1; | ||
82 | } | ||
83 | |||
84 | static 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; | ||
108 | found: | ||
109 | *apic_id = tmp; | ||
110 | return 1; | ||
111 | } | ||
112 | |||
113 | static 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 | |||
145 | static 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 | |||
171 | exit: | ||
172 | if (buffer.pointer) | ||
173 | kfree(buffer.pointer); | ||
174 | return apic_id; | ||
175 | } | ||
176 | |||
177 | int 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 | } | ||
194 | EXPORT_SYMBOL_GPL(acpi_get_cpuid); | ||
195 | #endif | ||
196 | |||
197 | |||
45 | static void acpi_set_pdc_bits(u32 *buf) | 198 | static 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 | ||
189 | void __init acpi_early_processor_set_pdc(void) | 342 | void __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. |