setup-bus.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617
  1. /*
  2. * drivers/pci/setup-bus.c
  3. *
  4. * Extruded from code written by
  5. * Dave Rusling (david.rusling@reo.mts.dec.com)
  6. * David Mosberger (davidm@cs.arizona.edu)
  7. * David Miller (davem@redhat.com)
  8. *
  9. * Support routines for initializing a PCI subsystem.
  10. */
  11. /*
  12. * Nov 2000, Ivan Kokshaysky <ink@jurassic.park.msu.ru>
  13. * PCI-PCI bridges cleanup, sorted resource allocation.
  14. * Feb 2002, Ivan Kokshaysky <ink@jurassic.park.msu.ru>
  15. * Converted to allocation in 3 passes, which gives
  16. * tighter packing. Prefetchable range support.
  17. */
  18. #include <linux/init.h>
  19. #include <linux/kernel.h>
  20. #include <linux/module.h>
  21. #include <linux/pci.h>
  22. #include <linux/errno.h>
  23. #include <linux/ioport.h>
  24. #include <linux/cache.h>
  25. #include <linux/slab.h>
  26. #include "pci.h"
  27. static void pbus_assign_resources_sorted(const struct pci_bus *bus)
  28. {
  29. struct pci_dev *dev;
  30. struct resource *res;
  31. struct resource_list head, *list, *tmp;
  32. int idx;
  33. head.next = NULL;
  34. list_for_each_entry(dev, &bus->devices, bus_list) {
  35. u16 class = dev->class >> 8;
  36. /* Don't touch classless devices or host bridges or ioapics. */
  37. if (class == PCI_CLASS_NOT_DEFINED ||
  38. class == PCI_CLASS_BRIDGE_HOST)
  39. continue;
  40. /* Don't touch ioapic devices already enabled by firmware */
  41. if (class == PCI_CLASS_SYSTEM_PIC) {
  42. u16 command;
  43. pci_read_config_word(dev, PCI_COMMAND, &command);
  44. if (command & (PCI_COMMAND_IO | PCI_COMMAND_MEMORY))
  45. continue;
  46. }
  47. pdev_sort_resources(dev, &head);
  48. }
  49. for (list = head.next; list;) {
  50. res = list->res;
  51. idx = res - &list->dev->resource[0];
  52. if (pci_assign_resource(list->dev, idx)) {
  53. res->start = 0;
  54. res->end = 0;
  55. res->flags = 0;
  56. }
  57. tmp = list;
  58. list = list->next;
  59. kfree(tmp);
  60. }
  61. }
  62. void pci_setup_cardbus(struct pci_bus *bus)
  63. {
  64. struct pci_dev *bridge = bus->self;
  65. struct pci_bus_region region;
  66. dev_info(&bridge->dev, "CardBus bridge, secondary bus %04x:%02x\n",
  67. pci_domain_nr(bus), bus->number);
  68. pcibios_resource_to_bus(bridge, &region, bus->resource[0]);
  69. if (bus->resource[0]->flags & IORESOURCE_IO) {
  70. /*
  71. * The IO resource is allocated a range twice as large as it
  72. * would normally need. This allows us to set both IO regs.
  73. */
  74. dev_info(&bridge->dev, " IO window: %#08lx-%#08lx\n",
  75. (unsigned long)region.start,
  76. (unsigned long)region.end);
  77. pci_write_config_dword(bridge, PCI_CB_IO_BASE_0,
  78. region.start);
  79. pci_write_config_dword(bridge, PCI_CB_IO_LIMIT_0,
  80. region.end);
  81. }
  82. pcibios_resource_to_bus(bridge, &region, bus->resource[1]);
  83. if (bus->resource[1]->flags & IORESOURCE_IO) {
  84. dev_info(&bridge->dev, " IO window: %#08lx-%#08lx\n",
  85. (unsigned long)region.start,
  86. (unsigned long)region.end);
  87. pci_write_config_dword(bridge, PCI_CB_IO_BASE_1,
  88. region.start);
  89. pci_write_config_dword(bridge, PCI_CB_IO_LIMIT_1,
  90. region.end);
  91. }
  92. pcibios_resource_to_bus(bridge, &region, bus->resource[2]);
  93. if (bus->resource[2]->flags & IORESOURCE_MEM) {
  94. dev_info(&bridge->dev, " PREFETCH window: %#08lx-%#08lx\n",
  95. (unsigned long)region.start,
  96. (unsigned long)region.end);
  97. pci_write_config_dword(bridge, PCI_CB_MEMORY_BASE_0,
  98. region.start);
  99. pci_write_config_dword(bridge, PCI_CB_MEMORY_LIMIT_0,
  100. region.end);
  101. }
  102. pcibios_resource_to_bus(bridge, &region, bus->resource[3]);
  103. if (bus->resource[3]->flags & IORESOURCE_MEM) {
  104. dev_info(&bridge->dev, " MEM window: %#08lx-%#08lx\n",
  105. (unsigned long)region.start,
  106. (unsigned long)region.end);
  107. pci_write_config_dword(bridge, PCI_CB_MEMORY_BASE_1,
  108. region.start);
  109. pci_write_config_dword(bridge, PCI_CB_MEMORY_LIMIT_1,
  110. region.end);
  111. }
  112. }
  113. EXPORT_SYMBOL(pci_setup_cardbus);
  114. /* Initialize bridges with base/limit values we have collected.
  115. PCI-to-PCI Bridge Architecture Specification rev. 1.1 (1998)
  116. requires that if there is no I/O ports or memory behind the
  117. bridge, corresponding range must be turned off by writing base
  118. value greater than limit to the bridge's base/limit registers.
  119. Note: care must be taken when updating I/O base/limit registers
  120. of bridges which support 32-bit I/O. This update requires two
  121. config space writes, so it's quite possible that an I/O window of
  122. the bridge will have some undesirable address (e.g. 0) after the
  123. first write. Ditto 64-bit prefetchable MMIO. */
  124. static void pci_setup_bridge(struct pci_bus *bus)
  125. {
  126. struct pci_dev *bridge = bus->self;
  127. struct pci_bus_region region;
  128. u32 l, bu, lu, io_upper16;
  129. int pref_mem64;
  130. if (pci_is_enabled(bridge))
  131. return;
  132. dev_info(&bridge->dev, "PCI bridge, secondary bus %04x:%02x\n",
  133. pci_domain_nr(bus), bus->number);
  134. /* Set up the top and bottom of the PCI I/O segment for this bus. */
  135. pcibios_resource_to_bus(bridge, &region, bus->resource[0]);
  136. if (bus->resource[0]->flags & IORESOURCE_IO) {
  137. pci_read_config_dword(bridge, PCI_IO_BASE, &l);
  138. l &= 0xffff0000;
  139. l |= (region.start >> 8) & 0x00f0;
  140. l |= region.end & 0xf000;
  141. /* Set up upper 16 bits of I/O base/limit. */
  142. io_upper16 = (region.end & 0xffff0000) | (region.start >> 16);
  143. dev_info(&bridge->dev, " IO window: %#04lx-%#04lx\n",
  144. (unsigned long)region.start,
  145. (unsigned long)region.end);
  146. }
  147. else {
  148. /* Clear upper 16 bits of I/O base/limit. */
  149. io_upper16 = 0;
  150. l = 0x00f0;
  151. dev_info(&bridge->dev, " IO window: disabled\n");
  152. }
  153. /* Temporarily disable the I/O range before updating PCI_IO_BASE. */
  154. pci_write_config_dword(bridge, PCI_IO_BASE_UPPER16, 0x0000ffff);
  155. /* Update lower 16 bits of I/O base/limit. */
  156. pci_write_config_dword(bridge, PCI_IO_BASE, l);
  157. /* Update upper 16 bits of I/O base/limit. */
  158. pci_write_config_dword(bridge, PCI_IO_BASE_UPPER16, io_upper16);
  159. /* Set up the top and bottom of the PCI Memory segment
  160. for this bus. */
  161. pcibios_resource_to_bus(bridge, &region, bus->resource[1]);
  162. if (bus->resource[1]->flags & IORESOURCE_MEM) {
  163. l = (region.start >> 16) & 0xfff0;
  164. l |= region.end & 0xfff00000;
  165. dev_info(&bridge->dev, " MEM window: %#08lx-%#08lx\n",
  166. (unsigned long)region.start,
  167. (unsigned long)region.end);
  168. }
  169. else {
  170. l = 0x0000fff0;
  171. dev_info(&bridge->dev, " MEM window: disabled\n");
  172. }
  173. pci_write_config_dword(bridge, PCI_MEMORY_BASE, l);
  174. /* Clear out the upper 32 bits of PREF limit.
  175. If PCI_PREF_BASE_UPPER32 was non-zero, this temporarily
  176. disables PREF range, which is ok. */
  177. pci_write_config_dword(bridge, PCI_PREF_LIMIT_UPPER32, 0);
  178. /* Set up PREF base/limit. */
  179. pref_mem64 = 0;
  180. bu = lu = 0;
  181. pcibios_resource_to_bus(bridge, &region, bus->resource[2]);
  182. if (bus->resource[2]->flags & IORESOURCE_PREFETCH) {
  183. int width = 8;
  184. l = (region.start >> 16) & 0xfff0;
  185. l |= region.end & 0xfff00000;
  186. if (bus->resource[2]->flags & IORESOURCE_MEM_64) {
  187. pref_mem64 = 1;
  188. bu = upper_32_bits(region.start);
  189. lu = upper_32_bits(region.end);
  190. width = 16;
  191. }
  192. dev_info(&bridge->dev, " PREFETCH window: %#0*llx-%#0*llx\n",
  193. width, (unsigned long long)region.start,
  194. width, (unsigned long long)region.end);
  195. }
  196. else {
  197. l = 0x0000fff0;
  198. dev_info(&bridge->dev, " PREFETCH window: disabled\n");
  199. }
  200. pci_write_config_dword(bridge, PCI_PREF_MEMORY_BASE, l);
  201. if (pref_mem64) {
  202. /* Set the upper 32 bits of PREF base & limit. */
  203. pci_write_config_dword(bridge, PCI_PREF_BASE_UPPER32, bu);
  204. pci_write_config_dword(bridge, PCI_PREF_LIMIT_UPPER32, lu);
  205. }
  206. pci_write_config_word(bridge, PCI_BRIDGE_CONTROL, bus->bridge_ctl);
  207. }
  208. /* Check whether the bridge supports optional I/O and
  209. prefetchable memory ranges. If not, the respective
  210. base/limit registers must be read-only and read as 0. */
  211. static void pci_bridge_check_ranges(struct pci_bus *bus)
  212. {
  213. u16 io;
  214. u32 pmem;
  215. struct pci_dev *bridge = bus->self;
  216. struct resource *b_res;
  217. b_res = &bridge->resource[PCI_BRIDGE_RESOURCES];
  218. b_res[1].flags |= IORESOURCE_MEM;
  219. pci_read_config_word(bridge, PCI_IO_BASE, &io);
  220. if (!io) {
  221. pci_write_config_word(bridge, PCI_IO_BASE, 0xf0f0);
  222. pci_read_config_word(bridge, PCI_IO_BASE, &io);
  223. pci_write_config_word(bridge, PCI_IO_BASE, 0x0);
  224. }
  225. if (io)
  226. b_res[0].flags |= IORESOURCE_IO;
  227. /* DECchip 21050 pass 2 errata: the bridge may miss an address
  228. disconnect boundary by one PCI data phase.
  229. Workaround: do not use prefetching on this device. */
  230. if (bridge->vendor == PCI_VENDOR_ID_DEC && bridge->device == 0x0001)
  231. return;
  232. pci_read_config_dword(bridge, PCI_PREF_MEMORY_BASE, &pmem);
  233. if (!pmem) {
  234. pci_write_config_dword(bridge, PCI_PREF_MEMORY_BASE,
  235. 0xfff0fff0);
  236. pci_read_config_dword(bridge, PCI_PREF_MEMORY_BASE, &pmem);
  237. pci_write_config_dword(bridge, PCI_PREF_MEMORY_BASE, 0x0);
  238. }
  239. if (pmem) {
  240. b_res[2].flags |= IORESOURCE_MEM | IORESOURCE_PREFETCH;
  241. if ((pmem & PCI_PREF_RANGE_TYPE_MASK) == PCI_PREF_RANGE_TYPE_64)
  242. b_res[2].flags |= IORESOURCE_MEM_64;
  243. }
  244. /* double check if bridge does support 64 bit pref */
  245. if (b_res[2].flags & IORESOURCE_MEM_64) {
  246. u32 mem_base_hi, tmp;
  247. pci_read_config_dword(bridge, PCI_PREF_BASE_UPPER32,
  248. &mem_base_hi);
  249. pci_write_config_dword(bridge, PCI_PREF_BASE_UPPER32,
  250. 0xffffffff);
  251. pci_read_config_dword(bridge, PCI_PREF_BASE_UPPER32, &tmp);
  252. if (!tmp)
  253. b_res[2].flags &= ~IORESOURCE_MEM_64;
  254. pci_write_config_dword(bridge, PCI_PREF_BASE_UPPER32,
  255. mem_base_hi);
  256. }
  257. }
  258. /* Helper function for sizing routines: find first available
  259. bus resource of a given type. Note: we intentionally skip
  260. the bus resources which have already been assigned (that is,
  261. have non-NULL parent resource). */
  262. static struct resource *find_free_bus_resource(struct pci_bus *bus, unsigned long type)
  263. {
  264. int i;
  265. struct resource *r;
  266. unsigned long type_mask = IORESOURCE_IO | IORESOURCE_MEM |
  267. IORESOURCE_PREFETCH;
  268. for (i = 0; i < PCI_BUS_NUM_RESOURCES; i++) {
  269. r = bus->resource[i];
  270. if (r == &ioport_resource || r == &iomem_resource)
  271. continue;
  272. if (r && (r->flags & type_mask) == type && !r->parent)
  273. return r;
  274. }
  275. return NULL;
  276. }
  277. /* Sizing the IO windows of the PCI-PCI bridge is trivial,
  278. since these windows have 4K granularity and the IO ranges
  279. of non-bridge PCI devices are limited to 256 bytes.
  280. We must be careful with the ISA aliasing though. */
  281. static void pbus_size_io(struct pci_bus *bus)
  282. {
  283. struct pci_dev *dev;
  284. struct resource *b_res = find_free_bus_resource(bus, IORESOURCE_IO);
  285. unsigned long size = 0, size1 = 0;
  286. if (!b_res)
  287. return;
  288. list_for_each_entry(dev, &bus->devices, bus_list) {
  289. int i;
  290. for (i = 0; i < PCI_NUM_RESOURCES; i++) {
  291. struct resource *r = &dev->resource[i];
  292. unsigned long r_size;
  293. if (r->parent || !(r->flags & IORESOURCE_IO))
  294. continue;
  295. r_size = resource_size(r);
  296. if (r_size < 0x400)
  297. /* Might be re-aligned for ISA */
  298. size += r_size;
  299. else
  300. size1 += r_size;
  301. }
  302. }
  303. /* To be fixed in 2.5: we should have sort of HAVE_ISA
  304. flag in the struct pci_bus. */
  305. #if defined(CONFIG_ISA) || defined(CONFIG_EISA)
  306. size = (size & 0xff) + ((size & ~0xffUL) << 2);
  307. #endif
  308. size = ALIGN(size + size1, 4096);
  309. if (!size) {
  310. b_res->flags = 0;
  311. return;
  312. }
  313. /* Alignment of the IO window is always 4K */
  314. b_res->start = 4096;
  315. b_res->end = b_res->start + size - 1;
  316. b_res->flags |= IORESOURCE_STARTALIGN;
  317. }
  318. /* Calculate the size of the bus and minimal alignment which
  319. guarantees that all child resources fit in this size. */
  320. static int pbus_size_mem(struct pci_bus *bus, unsigned long mask, unsigned long type)
  321. {
  322. struct pci_dev *dev;
  323. resource_size_t min_align, align, size;
  324. resource_size_t aligns[12]; /* Alignments from 1Mb to 2Gb */
  325. int order, max_order;
  326. struct resource *b_res = find_free_bus_resource(bus, type);
  327. unsigned int mem64_mask = 0;
  328. if (!b_res)
  329. return 0;
  330. memset(aligns, 0, sizeof(aligns));
  331. max_order = 0;
  332. size = 0;
  333. mem64_mask = b_res->flags & IORESOURCE_MEM_64;
  334. b_res->flags &= ~IORESOURCE_MEM_64;
  335. list_for_each_entry(dev, &bus->devices, bus_list) {
  336. int i;
  337. for (i = 0; i < PCI_NUM_RESOURCES; i++) {
  338. struct resource *r = &dev->resource[i];
  339. resource_size_t r_size;
  340. if (r->parent || (r->flags & mask) != type)
  341. continue;
  342. r_size = resource_size(r);
  343. /* For bridges size != alignment */
  344. align = pci_resource_alignment(dev, r);
  345. order = __ffs(align) - 20;
  346. if (order > 11) {
  347. dev_warn(&dev->dev, "BAR %d bad alignment %llx: "
  348. "%pR\n", i, (unsigned long long)align, r);
  349. r->flags = 0;
  350. continue;
  351. }
  352. size += r_size;
  353. if (order < 0)
  354. order = 0;
  355. /* Exclude ranges with size > align from
  356. calculation of the alignment. */
  357. if (r_size == align)
  358. aligns[order] += align;
  359. if (order > max_order)
  360. max_order = order;
  361. mem64_mask &= r->flags & IORESOURCE_MEM_64;
  362. }
  363. }
  364. align = 0;
  365. min_align = 0;
  366. for (order = 0; order <= max_order; order++) {
  367. resource_size_t align1 = 1;
  368. align1 <<= (order + 20);
  369. if (!align)
  370. min_align = align1;
  371. else if (ALIGN(align + min_align, min_align) < align1)
  372. min_align = align1 >> 1;
  373. align += aligns[order];
  374. }
  375. size = ALIGN(size, min_align);
  376. if (!size) {
  377. b_res->flags = 0;
  378. return 1;
  379. }
  380. b_res->start = min_align;
  381. b_res->end = size + min_align - 1;
  382. b_res->flags |= IORESOURCE_STARTALIGN;
  383. b_res->flags |= mem64_mask;
  384. return 1;
  385. }
  386. static void pci_bus_size_cardbus(struct pci_bus *bus)
  387. {
  388. struct pci_dev *bridge = bus->self;
  389. struct resource *b_res = &bridge->resource[PCI_BRIDGE_RESOURCES];
  390. u16 ctrl;
  391. /*
  392. * Reserve some resources for CardBus. We reserve
  393. * a fixed amount of bus space for CardBus bridges.
  394. */
  395. b_res[0].start = 0;
  396. b_res[0].end = pci_cardbus_io_size - 1;
  397. b_res[0].flags |= IORESOURCE_IO | IORESOURCE_SIZEALIGN;
  398. b_res[1].start = 0;
  399. b_res[1].end = pci_cardbus_io_size - 1;
  400. b_res[1].flags |= IORESOURCE_IO | IORESOURCE_SIZEALIGN;
  401. /*
  402. * Check whether prefetchable memory is supported
  403. * by this bridge.
  404. */
  405. pci_read_config_word(bridge, PCI_CB_BRIDGE_CONTROL, &ctrl);
  406. if (!(ctrl & PCI_CB_BRIDGE_CTL_PREFETCH_MEM0)) {
  407. ctrl |= PCI_CB_BRIDGE_CTL_PREFETCH_MEM0;
  408. pci_write_config_word(bridge, PCI_CB_BRIDGE_CONTROL, ctrl);
  409. pci_read_config_word(bridge, PCI_CB_BRIDGE_CONTROL, &ctrl);
  410. }
  411. /*
  412. * If we have prefetchable memory support, allocate
  413. * two regions. Otherwise, allocate one region of
  414. * twice the size.
  415. */
  416. if (ctrl & PCI_CB_BRIDGE_CTL_PREFETCH_MEM0) {
  417. b_res[2].start = 0;
  418. b_res[2].end = pci_cardbus_mem_size - 1;
  419. b_res[2].flags |= IORESOURCE_MEM | IORESOURCE_PREFETCH | IORESOURCE_SIZEALIGN;
  420. b_res[3].start = 0;
  421. b_res[3].end = pci_cardbus_mem_size - 1;
  422. b_res[3].flags |= IORESOURCE_MEM | IORESOURCE_SIZEALIGN;
  423. } else {
  424. b_res[3].start = 0;
  425. b_res[3].end = pci_cardbus_mem_size * 2 - 1;
  426. b_res[3].flags |= IORESOURCE_MEM | IORESOURCE_SIZEALIGN;
  427. }
  428. }
  429. void __ref pci_bus_size_bridges(struct pci_bus *bus)
  430. {
  431. struct pci_dev *dev;
  432. unsigned long mask, prefmask;
  433. list_for_each_entry(dev, &bus->devices, bus_list) {
  434. struct pci_bus *b = dev->subordinate;
  435. if (!b)
  436. continue;
  437. switch (dev->class >> 8) {
  438. case PCI_CLASS_BRIDGE_CARDBUS:
  439. pci_bus_size_cardbus(b);
  440. break;
  441. case PCI_CLASS_BRIDGE_PCI:
  442. default:
  443. pci_bus_size_bridges(b);
  444. break;
  445. }
  446. }
  447. /* The root bus? */
  448. if (!bus->self)
  449. return;
  450. switch (bus->self->class >> 8) {
  451. case PCI_CLASS_BRIDGE_CARDBUS:
  452. /* don't size cardbuses yet. */
  453. break;
  454. case PCI_CLASS_BRIDGE_PCI:
  455. pci_bridge_check_ranges(bus);
  456. default:
  457. pbus_size_io(bus);
  458. /* If the bridge supports prefetchable range, size it
  459. separately. If it doesn't, or its prefetchable window
  460. has already been allocated by arch code, try
  461. non-prefetchable range for both types of PCI memory
  462. resources. */
  463. mask = IORESOURCE_MEM;
  464. prefmask = IORESOURCE_MEM | IORESOURCE_PREFETCH;
  465. if (pbus_size_mem(bus, prefmask, prefmask))
  466. mask = prefmask; /* Success, size non-prefetch only. */
  467. pbus_size_mem(bus, mask, IORESOURCE_MEM);
  468. break;
  469. }
  470. }
  471. EXPORT_SYMBOL(pci_bus_size_bridges);
  472. void __ref pci_bus_assign_resources(const struct pci_bus *bus)
  473. {
  474. struct pci_bus *b;
  475. struct pci_dev *dev;
  476. pbus_assign_resources_sorted(bus);
  477. list_for_each_entry(dev, &bus->devices, bus_list) {
  478. b = dev->subordinate;
  479. if (!b)
  480. continue;
  481. pci_bus_assign_resources(b);
  482. switch (dev->class >> 8) {
  483. case PCI_CLASS_BRIDGE_PCI:
  484. pci_setup_bridge(b);
  485. break;
  486. case PCI_CLASS_BRIDGE_CARDBUS:
  487. pci_setup_cardbus(b);
  488. break;
  489. default:
  490. dev_info(&dev->dev, "not setting up bridge for bus "
  491. "%04x:%02x\n", pci_domain_nr(b), b->number);
  492. break;
  493. }
  494. }
  495. }
  496. EXPORT_SYMBOL(pci_bus_assign_resources);
  497. static void pci_bus_dump_res(struct pci_bus *bus)
  498. {
  499. int i;
  500. for (i = 0; i < PCI_BUS_NUM_RESOURCES; i++) {
  501. struct resource *res = bus->resource[i];
  502. if (!res || !res->end)
  503. continue;
  504. dev_printk(KERN_DEBUG, &bus->dev, "resource %d %s %pR\n", i,
  505. (res->flags & IORESOURCE_IO) ? "io: " :
  506. ((res->flags & IORESOURCE_PREFETCH)? "pref mem":"mem:"),
  507. res);
  508. }
  509. }
  510. static void pci_bus_dump_resources(struct pci_bus *bus)
  511. {
  512. struct pci_bus *b;
  513. struct pci_dev *dev;
  514. pci_bus_dump_res(bus);
  515. list_for_each_entry(dev, &bus->devices, bus_list) {
  516. b = dev->subordinate;
  517. if (!b)
  518. continue;
  519. pci_bus_dump_resources(b);
  520. }
  521. }
  522. void __init
  523. pci_assign_unassigned_resources(void)
  524. {
  525. struct pci_bus *bus;
  526. /* Depth first, calculate sizes and alignments of all
  527. subordinate buses. */
  528. list_for_each_entry(bus, &pci_root_buses, node) {
  529. pci_bus_size_bridges(bus);
  530. }
  531. /* Depth last, allocate resources and update the hardware. */
  532. list_for_each_entry(bus, &pci_root_buses, node) {
  533. pci_bus_assign_resources(bus);
  534. pci_enable_bridges(bus);
  535. }
  536. /* dump the resource on buses */
  537. list_for_each_entry(bus, &pci_root_buses, node) {
  538. pci_bus_dump_resources(bus);
  539. }
  540. }