Commit 9e8bf93a authored by Ram Pai's avatar Ram Pai Committed by Jesse Barnes

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: default avatarRam Pai <linuxram@us.ibm.com>
Signed-off-by: default avatarJesse Barnes <jbarnes@virtuousgeek.org>
parent 0a2daa1c
...@@ -125,18 +125,18 @@ static inline void reset_resource(struct resource *res) ...@@ -125,18 +125,18 @@ static inline void reset_resource(struct resource *res)
} }
/** /**
* adjust_resources_sorted() - satisfy any additional resource requests * reassign_resources_sorted() - satisfy any additional resource requests
* *
* @add_head : head of the list tracking requests requiring additional * @realloc_head : head of the list tracking requests requiring additional
* resources * resources
* @head : head of the list tracking requests with allocated * @head : head of the list tracking requests with allocated
* resources * resources
* *
* Walk through each element of the add_head and try to procure * Walk through each element of the realloc_head and try to procure
* additional resources for the element, provided the element * additional resources for the element, provided the element
* is in the head list. * is in the head list.
*/ */
static void adjust_resources_sorted(struct resource_list_x *add_head, static void reassign_resources_sorted(struct resource_list_x *realloc_head,
struct resource_list *head) struct resource_list *head)
{ {
struct resource *res; struct resource *res;
...@@ -145,8 +145,8 @@ static void adjust_resources_sorted(struct resource_list_x *add_head, ...@@ -145,8 +145,8 @@ static void adjust_resources_sorted(struct resource_list_x *add_head,
resource_size_t add_size; resource_size_t add_size;
int idx; int idx;
prev = add_head; prev = realloc_head;
for (list = add_head->next; list;) { for (list = realloc_head->next; list;) {
res = list->res; res = list->res;
/* skip resource that has been reset */ /* skip resource that has been reset */
if (!res->flags) if (!res->flags)
...@@ -218,7 +218,7 @@ static void assign_requested_resources_sorted(struct resource_list *head, ...@@ -218,7 +218,7 @@ static void assign_requested_resources_sorted(struct resource_list *head,
} }
static void __assign_resources_sorted(struct resource_list *head, static void __assign_resources_sorted(struct resource_list *head,
struct resource_list_x *add_head, struct resource_list_x *realloc_head,
struct resource_list_x *fail_head) struct resource_list_x *fail_head)
{ {
/* Satisfy the must-have resource requests */ /* Satisfy the must-have resource requests */
...@@ -226,8 +226,8 @@ static void __assign_resources_sorted(struct resource_list *head, ...@@ -226,8 +226,8 @@ static void __assign_resources_sorted(struct resource_list *head,
/* Try to satisfy any additional optional resource /* Try to satisfy any additional optional resource
requests */ requests */
if (add_head) if (realloc_head)
adjust_resources_sorted(add_head, head); reassign_resources_sorted(realloc_head, head);
free_list(resource_list, head); free_list(resource_list, head);
} }
...@@ -243,7 +243,7 @@ static void pdev_assign_resources_sorted(struct pci_dev *dev, ...@@ -243,7 +243,7 @@ static void pdev_assign_resources_sorted(struct pci_dev *dev,
} }
static void pbus_assign_resources_sorted(const struct pci_bus *bus, static void pbus_assign_resources_sorted(const struct pci_bus *bus,
struct resource_list_x *add_head, struct resource_list_x *realloc_head,
struct resource_list_x *fail_head) struct resource_list_x *fail_head)
{ {
struct pci_dev *dev; struct pci_dev *dev;
...@@ -253,7 +253,7 @@ static void pbus_assign_resources_sorted(const struct pci_bus *bus, ...@@ -253,7 +253,7 @@ static void pbus_assign_resources_sorted(const struct pci_bus *bus,
list_for_each_entry(dev, &bus->devices, bus_list) list_for_each_entry(dev, &bus->devices, bus_list)
__dev_sort_resources(dev, &head); __dev_sort_resources(dev, &head);
__assign_resources_sorted(&head, add_head, fail_head); __assign_resources_sorted(&head, realloc_head, fail_head);
} }
void pci_setup_cardbus(struct pci_bus *bus) void pci_setup_cardbus(struct pci_bus *bus)
...@@ -548,13 +548,13 @@ static resource_size_t calculate_memsize(resource_size_t size, ...@@ -548,13 +548,13 @@ static resource_size_t calculate_memsize(resource_size_t size,
return size; return size;
} }
static resource_size_t get_res_add_size(struct resource_list_x *add_head, static resource_size_t get_res_add_size(struct resource_list_x *realloc_head,
struct resource *res) struct resource *res)
{ {
struct resource_list_x *list; struct resource_list_x *list;
/* check if it is in add_head list */ /* check if it is in realloc_head list */
for (list = add_head->next; list && list->res != res; for (list = realloc_head->next; list && list->res != res;
list = list->next); list = list->next);
if (list) if (list)
return list->add_size; return list->add_size;
...@@ -568,7 +568,7 @@ static resource_size_t get_res_add_size(struct resource_list_x *add_head, ...@@ -568,7 +568,7 @@ static resource_size_t get_res_add_size(struct resource_list_x *add_head,
* @bus : the bus * @bus : the bus
* @min_size : the minimum io window that must to be allocated * @min_size : the minimum io window that must to be allocated
* @add_size : additional optional io window * @add_size : additional optional io window
* @add_head : track the additional io window on this list * @realloc_head : track the additional io window on this list
* *
* Sizing the IO windows of the PCI-PCI bridge is trivial, * Sizing the IO windows of the PCI-PCI bridge is trivial,
* since these windows have 4K granularity and the IO ranges * 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,7 +576,7 @@ static resource_size_t get_res_add_size(struct resource_list_x *add_head,
* We must be careful with the ISA aliasing though. * We must be careful with the ISA aliasing though.
*/ */
static void pbus_size_io(struct pci_bus *bus, resource_size_t min_size, static void pbus_size_io(struct pci_bus *bus, resource_size_t min_size,
resource_size_t add_size, struct resource_list_x *add_head) resource_size_t add_size, struct resource_list_x *realloc_head)
{ {
struct pci_dev *dev; struct pci_dev *dev;
struct resource *b_res = find_free_bus_resource(bus, IORESOURCE_IO); 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,15 +603,15 @@ static void pbus_size_io(struct pci_bus *bus, resource_size_t min_size,
else else
size1 += r_size; size1 += r_size;
if (add_head) if (realloc_head)
children_add_size += get_res_add_size(add_head, r); children_add_size += get_res_add_size(realloc_head, r);
} }
} }
size0 = calculate_iosize(size, min_size, size1, size0 = calculate_iosize(size, min_size, size1,
resource_size(b_res), 4096); resource_size(b_res), 4096);
if (children_add_size > add_size) if (children_add_size > add_size)
add_size = children_add_size; add_size = children_add_size;
size1 = (!add_head || (add_head && !add_size)) ? size0 : size1 = (!realloc_head || (realloc_head && !add_size)) ? size0 :
calculate_iosize(size, min_size+add_size, size1, calculate_iosize(size, min_size+add_size, size1,
resource_size(b_res), 4096); resource_size(b_res), 4096);
if (!size0 && !size1) { if (!size0 && !size1) {
...@@ -626,8 +626,8 @@ static void pbus_size_io(struct pci_bus *bus, resource_size_t min_size, ...@@ -626,8 +626,8 @@ static void pbus_size_io(struct pci_bus *bus, resource_size_t min_size,
b_res->start = 4096; b_res->start = 4096;
b_res->end = b_res->start + size0 - 1; b_res->end = b_res->start + size0 - 1;
b_res->flags |= IORESOURCE_STARTALIGN; b_res->flags |= IORESOURCE_STARTALIGN;
if (size1 > size0 && add_head) if (size1 > size0 && realloc_head)
add_to_list(add_head, bus->self, b_res, size1-size0, 4096); add_to_list(realloc_head, bus->self, b_res, size1-size0, 4096);
} }
/** /**
...@@ -636,7 +636,7 @@ static void pbus_size_io(struct pci_bus *bus, resource_size_t min_size, ...@@ -636,7 +636,7 @@ static void pbus_size_io(struct pci_bus *bus, resource_size_t min_size,
* @bus : the bus * @bus : the bus
* @min_size : the minimum memory window that must to be allocated * @min_size : the minimum memory window that must to be allocated
* @add_size : additional optional memory window * @add_size : additional optional memory window
* @add_head : track the additional memory window on this list * @realloc_head : track the additional memory window on this list
* *
* Calculate the size of the bus and minimal alignment which * Calculate the size of the bus and minimal alignment which
* guarantees that all child resources fit in this size. * 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, ...@@ -644,7 +644,7 @@ static void pbus_size_io(struct pci_bus *bus, resource_size_t min_size,
static int pbus_size_mem(struct pci_bus *bus, unsigned long mask, static int pbus_size_mem(struct pci_bus *bus, unsigned long mask,
unsigned long type, resource_size_t min_size, unsigned long type, resource_size_t min_size,
resource_size_t add_size, resource_size_t add_size,
struct resource_list_x *add_head) struct resource_list_x *realloc_head)
{ {
struct pci_dev *dev; struct pci_dev *dev;
resource_size_t min_align, align, size, size0, size1; 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,10 +676,10 @@ static int pbus_size_mem(struct pci_bus *bus, unsigned long mask,
r_size = resource_size(r); r_size = resource_size(r);
#ifdef CONFIG_PCI_IOV #ifdef CONFIG_PCI_IOV
/* put SRIOV requested res to the optional list */ /* put SRIOV requested res to the optional list */
if (add_head && i >= PCI_IOV_RESOURCES && if (realloc_head && i >= PCI_IOV_RESOURCES &&
i <= PCI_IOV_RESOURCE_END) { i <= PCI_IOV_RESOURCE_END) {
r->end = r->start - 1; r->end = r->start - 1;
add_to_list(add_head, dev, r, r_size, 0/* dont' care */); add_to_list(realloc_head, dev, r, r_size, 0/* dont' care */);
children_add_size += r_size; children_add_size += r_size;
continue; continue;
} }
...@@ -705,8 +705,8 @@ static int pbus_size_mem(struct pci_bus *bus, unsigned long mask, ...@@ -705,8 +705,8 @@ static int pbus_size_mem(struct pci_bus *bus, unsigned long mask,
max_order = order; max_order = order;
mem64_mask &= r->flags & IORESOURCE_MEM_64; mem64_mask &= r->flags & IORESOURCE_MEM_64;
if (add_head) if (realloc_head)
children_add_size += get_res_add_size(add_head, r); children_add_size += get_res_add_size(realloc_head, r);
} }
} }
align = 0; align = 0;
...@@ -725,7 +725,7 @@ static int pbus_size_mem(struct pci_bus *bus, unsigned long mask, ...@@ -725,7 +725,7 @@ static int pbus_size_mem(struct pci_bus *bus, unsigned long mask,
size0 = calculate_memsize(size, min_size, 0, resource_size(b_res), min_align); size0 = calculate_memsize(size, min_size, 0, resource_size(b_res), min_align);
if (children_add_size > add_size) if (children_add_size > add_size)
add_size = children_add_size; add_size = children_add_size;
size1 = (!add_head || (add_head && !add_size)) ? size0 : size1 = (!realloc_head || (realloc_head && !add_size)) ? size0 :
calculate_memsize(size, min_size+add_size, 0, calculate_memsize(size, min_size+add_size, 0,
resource_size(b_res), min_align); resource_size(b_res), min_align);
if (!size0 && !size1) { if (!size0 && !size1) {
...@@ -739,8 +739,8 @@ static int pbus_size_mem(struct pci_bus *bus, unsigned long mask, ...@@ -739,8 +739,8 @@ static int pbus_size_mem(struct pci_bus *bus, unsigned long mask,
b_res->start = min_align; b_res->start = min_align;
b_res->end = size0 + min_align - 1; b_res->end = size0 + min_align - 1;
b_res->flags |= IORESOURCE_STARTALIGN | mem64_mask; b_res->flags |= IORESOURCE_STARTALIGN | mem64_mask;
if (size1 > size0 && add_head) if (size1 > size0 && realloc_head)
add_to_list(add_head, bus->self, b_res, size1-size0, min_align); add_to_list(realloc_head, bus->self, b_res, size1-size0, min_align);
return 1; return 1;
} }
...@@ -754,7 +754,7 @@ unsigned long pci_cardbus_resource_alignment(struct resource *res) ...@@ -754,7 +754,7 @@ unsigned long pci_cardbus_resource_alignment(struct resource *res)
} }
static void pci_bus_size_cardbus(struct pci_bus *bus, static void pci_bus_size_cardbus(struct pci_bus *bus,
struct resource_list_x *add_head) struct resource_list_x *realloc_head)
{ {
struct pci_dev *bridge = bus->self; struct pci_dev *bridge = bus->self;
struct resource *b_res = &bridge->resource[PCI_BRIDGE_RESOURCES]; struct resource *b_res = &bridge->resource[PCI_BRIDGE_RESOURCES];
...@@ -766,13 +766,13 @@ static void pci_bus_size_cardbus(struct pci_bus *bus, ...@@ -766,13 +766,13 @@ static void pci_bus_size_cardbus(struct pci_bus *bus,
*/ */
b_res[0].start = 0; b_res[0].start = 0;
b_res[0].flags |= IORESOURCE_IO | IORESOURCE_SIZEALIGN; b_res[0].flags |= IORESOURCE_IO | IORESOURCE_SIZEALIGN;
if (add_head) if (realloc_head)
add_to_list(add_head, bridge, b_res, pci_cardbus_io_size, 0 /* dont care */); add_to_list(realloc_head, bridge, b_res, pci_cardbus_io_size, 0 /* dont care */);
b_res[1].start = 0; b_res[1].start = 0;
b_res[1].flags |= IORESOURCE_IO | IORESOURCE_SIZEALIGN; b_res[1].flags |= IORESOURCE_IO | IORESOURCE_SIZEALIGN;
if (add_head) if (realloc_head)
add_to_list(add_head, bridge, b_res+1, pci_cardbus_io_size, 0 /* dont care */); add_to_list(realloc_head, bridge, b_res+1, pci_cardbus_io_size, 0 /* dont care */);
/* /*
* Check whether prefetchable memory is supported * Check whether prefetchable memory is supported
...@@ -793,18 +793,18 @@ static void pci_bus_size_cardbus(struct pci_bus *bus, ...@@ -793,18 +793,18 @@ static void pci_bus_size_cardbus(struct pci_bus *bus,
if (ctrl & PCI_CB_BRIDGE_CTL_PREFETCH_MEM0) { if (ctrl & PCI_CB_BRIDGE_CTL_PREFETCH_MEM0) {
b_res[2].start = 0; b_res[2].start = 0;
b_res[2].flags |= IORESOURCE_MEM | IORESOURCE_PREFETCH | IORESOURCE_SIZEALIGN; b_res[2].flags |= IORESOURCE_MEM | IORESOURCE_PREFETCH | IORESOURCE_SIZEALIGN;
if (add_head) if (realloc_head)
add_to_list(add_head, bridge, b_res+2, pci_cardbus_mem_size, 0 /* dont care */); add_to_list(realloc_head, bridge, b_res+2, pci_cardbus_mem_size, 0 /* dont care */);
b_res[3].start = 0; b_res[3].start = 0;
b_res[3].flags |= IORESOURCE_MEM | IORESOURCE_SIZEALIGN; b_res[3].flags |= IORESOURCE_MEM | IORESOURCE_SIZEALIGN;
if (add_head) if (realloc_head)
add_to_list(add_head, bridge, b_res+3, pci_cardbus_mem_size, 0 /* dont care */); add_to_list(realloc_head, bridge, b_res+3, pci_cardbus_mem_size, 0 /* dont care */);
} else { } else {
b_res[3].start = 0; b_res[3].start = 0;
b_res[3].flags |= IORESOURCE_MEM | IORESOURCE_SIZEALIGN; b_res[3].flags |= IORESOURCE_MEM | IORESOURCE_SIZEALIGN;
if (add_head) if (realloc_head)
add_to_list(add_head, bridge, b_res+3, pci_cardbus_mem_size * 2, 0 /* dont care */); add_to_list(realloc_head, bridge, b_res+3, pci_cardbus_mem_size * 2, 0 /* dont care */);
} }
/* set the size of the resource to zero, so that the resource does not /* 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,7 +816,7 @@ static void pci_bus_size_cardbus(struct pci_bus *bus,
} }
void __ref __pci_bus_size_bridges(struct pci_bus *bus, void __ref __pci_bus_size_bridges(struct pci_bus *bus,
struct resource_list_x *add_head) struct resource_list_x *realloc_head)
{ {
struct pci_dev *dev; struct pci_dev *dev;
unsigned long mask, prefmask; unsigned long mask, prefmask;
...@@ -829,12 +829,12 @@ void __ref __pci_bus_size_bridges(struct pci_bus *bus, ...@@ -829,12 +829,12 @@ void __ref __pci_bus_size_bridges(struct pci_bus *bus,
switch (dev->class >> 8) { switch (dev->class >> 8) {
case PCI_CLASS_BRIDGE_CARDBUS: case PCI_CLASS_BRIDGE_CARDBUS:
pci_bus_size_cardbus(b, add_head); pci_bus_size_cardbus(b, realloc_head);
break; break;
case PCI_CLASS_BRIDGE_PCI: case PCI_CLASS_BRIDGE_PCI:
default: default:
__pci_bus_size_bridges(b, add_head); __pci_bus_size_bridges(b, realloc_head);
break; break;
} }
} }
...@@ -858,7 +858,7 @@ void __ref __pci_bus_size_bridges(struct pci_bus *bus, ...@@ -858,7 +858,7 @@ void __ref __pci_bus_size_bridges(struct pci_bus *bus,
* Follow thru * Follow thru
*/ */
default: default:
pbus_size_io(bus, 0, additional_io_size, add_head); pbus_size_io(bus, 0, additional_io_size, realloc_head);
/* If the bridge supports prefetchable range, size it /* If the bridge supports prefetchable range, size it
separately. If it doesn't, or its prefetchable window separately. If it doesn't, or its prefetchable window
has already been allocated by arch code, try has already been allocated by arch code, try
...@@ -866,11 +866,11 @@ void __ref __pci_bus_size_bridges(struct pci_bus *bus, ...@@ -866,11 +866,11 @@ void __ref __pci_bus_size_bridges(struct pci_bus *bus,
resources. */ resources. */
mask = IORESOURCE_MEM; mask = IORESOURCE_MEM;
prefmask = IORESOURCE_MEM | IORESOURCE_PREFETCH; prefmask = IORESOURCE_MEM | IORESOURCE_PREFETCH;
if (pbus_size_mem(bus, prefmask, prefmask, 0, additional_mem_size, add_head)) if (pbus_size_mem(bus, prefmask, prefmask, 0, additional_mem_size, realloc_head))
mask = prefmask; /* Success, size non-prefetch only. */ mask = prefmask; /* Success, size non-prefetch only. */
else else
additional_mem_size += additional_mem_size; additional_mem_size += additional_mem_size;
pbus_size_mem(bus, mask, IORESOURCE_MEM, 0, additional_mem_size, add_head); pbus_size_mem(bus, mask, IORESOURCE_MEM, 0, additional_mem_size, realloc_head);
break; break;
} }
} }
...@@ -882,20 +882,20 @@ void __ref pci_bus_size_bridges(struct pci_bus *bus) ...@@ -882,20 +882,20 @@ void __ref pci_bus_size_bridges(struct pci_bus *bus)
EXPORT_SYMBOL(pci_bus_size_bridges); EXPORT_SYMBOL(pci_bus_size_bridges);
static void __ref __pci_bus_assign_resources(const struct pci_bus *bus, static void __ref __pci_bus_assign_resources(const struct pci_bus *bus,
struct resource_list_x *add_head, struct resource_list_x *realloc_head,
struct resource_list_x *fail_head) struct resource_list_x *fail_head)
{ {
struct pci_bus *b; struct pci_bus *b;
struct pci_dev *dev; struct pci_dev *dev;
pbus_assign_resources_sorted(bus, add_head, fail_head); pbus_assign_resources_sorted(bus, realloc_head, fail_head);
list_for_each_entry(dev, &bus->devices, bus_list) { list_for_each_entry(dev, &bus->devices, bus_list) {
b = dev->subordinate; b = dev->subordinate;
if (!b) if (!b)
continue; continue;
__pci_bus_assign_resources(b, add_head, fail_head); __pci_bus_assign_resources(b, realloc_head, fail_head);
switch (dev->class >> 8) { switch (dev->class >> 8) {
case PCI_CLASS_BRIDGE_PCI: case PCI_CLASS_BRIDGE_PCI:
...@@ -1105,7 +1105,7 @@ void __init ...@@ -1105,7 +1105,7 @@ void __init
pci_assign_unassigned_resources(void) pci_assign_unassigned_resources(void)
{ {
struct pci_bus *bus; struct pci_bus *bus;
struct resource_list_x add_list; /* list of resources that struct resource_list_x realloc_list; /* list of resources that
want additional resources */ want additional resources */
int tried_times = 0; int tried_times = 0;
enum release_type rel_type = leaf_only; enum release_type rel_type = leaf_only;
...@@ -1118,7 +1118,7 @@ pci_assign_unassigned_resources(void) ...@@ -1118,7 +1118,7 @@ pci_assign_unassigned_resources(void)
head.next = NULL; head.next = NULL;
add_list.next = NULL; realloc_list.next = NULL;
pci_try_num = max_depth + 1; pci_try_num = max_depth + 1;
printk(KERN_DEBUG "PCI: max bus depth: %d pci_try_num: %d\n", printk(KERN_DEBUG "PCI: max bus depth: %d pci_try_num: %d\n",
...@@ -1128,12 +1128,12 @@ pci_assign_unassigned_resources(void) ...@@ -1128,12 +1128,12 @@ pci_assign_unassigned_resources(void)
/* Depth first, calculate sizes and alignments of all /* Depth first, calculate sizes and alignments of all
subordinate buses. */ subordinate buses. */
list_for_each_entry(bus, &pci_root_buses, node) list_for_each_entry(bus, &pci_root_buses, node)
__pci_bus_size_bridges(bus, &add_list); __pci_bus_size_bridges(bus, &realloc_list);
/* Depth last, allocate resources and update the hardware. */ /* Depth last, allocate resources and update the hardware. */
list_for_each_entry(bus, &pci_root_buses, node) list_for_each_entry(bus, &pci_root_buses, node)
__pci_bus_assign_resources(bus, &add_list, &head); __pci_bus_assign_resources(bus, &realloc_list, &head);
BUG_ON(add_list.next); BUG_ON(realloc_list.next);
tried_times++; tried_times++;
/* any device complain? */ /* any device complain? */
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment