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