Peter Tyser | 1c2b329 | 2008-12-17 16:36:23 -0600 | [diff] [blame] | 1 | /* |
| 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 | |
| 31 | extern int fsl_pci_setup_inbound_windows(struct pci_region *r); |
Peter Tyser | 2143be8 | 2008-10-29 12:39:27 -0500 | [diff] [blame^] | 32 | extern void fsl_pci_config_unlock(struct pci_controller *hose); |
Peter Tyser | 1c2b329 | 2008-12-17 16:36:23 -0600 | [diff] [blame] | 33 | extern void fsl_pci_init(struct pci_controller *hose); |
| 34 | |
| 35 | int first_free_busno = 0; |
| 36 | |
| 37 | #ifdef CONFIG_PCIE1 |
| 38 | static struct pci_controller pcie1_hose; |
| 39 | #endif |
| 40 | #ifdef CONFIG_PCIE2 |
| 41 | static struct pci_controller pcie2_hose; |
| 42 | #endif |
| 43 | #ifdef CONFIG_PCIE3 |
| 44 | static struct pci_controller pcie3_hose; |
| 45 | #endif |
| 46 | |
| 47 | /* Correlate host/agent POR bits to usable info. Table 4-14 */ |
| 48 | struct 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 */ |
| 63 | struct 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 | }; |
| 84 | |
| 85 | void pci_init_board(void) |
| 86 | { |
| 87 | struct pci_controller *hose; |
| 88 | volatile ccsr_fsl_pci_t *pci; |
| 89 | int width; |
| 90 | int host; |
| 91 | volatile ccsr_gur_t *gur = (void *)(CONFIG_SYS_MPC85xx_GUTS_ADDR); |
| 92 | uint devdisr = gur->devdisr; |
| 93 | uint io_sel = (gur->pordevsr & MPC85xx_PORDEVSR_IO_SEL) >> 19; |
| 94 | uint host_agent = (gur->porbmsr & MPC85xx_PORBMSR_HA) >> 16; |
| 95 | struct pci_region *r; |
| 96 | |
| 97 | debug(" pci_init_board: devdisr=%x, io_sel=%x, host_agent=%x\n", |
| 98 | devdisr, io_sel, host_agent); |
| 99 | |
| 100 | #ifdef CONFIG_PCIE1 |
| 101 | pci = (ccsr_fsl_pci_t *) CONFIG_SYS_PCIE1_ADDR; |
| 102 | hose = &pcie1_hose; |
| 103 | host = host_agent_cfg[host_agent].pcie_root[0]; |
| 104 | width = io_port_cfg[io_sel].pcie_width[0]; |
| 105 | r = hose->regions; |
| 106 | |
| 107 | if (width && !(devdisr & MPC85xx_DEVDISR_PCIE)) { |
| 108 | printf("\n PCIE1 connected as %s (x%d)", |
| 109 | host ? "Root Complex" : "End Point", width); |
| 110 | if (pci->pme_msg_det) { |
| 111 | pci->pme_msg_det = 0xffffffff; |
| 112 | debug(" with errors. Clearing. Now 0x%08x", |
| 113 | pci->pme_msg_det); |
| 114 | } |
| 115 | printf("\n"); |
| 116 | |
| 117 | /* inbound */ |
| 118 | r += fsl_pci_setup_inbound_windows(r); |
| 119 | |
| 120 | /* outbound memory */ |
| 121 | pci_set_region(r++, |
| 122 | CONFIG_SYS_PCIE1_MEM_BASE, |
| 123 | CONFIG_SYS_PCIE1_MEM_PHYS, |
| 124 | CONFIG_SYS_PCIE1_MEM_SIZE, |
| 125 | PCI_REGION_MEM); |
| 126 | |
| 127 | /* outbound io */ |
| 128 | pci_set_region(r++, |
| 129 | CONFIG_SYS_PCIE1_IO_BASE, |
| 130 | CONFIG_SYS_PCIE1_IO_PHYS, |
| 131 | CONFIG_SYS_PCIE1_IO_SIZE, |
| 132 | PCI_REGION_IO); |
| 133 | |
| 134 | hose->region_count = r - hose->regions; |
| 135 | |
| 136 | hose->first_busno = first_free_busno; |
| 137 | pci_setup_indirect(hose, (int)&pci->cfg_addr, |
| 138 | (int) &pci->cfg_data); |
| 139 | |
| 140 | fsl_pci_init(hose); |
| 141 | |
Peter Tyser | 2143be8 | 2008-10-29 12:39:27 -0500 | [diff] [blame^] | 142 | /* Unlock inbound PCI configuration cycles */ |
| 143 | if (!host) |
| 144 | fsl_pci_config_unlock(hose); |
| 145 | |
Peter Tyser | 1c2b329 | 2008-12-17 16:36:23 -0600 | [diff] [blame] | 146 | first_free_busno = hose->last_busno+1; |
| 147 | printf(" PCIE1 on bus %02x - %02x\n", |
| 148 | hose->first_busno, hose->last_busno); |
| 149 | } |
| 150 | #else |
| 151 | gur->devdisr |= MPC85xx_DEVDISR_PCIE; /* disable */ |
| 152 | #endif /* CONFIG_PCIE1 */ |
| 153 | |
| 154 | #ifdef CONFIG_PCIE2 |
| 155 | pci = (ccsr_fsl_pci_t *) CONFIG_SYS_PCIE2_ADDR; |
| 156 | hose = &pcie2_hose; |
| 157 | host = host_agent_cfg[host_agent].pcie_root[1]; |
| 158 | width = io_port_cfg[io_sel].pcie_width[1]; |
| 159 | r = hose->regions; |
| 160 | |
| 161 | if (width && !(devdisr & MPC85xx_DEVDISR_PCIE2)) { |
| 162 | printf("\n PCIE2 connected as %s (x%d)", |
| 163 | host ? "Root Complex" : "End Point", width); |
| 164 | if (pci->pme_msg_det) { |
| 165 | pci->pme_msg_det = 0xffffffff; |
| 166 | debug(" with errors. Clearing. Now 0x%08x", |
| 167 | pci->pme_msg_det); |
| 168 | } |
| 169 | printf("\n"); |
| 170 | |
| 171 | /* inbound */ |
| 172 | r += fsl_pci_setup_inbound_windows(r); |
| 173 | |
| 174 | /* outbound memory */ |
| 175 | pci_set_region(r++, |
| 176 | CONFIG_SYS_PCIE2_MEM_BASE, |
| 177 | CONFIG_SYS_PCIE2_MEM_PHYS, |
| 178 | CONFIG_SYS_PCIE2_MEM_SIZE, |
| 179 | PCI_REGION_MEM); |
| 180 | |
| 181 | /* outbound io */ |
| 182 | pci_set_region(r++, |
| 183 | CONFIG_SYS_PCIE2_IO_BASE, |
| 184 | CONFIG_SYS_PCIE2_IO_PHYS, |
| 185 | CONFIG_SYS_PCIE2_IO_SIZE, |
| 186 | PCI_REGION_IO); |
| 187 | |
| 188 | hose->region_count = r - hose->regions; |
| 189 | |
| 190 | hose->first_busno = first_free_busno; |
| 191 | pci_setup_indirect(hose, (int)&pci->cfg_addr, |
| 192 | (int)&pci->cfg_data); |
| 193 | |
| 194 | fsl_pci_init(hose); |
Peter Tyser | 2143be8 | 2008-10-29 12:39:27 -0500 | [diff] [blame^] | 195 | |
| 196 | /* Unlock inbound PCI configuration cycles */ |
| 197 | if (!host) |
| 198 | fsl_pci_config_unlock(hose); |
| 199 | |
Peter Tyser | 1c2b329 | 2008-12-17 16:36:23 -0600 | [diff] [blame] | 200 | first_free_busno = hose->last_busno+1; |
| 201 | printf(" PCIE2 on bus %02x - %02x\n", |
| 202 | hose->first_busno, hose->last_busno); |
| 203 | |
| 204 | } |
| 205 | #else |
| 206 | gur->devdisr |= MPC85xx_DEVDISR_PCIE2; /* disable */ |
| 207 | #endif /* CONFIG_PCIE2 */ |
| 208 | |
| 209 | #ifdef CONFIG_PCIE3 |
| 210 | pci = (ccsr_fsl_pci_t *) CONFIG_SYS_PCIE3_ADDR; |
| 211 | hose = &pcie3_hose; |
| 212 | host = host_agent_cfg[host_agent].pcie_root[2]; |
| 213 | width = io_port_cfg[io_sel].pcie_width[2]; |
| 214 | r = hose->regions; |
| 215 | |
| 216 | if (width && !(devdisr & MPC85xx_DEVDISR_PCIE3)) { |
| 217 | printf("\n PCIE3 connected as %s (x%d)", |
| 218 | host ? "Root Complex" : "End Point", width); |
| 219 | if (pci->pme_msg_det) { |
| 220 | pci->pme_msg_det = 0xffffffff; |
| 221 | debug(" with errors. Clearing. Now 0x%08x", |
| 222 | pci->pme_msg_det); |
| 223 | } |
| 224 | printf("\n"); |
| 225 | |
| 226 | /* inbound */ |
| 227 | r += fsl_pci_setup_inbound_windows(r); |
| 228 | |
| 229 | /* outbound memory */ |
| 230 | pci_set_region(r++, |
| 231 | CONFIG_SYS_PCIE3_MEM_BASE, |
| 232 | CONFIG_SYS_PCIE3_MEM_PHYS, |
| 233 | CONFIG_SYS_PCIE3_MEM_SIZE, |
| 234 | PCI_REGION_MEM); |
| 235 | |
| 236 | /* outbound io */ |
| 237 | pci_set_region(r++, |
| 238 | CONFIG_SYS_PCIE3_IO_BASE, |
| 239 | CONFIG_SYS_PCIE3_IO_PHYS, |
| 240 | CONFIG_SYS_PCIE3_IO_SIZE, |
| 241 | PCI_REGION_IO); |
| 242 | |
| 243 | hose->region_count = r - hose->regions; |
| 244 | |
| 245 | hose->first_busno = first_free_busno; |
| 246 | pci_setup_indirect(hose, (int)&pci->cfg_addr, |
| 247 | (int)&pci->cfg_data); |
| 248 | |
| 249 | fsl_pci_init(hose); |
Peter Tyser | 2143be8 | 2008-10-29 12:39:27 -0500 | [diff] [blame^] | 250 | |
| 251 | /* Unlock inbound PCI configuration cycles */ |
| 252 | if (!host) |
| 253 | fsl_pci_config_unlock(hose); |
| 254 | |
Peter Tyser | 1c2b329 | 2008-12-17 16:36:23 -0600 | [diff] [blame] | 255 | first_free_busno = hose->last_busno+1; |
| 256 | printf(" PCIE3 on bus %02x - %02x\n", |
| 257 | hose->first_busno, hose->last_busno); |
| 258 | } |
| 259 | #else |
| 260 | gur->devdisr |= MPC85xx_DEVDISR_PCIE3; /* disable */ |
| 261 | #endif /* CONFIG_PCIE3 */ |
| 262 | } |
| 263 | |
| 264 | #if defined(CONFIG_OF_BOARD_SETUP) |
| 265 | extern void ft_fsl_pci_setup(void *blob, const char *pci_alias, |
| 266 | struct pci_controller *hose); |
| 267 | |
| 268 | void ft_board_pci_setup(void *blob, bd_t *bd) |
| 269 | { |
| 270 | #ifdef CONFIG_PCIE1 |
| 271 | ft_fsl_pci_setup(blob, "pci2", &pcie1_hose); |
| 272 | #endif |
| 273 | #ifdef CONFIG_PCIE2 |
| 274 | ft_fsl_pci_setup(blob, "pci1", &pcie2_hose); |
| 275 | #endif |
| 276 | #ifdef CONFIG_PCIE3 |
| 277 | ft_fsl_pci_setup(blob, "pci0", &pcie3_hose); |
| 278 | #endif |
| 279 | } |
| 280 | #endif /* CONFIG_OF_BOARD_SETUP */ |