mirror of
https://mirrors.bfsu.edu.cn/git/linux.git
synced 2024-11-11 21:38:32 +08:00
PCI : ability to relocate assigned pci-resources
Currently pci-bridges are allocated enough resources to satisfy their immediate requirements. Any additional resource-requests fail if additional free space, contiguous to the one already allocated, is not available. This behavior is not reasonable since sufficient contiguous resources, that can satisfy the request, are available at a different location. This patch provides the ability to expand and relocate a allocated resource. v2: Changelog: Fixed size calculation in pci_reassign_resource() v3: Changelog : Split this patch. The resource.c changes are already upstream. All the pci driver changes are in here. Signed-off-by: Ram Pai <linuxram@us.ibm.com> Signed-off-by: Jesse Barnes <jbarnes@virtuousgeek.org>
This commit is contained in:
parent
be768912a4
commit
2bbc694227
@ -34,6 +34,7 @@ struct resource_list_x {
|
|||||||
resource_size_t start;
|
resource_size_t start;
|
||||||
resource_size_t end;
|
resource_size_t end;
|
||||||
resource_size_t add_size;
|
resource_size_t add_size;
|
||||||
|
resource_size_t min_align;
|
||||||
unsigned long flags;
|
unsigned long flags;
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -65,7 +66,7 @@ void pci_realloc(void)
|
|||||||
*/
|
*/
|
||||||
static void add_to_list(struct resource_list_x *head,
|
static void add_to_list(struct resource_list_x *head,
|
||||||
struct pci_dev *dev, struct resource *res,
|
struct pci_dev *dev, struct resource *res,
|
||||||
resource_size_t add_size)
|
resource_size_t add_size, resource_size_t min_align)
|
||||||
{
|
{
|
||||||
struct resource_list_x *list = head;
|
struct resource_list_x *list = head;
|
||||||
struct resource_list_x *ln = list->next;
|
struct resource_list_x *ln = list->next;
|
||||||
@ -84,13 +85,16 @@ static void add_to_list(struct resource_list_x *head,
|
|||||||
tmp->end = res->end;
|
tmp->end = res->end;
|
||||||
tmp->flags = res->flags;
|
tmp->flags = res->flags;
|
||||||
tmp->add_size = add_size;
|
tmp->add_size = add_size;
|
||||||
|
tmp->min_align = min_align;
|
||||||
list->next = tmp;
|
list->next = tmp;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void add_to_failed_list(struct resource_list_x *head,
|
static void add_to_failed_list(struct resource_list_x *head,
|
||||||
struct pci_dev *dev, struct resource *res)
|
struct pci_dev *dev, struct resource *res)
|
||||||
{
|
{
|
||||||
add_to_list(head, dev, res, 0);
|
add_to_list(head, dev, res,
|
||||||
|
0 /* dont care */,
|
||||||
|
0 /* dont care */);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void __dev_sort_resources(struct pci_dev *dev,
|
static void __dev_sort_resources(struct pci_dev *dev,
|
||||||
@ -159,13 +163,16 @@ static void adjust_resources_sorted(struct resource_list_x *add_head,
|
|||||||
|
|
||||||
idx = res - &list->dev->resource[0];
|
idx = res - &list->dev->resource[0];
|
||||||
add_size=list->add_size;
|
add_size=list->add_size;
|
||||||
if (!resource_size(res) && add_size) {
|
if (!resource_size(res)) {
|
||||||
res->end = res->start + add_size - 1;
|
res->end = res->start + add_size - 1;
|
||||||
if(pci_assign_resource(list->dev, idx))
|
if(pci_assign_resource(list->dev, idx))
|
||||||
reset_resource(res);
|
reset_resource(res);
|
||||||
} else if (add_size) {
|
} else {
|
||||||
adjust_resource(res, res->start,
|
resource_size_t align = list->min_align;
|
||||||
resource_size(res) + add_size);
|
res->flags |= list->flags & (IORESOURCE_STARTALIGN|IORESOURCE_SIZEALIGN);
|
||||||
|
if (pci_reassign_resource(list->dev, idx, add_size, align))
|
||||||
|
dev_printk(KERN_DEBUG, &list->dev->dev, "failed to add optional resources res=%pR\n",
|
||||||
|
res);
|
||||||
}
|
}
|
||||||
out:
|
out:
|
||||||
tmp = list;
|
tmp = list;
|
||||||
@ -619,7 +626,7 @@ static void pbus_size_io(struct pci_bus *bus, resource_size_t min_size,
|
|||||||
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 && add_head)
|
||||||
add_to_list(add_head, bus->self, b_res, size1-size0);
|
add_to_list(add_head, bus->self, b_res, size1-size0, 4096);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -722,7 +729,7 @@ static int pbus_size_mem(struct pci_bus *bus, unsigned long mask,
|
|||||||
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 && add_head)
|
||||||
add_to_list(add_head, bus->self, b_res, size1-size0);
|
add_to_list(add_head, bus->self, b_res, size1-size0, min_align);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -128,16 +128,16 @@ void pci_disable_bridge_window(struct pci_dev *dev)
|
|||||||
}
|
}
|
||||||
#endif /* CONFIG_PCI_QUIRKS */
|
#endif /* CONFIG_PCI_QUIRKS */
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
static int __pci_assign_resource(struct pci_bus *bus, struct pci_dev *dev,
|
static int __pci_assign_resource(struct pci_bus *bus, struct pci_dev *dev,
|
||||||
int resno)
|
int resno, resource_size_t size, resource_size_t align)
|
||||||
{
|
{
|
||||||
struct resource *res = dev->resource + resno;
|
struct resource *res = dev->resource + resno;
|
||||||
resource_size_t size, min, align;
|
resource_size_t min;
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
size = resource_size(res);
|
|
||||||
min = (res->flags & IORESOURCE_IO) ? PCIBIOS_MIN_IO : PCIBIOS_MIN_MEM;
|
min = (res->flags & IORESOURCE_IO) ? PCIBIOS_MIN_IO : PCIBIOS_MIN_MEM;
|
||||||
align = pci_resource_alignment(dev, res);
|
|
||||||
|
|
||||||
/* First, try exact prefetching match.. */
|
/* First, try exact prefetching match.. */
|
||||||
ret = pci_bus_alloc_resource(bus, res, size, align, min,
|
ret = pci_bus_alloc_resource(bus, res, size, align, min,
|
||||||
@ -154,16 +154,15 @@ static int __pci_assign_resource(struct pci_bus *bus, struct pci_dev *dev,
|
|||||||
ret = pci_bus_alloc_resource(bus, res, size, align, min, 0,
|
ret = pci_bus_alloc_resource(bus, res, size, align, min, 0,
|
||||||
pcibios_align_resource, dev);
|
pcibios_align_resource, dev);
|
||||||
}
|
}
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
if (ret < 0 && dev->fw_addr[resno]) {
|
static int pci_revert_fw_address(struct resource *res, struct pci_dev *dev,
|
||||||
|
int resno, resource_size_t size)
|
||||||
|
{
|
||||||
struct resource *root, *conflict;
|
struct resource *root, *conflict;
|
||||||
resource_size_t start, end;
|
resource_size_t start, end;
|
||||||
|
int ret = 0;
|
||||||
/*
|
|
||||||
* If we failed to assign anything, let's try the address
|
|
||||||
* where firmware left it. That at least has a chance of
|
|
||||||
* working, which is better than just leaving it disabled.
|
|
||||||
*/
|
|
||||||
|
|
||||||
if (res->flags & IORESOURCE_IO)
|
if (res->flags & IORESOURCE_IO)
|
||||||
root = &ioport_resource;
|
root = &ioport_resource;
|
||||||
@ -183,44 +182,23 @@ static int __pci_assign_resource(struct pci_bus *bus, struct pci_dev *dev,
|
|||||||
res, conflict->name, conflict);
|
res, conflict->name, conflict);
|
||||||
res->start = start;
|
res->start = start;
|
||||||
res->end = end;
|
res->end = end;
|
||||||
} else
|
ret = 1;
|
||||||
ret = 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!ret) {
|
|
||||||
res->flags &= ~IORESOURCE_STARTALIGN;
|
|
||||||
dev_info(&dev->dev, "BAR %d: assigned %pR\n", resno, res);
|
|
||||||
if (resno < PCI_BRIDGE_RESOURCES)
|
|
||||||
pci_update_resource(dev, resno);
|
|
||||||
}
|
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
int pci_assign_resource(struct pci_dev *dev, int resno)
|
static int _pci_assign_resource(struct pci_dev *dev, int resno, int size, resource_size_t min_align)
|
||||||
{
|
{
|
||||||
struct resource *res = dev->resource + resno;
|
struct resource *res = dev->resource + resno;
|
||||||
resource_size_t align;
|
|
||||||
struct pci_bus *bus;
|
struct pci_bus *bus;
|
||||||
int ret;
|
int ret;
|
||||||
char *type;
|
char *type;
|
||||||
|
|
||||||
align = pci_resource_alignment(dev, res);
|
|
||||||
if (!align) {
|
|
||||||
dev_info(&dev->dev, "BAR %d: can't assign %pR "
|
|
||||||
"(bogus alignment)\n", resno, res);
|
|
||||||
return -EINVAL;
|
|
||||||
}
|
|
||||||
|
|
||||||
bus = dev->bus;
|
bus = dev->bus;
|
||||||
while ((ret = __pci_assign_resource(bus, dev, resno))) {
|
while ((ret = __pci_assign_resource(bus, dev, resno, size, min_align))) {
|
||||||
if (bus->parent && bus->self->transparent)
|
if (!bus->parent || !bus->self->transparent)
|
||||||
bus = bus->parent;
|
|
||||||
else
|
|
||||||
bus = NULL;
|
|
||||||
if (bus)
|
|
||||||
continue;
|
|
||||||
break;
|
break;
|
||||||
|
bus = bus->parent;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ret) {
|
if (ret) {
|
||||||
@ -241,6 +219,66 @@ int pci_assign_resource(struct pci_dev *dev, int resno)
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int pci_reassign_resource(struct pci_dev *dev, int resno, resource_size_t addsize,
|
||||||
|
resource_size_t min_align)
|
||||||
|
{
|
||||||
|
struct resource *res = dev->resource + resno;
|
||||||
|
resource_size_t new_size;
|
||||||
|
int ret;
|
||||||
|
|
||||||
|
if (!res->parent) {
|
||||||
|
dev_info(&dev->dev, "BAR %d: can't reassign an unassigned resouce %pR "
|
||||||
|
"\n", resno, res);
|
||||||
|
return -EINVAL;
|
||||||
|
}
|
||||||
|
|
||||||
|
new_size = resource_size(res) + addsize + min_align;
|
||||||
|
ret = _pci_assign_resource(dev, resno, new_size, min_align);
|
||||||
|
if (!ret) {
|
||||||
|
res->flags &= ~IORESOURCE_STARTALIGN;
|
||||||
|
dev_info(&dev->dev, "BAR %d: assigned %pR\n", resno, res);
|
||||||
|
if (resno < PCI_BRIDGE_RESOURCES)
|
||||||
|
pci_update_resource(dev, resno);
|
||||||
|
}
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
int pci_assign_resource(struct pci_dev *dev, int resno)
|
||||||
|
{
|
||||||
|
struct resource *res = dev->resource + resno;
|
||||||
|
resource_size_t align, size;
|
||||||
|
struct pci_bus *bus;
|
||||||
|
int ret;
|
||||||
|
|
||||||
|
align = pci_resource_alignment(dev, res);
|
||||||
|
if (!align) {
|
||||||
|
dev_info(&dev->dev, "BAR %d: can't assign %pR "
|
||||||
|
"(bogus alignment)\n", resno, res);
|
||||||
|
return -EINVAL;
|
||||||
|
}
|
||||||
|
|
||||||
|
bus = dev->bus;
|
||||||
|
size = resource_size(res);
|
||||||
|
ret = _pci_assign_resource(dev, resno, size, align);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* If we failed to assign anything, let's try the address
|
||||||
|
* where firmware left it. That at least has a chance of
|
||||||
|
* working, which is better than just leaving it disabled.
|
||||||
|
*/
|
||||||
|
if (ret < 0 && dev->fw_addr[resno])
|
||||||
|
ret = pci_revert_fw_address(res, dev, resno, size);
|
||||||
|
|
||||||
|
if (!ret) {
|
||||||
|
res->flags &= ~IORESOURCE_STARTALIGN;
|
||||||
|
dev_info(&dev->dev, "BAR %d: assigned %pR\n", resno, res);
|
||||||
|
if (resno < PCI_BRIDGE_RESOURCES)
|
||||||
|
pci_update_resource(dev, resno);
|
||||||
|
}
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/* Sort resources by alignment */
|
/* Sort resources by alignment */
|
||||||
void pdev_sort_resources(struct pci_dev *dev, struct resource_list *head)
|
void pdev_sort_resources(struct pci_dev *dev, struct resource_list *head)
|
||||||
{
|
{
|
||||||
|
@ -813,6 +813,7 @@ int __pci_reset_function(struct pci_dev *dev);
|
|||||||
int pci_reset_function(struct pci_dev *dev);
|
int pci_reset_function(struct pci_dev *dev);
|
||||||
void pci_update_resource(struct pci_dev *dev, int resno);
|
void pci_update_resource(struct pci_dev *dev, int resno);
|
||||||
int __must_check pci_assign_resource(struct pci_dev *dev, int i);
|
int __must_check pci_assign_resource(struct pci_dev *dev, int i);
|
||||||
|
int __must_check pci_reassign_resource(struct pci_dev *dev, int i, resource_size_t add_size, resource_size_t align);
|
||||||
int pci_select_bars(struct pci_dev *dev, unsigned long flags);
|
int pci_select_bars(struct pci_dev *dev, unsigned long flags);
|
||||||
|
|
||||||
/* ROM control related routines */
|
/* ROM control related routines */
|
||||||
|
Loading…
Reference in New Issue
Block a user