wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 1 | /* |
| 2 | * (C) Copyright 2001 Sysgo Real-Time Solutions, GmbH <www.elinos.com> |
| 3 | * Andreas Heppel <aheppel@sysgo.de> |
| 4 | * |
wdenk | f4688a2 | 2003-05-28 08:06:31 +0000 | [diff] [blame] | 5 | * (C) Copyright 2002, 2003 |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 6 | * Wolfgang Denk, DENX Software Engineering, wd@denx.de. |
| 7 | * |
| 8 | * See file CREDITS for list of people who contributed to this |
| 9 | * project. |
| 10 | * |
| 11 | * This program is free software; you can redistribute it and/or |
| 12 | * modify it under the terms of the GNU General Public License as |
| 13 | * published by the Free Software Foundation; either version 2 of |
| 14 | * the License, or (at your option) any later version. |
| 15 | * |
| 16 | * This program is distributed in the hope that it will be useful, |
| 17 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 18 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 19 | * GNU General Public License for more details. |
| 20 | * |
| 21 | * You should have received a copy of the GNU General Public License |
| 22 | * along with this program; if not, write to the Free Software |
| 23 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, |
| 24 | * MA 02111-1307 USA |
| 25 | */ |
| 26 | |
| 27 | /* |
| 28 | * PCI routines |
| 29 | */ |
| 30 | |
| 31 | #include <common.h> |
| 32 | |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 33 | #include <command.h> |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 34 | #include <asm/processor.h> |
| 35 | #include <asm/io.h> |
| 36 | #include <pci.h> |
| 37 | |
wdenk | f4688a2 | 2003-05-28 08:06:31 +0000 | [diff] [blame] | 38 | #define PCI_HOSE_OP(rw, size, type) \ |
Wolfgang Denk | a1be476 | 2008-05-20 16:00:29 +0200 | [diff] [blame] | 39 | int pci_hose_##rw##_config_##size(struct pci_controller *hose, \ |
| 40 | pci_dev_t dev, \ |
wdenk | f4688a2 | 2003-05-28 08:06:31 +0000 | [diff] [blame] | 41 | int offset, type value) \ |
| 42 | { \ |
| 43 | return hose->rw##_##size(hose, dev, offset, value); \ |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 44 | } |
| 45 | |
| 46 | PCI_HOSE_OP(read, byte, u8 *) |
| 47 | PCI_HOSE_OP(read, word, u16 *) |
| 48 | PCI_HOSE_OP(read, dword, u32 *) |
| 49 | PCI_HOSE_OP(write, byte, u8) |
| 50 | PCI_HOSE_OP(write, word, u16) |
| 51 | PCI_HOSE_OP(write, dword, u32) |
| 52 | |
wdenk | f4688a2 | 2003-05-28 08:06:31 +0000 | [diff] [blame] | 53 | #define PCI_OP(rw, size, type, error_code) \ |
| 54 | int pci_##rw##_config_##size(pci_dev_t dev, int offset, type value) \ |
| 55 | { \ |
| 56 | struct pci_controller *hose = pci_bus_to_hose(PCI_BUS(dev)); \ |
| 57 | \ |
| 58 | if (!hose) \ |
| 59 | { \ |
| 60 | error_code; \ |
| 61 | return -1; \ |
| 62 | } \ |
| 63 | \ |
| 64 | return pci_hose_##rw##_config_##size(hose, dev, offset, value); \ |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 65 | } |
| 66 | |
| 67 | PCI_OP(read, byte, u8 *, *value = 0xff) |
| 68 | PCI_OP(read, word, u16 *, *value = 0xffff) |
| 69 | PCI_OP(read, dword, u32 *, *value = 0xffffffff) |
| 70 | PCI_OP(write, byte, u8, ) |
| 71 | PCI_OP(write, word, u16, ) |
| 72 | PCI_OP(write, dword, u32, ) |
| 73 | |
wdenk | f4688a2 | 2003-05-28 08:06:31 +0000 | [diff] [blame] | 74 | #define PCI_READ_VIA_DWORD_OP(size, type, off_mask) \ |
| 75 | int pci_hose_read_config_##size##_via_dword(struct pci_controller *hose,\ |
Wolfgang Denk | a1be476 | 2008-05-20 16:00:29 +0200 | [diff] [blame] | 76 | pci_dev_t dev, \ |
wdenk | f4688a2 | 2003-05-28 08:06:31 +0000 | [diff] [blame] | 77 | int offset, type val) \ |
| 78 | { \ |
| 79 | u32 val32; \ |
| 80 | \ |
Shinya Kuribayashi | f19da9d | 2007-08-17 12:43:44 +0900 | [diff] [blame] | 81 | if (pci_hose_read_config_dword(hose, dev, offset & 0xfc, &val32) < 0) { \ |
| 82 | *val = -1; \ |
wdenk | f4688a2 | 2003-05-28 08:06:31 +0000 | [diff] [blame] | 83 | return -1; \ |
Shinya Kuribayashi | f19da9d | 2007-08-17 12:43:44 +0900 | [diff] [blame] | 84 | } \ |
wdenk | f4688a2 | 2003-05-28 08:06:31 +0000 | [diff] [blame] | 85 | \ |
| 86 | *val = (val32 >> ((offset & (int)off_mask) * 8)); \ |
| 87 | \ |
| 88 | return 0; \ |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 89 | } |
| 90 | |
wdenk | f4688a2 | 2003-05-28 08:06:31 +0000 | [diff] [blame] | 91 | #define PCI_WRITE_VIA_DWORD_OP(size, type, off_mask, val_mask) \ |
| 92 | int pci_hose_write_config_##size##_via_dword(struct pci_controller *hose,\ |
Wolfgang Denk | a1be476 | 2008-05-20 16:00:29 +0200 | [diff] [blame] | 93 | pci_dev_t dev, \ |
wdenk | f4688a2 | 2003-05-28 08:06:31 +0000 | [diff] [blame] | 94 | int offset, type val) \ |
| 95 | { \ |
wdenk | 19c8fb7 | 2004-04-18 22:26:17 +0000 | [diff] [blame] | 96 | u32 val32, mask, ldata, shift; \ |
wdenk | f4688a2 | 2003-05-28 08:06:31 +0000 | [diff] [blame] | 97 | \ |
| 98 | if (pci_hose_read_config_dword(hose, dev, offset & 0xfc, &val32) < 0)\ |
| 99 | return -1; \ |
| 100 | \ |
wdenk | 19c8fb7 | 2004-04-18 22:26:17 +0000 | [diff] [blame] | 101 | shift = ((offset & (int)off_mask) * 8); \ |
| 102 | ldata = (((unsigned long)val) & val_mask) << shift; \ |
| 103 | mask = val_mask << shift; \ |
wdenk | f4688a2 | 2003-05-28 08:06:31 +0000 | [diff] [blame] | 104 | val32 = (val32 & ~mask) | ldata; \ |
| 105 | \ |
| 106 | if (pci_hose_write_config_dword(hose, dev, offset & 0xfc, val32) < 0)\ |
| 107 | return -1; \ |
| 108 | \ |
| 109 | return 0; \ |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 110 | } |
| 111 | |
| 112 | PCI_READ_VIA_DWORD_OP(byte, u8 *, 0x03) |
| 113 | PCI_READ_VIA_DWORD_OP(word, u16 *, 0x02) |
| 114 | PCI_WRITE_VIA_DWORD_OP(byte, u8, 0x03, 0x000000ff) |
| 115 | PCI_WRITE_VIA_DWORD_OP(word, u16, 0x02, 0x0000ffff) |
| 116 | |
Becky Bruce | 0709bfc | 2009-02-03 18:10:50 -0600 | [diff] [blame] | 117 | /* Get a virtual address associated with a BAR region */ |
| 118 | void *pci_map_bar(pci_dev_t pdev, int bar, int flags) |
| 119 | { |
| 120 | pci_addr_t pci_bus_addr; |
Andrew Sharp | f4f2482 | 2012-08-01 12:27:16 +0000 | [diff] [blame] | 121 | pci_addr_t bar_response; |
Becky Bruce | 0709bfc | 2009-02-03 18:10:50 -0600 | [diff] [blame] | 122 | |
| 123 | /* read BAR address */ |
| 124 | pci_read_config_dword(pdev, bar, &bar_response); |
Andrew Sharp | f4f2482 | 2012-08-01 12:27:16 +0000 | [diff] [blame] | 125 | pci_bus_addr = bar_response & ~0xf; |
Becky Bruce | 0709bfc | 2009-02-03 18:10:50 -0600 | [diff] [blame] | 126 | |
| 127 | /* |
| 128 | * Pass "0" as the length argument to pci_bus_to_virt. The arg |
| 129 | * isn't actualy used on any platform because u-boot assumes a static |
| 130 | * linear mapping. In the future, this could read the BAR size |
| 131 | * and pass that as the size if needed. |
| 132 | */ |
| 133 | return pci_bus_to_virt(pdev, pci_bus_addr, flags, 0, MAP_NOCACHE); |
| 134 | } |
| 135 | |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 136 | /* |
| 137 | * |
| 138 | */ |
| 139 | |
John Schmoller | 60e877f | 2010-10-22 00:20:23 -0500 | [diff] [blame] | 140 | static struct pci_controller* hose_head; |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 141 | |
| 142 | void pci_register_hose(struct pci_controller* hose) |
| 143 | { |
| 144 | struct pci_controller **phose = &hose_head; |
| 145 | |
| 146 | while(*phose) |
| 147 | phose = &(*phose)->next; |
| 148 | |
| 149 | hose->next = NULL; |
| 150 | |
| 151 | *phose = hose; |
| 152 | } |
| 153 | |
Andrew Sharp | 6870513 | 2012-08-29 14:16:29 +0000 | [diff] [blame^] | 154 | struct pci_controller *pci_bus_to_hose(int bus) |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 155 | { |
| 156 | struct pci_controller *hose; |
| 157 | |
Andrew Sharp | 6870513 | 2012-08-29 14:16:29 +0000 | [diff] [blame^] | 158 | for (hose = hose_head; hose; hose = hose->next) { |
wdenk | f4688a2 | 2003-05-28 08:06:31 +0000 | [diff] [blame] | 159 | if (bus >= hose->first_busno && bus <= hose->last_busno) |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 160 | return hose; |
Andrew Sharp | 6870513 | 2012-08-29 14:16:29 +0000 | [diff] [blame^] | 161 | } |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 162 | |
Rafal Jaworowski | 384da5e | 2005-10-17 02:39:53 +0200 | [diff] [blame] | 163 | printf("pci_bus_to_hose() failed\n"); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 164 | return NULL; |
| 165 | } |
| 166 | |
Kumar Gala | db943ed | 2010-12-17 05:57:25 -0600 | [diff] [blame] | 167 | struct pci_controller *find_hose_by_cfg_addr(void *cfg_addr) |
| 168 | { |
| 169 | struct pci_controller *hose; |
| 170 | |
| 171 | for (hose = hose_head; hose; hose = hose->next) { |
| 172 | if (hose->cfg_addr == cfg_addr) |
| 173 | return hose; |
| 174 | } |
| 175 | |
| 176 | return NULL; |
| 177 | } |
| 178 | |
Anton Vorontsov | 597b8c4 | 2009-02-19 18:20:41 +0300 | [diff] [blame] | 179 | int pci_last_busno(void) |
| 180 | { |
| 181 | struct pci_controller *hose = hose_head; |
| 182 | |
| 183 | if (!hose) |
| 184 | return -1; |
| 185 | |
| 186 | while (hose->next) |
| 187 | hose = hose->next; |
| 188 | |
| 189 | return hose->last_busno; |
| 190 | } |
| 191 | |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 192 | pci_dev_t pci_find_devices(struct pci_device_id *ids, int index) |
| 193 | { |
| 194 | struct pci_controller * hose; |
| 195 | u16 vendor, device; |
| 196 | u8 header_type; |
| 197 | pci_dev_t bdf; |
| 198 | int i, bus, found_multi = 0; |
| 199 | |
Andrew Sharp | 6870513 | 2012-08-29 14:16:29 +0000 | [diff] [blame^] | 200 | for (hose = hose_head; hose; hose = hose->next) { |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 201 | #ifdef CONFIG_SYS_SCSI_SCAN_BUS_REVERSE |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 202 | for (bus = hose->last_busno; bus >= hose->first_busno; bus--) |
| 203 | #else |
| 204 | for (bus = hose->first_busno; bus <= hose->last_busno; bus++) |
| 205 | #endif |
Andrew Sharp | 6870513 | 2012-08-29 14:16:29 +0000 | [diff] [blame^] | 206 | for (bdf = PCI_BDF(bus, 0, 0); |
Heiko Schocher | d7f77fb | 2006-06-19 11:02:41 +0200 | [diff] [blame] | 207 | #if defined(CONFIG_ELPPC) || defined(CONFIG_PPMC7XX) |
Andrew Sharp | 6870513 | 2012-08-29 14:16:29 +0000 | [diff] [blame^] | 208 | bdf < PCI_BDF(bus, PCI_MAX_PCI_DEVICES - 1, |
| 209 | PCI_MAX_PCI_FUNCTIONS - 1); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 210 | #else |
Andrew Sharp | 6870513 | 2012-08-29 14:16:29 +0000 | [diff] [blame^] | 211 | bdf < PCI_BDF(bus + 1, 0, 0); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 212 | #endif |
Andrew Sharp | 6870513 | 2012-08-29 14:16:29 +0000 | [diff] [blame^] | 213 | bdf += PCI_BDF(0, 0, 1)) { |
wdenk | f4688a2 | 2003-05-28 08:06:31 +0000 | [diff] [blame] | 214 | if (!PCI_FUNC(bdf)) { |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 215 | pci_read_config_byte(bdf, |
| 216 | PCI_HEADER_TYPE, |
| 217 | &header_type); |
| 218 | |
| 219 | found_multi = header_type & 0x80; |
wdenk | f4688a2 | 2003-05-28 08:06:31 +0000 | [diff] [blame] | 220 | } else { |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 221 | if (!found_multi) |
| 222 | continue; |
| 223 | } |
| 224 | |
| 225 | pci_read_config_word(bdf, |
| 226 | PCI_VENDOR_ID, |
| 227 | &vendor); |
| 228 | pci_read_config_word(bdf, |
| 229 | PCI_DEVICE_ID, |
| 230 | &device); |
| 231 | |
Andrew Sharp | 6870513 | 2012-08-29 14:16:29 +0000 | [diff] [blame^] | 232 | for (i = 0; ids[i].vendor != 0; i++) { |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 233 | if (vendor == ids[i].vendor && |
Andrew Sharp | 6870513 | 2012-08-29 14:16:29 +0000 | [diff] [blame^] | 234 | device == ids[i].device) { |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 235 | if (index <= 0) |
| 236 | return bdf; |
| 237 | |
| 238 | index--; |
| 239 | } |
Andrew Sharp | 6870513 | 2012-08-29 14:16:29 +0000 | [diff] [blame^] | 240 | } |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 241 | } |
| 242 | } |
| 243 | |
Andrew Sharp | 6870513 | 2012-08-29 14:16:29 +0000 | [diff] [blame^] | 244 | return -1; |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 245 | } |
| 246 | |
| 247 | pci_dev_t pci_find_device(unsigned int vendor, unsigned int device, int index) |
| 248 | { |
| 249 | static struct pci_device_id ids[2] = {{}, {0, 0}}; |
| 250 | |
| 251 | ids[0].vendor = vendor; |
| 252 | ids[0].device = device; |
| 253 | |
| 254 | return pci_find_devices(ids, index); |
| 255 | } |
| 256 | |
| 257 | /* |
| 258 | * |
| 259 | */ |
| 260 | |
Andrew Sharp | 6870513 | 2012-08-29 14:16:29 +0000 | [diff] [blame^] | 261 | int __pci_hose_phys_to_bus(struct pci_controller *hose, |
Kumar Gala | deb55f2 | 2009-02-06 09:49:32 -0600 | [diff] [blame] | 262 | phys_addr_t phys_addr, |
| 263 | unsigned long flags, |
| 264 | unsigned long skip_mask, |
| 265 | pci_addr_t *ba) |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 266 | { |
| 267 | struct pci_region *res; |
Kumar Gala | ad714f5 | 2008-10-21 08:36:08 -0500 | [diff] [blame] | 268 | pci_addr_t bus_addr; |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 269 | int i; |
| 270 | |
wdenk | f4688a2 | 2003-05-28 08:06:31 +0000 | [diff] [blame] | 271 | for (i = 0; i < hose->region_count; i++) { |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 272 | res = &hose->regions[i]; |
| 273 | |
| 274 | if (((res->flags ^ flags) & PCI_REGION_TYPE) != 0) |
| 275 | continue; |
| 276 | |
Kumar Gala | deb55f2 | 2009-02-06 09:49:32 -0600 | [diff] [blame] | 277 | if (res->flags & skip_mask) |
| 278 | continue; |
| 279 | |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 280 | bus_addr = phys_addr - res->phys_start + res->bus_start; |
| 281 | |
| 282 | if (bus_addr >= res->bus_start && |
wdenk | f4688a2 | 2003-05-28 08:06:31 +0000 | [diff] [blame] | 283 | bus_addr < res->bus_start + res->size) { |
Kumar Gala | deb55f2 | 2009-02-06 09:49:32 -0600 | [diff] [blame] | 284 | *ba = bus_addr; |
| 285 | return 0; |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 286 | } |
| 287 | } |
| 288 | |
Kumar Gala | deb55f2 | 2009-02-06 09:49:32 -0600 | [diff] [blame] | 289 | return 1; |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 290 | } |
| 291 | |
Kumar Gala | deb55f2 | 2009-02-06 09:49:32 -0600 | [diff] [blame] | 292 | pci_addr_t pci_hose_phys_to_bus (struct pci_controller *hose, |
| 293 | phys_addr_t phys_addr, |
| 294 | unsigned long flags) |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 295 | { |
Kumar Gala | deb55f2 | 2009-02-06 09:49:32 -0600 | [diff] [blame] | 296 | pci_addr_t bus_addr = 0; |
| 297 | int ret; |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 298 | |
wdenk | f4688a2 | 2003-05-28 08:06:31 +0000 | [diff] [blame] | 299 | if (!hose) { |
Andrew Sharp | 6870513 | 2012-08-29 14:16:29 +0000 | [diff] [blame^] | 300 | puts("pci_hose_phys_to_bus: invalid hose\n"); |
Kumar Gala | deb55f2 | 2009-02-06 09:49:32 -0600 | [diff] [blame] | 301 | return bus_addr; |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 302 | } |
| 303 | |
Andrew Sharp | 6870513 | 2012-08-29 14:16:29 +0000 | [diff] [blame^] | 304 | /* |
| 305 | * if PCI_REGION_MEM is set we do a two pass search with preference |
| 306 | * on matches that don't have PCI_REGION_SYS_MEMORY set |
| 307 | */ |
Kumar Gala | deb55f2 | 2009-02-06 09:49:32 -0600 | [diff] [blame] | 308 | if ((flags & PCI_REGION_MEM) == PCI_REGION_MEM) { |
| 309 | ret = __pci_hose_phys_to_bus(hose, phys_addr, |
| 310 | flags, PCI_REGION_SYS_MEMORY, &bus_addr); |
| 311 | if (!ret) |
| 312 | return bus_addr; |
| 313 | } |
| 314 | |
| 315 | ret = __pci_hose_phys_to_bus(hose, phys_addr, flags, 0, &bus_addr); |
| 316 | |
| 317 | if (ret) |
Andrew Sharp | 6870513 | 2012-08-29 14:16:29 +0000 | [diff] [blame^] | 318 | puts("pci_hose_phys_to_bus: invalid physical address\n"); |
Kumar Gala | deb55f2 | 2009-02-06 09:49:32 -0600 | [diff] [blame] | 319 | |
| 320 | return bus_addr; |
| 321 | } |
| 322 | |
Andrew Sharp | 6870513 | 2012-08-29 14:16:29 +0000 | [diff] [blame^] | 323 | int __pci_hose_bus_to_phys(struct pci_controller *hose, |
Kumar Gala | deb55f2 | 2009-02-06 09:49:32 -0600 | [diff] [blame] | 324 | pci_addr_t bus_addr, |
| 325 | unsigned long flags, |
| 326 | unsigned long skip_mask, |
| 327 | phys_addr_t *pa) |
| 328 | { |
| 329 | struct pci_region *res; |
| 330 | int i; |
| 331 | |
wdenk | f4688a2 | 2003-05-28 08:06:31 +0000 | [diff] [blame] | 332 | for (i = 0; i < hose->region_count; i++) { |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 333 | res = &hose->regions[i]; |
| 334 | |
| 335 | if (((res->flags ^ flags) & PCI_REGION_TYPE) != 0) |
| 336 | continue; |
| 337 | |
Kumar Gala | deb55f2 | 2009-02-06 09:49:32 -0600 | [diff] [blame] | 338 | if (res->flags & skip_mask) |
| 339 | continue; |
| 340 | |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 341 | if (bus_addr >= res->bus_start && |
wdenk | f4688a2 | 2003-05-28 08:06:31 +0000 | [diff] [blame] | 342 | bus_addr < res->bus_start + res->size) { |
Kumar Gala | deb55f2 | 2009-02-06 09:49:32 -0600 | [diff] [blame] | 343 | *pa = (bus_addr - res->bus_start + res->phys_start); |
| 344 | return 0; |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 345 | } |
| 346 | } |
| 347 | |
Kumar Gala | deb55f2 | 2009-02-06 09:49:32 -0600 | [diff] [blame] | 348 | return 1; |
| 349 | } |
| 350 | |
| 351 | phys_addr_t pci_hose_bus_to_phys(struct pci_controller* hose, |
| 352 | pci_addr_t bus_addr, |
| 353 | unsigned long flags) |
| 354 | { |
| 355 | phys_addr_t phys_addr = 0; |
| 356 | int ret; |
| 357 | |
| 358 | if (!hose) { |
Andrew Sharp | 6870513 | 2012-08-29 14:16:29 +0000 | [diff] [blame^] | 359 | puts("pci_hose_bus_to_phys: invalid hose\n"); |
Kumar Gala | deb55f2 | 2009-02-06 09:49:32 -0600 | [diff] [blame] | 360 | return phys_addr; |
| 361 | } |
| 362 | |
Andrew Sharp | 6870513 | 2012-08-29 14:16:29 +0000 | [diff] [blame^] | 363 | /* |
| 364 | * if PCI_REGION_MEM is set we do a two pass search with preference |
| 365 | * on matches that don't have PCI_REGION_SYS_MEMORY set |
| 366 | */ |
Kumar Gala | deb55f2 | 2009-02-06 09:49:32 -0600 | [diff] [blame] | 367 | if ((flags & PCI_REGION_MEM) == PCI_REGION_MEM) { |
| 368 | ret = __pci_hose_bus_to_phys(hose, bus_addr, |
| 369 | flags, PCI_REGION_SYS_MEMORY, &phys_addr); |
| 370 | if (!ret) |
| 371 | return phys_addr; |
| 372 | } |
| 373 | |
| 374 | ret = __pci_hose_bus_to_phys(hose, bus_addr, flags, 0, &phys_addr); |
| 375 | |
| 376 | if (ret) |
Andrew Sharp | 6870513 | 2012-08-29 14:16:29 +0000 | [diff] [blame^] | 377 | puts("pci_hose_bus_to_phys: invalid physical address\n"); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 378 | |
Kumar Gala | deb55f2 | 2009-02-06 09:49:32 -0600 | [diff] [blame] | 379 | return phys_addr; |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 380 | } |
| 381 | |
| 382 | /* |
| 383 | * |
| 384 | */ |
| 385 | |
| 386 | int pci_hose_config_device(struct pci_controller *hose, |
| 387 | pci_dev_t dev, |
| 388 | unsigned long io, |
Kumar Gala | ad714f5 | 2008-10-21 08:36:08 -0500 | [diff] [blame] | 389 | pci_addr_t mem, |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 390 | unsigned long command) |
| 391 | { |
Andrew Sharp | f4f2482 | 2012-08-01 12:27:16 +0000 | [diff] [blame] | 392 | pci_addr_t bar_response; |
| 393 | unsigned int old_command; |
Kumar Gala | ad714f5 | 2008-10-21 08:36:08 -0500 | [diff] [blame] | 394 | pci_addr_t bar_value; |
| 395 | pci_size_t bar_size; |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 396 | unsigned char pin; |
| 397 | int bar, found_mem64; |
| 398 | |
Andrew Sharp | 6870513 | 2012-08-29 14:16:29 +0000 | [diff] [blame^] | 399 | debug("PCI Config: I/O=0x%lx, Memory=0x%llx, Command=0x%lx\n", io, |
| 400 | (u64)mem, command); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 401 | |
Andrew Sharp | 6870513 | 2012-08-29 14:16:29 +0000 | [diff] [blame^] | 402 | pci_hose_write_config_dword(hose, dev, PCI_COMMAND, 0); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 403 | |
Wolfgang Denk | 03bebef | 2010-03-09 14:27:25 +0100 | [diff] [blame] | 404 | for (bar = PCI_BASE_ADDRESS_0; bar <= PCI_BASE_ADDRESS_5; bar += 4) { |
Andrew Sharp | 6870513 | 2012-08-29 14:16:29 +0000 | [diff] [blame^] | 405 | pci_hose_write_config_dword(hose, dev, bar, 0xffffffff); |
| 406 | pci_hose_read_config_dword(hose, dev, bar, &bar_response); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 407 | |
| 408 | if (!bar_response) |
| 409 | continue; |
| 410 | |
| 411 | found_mem64 = 0; |
| 412 | |
| 413 | /* Check the BAR type and set our address mask */ |
wdenk | f4688a2 | 2003-05-28 08:06:31 +0000 | [diff] [blame] | 414 | if (bar_response & PCI_BASE_ADDRESS_SPACE) { |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 415 | bar_size = ~(bar_response & PCI_BASE_ADDRESS_IO_MASK) + 1; |
wdenk | f4688a2 | 2003-05-28 08:06:31 +0000 | [diff] [blame] | 416 | /* round up region base address to a multiple of size */ |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 417 | io = ((io - 1) | (bar_size - 1)) + 1; |
wdenk | f4688a2 | 2003-05-28 08:06:31 +0000 | [diff] [blame] | 418 | bar_value = io; |
| 419 | /* compute new region base address */ |
| 420 | io = io + bar_size; |
| 421 | } else { |
| 422 | if ((bar_response & PCI_BASE_ADDRESS_MEM_TYPE_MASK) == |
Kumar Gala | ad714f5 | 2008-10-21 08:36:08 -0500 | [diff] [blame] | 423 | PCI_BASE_ADDRESS_MEM_TYPE_64) { |
| 424 | u32 bar_response_upper; |
| 425 | u64 bar64; |
Andrew Sharp | 6870513 | 2012-08-29 14:16:29 +0000 | [diff] [blame^] | 426 | pci_hose_write_config_dword(hose, dev, bar + 4, |
| 427 | 0xffffffff); |
| 428 | pci_hose_read_config_dword(hose, dev, bar + 4, |
| 429 | &bar_response_upper); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 430 | |
Kumar Gala | ad714f5 | 2008-10-21 08:36:08 -0500 | [diff] [blame] | 431 | bar64 = ((u64)bar_response_upper << 32) | bar_response; |
| 432 | |
| 433 | bar_size = ~(bar64 & PCI_BASE_ADDRESS_MEM_MASK) + 1; |
| 434 | found_mem64 = 1; |
| 435 | } else { |
| 436 | bar_size = (u32)(~(bar_response & PCI_BASE_ADDRESS_MEM_MASK) + 1); |
| 437 | } |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 438 | |
wdenk | f4688a2 | 2003-05-28 08:06:31 +0000 | [diff] [blame] | 439 | /* round up region base address to multiple of size */ |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 440 | mem = ((mem - 1) | (bar_size - 1)) + 1; |
wdenk | f4688a2 | 2003-05-28 08:06:31 +0000 | [diff] [blame] | 441 | bar_value = mem; |
| 442 | /* compute new region base address */ |
| 443 | mem = mem + bar_size; |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 444 | } |
| 445 | |
| 446 | /* Write it out and update our limit */ |
Kumar Gala | ad714f5 | 2008-10-21 08:36:08 -0500 | [diff] [blame] | 447 | pci_hose_write_config_dword (hose, dev, bar, (u32)bar_value); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 448 | |
wdenk | f4688a2 | 2003-05-28 08:06:31 +0000 | [diff] [blame] | 449 | if (found_mem64) { |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 450 | bar += 4; |
Kumar Gala | ad714f5 | 2008-10-21 08:36:08 -0500 | [diff] [blame] | 451 | #ifdef CONFIG_SYS_PCI_64BIT |
Andrew Sharp | 6870513 | 2012-08-29 14:16:29 +0000 | [diff] [blame^] | 452 | pci_hose_write_config_dword(hose, dev, bar, |
| 453 | (u32)(bar_value >> 32)); |
Kumar Gala | ad714f5 | 2008-10-21 08:36:08 -0500 | [diff] [blame] | 454 | #else |
Andrew Sharp | 6870513 | 2012-08-29 14:16:29 +0000 | [diff] [blame^] | 455 | pci_hose_write_config_dword(hose, dev, bar, 0x00000000); |
Kumar Gala | ad714f5 | 2008-10-21 08:36:08 -0500 | [diff] [blame] | 456 | #endif |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 457 | } |
| 458 | } |
| 459 | |
| 460 | /* Configure Cache Line Size Register */ |
Andrew Sharp | 6870513 | 2012-08-29 14:16:29 +0000 | [diff] [blame^] | 461 | pci_hose_write_config_byte(hose, dev, PCI_CACHE_LINE_SIZE, 0x08); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 462 | |
| 463 | /* Configure Latency Timer */ |
Andrew Sharp | 6870513 | 2012-08-29 14:16:29 +0000 | [diff] [blame^] | 464 | pci_hose_write_config_byte(hose, dev, PCI_LATENCY_TIMER, 0x80); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 465 | |
| 466 | /* Disable interrupt line, if device says it wants to use interrupts */ |
Andrew Sharp | 6870513 | 2012-08-29 14:16:29 +0000 | [diff] [blame^] | 467 | pci_hose_read_config_byte(hose, dev, PCI_INTERRUPT_PIN, &pin); |
wdenk | f4688a2 | 2003-05-28 08:06:31 +0000 | [diff] [blame] | 468 | if (pin != 0) { |
Andrew Sharp | 6870513 | 2012-08-29 14:16:29 +0000 | [diff] [blame^] | 469 | pci_hose_write_config_byte(hose, dev, PCI_INTERRUPT_LINE, 0xff); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 470 | } |
| 471 | |
Andrew Sharp | 6870513 | 2012-08-29 14:16:29 +0000 | [diff] [blame^] | 472 | pci_hose_read_config_dword(hose, dev, PCI_COMMAND, &old_command); |
| 473 | pci_hose_write_config_dword(hose, dev, PCI_COMMAND, |
wdenk | f4688a2 | 2003-05-28 08:06:31 +0000 | [diff] [blame] | 474 | (old_command & 0xffff0000) | command); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 475 | |
| 476 | return 0; |
| 477 | } |
| 478 | |
| 479 | /* |
| 480 | * |
| 481 | */ |
| 482 | |
| 483 | struct pci_config_table *pci_find_config(struct pci_controller *hose, |
| 484 | unsigned short class, |
| 485 | unsigned int vendor, |
| 486 | unsigned int device, |
| 487 | unsigned int bus, |
| 488 | unsigned int dev, |
| 489 | unsigned int func) |
| 490 | { |
| 491 | struct pci_config_table *table; |
| 492 | |
wdenk | f4688a2 | 2003-05-28 08:06:31 +0000 | [diff] [blame] | 493 | for (table = hose->config_table; table && table->vendor; table++) { |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 494 | if ((table->vendor == PCI_ANY_ID || table->vendor == vendor) && |
| 495 | (table->device == PCI_ANY_ID || table->device == device) && |
| 496 | (table->class == PCI_ANY_ID || table->class == class) && |
| 497 | (table->bus == PCI_ANY_ID || table->bus == bus) && |
| 498 | (table->dev == PCI_ANY_ID || table->dev == dev) && |
wdenk | f4688a2 | 2003-05-28 08:06:31 +0000 | [diff] [blame] | 499 | (table->func == PCI_ANY_ID || table->func == func)) { |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 500 | return table; |
| 501 | } |
| 502 | } |
| 503 | |
| 504 | return NULL; |
| 505 | } |
| 506 | |
| 507 | void pci_cfgfunc_config_device(struct pci_controller *hose, |
| 508 | pci_dev_t dev, |
| 509 | struct pci_config_table *entry) |
| 510 | { |
Andrew Sharp | 6870513 | 2012-08-29 14:16:29 +0000 | [diff] [blame^] | 511 | pci_hose_config_device(hose, dev, entry->priv[0], entry->priv[1], |
| 512 | entry->priv[2]); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 513 | } |
| 514 | |
| 515 | void pci_cfgfunc_do_nothing(struct pci_controller *hose, |
| 516 | pci_dev_t dev, struct pci_config_table *entry) |
| 517 | { |
| 518 | } |
| 519 | |
| 520 | /* |
Andrew Sharp | 6870513 | 2012-08-29 14:16:29 +0000 | [diff] [blame^] | 521 | * HJF: Changed this to return int. I think this is required |
wdenk | 452cfd6 | 2002-11-19 11:04:11 +0000 | [diff] [blame] | 522 | * to get the correct result when scanning bridges |
| 523 | */ |
| 524 | extern int pciauto_config_device(struct pci_controller *hose, pci_dev_t dev); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 525 | |
Peter Tyser | 22ccb7f | 2010-10-29 17:59:27 -0500 | [diff] [blame] | 526 | #if defined(CONFIG_CMD_PCI) || defined(CONFIG_PCI_SCAN_SHOW) |
| 527 | const char * pci_class_str(u8 class) |
| 528 | { |
| 529 | switch (class) { |
| 530 | case PCI_CLASS_NOT_DEFINED: |
| 531 | return "Build before PCI Rev2.0"; |
| 532 | break; |
| 533 | case PCI_BASE_CLASS_STORAGE: |
| 534 | return "Mass storage controller"; |
| 535 | break; |
| 536 | case PCI_BASE_CLASS_NETWORK: |
| 537 | return "Network controller"; |
| 538 | break; |
| 539 | case PCI_BASE_CLASS_DISPLAY: |
| 540 | return "Display controller"; |
| 541 | break; |
| 542 | case PCI_BASE_CLASS_MULTIMEDIA: |
| 543 | return "Multimedia device"; |
| 544 | break; |
| 545 | case PCI_BASE_CLASS_MEMORY: |
| 546 | return "Memory controller"; |
| 547 | break; |
| 548 | case PCI_BASE_CLASS_BRIDGE: |
| 549 | return "Bridge device"; |
| 550 | break; |
| 551 | case PCI_BASE_CLASS_COMMUNICATION: |
| 552 | return "Simple comm. controller"; |
| 553 | break; |
| 554 | case PCI_BASE_CLASS_SYSTEM: |
| 555 | return "Base system peripheral"; |
| 556 | break; |
| 557 | case PCI_BASE_CLASS_INPUT: |
| 558 | return "Input device"; |
| 559 | break; |
| 560 | case PCI_BASE_CLASS_DOCKING: |
| 561 | return "Docking station"; |
| 562 | break; |
| 563 | case PCI_BASE_CLASS_PROCESSOR: |
| 564 | return "Processor"; |
| 565 | break; |
| 566 | case PCI_BASE_CLASS_SERIAL: |
| 567 | return "Serial bus controller"; |
| 568 | break; |
| 569 | case PCI_BASE_CLASS_INTELLIGENT: |
| 570 | return "Intelligent controller"; |
| 571 | break; |
| 572 | case PCI_BASE_CLASS_SATELLITE: |
| 573 | return "Satellite controller"; |
| 574 | break; |
| 575 | case PCI_BASE_CLASS_CRYPT: |
| 576 | return "Cryptographic device"; |
| 577 | break; |
| 578 | case PCI_BASE_CLASS_SIGNAL_PROCESSING: |
| 579 | return "DSP"; |
| 580 | break; |
| 581 | case PCI_CLASS_OTHERS: |
| 582 | return "Does not fit any class"; |
| 583 | break; |
| 584 | default: |
| 585 | return "???"; |
| 586 | break; |
| 587 | }; |
| 588 | } |
| 589 | #endif /* CONFIG_CMD_PCI || CONFIG_PCI_SCAN_SHOW */ |
| 590 | |
Stefan Roese | 41e846f | 2008-07-08 12:01:47 +0200 | [diff] [blame] | 591 | int __pci_skip_dev(struct pci_controller *hose, pci_dev_t dev) |
| 592 | { |
| 593 | /* |
| 594 | * Check if pci device should be skipped in configuration |
| 595 | */ |
| 596 | if (dev == PCI_BDF(hose->first_busno, 0, 0)) { |
| 597 | #if defined(CONFIG_PCI_CONFIG_HOST_BRIDGE) /* don't skip host bridge */ |
| 598 | /* |
| 599 | * Only skip configuration if "pciconfighost" is not set |
| 600 | */ |
| 601 | if (getenv("pciconfighost") == NULL) |
| 602 | return 1; |
| 603 | #else |
| 604 | return 1; |
| 605 | #endif |
| 606 | } |
| 607 | |
| 608 | return 0; |
| 609 | } |
| 610 | int pci_skip_dev(struct pci_controller *hose, pci_dev_t dev) |
| 611 | __attribute__((weak, alias("__pci_skip_dev"))); |
| 612 | |
| 613 | #ifdef CONFIG_PCI_SCAN_SHOW |
| 614 | int __pci_print_dev(struct pci_controller *hose, pci_dev_t dev) |
| 615 | { |
| 616 | if (dev == PCI_BDF(hose->first_busno, 0, 0)) |
| 617 | return 0; |
| 618 | |
| 619 | return 1; |
| 620 | } |
| 621 | int pci_print_dev(struct pci_controller *hose, pci_dev_t dev) |
| 622 | __attribute__((weak, alias("__pci_print_dev"))); |
| 623 | #endif /* CONFIG_PCI_SCAN_SHOW */ |
| 624 | |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 625 | int pci_hose_scan_bus(struct pci_controller *hose, int bus) |
| 626 | { |
Andrew Sharp | 6870513 | 2012-08-29 14:16:29 +0000 | [diff] [blame^] | 627 | unsigned int sub_bus, found_multi = 0; |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 628 | unsigned short vendor, device, class; |
| 629 | unsigned char header_type; |
| 630 | struct pci_config_table *cfg; |
| 631 | pci_dev_t dev; |
Peter Tyser | b46513d | 2010-10-29 17:59:29 -0500 | [diff] [blame] | 632 | #ifdef CONFIG_PCI_SCAN_SHOW |
| 633 | static int indent = 0; |
| 634 | #endif |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 635 | |
| 636 | sub_bus = bus; |
| 637 | |
| 638 | for (dev = PCI_BDF(bus,0,0); |
Andrew Sharp | 6870513 | 2012-08-29 14:16:29 +0000 | [diff] [blame^] | 639 | dev < PCI_BDF(bus, PCI_MAX_PCI_DEVICES - 1, |
| 640 | PCI_MAX_PCI_FUNCTIONS - 1); |
| 641 | dev += PCI_BDF(0, 0, 1)) { |
Stefan Roese | 41e846f | 2008-07-08 12:01:47 +0200 | [diff] [blame] | 642 | |
| 643 | if (pci_skip_dev(hose, dev)) |
| 644 | continue; |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 645 | |
| 646 | if (PCI_FUNC(dev) && !found_multi) |
| 647 | continue; |
| 648 | |
| 649 | pci_hose_read_config_byte(hose, dev, PCI_HEADER_TYPE, &header_type); |
| 650 | |
| 651 | pci_hose_read_config_word(hose, dev, PCI_VENDOR_ID, &vendor); |
| 652 | |
Peter Tyser | 22ccb7f | 2010-10-29 17:59:27 -0500 | [diff] [blame] | 653 | if (vendor == 0xffff || vendor == 0x0000) |
| 654 | continue; |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 655 | |
Peter Tyser | 22ccb7f | 2010-10-29 17:59:27 -0500 | [diff] [blame] | 656 | if (!PCI_FUNC(dev)) |
| 657 | found_multi = header_type & 0x80; |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 658 | |
Andrew Sharp | 6870513 | 2012-08-29 14:16:29 +0000 | [diff] [blame^] | 659 | debug("PCI Scan: Found Bus %d, Device %d, Function %d\n", |
| 660 | PCI_BUS(dev), PCI_DEV(dev), PCI_FUNC(dev)); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 661 | |
Peter Tyser | 22ccb7f | 2010-10-29 17:59:27 -0500 | [diff] [blame] | 662 | pci_hose_read_config_word(hose, dev, PCI_DEVICE_ID, &device); |
| 663 | pci_hose_read_config_word(hose, dev, PCI_CLASS_DEVICE, &class); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 664 | |
Peter Tyser | d40cdc4 | 2010-10-29 17:59:28 -0500 | [diff] [blame] | 665 | #ifdef CONFIG_PCI_SCAN_SHOW |
Peter Tyser | b46513d | 2010-10-29 17:59:29 -0500 | [diff] [blame] | 666 | indent++; |
| 667 | |
| 668 | /* Print leading space, including bus indentation */ |
| 669 | printf("%*c", indent + 1, ' '); |
| 670 | |
Peter Tyser | d40cdc4 | 2010-10-29 17:59:28 -0500 | [diff] [blame] | 671 | if (pci_print_dev(hose, dev)) { |
Peter Tyser | b46513d | 2010-10-29 17:59:29 -0500 | [diff] [blame] | 672 | printf("%02x:%02x.%-*x - %04x:%04x - %s\n", |
| 673 | PCI_BUS(dev), PCI_DEV(dev), 6 - indent, PCI_FUNC(dev), |
Peter Tyser | d40cdc4 | 2010-10-29 17:59:28 -0500 | [diff] [blame] | 674 | vendor, device, pci_class_str(class >> 8)); |
| 675 | } |
| 676 | #endif |
| 677 | |
Peter Tyser | 22ccb7f | 2010-10-29 17:59:27 -0500 | [diff] [blame] | 678 | cfg = pci_find_config(hose, class, vendor, device, |
| 679 | PCI_BUS(dev), PCI_DEV(dev), PCI_FUNC(dev)); |
| 680 | if (cfg) { |
| 681 | cfg->config_device(hose, dev, cfg); |
| 682 | sub_bus = max(sub_bus, hose->current_busno); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 683 | #ifdef CONFIG_PCI_PNP |
Peter Tyser | 22ccb7f | 2010-10-29 17:59:27 -0500 | [diff] [blame] | 684 | } else { |
| 685 | int n = pciauto_config_device(hose, dev); |
wdenk | 452cfd6 | 2002-11-19 11:04:11 +0000 | [diff] [blame] | 686 | |
Peter Tyser | 22ccb7f | 2010-10-29 17:59:27 -0500 | [diff] [blame] | 687 | sub_bus = max(sub_bus, n); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 688 | #endif |
Peter Tyser | 22ccb7f | 2010-10-29 17:59:27 -0500 | [diff] [blame] | 689 | } |
Peter Tyser | d40cdc4 | 2010-10-29 17:59:28 -0500 | [diff] [blame] | 690 | |
Peter Tyser | b46513d | 2010-10-29 17:59:29 -0500 | [diff] [blame] | 691 | #ifdef CONFIG_PCI_SCAN_SHOW |
| 692 | indent--; |
| 693 | #endif |
| 694 | |
Peter Tyser | 22ccb7f | 2010-10-29 17:59:27 -0500 | [diff] [blame] | 695 | if (hose->fixup_irq) |
| 696 | hose->fixup_irq(hose, dev); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 697 | } |
| 698 | |
| 699 | return sub_bus; |
| 700 | } |
| 701 | |
| 702 | int pci_hose_scan(struct pci_controller *hose) |
| 703 | { |
Anatolij Gustschin | 2bd2cb1 | 2011-10-11 22:44:30 +0000 | [diff] [blame] | 704 | #if defined(CONFIG_PCI_BOOTDELAY) |
| 705 | static int pcidelay_done; |
| 706 | char *s; |
| 707 | int i; |
| 708 | |
| 709 | if (!pcidelay_done) { |
| 710 | /* wait "pcidelay" ms (if defined)... */ |
| 711 | s = getenv("pcidelay"); |
| 712 | if (s) { |
| 713 | int val = simple_strtoul(s, NULL, 10); |
| 714 | for (i = 0; i < val; i++) |
| 715 | udelay(1000); |
| 716 | } |
| 717 | pcidelay_done = 1; |
| 718 | } |
| 719 | #endif /* CONFIG_PCI_BOOTDELAY */ |
| 720 | |
Andrew Sharp | 6870513 | 2012-08-29 14:16:29 +0000 | [diff] [blame^] | 721 | /* |
| 722 | * Start scan at current_busno. |
Ed Swarthout | f0d4347 | 2007-07-11 14:51:35 -0500 | [diff] [blame] | 723 | * PCIe will start scan at first_busno+1. |
| 724 | */ |
Andrew Sharp | 6870513 | 2012-08-29 14:16:29 +0000 | [diff] [blame^] | 725 | /* For legacy support, ensure current >= first */ |
Ed Swarthout | f0d4347 | 2007-07-11 14:51:35 -0500 | [diff] [blame] | 726 | if (hose->first_busno > hose->current_busno) |
| 727 | hose->current_busno = hose->first_busno; |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 728 | #ifdef CONFIG_PCI_PNP |
| 729 | pciauto_config_init(hose); |
| 730 | #endif |
Ed Swarthout | f0d4347 | 2007-07-11 14:51:35 -0500 | [diff] [blame] | 731 | return pci_hose_scan_bus(hose, hose->current_busno); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 732 | } |
| 733 | |
stroese | f5dd410 | 2003-02-14 11:21:23 +0000 | [diff] [blame] | 734 | void pci_init(void) |
| 735 | { |
John Schmoller | 60e877f | 2010-10-22 00:20:23 -0500 | [diff] [blame] | 736 | hose_head = NULL; |
| 737 | |
stroese | f5dd410 | 2003-02-14 11:21:23 +0000 | [diff] [blame] | 738 | /* now call board specific pci_init()... */ |
| 739 | pci_init_board(); |
| 740 | } |