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