wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 1 | /* |
| 2 | * arch/ppc/kernel/pci_auto.c |
| 3 | * |
| 4 | * PCI autoconfiguration library |
| 5 | * |
| 6 | * Author: Matt Porter <mporter@mvista.com> |
| 7 | * |
| 8 | * Copyright 2000 MontaVista Software Inc. |
| 9 | * |
| 10 | * This program is free software; you can redistribute it and/or modify it |
| 11 | * under the terms of the GNU General Public License as published by the |
| 12 | * Free Software Foundation; either version 2 of the License, or (at your |
| 13 | * option) any later version. |
| 14 | */ |
| 15 | |
| 16 | #include <common.h> |
| 17 | |
| 18 | #ifdef CONFIG_PCI |
| 19 | |
| 20 | #include <pci.h> |
| 21 | |
| 22 | #undef DEBUG |
| 23 | #ifdef DEBUG |
| 24 | #define DEBUGF(x...) printf(x) |
| 25 | #else |
| 26 | #define DEBUGF(x...) |
| 27 | #endif /* DEBUG */ |
| 28 | |
| 29 | #define PCIAUTO_IDE_MODE_MASK 0x05 |
| 30 | |
| 31 | /* |
| 32 | * |
| 33 | */ |
| 34 | |
| 35 | void pciauto_region_init(struct pci_region* res) |
| 36 | { |
Sergei Shtylyov | b7598a4 | 2007-04-23 15:30:39 +0200 | [diff] [blame] | 37 | /* |
| 38 | * Avoid allocating PCI resources from address 0 -- this is illegal |
| 39 | * according to PCI 2.1 and moreover, this is known to cause Linux IDE |
| 40 | * drivers to fail. Use a reasonable starting value of 0x1000 instead. |
| 41 | */ |
| 42 | res->bus_lower = res->bus_start ? res->bus_start : 0x1000; |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 43 | } |
| 44 | |
| 45 | void pciauto_region_align(struct pci_region *res, unsigned long size) |
| 46 | { |
| 47 | res->bus_lower = ((res->bus_lower - 1) | (size - 1)) + 1; |
| 48 | } |
| 49 | |
| 50 | int pciauto_region_allocate(struct pci_region* res, unsigned int size, unsigned int *bar) |
| 51 | { |
| 52 | unsigned long addr; |
| 53 | |
wdenk | 3c74e32 | 2004-02-22 23:46:08 +0000 | [diff] [blame] | 54 | if (!res) { |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 55 | DEBUGF("No resource"); |
| 56 | goto error; |
| 57 | } |
| 58 | |
| 59 | addr = ((res->bus_lower - 1) | (size - 1)) + 1; |
| 60 | |
wdenk | 3c74e32 | 2004-02-22 23:46:08 +0000 | [diff] [blame] | 61 | if (addr - res->bus_start + size > res->size) { |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 62 | DEBUGF("No room in resource"); |
| 63 | goto error; |
| 64 | } |
| 65 | |
| 66 | res->bus_lower = addr + size; |
| 67 | |
Ed Swarthout | ba5feb1 | 2007-07-11 14:51:48 -0500 | [diff] [blame] | 68 | DEBUGF("address=0x%lx bus_lower=%x", addr, res->bus_lower); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 69 | |
| 70 | *bar = addr; |
| 71 | return 0; |
| 72 | |
| 73 | error: |
| 74 | *bar = 0xffffffff; |
| 75 | return -1; |
| 76 | } |
| 77 | |
| 78 | /* |
| 79 | * |
| 80 | */ |
| 81 | |
| 82 | void pciauto_setup_device(struct pci_controller *hose, |
| 83 | pci_dev_t dev, int bars_num, |
| 84 | struct pci_region *mem, |
Kumar Gala | a179012 | 2006-01-11 13:24:15 -0600 | [diff] [blame] | 85 | struct pci_region *prefetch, |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 86 | struct pci_region *io) |
| 87 | { |
| 88 | unsigned int bar_value, bar_response, bar_size; |
| 89 | unsigned int cmdstat = 0; |
| 90 | struct pci_region *bar_res; |
| 91 | int bar, bar_nr = 0; |
| 92 | int found_mem64 = 0; |
| 93 | |
| 94 | pci_hose_read_config_dword(hose, dev, PCI_COMMAND, &cmdstat); |
| 95 | cmdstat = (cmdstat & ~(PCI_COMMAND_IO | PCI_COMMAND_MEMORY)) | PCI_COMMAND_MASTER; |
| 96 | |
Ed Swarthout | 936b3e6 | 2007-07-27 01:50:44 -0500 | [diff] [blame] | 97 | for (bar = PCI_BASE_ADDRESS_0; bar < PCI_BASE_ADDRESS_0 + (bars_num*4); bar += 4) { |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 98 | /* Tickle the BAR and get the response */ |
| 99 | pci_hose_write_config_dword(hose, dev, bar, 0xffffffff); |
| 100 | pci_hose_read_config_dword(hose, dev, bar, &bar_response); |
| 101 | |
| 102 | /* If BAR is not implemented go to the next BAR */ |
| 103 | if (!bar_response) |
| 104 | continue; |
| 105 | |
| 106 | found_mem64 = 0; |
| 107 | |
| 108 | /* Check the BAR type and set our address mask */ |
wdenk | 3c74e32 | 2004-02-22 23:46:08 +0000 | [diff] [blame] | 109 | if (bar_response & PCI_BASE_ADDRESS_SPACE) { |
Jin Zhengxiong-R64188 | bd22c2b | 2006-06-27 18:12:02 +0800 | [diff] [blame] | 110 | bar_size = ((~(bar_response & PCI_BASE_ADDRESS_IO_MASK)) |
| 111 | & 0xffff) + 1; |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 112 | bar_res = io; |
| 113 | |
| 114 | DEBUGF("PCI Autoconfig: BAR %d, I/O, size=0x%x, ", bar_nr, bar_size); |
wdenk | 3c74e32 | 2004-02-22 23:46:08 +0000 | [diff] [blame] | 115 | } else { |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 116 | if ( (bar_response & PCI_BASE_ADDRESS_MEM_TYPE_MASK) == |
| 117 | PCI_BASE_ADDRESS_MEM_TYPE_64) |
| 118 | found_mem64 = 1; |
| 119 | |
| 120 | bar_size = ~(bar_response & PCI_BASE_ADDRESS_MEM_MASK) + 1; |
Kumar Gala | a179012 | 2006-01-11 13:24:15 -0600 | [diff] [blame] | 121 | if (prefetch && (bar_response & PCI_BASE_ADDRESS_MEM_PREFETCH)) |
| 122 | bar_res = prefetch; |
| 123 | else |
| 124 | bar_res = mem; |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 125 | |
| 126 | DEBUGF("PCI Autoconfig: BAR %d, Mem, size=0x%x, ", bar_nr, bar_size); |
| 127 | } |
| 128 | |
wdenk | 3c74e32 | 2004-02-22 23:46:08 +0000 | [diff] [blame] | 129 | if (pciauto_region_allocate(bar_res, bar_size, &bar_value) == 0) { |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 130 | /* Write it out and update our limit */ |
| 131 | pci_hose_write_config_dword(hose, dev, bar, bar_value); |
| 132 | |
| 133 | /* |
| 134 | * If we are a 64-bit decoder then increment to the |
| 135 | * upper 32 bits of the bar and force it to locate |
| 136 | * in the lower 4GB of memory. |
| 137 | */ |
wdenk | 3c74e32 | 2004-02-22 23:46:08 +0000 | [diff] [blame] | 138 | if (found_mem64) { |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 139 | bar += 4; |
| 140 | pci_hose_write_config_dword(hose, dev, bar, 0x00000000); |
| 141 | } |
| 142 | |
| 143 | cmdstat |= (bar_response & PCI_BASE_ADDRESS_SPACE) ? |
| 144 | PCI_COMMAND_IO : PCI_COMMAND_MEMORY; |
| 145 | } |
| 146 | |
| 147 | DEBUGF("\n"); |
| 148 | |
| 149 | bar_nr++; |
| 150 | } |
| 151 | |
| 152 | pci_hose_write_config_dword(hose, dev, PCI_COMMAND, cmdstat); |
| 153 | pci_hose_write_config_byte(hose, dev, PCI_CACHE_LINE_SIZE, 0x08); |
| 154 | pci_hose_write_config_byte(hose, dev, PCI_LATENCY_TIMER, 0x80); |
| 155 | } |
| 156 | |
Ed Swarthout | ba5feb1 | 2007-07-11 14:51:48 -0500 | [diff] [blame] | 157 | void pciauto_prescan_setup_bridge(struct pci_controller *hose, |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 158 | pci_dev_t dev, int sub_bus) |
| 159 | { |
| 160 | struct pci_region *pci_mem = hose->pci_mem; |
Kumar Gala | a179012 | 2006-01-11 13:24:15 -0600 | [diff] [blame] | 161 | struct pci_region *pci_prefetch = hose->pci_prefetch; |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 162 | struct pci_region *pci_io = hose->pci_io; |
| 163 | unsigned int cmdstat; |
| 164 | |
| 165 | pci_hose_read_config_dword(hose, dev, PCI_COMMAND, &cmdstat); |
| 166 | |
| 167 | /* Configure bus number registers */ |
Ed Swarthout | e8b85f3 | 2007-07-11 14:52:08 -0500 | [diff] [blame] | 168 | pci_hose_write_config_byte(hose, dev, PCI_PRIMARY_BUS, |
| 169 | PCI_BUS(dev) - hose->first_busno); |
| 170 | pci_hose_write_config_byte(hose, dev, PCI_SECONDARY_BUS, |
| 171 | sub_bus - hose->first_busno); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 172 | pci_hose_write_config_byte(hose, dev, PCI_SUBORDINATE_BUS, 0xff); |
| 173 | |
wdenk | 3c74e32 | 2004-02-22 23:46:08 +0000 | [diff] [blame] | 174 | if (pci_mem) { |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 175 | /* Round memory allocator to 1MB boundary */ |
| 176 | pciauto_region_align(pci_mem, 0x100000); |
| 177 | |
| 178 | /* Set up memory and I/O filter limits, assume 32-bit I/O space */ |
| 179 | pci_hose_write_config_word(hose, dev, PCI_MEMORY_BASE, |
| 180 | (pci_mem->bus_lower & 0xfff00000) >> 16); |
| 181 | |
| 182 | cmdstat |= PCI_COMMAND_MEMORY; |
| 183 | } |
| 184 | |
Kumar Gala | a179012 | 2006-01-11 13:24:15 -0600 | [diff] [blame] | 185 | if (pci_prefetch) { |
| 186 | /* Round memory allocator to 1MB boundary */ |
| 187 | pciauto_region_align(pci_prefetch, 0x100000); |
| 188 | |
| 189 | /* Set up memory and I/O filter limits, assume 32-bit I/O space */ |
| 190 | pci_hose_write_config_word(hose, dev, PCI_PREF_MEMORY_BASE, |
| 191 | (pci_prefetch->bus_lower & 0xfff00000) >> 16); |
| 192 | |
| 193 | cmdstat |= PCI_COMMAND_MEMORY; |
| 194 | } else { |
| 195 | /* We don't support prefetchable memory for now, so disable */ |
| 196 | pci_hose_write_config_word(hose, dev, PCI_PREF_MEMORY_BASE, 0x1000); |
Matthew McClintock | a4e1155 | 2006-06-28 10:44:23 -0500 | [diff] [blame] | 197 | pci_hose_write_config_word(hose, dev, PCI_PREF_MEMORY_LIMIT, 0x0); |
Kumar Gala | a179012 | 2006-01-11 13:24:15 -0600 | [diff] [blame] | 198 | } |
| 199 | |
wdenk | 3c74e32 | 2004-02-22 23:46:08 +0000 | [diff] [blame] | 200 | if (pci_io) { |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 201 | /* Round I/O allocator to 4KB boundary */ |
| 202 | pciauto_region_align(pci_io, 0x1000); |
| 203 | |
| 204 | pci_hose_write_config_byte(hose, dev, PCI_IO_BASE, |
| 205 | (pci_io->bus_lower & 0x0000f000) >> 8); |
| 206 | pci_hose_write_config_word(hose, dev, PCI_IO_BASE_UPPER16, |
| 207 | (pci_io->bus_lower & 0xffff0000) >> 16); |
| 208 | |
| 209 | cmdstat |= PCI_COMMAND_IO; |
| 210 | } |
| 211 | |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 212 | /* Enable memory and I/O accesses, enable bus master */ |
| 213 | pci_hose_write_config_dword(hose, dev, PCI_COMMAND, cmdstat | PCI_COMMAND_MASTER); |
| 214 | } |
| 215 | |
Ed Swarthout | ba5feb1 | 2007-07-11 14:51:48 -0500 | [diff] [blame] | 216 | void pciauto_postscan_setup_bridge(struct pci_controller *hose, |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 217 | pci_dev_t dev, int sub_bus) |
| 218 | { |
| 219 | struct pci_region *pci_mem = hose->pci_mem; |
Kumar Gala | a179012 | 2006-01-11 13:24:15 -0600 | [diff] [blame] | 220 | struct pci_region *pci_prefetch = hose->pci_prefetch; |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 221 | struct pci_region *pci_io = hose->pci_io; |
| 222 | |
| 223 | /* Configure bus number registers */ |
Ed Swarthout | e8b85f3 | 2007-07-11 14:52:08 -0500 | [diff] [blame] | 224 | pci_hose_write_config_byte(hose, dev, PCI_SUBORDINATE_BUS, |
| 225 | sub_bus - hose->first_busno); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 226 | |
wdenk | 3c74e32 | 2004-02-22 23:46:08 +0000 | [diff] [blame] | 227 | if (pci_mem) { |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 228 | /* Round memory allocator to 1MB boundary */ |
| 229 | pciauto_region_align(pci_mem, 0x100000); |
| 230 | |
| 231 | pci_hose_write_config_word(hose, dev, PCI_MEMORY_LIMIT, |
| 232 | (pci_mem->bus_lower-1) >> 16); |
| 233 | } |
| 234 | |
Kumar Gala | a179012 | 2006-01-11 13:24:15 -0600 | [diff] [blame] | 235 | if (pci_prefetch) { |
| 236 | /* Round memory allocator to 1MB boundary */ |
| 237 | pciauto_region_align(pci_prefetch, 0x100000); |
| 238 | |
| 239 | pci_hose_write_config_word(hose, dev, PCI_PREF_MEMORY_LIMIT, |
| 240 | (pci_prefetch->bus_lower-1) >> 16); |
| 241 | } |
| 242 | |
wdenk | 3c74e32 | 2004-02-22 23:46:08 +0000 | [diff] [blame] | 243 | if (pci_io) { |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 244 | /* Round I/O allocator to 4KB boundary */ |
| 245 | pciauto_region_align(pci_io, 0x1000); |
| 246 | |
| 247 | pci_hose_write_config_byte(hose, dev, PCI_IO_LIMIT, |
| 248 | ((pci_io->bus_lower-1) & 0x0000f000) >> 8); |
| 249 | pci_hose_write_config_word(hose, dev, PCI_IO_LIMIT_UPPER16, |
| 250 | ((pci_io->bus_lower-1) & 0xffff0000) >> 16); |
| 251 | } |
| 252 | } |
| 253 | |
| 254 | /* |
| 255 | * |
| 256 | */ |
| 257 | |
| 258 | void pciauto_config_init(struct pci_controller *hose) |
| 259 | { |
| 260 | int i; |
| 261 | |
| 262 | hose->pci_io = hose->pci_mem = NULL; |
| 263 | |
wdenk | 3c74e32 | 2004-02-22 23:46:08 +0000 | [diff] [blame] | 264 | for (i=0; i<hose->region_count; i++) { |
| 265 | switch(hose->regions[i].flags) { |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 266 | case PCI_REGION_IO: |
| 267 | if (!hose->pci_io || |
| 268 | hose->pci_io->size < hose->regions[i].size) |
| 269 | hose->pci_io = hose->regions + i; |
| 270 | break; |
| 271 | case PCI_REGION_MEM: |
| 272 | if (!hose->pci_mem || |
| 273 | hose->pci_mem->size < hose->regions[i].size) |
| 274 | hose->pci_mem = hose->regions + i; |
| 275 | break; |
Kumar Gala | a179012 | 2006-01-11 13:24:15 -0600 | [diff] [blame] | 276 | case (PCI_REGION_MEM | PCI_REGION_PREFETCH): |
| 277 | if (!hose->pci_prefetch || |
| 278 | hose->pci_prefetch->size < hose->regions[i].size) |
| 279 | hose->pci_prefetch = hose->regions + i; |
| 280 | break; |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 281 | } |
| 282 | } |
| 283 | |
| 284 | |
wdenk | 3c74e32 | 2004-02-22 23:46:08 +0000 | [diff] [blame] | 285 | if (hose->pci_mem) { |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 286 | pciauto_region_init(hose->pci_mem); |
| 287 | |
Ed Swarthout | ba5feb1 | 2007-07-11 14:51:48 -0500 | [diff] [blame] | 288 | DEBUGF("PCI Autoconfig: Bus Memory region: [%lx-%lx],\n" |
| 289 | "\t\tPhysical Memory [%x-%x]\n", |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 290 | hose->pci_mem->bus_start, |
Ed Swarthout | ba5feb1 | 2007-07-11 14:51:48 -0500 | [diff] [blame] | 291 | hose->pci_mem->bus_start + hose->pci_mem->size - 1, |
| 292 | hose->pci_mem->phys_start, |
| 293 | hose->pci_mem->phys_start + hose->pci_mem->size - 1); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 294 | } |
| 295 | |
Kumar Gala | a179012 | 2006-01-11 13:24:15 -0600 | [diff] [blame] | 296 | if (hose->pci_prefetch) { |
| 297 | pciauto_region_init(hose->pci_prefetch); |
| 298 | |
Ed Swarthout | ba5feb1 | 2007-07-11 14:51:48 -0500 | [diff] [blame] | 299 | DEBUGF("PCI Autoconfig: Bus Prefetchable Mem: [%lx-%lx],\n" |
| 300 | "\t\tPhysical Memory [%x-%x]\n", |
Kumar Gala | a179012 | 2006-01-11 13:24:15 -0600 | [diff] [blame] | 301 | hose->pci_prefetch->bus_start, |
Ed Swarthout | ba5feb1 | 2007-07-11 14:51:48 -0500 | [diff] [blame] | 302 | hose->pci_prefetch->bus_start + hose->pci_prefetch->size - 1, |
| 303 | hose->pci_prefetch->phys_start, |
| 304 | hose->pci_prefetch->phys_start + |
| 305 | hose->pci_prefetch->size - 1); |
Kumar Gala | a179012 | 2006-01-11 13:24:15 -0600 | [diff] [blame] | 306 | } |
| 307 | |
wdenk | 3c74e32 | 2004-02-22 23:46:08 +0000 | [diff] [blame] | 308 | if (hose->pci_io) { |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 309 | pciauto_region_init(hose->pci_io); |
| 310 | |
Ed Swarthout | ba5feb1 | 2007-07-11 14:51:48 -0500 | [diff] [blame] | 311 | DEBUGF("PCI Autoconfig: Bus I/O region: [%lx-%lx],\n" |
| 312 | "\t\tPhysical Memory: [%x-%x]\n", |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 313 | hose->pci_io->bus_start, |
Ed Swarthout | ba5feb1 | 2007-07-11 14:51:48 -0500 | [diff] [blame] | 314 | hose->pci_io->bus_start + hose->pci_io->size - 1, |
| 315 | hose->pci_io->phys_start, |
| 316 | hose->pci_io->phys_start + hose->pci_io->size - 1); |
| 317 | |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 318 | } |
| 319 | } |
| 320 | |
wdenk | c7de829 | 2002-11-19 11:04:11 +0000 | [diff] [blame] | 321 | /* HJF: Changed this to return int. I think this is required |
| 322 | * to get the correct result when scanning bridges |
| 323 | */ |
| 324 | int pciauto_config_device(struct pci_controller *hose, pci_dev_t dev) |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 325 | { |
wdenk | c7de829 | 2002-11-19 11:04:11 +0000 | [diff] [blame] | 326 | unsigned int sub_bus = PCI_BUS(dev); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 327 | unsigned short class; |
| 328 | unsigned char prg_iface; |
wdenk | 5653fc3 | 2004-02-08 22:55:38 +0000 | [diff] [blame] | 329 | int n; |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 330 | |
| 331 | pci_hose_read_config_word(hose, dev, PCI_CLASS_DEVICE, &class); |
| 332 | |
wdenk | 3c74e32 | 2004-02-22 23:46:08 +0000 | [diff] [blame] | 333 | switch(class) { |
Ed Swarthout | 5dc210d | 2007-07-11 14:52:16 -0500 | [diff] [blame] | 334 | case PCI_CLASS_PROCESSOR_POWERPC: /* an agent or end-point */ |
| 335 | DEBUGF("PCI AutoConfig: Found PowerPC device\n"); |
| 336 | pciauto_setup_device(hose, dev, 6, hose->pci_mem, |
| 337 | hose->pci_prefetch, hose->pci_io); |
| 338 | break; |
| 339 | |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 340 | case PCI_CLASS_BRIDGE_PCI: |
wdenk | db2f721f | 2003-03-06 00:58:30 +0000 | [diff] [blame] | 341 | hose->current_busno++; |
Kumar Gala | a179012 | 2006-01-11 13:24:15 -0600 | [diff] [blame] | 342 | pciauto_setup_device(hose, dev, 2, hose->pci_mem, hose->pci_prefetch, hose->pci_io); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 343 | |
wdenk | db2f721f | 2003-03-06 00:58:30 +0000 | [diff] [blame] | 344 | DEBUGF("PCI Autoconfig: Found P2P bridge, device %d\n", PCI_DEV(dev)); |
wdenk | cd37d9e | 2004-02-10 00:03:41 +0000 | [diff] [blame] | 345 | |
wdenk | 3c74e32 | 2004-02-22 23:46:08 +0000 | [diff] [blame] | 346 | /* Passing in current_busno allows for sibling P2P bridges */ |
wdenk | 5653fc3 | 2004-02-08 22:55:38 +0000 | [diff] [blame] | 347 | pciauto_prescan_setup_bridge(hose, dev, hose->current_busno); |
wdenk | cd37d9e | 2004-02-10 00:03:41 +0000 | [diff] [blame] | 348 | /* |
wdenk | 3c74e32 | 2004-02-22 23:46:08 +0000 | [diff] [blame] | 349 | * need to figure out if this is a subordinate bridge on the bus |
wdenk | 5653fc3 | 2004-02-08 22:55:38 +0000 | [diff] [blame] | 350 | * to be able to properly set the pri/sec/sub bridge registers. |
| 351 | */ |
| 352 | n = pci_hose_scan_bus(hose, hose->current_busno); |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 353 | |
wdenk | 3c74e32 | 2004-02-22 23:46:08 +0000 | [diff] [blame] | 354 | /* figure out the deepest we've gone for this leg */ |
wdenk | 5653fc3 | 2004-02-08 22:55:38 +0000 | [diff] [blame] | 355 | sub_bus = max(n, sub_bus); |
wdenk | db2f721f | 2003-03-06 00:58:30 +0000 | [diff] [blame] | 356 | pciauto_postscan_setup_bridge(hose, dev, sub_bus); |
wdenk | 5653fc3 | 2004-02-08 22:55:38 +0000 | [diff] [blame] | 357 | |
wdenk | db2f721f | 2003-03-06 00:58:30 +0000 | [diff] [blame] | 358 | sub_bus = hose->current_busno; |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 359 | break; |
| 360 | |
| 361 | case PCI_CLASS_STORAGE_IDE: |
| 362 | pci_hose_read_config_byte(hose, dev, PCI_CLASS_PROG, &prg_iface); |
wdenk | 3c74e32 | 2004-02-22 23:46:08 +0000 | [diff] [blame] | 363 | if (!(prg_iface & PCIAUTO_IDE_MODE_MASK)) { |
| 364 | DEBUGF("PCI Autoconfig: Skipping legacy mode IDE controller\n"); |
| 365 | return sub_bus; |
| 366 | } |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 367 | |
Kumar Gala | a179012 | 2006-01-11 13:24:15 -0600 | [diff] [blame] | 368 | pciauto_setup_device(hose, dev, 6, hose->pci_mem, hose->pci_prefetch, hose->pci_io); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 369 | break; |
| 370 | |
wdenk | 1cb8e98 | 2003-03-06 21:55:29 +0000 | [diff] [blame] | 371 | case PCI_CLASS_BRIDGE_CARDBUS: |
| 372 | /* just do a minimal setup of the bridge, let the OS take care of the rest */ |
Kumar Gala | a179012 | 2006-01-11 13:24:15 -0600 | [diff] [blame] | 373 | pciauto_setup_device(hose, dev, 0, hose->pci_mem, hose->pci_prefetch, hose->pci_io); |
wdenk | 1cb8e98 | 2003-03-06 21:55:29 +0000 | [diff] [blame] | 374 | |
wdenk | 3c74e32 | 2004-02-22 23:46:08 +0000 | [diff] [blame] | 375 | DEBUGF("PCI Autoconfig: Found P2CardBus bridge, device %d\n", PCI_DEV(dev)); |
wdenk | 1cb8e98 | 2003-03-06 21:55:29 +0000 | [diff] [blame] | 376 | |
| 377 | hose->current_busno++; |
| 378 | break; |
| 379 | |
wdenk | e0ac62d | 2003-08-17 18:55:18 +0000 | [diff] [blame] | 380 | #ifdef CONFIG_MPC5200 |
| 381 | case PCI_CLASS_BRIDGE_OTHER: |
| 382 | DEBUGF("PCI Autoconfig: Skipping bridge device %d\n", |
| 383 | PCI_DEV(dev)); |
| 384 | break; |
| 385 | #endif |
Rafal Jaworowski | 6902df5 | 2005-10-17 02:39:53 +0200 | [diff] [blame] | 386 | #ifdef CONFIG_MPC834X |
| 387 | case PCI_CLASS_BRIDGE_OTHER: |
| 388 | /* |
| 389 | * The host/PCI bridge 1 seems broken in 8349 - it presents |
| 390 | * itself as 'PCI_CLASS_BRIDGE_OTHER' and appears as an _agent_ |
| 391 | * device claiming resources io/mem/irq.. we only allow for |
| 392 | * the PIMMR window to be allocated (BAR0 - 1MB size) |
| 393 | */ |
| 394 | DEBUGF("PCI Autoconfig: Broken bridge found, only minimal config\n"); |
Kumar Gala | a179012 | 2006-01-11 13:24:15 -0600 | [diff] [blame] | 395 | pciauto_setup_device(hose, dev, 0, hose->pci_mem, hose->pci_prefetch, hose->pci_io); |
Rafal Jaworowski | 6902df5 | 2005-10-17 02:39:53 +0200 | [diff] [blame] | 396 | break; |
| 397 | #endif |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 398 | default: |
Kumar Gala | a179012 | 2006-01-11 13:24:15 -0600 | [diff] [blame] | 399 | pciauto_setup_device(hose, dev, 6, hose->pci_mem, hose->pci_prefetch, hose->pci_io); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 400 | break; |
| 401 | } |
wdenk | c7de829 | 2002-11-19 11:04:11 +0000 | [diff] [blame] | 402 | |
| 403 | return sub_bus; |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 404 | } |
| 405 | |
| 406 | #endif /* CONFIG_PCI */ |