setup-bus.c 17 KB

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