blob: a6158206516f56f4a0e467769ee48810184a9ee1 [file] [log] [blame]
Peter Tyserccf0fdd2008-12-17 16:36:23 -06001/*
2 * Copyright 2008 Extreme Engineering Solutions, Inc.
3 * Copyright 2007-2008 Freescale Semiconductor, Inc.
4 *
5 * See file CREDITS for list of people who contributed to this
6 * project.
7 *
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License as
10 * published by the Free Software Foundation; either version 2 of
11 * the License, or (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
21 * MA 02111-1307 USA
22 */
23
24#include <common.h>
25#include <pci.h>
Kumar Galac8514622009-04-02 13:22:48 -050026#include <asm/fsl_pci.h>
Peter Tyser1bb61b62009-08-07 13:16:34 -050027#include <asm/io.h>
Peter Tyserccf0fdd2008-12-17 16:36:23 -060028#include <libfdt.h>
29#include <fdt_support.h>
30
Peter Tyserccf0fdd2008-12-17 16:36:23 -060031int first_free_busno = 0;
32
Peter Tyser78bbc5c2008-12-01 13:47:13 -060033#ifdef CONFIG_PCI1
34static struct pci_controller pci1_hose;
35#endif
Peter Tyserccf0fdd2008-12-17 16:36:23 -060036#ifdef CONFIG_PCIE1
37static struct pci_controller pcie1_hose;
38#endif
39#ifdef CONFIG_PCIE2
40static struct pci_controller pcie2_hose;
41#endif
42#ifdef CONFIG_PCIE3
43static struct pci_controller pcie3_hose;
44#endif
45
Peter Tyser78bbc5c2008-12-01 13:47:13 -060046#ifdef CONFIG_MPC8572
Peter Tyserccf0fdd2008-12-17 16:36:23 -060047/* Correlate host/agent POR bits to usable info. Table 4-14 */
48struct host_agent_cfg_t {
49 uchar pcie_root[3];
50 uchar rio_host;
51} host_agent_cfg[8] = {
52 {{0, 0, 0}, 0},
53 {{0, 1, 1}, 1},
54 {{1, 0, 1}, 0},
55 {{1, 1, 0}, 1},
56 {{0, 0, 1}, 0},
57 {{0, 1, 0}, 1},
58 {{1, 0, 0}, 0},
59 {{1, 1, 1}, 1}
60};
61
62/* Correlate port width POR bits to usable info. Table 4-15 */
63struct io_port_cfg_t {
64 uchar pcie_width[3];
65 uchar rio_width;
66} io_port_cfg[16] = {
67 {{0, 0, 0}, 0},
68 {{0, 0, 0}, 0},
69 {{4, 0, 0}, 0},
70 {{4, 4, 0}, 0},
71 {{0, 0, 0}, 0},
72 {{0, 0, 0}, 0},
73 {{0, 0, 0}, 4},
74 {{4, 2, 2}, 0},
75 {{0, 0, 0}, 0},
76 {{0, 0, 0}, 0},
77 {{0, 0, 0}, 0},
78 {{4, 0, 0}, 4},
79 {{4, 0, 0}, 4},
80 {{0, 0, 0}, 4},
81 {{0, 0, 0}, 4},
82 {{8, 0, 0}, 0},
83};
Peter Tyser78bbc5c2008-12-01 13:47:13 -060084#elif defined CONFIG_MPC8548
85/* Correlate host/agent POR bits to usable info. Table 4-12 */
86struct host_agent_cfg_t {
87 uchar pci_host[2];
88 uchar pcie_root[1];
89 uchar rio_host;
90} host_agent_cfg[8] = {
91 {{1, 1}, {0}, 0},
92 {{1, 1}, {1}, 0},
93 {{1, 1}, {0}, 1},
94 {{0, 0}, {0}, 0}, /* reserved */
95 {{0, 1}, {1}, 0},
96 {{1, 1}, {1}, 0},
97 {{0, 1}, {1}, 1},
98 {{1, 1}, {1}, 1}
99};
100
101/* Correlate port width POR bits to usable info. Table 4-13 */
102struct io_port_cfg_t {
103 uchar pcie_width[1];
104 uchar rio_width;
105} io_port_cfg[8] = {
106 {{0}, 0},
107 {{0}, 0},
108 {{0}, 0},
109 {{4}, 4},
110 {{4}, 4},
111 {{0}, 4},
112 {{0}, 4},
113 {{8}, 0},
114};
Peter Tyserbef30132009-05-22 10:26:35 -0500115#elif defined CONFIG_MPC86xx
116/* Correlate host/agent POR bits to usable info. Table 4-17 */
117struct host_agent_cfg_t {
118 uchar pcie_root[2];
119 uchar rio_host;
120} host_agent_cfg[8] = {
121 {{0, 0}, 0},
122 {{1, 0}, 1},
123 {{0, 1}, 0},
124 {{1, 1}, 1}
125};
126
127/* Correlate port width POR bits to usable info. Table 4-16 */
128struct io_port_cfg_t {
129 uchar pcie_width[2];
130 uchar rio_width;
131} io_port_cfg[16] = {
132 {{0, 0}, 0},
133 {{0, 0}, 0},
134 {{8, 0}, 0},
135 {{8, 8}, 0},
136 {{0, 0}, 0},
137 {{8, 0}, 4},
138 {{8, 0}, 4},
139 {{8, 0}, 4},
140 {{0, 0}, 0},
141 {{0, 0}, 4},
142 {{0, 0}, 4},
143 {{0, 0}, 4},
144 {{0, 0}, 0},
145 {{0, 0}, 0},
146 {{0, 8}, 0},
147 {{8, 8}, 0},
148};
149#endif
150
151/*
152 * 85xx and 86xx share naming conventions, but different layout.
153 * Correlate names to CPU-specific values to share common
154 * PCI code.
155 */
156#if defined(CONFIG_MPC85xx)
157#define MPC8xxx_DEVDISR_PCIE1 MPC85xx_DEVDISR_PCIE
158#define MPC8xxx_DEVDISR_PCIE2 MPC85xx_DEVDISR_PCIE2
159#define MPC8xxx_DEVDISR_PCIE3 MPC85xx_DEVDISR_PCIE3
160#define MPC8xxx_PORDEVSR_IO_SEL MPC85xx_PORDEVSR_IO_SEL
161#define MPC8xxx_PORDEVSR_IO_SEL_SHIFT MPC85xx_PORDEVSR_IO_SEL_SHIFT
162#define MPC8xxx_PORBMSR_HA MPC85xx_PORBMSR_HA
163#define MPC8xxx_PORBMSR_HA_SHIFT MPC85xx_PORBMSR_HA_SHIFT
164#elif defined(CONFIG_MPC86xx)
165#define MPC8xxx_DEVDISR_PCIE1 MPC86xx_DEVDISR_PCIEX1
166#define MPC8xxx_DEVDISR_PCIE2 MPC86xx_DEVDISR_PCIEX2
167#define MPC8xxx_DEVDISR_PCIE3 0 /* 8641 doesn't have PCIe3 */
168#define MPC8xxx_PORDEVSR_IO_SEL MPC8641_PORDEVSR_IO_SEL
169#define MPC8xxx_PORDEVSR_IO_SEL_SHIFT MPC8641_PORDEVSR_IO_SEL_SHIFT
170#define MPC8xxx_PORBMSR_HA MPC8641_PORBMSR_HA
171#define MPC8xxx_PORBMSR_HA_SHIFT MPC8641_PORBMSR_HA_SHIFT
Peter Tyser78bbc5c2008-12-01 13:47:13 -0600172#endif
Peter Tyserccf0fdd2008-12-17 16:36:23 -0600173
174void pci_init_board(void)
175{
176 struct pci_controller *hose;
177 volatile ccsr_fsl_pci_t *pci;
178 int width;
179 int host;
Peter Tyserbef30132009-05-22 10:26:35 -0500180#if defined(CONFIG_MPC85xx)
Peter Tyserccf0fdd2008-12-17 16:36:23 -0600181 volatile ccsr_gur_t *gur = (void *)(CONFIG_SYS_MPC85xx_GUTS_ADDR);
Peter Tyserbef30132009-05-22 10:26:35 -0500182#elif defined(CONFIG_MPC86xx)
183 immap_t *immap = (immap_t *)CONFIG_SYS_IMMR;
184 volatile ccsr_gur_t *gur = &immap->im_gur;
185#endif
Peter Tyser1bb61b62009-08-07 13:16:34 -0500186 uint devdisr = in_be32(&gur->devdisr);
187 uint io_sel = (in_be32(&gur->pordevsr) & MPC8xxx_PORDEVSR_IO_SEL) >>
Peter Tyserbef30132009-05-22 10:26:35 -0500188 MPC8xxx_PORDEVSR_IO_SEL_SHIFT;
Peter Tyser1bb61b62009-08-07 13:16:34 -0500189 uint host_agent = (in_be32(&gur->porbmsr) & MPC8xxx_PORBMSR_HA) >>
Peter Tyserbef30132009-05-22 10:26:35 -0500190 MPC8xxx_PORBMSR_HA_SHIFT;
Peter Tyserccf0fdd2008-12-17 16:36:23 -0600191 struct pci_region *r;
192
Peter Tyser78bbc5c2008-12-01 13:47:13 -0600193#ifdef CONFIG_PCI1
Peter Tyser1bb61b62009-08-07 13:16:34 -0500194 uint pci_spd_norm = in_be32(&gur->pordevsr) & MPC85xx_PORDEVSR_PCI1_SPD;
195 uint pci_32 = in_be32(&gur->pordevsr) & MPC85xx_PORDEVSR_PCI1_PCI32;
196 uint pci_arb = in_be32(&gur->pordevsr) & MPC85xx_PORDEVSR_PCI1_ARB;
197 uint pcix = in_be32(&gur->pordevsr) & MPC85xx_PORDEVSR_PCI1;
Peter Tyser78bbc5c2008-12-01 13:47:13 -0600198 uint freq = CONFIG_SYS_CLK_FREQ / 1000 / 1000;
Peter Tyserccf0fdd2008-12-17 16:36:23 -0600199
Peter Tyser78bbc5c2008-12-01 13:47:13 -0600200 width = 0; /* Silence compiler warning... */
201 io_sel &= 0xf; /* Silence compiler warning... */
202 pci = (ccsr_fsl_pci_t *) CONFIG_SYS_PCI1_ADDR;
203 hose = &pci1_hose;
204 host = host_agent_cfg[host_agent].pci_host[0];
205 r = hose->regions;
206
Peter Tyser78bbc5c2008-12-01 13:47:13 -0600207 if (!(devdisr & MPC85xx_DEVDISR_PCI1)) {
208 printf("\n PCI1: %d bit %s, %s %d MHz, %s, %s\n",
209 pci_32 ? 32 : 64,
210 pcix ? "PCIX" : "PCI",
Peter Tyser1bb61b62009-08-07 13:16:34 -0500211 pci_spd_norm ? ">=" : "<=",
Peter Tyser78bbc5c2008-12-01 13:47:13 -0600212 pcix ? freq * 2 : freq,
213 host ? "host" : "agent",
214 pci_arb ? "arbiter" : "external-arbiter");
215
Peter Tyser78bbc5c2008-12-01 13:47:13 -0600216 /* outbound memory */
217 pci_set_region(r++,
218 CONFIG_SYS_PCI1_MEM_BASE,
219 CONFIG_SYS_PCI1_MEM_PHYS,
220 CONFIG_SYS_PCI1_MEM_SIZE,
221 PCI_REGION_MEM);
222
223 /* outbound io */
224 pci_set_region(r++,
225 CONFIG_SYS_PCI1_IO_BASE,
226 CONFIG_SYS_PCI1_IO_PHYS,
227 CONFIG_SYS_PCI1_IO_SIZE,
228 PCI_REGION_IO);
229
230 hose->region_count = r - hose->regions;
231
232 hose->first_busno = first_free_busno;
Peter Tyser78bbc5c2008-12-01 13:47:13 -0600233
Kumar Galafb3143b2009-08-03 20:44:55 -0500234 fsl_pci_init(hose, (u32)&pci->cfg_addr, (u32)&pci->cfg_data);
Peter Tyser78bbc5c2008-12-01 13:47:13 -0600235
Peter Tyserd9011f92008-12-23 16:32:01 -0600236 /* Unlock inbound PCI configuration cycles */
237 if (!host)
238 fsl_pci_config_unlock(hose);
239
Peter Tyser1f03cbf2008-12-23 16:32:00 -0600240 first_free_busno = hose->last_busno + 1;
Peter Tyser78bbc5c2008-12-01 13:47:13 -0600241 printf(" PCI1 on bus %02x - %02x\n",
242 hose->first_busno, hose->last_busno);
243 } else {
244 printf(" PCI1: disabled\n");
245 }
246#elif defined CONFIG_MPC8548
247 /* PCI1 not present on MPC8572 */
Peter Tyser1bb61b62009-08-07 13:16:34 -0500248 setbits_be32(&gur->devdisr, MPC85xx_DEVDISR_PCI1);
Peter Tyser78bbc5c2008-12-01 13:47:13 -0600249#endif
Peter Tyserccf0fdd2008-12-17 16:36:23 -0600250#ifdef CONFIG_PCIE1
251 pci = (ccsr_fsl_pci_t *) CONFIG_SYS_PCIE1_ADDR;
252 hose = &pcie1_hose;
253 host = host_agent_cfg[host_agent].pcie_root[0];
254 width = io_port_cfg[io_sel].pcie_width[0];
255 r = hose->regions;
256
Peter Tyserbef30132009-05-22 10:26:35 -0500257 if (width && !(devdisr & MPC8xxx_DEVDISR_PCIE1)) {
Peter Tyserccf0fdd2008-12-17 16:36:23 -0600258 printf("\n PCIE1 connected as %s (x%d)",
259 host ? "Root Complex" : "End Point", width);
Peter Tyser1bb61b62009-08-07 13:16:34 -0500260 if (in_be32(&pci->pme_msg_det)) {
261 out_be32(&pci->pme_msg_det, 0xffffffff);
Peter Tyserccf0fdd2008-12-17 16:36:23 -0600262 debug(" with errors. Clearing. Now 0x%08x",
Peter Tyser1bb61b62009-08-07 13:16:34 -0500263 in_be32(&pci->pme_msg_det));
Peter Tyserccf0fdd2008-12-17 16:36:23 -0600264 }
265 printf("\n");
266
Peter Tyserccf0fdd2008-12-17 16:36:23 -0600267 /* outbound memory */
268 pci_set_region(r++,
269 CONFIG_SYS_PCIE1_MEM_BASE,
270 CONFIG_SYS_PCIE1_MEM_PHYS,
271 CONFIG_SYS_PCIE1_MEM_SIZE,
272 PCI_REGION_MEM);
273
274 /* outbound io */
275 pci_set_region(r++,
276 CONFIG_SYS_PCIE1_IO_BASE,
277 CONFIG_SYS_PCIE1_IO_PHYS,
278 CONFIG_SYS_PCIE1_IO_SIZE,
279 PCI_REGION_IO);
280
281 hose->region_count = r - hose->regions;
282
283 hose->first_busno = first_free_busno;
Peter Tyserccf0fdd2008-12-17 16:36:23 -0600284
Kumar Galafb3143b2009-08-03 20:44:55 -0500285 fsl_pci_init(hose, (u32)&pci->cfg_addr, (u32)&pci->cfg_data);
Peter Tyserccf0fdd2008-12-17 16:36:23 -0600286
Peter Tyser487dcb42008-10-29 12:39:27 -0500287 /* Unlock inbound PCI configuration cycles */
288 if (!host)
289 fsl_pci_config_unlock(hose);
290
Peter Tyser78bbc5c2008-12-01 13:47:13 -0600291 first_free_busno = hose->last_busno + 1;
Peter Tyserccf0fdd2008-12-17 16:36:23 -0600292 printf(" PCIE1 on bus %02x - %02x\n",
293 hose->first_busno, hose->last_busno);
294 }
295#else
Peter Tyser1bb61b62009-08-07 13:16:34 -0500296 setbits_be32(&gur->devdisr, MPC8xxx_DEVDISR_PCIE1);
Peter Tyserccf0fdd2008-12-17 16:36:23 -0600297#endif /* CONFIG_PCIE1 */
298
299#ifdef CONFIG_PCIE2
300 pci = (ccsr_fsl_pci_t *) CONFIG_SYS_PCIE2_ADDR;
301 hose = &pcie2_hose;
302 host = host_agent_cfg[host_agent].pcie_root[1];
303 width = io_port_cfg[io_sel].pcie_width[1];
304 r = hose->regions;
305
Peter Tyserbef30132009-05-22 10:26:35 -0500306 if (width && !(devdisr & MPC8xxx_DEVDISR_PCIE2)) {
Peter Tyserccf0fdd2008-12-17 16:36:23 -0600307 printf("\n PCIE2 connected as %s (x%d)",
308 host ? "Root Complex" : "End Point", width);
Peter Tyser1bb61b62009-08-07 13:16:34 -0500309 if (in_be32(&pci->pme_msg_det)) {
310 out_be32(&pci->pme_msg_det, 0xffffffff);
Peter Tyserccf0fdd2008-12-17 16:36:23 -0600311 debug(" with errors. Clearing. Now 0x%08x",
Peter Tyser1bb61b62009-08-07 13:16:34 -0500312 in_be32(&pci->pme_msg_det));
Peter Tyserccf0fdd2008-12-17 16:36:23 -0600313 }
314 printf("\n");
315
Peter Tyserccf0fdd2008-12-17 16:36:23 -0600316 /* outbound memory */
317 pci_set_region(r++,
318 CONFIG_SYS_PCIE2_MEM_BASE,
319 CONFIG_SYS_PCIE2_MEM_PHYS,
320 CONFIG_SYS_PCIE2_MEM_SIZE,
321 PCI_REGION_MEM);
322
323 /* outbound io */
324 pci_set_region(r++,
325 CONFIG_SYS_PCIE2_IO_BASE,
326 CONFIG_SYS_PCIE2_IO_PHYS,
327 CONFIG_SYS_PCIE2_IO_SIZE,
328 PCI_REGION_IO);
329
330 hose->region_count = r - hose->regions;
331
332 hose->first_busno = first_free_busno;
Peter Tyserccf0fdd2008-12-17 16:36:23 -0600333
Kumar Galafb3143b2009-08-03 20:44:55 -0500334 fsl_pci_init(hose, (u32)&pci->cfg_addr, (u32)&pci->cfg_data);
Peter Tyser487dcb42008-10-29 12:39:27 -0500335
336 /* Unlock inbound PCI configuration cycles */
337 if (!host)
338 fsl_pci_config_unlock(hose);
339
Peter Tyser1f03cbf2008-12-23 16:32:00 -0600340 first_free_busno = hose->last_busno + 1;
Peter Tyserccf0fdd2008-12-17 16:36:23 -0600341 printf(" PCIE2 on bus %02x - %02x\n",
342 hose->first_busno, hose->last_busno);
Peter Tyserccf0fdd2008-12-17 16:36:23 -0600343 }
344#else
Peter Tyser1bb61b62009-08-07 13:16:34 -0500345 setbits_be32(&gur->devdisr, MPC8xxx_DEVDISR_PCIE2);
Peter Tyserccf0fdd2008-12-17 16:36:23 -0600346#endif /* CONFIG_PCIE2 */
347
348#ifdef CONFIG_PCIE3
349 pci = (ccsr_fsl_pci_t *) CONFIG_SYS_PCIE3_ADDR;
350 hose = &pcie3_hose;
351 host = host_agent_cfg[host_agent].pcie_root[2];
352 width = io_port_cfg[io_sel].pcie_width[2];
353 r = hose->regions;
354
Peter Tyserbef30132009-05-22 10:26:35 -0500355 if (width && !(devdisr & MPC8xxx_DEVDISR_PCIE3)) {
Peter Tyserccf0fdd2008-12-17 16:36:23 -0600356 printf("\n PCIE3 connected as %s (x%d)",
357 host ? "Root Complex" : "End Point", width);
Peter Tyser1bb61b62009-08-07 13:16:34 -0500358 if (in_be32(&pci->pme_msg_det)) {
359 out_be32(&pci->pme_msg_det, 0xffffffff);
Peter Tyserccf0fdd2008-12-17 16:36:23 -0600360 debug(" with errors. Clearing. Now 0x%08x",
Peter Tyser1bb61b62009-08-07 13:16:34 -0500361 in_be32(&pci->pme_msg_det));
Peter Tyserccf0fdd2008-12-17 16:36:23 -0600362 }
363 printf("\n");
364
Peter Tyserccf0fdd2008-12-17 16:36:23 -0600365 /* outbound memory */
366 pci_set_region(r++,
367 CONFIG_SYS_PCIE3_MEM_BASE,
368 CONFIG_SYS_PCIE3_MEM_PHYS,
369 CONFIG_SYS_PCIE3_MEM_SIZE,
370 PCI_REGION_MEM);
371
372 /* outbound io */
373 pci_set_region(r++,
374 CONFIG_SYS_PCIE3_IO_BASE,
375 CONFIG_SYS_PCIE3_IO_PHYS,
376 CONFIG_SYS_PCIE3_IO_SIZE,
377 PCI_REGION_IO);
378
379 hose->region_count = r - hose->regions;
380
381 hose->first_busno = first_free_busno;
Peter Tyserccf0fdd2008-12-17 16:36:23 -0600382
Kumar Galafb3143b2009-08-03 20:44:55 -0500383 fsl_pci_init(hose, (u32)&pci->cfg_addr, (u32)&pci->cfg_data);
Peter Tyser487dcb42008-10-29 12:39:27 -0500384
385 /* Unlock inbound PCI configuration cycles */
386 if (!host)
387 fsl_pci_config_unlock(hose);
388
Peter Tyser1f03cbf2008-12-23 16:32:00 -0600389 first_free_busno = hose->last_busno + 1;
Peter Tyserccf0fdd2008-12-17 16:36:23 -0600390 printf(" PCIE3 on bus %02x - %02x\n",
391 hose->first_busno, hose->last_busno);
392 }
393#else
Peter Tyser1bb61b62009-08-07 13:16:34 -0500394 setbits_be32(&gur->devdisr, MPC8xxx_DEVDISR_PCIE3);
Peter Tyserccf0fdd2008-12-17 16:36:23 -0600395#endif /* CONFIG_PCIE3 */
396}
397
398#if defined(CONFIG_OF_BOARD_SETUP)
Peter Tyserccf0fdd2008-12-17 16:36:23 -0600399void ft_board_pci_setup(void *blob, bd_t *bd)
400{
Peter Tyser78bbc5c2008-12-01 13:47:13 -0600401 /* TODO - make node name (eg pci0) dynamic */
402#ifdef CONFIG_PCI1
403 ft_fsl_pci_setup(blob, "pci0", &pci1_hose);
404#endif
Peter Tyserccf0fdd2008-12-17 16:36:23 -0600405#ifdef CONFIG_PCIE1
406 ft_fsl_pci_setup(blob, "pci2", &pcie1_hose);
407#endif
408#ifdef CONFIG_PCIE2
409 ft_fsl_pci_setup(blob, "pci1", &pcie2_hose);
410#endif
411#ifdef CONFIG_PCIE3
412 ft_fsl_pci_setup(blob, "pci0", &pcie3_hose);
413#endif
414}
415#endif /* CONFIG_OF_BOARD_SETUP */