Skip to content

Commit d56dbf5

Browse files
Yinghai Lubjorn-helgaas
Yinghai Lu
authored andcommitted
PCI: Allocate 64-bit BARs above 4G when possible
Try to allocate space for 64-bit BARs above 4G first, to preserve the space below 4G for 32-bit BARs. If there's no space above 4G available, fall back to allocating anywhere. [bhelgaas: reworked starting from http://lkml.kernel.org/r/[email protected]] Signed-off-by: Yinghai Lu <[email protected]> Signed-off-by: Bjorn Helgaas <[email protected]>
1 parent f75b99d commit d56dbf5

File tree

1 file changed

+13
-3
lines changed

1 file changed

+13
-3
lines changed

drivers/pci/bus.c

+13-3
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,8 @@ static struct pci_bus_region pci_32_bit = {0, 0xffffffffULL};
102102
#ifdef CONFIG_ARCH_DMA_ADDR_T_64BIT
103103
static struct pci_bus_region pci_64_bit = {0,
104104
(dma_addr_t) 0xffffffffffffffffULL};
105+
static struct pci_bus_region pci_high = {(dma_addr_t) 0x100000000ULL,
106+
(dma_addr_t) 0xffffffffffffffffULL};
105107
#endif
106108

107109
/*
@@ -198,8 +200,7 @@ static int pci_bus_alloc_from_region(struct pci_bus *bus, struct resource *res,
198200
* alignment and type, try to find an acceptable resource allocation
199201
* for a specific device resource.
200202
*/
201-
int
202-
pci_bus_alloc_resource(struct pci_bus *bus, struct resource *res,
203+
int pci_bus_alloc_resource(struct pci_bus *bus, struct resource *res,
203204
resource_size_t size, resource_size_t align,
204205
resource_size_t min, unsigned int type_mask,
205206
resource_size_t (*alignf)(void *,
@@ -209,10 +210,19 @@ pci_bus_alloc_resource(struct pci_bus *bus, struct resource *res,
209210
void *alignf_data)
210211
{
211212
#ifdef CONFIG_ARCH_DMA_ADDR_T_64BIT
212-
if (res->flags & IORESOURCE_MEM_64)
213+
int rc;
214+
215+
if (res->flags & IORESOURCE_MEM_64) {
216+
rc = pci_bus_alloc_from_region(bus, res, size, align, min,
217+
type_mask, alignf, alignf_data,
218+
&pci_high);
219+
if (rc == 0)
220+
return 0;
221+
213222
return pci_bus_alloc_from_region(bus, res, size, align, min,
214223
type_mask, alignf, alignf_data,
215224
&pci_64_bit);
225+
}
216226
#endif
217227

218228
return pci_bus_alloc_from_region(bus, res, size, align, min,

0 commit comments

Comments
 (0)