diff options
Diffstat (limited to 'drivers/acpi/bus.c')
-rw-r--r-- | drivers/acpi/bus.c | 160 |
1 files changed, 160 insertions, 0 deletions
diff --git a/drivers/acpi/bus.c b/drivers/acpi/bus.c index 741191524353..cf761b904e4a 100644 --- a/drivers/acpi/bus.c +++ b/drivers/acpi/bus.c | |||
@@ -344,6 +344,162 @@ bool acpi_bus_can_wakeup(acpi_handle handle) | |||
344 | 344 | ||
345 | EXPORT_SYMBOL(acpi_bus_can_wakeup); | 345 | EXPORT_SYMBOL(acpi_bus_can_wakeup); |
346 | 346 | ||
347 | static void acpi_print_osc_error(acpi_handle handle, | ||
348 | struct acpi_osc_context *context, char *error) | ||
349 | { | ||
350 | struct acpi_buffer buffer = {ACPI_ALLOCATE_BUFFER}; | ||
351 | int i; | ||
352 | |||
353 | if (ACPI_FAILURE(acpi_get_name(handle, ACPI_FULL_PATHNAME, &buffer))) | ||
354 | printk(KERN_DEBUG "%s\n", error); | ||
355 | else { | ||
356 | printk(KERN_DEBUG "%s:%s\n", (char *)buffer.pointer, error); | ||
357 | kfree(buffer.pointer); | ||
358 | } | ||
359 | printk(KERN_DEBUG"_OSC request data:"); | ||
360 | for (i = 0; i < context->cap.length; i += sizeof(u32)) | ||
361 | printk("%x ", *((u32 *)(context->cap.pointer + i))); | ||
362 | printk("\n"); | ||
363 | } | ||
364 | |||
365 | static u8 hex_val(unsigned char c) | ||
366 | { | ||
367 | return isdigit(c) ? c - '0' : toupper(c) - 'A' + 10; | ||
368 | } | ||
369 | |||
370 | static acpi_status acpi_str_to_uuid(char *str, u8 *uuid) | ||
371 | { | ||
372 | int i; | ||
373 | static int opc_map_to_uuid[16] = {6, 4, 2, 0, 11, 9, 16, 14, 19, 21, | ||
374 | 24, 26, 28, 30, 32, 34}; | ||
375 | |||
376 | if (strlen(str) != 36) | ||
377 | return AE_BAD_PARAMETER; | ||
378 | for (i = 0; i < 36; i++) { | ||
379 | if (i == 8 || i == 13 || i == 18 || i == 23) { | ||
380 | if (str[i] != '-') | ||
381 | return AE_BAD_PARAMETER; | ||
382 | } else if (!isxdigit(str[i])) | ||
383 | return AE_BAD_PARAMETER; | ||
384 | } | ||
385 | for (i = 0; i < 16; i++) { | ||
386 | uuid[i] = hex_val(str[opc_map_to_uuid[i]]) << 4; | ||
387 | uuid[i] |= hex_val(str[opc_map_to_uuid[i] + 1]); | ||
388 | } | ||
389 | return AE_OK; | ||
390 | } | ||
391 | |||
392 | acpi_status acpi_run_osc(acpi_handle handle, struct acpi_osc_context *context) | ||
393 | { | ||
394 | acpi_status status; | ||
395 | struct acpi_object_list input; | ||
396 | union acpi_object in_params[4]; | ||
397 | union acpi_object *out_obj; | ||
398 | u8 uuid[16]; | ||
399 | u32 errors; | ||
400 | struct acpi_buffer output = {ACPI_ALLOCATE_BUFFER, NULL}; | ||
401 | |||
402 | if (!context) | ||
403 | return AE_ERROR; | ||
404 | if (ACPI_FAILURE(acpi_str_to_uuid(context->uuid_str, uuid))) | ||
405 | return AE_ERROR; | ||
406 | context->ret.length = ACPI_ALLOCATE_BUFFER; | ||
407 | context->ret.pointer = NULL; | ||
408 | |||
409 | /* Setting up input parameters */ | ||
410 | input.count = 4; | ||
411 | input.pointer = in_params; | ||
412 | in_params[0].type = ACPI_TYPE_BUFFER; | ||
413 | in_params[0].buffer.length = 16; | ||
414 | in_params[0].buffer.pointer = uuid; | ||
415 | in_params[1].type = ACPI_TYPE_INTEGER; | ||
416 | in_params[1].integer.value = context->rev; | ||
417 | in_params[2].type = ACPI_TYPE_INTEGER; | ||
418 | in_params[2].integer.value = context->cap.length/sizeof(u32); | ||
419 | in_params[3].type = ACPI_TYPE_BUFFER; | ||
420 | in_params[3].buffer.length = context->cap.length; | ||
421 | in_params[3].buffer.pointer = context->cap.pointer; | ||
422 | |||
423 | status = acpi_evaluate_object(handle, "_OSC", &input, &output); | ||
424 | if (ACPI_FAILURE(status)) | ||
425 | return status; | ||
426 | |||
427 | if (!output.length) | ||
428 | return AE_NULL_OBJECT; | ||
429 | |||
430 | out_obj = output.pointer; | ||
431 | if (out_obj->type != ACPI_TYPE_BUFFER | ||
432 | || out_obj->buffer.length != context->cap.length) { | ||
433 | acpi_print_osc_error(handle, context, | ||
434 | "_OSC evaluation returned wrong type"); | ||
435 | status = AE_TYPE; | ||
436 | goto out_kfree; | ||
437 | } | ||
438 | /* Need to ignore the bit0 in result code */ | ||
439 | errors = *((u32 *)out_obj->buffer.pointer) & ~(1 << 0); | ||
440 | if (errors) { | ||
441 | if (errors & OSC_REQUEST_ERROR) | ||
442 | acpi_print_osc_error(handle, context, | ||
443 | "_OSC request failed"); | ||
444 | if (errors & OSC_INVALID_UUID_ERROR) | ||
445 | acpi_print_osc_error(handle, context, | ||
446 | "_OSC invalid UUID"); | ||
447 | if (errors & OSC_INVALID_REVISION_ERROR) | ||
448 | acpi_print_osc_error(handle, context, | ||
449 | "_OSC invalid revision"); | ||
450 | if (errors & OSC_CAPABILITIES_MASK_ERROR) { | ||
451 | if (((u32 *)context->cap.pointer)[OSC_QUERY_TYPE] | ||
452 | & OSC_QUERY_ENABLE) | ||
453 | goto out_success; | ||
454 | status = AE_SUPPORT; | ||
455 | goto out_kfree; | ||
456 | } | ||
457 | status = AE_ERROR; | ||
458 | goto out_kfree; | ||
459 | } | ||
460 | out_success: | ||
461 | context->ret.length = out_obj->buffer.length; | ||
462 | context->ret.pointer = kmalloc(context->ret.length, GFP_KERNEL); | ||
463 | if (!context->ret.pointer) { | ||
464 | status = AE_NO_MEMORY; | ||
465 | goto out_kfree; | ||
466 | } | ||
467 | memcpy(context->ret.pointer, out_obj->buffer.pointer, | ||
468 | context->ret.length); | ||
469 | status = AE_OK; | ||
470 | |||
471 | out_kfree: | ||
472 | kfree(output.pointer); | ||
473 | if (status != AE_OK) | ||
474 | context->ret.pointer = NULL; | ||
475 | return status; | ||
476 | } | ||
477 | EXPORT_SYMBOL(acpi_run_osc); | ||
478 | |||
479 | static u8 sb_uuid_str[] = "0811B06E-4A27-44F9-8D60-3CBBC22E7B48"; | ||
480 | static void acpi_bus_osc_support(void) | ||
481 | { | ||
482 | u32 capbuf[2]; | ||
483 | struct acpi_osc_context context = { | ||
484 | .uuid_str = sb_uuid_str, | ||
485 | .rev = 1, | ||
486 | .cap.length = 8, | ||
487 | .cap.pointer = capbuf, | ||
488 | }; | ||
489 | acpi_handle handle; | ||
490 | |||
491 | capbuf[OSC_QUERY_TYPE] = OSC_QUERY_ENABLE; | ||
492 | capbuf[OSC_SUPPORT_TYPE] = OSC_SB_PR3_SUPPORT; /* _PR3 is in use */ | ||
493 | #ifdef CONFIG_ACPI_PROCESSOR_AGGREGATOR | ||
494 | capbuf[OSC_SUPPORT_TYPE] |= OSC_SB_PAD_SUPPORT; | ||
495 | #endif | ||
496 | if (ACPI_FAILURE(acpi_get_handle(NULL, "\\_SB", &handle))) | ||
497 | return; | ||
498 | if (ACPI_SUCCESS(acpi_run_osc(handle, &context))) | ||
499 | kfree(context.ret.pointer); | ||
500 | /* do we need to check the returned cap? Sounds no */ | ||
501 | } | ||
502 | |||
347 | /* -------------------------------------------------------------------------- | 503 | /* -------------------------------------------------------------------------- |
348 | Event Management | 504 | Event Management |
349 | -------------------------------------------------------------------------- */ | 505 | -------------------------------------------------------------------------- */ |
@@ -734,12 +890,16 @@ static int __init acpi_bus_init(void) | |||
734 | status = acpi_ec_ecdt_probe(); | 890 | status = acpi_ec_ecdt_probe(); |
735 | /* Ignore result. Not having an ECDT is not fatal. */ | 891 | /* Ignore result. Not having an ECDT is not fatal. */ |
736 | 892 | ||
893 | acpi_bus_osc_support(); | ||
894 | |||
737 | status = acpi_initialize_objects(ACPI_FULL_INITIALIZATION); | 895 | status = acpi_initialize_objects(ACPI_FULL_INITIALIZATION); |
738 | if (ACPI_FAILURE(status)) { | 896 | if (ACPI_FAILURE(status)) { |
739 | printk(KERN_ERR PREFIX "Unable to initialize ACPI objects\n"); | 897 | printk(KERN_ERR PREFIX "Unable to initialize ACPI objects\n"); |
740 | goto error1; | 898 | goto error1; |
741 | } | 899 | } |
742 | 900 | ||
901 | acpi_early_processor_set_pdc(); | ||
902 | |||
743 | /* | 903 | /* |
744 | * Maybe EC region is required at bus_scan/acpi_get_devices. So it | 904 | * Maybe EC region is required at bus_scan/acpi_get_devices. So it |
745 | * is necessary to enable it as early as possible. | 905 | * is necessary to enable it as early as possible. |