blob: a616365aa57b1177ce84f7b7ec8a8c4a01912568 [file] [log] [blame]
Rafal Jaworowskia2e7ef02006-08-10 12:43:17 +02001/*
Stefan Roesebdd13d12008-03-11 15:05:26 +01002 * (C) Copyright 2006 - 2008
Rafal Jaworowskia2e7ef02006-08-10 12:43:17 +02003 * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
4 *
5 * Copyright (c) 2005 Cisco Systems. All rights reserved.
6 * Roland Dreier <rolandd@cisco.com>
7 *
Wolfgang Denkd79de1d2013-07-08 09:37:19 +02008 * SPDX-License-Identifier: GPL-2.0+
Rafal Jaworowskia2e7ef02006-08-10 12:43:17 +02009 */
10
Stefan Roese3dced492007-10-05 07:57:20 +020011/* define DEBUG for debugging output (obviously ;-)) */
Stefan Roesedb4f4542007-10-05 09:22:33 +020012#if 0
Stefan Roese3dced492007-10-05 07:57:20 +020013#define DEBUG
14#endif
15
Rafal Jaworowskia2e7ef02006-08-10 12:43:17 +020016#include <common.h>
17#include <pci.h>
Stefan Roese247e9d72010-09-09 19:18:00 +020018#include <asm/ppc4xx.h>
Stefan Roese7105abd2008-07-10 11:38:26 +020019#include <asm/processor.h>
Peter Tyser133c0fe2010-04-12 22:28:07 -050020#include <asm/io.h>
Masahiro Yamada56a931c2016-09-21 11:28:55 +090021#include <linux/errno.h>
Rafal Jaworowskia2e7ef02006-08-10 12:43:17 +020022
Stefan Roesebdd13d12008-03-11 15:05:26 +010023#if (defined(CONFIG_440SPE) || defined(CONFIG_405EX) || \
24 defined(CONFIG_460EX) || defined(CONFIG_460GT)) && \
Dirk Eibach6bb88a02009-02-03 15:15:21 +010025 defined(CONFIG_PCI) && !defined(CONFIG_PCI_DISABLE_PCIE)
Rafal Jaworowskia2e7ef02006-08-10 12:43:17 +020026
Stefan Roese216f0632007-10-03 07:34:10 +020027#include <asm/4xx_pcie.h>
Rafal Jaworowskia2e7ef02006-08-10 12:43:17 +020028
29enum {
30 PTYPE_ENDPOINT = 0x0,
31 PTYPE_LEGACY_ENDPOINT = 0x1,
32 PTYPE_ROOT_PORT = 0x4,
33
34 LNKW_X1 = 0x1,
35 LNKW_X4 = 0x4,
36 LNKW_X8 = 0x8
37};
38
Stefan Roesee53b5cd2009-10-29 15:04:35 +010039static struct pci_controller pcie_hose[CONFIG_SYS_PCIE_NR_PORTS];
40
41/*
42 * Per default, all cards are present, so we need to check if the
43 * link comes up.
44 */
45int __board_pcie_card_present(int port)
46{
47 return 1;
48}
49int board_pcie_card_present(int port)
50 __attribute__((weak, alias("__board_pcie_card_present")));
51
52/*
53 * Some boards have runtime detection of the first and last PCIe
54 * slot used, so let's provide weak default functions for the
55 * common version.
56 */
57int __board_pcie_first(void)
58{
59 return 0;
60}
61int board_pcie_first(void)
62 __attribute__((weak, alias("__board_pcie_first")));
63
64int __board_pcie_last(void)
65{
66 return CONFIG_SYS_PCIE_NR_PORTS - 1;
67}
68int board_pcie_last(void)
69 __attribute__((weak, alias("__board_pcie_last")));
70
71void __board_pcie_setup_port(int port, int rootpoint)
72{
73 /* noting in this weak default implementation */
74}
75void board_pcie_setup_port(int port, int rootpoint)
76 __attribute__((weak, alias("__board_pcie_setup_port")));
77
78void pcie_setup_hoses(int busno)
79{
80 struct pci_controller *hose;
81 int i, bus;
82 int ret = 0;
83 char *env;
84 unsigned int delay;
85 int first = board_pcie_first();
86 int last = board_pcie_last();
87
88 /*
89 * Assume we're called after the PCI(X) hose(s) are initialized,
90 * which takes bus ID 0... and therefore start numbering PCIe's
91 * from the next number.
92 */
93 bus = busno;
94
95 for (i = first; i <= last; i++) {
96 /*
97 * Some boards (e.g. Katmai) can detects via hardware
98 * if a PCIe card is plugged, so let's check this.
99 */
100 if (!board_pcie_card_present(i))
101 continue;
102
103 if (is_end_point(i)) {
104 board_pcie_setup_port(i, 0);
105 ret = ppc4xx_init_pcie_endport(i);
106 } else {
107 board_pcie_setup_port(i, 1);
108 ret = ppc4xx_init_pcie_rootport(i);
109 }
110 if (ret == -ENODEV)
111 continue;
112 if (ret) {
113 printf("PCIE%d: initialization as %s failed\n", i,
114 is_end_point(i) ? "endpoint" : "root-complex");
115 continue;
116 }
117
118 hose = &pcie_hose[i];
119 hose->first_busno = bus;
120 hose->last_busno = bus;
121 hose->current_busno = bus;
122
123 /* setup mem resource */
124 pci_set_region(hose->regions + 0,
125 CONFIG_SYS_PCIE_MEMBASE + i * CONFIG_SYS_PCIE_MEMSIZE,
126 CONFIG_SYS_PCIE_MEMBASE + i * CONFIG_SYS_PCIE_MEMSIZE,
127 CONFIG_SYS_PCIE_MEMSIZE,
128 PCI_REGION_MEM);
129 hose->region_count = 1;
130 pci_register_hose(hose);
131
132 if (is_end_point(i)) {
133 ppc4xx_setup_pcie_endpoint(hose, i);
134 /*
135 * Reson for no scanning is endpoint can not generate
136 * upstream configuration accesses.
137 */
138 } else {
139 ppc4xx_setup_pcie_rootpoint(hose, i);
140 env = getenv ("pciscandelay");
141 if (env != NULL) {
142 delay = simple_strtoul(env, NULL, 10);
143 if (delay > 5)
144 printf("Warning, expect noticable delay before "
145 "PCIe scan due to 'pciscandelay' value!\n");
146 mdelay(delay * 1000);
147 }
148
149 /*
150 * Config access can only go down stream
151 */
152 hose->last_busno = pci_hose_scan(hose);
153 bus = hose->last_busno + 1;
154 }
155 }
156}
Stefan Roesee53b5cd2009-10-29 15:04:35 +0100157
Stefan Roese89bac402007-10-13 16:43:23 +0200158static int validate_endpoint(struct pci_controller *hose)
159{
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200160 if (hose->cfg_data == (u8 *)CONFIG_SYS_PCIE0_CFGBASE)
Stefan Roese89bac402007-10-13 16:43:23 +0200161 return (is_end_point(0));
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200162 else if (hose->cfg_data == (u8 *)CONFIG_SYS_PCIE1_CFGBASE)
Stefan Roese89bac402007-10-13 16:43:23 +0200163 return (is_end_point(1));
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200164#if CONFIG_SYS_PCIE_NR_PORTS > 2
165 else if (hose->cfg_data == (u8 *)CONFIG_SYS_PCIE2_CFGBASE)
Stefan Roese89bac402007-10-13 16:43:23 +0200166 return (is_end_point(2));
167#endif
168
169 return 0;
170}
171
Grzegorz Bernackid2f21332007-09-07 18:20:23 +0200172static u8* pcie_get_base(struct pci_controller *hose, unsigned int devfn)
173{
174 u8 *base = (u8*)hose->cfg_data;
175
176 /* use local configuration space for the first bus */
177 if (PCI_BUS(devfn) == 0) {
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200178 if (hose->cfg_data == (u8*)CONFIG_SYS_PCIE0_CFGBASE)
179 base = (u8*)CONFIG_SYS_PCIE0_XCFGBASE;
180 if (hose->cfg_data == (u8*)CONFIG_SYS_PCIE1_CFGBASE)
181 base = (u8*)CONFIG_SYS_PCIE1_XCFGBASE;
182#if CONFIG_SYS_PCIE_NR_PORTS > 2
183 if (hose->cfg_data == (u8*)CONFIG_SYS_PCIE2_CFGBASE)
184 base = (u8*)CONFIG_SYS_PCIE2_XCFGBASE;
Stefan Roese7a41bde2007-10-05 09:18:23 +0200185#endif
Grzegorz Bernackid2f21332007-09-07 18:20:23 +0200186 }
187
188 return base;
189}
190
Grzegorz Bernackieff9bc12007-09-07 17:46:18 +0200191static void pcie_dmer_disable(void)
Grzegorz Bernackid84fe302007-07-31 18:51:48 +0200192{
Grzegorz Bernackieff9bc12007-09-07 17:46:18 +0200193 mtdcr (DCRN_PEGPL_CFG(DCRN_PCIE0_BASE),
194 mfdcr (DCRN_PEGPL_CFG(DCRN_PCIE0_BASE)) | GPL_DMER_MASK_DISA);
195 mtdcr (DCRN_PEGPL_CFG(DCRN_PCIE1_BASE),
196 mfdcr (DCRN_PEGPL_CFG(DCRN_PCIE1_BASE)) | GPL_DMER_MASK_DISA);
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200197#if CONFIG_SYS_PCIE_NR_PORTS > 2
Grzegorz Bernackieff9bc12007-09-07 17:46:18 +0200198 mtdcr (DCRN_PEGPL_CFG(DCRN_PCIE2_BASE),
199 mfdcr (DCRN_PEGPL_CFG(DCRN_PCIE2_BASE)) | GPL_DMER_MASK_DISA);
Stefan Roese7a41bde2007-10-05 09:18:23 +0200200#endif
Grzegorz Bernackid84fe302007-07-31 18:51:48 +0200201}
202
Grzegorz Bernackieff9bc12007-09-07 17:46:18 +0200203static void pcie_dmer_enable(void)
Grzegorz Bernackid84fe302007-07-31 18:51:48 +0200204{
Grzegorz Bernackieff9bc12007-09-07 17:46:18 +0200205 mtdcr (DCRN_PEGPL_CFG (DCRN_PCIE0_BASE),
206 mfdcr (DCRN_PEGPL_CFG(DCRN_PCIE0_BASE)) & ~GPL_DMER_MASK_DISA);
207 mtdcr (DCRN_PEGPL_CFG (DCRN_PCIE1_BASE),
208 mfdcr (DCRN_PEGPL_CFG(DCRN_PCIE1_BASE)) & ~GPL_DMER_MASK_DISA);
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200209#if CONFIG_SYS_PCIE_NR_PORTS > 2
Grzegorz Bernackieff9bc12007-09-07 17:46:18 +0200210 mtdcr (DCRN_PEGPL_CFG (DCRN_PCIE2_BASE),
211 mfdcr (DCRN_PEGPL_CFG(DCRN_PCIE2_BASE)) & ~GPL_DMER_MASK_DISA);
Stefan Roese7a41bde2007-10-05 09:18:23 +0200212#endif
Grzegorz Bernackid84fe302007-07-31 18:51:48 +0200213}
214
Rafal Jaworowskia2e7ef02006-08-10 12:43:17 +0200215static int pcie_read_config(struct pci_controller *hose, unsigned int devfn,
216 int offset, int len, u32 *val) {
217
218 *val = 0;
Grzegorz Bernackid2f21332007-09-07 18:20:23 +0200219
Stefan Roese89bac402007-10-13 16:43:23 +0200220 if (validate_endpoint(hose))
221 return 0; /* No upstream config access */
222
Rafal Jaworowskia2e7ef02006-08-10 12:43:17 +0200223 /*
Grzegorz Bernackid2f21332007-09-07 18:20:23 +0200224 * Bus numbers are relative to hose->first_busno
Rafal Jaworowskia2e7ef02006-08-10 12:43:17 +0200225 */
Grzegorz Bernackid2f21332007-09-07 18:20:23 +0200226 devfn -= PCI_BDF(hose->first_busno, 0, 0);
227
228 /*
229 * NOTICE: configuration space ranges are currenlty mapped only for
230 * the first 16 buses, so such limit must be imposed. In case more
231 * buses are required the TLB settings in board/amcc/<board>/init.S
232 * need to be altered accordingly (one bus takes 1 MB of memory space).
233 */
234 if (PCI_BUS(devfn) >= 16)
Rafal Jaworowskia2e7ef02006-08-10 12:43:17 +0200235 return 0;
236
Grzegorz Bernackid2f21332007-09-07 18:20:23 +0200237 /*
238 * Only single device/single function is supported for the primary and
239 * secondary buses of the 440SPe host bridge.
240 */
241 if ((!((PCI_FUNC(devfn) == 0) && (PCI_DEV(devfn) == 0))) &&
242 ((PCI_BUS(devfn) == 0) || (PCI_BUS(devfn) == 1)))
243 return 0;
Stefan Roese43867c82007-10-02 11:44:46 +0200244
Stefan Roese53dcbca2011-11-15 08:02:04 +0000245 pcie_get_base(hose, devfn);
Rafal Jaworowskia2e7ef02006-08-10 12:43:17 +0200246 offset += devfn << 4;
247
Grzegorz Bernackieff9bc12007-09-07 17:46:18 +0200248 /*
249 * Reading from configuration space of non-existing device can
250 * generate transaction errors. For the read duration we suppress
251 * assertion of machine check exceptions to avoid those.
252 */
253 pcie_dmer_disable ();
254
Marek Vasut60814902011-10-21 14:17:15 +0000255 debug("%s: cfg_data=%p offset=%08x\n", __func__,
256 hose->cfg_data, offset);
Rafal Jaworowskia2e7ef02006-08-10 12:43:17 +0200257 switch (len) {
258 case 1:
Grzegorz Bernackieff9bc12007-09-07 17:46:18 +0200259 *val = in_8(hose->cfg_data + offset);
Rafal Jaworowskia2e7ef02006-08-10 12:43:17 +0200260 break;
261 case 2:
Grzegorz Bernackieff9bc12007-09-07 17:46:18 +0200262 *val = in_le16((u16 *)(hose->cfg_data + offset));
Rafal Jaworowskia2e7ef02006-08-10 12:43:17 +0200263 break;
264 default:
Grzegorz Bernackieff9bc12007-09-07 17:46:18 +0200265 *val = in_le32((u32*)(hose->cfg_data + offset));
Rafal Jaworowskia2e7ef02006-08-10 12:43:17 +0200266 break;
267 }
Grzegorz Bernackieff9bc12007-09-07 17:46:18 +0200268
269 pcie_dmer_enable ();
270
Rafal Jaworowskia2e7ef02006-08-10 12:43:17 +0200271 return 0;
272}
273
274static int pcie_write_config(struct pci_controller *hose, unsigned int devfn,
275 int offset, int len, u32 val) {
276
Stefan Roese89bac402007-10-13 16:43:23 +0200277 if (validate_endpoint(hose))
278 return 0; /* No upstream config access */
279
Rafal Jaworowskia2e7ef02006-08-10 12:43:17 +0200280 /*
Grzegorz Bernackid2f21332007-09-07 18:20:23 +0200281 * Bus numbers are relative to hose->first_busno
Rafal Jaworowskia2e7ef02006-08-10 12:43:17 +0200282 */
Grzegorz Bernackid2f21332007-09-07 18:20:23 +0200283 devfn -= PCI_BDF(hose->first_busno, 0, 0);
Stefan Roese43867c82007-10-02 11:44:46 +0200284
Grzegorz Bernackid2f21332007-09-07 18:20:23 +0200285 /*
286 * Same constraints as in pcie_read_config().
287 */
288 if (PCI_BUS(devfn) >= 16)
Rafal Jaworowskia2e7ef02006-08-10 12:43:17 +0200289 return 0;
290
Grzegorz Bernackid2f21332007-09-07 18:20:23 +0200291 if ((!((PCI_FUNC(devfn) == 0) && (PCI_DEV(devfn) == 0))) &&
292 ((PCI_BUS(devfn) == 0) || (PCI_BUS(devfn) == 1)))
293 return 0;
Stefan Roese43867c82007-10-02 11:44:46 +0200294
Stefan Roese53dcbca2011-11-15 08:02:04 +0000295 pcie_get_base(hose, devfn);
Rafal Jaworowskia2e7ef02006-08-10 12:43:17 +0200296 offset += devfn << 4;
297
Grzegorz Bernackieff9bc12007-09-07 17:46:18 +0200298 /*
299 * Suppress MCK exceptions, similar to pcie_read_config()
300 */
301 pcie_dmer_disable ();
302
Rafal Jaworowskia2e7ef02006-08-10 12:43:17 +0200303 switch (len) {
304 case 1:
305 out_8(hose->cfg_data + offset, val);
306 break;
307 case 2:
308 out_le16((u16 *)(hose->cfg_data + offset), val);
309 break;
310 default:
311 out_le32((u32 *)(hose->cfg_data + offset), val);
312 break;
313 }
Grzegorz Bernackieff9bc12007-09-07 17:46:18 +0200314
315 pcie_dmer_enable ();
316
Rafal Jaworowskia2e7ef02006-08-10 12:43:17 +0200317 return 0;
318}
319
320int pcie_read_config_byte(struct pci_controller *hose,pci_dev_t dev,int offset,u8 *val)
321{
322 u32 v;
323 int rv;
324
Grzegorz Bernackid2f21332007-09-07 18:20:23 +0200325 rv = pcie_read_config(hose, dev, offset, 1, &v);
Rafal Jaworowskia2e7ef02006-08-10 12:43:17 +0200326 *val = (u8)v;
327 return rv;
328}
329
330int pcie_read_config_word(struct pci_controller *hose,pci_dev_t dev,int offset,u16 *val)
331{
332 u32 v;
333 int rv;
334
335 rv = pcie_read_config(hose, dev, offset, 2, &v);
336 *val = (u16)v;
337 return rv;
338}
339
340int pcie_read_config_dword(struct pci_controller *hose,pci_dev_t dev,int offset,u32 *val)
341{
342 u32 v;
343 int rv;
344
345 rv = pcie_read_config(hose, dev, offset, 3, &v);
346 *val = (u32)v;
347 return rv;
348}
349
350int pcie_write_config_byte(struct pci_controller *hose,pci_dev_t dev,int offset,u8 val)
351{
352 return pcie_write_config(hose,(u32)dev,offset,1,val);
353}
354
355int pcie_write_config_word(struct pci_controller *hose,pci_dev_t dev,int offset,u16 val)
356{
357 return pcie_write_config(hose,(u32)dev,offset,2,(u32 )val);
358}
359
360int pcie_write_config_dword(struct pci_controller *hose,pci_dev_t dev,int offset,u32 val)
361{
362 return pcie_write_config(hose,(u32)dev,offset,3,(u32 )val);
363}
364
Stefan Roese7a41bde2007-10-05 09:18:23 +0200365#if defined(CONFIG_440SPE)
Stefan Roese9c00e512007-10-03 07:48:09 +0200366static void ppc4xx_setup_utl(u32 port) {
Rafal Jaworowskia2e7ef02006-08-10 12:43:17 +0200367
368 volatile void *utl_base = NULL;
369
370 /*
371 * Map UTL registers
372 */
373 switch (port) {
374 case 0:
Rafal Jaworowskie9799092006-08-11 12:35:52 +0200375 mtdcr(DCRN_PEGPL_REGBAH(PCIE0), 0x0000000c);
376 mtdcr(DCRN_PEGPL_REGBAL(PCIE0), 0x20000000);
377 mtdcr(DCRN_PEGPL_REGMSK(PCIE0), 0x00007001);
Rafal Jaworowskia2e7ef02006-08-10 12:43:17 +0200378 mtdcr(DCRN_PEGPL_SPECIAL(PCIE0), 0x68782800);
Rafal Jaworowskia2e7ef02006-08-10 12:43:17 +0200379 break;
380
381 case 1:
Rafal Jaworowskie9799092006-08-11 12:35:52 +0200382 mtdcr(DCRN_PEGPL_REGBAH(PCIE1), 0x0000000c);
383 mtdcr(DCRN_PEGPL_REGBAL(PCIE1), 0x20001000);
384 mtdcr(DCRN_PEGPL_REGMSK(PCIE1), 0x00007001);
Rafal Jaworowskia2e7ef02006-08-10 12:43:17 +0200385 mtdcr(DCRN_PEGPL_SPECIAL(PCIE1), 0x68782800);
Rafal Jaworowskia2e7ef02006-08-10 12:43:17 +0200386 break;
387
388 case 2:
Rafal Jaworowskie9799092006-08-11 12:35:52 +0200389 mtdcr(DCRN_PEGPL_REGBAH(PCIE2), 0x0000000c);
390 mtdcr(DCRN_PEGPL_REGBAL(PCIE2), 0x20002000);
391 mtdcr(DCRN_PEGPL_REGMSK(PCIE2), 0x00007001);
Rafal Jaworowskia2e7ef02006-08-10 12:43:17 +0200392 mtdcr(DCRN_PEGPL_SPECIAL(PCIE2), 0x68782800);
Rafal Jaworowskia2e7ef02006-08-10 12:43:17 +0200393 break;
394 }
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200395 utl_base = (unsigned int *)(CONFIG_SYS_PCIE_BASE + 0x1000 * port);
Wolfgang Denkdd314d12006-08-27 18:10:01 +0200396
Rafal Jaworowskia2e7ef02006-08-10 12:43:17 +0200397 /*
398 * Set buffer allocations and then assert VRB and TXE.
399 */
400 out_be32(utl_base + PEUTL_OUTTR, 0x08000000);
401 out_be32(utl_base + PEUTL_INTR, 0x02000000);
402 out_be32(utl_base + PEUTL_OPDBSZ, 0x10000000);
403 out_be32(utl_base + PEUTL_PBBSZ, 0x53000000);
404 out_be32(utl_base + PEUTL_IPHBSZ, 0x08000000);
405 out_be32(utl_base + PEUTL_IPDBSZ, 0x10000000);
406 out_be32(utl_base + PEUTL_RCIRQEN, 0x00f00000);
Rafal Jaworowskie9799092006-08-11 12:35:52 +0200407 out_be32(utl_base + PEUTL_PCTL, 0x80800066);
Rafal Jaworowskia2e7ef02006-08-10 12:43:17 +0200408}
409
410static int check_error(void)
411{
412 u32 valPE0, valPE1, valPE2;
413 int err = 0;
414
415 /* SDR0_PEGPLLLCT1 reset */
Stefan Roesebdd13d12008-03-11 15:05:26 +0100416 if (!(valPE0 = SDR_READ(PESDR0_PLLLCT1) & 0x01000000))
Rafal Jaworowskia2e7ef02006-08-10 12:43:17 +0200417 printf("PCIE: SDR0_PEGPLLLCT1 reset error 0x%x\n", valPE0);
Rafal Jaworowskia2e7ef02006-08-10 12:43:17 +0200418
419 valPE0 = SDR_READ(PESDR0_RCSSET);
420 valPE1 = SDR_READ(PESDR1_RCSSET);
421 valPE2 = SDR_READ(PESDR2_RCSSET);
422
423 /* SDR0_PExRCSSET rstgu */
424 if (!(valPE0 & 0x01000000) ||
425 !(valPE1 & 0x01000000) ||
426 !(valPE2 & 0x01000000)) {
427 printf("PCIE: SDR0_PExRCSSET rstgu error\n");
428 err = -1;
429 }
430
431 /* SDR0_PExRCSSET rstdl */
432 if (!(valPE0 & 0x00010000) ||
433 !(valPE1 & 0x00010000) ||
434 !(valPE2 & 0x00010000)) {
435 printf("PCIE: SDR0_PExRCSSET rstdl error\n");
436 err = -1;
437 }
438
439 /* SDR0_PExRCSSET rstpyn */
440 if ((valPE0 & 0x00001000) ||
441 (valPE1 & 0x00001000) ||
442 (valPE2 & 0x00001000)) {
443 printf("PCIE: SDR0_PExRCSSET rstpyn error\n");
444 err = -1;
445 }
446
447 /* SDR0_PExRCSSET hldplb */
448 if ((valPE0 & 0x10000000) ||
449 (valPE1 & 0x10000000) ||
450 (valPE2 & 0x10000000)) {
451 printf("PCIE: SDR0_PExRCSSET hldplb error\n");
452 err = -1;
453 }
454
455 /* SDR0_PExRCSSET rdy */
456 if ((valPE0 & 0x00100000) ||
457 (valPE1 & 0x00100000) ||
458 (valPE2 & 0x00100000)) {
459 printf("PCIE: SDR0_PExRCSSET rdy error\n");
460 err = -1;
461 }
462
463 /* SDR0_PExRCSSET shutdown */
464 if ((valPE0 & 0x00000100) ||
465 (valPE1 & 0x00000100) ||
466 (valPE2 & 0x00000100)) {
467 printf("PCIE: SDR0_PExRCSSET shutdown error\n");
468 err = -1;
469 }
470 return err;
471}
472
473/*
474 * Initialize PCI Express core
475 */
Stefan Roese9c00e512007-10-03 07:48:09 +0200476int ppc4xx_init_pcie(void)
Rafal Jaworowskia2e7ef02006-08-10 12:43:17 +0200477{
478 int time_out = 20;
479
480 /* Set PLL clock receiver to LVPECL */
481 SDR_WRITE(PESDR0_PLLLCT1, SDR_READ(PESDR0_PLLLCT1) | 1 << 28);
482
Rupjyoti Sarmah73343ca2009-09-21 11:26:19 -0700483 if (check_error()) {
484 printf("ERROR: failed to set PCIe reference clock receiver --"
485 "PESDR0_PLLLCT1 = 0x%08x\n", SDR_READ(PESDR0_PLLLCT1));
486
Rafal Jaworowskia2e7ef02006-08-10 12:43:17 +0200487 return -1;
Rupjyoti Sarmah73343ca2009-09-21 11:26:19 -0700488 }
Rafal Jaworowskia2e7ef02006-08-10 12:43:17 +0200489
Rupjyoti Sarmah73343ca2009-09-21 11:26:19 -0700490 /* Did resistance calibration work? */
491 if (!(SDR_READ(PESDR0_PLLLCT2) & 0x10000)) {
492 printf("ERROR: PCIe resistance calibration failed --"
493 "PESDR0_PLLLCT2 = 0x%08x\n", SDR_READ(PESDR0_PLLLCT2));
494
Rafal Jaworowskia2e7ef02006-08-10 12:43:17 +0200495 return -1;
496 }
497 /* De-assert reset of PCIe PLL, wait for lock */
498 SDR_WRITE(PESDR0_PLLLCT1, SDR_READ(PESDR0_PLLLCT1) & ~(1 << 24));
Rupjyoti Sarmah73343ca2009-09-21 11:26:19 -0700499 udelay(300); /* 300 uS is maximum time lock should take */
Rafal Jaworowskia2e7ef02006-08-10 12:43:17 +0200500
Stefan Roese074e9752006-08-29 08:05:15 +0200501 while (time_out) {
Rafal Jaworowskia2e7ef02006-08-10 12:43:17 +0200502 if (!(SDR_READ(PESDR0_PLLLCT3) & 0x10000000)) {
503 time_out--;
Rupjyoti Sarmah73343ca2009-09-21 11:26:19 -0700504 udelay(20); /* Wait 20 uS more if needed */
Rafal Jaworowskia2e7ef02006-08-10 12:43:17 +0200505 } else
506 break;
507 }
508 if (!time_out) {
Rupjyoti Sarmah73343ca2009-09-21 11:26:19 -0700509 printf("ERROR: PCIe PLL VCO output not locked to ref clock --"
510 "PESDR0_PLLLCTS=0x%08x\n", SDR_READ(PESDR0_PLLLCT3));
511
Rafal Jaworowskia2e7ef02006-08-10 12:43:17 +0200512 return -1;
513 }
Stefan Roesebdd13d12008-03-11 15:05:26 +0100514 return 0;
515}
516#endif
517
518#if defined(CONFIG_460EX) || defined(CONFIG_460GT)
519static void ppc4xx_setup_utl(u32 port)
520{
521 volatile void *utl_base = NULL;
522
523 /*
524 * Map UTL registers at 0x0801_n000 (4K 0xfff mask) PEGPLn_REGMSK
525 */
526 switch (port) {
527 case 0:
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200528 mtdcr(DCRN_PEGPL_REGBAH(PCIE0), U64_TO_U32_HIGH(CONFIG_SYS_PCIE0_UTLBASE));
529 mtdcr(DCRN_PEGPL_REGBAL(PCIE0), U64_TO_U32_LOW(CONFIG_SYS_PCIE0_UTLBASE));
Stefan Roesebdd13d12008-03-11 15:05:26 +0100530 mtdcr(DCRN_PEGPL_REGMSK(PCIE0), 0x00007001); /* BAM 11100000=4KB */
531 mtdcr(DCRN_PEGPL_SPECIAL(PCIE0), 0);
532 break;
533
534 case 1:
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200535 mtdcr(DCRN_PEGPL_REGBAH(PCIE1), U64_TO_U32_HIGH(CONFIG_SYS_PCIE0_UTLBASE));
536 mtdcr(DCRN_PEGPL_REGBAL(PCIE1), U64_TO_U32_LOW(CONFIG_SYS_PCIE0_UTLBASE)
Stefan Roesebdd13d12008-03-11 15:05:26 +0100537 + 0x1000);
538 mtdcr(DCRN_PEGPL_REGMSK(PCIE1), 0x00007001); /* BAM 11100000=4KB */
539 mtdcr(DCRN_PEGPL_SPECIAL(PCIE1), 0);
540 break;
541 }
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200542 utl_base = (unsigned int *)(CONFIG_SYS_PCIE_BASE + 0x1000 * port);
Stefan Roesebdd13d12008-03-11 15:05:26 +0100543
544 /*
545 * Set buffer allocations and then assert VRB and TXE.
546 */
547 out_be32(utl_base + PEUTL_PBCTL, 0x0800000c); /* PLBME, CRRE */
548 out_be32(utl_base + PEUTL_OUTTR, 0x08000000);
549 out_be32(utl_base + PEUTL_INTR, 0x02000000);
550 out_be32(utl_base + PEUTL_OPDBSZ, 0x04000000); /* OPD = 512 Bytes */
551 out_be32(utl_base + PEUTL_PBBSZ, 0x00000000); /* Max 512 Bytes */
552 out_be32(utl_base + PEUTL_IPHBSZ, 0x02000000);
553 out_be32(utl_base + PEUTL_IPDBSZ, 0x04000000); /* IPD = 512 Bytes */
554 out_be32(utl_base + PEUTL_RCIRQEN, 0x00f00000);
555 out_be32(utl_base + PEUTL_PCTL, 0x80800066); /* VRB,TXE,timeout=default */
556}
557
558/*
559 * TODO: double check PCI express SDR based on the latest user manual
Wolfgang Denka1be4762008-05-20 16:00:29 +0200560 * Some registers specified here no longer exist.. has to be
561 * updated based on the final EAS spec.
Stefan Roesebdd13d12008-03-11 15:05:26 +0100562 */
563static int check_error(void)
564{
565 u32 valPE0, valPE1;
566 int err = 0;
567
568 valPE0 = SDR_READ(SDRN_PESDR_RCSSET(0));
569 valPE1 = SDR_READ(SDRN_PESDR_RCSSET(1));
570
571 /* SDR0_PExRCSSET rstgu */
572 if (!(valPE0 & PESDRx_RCSSET_RSTGU) || !(valPE1 & PESDRx_RCSSET_RSTGU)) {
573 printf("PCIE: SDR0_PExRCSSET rstgu error\n");
574 err = -1;
575 }
576
577 /* SDR0_PExRCSSET rstdl */
578 if (!(valPE0 & PESDRx_RCSSET_RSTDL) || !(valPE1 & PESDRx_RCSSET_RSTDL)) {
579 printf("PCIE: SDR0_PExRCSSET rstdl error\n");
580 err = -1;
581 }
582
583 /* SDR0_PExRCSSET rstpyn */
584 if ((valPE0 & PESDRx_RCSSET_RSTPYN) || (valPE1 & PESDRx_RCSSET_RSTPYN)) {
585 printf("PCIE: SDR0_PExRCSSET rstpyn error\n");
586 err = -1;
587 }
588
589 /* SDR0_PExRCSSET hldplb */
590 if ((valPE0 & PESDRx_RCSSET_HLDPLB) || (valPE1 & PESDRx_RCSSET_HLDPLB)) {
591 printf("PCIE: SDR0_PExRCSSET hldplb error\n");
592 err = -1;
593 }
594
595 /* SDR0_PExRCSSET rdy */
596 if ((valPE0 & PESDRx_RCSSET_RDY) || (valPE1 & PESDRx_RCSSET_RDY)) {
597 printf("PCIE: SDR0_PExRCSSET rdy error\n");
598 err = -1;
599 }
600
601 return err;
602}
603
604/*
605 * Initialize PCI Express core as described in User Manual
606 * TODO: double check PE SDR PLL Register with the updated user manual.
607 */
608int ppc4xx_init_pcie(void)
609{
610 if (check_error())
611 return -1;
612
Rafal Jaworowskia2e7ef02006-08-10 12:43:17 +0200613 return 0;
614}
Stefan Roesebdd13d12008-03-11 15:05:26 +0100615#endif /* CONFIG_460EX */
616
617#if defined(CONFIG_405EX)
Stefan Roese1ce9fe92007-11-16 14:16:54 +0100618static void ppc4xx_setup_utl(u32 port)
619{
620 u32 utl_base;
621
622 /*
623 * Map UTL registers at 0xef4f_n000 (4K 0xfff mask) PEGPLn_REGMSK
624 */
625 switch (port) {
626 case 0:
627 mtdcr(DCRN_PEGPL_REGBAH(PCIE0), 0x00000000);
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200628 mtdcr(DCRN_PEGPL_REGBAL(PCIE0), CONFIG_SYS_PCIE0_UTLBASE);
Stefan Roese95805952007-11-18 14:44:44 +0100629 mtdcr(DCRN_PEGPL_REGMSK(PCIE0), 0x00007001); /* 4k region, valid */
Stefan Roese1ce9fe92007-11-16 14:16:54 +0100630 mtdcr(DCRN_PEGPL_SPECIAL(PCIE0), 0);
631 break;
632
633 case 1:
634 mtdcr(DCRN_PEGPL_REGBAH(PCIE1), 0x00000000);
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200635 mtdcr(DCRN_PEGPL_REGBAL(PCIE1), CONFIG_SYS_PCIE1_UTLBASE);
Stefan Roese95805952007-11-18 14:44:44 +0100636 mtdcr(DCRN_PEGPL_REGMSK(PCIE1), 0x00007001); /* 4k region, valid */
Stefan Roese1ce9fe92007-11-16 14:16:54 +0100637 mtdcr(DCRN_PEGPL_SPECIAL(PCIE1), 0);
638
639 break;
640 }
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200641 utl_base = (port==0) ? CONFIG_SYS_PCIE0_UTLBASE : CONFIG_SYS_PCIE1_UTLBASE;
Stefan Roese1ce9fe92007-11-16 14:16:54 +0100642
643 /*
644 * Set buffer allocations and then assert VRB and TXE.
645 */
646 out_be32((u32 *)(utl_base + PEUTL_OUTTR), 0x02000000);
647 out_be32((u32 *)(utl_base + PEUTL_INTR), 0x02000000);
648 out_be32((u32 *)(utl_base + PEUTL_OPDBSZ), 0x04000000);
649 out_be32((u32 *)(utl_base + PEUTL_PBBSZ), 0x21000000);
650 out_be32((u32 *)(utl_base + PEUTL_IPHBSZ), 0x02000000);
651 out_be32((u32 *)(utl_base + PEUTL_IPDBSZ), 0x04000000);
652 out_be32((u32 *)(utl_base + PEUTL_RCIRQEN), 0x00f00000);
653 out_be32((u32 *)(utl_base + PEUTL_PCTL), 0x80800066);
654
655 out_be32((u32 *)(utl_base + PEUTL_PBCTL), 0x0800000c);
656 out_be32((u32 *)(utl_base + PEUTL_RCSTA),
657 in_be32((u32 *)(utl_base + PEUTL_RCSTA)) | 0x000040000);
658}
659
Stefan Roese7a41bde2007-10-05 09:18:23 +0200660int ppc4xx_init_pcie(void)
661{
662 /*
663 * Nothing to do on 405EX
664 */
665 return 0;
666}
Stefan Roesebdd13d12008-03-11 15:05:26 +0100667#endif /* CONFIG_405EX */
Rafal Jaworowskia2e7ef02006-08-10 12:43:17 +0200668
Stefan Roese074e9752006-08-29 08:05:15 +0200669/*
Stefan Roesea0d96342007-10-03 10:38:09 +0200670 * Board-specific pcie initialization
671 * Platform code can reimplement ppc4xx_init_pcie_port_hw() if needed
672 */
673
674/*
675 * Initialize various parts of the PCI Express core for our port:
676 *
677 * - Set as a root port and enable max width
678 * (PXIE0 -> X8, PCIE1 and PCIE2 -> X4).
679 * - Set up UTL configuration.
680 * - Increase SERDES drive strength to levels suggested by AMCC.
681 * - De-assert RSTPYN, RSTDL and RSTGU.
682 *
683 * NOTICE for 440SPE revB chip: PESDRn_UTLSET2 is not set - we leave it
684 * with default setting 0x11310000. The register has new fields,
685 * PESDRn_UTLSET2[LKINE] in particular: clearing it leads to PCIE core
686 * hang.
687 */
688#if defined(CONFIG_440SPE)
689int __ppc4xx_init_pcie_port_hw(int port, int rootport)
690{
691 u32 val = 1 << 24;
692 u32 utlset1;
693
694 if (rootport) {
695 val = PTYPE_ROOT_PORT << 20;
696 utlset1 = 0x21222222;
697 } else {
698 val = PTYPE_LEGACY_ENDPOINT << 20;
699 utlset1 = 0x20222222;
700 }
701
702 if (port == 0)
703 val |= LNKW_X8 << 12;
704 else
705 val |= LNKW_X4 << 12;
706
707 SDR_WRITE(SDRN_PESDR_DLPSET(port), val);
708 SDR_WRITE(SDRN_PESDR_UTLSET1(port), utlset1);
709 if (!ppc440spe_revB())
710 SDR_WRITE(SDRN_PESDR_UTLSET2(port), 0x11000000);
711 SDR_WRITE(SDRN_PESDR_HSSL0SET1(port), 0x35000000);
712 SDR_WRITE(SDRN_PESDR_HSSL1SET1(port), 0x35000000);
713 SDR_WRITE(SDRN_PESDR_HSSL2SET1(port), 0x35000000);
714 SDR_WRITE(SDRN_PESDR_HSSL3SET1(port), 0x35000000);
715 if (port == 0) {
716 SDR_WRITE(PESDR0_HSSL4SET1, 0x35000000);
717 SDR_WRITE(PESDR0_HSSL5SET1, 0x35000000);
718 SDR_WRITE(PESDR0_HSSL6SET1, 0x35000000);
719 SDR_WRITE(PESDR0_HSSL7SET1, 0x35000000);
720 }
721 SDR_WRITE(SDRN_PESDR_RCSSET(port), (SDR_READ(SDRN_PESDR_RCSSET(port)) &
722 ~(1 << 24 | 1 << 16)) | 1 << 12);
723
724 return 0;
725}
726#endif /* CONFIG_440SPE */
727
Stefan Roesebdd13d12008-03-11 15:05:26 +0100728#if defined(CONFIG_460EX) || defined(CONFIG_460GT)
729int __ppc4xx_init_pcie_port_hw(int port, int rootport)
730{
Stefan Roese142b1d42008-07-01 17:03:19 +0200731 u32 val;
Stefan Roesebdd13d12008-03-11 15:05:26 +0100732 u32 utlset1;
733
Stefan Roese142b1d42008-07-01 17:03:19 +0200734 if (rootport)
Stefan Roesebdd13d12008-03-11 15:05:26 +0100735 val = PTYPE_ROOT_PORT << 20;
Stefan Roese142b1d42008-07-01 17:03:19 +0200736 else
Stefan Roesebdd13d12008-03-11 15:05:26 +0100737 val = PTYPE_LEGACY_ENDPOINT << 20;
Stefan Roesebdd13d12008-03-11 15:05:26 +0100738
739 if (port == 0) {
740 val |= LNKW_X1 << 12;
Stefan Roese142b1d42008-07-01 17:03:19 +0200741 utlset1 = 0x20000000;
Stefan Roesebdd13d12008-03-11 15:05:26 +0100742 } else {
743 val |= LNKW_X4 << 12;
Stefan Roese142b1d42008-07-01 17:03:19 +0200744 utlset1 = 0x20101101;
Stefan Roesebdd13d12008-03-11 15:05:26 +0100745 }
746
747 SDR_WRITE(SDRN_PESDR_DLPSET(port), val);
748 SDR_WRITE(SDRN_PESDR_UTLSET1(port), utlset1);
749 SDR_WRITE(SDRN_PESDR_UTLSET2(port), 0x01210000);
750
751 switch (port) {
752 case 0:
753 SDR_WRITE(PESDR0_L0CDRCTL, 0x00003230);
Tirumala R Marri75e22a42008-08-21 21:54:53 -0700754 SDR_WRITE(PESDR0_L0DRV, 0x00000130);
Stefan Roesebdd13d12008-03-11 15:05:26 +0100755 SDR_WRITE(PESDR0_L0CLK, 0x00000006);
756
757 SDR_WRITE(PESDR0_PHY_CTL_RST,0x10000000);
758 break;
759
760 case 1:
761 SDR_WRITE(PESDR1_L0CDRCTL, 0x00003230);
762 SDR_WRITE(PESDR1_L1CDRCTL, 0x00003230);
763 SDR_WRITE(PESDR1_L2CDRCTL, 0x00003230);
764 SDR_WRITE(PESDR1_L3CDRCTL, 0x00003230);
Tirumala R Marri75e22a42008-08-21 21:54:53 -0700765 SDR_WRITE(PESDR1_L0DRV, 0x00000130);
766 SDR_WRITE(PESDR1_L1DRV, 0x00000130);
767 SDR_WRITE(PESDR1_L2DRV, 0x00000130);
768 SDR_WRITE(PESDR1_L3DRV, 0x00000130);
Stefan Roesebdd13d12008-03-11 15:05:26 +0100769 SDR_WRITE(PESDR1_L0CLK, 0x00000006);
770 SDR_WRITE(PESDR1_L1CLK, 0x00000006);
771 SDR_WRITE(PESDR1_L2CLK, 0x00000006);
772 SDR_WRITE(PESDR1_L3CLK, 0x00000006);
773
774 SDR_WRITE(PESDR1_PHY_CTL_RST,0x10000000);
775 break;
776 }
777
778 SDR_WRITE(SDRN_PESDR_RCSSET(port), SDR_READ(SDRN_PESDR_RCSSET(port)) |
779 (PESDRx_RCSSET_RSTGU | PESDRx_RCSSET_RSTPYN));
780
781 /* Poll for PHY reset */
782 switch (port) {
783 case 0:
784 while (!(SDR_READ(PESDR0_RSTSTA) & 0x1))
785 udelay(10);
786 break;
787 case 1:
788 while (!(SDR_READ(PESDR1_RSTSTA) & 0x1))
789 udelay(10);
790 break;
791 }
792
793 SDR_WRITE(SDRN_PESDR_RCSSET(port),
794 (SDR_READ(SDRN_PESDR_RCSSET(port)) &
795 ~(PESDRx_RCSSET_RSTGU | PESDRx_RCSSET_RSTDL)) |
796 PESDRx_RCSSET_RSTPYN);
797
798 return 0;
799}
800#endif /* CONFIG_440SPE */
801
Stefan Roesea0d96342007-10-03 10:38:09 +0200802#if defined(CONFIG_405EX)
803int __ppc4xx_init_pcie_port_hw(int port, int rootport)
804{
805 u32 val;
806
807 if (rootport)
808 val = 0x00401000;
809 else
810 val = 0x00101000;
811
812 SDR_WRITE(SDRN_PESDR_DLPSET(port), val);
Stefan Roese4aabdc82007-11-13 08:06:11 +0100813 SDR_WRITE(SDRN_PESDR_UTLSET1(port), 0x00000000);
814 SDR_WRITE(SDRN_PESDR_UTLSET2(port), 0x01010000);
Stefan Roesea0d96342007-10-03 10:38:09 +0200815 SDR_WRITE(SDRN_PESDR_PHYSET1(port), 0x720F0000);
816 SDR_WRITE(SDRN_PESDR_PHYSET2(port), 0x70600003);
817
818 /* Assert the PE0_PHY reset */
819 SDR_WRITE(SDRN_PESDR_RCSSET(port), 0x01010000);
820 udelay(1000);
821
822 /* deassert the PE0_hotreset */
Stefan Roesee7fe4c52007-10-18 07:39:38 +0200823 if (is_end_point(port))
824 SDR_WRITE(SDRN_PESDR_RCSSET(port), 0x01111000);
825 else
826 SDR_WRITE(SDRN_PESDR_RCSSET(port), 0x01101000);
Stefan Roesea0d96342007-10-03 10:38:09 +0200827
828 /* poll for phy !reset */
829 while (!(SDR_READ(SDRN_PESDR_PHYSTA(port)) & 0x00001000))
830 ;
831
832 /* deassert the PE0_gpl_utl_reset */
833 SDR_WRITE(SDRN_PESDR_RCSSET(port), 0x00101000);
834
835 if (port == 0)
836 mtdcr(DCRN_PEGPL_CFG(PCIE0), 0x10000000); /* guarded on */
837 else
838 mtdcr(DCRN_PEGPL_CFG(PCIE1), 0x10000000); /* guarded on */
839
840 return 0;
841}
842#endif /* CONFIG_405EX */
843
844int ppc4xx_init_pcie_port_hw(int port, int rootport)
Stefan Roese95805952007-11-18 14:44:44 +0100845__attribute__((weak, alias("__ppc4xx_init_pcie_port_hw")));
Stefan Roesea0d96342007-10-03 10:38:09 +0200846
847/*
848 * We map PCI Express configuration access into the 512MB regions
849 *
850 * NOTICE: revB is very strict about PLB real addressess and ranges to
851 * be mapped for config space; it seems to only work with d_nnnn_nnnn
852 * range (hangs the core upon config transaction attempts when set
853 * otherwise) while revA uses c_nnnn_nnnn.
854 *
Stefan Roesebdd13d12008-03-11 15:05:26 +0100855 * For 440SPe revA:
Stefan Roesea0d96342007-10-03 10:38:09 +0200856 * PCIE0: 0xc_4000_0000
857 * PCIE1: 0xc_8000_0000
858 * PCIE2: 0xc_c000_0000
859 *
Stefan Roesebdd13d12008-03-11 15:05:26 +0100860 * For 440SPe revB:
Stefan Roesea0d96342007-10-03 10:38:09 +0200861 * PCIE0: 0xd_0000_0000
862 * PCIE1: 0xd_2000_0000
863 * PCIE2: 0xd_4000_0000
864 *
865 * For 405EX:
866 * PCIE0: 0xa000_0000
867 * PCIE1: 0xc000_0000
Stefan Roesebdd13d12008-03-11 15:05:26 +0100868 *
869 * For 460EX/GT:
870 * PCIE0: 0xd_0000_0000
871 * PCIE1: 0xd_2000_0000
Stefan Roesea0d96342007-10-03 10:38:09 +0200872 */
873static inline u64 ppc4xx_get_cfgaddr(int port)
874{
875#if defined(CONFIG_405EX)
876 if (port == 0)
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200877 return (u64)CONFIG_SYS_PCIE0_CFGBASE;
Stefan Roesea0d96342007-10-03 10:38:09 +0200878 else
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200879 return (u64)CONFIG_SYS_PCIE1_CFGBASE;
Stefan Roesea0d96342007-10-03 10:38:09 +0200880#endif
881#if defined(CONFIG_440SPE)
882 if (ppc440spe_revB()) {
883 switch (port) {
884 default: /* to satisfy compiler */
885 case 0:
886 return 0x0000000d00000000ULL;
887 case 1:
888 return 0x0000000d20000000ULL;
889 case 2:
890 return 0x0000000d40000000ULL;
891 }
892 } else {
893 switch (port) {
894 default: /* to satisfy compiler */
895 case 0:
896 return 0x0000000c40000000ULL;
897 case 1:
898 return 0x0000000c80000000ULL;
899 case 2:
900 return 0x0000000cc0000000ULL;
901 }
902 }
903#endif
Stefan Roesebdd13d12008-03-11 15:05:26 +0100904#if defined(CONFIG_460EX) || defined(CONFIG_460GT)
905 if (port == 0)
906 return 0x0000000d00000000ULL;
907 else
908 return 0x0000000d20000000ULL;
909#endif
Stefan Roesea0d96342007-10-03 10:38:09 +0200910}
911
912/*
Peter Tyser62825a52010-01-17 15:38:26 -0600913 * 4xx boards as endpoint and root point setup
Stefan Roese074e9752006-08-29 08:05:15 +0200914 * and
915 * testing inbound and out bound windows
916 *
Stefan Roesea0d96342007-10-03 10:38:09 +0200917 * 4xx boards can be plugged into another 4xx boards or you can get PCI-E
Stefan Roese074e9752006-08-29 08:05:15 +0200918 * cable which can be used to setup loop back from one port to another port.
919 * Please rememeber that unless there is a endpoint plugged in to root port it
920 * will not initialize. It is the same in case of endpoint , unless there is
921 * root port attached it will not initialize.
922 *
923 * In this release of software all the PCI-E ports are configured as either
924 * endpoint or rootpoint.In future we will have support for selective ports
925 * setup as endpoint and root point in single board.
926 *
927 * Once your board came up as root point , you can verify by reading
928 * /proc/bus/pci/devices. Where you can see the configuration registers
Peter Tyser62825a52010-01-17 15:38:26 -0600929 * of endpoint device attached to the port.
Stefan Roese074e9752006-08-29 08:05:15 +0200930 *
Stefan Roesea0d96342007-10-03 10:38:09 +0200931 * Enpoint cofiguration can be verified by connecting 4xx board to any
932 * host or another 4xx board. Then try to scan the device. In case of
Stefan Roese074e9752006-08-29 08:05:15 +0200933 * linux use "lspci" or appripriate os command.
934 *
Stefan Roesea0d96342007-10-03 10:38:09 +0200935 * How do I verify the inbound and out bound windows ? (4xx to 4xx)
Stefan Roese074e9752006-08-29 08:05:15 +0200936 * in this configuration inbound and outbound windows are setup to access
937 * sram memroy area. SRAM is at 0x4 0000 0000 , on PLB bus. This address
938 * is mapped at 0x90000000. From u-boot prompt write data 0xb000 0000,
939 * This is waere your POM(PLB out bound memory window) mapped. then
Stefan Roesea0d96342007-10-03 10:38:09 +0200940 * read the data from other 4xx board's u-boot prompt at address
Stefan Roese074e9752006-08-29 08:05:15 +0200941 * 0x9000 0000(SRAM). Data should match.
942 * In case of inbound , write data to u-boot command prompt at 0xb000 0000
943 * which is mapped to 0x4 0000 0000. Now on rootpoint yucca u-boot prompt check
944 * data at 0x9000 0000(SRAM).Data should match.
945 */
Stefan Roesea0d96342007-10-03 10:38:09 +0200946int ppc4xx_init_pcie_port(int port, int rootport)
Rafal Jaworowskia2e7ef02006-08-10 12:43:17 +0200947{
948 static int core_init;
949 volatile u32 val = 0;
950 int attempts;
Stefan Roesea0d96342007-10-03 10:38:09 +0200951 u64 addr;
952 u32 low, high;
Rafal Jaworowskia2e7ef02006-08-10 12:43:17 +0200953
954 if (!core_init) {
Stefan Roese9c00e512007-10-03 07:48:09 +0200955 if (ppc4xx_init_pcie())
Rafal Jaworowskia2e7ef02006-08-10 12:43:17 +0200956 return -1;
Stefan Roese89bac402007-10-13 16:43:23 +0200957 ++core_init;
Rafal Jaworowskia2e7ef02006-08-10 12:43:17 +0200958 }
959
960 /*
Stefan Roesea0d96342007-10-03 10:38:09 +0200961 * Initialize various parts of the PCI Express core for our port
Rafal Jaworowskia2e7ef02006-08-10 12:43:17 +0200962 */
Stefan Roesea0d96342007-10-03 10:38:09 +0200963 ppc4xx_init_pcie_port_hw(port, rootport);
Rafal Jaworowskia2e7ef02006-08-10 12:43:17 +0200964
Stefan Roese074e9752006-08-29 08:05:15 +0200965 /*
966 * Notice: the following delay has critical impact on device
967 * initialization - if too short (<50ms) the link doesn't get up.
968 */
969 mdelay(100);
970
Stefan Roesebe6fea92007-10-03 21:16:32 +0200971 val = SDR_READ(SDRN_PESDR_RCSSTS(port));
Stefan Roese074e9752006-08-29 08:05:15 +0200972 if (val & (1 << 20)) {
973 printf("PCIE%d: PGRST failed %08x\n", port, val);
974 return -1;
975 }
976
977 /*
978 * Verify link is up
979 */
Stefan Roesebe6fea92007-10-03 21:16:32 +0200980 val = SDR_READ(SDRN_PESDR_LOOP(port));
Stefan Roese074e9752006-08-29 08:05:15 +0200981 if (!(val & 0x00001000)) {
982 printf("PCIE%d: link is not up.\n", port);
Stefan Roese14fd12f2009-10-02 14:35:16 +0200983 return -ENODEV;
Stefan Roese074e9752006-08-29 08:05:15 +0200984 }
985
986 /*
987 * Setup UTL registers - but only on revA!
988 * We use default settings for revB chip.
989 */
990 if (!ppc440spe_revB())
Stefan Roese9c00e512007-10-03 07:48:09 +0200991 ppc4xx_setup_utl(port);
Stefan Roese074e9752006-08-29 08:05:15 +0200992
993 /*
994 * We map PCI Express configuration access into the 512MB regions
Stefan Roese074e9752006-08-29 08:05:15 +0200995 */
Stefan Roesea0d96342007-10-03 10:38:09 +0200996 addr = ppc4xx_get_cfgaddr(port);
Stefan Roese7a41bde2007-10-05 09:18:23 +0200997 low = U64_TO_U32_LOW(addr);
998 high = U64_TO_U32_HIGH(addr);
Stefan Roese074e9752006-08-29 08:05:15 +0200999
1000 switch (port) {
1001 case 0:
Stefan Roesea0d96342007-10-03 10:38:09 +02001002 mtdcr(DCRN_PEGPL_CFGBAH(PCIE0), high);
1003 mtdcr(DCRN_PEGPL_CFGBAL(PCIE0), low);
Stefan Roese074e9752006-08-29 08:05:15 +02001004 mtdcr(DCRN_PEGPL_CFGMSK(PCIE0), 0xe0000001); /* 512MB region, valid */
1005 break;
Stefan Roese074e9752006-08-29 08:05:15 +02001006 case 1:
Stefan Roesea0d96342007-10-03 10:38:09 +02001007 mtdcr(DCRN_PEGPL_CFGBAH(PCIE1), high);
1008 mtdcr(DCRN_PEGPL_CFGBAL(PCIE1), low);
Stefan Roese074e9752006-08-29 08:05:15 +02001009 mtdcr(DCRN_PEGPL_CFGMSK(PCIE1), 0xe0000001); /* 512MB region, valid */
1010 break;
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +02001011#if CONFIG_SYS_PCIE_NR_PORTS > 2
Stefan Roese074e9752006-08-29 08:05:15 +02001012 case 2:
Stefan Roesea0d96342007-10-03 10:38:09 +02001013 mtdcr(DCRN_PEGPL_CFGBAH(PCIE2), high);
1014 mtdcr(DCRN_PEGPL_CFGBAL(PCIE2), low);
Stefan Roese074e9752006-08-29 08:05:15 +02001015 mtdcr(DCRN_PEGPL_CFGMSK(PCIE2), 0xe0000001); /* 512MB region, valid */
1016 break;
Stefan Roese7a41bde2007-10-05 09:18:23 +02001017#endif
Stefan Roese074e9752006-08-29 08:05:15 +02001018 }
1019
1020 /*
1021 * Check for VC0 active and assert RDY.
1022 */
1023 attempts = 10;
Stefan Roesebe6fea92007-10-03 21:16:32 +02001024 while(!(SDR_READ(SDRN_PESDR_RCSSTS(port)) & (1 << 16))) {
Stefan Roesea0d96342007-10-03 10:38:09 +02001025 if (!(attempts--)) {
1026 printf("PCIE%d: VC0 not active\n", port);
1027 return -1;
Stefan Roese074e9752006-08-29 08:05:15 +02001028 }
Stefan Roesea0d96342007-10-03 10:38:09 +02001029 mdelay(1000);
Stefan Roese074e9752006-08-29 08:05:15 +02001030 }
Stefan Roesebe6fea92007-10-03 21:16:32 +02001031 SDR_WRITE(SDRN_PESDR_RCSSET(port),
1032 SDR_READ(SDRN_PESDR_RCSSET(port)) | 1 << 20);
Stefan Roese074e9752006-08-29 08:05:15 +02001033 mdelay(100);
1034
1035 return 0;
1036}
1037
Stefan Roesea0d96342007-10-03 10:38:09 +02001038int ppc4xx_init_pcie_rootport(int port)
Stefan Roese074e9752006-08-29 08:05:15 +02001039{
Stefan Roesea0d96342007-10-03 10:38:09 +02001040 return ppc4xx_init_pcie_port(port, 1);
1041}
Rafal Jaworowskia2e7ef02006-08-10 12:43:17 +02001042
Stefan Roesea0d96342007-10-03 10:38:09 +02001043int ppc4xx_init_pcie_endport(int port)
1044{
1045 return ppc4xx_init_pcie_port(port, 0);
Rafal Jaworowskia2e7ef02006-08-10 12:43:17 +02001046}
1047
Stefan Roese9c00e512007-10-03 07:48:09 +02001048void ppc4xx_setup_pcie_rootpoint(struct pci_controller *hose, int port)
Rafal Jaworowskia2e7ef02006-08-10 12:43:17 +02001049{
1050 volatile void *mbase = NULL;
1051
1052 pci_set_ops(hose,
Stefan Roesea0d96342007-10-03 10:38:09 +02001053 pcie_read_config_byte,
1054 pcie_read_config_word,
1055 pcie_read_config_dword,
1056 pcie_write_config_byte,
1057 pcie_write_config_word,
1058 pcie_write_config_dword);
Rafal Jaworowskia2e7ef02006-08-10 12:43:17 +02001059
Stefan Roese074e9752006-08-29 08:05:15 +02001060 switch (port) {
Rafal Jaworowskia2e7ef02006-08-10 12:43:17 +02001061 case 0:
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +02001062 mbase = (u32 *)CONFIG_SYS_PCIE0_XCFGBASE;
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +02001063 hose->cfg_data = (u8 *)CONFIG_SYS_PCIE0_CFGBASE;
Rafal Jaworowskia2e7ef02006-08-10 12:43:17 +02001064 break;
1065 case 1:
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +02001066 mbase = (u32 *)CONFIG_SYS_PCIE1_XCFGBASE;
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +02001067 hose->cfg_data = (u8 *)CONFIG_SYS_PCIE1_CFGBASE;
Rafal Jaworowskia2e7ef02006-08-10 12:43:17 +02001068 break;
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +02001069#if CONFIG_SYS_PCIE_NR_PORTS > 2
Rafal Jaworowskia2e7ef02006-08-10 12:43:17 +02001070 case 2:
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +02001071 mbase = (u32 *)CONFIG_SYS_PCIE2_XCFGBASE;
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +02001072 hose->cfg_data = (u8 *)CONFIG_SYS_PCIE2_CFGBASE;
Rafal Jaworowskia2e7ef02006-08-10 12:43:17 +02001073 break;
Stefan Roese7a41bde2007-10-05 09:18:23 +02001074#endif
Rafal Jaworowskia2e7ef02006-08-10 12:43:17 +02001075 }
1076
1077 /*
1078 * Set bus numbers on our root port
1079 */
Grzegorz Bernackid2f21332007-09-07 18:20:23 +02001080 out_8((u8 *)mbase + PCI_PRIMARY_BUS, 0);
1081 out_8((u8 *)mbase + PCI_SECONDARY_BUS, 1);
1082 out_8((u8 *)mbase + PCI_SUBORDINATE_BUS, 1);
Rafal Jaworowskia2e7ef02006-08-10 12:43:17 +02001083
1084 /*
1085 * Set up outbound translation to hose->mem_space from PLB
1086 * addresses at an offset of 0xd_0000_0000. We set the low
1087 * bits of the mask to 11 to turn off splitting into 8
1088 * subregions and to enable the outbound translation.
1089 */
1090 out_le32(mbase + PECFG_POM0LAH, 0x00000000);
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +02001091 out_le32(mbase + PECFG_POM0LAL, CONFIG_SYS_PCIE_MEMBASE +
1092 port * CONFIG_SYS_PCIE_MEMSIZE);
Stefan Roese3dced492007-10-05 07:57:20 +02001093 debug("PECFG_POM0LA=%08x.%08x\n", in_le32(mbase + PECFG_POM0LAH),
1094 in_le32(mbase + PECFG_POM0LAL));
Rafal Jaworowskia2e7ef02006-08-10 12:43:17 +02001095
1096 switch (port) {
1097 case 0:
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +02001098 mtdcr(DCRN_PEGPL_OMR1BAH(PCIE0), CONFIG_SYS_PCIE_ADDR_HIGH);
1099 mtdcr(DCRN_PEGPL_OMR1BAL(PCIE0), CONFIG_SYS_PCIE_MEMBASE +
1100 port * CONFIG_SYS_PCIE_MEMSIZE);
Rafal Jaworowskia2e7ef02006-08-10 12:43:17 +02001101 mtdcr(DCRN_PEGPL_OMR1MSKH(PCIE0), 0x7fffffff);
1102 mtdcr(DCRN_PEGPL_OMR1MSKL(PCIE0),
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +02001103 ~(CONFIG_SYS_PCIE_MEMSIZE - 1) | 3);
Stefan Roese3dced492007-10-05 07:57:20 +02001104 debug("0:PEGPL_OMR1BA=%08x.%08x MSK=%08x.%08x\n",
1105 mfdcr(DCRN_PEGPL_OMR1BAH(PCIE0)),
1106 mfdcr(DCRN_PEGPL_OMR1BAL(PCIE0)),
1107 mfdcr(DCRN_PEGPL_OMR1MSKH(PCIE0)),
1108 mfdcr(DCRN_PEGPL_OMR1MSKL(PCIE0)));
Rafal Jaworowskia2e7ef02006-08-10 12:43:17 +02001109 break;
1110 case 1:
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +02001111 mtdcr(DCRN_PEGPL_OMR1BAH(PCIE1), CONFIG_SYS_PCIE_ADDR_HIGH);
1112 mtdcr(DCRN_PEGPL_OMR1BAL(PCIE1), CONFIG_SYS_PCIE_MEMBASE +
1113 port * CONFIG_SYS_PCIE_MEMSIZE);
Rafal Jaworowskia2e7ef02006-08-10 12:43:17 +02001114 mtdcr(DCRN_PEGPL_OMR1MSKH(PCIE1), 0x7fffffff);
1115 mtdcr(DCRN_PEGPL_OMR1MSKL(PCIE1),
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +02001116 ~(CONFIG_SYS_PCIE_MEMSIZE - 1) | 3);
Stefan Roese3dced492007-10-05 07:57:20 +02001117 debug("1:PEGPL_OMR1BA=%08x.%08x MSK=%08x.%08x\n",
1118 mfdcr(DCRN_PEGPL_OMR1BAH(PCIE1)),
1119 mfdcr(DCRN_PEGPL_OMR1BAL(PCIE1)),
1120 mfdcr(DCRN_PEGPL_OMR1MSKH(PCIE1)),
1121 mfdcr(DCRN_PEGPL_OMR1MSKL(PCIE1)));
Rafal Jaworowskia2e7ef02006-08-10 12:43:17 +02001122 break;
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +02001123#if CONFIG_SYS_PCIE_NR_PORTS > 2
Rafal Jaworowskia2e7ef02006-08-10 12:43:17 +02001124 case 2:
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +02001125 mtdcr(DCRN_PEGPL_OMR1BAH(PCIE2), CONFIG_SYS_PCIE_ADDR_HIGH);
1126 mtdcr(DCRN_PEGPL_OMR1BAL(PCIE2), CONFIG_SYS_PCIE_MEMBASE +
1127 port * CONFIG_SYS_PCIE_MEMSIZE);
Rafal Jaworowskia2e7ef02006-08-10 12:43:17 +02001128 mtdcr(DCRN_PEGPL_OMR1MSKH(PCIE2), 0x7fffffff);
1129 mtdcr(DCRN_PEGPL_OMR1MSKL(PCIE2),
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +02001130 ~(CONFIG_SYS_PCIE_MEMSIZE - 1) | 3);
Stefan Roese3dced492007-10-05 07:57:20 +02001131 debug("2:PEGPL_OMR1BA=%08x.%08x MSK=%08x.%08x\n",
1132 mfdcr(DCRN_PEGPL_OMR1BAH(PCIE2)),
1133 mfdcr(DCRN_PEGPL_OMR1BAL(PCIE2)),
1134 mfdcr(DCRN_PEGPL_OMR1MSKH(PCIE2)),
1135 mfdcr(DCRN_PEGPL_OMR1MSKL(PCIE2)));
Rafal Jaworowskia2e7ef02006-08-10 12:43:17 +02001136 break;
Stefan Roese7a41bde2007-10-05 09:18:23 +02001137#endif
Rafal Jaworowskia2e7ef02006-08-10 12:43:17 +02001138 }
1139
Stefan Roesee2ea0802009-02-18 13:18:00 +01001140 /* Set up 4GB inbound memory window at 0 */
Rafal Jaworowskia2e7ef02006-08-10 12:43:17 +02001141 out_le32(mbase + PCI_BASE_ADDRESS_0, 0);
1142 out_le32(mbase + PCI_BASE_ADDRESS_1, 0);
Stefan Roesee2ea0802009-02-18 13:18:00 +01001143 out_le32(mbase + PECFG_BAR0HMPA, 0x7ffffff);
Rafal Jaworowskia2e7ef02006-08-10 12:43:17 +02001144 out_le32(mbase + PECFG_BAR0LMPA, 0);
Stefan Roese074e9752006-08-29 08:05:15 +02001145
1146 out_le32(mbase + PECFG_PIM01SAH, 0xffff0000);
1147 out_le32(mbase + PECFG_PIM01SAL, 0x00000000);
Rafal Jaworowskia2e7ef02006-08-10 12:43:17 +02001148 out_le32(mbase + PECFG_PIM0LAL, 0);
1149 out_le32(mbase + PECFG_PIM0LAH, 0);
Stefan Roese7a41bde2007-10-05 09:18:23 +02001150 out_le32(mbase + PECFG_PIM1LAL, 0x00000000);
1151 out_le32(mbase + PECFG_PIM1LAH, 0x00000004);
Stefan Roese074e9752006-08-29 08:05:15 +02001152 out_le32(mbase + PECFG_PIMEN, 0x1);
1153
1154 /* Enable I/O, Mem, and Busmaster cycles */
1155 out_le16((u16 *)(mbase + PCI_COMMAND),
1156 in_le16((u16 *)(mbase + PCI_COMMAND)) |
1157 PCI_COMMAND_IO | PCI_COMMAND_MEMORY | PCI_COMMAND_MASTER);
Stefan Roese43867c82007-10-02 11:44:46 +02001158
Grzegorz Bernackid2f21332007-09-07 18:20:23 +02001159 /* Set Device and Vendor Id */
Stefan Roese7a41bde2007-10-05 09:18:23 +02001160 out_le16(mbase + 0x200, 0xaaa0 + port);
1161 out_le16(mbase + 0x202, 0xbed0 + port);
Grzegorz Bernackid2f21332007-09-07 18:20:23 +02001162
1163 /* Set Class Code to PCI-PCI bridge and Revision Id to 1 */
1164 out_le32(mbase + 0x208, 0x06040001);
1165
Stefan Roese4e456622007-10-05 14:23:43 +02001166 printf("PCIE%d: successfully set as root-complex\n", port);
Stefan Roese074e9752006-08-29 08:05:15 +02001167}
1168
Stefan Roese9c00e512007-10-03 07:48:09 +02001169int ppc4xx_setup_pcie_endpoint(struct pci_controller *hose, int port)
Stefan Roese074e9752006-08-29 08:05:15 +02001170{
1171 volatile void *mbase = NULL;
1172 int attempts = 0;
1173
1174 pci_set_ops(hose,
1175 pcie_read_config_byte,
1176 pcie_read_config_word,
1177 pcie_read_config_dword,
1178 pcie_write_config_byte,
1179 pcie_write_config_word,
1180 pcie_write_config_dword);
1181
1182 switch (port) {
1183 case 0:
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +02001184 mbase = (u32 *)CONFIG_SYS_PCIE0_XCFGBASE;
1185 hose->cfg_data = (u8 *)CONFIG_SYS_PCIE0_CFGBASE;
Stefan Roese074e9752006-08-29 08:05:15 +02001186 break;
1187 case 1:
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +02001188 mbase = (u32 *)CONFIG_SYS_PCIE1_XCFGBASE;
1189 hose->cfg_data = (u8 *)CONFIG_SYS_PCIE1_CFGBASE;
Stefan Roese074e9752006-08-29 08:05:15 +02001190 break;
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +02001191#if defined(CONFIG_SYS_PCIE2_CFGBASE)
Stefan Roese074e9752006-08-29 08:05:15 +02001192 case 2:
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +02001193 mbase = (u32 *)CONFIG_SYS_PCIE2_XCFGBASE;
1194 hose->cfg_data = (u8 *)CONFIG_SYS_PCIE2_CFGBASE;
Stefan Roese074e9752006-08-29 08:05:15 +02001195 break;
Stefan Roese7a41bde2007-10-05 09:18:23 +02001196#endif
Stefan Roese074e9752006-08-29 08:05:15 +02001197 }
1198
1199 /*
1200 * Set up outbound translation to hose->mem_space from PLB
1201 * addresses at an offset of 0xd_0000_0000. We set the low
1202 * bits of the mask to 11 to turn off splitting into 8
1203 * subregions and to enable the outbound translation.
1204 */
1205 out_le32(mbase + PECFG_POM0LAH, 0x00001ff8);
1206 out_le32(mbase + PECFG_POM0LAL, 0x00001000);
1207
1208 switch (port) {
1209 case 0:
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +02001210 mtdcr(DCRN_PEGPL_OMR1BAH(PCIE0), CONFIG_SYS_PCIE_ADDR_HIGH);
1211 mtdcr(DCRN_PEGPL_OMR1BAL(PCIE0), CONFIG_SYS_PCIE_MEMBASE +
1212 port * CONFIG_SYS_PCIE_MEMSIZE);
Stefan Roese074e9752006-08-29 08:05:15 +02001213 mtdcr(DCRN_PEGPL_OMR1MSKH(PCIE0), 0x7fffffff);
1214 mtdcr(DCRN_PEGPL_OMR1MSKL(PCIE0),
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +02001215 ~(CONFIG_SYS_PCIE_MEMSIZE - 1) | 3);
Stefan Roese074e9752006-08-29 08:05:15 +02001216 break;
1217 case 1:
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +02001218 mtdcr(DCRN_PEGPL_OMR1BAH(PCIE1), CONFIG_SYS_PCIE_ADDR_HIGH);
1219 mtdcr(DCRN_PEGPL_OMR1BAL(PCIE1), CONFIG_SYS_PCIE_MEMBASE +
1220 port * CONFIG_SYS_PCIE_MEMSIZE);
Stefan Roese074e9752006-08-29 08:05:15 +02001221 mtdcr(DCRN_PEGPL_OMR1MSKH(PCIE1), 0x7fffffff);
1222 mtdcr(DCRN_PEGPL_OMR1MSKL(PCIE1),
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +02001223 ~(CONFIG_SYS_PCIE_MEMSIZE - 1) | 3);
Stefan Roese074e9752006-08-29 08:05:15 +02001224 break;
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +02001225#if CONFIG_SYS_PCIE_NR_PORTS > 2
Stefan Roese074e9752006-08-29 08:05:15 +02001226 case 2:
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +02001227 mtdcr(DCRN_PEGPL_OMR1BAH(PCIE2), CONFIG_SYS_PCIE_ADDR_HIGH);
1228 mtdcr(DCRN_PEGPL_OMR1BAL(PCIE2), CONFIG_SYS_PCIE_MEMBASE +
1229 port * CONFIG_SYS_PCIE_MEMSIZE);
Stefan Roese074e9752006-08-29 08:05:15 +02001230 mtdcr(DCRN_PEGPL_OMR1MSKH(PCIE2), 0x7fffffff);
1231 mtdcr(DCRN_PEGPL_OMR1MSKL(PCIE2),
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +02001232 ~(CONFIG_SYS_PCIE_MEMSIZE - 1) | 3);
Stefan Roese074e9752006-08-29 08:05:15 +02001233 break;
Stefan Roese7a41bde2007-10-05 09:18:23 +02001234#endif
Stefan Roese074e9752006-08-29 08:05:15 +02001235 }
1236
Stefan Roesee7fe4c52007-10-18 07:39:38 +02001237 /* Set up 64MB inbound memory window at 0 */
Stefan Roese074e9752006-08-29 08:05:15 +02001238 out_le32(mbase + PCI_BASE_ADDRESS_0, 0);
1239 out_le32(mbase + PCI_BASE_ADDRESS_1, 0);
Stefan Roesee7fe4c52007-10-18 07:39:38 +02001240
1241 out_le32(mbase + PECFG_PIM01SAH, 0xffffffff);
1242 out_le32(mbase + PECFG_PIM01SAL, 0xfc000000);
1243
1244 /* Setup BAR0 */
1245 out_le32(mbase + PECFG_BAR0HMPA, 0x7fffffff);
1246 out_le32(mbase + PECFG_BAR0LMPA, 0xfc000000 | PCI_BASE_ADDRESS_MEM_TYPE_64);
1247
1248 /* Disable BAR1 & BAR2 */
1249 out_le32(mbase + PECFG_BAR1MPA, 0);
1250 out_le32(mbase + PECFG_BAR2HMPA, 0);
1251 out_le32(mbase + PECFG_BAR2LMPA, 0);
1252
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +02001253 out_le32(mbase + PECFG_PIM0LAL, U64_TO_U32_LOW(CONFIG_SYS_PCIE_INBOUND_BASE));
1254 out_le32(mbase + PECFG_PIM0LAH, U64_TO_U32_HIGH(CONFIG_SYS_PCIE_INBOUND_BASE));
Rafal Jaworowskia2e7ef02006-08-10 12:43:17 +02001255 out_le32(mbase + PECFG_PIMEN, 0x1);
1256
1257 /* Enable I/O, Mem, and Busmaster cycles */
1258 out_le16((u16 *)(mbase + PCI_COMMAND),
Stefan Roesea0d96342007-10-03 10:38:09 +02001259 in_le16((u16 *)(mbase + PCI_COMMAND)) |
1260 PCI_COMMAND_IO | PCI_COMMAND_MEMORY | PCI_COMMAND_MASTER);
Stefan Roese7a41bde2007-10-05 09:18:23 +02001261 out_le16(mbase + 0x200, 0xcaad); /* Setting vendor ID */
1262 out_le16(mbase + 0x202, 0xfeed); /* Setting device ID */
Stefan Roesea0d96342007-10-03 10:38:09 +02001263
Stefan Roesee7fe4c52007-10-18 07:39:38 +02001264 /* Set Class Code to Processor/PPC */
1265 out_le32(mbase + 0x208, 0x0b200001);
1266
Stefan Roese074e9752006-08-29 08:05:15 +02001267 attempts = 10;
Stefan Roesebe6fea92007-10-03 21:16:32 +02001268 while(!(SDR_READ(SDRN_PESDR_RCSSTS(port)) & (1 << 8))) {
Stefan Roesea0d96342007-10-03 10:38:09 +02001269 if (!(attempts--)) {
1270 printf("PCIE%d: BME not active\n", port);
1271 return -1;
Stefan Roese074e9752006-08-29 08:05:15 +02001272 }
Stefan Roesea0d96342007-10-03 10:38:09 +02001273 mdelay(1000);
Stefan Roese074e9752006-08-29 08:05:15 +02001274 }
Stefan Roesea0d96342007-10-03 10:38:09 +02001275
Stefan Roese4e456622007-10-05 14:23:43 +02001276 printf("PCIE%d: successfully set as endpoint\n", port);
Stefan Roese074e9752006-08-29 08:05:15 +02001277
1278 return 0;
Rafal Jaworowskia2e7ef02006-08-10 12:43:17 +02001279}
Stefan Roese8d982302007-01-18 10:25:34 +01001280#endif /* CONFIG_440SPE && CONFIG_PCI */