Skip to content

Commit f3170e6

Browse files
jgunthorpegregkh
authored andcommitted
PCI: mvebu: Handle changes to the bridge windows while enabled
[ Upstream commit d9bf28e2650fe3eeefed7e34841aea07d10c6543 ] The PCI core will write to the bridge window config multiple times while they are enabled. This can lead to mbus failures like this: mvebu_mbus: cannot add window '4:e8', conflicts with another window mvebu-pcie mbus:pex@e0000000: Could not create MBus window at [mem 0xe0000000-0xe00fffff]: -22 For me this is happening during a hotplug cycle. The PCI core is not changing the values, just writing them twice while active. The patch addresses the general case of any change to an active window, but not atomically. The code is slightly refactored so io and mem can share more of the window logic. Signed-off-by: Jason Gunthorpe <jgunthorpe@obsidianresearch.com> Signed-off-by: Bjorn Helgaas <bhelgaas@google.com> Acked-by: Jason Cooper <jason@lakedaemon.net> Signed-off-by: Sasha Levin <alexander.levin@verizon.com> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent 414aa11 commit f3170e6

1 file changed

Lines changed: 60 additions & 41 deletions

File tree

drivers/pci/host/pci-mvebu.c

Lines changed: 60 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,12 @@ struct mvebu_pcie {
131131
int nports;
132132
};
133133

134+
struct mvebu_pcie_window {
135+
phys_addr_t base;
136+
phys_addr_t remap;
137+
size_t size;
138+
};
139+
134140
/* Structure representing one PCIe interface */
135141
struct mvebu_pcie_port {
136142
char *name;
@@ -148,10 +154,8 @@ struct mvebu_pcie_port {
148154
struct mvebu_sw_pci_bridge bridge;
149155
struct device_node *dn;
150156
struct mvebu_pcie *pcie;
151-
phys_addr_t memwin_base;
152-
size_t memwin_size;
153-
phys_addr_t iowin_base;
154-
size_t iowin_size;
157+
struct mvebu_pcie_window memwin;
158+
struct mvebu_pcie_window iowin;
155159
u32 saved_pcie_stat;
156160
};
157161

@@ -377,23 +381,45 @@ static void mvebu_pcie_add_windows(struct mvebu_pcie_port *port,
377381
}
378382
}
379383

384+
static void mvebu_pcie_set_window(struct mvebu_pcie_port *port,
385+
unsigned int target, unsigned int attribute,
386+
const struct mvebu_pcie_window *desired,
387+
struct mvebu_pcie_window *cur)
388+
{
389+
if (desired->base == cur->base && desired->remap == cur->remap &&
390+
desired->size == cur->size)
391+
return;
392+
393+
if (cur->size != 0) {
394+
mvebu_pcie_del_windows(port, cur->base, cur->size);
395+
cur->size = 0;
396+
cur->base = 0;
397+
398+
/*
399+
* If something tries to change the window while it is enabled
400+
* the change will not be done atomically. That would be
401+
* difficult to do in the general case.
402+
*/
403+
}
404+
405+
if (desired->size == 0)
406+
return;
407+
408+
mvebu_pcie_add_windows(port, target, attribute, desired->base,
409+
desired->size, desired->remap);
410+
*cur = *desired;
411+
}
412+
380413
static void mvebu_pcie_handle_iobase_change(struct mvebu_pcie_port *port)
381414
{
382-
phys_addr_t iobase;
415+
struct mvebu_pcie_window desired = {};
383416

384417
/* Are the new iobase/iolimit values invalid? */
385418
if (port->bridge.iolimit < port->bridge.iobase ||
386419
port->bridge.iolimitupper < port->bridge.iobaseupper ||
387420
!(port->bridge.command & PCI_COMMAND_IO)) {
388-
389-
/* If a window was configured, remove it */
390-
if (port->iowin_base) {
391-
mvebu_pcie_del_windows(port, port->iowin_base,
392-
port->iowin_size);
393-
port->iowin_base = 0;
394-
port->iowin_size = 0;
395-
}
396-
421+
mvebu_pcie_set_window(port, port->io_target, port->io_attr,
422+
&desired, &port->iowin);
397423
return;
398424
}
399425

@@ -410,32 +436,27 @@ static void mvebu_pcie_handle_iobase_change(struct mvebu_pcie_port *port)
410436
* specifications. iobase is the bus address, port->iowin_base
411437
* is the CPU address.
412438
*/
413-
iobase = ((port->bridge.iobase & 0xF0) << 8) |
414-
(port->bridge.iobaseupper << 16);
415-
port->iowin_base = port->pcie->io.start + iobase;
416-
port->iowin_size = ((0xFFF | ((port->bridge.iolimit & 0xF0) << 8) |
417-
(port->bridge.iolimitupper << 16)) -
418-
iobase) + 1;
419-
420-
mvebu_pcie_add_windows(port, port->io_target, port->io_attr,
421-
port->iowin_base, port->iowin_size,
422-
iobase);
439+
desired.remap = ((port->bridge.iobase & 0xF0) << 8) |
440+
(port->bridge.iobaseupper << 16);
441+
desired.base = port->pcie->io.start + desired.remap;
442+
desired.size = ((0xFFF | ((port->bridge.iolimit & 0xF0) << 8) |
443+
(port->bridge.iolimitupper << 16)) -
444+
desired.remap) +
445+
1;
446+
447+
mvebu_pcie_set_window(port, port->io_target, port->io_attr, &desired,
448+
&port->iowin);
423449
}
424450

425451
static void mvebu_pcie_handle_membase_change(struct mvebu_pcie_port *port)
426452
{
453+
struct mvebu_pcie_window desired = {.remap = MVEBU_MBUS_NO_REMAP};
454+
427455
/* Are the new membase/memlimit values invalid? */
428456
if (port->bridge.memlimit < port->bridge.membase ||
429457
!(port->bridge.command & PCI_COMMAND_MEMORY)) {
430-
431-
/* If a window was configured, remove it */
432-
if (port->memwin_base) {
433-
mvebu_pcie_del_windows(port, port->memwin_base,
434-
port->memwin_size);
435-
port->memwin_base = 0;
436-
port->memwin_size = 0;
437-
}
438-
458+
mvebu_pcie_set_window(port, port->mem_target, port->mem_attr,
459+
&desired, &port->memwin);
439460
return;
440461
}
441462

@@ -445,14 +466,12 @@ static void mvebu_pcie_handle_membase_change(struct mvebu_pcie_port *port)
445466
* window to setup, according to the PCI-to-PCI bridge
446467
* specifications.
447468
*/
448-
port->memwin_base = ((port->bridge.membase & 0xFFF0) << 16);
449-
port->memwin_size =
450-
(((port->bridge.memlimit & 0xFFF0) << 16) | 0xFFFFF) -
451-
port->memwin_base + 1;
452-
453-
mvebu_pcie_add_windows(port, port->mem_target, port->mem_attr,
454-
port->memwin_base, port->memwin_size,
455-
MVEBU_MBUS_NO_REMAP);
469+
desired.base = ((port->bridge.membase & 0xFFF0) << 16);
470+
desired.size = (((port->bridge.memlimit & 0xFFF0) << 16) | 0xFFFFF) -
471+
desired.base + 1;
472+
473+
mvebu_pcie_set_window(port, port->mem_target, port->mem_attr, &desired,
474+
&port->memwin);
456475
}
457476

458477
/*

0 commit comments

Comments
 (0)