aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/pci
diff options
context:
space:
mode:
authorRam Pai <linuxram@us.ibm.com>2011-07-25 16:08:42 -0400
committerJesse Barnes <jbarnes@virtuousgeek.org>2011-08-01 14:50:50 -0400
commit9e8bf93a7f416a3fa8fb6d76177d90e67bd45496 (patch)
tree0ad966551eec5894129010dbcaef1f271c960cec /drivers/pci
parent0a2daa1cf35004f5adbf4138555cc5669abf3a3e (diff)
PCI: code and comments cleanup
a) adjust_resource_sorted() is now called reassign_resource_sorted() b) nice-to-have is now called optional c) add_list is now called realloc_list. Signed-off-by: Ram Pai <linuxram@us.ibm.com> Signed-off-by: Jesse Barnes <jbarnes@virtuousgeek.org>
Diffstat (limited to 'drivers/pci')
-rw-r--r--drivers/pci/setup-bus.c110
1 files changed, 55 insertions, 55 deletions
diff --git a/drivers/pci/setup-bus.c b/drivers/pci/setup-bus.c
index 29e7cc73537c..784da9d36029 100644
--- a/drivers/pci/setup-bus.c
+++ b/drivers/pci/setup-bus.c
@@ -125,18 +125,18 @@ static inline void reset_resource(struct resource *res)
125} 125}
126 126
127/** 127/**
128 * adjust_resources_sorted() - satisfy any additional resource requests 128 * reassign_resources_sorted() - satisfy any additional resource requests
129 * 129 *
130 * @add_head : head of the list tracking requests requiring additional 130 * @realloc_head : head of the list tracking requests requiring additional
131 * resources 131 * resources
132 * @head : head of the list tracking requests with allocated 132 * @head : head of the list tracking requests with allocated
133 * resources 133 * resources
134 * 134 *
135 * Walk through each element of the add_head and try to procure 135 * Walk through each element of the realloc_head and try to procure
136 * additional resources for the element, provided the element 136 * additional resources for the element, provided the element
137 * is in the head list. 137 * is in the head list.
138 */ 138 */
139static void adjust_resources_sorted(struct resource_list_x *add_head, 139static void reassign_resources_sorted(struct resource_list_x *realloc_head,
140 struct resource_list *head) 140 struct resource_list *head)
141{ 141{
142 struct resource *res; 142 struct resource *res;
@@ -145,8 +145,8 @@ static void adjust_resources_sorted(struct resource_list_x *add_head,
145 resource_size_t add_size; 145 resource_size_t add_size;
146 int idx; 146 int idx;
147 147
148 prev = add_head; 148 prev = realloc_head;
149 for (list = add_head->next; list;) { 149 for (list = realloc_head->next; list;) {
150 res = list->res; 150 res = list->res;
151 /* skip resource that has been reset */ 151 /* skip resource that has been reset */
152 if (!res->flags) 152 if (!res->flags)
@@ -218,7 +218,7 @@ static void assign_requested_resources_sorted(struct resource_list *head,
218} 218}
219 219
220static void __assign_resources_sorted(struct resource_list *head, 220static void __assign_resources_sorted(struct resource_list *head,
221 struct resource_list_x *add_head, 221 struct resource_list_x *realloc_head,
222 struct resource_list_x *fail_head) 222 struct resource_list_x *fail_head)
223{ 223{
224 /* Satisfy the must-have resource requests */ 224 /* Satisfy the must-have resource requests */
@@ -226,8 +226,8 @@ static void __assign_resources_sorted(struct resource_list *head,
226 226
227 /* Try to satisfy any additional optional resource 227 /* Try to satisfy any additional optional resource
228 requests */ 228 requests */
229 if (add_head) 229 if (realloc_head)
230 adjust_resources_sorted(add_head, head); 230 reassign_resources_sorted(realloc_head, head);
231 free_list(resource_list, head); 231 free_list(resource_list, head);
232} 232}
233 233
@@ -243,7 +243,7 @@ static void pdev_assign_resources_sorted(struct pci_dev *dev,
243} 243}
244 244
245static void pbus_assign_resources_sorted(const struct pci_bus *bus, 245static void pbus_assign_resources_sorted(const struct pci_bus *bus,
246 struct resource_list_x *add_head, 246 struct resource_list_x *realloc_head,
247 struct resource_list_x *fail_head) 247 struct resource_list_x *fail_head)
248{ 248{
249 struct pci_dev *dev; 249 struct pci_dev *dev;
@@ -253,7 +253,7 @@ static void pbus_assign_resources_sorted(const struct pci_bus *bus,
253 list_for_each_entry(dev, &bus->devices, bus_list) 253 list_for_each_entry(dev, &bus->devices, bus_list)
254 __dev_sort_resources(dev, &head); 254 __dev_sort_resources(dev, &head);
255 255
256 __assign_resources_sorted(&head, add_head, fail_head); 256 __assign_resources_sorted(&head, realloc_head, fail_head);
257} 257}
258 258
259void pci_setup_cardbus(struct pci_bus *bus) 259void pci_setup_cardbus(struct pci_bus *bus)
@@ -548,13 +548,13 @@ static resource_size_t calculate_memsize(resource_size_t size,
548 return size; 548 return size;
549} 549}
550 550
551static resource_size_t get_res_add_size(struct resource_list_x *add_head, 551static resource_size_t get_res_add_size(struct resource_list_x *realloc_head,
552 struct resource *res) 552 struct resource *res)
553{ 553{
554 struct resource_list_x *list; 554 struct resource_list_x *list;
555 555
556 /* check if it is in add_head list */ 556 /* check if it is in realloc_head list */
557 for (list = add_head->next; list && list->res != res; 557 for (list = realloc_head->next; list && list->res != res;
558 list = list->next); 558 list = list->next);
559 if (list) 559 if (list)
560 return list->add_size; 560 return list->add_size;
@@ -568,7 +568,7 @@ static resource_size_t get_res_add_size(struct resource_list_x *add_head,
568 * @bus : the bus 568 * @bus : the bus
569 * @min_size : the minimum io window that must to be allocated 569 * @min_size : the minimum io window that must to be allocated
570 * @add_size : additional optional io window 570 * @add_size : additional optional io window
571 * @add_head : track the additional io window on this list 571 * @realloc_head : track the additional io window on this list
572 * 572 *
573 * Sizing the IO windows of the PCI-PCI bridge is trivial, 573 * Sizing the IO windows of the PCI-PCI bridge is trivial,
574 * since these windows have 4K granularity and the IO ranges 574 * since these windows have 4K granularity and the IO ranges
@@ -576,7 +576,7 @@ static resource_size_t get_res_add_size(struct resource_list_x *add_head,
576 * We must be careful with the ISA aliasing though. 576 * We must be careful with the ISA aliasing though.
577 */ 577 */
578static void pbus_size_io(struct pci_bus *bus, resource_size_t min_size, 578static void pbus_size_io(struct pci_bus *bus, resource_size_t min_size,
579 resource_size_t add_size, struct resource_list_x *add_head) 579 resource_size_t add_size, struct resource_list_x *realloc_head)
580{ 580{
581 struct pci_dev *dev; 581 struct pci_dev *dev;
582 struct resource *b_res = find_free_bus_resource(bus, IORESOURCE_IO); 582 struct resource *b_res = find_free_bus_resource(bus, IORESOURCE_IO);
@@ -603,15 +603,15 @@ static void pbus_size_io(struct pci_bus *bus, resource_size_t min_size,
603 else 603 else
604 size1 += r_size; 604 size1 += r_size;
605 605
606 if (add_head) 606 if (realloc_head)
607 children_add_size += get_res_add_size(add_head, r); 607 children_add_size += get_res_add_size(realloc_head, r);
608 } 608 }
609 } 609 }
610 size0 = calculate_iosize(size, min_size, size1, 610 size0 = calculate_iosize(size, min_size, size1,
611 resource_size(b_res), 4096); 611 resource_size(b_res), 4096);
612 if (children_add_size > add_size) 612 if (children_add_size > add_size)
613 add_size = children_add_size; 613 add_size = children_add_size;
614 size1 = (!add_head || (add_head && !add_size)) ? size0 : 614 size1 = (!realloc_head || (realloc_head && !add_size)) ? size0 :
615 calculate_iosize(size, min_size+add_size, size1, 615 calculate_iosize(size, min_size+add_size, size1,
616 resource_size(b_res), 4096); 616 resource_size(b_res), 4096);
617 if (!size0 && !size1) { 617 if (!size0 && !size1) {
@@ -626,8 +626,8 @@ static void pbus_size_io(struct pci_bus *bus, resource_size_t min_size,
626 b_res->start = 4096; 626 b_res->start = 4096;
627 b_res->end = b_res->start + size0 - 1; 627 b_res->end = b_res->start + size0 - 1;
628 b_res->flags |= IORESOURCE_STARTALIGN; 628 b_res->flags |= IORESOURCE_STARTALIGN;
629 if (size1 > size0 && add_head) 629 if (size1 > size0 && realloc_head)
630 add_to_list(add_head, bus->self, b_res, size1-size0, 4096); 630 add_to_list(realloc_head, bus->self, b_res, size1-size0, 4096);
631} 631}
632 632
633/** 633/**
@@ -636,7 +636,7 @@ static void pbus_size_io(struct pci_bus *bus, resource_size_t min_size,
636 * @bus : the bus 636 * @bus : the bus
637 * @min_size : the minimum memory window that must to be allocated 637 * @min_size : the minimum memory window that must to be allocated
638 * @add_size : additional optional memory window 638 * @add_size : additional optional memory window
639 * @add_head : track the additional memory window on this list 639 * @realloc_head : track the additional memory window on this list
640 * 640 *
641 * Calculate the size of the bus and minimal alignment which 641 * Calculate the size of the bus and minimal alignment which
642 * guarantees that all child resources fit in this size. 642 * guarantees that all child resources fit in this size.
@@ -644,7 +644,7 @@ static void pbus_size_io(struct pci_bus *bus, resource_size_t min_size,
644static int pbus_size_mem(struct pci_bus *bus, unsigned long mask, 644static int pbus_size_mem(struct pci_bus *bus, unsigned long mask,
645 unsigned long type, resource_size_t min_size, 645 unsigned long type, resource_size_t min_size,
646 resource_size_t add_size, 646 resource_size_t add_size,
647 struct resource_list_x *add_head) 647 struct resource_list_x *realloc_head)
648{ 648{
649 struct pci_dev *dev; 649 struct pci_dev *dev;
650 resource_size_t min_align, align, size, size0, size1; 650 resource_size_t min_align, align, size, size0, size1;
@@ -676,10 +676,10 @@ static int pbus_size_mem(struct pci_bus *bus, unsigned long mask,
676 r_size = resource_size(r); 676 r_size = resource_size(r);
677#ifdef CONFIG_PCI_IOV 677#ifdef CONFIG_PCI_IOV
678 /* put SRIOV requested res to the optional list */ 678 /* put SRIOV requested res to the optional list */
679 if (add_head && i >= PCI_IOV_RESOURCES && 679 if (realloc_head && i >= PCI_IOV_RESOURCES &&
680 i <= PCI_IOV_RESOURCE_END) { 680 i <= PCI_IOV_RESOURCE_END) {
681 r->end = r->start - 1; 681 r->end = r->start - 1;
682 add_to_list(add_head, dev, r, r_size, 0/* dont' care */); 682 add_to_list(realloc_head, dev, r, r_size, 0/* dont' care */);
683 children_add_size += r_size; 683 children_add_size += r_size;
684 continue; 684 continue;
685 } 685 }
@@ -705,8 +705,8 @@ static int pbus_size_mem(struct pci_bus *bus, unsigned long mask,
705 max_order = order; 705 max_order = order;
706 mem64_mask &= r->flags & IORESOURCE_MEM_64; 706 mem64_mask &= r->flags & IORESOURCE_MEM_64;
707 707
708 if (add_head) 708 if (realloc_head)
709 children_add_size += get_res_add_size(add_head, r); 709 children_add_size += get_res_add_size(realloc_head, r);
710 } 710 }
711 } 711 }
712 align = 0; 712 align = 0;
@@ -725,7 +725,7 @@ static int pbus_size_mem(struct pci_bus *bus, unsigned long mask,
725 size0 = calculate_memsize(size, min_size, 0, resource_size(b_res), min_align); 725 size0 = calculate_memsize(size, min_size, 0, resource_size(b_res), min_align);
726 if (children_add_size > add_size) 726 if (children_add_size > add_size)
727 add_size = children_add_size; 727 add_size = children_add_size;
728 size1 = (!add_head || (add_head && !add_size)) ? size0 : 728 size1 = (!realloc_head || (realloc_head && !add_size)) ? size0 :
729 calculate_memsize(size, min_size+add_size, 0, 729 calculate_memsize(size, min_size+add_size, 0,
730 resource_size(b_res), min_align); 730 resource_size(b_res), min_align);
731 if (!size0 && !size1) { 731 if (!size0 && !size1) {
@@ -739,8 +739,8 @@ static int pbus_size_mem(struct pci_bus *bus, unsigned long mask,
739 b_res->start = min_align; 739 b_res->start = min_align;
740 b_res->end = size0 + min_align - 1; 740 b_res->end = size0 + min_align - 1;
741 b_res->flags |= IORESOURCE_STARTALIGN | mem64_mask; 741 b_res->flags |= IORESOURCE_STARTALIGN | mem64_mask;
742 if (size1 > size0 && add_head) 742 if (size1 > size0 && realloc_head)
743 add_to_list(add_head, bus->self, b_res, size1-size0, min_align); 743 add_to_list(realloc_head, bus->self, b_res, size1-size0, min_align);
744 return 1; 744 return 1;
745} 745}
746 746
@@ -754,7 +754,7 @@ unsigned long pci_cardbus_resource_alignment(struct resource *res)
754} 754}
755 755
756static void pci_bus_size_cardbus(struct pci_bus *bus, 756static void pci_bus_size_cardbus(struct pci_bus *bus,
757 struct resource_list_x *add_head) 757 struct resource_list_x *realloc_head)
758{ 758{
759 struct pci_dev *bridge = bus->self; 759 struct pci_dev *bridge = bus->self;
760 struct resource *b_res = &bridge->resource[PCI_BRIDGE_RESOURCES]; 760 struct resource *b_res = &bridge->resource[PCI_BRIDGE_RESOURCES];
@@ -766,13 +766,13 @@ static void pci_bus_size_cardbus(struct pci_bus *bus,
766 */ 766 */
767 b_res[0].start = 0; 767 b_res[0].start = 0;
768 b_res[0].flags |= IORESOURCE_IO | IORESOURCE_SIZEALIGN; 768 b_res[0].flags |= IORESOURCE_IO | IORESOURCE_SIZEALIGN;
769 if (add_head) 769 if (realloc_head)
770 add_to_list(add_head, bridge, b_res, pci_cardbus_io_size, 0 /* dont care */); 770 add_to_list(realloc_head, bridge, b_res, pci_cardbus_io_size, 0 /* dont care */);
771 771
772 b_res[1].start = 0; 772 b_res[1].start = 0;
773 b_res[1].flags |= IORESOURCE_IO | IORESOURCE_SIZEALIGN; 773 b_res[1].flags |= IORESOURCE_IO | IORESOURCE_SIZEALIGN;
774 if (add_head) 774 if (realloc_head)
775 add_to_list(add_head, bridge, b_res+1, pci_cardbus_io_size, 0 /* dont care */); 775 add_to_list(realloc_head, bridge, b_res+1, pci_cardbus_io_size, 0 /* dont care */);
776 776
777 /* 777 /*
778 * Check whether prefetchable memory is supported 778 * Check whether prefetchable memory is supported
@@ -793,18 +793,18 @@ static void pci_bus_size_cardbus(struct pci_bus *bus,
793 if (ctrl & PCI_CB_BRIDGE_CTL_PREFETCH_MEM0) { 793 if (ctrl & PCI_CB_BRIDGE_CTL_PREFETCH_MEM0) {
794 b_res[2].start = 0; 794 b_res[2].start = 0;
795 b_res[2].flags |= IORESOURCE_MEM | IORESOURCE_PREFETCH | IORESOURCE_SIZEALIGN; 795 b_res[2].flags |= IORESOURCE_MEM | IORESOURCE_PREFETCH | IORESOURCE_SIZEALIGN;
796 if (add_head) 796 if (realloc_head)
797 add_to_list(add_head, bridge, b_res+2, pci_cardbus_mem_size, 0 /* dont care */); 797 add_to_list(realloc_head, bridge, b_res+2, pci_cardbus_mem_size, 0 /* dont care */);
798 798
799 b_res[3].start = 0; 799 b_res[3].start = 0;
800 b_res[3].flags |= IORESOURCE_MEM | IORESOURCE_SIZEALIGN; 800 b_res[3].flags |= IORESOURCE_MEM | IORESOURCE_SIZEALIGN;
801 if (add_head) 801 if (realloc_head)
802 add_to_list(add_head, bridge, b_res+3, pci_cardbus_mem_size, 0 /* dont care */); 802 add_to_list(realloc_head, bridge, b_res+3, pci_cardbus_mem_size, 0 /* dont care */);
803 } else { 803 } else {
804 b_res[3].start = 0; 804 b_res[3].start = 0;
805 b_res[3].flags |= IORESOURCE_MEM | IORESOURCE_SIZEALIGN; 805 b_res[3].flags |= IORESOURCE_MEM | IORESOURCE_SIZEALIGN;
806 if (add_head) 806 if (realloc_head)
807 add_to_list(add_head, bridge, b_res+3, pci_cardbus_mem_size * 2, 0 /* dont care */); 807 add_to_list(realloc_head, bridge, b_res+3, pci_cardbus_mem_size * 2, 0 /* dont care */);
808 } 808 }
809 809
810 /* set the size of the resource to zero, so that the resource does not 810 /* set the size of the resource to zero, so that the resource does not
@@ -816,7 +816,7 @@ static void pci_bus_size_cardbus(struct pci_bus *bus,
816} 816}
817 817
818void __ref __pci_bus_size_bridges(struct pci_bus *bus, 818void __ref __pci_bus_size_bridges(struct pci_bus *bus,
819 struct resource_list_x *add_head) 819 struct resource_list_x *realloc_head)
820{ 820{
821 struct pci_dev *dev; 821 struct pci_dev *dev;
822 unsigned long mask, prefmask; 822 unsigned long mask, prefmask;
@@ -829,12 +829,12 @@ void __ref __pci_bus_size_bridges(struct pci_bus *bus,
829 829
830 switch (dev->class >> 8) { 830 switch (dev->class >> 8) {
831 case PCI_CLASS_BRIDGE_CARDBUS: 831 case PCI_CLASS_BRIDGE_CARDBUS:
832 pci_bus_size_cardbus(b, add_head); 832 pci_bus_size_cardbus(b, realloc_head);
833 break; 833 break;
834 834
835 case PCI_CLASS_BRIDGE_PCI: 835 case PCI_CLASS_BRIDGE_PCI:
836 default: 836 default:
837 __pci_bus_size_bridges(b, add_head); 837 __pci_bus_size_bridges(b, realloc_head);
838 break; 838 break;
839 } 839 }
840 } 840 }
@@ -858,7 +858,7 @@ void __ref __pci_bus_size_bridges(struct pci_bus *bus,
858 * Follow thru 858 * Follow thru
859 */ 859 */
860 default: 860 default:
861 pbus_size_io(bus, 0, additional_io_size, add_head); 861 pbus_size_io(bus, 0, additional_io_size, realloc_head);
862 /* If the bridge supports prefetchable range, size it 862 /* If the bridge supports prefetchable range, size it
863 separately. If it doesn't, or its prefetchable window 863 separately. If it doesn't, or its prefetchable window
864 has already been allocated by arch code, try 864 has already been allocated by arch code, try
@@ -866,11 +866,11 @@ void __ref __pci_bus_size_bridges(struct pci_bus *bus,
866 resources. */ 866 resources. */
867 mask = IORESOURCE_MEM; 867 mask = IORESOURCE_MEM;
868 prefmask = IORESOURCE_MEM | IORESOURCE_PREFETCH; 868 prefmask = IORESOURCE_MEM | IORESOURCE_PREFETCH;
869 if (pbus_size_mem(bus, prefmask, prefmask, 0, additional_mem_size, add_head)) 869 if (pbus_size_mem(bus, prefmask, prefmask, 0, additional_mem_size, realloc_head))
870 mask = prefmask; /* Success, size non-prefetch only. */ 870 mask = prefmask; /* Success, size non-prefetch only. */
871 else 871 else
872 additional_mem_size += additional_mem_size; 872 additional_mem_size += additional_mem_size;
873 pbus_size_mem(bus, mask, IORESOURCE_MEM, 0, additional_mem_size, add_head); 873 pbus_size_mem(bus, mask, IORESOURCE_MEM, 0, additional_mem_size, realloc_head);
874 break; 874 break;
875 } 875 }
876} 876}
@@ -882,20 +882,20 @@ void __ref pci_bus_size_bridges(struct pci_bus *bus)
882EXPORT_SYMBOL(pci_bus_size_bridges); 882EXPORT_SYMBOL(pci_bus_size_bridges);
883 883
884static void __ref __pci_bus_assign_resources(const struct pci_bus *bus, 884static void __ref __pci_bus_assign_resources(const struct pci_bus *bus,
885 struct resource_list_x *add_head, 885 struct resource_list_x *realloc_head,
886 struct resource_list_x *fail_head) 886 struct resource_list_x *fail_head)
887{ 887{
888 struct pci_bus *b; 888 struct pci_bus *b;
889 struct pci_dev *dev; 889 struct pci_dev *dev;
890 890
891 pbus_assign_resources_sorted(bus, add_head, fail_head); 891 pbus_assign_resources_sorted(bus, realloc_head, fail_head);
892 892
893 list_for_each_entry(dev, &bus->devices, bus_list) { 893 list_for_each_entry(dev, &bus->devices, bus_list) {
894 b = dev->subordinate; 894 b = dev->subordinate;
895 if (!b) 895 if (!b)
896 continue; 896 continue;
897 897
898 __pci_bus_assign_resources(b, add_head, fail_head); 898 __pci_bus_assign_resources(b, realloc_head, fail_head);
899 899
900 switch (dev->class >> 8) { 900 switch (dev->class >> 8) {
901 case PCI_CLASS_BRIDGE_PCI: 901 case PCI_CLASS_BRIDGE_PCI:
@@ -1105,7 +1105,7 @@ void __init
1105pci_assign_unassigned_resources(void) 1105pci_assign_unassigned_resources(void)
1106{ 1106{
1107 struct pci_bus *bus; 1107 struct pci_bus *bus;
1108 struct resource_list_x add_list; /* list of resources that 1108 struct resource_list_x realloc_list; /* list of resources that
1109 want additional resources */ 1109 want additional resources */
1110 int tried_times = 0; 1110 int tried_times = 0;
1111 enum release_type rel_type = leaf_only; 1111 enum release_type rel_type = leaf_only;
@@ -1118,7 +1118,7 @@ pci_assign_unassigned_resources(void)
1118 1118
1119 1119
1120 head.next = NULL; 1120 head.next = NULL;
1121 add_list.next = NULL; 1121 realloc_list.next = NULL;
1122 1122
1123 pci_try_num = max_depth + 1; 1123 pci_try_num = max_depth + 1;
1124 printk(KERN_DEBUG "PCI: max bus depth: %d pci_try_num: %d\n", 1124 printk(KERN_DEBUG "PCI: max bus depth: %d pci_try_num: %d\n",
@@ -1128,12 +1128,12 @@ again:
1128 /* Depth first, calculate sizes and alignments of all 1128 /* Depth first, calculate sizes and alignments of all
1129 subordinate buses. */ 1129 subordinate buses. */
1130 list_for_each_entry(bus, &pci_root_buses, node) 1130 list_for_each_entry(bus, &pci_root_buses, node)
1131 __pci_bus_size_bridges(bus, &add_list); 1131 __pci_bus_size_bridges(bus, &realloc_list);
1132 1132
1133 /* Depth last, allocate resources and update the hardware. */ 1133 /* Depth last, allocate resources and update the hardware. */
1134 list_for_each_entry(bus, &pci_root_buses, node) 1134 list_for_each_entry(bus, &pci_root_buses, node)
1135 __pci_bus_assign_resources(bus, &add_list, &head); 1135 __pci_bus_assign_resources(bus, &realloc_list, &head);
1136 BUG_ON(add_list.next); 1136 BUG_ON(realloc_list.next);
1137 tried_times++; 1137 tried_times++;
1138 1138
1139 /* any device complain? */ 1139 /* any device complain? */