1 /* 2 * acpi_bus.c - ACPI Bus Driver ($Revision: 80 $) 3 * 4 * Copyright (C) 2001, 2002 Paul Diefenbaugh <paul.s.diefenbaugh@intel.com> 5 * 6 * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 7 * 8 * This program is free software; you can redistribute it and/or modify 9 * it under the terms of the GNU General Public License as published by 10 * the Free Software Foundation; either version 2 of the License, or (at 11 * your option) any later version. 12 * 13 * This program is distributed in the hope that it will be useful, but 14 * WITHOUT ANY WARRANTY; without even the implied warranty of 15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 16 * General Public License for more details. 17 * 18 * You should have received a copy of the GNU General Public License along 19 * with this program; if not, write to the Free Software Foundation, Inc., 20 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. 21 * 22 * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 23 */ 24 25 #include <linux/module.h> 26 #include <linux/init.h> 27 #include <linux/ioport.h> 28 #include <linux/kernel.h> 29 #include <linux/list.h> 30 #include <linux/sched.h> 31 #include <linux/pm.h> 32 #include <linux/device.h> 33 #include <linux/proc_fs.h> 34 #include <linux/acpi.h> 35 #ifdef CONFIG_X86 36 #include <asm/mpspec.h> 37 #endif 38 #include <linux/pci.h> 39 #include <acpi/acpi_bus.h> 40 #include <acpi/acpi_drivers.h> 41 #include <linux/dmi.h> 42 43 #include "internal.h" 44 45 #define _COMPONENT ACPI_BUS_COMPONENT 46 ACPI_MODULE_NAME("bus"); 47 48 struct acpi_device *acpi_root; 49 struct proc_dir_entry *acpi_root_dir; 50 EXPORT_SYMBOL(acpi_root_dir); 51 52 #define STRUCT_TO_INT(s) (*((int*)&s)) 53 54 static int set_power_nocheck(const struct dmi_system_id *id) 55 { 56 printk(KERN_NOTICE PREFIX "%s detected - " 57 "disable power check in power transistion\n", id->ident); 58 acpi_power_nocheck = 1; 59 return 0; 60 } 61 static struct dmi_system_id __cpuinitdata power_nocheck_dmi_table[] = { 62 { 63 set_power_nocheck, "HP Pavilion 05", { 64 DMI_MATCH(DMI_BIOS_VENDOR, "Phoenix Technologies LTD"), 65 DMI_MATCH(DMI_SYS_VENDOR, "HP Pavilion 05"), 66 DMI_MATCH(DMI_PRODUCT_VERSION, "2001211RE101GLEND") }, NULL}, 67 {}, 68 }; 69 70 71 /* -------------------------------------------------------------------------- 72 Device Management 73 -------------------------------------------------------------------------- */ 74 75 int acpi_bus_get_device(acpi_handle handle, struct acpi_device **device) 76 { 77 acpi_status status = AE_OK; 78 79 80 if (!device) 81 return -EINVAL; 82 83 /* TBD: Support fixed-feature devices */ 84 85 status = acpi_get_data(handle, acpi_bus_data_handler, (void **)device); 86 if (ACPI_FAILURE(status) || !*device) { 87 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "No context for object [%p]\n", 88 handle)); 89 return -ENODEV; 90 } 91 92 return 0; 93 } 94 95 EXPORT_SYMBOL(acpi_bus_get_device); 96 97 acpi_status acpi_bus_get_status_handle(acpi_handle handle, 98 unsigned long long *sta) 99 { 100 acpi_status status; 101 102 status = acpi_evaluate_integer(handle, "_STA", NULL, sta); 103 if (ACPI_SUCCESS(status)) 104 return AE_OK; 105 106 if (status == AE_NOT_FOUND) { 107 *sta = ACPI_STA_DEVICE_PRESENT | ACPI_STA_DEVICE_ENABLED | 108 ACPI_STA_DEVICE_UI | ACPI_STA_DEVICE_FUNCTIONING; 109 return AE_OK; 110 } 111 return status; 112 } 113 114 int acpi_bus_get_status(struct acpi_device *device) 115 { 116 acpi_status status; 117 unsigned long long sta; 118 119 status = acpi_bus_get_status_handle(device->handle, &sta); 120 if (ACPI_FAILURE(status)) 121 return -ENODEV; 122 123 STRUCT_TO_INT(device->status) = (int) sta; 124 125 if (device->status.functional && !device->status.present) { 126 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Device [%s] status [%08x]: " 127 "functional but not present;\n", 128 device->pnp.bus_id, 129 (u32) STRUCT_TO_INT(device->status))); 130 } 131 132 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Device [%s] status [%08x]\n", 133 device->pnp.bus_id, 134 (u32) STRUCT_TO_INT(device->status))); 135 return 0; 136 } 137 EXPORT_SYMBOL(acpi_bus_get_status); 138 139 void acpi_bus_private_data_handler(acpi_handle handle, 140 void *context) 141 { 142 return; 143 } 144 EXPORT_SYMBOL(acpi_bus_private_data_handler); 145 146 int acpi_bus_get_private_data(acpi_handle handle, void **data) 147 { 148 acpi_status status = AE_OK; 149 150 if (!*data) 151 return -EINVAL; 152 153 status = acpi_get_data(handle, acpi_bus_private_data_handler, data); 154 if (ACPI_FAILURE(status) || !*data) { 155 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "No context for object [%p]\n", 156 handle)); 157 return -ENODEV; 158 } 159 160 return 0; 161 } 162 EXPORT_SYMBOL(acpi_bus_get_private_data); 163 164 /* -------------------------------------------------------------------------- 165 Power Management 166 -------------------------------------------------------------------------- */ 167 168 int acpi_bus_get_power(acpi_handle handle, int *state) 169 { 170 int result = 0; 171 acpi_status status = 0; 172 struct acpi_device *device = NULL; 173 unsigned long long psc = 0; 174 175 176 result = acpi_bus_get_device(handle, &device); 177 if (result) 178 return result; 179 180 *state = ACPI_STATE_UNKNOWN; 181 182 if (!device->flags.power_manageable) { 183 /* TBD: Non-recursive algorithm for walking up hierarchy */ 184 if (device->parent) 185 *state = device->parent->power.state; 186 else 187 *state = ACPI_STATE_D0; 188 } else { 189 /* 190 * Get the device's power state either directly (via _PSC) or 191 * indirectly (via power resources). 192 */ 193 if (device->power.flags.explicit_get) { 194 status = acpi_evaluate_integer(device->handle, "_PSC", 195 NULL, &psc); 196 if (ACPI_FAILURE(status)) 197 return -ENODEV; 198 device->power.state = (int)psc; 199 } else if (device->power.flags.power_resources) { 200 result = acpi_power_get_inferred_state(device); 201 if (result) 202 return result; 203 } 204 205 *state = device->power.state; 206 } 207 208 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Device [%s] power state is D%d\n", 209 device->pnp.bus_id, device->power.state)); 210 211 return 0; 212 } 213 214 EXPORT_SYMBOL(acpi_bus_get_power); 215 216 int acpi_bus_set_power(acpi_handle handle, int state) 217 { 218 int result = 0; 219 acpi_status status = AE_OK; 220 struct acpi_device *device = NULL; 221 char object_name[5] = { '_', 'P', 'S', '0' + state, '\0' }; 222 223 224 result = acpi_bus_get_device(handle, &device); 225 if (result) 226 return result; 227 228 if ((state < ACPI_STATE_D0) || (state > ACPI_STATE_D3)) 229 return -EINVAL; 230 231 /* Make sure this is a valid target state */ 232 233 if (!device->flags.power_manageable) { 234 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Device `[%s]' is not power manageable\n", 235 kobject_name(&device->dev.kobj))); 236 return -ENODEV; 237 } 238 /* 239 * Get device's current power state 240 */ 241 if (!acpi_power_nocheck) { 242 /* 243 * Maybe the incorrect power state is returned on the bogus 244 * bios, which is different with the real power state. 245 * For example: the bios returns D0 state and the real power 246 * state is D3. OS expects to set the device to D0 state. In 247 * such case if OS uses the power state returned by the BIOS, 248 * the device can't be transisted to the correct power state. 249 * So if the acpi_power_nocheck is set, it is unnecessary to 250 * get the power state by calling acpi_bus_get_power. 251 */ 252 acpi_bus_get_power(device->handle, &device->power.state); 253 } 254 if ((state == device->power.state) && !device->flags.force_power_state) { 255 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Device is already at D%d\n", 256 state)); 257 return 0; 258 } 259 260 if (!device->power.states[state].flags.valid) { 261 printk(KERN_WARNING PREFIX "Device does not support D%d\n", state); 262 return -ENODEV; 263 } 264 if (device->parent && (state < device->parent->power.state)) { 265 printk(KERN_WARNING PREFIX 266 "Cannot set device to a higher-powered" 267 " state than parent\n"); 268 return -ENODEV; 269 } 270 271 /* 272 * Transition Power 273 * ---------------- 274 * On transitions to a high-powered state we first apply power (via 275 * power resources) then evalute _PSx. Conversly for transitions to 276 * a lower-powered state. 277 */ 278 if (state < device->power.state) { 279 if (device->power.flags.power_resources) { 280 result = acpi_power_transition(device, state); 281 if (result) 282 goto end; 283 } 284 if (device->power.states[state].flags.explicit_set) { 285 status = acpi_evaluate_object(device->handle, 286 object_name, NULL, NULL); 287 if (ACPI_FAILURE(status)) { 288 result = -ENODEV; 289 goto end; 290 } 291 } 292 } else { 293 if (device->power.states[state].flags.explicit_set) { 294 status = acpi_evaluate_object(device->handle, 295 object_name, NULL, NULL); 296 if (ACPI_FAILURE(status)) { 297 result = -ENODEV; 298 goto end; 299 } 300 } 301 if (device->power.flags.power_resources) { 302 result = acpi_power_transition(device, state); 303 if (result) 304 goto end; 305 } 306 } 307 308 end: 309 if (result) 310 printk(KERN_WARNING PREFIX 311 "Device [%s] failed to transition to D%d\n", 312 device->pnp.bus_id, state); 313 else { 314 device->power.state = state; 315 ACPI_DEBUG_PRINT((ACPI_DB_INFO, 316 "Device [%s] transitioned to D%d\n", 317 device->pnp.bus_id, state)); 318 } 319 320 return result; 321 } 322 323 EXPORT_SYMBOL(acpi_bus_set_power); 324 325 bool acpi_bus_power_manageable(acpi_handle handle) 326 { 327 struct acpi_device *device; 328 int result; 329 330 result = acpi_bus_get_device(handle, &device); 331 return result ? false : device->flags.power_manageable; 332 } 333 334 EXPORT_SYMBOL(acpi_bus_power_manageable); 335 336 bool acpi_bus_can_wakeup(acpi_handle handle) 337 { 338 struct acpi_device *device; 339 int result; 340 341 result = acpi_bus_get_device(handle, &device); 342 return result ? false : device->wakeup.flags.valid; 343 } 344 345 EXPORT_SYMBOL(acpi_bus_can_wakeup); 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 401 if (!context) 402 return AE_ERROR; 403 if (ACPI_FAILURE(acpi_str_to_uuid(context->uuid_str, uuid))) 404 return AE_ERROR; 405 context->ret.length = ACPI_ALLOCATE_BUFFER; 406 context->ret.pointer = NULL; 407 408 /* Setting up input parameters */ 409 input.count = 4; 410 input.pointer = in_params; 411 in_params[0].type = ACPI_TYPE_BUFFER; 412 in_params[0].buffer.length = 16; 413 in_params[0].buffer.pointer = uuid; 414 in_params[1].type = ACPI_TYPE_INTEGER; 415 in_params[1].integer.value = context->rev; 416 in_params[2].type = ACPI_TYPE_INTEGER; 417 in_params[2].integer.value = context->cap.length/sizeof(u32); 418 in_params[3].type = ACPI_TYPE_BUFFER; 419 in_params[3].buffer.length = context->cap.length; 420 in_params[3].buffer.pointer = context->cap.pointer; 421 422 status = acpi_evaluate_object(handle, "_OSC", &input, &context->ret); 423 if (ACPI_FAILURE(status)) 424 return status; 425 426 /* return buffer should have the same length as cap buffer */ 427 if (context->ret.length != context->cap.length) 428 return AE_NULL_OBJECT; 429 430 out_obj = context->ret.pointer; 431 if (out_obj->type != ACPI_TYPE_BUFFER) { 432 acpi_print_osc_error(handle, context, 433 "_OSC evaluation returned wrong type"); 434 status = AE_TYPE; 435 goto out_kfree; 436 } 437 /* Need to ignore the bit0 in result code */ 438 errors = *((u32 *)out_obj->buffer.pointer) & ~(1 << 0); 439 if (errors) { 440 if (errors & OSC_REQUEST_ERROR) 441 acpi_print_osc_error(handle, context, 442 "_OSC request failed"); 443 if (errors & OSC_INVALID_UUID_ERROR) 444 acpi_print_osc_error(handle, context, 445 "_OSC invalid UUID"); 446 if (errors & OSC_INVALID_REVISION_ERROR) 447 acpi_print_osc_error(handle, context, 448 "_OSC invalid revision"); 449 if (errors & OSC_CAPABILITIES_MASK_ERROR) { 450 if (((u32 *)context->cap.pointer)[OSC_QUERY_TYPE] 451 & OSC_QUERY_ENABLE) 452 goto out_success; 453 status = AE_SUPPORT; 454 goto out_kfree; 455 } 456 status = AE_ERROR; 457 goto out_kfree; 458 } 459 out_success: 460 return AE_OK; 461 462 out_kfree: 463 kfree(context->ret.pointer); 464 context->ret.pointer = NULL; 465 return status; 466 } 467 EXPORT_SYMBOL(acpi_run_osc); 468 469 static u8 sb_uuid_str[] = "0811B06E-4A27-44F9-8D60-3CBBC22E7B48"; 470 static void acpi_bus_osc_support(void) 471 { 472 u32 capbuf[2]; 473 struct acpi_osc_context context = { 474 .uuid_str = sb_uuid_str, 475 .rev = 1, 476 .cap.length = 8, 477 .cap.pointer = capbuf, 478 }; 479 acpi_handle handle; 480 481 capbuf[OSC_QUERY_TYPE] = OSC_QUERY_ENABLE; 482 capbuf[OSC_SUPPORT_TYPE] = OSC_SB_PR3_SUPPORT; /* _PR3 is in use */ 483 #ifdef CONFIG_ACPI_PROCESSOR_AGGREGATOR 484 capbuf[OSC_SUPPORT_TYPE] |= OSC_SB_PAD_SUPPORT; 485 #endif 486 if (ACPI_FAILURE(acpi_get_handle(NULL, "\\_SB", &handle))) 487 return; 488 if (ACPI_SUCCESS(acpi_run_osc(handle, &context))) 489 kfree(context.ret.pointer); 490 /* do we need to check the returned cap? Sounds no */ 491 } 492 493 /* -------------------------------------------------------------------------- 494 Event Management 495 -------------------------------------------------------------------------- */ 496 497 #ifdef CONFIG_ACPI_PROC_EVENT 498 static DEFINE_SPINLOCK(acpi_bus_event_lock); 499 500 LIST_HEAD(acpi_bus_event_list); 501 DECLARE_WAIT_QUEUE_HEAD(acpi_bus_event_queue); 502 503 extern int event_is_open; 504 505 int acpi_bus_generate_proc_event4(const char *device_class, const char *bus_id, u8 type, int data) 506 { 507 struct acpi_bus_event *event; 508 unsigned long flags = 0; 509 510 /* drop event on the floor if no one's listening */ 511 if (!event_is_open) 512 return 0; 513 514 event = kmalloc(sizeof(struct acpi_bus_event), GFP_ATOMIC); 515 if (!event) 516 return -ENOMEM; 517 518 strcpy(event->device_class, device_class); 519 strcpy(event->bus_id, bus_id); 520 event->type = type; 521 event->data = data; 522 523 spin_lock_irqsave(&acpi_bus_event_lock, flags); 524 list_add_tail(&event->node, &acpi_bus_event_list); 525 spin_unlock_irqrestore(&acpi_bus_event_lock, flags); 526 527 wake_up_interruptible(&acpi_bus_event_queue); 528 529 return 0; 530 531 } 532 533 EXPORT_SYMBOL_GPL(acpi_bus_generate_proc_event4); 534 535 int acpi_bus_generate_proc_event(struct acpi_device *device, u8 type, int data) 536 { 537 if (!device) 538 return -EINVAL; 539 return acpi_bus_generate_proc_event4(device->pnp.device_class, 540 device->pnp.bus_id, type, data); 541 } 542 543 EXPORT_SYMBOL(acpi_bus_generate_proc_event); 544 545 int acpi_bus_receive_event(struct acpi_bus_event *event) 546 { 547 unsigned long flags = 0; 548 struct acpi_bus_event *entry = NULL; 549 550 DECLARE_WAITQUEUE(wait, current); 551 552 553 if (!event) 554 return -EINVAL; 555 556 if (list_empty(&acpi_bus_event_list)) { 557 558 set_current_state(TASK_INTERRUPTIBLE); 559 add_wait_queue(&acpi_bus_event_queue, &wait); 560 561 if (list_empty(&acpi_bus_event_list)) 562 schedule(); 563 564 remove_wait_queue(&acpi_bus_event_queue, &wait); 565 set_current_state(TASK_RUNNING); 566 567 if (signal_pending(current)) 568 return -ERESTARTSYS; 569 } 570 571 spin_lock_irqsave(&acpi_bus_event_lock, flags); 572 if (!list_empty(&acpi_bus_event_list)) { 573 entry = list_entry(acpi_bus_event_list.next, 574 struct acpi_bus_event, node); 575 list_del(&entry->node); 576 } 577 spin_unlock_irqrestore(&acpi_bus_event_lock, flags); 578 579 if (!entry) 580 return -ENODEV; 581 582 memcpy(event, entry, sizeof(struct acpi_bus_event)); 583 584 kfree(entry); 585 586 return 0; 587 } 588 589 #endif /* CONFIG_ACPI_PROC_EVENT */ 590 591 /* -------------------------------------------------------------------------- 592 Notification Handling 593 -------------------------------------------------------------------------- */ 594 595 static void acpi_bus_check_device(acpi_handle handle) 596 { 597 struct acpi_device *device; 598 acpi_status status; 599 struct acpi_device_status old_status; 600 601 if (acpi_bus_get_device(handle, &device)) 602 return; 603 if (!device) 604 return; 605 606 old_status = device->status; 607 608 /* 609 * Make sure this device's parent is present before we go about 610 * messing with the device. 611 */ 612 if (device->parent && !device->parent->status.present) { 613 device->status = device->parent->status; 614 return; 615 } 616 617 status = acpi_bus_get_status(device); 618 if (ACPI_FAILURE(status)) 619 return; 620 621 if (STRUCT_TO_INT(old_status) == STRUCT_TO_INT(device->status)) 622 return; 623 624 /* 625 * Device Insertion/Removal 626 */ 627 if ((device->status.present) && !(old_status.present)) { 628 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Device insertion detected\n")); 629 /* TBD: Handle device insertion */ 630 } else if (!(device->status.present) && (old_status.present)) { 631 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Device removal detected\n")); 632 /* TBD: Handle device removal */ 633 } 634 } 635 636 static void acpi_bus_check_scope(acpi_handle handle) 637 { 638 /* Status Change? */ 639 acpi_bus_check_device(handle); 640 641 /* 642 * TBD: Enumerate child devices within this device's scope and 643 * run acpi_bus_check_device()'s on them. 644 */ 645 } 646 647 static BLOCKING_NOTIFIER_HEAD(acpi_bus_notify_list); 648 int register_acpi_bus_notifier(struct notifier_block *nb) 649 { 650 return blocking_notifier_chain_register(&acpi_bus_notify_list, nb); 651 } 652 EXPORT_SYMBOL_GPL(register_acpi_bus_notifier); 653 654 void unregister_acpi_bus_notifier(struct notifier_block *nb) 655 { 656 blocking_notifier_chain_unregister(&acpi_bus_notify_list, nb); 657 } 658 EXPORT_SYMBOL_GPL(unregister_acpi_bus_notifier); 659 660 /** 661 * acpi_bus_notify 662 * --------------- 663 * Callback for all 'system-level' device notifications (values 0x00-0x7F). 664 */ 665 static void acpi_bus_notify(acpi_handle handle, u32 type, void *data) 666 { 667 struct acpi_device *device = NULL; 668 struct acpi_driver *driver; 669 670 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Notification %#02x to handle %p\n", 671 type, handle)); 672 673 blocking_notifier_call_chain(&acpi_bus_notify_list, 674 type, (void *)handle); 675 676 switch (type) { 677 678 case ACPI_NOTIFY_BUS_CHECK: 679 acpi_bus_check_scope(handle); 680 /* 681 * TBD: We'll need to outsource certain events to non-ACPI 682 * drivers via the device manager (device.c). 683 */ 684 break; 685 686 case ACPI_NOTIFY_DEVICE_CHECK: 687 acpi_bus_check_device(handle); 688 /* 689 * TBD: We'll need to outsource certain events to non-ACPI 690 * drivers via the device manager (device.c). 691 */ 692 break; 693 694 case ACPI_NOTIFY_DEVICE_WAKE: 695 /* TBD */ 696 break; 697 698 case ACPI_NOTIFY_EJECT_REQUEST: 699 /* TBD */ 700 break; 701 702 case ACPI_NOTIFY_DEVICE_CHECK_LIGHT: 703 /* TBD: Exactly what does 'light' mean? */ 704 break; 705 706 case ACPI_NOTIFY_FREQUENCY_MISMATCH: 707 /* TBD */ 708 break; 709 710 case ACPI_NOTIFY_BUS_MODE_MISMATCH: 711 /* TBD */ 712 break; 713 714 case ACPI_NOTIFY_POWER_FAULT: 715 /* TBD */ 716 break; 717 718 default: 719 ACPI_DEBUG_PRINT((ACPI_DB_INFO, 720 "Received unknown/unsupported notification [%08x]\n", 721 type)); 722 break; 723 } 724 725 acpi_bus_get_device(handle, &device); 726 if (device) { 727 driver = device->driver; 728 if (driver && driver->ops.notify && 729 (driver->flags & ACPI_DRIVER_ALL_NOTIFY_EVENTS)) 730 driver->ops.notify(device, type); 731 } 732 } 733 734 /* -------------------------------------------------------------------------- 735 Initialization/Cleanup 736 -------------------------------------------------------------------------- */ 737 738 static int __init acpi_bus_init_irq(void) 739 { 740 acpi_status status = AE_OK; 741 union acpi_object arg = { ACPI_TYPE_INTEGER }; 742 struct acpi_object_list arg_list = { 1, &arg }; 743 char *message = NULL; 744 745 746 /* 747 * Let the system know what interrupt model we are using by 748 * evaluating the \_PIC object, if exists. 749 */ 750 751 switch (acpi_irq_model) { 752 case ACPI_IRQ_MODEL_PIC: 753 message = "PIC"; 754 break; 755 case ACPI_IRQ_MODEL_IOAPIC: 756 message = "IOAPIC"; 757 break; 758 case ACPI_IRQ_MODEL_IOSAPIC: 759 message = "IOSAPIC"; 760 break; 761 case ACPI_IRQ_MODEL_PLATFORM: 762 message = "platform specific model"; 763 break; 764 default: 765 printk(KERN_WARNING PREFIX "Unknown interrupt routing model\n"); 766 return -ENODEV; 767 } 768 769 printk(KERN_INFO PREFIX "Using %s for interrupt routing\n", message); 770 771 arg.integer.value = acpi_irq_model; 772 773 status = acpi_evaluate_object(NULL, "\\_PIC", &arg_list, NULL); 774 if (ACPI_FAILURE(status) && (status != AE_NOT_FOUND)) { 775 ACPI_EXCEPTION((AE_INFO, status, "Evaluating _PIC")); 776 return -ENODEV; 777 } 778 779 return 0; 780 } 781 782 u8 acpi_gbl_permanent_mmap; 783 784 785 void __init acpi_early_init(void) 786 { 787 acpi_status status = AE_OK; 788 789 if (acpi_disabled) 790 return; 791 792 printk(KERN_INFO PREFIX "Core revision %08x\n", ACPI_CA_VERSION); 793 794 /* enable workarounds, unless strict ACPI spec. compliance */ 795 if (!acpi_strict) 796 acpi_gbl_enable_interpreter_slack = TRUE; 797 798 acpi_gbl_permanent_mmap = 1; 799 800 status = acpi_reallocate_root_table(); 801 if (ACPI_FAILURE(status)) { 802 printk(KERN_ERR PREFIX 803 "Unable to reallocate ACPI tables\n"); 804 goto error0; 805 } 806 807 status = acpi_initialize_subsystem(); 808 if (ACPI_FAILURE(status)) { 809 printk(KERN_ERR PREFIX 810 "Unable to initialize the ACPI Interpreter\n"); 811 goto error0; 812 } 813 814 status = acpi_load_tables(); 815 if (ACPI_FAILURE(status)) { 816 printk(KERN_ERR PREFIX 817 "Unable to load the System Description Tables\n"); 818 goto error0; 819 } 820 821 #ifdef CONFIG_X86 822 if (!acpi_ioapic) { 823 /* compatible (0) means level (3) */ 824 if (!(acpi_sci_flags & ACPI_MADT_TRIGGER_MASK)) { 825 acpi_sci_flags &= ~ACPI_MADT_TRIGGER_MASK; 826 acpi_sci_flags |= ACPI_MADT_TRIGGER_LEVEL; 827 } 828 /* Set PIC-mode SCI trigger type */ 829 acpi_pic_sci_set_trigger(acpi_gbl_FADT.sci_interrupt, 830 (acpi_sci_flags & ACPI_MADT_TRIGGER_MASK) >> 2); 831 } else { 832 /* 833 * now that acpi_gbl_FADT is initialized, 834 * update it with result from INT_SRC_OVR parsing 835 */ 836 acpi_gbl_FADT.sci_interrupt = acpi_sci_override_gsi; 837 } 838 #endif 839 840 status = 841 acpi_enable_subsystem(~ 842 (ACPI_NO_HARDWARE_INIT | 843 ACPI_NO_ACPI_ENABLE)); 844 if (ACPI_FAILURE(status)) { 845 printk(KERN_ERR PREFIX "Unable to enable ACPI\n"); 846 goto error0; 847 } 848 849 return; 850 851 error0: 852 disable_acpi(); 853 return; 854 } 855 856 static int __init acpi_bus_init(void) 857 { 858 int result = 0; 859 acpi_status status = AE_OK; 860 extern acpi_status acpi_os_initialize1(void); 861 862 acpi_os_initialize1(); 863 864 status = 865 acpi_enable_subsystem(ACPI_NO_HARDWARE_INIT | ACPI_NO_ACPI_ENABLE); 866 if (ACPI_FAILURE(status)) { 867 printk(KERN_ERR PREFIX 868 "Unable to start the ACPI Interpreter\n"); 869 goto error1; 870 } 871 872 /* 873 * ACPI 2.0 requires the EC driver to be loaded and work before 874 * the EC device is found in the namespace (i.e. before acpi_initialize_objects() 875 * is called). 876 * 877 * This is accomplished by looking for the ECDT table, and getting 878 * the EC parameters out of that. 879 */ 880 status = acpi_ec_ecdt_probe(); 881 /* Ignore result. Not having an ECDT is not fatal. */ 882 883 acpi_bus_osc_support(); 884 885 status = acpi_initialize_objects(ACPI_FULL_INITIALIZATION); 886 if (ACPI_FAILURE(status)) { 887 printk(KERN_ERR PREFIX "Unable to initialize ACPI objects\n"); 888 goto error1; 889 } 890 891 /* 892 * Maybe EC region is required at bus_scan/acpi_get_devices. So it 893 * is necessary to enable it as early as possible. 894 */ 895 acpi_boot_ec_enable(); 896 897 printk(KERN_INFO PREFIX "Interpreter enabled\n"); 898 899 /* Initialize sleep structures */ 900 acpi_sleep_init(); 901 902 /* 903 * Get the system interrupt model and evaluate \_PIC. 904 */ 905 result = acpi_bus_init_irq(); 906 if (result) 907 goto error1; 908 909 /* 910 * Register the for all standard device notifications. 911 */ 912 status = 913 acpi_install_notify_handler(ACPI_ROOT_OBJECT, ACPI_SYSTEM_NOTIFY, 914 &acpi_bus_notify, NULL); 915 if (ACPI_FAILURE(status)) { 916 printk(KERN_ERR PREFIX 917 "Unable to register for device notifications\n"); 918 goto error1; 919 } 920 921 /* 922 * Create the top ACPI proc directory 923 */ 924 acpi_root_dir = proc_mkdir(ACPI_BUS_FILE_ROOT, NULL); 925 926 return 0; 927 928 /* Mimic structured exception handling */ 929 error1: 930 acpi_terminate(); 931 return -ENODEV; 932 } 933 934 struct kobject *acpi_kobj; 935 936 static int __init acpi_init(void) 937 { 938 int result = 0; 939 940 941 if (acpi_disabled) { 942 printk(KERN_INFO PREFIX "Interpreter disabled.\n"); 943 return -ENODEV; 944 } 945 946 acpi_kobj = kobject_create_and_add("acpi", firmware_kobj); 947 if (!acpi_kobj) { 948 printk(KERN_WARNING "%s: kset create error\n", __func__); 949 acpi_kobj = NULL; 950 } 951 952 init_acpi_device_notify(); 953 result = acpi_bus_init(); 954 955 if (!result) { 956 pci_mmcfg_late_init(); 957 if (!(pm_flags & PM_APM)) 958 pm_flags |= PM_ACPI; 959 else { 960 printk(KERN_INFO PREFIX 961 "APM is already active, exiting\n"); 962 disable_acpi(); 963 result = -ENODEV; 964 } 965 } else 966 disable_acpi(); 967 968 if (acpi_disabled) 969 return result; 970 971 /* 972 * If the laptop falls into the DMI check table, the power state check 973 * will be disabled in the course of device power transistion. 974 */ 975 dmi_check_system(power_nocheck_dmi_table); 976 977 acpi_scan_init(); 978 acpi_ec_init(); 979 acpi_power_init(); 980 acpi_system_init(); 981 acpi_debug_init(); 982 acpi_sleep_proc_init(); 983 acpi_wakeup_device_init(); 984 return result; 985 } 986 987 subsys_initcall(acpi_init); 988