]> git.ipfire.org Git - people/ms/u-boot.git/blob - include/asm-ppc/4xx_pcie.h
ppc4xx: Pass PCIe root-complex/endpoint configuration to Linux via the fdt
[people/ms/u-boot.git] / include / asm-ppc / 4xx_pcie.h
1 /*
2 * Copyright (c) 2005 Cisco Systems. All rights reserved.
3 * Roland Dreier <rolandd@cisco.com>
4 *
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License as published by the
7 * Free Software Foundation; either version 2 of the License, or (at your
8 * option) any later version.
9 */
10
11 #ifndef __4XX_PCIE_H
12 #define __4XX_PCIE_H
13
14 #include <ppc4xx.h>
15
16 #define DCRN_SDR0_CFGADDR 0x00e
17 #define DCRN_SDR0_CFGDATA 0x00f
18
19 #if defined(CONFIG_440SPE)
20 #define CFG_PCIE_NR_PORTS 3
21
22 #define CFG_PCIE_ADDR_HIGH 0x0000000d
23
24 #define DCRN_PCIE0_BASE 0x100
25 #define DCRN_PCIE1_BASE 0x120
26 #define DCRN_PCIE2_BASE 0x140
27
28 #define PCIE0_SDR 0x300
29 #define PCIE1_SDR 0x340
30 #define PCIE2_SDR 0x370
31 #endif
32
33 #if defined(CONFIG_460EX) || defined(CONFIG_460GT)
34 #define CFG_PCIE_NR_PORTS 2
35
36 #define CFG_PCIE_ADDR_HIGH 0x0000000d
37
38 #define DCRN_PCIE0_BASE 0x100
39 #define DCRN_PCIE1_BASE 0x120
40
41 #define PCIE0_SDR 0x300
42 #define PCIE1_SDR 0x340
43 #endif
44
45 #if defined(CONFIG_405EX)
46 #define CFG_PCIE_NR_PORTS 2
47
48 #define CFG_PCIE_ADDR_HIGH 0x00000000
49
50 #define DCRN_PCIE0_BASE 0x040
51 #define DCRN_PCIE1_BASE 0x060
52
53 #define PCIE0_SDR 0x400
54 #define PCIE1_SDR 0x440
55 #endif
56
57 #define PCIE0 DCRN_PCIE0_BASE
58 #define PCIE1 DCRN_PCIE1_BASE
59 #define PCIE2 DCRN_PCIE2_BASE
60
61 #define DCRN_PEGPL_CFGBAH(base) (base + 0x00)
62 #define DCRN_PEGPL_CFGBAL(base) (base + 0x01)
63 #define DCRN_PEGPL_CFGMSK(base) (base + 0x02)
64 #define DCRN_PEGPL_MSGBAH(base) (base + 0x03)
65 #define DCRN_PEGPL_MSGBAL(base) (base + 0x04)
66 #define DCRN_PEGPL_MSGMSK(base) (base + 0x05)
67 #define DCRN_PEGPL_OMR1BAH(base) (base + 0x06)
68 #define DCRN_PEGPL_OMR1BAL(base) (base + 0x07)
69 #define DCRN_PEGPL_OMR1MSKH(base) (base + 0x08)
70 #define DCRN_PEGPL_OMR1MSKL(base) (base + 0x09)
71 #define DCRN_PEGPL_REGBAH(base) (base + 0x12)
72 #define DCRN_PEGPL_REGBAL(base) (base + 0x13)
73 #define DCRN_PEGPL_REGMSK(base) (base + 0x14)
74 #define DCRN_PEGPL_SPECIAL(base) (base + 0x15)
75 #define DCRN_PEGPL_CFG(base) (base + 0x16)
76
77 /*
78 * System DCRs (SDRs)
79 */
80 #define PESDR0_PLLLCT1 0x03a0
81 #define PESDR0_PLLLCT2 0x03a1
82 #define PESDR0_PLLLCT3 0x03a2
83
84 /* common regs, at for all 4xx with PCIe core */
85 #define SDRN_PESDR_UTLSET1(n) (sdr_base(n) + 0x00)
86 #define SDRN_PESDR_UTLSET2(n) (sdr_base(n) + 0x01)
87 #define SDRN_PESDR_DLPSET(n) (sdr_base(n) + 0x02)
88 #define SDRN_PESDR_LOOP(n) (sdr_base(n) + 0x03)
89 #define SDRN_PESDR_RCSSET(n) (sdr_base(n) + 0x04)
90 #define SDRN_PESDR_RCSSTS(n) (sdr_base(n) + 0x05)
91
92 #if defined(CONFIG_440SPE)
93 #define SDRN_PESDR_HSSL0SET1(n) (sdr_base(n) + 0x06)
94 #define SDRN_PESDR_HSSL0SET2(n) (sdr_base(n) + 0x07)
95 #define SDRN_PESDR_HSSL0STS(n) (sdr_base(n) + 0x08)
96 #define SDRN_PESDR_HSSL1SET1(n) (sdr_base(n) + 0x09)
97 #define SDRN_PESDR_HSSL1SET2(n) (sdr_base(n) + 0x0a)
98 #define SDRN_PESDR_HSSL1STS(n) (sdr_base(n) + 0x0b)
99 #define SDRN_PESDR_HSSL2SET1(n) (sdr_base(n) + 0x0c)
100 #define SDRN_PESDR_HSSL2SET2(n) (sdr_base(n) + 0x0d)
101 #define SDRN_PESDR_HSSL2STS(n) (sdr_base(n) + 0x0e)
102 #define SDRN_PESDR_HSSL3SET1(n) (sdr_base(n) + 0x0f)
103 #define SDRN_PESDR_HSSL3SET2(n) (sdr_base(n) + 0x10)
104 #define SDRN_PESDR_HSSL3STS(n) (sdr_base(n) + 0x11)
105
106 #define PESDR0_UTLSET1 0x0300
107 #define PESDR0_UTLSET2 0x0301
108 #define PESDR0_DLPSET 0x0302
109 #define PESDR0_LOOP 0x0303
110 #define PESDR0_RCSSET 0x0304
111 #define PESDR0_RCSSTS 0x0305
112 #define PESDR0_HSSL0SET1 0x0306
113 #define PESDR0_HSSL0SET2 0x0307
114 #define PESDR0_HSSL0STS 0x0308
115 #define PESDR0_HSSL1SET1 0x0309
116 #define PESDR0_HSSL1SET2 0x030a
117 #define PESDR0_HSSL1STS 0x030b
118 #define PESDR0_HSSL2SET1 0x030c
119 #define PESDR0_HSSL2SET2 0x030d
120 #define PESDR0_HSSL2STS 0x030e
121 #define PESDR0_HSSL3SET1 0x030f
122 #define PESDR0_HSSL3SET2 0x0310
123 #define PESDR0_HSSL3STS 0x0311
124 #define PESDR0_HSSL4SET1 0x0312
125 #define PESDR0_HSSL4SET2 0x0313
126 #define PESDR0_HSSL4STS 0x0314
127 #define PESDR0_HSSL5SET1 0x0315
128 #define PESDR0_HSSL5SET2 0x0316
129 #define PESDR0_HSSL5STS 0x0317
130 #define PESDR0_HSSL6SET1 0x0318
131 #define PESDR0_HSSL6SET2 0x0319
132 #define PESDR0_HSSL6STS 0x031a
133 #define PESDR0_HSSL7SET1 0x031b
134 #define PESDR0_HSSL7SET2 0x031c
135 #define PESDR0_HSSL7STS 0x031d
136 #define PESDR0_HSSCTLSET 0x031e
137 #define PESDR0_LANE_ABCD 0x031f
138 #define PESDR0_LANE_EFGH 0x0320
139
140 #define PESDR1_UTLSET1 0x0340
141 #define PESDR1_UTLSET2 0x0341
142 #define PESDR1_DLPSET 0x0342
143 #define PESDR1_LOOP 0x0343
144 #define PESDR1_RCSSET 0x0344
145 #define PESDR1_RCSSTS 0x0345
146 #define PESDR1_HSSL0SET1 0x0346
147 #define PESDR1_HSSL0SET2 0x0347
148 #define PESDR1_HSSL0STS 0x0348
149 #define PESDR1_HSSL1SET1 0x0349
150 #define PESDR1_HSSL1SET2 0x034a
151 #define PESDR1_HSSL1STS 0x034b
152 #define PESDR1_HSSL2SET1 0x034c
153 #define PESDR1_HSSL2SET2 0x034d
154 #define PESDR1_HSSL2STS 0x034e
155 #define PESDR1_HSSL3SET1 0x034f
156 #define PESDR1_HSSL3SET2 0x0350
157 #define PESDR1_HSSL3STS 0x0351
158 #define PESDR1_HSSCTLSET 0x0352
159 #define PESDR1_LANE_ABCD 0x0353
160
161 #define PESDR2_UTLSET1 0x0370
162 #define PESDR2_UTLSET2 0x0371
163 #define PESDR2_DLPSET 0x0372
164 #define PESDR2_LOOP 0x0373
165 #define PESDR2_RCSSET 0x0374
166 #define PESDR2_RCSSTS 0x0375
167 #define PESDR2_HSSL0SET1 0x0376
168 #define PESDR2_HSSL0SET2 0x0377
169 #define PESDR2_HSSL0STS 0x0378
170 #define PESDR2_HSSL1SET1 0x0379
171 #define PESDR2_HSSL1SET2 0x037a
172 #define PESDR2_HSSL1STS 0x037b
173 #define PESDR2_HSSL2SET1 0x037c
174 #define PESDR2_HSSL2SET2 0x037d
175 #define PESDR2_HSSL2STS 0x037e
176 #define PESDR2_HSSL3SET1 0x037f
177 #define PESDR2_HSSL3SET2 0x0380
178 #define PESDR2_HSSL3STS 0x0381
179 #define PESDR2_HSSCTLSET 0x0382
180 #define PESDR2_LANE_ABCD 0x0383
181
182 #elif defined(CONFIG_405EX)
183
184 #define SDRN_PESDR_PHYSET1(n) (sdr_base(n) + 0x06)
185 #define SDRN_PESDR_PHYSET2(n) (sdr_base(n) + 0x07)
186 #define SDRN_PESDR_BIST(n) (sdr_base(n) + 0x08)
187 #define SDRN_PESDR_LPB(n) (sdr_base(n) + 0x0b)
188 #define SDRN_PESDR_PHYSTA(n) (sdr_base(n) + 0x0c)
189
190 #define PESDR0_UTLSET1 0x0400
191 #define PESDR0_UTLSET2 0x0401
192 #define PESDR0_DLPSET 0x0402
193 #define PESDR0_LOOP 0x0403
194 #define PESDR0_RCSSET 0x0404
195 #define PESDR0_RCSSTS 0x0405
196 #define PESDR0_PHYSET1 0x0406
197 #define PESDR0_PHYSET2 0x0407
198 #define PESDR0_BIST 0x0408
199 #define PESDR0_LPB 0x040B
200 #define PESDR0_PHYSTA 0x040C
201
202 #define PESDR1_UTLSET1 0x0440
203 #define PESDR1_UTLSET2 0x0441
204 #define PESDR1_DLPSET 0x0442
205 #define PESDR1_LOOP 0x0443
206 #define PESDR1_RCSSET 0x0444
207 #define PESDR1_RCSSTS 0x0445
208 #define PESDR1_PHYSET1 0x0446
209 #define PESDR1_PHYSET2 0x0447
210 #define PESDR1_BIST 0x0448
211 #define PESDR1_LPB 0x044B
212 #define PESDR1_PHYSTA 0x044C
213
214 #elif defined(CONFIG_460EX) || defined(CONFIG_460GT)
215
216 #define PESDR0_L0BIST 0x0308 /* PE0 L0 built in self test */
217 #define PESDR0_L0BISTSTS 0x0309 /* PE0 L0 built in self test status */
218 #define PESDR0_L0CDRCTL 0x030A /* PE0 L0 CDR control */
219 #define PESDR0_L0DRV 0x030B /* PE0 L0 drive */
220 #define PESDR0_L0REC 0x030C /* PE0 L0 receiver */
221 #define PESDR0_L0LPB 0x030D /* PE0 L0 loopback */
222 #define PESDR0_L0CLK 0x030E /* PE0 L0 clocking */
223 #define PESDR0_PHY_CTL_RST 0x030F /* PE0 PHY control reset */
224 #define PESDR0_RSTSTA 0x0310 /* PE0 reset status */
225 #define PESDR0_OBS 0x0311 /* PE0 observation register */
226 #define PESDR0_L0ERRC 0x0320 /* PE0 L0 error counter */
227
228 #define PESDR1_L0BIST 0x0348 /* PE1 L0 built in self test */
229 #define PESDR1_L1BIST 0x0349 /* PE1 L1 built in self test */
230 #define PESDR1_L2BIST 0x034A /* PE1 L2 built in self test */
231 #define PESDR1_L3BIST 0x034B /* PE1 L3 built in self test */
232 #define PESDR1_L0BISTSTS 0x034C /* PE1 L0 built in self test status */
233 #define PESDR1_L1BISTSTS 0x034D /* PE1 L1 built in self test status */
234 #define PESDR1_L2BISTSTS 0x034E /* PE1 L2 built in self test status */
235 #define PESDR1_L3BISTSTS 0x034F /* PE1 L3 built in self test status */
236 #define PESDR1_L0CDRCTL 0x0350 /* PE1 L0 CDR control */
237 #define PESDR1_L1CDRCTL 0x0351 /* PE1 L1 CDR control */
238 #define PESDR1_L2CDRCTL 0x0352 /* PE1 L2 CDR control */
239 #define PESDR1_L3CDRCTL 0x0353 /* PE1 L3 CDR control */
240 #define PESDR1_L0DRV 0x0354 /* PE1 L0 drive */
241 #define PESDR1_L1DRV 0x0355 /* PE1 L1 drive */
242 #define PESDR1_L2DRV 0x0356 /* PE1 L2 drive */
243 #define PESDR1_L3DRV 0x0357 /* PE1 L3 drive */
244 #define PESDR1_L0REC 0x0358 /* PE1 L0 receiver */
245 #define PESDR1_L1REC 0x0359 /* PE1 L1 receiver */
246 #define PESDR1_L2REC 0x035A /* PE1 L2 receiver */
247 #define PESDR1_L3REC 0x035B /* PE1 L3 receiver */
248 #define PESDR1_L0LPB 0x035C /* PE1 L0 loopback */
249 #define PESDR1_L1LPB 0x035D /* PE1 L1 loopback */
250 #define PESDR1_L2LPB 0x035E /* PE1 L2 loopback */
251 #define PESDR1_L3LPB 0x035F /* PE1 L3 loopback */
252 #define PESDR1_L0CLK 0x0360 /* PE1 L0 clocking */
253 #define PESDR1_L1CLK 0x0361 /* PE1 L1 clocking */
254 #define PESDR1_L2CLK 0x0362 /* PE1 L2 clocking */
255 #define PESDR1_L3CLK 0x0363 /* PE1 L3 clocking */
256 #define PESDR1_PHY_CTL_RST 0x0364 /* PE1 PHY control reset */
257 #define PESDR1_RSTSTA 0x0365 /* PE1 reset status */
258 #define PESDR1_OBS 0x0366 /* PE1 observation register */
259 #define PESDR1_L0ERRC 0x0368 /* PE1 L0 error counter */
260 #define PESDR1_L1ERRC 0x0369 /* PE1 L1 error counter */
261 #define PESDR1_L2ERRC 0x036A /* PE1 L2 error counter */
262 #define PESDR1_L3ERRC 0x036B /* PE1 L3 error counter */
263 #define PESDR0_IHS1 0x036C /* PE interrupt handler interfact setting 1 */
264 #define PESDR0_IHS2 0x036D /* PE interrupt handler interfact setting 2 */
265
266 #endif
267
268 /* SDR Bit Mappings */
269 #define PESDRx_RCSSET_HLDPLB 0x10000000
270 #define PESDRx_RCSSET_RSTGU 0x01000000
271 #define PESDRx_RCSSET_RDY 0x00100000
272 #define PESDRx_RCSSET_RSTDL 0x00010000
273 #define PESDRx_RCSSET_RSTPYN 0x00001000
274
275 #define PESDRx_RCSSTS_PLBIDL 0x10000000
276 #define PESDRx_RCSSTS_HRSTRQ 0x01000000
277 #define PESDRx_RCSSTS_PGRST 0x00100000
278 #define PESDRx_RCSSTS_VC0ACT 0x00010000
279 #define PESDRx_RCSSTS_BMEN 0x00000100
280
281 /*
282 * UTL register offsets
283 */
284 #define PEUTL_PBCTL 0x00
285 #define PEUTL_PBBSZ 0x20
286 #define PEUTL_OPDBSZ 0x68
287 #define PEUTL_IPHBSZ 0x70
288 #define PEUTL_IPDBSZ 0x78
289 #define PEUTL_OUTTR 0x90
290 #define PEUTL_INTR 0x98
291 #define PEUTL_PCTL 0xa0
292 #define PEUTL_RCSTA 0xb0
293 #define PEUTL_RCIRQEN 0xb8
294
295 /*
296 * Config space register offsets
297 */
298 #define PECFG_BAR0LMPA 0x210
299 #define PECFG_BAR0HMPA 0x214
300 #define PECFG_BAR1MPA 0x218
301 #define PECFG_BAR2LMPA 0x220
302 #define PECFG_BAR2HMPA 0x224
303
304 #define PECFG_PIMEN 0x33c
305 #define PECFG_PIM0LAL 0x340
306 #define PECFG_PIM0LAH 0x344
307 #define PECFG_PIM1LAL 0x348
308 #define PECFG_PIM1LAH 0x34c
309 #define PECFG_PIM01SAL 0x350
310 #define PECFG_PIM01SAH 0x354
311
312 #define PECFG_POM0LAL 0x380
313 #define PECFG_POM0LAH 0x384
314
315 #define SDR_READ(offset) ({\
316 mtdcr(DCRN_SDR0_CFGADDR, offset); \
317 mfdcr(DCRN_SDR0_CFGDATA);})
318
319 #define SDR_WRITE(offset, data) ({\
320 mtdcr(DCRN_SDR0_CFGADDR, offset); \
321 mtdcr(DCRN_SDR0_CFGDATA,data);})
322
323 #define GPL_DMER_MASK_DISA 0x02000000
324
325 #define U64_TO_U32_LOW(val) ((u32)((val) & 0x00000000ffffffffULL))
326 #define U64_TO_U32_HIGH(val) ((u32)((val) >> 32))
327
328 /*
329 * Prototypes
330 */
331 int ppc4xx_init_pcie(void);
332 int ppc4xx_init_pcie_rootport(int port);
333 int ppc4xx_init_pcie_endport(int port);
334 void ppc4xx_setup_pcie_rootpoint(struct pci_controller *hose, int port);
335 int ppc4xx_setup_pcie_endpoint(struct pci_controller *hose, int port);
336 int pcie_hose_scan(struct pci_controller *hose, int bus);
337
338 /*
339 * Function to determine root port or endport from env variable.
340 */
341 static inline int is_end_point(int port)
342 {
343 char s[10], *tk;
344 char *pcie_mode = getenv("pcie_mode");
345
346 if (pcie_mode == NULL)
347 return 0;
348
349 strcpy(s, pcie_mode);
350 tk = strtok(s, ":");
351
352 switch (port) {
353 case 0:
354 if (tk != NULL) {
355 if (!(strcmp(tk, "ep") && strcmp(tk, "EP")))
356 return 1;
357 else
358 return 0;
359 }
360 else
361 return 0;
362
363 case 1:
364 tk = strtok(NULL, ":");
365 if (tk != NULL) {
366 if (!(strcmp(tk, "ep") && strcmp(tk, "EP")))
367 return 1;
368 else
369 return 0;
370 }
371 else
372 return 0;
373
374 case 2:
375 tk = strtok(NULL, ":");
376 if (tk != NULL)
377 tk = strtok(NULL, ":");
378 if (tk != NULL) {
379 if (!(strcmp(tk, "ep") && strcmp(tk, "EP")))
380 return 1;
381 else
382 return 0;
383 }
384 else
385 return 0;
386 }
387
388 return 0;
389 }
390
391 static inline void mdelay(int n)
392 {
393 u32 ms = n;
394
395 while (ms--)
396 udelay(1000);
397 }
398
399 #if defined(PCIE0_SDR)
400 static inline u32 sdr_base(int port)
401 {
402 switch (port) {
403 default: /* to satisfy compiler */
404 case 0:
405 return PCIE0_SDR;
406 case 1:
407 return PCIE1_SDR;
408 #if CFG_PCIE_NR_PORTS > 2
409 case 2:
410 return PCIE2_SDR;
411 #endif
412 }
413 }
414 #endif /* defined(PCIE0_SDR) */
415
416 #endif /* __4XX_PCIE_H */