setup-bus.c 34 KB

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