setup-bus.c 50 KB

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