blob: 7c109832f6d827ee0173d26cef63ec5056aaef64 [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 *
Wolfgang Denk1a459662013-07-08 09:37:19 +020010 * SPDX-License-Identifier: GPL-2.0+
wdenkc6097192002-11-03 00:24:07 +000011 */
12
13#include <common.h>
Simon Glass4a2708a2015-01-14 21:37:04 -070014#include <errno.h>
wdenkc6097192002-11-03 00:24:07 +000015#include <pci.h>
16
wdenkc6097192002-11-03 00:24:07 +000017#ifdef DEBUG
18#define DEBUGF(x...) printf(x)
19#else
20#define DEBUGF(x...)
21#endif /* DEBUG */
22
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +020023/* the user can define CONFIG_SYS_PCI_CACHE_LINE_SIZE to avoid problems */
24#ifndef CONFIG_SYS_PCI_CACHE_LINE_SIZE
25#define CONFIG_SYS_PCI_CACHE_LINE_SIZE 8
Gary Jennejohn81b73de2007-08-31 15:21:46 +020026#endif
27
wdenkc6097192002-11-03 00:24:07 +000028/*
29 *
30 */
31
Andrew Sharpcb2bf932012-08-29 14:16:29 +000032void pciauto_region_init(struct pci_region *res)
wdenkc6097192002-11-03 00:24:07 +000033{
Sergei Shtylyovb7598a42007-04-23 15:30:39 +020034 /*
35 * Avoid allocating PCI resources from address 0 -- this is illegal
36 * according to PCI 2.1 and moreover, this is known to cause Linux IDE
37 * drivers to fail. Use a reasonable starting value of 0x1000 instead.
38 */
39 res->bus_lower = res->bus_start ? res->bus_start : 0x1000;
wdenkc6097192002-11-03 00:24:07 +000040}
41
Kumar Gala30e76d52008-10-21 08:36:08 -050042void pciauto_region_align(struct pci_region *res, pci_size_t size)
wdenkc6097192002-11-03 00:24:07 +000043{
44 res->bus_lower = ((res->bus_lower - 1) | (size - 1)) + 1;
45}
46
Andrew Sharpcb2bf932012-08-29 14:16:29 +000047int pciauto_region_allocate(struct pci_region *res, pci_size_t size,
48 pci_addr_t *bar)
wdenkc6097192002-11-03 00:24:07 +000049{
Kumar Gala30e76d52008-10-21 08:36:08 -050050 pci_addr_t addr;
wdenkc6097192002-11-03 00:24:07 +000051
wdenk3c74e322004-02-22 23:46:08 +000052 if (!res) {
wdenkc6097192002-11-03 00:24:07 +000053 DEBUGF("No resource");
54 goto error;
55 }
56
57 addr = ((res->bus_lower - 1) | (size - 1)) + 1;
58
wdenk3c74e322004-02-22 23:46:08 +000059 if (addr - res->bus_start + size > res->size) {
wdenkc6097192002-11-03 00:24:07 +000060 DEBUGF("No room in resource");
61 goto error;
62 }
63
64 res->bus_lower = addr + size;
65
Kumar Gala30e76d52008-10-21 08:36:08 -050066 DEBUGF("address=0x%llx bus_lower=0x%llx", (u64)addr, (u64)res->bus_lower);
wdenkc6097192002-11-03 00:24:07 +000067
68 *bar = addr;
69 return 0;
70
71 error:
Kumar Gala30e76d52008-10-21 08:36:08 -050072 *bar = (pci_addr_t)-1;
wdenkc6097192002-11-03 00:24:07 +000073 return -1;
74}
75
76/*
77 *
78 */
79
80void pciauto_setup_device(struct pci_controller *hose,
81 pci_dev_t dev, int bars_num,
82 struct pci_region *mem,
Kumar Galaa1790122006-01-11 13:24:15 -060083 struct pci_region *prefetch,
wdenkc6097192002-11-03 00:24:07 +000084 struct pci_region *io)
85{
Kumar Galacf5787f2012-09-19 04:47:36 +000086 u32 bar_response;
Kumar Gala30e76d52008-10-21 08:36:08 -050087 pci_size_t bar_size;
Andrew Sharpaf778c62012-08-01 12:27:16 +000088 u16 cmdstat = 0;
wdenkc6097192002-11-03 00:24:07 +000089 int bar, bar_nr = 0;
Andrew Sharp69fd2d32012-08-29 14:16:32 +000090#ifndef CONFIG_PCI_ENUM_ONLY
91 pci_addr_t bar_value;
92 struct pci_region *bar_res;
wdenkc6097192002-11-03 00:24:07 +000093 int found_mem64 = 0;
Andrew Sharp69fd2d32012-08-29 14:16:32 +000094#endif
wdenkc6097192002-11-03 00:24:07 +000095
Andrew Sharpaf778c62012-08-01 12:27:16 +000096 pci_hose_read_config_word(hose, dev, PCI_COMMAND, &cmdstat);
wdenkc6097192002-11-03 00:24:07 +000097 cmdstat = (cmdstat & ~(PCI_COMMAND_IO | PCI_COMMAND_MEMORY)) | PCI_COMMAND_MASTER;
98
Andrew Sharpcb2bf932012-08-29 14:16:29 +000099 for (bar = PCI_BASE_ADDRESS_0;
100 bar < PCI_BASE_ADDRESS_0 + (bars_num * 4); bar += 4) {
wdenkc6097192002-11-03 00:24:07 +0000101 /* Tickle the BAR and get the response */
Andrew Sharp69fd2d32012-08-29 14:16:32 +0000102#ifndef CONFIG_PCI_ENUM_ONLY
wdenkc6097192002-11-03 00:24:07 +0000103 pci_hose_write_config_dword(hose, dev, bar, 0xffffffff);
Andrew Sharp69fd2d32012-08-29 14:16:32 +0000104#endif
wdenkc6097192002-11-03 00:24:07 +0000105 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
Andrew Sharp69fd2d32012-08-29 14:16:32 +0000111#ifndef CONFIG_PCI_ENUM_ONLY
wdenkc6097192002-11-03 00:24:07 +0000112 found_mem64 = 0;
Andrew Sharp69fd2d32012-08-29 14:16:32 +0000113#endif
wdenkc6097192002-11-03 00:24:07 +0000114
115 /* Check the BAR type and set our address mask */
wdenk3c74e322004-02-22 23:46:08 +0000116 if (bar_response & PCI_BASE_ADDRESS_SPACE) {
Jin Zhengxiong-R64188bd22c2b2006-06-27 18:12:02 +0800117 bar_size = ((~(bar_response & PCI_BASE_ADDRESS_IO_MASK))
118 & 0xffff) + 1;
Andrew Sharp69fd2d32012-08-29 14:16:32 +0000119#ifndef CONFIG_PCI_ENUM_ONLY
wdenkc6097192002-11-03 00:24:07 +0000120 bar_res = io;
Andrew Sharp69fd2d32012-08-29 14:16:32 +0000121#endif
wdenkc6097192002-11-03 00:24:07 +0000122
Kumar Gala30e76d52008-10-21 08:36:08 -0500123 DEBUGF("PCI Autoconfig: BAR %d, I/O, size=0x%llx, ", bar_nr, (u64)bar_size);
wdenk3c74e322004-02-22 23:46:08 +0000124 } else {
Andrew Sharpcb2bf932012-08-29 14:16:29 +0000125 if ((bar_response & PCI_BASE_ADDRESS_MEM_TYPE_MASK) ==
Kumar Gala30e76d52008-10-21 08:36:08 -0500126 PCI_BASE_ADDRESS_MEM_TYPE_64) {
127 u32 bar_response_upper;
128 u64 bar64;
Andrew Sharp69fd2d32012-08-29 14:16:32 +0000129
130#ifndef CONFIG_PCI_ENUM_ONLY
Andrew Sharpcb2bf932012-08-29 14:16:29 +0000131 pci_hose_write_config_dword(hose, dev, bar + 4,
132 0xffffffff);
Andrew Sharp69fd2d32012-08-29 14:16:32 +0000133#endif
Andrew Sharpcb2bf932012-08-29 14:16:29 +0000134 pci_hose_read_config_dword(hose, dev, bar + 4,
135 &bar_response_upper);
wdenkc6097192002-11-03 00:24:07 +0000136
Kumar Gala30e76d52008-10-21 08:36:08 -0500137 bar64 = ((u64)bar_response_upper << 32) | bar_response;
138
139 bar_size = ~(bar64 & PCI_BASE_ADDRESS_MEM_MASK) + 1;
Andrew Sharp69fd2d32012-08-29 14:16:32 +0000140#ifndef CONFIG_PCI_ENUM_ONLY
Kumar Gala30e76d52008-10-21 08:36:08 -0500141 found_mem64 = 1;
Andrew Sharp69fd2d32012-08-29 14:16:32 +0000142#endif
Kumar Gala30e76d52008-10-21 08:36:08 -0500143 } else {
144 bar_size = (u32)(~(bar_response & PCI_BASE_ADDRESS_MEM_MASK) + 1);
145 }
Andrew Sharp69fd2d32012-08-29 14:16:32 +0000146#ifndef CONFIG_PCI_ENUM_ONLY
Kumar Galaa1790122006-01-11 13:24:15 -0600147 if (prefetch && (bar_response & PCI_BASE_ADDRESS_MEM_PREFETCH))
148 bar_res = prefetch;
149 else
150 bar_res = mem;
Andrew Sharp69fd2d32012-08-29 14:16:32 +0000151#endif
wdenkc6097192002-11-03 00:24:07 +0000152
Kumar Gala30e76d52008-10-21 08:36:08 -0500153 DEBUGF("PCI Autoconfig: BAR %d, Mem, size=0x%llx, ", bar_nr, (u64)bar_size);
wdenkc6097192002-11-03 00:24:07 +0000154 }
155
Andrew Sharp69fd2d32012-08-29 14:16:32 +0000156#ifndef CONFIG_PCI_ENUM_ONLY
wdenk3c74e322004-02-22 23:46:08 +0000157 if (pciauto_region_allocate(bar_res, bar_size, &bar_value) == 0) {
wdenkc6097192002-11-03 00:24:07 +0000158 /* Write it out and update our limit */
Kumar Gala30e76d52008-10-21 08:36:08 -0500159 pci_hose_write_config_dword(hose, dev, bar, (u32)bar_value);
wdenkc6097192002-11-03 00:24:07 +0000160
wdenk3c74e322004-02-22 23:46:08 +0000161 if (found_mem64) {
wdenkc6097192002-11-03 00:24:07 +0000162 bar += 4;
Kumar Gala30e76d52008-10-21 08:36:08 -0500163#ifdef CONFIG_SYS_PCI_64BIT
164 pci_hose_write_config_dword(hose, dev, bar, (u32)(bar_value>>32));
165#else
166 /*
167 * If we are a 64-bit decoder then increment to the
168 * upper 32 bits of the bar and force it to locate
169 * in the lower 4GB of memory.
170 */
wdenkc6097192002-11-03 00:24:07 +0000171 pci_hose_write_config_dword(hose, dev, bar, 0x00000000);
Kumar Gala30e76d52008-10-21 08:36:08 -0500172#endif
wdenkc6097192002-11-03 00:24:07 +0000173 }
174
wdenkc6097192002-11-03 00:24:07 +0000175 }
Andrew Sharp69fd2d32012-08-29 14:16:32 +0000176#endif
177 cmdstat |= (bar_response & PCI_BASE_ADDRESS_SPACE) ?
178 PCI_COMMAND_IO : PCI_COMMAND_MEMORY;
wdenkc6097192002-11-03 00:24:07 +0000179
180 DEBUGF("\n");
181
182 bar_nr++;
183 }
184
Andrew Sharpaf778c62012-08-01 12:27:16 +0000185 pci_hose_write_config_word(hose, dev, PCI_COMMAND, cmdstat);
Gary Jennejohn81b73de2007-08-31 15:21:46 +0200186 pci_hose_write_config_byte(hose, dev, PCI_CACHE_LINE_SIZE,
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200187 CONFIG_SYS_PCI_CACHE_LINE_SIZE);
wdenkc6097192002-11-03 00:24:07 +0000188 pci_hose_write_config_byte(hose, dev, PCI_LATENCY_TIMER, 0x80);
189}
190
Simon Glass4a2708a2015-01-14 21:37:04 -0700191int pciauto_setup_rom(struct pci_controller *hose, pci_dev_t dev)
192{
193 pci_addr_t bar_value;
194 pci_size_t bar_size;
195 u32 bar_response;
196 u16 cmdstat = 0;
197
198 pci_hose_write_config_dword(hose, dev, PCI_ROM_ADDRESS, 0xfffffffe);
199 pci_hose_read_config_dword(hose, dev, PCI_ROM_ADDRESS, &bar_response);
200 if (!bar_response)
201 return -ENOENT;
202
203 bar_size = -(bar_response & ~1);
204 DEBUGF("PCI Autoconfig: ROM, size=%#x, ", bar_size);
205 if (pciauto_region_allocate(hose->pci_mem, bar_size, &bar_value) == 0) {
206 pci_hose_write_config_dword(hose, dev, PCI_ROM_ADDRESS,
207 bar_value);
208 }
209 DEBUGF("\n");
210 pci_hose_read_config_word(hose, dev, PCI_COMMAND, &cmdstat);
211 cmdstat |= PCI_COMMAND_IO | PCI_COMMAND_MEMORY | PCI_COMMAND_MASTER;
212 pci_hose_write_config_word(hose, dev, PCI_COMMAND, cmdstat);
213
214 return 0;
215}
216
Ed Swarthoutba5feb12007-07-11 14:51:48 -0500217void pciauto_prescan_setup_bridge(struct pci_controller *hose,
wdenkc6097192002-11-03 00:24:07 +0000218 pci_dev_t dev, int sub_bus)
219{
220 struct pci_region *pci_mem = hose->pci_mem;
Kumar Galaa1790122006-01-11 13:24:15 -0600221 struct pci_region *pci_prefetch = hose->pci_prefetch;
wdenkc6097192002-11-03 00:24:07 +0000222 struct pci_region *pci_io = hose->pci_io;
David Feng6eefd522015-02-02 16:53:13 +0800223 u16 cmdstat, prefechable_64;
wdenkc6097192002-11-03 00:24:07 +0000224
Andrew Sharpaf778c62012-08-01 12:27:16 +0000225 pci_hose_read_config_word(hose, dev, PCI_COMMAND, &cmdstat);
David Feng6eefd522015-02-02 16:53:13 +0800226 pci_hose_read_config_word(hose, dev, PCI_PREF_MEMORY_BASE,
227 &prefechable_64);
228 prefechable_64 &= PCI_PREF_RANGE_TYPE_MASK;
wdenkc6097192002-11-03 00:24:07 +0000229
230 /* Configure bus number registers */
Ed Swarthoute8b85f32007-07-11 14:52:08 -0500231 pci_hose_write_config_byte(hose, dev, PCI_PRIMARY_BUS,
232 PCI_BUS(dev) - hose->first_busno);
233 pci_hose_write_config_byte(hose, dev, PCI_SECONDARY_BUS,
234 sub_bus - hose->first_busno);
wdenkc6097192002-11-03 00:24:07 +0000235 pci_hose_write_config_byte(hose, dev, PCI_SUBORDINATE_BUS, 0xff);
236
wdenk3c74e322004-02-22 23:46:08 +0000237 if (pci_mem) {
wdenkc6097192002-11-03 00:24:07 +0000238 /* Round memory allocator to 1MB boundary */
239 pciauto_region_align(pci_mem, 0x100000);
240
241 /* Set up memory and I/O filter limits, assume 32-bit I/O space */
242 pci_hose_write_config_word(hose, dev, PCI_MEMORY_BASE,
243 (pci_mem->bus_lower & 0xfff00000) >> 16);
244
245 cmdstat |= PCI_COMMAND_MEMORY;
246 }
247
Kumar Galaa1790122006-01-11 13:24:15 -0600248 if (pci_prefetch) {
249 /* Round memory allocator to 1MB boundary */
250 pciauto_region_align(pci_prefetch, 0x100000);
251
252 /* Set up memory and I/O filter limits, assume 32-bit I/O space */
253 pci_hose_write_config_word(hose, dev, PCI_PREF_MEMORY_BASE,
254 (pci_prefetch->bus_lower & 0xfff00000) >> 16);
David Feng6eefd522015-02-02 16:53:13 +0800255 if (prefechable_64 == PCI_PREF_RANGE_TYPE_64)
256#ifdef CONFIG_SYS_PCI_64BIT
257 pci_hose_write_config_dword(hose, dev,
258 PCI_PREF_BASE_UPPER32,
259 pci_prefetch->bus_lower >> 32);
260#else
261 pci_hose_write_config_dword(hose, dev,
262 PCI_PREF_BASE_UPPER32,
263 0x0);
264#endif
Kumar Galaa1790122006-01-11 13:24:15 -0600265
266 cmdstat |= PCI_COMMAND_MEMORY;
267 } else {
268 /* We don't support prefetchable memory for now, so disable */
269 pci_hose_write_config_word(hose, dev, PCI_PREF_MEMORY_BASE, 0x1000);
Matthew McClintocka4e11552006-06-28 10:44:23 -0500270 pci_hose_write_config_word(hose, dev, PCI_PREF_MEMORY_LIMIT, 0x0);
David Feng6eefd522015-02-02 16:53:13 +0800271 if (prefechable_64 == PCI_PREF_RANGE_TYPE_64) {
272 pci_hose_write_config_word(hose, dev, PCI_PREF_BASE_UPPER32, 0x0);
273 pci_hose_write_config_word(hose, dev, PCI_PREF_LIMIT_UPPER32, 0x0);
274 }
Kumar Galaa1790122006-01-11 13:24:15 -0600275 }
276
wdenk3c74e322004-02-22 23:46:08 +0000277 if (pci_io) {
wdenkc6097192002-11-03 00:24:07 +0000278 /* Round I/O allocator to 4KB boundary */
279 pciauto_region_align(pci_io, 0x1000);
280
281 pci_hose_write_config_byte(hose, dev, PCI_IO_BASE,
282 (pci_io->bus_lower & 0x0000f000) >> 8);
283 pci_hose_write_config_word(hose, dev, PCI_IO_BASE_UPPER16,
284 (pci_io->bus_lower & 0xffff0000) >> 16);
285
286 cmdstat |= PCI_COMMAND_IO;
287 }
288
wdenkc6097192002-11-03 00:24:07 +0000289 /* Enable memory and I/O accesses, enable bus master */
Andrew Sharpaf778c62012-08-01 12:27:16 +0000290 pci_hose_write_config_word(hose, dev, PCI_COMMAND,
291 cmdstat | PCI_COMMAND_MASTER);
wdenkc6097192002-11-03 00:24:07 +0000292}
293
Ed Swarthoutba5feb12007-07-11 14:51:48 -0500294void pciauto_postscan_setup_bridge(struct pci_controller *hose,
wdenkc6097192002-11-03 00:24:07 +0000295 pci_dev_t dev, int sub_bus)
296{
297 struct pci_region *pci_mem = hose->pci_mem;
Kumar Galaa1790122006-01-11 13:24:15 -0600298 struct pci_region *pci_prefetch = hose->pci_prefetch;
wdenkc6097192002-11-03 00:24:07 +0000299 struct pci_region *pci_io = hose->pci_io;
300
301 /* Configure bus number registers */
Ed Swarthoute8b85f32007-07-11 14:52:08 -0500302 pci_hose_write_config_byte(hose, dev, PCI_SUBORDINATE_BUS,
303 sub_bus - hose->first_busno);
wdenkc6097192002-11-03 00:24:07 +0000304
wdenk3c74e322004-02-22 23:46:08 +0000305 if (pci_mem) {
wdenkc6097192002-11-03 00:24:07 +0000306 /* Round memory allocator to 1MB boundary */
307 pciauto_region_align(pci_mem, 0x100000);
308
309 pci_hose_write_config_word(hose, dev, PCI_MEMORY_LIMIT,
Andrew Sharpcb2bf932012-08-29 14:16:29 +0000310 (pci_mem->bus_lower - 1) >> 16);
wdenkc6097192002-11-03 00:24:07 +0000311 }
312
Kumar Galaa1790122006-01-11 13:24:15 -0600313 if (pci_prefetch) {
David Feng6eefd522015-02-02 16:53:13 +0800314 u16 prefechable_64;
315
316 pci_hose_read_config_word(hose, dev,
317 PCI_PREF_MEMORY_LIMIT,
318 &prefechable_64);
319 prefechable_64 &= PCI_PREF_RANGE_TYPE_MASK;
320
Kumar Galaa1790122006-01-11 13:24:15 -0600321 /* Round memory allocator to 1MB boundary */
322 pciauto_region_align(pci_prefetch, 0x100000);
323
324 pci_hose_write_config_word(hose, dev, PCI_PREF_MEMORY_LIMIT,
Andrew Sharpcb2bf932012-08-29 14:16:29 +0000325 (pci_prefetch->bus_lower - 1) >> 16);
David Feng6eefd522015-02-02 16:53:13 +0800326 if (prefechable_64 == PCI_PREF_RANGE_TYPE_64)
327#ifdef CONFIG_SYS_PCI_64BIT
328 pci_hose_write_config_dword(hose, dev,
329 PCI_PREF_LIMIT_UPPER32,
330 (pci_prefetch->bus_lower - 1) >> 32);
331#else
332 pci_hose_write_config_dword(hose, dev,
333 PCI_PREF_LIMIT_UPPER32,
334 0x0);
335#endif
Kumar Galaa1790122006-01-11 13:24:15 -0600336 }
337
wdenk3c74e322004-02-22 23:46:08 +0000338 if (pci_io) {
wdenkc6097192002-11-03 00:24:07 +0000339 /* Round I/O allocator to 4KB boundary */
340 pciauto_region_align(pci_io, 0x1000);
341
342 pci_hose_write_config_byte(hose, dev, PCI_IO_LIMIT,
Andrew Sharpcb2bf932012-08-29 14:16:29 +0000343 ((pci_io->bus_lower - 1) & 0x0000f000) >> 8);
wdenkc6097192002-11-03 00:24:07 +0000344 pci_hose_write_config_word(hose, dev, PCI_IO_LIMIT_UPPER16,
Andrew Sharpcb2bf932012-08-29 14:16:29 +0000345 ((pci_io->bus_lower - 1) & 0xffff0000) >> 16);
wdenkc6097192002-11-03 00:24:07 +0000346 }
347}
348
349/*
350 *
351 */
352
353void pciauto_config_init(struct pci_controller *hose)
354{
355 int i;
356
Thierry Reding010c4802013-09-20 15:50:50 +0200357 hose->pci_io = hose->pci_mem = hose->pci_prefetch = NULL;
wdenkc6097192002-11-03 00:24:07 +0000358
Andrew Sharpcb2bf932012-08-29 14:16:29 +0000359 for (i = 0; i < hose->region_count; i++) {
wdenk3c74e322004-02-22 23:46:08 +0000360 switch(hose->regions[i].flags) {
wdenkc6097192002-11-03 00:24:07 +0000361 case PCI_REGION_IO:
362 if (!hose->pci_io ||
363 hose->pci_io->size < hose->regions[i].size)
364 hose->pci_io = hose->regions + i;
365 break;
366 case PCI_REGION_MEM:
367 if (!hose->pci_mem ||
368 hose->pci_mem->size < hose->regions[i].size)
369 hose->pci_mem = hose->regions + i;
370 break;
Kumar Galaa1790122006-01-11 13:24:15 -0600371 case (PCI_REGION_MEM | PCI_REGION_PREFETCH):
372 if (!hose->pci_prefetch ||
373 hose->pci_prefetch->size < hose->regions[i].size)
374 hose->pci_prefetch = hose->regions + i;
375 break;
wdenkc6097192002-11-03 00:24:07 +0000376 }
377 }
378
379
wdenk3c74e322004-02-22 23:46:08 +0000380 if (hose->pci_mem) {
wdenkc6097192002-11-03 00:24:07 +0000381 pciauto_region_init(hose->pci_mem);
382
Kumar Gala30e76d52008-10-21 08:36:08 -0500383 DEBUGF("PCI Autoconfig: Bus Memory region: [0x%llx-0x%llx],\n"
384 "\t\tPhysical Memory [%llx-%llxx]\n",
385 (u64)hose->pci_mem->bus_start,
386 (u64)(hose->pci_mem->bus_start + hose->pci_mem->size - 1),
387 (u64)hose->pci_mem->phys_start,
388 (u64)(hose->pci_mem->phys_start + hose->pci_mem->size - 1));
wdenkc6097192002-11-03 00:24:07 +0000389 }
390
Kumar Galaa1790122006-01-11 13:24:15 -0600391 if (hose->pci_prefetch) {
392 pciauto_region_init(hose->pci_prefetch);
393
Kumar Gala30e76d52008-10-21 08:36:08 -0500394 DEBUGF("PCI Autoconfig: Bus Prefetchable Mem: [0x%llx-0x%llx],\n"
395 "\t\tPhysical Memory [%llx-%llx]\n",
396 (u64)hose->pci_prefetch->bus_start,
397 (u64)(hose->pci_prefetch->bus_start +
398 hose->pci_prefetch->size - 1),
399 (u64)hose->pci_prefetch->phys_start,
400 (u64)(hose->pci_prefetch->phys_start +
401 hose->pci_prefetch->size - 1));
Kumar Galaa1790122006-01-11 13:24:15 -0600402 }
403
wdenk3c74e322004-02-22 23:46:08 +0000404 if (hose->pci_io) {
wdenkc6097192002-11-03 00:24:07 +0000405 pciauto_region_init(hose->pci_io);
406
Kumar Gala30e76d52008-10-21 08:36:08 -0500407 DEBUGF("PCI Autoconfig: Bus I/O region: [0x%llx-0x%llx],\n"
408 "\t\tPhysical Memory: [%llx-%llx]\n",
409 (u64)hose->pci_io->bus_start,
410 (u64)(hose->pci_io->bus_start + hose->pci_io->size - 1),
411 (u64)hose->pci_io->phys_start,
412 (u64)(hose->pci_io->phys_start + hose->pci_io->size - 1));
Ed Swarthoutba5feb12007-07-11 14:51:48 -0500413
wdenkc6097192002-11-03 00:24:07 +0000414 }
415}
416
Andrew Sharpcb2bf932012-08-29 14:16:29 +0000417/*
418 * HJF: Changed this to return int. I think this is required
wdenkc7de8292002-11-19 11:04:11 +0000419 * to get the correct result when scanning bridges
420 */
421int pciauto_config_device(struct pci_controller *hose, pci_dev_t dev)
wdenkc6097192002-11-03 00:24:07 +0000422{
wdenkc7de8292002-11-19 11:04:11 +0000423 unsigned int sub_bus = PCI_BUS(dev);
wdenkc6097192002-11-03 00:24:07 +0000424 unsigned short class;
wdenk5653fc32004-02-08 22:55:38 +0000425 int n;
wdenkc6097192002-11-03 00:24:07 +0000426
427 pci_hose_read_config_word(hose, dev, PCI_CLASS_DEVICE, &class);
428
Andrew Sharpcb2bf932012-08-29 14:16:29 +0000429 switch (class) {
wdenkc6097192002-11-03 00:24:07 +0000430 case PCI_CLASS_BRIDGE_PCI:
Simon Glassff3e0772015-03-05 12:25:25 -0700431 DEBUGF("PCI Autoconfig: Found P2P bridge, device %d\n",
432 PCI_DEV(dev));
433
Andrew Sharpcb2bf932012-08-29 14:16:29 +0000434 pciauto_setup_device(hose, dev, 2, hose->pci_mem,
435 hose->pci_prefetch, hose->pci_io);
wdenkc6097192002-11-03 00:24:07 +0000436
Simon Glassff3e0772015-03-05 12:25:25 -0700437#ifdef CONFIG_DM_PCI
438 n = dm_pci_hose_probe_bus(hose, dev);
439 if (n < 0)
440 return n;
441 sub_bus = (unsigned int)n;
442#else
wdenk3c74e322004-02-22 23:46:08 +0000443 /* Passing in current_busno allows for sibling P2P bridges */
Simon Glassff3e0772015-03-05 12:25:25 -0700444 hose->current_busno++;
wdenk5653fc32004-02-08 22:55:38 +0000445 pciauto_prescan_setup_bridge(hose, dev, hose->current_busno);
wdenkcd37d9e2004-02-10 00:03:41 +0000446 /*
wdenk3c74e322004-02-22 23:46:08 +0000447 * need to figure out if this is a subordinate bridge on the bus
wdenk5653fc32004-02-08 22:55:38 +0000448 * to be able to properly set the pri/sec/sub bridge registers.
449 */
450 n = pci_hose_scan_bus(hose, hose->current_busno);
wdenk8bde7f72003-06-27 21:31:46 +0000451
wdenk3c74e322004-02-22 23:46:08 +0000452 /* figure out the deepest we've gone for this leg */
Masahiro Yamadab4141192014-11-07 03:03:31 +0900453 sub_bus = max((unsigned int)n, sub_bus);
wdenkdb2f721f2003-03-06 00:58:30 +0000454 pciauto_postscan_setup_bridge(hose, dev, sub_bus);
wdenk5653fc32004-02-08 22:55:38 +0000455
wdenkdb2f721f2003-03-06 00:58:30 +0000456 sub_bus = hose->current_busno;
Simon Glassff3e0772015-03-05 12:25:25 -0700457#endif
wdenkc6097192002-11-03 00:24:07 +0000458 break;
459
wdenk1cb8e982003-03-06 21:55:29 +0000460 case PCI_CLASS_BRIDGE_CARDBUS:
Andrew Sharpcb2bf932012-08-29 14:16:29 +0000461 /*
462 * just do a minimal setup of the bridge,
463 * let the OS take care of the rest
464 */
465 pciauto_setup_device(hose, dev, 0, hose->pci_mem,
466 hose->pci_prefetch, hose->pci_io);
wdenk1cb8e982003-03-06 21:55:29 +0000467
Andrew Sharpcb2bf932012-08-29 14:16:29 +0000468 DEBUGF("PCI Autoconfig: Found P2CardBus bridge, device %d\n",
469 PCI_DEV(dev));
wdenk1cb8e982003-03-06 21:55:29 +0000470
Simon Glassff3e0772015-03-05 12:25:25 -0700471#ifndef CONFIG_DM_PCI
wdenk1cb8e982003-03-06 21:55:29 +0000472 hose->current_busno++;
Simon Glassff3e0772015-03-05 12:25:25 -0700473#endif
wdenk1cb8e982003-03-06 21:55:29 +0000474 break;
475
TsiChung Liewf33fca22008-03-30 01:19:06 -0500476#if defined(CONFIG_PCIAUTO_SKIP_HOST_BRIDGE)
wdenke0ac62d2003-08-17 18:55:18 +0000477 case PCI_CLASS_BRIDGE_OTHER:
478 DEBUGF("PCI Autoconfig: Skipping bridge device %d\n",
479 PCI_DEV(dev));
480 break;
481#endif
Reinhard Arltc2e49f72009-07-25 06:19:12 +0200482#if defined(CONFIG_MPC834x) && !defined(CONFIG_VME8349)
Rafal Jaworowski6902df52005-10-17 02:39:53 +0200483 case PCI_CLASS_BRIDGE_OTHER:
484 /*
485 * The host/PCI bridge 1 seems broken in 8349 - it presents
486 * itself as 'PCI_CLASS_BRIDGE_OTHER' and appears as an _agent_
487 * device claiming resources io/mem/irq.. we only allow for
488 * the PIMMR window to be allocated (BAR0 - 1MB size)
489 */
490 DEBUGF("PCI Autoconfig: Broken bridge found, only minimal config\n");
Andrew Sharpcb2bf932012-08-29 14:16:29 +0000491 pciauto_setup_device(hose, dev, 0, hose->pci_mem,
492 hose->pci_prefetch, hose->pci_io);
Rafal Jaworowski6902df52005-10-17 02:39:53 +0200493 break;
494#endif
Andrew Sharp69fd2d32012-08-29 14:16:32 +0000495
496 case PCI_CLASS_PROCESSOR_POWERPC: /* an agent or end-point */
497 DEBUGF("PCI AutoConfig: Found PowerPC device\n");
498
wdenkc6097192002-11-03 00:24:07 +0000499 default:
Andrew Sharpcb2bf932012-08-29 14:16:29 +0000500 pciauto_setup_device(hose, dev, 6, hose->pci_mem,
501 hose->pci_prefetch, hose->pci_io);
wdenkc6097192002-11-03 00:24:07 +0000502 break;
503 }
wdenkc7de8292002-11-19 11:04:11 +0000504
505 return sub_bus;
wdenkc6097192002-11-03 00:24:07 +0000506}