setup-bus.c 17 KB

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