Alex Chiang | 4781725 | 2009-12-20 12:19:34 -0700 | [diff] [blame] | 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 | */ |
Alex Chiang | 78f1699 | 2009-12-20 12:19:09 -0700 | [diff] [blame] | 10 | #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 Chiang | 4d5d4cd | 2010-02-22 12:11:14 -0700 | [diff] [blame] | 19 | ACPI_MODULE_NAME("processor_core"); |
Alex Chiang | 78f1699 | 2009-12-20 12:19:09 -0700 | [diff] [blame] | 20 | |
| 21 | static 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 | |
| 29 | static 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 Chiang | 78ed8bd | 2010-02-22 12:11:24 -0700 | [diff] [blame] | 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; |
Alex Chiang | 1113073 | 2010-02-22 12:11:44 -0700 | [diff] [blame^] | 53 | |
| 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 Chiang | 78ed8bd | 2010-02-22 12:11:24 -0700 | [diff] [blame] | 62 | } |
| 63 | |
| 64 | static 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; |
| 82 | found: |
| 83 | *apic_id = tmp; |
| 84 | return 1; |
| 85 | } |
| 86 | |
| 87 | static 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; |
| 111 | found: |
| 112 | *apic_id = tmp; |
| 113 | return 1; |
| 114 | } |
| 115 | |
| 116 | static 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 | |
| 148 | static 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 | |
| 174 | exit: |
| 175 | if (buffer.pointer) |
| 176 | kfree(buffer.pointer); |
| 177 | return apic_id; |
| 178 | } |
| 179 | |
| 180 | int 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 | } |
| 197 | EXPORT_SYMBOL_GPL(acpi_get_cpuid); |
| 198 | #endif |
| 199 | |
Alex Chiang | 5d554a7 | 2010-02-22 12:11:29 -0700 | [diff] [blame] | 200 | static 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 Chiang | 78ed8bd | 2010-02-22 12:11:24 -0700 | [diff] [blame] | 239 | |
Alex Chiang | 08ea48a | 2009-12-20 12:19:24 -0700 | [diff] [blame] | 240 | static 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 Chiang | 6c5807d | 2009-12-20 12:19:29 -0700 | [diff] [blame] | 247 | |
| 248 | /* Twiddle arch-specific bits needed for _PDC */ |
| 249 | arch_acpi_set_pdc_bits(buf); |
Alex Chiang | 08ea48a | 2009-12-20 12:19:24 -0700 | [diff] [blame] | 250 | } |
| 251 | |
Alex Chiang | 3b407ae | 2009-12-20 12:19:39 -0700 | [diff] [blame] | 252 | static struct acpi_object_list *acpi_processor_alloc_pdc(void) |
Alex Chiang | 407cd87 | 2009-12-20 12:19:19 -0700 | [diff] [blame] | 253 | { |
| 254 | struct acpi_object_list *obj_list; |
| 255 | union acpi_object *obj; |
| 256 | u32 *buf; |
| 257 | |
Alex Chiang | 407cd87 | 2009-12-20 12:19:19 -0700 | [diff] [blame] | 258 | /* 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 Chiang | 3b407ae | 2009-12-20 12:19:39 -0700 | [diff] [blame] | 262 | return NULL; |
Alex Chiang | 407cd87 | 2009-12-20 12:19:19 -0700 | [diff] [blame] | 263 | } |
| 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 Chiang | 3b407ae | 2009-12-20 12:19:39 -0700 | [diff] [blame] | 269 | return NULL; |
Alex Chiang | 407cd87 | 2009-12-20 12:19:19 -0700 | [diff] [blame] | 270 | } |
| 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 Chiang | 3b407ae | 2009-12-20 12:19:39 -0700 | [diff] [blame] | 277 | return NULL; |
Alex Chiang | 407cd87 | 2009-12-20 12:19:19 -0700 | [diff] [blame] | 278 | } |
| 279 | |
Alex Chiang | 08ea48a | 2009-12-20 12:19:24 -0700 | [diff] [blame] | 280 | acpi_set_pdc_bits(buf); |
| 281 | |
Alex Chiang | 407cd87 | 2009-12-20 12:19:19 -0700 | [diff] [blame] | 282 | 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 Chiang | 407cd87 | 2009-12-20 12:19:19 -0700 | [diff] [blame] | 287 | |
Alex Chiang | 3b407ae | 2009-12-20 12:19:39 -0700 | [diff] [blame] | 288 | return obj_list; |
Alex Chiang | 407cd87 | 2009-12-20 12:19:19 -0700 | [diff] [blame] | 289 | } |
| 290 | |
Alex Chiang | 78f1699 | 2009-12-20 12:19:09 -0700 | [diff] [blame] | 291 | /* |
| 292 | * _PDC is required for a BIOS-OS handshake for most of the newer |
| 293 | * ACPI processor features. |
| 294 | */ |
Alex Chiang | fa11856 | 2009-12-20 12:19:45 -0700 | [diff] [blame] | 295 | static int |
| 296 | acpi_processor_eval_pdc(acpi_handle handle, struct acpi_object_list *pdc_in) |
Alex Chiang | 78f1699 | 2009-12-20 12:19:09 -0700 | [diff] [blame] | 297 | { |
Alex Chiang | 78f1699 | 2009-12-20 12:19:09 -0700 | [diff] [blame] | 298 | acpi_status status = AE_OK; |
| 299 | |
Alex Chiang | 78f1699 | 2009-12-20 12:19:09 -0700 | [diff] [blame] | 300 | 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 Chiang | fa11856 | 2009-12-20 12:19:45 -0700 | [diff] [blame] | 314 | status = acpi_evaluate_object(handle, "_PDC", pdc_in, NULL); |
Alex Chiang | 78f1699 | 2009-12-20 12:19:09 -0700 | [diff] [blame] | 315 | |
| 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 Chiang | 43bab25 | 2009-12-20 12:23:16 -0700 | [diff] [blame] | 323 | void acpi_processor_set_pdc(acpi_handle handle) |
Alex Chiang | 78f1699 | 2009-12-20 12:19:09 -0700 | [diff] [blame] | 324 | { |
Alex Chiang | 3b407ae | 2009-12-20 12:19:39 -0700 | [diff] [blame] | 325 | struct acpi_object_list *obj_list; |
| 326 | |
Alex Chiang | 1d9cb47 | 2009-12-20 12:19:14 -0700 | [diff] [blame] | 327 | if (arch_has_acpi_pdc() == false) |
| 328 | return; |
| 329 | |
Alex Chiang | 3b407ae | 2009-12-20 12:19:39 -0700 | [diff] [blame] | 330 | obj_list = acpi_processor_alloc_pdc(); |
| 331 | if (!obj_list) |
| 332 | return; |
| 333 | |
Alex Chiang | 43bab25 | 2009-12-20 12:23:16 -0700 | [diff] [blame] | 334 | acpi_processor_eval_pdc(handle, obj_list); |
Alex Chiang | b9c2db7 | 2009-12-20 12:23:11 -0700 | [diff] [blame] | 335 | |
| 336 | kfree(obj_list->pointer->buffer.pointer); |
| 337 | kfree(obj_list->pointer); |
| 338 | kfree(obj_list); |
Alex Chiang | 78f1699 | 2009-12-20 12:19:09 -0700 | [diff] [blame] | 339 | } |
| 340 | EXPORT_SYMBOL_GPL(acpi_processor_set_pdc); |
| 341 | |
| 342 | static acpi_status |
| 343 | early_init_pdc(acpi_handle handle, u32 lvl, void *context, void **rv) |
| 344 | { |
Alex Chiang | 5d554a7 | 2010-02-22 12:11:29 -0700 | [diff] [blame] | 345 | if (processor_physically_present(handle) == false) |
| 346 | return AE_OK; |
| 347 | |
Alex Chiang | 43bab25 | 2009-12-20 12:23:16 -0700 | [diff] [blame] | 348 | acpi_processor_set_pdc(handle); |
Alex Chiang | 78f1699 | 2009-12-20 12:19:09 -0700 | [diff] [blame] | 349 | return AE_OK; |
| 350 | } |
| 351 | |
Luck, Tony | 7a0b73a | 2009-12-28 10:39:23 -0800 | [diff] [blame] | 352 | void __init acpi_early_processor_set_pdc(void) |
Alex Chiang | 78f1699 | 2009-12-20 12:19:09 -0700 | [diff] [blame] | 353 | { |
Alex Chiang | 78ed8bd | 2010-02-22 12:11:24 -0700 | [diff] [blame] | 354 | |
| 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 Chiang | 78f1699 | 2009-12-20 12:19:09 -0700 | [diff] [blame] | 361 | /* |
| 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 Chiang | 78f1699 | 2009-12-20 12:19:09 -0700 | [diff] [blame] | 367 | acpi_walk_namespace(ACPI_TYPE_PROCESSOR, ACPI_ROOT_OBJECT, |
| 368 | ACPI_UINT32_MAX, |
| 369 | early_init_pdc, NULL, NULL, NULL); |
Alex Chiang | 78f1699 | 2009-12-20 12:19:09 -0700 | [diff] [blame] | 370 | } |