/* For given resource region of given device, return the resource region of parent bus the given region is contained in or where it should be allocated from.  */
struct resource* pci_find_parent_resource(const struct pci_dev *dev, struct resource *res)
/* For given resource region of given device, return the resource region of parent bus the given region is contained in or where it should be allocated from.  */
struct resource* pci_find_parent_resource(const struct pci_dev *dev, struct resource *res)
{
	const struct pci_bus *bus = dev->bus;
	int i;
	struct resource *best = NULL;
	for(i = 0; i < PCI_BUS_NUM_RESOURCES; i++) {
		struct resource *r = bus->resource[i];
		if (!r)
			continue;
		if (res->start && !(res->start >= r->start && res->end <= r->end))
			continue;
		if ((res->flags ^ r->flags) & (IORESOURCE_IO | IORESOURCE_MEM))
			continue;
		if (!((res->flags ^ r->flags) & IORESOURCE_PREFETCH))
			return r;
		if (r->flags & IORESOURCE_PREFETCH)
			continue;
		if (!best)
			best = r;
	}
	return best;
}