pci.c 47 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857
  1. /*
  2. * PCI Bus Services, see include/linux/pci.h for further explanation.
  3. *
  4. * Copyright 1993 -- 1997 Drew Eckhardt, Frederic Potter,
  5. * David Mosberger-Tang
  6. *
  7. * Copyright 1997 -- 2000 Martin Mares <mj@ucw.cz>
  8. */
  9. #include <linux/kernel.h>
  10. #include <linux/delay.h>
  11. #include <linux/init.h>
  12. #include <linux/pci.h>
  13. #include <linux/pm.h>
  14. #include <linux/module.h>
  15. #include <linux/spinlock.h>
  16. #include <linux/string.h>
  17. #include <linux/log2.h>
  18. #include <linux/pci-aspm.h>
  19. #include <asm/dma.h> /* isa_dma_bridge_buggy */
  20. #include "pci.h"
  21. unsigned int pci_pm_d3_delay = 10;
  22. #ifdef CONFIG_PCI_DOMAINS
  23. int pci_domains_supported = 1;
  24. #endif
  25. #define DEFAULT_CARDBUS_IO_SIZE (256)
  26. #define DEFAULT_CARDBUS_MEM_SIZE (64*1024*1024)
  27. /* pci=cbmemsize=nnM,cbiosize=nn can override this */
  28. unsigned long pci_cardbus_io_size = DEFAULT_CARDBUS_IO_SIZE;
  29. unsigned long pci_cardbus_mem_size = DEFAULT_CARDBUS_MEM_SIZE;
  30. /**
  31. * pci_bus_max_busnr - returns maximum PCI bus number of given bus' children
  32. * @bus: pointer to PCI bus structure to search
  33. *
  34. * Given a PCI bus, returns the highest PCI bus number present in the set
  35. * including the given PCI bus and its list of child PCI buses.
  36. */
  37. unsigned char pci_bus_max_busnr(struct pci_bus* bus)
  38. {
  39. struct list_head *tmp;
  40. unsigned char max, n;
  41. max = bus->subordinate;
  42. list_for_each(tmp, &bus->children) {
  43. n = pci_bus_max_busnr(pci_bus_b(tmp));
  44. if(n > max)
  45. max = n;
  46. }
  47. return max;
  48. }
  49. EXPORT_SYMBOL_GPL(pci_bus_max_busnr);
  50. #if 0
  51. /**
  52. * pci_max_busnr - returns maximum PCI bus number
  53. *
  54. * Returns the highest PCI bus number present in the system global list of
  55. * PCI buses.
  56. */
  57. unsigned char __devinit
  58. pci_max_busnr(void)
  59. {
  60. struct pci_bus *bus = NULL;
  61. unsigned char max, n;
  62. max = 0;
  63. while ((bus = pci_find_next_bus(bus)) != NULL) {
  64. n = pci_bus_max_busnr(bus);
  65. if(n > max)
  66. max = n;
  67. }
  68. return max;
  69. }
  70. #endif /* 0 */
  71. #define PCI_FIND_CAP_TTL 48
  72. static int __pci_find_next_cap_ttl(struct pci_bus *bus, unsigned int devfn,
  73. u8 pos, int cap, int *ttl)
  74. {
  75. u8 id;
  76. while ((*ttl)--) {
  77. pci_bus_read_config_byte(bus, devfn, pos, &pos);
  78. if (pos < 0x40)
  79. break;
  80. pos &= ~3;
  81. pci_bus_read_config_byte(bus, devfn, pos + PCI_CAP_LIST_ID,
  82. &id);
  83. if (id == 0xff)
  84. break;
  85. if (id == cap)
  86. return pos;
  87. pos += PCI_CAP_LIST_NEXT;
  88. }
  89. return 0;
  90. }
  91. static int __pci_find_next_cap(struct pci_bus *bus, unsigned int devfn,
  92. u8 pos, int cap)
  93. {
  94. int ttl = PCI_FIND_CAP_TTL;
  95. return __pci_find_next_cap_ttl(bus, devfn, pos, cap, &ttl);
  96. }
  97. int pci_find_next_capability(struct pci_dev *dev, u8 pos, int cap)
  98. {
  99. return __pci_find_next_cap(dev->bus, dev->devfn,
  100. pos + PCI_CAP_LIST_NEXT, cap);
  101. }
  102. EXPORT_SYMBOL_GPL(pci_find_next_capability);
  103. static int __pci_bus_find_cap_start(struct pci_bus *bus,
  104. unsigned int devfn, u8 hdr_type)
  105. {
  106. u16 status;
  107. pci_bus_read_config_word(bus, devfn, PCI_STATUS, &status);
  108. if (!(status & PCI_STATUS_CAP_LIST))
  109. return 0;
  110. switch (hdr_type) {
  111. case PCI_HEADER_TYPE_NORMAL:
  112. case PCI_HEADER_TYPE_BRIDGE:
  113. return PCI_CAPABILITY_LIST;
  114. case PCI_HEADER_TYPE_CARDBUS:
  115. return PCI_CB_CAPABILITY_LIST;
  116. default:
  117. return 0;
  118. }
  119. return 0;
  120. }
  121. /**
  122. * pci_find_capability - query for devices' capabilities
  123. * @dev: PCI device to query
  124. * @cap: capability code
  125. *
  126. * Tell if a device supports a given PCI capability.
  127. * Returns the address of the requested capability structure within the
  128. * device's PCI configuration space or 0 in case the device does not
  129. * support it. Possible values for @cap:
  130. *
  131. * %PCI_CAP_ID_PM Power Management
  132. * %PCI_CAP_ID_AGP Accelerated Graphics Port
  133. * %PCI_CAP_ID_VPD Vital Product Data
  134. * %PCI_CAP_ID_SLOTID Slot Identification
  135. * %PCI_CAP_ID_MSI Message Signalled Interrupts
  136. * %PCI_CAP_ID_CHSWP CompactPCI HotSwap
  137. * %PCI_CAP_ID_PCIX PCI-X
  138. * %PCI_CAP_ID_EXP PCI Express
  139. */
  140. int pci_find_capability(struct pci_dev *dev, int cap)
  141. {
  142. int pos;
  143. pos = __pci_bus_find_cap_start(dev->bus, dev->devfn, dev->hdr_type);
  144. if (pos)
  145. pos = __pci_find_next_cap(dev->bus, dev->devfn, pos, cap);
  146. return pos;
  147. }
  148. /**
  149. * pci_bus_find_capability - query for devices' capabilities
  150. * @bus: the PCI bus to query
  151. * @devfn: PCI device to query
  152. * @cap: capability code
  153. *
  154. * Like pci_find_capability() but works for pci devices that do not have a
  155. * pci_dev structure set up yet.
  156. *
  157. * Returns the address of the requested capability structure within the
  158. * device's PCI configuration space or 0 in case the device does not
  159. * support it.
  160. */
  161. int pci_bus_find_capability(struct pci_bus *bus, unsigned int devfn, int cap)
  162. {
  163. int pos;
  164. u8 hdr_type;
  165. pci_bus_read_config_byte(bus, devfn, PCI_HEADER_TYPE, &hdr_type);
  166. pos = __pci_bus_find_cap_start(bus, devfn, hdr_type & 0x7f);
  167. if (pos)
  168. pos = __pci_find_next_cap(bus, devfn, pos, cap);
  169. return pos;
  170. }
  171. /**
  172. * pci_find_ext_capability - Find an extended capability
  173. * @dev: PCI device to query
  174. * @cap: capability code
  175. *
  176. * Returns the address of the requested extended capability structure
  177. * within the device's PCI configuration space or 0 if the device does
  178. * not support it. Possible values for @cap:
  179. *
  180. * %PCI_EXT_CAP_ID_ERR Advanced Error Reporting
  181. * %PCI_EXT_CAP_ID_VC Virtual Channel
  182. * %PCI_EXT_CAP_ID_DSN Device Serial Number
  183. * %PCI_EXT_CAP_ID_PWR Power Budgeting
  184. */
  185. int pci_find_ext_capability(struct pci_dev *dev, int cap)
  186. {
  187. u32 header;
  188. int ttl = 480; /* 3840 bytes, minimum 8 bytes per capability */
  189. int pos = 0x100;
  190. if (dev->cfg_size <= 256)
  191. return 0;
  192. if (pci_read_config_dword(dev, pos, &header) != PCIBIOS_SUCCESSFUL)
  193. return 0;
  194. /*
  195. * If we have no capabilities, this is indicated by cap ID,
  196. * cap version and next pointer all being 0.
  197. */
  198. if (header == 0)
  199. return 0;
  200. while (ttl-- > 0) {
  201. if (PCI_EXT_CAP_ID(header) == cap)
  202. return pos;
  203. pos = PCI_EXT_CAP_NEXT(header);
  204. if (pos < 0x100)
  205. break;
  206. if (pci_read_config_dword(dev, pos, &header) != PCIBIOS_SUCCESSFUL)
  207. break;
  208. }
  209. return 0;
  210. }
  211. EXPORT_SYMBOL_GPL(pci_find_ext_capability);
  212. static int __pci_find_next_ht_cap(struct pci_dev *dev, int pos, int ht_cap)
  213. {
  214. int rc, ttl = PCI_FIND_CAP_TTL;
  215. u8 cap, mask;
  216. if (ht_cap == HT_CAPTYPE_SLAVE || ht_cap == HT_CAPTYPE_HOST)
  217. mask = HT_3BIT_CAP_MASK;
  218. else
  219. mask = HT_5BIT_CAP_MASK;
  220. pos = __pci_find_next_cap_ttl(dev->bus, dev->devfn, pos,
  221. PCI_CAP_ID_HT, &ttl);
  222. while (pos) {
  223. rc = pci_read_config_byte(dev, pos + 3, &cap);
  224. if (rc != PCIBIOS_SUCCESSFUL)
  225. return 0;
  226. if ((cap & mask) == ht_cap)
  227. return pos;
  228. pos = __pci_find_next_cap_ttl(dev->bus, dev->devfn,
  229. pos + PCI_CAP_LIST_NEXT,
  230. PCI_CAP_ID_HT, &ttl);
  231. }
  232. return 0;
  233. }
  234. /**
  235. * pci_find_next_ht_capability - query a device's Hypertransport capabilities
  236. * @dev: PCI device to query
  237. * @pos: Position from which to continue searching
  238. * @ht_cap: Hypertransport capability code
  239. *
  240. * To be used in conjunction with pci_find_ht_capability() to search for
  241. * all capabilities matching @ht_cap. @pos should always be a value returned
  242. * from pci_find_ht_capability().
  243. *
  244. * NB. To be 100% safe against broken PCI devices, the caller should take
  245. * steps to avoid an infinite loop.
  246. */
  247. int pci_find_next_ht_capability(struct pci_dev *dev, int pos, int ht_cap)
  248. {
  249. return __pci_find_next_ht_cap(dev, pos + PCI_CAP_LIST_NEXT, ht_cap);
  250. }
  251. EXPORT_SYMBOL_GPL(pci_find_next_ht_capability);
  252. /**
  253. * pci_find_ht_capability - query a device's Hypertransport capabilities
  254. * @dev: PCI device to query
  255. * @ht_cap: Hypertransport capability code
  256. *
  257. * Tell if a device supports a given Hypertransport capability.
  258. * Returns an address within the device's PCI configuration space
  259. * or 0 in case the device does not support the request capability.
  260. * The address points to the PCI capability, of type PCI_CAP_ID_HT,
  261. * which has a Hypertransport capability matching @ht_cap.
  262. */
  263. int pci_find_ht_capability(struct pci_dev *dev, int ht_cap)
  264. {
  265. int pos;
  266. pos = __pci_bus_find_cap_start(dev->bus, dev->devfn, dev->hdr_type);
  267. if (pos)
  268. pos = __pci_find_next_ht_cap(dev, pos, ht_cap);
  269. return pos;
  270. }
  271. EXPORT_SYMBOL_GPL(pci_find_ht_capability);
  272. /**
  273. * pci_find_parent_resource - return resource region of parent bus of given region
  274. * @dev: PCI device structure contains resources to be searched
  275. * @res: child resource record for which parent is sought
  276. *
  277. * For given resource region of given device, return the resource
  278. * region of parent bus the given region is contained in or where
  279. * it should be allocated from.
  280. */
  281. struct resource *
  282. pci_find_parent_resource(const struct pci_dev *dev, struct resource *res)
  283. {
  284. const struct pci_bus *bus = dev->bus;
  285. int i;
  286. struct resource *best = NULL;
  287. for(i = 0; i < PCI_BUS_NUM_RESOURCES; i++) {
  288. struct resource *r = bus->resource[i];
  289. if (!r)
  290. continue;
  291. if (res->start && !(res->start >= r->start && res->end <= r->end))
  292. continue; /* Not contained */
  293. if ((res->flags ^ r->flags) & (IORESOURCE_IO | IORESOURCE_MEM))
  294. continue; /* Wrong type */
  295. if (!((res->flags ^ r->flags) & IORESOURCE_PREFETCH))
  296. return r; /* Exact match */
  297. if ((res->flags & IORESOURCE_PREFETCH) && !(r->flags & IORESOURCE_PREFETCH))
  298. best = r; /* Approximating prefetchable by non-prefetchable */
  299. }
  300. return best;
  301. }
  302. /**
  303. * pci_restore_bars - restore a devices BAR values (e.g. after wake-up)
  304. * @dev: PCI device to have its BARs restored
  305. *
  306. * Restore the BAR values for a given device, so as to make it
  307. * accessible by its driver.
  308. */
  309. static void
  310. pci_restore_bars(struct pci_dev *dev)
  311. {
  312. int i, numres;
  313. switch (dev->hdr_type) {
  314. case PCI_HEADER_TYPE_NORMAL:
  315. numres = 6;
  316. break;
  317. case PCI_HEADER_TYPE_BRIDGE:
  318. numres = 2;
  319. break;
  320. case PCI_HEADER_TYPE_CARDBUS:
  321. numres = 1;
  322. break;
  323. default:
  324. /* Should never get here, but just in case... */
  325. return;
  326. }
  327. for (i = 0; i < numres; i ++)
  328. pci_update_resource(dev, &dev->resource[i], i);
  329. }
  330. static struct pci_platform_pm_ops *pci_platform_pm;
  331. int pci_set_platform_pm(struct pci_platform_pm_ops *ops)
  332. {
  333. if (!ops->is_manageable || !ops->set_state || !ops->choose_state
  334. || !ops->sleep_wake || !ops->can_wakeup)
  335. return -EINVAL;
  336. pci_platform_pm = ops;
  337. return 0;
  338. }
  339. static inline bool platform_pci_power_manageable(struct pci_dev *dev)
  340. {
  341. return pci_platform_pm ? pci_platform_pm->is_manageable(dev) : false;
  342. }
  343. static inline int platform_pci_set_power_state(struct pci_dev *dev,
  344. pci_power_t t)
  345. {
  346. return pci_platform_pm ? pci_platform_pm->set_state(dev, t) : -ENOSYS;
  347. }
  348. static inline pci_power_t platform_pci_choose_state(struct pci_dev *dev)
  349. {
  350. return pci_platform_pm ?
  351. pci_platform_pm->choose_state(dev) : PCI_POWER_ERROR;
  352. }
  353. static inline bool platform_pci_can_wakeup(struct pci_dev *dev)
  354. {
  355. return pci_platform_pm ? pci_platform_pm->can_wakeup(dev) : false;
  356. }
  357. static inline int platform_pci_sleep_wake(struct pci_dev *dev, bool enable)
  358. {
  359. return pci_platform_pm ?
  360. pci_platform_pm->sleep_wake(dev, enable) : -ENODEV;
  361. }
  362. /**
  363. * pci_raw_set_power_state - Use PCI PM registers to set the power state of
  364. * given PCI device
  365. * @dev: PCI device to handle.
  366. * @pm: PCI PM capability offset of the device.
  367. * @state: PCI power state (D0, D1, D2, D3hot) to put the device into.
  368. *
  369. * RETURN VALUE:
  370. * -EINVAL if the requested state is invalid.
  371. * -EIO if device does not support PCI PM or its PM capabilities register has a
  372. * wrong version, or device doesn't support the requested state.
  373. * 0 if device already is in the requested state.
  374. * 0 if device's power state has been successfully changed.
  375. */
  376. static int
  377. pci_raw_set_power_state(struct pci_dev *dev, int pm, pci_power_t state)
  378. {
  379. u16 pmcsr, pmc;
  380. bool need_restore = false;
  381. if (!pm)
  382. return -EIO;
  383. if (state < PCI_D0 || state > PCI_D3hot)
  384. return -EINVAL;
  385. /* Validate current state:
  386. * Can enter D0 from any state, but if we can only go deeper
  387. * to sleep if we're already in a low power state
  388. */
  389. if (dev->current_state == state) {
  390. /* we're already there */
  391. return 0;
  392. } else if (state != PCI_D0 && dev->current_state <= PCI_D3cold
  393. && dev->current_state > state) {
  394. dev_err(&dev->dev, "invalid power transition "
  395. "(from state %d to %d)\n", dev->current_state, state);
  396. return -EINVAL;
  397. }
  398. pci_read_config_word(dev, pm + PCI_PM_PMC, &pmc);
  399. if ((pmc & PCI_PM_CAP_VER_MASK) > 3) {
  400. dev_err(&dev->dev, "unsupported PM cap regs version (%u)\n",
  401. pmc & PCI_PM_CAP_VER_MASK);
  402. return -EIO;
  403. }
  404. /* check if this device supports the desired state */
  405. if ((state == PCI_D1 && !(pmc & PCI_PM_CAP_D1))
  406. || (state == PCI_D2 && !(pmc & PCI_PM_CAP_D2)))
  407. return -EIO;
  408. pci_read_config_word(dev, pm + PCI_PM_CTRL, &pmcsr);
  409. /* If we're (effectively) in D3, force entire word to 0.
  410. * This doesn't affect PME_Status, disables PME_En, and
  411. * sets PowerState to 0.
  412. */
  413. switch (dev->current_state) {
  414. case PCI_D0:
  415. case PCI_D1:
  416. case PCI_D2:
  417. pmcsr &= ~PCI_PM_CTRL_STATE_MASK;
  418. pmcsr |= state;
  419. break;
  420. case PCI_UNKNOWN: /* Boot-up */
  421. if ((pmcsr & PCI_PM_CTRL_STATE_MASK) == PCI_D3hot
  422. && !(pmcsr & PCI_PM_CTRL_NO_SOFT_RESET))
  423. need_restore = true;
  424. /* Fall-through: force to D0 */
  425. default:
  426. pmcsr = 0;
  427. break;
  428. }
  429. /* enter specified state */
  430. pci_write_config_word(dev, pm + PCI_PM_CTRL, pmcsr);
  431. /* Mandatory power management transition delays */
  432. /* see PCI PM 1.1 5.6.1 table 18 */
  433. if (state == PCI_D3hot || dev->current_state == PCI_D3hot)
  434. msleep(pci_pm_d3_delay);
  435. else if (state == PCI_D2 || dev->current_state == PCI_D2)
  436. udelay(200);
  437. dev->current_state = state;
  438. /* According to section 5.4.1 of the "PCI BUS POWER MANAGEMENT
  439. * INTERFACE SPECIFICATION, REV. 1.2", a device transitioning
  440. * from D3hot to D0 _may_ perform an internal reset, thereby
  441. * going to "D0 Uninitialized" rather than "D0 Initialized".
  442. * For example, at least some versions of the 3c905B and the
  443. * 3c556B exhibit this behaviour.
  444. *
  445. * At least some laptop BIOSen (e.g. the Thinkpad T21) leave
  446. * devices in a D3hot state at boot. Consequently, we need to
  447. * restore at least the BARs so that the device will be
  448. * accessible to its driver.
  449. */
  450. if (need_restore)
  451. pci_restore_bars(dev);
  452. if (dev->bus->self)
  453. pcie_aspm_pm_state_change(dev->bus->self);
  454. return 0;
  455. }
  456. /**
  457. * pci_update_current_state - Read PCI power state of given device from its
  458. * PCI PM registers and cache it
  459. * @dev: PCI device to handle.
  460. * @pm: PCI PM capability offset of the device.
  461. */
  462. static void pci_update_current_state(struct pci_dev *dev, int pm)
  463. {
  464. if (pm) {
  465. u16 pmcsr;
  466. pci_read_config_word(dev, pm + PCI_PM_CTRL, &pmcsr);
  467. dev->current_state = (pmcsr & PCI_PM_CTRL_STATE_MASK);
  468. }
  469. }
  470. /**
  471. * pci_set_power_state - Set the power state of a PCI device
  472. * @dev: PCI device to handle.
  473. * @state: PCI power state (D0, D1, D2, D3hot) to put the device into.
  474. *
  475. * Transition a device to a new power state, using the platform formware and/or
  476. * the device's PCI PM registers.
  477. *
  478. * RETURN VALUE:
  479. * -EINVAL if the requested state is invalid.
  480. * -EIO if device does not support PCI PM or its PM capabilities register has a
  481. * wrong version, or device doesn't support the requested state.
  482. * 0 if device already is in the requested state.
  483. * 0 if device's power state has been successfully changed.
  484. */
  485. int pci_set_power_state(struct pci_dev *dev, pci_power_t state)
  486. {
  487. int pm, error;
  488. /* bound the state we're entering */
  489. if (state > PCI_D3hot)
  490. state = PCI_D3hot;
  491. else if (state < PCI_D0)
  492. state = PCI_D0;
  493. else if ((state == PCI_D1 || state == PCI_D2) && pci_no_d1d2(dev))
  494. /*
  495. * If the device or the parent bridge do not support PCI PM,
  496. * ignore the request if we're doing anything other than putting
  497. * it into D0 (which would only happen on boot).
  498. */
  499. return 0;
  500. /* Find PCI PM capability in the list */
  501. pm = pci_find_capability(dev, PCI_CAP_ID_PM);
  502. if (state == PCI_D0 && platform_pci_power_manageable(dev)) {
  503. /*
  504. * Allow the platform to change the state, for example via ACPI
  505. * _PR0, _PS0 and some such, but do not trust it.
  506. */
  507. int ret = platform_pci_set_power_state(dev, PCI_D0);
  508. if (!ret)
  509. pci_update_current_state(dev, pm);
  510. }
  511. error = pci_raw_set_power_state(dev, pm, state);
  512. if (state > PCI_D0 && platform_pci_power_manageable(dev)) {
  513. /* Allow the platform to finalize the transition */
  514. int ret = platform_pci_set_power_state(dev, state);
  515. if (!ret) {
  516. pci_update_current_state(dev, pm);
  517. error = 0;
  518. }
  519. }
  520. return error;
  521. }
  522. /**
  523. * pci_choose_state - Choose the power state of a PCI device
  524. * @dev: PCI device to be suspended
  525. * @state: target sleep state for the whole system. This is the value
  526. * that is passed to suspend() function.
  527. *
  528. * Returns PCI power state suitable for given device and given system
  529. * message.
  530. */
  531. pci_power_t pci_choose_state(struct pci_dev *dev, pm_message_t state)
  532. {
  533. pci_power_t ret;
  534. if (!pci_find_capability(dev, PCI_CAP_ID_PM))
  535. return PCI_D0;
  536. ret = platform_pci_choose_state(dev);
  537. if (ret != PCI_POWER_ERROR)
  538. return ret;
  539. switch (state.event) {
  540. case PM_EVENT_ON:
  541. return PCI_D0;
  542. case PM_EVENT_FREEZE:
  543. case PM_EVENT_PRETHAW:
  544. /* REVISIT both freeze and pre-thaw "should" use D0 */
  545. case PM_EVENT_SUSPEND:
  546. case PM_EVENT_HIBERNATE:
  547. return PCI_D3hot;
  548. default:
  549. dev_info(&dev->dev, "unrecognized suspend event %d\n",
  550. state.event);
  551. BUG();
  552. }
  553. return PCI_D0;
  554. }
  555. EXPORT_SYMBOL(pci_choose_state);
  556. static int pci_save_pcie_state(struct pci_dev *dev)
  557. {
  558. int pos, i = 0;
  559. struct pci_cap_saved_state *save_state;
  560. u16 *cap;
  561. int found = 0;
  562. pos = pci_find_capability(dev, PCI_CAP_ID_EXP);
  563. if (pos <= 0)
  564. return 0;
  565. save_state = pci_find_saved_cap(dev, PCI_CAP_ID_EXP);
  566. if (!save_state)
  567. save_state = kzalloc(sizeof(*save_state) + sizeof(u16) * 4, GFP_KERNEL);
  568. else
  569. found = 1;
  570. if (!save_state) {
  571. dev_err(&dev->dev, "out of memory in pci_save_pcie_state\n");
  572. return -ENOMEM;
  573. }
  574. cap = (u16 *)&save_state->data[0];
  575. pci_read_config_word(dev, pos + PCI_EXP_DEVCTL, &cap[i++]);
  576. pci_read_config_word(dev, pos + PCI_EXP_LNKCTL, &cap[i++]);
  577. pci_read_config_word(dev, pos + PCI_EXP_SLTCTL, &cap[i++]);
  578. pci_read_config_word(dev, pos + PCI_EXP_RTCTL, &cap[i++]);
  579. save_state->cap_nr = PCI_CAP_ID_EXP;
  580. if (!found)
  581. pci_add_saved_cap(dev, save_state);
  582. return 0;
  583. }
  584. static void pci_restore_pcie_state(struct pci_dev *dev)
  585. {
  586. int i = 0, pos;
  587. struct pci_cap_saved_state *save_state;
  588. u16 *cap;
  589. save_state = pci_find_saved_cap(dev, PCI_CAP_ID_EXP);
  590. pos = pci_find_capability(dev, PCI_CAP_ID_EXP);
  591. if (!save_state || pos <= 0)
  592. return;
  593. cap = (u16 *)&save_state->data[0];
  594. pci_write_config_word(dev, pos + PCI_EXP_DEVCTL, cap[i++]);
  595. pci_write_config_word(dev, pos + PCI_EXP_LNKCTL, cap[i++]);
  596. pci_write_config_word(dev, pos + PCI_EXP_SLTCTL, cap[i++]);
  597. pci_write_config_word(dev, pos + PCI_EXP_RTCTL, cap[i++]);
  598. }
  599. static int pci_save_pcix_state(struct pci_dev *dev)
  600. {
  601. int pos, i = 0;
  602. struct pci_cap_saved_state *save_state;
  603. u16 *cap;
  604. int found = 0;
  605. pos = pci_find_capability(dev, PCI_CAP_ID_PCIX);
  606. if (pos <= 0)
  607. return 0;
  608. save_state = pci_find_saved_cap(dev, PCI_CAP_ID_PCIX);
  609. if (!save_state)
  610. save_state = kzalloc(sizeof(*save_state) + sizeof(u16), GFP_KERNEL);
  611. else
  612. found = 1;
  613. if (!save_state) {
  614. dev_err(&dev->dev, "out of memory in pci_save_pcie_state\n");
  615. return -ENOMEM;
  616. }
  617. cap = (u16 *)&save_state->data[0];
  618. pci_read_config_word(dev, pos + PCI_X_CMD, &cap[i++]);
  619. save_state->cap_nr = PCI_CAP_ID_PCIX;
  620. if (!found)
  621. pci_add_saved_cap(dev, save_state);
  622. return 0;
  623. }
  624. static void pci_restore_pcix_state(struct pci_dev *dev)
  625. {
  626. int i = 0, pos;
  627. struct pci_cap_saved_state *save_state;
  628. u16 *cap;
  629. save_state = pci_find_saved_cap(dev, PCI_CAP_ID_PCIX);
  630. pos = pci_find_capability(dev, PCI_CAP_ID_PCIX);
  631. if (!save_state || pos <= 0)
  632. return;
  633. cap = (u16 *)&save_state->data[0];
  634. pci_write_config_word(dev, pos + PCI_X_CMD, cap[i++]);
  635. }
  636. /**
  637. * pci_save_state - save the PCI configuration space of a device before suspending
  638. * @dev: - PCI device that we're dealing with
  639. */
  640. int
  641. pci_save_state(struct pci_dev *dev)
  642. {
  643. int i;
  644. /* XXX: 100% dword access ok here? */
  645. for (i = 0; i < 16; i++)
  646. pci_read_config_dword(dev, i * 4,&dev->saved_config_space[i]);
  647. if ((i = pci_save_pcie_state(dev)) != 0)
  648. return i;
  649. if ((i = pci_save_pcix_state(dev)) != 0)
  650. return i;
  651. return 0;
  652. }
  653. /**
  654. * pci_restore_state - Restore the saved state of a PCI device
  655. * @dev: - PCI device that we're dealing with
  656. */
  657. int
  658. pci_restore_state(struct pci_dev *dev)
  659. {
  660. int i;
  661. u32 val;
  662. /* PCI Express register must be restored first */
  663. pci_restore_pcie_state(dev);
  664. /*
  665. * The Base Address register should be programmed before the command
  666. * register(s)
  667. */
  668. for (i = 15; i >= 0; i--) {
  669. pci_read_config_dword(dev, i * 4, &val);
  670. if (val != dev->saved_config_space[i]) {
  671. dev_printk(KERN_DEBUG, &dev->dev, "restoring config "
  672. "space at offset %#x (was %#x, writing %#x)\n",
  673. i, val, (int)dev->saved_config_space[i]);
  674. pci_write_config_dword(dev,i * 4,
  675. dev->saved_config_space[i]);
  676. }
  677. }
  678. pci_restore_pcix_state(dev);
  679. pci_restore_msi_state(dev);
  680. return 0;
  681. }
  682. static int do_pci_enable_device(struct pci_dev *dev, int bars)
  683. {
  684. int err;
  685. err = pci_set_power_state(dev, PCI_D0);
  686. if (err < 0 && err != -EIO)
  687. return err;
  688. err = pcibios_enable_device(dev, bars);
  689. if (err < 0)
  690. return err;
  691. pci_fixup_device(pci_fixup_enable, dev);
  692. return 0;
  693. }
  694. /**
  695. * pci_reenable_device - Resume abandoned device
  696. * @dev: PCI device to be resumed
  697. *
  698. * Note this function is a backend of pci_default_resume and is not supposed
  699. * to be called by normal code, write proper resume handler and use it instead.
  700. */
  701. int pci_reenable_device(struct pci_dev *dev)
  702. {
  703. if (atomic_read(&dev->enable_cnt))
  704. return do_pci_enable_device(dev, (1 << PCI_NUM_RESOURCES) - 1);
  705. return 0;
  706. }
  707. static int __pci_enable_device_flags(struct pci_dev *dev,
  708. resource_size_t flags)
  709. {
  710. int err;
  711. int i, bars = 0;
  712. if (atomic_add_return(1, &dev->enable_cnt) > 1)
  713. return 0; /* already enabled */
  714. for (i = 0; i < DEVICE_COUNT_RESOURCE; i++)
  715. if (dev->resource[i].flags & flags)
  716. bars |= (1 << i);
  717. err = do_pci_enable_device(dev, bars);
  718. if (err < 0)
  719. atomic_dec(&dev->enable_cnt);
  720. return err;
  721. }
  722. /**
  723. * pci_enable_device_io - Initialize a device for use with IO space
  724. * @dev: PCI device to be initialized
  725. *
  726. * Initialize device before it's used by a driver. Ask low-level code
  727. * to enable I/O resources. Wake up the device if it was suspended.
  728. * Beware, this function can fail.
  729. */
  730. int pci_enable_device_io(struct pci_dev *dev)
  731. {
  732. return __pci_enable_device_flags(dev, IORESOURCE_IO);
  733. }
  734. /**
  735. * pci_enable_device_mem - Initialize a device for use with Memory space
  736. * @dev: PCI device to be initialized
  737. *
  738. * Initialize device before it's used by a driver. Ask low-level code
  739. * to enable Memory resources. Wake up the device if it was suspended.
  740. * Beware, this function can fail.
  741. */
  742. int pci_enable_device_mem(struct pci_dev *dev)
  743. {
  744. return __pci_enable_device_flags(dev, IORESOURCE_MEM);
  745. }
  746. /**
  747. * pci_enable_device - Initialize device before it's used by a driver.
  748. * @dev: PCI device to be initialized
  749. *
  750. * Initialize device before it's used by a driver. Ask low-level code
  751. * to enable I/O and memory. Wake up the device if it was suspended.
  752. * Beware, this function can fail.
  753. *
  754. * Note we don't actually enable the device many times if we call
  755. * this function repeatedly (we just increment the count).
  756. */
  757. int pci_enable_device(struct pci_dev *dev)
  758. {
  759. return __pci_enable_device_flags(dev, IORESOURCE_MEM | IORESOURCE_IO);
  760. }
  761. /*
  762. * Managed PCI resources. This manages device on/off, intx/msi/msix
  763. * on/off and BAR regions. pci_dev itself records msi/msix status, so
  764. * there's no need to track it separately. pci_devres is initialized
  765. * when a device is enabled using managed PCI device enable interface.
  766. */
  767. struct pci_devres {
  768. unsigned int enabled:1;
  769. unsigned int pinned:1;
  770. unsigned int orig_intx:1;
  771. unsigned int restore_intx:1;
  772. u32 region_mask;
  773. };
  774. static void pcim_release(struct device *gendev, void *res)
  775. {
  776. struct pci_dev *dev = container_of(gendev, struct pci_dev, dev);
  777. struct pci_devres *this = res;
  778. int i;
  779. if (dev->msi_enabled)
  780. pci_disable_msi(dev);
  781. if (dev->msix_enabled)
  782. pci_disable_msix(dev);
  783. for (i = 0; i < DEVICE_COUNT_RESOURCE; i++)
  784. if (this->region_mask & (1 << i))
  785. pci_release_region(dev, i);
  786. if (this->restore_intx)
  787. pci_intx(dev, this->orig_intx);
  788. if (this->enabled && !this->pinned)
  789. pci_disable_device(dev);
  790. }
  791. static struct pci_devres * get_pci_dr(struct pci_dev *pdev)
  792. {
  793. struct pci_devres *dr, *new_dr;
  794. dr = devres_find(&pdev->dev, pcim_release, NULL, NULL);
  795. if (dr)
  796. return dr;
  797. new_dr = devres_alloc(pcim_release, sizeof(*new_dr), GFP_KERNEL);
  798. if (!new_dr)
  799. return NULL;
  800. return devres_get(&pdev->dev, new_dr, NULL, NULL);
  801. }
  802. static struct pci_devres * find_pci_dr(struct pci_dev *pdev)
  803. {
  804. if (pci_is_managed(pdev))
  805. return devres_find(&pdev->dev, pcim_release, NULL, NULL);
  806. return NULL;
  807. }
  808. /**
  809. * pcim_enable_device - Managed pci_enable_device()
  810. * @pdev: PCI device to be initialized
  811. *
  812. * Managed pci_enable_device().
  813. */
  814. int pcim_enable_device(struct pci_dev *pdev)
  815. {
  816. struct pci_devres *dr;
  817. int rc;
  818. dr = get_pci_dr(pdev);
  819. if (unlikely(!dr))
  820. return -ENOMEM;
  821. if (dr->enabled)
  822. return 0;
  823. rc = pci_enable_device(pdev);
  824. if (!rc) {
  825. pdev->is_managed = 1;
  826. dr->enabled = 1;
  827. }
  828. return rc;
  829. }
  830. /**
  831. * pcim_pin_device - Pin managed PCI device
  832. * @pdev: PCI device to pin
  833. *
  834. * Pin managed PCI device @pdev. Pinned device won't be disabled on
  835. * driver detach. @pdev must have been enabled with
  836. * pcim_enable_device().
  837. */
  838. void pcim_pin_device(struct pci_dev *pdev)
  839. {
  840. struct pci_devres *dr;
  841. dr = find_pci_dr(pdev);
  842. WARN_ON(!dr || !dr->enabled);
  843. if (dr)
  844. dr->pinned = 1;
  845. }
  846. /**
  847. * pcibios_disable_device - disable arch specific PCI resources for device dev
  848. * @dev: the PCI device to disable
  849. *
  850. * Disables architecture specific PCI resources for the device. This
  851. * is the default implementation. Architecture implementations can
  852. * override this.
  853. */
  854. void __attribute__ ((weak)) pcibios_disable_device (struct pci_dev *dev) {}
  855. /**
  856. * pci_disable_device - Disable PCI device after use
  857. * @dev: PCI device to be disabled
  858. *
  859. * Signal to the system that the PCI device is not in use by the system
  860. * anymore. This only involves disabling PCI bus-mastering, if active.
  861. *
  862. * Note we don't actually disable the device until all callers of
  863. * pci_device_enable() have called pci_device_disable().
  864. */
  865. void
  866. pci_disable_device(struct pci_dev *dev)
  867. {
  868. struct pci_devres *dr;
  869. u16 pci_command;
  870. dr = find_pci_dr(dev);
  871. if (dr)
  872. dr->enabled = 0;
  873. if (atomic_sub_return(1, &dev->enable_cnt) != 0)
  874. return;
  875. pci_read_config_word(dev, PCI_COMMAND, &pci_command);
  876. if (pci_command & PCI_COMMAND_MASTER) {
  877. pci_command &= ~PCI_COMMAND_MASTER;
  878. pci_write_config_word(dev, PCI_COMMAND, pci_command);
  879. }
  880. dev->is_busmaster = 0;
  881. pcibios_disable_device(dev);
  882. }
  883. /**
  884. * pcibios_set_pcie_reset_state - set reset state for device dev
  885. * @dev: the PCI-E device reset
  886. * @state: Reset state to enter into
  887. *
  888. *
  889. * Sets the PCI-E reset state for the device. This is the default
  890. * implementation. Architecture implementations can override this.
  891. */
  892. int __attribute__ ((weak)) pcibios_set_pcie_reset_state(struct pci_dev *dev,
  893. enum pcie_reset_state state)
  894. {
  895. return -EINVAL;
  896. }
  897. /**
  898. * pci_set_pcie_reset_state - set reset state for device dev
  899. * @dev: the PCI-E device reset
  900. * @state: Reset state to enter into
  901. *
  902. *
  903. * Sets the PCI reset state for the device.
  904. */
  905. int pci_set_pcie_reset_state(struct pci_dev *dev, enum pcie_reset_state state)
  906. {
  907. return pcibios_set_pcie_reset_state(dev, state);
  908. }
  909. /**
  910. * pci_pme_capable - check the capability of PCI device to generate PME#
  911. * @dev: PCI device to handle.
  912. * @pm: PCI PM capability offset of the device.
  913. * @state: PCI state from which device will issue PME#.
  914. */
  915. static bool pci_pme_capable(struct pci_dev *dev, int pm, pci_power_t state)
  916. {
  917. u16 pmc;
  918. if (!pm)
  919. return false;
  920. /* Check device's ability to generate PME# from given state */
  921. pci_read_config_word(dev, pm + PCI_PM_PMC, &pmc);
  922. pmc &= PCI_PM_CAP_PME_MASK;
  923. pmc >>= ffs(PCI_PM_CAP_PME_MASK) - 1; /* First bit of mask */
  924. return !!(pmc & (1 << state));
  925. }
  926. /**
  927. * pci_pme_active - enable or disable PCI device's PME# function
  928. * @dev: PCI device to handle.
  929. * @pm: PCI PM capability offset of the device.
  930. * @enable: 'true' to enable PME# generation; 'false' to disable it.
  931. *
  932. * The caller must verify that the device is capable of generating PME# before
  933. * calling this function with @enable equal to 'true'.
  934. */
  935. static void pci_pme_active(struct pci_dev *dev, int pm, bool enable)
  936. {
  937. u16 pmcsr;
  938. if (!pm)
  939. return;
  940. pci_read_config_word(dev, pm + PCI_PM_CTRL, &pmcsr);
  941. /* Clear PME_Status by writing 1 to it and enable PME# */
  942. pmcsr |= PCI_PM_CTRL_PME_STATUS | PCI_PM_CTRL_PME_ENABLE;
  943. if (!enable)
  944. pmcsr &= ~PCI_PM_CTRL_PME_ENABLE;
  945. pci_write_config_word(dev, pm + PCI_PM_CTRL, pmcsr);
  946. dev_printk(KERN_INFO, &dev->dev, "PME# %s\n",
  947. enable ? "enabled" : "disabled");
  948. }
  949. /**
  950. * pci_enable_wake - enable PCI device as wakeup event source
  951. * @dev: PCI device affected
  952. * @state: PCI state from which device will issue wakeup events
  953. * @enable: True to enable event generation; false to disable
  954. *
  955. * This enables the device as a wakeup event source, or disables it.
  956. * When such events involves platform-specific hooks, those hooks are
  957. * called automatically by this routine.
  958. *
  959. * Devices with legacy power management (no standard PCI PM capabilities)
  960. * always require such platform hooks.
  961. *
  962. * RETURN VALUE:
  963. * 0 is returned on success
  964. * -EINVAL is returned if device is not supposed to wake up the system
  965. * Error code depending on the platform is returned if both the platform and
  966. * the native mechanism fail to enable the generation of wake-up events
  967. */
  968. int pci_enable_wake(struct pci_dev *dev, pci_power_t state, int enable)
  969. {
  970. int pm;
  971. int error = 0;
  972. bool pme_done = false;
  973. if (!device_may_wakeup(&dev->dev))
  974. return -EINVAL;
  975. /*
  976. * According to "PCI System Architecture" 4th ed. by Tom Shanley & Don
  977. * Anderson we should be doing PME# wake enable followed by ACPI wake
  978. * enable. To disable wake-up we call the platform first, for symmetry.
  979. */
  980. if (!enable && platform_pci_can_wakeup(dev))
  981. error = platform_pci_sleep_wake(dev, false);
  982. pm = pci_find_capability(dev, PCI_CAP_ID_PM);
  983. if (!enable || pci_pme_capable(dev, pm, state)) {
  984. pci_pme_active(dev, pm, enable);
  985. pme_done = true;
  986. }
  987. if (enable && platform_pci_can_wakeup(dev))
  988. error = platform_pci_sleep_wake(dev, true);
  989. return pme_done ? 0 : error;
  990. }
  991. /**
  992. * pci_pm_init - Initialize PM functions of given PCI device
  993. * @dev: PCI device to handle.
  994. */
  995. void pci_pm_init(struct pci_dev *dev)
  996. {
  997. int pm;
  998. u16 pmc;
  999. /* find PCI PM capability in list */
  1000. pm = pci_find_capability(dev, PCI_CAP_ID_PM);
  1001. if (!pm)
  1002. return;
  1003. /* Check device's ability to generate PME# */
  1004. pci_read_config_word(dev, pm + PCI_PM_PMC, &pmc);
  1005. if ((pmc & PCI_PM_CAP_VER_MASK) > 3) {
  1006. dev_err(&dev->dev, "unsupported PM cap regs version (%u)\n",
  1007. pmc & PCI_PM_CAP_VER_MASK);
  1008. return;
  1009. }
  1010. if (pmc & PCI_PM_CAP_PME_MASK) {
  1011. dev_printk(KERN_INFO, &dev->dev,
  1012. "PME# supported from%s%s%s%s%s\n",
  1013. (pmc & PCI_PM_CAP_PME_D0) ? " D0" : "",
  1014. (pmc & PCI_PM_CAP_PME_D1) ? " D1" : "",
  1015. (pmc & PCI_PM_CAP_PME_D2) ? " D2" : "",
  1016. (pmc & PCI_PM_CAP_PME_D3) ? " D3hot" : "",
  1017. (pmc & PCI_PM_CAP_PME_D3cold) ? " D3cold" : "");
  1018. /*
  1019. * Make device's PM flags reflect the wake-up capability, but
  1020. * let the user space enable it to wake up the system as needed.
  1021. */
  1022. device_set_wakeup_capable(&dev->dev, true);
  1023. device_set_wakeup_enable(&dev->dev, false);
  1024. /* Disable the PME# generation functionality */
  1025. pci_pme_active(dev, pm, false);
  1026. }
  1027. }
  1028. int
  1029. pci_get_interrupt_pin(struct pci_dev *dev, struct pci_dev **bridge)
  1030. {
  1031. u8 pin;
  1032. pin = dev->pin;
  1033. if (!pin)
  1034. return -1;
  1035. pin--;
  1036. while (dev->bus->self) {
  1037. pin = (pin + PCI_SLOT(dev->devfn)) % 4;
  1038. dev = dev->bus->self;
  1039. }
  1040. *bridge = dev;
  1041. return pin;
  1042. }
  1043. /**
  1044. * pci_release_region - Release a PCI bar
  1045. * @pdev: PCI device whose resources were previously reserved by pci_request_region
  1046. * @bar: BAR to release
  1047. *
  1048. * Releases the PCI I/O and memory resources previously reserved by a
  1049. * successful call to pci_request_region. Call this function only
  1050. * after all use of the PCI regions has ceased.
  1051. */
  1052. void pci_release_region(struct pci_dev *pdev, int bar)
  1053. {
  1054. struct pci_devres *dr;
  1055. if (pci_resource_len(pdev, bar) == 0)
  1056. return;
  1057. if (pci_resource_flags(pdev, bar) & IORESOURCE_IO)
  1058. release_region(pci_resource_start(pdev, bar),
  1059. pci_resource_len(pdev, bar));
  1060. else if (pci_resource_flags(pdev, bar) & IORESOURCE_MEM)
  1061. release_mem_region(pci_resource_start(pdev, bar),
  1062. pci_resource_len(pdev, bar));
  1063. dr = find_pci_dr(pdev);
  1064. if (dr)
  1065. dr->region_mask &= ~(1 << bar);
  1066. }
  1067. /**
  1068. * pci_request_region - Reserved PCI I/O and memory resource
  1069. * @pdev: PCI device whose resources are to be reserved
  1070. * @bar: BAR to be reserved
  1071. * @res_name: Name to be associated with resource.
  1072. *
  1073. * Mark the PCI region associated with PCI device @pdev BR @bar as
  1074. * being reserved by owner @res_name. Do not access any
  1075. * address inside the PCI regions unless this call returns
  1076. * successfully.
  1077. *
  1078. * Returns 0 on success, or %EBUSY on error. A warning
  1079. * message is also printed on failure.
  1080. */
  1081. int pci_request_region(struct pci_dev *pdev, int bar, const char *res_name)
  1082. {
  1083. struct pci_devres *dr;
  1084. if (pci_resource_len(pdev, bar) == 0)
  1085. return 0;
  1086. if (pci_resource_flags(pdev, bar) & IORESOURCE_IO) {
  1087. if (!request_region(pci_resource_start(pdev, bar),
  1088. pci_resource_len(pdev, bar), res_name))
  1089. goto err_out;
  1090. }
  1091. else if (pci_resource_flags(pdev, bar) & IORESOURCE_MEM) {
  1092. if (!request_mem_region(pci_resource_start(pdev, bar),
  1093. pci_resource_len(pdev, bar), res_name))
  1094. goto err_out;
  1095. }
  1096. dr = find_pci_dr(pdev);
  1097. if (dr)
  1098. dr->region_mask |= 1 << bar;
  1099. return 0;
  1100. err_out:
  1101. dev_warn(&pdev->dev, "BAR %d: can't reserve %s region [%#llx-%#llx]\n",
  1102. bar,
  1103. pci_resource_flags(pdev, bar) & IORESOURCE_IO ? "I/O" : "mem",
  1104. (unsigned long long)pci_resource_start(pdev, bar),
  1105. (unsigned long long)pci_resource_end(pdev, bar));
  1106. return -EBUSY;
  1107. }
  1108. /**
  1109. * pci_release_selected_regions - Release selected PCI I/O and memory resources
  1110. * @pdev: PCI device whose resources were previously reserved
  1111. * @bars: Bitmask of BARs to be released
  1112. *
  1113. * Release selected PCI I/O and memory resources previously reserved.
  1114. * Call this function only after all use of the PCI regions has ceased.
  1115. */
  1116. void pci_release_selected_regions(struct pci_dev *pdev, int bars)
  1117. {
  1118. int i;
  1119. for (i = 0; i < 6; i++)
  1120. if (bars & (1 << i))
  1121. pci_release_region(pdev, i);
  1122. }
  1123. /**
  1124. * pci_request_selected_regions - Reserve selected PCI I/O and memory resources
  1125. * @pdev: PCI device whose resources are to be reserved
  1126. * @bars: Bitmask of BARs to be requested
  1127. * @res_name: Name to be associated with resource
  1128. */
  1129. int pci_request_selected_regions(struct pci_dev *pdev, int bars,
  1130. const char *res_name)
  1131. {
  1132. int i;
  1133. for (i = 0; i < 6; i++)
  1134. if (bars & (1 << i))
  1135. if(pci_request_region(pdev, i, res_name))
  1136. goto err_out;
  1137. return 0;
  1138. err_out:
  1139. while(--i >= 0)
  1140. if (bars & (1 << i))
  1141. pci_release_region(pdev, i);
  1142. return -EBUSY;
  1143. }
  1144. /**
  1145. * pci_release_regions - Release reserved PCI I/O and memory resources
  1146. * @pdev: PCI device whose resources were previously reserved by pci_request_regions
  1147. *
  1148. * Releases all PCI I/O and memory resources previously reserved by a
  1149. * successful call to pci_request_regions. Call this function only
  1150. * after all use of the PCI regions has ceased.
  1151. */
  1152. void pci_release_regions(struct pci_dev *pdev)
  1153. {
  1154. pci_release_selected_regions(pdev, (1 << 6) - 1);
  1155. }
  1156. /**
  1157. * pci_request_regions - Reserved PCI I/O and memory resources
  1158. * @pdev: PCI device whose resources are to be reserved
  1159. * @res_name: Name to be associated with resource.
  1160. *
  1161. * Mark all PCI regions associated with PCI device @pdev as
  1162. * being reserved by owner @res_name. Do not access any
  1163. * address inside the PCI regions unless this call returns
  1164. * successfully.
  1165. *
  1166. * Returns 0 on success, or %EBUSY on error. A warning
  1167. * message is also printed on failure.
  1168. */
  1169. int pci_request_regions(struct pci_dev *pdev, const char *res_name)
  1170. {
  1171. return pci_request_selected_regions(pdev, ((1 << 6) - 1), res_name);
  1172. }
  1173. /**
  1174. * pci_set_master - enables bus-mastering for device dev
  1175. * @dev: the PCI device to enable
  1176. *
  1177. * Enables bus-mastering on the device and calls pcibios_set_master()
  1178. * to do the needed arch specific settings.
  1179. */
  1180. void
  1181. pci_set_master(struct pci_dev *dev)
  1182. {
  1183. u16 cmd;
  1184. pci_read_config_word(dev, PCI_COMMAND, &cmd);
  1185. if (! (cmd & PCI_COMMAND_MASTER)) {
  1186. dev_dbg(&dev->dev, "enabling bus mastering\n");
  1187. cmd |= PCI_COMMAND_MASTER;
  1188. pci_write_config_word(dev, PCI_COMMAND, cmd);
  1189. }
  1190. dev->is_busmaster = 1;
  1191. pcibios_set_master(dev);
  1192. }
  1193. #ifdef PCI_DISABLE_MWI
  1194. int pci_set_mwi(struct pci_dev *dev)
  1195. {
  1196. return 0;
  1197. }
  1198. int pci_try_set_mwi(struct pci_dev *dev)
  1199. {
  1200. return 0;
  1201. }
  1202. void pci_clear_mwi(struct pci_dev *dev)
  1203. {
  1204. }
  1205. #else
  1206. #ifndef PCI_CACHE_LINE_BYTES
  1207. #define PCI_CACHE_LINE_BYTES L1_CACHE_BYTES
  1208. #endif
  1209. /* This can be overridden by arch code. */
  1210. /* Don't forget this is measured in 32-bit words, not bytes */
  1211. u8 pci_cache_line_size = PCI_CACHE_LINE_BYTES / 4;
  1212. /**
  1213. * pci_set_cacheline_size - ensure the CACHE_LINE_SIZE register is programmed
  1214. * @dev: the PCI device for which MWI is to be enabled
  1215. *
  1216. * Helper function for pci_set_mwi.
  1217. * Originally copied from drivers/net/acenic.c.
  1218. * Copyright 1998-2001 by Jes Sorensen, <jes@trained-monkey.org>.
  1219. *
  1220. * RETURNS: An appropriate -ERRNO error value on error, or zero for success.
  1221. */
  1222. static int
  1223. pci_set_cacheline_size(struct pci_dev *dev)
  1224. {
  1225. u8 cacheline_size;
  1226. if (!pci_cache_line_size)
  1227. return -EINVAL; /* The system doesn't support MWI. */
  1228. /* Validate current setting: the PCI_CACHE_LINE_SIZE must be
  1229. equal to or multiple of the right value. */
  1230. pci_read_config_byte(dev, PCI_CACHE_LINE_SIZE, &cacheline_size);
  1231. if (cacheline_size >= pci_cache_line_size &&
  1232. (cacheline_size % pci_cache_line_size) == 0)
  1233. return 0;
  1234. /* Write the correct value. */
  1235. pci_write_config_byte(dev, PCI_CACHE_LINE_SIZE, pci_cache_line_size);
  1236. /* Read it back. */
  1237. pci_read_config_byte(dev, PCI_CACHE_LINE_SIZE, &cacheline_size);
  1238. if (cacheline_size == pci_cache_line_size)
  1239. return 0;
  1240. dev_printk(KERN_DEBUG, &dev->dev, "cache line size of %d is not "
  1241. "supported\n", pci_cache_line_size << 2);
  1242. return -EINVAL;
  1243. }
  1244. /**
  1245. * pci_set_mwi - enables memory-write-invalidate PCI transaction
  1246. * @dev: the PCI device for which MWI is enabled
  1247. *
  1248. * Enables the Memory-Write-Invalidate transaction in %PCI_COMMAND.
  1249. *
  1250. * RETURNS: An appropriate -ERRNO error value on error, or zero for success.
  1251. */
  1252. int
  1253. pci_set_mwi(struct pci_dev *dev)
  1254. {
  1255. int rc;
  1256. u16 cmd;
  1257. rc = pci_set_cacheline_size(dev);
  1258. if (rc)
  1259. return rc;
  1260. pci_read_config_word(dev, PCI_COMMAND, &cmd);
  1261. if (! (cmd & PCI_COMMAND_INVALIDATE)) {
  1262. dev_dbg(&dev->dev, "enabling Mem-Wr-Inval\n");
  1263. cmd |= PCI_COMMAND_INVALIDATE;
  1264. pci_write_config_word(dev, PCI_COMMAND, cmd);
  1265. }
  1266. return 0;
  1267. }
  1268. /**
  1269. * pci_try_set_mwi - enables memory-write-invalidate PCI transaction
  1270. * @dev: the PCI device for which MWI is enabled
  1271. *
  1272. * Enables the Memory-Write-Invalidate transaction in %PCI_COMMAND.
  1273. * Callers are not required to check the return value.
  1274. *
  1275. * RETURNS: An appropriate -ERRNO error value on error, or zero for success.
  1276. */
  1277. int pci_try_set_mwi(struct pci_dev *dev)
  1278. {
  1279. int rc = pci_set_mwi(dev);
  1280. return rc;
  1281. }
  1282. /**
  1283. * pci_clear_mwi - disables Memory-Write-Invalidate for device dev
  1284. * @dev: the PCI device to disable
  1285. *
  1286. * Disables PCI Memory-Write-Invalidate transaction on the device
  1287. */
  1288. void
  1289. pci_clear_mwi(struct pci_dev *dev)
  1290. {
  1291. u16 cmd;
  1292. pci_read_config_word(dev, PCI_COMMAND, &cmd);
  1293. if (cmd & PCI_COMMAND_INVALIDATE) {
  1294. cmd &= ~PCI_COMMAND_INVALIDATE;
  1295. pci_write_config_word(dev, PCI_COMMAND, cmd);
  1296. }
  1297. }
  1298. #endif /* ! PCI_DISABLE_MWI */
  1299. /**
  1300. * pci_intx - enables/disables PCI INTx for device dev
  1301. * @pdev: the PCI device to operate on
  1302. * @enable: boolean: whether to enable or disable PCI INTx
  1303. *
  1304. * Enables/disables PCI INTx for device dev
  1305. */
  1306. void
  1307. pci_intx(struct pci_dev *pdev, int enable)
  1308. {
  1309. u16 pci_command, new;
  1310. pci_read_config_word(pdev, PCI_COMMAND, &pci_command);
  1311. if (enable) {
  1312. new = pci_command & ~PCI_COMMAND_INTX_DISABLE;
  1313. } else {
  1314. new = pci_command | PCI_COMMAND_INTX_DISABLE;
  1315. }
  1316. if (new != pci_command) {
  1317. struct pci_devres *dr;
  1318. pci_write_config_word(pdev, PCI_COMMAND, new);
  1319. dr = find_pci_dr(pdev);
  1320. if (dr && !dr->restore_intx) {
  1321. dr->restore_intx = 1;
  1322. dr->orig_intx = !enable;
  1323. }
  1324. }
  1325. }
  1326. /**
  1327. * pci_msi_off - disables any msi or msix capabilities
  1328. * @dev: the PCI device to operate on
  1329. *
  1330. * If you want to use msi see pci_enable_msi and friends.
  1331. * This is a lower level primitive that allows us to disable
  1332. * msi operation at the device level.
  1333. */
  1334. void pci_msi_off(struct pci_dev *dev)
  1335. {
  1336. int pos;
  1337. u16 control;
  1338. pos = pci_find_capability(dev, PCI_CAP_ID_MSI);
  1339. if (pos) {
  1340. pci_read_config_word(dev, pos + PCI_MSI_FLAGS, &control);
  1341. control &= ~PCI_MSI_FLAGS_ENABLE;
  1342. pci_write_config_word(dev, pos + PCI_MSI_FLAGS, control);
  1343. }
  1344. pos = pci_find_capability(dev, PCI_CAP_ID_MSIX);
  1345. if (pos) {
  1346. pci_read_config_word(dev, pos + PCI_MSIX_FLAGS, &control);
  1347. control &= ~PCI_MSIX_FLAGS_ENABLE;
  1348. pci_write_config_word(dev, pos + PCI_MSIX_FLAGS, control);
  1349. }
  1350. }
  1351. #ifndef HAVE_ARCH_PCI_SET_DMA_MASK
  1352. /*
  1353. * These can be overridden by arch-specific implementations
  1354. */
  1355. int
  1356. pci_set_dma_mask(struct pci_dev *dev, u64 mask)
  1357. {
  1358. if (!pci_dma_supported(dev, mask))
  1359. return -EIO;
  1360. dev->dma_mask = mask;
  1361. return 0;
  1362. }
  1363. int
  1364. pci_set_consistent_dma_mask(struct pci_dev *dev, u64 mask)
  1365. {
  1366. if (!pci_dma_supported(dev, mask))
  1367. return -EIO;
  1368. dev->dev.coherent_dma_mask = mask;
  1369. return 0;
  1370. }
  1371. #endif
  1372. #ifndef HAVE_ARCH_PCI_SET_DMA_MAX_SEGMENT_SIZE
  1373. int pci_set_dma_max_seg_size(struct pci_dev *dev, unsigned int size)
  1374. {
  1375. return dma_set_max_seg_size(&dev->dev, size);
  1376. }
  1377. EXPORT_SYMBOL(pci_set_dma_max_seg_size);
  1378. #endif
  1379. #ifndef HAVE_ARCH_PCI_SET_DMA_SEGMENT_BOUNDARY
  1380. int pci_set_dma_seg_boundary(struct pci_dev *dev, unsigned long mask)
  1381. {
  1382. return dma_set_seg_boundary(&dev->dev, mask);
  1383. }
  1384. EXPORT_SYMBOL(pci_set_dma_seg_boundary);
  1385. #endif
  1386. /**
  1387. * pcix_get_max_mmrbc - get PCI-X maximum designed memory read byte count
  1388. * @dev: PCI device to query
  1389. *
  1390. * Returns mmrbc: maximum designed memory read count in bytes
  1391. * or appropriate error value.
  1392. */
  1393. int pcix_get_max_mmrbc(struct pci_dev *dev)
  1394. {
  1395. int err, cap;
  1396. u32 stat;
  1397. cap = pci_find_capability(dev, PCI_CAP_ID_PCIX);
  1398. if (!cap)
  1399. return -EINVAL;
  1400. err = pci_read_config_dword(dev, cap + PCI_X_STATUS, &stat);
  1401. if (err)
  1402. return -EINVAL;
  1403. return (stat & PCI_X_STATUS_MAX_READ) >> 12;
  1404. }
  1405. EXPORT_SYMBOL(pcix_get_max_mmrbc);
  1406. /**
  1407. * pcix_get_mmrbc - get PCI-X maximum memory read byte count
  1408. * @dev: PCI device to query
  1409. *
  1410. * Returns mmrbc: maximum memory read count in bytes
  1411. * or appropriate error value.
  1412. */
  1413. int pcix_get_mmrbc(struct pci_dev *dev)
  1414. {
  1415. int ret, cap;
  1416. u32 cmd;
  1417. cap = pci_find_capability(dev, PCI_CAP_ID_PCIX);
  1418. if (!cap)
  1419. return -EINVAL;
  1420. ret = pci_read_config_dword(dev, cap + PCI_X_CMD, &cmd);
  1421. if (!ret)
  1422. ret = 512 << ((cmd & PCI_X_CMD_MAX_READ) >> 2);
  1423. return ret;
  1424. }
  1425. EXPORT_SYMBOL(pcix_get_mmrbc);
  1426. /**
  1427. * pcix_set_mmrbc - set PCI-X maximum memory read byte count
  1428. * @dev: PCI device to query
  1429. * @mmrbc: maximum memory read count in bytes
  1430. * valid values are 512, 1024, 2048, 4096
  1431. *
  1432. * If possible sets maximum memory read byte count, some bridges have erratas
  1433. * that prevent this.
  1434. */
  1435. int pcix_set_mmrbc(struct pci_dev *dev, int mmrbc)
  1436. {
  1437. int cap, err = -EINVAL;
  1438. u32 stat, cmd, v, o;
  1439. if (mmrbc < 512 || mmrbc > 4096 || !is_power_of_2(mmrbc))
  1440. goto out;
  1441. v = ffs(mmrbc) - 10;
  1442. cap = pci_find_capability(dev, PCI_CAP_ID_PCIX);
  1443. if (!cap)
  1444. goto out;
  1445. err = pci_read_config_dword(dev, cap + PCI_X_STATUS, &stat);
  1446. if (err)
  1447. goto out;
  1448. if (v > (stat & PCI_X_STATUS_MAX_READ) >> 21)
  1449. return -E2BIG;
  1450. err = pci_read_config_dword(dev, cap + PCI_X_CMD, &cmd);
  1451. if (err)
  1452. goto out;
  1453. o = (cmd & PCI_X_CMD_MAX_READ) >> 2;
  1454. if (o != v) {
  1455. if (v > o && dev->bus &&
  1456. (dev->bus->bus_flags & PCI_BUS_FLAGS_NO_MMRBC))
  1457. return -EIO;
  1458. cmd &= ~PCI_X_CMD_MAX_READ;
  1459. cmd |= v << 2;
  1460. err = pci_write_config_dword(dev, cap + PCI_X_CMD, cmd);
  1461. }
  1462. out:
  1463. return err;
  1464. }
  1465. EXPORT_SYMBOL(pcix_set_mmrbc);
  1466. /**
  1467. * pcie_get_readrq - get PCI Express read request size
  1468. * @dev: PCI device to query
  1469. *
  1470. * Returns maximum memory read request in bytes
  1471. * or appropriate error value.
  1472. */
  1473. int pcie_get_readrq(struct pci_dev *dev)
  1474. {
  1475. int ret, cap;
  1476. u16 ctl;
  1477. cap = pci_find_capability(dev, PCI_CAP_ID_EXP);
  1478. if (!cap)
  1479. return -EINVAL;
  1480. ret = pci_read_config_word(dev, cap + PCI_EXP_DEVCTL, &ctl);
  1481. if (!ret)
  1482. ret = 128 << ((ctl & PCI_EXP_DEVCTL_READRQ) >> 12);
  1483. return ret;
  1484. }
  1485. EXPORT_SYMBOL(pcie_get_readrq);
  1486. /**
  1487. * pcie_set_readrq - set PCI Express maximum memory read request
  1488. * @dev: PCI device to query
  1489. * @rq: maximum memory read count in bytes
  1490. * valid values are 128, 256, 512, 1024, 2048, 4096
  1491. *
  1492. * If possible sets maximum read byte count
  1493. */
  1494. int pcie_set_readrq(struct pci_dev *dev, int rq)
  1495. {
  1496. int cap, err = -EINVAL;
  1497. u16 ctl, v;
  1498. if (rq < 128 || rq > 4096 || !is_power_of_2(rq))
  1499. goto out;
  1500. v = (ffs(rq) - 8) << 12;
  1501. cap = pci_find_capability(dev, PCI_CAP_ID_EXP);
  1502. if (!cap)
  1503. goto out;
  1504. err = pci_read_config_word(dev, cap + PCI_EXP_DEVCTL, &ctl);
  1505. if (err)
  1506. goto out;
  1507. if ((ctl & PCI_EXP_DEVCTL_READRQ) != v) {
  1508. ctl &= ~PCI_EXP_DEVCTL_READRQ;
  1509. ctl |= v;
  1510. err = pci_write_config_dword(dev, cap + PCI_EXP_DEVCTL, ctl);
  1511. }
  1512. out:
  1513. return err;
  1514. }
  1515. EXPORT_SYMBOL(pcie_set_readrq);
  1516. /**
  1517. * pci_select_bars - Make BAR mask from the type of resource
  1518. * @dev: the PCI device for which BAR mask is made
  1519. * @flags: resource type mask to be selected
  1520. *
  1521. * This helper routine makes bar mask from the type of resource.
  1522. */
  1523. int pci_select_bars(struct pci_dev *dev, unsigned long flags)
  1524. {
  1525. int i, bars = 0;
  1526. for (i = 0; i < PCI_NUM_RESOURCES; i++)
  1527. if (pci_resource_flags(dev, i) & flags)
  1528. bars |= (1 << i);
  1529. return bars;
  1530. }
  1531. static void __devinit pci_no_domains(void)
  1532. {
  1533. #ifdef CONFIG_PCI_DOMAINS
  1534. pci_domains_supported = 0;
  1535. #endif
  1536. }
  1537. static int __devinit pci_init(void)
  1538. {
  1539. struct pci_dev *dev = NULL;
  1540. while ((dev = pci_get_device(PCI_ANY_ID, PCI_ANY_ID, dev)) != NULL) {
  1541. pci_fixup_device(pci_fixup_final, dev);
  1542. }
  1543. return 0;
  1544. }
  1545. static int __devinit pci_setup(char *str)
  1546. {
  1547. while (str) {
  1548. char *k = strchr(str, ',');
  1549. if (k)
  1550. *k++ = 0;
  1551. if (*str && (str = pcibios_setup(str)) && *str) {
  1552. if (!strcmp(str, "nomsi")) {
  1553. pci_no_msi();
  1554. } else if (!strcmp(str, "noaer")) {
  1555. pci_no_aer();
  1556. } else if (!strcmp(str, "nodomains")) {
  1557. pci_no_domains();
  1558. } else if (!strncmp(str, "cbiosize=", 9)) {
  1559. pci_cardbus_io_size = memparse(str + 9, &str);
  1560. } else if (!strncmp(str, "cbmemsize=", 10)) {
  1561. pci_cardbus_mem_size = memparse(str + 10, &str);
  1562. } else {
  1563. printk(KERN_ERR "PCI: Unknown option `%s'\n",
  1564. str);
  1565. }
  1566. }
  1567. str = k;
  1568. }
  1569. return 0;
  1570. }
  1571. early_param("pci", pci_setup);
  1572. device_initcall(pci_init);
  1573. EXPORT_SYMBOL(pci_reenable_device);
  1574. EXPORT_SYMBOL(pci_enable_device_io);
  1575. EXPORT_SYMBOL(pci_enable_device_mem);
  1576. EXPORT_SYMBOL(pci_enable_device);
  1577. EXPORT_SYMBOL(pcim_enable_device);
  1578. EXPORT_SYMBOL(pcim_pin_device);
  1579. EXPORT_SYMBOL(pci_disable_device);
  1580. EXPORT_SYMBOL(pci_find_capability);
  1581. EXPORT_SYMBOL(pci_bus_find_capability);
  1582. EXPORT_SYMBOL(pci_release_regions);
  1583. EXPORT_SYMBOL(pci_request_regions);
  1584. EXPORT_SYMBOL(pci_release_region);
  1585. EXPORT_SYMBOL(pci_request_region);
  1586. EXPORT_SYMBOL(pci_release_selected_regions);
  1587. EXPORT_SYMBOL(pci_request_selected_regions);
  1588. EXPORT_SYMBOL(pci_set_master);
  1589. EXPORT_SYMBOL(pci_set_mwi);
  1590. EXPORT_SYMBOL(pci_try_set_mwi);
  1591. EXPORT_SYMBOL(pci_clear_mwi);
  1592. EXPORT_SYMBOL_GPL(pci_intx);
  1593. EXPORT_SYMBOL(pci_set_dma_mask);
  1594. EXPORT_SYMBOL(pci_set_consistent_dma_mask);
  1595. EXPORT_SYMBOL(pci_assign_resource);
  1596. EXPORT_SYMBOL(pci_find_parent_resource);
  1597. EXPORT_SYMBOL(pci_select_bars);
  1598. EXPORT_SYMBOL(pci_set_power_state);
  1599. EXPORT_SYMBOL(pci_save_state);
  1600. EXPORT_SYMBOL(pci_restore_state);
  1601. EXPORT_SYMBOL(pci_enable_wake);
  1602. EXPORT_SYMBOL_GPL(pci_set_pcie_reset_state);