blob: cd78030cd6354aa816dc08dd5da608f03b7be9ab [file] [log] [blame]
wdenkc6097192002-11-03 00:24:07 +00001/*
Stefan Roesea47a12b2010-04-15 16:07:28 +02002 * arch/powerpc/kernel/pci_auto.c
wdenkc6097192002-11-03 00:24:07 +00003 *
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
wdenkc6097192002-11-03 00:24:07 +000018#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-VILLARD6d0f6bc2008-10-16 15:01:15 +020029/* 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 Jennejohn81b73de2007-08-31 15:21:46 +020032#endif
33
wdenkc6097192002-11-03 00:24:07 +000034/*
35 *
36 */
37
Andrew Sharpcb2bf932012-08-29 14:16:29 +000038void pciauto_region_init(struct pci_region *res)
wdenkc6097192002-11-03 00:24:07 +000039{
Sergei Shtylyovb7598a42007-04-23 15:30:39 +020040 /*
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;
wdenkc6097192002-11-03 00:24:07 +000046}
47
Kumar Gala30e76d52008-10-21 08:36:08 -050048void pciauto_region_align(struct pci_region *res, pci_size_t size)
wdenkc6097192002-11-03 00:24:07 +000049{
50 res->bus_lower = ((res->bus_lower - 1) | (size - 1)) + 1;
51}
52
Andrew Sharpcb2bf932012-08-29 14:16:29 +000053int pciauto_region_allocate(struct pci_region *res, pci_size_t size,
54 pci_addr_t *bar)
wdenkc6097192002-11-03 00:24:07 +000055{
Kumar Gala30e76d52008-10-21 08:36:08 -050056 pci_addr_t addr;
wdenkc6097192002-11-03 00:24:07 +000057
wdenk3c74e322004-02-22 23:46:08 +000058 if (!res) {
wdenkc6097192002-11-03 00:24:07 +000059 DEBUGF("No resource");
60 goto error;
61 }
62
63 addr = ((res->bus_lower - 1) | (size - 1)) + 1;
64
wdenk3c74e322004-02-22 23:46:08 +000065 if (addr - res->bus_start + size > res->size) {
wdenkc6097192002-11-03 00:24:07 +000066 DEBUGF("No room in resource");
67 goto error;
68 }
69
70 res->bus_lower = addr + size;
71
Kumar Gala30e76d52008-10-21 08:36:08 -050072 DEBUGF("address=0x%llx bus_lower=0x%llx", (u64)addr, (u64)res->bus_lower);
wdenkc6097192002-11-03 00:24:07 +000073
74 *bar = addr;
75 return 0;
76
77 error:
Kumar Gala30e76d52008-10-21 08:36:08 -050078 *bar = (pci_addr_t)-1;
wdenkc6097192002-11-03 00:24:07 +000079 return -1;
80}
81
82/*
83 *
84 */
85
86void pciauto_setup_device(struct pci_controller *hose,
87 pci_dev_t dev, int bars_num,
88 struct pci_region *mem,
Kumar Galaa1790122006-01-11 13:24:15 -060089 struct pci_region *prefetch,
wdenkc6097192002-11-03 00:24:07 +000090 struct pci_region *io)
91{
Kumar Galacf5787f2012-09-19 04:47:36 +000092 u32 bar_response;
Kumar Gala30e76d52008-10-21 08:36:08 -050093 pci_size_t bar_size;
Andrew Sharpaf778c62012-08-01 12:27:16 +000094 u16 cmdstat = 0;
wdenkc6097192002-11-03 00:24:07 +000095 int bar, bar_nr = 0;
Andrew Sharp69fd2d32012-08-29 14:16:32 +000096#ifndef CONFIG_PCI_ENUM_ONLY
97 pci_addr_t bar_value;
98 struct pci_region *bar_res;
wdenkc6097192002-11-03 00:24:07 +000099 int found_mem64 = 0;
Andrew Sharp69fd2d32012-08-29 14:16:32 +0000100#endif
wdenkc6097192002-11-03 00:24:07 +0000101
Andrew Sharpaf778c62012-08-01 12:27:16 +0000102 pci_hose_read_config_word(hose, dev, PCI_COMMAND, &cmdstat);
wdenkc6097192002-11-03 00:24:07 +0000103 cmdstat = (cmdstat & ~(PCI_COMMAND_IO | PCI_COMMAND_MEMORY)) | PCI_COMMAND_MASTER;
104
Andrew Sharpcb2bf932012-08-29 14:16:29 +0000105 for (bar = PCI_BASE_ADDRESS_0;
106 bar < PCI_BASE_ADDRESS_0 + (bars_num * 4); bar += 4) {
wdenkc6097192002-11-03 00:24:07 +0000107 /* Tickle the BAR and get the response */
Andrew Sharp69fd2d32012-08-29 14:16:32 +0000108#ifndef CONFIG_PCI_ENUM_ONLY
wdenkc6097192002-11-03 00:24:07 +0000109 pci_hose_write_config_dword(hose, dev, bar, 0xffffffff);
Andrew Sharp69fd2d32012-08-29 14:16:32 +0000110#endif
wdenkc6097192002-11-03 00:24:07 +0000111 pci_hose_read_config_dword(hose, dev, bar, &bar_response);
112
113 /* If BAR is not implemented go to the next BAR */
114 if (!bar_response)
115 continue;
116
Andrew Sharp69fd2d32012-08-29 14:16:32 +0000117#ifndef CONFIG_PCI_ENUM_ONLY
wdenkc6097192002-11-03 00:24:07 +0000118 found_mem64 = 0;
Andrew Sharp69fd2d32012-08-29 14:16:32 +0000119#endif
wdenkc6097192002-11-03 00:24:07 +0000120
121 /* Check the BAR type and set our address mask */
wdenk3c74e322004-02-22 23:46:08 +0000122 if (bar_response & PCI_BASE_ADDRESS_SPACE) {
Jin Zhengxiong-R64188bd22c2b2006-06-27 18:12:02 +0800123 bar_size = ((~(bar_response & PCI_BASE_ADDRESS_IO_MASK))
124 & 0xffff) + 1;
Andrew Sharp69fd2d32012-08-29 14:16:32 +0000125#ifndef CONFIG_PCI_ENUM_ONLY
wdenkc6097192002-11-03 00:24:07 +0000126 bar_res = io;
Andrew Sharp69fd2d32012-08-29 14:16:32 +0000127#endif
wdenkc6097192002-11-03 00:24:07 +0000128
Kumar Gala30e76d52008-10-21 08:36:08 -0500129 DEBUGF("PCI Autoconfig: BAR %d, I/O, size=0x%llx, ", bar_nr, (u64)bar_size);
wdenk3c74e322004-02-22 23:46:08 +0000130 } else {
Andrew Sharpcb2bf932012-08-29 14:16:29 +0000131 if ((bar_response & PCI_BASE_ADDRESS_MEM_TYPE_MASK) ==
Kumar Gala30e76d52008-10-21 08:36:08 -0500132 PCI_BASE_ADDRESS_MEM_TYPE_64) {
133 u32 bar_response_upper;
134 u64 bar64;
Andrew Sharp69fd2d32012-08-29 14:16:32 +0000135
136#ifndef CONFIG_PCI_ENUM_ONLY
Andrew Sharpcb2bf932012-08-29 14:16:29 +0000137 pci_hose_write_config_dword(hose, dev, bar + 4,
138 0xffffffff);
Andrew Sharp69fd2d32012-08-29 14:16:32 +0000139#endif
Andrew Sharpcb2bf932012-08-29 14:16:29 +0000140 pci_hose_read_config_dword(hose, dev, bar + 4,
141 &bar_response_upper);
wdenkc6097192002-11-03 00:24:07 +0000142
Kumar Gala30e76d52008-10-21 08:36:08 -0500143 bar64 = ((u64)bar_response_upper << 32) | bar_response;
144
145 bar_size = ~(bar64 & PCI_BASE_ADDRESS_MEM_MASK) + 1;
Andrew Sharp69fd2d32012-08-29 14:16:32 +0000146#ifndef CONFIG_PCI_ENUM_ONLY
Kumar Gala30e76d52008-10-21 08:36:08 -0500147 found_mem64 = 1;
Andrew Sharp69fd2d32012-08-29 14:16:32 +0000148#endif
Kumar Gala30e76d52008-10-21 08:36:08 -0500149 } else {
150 bar_size = (u32)(~(bar_response & PCI_BASE_ADDRESS_MEM_MASK) + 1);
151 }
Andrew Sharp69fd2d32012-08-29 14:16:32 +0000152#ifndef CONFIG_PCI_ENUM_ONLY
Kumar Galaa1790122006-01-11 13:24:15 -0600153 if (prefetch && (bar_response & PCI_BASE_ADDRESS_MEM_PREFETCH))
154 bar_res = prefetch;
155 else
156 bar_res = mem;
Andrew Sharp69fd2d32012-08-29 14:16:32 +0000157#endif
wdenkc6097192002-11-03 00:24:07 +0000158
Kumar Gala30e76d52008-10-21 08:36:08 -0500159 DEBUGF("PCI Autoconfig: BAR %d, Mem, size=0x%llx, ", bar_nr, (u64)bar_size);
wdenkc6097192002-11-03 00:24:07 +0000160 }
161
Andrew Sharp69fd2d32012-08-29 14:16:32 +0000162#ifndef CONFIG_PCI_ENUM_ONLY
wdenk3c74e322004-02-22 23:46:08 +0000163 if (pciauto_region_allocate(bar_res, bar_size, &bar_value) == 0) {
wdenkc6097192002-11-03 00:24:07 +0000164 /* Write it out and update our limit */
Kumar Gala30e76d52008-10-21 08:36:08 -0500165 pci_hose_write_config_dword(hose, dev, bar, (u32)bar_value);
wdenkc6097192002-11-03 00:24:07 +0000166
wdenk3c74e322004-02-22 23:46:08 +0000167 if (found_mem64) {
wdenkc6097192002-11-03 00:24:07 +0000168 bar += 4;
Kumar Gala30e76d52008-10-21 08:36:08 -0500169#ifdef CONFIG_SYS_PCI_64BIT
170 pci_hose_write_config_dword(hose, dev, bar, (u32)(bar_value>>32));
171#else
172 /*
173 * If we are a 64-bit decoder then increment to the
174 * upper 32 bits of the bar and force it to locate
175 * in the lower 4GB of memory.
176 */
wdenkc6097192002-11-03 00:24:07 +0000177 pci_hose_write_config_dword(hose, dev, bar, 0x00000000);
Kumar Gala30e76d52008-10-21 08:36:08 -0500178#endif
wdenkc6097192002-11-03 00:24:07 +0000179 }
180
wdenkc6097192002-11-03 00:24:07 +0000181 }
Andrew Sharp69fd2d32012-08-29 14:16:32 +0000182#endif
183 cmdstat |= (bar_response & PCI_BASE_ADDRESS_SPACE) ?
184 PCI_COMMAND_IO : PCI_COMMAND_MEMORY;
wdenkc6097192002-11-03 00:24:07 +0000185
186 DEBUGF("\n");
187
188 bar_nr++;
189 }
190
Andrew Sharpaf778c62012-08-01 12:27:16 +0000191 pci_hose_write_config_word(hose, dev, PCI_COMMAND, cmdstat);
Gary Jennejohn81b73de2007-08-31 15:21:46 +0200192 pci_hose_write_config_byte(hose, dev, PCI_CACHE_LINE_SIZE,
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200193 CONFIG_SYS_PCI_CACHE_LINE_SIZE);
wdenkc6097192002-11-03 00:24:07 +0000194 pci_hose_write_config_byte(hose, dev, PCI_LATENCY_TIMER, 0x80);
195}
196
Ed Swarthoutba5feb12007-07-11 14:51:48 -0500197void pciauto_prescan_setup_bridge(struct pci_controller *hose,
wdenkc6097192002-11-03 00:24:07 +0000198 pci_dev_t dev, int sub_bus)
199{
200 struct pci_region *pci_mem = hose->pci_mem;
Kumar Galaa1790122006-01-11 13:24:15 -0600201 struct pci_region *pci_prefetch = hose->pci_prefetch;
wdenkc6097192002-11-03 00:24:07 +0000202 struct pci_region *pci_io = hose->pci_io;
Andrew Sharpaf778c62012-08-01 12:27:16 +0000203 u16 cmdstat;
wdenkc6097192002-11-03 00:24:07 +0000204
Andrew Sharpaf778c62012-08-01 12:27:16 +0000205 pci_hose_read_config_word(hose, dev, PCI_COMMAND, &cmdstat);
wdenkc6097192002-11-03 00:24:07 +0000206
207 /* Configure bus number registers */
Ed Swarthoute8b85f32007-07-11 14:52:08 -0500208 pci_hose_write_config_byte(hose, dev, PCI_PRIMARY_BUS,
209 PCI_BUS(dev) - hose->first_busno);
210 pci_hose_write_config_byte(hose, dev, PCI_SECONDARY_BUS,
211 sub_bus - hose->first_busno);
wdenkc6097192002-11-03 00:24:07 +0000212 pci_hose_write_config_byte(hose, dev, PCI_SUBORDINATE_BUS, 0xff);
213
wdenk3c74e322004-02-22 23:46:08 +0000214 if (pci_mem) {
wdenkc6097192002-11-03 00:24:07 +0000215 /* Round memory allocator to 1MB boundary */
216 pciauto_region_align(pci_mem, 0x100000);
217
218 /* Set up memory and I/O filter limits, assume 32-bit I/O space */
219 pci_hose_write_config_word(hose, dev, PCI_MEMORY_BASE,
220 (pci_mem->bus_lower & 0xfff00000) >> 16);
221
222 cmdstat |= PCI_COMMAND_MEMORY;
223 }
224
Kumar Galaa1790122006-01-11 13:24:15 -0600225 if (pci_prefetch) {
226 /* Round memory allocator to 1MB boundary */
227 pciauto_region_align(pci_prefetch, 0x100000);
228
229 /* Set up memory and I/O filter limits, assume 32-bit I/O space */
230 pci_hose_write_config_word(hose, dev, PCI_PREF_MEMORY_BASE,
231 (pci_prefetch->bus_lower & 0xfff00000) >> 16);
232
233 cmdstat |= PCI_COMMAND_MEMORY;
234 } else {
235 /* We don't support prefetchable memory for now, so disable */
236 pci_hose_write_config_word(hose, dev, PCI_PREF_MEMORY_BASE, 0x1000);
Matthew McClintocka4e11552006-06-28 10:44:23 -0500237 pci_hose_write_config_word(hose, dev, PCI_PREF_MEMORY_LIMIT, 0x0);
Kumar Galaa1790122006-01-11 13:24:15 -0600238 }
239
wdenk3c74e322004-02-22 23:46:08 +0000240 if (pci_io) {
wdenkc6097192002-11-03 00:24:07 +0000241 /* Round I/O allocator to 4KB boundary */
242 pciauto_region_align(pci_io, 0x1000);
243
244 pci_hose_write_config_byte(hose, dev, PCI_IO_BASE,
245 (pci_io->bus_lower & 0x0000f000) >> 8);
246 pci_hose_write_config_word(hose, dev, PCI_IO_BASE_UPPER16,
247 (pci_io->bus_lower & 0xffff0000) >> 16);
248
249 cmdstat |= PCI_COMMAND_IO;
250 }
251
wdenkc6097192002-11-03 00:24:07 +0000252 /* Enable memory and I/O accesses, enable bus master */
Andrew Sharpaf778c62012-08-01 12:27:16 +0000253 pci_hose_write_config_word(hose, dev, PCI_COMMAND,
254 cmdstat | PCI_COMMAND_MASTER);
wdenkc6097192002-11-03 00:24:07 +0000255}
256
Ed Swarthoutba5feb12007-07-11 14:51:48 -0500257void pciauto_postscan_setup_bridge(struct pci_controller *hose,
wdenkc6097192002-11-03 00:24:07 +0000258 pci_dev_t dev, int sub_bus)
259{
260 struct pci_region *pci_mem = hose->pci_mem;
Kumar Galaa1790122006-01-11 13:24:15 -0600261 struct pci_region *pci_prefetch = hose->pci_prefetch;
wdenkc6097192002-11-03 00:24:07 +0000262 struct pci_region *pci_io = hose->pci_io;
263
264 /* Configure bus number registers */
Ed Swarthoute8b85f32007-07-11 14:52:08 -0500265 pci_hose_write_config_byte(hose, dev, PCI_SUBORDINATE_BUS,
266 sub_bus - hose->first_busno);
wdenkc6097192002-11-03 00:24:07 +0000267
wdenk3c74e322004-02-22 23:46:08 +0000268 if (pci_mem) {
wdenkc6097192002-11-03 00:24:07 +0000269 /* Round memory allocator to 1MB boundary */
270 pciauto_region_align(pci_mem, 0x100000);
271
272 pci_hose_write_config_word(hose, dev, PCI_MEMORY_LIMIT,
Andrew Sharpcb2bf932012-08-29 14:16:29 +0000273 (pci_mem->bus_lower - 1) >> 16);
wdenkc6097192002-11-03 00:24:07 +0000274 }
275
Kumar Galaa1790122006-01-11 13:24:15 -0600276 if (pci_prefetch) {
277 /* Round memory allocator to 1MB boundary */
278 pciauto_region_align(pci_prefetch, 0x100000);
279
280 pci_hose_write_config_word(hose, dev, PCI_PREF_MEMORY_LIMIT,
Andrew Sharpcb2bf932012-08-29 14:16:29 +0000281 (pci_prefetch->bus_lower - 1) >> 16);
Kumar Galaa1790122006-01-11 13:24:15 -0600282 }
283
wdenk3c74e322004-02-22 23:46:08 +0000284 if (pci_io) {
wdenkc6097192002-11-03 00:24:07 +0000285 /* Round I/O allocator to 4KB boundary */
286 pciauto_region_align(pci_io, 0x1000);
287
288 pci_hose_write_config_byte(hose, dev, PCI_IO_LIMIT,
Andrew Sharpcb2bf932012-08-29 14:16:29 +0000289 ((pci_io->bus_lower - 1) & 0x0000f000) >> 8);
wdenkc6097192002-11-03 00:24:07 +0000290 pci_hose_write_config_word(hose, dev, PCI_IO_LIMIT_UPPER16,
Andrew Sharpcb2bf932012-08-29 14:16:29 +0000291 ((pci_io->bus_lower - 1) & 0xffff0000) >> 16);
wdenkc6097192002-11-03 00:24:07 +0000292 }
293}
294
295/*
296 *
297 */
298
299void pciauto_config_init(struct pci_controller *hose)
300{
301 int i;
302
303 hose->pci_io = hose->pci_mem = NULL;
304
Andrew Sharpcb2bf932012-08-29 14:16:29 +0000305 for (i = 0; i < hose->region_count; i++) {
wdenk3c74e322004-02-22 23:46:08 +0000306 switch(hose->regions[i].flags) {
wdenkc6097192002-11-03 00:24:07 +0000307 case PCI_REGION_IO:
308 if (!hose->pci_io ||
309 hose->pci_io->size < hose->regions[i].size)
310 hose->pci_io = hose->regions + i;
311 break;
312 case PCI_REGION_MEM:
313 if (!hose->pci_mem ||
314 hose->pci_mem->size < hose->regions[i].size)
315 hose->pci_mem = hose->regions + i;
316 break;
Kumar Galaa1790122006-01-11 13:24:15 -0600317 case (PCI_REGION_MEM | PCI_REGION_PREFETCH):
318 if (!hose->pci_prefetch ||
319 hose->pci_prefetch->size < hose->regions[i].size)
320 hose->pci_prefetch = hose->regions + i;
321 break;
wdenkc6097192002-11-03 00:24:07 +0000322 }
323 }
324
325
wdenk3c74e322004-02-22 23:46:08 +0000326 if (hose->pci_mem) {
wdenkc6097192002-11-03 00:24:07 +0000327 pciauto_region_init(hose->pci_mem);
328
Kumar Gala30e76d52008-10-21 08:36:08 -0500329 DEBUGF("PCI Autoconfig: Bus Memory region: [0x%llx-0x%llx],\n"
330 "\t\tPhysical Memory [%llx-%llxx]\n",
331 (u64)hose->pci_mem->bus_start,
332 (u64)(hose->pci_mem->bus_start + hose->pci_mem->size - 1),
333 (u64)hose->pci_mem->phys_start,
334 (u64)(hose->pci_mem->phys_start + hose->pci_mem->size - 1));
wdenkc6097192002-11-03 00:24:07 +0000335 }
336
Kumar Galaa1790122006-01-11 13:24:15 -0600337 if (hose->pci_prefetch) {
338 pciauto_region_init(hose->pci_prefetch);
339
Kumar Gala30e76d52008-10-21 08:36:08 -0500340 DEBUGF("PCI Autoconfig: Bus Prefetchable Mem: [0x%llx-0x%llx],\n"
341 "\t\tPhysical Memory [%llx-%llx]\n",
342 (u64)hose->pci_prefetch->bus_start,
343 (u64)(hose->pci_prefetch->bus_start +
344 hose->pci_prefetch->size - 1),
345 (u64)hose->pci_prefetch->phys_start,
346 (u64)(hose->pci_prefetch->phys_start +
347 hose->pci_prefetch->size - 1));
Kumar Galaa1790122006-01-11 13:24:15 -0600348 }
349
wdenk3c74e322004-02-22 23:46:08 +0000350 if (hose->pci_io) {
wdenkc6097192002-11-03 00:24:07 +0000351 pciauto_region_init(hose->pci_io);
352
Kumar Gala30e76d52008-10-21 08:36:08 -0500353 DEBUGF("PCI Autoconfig: Bus I/O region: [0x%llx-0x%llx],\n"
354 "\t\tPhysical Memory: [%llx-%llx]\n",
355 (u64)hose->pci_io->bus_start,
356 (u64)(hose->pci_io->bus_start + hose->pci_io->size - 1),
357 (u64)hose->pci_io->phys_start,
358 (u64)(hose->pci_io->phys_start + hose->pci_io->size - 1));
Ed Swarthoutba5feb12007-07-11 14:51:48 -0500359
wdenkc6097192002-11-03 00:24:07 +0000360 }
361}
362
Andrew Sharpcb2bf932012-08-29 14:16:29 +0000363/*
364 * HJF: Changed this to return int. I think this is required
wdenkc7de8292002-11-19 11:04:11 +0000365 * to get the correct result when scanning bridges
366 */
367int pciauto_config_device(struct pci_controller *hose, pci_dev_t dev)
wdenkc6097192002-11-03 00:24:07 +0000368{
wdenkc7de8292002-11-19 11:04:11 +0000369 unsigned int sub_bus = PCI_BUS(dev);
wdenkc6097192002-11-03 00:24:07 +0000370 unsigned short class;
371 unsigned char prg_iface;
wdenk5653fc32004-02-08 22:55:38 +0000372 int n;
wdenkc6097192002-11-03 00:24:07 +0000373
374 pci_hose_read_config_word(hose, dev, PCI_CLASS_DEVICE, &class);
375
Andrew Sharpcb2bf932012-08-29 14:16:29 +0000376 switch (class) {
wdenkc6097192002-11-03 00:24:07 +0000377 case PCI_CLASS_BRIDGE_PCI:
wdenkdb2f721f2003-03-06 00:58:30 +0000378 hose->current_busno++;
Andrew Sharpcb2bf932012-08-29 14:16:29 +0000379 pciauto_setup_device(hose, dev, 2, hose->pci_mem,
380 hose->pci_prefetch, hose->pci_io);
wdenkc6097192002-11-03 00:24:07 +0000381
wdenkdb2f721f2003-03-06 00:58:30 +0000382 DEBUGF("PCI Autoconfig: Found P2P bridge, device %d\n", PCI_DEV(dev));
wdenkcd37d9e2004-02-10 00:03:41 +0000383
wdenk3c74e322004-02-22 23:46:08 +0000384 /* Passing in current_busno allows for sibling P2P bridges */
wdenk5653fc32004-02-08 22:55:38 +0000385 pciauto_prescan_setup_bridge(hose, dev, hose->current_busno);
wdenkcd37d9e2004-02-10 00:03:41 +0000386 /*
wdenk3c74e322004-02-22 23:46:08 +0000387 * need to figure out if this is a subordinate bridge on the bus
wdenk5653fc32004-02-08 22:55:38 +0000388 * to be able to properly set the pri/sec/sub bridge registers.
389 */
390 n = pci_hose_scan_bus(hose, hose->current_busno);
wdenk8bde7f72003-06-27 21:31:46 +0000391
wdenk3c74e322004-02-22 23:46:08 +0000392 /* figure out the deepest we've gone for this leg */
wdenk5653fc32004-02-08 22:55:38 +0000393 sub_bus = max(n, sub_bus);
wdenkdb2f721f2003-03-06 00:58:30 +0000394 pciauto_postscan_setup_bridge(hose, dev, sub_bus);
wdenk5653fc32004-02-08 22:55:38 +0000395
wdenkdb2f721f2003-03-06 00:58:30 +0000396 sub_bus = hose->current_busno;
wdenkc6097192002-11-03 00:24:07 +0000397 break;
398
399 case PCI_CLASS_STORAGE_IDE:
400 pci_hose_read_config_byte(hose, dev, PCI_CLASS_PROG, &prg_iface);
wdenk3c74e322004-02-22 23:46:08 +0000401 if (!(prg_iface & PCIAUTO_IDE_MODE_MASK)) {
402 DEBUGF("PCI Autoconfig: Skipping legacy mode IDE controller\n");
403 return sub_bus;
404 }
wdenkc6097192002-11-03 00:24:07 +0000405
Andrew Sharpcb2bf932012-08-29 14:16:29 +0000406 pciauto_setup_device(hose, dev, 6, hose->pci_mem,
407 hose->pci_prefetch, hose->pci_io);
wdenkc6097192002-11-03 00:24:07 +0000408 break;
409
wdenk1cb8e982003-03-06 21:55:29 +0000410 case PCI_CLASS_BRIDGE_CARDBUS:
Andrew Sharpcb2bf932012-08-29 14:16:29 +0000411 /*
412 * just do a minimal setup of the bridge,
413 * let the OS take care of the rest
414 */
415 pciauto_setup_device(hose, dev, 0, hose->pci_mem,
416 hose->pci_prefetch, hose->pci_io);
wdenk1cb8e982003-03-06 21:55:29 +0000417
Andrew Sharpcb2bf932012-08-29 14:16:29 +0000418 DEBUGF("PCI Autoconfig: Found P2CardBus bridge, device %d\n",
419 PCI_DEV(dev));
wdenk1cb8e982003-03-06 21:55:29 +0000420
421 hose->current_busno++;
422 break;
423
TsiChung Liewf33fca22008-03-30 01:19:06 -0500424#if defined(CONFIG_PCIAUTO_SKIP_HOST_BRIDGE)
wdenke0ac62d2003-08-17 18:55:18 +0000425 case PCI_CLASS_BRIDGE_OTHER:
426 DEBUGF("PCI Autoconfig: Skipping bridge device %d\n",
427 PCI_DEV(dev));
428 break;
429#endif
Reinhard Arltc2e49f72009-07-25 06:19:12 +0200430#if defined(CONFIG_MPC834x) && !defined(CONFIG_VME8349)
Rafal Jaworowski6902df52005-10-17 02:39:53 +0200431 case PCI_CLASS_BRIDGE_OTHER:
432 /*
433 * The host/PCI bridge 1 seems broken in 8349 - it presents
434 * itself as 'PCI_CLASS_BRIDGE_OTHER' and appears as an _agent_
435 * device claiming resources io/mem/irq.. we only allow for
436 * the PIMMR window to be allocated (BAR0 - 1MB size)
437 */
438 DEBUGF("PCI Autoconfig: Broken bridge found, only minimal config\n");
Andrew Sharpcb2bf932012-08-29 14:16:29 +0000439 pciauto_setup_device(hose, dev, 0, hose->pci_mem,
440 hose->pci_prefetch, hose->pci_io);
Rafal Jaworowski6902df52005-10-17 02:39:53 +0200441 break;
442#endif
Andrew Sharp69fd2d32012-08-29 14:16:32 +0000443
444 case PCI_CLASS_PROCESSOR_POWERPC: /* an agent or end-point */
445 DEBUGF("PCI AutoConfig: Found PowerPC device\n");
446
wdenkc6097192002-11-03 00:24:07 +0000447 default:
Andrew Sharpcb2bf932012-08-29 14:16:29 +0000448 pciauto_setup_device(hose, dev, 6, hose->pci_mem,
449 hose->pci_prefetch, hose->pci_io);
wdenkc6097192002-11-03 00:24:07 +0000450 break;
451 }
wdenkc7de8292002-11-19 11:04:11 +0000452
453 return sub_bus;
wdenkc6097192002-11-03 00:24:07 +0000454}