Commit 5edb93b8 authored by Bjorn Helgaas's avatar Bjorn Helgaas

resource: Add resource_contains()

We have two identical copies of resource_contains() already, and more
places that could use it.  This moves it to ioport.h where it can be
shared.

resource_contains(struct resource *r1, struct resource *r2) returns true
iff r1 and r2 are the same type (most callers already checked this
separately) and the r1 address range completely contains r2.

In addition, the new resource_contains() checks that both r1 and r2 have
addresses assigned to them.  If a resource is IORESOURCE_UNSET, it doesn't
have a valid address and can't contain or be contained by another resource.
Some callers already check this or for res->start.

No functional change.
Signed-off-by: default avatarBjorn Helgaas <bhelgaas@google.com>
parent d2e074cc
...@@ -32,11 +32,6 @@ void pci_set_host_bridge_release(struct pci_host_bridge *bridge, ...@@ -32,11 +32,6 @@ void pci_set_host_bridge_release(struct pci_host_bridge *bridge,
bridge->release_data = release_data; bridge->release_data = release_data;
} }
static bool resource_contains(struct resource *res1, struct resource *res2)
{
return res1->start <= res2->start && res1->end >= res2->end;
}
void pcibios_resource_to_bus(struct pci_bus *bus, struct pci_bus_region *region, void pcibios_resource_to_bus(struct pci_bus *bus, struct pci_bus_region *region,
struct resource *res) struct resource *res)
{ {
...@@ -45,9 +40,6 @@ void pcibios_resource_to_bus(struct pci_bus *bus, struct pci_bus_region *region, ...@@ -45,9 +40,6 @@ void pcibios_resource_to_bus(struct pci_bus *bus, struct pci_bus_region *region,
resource_size_t offset = 0; resource_size_t offset = 0;
list_for_each_entry(window, &bridge->windows, list) { list_for_each_entry(window, &bridge->windows, list) {
if (resource_type(res) != resource_type(window->res))
continue;
if (resource_contains(window->res, res)) { if (resource_contains(window->res, res)) {
offset = window->offset; offset = window->offset;
break; break;
......
...@@ -169,6 +169,16 @@ static inline unsigned long resource_type(const struct resource *res) ...@@ -169,6 +169,16 @@ static inline unsigned long resource_type(const struct resource *res)
{ {
return res->flags & IORESOURCE_TYPE_BITS; return res->flags & IORESOURCE_TYPE_BITS;
} }
/* True iff r1 completely contains r2 */
static inline bool resource_contains(struct resource *r1, struct resource *r2)
{
if (resource_type(r1) != resource_type(r2))
return false;
if (r1->flags & IORESOURCE_UNSET || r2->flags & IORESOURCE_UNSET)
return false;
return r1->start <= r2->start && r1->end >= r2->end;
}
/* Convenience shorthand with allocation */ /* Convenience shorthand with allocation */
#define request_region(start,n,name) __request_region(&ioport_resource, (start), (n), (name), 0) #define request_region(start,n,name) __request_region(&ioport_resource, (start), (n), (name), 0)
......
...@@ -432,11 +432,6 @@ static void resource_clip(struct resource *res, resource_size_t min, ...@@ -432,11 +432,6 @@ static void resource_clip(struct resource *res, resource_size_t min,
res->end = max; res->end = max;
} }
static bool resource_contains(struct resource *res1, struct resource *res2)
{
return res1->start <= res2->start && res1->end >= res2->end;
}
/* /*
* Find empty slot in the resource tree with the given range and * Find empty slot in the resource tree with the given range and
* alignment constraints * alignment constraints
...@@ -471,10 +466,11 @@ static int __find_resource(struct resource *root, struct resource *old, ...@@ -471,10 +466,11 @@ static int __find_resource(struct resource *root, struct resource *old,
arch_remove_reservations(&tmp); arch_remove_reservations(&tmp);
/* Check for overflow after ALIGN() */ /* Check for overflow after ALIGN() */
avail = *new;
avail.start = ALIGN(tmp.start, constraint->align); avail.start = ALIGN(tmp.start, constraint->align);
avail.end = tmp.end; avail.end = tmp.end;
avail.flags = new->flags & ~IORESOURCE_UNSET;
if (avail.start >= tmp.start) { if (avail.start >= tmp.start) {
alloc.flags = avail.flags;
alloc.start = constraint->alignf(constraint->alignf_data, &avail, alloc.start = constraint->alignf(constraint->alignf_data, &avail,
size, constraint->align); size, constraint->align);
alloc.end = alloc.start + size - 1; alloc.end = alloc.start + size - 1;
......
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