setup-bus.c 50 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862
  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. unsigned int pci_flags;
  28. struct pci_dev_resource {
  29. struct list_head list;
  30. struct resource *res;
  31. struct pci_dev *dev;
  32. resource_size_t start;
  33. resource_size_t end;
  34. resource_size_t add_size;
  35. resource_size_t min_align;
  36. unsigned long flags;
  37. };
  38. static void free_list(struct list_head *head)
  39. {
  40. struct pci_dev_resource *dev_res, *tmp;
  41. list_for_each_entry_safe(dev_res, tmp, head, list) {
  42. list_del(&dev_res->list);
  43. kfree(dev_res);
  44. }
  45. }
  46. /**
  47. * add_to_list() - add a new resource tracker to the list
  48. * @head: Head of the list
  49. * @dev: device corresponding to which the resource
  50. * belongs
  51. * @res: The resource to be tracked
  52. * @add_size: additional size to be optionally added
  53. * to the resource
  54. */
  55. static int add_to_list(struct list_head *head,
  56. struct pci_dev *dev, struct resource *res,
  57. resource_size_t add_size, resource_size_t min_align)
  58. {
  59. struct pci_dev_resource *tmp;
  60. tmp = kzalloc(sizeof(*tmp), GFP_KERNEL);
  61. if (!tmp) {
  62. pr_warn("add_to_list: kmalloc() failed!\n");
  63. return -ENOMEM;
  64. }
  65. tmp->res = res;
  66. tmp->dev = dev;
  67. tmp->start = res->start;
  68. tmp->end = res->end;
  69. tmp->flags = res->flags;
  70. tmp->add_size = add_size;
  71. tmp->min_align = min_align;
  72. list_add(&tmp->list, head);
  73. return 0;
  74. }
  75. static void remove_from_list(struct list_head *head,
  76. struct resource *res)
  77. {
  78. struct pci_dev_resource *dev_res, *tmp;
  79. list_for_each_entry_safe(dev_res, tmp, head, list) {
  80. if (dev_res->res == res) {
  81. list_del(&dev_res->list);
  82. kfree(dev_res);
  83. break;
  84. }
  85. }
  86. }
  87. static struct pci_dev_resource *res_to_dev_res(struct list_head *head,
  88. struct resource *res)
  89. {
  90. struct pci_dev_resource *dev_res;
  91. list_for_each_entry(dev_res, head, list) {
  92. if (dev_res->res == res) {
  93. int idx = res - &dev_res->dev->resource[0];
  94. dev_printk(KERN_DEBUG, &dev_res->dev->dev,
  95. "res[%d]=%pR res_to_dev_res add_size %llx min_align %llx\n",
  96. idx, dev_res->res,
  97. (unsigned long long)dev_res->add_size,
  98. (unsigned long long)dev_res->min_align);
  99. return dev_res;
  100. }
  101. }
  102. return NULL;
  103. }
  104. static resource_size_t get_res_add_size(struct list_head *head,
  105. struct resource *res)
  106. {
  107. struct pci_dev_resource *dev_res;
  108. dev_res = res_to_dev_res(head, res);
  109. return dev_res ? dev_res->add_size : 0;
  110. }
  111. static resource_size_t get_res_add_align(struct list_head *head,
  112. struct resource *res)
  113. {
  114. struct pci_dev_resource *dev_res;
  115. dev_res = res_to_dev_res(head, res);
  116. return dev_res ? dev_res->min_align : 0;
  117. }
  118. /* Sort resources by alignment */
  119. static void pdev_sort_resources(struct pci_dev *dev, struct list_head *head)
  120. {
  121. int i;
  122. for (i = 0; i < PCI_NUM_RESOURCES; i++) {
  123. struct resource *r;
  124. struct pci_dev_resource *dev_res, *tmp;
  125. resource_size_t r_align;
  126. struct list_head *n;
  127. r = &dev->resource[i];
  128. if (r->flags & IORESOURCE_PCI_FIXED)
  129. continue;
  130. if (!(r->flags) || r->parent)
  131. continue;
  132. r_align = pci_resource_alignment(dev, r);
  133. if (!r_align) {
  134. dev_warn(&dev->dev, "BAR %d: %pR has bogus alignment\n",
  135. i, r);
  136. continue;
  137. }
  138. tmp = kzalloc(sizeof(*tmp), GFP_KERNEL);
  139. if (!tmp)
  140. panic("pdev_sort_resources(): kmalloc() failed!\n");
  141. tmp->res = r;
  142. tmp->dev = dev;
  143. /* fallback is smallest one or list is empty*/
  144. n = head;
  145. list_for_each_entry(dev_res, head, list) {
  146. resource_size_t align;
  147. align = pci_resource_alignment(dev_res->dev,
  148. dev_res->res);
  149. if (r_align > align) {
  150. n = &dev_res->list;
  151. break;
  152. }
  153. }
  154. /* Insert it just before n*/
  155. list_add_tail(&tmp->list, n);
  156. }
  157. }
  158. static void __dev_sort_resources(struct pci_dev *dev,
  159. struct list_head *head)
  160. {
  161. u16 class = dev->class >> 8;
  162. /* Don't touch classless devices or host bridges or ioapics. */
  163. if (class == PCI_CLASS_NOT_DEFINED || class == PCI_CLASS_BRIDGE_HOST)
  164. return;
  165. /* Don't touch ioapic devices already enabled by firmware */
  166. if (class == PCI_CLASS_SYSTEM_PIC) {
  167. u16 command;
  168. pci_read_config_word(dev, PCI_COMMAND, &command);
  169. if (command & (PCI_COMMAND_IO | PCI_COMMAND_MEMORY))
  170. return;
  171. }
  172. pdev_sort_resources(dev, head);
  173. }
  174. static inline void reset_resource(struct resource *res)
  175. {
  176. res->start = 0;
  177. res->end = 0;
  178. res->flags = 0;
  179. }
  180. /**
  181. * reassign_resources_sorted() - satisfy any additional resource requests
  182. *
  183. * @realloc_head : head of the list tracking requests requiring additional
  184. * resources
  185. * @head : head of the list tracking requests with allocated
  186. * resources
  187. *
  188. * Walk through each element of the realloc_head and try to procure
  189. * additional resources for the element, provided the element
  190. * is in the head list.
  191. */
  192. static void reassign_resources_sorted(struct list_head *realloc_head,
  193. struct list_head *head)
  194. {
  195. struct resource *res;
  196. struct pci_dev_resource *add_res, *tmp;
  197. struct pci_dev_resource *dev_res;
  198. resource_size_t add_size, align;
  199. int idx;
  200. list_for_each_entry_safe(add_res, tmp, realloc_head, list) {
  201. bool found_match = false;
  202. res = add_res->res;
  203. /* skip resource that has been reset */
  204. if (!res->flags)
  205. goto out;
  206. /* skip this resource if not found in head list */
  207. list_for_each_entry(dev_res, head, list) {
  208. if (dev_res->res == res) {
  209. found_match = true;
  210. break;
  211. }
  212. }
  213. if (!found_match)/* just skip */
  214. continue;
  215. idx = res - &add_res->dev->resource[0];
  216. add_size = add_res->add_size;
  217. align = add_res->min_align;
  218. if (!resource_size(res)) {
  219. res->start = align;
  220. res->end = res->start + add_size - 1;
  221. if (pci_assign_resource(add_res->dev, idx))
  222. reset_resource(res);
  223. } else {
  224. res->flags |= add_res->flags &
  225. (IORESOURCE_STARTALIGN|IORESOURCE_SIZEALIGN);
  226. if (pci_reassign_resource(add_res->dev, idx,
  227. add_size, align))
  228. dev_printk(KERN_DEBUG, &add_res->dev->dev,
  229. "failed to add %llx res[%d]=%pR\n",
  230. (unsigned long long)add_size,
  231. idx, res);
  232. }
  233. out:
  234. list_del(&add_res->list);
  235. kfree(add_res);
  236. }
  237. }
  238. /**
  239. * assign_requested_resources_sorted() - satisfy resource requests
  240. *
  241. * @head : head of the list tracking requests for resources
  242. * @fail_head : head of the list tracking requests that could
  243. * not be allocated
  244. *
  245. * Satisfy resource requests of each element in the list. Add
  246. * requests that could not satisfied to the failed_list.
  247. */
  248. static void assign_requested_resources_sorted(struct list_head *head,
  249. struct list_head *fail_head)
  250. {
  251. struct resource *res;
  252. struct pci_dev_resource *dev_res;
  253. int idx;
  254. list_for_each_entry(dev_res, head, list) {
  255. res = dev_res->res;
  256. idx = res - &dev_res->dev->resource[0];
  257. if (resource_size(res) &&
  258. pci_assign_resource(dev_res->dev, idx)) {
  259. if (fail_head) {
  260. /*
  261. * if the failed res is for ROM BAR, and it will
  262. * be enabled later, don't add it to the list
  263. */
  264. if (!((idx == PCI_ROM_RESOURCE) &&
  265. (!(res->flags & IORESOURCE_ROM_ENABLE))))
  266. add_to_list(fail_head,
  267. dev_res->dev, res,
  268. 0 /* don't care */,
  269. 0 /* don't care */);
  270. }
  271. reset_resource(res);
  272. }
  273. }
  274. }
  275. static unsigned long pci_fail_res_type_mask(struct list_head *fail_head)
  276. {
  277. struct pci_dev_resource *fail_res;
  278. unsigned long mask = 0;
  279. /* check failed type */
  280. list_for_each_entry(fail_res, fail_head, list)
  281. mask |= fail_res->flags;
  282. /*
  283. * one pref failed resource will set IORESOURCE_MEM,
  284. * as we can allocate pref in non-pref range.
  285. * Will release all assigned non-pref sibling resources
  286. * according to that bit.
  287. */
  288. return mask & (IORESOURCE_IO | IORESOURCE_MEM | IORESOURCE_PREFETCH);
  289. }
  290. static bool pci_need_to_release(unsigned long mask, struct resource *res)
  291. {
  292. if (res->flags & IORESOURCE_IO)
  293. return !!(mask & IORESOURCE_IO);
  294. /* check pref at first */
  295. if (res->flags & IORESOURCE_PREFETCH) {
  296. if (mask & IORESOURCE_PREFETCH)
  297. return true;
  298. /* count pref if its parent is non-pref */
  299. else if ((mask & IORESOURCE_MEM) &&
  300. !(res->parent->flags & IORESOURCE_PREFETCH))
  301. return true;
  302. else
  303. return false;
  304. }
  305. if (res->flags & IORESOURCE_MEM)
  306. return !!(mask & IORESOURCE_MEM);
  307. return false; /* should not get here */
  308. }
  309. static void __assign_resources_sorted(struct list_head *head,
  310. struct list_head *realloc_head,
  311. struct list_head *fail_head)
  312. {
  313. /*
  314. * Should not assign requested resources at first.
  315. * they could be adjacent, so later reassign can not reallocate
  316. * them one by one in parent resource window.
  317. * Try to assign requested + add_size at beginning
  318. * if could do that, could get out early.
  319. * if could not do that, we still try to assign requested at first,
  320. * then try to reassign add_size for some resources.
  321. *
  322. * Separate three resource type checking if we need to release
  323. * assigned resource after requested + add_size try.
  324. * 1. if there is io port assign fail, will release assigned
  325. * io port.
  326. * 2. if there is pref mmio assign fail, release assigned
  327. * pref mmio.
  328. * if assigned pref mmio's parent is non-pref mmio and there
  329. * is non-pref mmio assign fail, will release that assigned
  330. * pref mmio.
  331. * 3. if there is non-pref mmio assign fail or pref mmio
  332. * assigned fail, will release assigned non-pref mmio.
  333. */
  334. LIST_HEAD(save_head);
  335. LIST_HEAD(local_fail_head);
  336. struct pci_dev_resource *save_res;
  337. struct pci_dev_resource *dev_res, *tmp_res, *dev_res2;
  338. unsigned long fail_type;
  339. resource_size_t add_align, align;
  340. /* Check if optional add_size is there */
  341. if (!realloc_head || list_empty(realloc_head))
  342. goto requested_and_reassign;
  343. /* Save original start, end, flags etc at first */
  344. list_for_each_entry(dev_res, head, list) {
  345. if (add_to_list(&save_head, dev_res->dev, dev_res->res, 0, 0)) {
  346. free_list(&save_head);
  347. goto requested_and_reassign;
  348. }
  349. }
  350. /* Update res in head list with add_size in realloc_head list */
  351. list_for_each_entry_safe(dev_res, tmp_res, head, list) {
  352. dev_res->res->end += get_res_add_size(realloc_head,
  353. dev_res->res);
  354. /*
  355. * There are two kinds of additional resources in the list:
  356. * 1. bridge resource -- IORESOURCE_STARTALIGN
  357. * 2. SR-IOV resource -- IORESOURCE_SIZEALIGN
  358. * Here just fix the additional alignment for bridge
  359. */
  360. if (!(dev_res->res->flags & IORESOURCE_STARTALIGN))
  361. continue;
  362. add_align = get_res_add_align(realloc_head, dev_res->res);
  363. /*
  364. * The "head" list is sorted by the alignment to make sure
  365. * resources with bigger alignment will be assigned first.
  366. * After we change the alignment of a dev_res in "head" list,
  367. * we need to reorder the list by alignment to make it
  368. * consistent.
  369. */
  370. if (add_align > dev_res->res->start) {
  371. resource_size_t r_size = resource_size(dev_res->res);
  372. dev_res->res->start = add_align;
  373. dev_res->res->end = add_align + r_size - 1;
  374. list_for_each_entry(dev_res2, head, list) {
  375. align = pci_resource_alignment(dev_res2->dev,
  376. dev_res2->res);
  377. if (add_align > align) {
  378. list_move_tail(&dev_res->list,
  379. &dev_res2->list);
  380. break;
  381. }
  382. }
  383. }
  384. }
  385. /* Try updated head list with add_size added */
  386. assign_requested_resources_sorted(head, &local_fail_head);
  387. /* all assigned with add_size ? */
  388. if (list_empty(&local_fail_head)) {
  389. /* Remove head list from realloc_head list */
  390. list_for_each_entry(dev_res, head, list)
  391. remove_from_list(realloc_head, dev_res->res);
  392. free_list(&save_head);
  393. free_list(head);
  394. return;
  395. }
  396. /* check failed type */
  397. fail_type = pci_fail_res_type_mask(&local_fail_head);
  398. /* remove not need to be released assigned res from head list etc */
  399. list_for_each_entry_safe(dev_res, tmp_res, head, list)
  400. if (dev_res->res->parent &&
  401. !pci_need_to_release(fail_type, dev_res->res)) {
  402. /* remove it from realloc_head list */
  403. remove_from_list(realloc_head, dev_res->res);
  404. remove_from_list(&save_head, dev_res->res);
  405. list_del(&dev_res->list);
  406. kfree(dev_res);
  407. }
  408. free_list(&local_fail_head);
  409. /* Release assigned resource */
  410. list_for_each_entry(dev_res, head, list)
  411. if (dev_res->res->parent)
  412. release_resource(dev_res->res);
  413. /* Restore start/end/flags from saved list */
  414. list_for_each_entry(save_res, &save_head, list) {
  415. struct resource *res = save_res->res;
  416. res->start = save_res->start;
  417. res->end = save_res->end;
  418. res->flags = save_res->flags;
  419. }
  420. free_list(&save_head);
  421. requested_and_reassign:
  422. /* Satisfy the must-have resource requests */
  423. assign_requested_resources_sorted(head, fail_head);
  424. /* Try to satisfy any additional optional resource
  425. requests */
  426. if (realloc_head)
  427. reassign_resources_sorted(realloc_head, head);
  428. free_list(head);
  429. }
  430. static void pdev_assign_resources_sorted(struct pci_dev *dev,
  431. struct list_head *add_head,
  432. struct list_head *fail_head)
  433. {
  434. LIST_HEAD(head);
  435. __dev_sort_resources(dev, &head);
  436. __assign_resources_sorted(&head, add_head, fail_head);
  437. }
  438. static void pbus_assign_resources_sorted(const struct pci_bus *bus,
  439. struct list_head *realloc_head,
  440. struct list_head *fail_head)
  441. {
  442. struct pci_dev *dev;
  443. LIST_HEAD(head);
  444. list_for_each_entry(dev, &bus->devices, bus_list)
  445. __dev_sort_resources(dev, &head);
  446. __assign_resources_sorted(&head, realloc_head, fail_head);
  447. }
  448. void pci_setup_cardbus(struct pci_bus *bus)
  449. {
  450. struct pci_dev *bridge = bus->self;
  451. struct resource *res;
  452. struct pci_bus_region region;
  453. dev_info(&bridge->dev, "CardBus bridge to %pR\n",
  454. &bus->busn_res);
  455. res = bus->resource[0];
  456. pcibios_resource_to_bus(bridge->bus, &region, res);
  457. if (res->flags & IORESOURCE_IO) {
  458. /*
  459. * The IO resource is allocated a range twice as large as it
  460. * would normally need. This allows us to set both IO regs.
  461. */
  462. dev_info(&bridge->dev, " bridge window %pR\n", res);
  463. pci_write_config_dword(bridge, PCI_CB_IO_BASE_0,
  464. region.start);
  465. pci_write_config_dword(bridge, PCI_CB_IO_LIMIT_0,
  466. region.end);
  467. }
  468. res = bus->resource[1];
  469. pcibios_resource_to_bus(bridge->bus, &region, res);
  470. if (res->flags & IORESOURCE_IO) {
  471. dev_info(&bridge->dev, " bridge window %pR\n", res);
  472. pci_write_config_dword(bridge, PCI_CB_IO_BASE_1,
  473. region.start);
  474. pci_write_config_dword(bridge, PCI_CB_IO_LIMIT_1,
  475. region.end);
  476. }
  477. res = bus->resource[2];
  478. pcibios_resource_to_bus(bridge->bus, &region, res);
  479. if (res->flags & IORESOURCE_MEM) {
  480. dev_info(&bridge->dev, " bridge window %pR\n", res);
  481. pci_write_config_dword(bridge, PCI_CB_MEMORY_BASE_0,
  482. region.start);
  483. pci_write_config_dword(bridge, PCI_CB_MEMORY_LIMIT_0,
  484. region.end);
  485. }
  486. res = bus->resource[3];
  487. pcibios_resource_to_bus(bridge->bus, &region, res);
  488. if (res->flags & IORESOURCE_MEM) {
  489. dev_info(&bridge->dev, " bridge window %pR\n", res);
  490. pci_write_config_dword(bridge, PCI_CB_MEMORY_BASE_1,
  491. region.start);
  492. pci_write_config_dword(bridge, PCI_CB_MEMORY_LIMIT_1,
  493. region.end);
  494. }
  495. }
  496. EXPORT_SYMBOL(pci_setup_cardbus);
  497. /* Initialize bridges with base/limit values we have collected.
  498. PCI-to-PCI Bridge Architecture Specification rev. 1.1 (1998)
  499. requires that if there is no I/O ports or memory behind the
  500. bridge, corresponding range must be turned off by writing base
  501. value greater than limit to the bridge's base/limit registers.
  502. Note: care must be taken when updating I/O base/limit registers
  503. of bridges which support 32-bit I/O. This update requires two
  504. config space writes, so it's quite possible that an I/O window of
  505. the bridge will have some undesirable address (e.g. 0) after the
  506. first write. Ditto 64-bit prefetchable MMIO. */
  507. static void pci_setup_bridge_io(struct pci_dev *bridge)
  508. {
  509. struct resource *res;
  510. struct pci_bus_region region;
  511. unsigned long io_mask;
  512. u8 io_base_lo, io_limit_lo;
  513. u16 l;
  514. u32 io_upper16;
  515. io_mask = PCI_IO_RANGE_MASK;
  516. if (bridge->io_window_1k)
  517. io_mask = PCI_IO_1K_RANGE_MASK;
  518. /* Set up the top and bottom of the PCI I/O segment for this bus. */
  519. res = &bridge->resource[PCI_BRIDGE_RESOURCES + 0];
  520. pcibios_resource_to_bus(bridge->bus, &region, res);
  521. if (res->flags & IORESOURCE_IO) {
  522. pci_read_config_word(bridge, PCI_IO_BASE, &l);
  523. io_base_lo = (region.start >> 8) & io_mask;
  524. io_limit_lo = (region.end >> 8) & io_mask;
  525. l = ((u16) io_limit_lo << 8) | io_base_lo;
  526. /* Set up upper 16 bits of I/O base/limit. */
  527. io_upper16 = (region.end & 0xffff0000) | (region.start >> 16);
  528. dev_info(&bridge->dev, " bridge window %pR\n", res);
  529. } else {
  530. /* Clear upper 16 bits of I/O base/limit. */
  531. io_upper16 = 0;
  532. l = 0x00f0;
  533. }
  534. /* Temporarily disable the I/O range before updating PCI_IO_BASE. */
  535. pci_write_config_dword(bridge, PCI_IO_BASE_UPPER16, 0x0000ffff);
  536. /* Update lower 16 bits of I/O base/limit. */
  537. pci_write_config_word(bridge, PCI_IO_BASE, l);
  538. /* Update upper 16 bits of I/O base/limit. */
  539. pci_write_config_dword(bridge, PCI_IO_BASE_UPPER16, io_upper16);
  540. }
  541. static void pci_setup_bridge_mmio(struct pci_dev *bridge)
  542. {
  543. struct resource *res;
  544. struct pci_bus_region region;
  545. u32 l;
  546. /* Set up the top and bottom of the PCI Memory segment for this bus. */
  547. res = &bridge->resource[PCI_BRIDGE_RESOURCES + 1];
  548. pcibios_resource_to_bus(bridge->bus, &region, res);
  549. if (res->flags & IORESOURCE_MEM) {
  550. l = (region.start >> 16) & 0xfff0;
  551. l |= region.end & 0xfff00000;
  552. dev_info(&bridge->dev, " bridge window %pR\n", res);
  553. } else {
  554. l = 0x0000fff0;
  555. }
  556. pci_write_config_dword(bridge, PCI_MEMORY_BASE, l);
  557. }
  558. static void pci_setup_bridge_mmio_pref(struct pci_dev *bridge)
  559. {
  560. struct resource *res;
  561. struct pci_bus_region region;
  562. u32 l, bu, lu;
  563. /* Clear out the upper 32 bits of PREF limit.
  564. If PCI_PREF_BASE_UPPER32 was non-zero, this temporarily
  565. disables PREF range, which is ok. */
  566. pci_write_config_dword(bridge, PCI_PREF_LIMIT_UPPER32, 0);
  567. /* Set up PREF base/limit. */
  568. bu = lu = 0;
  569. res = &bridge->resource[PCI_BRIDGE_RESOURCES + 2];
  570. pcibios_resource_to_bus(bridge->bus, &region, res);
  571. if (res->flags & IORESOURCE_PREFETCH) {
  572. l = (region.start >> 16) & 0xfff0;
  573. l |= region.end & 0xfff00000;
  574. if (res->flags & IORESOURCE_MEM_64) {
  575. bu = upper_32_bits(region.start);
  576. lu = upper_32_bits(region.end);
  577. }
  578. dev_info(&bridge->dev, " bridge window %pR\n", res);
  579. } else {
  580. l = 0x0000fff0;
  581. }
  582. pci_write_config_dword(bridge, PCI_PREF_MEMORY_BASE, l);
  583. /* Set the upper 32 bits of PREF base & limit. */
  584. pci_write_config_dword(bridge, PCI_PREF_BASE_UPPER32, bu);
  585. pci_write_config_dword(bridge, PCI_PREF_LIMIT_UPPER32, lu);
  586. }
  587. static void __pci_setup_bridge(struct pci_bus *bus, unsigned long type)
  588. {
  589. struct pci_dev *bridge = bus->self;
  590. dev_info(&bridge->dev, "PCI bridge to %pR\n",
  591. &bus->busn_res);
  592. if (type & IORESOURCE_IO)
  593. pci_setup_bridge_io(bridge);
  594. if (type & IORESOURCE_MEM)
  595. pci_setup_bridge_mmio(bridge);
  596. if (type & IORESOURCE_PREFETCH)
  597. pci_setup_bridge_mmio_pref(bridge);
  598. pci_write_config_word(bridge, PCI_BRIDGE_CONTROL, bus->bridge_ctl);
  599. }
  600. void pci_setup_bridge(struct pci_bus *bus)
  601. {
  602. unsigned long type = IORESOURCE_IO | IORESOURCE_MEM |
  603. IORESOURCE_PREFETCH;
  604. __pci_setup_bridge(bus, type);
  605. }
  606. int pci_claim_bridge_resource(struct pci_dev *bridge, int i)
  607. {
  608. if (i < PCI_BRIDGE_RESOURCES || i > PCI_BRIDGE_RESOURCE_END)
  609. return 0;
  610. if (pci_claim_resource(bridge, i) == 0)
  611. return 0; /* claimed the window */
  612. if ((bridge->class >> 8) != PCI_CLASS_BRIDGE_PCI)
  613. return 0;
  614. if (!pci_bus_clip_resource(bridge, i))
  615. return -EINVAL; /* clipping didn't change anything */
  616. switch (i - PCI_BRIDGE_RESOURCES) {
  617. case 0:
  618. pci_setup_bridge_io(bridge);
  619. break;
  620. case 1:
  621. pci_setup_bridge_mmio(bridge);
  622. break;
  623. case 2:
  624. pci_setup_bridge_mmio_pref(bridge);
  625. break;
  626. default:
  627. return -EINVAL;
  628. }
  629. if (pci_claim_resource(bridge, i) == 0)
  630. return 0; /* claimed a smaller window */
  631. return -EINVAL;
  632. }
  633. /* Check whether the bridge supports optional I/O and
  634. prefetchable memory ranges. If not, the respective
  635. base/limit registers must be read-only and read as 0. */
  636. static void pci_bridge_check_ranges(struct pci_bus *bus)
  637. {
  638. u16 io;
  639. u32 pmem;
  640. struct pci_dev *bridge = bus->self;
  641. struct resource *b_res;
  642. b_res = &bridge->resource[PCI_BRIDGE_RESOURCES];
  643. b_res[1].flags |= IORESOURCE_MEM;
  644. pci_read_config_word(bridge, PCI_IO_BASE, &io);
  645. if (!io) {
  646. pci_write_config_word(bridge, PCI_IO_BASE, 0xe0f0);
  647. pci_read_config_word(bridge, PCI_IO_BASE, &io);
  648. pci_write_config_word(bridge, PCI_IO_BASE, 0x0);
  649. }
  650. if (io)
  651. b_res[0].flags |= IORESOURCE_IO;
  652. /* DECchip 21050 pass 2 errata: the bridge may miss an address
  653. disconnect boundary by one PCI data phase.
  654. Workaround: do not use prefetching on this device. */
  655. if (bridge->vendor == PCI_VENDOR_ID_DEC && bridge->device == 0x0001)
  656. return;
  657. pci_read_config_dword(bridge, PCI_PREF_MEMORY_BASE, &pmem);
  658. if (!pmem) {
  659. pci_write_config_dword(bridge, PCI_PREF_MEMORY_BASE,
  660. 0xffe0fff0);
  661. pci_read_config_dword(bridge, PCI_PREF_MEMORY_BASE, &pmem);
  662. pci_write_config_dword(bridge, PCI_PREF_MEMORY_BASE, 0x0);
  663. }
  664. if (pmem) {
  665. b_res[2].flags |= IORESOURCE_MEM | IORESOURCE_PREFETCH;
  666. if ((pmem & PCI_PREF_RANGE_TYPE_MASK) ==
  667. PCI_PREF_RANGE_TYPE_64) {
  668. b_res[2].flags |= IORESOURCE_MEM_64;
  669. b_res[2].flags |= PCI_PREF_RANGE_TYPE_64;
  670. }
  671. }
  672. /* double check if bridge does support 64 bit pref */
  673. if (b_res[2].flags & IORESOURCE_MEM_64) {
  674. u32 mem_base_hi, tmp;
  675. pci_read_config_dword(bridge, PCI_PREF_BASE_UPPER32,
  676. &mem_base_hi);
  677. pci_write_config_dword(bridge, PCI_PREF_BASE_UPPER32,
  678. 0xffffffff);
  679. pci_read_config_dword(bridge, PCI_PREF_BASE_UPPER32, &tmp);
  680. if (!tmp)
  681. b_res[2].flags &= ~IORESOURCE_MEM_64;
  682. pci_write_config_dword(bridge, PCI_PREF_BASE_UPPER32,
  683. mem_base_hi);
  684. }
  685. }
  686. /* Helper function for sizing routines: find first available
  687. bus resource of a given type. Note: we intentionally skip
  688. the bus resources which have already been assigned (that is,
  689. have non-NULL parent resource). */
  690. static struct resource *find_free_bus_resource(struct pci_bus *bus,
  691. unsigned long type_mask, unsigned long type)
  692. {
  693. int i;
  694. struct resource *r;
  695. pci_bus_for_each_resource(bus, r, i) {
  696. if (r == &ioport_resource || r == &iomem_resource)
  697. continue;
  698. if (r && (r->flags & type_mask) == type && !r->parent)
  699. return r;
  700. }
  701. return NULL;
  702. }
  703. static resource_size_t calculate_iosize(resource_size_t size,
  704. resource_size_t min_size,
  705. resource_size_t size1,
  706. resource_size_t old_size,
  707. resource_size_t align)
  708. {
  709. if (size < min_size)
  710. size = min_size;
  711. if (old_size == 1)
  712. old_size = 0;
  713. /* To be fixed in 2.5: we should have sort of HAVE_ISA
  714. flag in the struct pci_bus. */
  715. #if defined(CONFIG_ISA) || defined(CONFIG_EISA)
  716. size = (size & 0xff) + ((size & ~0xffUL) << 2);
  717. #endif
  718. size = ALIGN(size + size1, align);
  719. if (size < old_size)
  720. size = old_size;
  721. return size;
  722. }
  723. static resource_size_t calculate_memsize(resource_size_t size,
  724. resource_size_t min_size,
  725. resource_size_t size1,
  726. resource_size_t old_size,
  727. resource_size_t align)
  728. {
  729. if (size < min_size)
  730. size = min_size;
  731. if (old_size == 1)
  732. old_size = 0;
  733. if (size < old_size)
  734. size = old_size;
  735. size = ALIGN(size + size1, align);
  736. return size;
  737. }
  738. resource_size_t __weak pcibios_window_alignment(struct pci_bus *bus,
  739. unsigned long type)
  740. {
  741. return 1;
  742. }
  743. #define PCI_P2P_DEFAULT_MEM_ALIGN 0x100000 /* 1MiB */
  744. #define PCI_P2P_DEFAULT_IO_ALIGN 0x1000 /* 4KiB */
  745. #define PCI_P2P_DEFAULT_IO_ALIGN_1K 0x400 /* 1KiB */
  746. static resource_size_t window_alignment(struct pci_bus *bus,
  747. unsigned long type)
  748. {
  749. resource_size_t align = 1, arch_align;
  750. if (type & IORESOURCE_MEM)
  751. align = PCI_P2P_DEFAULT_MEM_ALIGN;
  752. else if (type & IORESOURCE_IO) {
  753. /*
  754. * Per spec, I/O windows are 4K-aligned, but some
  755. * bridges have an extension to support 1K alignment.
  756. */
  757. if (bus->self->io_window_1k)
  758. align = PCI_P2P_DEFAULT_IO_ALIGN_1K;
  759. else
  760. align = PCI_P2P_DEFAULT_IO_ALIGN;
  761. }
  762. arch_align = pcibios_window_alignment(bus, type);
  763. return max(align, arch_align);
  764. }
  765. /**
  766. * pbus_size_io() - size the io window of a given bus
  767. *
  768. * @bus : the bus
  769. * @min_size : the minimum io window that must to be allocated
  770. * @add_size : additional optional io window
  771. * @realloc_head : track the additional io window on this list
  772. *
  773. * Sizing the IO windows of the PCI-PCI bridge is trivial,
  774. * since these windows have 1K or 4K granularity and the IO ranges
  775. * of non-bridge PCI devices are limited to 256 bytes.
  776. * We must be careful with the ISA aliasing though.
  777. */
  778. static void pbus_size_io(struct pci_bus *bus, resource_size_t min_size,
  779. resource_size_t add_size, struct list_head *realloc_head)
  780. {
  781. struct pci_dev *dev;
  782. struct resource *b_res = find_free_bus_resource(bus, IORESOURCE_IO,
  783. IORESOURCE_IO);
  784. resource_size_t size = 0, size0 = 0, size1 = 0;
  785. resource_size_t children_add_size = 0;
  786. resource_size_t min_align, align;
  787. if (!b_res)
  788. return;
  789. min_align = window_alignment(bus, IORESOURCE_IO);
  790. list_for_each_entry(dev, &bus->devices, bus_list) {
  791. int i;
  792. for (i = 0; i < PCI_NUM_RESOURCES; i++) {
  793. struct resource *r = &dev->resource[i];
  794. unsigned long r_size;
  795. if (r->parent || !(r->flags & IORESOURCE_IO))
  796. continue;
  797. r_size = resource_size(r);
  798. if (r_size < 0x400)
  799. /* Might be re-aligned for ISA */
  800. size += r_size;
  801. else
  802. size1 += r_size;
  803. align = pci_resource_alignment(dev, r);
  804. if (align > min_align)
  805. min_align = align;
  806. if (realloc_head)
  807. children_add_size += get_res_add_size(realloc_head, r);
  808. }
  809. }
  810. size0 = calculate_iosize(size, min_size, size1,
  811. resource_size(b_res), min_align);
  812. if (children_add_size > add_size)
  813. add_size = children_add_size;
  814. size1 = (!realloc_head || (realloc_head && !add_size)) ? size0 :
  815. calculate_iosize(size, min_size, add_size + size1,
  816. resource_size(b_res), min_align);
  817. if (!size0 && !size1) {
  818. if (b_res->start || b_res->end)
  819. dev_info(&bus->self->dev, "disabling bridge window %pR to %pR (unused)\n",
  820. b_res, &bus->busn_res);
  821. b_res->flags = 0;
  822. return;
  823. }
  824. b_res->start = min_align;
  825. b_res->end = b_res->start + size0 - 1;
  826. b_res->flags |= IORESOURCE_STARTALIGN;
  827. if (size1 > size0 && realloc_head) {
  828. add_to_list(realloc_head, bus->self, b_res, size1-size0,
  829. min_align);
  830. dev_printk(KERN_DEBUG, &bus->self->dev, "bridge window %pR to %pR add_size %llx\n",
  831. b_res, &bus->busn_res,
  832. (unsigned long long)size1-size0);
  833. }
  834. }
  835. static inline resource_size_t calculate_mem_align(resource_size_t *aligns,
  836. int max_order)
  837. {
  838. resource_size_t align = 0;
  839. resource_size_t min_align = 0;
  840. int order;
  841. for (order = 0; order <= max_order; order++) {
  842. resource_size_t align1 = 1;
  843. align1 <<= (order + 20);
  844. if (!align)
  845. min_align = align1;
  846. else if (ALIGN(align + min_align, min_align) < align1)
  847. min_align = align1 >> 1;
  848. align += aligns[order];
  849. }
  850. return min_align;
  851. }
  852. /**
  853. * pbus_size_mem() - size the memory window of a given bus
  854. *
  855. * @bus : the bus
  856. * @mask: mask the resource flag, then compare it with type
  857. * @type: the type of free resource from bridge
  858. * @type2: second match type
  859. * @type3: third match type
  860. * @min_size : the minimum memory window that must to be allocated
  861. * @add_size : additional optional memory window
  862. * @realloc_head : track the additional memory window on this list
  863. *
  864. * Calculate the size of the bus and minimal alignment which
  865. * guarantees that all child resources fit in this size.
  866. *
  867. * Returns -ENOSPC if there's no available bus resource of the desired type.
  868. * Otherwise, sets the bus resource start/end to indicate the required
  869. * size, adds things to realloc_head (if supplied), and returns 0.
  870. */
  871. static int pbus_size_mem(struct pci_bus *bus, unsigned long mask,
  872. unsigned long type, unsigned long type2,
  873. unsigned long type3,
  874. resource_size_t min_size, resource_size_t add_size,
  875. struct list_head *realloc_head)
  876. {
  877. struct pci_dev *dev;
  878. resource_size_t min_align, align, size, size0, size1;
  879. resource_size_t aligns[18]; /* Alignments from 1Mb to 128Gb */
  880. int order, max_order;
  881. struct resource *b_res = find_free_bus_resource(bus,
  882. mask | IORESOURCE_PREFETCH, type);
  883. resource_size_t children_add_size = 0;
  884. resource_size_t children_add_align = 0;
  885. resource_size_t add_align = 0;
  886. if (!b_res)
  887. return -ENOSPC;
  888. memset(aligns, 0, sizeof(aligns));
  889. max_order = 0;
  890. size = 0;
  891. list_for_each_entry(dev, &bus->devices, bus_list) {
  892. int i;
  893. for (i = 0; i < PCI_NUM_RESOURCES; i++) {
  894. struct resource *r = &dev->resource[i];
  895. resource_size_t r_size;
  896. if (r->parent || (r->flags & IORESOURCE_PCI_FIXED) ||
  897. ((r->flags & mask) != type &&
  898. (r->flags & mask) != type2 &&
  899. (r->flags & mask) != type3))
  900. continue;
  901. r_size = resource_size(r);
  902. #ifdef CONFIG_PCI_IOV
  903. /* put SRIOV requested res to the optional list */
  904. if (realloc_head && i >= PCI_IOV_RESOURCES &&
  905. i <= PCI_IOV_RESOURCE_END) {
  906. add_align = max(pci_resource_alignment(dev, r), add_align);
  907. r->end = r->start - 1;
  908. add_to_list(realloc_head, dev, r, r_size, 0/* don't care */);
  909. children_add_size += r_size;
  910. continue;
  911. }
  912. #endif
  913. /*
  914. * aligns[0] is for 1MB (since bridge memory
  915. * windows are always at least 1MB aligned), so
  916. * keep "order" from being negative for smaller
  917. * resources.
  918. */
  919. align = pci_resource_alignment(dev, r);
  920. order = __ffs(align) - 20;
  921. if (order < 0)
  922. order = 0;
  923. if (order >= ARRAY_SIZE(aligns)) {
  924. dev_warn(&dev->dev, "disabling BAR %d: %pR (bad alignment %#llx)\n",
  925. i, r, (unsigned long long) align);
  926. r->flags = 0;
  927. continue;
  928. }
  929. size += r_size;
  930. /* Exclude ranges with size > align from
  931. calculation of the alignment. */
  932. if (r_size == align)
  933. aligns[order] += align;
  934. if (order > max_order)
  935. max_order = order;
  936. if (realloc_head) {
  937. children_add_size += get_res_add_size(realloc_head, r);
  938. children_add_align = get_res_add_align(realloc_head, r);
  939. add_align = max(add_align, children_add_align);
  940. }
  941. }
  942. }
  943. min_align = calculate_mem_align(aligns, max_order);
  944. min_align = max(min_align, window_alignment(bus, b_res->flags));
  945. size0 = calculate_memsize(size, min_size, 0, resource_size(b_res), min_align);
  946. add_align = max(min_align, add_align);
  947. if (children_add_size > add_size)
  948. add_size = children_add_size;
  949. size1 = (!realloc_head || (realloc_head && !add_size)) ? size0 :
  950. calculate_memsize(size, min_size, add_size,
  951. resource_size(b_res), add_align);
  952. if (!size0 && !size1) {
  953. if (b_res->start || b_res->end)
  954. dev_info(&bus->self->dev, "disabling bridge window %pR to %pR (unused)\n",
  955. b_res, &bus->busn_res);
  956. b_res->flags = 0;
  957. return 0;
  958. }
  959. b_res->start = min_align;
  960. b_res->end = size0 + min_align - 1;
  961. b_res->flags |= IORESOURCE_STARTALIGN;
  962. if (size1 > size0 && realloc_head) {
  963. add_to_list(realloc_head, bus->self, b_res, size1-size0, add_align);
  964. dev_printk(KERN_DEBUG, &bus->self->dev, "bridge window %pR to %pR add_size %llx add_align %llx\n",
  965. b_res, &bus->busn_res,
  966. (unsigned long long) (size1 - size0),
  967. (unsigned long long) add_align);
  968. }
  969. return 0;
  970. }
  971. unsigned long pci_cardbus_resource_alignment(struct resource *res)
  972. {
  973. if (res->flags & IORESOURCE_IO)
  974. return pci_cardbus_io_size;
  975. if (res->flags & IORESOURCE_MEM)
  976. return pci_cardbus_mem_size;
  977. return 0;
  978. }
  979. static void pci_bus_size_cardbus(struct pci_bus *bus,
  980. struct list_head *realloc_head)
  981. {
  982. struct pci_dev *bridge = bus->self;
  983. struct resource *b_res = &bridge->resource[PCI_BRIDGE_RESOURCES];
  984. resource_size_t b_res_3_size = pci_cardbus_mem_size * 2;
  985. u16 ctrl;
  986. if (b_res[0].parent)
  987. goto handle_b_res_1;
  988. /*
  989. * Reserve some resources for CardBus. We reserve
  990. * a fixed amount of bus space for CardBus bridges.
  991. */
  992. b_res[0].start = pci_cardbus_io_size;
  993. b_res[0].end = b_res[0].start + pci_cardbus_io_size - 1;
  994. b_res[0].flags |= IORESOURCE_IO | IORESOURCE_STARTALIGN;
  995. if (realloc_head) {
  996. b_res[0].end -= pci_cardbus_io_size;
  997. add_to_list(realloc_head, bridge, b_res, pci_cardbus_io_size,
  998. pci_cardbus_io_size);
  999. }
  1000. handle_b_res_1:
  1001. if (b_res[1].parent)
  1002. goto handle_b_res_2;
  1003. b_res[1].start = pci_cardbus_io_size;
  1004. b_res[1].end = b_res[1].start + pci_cardbus_io_size - 1;
  1005. b_res[1].flags |= IORESOURCE_IO | IORESOURCE_STARTALIGN;
  1006. if (realloc_head) {
  1007. b_res[1].end -= pci_cardbus_io_size;
  1008. add_to_list(realloc_head, bridge, b_res+1, pci_cardbus_io_size,
  1009. pci_cardbus_io_size);
  1010. }
  1011. handle_b_res_2:
  1012. /* MEM1 must not be pref mmio */
  1013. pci_read_config_word(bridge, PCI_CB_BRIDGE_CONTROL, &ctrl);
  1014. if (ctrl & PCI_CB_BRIDGE_CTL_PREFETCH_MEM1) {
  1015. ctrl &= ~PCI_CB_BRIDGE_CTL_PREFETCH_MEM1;
  1016. pci_write_config_word(bridge, PCI_CB_BRIDGE_CONTROL, ctrl);
  1017. pci_read_config_word(bridge, PCI_CB_BRIDGE_CONTROL, &ctrl);
  1018. }
  1019. /*
  1020. * Check whether prefetchable memory is supported
  1021. * by this bridge.
  1022. */
  1023. pci_read_config_word(bridge, PCI_CB_BRIDGE_CONTROL, &ctrl);
  1024. if (!(ctrl & PCI_CB_BRIDGE_CTL_PREFETCH_MEM0)) {
  1025. ctrl |= PCI_CB_BRIDGE_CTL_PREFETCH_MEM0;
  1026. pci_write_config_word(bridge, PCI_CB_BRIDGE_CONTROL, ctrl);
  1027. pci_read_config_word(bridge, PCI_CB_BRIDGE_CONTROL, &ctrl);
  1028. }
  1029. if (b_res[2].parent)
  1030. goto handle_b_res_3;
  1031. /*
  1032. * If we have prefetchable memory support, allocate
  1033. * two regions. Otherwise, allocate one region of
  1034. * twice the size.
  1035. */
  1036. if (ctrl & PCI_CB_BRIDGE_CTL_PREFETCH_MEM0) {
  1037. b_res[2].start = pci_cardbus_mem_size;
  1038. b_res[2].end = b_res[2].start + pci_cardbus_mem_size - 1;
  1039. b_res[2].flags |= IORESOURCE_MEM | IORESOURCE_PREFETCH |
  1040. IORESOURCE_STARTALIGN;
  1041. if (realloc_head) {
  1042. b_res[2].end -= pci_cardbus_mem_size;
  1043. add_to_list(realloc_head, bridge, b_res+2,
  1044. pci_cardbus_mem_size, pci_cardbus_mem_size);
  1045. }
  1046. /* reduce that to half */
  1047. b_res_3_size = pci_cardbus_mem_size;
  1048. }
  1049. handle_b_res_3:
  1050. if (b_res[3].parent)
  1051. goto handle_done;
  1052. b_res[3].start = pci_cardbus_mem_size;
  1053. b_res[3].end = b_res[3].start + b_res_3_size - 1;
  1054. b_res[3].flags |= IORESOURCE_MEM | IORESOURCE_STARTALIGN;
  1055. if (realloc_head) {
  1056. b_res[3].end -= b_res_3_size;
  1057. add_to_list(realloc_head, bridge, b_res+3, b_res_3_size,
  1058. pci_cardbus_mem_size);
  1059. }
  1060. handle_done:
  1061. ;
  1062. }
  1063. void __pci_bus_size_bridges(struct pci_bus *bus, struct list_head *realloc_head)
  1064. {
  1065. struct pci_dev *dev;
  1066. unsigned long mask, prefmask, type2 = 0, type3 = 0;
  1067. resource_size_t additional_mem_size = 0, additional_io_size = 0;
  1068. struct resource *b_res;
  1069. int ret;
  1070. list_for_each_entry(dev, &bus->devices, bus_list) {
  1071. struct pci_bus *b = dev->subordinate;
  1072. if (!b)
  1073. continue;
  1074. switch (dev->class >> 8) {
  1075. case PCI_CLASS_BRIDGE_CARDBUS:
  1076. pci_bus_size_cardbus(b, realloc_head);
  1077. break;
  1078. case PCI_CLASS_BRIDGE_PCI:
  1079. default:
  1080. __pci_bus_size_bridges(b, realloc_head);
  1081. break;
  1082. }
  1083. }
  1084. /* The root bus? */
  1085. if (pci_is_root_bus(bus))
  1086. return;
  1087. switch (bus->self->class >> 8) {
  1088. case PCI_CLASS_BRIDGE_CARDBUS:
  1089. /* don't size cardbuses yet. */
  1090. break;
  1091. case PCI_CLASS_BRIDGE_PCI:
  1092. pci_bridge_check_ranges(bus);
  1093. if (bus->self->is_hotplug_bridge) {
  1094. additional_io_size = pci_hotplug_io_size;
  1095. additional_mem_size = pci_hotplug_mem_size;
  1096. }
  1097. /* Fall through */
  1098. default:
  1099. pbus_size_io(bus, realloc_head ? 0 : additional_io_size,
  1100. additional_io_size, realloc_head);
  1101. /*
  1102. * If there's a 64-bit prefetchable MMIO window, compute
  1103. * the size required to put all 64-bit prefetchable
  1104. * resources in it.
  1105. */
  1106. b_res = &bus->self->resource[PCI_BRIDGE_RESOURCES];
  1107. mask = IORESOURCE_MEM;
  1108. prefmask = IORESOURCE_MEM | IORESOURCE_PREFETCH;
  1109. if (b_res[2].flags & IORESOURCE_MEM_64) {
  1110. prefmask |= IORESOURCE_MEM_64;
  1111. ret = pbus_size_mem(bus, prefmask, prefmask,
  1112. prefmask, prefmask,
  1113. realloc_head ? 0 : additional_mem_size,
  1114. additional_mem_size, realloc_head);
  1115. /*
  1116. * If successful, all non-prefetchable resources
  1117. * and any 32-bit prefetchable resources will go in
  1118. * the non-prefetchable window.
  1119. */
  1120. if (ret == 0) {
  1121. mask = prefmask;
  1122. type2 = prefmask & ~IORESOURCE_MEM_64;
  1123. type3 = prefmask & ~IORESOURCE_PREFETCH;
  1124. }
  1125. }
  1126. /*
  1127. * If there is no 64-bit prefetchable window, compute the
  1128. * size required to put all prefetchable resources in the
  1129. * 32-bit prefetchable window (if there is one).
  1130. */
  1131. if (!type2) {
  1132. prefmask &= ~IORESOURCE_MEM_64;
  1133. ret = pbus_size_mem(bus, prefmask, prefmask,
  1134. prefmask, prefmask,
  1135. realloc_head ? 0 : additional_mem_size,
  1136. additional_mem_size, realloc_head);
  1137. /*
  1138. * If successful, only non-prefetchable resources
  1139. * will go in the non-prefetchable window.
  1140. */
  1141. if (ret == 0)
  1142. mask = prefmask;
  1143. else
  1144. additional_mem_size += additional_mem_size;
  1145. type2 = type3 = IORESOURCE_MEM;
  1146. }
  1147. /*
  1148. * Compute the size required to put everything else in the
  1149. * non-prefetchable window. This includes:
  1150. *
  1151. * - all non-prefetchable resources
  1152. * - 32-bit prefetchable resources if there's a 64-bit
  1153. * prefetchable window or no prefetchable window at all
  1154. * - 64-bit prefetchable resources if there's no
  1155. * prefetchable window at all
  1156. *
  1157. * Note that the strategy in __pci_assign_resource() must
  1158. * match that used here. Specifically, we cannot put a
  1159. * 32-bit prefetchable resource in a 64-bit prefetchable
  1160. * window.
  1161. */
  1162. pbus_size_mem(bus, mask, IORESOURCE_MEM, type2, type3,
  1163. realloc_head ? 0 : additional_mem_size,
  1164. additional_mem_size, realloc_head);
  1165. break;
  1166. }
  1167. }
  1168. void pci_bus_size_bridges(struct pci_bus *bus)
  1169. {
  1170. __pci_bus_size_bridges(bus, NULL);
  1171. }
  1172. EXPORT_SYMBOL(pci_bus_size_bridges);
  1173. static void assign_fixed_resource_on_bus(struct pci_bus *b, struct resource *r)
  1174. {
  1175. int i;
  1176. struct resource *parent_r;
  1177. unsigned long mask = IORESOURCE_IO | IORESOURCE_MEM |
  1178. IORESOURCE_PREFETCH;
  1179. pci_bus_for_each_resource(b, parent_r, i) {
  1180. if (!parent_r)
  1181. continue;
  1182. if ((r->flags & mask) == (parent_r->flags & mask) &&
  1183. resource_contains(parent_r, r))
  1184. request_resource(parent_r, r);
  1185. }
  1186. }
  1187. /*
  1188. * Try to assign any resources marked as IORESOURCE_PCI_FIXED, as they
  1189. * are skipped by pbus_assign_resources_sorted().
  1190. */
  1191. static void pdev_assign_fixed_resources(struct pci_dev *dev)
  1192. {
  1193. int i;
  1194. for (i = 0; i < PCI_NUM_RESOURCES; i++) {
  1195. struct pci_bus *b;
  1196. struct resource *r = &dev->resource[i];
  1197. if (r->parent || !(r->flags & IORESOURCE_PCI_FIXED) ||
  1198. !(r->flags & (IORESOURCE_IO | IORESOURCE_MEM)))
  1199. continue;
  1200. b = dev->bus;
  1201. while (b && !r->parent) {
  1202. assign_fixed_resource_on_bus(b, r);
  1203. b = b->parent;
  1204. }
  1205. }
  1206. }
  1207. void __pci_bus_assign_resources(const struct pci_bus *bus,
  1208. struct list_head *realloc_head,
  1209. struct list_head *fail_head)
  1210. {
  1211. struct pci_bus *b;
  1212. struct pci_dev *dev;
  1213. pbus_assign_resources_sorted(bus, realloc_head, fail_head);
  1214. list_for_each_entry(dev, &bus->devices, bus_list) {
  1215. pdev_assign_fixed_resources(dev);
  1216. b = dev->subordinate;
  1217. if (!b)
  1218. continue;
  1219. __pci_bus_assign_resources(b, realloc_head, fail_head);
  1220. switch (dev->class >> 8) {
  1221. case PCI_CLASS_BRIDGE_PCI:
  1222. if (!pci_is_enabled(dev))
  1223. pci_setup_bridge(b);
  1224. break;
  1225. case PCI_CLASS_BRIDGE_CARDBUS:
  1226. pci_setup_cardbus(b);
  1227. break;
  1228. default:
  1229. dev_info(&dev->dev, "not setting up bridge for bus %04x:%02x\n",
  1230. pci_domain_nr(b), b->number);
  1231. break;
  1232. }
  1233. }
  1234. }
  1235. void pci_bus_assign_resources(const struct pci_bus *bus)
  1236. {
  1237. __pci_bus_assign_resources(bus, NULL, NULL);
  1238. }
  1239. EXPORT_SYMBOL(pci_bus_assign_resources);
  1240. static void __pci_bridge_assign_resources(const struct pci_dev *bridge,
  1241. struct list_head *add_head,
  1242. struct list_head *fail_head)
  1243. {
  1244. struct pci_bus *b;
  1245. pdev_assign_resources_sorted((struct pci_dev *)bridge,
  1246. add_head, fail_head);
  1247. b = bridge->subordinate;
  1248. if (!b)
  1249. return;
  1250. __pci_bus_assign_resources(b, add_head, fail_head);
  1251. switch (bridge->class >> 8) {
  1252. case PCI_CLASS_BRIDGE_PCI:
  1253. pci_setup_bridge(b);
  1254. break;
  1255. case PCI_CLASS_BRIDGE_CARDBUS:
  1256. pci_setup_cardbus(b);
  1257. break;
  1258. default:
  1259. dev_info(&bridge->dev, "not setting up bridge for bus %04x:%02x\n",
  1260. pci_domain_nr(b), b->number);
  1261. break;
  1262. }
  1263. }
  1264. static void pci_bridge_release_resources(struct pci_bus *bus,
  1265. unsigned long type)
  1266. {
  1267. struct pci_dev *dev = bus->self;
  1268. struct resource *r;
  1269. unsigned long type_mask = IORESOURCE_IO | IORESOURCE_MEM |
  1270. IORESOURCE_PREFETCH | IORESOURCE_MEM_64;
  1271. unsigned old_flags = 0;
  1272. struct resource *b_res;
  1273. int idx = 1;
  1274. b_res = &dev->resource[PCI_BRIDGE_RESOURCES];
  1275. /*
  1276. * 1. if there is io port assign fail, will release bridge
  1277. * io port.
  1278. * 2. if there is non pref mmio assign fail, release bridge
  1279. * nonpref mmio.
  1280. * 3. if there is 64bit pref mmio assign fail, and bridge pref
  1281. * is 64bit, release bridge pref mmio.
  1282. * 4. if there is pref mmio assign fail, and bridge pref is
  1283. * 32bit mmio, release bridge pref mmio
  1284. * 5. if there is pref mmio assign fail, and bridge pref is not
  1285. * assigned, release bridge nonpref mmio.
  1286. */
  1287. if (type & IORESOURCE_IO)
  1288. idx = 0;
  1289. else if (!(type & IORESOURCE_PREFETCH))
  1290. idx = 1;
  1291. else if ((type & IORESOURCE_MEM_64) &&
  1292. (b_res[2].flags & IORESOURCE_MEM_64))
  1293. idx = 2;
  1294. else if (!(b_res[2].flags & IORESOURCE_MEM_64) &&
  1295. (b_res[2].flags & IORESOURCE_PREFETCH))
  1296. idx = 2;
  1297. else
  1298. idx = 1;
  1299. r = &b_res[idx];
  1300. if (!r->parent)
  1301. return;
  1302. /*
  1303. * if there are children under that, we should release them
  1304. * all
  1305. */
  1306. release_child_resources(r);
  1307. if (!release_resource(r)) {
  1308. type = old_flags = r->flags & type_mask;
  1309. dev_printk(KERN_DEBUG, &dev->dev, "resource %d %pR released\n",
  1310. PCI_BRIDGE_RESOURCES + idx, r);
  1311. /* keep the old size */
  1312. r->end = resource_size(r) - 1;
  1313. r->start = 0;
  1314. r->flags = 0;
  1315. /* avoiding touch the one without PREF */
  1316. if (type & IORESOURCE_PREFETCH)
  1317. type = IORESOURCE_PREFETCH;
  1318. __pci_setup_bridge(bus, type);
  1319. /* for next child res under same bridge */
  1320. r->flags = old_flags;
  1321. }
  1322. }
  1323. enum release_type {
  1324. leaf_only,
  1325. whole_subtree,
  1326. };
  1327. /*
  1328. * try to release pci bridge resources that is from leaf bridge,
  1329. * so we can allocate big new one later
  1330. */
  1331. static void pci_bus_release_bridge_resources(struct pci_bus *bus,
  1332. unsigned long type,
  1333. enum release_type rel_type)
  1334. {
  1335. struct pci_dev *dev;
  1336. bool is_leaf_bridge = true;
  1337. list_for_each_entry(dev, &bus->devices, bus_list) {
  1338. struct pci_bus *b = dev->subordinate;
  1339. if (!b)
  1340. continue;
  1341. is_leaf_bridge = false;
  1342. if ((dev->class >> 8) != PCI_CLASS_BRIDGE_PCI)
  1343. continue;
  1344. if (rel_type == whole_subtree)
  1345. pci_bus_release_bridge_resources(b, type,
  1346. whole_subtree);
  1347. }
  1348. if (pci_is_root_bus(bus))
  1349. return;
  1350. if ((bus->self->class >> 8) != PCI_CLASS_BRIDGE_PCI)
  1351. return;
  1352. if ((rel_type == whole_subtree) || is_leaf_bridge)
  1353. pci_bridge_release_resources(bus, type);
  1354. }
  1355. static void pci_bus_dump_res(struct pci_bus *bus)
  1356. {
  1357. struct resource *res;
  1358. int i;
  1359. pci_bus_for_each_resource(bus, res, i) {
  1360. if (!res || !res->end || !res->flags)
  1361. continue;
  1362. dev_printk(KERN_DEBUG, &bus->dev, "resource %d %pR\n", i, res);
  1363. }
  1364. }
  1365. static void pci_bus_dump_resources(struct pci_bus *bus)
  1366. {
  1367. struct pci_bus *b;
  1368. struct pci_dev *dev;
  1369. pci_bus_dump_res(bus);
  1370. list_for_each_entry(dev, &bus->devices, bus_list) {
  1371. b = dev->subordinate;
  1372. if (!b)
  1373. continue;
  1374. pci_bus_dump_resources(b);
  1375. }
  1376. }
  1377. static int pci_bus_get_depth(struct pci_bus *bus)
  1378. {
  1379. int depth = 0;
  1380. struct pci_bus *child_bus;
  1381. list_for_each_entry(child_bus, &bus->children, node) {
  1382. int ret;
  1383. ret = pci_bus_get_depth(child_bus);
  1384. if (ret + 1 > depth)
  1385. depth = ret + 1;
  1386. }
  1387. return depth;
  1388. }
  1389. /*
  1390. * -1: undefined, will auto detect later
  1391. * 0: disabled by user
  1392. * 1: disabled by auto detect
  1393. * 2: enabled by user
  1394. * 3: enabled by auto detect
  1395. */
  1396. enum enable_type {
  1397. undefined = -1,
  1398. user_disabled,
  1399. auto_disabled,
  1400. user_enabled,
  1401. auto_enabled,
  1402. };
  1403. static enum enable_type pci_realloc_enable = undefined;
  1404. void __init pci_realloc_get_opt(char *str)
  1405. {
  1406. if (!strncmp(str, "off", 3))
  1407. pci_realloc_enable = user_disabled;
  1408. else if (!strncmp(str, "on", 2))
  1409. pci_realloc_enable = user_enabled;
  1410. }
  1411. static bool pci_realloc_enabled(enum enable_type enable)
  1412. {
  1413. return enable >= user_enabled;
  1414. }
  1415. #if defined(CONFIG_PCI_IOV) && defined(CONFIG_PCI_REALLOC_ENABLE_AUTO)
  1416. static int iov_resources_unassigned(struct pci_dev *dev, void *data)
  1417. {
  1418. int i;
  1419. bool *unassigned = data;
  1420. for (i = PCI_IOV_RESOURCES; i <= PCI_IOV_RESOURCE_END; i++) {
  1421. struct resource *r = &dev->resource[i];
  1422. struct pci_bus_region region;
  1423. /* Not assigned or rejected by kernel? */
  1424. if (!r->flags)
  1425. continue;
  1426. pcibios_resource_to_bus(dev->bus, &region, r);
  1427. if (!region.start) {
  1428. *unassigned = true;
  1429. return 1; /* return early from pci_walk_bus() */
  1430. }
  1431. }
  1432. return 0;
  1433. }
  1434. static enum enable_type pci_realloc_detect(struct pci_bus *bus,
  1435. enum enable_type enable_local)
  1436. {
  1437. bool unassigned = false;
  1438. if (enable_local != undefined)
  1439. return enable_local;
  1440. pci_walk_bus(bus, iov_resources_unassigned, &unassigned);
  1441. if (unassigned)
  1442. return auto_enabled;
  1443. return enable_local;
  1444. }
  1445. #else
  1446. static enum enable_type pci_realloc_detect(struct pci_bus *bus,
  1447. enum enable_type enable_local)
  1448. {
  1449. return enable_local;
  1450. }
  1451. #endif
  1452. /*
  1453. * first try will not touch pci bridge res
  1454. * second and later try will clear small leaf bridge res
  1455. * will stop till to the max depth if can not find good one
  1456. */
  1457. void pci_assign_unassigned_root_bus_resources(struct pci_bus *bus)
  1458. {
  1459. LIST_HEAD(realloc_head); /* list of resources that
  1460. want additional resources */
  1461. struct list_head *add_list = NULL;
  1462. int tried_times = 0;
  1463. enum release_type rel_type = leaf_only;
  1464. LIST_HEAD(fail_head);
  1465. struct pci_dev_resource *fail_res;
  1466. unsigned long type_mask = IORESOURCE_IO | IORESOURCE_MEM |
  1467. IORESOURCE_PREFETCH | IORESOURCE_MEM_64;
  1468. int pci_try_num = 1;
  1469. enum enable_type enable_local;
  1470. /* don't realloc if asked to do so */
  1471. enable_local = pci_realloc_detect(bus, pci_realloc_enable);
  1472. if (pci_realloc_enabled(enable_local)) {
  1473. int max_depth = pci_bus_get_depth(bus);
  1474. pci_try_num = max_depth + 1;
  1475. dev_printk(KERN_DEBUG, &bus->dev,
  1476. "max bus depth: %d pci_try_num: %d\n",
  1477. max_depth, pci_try_num);
  1478. }
  1479. again:
  1480. /*
  1481. * last try will use add_list, otherwise will try good to have as
  1482. * must have, so can realloc parent bridge resource
  1483. */
  1484. if (tried_times + 1 == pci_try_num)
  1485. add_list = &realloc_head;
  1486. /* Depth first, calculate sizes and alignments of all
  1487. subordinate buses. */
  1488. __pci_bus_size_bridges(bus, add_list);
  1489. /* Depth last, allocate resources and update the hardware. */
  1490. __pci_bus_assign_resources(bus, add_list, &fail_head);
  1491. if (add_list)
  1492. BUG_ON(!list_empty(add_list));
  1493. tried_times++;
  1494. /* any device complain? */
  1495. if (list_empty(&fail_head))
  1496. goto dump;
  1497. if (tried_times >= pci_try_num) {
  1498. if (enable_local == undefined)
  1499. dev_info(&bus->dev, "Some PCI device resources are unassigned, try booting with pci=realloc\n");
  1500. else if (enable_local == auto_enabled)
  1501. dev_info(&bus->dev, "Automatically enabled pci realloc, if you have problem, try booting with pci=realloc=off\n");
  1502. free_list(&fail_head);
  1503. goto dump;
  1504. }
  1505. dev_printk(KERN_DEBUG, &bus->dev,
  1506. "No. %d try to assign unassigned res\n", tried_times + 1);
  1507. /* third times and later will not check if it is leaf */
  1508. if ((tried_times + 1) > 2)
  1509. rel_type = whole_subtree;
  1510. /*
  1511. * Try to release leaf bridge's resources that doesn't fit resource of
  1512. * child device under that bridge
  1513. */
  1514. list_for_each_entry(fail_res, &fail_head, list)
  1515. pci_bus_release_bridge_resources(fail_res->dev->bus,
  1516. fail_res->flags & type_mask,
  1517. rel_type);
  1518. /* restore size and flags */
  1519. list_for_each_entry(fail_res, &fail_head, list) {
  1520. struct resource *res = fail_res->res;
  1521. res->start = fail_res->start;
  1522. res->end = fail_res->end;
  1523. res->flags = fail_res->flags;
  1524. if (fail_res->dev->subordinate)
  1525. res->flags = 0;
  1526. }
  1527. free_list(&fail_head);
  1528. goto again;
  1529. dump:
  1530. /* dump the resource on buses */
  1531. pci_bus_dump_resources(bus);
  1532. }
  1533. void __init pci_assign_unassigned_resources(void)
  1534. {
  1535. struct pci_bus *root_bus;
  1536. list_for_each_entry(root_bus, &pci_root_buses, node)
  1537. pci_assign_unassigned_root_bus_resources(root_bus);
  1538. }
  1539. void pci_assign_unassigned_bridge_resources(struct pci_dev *bridge)
  1540. {
  1541. struct pci_bus *parent = bridge->subordinate;
  1542. LIST_HEAD(add_list); /* list of resources that
  1543. want additional resources */
  1544. int tried_times = 0;
  1545. LIST_HEAD(fail_head);
  1546. struct pci_dev_resource *fail_res;
  1547. int retval;
  1548. unsigned long type_mask = IORESOURCE_IO | IORESOURCE_MEM |
  1549. IORESOURCE_PREFETCH | IORESOURCE_MEM_64;
  1550. again:
  1551. __pci_bus_size_bridges(parent, &add_list);
  1552. __pci_bridge_assign_resources(bridge, &add_list, &fail_head);
  1553. BUG_ON(!list_empty(&add_list));
  1554. tried_times++;
  1555. if (list_empty(&fail_head))
  1556. goto enable_all;
  1557. if (tried_times >= 2) {
  1558. /* still fail, don't need to try more */
  1559. free_list(&fail_head);
  1560. goto enable_all;
  1561. }
  1562. printk(KERN_DEBUG "PCI: No. %d try to assign unassigned res\n",
  1563. tried_times + 1);
  1564. /*
  1565. * Try to release leaf bridge's resources that doesn't fit resource of
  1566. * child device under that bridge
  1567. */
  1568. list_for_each_entry(fail_res, &fail_head, list)
  1569. pci_bus_release_bridge_resources(fail_res->dev->bus,
  1570. fail_res->flags & type_mask,
  1571. whole_subtree);
  1572. /* restore size and flags */
  1573. list_for_each_entry(fail_res, &fail_head, list) {
  1574. struct resource *res = fail_res->res;
  1575. res->start = fail_res->start;
  1576. res->end = fail_res->end;
  1577. res->flags = fail_res->flags;
  1578. if (fail_res->dev->subordinate)
  1579. res->flags = 0;
  1580. }
  1581. free_list(&fail_head);
  1582. goto again;
  1583. enable_all:
  1584. retval = pci_reenable_device(bridge);
  1585. if (retval)
  1586. dev_err(&bridge->dev, "Error reenabling bridge (%d)\n", retval);
  1587. pci_set_master(bridge);
  1588. }
  1589. EXPORT_SYMBOL_GPL(pci_assign_unassigned_bridge_resources);
  1590. void pci_assign_unassigned_bus_resources(struct pci_bus *bus)
  1591. {
  1592. struct pci_dev *dev;
  1593. LIST_HEAD(add_list); /* list of resources that
  1594. want additional resources */
  1595. down_read(&pci_bus_sem);
  1596. list_for_each_entry(dev, &bus->devices, bus_list)
  1597. if (pci_is_bridge(dev) && pci_has_subordinate(dev))
  1598. __pci_bus_size_bridges(dev->subordinate,
  1599. &add_list);
  1600. up_read(&pci_bus_sem);
  1601. __pci_bus_assign_resources(bus, &add_list, NULL);
  1602. BUG_ON(!list_empty(&add_list));
  1603. }
  1604. EXPORT_SYMBOL_GPL(pci_assign_unassigned_bus_resources);