aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/pci
diff options
context:
space:
mode:
authorAlex Chiang <achiang@hp.com>2009-03-31 11:23:46 -0400
committerJesse Barnes <jbarnes@virtuousgeek.org>2009-06-11 15:04:12 -0400
commitde86ae16d55a23315cdf1dae68df9de55312cf25 (patch)
tree740a8a9134c201c628750c70266d318b05bd4bde /drivers/pci
parent1d3ecf1376bf22be57c6138e7cdf425c6027b115 (diff)
PCI Hotplug: cpqphp: refactor cpqphp_save_slot_config
Check for an empty slot, and return early if so. This allows us to un-indent the rest of the function by one level. Signed-off-by: Alex Chiang <achiang@hp.com> Signed-off-by: Jesse Barnes <jbarnes@virtuousgeek.org>
Diffstat (limited to 'drivers/pci')
-rw-r--r--drivers/pci/hotplug/cpqphp_pci.c85
1 files changed, 39 insertions, 46 deletions
diff --git a/drivers/pci/hotplug/cpqphp_pci.c b/drivers/pci/hotplug/cpqphp_pci.c
index 2e96bae3c82a..1f1c90dd791d 100644
--- a/drivers/pci/hotplug/cpqphp_pci.c
+++ b/drivers/pci/hotplug/cpqphp_pci.c
@@ -494,7 +494,7 @@ int cpqhp_save_slot_config (struct controller *ctrl, struct pci_func * new_slot)
494 u8 secondary_bus; 494 u8 secondary_bus;
495 int sub_bus; 495 int sub_bus;
496 int max_functions; 496 int max_functions;
497 int function; 497 int function = 0;
498 int cloop = 0; 498 int cloop = 0;
499 int stop_it; 499 int stop_it;
500 500
@@ -503,65 +503,58 @@ int cpqhp_save_slot_config (struct controller *ctrl, struct pci_func * new_slot)
503 ctrl->pci_bus->number = new_slot->bus; 503 ctrl->pci_bus->number = new_slot->bus;
504 pci_bus_read_config_dword (ctrl->pci_bus, PCI_DEVFN(new_slot->device, 0), PCI_VENDOR_ID, &ID); 504 pci_bus_read_config_dword (ctrl->pci_bus, PCI_DEVFN(new_slot->device, 0), PCI_VENDOR_ID, &ID);
505 505
506 if (ID != 0xFFFFFFFF) { /* device in slot */ 506 if (ID == 0xFFFFFFFF)
507 pci_bus_read_config_byte (ctrl->pci_bus, PCI_DEVFN(new_slot->device, 0), 0x0B, &class_code); 507 return 2;
508 pci_bus_read_config_byte (ctrl->pci_bus, PCI_DEVFN(new_slot->device, 0), PCI_HEADER_TYPE, &header_type);
509
510 if (header_type & 0x80) /* Multi-function device */
511 max_functions = 8;
512 else
513 max_functions = 1;
514
515 function = 0;
516 508
517 do { 509 pci_bus_read_config_byte(ctrl->pci_bus, PCI_DEVFN(new_slot->device, 0), 0x0B, &class_code);
518 if ((header_type & 0x7F) == PCI_HEADER_TYPE_BRIDGE) { 510 pci_bus_read_config_byte(ctrl->pci_bus, PCI_DEVFN(new_slot->device, 0), PCI_HEADER_TYPE, &header_type);
519 /* Recurse the subordinate bus */
520 pci_bus_read_config_byte (ctrl->pci_bus, PCI_DEVFN(new_slot->device, function), PCI_SECONDARY_BUS, &secondary_bus);
521 511
522 sub_bus = (int) secondary_bus; 512 if (header_type & 0x80) /* Multi-function device */
513 max_functions = 8;
514 else
515 max_functions = 1;
523 516
524 /* Save the config headers for the secondary 517 while (function < max_functions) {
525 * bus. 518 if ((header_type & 0x7F) == PCI_HEADER_TYPE_BRIDGE) {
526 */ 519 /* Recurse the subordinate bus */
527 rc = cpqhp_save_config(ctrl, sub_bus, 0); 520 pci_bus_read_config_byte (ctrl->pci_bus, PCI_DEVFN(new_slot->device, function), PCI_SECONDARY_BUS, &secondary_bus);
528 if (rc)
529 return(rc);
530 ctrl->pci_bus->number = new_slot->bus;
531 521
532 } /* End of IF */ 522 sub_bus = (int) secondary_bus;
533 523
534 new_slot->status = 0; 524 /* Save the config headers for the secondary
525 * bus.
526 */
527 rc = cpqhp_save_config(ctrl, sub_bus, 0);
528 if (rc)
529 return(rc);
530 ctrl->pci_bus->number = new_slot->bus;
535 531
536 for (cloop = 0; cloop < 0x20; cloop++) { 532 }
537 pci_bus_read_config_dword (ctrl->pci_bus, PCI_DEVFN(new_slot->device, function), cloop << 2, (u32 *) & (new_slot-> config_space [cloop]));
538 }
539 533
540 function++; 534 new_slot->status = 0;
541 535
542 stop_it = 0; 536 for (cloop = 0; cloop < 0x20; cloop++)
537 pci_bus_read_config_dword(ctrl->pci_bus, PCI_DEVFN(new_slot->device, function), cloop << 2, (u32 *) & (new_slot-> config_space [cloop]));
543 538
544 /* this loop skips to the next present function 539 function++;
545 * reading in the Class Code and the Header type.
546 */
547 while ((function < max_functions) && (!stop_it)) {
548 pci_bus_read_config_dword (ctrl->pci_bus, PCI_DEVFN(new_slot->device, function), PCI_VENDOR_ID, &ID);
549 540
550 if (ID == 0xFFFFFFFF) { /* nothing there. */ 541 stop_it = 0;
551 function++;
552 } else { /* Something there */
553 pci_bus_read_config_byte (ctrl->pci_bus, PCI_DEVFN(new_slot->device, function), 0x0B, &class_code);
554 542
555 pci_bus_read_config_byte (ctrl->pci_bus, PCI_DEVFN(new_slot->device, function), PCI_HEADER_TYPE, &header_type); 543 /* this loop skips to the next present function
544 * reading in the Class Code and the Header type.
545 */
546 while ((function < max_functions) && (!stop_it)) {
547 pci_bus_read_config_dword(ctrl->pci_bus, PCI_DEVFN(new_slot->device, function), PCI_VENDOR_ID, &ID);
556 548
557 stop_it++; 549 if (ID == 0xFFFFFFFF)
558 } 550 function++;
551 else {
552 pci_bus_read_config_byte(ctrl->pci_bus, PCI_DEVFN(new_slot->device, function), 0x0B, &class_code);
553 pci_bus_read_config_byte(ctrl->pci_bus, PCI_DEVFN(new_slot->device, function), PCI_HEADER_TYPE, &header_type);
554 stop_it++;
559 } 555 }
556 }
560 557
561 } while (function < max_functions);
562 } /* End of IF (device in slot?) */
563 else {
564 return 2;
565 } 558 }
566 559
567 return 0; 560 return 0;