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