setup-bus.c 34 KB

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