PCI: Use bridge window names (PCI_BRIDGE_IO_WINDOW etc)
Use bridge resource definitions instead of using the PCI_BRIDGE_RESOURCES constant with an integer offeset. Link: https://lore.kernel.org/r/20200520183411.1534621-2-kw@linux.com Signed-off-by: Krzysztof Wilczynski <kw@linux.com> Signed-off-by: Bjorn Helgaas <bhelgaas@google.com>
This commit is contained in:
Родитель
7b38fd9760
Коммит
6e0688dbff
|
@ -583,7 +583,7 @@ static void pci_setup_bridge_io(struct pci_dev *bridge)
|
|||
io_mask = PCI_IO_1K_RANGE_MASK;
|
||||
|
||||
/* Set up the top and bottom of the PCI I/O segment for this bus */
|
||||
res = &bridge->resource[PCI_BRIDGE_RESOURCES + 0];
|
||||
res = &bridge->resource[PCI_BRIDGE_IO_WINDOW];
|
||||
pcibios_resource_to_bus(bridge->bus, ®ion, res);
|
||||
if (res->flags & IORESOURCE_IO) {
|
||||
pci_read_config_word(bridge, PCI_IO_BASE, &l);
|
||||
|
@ -613,7 +613,7 @@ static void pci_setup_bridge_mmio(struct pci_dev *bridge)
|
|||
u32 l;
|
||||
|
||||
/* Set up the top and bottom of the PCI Memory segment for this bus */
|
||||
res = &bridge->resource[PCI_BRIDGE_RESOURCES + 1];
|
||||
res = &bridge->resource[PCI_BRIDGE_MEM_WINDOW];
|
||||
pcibios_resource_to_bus(bridge->bus, ®ion, res);
|
||||
if (res->flags & IORESOURCE_MEM) {
|
||||
l = (region.start >> 16) & 0xfff0;
|
||||
|
@ -640,7 +640,7 @@ static void pci_setup_bridge_mmio_pref(struct pci_dev *bridge)
|
|||
|
||||
/* Set up PREF base/limit */
|
||||
bu = lu = 0;
|
||||
res = &bridge->resource[PCI_BRIDGE_RESOURCES + 2];
|
||||
res = &bridge->resource[PCI_BRIDGE_PREF_MEM_WINDOW];
|
||||
pcibios_resource_to_bus(bridge->bus, ®ion, res);
|
||||
if (res->flags & IORESOURCE_PREFETCH) {
|
||||
l = (region.start >> 16) & 0xfff0;
|
||||
|
@ -707,14 +707,14 @@ int pci_claim_bridge_resource(struct pci_dev *bridge, int i)
|
|||
if (!pci_bus_clip_resource(bridge, i))
|
||||
return -EINVAL; /* Clipping didn't change anything */
|
||||
|
||||
switch (i - PCI_BRIDGE_RESOURCES) {
|
||||
case 0:
|
||||
switch (i) {
|
||||
case PCI_BRIDGE_IO_WINDOW:
|
||||
pci_setup_bridge_io(bridge);
|
||||
break;
|
||||
case 1:
|
||||
case PCI_BRIDGE_MEM_WINDOW:
|
||||
pci_setup_bridge_mmio(bridge);
|
||||
break;
|
||||
case 2:
|
||||
case PCI_BRIDGE_PREF_MEM_WINDOW:
|
||||
pci_setup_bridge_mmio_pref(bridge);
|
||||
break;
|
||||
default:
|
||||
|
@ -735,18 +735,22 @@ int pci_claim_bridge_resource(struct pci_dev *bridge, int i)
|
|||
static void pci_bridge_check_ranges(struct pci_bus *bus)
|
||||
{
|
||||
struct pci_dev *bridge = bus->self;
|
||||
struct resource *b_res = &bridge->resource[PCI_BRIDGE_RESOURCES];
|
||||
struct resource *b_res;
|
||||
|
||||
b_res[1].flags |= IORESOURCE_MEM;
|
||||
b_res = &bridge->resource[PCI_BRIDGE_MEM_WINDOW];
|
||||
b_res->flags |= IORESOURCE_MEM;
|
||||
|
||||
if (bridge->io_window)
|
||||
b_res[0].flags |= IORESOURCE_IO;
|
||||
if (bridge->io_window) {
|
||||
b_res = &bridge->resource[PCI_BRIDGE_IO_WINDOW];
|
||||
b_res->flags |= IORESOURCE_IO;
|
||||
}
|
||||
|
||||
if (bridge->pref_window) {
|
||||
b_res[2].flags |= IORESOURCE_MEM | IORESOURCE_PREFETCH;
|
||||
b_res = &bridge->resource[PCI_BRIDGE_PREF_MEM_WINDOW];
|
||||
b_res->flags |= IORESOURCE_MEM | IORESOURCE_PREFETCH;
|
||||
if (bridge->pref_64_window) {
|
||||
b_res[2].flags |= IORESOURCE_MEM_64;
|
||||
b_res[2].flags |= PCI_PREF_RANGE_TYPE_64;
|
||||
b_res->flags |= IORESOURCE_MEM_64 |
|
||||
PCI_PREF_RANGE_TYPE_64;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1105,35 +1109,37 @@ static void pci_bus_size_cardbus(struct pci_bus *bus,
|
|||
struct list_head *realloc_head)
|
||||
{
|
||||
struct pci_dev *bridge = bus->self;
|
||||
struct resource *b_res = &bridge->resource[PCI_BRIDGE_RESOURCES];
|
||||
struct resource *b_res;
|
||||
resource_size_t b_res_3_size = pci_cardbus_mem_size * 2;
|
||||
u16 ctrl;
|
||||
|
||||
if (b_res[0].parent)
|
||||
b_res = &bridge->resource[PCI_CB_BRIDGE_IO_0_WINDOW];
|
||||
if (b_res->parent)
|
||||
goto handle_b_res_1;
|
||||
/*
|
||||
* Reserve some resources for CardBus. We reserve a fixed amount
|
||||
* of bus space for CardBus bridges.
|
||||
*/
|
||||
b_res[0].start = pci_cardbus_io_size;
|
||||
b_res[0].end = b_res[0].start + pci_cardbus_io_size - 1;
|
||||
b_res[0].flags |= IORESOURCE_IO | IORESOURCE_STARTALIGN;
|
||||
b_res->start = pci_cardbus_io_size;
|
||||
b_res->end = b_res->start + pci_cardbus_io_size - 1;
|
||||
b_res->flags |= IORESOURCE_IO | IORESOURCE_STARTALIGN;
|
||||
if (realloc_head) {
|
||||
b_res[0].end -= pci_cardbus_io_size;
|
||||
b_res->end -= pci_cardbus_io_size;
|
||||
add_to_list(realloc_head, bridge, b_res, pci_cardbus_io_size,
|
||||
pci_cardbus_io_size);
|
||||
pci_cardbus_io_size);
|
||||
}
|
||||
|
||||
handle_b_res_1:
|
||||
if (b_res[1].parent)
|
||||
b_res = &bridge->resource[PCI_CB_BRIDGE_IO_1_WINDOW];
|
||||
if (b_res->parent)
|
||||
goto handle_b_res_2;
|
||||
b_res[1].start = pci_cardbus_io_size;
|
||||
b_res[1].end = b_res[1].start + pci_cardbus_io_size - 1;
|
||||
b_res[1].flags |= IORESOURCE_IO | IORESOURCE_STARTALIGN;
|
||||
b_res->start = pci_cardbus_io_size;
|
||||
b_res->end = b_res->start + pci_cardbus_io_size - 1;
|
||||
b_res->flags |= IORESOURCE_IO | IORESOURCE_STARTALIGN;
|
||||
if (realloc_head) {
|
||||
b_res[1].end -= pci_cardbus_io_size;
|
||||
add_to_list(realloc_head, bridge, b_res+1, pci_cardbus_io_size,
|
||||
pci_cardbus_io_size);
|
||||
b_res->end -= pci_cardbus_io_size;
|
||||
add_to_list(realloc_head, bridge, b_res, pci_cardbus_io_size,
|
||||
pci_cardbus_io_size);
|
||||
}
|
||||
|
||||
handle_b_res_2:
|
||||
|
@ -1153,21 +1159,22 @@ handle_b_res_2:
|
|||
pci_read_config_word(bridge, PCI_CB_BRIDGE_CONTROL, &ctrl);
|
||||
}
|
||||
|
||||
if (b_res[2].parent)
|
||||
b_res = &bridge->resource[PCI_CB_BRIDGE_MEM_0_WINDOW];
|
||||
if (b_res->parent)
|
||||
goto handle_b_res_3;
|
||||
/*
|
||||
* If we have prefetchable memory support, allocate two regions.
|
||||
* Otherwise, allocate one region of twice the size.
|
||||
*/
|
||||
if (ctrl & PCI_CB_BRIDGE_CTL_PREFETCH_MEM0) {
|
||||
b_res[2].start = pci_cardbus_mem_size;
|
||||
b_res[2].end = b_res[2].start + pci_cardbus_mem_size - 1;
|
||||
b_res[2].flags |= IORESOURCE_MEM | IORESOURCE_PREFETCH |
|
||||
IORESOURCE_STARTALIGN;
|
||||
b_res->start = pci_cardbus_mem_size;
|
||||
b_res->end = b_res->start + pci_cardbus_mem_size - 1;
|
||||
b_res->flags |= IORESOURCE_MEM | IORESOURCE_PREFETCH |
|
||||
IORESOURCE_STARTALIGN;
|
||||
if (realloc_head) {
|
||||
b_res[2].end -= pci_cardbus_mem_size;
|
||||
add_to_list(realloc_head, bridge, b_res+2,
|
||||
pci_cardbus_mem_size, pci_cardbus_mem_size);
|
||||
b_res->end -= pci_cardbus_mem_size;
|
||||
add_to_list(realloc_head, bridge, b_res,
|
||||
pci_cardbus_mem_size, pci_cardbus_mem_size);
|
||||
}
|
||||
|
||||
/* Reduce that to half */
|
||||
|
@ -1175,15 +1182,16 @@ handle_b_res_2:
|
|||
}
|
||||
|
||||
handle_b_res_3:
|
||||
if (b_res[3].parent)
|
||||
b_res = &bridge->resource[PCI_CB_BRIDGE_MEM_1_WINDOW];
|
||||
if (b_res->parent)
|
||||
goto handle_done;
|
||||
b_res[3].start = pci_cardbus_mem_size;
|
||||
b_res[3].end = b_res[3].start + b_res_3_size - 1;
|
||||
b_res[3].flags |= IORESOURCE_MEM | IORESOURCE_STARTALIGN;
|
||||
b_res->start = pci_cardbus_mem_size;
|
||||
b_res->end = b_res->start + b_res_3_size - 1;
|
||||
b_res->flags |= IORESOURCE_MEM | IORESOURCE_STARTALIGN;
|
||||
if (realloc_head) {
|
||||
b_res[3].end -= b_res_3_size;
|
||||
add_to_list(realloc_head, bridge, b_res+3, b_res_3_size,
|
||||
pci_cardbus_mem_size);
|
||||
b_res->end -= b_res_3_size;
|
||||
add_to_list(realloc_head, bridge, b_res, b_res_3_size,
|
||||
pci_cardbus_mem_size);
|
||||
}
|
||||
|
||||
handle_done:
|
||||
|
@ -1227,7 +1235,7 @@ void __pci_bus_size_bridges(struct pci_bus *bus, struct list_head *realloc_head)
|
|||
break;
|
||||
hdr_type = -1; /* Intentionally invalid - not a PCI device. */
|
||||
} else {
|
||||
pref = &bus->self->resource[PCI_BRIDGE_RESOURCES + 2];
|
||||
pref = &bus->self->resource[PCI_BRIDGE_PREF_MEM_WINDOW];
|
||||
hdr_type = bus->self->hdr_type;
|
||||
}
|
||||
|
||||
|
@ -1885,9 +1893,9 @@ static void pci_bus_distribute_available_resources(struct pci_bus *bus,
|
|||
struct pci_dev *dev, *bridge = bus->self;
|
||||
resource_size_t io_per_hp, mmio_per_hp, mmio_pref_per_hp, align;
|
||||
|
||||
io_res = &bridge->resource[PCI_BRIDGE_RESOURCES + 0];
|
||||
mmio_res = &bridge->resource[PCI_BRIDGE_RESOURCES + 1];
|
||||
mmio_pref_res = &bridge->resource[PCI_BRIDGE_RESOURCES + 2];
|
||||
io_res = &bridge->resource[PCI_BRIDGE_IO_WINDOW];
|
||||
mmio_res = &bridge->resource[PCI_BRIDGE_MEM_WINDOW];
|
||||
mmio_pref_res = &bridge->resource[PCI_BRIDGE_PREF_MEM_WINDOW];
|
||||
|
||||
/*
|
||||
* The alignment of this bridge is yet to be considered, hence it must
|
||||
|
@ -1960,21 +1968,21 @@ static void pci_bus_distribute_available_resources(struct pci_bus *bus,
|
|||
* Reduce the available resource space by what the
|
||||
* bridge and devices below it occupy.
|
||||
*/
|
||||
res = &dev->resource[PCI_BRIDGE_RESOURCES + 0];
|
||||
res = &dev->resource[PCI_BRIDGE_IO_WINDOW];
|
||||
align = pci_resource_alignment(dev, res);
|
||||
align = align ? ALIGN(io.start, align) - io.start : 0;
|
||||
used_size = align + resource_size(res);
|
||||
if (!res->parent)
|
||||
io.start = min(io.start + used_size, io.end + 1);
|
||||
|
||||
res = &dev->resource[PCI_BRIDGE_RESOURCES + 1];
|
||||
res = &dev->resource[PCI_BRIDGE_MEM_WINDOW];
|
||||
align = pci_resource_alignment(dev, res);
|
||||
align = align ? ALIGN(mmio.start, align) - mmio.start : 0;
|
||||
used_size = align + resource_size(res);
|
||||
if (!res->parent)
|
||||
mmio.start = min(mmio.start + used_size, mmio.end + 1);
|
||||
|
||||
res = &dev->resource[PCI_BRIDGE_RESOURCES + 2];
|
||||
res = &dev->resource[PCI_BRIDGE_PREF_MEM_WINDOW];
|
||||
align = pci_resource_alignment(dev, res);
|
||||
align = align ? ALIGN(mmio_pref.start, align) -
|
||||
mmio_pref.start : 0;
|
||||
|
@ -2027,9 +2035,9 @@ static void pci_bridge_distribute_available_resources(struct pci_dev *bridge,
|
|||
return;
|
||||
|
||||
/* Take the initial extra resources from the hotplug port */
|
||||
available_io = bridge->resource[PCI_BRIDGE_RESOURCES + 0];
|
||||
available_mmio = bridge->resource[PCI_BRIDGE_RESOURCES + 1];
|
||||
available_mmio_pref = bridge->resource[PCI_BRIDGE_RESOURCES + 2];
|
||||
available_io = bridge->resource[PCI_BRIDGE_IO_WINDOW];
|
||||
available_mmio = bridge->resource[PCI_BRIDGE_MEM_WINDOW];
|
||||
available_mmio_pref = bridge->resource[PCI_BRIDGE_PREF_MEM_WINDOW];
|
||||
|
||||
pci_bus_distribute_available_resources(bridge->subordinate,
|
||||
add_list, available_io,
|
||||
|
|
|
@ -694,7 +694,7 @@ static int yenta_allocate_res(struct yenta_socket *socket, int nr, unsigned type
|
|||
struct pci_bus_region region;
|
||||
unsigned mask;
|
||||
|
||||
res = dev->resource + PCI_BRIDGE_RESOURCES + nr;
|
||||
res = &dev->resource[nr];
|
||||
/* Already allocated? */
|
||||
if (res->parent)
|
||||
return 0;
|
||||
|
@ -711,7 +711,7 @@ static int yenta_allocate_res(struct yenta_socket *socket, int nr, unsigned type
|
|||
region.end = config_readl(socket, addr_end) | ~mask;
|
||||
if (region.start && region.end > region.start && !override_bios) {
|
||||
pcibios_bus_to_resource(dev->bus, res, ®ion);
|
||||
if (pci_claim_resource(dev, PCI_BRIDGE_RESOURCES + nr) == 0)
|
||||
if (pci_claim_resource(dev, nr) == 0)
|
||||
return 0;
|
||||
dev_info(&dev->dev,
|
||||
"Preassigned resource %d busy or not available, reconfiguring...\n",
|
||||
|
@ -751,13 +751,17 @@ static int yenta_allocate_res(struct yenta_socket *socket, int nr, unsigned type
|
|||
static void yenta_allocate_resources(struct yenta_socket *socket)
|
||||
{
|
||||
int program = 0;
|
||||
program += yenta_allocate_res(socket, 0, IORESOURCE_IO,
|
||||
program += yenta_allocate_res(socket, PCI_CB_BRIDGE_IO_0_WINDOW,
|
||||
IORESOURCE_IO,
|
||||
PCI_CB_IO_BASE_0, PCI_CB_IO_LIMIT_0);
|
||||
program += yenta_allocate_res(socket, 1, IORESOURCE_IO,
|
||||
program += yenta_allocate_res(socket, PCI_CB_BRIDGE_IO_1_WINDOW,
|
||||
IORESOURCE_IO,
|
||||
PCI_CB_IO_BASE_1, PCI_CB_IO_LIMIT_1);
|
||||
program += yenta_allocate_res(socket, 2, IORESOURCE_MEM|IORESOURCE_PREFETCH,
|
||||
program += yenta_allocate_res(socket, PCI_CB_BRIDGE_MEM_0_WINDOW,
|
||||
IORESOURCE_MEM | IORESOURCE_PREFETCH,
|
||||
PCI_CB_MEMORY_BASE_0, PCI_CB_MEMORY_LIMIT_0);
|
||||
program += yenta_allocate_res(socket, 3, IORESOURCE_MEM,
|
||||
program += yenta_allocate_res(socket, PCI_CB_BRIDGE_MEM_1_WINDOW,
|
||||
IORESOURCE_MEM,
|
||||
PCI_CB_MEMORY_BASE_1, PCI_CB_MEMORY_LIMIT_1);
|
||||
if (program)
|
||||
pci_setup_cardbus(socket->dev->subordinate);
|
||||
|
|
|
@ -100,9 +100,21 @@ enum {
|
|||
PCI_IOV_RESOURCE_END = PCI_IOV_RESOURCES + PCI_SRIOV_NUM_BARS - 1,
|
||||
#endif
|
||||
|
||||
/* Resources assigned to buses behind the bridge */
|
||||
/* PCI-to-PCI (P2P) bridge windows */
|
||||
#define PCI_BRIDGE_IO_WINDOW (PCI_BRIDGE_RESOURCES + 0)
|
||||
#define PCI_BRIDGE_MEM_WINDOW (PCI_BRIDGE_RESOURCES + 1)
|
||||
#define PCI_BRIDGE_PREF_MEM_WINDOW (PCI_BRIDGE_RESOURCES + 2)
|
||||
|
||||
/* CardBus bridge windows */
|
||||
#define PCI_CB_BRIDGE_IO_0_WINDOW (PCI_BRIDGE_RESOURCES + 0)
|
||||
#define PCI_CB_BRIDGE_IO_1_WINDOW (PCI_BRIDGE_RESOURCES + 1)
|
||||
#define PCI_CB_BRIDGE_MEM_0_WINDOW (PCI_BRIDGE_RESOURCES + 2)
|
||||
#define PCI_CB_BRIDGE_MEM_1_WINDOW (PCI_BRIDGE_RESOURCES + 3)
|
||||
|
||||
/* Total number of bridge resources for P2P and CardBus */
|
||||
#define PCI_BRIDGE_RESOURCE_NUM 4
|
||||
|
||||
/* Resources assigned to buses behind the bridge */
|
||||
PCI_BRIDGE_RESOURCES,
|
||||
PCI_BRIDGE_RESOURCE_END = PCI_BRIDGE_RESOURCES +
|
||||
PCI_BRIDGE_RESOURCE_NUM - 1,
|
||||
|
|
Загрузка…
Ссылка в новой задаче