Skip to content

Commit fe7498e

Browse files
parakabjorn-helgaas
authored andcommitted
PCI: mt7621: Move MIPS setup to pcibios_root_bridge_prepare()
On the MIPS ralink mt7621 platform, we need to set up I/O coherency units based on the host bridge apertures. To remove this arch dependency from the driver itself, move the coherency setup from the driver to pcibios_root_bridge_prepare(). [bhelgaas: squash add/remove into one patch, commit log] Link: https://lore.kernel.org/r/[email protected] Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Sergio Paracuellos <[email protected]> Signed-off-by: Bjorn Helgaas <[email protected]> Reviewed-by: Guenter Roeck <[email protected]> # arch/mips Acked-by: Thomas Bogendoerfer <[email protected]> # arch/mips
1 parent 661c4c4 commit fe7498e

File tree

2 files changed

+31
-37
lines changed

2 files changed

+31
-37
lines changed

arch/mips/ralink/mt7621.c

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
#include <linux/slab.h>
1111
#include <linux/sys_soc.h>
1212
#include <linux/memblock.h>
13+
#include <linux/pci.h>
14+
#include <linux/bug.h>
1315

1416
#include <asm/bootinfo.h>
1517
#include <asm/mipsregs.h>
@@ -22,6 +24,35 @@
2224

2325
static void *detect_magic __initdata = detect_memory_region;
2426

27+
int pcibios_root_bridge_prepare(struct pci_host_bridge *bridge)
28+
{
29+
struct resource_entry *entry;
30+
resource_size_t mask;
31+
32+
entry = resource_list_first_type(&bridge->windows, IORESOURCE_MEM);
33+
if (!entry) {
34+
pr_err("Cannot get memory resource\n");
35+
return -EINVAL;
36+
}
37+
38+
if (mips_cps_numiocu(0)) {
39+
/*
40+
* Hardware doesn't accept mask values with 1s after
41+
* 0s (e.g. 0xffef), so warn if that's happen
42+
*/
43+
mask = ~(entry->res->end - entry->res->start) & CM_GCR_REGn_MASK_ADDRMASK;
44+
WARN_ON(mask && BIT(ffz(~mask)) - 1 != ~mask);
45+
46+
write_gcr_reg1_base(entry->res->start);
47+
write_gcr_reg1_mask(mask | CM_GCR_REGn_MASK_CMTGT_IOCU0);
48+
pr_info("PCI coherence region base: 0x%08llx, mask/settings: 0x%08llx\n",
49+
(unsigned long long)read_gcr_reg1_base(),
50+
(unsigned long long)read_gcr_reg1_mask());
51+
}
52+
53+
return 0;
54+
}
55+
2556
phys_addr_t mips_cpc_default_phys_base(void)
2657
{
2758
panic("Cannot detect cpc address");

drivers/pci/controller/pcie-mt7621.c

Lines changed: 0 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -208,37 +208,6 @@ static inline void mt7621_control_deassert(struct mt7621_pcie_port *port)
208208
reset_control_assert(port->pcie_rst);
209209
}
210210

211-
static int setup_cm_memory_region(struct pci_host_bridge *host)
212-
{
213-
struct mt7621_pcie *pcie = pci_host_bridge_priv(host);
214-
struct device *dev = pcie->dev;
215-
struct resource_entry *entry;
216-
resource_size_t mask;
217-
218-
entry = resource_list_first_type(&host->windows, IORESOURCE_MEM);
219-
if (!entry) {
220-
dev_err(dev, "cannot get memory resource\n");
221-
return -EINVAL;
222-
}
223-
224-
if (mips_cps_numiocu(0)) {
225-
/*
226-
* FIXME: hardware doesn't accept mask values with 1s after
227-
* 0s (e.g. 0xffef), so it would be great to warn if that's
228-
* about to happen
229-
*/
230-
mask = ~(entry->res->end - entry->res->start);
231-
232-
write_gcr_reg1_base(entry->res->start);
233-
write_gcr_reg1_mask(mask | CM_GCR_REGn_MASK_CMTGT_IOCU0);
234-
dev_info(dev, "PCI coherence region base: 0x%08llx, mask/settings: 0x%08llx\n",
235-
(unsigned long long)read_gcr_reg1_base(),
236-
(unsigned long long)read_gcr_reg1_mask());
237-
}
238-
239-
return 0;
240-
}
241-
242211
static int mt7621_pcie_parse_port(struct mt7621_pcie *pcie,
243212
struct device_node *node,
244213
int slot)
@@ -557,12 +526,6 @@ static int mt7621_pci_probe(struct platform_device *pdev)
557526
goto remove_resets;
558527
}
559528

560-
err = setup_cm_memory_region(bridge);
561-
if (err) {
562-
dev_err(dev, "error setting up iocu mem regions\n");
563-
goto remove_resets;
564-
}
565-
566529
return mt7621_pcie_register_host(bridge);
567530

568531
remove_resets:

0 commit comments

Comments
 (0)