Skip to content

Commit 34642bb

Browse files
committed
powerpc/fsl-pci: Keep PCI SoC controller registers in pci_controller
Move to keeping the SoC registers that control and config the PCI controllers on FSL SoCs in the pci_controller struct. This allows us to not need to ioremap() the registers in multiple different places that use them. Signed-off-by: Kumar Gala <[email protected]>
1 parent 9f4c350 commit 34642bb

File tree

2 files changed

+34
-40
lines changed

2 files changed

+34
-40
lines changed

arch/powerpc/include/asm/pci-bridge.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,13 +70,16 @@ struct pci_controller {
7070
* BIG_ENDIAN - cfg_addr is a big endian register
7171
* BROKEN_MRM - the 440EPx/GRx chips have an errata that causes hangs on
7272
* the PLB4. Effectively disable MRM commands by setting this.
73+
* FSL_CFG_REG_LINK - Freescale controller version in which the PCIe
74+
* link status is in a RC PCIe cfg register (vs being a SoC register)
7375
*/
7476
#define PPC_INDIRECT_TYPE_SET_CFG_TYPE 0x00000001
7577
#define PPC_INDIRECT_TYPE_EXT_REG 0x00000002
7678
#define PPC_INDIRECT_TYPE_SURPRESS_PRIMARY_BUS 0x00000004
7779
#define PPC_INDIRECT_TYPE_NO_PCIE_LINK 0x00000008
7880
#define PPC_INDIRECT_TYPE_BIG_ENDIAN 0x00000010
7981
#define PPC_INDIRECT_TYPE_BROKEN_MRM 0x00000020
82+
#define PPC_INDIRECT_TYPE_FSL_CFG_REG_LINK 0x00000040
8083
u32 indirect_type;
8184
/* Currently, we limit ourselves to 1 IO range and 3 mem
8285
* ranges since the common pci_bus structure can't handle more
@@ -90,9 +93,9 @@ struct pci_controller {
9093

9194
#ifdef CONFIG_PPC64
9295
unsigned long buid;
96+
#endif /* CONFIG_PPC64 */
9397

9498
void *private_data;
95-
#endif /* CONFIG_PPC64 */
9699
};
97100

98101
/* These are used for config access before all the PCI probing

arch/powerpc/sysdev/fsl_pci.c

Lines changed: 30 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -54,34 +54,22 @@ static void quirk_fsl_pcie_header(struct pci_dev *dev)
5454
return;
5555
}
5656

57-
static int __init fsl_pcie_check_link(struct pci_controller *hose,
58-
struct resource *rsrc)
57+
static int __init fsl_pcie_check_link(struct pci_controller *hose)
5958
{
60-
struct ccsr_pci __iomem *pci = NULL;
6159
u32 val;
6260

63-
/* for PCIe IP rev 3.0 or greater use CSR0 for link state */
64-
if (rsrc) {
65-
pr_debug("PCI memory map start 0x%016llx, size 0x%016llx\n",
66-
(u64)rsrc->start, (u64)rsrc->end - (u64)rsrc->start + 1);
67-
pci = ioremap(rsrc->start, rsrc->end - rsrc->start + 1);
68-
if (!pci) {
69-
dev_err(hose->parent, "Unable to map PCIe registers\n");
70-
return -ENOMEM;
71-
}
72-
if (in_be32(&pci->block_rev1) >= PCIE_IP_REV_3_0) {
73-
val = (in_be32(&pci->pex_csr0) & PEX_CSR0_LTSSM_MASK)
74-
>> PEX_CSR0_LTSSM_SHIFT;
75-
if (val != PEX_CSR0_LTSSM_L0)
76-
return 1;
77-
iounmap(pci);
78-
return 0;
79-
}
80-
iounmap(pci);
61+
if (hose->indirect_type & PPC_INDIRECT_TYPE_FSL_CFG_REG_LINK) {
62+
early_read_config_dword(hose, 0, 0, PCIE_LTSSM, &val);
63+
if (val < PCIE_LTSSM_L0)
64+
return 1;
65+
} else {
66+
struct ccsr_pci __iomem *pci = hose->private_data;
67+
/* for PCIe IP rev 3.0 or greater use CSR0 for link state */
68+
val = (in_be32(&pci->pex_csr0) & PEX_CSR0_LTSSM_MASK)
69+
>> PEX_CSR0_LTSSM_SHIFT;
70+
if (val != PEX_CSR0_LTSSM_L0)
71+
return 1;
8172
}
82-
early_read_config_dword(hose, 0, 0, PCIE_LTSSM, &val);
83-
if (val < PCIE_LTSSM_L0)
84-
return 1;
8573

8674
return 0;
8775
}
@@ -148,10 +136,9 @@ static int setup_one_atmu(struct ccsr_pci __iomem *pci,
148136
}
149137

150138
/* atmu setup for fsl pci/pcie controller */
151-
static void setup_pci_atmu(struct pci_controller *hose,
152-
struct resource *rsrc)
139+
static void setup_pci_atmu(struct pci_controller *hose)
153140
{
154-
struct ccsr_pci __iomem *pci;
141+
struct ccsr_pci __iomem *pci = hose->private_data;
155142
int i, j, n, mem_log, win_idx = 3, start_idx = 1, end_idx = 4;
156143
u64 mem, sz, paddr_hi = 0;
157144
u64 paddr_lo = ULLONG_MAX;
@@ -162,15 +149,6 @@ static void setup_pci_atmu(struct pci_controller *hose,
162149
const u64 *reg;
163150
int len;
164151

165-
pr_debug("PCI memory map start 0x%016llx, size 0x%016llx\n",
166-
(u64)rsrc->start, (u64)resource_size(rsrc));
167-
168-
pci = ioremap(rsrc->start, resource_size(rsrc));
169-
if (!pci) {
170-
dev_err(hose->parent, "Unable to map ATMU registers\n");
171-
return;
172-
}
173-
174152
if (early_find_capability(hose, 0, 0, PCI_CAP_ID_EXP)) {
175153
if (in_be32(&pci->block_rev1) >= PCIE_IP_REV_2_2) {
176154
win_idx = 2;
@@ -451,6 +429,7 @@ int __init fsl_add_bridge(struct platform_device *pdev, int is_primary)
451429
const int *bus_range;
452430
u8 hdr_type, progif;
453431
struct device_node *dev;
432+
struct ccsr_pci __iomem *pci;
454433

455434
dev = pdev->dev.of_node;
456435

@@ -483,9 +462,19 @@ int __init fsl_add_bridge(struct platform_device *pdev, int is_primary)
483462
hose->first_busno = bus_range ? bus_range[0] : 0x0;
484463
hose->last_busno = bus_range ? bus_range[1] : 0xff;
485464

465+
pr_debug("PCI memory map start 0x%016llx, size 0x%016llx\n",
466+
(u64)rsrc.start, (u64)resource_size(&rsrc));
467+
468+
pci = hose->private_data = ioremap(rsrc.start, resource_size(&rsrc));
469+
if (!hose->private_data)
470+
goto no_bridge;
471+
486472
setup_indirect_pci(hose, rsrc.start, rsrc.start + 0x4,
487473
PPC_INDIRECT_TYPE_BIG_ENDIAN);
488474

475+
if (in_be32(&pci->block_rev1) < PCIE_IP_REV_3_0)
476+
hose->indirect_type |= PPC_INDIRECT_TYPE_FSL_CFG_REG_LINK;
477+
489478
if (early_find_capability(hose, 0, 0, PCI_CAP_ID_EXP)) {
490479
/* For PCIE read HEADER_TYPE to identify controler mode */
491480
early_read_config_byte(hose, 0, 0, PCI_HEADER_TYPE, &hdr_type);
@@ -505,7 +494,7 @@ int __init fsl_add_bridge(struct platform_device *pdev, int is_primary)
505494
if (early_find_capability(hose, 0, 0, PCI_CAP_ID_EXP)) {
506495
hose->indirect_type |= PPC_INDIRECT_TYPE_EXT_REG |
507496
PPC_INDIRECT_TYPE_SURPRESS_PRIMARY_BUS;
508-
if (fsl_pcie_check_link(hose, &rsrc))
497+
if (fsl_pcie_check_link(hose))
509498
hose->indirect_type |= PPC_INDIRECT_TYPE_NO_PCIE_LINK;
510499
}
511500

@@ -522,11 +511,12 @@ int __init fsl_add_bridge(struct platform_device *pdev, int is_primary)
522511
pci_process_bridge_OF_ranges(hose, dev, is_primary);
523512

524513
/* Setup PEX window registers */
525-
setup_pci_atmu(hose, &rsrc);
514+
setup_pci_atmu(hose);
526515

527516
return 0;
528517

529518
no_bridge:
519+
iounmap(hose->private_data);
530520
/* unmap cfg_data & cfg_addr separately if not on same page */
531521
if (((unsigned long)hose->cfg_data & PAGE_MASK) !=
532522
((unsigned long)hose->cfg_addr & PAGE_MASK))
@@ -703,11 +693,12 @@ static int __init mpc83xx_pcie_setup(struct pci_controller *hose,
703693
WARN_ON(hose->dn->data);
704694
hose->dn->data = pcie;
705695
hose->ops = &mpc83xx_pcie_ops;
696+
hose->indirect_type |= PPC_INDIRECT_TYPE_FSL_CFG_REG_LINK;
706697

707698
out_le32(pcie->cfg_type0 + PEX_OUTWIN0_TAH, 0);
708699
out_le32(pcie->cfg_type0 + PEX_OUTWIN0_TAL, 0);
709700

710-
if (fsl_pcie_check_link(hose, NULL))
701+
if (fsl_pcie_check_link(hose))
711702
hose->indirect_type |= PPC_INDIRECT_TYPE_NO_PCIE_LINK;
712703

713704
return 0;

0 commit comments

Comments
 (0)