Skip to content

Commit 0a2daa1

Browse files
Ram Paijbarnes993
authored andcommitted
PCI: make cardbus-bridge resources optional
Allocate resources to cardbus bridge only after all other genuine resources requests are satisfied. Dont retry if resource allocation for cardbus-bridges fail. Signed-off-by: Ram Pai <[email protected]> Signed-off-by: Jesse Barnes <[email protected]>
1 parent 2aceefc commit 0a2daa1

File tree

2 files changed

+36
-9
lines changed

2 files changed

+36
-9
lines changed

drivers/pci/pci.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -283,6 +283,8 @@ static inline int pci_iov_bus_range(struct pci_bus *bus)
283283

284284
#endif /* CONFIG_PCI_IOV */
285285

286+
extern unsigned long pci_cardbus_resource_alignment(struct resource *);
287+
286288
static inline resource_size_t pci_resource_alignment(struct pci_dev *dev,
287289
struct resource *res)
288290
{
@@ -292,6 +294,8 @@ static inline resource_size_t pci_resource_alignment(struct pci_dev *dev,
292294
if (resno >= PCI_IOV_RESOURCES && resno <= PCI_IOV_RESOURCE_END)
293295
return pci_sriov_resource_alignment(dev, resno);
294296
#endif
297+
if (dev->class >> 8 == PCI_CLASS_BRIDGE_CARDBUS)
298+
return pci_cardbus_resource_alignment(res);
295299
return resource_alignment(res);
296300
}
297301

drivers/pci/setup-bus.c

Lines changed: 32 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,7 @@ static void adjust_resources_sorted(struct resource_list_x *add_head,
164164
idx = res - &list->dev->resource[0];
165165
add_size=list->add_size;
166166
if (!resource_size(res)) {
167+
res->start = list->start;
167168
res->end = res->start + add_size - 1;
168169
if(pci_assign_resource(list->dev, idx))
169170
reset_resource(res);
@@ -223,7 +224,7 @@ static void __assign_resources_sorted(struct resource_list *head,
223224
/* Satisfy the must-have resource requests */
224225
assign_requested_resources_sorted(head, fail_head);
225226

226-
/* Try to satisfy any additional nice-to-have resource
227+
/* Try to satisfy any additional optional resource
227228
requests */
228229
if (add_head)
229230
adjust_resources_sorted(add_head, head);
@@ -678,7 +679,7 @@ static int pbus_size_mem(struct pci_bus *bus, unsigned long mask,
678679
if (add_head && i >= PCI_IOV_RESOURCES &&
679680
i <= PCI_IOV_RESOURCE_END) {
680681
r->end = r->start - 1;
681-
add_to_list(add_head, dev, r, r_size, 1);
682+
add_to_list(add_head, dev, r, r_size, 0/* dont' care */);
682683
children_add_size += r_size;
683684
continue;
684685
}
@@ -743,7 +744,17 @@ static int pbus_size_mem(struct pci_bus *bus, unsigned long mask,
743744
return 1;
744745
}
745746

746-
static void pci_bus_size_cardbus(struct pci_bus *bus)
747+
unsigned long pci_cardbus_resource_alignment(struct resource *res)
748+
{
749+
if (res->flags & IORESOURCE_IO)
750+
return pci_cardbus_io_size;
751+
if (res->flags & IORESOURCE_MEM)
752+
return pci_cardbus_mem_size;
753+
return 0;
754+
}
755+
756+
static void pci_bus_size_cardbus(struct pci_bus *bus,
757+
struct resource_list_x *add_head)
747758
{
748759
struct pci_dev *bridge = bus->self;
749760
struct resource *b_res = &bridge->resource[PCI_BRIDGE_RESOURCES];
@@ -754,12 +765,14 @@ static void pci_bus_size_cardbus(struct pci_bus *bus)
754765
* a fixed amount of bus space for CardBus bridges.
755766
*/
756767
b_res[0].start = 0;
757-
b_res[0].end = pci_cardbus_io_size - 1;
758768
b_res[0].flags |= IORESOURCE_IO | IORESOURCE_SIZEALIGN;
769+
if (add_head)
770+
add_to_list(add_head, bridge, b_res, pci_cardbus_io_size, 0 /* dont care */);
759771

760772
b_res[1].start = 0;
761-
b_res[1].end = pci_cardbus_io_size - 1;
762773
b_res[1].flags |= IORESOURCE_IO | IORESOURCE_SIZEALIGN;
774+
if (add_head)
775+
add_to_list(add_head, bridge, b_res+1, pci_cardbus_io_size, 0 /* dont care */);
763776

764777
/*
765778
* Check whether prefetchable memory is supported
@@ -779,17 +792,27 @@ static void pci_bus_size_cardbus(struct pci_bus *bus)
779792
*/
780793
if (ctrl & PCI_CB_BRIDGE_CTL_PREFETCH_MEM0) {
781794
b_res[2].start = 0;
782-
b_res[2].end = pci_cardbus_mem_size - 1;
783795
b_res[2].flags |= IORESOURCE_MEM | IORESOURCE_PREFETCH | IORESOURCE_SIZEALIGN;
796+
if (add_head)
797+
add_to_list(add_head, bridge, b_res+2, pci_cardbus_mem_size, 0 /* dont care */);
784798

785799
b_res[3].start = 0;
786-
b_res[3].end = pci_cardbus_mem_size - 1;
787800
b_res[3].flags |= IORESOURCE_MEM | IORESOURCE_SIZEALIGN;
801+
if (add_head)
802+
add_to_list(add_head, bridge, b_res+3, pci_cardbus_mem_size, 0 /* dont care */);
788803
} else {
789804
b_res[3].start = 0;
790-
b_res[3].end = pci_cardbus_mem_size * 2 - 1;
791805
b_res[3].flags |= IORESOURCE_MEM | IORESOURCE_SIZEALIGN;
806+
if (add_head)
807+
add_to_list(add_head, bridge, b_res+3, pci_cardbus_mem_size * 2, 0 /* dont care */);
792808
}
809+
810+
/* set the size of the resource to zero, so that the resource does not
811+
* get assigned during required-resource allocation cycle but gets assigned
812+
* during the optional-resource allocation cycle.
813+
*/
814+
b_res[0].start = b_res[1].start = b_res[2].start = b_res[3].start = 1;
815+
b_res[0].end = b_res[1].end = b_res[2].end = b_res[3].end = 0;
793816
}
794817

795818
void __ref __pci_bus_size_bridges(struct pci_bus *bus,
@@ -806,7 +829,7 @@ void __ref __pci_bus_size_bridges(struct pci_bus *bus,
806829

807830
switch (dev->class >> 8) {
808831
case PCI_CLASS_BRIDGE_CARDBUS:
809-
pci_bus_size_cardbus(b);
832+
pci_bus_size_cardbus(b, add_head);
810833
break;
811834

812835
case PCI_CLASS_BRIDGE_PCI:

0 commit comments

Comments
 (0)