setup-bus.c 34 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272
  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. struct resource_list_x {
  28. struct resource_list_x *next;
  29. struct resource *res;
  30. struct pci_dev *dev;
  31. resource_size_t start;
  32. resource_size_t end;
  33. resource_size_t add_size;
  34. resource_size_t min_align;
  35. unsigned long flags;
  36. };
  37. #define free_list(type, head) do { \
  38. struct type *list, *tmp; \
  39. for (list = (head)->next; list;) { \
  40. tmp = list; \
  41. list = list->next; \
  42. kfree(tmp); \
  43. } \
  44. (head)->next = NULL; \
  45. } while (0)
  46. int pci_realloc_enable = 0;
  47. #define pci_realloc_enabled() pci_realloc_enable
  48. void pci_realloc(void)
  49. {
  50. pci_realloc_enable = 1;
  51. }
  52. /**
  53. * add_to_list() - add a new resource tracker to the list
  54. * @head: Head of the list
  55. * @dev: device corresponding to which the resource
  56. * belongs
  57. * @res: The resource to be tracked
  58. * @add_size: additional size to be optionally added
  59. * to the resource
  60. */
  61. static int add_to_list(struct resource_list_x *head,
  62. struct pci_dev *dev, struct resource *res,
  63. resource_size_t add_size, resource_size_t min_align)
  64. {
  65. struct resource_list_x *list = head;
  66. struct resource_list_x *ln = list->next;
  67. struct resource_list_x *tmp;
  68. tmp = kmalloc(sizeof(*tmp), GFP_KERNEL);
  69. if (!tmp) {
  70. pr_warning("add_to_list: kmalloc() failed!\n");
  71. return -ENOMEM;
  72. }
  73. tmp->next = ln;
  74. tmp->res = res;
  75. tmp->dev = dev;
  76. tmp->start = res->start;
  77. tmp->end = res->end;
  78. tmp->flags = res->flags;
  79. tmp->add_size = add_size;
  80. tmp->min_align = min_align;
  81. list->next = tmp;
  82. return 0;
  83. }
  84. static void add_to_failed_list(struct resource_list_x *head,
  85. struct pci_dev *dev, struct resource *res)
  86. {
  87. add_to_list(head, dev, res,
  88. 0 /* dont care */,
  89. 0 /* dont care */);
  90. }
  91. static resource_size_t get_res_add_size(struct resource_list_x *realloc_head,
  92. struct resource *res)
  93. {
  94. struct resource_list_x *list;
  95. /* check if it is in realloc_head list */
  96. for (list = realloc_head->next; list && list->res != res;
  97. list = list->next)
  98. ;
  99. if (list)
  100. return list->add_size;
  101. return 0;
  102. }
  103. static void __dev_sort_resources(struct pci_dev *dev,
  104. struct resource_list *head)
  105. {
  106. u16 class = dev->class >> 8;
  107. /* Don't touch classless devices or host bridges or ioapics. */
  108. if (class == PCI_CLASS_NOT_DEFINED || class == PCI_CLASS_BRIDGE_HOST)
  109. return;
  110. /* Don't touch ioapic devices already enabled by firmware */
  111. if (class == PCI_CLASS_SYSTEM_PIC) {
  112. u16 command;
  113. pci_read_config_word(dev, PCI_COMMAND, &command);
  114. if (command & (PCI_COMMAND_IO | PCI_COMMAND_MEMORY))
  115. return;
  116. }
  117. pdev_sort_resources(dev, head);
  118. }
  119. static inline void reset_resource(struct resource *res)
  120. {
  121. res->start = 0;
  122. res->end = 0;
  123. res->flags = 0;
  124. }
  125. /**
  126. * reassign_resources_sorted() - satisfy any additional resource requests
  127. *
  128. * @realloc_head : head of the list tracking requests requiring additional
  129. * resources
  130. * @head : head of the list tracking requests with allocated
  131. * resources
  132. *
  133. * Walk through each element of the realloc_head and try to procure
  134. * additional resources for the element, provided the element
  135. * is in the head list.
  136. */
  137. static void reassign_resources_sorted(struct resource_list_x *realloc_head,
  138. struct resource_list *head)
  139. {
  140. struct resource *res;
  141. struct resource_list_x *list, *tmp, *prev;
  142. struct resource_list *hlist;
  143. resource_size_t add_size;
  144. int idx;
  145. prev = realloc_head;
  146. for (list = realloc_head->next; list;) {
  147. res = list->res;
  148. /* skip resource that has been reset */
  149. if (!res->flags)
  150. goto out;
  151. /* skip this resource if not found in head list */
  152. for (hlist = head->next; hlist && hlist->res != res;
  153. hlist = hlist->next);
  154. if (!hlist) { /* just skip */
  155. prev = list;
  156. list = list->next;
  157. continue;
  158. }
  159. idx = res - &list->dev->resource[0];
  160. add_size=list->add_size;
  161. if (!resource_size(res)) {
  162. res->start = list->start;
  163. res->end = res->start + add_size - 1;
  164. if(pci_assign_resource(list->dev, idx))
  165. reset_resource(res);
  166. } else {
  167. resource_size_t align = list->min_align;
  168. res->flags |= list->flags & (IORESOURCE_STARTALIGN|IORESOURCE_SIZEALIGN);
  169. if (pci_reassign_resource(list->dev, idx, add_size, align))
  170. dev_printk(KERN_DEBUG, &list->dev->dev, "failed to add optional resources res=%pR\n",
  171. res);
  172. }
  173. out:
  174. tmp = list;
  175. prev->next = list = list->next;
  176. kfree(tmp);
  177. }
  178. }
  179. /**
  180. * assign_requested_resources_sorted() - satisfy resource requests
  181. *
  182. * @head : head of the list tracking requests for resources
  183. * @failed_list : head of the list tracking requests that could
  184. * not be allocated
  185. *
  186. * Satisfy resource requests of each element in the list. Add
  187. * requests that could not satisfied to the failed_list.
  188. */
  189. static void assign_requested_resources_sorted(struct resource_list *head,
  190. struct resource_list_x *fail_head)
  191. {
  192. struct resource *res;
  193. struct resource_list *list;
  194. int idx;
  195. for (list = head->next; list; list = list->next) {
  196. res = list->res;
  197. idx = res - &list->dev->resource[0];
  198. if (resource_size(res) && pci_assign_resource(list->dev, idx)) {
  199. if (fail_head && !pci_is_root_bus(list->dev->bus)) {
  200. /*
  201. * if the failed res is for ROM BAR, and it will
  202. * be enabled later, don't add it to the list
  203. */
  204. if (!((idx == PCI_ROM_RESOURCE) &&
  205. (!(res->flags & IORESOURCE_ROM_ENABLE))))
  206. add_to_failed_list(fail_head, list->dev, res);
  207. }
  208. reset_resource(res);
  209. }
  210. }
  211. }
  212. static void __assign_resources_sorted(struct resource_list *head,
  213. struct resource_list_x *realloc_head,
  214. struct resource_list_x *fail_head)
  215. {
  216. /* Satisfy the must-have resource requests */
  217. assign_requested_resources_sorted(head, fail_head);
  218. /* Try to satisfy any additional optional resource
  219. requests */
  220. if (realloc_head)
  221. reassign_resources_sorted(realloc_head, head);
  222. free_list(resource_list, head);
  223. }
  224. static void pdev_assign_resources_sorted(struct pci_dev *dev,
  225. struct resource_list_x *fail_head)
  226. {
  227. struct resource_list head;
  228. head.next = NULL;
  229. __dev_sort_resources(dev, &head);
  230. __assign_resources_sorted(&head, NULL, fail_head);
  231. }
  232. static void pbus_assign_resources_sorted(const struct pci_bus *bus,
  233. struct resource_list_x *realloc_head,
  234. struct resource_list_x *fail_head)
  235. {
  236. struct pci_dev *dev;
  237. struct resource_list head;
  238. head.next = NULL;
  239. list_for_each_entry(dev, &bus->devices, bus_list)
  240. __dev_sort_resources(dev, &head);
  241. __assign_resources_sorted(&head, realloc_head, fail_head);
  242. }
  243. void pci_setup_cardbus(struct pci_bus *bus)
  244. {
  245. struct pci_dev *bridge = bus->self;
  246. struct resource *res;
  247. struct pci_bus_region region;
  248. dev_info(&bridge->dev, "CardBus bridge to [bus %02x-%02x]\n",
  249. bus->secondary, bus->subordinate);
  250. res = bus->resource[0];
  251. pcibios_resource_to_bus(bridge, &region, res);
  252. if (res->flags & IORESOURCE_IO) {
  253. /*
  254. * The IO resource is allocated a range twice as large as it
  255. * would normally need. This allows us to set both IO regs.
  256. */
  257. dev_info(&bridge->dev, " bridge window %pR\n", res);
  258. pci_write_config_dword(bridge, PCI_CB_IO_BASE_0,
  259. region.start);
  260. pci_write_config_dword(bridge, PCI_CB_IO_LIMIT_0,
  261. region.end);
  262. }
  263. res = bus->resource[1];
  264. pcibios_resource_to_bus(bridge, &region, res);
  265. if (res->flags & IORESOURCE_IO) {
  266. dev_info(&bridge->dev, " bridge window %pR\n", res);
  267. pci_write_config_dword(bridge, PCI_CB_IO_BASE_1,
  268. region.start);
  269. pci_write_config_dword(bridge, PCI_CB_IO_LIMIT_1,
  270. region.end);
  271. }
  272. res = bus->resource[2];
  273. pcibios_resource_to_bus(bridge, &region, res);
  274. if (res->flags & IORESOURCE_MEM) {
  275. dev_info(&bridge->dev, " bridge window %pR\n", res);
  276. pci_write_config_dword(bridge, PCI_CB_MEMORY_BASE_0,
  277. region.start);
  278. pci_write_config_dword(bridge, PCI_CB_MEMORY_LIMIT_0,
  279. region.end);
  280. }
  281. res = bus->resource[3];
  282. pcibios_resource_to_bus(bridge, &region, res);
  283. if (res->flags & IORESOURCE_MEM) {
  284. dev_info(&bridge->dev, " bridge window %pR\n", res);
  285. pci_write_config_dword(bridge, PCI_CB_MEMORY_BASE_1,
  286. region.start);
  287. pci_write_config_dword(bridge, PCI_CB_MEMORY_LIMIT_1,
  288. region.end);
  289. }
  290. }
  291. EXPORT_SYMBOL(pci_setup_cardbus);
  292. /* Initialize bridges with base/limit values we have collected.
  293. PCI-to-PCI Bridge Architecture Specification rev. 1.1 (1998)
  294. requires that if there is no I/O ports or memory behind the
  295. bridge, corresponding range must be turned off by writing base
  296. value greater than limit to the bridge's base/limit registers.
  297. Note: care must be taken when updating I/O base/limit registers
  298. of bridges which support 32-bit I/O. This update requires two
  299. config space writes, so it's quite possible that an I/O window of
  300. the bridge will have some undesirable address (e.g. 0) after the
  301. first write. Ditto 64-bit prefetchable MMIO. */
  302. static void pci_setup_bridge_io(struct pci_bus *bus)
  303. {
  304. struct pci_dev *bridge = bus->self;
  305. struct resource *res;
  306. struct pci_bus_region region;
  307. u32 l, io_upper16;
  308. /* Set up the top and bottom of the PCI I/O segment for this bus. */
  309. res = bus->resource[0];
  310. pcibios_resource_to_bus(bridge, &region, res);
  311. if (res->flags & IORESOURCE_IO) {
  312. pci_read_config_dword(bridge, PCI_IO_BASE, &l);
  313. l &= 0xffff0000;
  314. l |= (region.start >> 8) & 0x00f0;
  315. l |= region.end & 0xf000;
  316. /* Set up upper 16 bits of I/O base/limit. */
  317. io_upper16 = (region.end & 0xffff0000) | (region.start >> 16);
  318. dev_info(&bridge->dev, " bridge window %pR\n", res);
  319. } else {
  320. /* Clear upper 16 bits of I/O base/limit. */
  321. io_upper16 = 0;
  322. l = 0x00f0;
  323. }
  324. /* Temporarily disable the I/O range before updating PCI_IO_BASE. */
  325. pci_write_config_dword(bridge, PCI_IO_BASE_UPPER16, 0x0000ffff);
  326. /* Update lower 16 bits of I/O base/limit. */
  327. pci_write_config_dword(bridge, PCI_IO_BASE, l);
  328. /* Update upper 16 bits of I/O base/limit. */
  329. pci_write_config_dword(bridge, PCI_IO_BASE_UPPER16, io_upper16);
  330. }
  331. static void pci_setup_bridge_mmio(struct pci_bus *bus)
  332. {
  333. struct pci_dev *bridge = bus->self;
  334. struct resource *res;
  335. struct pci_bus_region region;
  336. u32 l;
  337. /* Set up the top and bottom of the PCI Memory segment for this bus. */
  338. res = bus->resource[1];
  339. pcibios_resource_to_bus(bridge, &region, res);
  340. if (res->flags & IORESOURCE_MEM) {
  341. l = (region.start >> 16) & 0xfff0;
  342. l |= region.end & 0xfff00000;
  343. dev_info(&bridge->dev, " bridge window %pR\n", res);
  344. } else {
  345. l = 0x0000fff0;
  346. }
  347. pci_write_config_dword(bridge, PCI_MEMORY_BASE, l);
  348. }
  349. static void pci_setup_bridge_mmio_pref(struct pci_bus *bus)
  350. {
  351. struct pci_dev *bridge = bus->self;
  352. struct resource *res;
  353. struct pci_bus_region region;
  354. u32 l, bu, lu;
  355. /* Clear out the upper 32 bits of PREF limit.
  356. If PCI_PREF_BASE_UPPER32 was non-zero, this temporarily
  357. disables PREF range, which is ok. */
  358. pci_write_config_dword(bridge, PCI_PREF_LIMIT_UPPER32, 0);
  359. /* Set up PREF base/limit. */
  360. bu = lu = 0;
  361. res = bus->resource[2];
  362. pcibios_resource_to_bus(bridge, &region, res);
  363. if (res->flags & IORESOURCE_PREFETCH) {
  364. l = (region.start >> 16) & 0xfff0;
  365. l |= region.end & 0xfff00000;
  366. if (res->flags & IORESOURCE_MEM_64) {
  367. bu = upper_32_bits(region.start);
  368. lu = upper_32_bits(region.end);
  369. }
  370. dev_info(&bridge->dev, " bridge window %pR\n", res);
  371. } else {
  372. l = 0x0000fff0;
  373. }
  374. pci_write_config_dword(bridge, PCI_PREF_MEMORY_BASE, l);
  375. /* Set the upper 32 bits of PREF base & limit. */
  376. pci_write_config_dword(bridge, PCI_PREF_BASE_UPPER32, bu);
  377. pci_write_config_dword(bridge, PCI_PREF_LIMIT_UPPER32, lu);
  378. }
  379. static void __pci_setup_bridge(struct pci_bus *bus, unsigned long type)
  380. {
  381. struct pci_dev *bridge = bus->self;
  382. dev_info(&bridge->dev, "PCI bridge to [bus %02x-%02x]\n",
  383. bus->secondary, bus->subordinate);
  384. if (type & IORESOURCE_IO)
  385. pci_setup_bridge_io(bus);
  386. if (type & IORESOURCE_MEM)
  387. pci_setup_bridge_mmio(bus);
  388. if (type & IORESOURCE_PREFETCH)
  389. pci_setup_bridge_mmio_pref(bus);
  390. pci_write_config_word(bridge, PCI_BRIDGE_CONTROL, bus->bridge_ctl);
  391. }
  392. void pci_setup_bridge(struct pci_bus *bus)
  393. {
  394. unsigned long type = IORESOURCE_IO | IORESOURCE_MEM |
  395. IORESOURCE_PREFETCH;
  396. __pci_setup_bridge(bus, type);
  397. }
  398. /* Check whether the bridge supports optional I/O and
  399. prefetchable memory ranges. If not, the respective
  400. base/limit registers must be read-only and read as 0. */
  401. static void pci_bridge_check_ranges(struct pci_bus *bus)
  402. {
  403. u16 io;
  404. u32 pmem;
  405. struct pci_dev *bridge = bus->self;
  406. struct resource *b_res;
  407. b_res = &bridge->resource[PCI_BRIDGE_RESOURCES];
  408. b_res[1].flags |= IORESOURCE_MEM;
  409. pci_read_config_word(bridge, PCI_IO_BASE, &io);
  410. if (!io) {
  411. pci_write_config_word(bridge, PCI_IO_BASE, 0xf0f0);
  412. pci_read_config_word(bridge, PCI_IO_BASE, &io);
  413. pci_write_config_word(bridge, PCI_IO_BASE, 0x0);
  414. }
  415. if (io)
  416. b_res[0].flags |= IORESOURCE_IO;
  417. /* DECchip 21050 pass 2 errata: the bridge may miss an address
  418. disconnect boundary by one PCI data phase.
  419. Workaround: do not use prefetching on this device. */
  420. if (bridge->vendor == PCI_VENDOR_ID_DEC && bridge->device == 0x0001)
  421. return;
  422. pci_read_config_dword(bridge, PCI_PREF_MEMORY_BASE, &pmem);
  423. if (!pmem) {
  424. pci_write_config_dword(bridge, PCI_PREF_MEMORY_BASE,
  425. 0xfff0fff0);
  426. pci_read_config_dword(bridge, PCI_PREF_MEMORY_BASE, &pmem);
  427. pci_write_config_dword(bridge, PCI_PREF_MEMORY_BASE, 0x0);
  428. }
  429. if (pmem) {
  430. b_res[2].flags |= IORESOURCE_MEM | IORESOURCE_PREFETCH;
  431. if ((pmem & PCI_PREF_RANGE_TYPE_MASK) ==
  432. PCI_PREF_RANGE_TYPE_64) {
  433. b_res[2].flags |= IORESOURCE_MEM_64;
  434. b_res[2].flags |= PCI_PREF_RANGE_TYPE_64;
  435. }
  436. }
  437. /* double check if bridge does support 64 bit pref */
  438. if (b_res[2].flags & IORESOURCE_MEM_64) {
  439. u32 mem_base_hi, tmp;
  440. pci_read_config_dword(bridge, PCI_PREF_BASE_UPPER32,
  441. &mem_base_hi);
  442. pci_write_config_dword(bridge, PCI_PREF_BASE_UPPER32,
  443. 0xffffffff);
  444. pci_read_config_dword(bridge, PCI_PREF_BASE_UPPER32, &tmp);
  445. if (!tmp)
  446. b_res[2].flags &= ~IORESOURCE_MEM_64;
  447. pci_write_config_dword(bridge, PCI_PREF_BASE_UPPER32,
  448. mem_base_hi);
  449. }
  450. }
  451. /* Helper function for sizing routines: find first available
  452. bus resource of a given type. Note: we intentionally skip
  453. the bus resources which have already been assigned (that is,
  454. have non-NULL parent resource). */
  455. static struct resource *find_free_bus_resource(struct pci_bus *bus, unsigned long type)
  456. {
  457. int i;
  458. struct resource *r;
  459. unsigned long type_mask = IORESOURCE_IO | IORESOURCE_MEM |
  460. IORESOURCE_PREFETCH;
  461. pci_bus_for_each_resource(bus, r, i) {
  462. if (r == &ioport_resource || r == &iomem_resource)
  463. continue;
  464. if (r && (r->flags & type_mask) == type && !r->parent)
  465. return r;
  466. }
  467. return NULL;
  468. }
  469. static resource_size_t calculate_iosize(resource_size_t size,
  470. resource_size_t min_size,
  471. resource_size_t size1,
  472. resource_size_t old_size,
  473. resource_size_t align)
  474. {
  475. if (size < min_size)
  476. size = min_size;
  477. if (old_size == 1 )
  478. old_size = 0;
  479. /* To be fixed in 2.5: we should have sort of HAVE_ISA
  480. flag in the struct pci_bus. */
  481. #if defined(CONFIG_ISA) || defined(CONFIG_EISA)
  482. size = (size & 0xff) + ((size & ~0xffUL) << 2);
  483. #endif
  484. size = ALIGN(size + size1, align);
  485. if (size < old_size)
  486. size = old_size;
  487. return size;
  488. }
  489. static resource_size_t calculate_memsize(resource_size_t size,
  490. resource_size_t min_size,
  491. resource_size_t size1,
  492. resource_size_t old_size,
  493. resource_size_t align)
  494. {
  495. if (size < min_size)
  496. size = min_size;
  497. if (old_size == 1 )
  498. old_size = 0;
  499. if (size < old_size)
  500. size = old_size;
  501. size = ALIGN(size + size1, align);
  502. return size;
  503. }
  504. /**
  505. * pbus_size_io() - size the io window of a given bus
  506. *
  507. * @bus : the bus
  508. * @min_size : the minimum io window that must to be allocated
  509. * @add_size : additional optional io window
  510. * @realloc_head : track the additional io window on this list
  511. *
  512. * Sizing the IO windows of the PCI-PCI bridge is trivial,
  513. * since these windows have 4K granularity and the IO ranges
  514. * of non-bridge PCI devices are limited to 256 bytes.
  515. * We must be careful with the ISA aliasing though.
  516. */
  517. static void pbus_size_io(struct pci_bus *bus, resource_size_t min_size,
  518. resource_size_t add_size, struct resource_list_x *realloc_head)
  519. {
  520. struct pci_dev *dev;
  521. struct resource *b_res = find_free_bus_resource(bus, IORESOURCE_IO);
  522. unsigned long size = 0, size0 = 0, size1 = 0;
  523. resource_size_t children_add_size = 0;
  524. if (!b_res)
  525. return;
  526. list_for_each_entry(dev, &bus->devices, bus_list) {
  527. int i;
  528. for (i = 0; i < PCI_NUM_RESOURCES; i++) {
  529. struct resource *r = &dev->resource[i];
  530. unsigned long r_size;
  531. if (r->parent || !(r->flags & IORESOURCE_IO))
  532. continue;
  533. r_size = resource_size(r);
  534. if (r_size < 0x400)
  535. /* Might be re-aligned for ISA */
  536. size += r_size;
  537. else
  538. size1 += r_size;
  539. if (realloc_head)
  540. children_add_size += get_res_add_size(realloc_head, r);
  541. }
  542. }
  543. size0 = calculate_iosize(size, min_size, size1,
  544. resource_size(b_res), 4096);
  545. if (children_add_size > add_size)
  546. add_size = children_add_size;
  547. size1 = (!realloc_head || (realloc_head && !add_size)) ? size0 :
  548. calculate_iosize(size, min_size, add_size + size1,
  549. resource_size(b_res), 4096);
  550. if (!size0 && !size1) {
  551. if (b_res->start || b_res->end)
  552. dev_info(&bus->self->dev, "disabling bridge window "
  553. "%pR to [bus %02x-%02x] (unused)\n", b_res,
  554. bus->secondary, bus->subordinate);
  555. b_res->flags = 0;
  556. return;
  557. }
  558. /* Alignment of the IO window is always 4K */
  559. b_res->start = 4096;
  560. b_res->end = b_res->start + size0 - 1;
  561. b_res->flags |= IORESOURCE_STARTALIGN;
  562. if (size1 > size0 && realloc_head)
  563. add_to_list(realloc_head, bus->self, b_res, size1-size0, 4096);
  564. }
  565. /**
  566. * pbus_size_mem() - size the memory window of a given bus
  567. *
  568. * @bus : the bus
  569. * @min_size : the minimum memory window that must to be allocated
  570. * @add_size : additional optional memory window
  571. * @realloc_head : track the additional memory window on this list
  572. *
  573. * Calculate the size of the bus and minimal alignment which
  574. * guarantees that all child resources fit in this size.
  575. */
  576. static int pbus_size_mem(struct pci_bus *bus, unsigned long mask,
  577. unsigned long type, resource_size_t min_size,
  578. resource_size_t add_size,
  579. struct resource_list_x *realloc_head)
  580. {
  581. struct pci_dev *dev;
  582. resource_size_t min_align, align, size, size0, size1;
  583. resource_size_t aligns[12]; /* Alignments from 1Mb to 2Gb */
  584. int order, max_order;
  585. struct resource *b_res = find_free_bus_resource(bus, type);
  586. unsigned int mem64_mask = 0;
  587. resource_size_t children_add_size = 0;
  588. if (!b_res)
  589. return 0;
  590. memset(aligns, 0, sizeof(aligns));
  591. max_order = 0;
  592. size = 0;
  593. mem64_mask = b_res->flags & IORESOURCE_MEM_64;
  594. b_res->flags &= ~IORESOURCE_MEM_64;
  595. list_for_each_entry(dev, &bus->devices, bus_list) {
  596. int i;
  597. for (i = 0; i < PCI_NUM_RESOURCES; i++) {
  598. struct resource *r = &dev->resource[i];
  599. resource_size_t r_size;
  600. if (r->parent || (r->flags & mask) != type)
  601. continue;
  602. r_size = resource_size(r);
  603. #ifdef CONFIG_PCI_IOV
  604. /* put SRIOV requested res to the optional list */
  605. if (realloc_head && i >= PCI_IOV_RESOURCES &&
  606. i <= PCI_IOV_RESOURCE_END) {
  607. r->end = r->start - 1;
  608. add_to_list(realloc_head, dev, r, r_size, 0/* dont' care */);
  609. children_add_size += r_size;
  610. continue;
  611. }
  612. #endif
  613. /* For bridges size != alignment */
  614. align = pci_resource_alignment(dev, r);
  615. order = __ffs(align) - 20;
  616. if (order > 11) {
  617. dev_warn(&dev->dev, "disabling BAR %d: %pR "
  618. "(bad alignment %#llx)\n", i, r,
  619. (unsigned long long) align);
  620. r->flags = 0;
  621. continue;
  622. }
  623. size += r_size;
  624. if (order < 0)
  625. order = 0;
  626. /* Exclude ranges with size > align from
  627. calculation of the alignment. */
  628. if (r_size == align)
  629. aligns[order] += align;
  630. if (order > max_order)
  631. max_order = order;
  632. mem64_mask &= r->flags & IORESOURCE_MEM_64;
  633. if (realloc_head)
  634. children_add_size += get_res_add_size(realloc_head, r);
  635. }
  636. }
  637. align = 0;
  638. min_align = 0;
  639. for (order = 0; order <= max_order; order++) {
  640. resource_size_t align1 = 1;
  641. align1 <<= (order + 20);
  642. if (!align)
  643. min_align = align1;
  644. else if (ALIGN(align + min_align, min_align) < align1)
  645. min_align = align1 >> 1;
  646. align += aligns[order];
  647. }
  648. size0 = calculate_memsize(size, min_size, 0, resource_size(b_res), min_align);
  649. if (children_add_size > add_size)
  650. add_size = children_add_size;
  651. size1 = (!realloc_head || (realloc_head && !add_size)) ? size0 :
  652. calculate_memsize(size, min_size, add_size,
  653. resource_size(b_res), min_align);
  654. if (!size0 && !size1) {
  655. if (b_res->start || b_res->end)
  656. dev_info(&bus->self->dev, "disabling bridge window "
  657. "%pR to [bus %02x-%02x] (unused)\n", b_res,
  658. bus->secondary, bus->subordinate);
  659. b_res->flags = 0;
  660. return 1;
  661. }
  662. b_res->start = min_align;
  663. b_res->end = size0 + min_align - 1;
  664. b_res->flags |= IORESOURCE_STARTALIGN | mem64_mask;
  665. if (size1 > size0 && realloc_head)
  666. add_to_list(realloc_head, bus->self, b_res, size1-size0, min_align);
  667. return 1;
  668. }
  669. unsigned long pci_cardbus_resource_alignment(struct resource *res)
  670. {
  671. if (res->flags & IORESOURCE_IO)
  672. return pci_cardbus_io_size;
  673. if (res->flags & IORESOURCE_MEM)
  674. return pci_cardbus_mem_size;
  675. return 0;
  676. }
  677. static void pci_bus_size_cardbus(struct pci_bus *bus,
  678. struct resource_list_x *realloc_head)
  679. {
  680. struct pci_dev *bridge = bus->self;
  681. struct resource *b_res = &bridge->resource[PCI_BRIDGE_RESOURCES];
  682. u16 ctrl;
  683. /*
  684. * Reserve some resources for CardBus. We reserve
  685. * a fixed amount of bus space for CardBus bridges.
  686. */
  687. b_res[0].start = 0;
  688. b_res[0].flags |= IORESOURCE_IO | IORESOURCE_SIZEALIGN;
  689. if (realloc_head)
  690. add_to_list(realloc_head, bridge, b_res, pci_cardbus_io_size, 0 /* dont care */);
  691. b_res[1].start = 0;
  692. b_res[1].flags |= IORESOURCE_IO | IORESOURCE_SIZEALIGN;
  693. if (realloc_head)
  694. add_to_list(realloc_head, bridge, b_res+1, pci_cardbus_io_size, 0 /* dont care */);
  695. /*
  696. * Check whether prefetchable memory is supported
  697. * by this bridge.
  698. */
  699. pci_read_config_word(bridge, PCI_CB_BRIDGE_CONTROL, &ctrl);
  700. if (!(ctrl & PCI_CB_BRIDGE_CTL_PREFETCH_MEM0)) {
  701. ctrl |= PCI_CB_BRIDGE_CTL_PREFETCH_MEM0;
  702. pci_write_config_word(bridge, PCI_CB_BRIDGE_CONTROL, ctrl);
  703. pci_read_config_word(bridge, PCI_CB_BRIDGE_CONTROL, &ctrl);
  704. }
  705. /*
  706. * If we have prefetchable memory support, allocate
  707. * two regions. Otherwise, allocate one region of
  708. * twice the size.
  709. */
  710. if (ctrl & PCI_CB_BRIDGE_CTL_PREFETCH_MEM0) {
  711. b_res[2].start = 0;
  712. b_res[2].flags |= IORESOURCE_MEM | IORESOURCE_PREFETCH | IORESOURCE_SIZEALIGN;
  713. if (realloc_head)
  714. add_to_list(realloc_head, bridge, b_res+2, pci_cardbus_mem_size, 0 /* dont care */);
  715. b_res[3].start = 0;
  716. b_res[3].flags |= IORESOURCE_MEM | IORESOURCE_SIZEALIGN;
  717. if (realloc_head)
  718. add_to_list(realloc_head, bridge, b_res+3, pci_cardbus_mem_size, 0 /* dont care */);
  719. } else {
  720. b_res[3].start = 0;
  721. b_res[3].flags |= IORESOURCE_MEM | IORESOURCE_SIZEALIGN;
  722. if (realloc_head)
  723. add_to_list(realloc_head, bridge, b_res+3, pci_cardbus_mem_size * 2, 0 /* dont care */);
  724. }
  725. /* set the size of the resource to zero, so that the resource does not
  726. * get assigned during required-resource allocation cycle but gets assigned
  727. * during the optional-resource allocation cycle.
  728. */
  729. b_res[0].start = b_res[1].start = b_res[2].start = b_res[3].start = 1;
  730. b_res[0].end = b_res[1].end = b_res[2].end = b_res[3].end = 0;
  731. }
  732. void __ref __pci_bus_size_bridges(struct pci_bus *bus,
  733. struct resource_list_x *realloc_head)
  734. {
  735. struct pci_dev *dev;
  736. unsigned long mask, prefmask;
  737. resource_size_t additional_mem_size = 0, additional_io_size = 0;
  738. list_for_each_entry(dev, &bus->devices, bus_list) {
  739. struct pci_bus *b = dev->subordinate;
  740. if (!b)
  741. continue;
  742. switch (dev->class >> 8) {
  743. case PCI_CLASS_BRIDGE_CARDBUS:
  744. pci_bus_size_cardbus(b, realloc_head);
  745. break;
  746. case PCI_CLASS_BRIDGE_PCI:
  747. default:
  748. __pci_bus_size_bridges(b, realloc_head);
  749. break;
  750. }
  751. }
  752. /* The root bus? */
  753. if (!bus->self)
  754. return;
  755. switch (bus->self->class >> 8) {
  756. case PCI_CLASS_BRIDGE_CARDBUS:
  757. /* don't size cardbuses yet. */
  758. break;
  759. case PCI_CLASS_BRIDGE_PCI:
  760. pci_bridge_check_ranges(bus);
  761. if (bus->self->is_hotplug_bridge) {
  762. additional_io_size = pci_hotplug_io_size;
  763. additional_mem_size = pci_hotplug_mem_size;
  764. }
  765. /*
  766. * Follow thru
  767. */
  768. default:
  769. pbus_size_io(bus, 0, additional_io_size, realloc_head);
  770. /* If the bridge supports prefetchable range, size it
  771. separately. If it doesn't, or its prefetchable window
  772. has already been allocated by arch code, try
  773. non-prefetchable range for both types of PCI memory
  774. resources. */
  775. mask = IORESOURCE_MEM;
  776. prefmask = IORESOURCE_MEM | IORESOURCE_PREFETCH;
  777. if (pbus_size_mem(bus, prefmask, prefmask, 0, additional_mem_size, realloc_head))
  778. mask = prefmask; /* Success, size non-prefetch only. */
  779. else
  780. additional_mem_size += additional_mem_size;
  781. pbus_size_mem(bus, mask, IORESOURCE_MEM, 0, additional_mem_size, realloc_head);
  782. break;
  783. }
  784. }
  785. void __ref pci_bus_size_bridges(struct pci_bus *bus)
  786. {
  787. __pci_bus_size_bridges(bus, NULL);
  788. }
  789. EXPORT_SYMBOL(pci_bus_size_bridges);
  790. static void __ref __pci_bus_assign_resources(const struct pci_bus *bus,
  791. struct resource_list_x *realloc_head,
  792. struct resource_list_x *fail_head)
  793. {
  794. struct pci_bus *b;
  795. struct pci_dev *dev;
  796. pbus_assign_resources_sorted(bus, realloc_head, fail_head);
  797. list_for_each_entry(dev, &bus->devices, bus_list) {
  798. b = dev->subordinate;
  799. if (!b)
  800. continue;
  801. __pci_bus_assign_resources(b, realloc_head, fail_head);
  802. switch (dev->class >> 8) {
  803. case PCI_CLASS_BRIDGE_PCI:
  804. if (!pci_is_enabled(dev))
  805. pci_setup_bridge(b);
  806. break;
  807. case PCI_CLASS_BRIDGE_CARDBUS:
  808. pci_setup_cardbus(b);
  809. break;
  810. default:
  811. dev_info(&dev->dev, "not setting up bridge for bus "
  812. "%04x:%02x\n", pci_domain_nr(b), b->number);
  813. break;
  814. }
  815. }
  816. }
  817. void __ref pci_bus_assign_resources(const struct pci_bus *bus)
  818. {
  819. __pci_bus_assign_resources(bus, NULL, NULL);
  820. }
  821. EXPORT_SYMBOL(pci_bus_assign_resources);
  822. static void __ref __pci_bridge_assign_resources(const struct pci_dev *bridge,
  823. struct resource_list_x *fail_head)
  824. {
  825. struct pci_bus *b;
  826. pdev_assign_resources_sorted((struct pci_dev *)bridge, fail_head);
  827. b = bridge->subordinate;
  828. if (!b)
  829. return;
  830. __pci_bus_assign_resources(b, NULL, fail_head);
  831. switch (bridge->class >> 8) {
  832. case PCI_CLASS_BRIDGE_PCI:
  833. pci_setup_bridge(b);
  834. break;
  835. case PCI_CLASS_BRIDGE_CARDBUS:
  836. pci_setup_cardbus(b);
  837. break;
  838. default:
  839. dev_info(&bridge->dev, "not setting up bridge for bus "
  840. "%04x:%02x\n", pci_domain_nr(b), b->number);
  841. break;
  842. }
  843. }
  844. static void pci_bridge_release_resources(struct pci_bus *bus,
  845. unsigned long type)
  846. {
  847. int idx;
  848. bool changed = false;
  849. struct pci_dev *dev;
  850. struct resource *r;
  851. unsigned long type_mask = IORESOURCE_IO | IORESOURCE_MEM |
  852. IORESOURCE_PREFETCH;
  853. dev = bus->self;
  854. for (idx = PCI_BRIDGE_RESOURCES; idx <= PCI_BRIDGE_RESOURCE_END;
  855. idx++) {
  856. r = &dev->resource[idx];
  857. if ((r->flags & type_mask) != type)
  858. continue;
  859. if (!r->parent)
  860. continue;
  861. /*
  862. * if there are children under that, we should release them
  863. * all
  864. */
  865. release_child_resources(r);
  866. if (!release_resource(r)) {
  867. dev_printk(KERN_DEBUG, &dev->dev,
  868. "resource %d %pR released\n", idx, r);
  869. /* keep the old size */
  870. r->end = resource_size(r) - 1;
  871. r->start = 0;
  872. r->flags = 0;
  873. changed = true;
  874. }
  875. }
  876. if (changed) {
  877. /* avoiding touch the one without PREF */
  878. if (type & IORESOURCE_PREFETCH)
  879. type = IORESOURCE_PREFETCH;
  880. __pci_setup_bridge(bus, type);
  881. }
  882. }
  883. enum release_type {
  884. leaf_only,
  885. whole_subtree,
  886. };
  887. /*
  888. * try to release pci bridge resources that is from leaf bridge,
  889. * so we can allocate big new one later
  890. */
  891. static void __ref pci_bus_release_bridge_resources(struct pci_bus *bus,
  892. unsigned long type,
  893. enum release_type rel_type)
  894. {
  895. struct pci_dev *dev;
  896. bool is_leaf_bridge = true;
  897. list_for_each_entry(dev, &bus->devices, bus_list) {
  898. struct pci_bus *b = dev->subordinate;
  899. if (!b)
  900. continue;
  901. is_leaf_bridge = false;
  902. if ((dev->class >> 8) != PCI_CLASS_BRIDGE_PCI)
  903. continue;
  904. if (rel_type == whole_subtree)
  905. pci_bus_release_bridge_resources(b, type,
  906. whole_subtree);
  907. }
  908. if (pci_is_root_bus(bus))
  909. return;
  910. if ((bus->self->class >> 8) != PCI_CLASS_BRIDGE_PCI)
  911. return;
  912. if ((rel_type == whole_subtree) || is_leaf_bridge)
  913. pci_bridge_release_resources(bus, type);
  914. }
  915. static void pci_bus_dump_res(struct pci_bus *bus)
  916. {
  917. struct resource *res;
  918. int i;
  919. pci_bus_for_each_resource(bus, res, i) {
  920. if (!res || !res->end || !res->flags)
  921. continue;
  922. dev_printk(KERN_DEBUG, &bus->dev, "resource %d %pR\n", i, res);
  923. }
  924. }
  925. static void pci_bus_dump_resources(struct pci_bus *bus)
  926. {
  927. struct pci_bus *b;
  928. struct pci_dev *dev;
  929. pci_bus_dump_res(bus);
  930. list_for_each_entry(dev, &bus->devices, bus_list) {
  931. b = dev->subordinate;
  932. if (!b)
  933. continue;
  934. pci_bus_dump_resources(b);
  935. }
  936. }
  937. static int __init pci_bus_get_depth(struct pci_bus *bus)
  938. {
  939. int depth = 0;
  940. struct pci_dev *dev;
  941. list_for_each_entry(dev, &bus->devices, bus_list) {
  942. int ret;
  943. struct pci_bus *b = dev->subordinate;
  944. if (!b)
  945. continue;
  946. ret = pci_bus_get_depth(b);
  947. if (ret + 1 > depth)
  948. depth = ret + 1;
  949. }
  950. return depth;
  951. }
  952. static int __init pci_get_max_depth(void)
  953. {
  954. int depth = 0;
  955. struct pci_bus *bus;
  956. list_for_each_entry(bus, &pci_root_buses, node) {
  957. int ret;
  958. ret = pci_bus_get_depth(bus);
  959. if (ret > depth)
  960. depth = ret;
  961. }
  962. return depth;
  963. }
  964. /*
  965. * first try will not touch pci bridge res
  966. * second and later try will clear small leaf bridge res
  967. * will stop till to the max deepth if can not find good one
  968. */
  969. void __init
  970. pci_assign_unassigned_resources(void)
  971. {
  972. struct pci_bus *bus;
  973. struct resource_list_x realloc_list; /* list of resources that
  974. want additional resources */
  975. int tried_times = 0;
  976. enum release_type rel_type = leaf_only;
  977. struct resource_list_x head, *list;
  978. unsigned long type_mask = IORESOURCE_IO | IORESOURCE_MEM |
  979. IORESOURCE_PREFETCH;
  980. unsigned long failed_type;
  981. int max_depth = pci_get_max_depth();
  982. int pci_try_num;
  983. head.next = NULL;
  984. realloc_list.next = NULL;
  985. pci_try_num = max_depth + 1;
  986. printk(KERN_DEBUG "PCI: max bus depth: %d pci_try_num: %d\n",
  987. max_depth, pci_try_num);
  988. again:
  989. /* Depth first, calculate sizes and alignments of all
  990. subordinate buses. */
  991. list_for_each_entry(bus, &pci_root_buses, node)
  992. __pci_bus_size_bridges(bus, &realloc_list);
  993. /* Depth last, allocate resources and update the hardware. */
  994. list_for_each_entry(bus, &pci_root_buses, node)
  995. __pci_bus_assign_resources(bus, &realloc_list, &head);
  996. BUG_ON(realloc_list.next);
  997. tried_times++;
  998. /* any device complain? */
  999. if (!head.next)
  1000. goto enable_and_dump;
  1001. /* don't realloc if asked to do so */
  1002. if (!pci_realloc_enabled()) {
  1003. free_list(resource_list_x, &head);
  1004. goto enable_and_dump;
  1005. }
  1006. failed_type = 0;
  1007. for (list = head.next; list;) {
  1008. failed_type |= list->flags;
  1009. list = list->next;
  1010. }
  1011. /*
  1012. * io port are tight, don't try extra
  1013. * or if reach the limit, don't want to try more
  1014. */
  1015. failed_type &= type_mask;
  1016. if ((failed_type == IORESOURCE_IO) || (tried_times >= pci_try_num)) {
  1017. free_list(resource_list_x, &head);
  1018. goto enable_and_dump;
  1019. }
  1020. printk(KERN_DEBUG "PCI: No. %d try to assign unassigned res\n",
  1021. tried_times + 1);
  1022. /* third times and later will not check if it is leaf */
  1023. if ((tried_times + 1) > 2)
  1024. rel_type = whole_subtree;
  1025. /*
  1026. * Try to release leaf bridge's resources that doesn't fit resource of
  1027. * child device under that bridge
  1028. */
  1029. for (list = head.next; list;) {
  1030. bus = list->dev->bus;
  1031. pci_bus_release_bridge_resources(bus, list->flags & type_mask,
  1032. rel_type);
  1033. list = list->next;
  1034. }
  1035. /* restore size and flags */
  1036. for (list = head.next; list;) {
  1037. struct resource *res = list->res;
  1038. res->start = list->start;
  1039. res->end = list->end;
  1040. res->flags = list->flags;
  1041. if (list->dev->subordinate)
  1042. res->flags = 0;
  1043. list = list->next;
  1044. }
  1045. free_list(resource_list_x, &head);
  1046. goto again;
  1047. enable_and_dump:
  1048. /* Depth last, update the hardware. */
  1049. list_for_each_entry(bus, &pci_root_buses, node)
  1050. pci_enable_bridges(bus);
  1051. /* dump the resource on buses */
  1052. list_for_each_entry(bus, &pci_root_buses, node)
  1053. pci_bus_dump_resources(bus);
  1054. }
  1055. void pci_assign_unassigned_bridge_resources(struct pci_dev *bridge)
  1056. {
  1057. struct pci_bus *parent = bridge->subordinate;
  1058. int tried_times = 0;
  1059. struct resource_list_x head, *list;
  1060. int retval;
  1061. unsigned long type_mask = IORESOURCE_IO | IORESOURCE_MEM |
  1062. IORESOURCE_PREFETCH;
  1063. head.next = NULL;
  1064. again:
  1065. pci_bus_size_bridges(parent);
  1066. __pci_bridge_assign_resources(bridge, &head);
  1067. tried_times++;
  1068. if (!head.next)
  1069. goto enable_all;
  1070. if (tried_times >= 2) {
  1071. /* still fail, don't need to try more */
  1072. free_list(resource_list_x, &head);
  1073. goto enable_all;
  1074. }
  1075. printk(KERN_DEBUG "PCI: No. %d try to assign unassigned res\n",
  1076. tried_times + 1);
  1077. /*
  1078. * Try to release leaf bridge's resources that doesn't fit resource of
  1079. * child device under that bridge
  1080. */
  1081. for (list = head.next; list;) {
  1082. struct pci_bus *bus = list->dev->bus;
  1083. unsigned long flags = list->flags;
  1084. pci_bus_release_bridge_resources(bus, flags & type_mask,
  1085. whole_subtree);
  1086. list = list->next;
  1087. }
  1088. /* restore size and flags */
  1089. for (list = head.next; list;) {
  1090. struct resource *res = list->res;
  1091. res->start = list->start;
  1092. res->end = list->end;
  1093. res->flags = list->flags;
  1094. if (list->dev->subordinate)
  1095. res->flags = 0;
  1096. list = list->next;
  1097. }
  1098. free_list(resource_list_x, &head);
  1099. goto again;
  1100. enable_all:
  1101. retval = pci_reenable_device(bridge);
  1102. pci_set_master(bridge);
  1103. pci_enable_bridges(parent);
  1104. }
  1105. EXPORT_SYMBOL_GPL(pci_assign_unassigned_bridge_resources);