Skip to content

Commit d09ee96

Browse files
Yinghai Lujbarnes993
authored andcommitted
PCI: improve resource allocation under transparent bridges
We could run out of space under under 4g, but devices under transparent bridges can use 64bit resources, so keep trying on the parent bus until we hit a non-transparent bridge. Impact: better support for assigning unassigned resources Reviewed-by: Ivan Kokshaysky <ink@jurassic.park.msu.ru> Signed-off-by: Yinghai Lu <yinghai@kernel.org> Signed-off-by: Jesse Barnes <jbarnes@virtuousgeek.org>
1 parent 1f82de1 commit d09ee96

2 files changed

Lines changed: 36 additions & 14 deletions

File tree

‎drivers/pci/setup-bus.c‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,6 @@ static void pbus_assign_resources_sorted(const struct pci_bus *bus)
5858
res = list->res;
5959
idx = res - &list->dev->resource[0];
6060
if (pci_assign_resource(list->dev, idx)) {
61-
/* FIXME: get rid of this */
6261
res->start = 0;
6362
res->end = 0;
6463
res->flags = 0;

‎drivers/pci/setup-res.c‎

Lines changed: 36 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -135,23 +135,16 @@ void pci_disable_bridge_window(struct pci_dev *dev)
135135
}
136136
#endif /* CONFIG_PCI_QUIRKS */
137137

138-
int pci_assign_resource(struct pci_dev *dev, int resno)
138+
static int __pci_assign_resource(struct pci_bus *bus, struct pci_dev *dev,
139+
int resno)
139140
{
140-
struct pci_bus *bus = dev->bus;
141141
struct resource *res = dev->resource + resno;
142142
resource_size_t size, min, align;
143143
int ret;
144144

145145
size = resource_size(res);
146146
min = (res->flags & IORESOURCE_IO) ? PCIBIOS_MIN_IO : PCIBIOS_MIN_MEM;
147-
148147
align = resource_alignment(res);
149-
if (!align) {
150-
dev_info(&dev->dev, "BAR %d: can't allocate resource (bogus "
151-
"alignment) %pR flags %#lx\n",
152-
resno, res, res->flags);
153-
return -EINVAL;
154-
}
155148

156149
/* First, try exact prefetching match.. */
157150
ret = pci_bus_alloc_resource(bus, res, size, align, min,
@@ -169,10 +162,7 @@ int pci_assign_resource(struct pci_dev *dev, int resno)
169162
pcibios_align_resource, dev);
170163
}
171164

172-
if (ret) {
173-
dev_info(&dev->dev, "BAR %d: can't allocate %s resource %pR\n",
174-
resno, res->flags & IORESOURCE_IO ? "I/O" : "mem", res);
175-
} else {
165+
if (!ret) {
176166
res->flags &= ~IORESOURCE_STARTALIGN;
177167
if (resno < PCI_BRIDGE_RESOURCES)
178168
pci_update_resource(dev, resno);
@@ -181,6 +171,39 @@ int pci_assign_resource(struct pci_dev *dev, int resno)
181171
return ret;
182172
}
183173

174+
int pci_assign_resource(struct pci_dev *dev, int resno)
175+
{
176+
struct resource *res = dev->resource + resno;
177+
resource_size_t align;
178+
struct pci_bus *bus;
179+
int ret;
180+
181+
align = resource_alignment(res);
182+
if (!align) {
183+
dev_info(&dev->dev, "BAR %d: can't allocate resource (bogus "
184+
"alignment) %pR flags %#lx\n",
185+
resno, res, res->flags);
186+
return -EINVAL;
187+
}
188+
189+
bus = dev->bus;
190+
while ((ret = __pci_assign_resource(bus, dev, resno))) {
191+
if (bus->parent && bus->self->transparent)
192+
bus = bus->parent;
193+
else
194+
bus = NULL;
195+
if (bus)
196+
continue;
197+
break;
198+
}
199+
200+
if (ret)
201+
dev_info(&dev->dev, "BAR %d: can't allocate %s resource %pR\n",
202+
resno, res->flags & IORESOURCE_IO ? "I/O" : "mem", res);
203+
204+
return ret;
205+
}
206+
184207
#if 0
185208
int pci_assign_resource_fixed(struct pci_dev *dev, int resno)
186209
{

0 commit comments

Comments
 (0)