aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/acpi/pci_root.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/acpi/pci_root.c')
-rw-r--r--drivers/acpi/pci_root.c101
1 files changed, 39 insertions, 62 deletions
diff --git a/drivers/acpi/pci_root.c b/drivers/acpi/pci_root.c
index 1dd6f6c85874..122b4dc7b0fa 100644
--- a/drivers/acpi/pci_root.c
+++ b/drivers/acpi/pci_root.c
@@ -65,10 +65,6 @@ static struct acpi_scan_handler pci_root_handler = {
65 .detach = acpi_pci_root_remove, 65 .detach = acpi_pci_root_remove,
66}; 66};
67 67
68/* Lock to protect both acpi_pci_roots lists */
69static DEFINE_MUTEX(acpi_pci_root_lock);
70static LIST_HEAD(acpi_pci_roots);
71
72static DEFINE_MUTEX(osc_lock); 68static DEFINE_MUTEX(osc_lock);
73 69
74/** 70/**
@@ -100,13 +96,12 @@ get_root_bridge_busnr_callback(struct acpi_resource *resource, void *data)
100{ 96{
101 struct resource *res = data; 97 struct resource *res = data;
102 struct acpi_resource_address64 address; 98 struct acpi_resource_address64 address;
99 acpi_status status;
103 100
104 if (resource->type != ACPI_RESOURCE_TYPE_ADDRESS16 && 101 status = acpi_resource_to_address64(resource, &address);
105 resource->type != ACPI_RESOURCE_TYPE_ADDRESS32 && 102 if (ACPI_FAILURE(status))
106 resource->type != ACPI_RESOURCE_TYPE_ADDRESS64)
107 return AE_OK; 103 return AE_OK;
108 104
109 acpi_resource_to_address64(resource, &address);
110 if ((address.address_length > 0) && 105 if ((address.address_length > 0) &&
111 (address.resource_type == ACPI_BUS_NUMBER_RANGE)) { 106 (address.resource_type == ACPI_BUS_NUMBER_RANGE)) {
112 res->start = address.minimum; 107 res->start = address.minimum;
@@ -382,23 +377,24 @@ static int acpi_pci_root_add(struct acpi_device *device,
382 int result; 377 int result;
383 struct acpi_pci_root *root; 378 struct acpi_pci_root *root;
384 u32 flags, base_flags; 379 u32 flags, base_flags;
380 acpi_handle handle = device->handle;
385 381
386 root = kzalloc(sizeof(struct acpi_pci_root), GFP_KERNEL); 382 root = kzalloc(sizeof(struct acpi_pci_root), GFP_KERNEL);
387 if (!root) 383 if (!root)
388 return -ENOMEM; 384 return -ENOMEM;
389 385
390 segment = 0; 386 segment = 0;
391 status = acpi_evaluate_integer(device->handle, METHOD_NAME__SEG, NULL, 387 status = acpi_evaluate_integer(handle, METHOD_NAME__SEG, NULL,
392 &segment); 388 &segment);
393 if (ACPI_FAILURE(status) && status != AE_NOT_FOUND) { 389 if (ACPI_FAILURE(status) && status != AE_NOT_FOUND) {
394 printk(KERN_ERR PREFIX "can't evaluate _SEG\n"); 390 dev_err(&device->dev, "can't evaluate _SEG\n");
395 result = -ENODEV; 391 result = -ENODEV;
396 goto end; 392 goto end;
397 } 393 }
398 394
399 /* Check _CRS first, then _BBN. If no _BBN, default to zero. */ 395 /* Check _CRS first, then _BBN. If no _BBN, default to zero. */
400 root->secondary.flags = IORESOURCE_BUS; 396 root->secondary.flags = IORESOURCE_BUS;
401 status = try_get_root_bridge_busnr(device->handle, &root->secondary); 397 status = try_get_root_bridge_busnr(handle, &root->secondary);
402 if (ACPI_FAILURE(status)) { 398 if (ACPI_FAILURE(status)) {
403 /* 399 /*
404 * We need both the start and end of the downstream bus range 400 * We need both the start and end of the downstream bus range
@@ -407,33 +403,32 @@ static int acpi_pci_root_add(struct acpi_device *device,
407 * can do is assume [_BBN-0xFF] or [0-0xFF]. 403 * can do is assume [_BBN-0xFF] or [0-0xFF].
408 */ 404 */
409 root->secondary.end = 0xFF; 405 root->secondary.end = 0xFF;
410 printk(KERN_WARNING FW_BUG PREFIX 406 dev_warn(&device->dev,
411 "no secondary bus range in _CRS\n"); 407 FW_BUG "no secondary bus range in _CRS\n");
412 status = acpi_evaluate_integer(device->handle, METHOD_NAME__BBN, 408 status = acpi_evaluate_integer(handle, METHOD_NAME__BBN,
413 NULL, &bus); 409 NULL, &bus);
414 if (ACPI_SUCCESS(status)) 410 if (ACPI_SUCCESS(status))
415 root->secondary.start = bus; 411 root->secondary.start = bus;
416 else if (status == AE_NOT_FOUND) 412 else if (status == AE_NOT_FOUND)
417 root->secondary.start = 0; 413 root->secondary.start = 0;
418 else { 414 else {
419 printk(KERN_ERR PREFIX "can't evaluate _BBN\n"); 415 dev_err(&device->dev, "can't evaluate _BBN\n");
420 result = -ENODEV; 416 result = -ENODEV;
421 goto end; 417 goto end;
422 } 418 }
423 } 419 }
424 420
425 INIT_LIST_HEAD(&root->node);
426 root->device = device; 421 root->device = device;
427 root->segment = segment & 0xFFFF; 422 root->segment = segment & 0xFFFF;
428 strcpy(acpi_device_name(device), ACPI_PCI_ROOT_DEVICE_NAME); 423 strcpy(acpi_device_name(device), ACPI_PCI_ROOT_DEVICE_NAME);
429 strcpy(acpi_device_class(device), ACPI_PCI_ROOT_CLASS); 424 strcpy(acpi_device_class(device), ACPI_PCI_ROOT_CLASS);
430 device->driver_data = root; 425 device->driver_data = root;
431 426
432 printk(KERN_INFO PREFIX "%s [%s] (domain %04x %pR)\n", 427 pr_info(PREFIX "%s [%s] (domain %04x %pR)\n",
433 acpi_device_name(device), acpi_device_bid(device), 428 acpi_device_name(device), acpi_device_bid(device),
434 root->segment, &root->secondary); 429 root->segment, &root->secondary);
435 430
436 root->mcfg_addr = acpi_pci_root_get_mcfg_addr(device->handle); 431 root->mcfg_addr = acpi_pci_root_get_mcfg_addr(handle);
437 432
438 /* 433 /*
439 * All supported architectures that use ACPI have support for 434 * All supported architectures that use ACPI have support for
@@ -446,10 +441,6 @@ static int acpi_pci_root_add(struct acpi_device *device,
446 * TBD: Need PCI interface for enumeration/configuration of roots. 441 * TBD: Need PCI interface for enumeration/configuration of roots.
447 */ 442 */
448 443
449 mutex_lock(&acpi_pci_root_lock);
450 list_add_tail(&root->node, &acpi_pci_roots);
451 mutex_unlock(&acpi_pci_root_lock);
452
453 /* 444 /*
454 * Scan the Root Bridge 445 * Scan the Root Bridge
455 * -------------------- 446 * --------------------
@@ -459,11 +450,11 @@ static int acpi_pci_root_add(struct acpi_device *device,
459 */ 450 */
460 root->bus = pci_acpi_scan_root(root); 451 root->bus = pci_acpi_scan_root(root);
461 if (!root->bus) { 452 if (!root->bus) {
462 printk(KERN_ERR PREFIX 453 dev_err(&device->dev,
463 "Bus %04x:%02x not present in PCI namespace\n", 454 "Bus %04x:%02x not present in PCI namespace\n",
464 root->segment, (unsigned int)root->secondary.start); 455 root->segment, (unsigned int)root->secondary.start);
465 result = -ENODEV; 456 result = -ENODEV;
466 goto out_del_root; 457 goto end;
467 } 458 }
468 459
469 /* Indicate support for various _OSC capabilities. */ 460 /* Indicate support for various _OSC capabilities. */
@@ -502,7 +493,7 @@ static int acpi_pci_root_add(struct acpi_device *device,
502 dev_info(&device->dev, 493 dev_info(&device->dev,
503 "Requesting ACPI _OSC control (0x%02x)\n", flags); 494 "Requesting ACPI _OSC control (0x%02x)\n", flags);
504 495
505 status = acpi_pci_osc_control_set(device->handle, &flags, 496 status = acpi_pci_osc_control_set(handle, &flags,
506 OSC_PCI_EXPRESS_CAP_STRUCTURE_CONTROL); 497 OSC_PCI_EXPRESS_CAP_STRUCTURE_CONTROL);
507 if (ACPI_SUCCESS(status)) { 498 if (ACPI_SUCCESS(status)) {
508 dev_info(&device->dev, 499 dev_info(&device->dev,
@@ -519,8 +510,8 @@ static int acpi_pci_root_add(struct acpi_device *device,
519 "ACPI _OSC request failed (%s), " 510 "ACPI _OSC request failed (%s), "
520 "returned control mask: 0x%02x\n", 511 "returned control mask: 0x%02x\n",
521 acpi_format_exception(status), flags); 512 acpi_format_exception(status), flags);
522 pr_info("ACPI _OSC control for PCIe not granted, " 513 dev_info(&device->dev,
523 "disabling ASPM\n"); 514 "ACPI _OSC control for PCIe not granted, disabling ASPM\n");
524 pcie_no_aspm(); 515 pcie_no_aspm();
525 } 516 }
526 } else { 517 } else {
@@ -536,20 +527,14 @@ static int acpi_pci_root_add(struct acpi_device *device,
536 if (system_state != SYSTEM_BOOTING) { 527 if (system_state != SYSTEM_BOOTING) {
537 pcibios_resource_survey_bus(root->bus); 528 pcibios_resource_survey_bus(root->bus);
538 pci_assign_unassigned_bus_resources(root->bus); 529 pci_assign_unassigned_bus_resources(root->bus);
539 }
540 530
541 /* need to after hot-added ioapic is registered */ 531 /* need to after hot-added ioapic is registered */
542 if (system_state != SYSTEM_BOOTING)
543 pci_enable_bridges(root->bus); 532 pci_enable_bridges(root->bus);
533 }
544 534
545 pci_bus_add_devices(root->bus); 535 pci_bus_add_devices(root->bus);
546 return 1; 536 return 1;
547 537
548out_del_root:
549 mutex_lock(&acpi_pci_root_lock);
550 list_del(&root->node);
551 mutex_unlock(&acpi_pci_root_lock);
552
553end: 538end:
554 kfree(root); 539 kfree(root);
555 return result; 540 return result;
@@ -566,9 +551,6 @@ static void acpi_pci_root_remove(struct acpi_device *device)
566 551
567 pci_remove_root_bus(root->bus); 552 pci_remove_root_bus(root->bus);
568 553
569 mutex_lock(&acpi_pci_root_lock);
570 list_del(&root->node);
571 mutex_unlock(&acpi_pci_root_lock);
572 kfree(root); 554 kfree(root);
573} 555}
574 556
@@ -588,12 +570,13 @@ static void handle_root_bridge_insertion(acpi_handle handle)
588 struct acpi_device *device; 570 struct acpi_device *device;
589 571
590 if (!acpi_bus_get_device(handle, &device)) { 572 if (!acpi_bus_get_device(handle, &device)) {
591 printk(KERN_DEBUG "acpi device exists...\n"); 573 dev_printk(KERN_DEBUG, &device->dev,
574 "acpi device already exists; ignoring notify\n");
592 return; 575 return;
593 } 576 }
594 577
595 if (acpi_bus_scan(handle)) 578 if (acpi_bus_scan(handle))
596 printk(KERN_ERR "cannot add bridge to acpi list\n"); 579 acpi_handle_err(handle, "cannot add bridge to acpi list\n");
597} 580}
598 581
599static void handle_root_bridge_removal(struct acpi_device *device) 582static void handle_root_bridge_removal(struct acpi_device *device)
@@ -622,7 +605,6 @@ static void handle_root_bridge_removal(struct acpi_device *device)
622static void _handle_hotplug_event_root(struct work_struct *work) 605static void _handle_hotplug_event_root(struct work_struct *work)
623{ 606{
624 struct acpi_pci_root *root; 607 struct acpi_pci_root *root;
625 struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER };
626 struct acpi_hp_work *hp_work; 608 struct acpi_hp_work *hp_work;
627 acpi_handle handle; 609 acpi_handle handle;
628 u32 type; 610 u32 type;
@@ -634,13 +616,12 @@ static void _handle_hotplug_event_root(struct work_struct *work)
634 acpi_scan_lock_acquire(); 616 acpi_scan_lock_acquire();
635 617
636 root = acpi_pci_find_root(handle); 618 root = acpi_pci_find_root(handle);
637 acpi_get_name(handle, ACPI_FULL_PATHNAME, &buffer);
638 619
639 switch (type) { 620 switch (type) {
640 case ACPI_NOTIFY_BUS_CHECK: 621 case ACPI_NOTIFY_BUS_CHECK:
641 /* bus enumerate */ 622 /* bus enumerate */
642 printk(KERN_DEBUG "%s: Bus check notify on %s\n", __func__, 623 acpi_handle_printk(KERN_DEBUG, handle,
643 (char *)buffer.pointer); 624 "Bus check notify on %s\n", __func__);
644 if (!root) 625 if (!root)
645 handle_root_bridge_insertion(handle); 626 handle_root_bridge_insertion(handle);
646 627
@@ -648,28 +629,28 @@ static void _handle_hotplug_event_root(struct work_struct *work)
648 629
649 case ACPI_NOTIFY_DEVICE_CHECK: 630 case ACPI_NOTIFY_DEVICE_CHECK:
650 /* device check */ 631 /* device check */
651 printk(KERN_DEBUG "%s: Device check notify on %s\n", __func__, 632 acpi_handle_printk(KERN_DEBUG, handle,
652 (char *)buffer.pointer); 633 "Device check notify on %s\n", __func__);
653 if (!root) 634 if (!root)
654 handle_root_bridge_insertion(handle); 635 handle_root_bridge_insertion(handle);
655 break; 636 break;
656 637
657 case ACPI_NOTIFY_EJECT_REQUEST: 638 case ACPI_NOTIFY_EJECT_REQUEST:
658 /* request device eject */ 639 /* request device eject */
659 printk(KERN_DEBUG "%s: Device eject notify on %s\n", __func__, 640 acpi_handle_printk(KERN_DEBUG, handle,
660 (char *)buffer.pointer); 641 "Device eject notify on %s\n", __func__);
661 if (root) 642 if (root)
662 handle_root_bridge_removal(root->device); 643 handle_root_bridge_removal(root->device);
663 break; 644 break;
664 default: 645 default:
665 printk(KERN_WARNING "notify_handler: unknown event type 0x%x for %s\n", 646 acpi_handle_warn(handle,
666 type, (char *)buffer.pointer); 647 "notify_handler: unknown event type 0x%x\n",
648 type);
667 break; 649 break;
668 } 650 }
669 651
670 acpi_scan_lock_release(); 652 acpi_scan_lock_release();
671 kfree(hp_work); /* allocated in handle_hotplug_event_bridge */ 653 kfree(hp_work); /* allocated in handle_hotplug_event_bridge */
672 kfree(buffer.pointer);
673} 654}
674 655
675static void handle_hotplug_event_root(acpi_handle handle, u32 type, 656static void handle_hotplug_event_root(acpi_handle handle, u32 type,
@@ -683,9 +664,6 @@ static acpi_status __init
683find_root_bridges(acpi_handle handle, u32 lvl, void *context, void **rv) 664find_root_bridges(acpi_handle handle, u32 lvl, void *context, void **rv)
684{ 665{
685 acpi_status status; 666 acpi_status status;
686 char objname[64];
687 struct acpi_buffer buffer = { .length = sizeof(objname),
688 .pointer = objname };
689 int *count = (int *)context; 667 int *count = (int *)context;
690 668
691 if (!acpi_is_root_bridge(handle)) 669 if (!acpi_is_root_bridge(handle))
@@ -693,16 +671,15 @@ find_root_bridges(acpi_handle handle, u32 lvl, void *context, void **rv)
693 671
694 (*count)++; 672 (*count)++;
695 673
696 acpi_get_name(handle, ACPI_FULL_PATHNAME, &buffer);
697
698 status = acpi_install_notify_handler(handle, ACPI_SYSTEM_NOTIFY, 674 status = acpi_install_notify_handler(handle, ACPI_SYSTEM_NOTIFY,
699 handle_hotplug_event_root, NULL); 675 handle_hotplug_event_root, NULL);
700 if (ACPI_FAILURE(status)) 676 if (ACPI_FAILURE(status))
701 printk(KERN_DEBUG "acpi root: %s notify handler is not installed, exit status: %u\n", 677 acpi_handle_printk(KERN_DEBUG, handle,
702 objname, (unsigned int)status); 678 "notify handler is not installed, exit status: %u\n",
679 (unsigned int)status);
703 else 680 else
704 printk(KERN_DEBUG "acpi root: %s notify handler is installed\n", 681 acpi_handle_printk(KERN_DEBUG, handle,
705 objname); 682 "notify handler is installed\n");
706 683
707 return AE_OK; 684 return AE_OK;
708} 685}