Skip to content

Commit

Permalink
---
Browse files Browse the repository at this point in the history
yaml
---
r: 219565
b: refs/heads/master
c: b126b47
h: refs/heads/master
i:
  219563: 24ac706
v: v3
  • Loading branch information
Bjorn Helgaas authored and Jesse Barnes committed Oct 26, 2010
1 parent eb72d09 commit 97f7edf
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 6 deletions.
2 changes: 1 addition & 1 deletion [refs]
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
---
refs/heads/master: e7f8567db9a7f6b3151b0b275e245c1cef0d9c70
refs/heads/master: b126b4703afa4010b161784a43650337676dd03b
53 changes: 48 additions & 5 deletions trunk/drivers/pci/bus.c
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,49 @@ void pci_bus_remove_resources(struct pci_bus *bus)
}
}

/*
* Find the highest-address bus resource below the cursor "res". If the
* cursor is NULL, return the highest resource.
*/
static struct resource *pci_bus_find_resource_prev(struct pci_bus *bus,
unsigned int type,
struct resource *res)
{
struct resource *r, *prev = NULL;
int i;

pci_bus_for_each_resource(bus, r, i) {
if (!r)
continue;

if ((r->flags & IORESOURCE_TYPE_BITS) != type)
continue;

/* If this resource is at or past the cursor, skip it */
if (res) {
if (r == res)
continue;
if (r->end > res->end)
continue;
if (r->end == res->end && r->start > res->start)
continue;
}

if (!prev)
prev = r;

/*
* A small resource is higher than a large one that ends at
* the same address.
*/
if (r->end > prev->end ||
(r->end == prev->end && r->start > prev->start))
prev = r;
}

return prev;
}

/**
* pci_bus_alloc_resource - allocate a resource from a parent bus
* @bus: PCI bus
Expand All @@ -89,20 +132,20 @@ pci_bus_alloc_resource(struct pci_bus *bus, struct resource *res,
resource_size_t),
void *alignf_data)
{
int i, ret = -ENOMEM;
int ret = -ENOMEM;
struct resource *r;
resource_size_t max = -1;
unsigned int type = res->flags & IORESOURCE_TYPE_BITS;

type_mask |= IORESOURCE_IO | IORESOURCE_MEM;

/* don't allocate too high if the pref mem doesn't support 64bit*/
if (!(res->flags & IORESOURCE_MEM_64))
max = PCIBIOS_MAX_MEM_32;

pci_bus_for_each_resource(bus, r, i) {
if (!r)
continue;

/* Look for space at highest addresses first */
r = pci_bus_find_resource_prev(bus, type, NULL);
for ( ; r; r = pci_bus_find_resource_prev(bus, type, r)) {
/* type_mask must match */
if ((res->flags ^ r->flags) & type_mask)
continue;
Expand Down

0 comments on commit 97f7edf

Please sign in to comment.