blob: b8e363ec9656a98ac635c4adb695cce0a50dba0c [file] [log] [blame]
Peter Tyser1c2b3292008-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>
26#include <asm/immap_85xx.h>
27#include <asm/immap_fsl_pci.h>
28#include <libfdt.h>
29#include <fdt_support.h>
30
31extern int fsl_pci_setup_inbound_windows(struct pci_region *r);
32extern void fsl_pci_init(struct pci_controller *hose);
33
34int first_free_busno = 0;
35
36#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
46/* Correlate host/agent POR bits to usable info. Table 4-14 */
47struct host_agent_cfg_t {
48 uchar pcie_root[3];
49 uchar rio_host;
50} host_agent_cfg[8] = {
51 {{0, 0, 0}, 0},
52 {{0, 1, 1}, 1},
53 {{1, 0, 1}, 0},
54 {{1, 1, 0}, 1},
55 {{0, 0, 1}, 0},
56 {{0, 1, 0}, 1},
57 {{1, 0, 0}, 0},
58 {{1, 1, 1}, 1}
59};
60
61/* Correlate port width POR bits to usable info. Table 4-15 */
62struct io_port_cfg_t {
63 uchar pcie_width[3];
64 uchar rio_width;
65} io_port_cfg[16] = {
66 {{0, 0, 0}, 0},
67 {{0, 0, 0}, 0},
68 {{4, 0, 0}, 0},
69 {{4, 4, 0}, 0},
70 {{0, 0, 0}, 0},
71 {{0, 0, 0}, 0},
72 {{0, 0, 0}, 4},
73 {{4, 2, 2}, 0},
74 {{0, 0, 0}, 0},
75 {{0, 0, 0}, 0},
76 {{0, 0, 0}, 0},
77 {{4, 0, 0}, 4},
78 {{4, 0, 0}, 4},
79 {{0, 0, 0}, 4},
80 {{0, 0, 0}, 4},
81 {{8, 0, 0}, 0},
82};
83
84void pci_init_board(void)
85{
86 struct pci_controller *hose;
87 volatile ccsr_fsl_pci_t *pci;
88 int width;
89 int host;
90 volatile ccsr_gur_t *gur = (void *)(CONFIG_SYS_MPC85xx_GUTS_ADDR);
91 uint devdisr = gur->devdisr;
92 uint io_sel = (gur->pordevsr & MPC85xx_PORDEVSR_IO_SEL) >> 19;
93 uint host_agent = (gur->porbmsr & MPC85xx_PORBMSR_HA) >> 16;
94 struct pci_region *r;
95
96 debug(" pci_init_board: devdisr=%x, io_sel=%x, host_agent=%x\n",
97 devdisr, io_sel, host_agent);
98
99#ifdef CONFIG_PCIE1
100 pci = (ccsr_fsl_pci_t *) CONFIG_SYS_PCIE1_ADDR;
101 hose = &pcie1_hose;
102 host = host_agent_cfg[host_agent].pcie_root[0];
103 width = io_port_cfg[io_sel].pcie_width[0];
104 r = hose->regions;
105
106 if (width && !(devdisr & MPC85xx_DEVDISR_PCIE)) {
107 printf("\n PCIE1 connected as %s (x%d)",
108 host ? "Root Complex" : "End Point", width);
109 if (pci->pme_msg_det) {
110 pci->pme_msg_det = 0xffffffff;
111 debug(" with errors. Clearing. Now 0x%08x",
112 pci->pme_msg_det);
113 }
114 printf("\n");
115
116 /* inbound */
117 r += fsl_pci_setup_inbound_windows(r);
118
119 /* outbound memory */
120 pci_set_region(r++,
121 CONFIG_SYS_PCIE1_MEM_BASE,
122 CONFIG_SYS_PCIE1_MEM_PHYS,
123 CONFIG_SYS_PCIE1_MEM_SIZE,
124 PCI_REGION_MEM);
125
126 /* outbound io */
127 pci_set_region(r++,
128 CONFIG_SYS_PCIE1_IO_BASE,
129 CONFIG_SYS_PCIE1_IO_PHYS,
130 CONFIG_SYS_PCIE1_IO_SIZE,
131 PCI_REGION_IO);
132
133 hose->region_count = r - hose->regions;
134
135 hose->first_busno = first_free_busno;
136 pci_setup_indirect(hose, (int)&pci->cfg_addr,
137 (int) &pci->cfg_data);
138
139 fsl_pci_init(hose);
140
141 first_free_busno = hose->last_busno+1;
142 printf(" PCIE1 on bus %02x - %02x\n",
143 hose->first_busno, hose->last_busno);
144 }
145#else
146 gur->devdisr |= MPC85xx_DEVDISR_PCIE; /* disable */
147#endif /* CONFIG_PCIE1 */
148
149#ifdef CONFIG_PCIE2
150 pci = (ccsr_fsl_pci_t *) CONFIG_SYS_PCIE2_ADDR;
151 hose = &pcie2_hose;
152 host = host_agent_cfg[host_agent].pcie_root[1];
153 width = io_port_cfg[io_sel].pcie_width[1];
154 r = hose->regions;
155
156 if (width && !(devdisr & MPC85xx_DEVDISR_PCIE2)) {
157 printf("\n PCIE2 connected as %s (x%d)",
158 host ? "Root Complex" : "End Point", width);
159 if (pci->pme_msg_det) {
160 pci->pme_msg_det = 0xffffffff;
161 debug(" with errors. Clearing. Now 0x%08x",
162 pci->pme_msg_det);
163 }
164 printf("\n");
165
166 /* inbound */
167 r += fsl_pci_setup_inbound_windows(r);
168
169 /* outbound memory */
170 pci_set_region(r++,
171 CONFIG_SYS_PCIE2_MEM_BASE,
172 CONFIG_SYS_PCIE2_MEM_PHYS,
173 CONFIG_SYS_PCIE2_MEM_SIZE,
174 PCI_REGION_MEM);
175
176 /* outbound io */
177 pci_set_region(r++,
178 CONFIG_SYS_PCIE2_IO_BASE,
179 CONFIG_SYS_PCIE2_IO_PHYS,
180 CONFIG_SYS_PCIE2_IO_SIZE,
181 PCI_REGION_IO);
182
183 hose->region_count = r - hose->regions;
184
185 hose->first_busno = first_free_busno;
186 pci_setup_indirect(hose, (int)&pci->cfg_addr,
187 (int)&pci->cfg_data);
188
189 fsl_pci_init(hose);
190 first_free_busno = hose->last_busno+1;
191 printf(" PCIE2 on bus %02x - %02x\n",
192 hose->first_busno, hose->last_busno);
193
194 }
195#else
196 gur->devdisr |= MPC85xx_DEVDISR_PCIE2; /* disable */
197#endif /* CONFIG_PCIE2 */
198
199#ifdef CONFIG_PCIE3
200 pci = (ccsr_fsl_pci_t *) CONFIG_SYS_PCIE3_ADDR;
201 hose = &pcie3_hose;
202 host = host_agent_cfg[host_agent].pcie_root[2];
203 width = io_port_cfg[io_sel].pcie_width[2];
204 r = hose->regions;
205
206 if (width && !(devdisr & MPC85xx_DEVDISR_PCIE3)) {
207 printf("\n PCIE3 connected as %s (x%d)",
208 host ? "Root Complex" : "End Point", width);
209 if (pci->pme_msg_det) {
210 pci->pme_msg_det = 0xffffffff;
211 debug(" with errors. Clearing. Now 0x%08x",
212 pci->pme_msg_det);
213 }
214 printf("\n");
215
216 /* inbound */
217 r += fsl_pci_setup_inbound_windows(r);
218
219 /* outbound memory */
220 pci_set_region(r++,
221 CONFIG_SYS_PCIE3_MEM_BASE,
222 CONFIG_SYS_PCIE3_MEM_PHYS,
223 CONFIG_SYS_PCIE3_MEM_SIZE,
224 PCI_REGION_MEM);
225
226 /* outbound io */
227 pci_set_region(r++,
228 CONFIG_SYS_PCIE3_IO_BASE,
229 CONFIG_SYS_PCIE3_IO_PHYS,
230 CONFIG_SYS_PCIE3_IO_SIZE,
231 PCI_REGION_IO);
232
233 hose->region_count = r - hose->regions;
234
235 hose->first_busno = first_free_busno;
236 pci_setup_indirect(hose, (int)&pci->cfg_addr,
237 (int)&pci->cfg_data);
238
239 fsl_pci_init(hose);
240 first_free_busno = hose->last_busno+1;
241 printf(" PCIE3 on bus %02x - %02x\n",
242 hose->first_busno, hose->last_busno);
243 }
244#else
245 gur->devdisr |= MPC85xx_DEVDISR_PCIE3; /* disable */
246#endif /* CONFIG_PCIE3 */
247}
248
249#if defined(CONFIG_OF_BOARD_SETUP)
250extern void ft_fsl_pci_setup(void *blob, const char *pci_alias,
251 struct pci_controller *hose);
252
253void ft_board_pci_setup(void *blob, bd_t *bd)
254{
255#ifdef CONFIG_PCIE1
256 ft_fsl_pci_setup(blob, "pci2", &pcie1_hose);
257#endif
258#ifdef CONFIG_PCIE2
259 ft_fsl_pci_setup(blob, "pci1", &pcie2_hose);
260#endif
261#ifdef CONFIG_PCIE3
262 ft_fsl_pci_setup(blob, "pci0", &pcie3_hose);
263#endif
264}
265#endif /* CONFIG_OF_BOARD_SETUP */