1 /* pci_fire.c: Sun4u platform PCI-E controller support.
3 * Copyright (C) 2007 David S. Miller (davem@davemloft.net)
5 #include <linux/kernel.h>
7 #include <linux/slab.h>
8 #include <linux/init.h>
10 #include <asm/oplib.h>
15 #define fire_read(__reg) \
17 __asm__ __volatile__("ldxa [%1] %2, %0" \
19 : "r" (__reg), "i" (ASI_PHYS_BYPASS_EC_E) \
23 #define fire_write(__reg, __val) \
24 __asm__ __volatile__("stxa %0, [%1] %2" \
26 : "r" (__val), "r" (__reg), \
27 "i" (ASI_PHYS_BYPASS_EC_E) \
30 static void pci_fire_scan_bus(struct pci_pbm_info *pbm)
32 pbm->pci_bus = pci_scan_one_pbm(pbm);
34 /* XXX register error interrupt handlers XXX */
37 #define FIRE_IOMMU_CONTROL 0x40000UL
38 #define FIRE_IOMMU_TSBBASE 0x40008UL
39 #define FIRE_IOMMU_FLUSH 0x40100UL
40 #define FIRE_IOMMU_FLUSHINV 0x40108UL
42 static void pci_fire_pbm_iommu_init(struct pci_pbm_info *pbm)
44 struct iommu *iommu = pbm->iommu;
45 u32 vdma[2], dma_mask;
49 /* No virtual-dma property on these guys, use largest size. */
50 vdma[0] = 0xc0000000; /* base */
51 vdma[1] = 0x40000000; /* size */
52 dma_mask = 0xffffffff;
55 /* Register addresses. */
56 iommu->iommu_control = pbm->pbm_regs + FIRE_IOMMU_CONTROL;
57 iommu->iommu_tsbbase = pbm->pbm_regs + FIRE_IOMMU_TSBBASE;
58 iommu->iommu_flush = pbm->pbm_regs + FIRE_IOMMU_FLUSH;
59 iommu->iommu_flushinv = pbm->pbm_regs + FIRE_IOMMU_FLUSHINV;
61 /* We use the main control/status register of FIRE as the write
62 * completion register.
64 iommu->write_complete_reg = pbm->controller_regs + 0x410000UL;
67 * Invalidate TLB Entries.
69 fire_write(iommu->iommu_flushinv, ~(u64)0);
71 pci_iommu_table_init(iommu, tsbsize * 8 * 1024, vdma[0], dma_mask);
73 fire_write(iommu->iommu_tsbbase, __pa(iommu->page_table) | 0x7UL);
75 control = fire_read(iommu->iommu_control);
76 control |= (0x00000400 /* TSB cache snoop enable */ |
77 0x00000300 /* Cache mode */ |
78 0x00000002 /* Bypass enable */ |
79 0x00000001 /* Translation enable */);
80 fire_write(iommu->iommu_control, control);
83 /* Based at pbm->controller_regs */
84 #define FIRE_PARITY_CONTROL 0x470010UL
85 #define FIRE_PARITY_ENAB 0x8000000000000000UL
86 #define FIRE_FATAL_RESET_CTL 0x471028UL
87 #define FIRE_FATAL_RESET_SPARE 0x0000000004000000UL
88 #define FIRE_FATAL_RESET_MB 0x0000000002000000UL
89 #define FIRE_FATAL_RESET_CPE 0x0000000000008000UL
90 #define FIRE_FATAL_RESET_APE 0x0000000000004000UL
91 #define FIRE_FATAL_RESET_PIO 0x0000000000000040UL
92 #define FIRE_FATAL_RESET_JW 0x0000000000000004UL
93 #define FIRE_FATAL_RESET_JI 0x0000000000000002UL
94 #define FIRE_FATAL_RESET_JR 0x0000000000000001UL
95 #define FIRE_CORE_INTR_ENABLE 0x471800UL
97 /* Based at pbm->pbm_regs */
98 #define FIRE_TLU_CTRL 0x80000UL
99 #define FIRE_TLU_CTRL_TIM 0x00000000da000000UL
100 #define FIRE_TLU_CTRL_QDET 0x0000000000000100UL
101 #define FIRE_TLU_CTRL_CFG 0x0000000000000001UL
102 #define FIRE_TLU_DEV_CTRL 0x90008UL
103 #define FIRE_TLU_LINK_CTRL 0x90020UL
104 #define FIRE_TLU_LINK_CTRL_CLK 0x0000000000000040UL
105 #define FIRE_LPU_RESET 0xe2008UL
106 #define FIRE_LPU_LLCFG 0xe2200UL
107 #define FIRE_LPU_LLCFG_VC0 0x0000000000000100UL
108 #define FIRE_LPU_FCTRL_UCTRL 0xe2240UL
109 #define FIRE_LPU_FCTRL_UCTRL_N 0x0000000000000002UL
110 #define FIRE_LPU_FCTRL_UCTRL_P 0x0000000000000001UL
111 #define FIRE_LPU_TXL_FIFOP 0xe2430UL
112 #define FIRE_LPU_LTSSM_CFG2 0xe2788UL
113 #define FIRE_LPU_LTSSM_CFG3 0xe2790UL
114 #define FIRE_LPU_LTSSM_CFG4 0xe2798UL
115 #define FIRE_LPU_LTSSM_CFG5 0xe27a0UL
116 #define FIRE_DMC_IENAB 0x31800UL
117 #define FIRE_DMC_DBG_SEL_A 0x53000UL
118 #define FIRE_DMC_DBG_SEL_B 0x53008UL
119 #define FIRE_PEC_IENAB 0x51800UL
121 static void pci_fire_hw_init(struct pci_pbm_info *pbm)
125 fire_write(pbm->controller_regs + FIRE_PARITY_CONTROL,
128 fire_write(pbm->controller_regs + FIRE_FATAL_RESET_CTL,
129 (FIRE_FATAL_RESET_SPARE |
130 FIRE_FATAL_RESET_MB |
131 FIRE_FATAL_RESET_CPE |
132 FIRE_FATAL_RESET_APE |
133 FIRE_FATAL_RESET_PIO |
134 FIRE_FATAL_RESET_JW |
135 FIRE_FATAL_RESET_JI |
136 FIRE_FATAL_RESET_JR));
138 fire_write(pbm->controller_regs + FIRE_CORE_INTR_ENABLE, ~(u64)0);
140 val = fire_read(pbm->pbm_regs + FIRE_TLU_CTRL);
141 val |= (FIRE_TLU_CTRL_TIM |
144 fire_write(pbm->pbm_regs + FIRE_TLU_CTRL, val);
145 fire_write(pbm->pbm_regs + FIRE_TLU_DEV_CTRL, 0);
146 fire_write(pbm->pbm_regs + FIRE_TLU_LINK_CTRL,
147 FIRE_TLU_LINK_CTRL_CLK);
149 fire_write(pbm->pbm_regs + FIRE_LPU_RESET, 0);
150 fire_write(pbm->pbm_regs + FIRE_LPU_LLCFG,
152 fire_write(pbm->pbm_regs + FIRE_LPU_FCTRL_UCTRL,
153 (FIRE_LPU_FCTRL_UCTRL_N |
154 FIRE_LPU_FCTRL_UCTRL_P));
155 fire_write(pbm->pbm_regs + FIRE_LPU_TXL_FIFOP,
156 ((0xffff << 16) | (0x0000 << 0)));
157 fire_write(pbm->pbm_regs + FIRE_LPU_LTSSM_CFG2, 3000000);
158 fire_write(pbm->pbm_regs + FIRE_LPU_LTSSM_CFG3, 500000);
159 fire_write(pbm->pbm_regs + FIRE_LPU_LTSSM_CFG4,
160 (2 << 16) | (140 << 8));
161 fire_write(pbm->pbm_regs + FIRE_LPU_LTSSM_CFG5, 0);
163 fire_write(pbm->pbm_regs + FIRE_DMC_IENAB, ~(u64)0);
164 fire_write(pbm->pbm_regs + FIRE_DMC_DBG_SEL_A, 0);
165 fire_write(pbm->pbm_regs + FIRE_DMC_DBG_SEL_B, 0);
167 fire_write(pbm->pbm_regs + FIRE_PEC_IENAB, ~(u64)0);
170 static void pci_fire_pbm_init(struct pci_controller_info *p,
171 struct device_node *dp, u32 portid)
173 const struct linux_prom64_registers *regs;
174 struct pci_pbm_info *pbm;
176 if ((portid & 1) == 0)
181 pbm->next = pci_pbm_root;
184 pbm->scan_bus = pci_fire_scan_bus;
185 pbm->pci_ops = &sun4u_pci_ops;
186 pbm->config_space_reg_bits = 12;
188 pbm->index = pci_num_pbms++;
190 pbm->portid = portid;
193 pbm->name = dp->full_name;
195 regs = of_get_property(dp, "reg", NULL);
196 pbm->pbm_regs = regs[0].phys_addr;
197 pbm->controller_regs = regs[1].phys_addr - 0x410000UL;
199 printk("%s: SUN4U PCIE Bus Module\n", pbm->name);
201 pci_determine_mem_io_space(pbm);
203 pci_get_pbm_props(pbm);
205 pci_fire_hw_init(pbm);
206 pci_fire_pbm_iommu_init(pbm);
209 static inline int portid_compare(u32 x, u32 y)
216 void fire_pci_init(struct device_node *dp, const char *model_name)
218 struct pci_controller_info *p;
219 u32 portid = of_getintprop_default(dp, "portid", 0xff);
221 struct pci_pbm_info *pbm;
223 for (pbm = pci_pbm_root; pbm; pbm = pbm->next) {
224 if (portid_compare(pbm->portid, portid)) {
225 pci_fire_pbm_init(pbm->parent, dp, portid);
230 p = kzalloc(sizeof(struct pci_controller_info), GFP_ATOMIC);
232 goto fatal_memory_error;
234 iommu = kzalloc(sizeof(struct iommu), GFP_ATOMIC);
236 goto fatal_memory_error;
238 p->pbm_A.iommu = iommu;
240 iommu = kzalloc(sizeof(struct iommu), GFP_ATOMIC);
242 goto fatal_memory_error;
244 p->pbm_B.iommu = iommu;
246 /* XXX MSI support XXX */
248 /* Like PSYCHO and SCHIZO we have a 2GB aligned area
251 pci_memspace_mask = 0x7fffffffUL;
253 pci_fire_pbm_init(p, dp, portid);
257 prom_printf("PCI_FIRE: Fatal memory allocation error.\n");