blob: 9eeda9e437eaa2eb1e5422286cfcd70fd16a43d5 [file] [log] [blame]
Alex Chiang47817252009-12-20 12:19:34 -07001/*
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 */
Alex Chiang78f16992009-12-20 12:19:09 -070010#include <linux/dmi.h>
11
12#include <acpi/acpi_drivers.h>
13#include <acpi/processor.h>
14
15#include "internal.h"
16
17#define PREFIX "ACPI: "
18#define _COMPONENT ACPI_PROCESSOR_COMPONENT
Alex Chiang4d5d4cd2010-02-22 12:11:14 -070019ACPI_MODULE_NAME("processor_core");
Alex Chiang78f16992009-12-20 12:19:09 -070020
21static int set_no_mwait(const struct dmi_system_id *id)
22{
23 printk(KERN_NOTICE PREFIX "%s detected - "
24 "disabling mwait for CPU C-states\n", id->ident);
25 idle_nomwait = 1;
26 return 0;
27}
28
29static struct dmi_system_id __cpuinitdata processor_idle_dmi_table[] = {
30 {
31 set_no_mwait, "IFL91 board", {
32 DMI_MATCH(DMI_BIOS_VENDOR, "COMPAL"),
33 DMI_MATCH(DMI_SYS_VENDOR, "ZEPTO"),
34 DMI_MATCH(DMI_PRODUCT_VERSION, "3215W"),
35 DMI_MATCH(DMI_BOARD_NAME, "IFL91") }, NULL},
36 {
37 set_no_mwait, "Extensa 5220", {
38 DMI_MATCH(DMI_BIOS_VENDOR, "Phoenix Technologies LTD"),
39 DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
40 DMI_MATCH(DMI_PRODUCT_VERSION, "0100"),
41 DMI_MATCH(DMI_BOARD_NAME, "Columbia") }, NULL},
42 {},
43};
44
Alex Chiang78ed8bd2010-02-22 12:11:24 -070045#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;
Alex Chiang11130732010-02-22 12:11:44 -070053
54 if (!(lapic->lapic_flags & ACPI_MADT_ENABLED))
55 return 0;
56
57 if (lapic->processor_id != acpi_id)
58 return 0;
59
60 *apic_id = lapic->id;
61 return 1;
Alex Chiang78ed8bd2010-02-22 12:11:24 -070062}
63
64static int map_x2apic_id(struct acpi_subtable_header *entry,
65 int device_declaration, u32 acpi_id, int *apic_id)
66{
67 struct acpi_madt_local_x2apic *apic =
68 (struct acpi_madt_local_x2apic *)entry;
69 u32 tmp = apic->local_apic_id;
70
71 /* Only check enabled APICs*/
72 if (!(apic->lapic_flags & ACPI_MADT_ENABLED))
73 return 0;
74
75 /* Device statement declaration type */
76 if (device_declaration) {
77 if (apic->uid == acpi_id)
78 goto found;
79 }
80
81 return 0;
82found:
83 *apic_id = tmp;
84 return 1;
85}
86
87static int map_lsapic_id(struct acpi_subtable_header *entry,
88 int device_declaration, u32 acpi_id, int *apic_id)
89{
90 struct acpi_madt_local_sapic *lsapic =
91 (struct acpi_madt_local_sapic *)entry;
92 u32 tmp = (lsapic->id << 8) | lsapic->eid;
93
94 /* Only check enabled APICs*/
95 if (!(lsapic->lapic_flags & ACPI_MADT_ENABLED))
96 return 0;
97
98 /* Device statement declaration type */
99 if (device_declaration) {
100 if (entry->length < 16)
101 printk(KERN_ERR PREFIX
102 "Invalid LSAPIC with Device type processor (SAPIC ID %#x)\n",
103 tmp);
104 else if (lsapic->uid == acpi_id)
105 goto found;
106 /* Processor statement declaration type */
107 } else if (lsapic->processor_id == acpi_id)
108 goto found;
109
110 return 0;
111found:
112 *apic_id = tmp;
113 return 1;
114}
115
116static int map_madt_entry(int type, u32 acpi_id)
117{
118 unsigned long madt_end, entry;
119 int apic_id = -1;
120
121 if (!madt)
122 return apic_id;
123
124 entry = (unsigned long)madt;
125 madt_end = entry + madt->header.length;
126
127 /* Parse all entries looking for a match. */
128
129 entry += sizeof(struct acpi_table_madt);
130 while (entry + sizeof(struct acpi_subtable_header) < madt_end) {
131 struct acpi_subtable_header *header =
132 (struct acpi_subtable_header *)entry;
133 if (header->type == ACPI_MADT_TYPE_LOCAL_APIC) {
134 if (map_lapic_id(header, acpi_id, &apic_id))
135 break;
136 } else if (header->type == ACPI_MADT_TYPE_LOCAL_X2APIC) {
137 if (map_x2apic_id(header, type, acpi_id, &apic_id))
138 break;
139 } else if (header->type == ACPI_MADT_TYPE_LOCAL_SAPIC) {
140 if (map_lsapic_id(header, type, acpi_id, &apic_id))
141 break;
142 }
143 entry += header->length;
144 }
145 return apic_id;
146}
147
148static int map_mat_entry(acpi_handle handle, int type, u32 acpi_id)
149{
150 struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL };
151 union acpi_object *obj;
152 struct acpi_subtable_header *header;
153 int apic_id = -1;
154
155 if (ACPI_FAILURE(acpi_evaluate_object(handle, "_MAT", NULL, &buffer)))
156 goto exit;
157
158 if (!buffer.length || !buffer.pointer)
159 goto exit;
160
161 obj = buffer.pointer;
162 if (obj->type != ACPI_TYPE_BUFFER ||
163 obj->buffer.length < sizeof(struct acpi_subtable_header)) {
164 goto exit;
165 }
166
167 header = (struct acpi_subtable_header *)obj->buffer.pointer;
168 if (header->type == ACPI_MADT_TYPE_LOCAL_APIC) {
169 map_lapic_id(header, acpi_id, &apic_id);
170 } else if (header->type == ACPI_MADT_TYPE_LOCAL_SAPIC) {
171 map_lsapic_id(header, type, acpi_id, &apic_id);
172 }
173
174exit:
175 if (buffer.pointer)
176 kfree(buffer.pointer);
177 return apic_id;
178}
179
180int acpi_get_cpuid(acpi_handle handle, int type, u32 acpi_id)
181{
182 int i;
183 int apic_id = -1;
184
185 apic_id = map_mat_entry(handle, type, acpi_id);
186 if (apic_id == -1)
187 apic_id = map_madt_entry(type, acpi_id);
188 if (apic_id == -1)
189 return apic_id;
190
191 for_each_possible_cpu(i) {
192 if (cpu_physical_id(i) == apic_id)
193 return i;
194 }
195 return -1;
196}
197EXPORT_SYMBOL_GPL(acpi_get_cpuid);
198#endif
199
Alex Chiang5d554a72010-02-22 12:11:29 -0700200static bool processor_physically_present(acpi_handle handle)
201{
202 int cpuid, type;
203 u32 acpi_id;
204 acpi_status status;
205 acpi_object_type acpi_type;
206 unsigned long long tmp;
207 union acpi_object object = { 0 };
208 struct acpi_buffer buffer = { sizeof(union acpi_object), &object };
209
210 status = acpi_get_type(handle, &acpi_type);
211 if (ACPI_FAILURE(status))
212 return false;
213
214 switch (acpi_type) {
215 case ACPI_TYPE_PROCESSOR:
216 status = acpi_evaluate_object(handle, NULL, NULL, &buffer);
217 if (ACPI_FAILURE(status))
218 return false;
219 acpi_id = object.processor.proc_id;
220 break;
221 case ACPI_TYPE_DEVICE:
222 status = acpi_evaluate_integer(handle, "_UID", NULL, &tmp);
223 if (ACPI_FAILURE(status))
224 return false;
225 acpi_id = tmp;
226 break;
227 default:
228 return false;
229 }
230
231 type = (acpi_type == ACPI_TYPE_DEVICE) ? 1 : 0;
232 cpuid = acpi_get_cpuid(handle, type, acpi_id);
233
234 if (cpuid == -1)
235 return false;
236
237 return true;
238}
Alex Chiang78ed8bd2010-02-22 12:11:24 -0700239
Alex Chiang08ea48a2009-12-20 12:19:24 -0700240static void acpi_set_pdc_bits(u32 *buf)
241{
242 buf[0] = ACPI_PDC_REVISION_ID;
243 buf[1] = 1;
244
245 /* Enable coordination with firmware's _TSD info */
246 buf[2] = ACPI_PDC_SMP_T_SWCOORD;
Alex Chiang6c5807d2009-12-20 12:19:29 -0700247
248 /* Twiddle arch-specific bits needed for _PDC */
249 arch_acpi_set_pdc_bits(buf);
Alex Chiang08ea48a2009-12-20 12:19:24 -0700250}
251
Alex Chiang3b407ae2009-12-20 12:19:39 -0700252static struct acpi_object_list *acpi_processor_alloc_pdc(void)
Alex Chiang407cd872009-12-20 12:19:19 -0700253{
254 struct acpi_object_list *obj_list;
255 union acpi_object *obj;
256 u32 *buf;
257
Alex Chiang407cd872009-12-20 12:19:19 -0700258 /* allocate and initialize pdc. It will be used later. */
259 obj_list = kmalloc(sizeof(struct acpi_object_list), GFP_KERNEL);
260 if (!obj_list) {
261 printk(KERN_ERR "Memory allocation error\n");
Alex Chiang3b407ae2009-12-20 12:19:39 -0700262 return NULL;
Alex Chiang407cd872009-12-20 12:19:19 -0700263 }
264
265 obj = kmalloc(sizeof(union acpi_object), GFP_KERNEL);
266 if (!obj) {
267 printk(KERN_ERR "Memory allocation error\n");
268 kfree(obj_list);
Alex Chiang3b407ae2009-12-20 12:19:39 -0700269 return NULL;
Alex Chiang407cd872009-12-20 12:19:19 -0700270 }
271
272 buf = kmalloc(12, GFP_KERNEL);
273 if (!buf) {
274 printk(KERN_ERR "Memory allocation error\n");
275 kfree(obj);
276 kfree(obj_list);
Alex Chiang3b407ae2009-12-20 12:19:39 -0700277 return NULL;
Alex Chiang407cd872009-12-20 12:19:19 -0700278 }
279
Alex Chiang08ea48a2009-12-20 12:19:24 -0700280 acpi_set_pdc_bits(buf);
281
Alex Chiang407cd872009-12-20 12:19:19 -0700282 obj->type = ACPI_TYPE_BUFFER;
283 obj->buffer.length = 12;
284 obj->buffer.pointer = (u8 *) buf;
285 obj_list->count = 1;
286 obj_list->pointer = obj;
Alex Chiang407cd872009-12-20 12:19:19 -0700287
Alex Chiang3b407ae2009-12-20 12:19:39 -0700288 return obj_list;
Alex Chiang407cd872009-12-20 12:19:19 -0700289}
290
Alex Chiang78f16992009-12-20 12:19:09 -0700291/*
292 * _PDC is required for a BIOS-OS handshake for most of the newer
293 * ACPI processor features.
294 */
Alex Chiangfa118562009-12-20 12:19:45 -0700295static int
296acpi_processor_eval_pdc(acpi_handle handle, struct acpi_object_list *pdc_in)
Alex Chiang78f16992009-12-20 12:19:09 -0700297{
Alex Chiang78f16992009-12-20 12:19:09 -0700298 acpi_status status = AE_OK;
299
Alex Chiang78f16992009-12-20 12:19:09 -0700300 if (idle_nomwait) {
301 /*
302 * If mwait is disabled for CPU C-states, the C2C3_FFH access
303 * mode will be disabled in the parameter of _PDC object.
304 * Of course C1_FFH access mode will also be disabled.
305 */
306 union acpi_object *obj;
307 u32 *buffer = NULL;
308
309 obj = pdc_in->pointer;
310 buffer = (u32 *)(obj->buffer.pointer);
311 buffer[2] &= ~(ACPI_PDC_C_C2C3_FFH | ACPI_PDC_C_C1_FFH);
312
313 }
Alex Chiangfa118562009-12-20 12:19:45 -0700314 status = acpi_evaluate_object(handle, "_PDC", pdc_in, NULL);
Alex Chiang78f16992009-12-20 12:19:09 -0700315
316 if (ACPI_FAILURE(status))
317 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
318 "Could not evaluate _PDC, using legacy perf. control.\n"));
319
320 return status;
321}
322
Alex Chiang43bab252009-12-20 12:23:16 -0700323void acpi_processor_set_pdc(acpi_handle handle)
Alex Chiang78f16992009-12-20 12:19:09 -0700324{
Alex Chiang3b407ae2009-12-20 12:19:39 -0700325 struct acpi_object_list *obj_list;
326
Alex Chiang1d9cb472009-12-20 12:19:14 -0700327 if (arch_has_acpi_pdc() == false)
328 return;
329
Alex Chiang3b407ae2009-12-20 12:19:39 -0700330 obj_list = acpi_processor_alloc_pdc();
331 if (!obj_list)
332 return;
333
Alex Chiang43bab252009-12-20 12:23:16 -0700334 acpi_processor_eval_pdc(handle, obj_list);
Alex Chiangb9c2db72009-12-20 12:23:11 -0700335
336 kfree(obj_list->pointer->buffer.pointer);
337 kfree(obj_list->pointer);
338 kfree(obj_list);
Alex Chiang78f16992009-12-20 12:19:09 -0700339}
340EXPORT_SYMBOL_GPL(acpi_processor_set_pdc);
341
342static acpi_status
343early_init_pdc(acpi_handle handle, u32 lvl, void *context, void **rv)
344{
Alex Chiang5d554a72010-02-22 12:11:29 -0700345 if (processor_physically_present(handle) == false)
346 return AE_OK;
347
Alex Chiang43bab252009-12-20 12:23:16 -0700348 acpi_processor_set_pdc(handle);
Alex Chiang78f16992009-12-20 12:19:09 -0700349 return AE_OK;
350}
351
Luck, Tony7a0b73a2009-12-28 10:39:23 -0800352void __init acpi_early_processor_set_pdc(void)
Alex Chiang78f16992009-12-20 12:19:09 -0700353{
Alex Chiang78ed8bd2010-02-22 12:11:24 -0700354
355#ifdef CONFIG_SMP
356 if (ACPI_FAILURE(acpi_get_table(ACPI_SIG_MADT, 0,
357 (struct acpi_table_header **)&madt)))
358 madt = NULL;
359#endif
360
Alex Chiang78f16992009-12-20 12:19:09 -0700361 /*
362 * Check whether the system is DMI table. If yes, OSPM
363 * should not use mwait for CPU-states.
364 */
365 dmi_check_system(processor_idle_dmi_table);
366
Alex Chiang78f16992009-12-20 12:19:09 -0700367 acpi_walk_namespace(ACPI_TYPE_PROCESSOR, ACPI_ROOT_OBJECT,
368 ACPI_UINT32_MAX,
369 early_init_pdc, NULL, NULL, NULL);
Alex Chiang78f16992009-12-20 12:19:09 -0700370}