pci.c 63 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458
  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 <linux/pm_wakeup.h>
  20. #include <linux/interrupt.h>
  21. #include <asm/dma.h> /* isa_dma_bridge_buggy */
  22. #include "pci.h"
  23. unsigned int pci_pm_d3_delay = PCI_PM_D3_WAIT;
  24. #ifdef CONFIG_PCI_DOMAINS
  25. int pci_domains_supported = 1;
  26. #endif
  27. #define DEFAULT_CARDBUS_IO_SIZE (256)
  28. #define DEFAULT_CARDBUS_MEM_SIZE (64*1024*1024)
  29. /* pci=cbmemsize=nnM,cbiosize=nn can override this */
  30. unsigned long pci_cardbus_io_size = DEFAULT_CARDBUS_IO_SIZE;
  31. unsigned long pci_cardbus_mem_size = DEFAULT_CARDBUS_MEM_SIZE;
  32. /**
  33. * pci_bus_max_busnr - returns maximum PCI bus number of given bus' children
  34. * @bus: pointer to PCI bus structure to search
  35. *
  36. * Given a PCI bus, returns the highest PCI bus number present in the set
  37. * including the given PCI bus and its list of child PCI buses.
  38. */
  39. unsigned char pci_bus_max_busnr(struct pci_bus* bus)
  40. {
  41. struct list_head *tmp;
  42. unsigned char max, n;
  43. max = bus->subordinate;
  44. list_for_each(tmp, &bus->children) {
  45. n = pci_bus_max_busnr(pci_bus_b(tmp));
  46. if(n > max)
  47. max = n;
  48. }
  49. return max;
  50. }
  51. EXPORT_SYMBOL_GPL(pci_bus_max_busnr);
  52. #ifdef CONFIG_HAS_IOMEM
  53. void __iomem *pci_ioremap_bar(struct pci_dev *pdev, int bar)
  54. {
  55. /*
  56. * Make sure the BAR is actually a memory resource, not an IO resource
  57. */
  58. if (!(pci_resource_flags(pdev, bar) & IORESOURCE_MEM)) {
  59. WARN_ON(1);
  60. return NULL;
  61. }
  62. return ioremap_nocache(pci_resource_start(pdev, bar),
  63. pci_resource_len(pdev, bar));
  64. }
  65. EXPORT_SYMBOL_GPL(pci_ioremap_bar);
  66. #endif
  67. #if 0
  68. /**
  69. * pci_max_busnr - returns maximum PCI bus number
  70. *
  71. * Returns the highest PCI bus number present in the system global list of
  72. * PCI buses.
  73. */
  74. unsigned char __devinit
  75. pci_max_busnr(void)
  76. {
  77. struct pci_bus *bus = NULL;
  78. unsigned char max, n;
  79. max = 0;
  80. while ((bus = pci_find_next_bus(bus)) != NULL) {
  81. n = pci_bus_max_busnr(bus);
  82. if(n > max)
  83. max = n;
  84. }
  85. return max;
  86. }
  87. #endif /* 0 */
  88. #define PCI_FIND_CAP_TTL 48
  89. static int __pci_find_next_cap_ttl(struct pci_bus *bus, unsigned int devfn,
  90. u8 pos, int cap, int *ttl)
  91. {
  92. u8 id;
  93. while ((*ttl)--) {
  94. pci_bus_read_config_byte(bus, devfn, pos, &pos);
  95. if (pos < 0x40)
  96. break;
  97. pos &= ~3;
  98. pci_bus_read_config_byte(bus, devfn, pos + PCI_CAP_LIST_ID,
  99. &id);
  100. if (id == 0xff)
  101. break;
  102. if (id == cap)
  103. return pos;
  104. pos += PCI_CAP_LIST_NEXT;
  105. }
  106. return 0;
  107. }
  108. static int __pci_find_next_cap(struct pci_bus *bus, unsigned int devfn,
  109. u8 pos, int cap)
  110. {
  111. int ttl = PCI_FIND_CAP_TTL;
  112. return __pci_find_next_cap_ttl(bus, devfn, pos, cap, &ttl);
  113. }
  114. int pci_find_next_capability(struct pci_dev *dev, u8 pos, int cap)
  115. {
  116. return __pci_find_next_cap(dev->bus, dev->devfn,
  117. pos + PCI_CAP_LIST_NEXT, cap);
  118. }
  119. EXPORT_SYMBOL_GPL(pci_find_next_capability);
  120. static int __pci_bus_find_cap_start(struct pci_bus *bus,
  121. unsigned int devfn, u8 hdr_type)
  122. {
  123. u16 status;
  124. pci_bus_read_config_word(bus, devfn, PCI_STATUS, &status);
  125. if (!(status & PCI_STATUS_CAP_LIST))
  126. return 0;
  127. switch (hdr_type) {
  128. case PCI_HEADER_TYPE_NORMAL:
  129. case PCI_HEADER_TYPE_BRIDGE:
  130. return PCI_CAPABILITY_LIST;
  131. case PCI_HEADER_TYPE_CARDBUS:
  132. return PCI_CB_CAPABILITY_LIST;
  133. default:
  134. return 0;
  135. }
  136. return 0;
  137. }
  138. /**
  139. * pci_find_capability - query for devices' capabilities
  140. * @dev: PCI device to query
  141. * @cap: capability code
  142. *
  143. * Tell if a device supports a given PCI capability.
  144. * Returns the address of the requested capability structure within the
  145. * device's PCI configuration space or 0 in case the device does not
  146. * support it. Possible values for @cap:
  147. *
  148. * %PCI_CAP_ID_PM Power Management
  149. * %PCI_CAP_ID_AGP Accelerated Graphics Port
  150. * %PCI_CAP_ID_VPD Vital Product Data
  151. * %PCI_CAP_ID_SLOTID Slot Identification
  152. * %PCI_CAP_ID_MSI Message Signalled Interrupts
  153. * %PCI_CAP_ID_CHSWP CompactPCI HotSwap
  154. * %PCI_CAP_ID_PCIX PCI-X
  155. * %PCI_CAP_ID_EXP PCI Express
  156. */
  157. int pci_find_capability(struct pci_dev *dev, int cap)
  158. {
  159. int pos;
  160. pos = __pci_bus_find_cap_start(dev->bus, dev->devfn, dev->hdr_type);
  161. if (pos)
  162. pos = __pci_find_next_cap(dev->bus, dev->devfn, pos, cap);
  163. return pos;
  164. }
  165. /**
  166. * pci_bus_find_capability - query for devices' capabilities
  167. * @bus: the PCI bus to query
  168. * @devfn: PCI device to query
  169. * @cap: capability code
  170. *
  171. * Like pci_find_capability() but works for pci devices that do not have a
  172. * pci_dev structure set up yet.
  173. *
  174. * Returns the address of the requested capability structure within the
  175. * device's PCI configuration space or 0 in case the device does not
  176. * support it.
  177. */
  178. int pci_bus_find_capability(struct pci_bus *bus, unsigned int devfn, int cap)
  179. {
  180. int pos;
  181. u8 hdr_type;
  182. pci_bus_read_config_byte(bus, devfn, PCI_HEADER_TYPE, &hdr_type);
  183. pos = __pci_bus_find_cap_start(bus, devfn, hdr_type & 0x7f);
  184. if (pos)
  185. pos = __pci_find_next_cap(bus, devfn, pos, cap);
  186. return pos;
  187. }
  188. /**
  189. * pci_find_ext_capability - Find an extended capability
  190. * @dev: PCI device to query
  191. * @cap: capability code
  192. *
  193. * Returns the address of the requested extended capability structure
  194. * within the device's PCI configuration space or 0 if the device does
  195. * not support it. Possible values for @cap:
  196. *
  197. * %PCI_EXT_CAP_ID_ERR Advanced Error Reporting
  198. * %PCI_EXT_CAP_ID_VC Virtual Channel
  199. * %PCI_EXT_CAP_ID_DSN Device Serial Number
  200. * %PCI_EXT_CAP_ID_PWR Power Budgeting
  201. */
  202. int pci_find_ext_capability(struct pci_dev *dev, int cap)
  203. {
  204. u32 header;
  205. int ttl;
  206. int pos = PCI_CFG_SPACE_SIZE;
  207. /* minimum 8 bytes per capability */
  208. ttl = (PCI_CFG_SPACE_EXP_SIZE - PCI_CFG_SPACE_SIZE) / 8;
  209. if (dev->cfg_size <= PCI_CFG_SPACE_SIZE)
  210. return 0;
  211. if (pci_read_config_dword(dev, pos, &header) != PCIBIOS_SUCCESSFUL)
  212. return 0;
  213. /*
  214. * If we have no capabilities, this is indicated by cap ID,
  215. * cap version and next pointer all being 0.
  216. */
  217. if (header == 0)
  218. return 0;
  219. while (ttl-- > 0) {
  220. if (PCI_EXT_CAP_ID(header) == cap)
  221. return pos;
  222. pos = PCI_EXT_CAP_NEXT(header);
  223. if (pos < PCI_CFG_SPACE_SIZE)
  224. break;
  225. if (pci_read_config_dword(dev, pos, &header) != PCIBIOS_SUCCESSFUL)
  226. break;
  227. }
  228. return 0;
  229. }
  230. EXPORT_SYMBOL_GPL(pci_find_ext_capability);
  231. static int __pci_find_next_ht_cap(struct pci_dev *dev, int pos, int ht_cap)
  232. {
  233. int rc, ttl = PCI_FIND_CAP_TTL;
  234. u8 cap, mask;
  235. if (ht_cap == HT_CAPTYPE_SLAVE || ht_cap == HT_CAPTYPE_HOST)
  236. mask = HT_3BIT_CAP_MASK;
  237. else
  238. mask = HT_5BIT_CAP_MASK;
  239. pos = __pci_find_next_cap_ttl(dev->bus, dev->devfn, pos,
  240. PCI_CAP_ID_HT, &ttl);
  241. while (pos) {
  242. rc = pci_read_config_byte(dev, pos + 3, &cap);
  243. if (rc != PCIBIOS_SUCCESSFUL)
  244. return 0;
  245. if ((cap & mask) == ht_cap)
  246. return pos;
  247. pos = __pci_find_next_cap_ttl(dev->bus, dev->devfn,
  248. pos + PCI_CAP_LIST_NEXT,
  249. PCI_CAP_ID_HT, &ttl);
  250. }
  251. return 0;
  252. }
  253. /**
  254. * pci_find_next_ht_capability - query a device's Hypertransport capabilities
  255. * @dev: PCI device to query
  256. * @pos: Position from which to continue searching
  257. * @ht_cap: Hypertransport capability code
  258. *
  259. * To be used in conjunction with pci_find_ht_capability() to search for
  260. * all capabilities matching @ht_cap. @pos should always be a value returned
  261. * from pci_find_ht_capability().
  262. *
  263. * NB. To be 100% safe against broken PCI devices, the caller should take
  264. * steps to avoid an infinite loop.
  265. */
  266. int pci_find_next_ht_capability(struct pci_dev *dev, int pos, int ht_cap)
  267. {
  268. return __pci_find_next_ht_cap(dev, pos + PCI_CAP_LIST_NEXT, ht_cap);
  269. }
  270. EXPORT_SYMBOL_GPL(pci_find_next_ht_capability);
  271. /**
  272. * pci_find_ht_capability - query a device's Hypertransport capabilities
  273. * @dev: PCI device to query
  274. * @ht_cap: Hypertransport capability code
  275. *
  276. * Tell if a device supports a given Hypertransport capability.
  277. * Returns an address within the device's PCI configuration space
  278. * or 0 in case the device does not support the request capability.
  279. * The address points to the PCI capability, of type PCI_CAP_ID_HT,
  280. * which has a Hypertransport capability matching @ht_cap.
  281. */
  282. int pci_find_ht_capability(struct pci_dev *dev, int ht_cap)
  283. {
  284. int pos;
  285. pos = __pci_bus_find_cap_start(dev->bus, dev->devfn, dev->hdr_type);
  286. if (pos)
  287. pos = __pci_find_next_ht_cap(dev, pos, ht_cap);
  288. return pos;
  289. }
  290. EXPORT_SYMBOL_GPL(pci_find_ht_capability);
  291. /**
  292. * pci_find_parent_resource - return resource region of parent bus of given region
  293. * @dev: PCI device structure contains resources to be searched
  294. * @res: child resource record for which parent is sought
  295. *
  296. * For given resource region of given device, return the resource
  297. * region of parent bus the given region is contained in or where
  298. * it should be allocated from.
  299. */
  300. struct resource *
  301. pci_find_parent_resource(const struct pci_dev *dev, struct resource *res)
  302. {
  303. const struct pci_bus *bus = dev->bus;
  304. int i;
  305. struct resource *best = NULL;
  306. for(i = 0; i < PCI_BUS_NUM_RESOURCES; i++) {
  307. struct resource *r = bus->resource[i];
  308. if (!r)
  309. continue;
  310. if (res->start && !(res->start >= r->start && res->end <= r->end))
  311. continue; /* Not contained */
  312. if ((res->flags ^ r->flags) & (IORESOURCE_IO | IORESOURCE_MEM))
  313. continue; /* Wrong type */
  314. if (!((res->flags ^ r->flags) & IORESOURCE_PREFETCH))
  315. return r; /* Exact match */
  316. if ((res->flags & IORESOURCE_PREFETCH) && !(r->flags & IORESOURCE_PREFETCH))
  317. best = r; /* Approximating prefetchable by non-prefetchable */
  318. }
  319. return best;
  320. }
  321. /**
  322. * pci_restore_bars - restore a devices BAR values (e.g. after wake-up)
  323. * @dev: PCI device to have its BARs restored
  324. *
  325. * Restore the BAR values for a given device, so as to make it
  326. * accessible by its driver.
  327. */
  328. static void
  329. pci_restore_bars(struct pci_dev *dev)
  330. {
  331. int i;
  332. for (i = 0; i < PCI_BRIDGE_RESOURCES; i++)
  333. pci_update_resource(dev, i);
  334. }
  335. static struct pci_platform_pm_ops *pci_platform_pm;
  336. int pci_set_platform_pm(struct pci_platform_pm_ops *ops)
  337. {
  338. if (!ops->is_manageable || !ops->set_state || !ops->choose_state
  339. || !ops->sleep_wake || !ops->can_wakeup)
  340. return -EINVAL;
  341. pci_platform_pm = ops;
  342. return 0;
  343. }
  344. static inline bool platform_pci_power_manageable(struct pci_dev *dev)
  345. {
  346. return pci_platform_pm ? pci_platform_pm->is_manageable(dev) : false;
  347. }
  348. static inline int platform_pci_set_power_state(struct pci_dev *dev,
  349. pci_power_t t)
  350. {
  351. return pci_platform_pm ? pci_platform_pm->set_state(dev, t) : -ENOSYS;
  352. }
  353. static inline pci_power_t platform_pci_choose_state(struct pci_dev *dev)
  354. {
  355. return pci_platform_pm ?
  356. pci_platform_pm->choose_state(dev) : PCI_POWER_ERROR;
  357. }
  358. static inline bool platform_pci_can_wakeup(struct pci_dev *dev)
  359. {
  360. return pci_platform_pm ? pci_platform_pm->can_wakeup(dev) : false;
  361. }
  362. static inline int platform_pci_sleep_wake(struct pci_dev *dev, bool enable)
  363. {
  364. return pci_platform_pm ?
  365. pci_platform_pm->sleep_wake(dev, enable) : -ENODEV;
  366. }
  367. /**
  368. * pci_raw_set_power_state - Use PCI PM registers to set the power state of
  369. * given PCI device
  370. * @dev: PCI device to handle.
  371. * @state: PCI power state (D0, D1, D2, D3hot) to put the device into.
  372. * @wait: If 'true', wait for the device to change its power state
  373. *
  374. * RETURN VALUE:
  375. * -EINVAL if the requested state is invalid.
  376. * -EIO if device does not support PCI PM or its PM capabilities register has a
  377. * wrong version, or device doesn't support the requested state.
  378. * 0 if device already is in the requested state.
  379. * 0 if device's power state has been successfully changed.
  380. */
  381. static int
  382. pci_raw_set_power_state(struct pci_dev *dev, pci_power_t state, bool wait)
  383. {
  384. u16 pmcsr;
  385. bool need_restore = false;
  386. if (!dev->pm_cap)
  387. return -EIO;
  388. if (state < PCI_D0 || state > PCI_D3hot)
  389. return -EINVAL;
  390. /* Validate current state:
  391. * Can enter D0 from any state, but if we can only go deeper
  392. * to sleep if we're already in a low power state
  393. */
  394. if (dev->current_state == state) {
  395. /* we're already there */
  396. return 0;
  397. } else if (state != PCI_D0 && dev->current_state <= PCI_D3cold
  398. && dev->current_state > state) {
  399. dev_err(&dev->dev, "invalid power transition "
  400. "(from state %d to %d)\n", dev->current_state, state);
  401. return -EINVAL;
  402. }
  403. /* check if this device supports the desired state */
  404. if ((state == PCI_D1 && !dev->d1_support)
  405. || (state == PCI_D2 && !dev->d2_support))
  406. return -EIO;
  407. pci_read_config_word(dev, dev->pm_cap + PCI_PM_CTRL, &pmcsr);
  408. /* If we're (effectively) in D3, force entire word to 0.
  409. * This doesn't affect PME_Status, disables PME_En, and
  410. * sets PowerState to 0.
  411. */
  412. switch (dev->current_state) {
  413. case PCI_D0:
  414. case PCI_D1:
  415. case PCI_D2:
  416. pmcsr &= ~PCI_PM_CTRL_STATE_MASK;
  417. pmcsr |= state;
  418. break;
  419. case PCI_UNKNOWN: /* Boot-up */
  420. if ((pmcsr & PCI_PM_CTRL_STATE_MASK) == PCI_D3hot
  421. && !(pmcsr & PCI_PM_CTRL_NO_SOFT_RESET)) {
  422. need_restore = true;
  423. wait = true;
  424. }
  425. /* Fall-through: force to D0 */
  426. default:
  427. pmcsr = 0;
  428. break;
  429. }
  430. /* enter specified state */
  431. pci_write_config_word(dev, dev->pm_cap + PCI_PM_CTRL, pmcsr);
  432. if (!wait)
  433. return 0;
  434. /* Mandatory power management transition delays */
  435. /* see PCI PM 1.1 5.6.1 table 18 */
  436. if (state == PCI_D3hot || dev->current_state == PCI_D3hot)
  437. msleep(pci_pm_d3_delay);
  438. else if (state == PCI_D2 || dev->current_state == PCI_D2)
  439. udelay(PCI_PM_D2_DELAY);
  440. dev->current_state = state;
  441. /* According to section 5.4.1 of the "PCI BUS POWER MANAGEMENT
  442. * INTERFACE SPECIFICATION, REV. 1.2", a device transitioning
  443. * from D3hot to D0 _may_ perform an internal reset, thereby
  444. * going to "D0 Uninitialized" rather than "D0 Initialized".
  445. * For example, at least some versions of the 3c905B and the
  446. * 3c556B exhibit this behaviour.
  447. *
  448. * At least some laptop BIOSen (e.g. the Thinkpad T21) leave
  449. * devices in a D3hot state at boot. Consequently, we need to
  450. * restore at least the BARs so that the device will be
  451. * accessible to its driver.
  452. */
  453. if (need_restore)
  454. pci_restore_bars(dev);
  455. if (wait && dev->bus->self)
  456. pcie_aspm_pm_state_change(dev->bus->self);
  457. return 0;
  458. }
  459. /**
  460. * pci_update_current_state - Read PCI power state of given device from its
  461. * PCI PM registers and cache it
  462. * @dev: PCI device to handle.
  463. * @state: State to cache in case the device doesn't have the PM capability
  464. */
  465. void pci_update_current_state(struct pci_dev *dev, pci_power_t state)
  466. {
  467. if (dev->pm_cap) {
  468. u16 pmcsr;
  469. pci_read_config_word(dev, dev->pm_cap + PCI_PM_CTRL, &pmcsr);
  470. dev->current_state = (pmcsr & PCI_PM_CTRL_STATE_MASK);
  471. } else {
  472. dev->current_state = state;
  473. }
  474. }
  475. /**
  476. * pci_set_power_state - Set the power state of a PCI device
  477. * @dev: PCI device to handle.
  478. * @state: PCI power state (D0, D1, D2, D3hot) to put the device into.
  479. *
  480. * Transition a device to a new power state, using the platform formware and/or
  481. * the device's PCI PM registers.
  482. *
  483. * RETURN VALUE:
  484. * -EINVAL if the requested state is invalid.
  485. * -EIO if device does not support PCI PM or its PM capabilities register has a
  486. * wrong version, or device doesn't support the requested state.
  487. * 0 if device already is in the requested state.
  488. * 0 if device's power state has been successfully changed.
  489. */
  490. int pci_set_power_state(struct pci_dev *dev, pci_power_t state)
  491. {
  492. int error;
  493. /* bound the state we're entering */
  494. if (state > PCI_D3hot)
  495. state = PCI_D3hot;
  496. else if (state < PCI_D0)
  497. state = PCI_D0;
  498. else if ((state == PCI_D1 || state == PCI_D2) && pci_no_d1d2(dev))
  499. /*
  500. * If the device or the parent bridge do not support PCI PM,
  501. * ignore the request if we're doing anything other than putting
  502. * it into D0 (which would only happen on boot).
  503. */
  504. return 0;
  505. if (state == PCI_D0 && platform_pci_power_manageable(dev)) {
  506. /*
  507. * Allow the platform to change the state, for example via ACPI
  508. * _PR0, _PS0 and some such, but do not trust it.
  509. */
  510. int ret = platform_pci_set_power_state(dev, PCI_D0);
  511. if (!ret)
  512. pci_update_current_state(dev, PCI_D0);
  513. }
  514. /* This device is quirked not to be put into D3, so
  515. don't put it in D3 */
  516. if (state == PCI_D3hot && (dev->dev_flags & PCI_DEV_FLAGS_NO_D3))
  517. return 0;
  518. error = pci_raw_set_power_state(dev, state, true);
  519. if (state > PCI_D0 && platform_pci_power_manageable(dev)) {
  520. /* Allow the platform to finalize the transition */
  521. int ret = platform_pci_set_power_state(dev, state);
  522. if (!ret) {
  523. pci_update_current_state(dev, state);
  524. error = 0;
  525. }
  526. }
  527. return error;
  528. }
  529. /**
  530. * pci_choose_state - Choose the power state of a PCI device
  531. * @dev: PCI device to be suspended
  532. * @state: target sleep state for the whole system. This is the value
  533. * that is passed to suspend() function.
  534. *
  535. * Returns PCI power state suitable for given device and given system
  536. * message.
  537. */
  538. pci_power_t pci_choose_state(struct pci_dev *dev, pm_message_t state)
  539. {
  540. pci_power_t ret;
  541. if (!pci_find_capability(dev, PCI_CAP_ID_PM))
  542. return PCI_D0;
  543. ret = platform_pci_choose_state(dev);
  544. if (ret != PCI_POWER_ERROR)
  545. return ret;
  546. switch (state.event) {
  547. case PM_EVENT_ON:
  548. return PCI_D0;
  549. case PM_EVENT_FREEZE:
  550. case PM_EVENT_PRETHAW:
  551. /* REVISIT both freeze and pre-thaw "should" use D0 */
  552. case PM_EVENT_SUSPEND:
  553. case PM_EVENT_HIBERNATE:
  554. return PCI_D3hot;
  555. default:
  556. dev_info(&dev->dev, "unrecognized suspend event %d\n",
  557. state.event);
  558. BUG();
  559. }
  560. return PCI_D0;
  561. }
  562. EXPORT_SYMBOL(pci_choose_state);
  563. static int pci_save_pcie_state(struct pci_dev *dev)
  564. {
  565. int pos, i = 0;
  566. struct pci_cap_saved_state *save_state;
  567. u16 *cap;
  568. pos = pci_find_capability(dev, PCI_CAP_ID_EXP);
  569. if (pos <= 0)
  570. return 0;
  571. save_state = pci_find_saved_cap(dev, PCI_CAP_ID_EXP);
  572. if (!save_state) {
  573. dev_err(&dev->dev, "buffer not found in %s\n", __FUNCTION__);
  574. return -ENOMEM;
  575. }
  576. cap = (u16 *)&save_state->data[0];
  577. pci_read_config_word(dev, pos + PCI_EXP_DEVCTL, &cap[i++]);
  578. pci_read_config_word(dev, pos + PCI_EXP_LNKCTL, &cap[i++]);
  579. pci_read_config_word(dev, pos + PCI_EXP_SLTCTL, &cap[i++]);
  580. pci_read_config_word(dev, pos + PCI_EXP_RTCTL, &cap[i++]);
  581. return 0;
  582. }
  583. static void pci_restore_pcie_state(struct pci_dev *dev)
  584. {
  585. int i = 0, pos;
  586. struct pci_cap_saved_state *save_state;
  587. u16 *cap;
  588. save_state = pci_find_saved_cap(dev, PCI_CAP_ID_EXP);
  589. pos = pci_find_capability(dev, PCI_CAP_ID_EXP);
  590. if (!save_state || pos <= 0)
  591. return;
  592. cap = (u16 *)&save_state->data[0];
  593. pci_write_config_word(dev, pos + PCI_EXP_DEVCTL, cap[i++]);
  594. pci_write_config_word(dev, pos + PCI_EXP_LNKCTL, cap[i++]);
  595. pci_write_config_word(dev, pos + PCI_EXP_SLTCTL, cap[i++]);
  596. pci_write_config_word(dev, pos + PCI_EXP_RTCTL, cap[i++]);
  597. }
  598. static int pci_save_pcix_state(struct pci_dev *dev)
  599. {
  600. int pos;
  601. struct pci_cap_saved_state *save_state;
  602. pos = pci_find_capability(dev, PCI_CAP_ID_PCIX);
  603. if (pos <= 0)
  604. return 0;
  605. save_state = pci_find_saved_cap(dev, PCI_CAP_ID_PCIX);
  606. if (!save_state) {
  607. dev_err(&dev->dev, "buffer not found in %s\n", __FUNCTION__);
  608. return -ENOMEM;
  609. }
  610. pci_read_config_word(dev, pos + PCI_X_CMD, (u16 *)save_state->data);
  611. return 0;
  612. }
  613. static void pci_restore_pcix_state(struct pci_dev *dev)
  614. {
  615. int i = 0, pos;
  616. struct pci_cap_saved_state *save_state;
  617. u16 *cap;
  618. save_state = pci_find_saved_cap(dev, PCI_CAP_ID_PCIX);
  619. pos = pci_find_capability(dev, PCI_CAP_ID_PCIX);
  620. if (!save_state || pos <= 0)
  621. return;
  622. cap = (u16 *)&save_state->data[0];
  623. pci_write_config_word(dev, pos + PCI_X_CMD, cap[i++]);
  624. }
  625. /**
  626. * pci_save_state - save the PCI configuration space of a device before suspending
  627. * @dev: - PCI device that we're dealing with
  628. */
  629. int
  630. pci_save_state(struct pci_dev *dev)
  631. {
  632. int i;
  633. /* XXX: 100% dword access ok here? */
  634. for (i = 0; i < 16; i++)
  635. pci_read_config_dword(dev, i * 4,&dev->saved_config_space[i]);
  636. dev->state_saved = true;
  637. if ((i = pci_save_pcie_state(dev)) != 0)
  638. return i;
  639. if ((i = pci_save_pcix_state(dev)) != 0)
  640. return i;
  641. return 0;
  642. }
  643. /**
  644. * pci_restore_state - Restore the saved state of a PCI device
  645. * @dev: - PCI device that we're dealing with
  646. */
  647. int
  648. pci_restore_state(struct pci_dev *dev)
  649. {
  650. int i;
  651. u32 val;
  652. /* PCI Express register must be restored first */
  653. pci_restore_pcie_state(dev);
  654. /*
  655. * The Base Address register should be programmed before the command
  656. * register(s)
  657. */
  658. for (i = 15; i >= 0; i--) {
  659. pci_read_config_dword(dev, i * 4, &val);
  660. if (val != dev->saved_config_space[i]) {
  661. dev_printk(KERN_DEBUG, &dev->dev, "restoring config "
  662. "space at offset %#x (was %#x, writing %#x)\n",
  663. i, val, (int)dev->saved_config_space[i]);
  664. pci_write_config_dword(dev,i * 4,
  665. dev->saved_config_space[i]);
  666. }
  667. }
  668. pci_restore_pcix_state(dev);
  669. pci_restore_msi_state(dev);
  670. return 0;
  671. }
  672. static int do_pci_enable_device(struct pci_dev *dev, int bars)
  673. {
  674. int err;
  675. err = pci_set_power_state(dev, PCI_D0);
  676. if (err < 0 && err != -EIO)
  677. return err;
  678. err = pcibios_enable_device(dev, bars);
  679. if (err < 0)
  680. return err;
  681. pci_fixup_device(pci_fixup_enable, dev);
  682. return 0;
  683. }
  684. /**
  685. * pci_reenable_device - Resume abandoned device
  686. * @dev: PCI device to be resumed
  687. *
  688. * Note this function is a backend of pci_default_resume and is not supposed
  689. * to be called by normal code, write proper resume handler and use it instead.
  690. */
  691. int pci_reenable_device(struct pci_dev *dev)
  692. {
  693. if (atomic_read(&dev->enable_cnt))
  694. return do_pci_enable_device(dev, (1 << PCI_NUM_RESOURCES) - 1);
  695. return 0;
  696. }
  697. static int __pci_enable_device_flags(struct pci_dev *dev,
  698. resource_size_t flags)
  699. {
  700. int err;
  701. int i, bars = 0;
  702. if (atomic_add_return(1, &dev->enable_cnt) > 1)
  703. return 0; /* already enabled */
  704. for (i = 0; i < DEVICE_COUNT_RESOURCE; i++)
  705. if (dev->resource[i].flags & flags)
  706. bars |= (1 << i);
  707. err = do_pci_enable_device(dev, bars);
  708. if (err < 0)
  709. atomic_dec(&dev->enable_cnt);
  710. return err;
  711. }
  712. /**
  713. * pci_enable_device_io - Initialize a device for use with IO space
  714. * @dev: PCI device to be initialized
  715. *
  716. * Initialize device before it's used by a driver. Ask low-level code
  717. * to enable I/O resources. Wake up the device if it was suspended.
  718. * Beware, this function can fail.
  719. */
  720. int pci_enable_device_io(struct pci_dev *dev)
  721. {
  722. return __pci_enable_device_flags(dev, IORESOURCE_IO);
  723. }
  724. /**
  725. * pci_enable_device_mem - Initialize a device for use with Memory space
  726. * @dev: PCI device to be initialized
  727. *
  728. * Initialize device before it's used by a driver. Ask low-level code
  729. * to enable Memory resources. Wake up the device if it was suspended.
  730. * Beware, this function can fail.
  731. */
  732. int pci_enable_device_mem(struct pci_dev *dev)
  733. {
  734. return __pci_enable_device_flags(dev, IORESOURCE_MEM);
  735. }
  736. /**
  737. * pci_enable_device - Initialize device before it's used by a driver.
  738. * @dev: PCI device to be initialized
  739. *
  740. * Initialize device before it's used by a driver. Ask low-level code
  741. * to enable I/O and memory. Wake up the device if it was suspended.
  742. * Beware, this function can fail.
  743. *
  744. * Note we don't actually enable the device many times if we call
  745. * this function repeatedly (we just increment the count).
  746. */
  747. int pci_enable_device(struct pci_dev *dev)
  748. {
  749. return __pci_enable_device_flags(dev, IORESOURCE_MEM | IORESOURCE_IO);
  750. }
  751. /*
  752. * Managed PCI resources. This manages device on/off, intx/msi/msix
  753. * on/off and BAR regions. pci_dev itself records msi/msix status, so
  754. * there's no need to track it separately. pci_devres is initialized
  755. * when a device is enabled using managed PCI device enable interface.
  756. */
  757. struct pci_devres {
  758. unsigned int enabled:1;
  759. unsigned int pinned:1;
  760. unsigned int orig_intx:1;
  761. unsigned int restore_intx:1;
  762. u32 region_mask;
  763. };
  764. static void pcim_release(struct device *gendev, void *res)
  765. {
  766. struct pci_dev *dev = container_of(gendev, struct pci_dev, dev);
  767. struct pci_devres *this = res;
  768. int i;
  769. if (dev->msi_enabled)
  770. pci_disable_msi(dev);
  771. if (dev->msix_enabled)
  772. pci_disable_msix(dev);
  773. for (i = 0; i < DEVICE_COUNT_RESOURCE; i++)
  774. if (this->region_mask & (1 << i))
  775. pci_release_region(dev, i);
  776. if (this->restore_intx)
  777. pci_intx(dev, this->orig_intx);
  778. if (this->enabled && !this->pinned)
  779. pci_disable_device(dev);
  780. }
  781. static struct pci_devres * get_pci_dr(struct pci_dev *pdev)
  782. {
  783. struct pci_devres *dr, *new_dr;
  784. dr = devres_find(&pdev->dev, pcim_release, NULL, NULL);
  785. if (dr)
  786. return dr;
  787. new_dr = devres_alloc(pcim_release, sizeof(*new_dr), GFP_KERNEL);
  788. if (!new_dr)
  789. return NULL;
  790. return devres_get(&pdev->dev, new_dr, NULL, NULL);
  791. }
  792. static struct pci_devres * find_pci_dr(struct pci_dev *pdev)
  793. {
  794. if (pci_is_managed(pdev))
  795. return devres_find(&pdev->dev, pcim_release, NULL, NULL);
  796. return NULL;
  797. }
  798. /**
  799. * pcim_enable_device - Managed pci_enable_device()
  800. * @pdev: PCI device to be initialized
  801. *
  802. * Managed pci_enable_device().
  803. */
  804. int pcim_enable_device(struct pci_dev *pdev)
  805. {
  806. struct pci_devres *dr;
  807. int rc;
  808. dr = get_pci_dr(pdev);
  809. if (unlikely(!dr))
  810. return -ENOMEM;
  811. if (dr->enabled)
  812. return 0;
  813. rc = pci_enable_device(pdev);
  814. if (!rc) {
  815. pdev->is_managed = 1;
  816. dr->enabled = 1;
  817. }
  818. return rc;
  819. }
  820. /**
  821. * pcim_pin_device - Pin managed PCI device
  822. * @pdev: PCI device to pin
  823. *
  824. * Pin managed PCI device @pdev. Pinned device won't be disabled on
  825. * driver detach. @pdev must have been enabled with
  826. * pcim_enable_device().
  827. */
  828. void pcim_pin_device(struct pci_dev *pdev)
  829. {
  830. struct pci_devres *dr;
  831. dr = find_pci_dr(pdev);
  832. WARN_ON(!dr || !dr->enabled);
  833. if (dr)
  834. dr->pinned = 1;
  835. }
  836. /**
  837. * pcibios_disable_device - disable arch specific PCI resources for device dev
  838. * @dev: the PCI device to disable
  839. *
  840. * Disables architecture specific PCI resources for the device. This
  841. * is the default implementation. Architecture implementations can
  842. * override this.
  843. */
  844. void __attribute__ ((weak)) pcibios_disable_device (struct pci_dev *dev) {}
  845. static void do_pci_disable_device(struct pci_dev *dev)
  846. {
  847. u16 pci_command;
  848. pci_read_config_word(dev, PCI_COMMAND, &pci_command);
  849. if (pci_command & PCI_COMMAND_MASTER) {
  850. pci_command &= ~PCI_COMMAND_MASTER;
  851. pci_write_config_word(dev, PCI_COMMAND, pci_command);
  852. }
  853. pcibios_disable_device(dev);
  854. }
  855. /**
  856. * pci_disable_enabled_device - Disable device without updating enable_cnt
  857. * @dev: PCI device to disable
  858. *
  859. * NOTE: This function is a backend of PCI power management routines and is
  860. * not supposed to be called drivers.
  861. */
  862. void pci_disable_enabled_device(struct pci_dev *dev)
  863. {
  864. if (atomic_read(&dev->enable_cnt))
  865. do_pci_disable_device(dev);
  866. }
  867. /**
  868. * pci_disable_device - Disable PCI device after use
  869. * @dev: PCI device to be disabled
  870. *
  871. * Signal to the system that the PCI device is not in use by the system
  872. * anymore. This only involves disabling PCI bus-mastering, if active.
  873. *
  874. * Note we don't actually disable the device until all callers of
  875. * pci_device_enable() have called pci_device_disable().
  876. */
  877. void
  878. pci_disable_device(struct pci_dev *dev)
  879. {
  880. struct pci_devres *dr;
  881. dr = find_pci_dr(dev);
  882. if (dr)
  883. dr->enabled = 0;
  884. if (atomic_sub_return(1, &dev->enable_cnt) != 0)
  885. return;
  886. do_pci_disable_device(dev);
  887. dev->is_busmaster = 0;
  888. }
  889. /**
  890. * pcibios_set_pcie_reset_state - set reset state for device dev
  891. * @dev: the PCI-E device reset
  892. * @state: Reset state to enter into
  893. *
  894. *
  895. * Sets the PCI-E reset state for the device. This is the default
  896. * implementation. Architecture implementations can override this.
  897. */
  898. int __attribute__ ((weak)) pcibios_set_pcie_reset_state(struct pci_dev *dev,
  899. enum pcie_reset_state state)
  900. {
  901. return -EINVAL;
  902. }
  903. /**
  904. * pci_set_pcie_reset_state - set reset state for device dev
  905. * @dev: the PCI-E device reset
  906. * @state: Reset state to enter into
  907. *
  908. *
  909. * Sets the PCI reset state for the device.
  910. */
  911. int pci_set_pcie_reset_state(struct pci_dev *dev, enum pcie_reset_state state)
  912. {
  913. return pcibios_set_pcie_reset_state(dev, state);
  914. }
  915. /**
  916. * pci_pme_capable - check the capability of PCI device to generate PME#
  917. * @dev: PCI device to handle.
  918. * @state: PCI state from which device will issue PME#.
  919. */
  920. bool pci_pme_capable(struct pci_dev *dev, pci_power_t state)
  921. {
  922. if (!dev->pm_cap)
  923. return false;
  924. return !!(dev->pme_support & (1 << state));
  925. }
  926. /**
  927. * pci_pme_active - enable or disable PCI device's PME# function
  928. * @dev: PCI device to handle.
  929. * @enable: 'true' to enable PME# generation; 'false' to disable it.
  930. *
  931. * The caller must verify that the device is capable of generating PME# before
  932. * calling this function with @enable equal to 'true'.
  933. */
  934. void pci_pme_active(struct pci_dev *dev, bool enable)
  935. {
  936. u16 pmcsr;
  937. if (!dev->pm_cap)
  938. return;
  939. pci_read_config_word(dev, dev->pm_cap + PCI_PM_CTRL, &pmcsr);
  940. /* Clear PME_Status by writing 1 to it and enable PME# */
  941. pmcsr |= PCI_PM_CTRL_PME_STATUS | PCI_PM_CTRL_PME_ENABLE;
  942. if (!enable)
  943. pmcsr &= ~PCI_PM_CTRL_PME_ENABLE;
  944. pci_write_config_word(dev, dev->pm_cap + PCI_PM_CTRL, pmcsr);
  945. dev_printk(KERN_INFO, &dev->dev, "PME# %s\n",
  946. enable ? "enabled" : "disabled");
  947. }
  948. /**
  949. * pci_enable_wake - enable PCI device as wakeup event source
  950. * @dev: PCI device affected
  951. * @state: PCI state from which device will issue wakeup events
  952. * @enable: True to enable event generation; false to disable
  953. *
  954. * This enables the device as a wakeup event source, or disables it.
  955. * When such events involves platform-specific hooks, those hooks are
  956. * called automatically by this routine.
  957. *
  958. * Devices with legacy power management (no standard PCI PM capabilities)
  959. * always require such platform hooks.
  960. *
  961. * RETURN VALUE:
  962. * 0 is returned on success
  963. * -EINVAL is returned if device is not supposed to wake up the system
  964. * Error code depending on the platform is returned if both the platform and
  965. * the native mechanism fail to enable the generation of wake-up events
  966. */
  967. int pci_enable_wake(struct pci_dev *dev, pci_power_t state, int enable)
  968. {
  969. int error = 0;
  970. bool pme_done = false;
  971. if (enable && !device_may_wakeup(&dev->dev))
  972. return -EINVAL;
  973. /*
  974. * According to "PCI System Architecture" 4th ed. by Tom Shanley & Don
  975. * Anderson we should be doing PME# wake enable followed by ACPI wake
  976. * enable. To disable wake-up we call the platform first, for symmetry.
  977. */
  978. if (!enable && platform_pci_can_wakeup(dev))
  979. error = platform_pci_sleep_wake(dev, false);
  980. if (!enable || pci_pme_capable(dev, state)) {
  981. pci_pme_active(dev, enable);
  982. pme_done = true;
  983. }
  984. if (enable && platform_pci_can_wakeup(dev))
  985. error = platform_pci_sleep_wake(dev, true);
  986. return pme_done ? 0 : error;
  987. }
  988. /**
  989. * pci_wake_from_d3 - enable/disable device to wake up from D3_hot or D3_cold
  990. * @dev: PCI device to prepare
  991. * @enable: True to enable wake-up event generation; false to disable
  992. *
  993. * Many drivers want the device to wake up the system from D3_hot or D3_cold
  994. * and this function allows them to set that up cleanly - pci_enable_wake()
  995. * should not be called twice in a row to enable wake-up due to PCI PM vs ACPI
  996. * ordering constraints.
  997. *
  998. * This function only returns error code if the device is not capable of
  999. * generating PME# from both D3_hot and D3_cold, and the platform is unable to
  1000. * enable wake-up power for it.
  1001. */
  1002. int pci_wake_from_d3(struct pci_dev *dev, bool enable)
  1003. {
  1004. return pci_pme_capable(dev, PCI_D3cold) ?
  1005. pci_enable_wake(dev, PCI_D3cold, enable) :
  1006. pci_enable_wake(dev, PCI_D3hot, enable);
  1007. }
  1008. /**
  1009. * pci_target_state - find an appropriate low power state for a given PCI dev
  1010. * @dev: PCI device
  1011. *
  1012. * Use underlying platform code to find a supported low power state for @dev.
  1013. * If the platform can't manage @dev, return the deepest state from which it
  1014. * can generate wake events, based on any available PME info.
  1015. */
  1016. pci_power_t pci_target_state(struct pci_dev *dev)
  1017. {
  1018. pci_power_t target_state = PCI_D3hot;
  1019. if (platform_pci_power_manageable(dev)) {
  1020. /*
  1021. * Call the platform to choose the target state of the device
  1022. * and enable wake-up from this state if supported.
  1023. */
  1024. pci_power_t state = platform_pci_choose_state(dev);
  1025. switch (state) {
  1026. case PCI_POWER_ERROR:
  1027. case PCI_UNKNOWN:
  1028. break;
  1029. case PCI_D1:
  1030. case PCI_D2:
  1031. if (pci_no_d1d2(dev))
  1032. break;
  1033. default:
  1034. target_state = state;
  1035. }
  1036. } else if (device_may_wakeup(&dev->dev)) {
  1037. /*
  1038. * Find the deepest state from which the device can generate
  1039. * wake-up events, make it the target state and enable device
  1040. * to generate PME#.
  1041. */
  1042. if (!dev->pm_cap)
  1043. return PCI_POWER_ERROR;
  1044. if (dev->pme_support) {
  1045. while (target_state
  1046. && !(dev->pme_support & (1 << target_state)))
  1047. target_state--;
  1048. }
  1049. }
  1050. return target_state;
  1051. }
  1052. /**
  1053. * pci_prepare_to_sleep - prepare PCI device for system-wide transition into a sleep state
  1054. * @dev: Device to handle.
  1055. *
  1056. * Choose the power state appropriate for the device depending on whether
  1057. * it can wake up the system and/or is power manageable by the platform
  1058. * (PCI_D3hot is the default) and put the device into that state.
  1059. */
  1060. int pci_prepare_to_sleep(struct pci_dev *dev)
  1061. {
  1062. pci_power_t target_state = pci_target_state(dev);
  1063. int error;
  1064. if (target_state == PCI_POWER_ERROR)
  1065. return -EIO;
  1066. pci_enable_wake(dev, target_state, true);
  1067. error = pci_set_power_state(dev, target_state);
  1068. if (error)
  1069. pci_enable_wake(dev, target_state, false);
  1070. return error;
  1071. }
  1072. /**
  1073. * pci_back_from_sleep - turn PCI device on during system-wide transition into working state
  1074. * @dev: Device to handle.
  1075. *
  1076. * Disable device's sytem wake-up capability and put it into D0.
  1077. */
  1078. int pci_back_from_sleep(struct pci_dev *dev)
  1079. {
  1080. pci_enable_wake(dev, PCI_D0, false);
  1081. return pci_set_power_state(dev, PCI_D0);
  1082. }
  1083. /**
  1084. * pci_pm_init - Initialize PM functions of given PCI device
  1085. * @dev: PCI device to handle.
  1086. */
  1087. void pci_pm_init(struct pci_dev *dev)
  1088. {
  1089. int pm;
  1090. u16 pmc;
  1091. dev->pm_cap = 0;
  1092. /* find PCI PM capability in list */
  1093. pm = pci_find_capability(dev, PCI_CAP_ID_PM);
  1094. if (!pm)
  1095. return;
  1096. /* Check device's ability to generate PME# */
  1097. pci_read_config_word(dev, pm + PCI_PM_PMC, &pmc);
  1098. if ((pmc & PCI_PM_CAP_VER_MASK) > 3) {
  1099. dev_err(&dev->dev, "unsupported PM cap regs version (%u)\n",
  1100. pmc & PCI_PM_CAP_VER_MASK);
  1101. return;
  1102. }
  1103. dev->pm_cap = pm;
  1104. dev->d1_support = false;
  1105. dev->d2_support = false;
  1106. if (!pci_no_d1d2(dev)) {
  1107. if (pmc & PCI_PM_CAP_D1)
  1108. dev->d1_support = true;
  1109. if (pmc & PCI_PM_CAP_D2)
  1110. dev->d2_support = true;
  1111. if (dev->d1_support || dev->d2_support)
  1112. dev_printk(KERN_DEBUG, &dev->dev, "supports%s%s\n",
  1113. dev->d1_support ? " D1" : "",
  1114. dev->d2_support ? " D2" : "");
  1115. }
  1116. pmc &= PCI_PM_CAP_PME_MASK;
  1117. if (pmc) {
  1118. dev_info(&dev->dev, "PME# supported from%s%s%s%s%s\n",
  1119. (pmc & PCI_PM_CAP_PME_D0) ? " D0" : "",
  1120. (pmc & PCI_PM_CAP_PME_D1) ? " D1" : "",
  1121. (pmc & PCI_PM_CAP_PME_D2) ? " D2" : "",
  1122. (pmc & PCI_PM_CAP_PME_D3) ? " D3hot" : "",
  1123. (pmc & PCI_PM_CAP_PME_D3cold) ? " D3cold" : "");
  1124. dev->pme_support = pmc >> PCI_PM_CAP_PME_SHIFT;
  1125. /*
  1126. * Make device's PM flags reflect the wake-up capability, but
  1127. * let the user space enable it to wake up the system as needed.
  1128. */
  1129. device_set_wakeup_capable(&dev->dev, true);
  1130. device_set_wakeup_enable(&dev->dev, false);
  1131. /* Disable the PME# generation functionality */
  1132. pci_pme_active(dev, false);
  1133. } else {
  1134. dev->pme_support = 0;
  1135. }
  1136. }
  1137. /**
  1138. * platform_pci_wakeup_init - init platform wakeup if present
  1139. * @dev: PCI device
  1140. *
  1141. * Some devices don't have PCI PM caps but can still generate wakeup
  1142. * events through platform methods (like ACPI events). If @dev supports
  1143. * platform wakeup events, set the device flag to indicate as much. This
  1144. * may be redundant if the device also supports PCI PM caps, but double
  1145. * initialization should be safe in that case.
  1146. */
  1147. void platform_pci_wakeup_init(struct pci_dev *dev)
  1148. {
  1149. if (!platform_pci_can_wakeup(dev))
  1150. return;
  1151. device_set_wakeup_capable(&dev->dev, true);
  1152. device_set_wakeup_enable(&dev->dev, false);
  1153. platform_pci_sleep_wake(dev, false);
  1154. }
  1155. /**
  1156. * pci_add_save_buffer - allocate buffer for saving given capability registers
  1157. * @dev: the PCI device
  1158. * @cap: the capability to allocate the buffer for
  1159. * @size: requested size of the buffer
  1160. */
  1161. static int pci_add_cap_save_buffer(
  1162. struct pci_dev *dev, char cap, unsigned int size)
  1163. {
  1164. int pos;
  1165. struct pci_cap_saved_state *save_state;
  1166. pos = pci_find_capability(dev, cap);
  1167. if (pos <= 0)
  1168. return 0;
  1169. save_state = kzalloc(sizeof(*save_state) + size, GFP_KERNEL);
  1170. if (!save_state)
  1171. return -ENOMEM;
  1172. save_state->cap_nr = cap;
  1173. pci_add_saved_cap(dev, save_state);
  1174. return 0;
  1175. }
  1176. /**
  1177. * pci_allocate_cap_save_buffers - allocate buffers for saving capabilities
  1178. * @dev: the PCI device
  1179. */
  1180. void pci_allocate_cap_save_buffers(struct pci_dev *dev)
  1181. {
  1182. int error;
  1183. error = pci_add_cap_save_buffer(dev, PCI_CAP_ID_EXP, 4 * sizeof(u16));
  1184. if (error)
  1185. dev_err(&dev->dev,
  1186. "unable to preallocate PCI Express save buffer\n");
  1187. error = pci_add_cap_save_buffer(dev, PCI_CAP_ID_PCIX, sizeof(u16));
  1188. if (error)
  1189. dev_err(&dev->dev,
  1190. "unable to preallocate PCI-X save buffer\n");
  1191. }
  1192. /**
  1193. * pci_restore_standard_config - restore standard config registers of PCI device
  1194. * @dev: PCI device to handle
  1195. *
  1196. * This function assumes that the device's configuration space is accessible.
  1197. * If the device needs to be powered up, the function will wait for it to
  1198. * change the state.
  1199. */
  1200. int pci_restore_standard_config(struct pci_dev *dev)
  1201. {
  1202. pci_power_t prev_state;
  1203. int error;
  1204. pci_restore_state(dev);
  1205. pci_update_current_state(dev, PCI_D0);
  1206. prev_state = dev->current_state;
  1207. if (prev_state == PCI_D0)
  1208. return 0;
  1209. error = pci_raw_set_power_state(dev, PCI_D0, false);
  1210. if (error)
  1211. return error;
  1212. if (pci_is_bridge(dev)) {
  1213. if (prev_state > PCI_D1)
  1214. mdelay(PCI_PM_BUS_WAIT);
  1215. } else {
  1216. switch(prev_state) {
  1217. case PCI_D3cold:
  1218. case PCI_D3hot:
  1219. mdelay(pci_pm_d3_delay);
  1220. break;
  1221. case PCI_D2:
  1222. udelay(PCI_PM_D2_DELAY);
  1223. break;
  1224. }
  1225. }
  1226. dev->current_state = PCI_D0;
  1227. return 0;
  1228. }
  1229. /**
  1230. * pci_enable_ari - enable ARI forwarding if hardware support it
  1231. * @dev: the PCI device
  1232. */
  1233. void pci_enable_ari(struct pci_dev *dev)
  1234. {
  1235. int pos;
  1236. u32 cap;
  1237. u16 ctrl;
  1238. struct pci_dev *bridge;
  1239. if (!dev->is_pcie || dev->devfn)
  1240. return;
  1241. pos = pci_find_ext_capability(dev, PCI_EXT_CAP_ID_ARI);
  1242. if (!pos)
  1243. return;
  1244. bridge = dev->bus->self;
  1245. if (!bridge || !bridge->is_pcie)
  1246. return;
  1247. pos = pci_find_capability(bridge, PCI_CAP_ID_EXP);
  1248. if (!pos)
  1249. return;
  1250. pci_read_config_dword(bridge, pos + PCI_EXP_DEVCAP2, &cap);
  1251. if (!(cap & PCI_EXP_DEVCAP2_ARI))
  1252. return;
  1253. pci_read_config_word(bridge, pos + PCI_EXP_DEVCTL2, &ctrl);
  1254. ctrl |= PCI_EXP_DEVCTL2_ARI;
  1255. pci_write_config_word(bridge, pos + PCI_EXP_DEVCTL2, ctrl);
  1256. bridge->ari_enabled = 1;
  1257. }
  1258. /**
  1259. * pci_swizzle_interrupt_pin - swizzle INTx for device behind bridge
  1260. * @dev: the PCI device
  1261. * @pin: the INTx pin (1=INTA, 2=INTB, 3=INTD, 4=INTD)
  1262. *
  1263. * Perform INTx swizzling for a device behind one level of bridge. This is
  1264. * required by section 9.1 of the PCI-to-PCI bridge specification for devices
  1265. * behind bridges on add-in cards.
  1266. */
  1267. u8 pci_swizzle_interrupt_pin(struct pci_dev *dev, u8 pin)
  1268. {
  1269. return (((pin - 1) + PCI_SLOT(dev->devfn)) % 4) + 1;
  1270. }
  1271. int
  1272. pci_get_interrupt_pin(struct pci_dev *dev, struct pci_dev **bridge)
  1273. {
  1274. u8 pin;
  1275. pin = dev->pin;
  1276. if (!pin)
  1277. return -1;
  1278. while (dev->bus->self) {
  1279. pin = pci_swizzle_interrupt_pin(dev, pin);
  1280. dev = dev->bus->self;
  1281. }
  1282. *bridge = dev;
  1283. return pin;
  1284. }
  1285. /**
  1286. * pci_common_swizzle - swizzle INTx all the way to root bridge
  1287. * @dev: the PCI device
  1288. * @pinp: pointer to the INTx pin value (1=INTA, 2=INTB, 3=INTD, 4=INTD)
  1289. *
  1290. * Perform INTx swizzling for a device. This traverses through all PCI-to-PCI
  1291. * bridges all the way up to a PCI root bus.
  1292. */
  1293. u8 pci_common_swizzle(struct pci_dev *dev, u8 *pinp)
  1294. {
  1295. u8 pin = *pinp;
  1296. while (dev->bus->self) {
  1297. pin = pci_swizzle_interrupt_pin(dev, pin);
  1298. dev = dev->bus->self;
  1299. }
  1300. *pinp = pin;
  1301. return PCI_SLOT(dev->devfn);
  1302. }
  1303. /**
  1304. * pci_release_region - Release a PCI bar
  1305. * @pdev: PCI device whose resources were previously reserved by pci_request_region
  1306. * @bar: BAR to release
  1307. *
  1308. * Releases the PCI I/O and memory resources previously reserved by a
  1309. * successful call to pci_request_region. Call this function only
  1310. * after all use of the PCI regions has ceased.
  1311. */
  1312. void pci_release_region(struct pci_dev *pdev, int bar)
  1313. {
  1314. struct pci_devres *dr;
  1315. if (pci_resource_len(pdev, bar) == 0)
  1316. return;
  1317. if (pci_resource_flags(pdev, bar) & IORESOURCE_IO)
  1318. release_region(pci_resource_start(pdev, bar),
  1319. pci_resource_len(pdev, bar));
  1320. else if (pci_resource_flags(pdev, bar) & IORESOURCE_MEM)
  1321. release_mem_region(pci_resource_start(pdev, bar),
  1322. pci_resource_len(pdev, bar));
  1323. dr = find_pci_dr(pdev);
  1324. if (dr)
  1325. dr->region_mask &= ~(1 << bar);
  1326. }
  1327. /**
  1328. * pci_request_region - Reserved PCI I/O and memory resource
  1329. * @pdev: PCI device whose resources are to be reserved
  1330. * @bar: BAR to be reserved
  1331. * @res_name: Name to be associated with resource.
  1332. *
  1333. * Mark the PCI region associated with PCI device @pdev BR @bar as
  1334. * being reserved by owner @res_name. Do not access any
  1335. * address inside the PCI regions unless this call returns
  1336. * successfully.
  1337. *
  1338. * Returns 0 on success, or %EBUSY on error. A warning
  1339. * message is also printed on failure.
  1340. */
  1341. static int __pci_request_region(struct pci_dev *pdev, int bar, const char *res_name,
  1342. int exclusive)
  1343. {
  1344. struct pci_devres *dr;
  1345. if (pci_resource_len(pdev, bar) == 0)
  1346. return 0;
  1347. if (pci_resource_flags(pdev, bar) & IORESOURCE_IO) {
  1348. if (!request_region(pci_resource_start(pdev, bar),
  1349. pci_resource_len(pdev, bar), res_name))
  1350. goto err_out;
  1351. }
  1352. else if (pci_resource_flags(pdev, bar) & IORESOURCE_MEM) {
  1353. if (!__request_mem_region(pci_resource_start(pdev, bar),
  1354. pci_resource_len(pdev, bar), res_name,
  1355. exclusive))
  1356. goto err_out;
  1357. }
  1358. dr = find_pci_dr(pdev);
  1359. if (dr)
  1360. dr->region_mask |= 1 << bar;
  1361. return 0;
  1362. err_out:
  1363. dev_warn(&pdev->dev, "BAR %d: can't reserve %s region %pR\n",
  1364. bar,
  1365. pci_resource_flags(pdev, bar) & IORESOURCE_IO ? "I/O" : "mem",
  1366. &pdev->resource[bar]);
  1367. return -EBUSY;
  1368. }
  1369. /**
  1370. * pci_request_region - Reserved PCI I/O and memory resource
  1371. * @pdev: PCI device whose resources are to be reserved
  1372. * @bar: BAR to be reserved
  1373. * @res_name: Name to be associated with resource.
  1374. *
  1375. * Mark the PCI region associated with PCI device @pdev BR @bar as
  1376. * being reserved by owner @res_name. Do not access any
  1377. * address inside the PCI regions unless this call returns
  1378. * successfully.
  1379. *
  1380. * Returns 0 on success, or %EBUSY on error. A warning
  1381. * message is also printed on failure.
  1382. */
  1383. int pci_request_region(struct pci_dev *pdev, int bar, const char *res_name)
  1384. {
  1385. return __pci_request_region(pdev, bar, res_name, 0);
  1386. }
  1387. /**
  1388. * pci_request_region_exclusive - Reserved PCI I/O and memory resource
  1389. * @pdev: PCI device whose resources are to be reserved
  1390. * @bar: BAR to be reserved
  1391. * @res_name: Name to be associated with resource.
  1392. *
  1393. * Mark the PCI region associated with PCI device @pdev BR @bar as
  1394. * being reserved by owner @res_name. Do not access any
  1395. * address inside the PCI regions unless this call returns
  1396. * successfully.
  1397. *
  1398. * Returns 0 on success, or %EBUSY on error. A warning
  1399. * message is also printed on failure.
  1400. *
  1401. * The key difference that _exclusive makes it that userspace is
  1402. * explicitly not allowed to map the resource via /dev/mem or
  1403. * sysfs.
  1404. */
  1405. int pci_request_region_exclusive(struct pci_dev *pdev, int bar, const char *res_name)
  1406. {
  1407. return __pci_request_region(pdev, bar, res_name, IORESOURCE_EXCLUSIVE);
  1408. }
  1409. /**
  1410. * pci_release_selected_regions - Release selected PCI I/O and memory resources
  1411. * @pdev: PCI device whose resources were previously reserved
  1412. * @bars: Bitmask of BARs to be released
  1413. *
  1414. * Release selected PCI I/O and memory resources previously reserved.
  1415. * Call this function only after all use of the PCI regions has ceased.
  1416. */
  1417. void pci_release_selected_regions(struct pci_dev *pdev, int bars)
  1418. {
  1419. int i;
  1420. for (i = 0; i < 6; i++)
  1421. if (bars & (1 << i))
  1422. pci_release_region(pdev, i);
  1423. }
  1424. int __pci_request_selected_regions(struct pci_dev *pdev, int bars,
  1425. const char *res_name, int excl)
  1426. {
  1427. int i;
  1428. for (i = 0; i < 6; i++)
  1429. if (bars & (1 << i))
  1430. if (__pci_request_region(pdev, i, res_name, excl))
  1431. goto err_out;
  1432. return 0;
  1433. err_out:
  1434. while(--i >= 0)
  1435. if (bars & (1 << i))
  1436. pci_release_region(pdev, i);
  1437. return -EBUSY;
  1438. }
  1439. /**
  1440. * pci_request_selected_regions - Reserve selected PCI I/O and memory resources
  1441. * @pdev: PCI device whose resources are to be reserved
  1442. * @bars: Bitmask of BARs to be requested
  1443. * @res_name: Name to be associated with resource
  1444. */
  1445. int pci_request_selected_regions(struct pci_dev *pdev, int bars,
  1446. const char *res_name)
  1447. {
  1448. return __pci_request_selected_regions(pdev, bars, res_name, 0);
  1449. }
  1450. int pci_request_selected_regions_exclusive(struct pci_dev *pdev,
  1451. int bars, const char *res_name)
  1452. {
  1453. return __pci_request_selected_regions(pdev, bars, res_name,
  1454. IORESOURCE_EXCLUSIVE);
  1455. }
  1456. /**
  1457. * pci_release_regions - Release reserved PCI I/O and memory resources
  1458. * @pdev: PCI device whose resources were previously reserved by pci_request_regions
  1459. *
  1460. * Releases all PCI I/O and memory resources previously reserved by a
  1461. * successful call to pci_request_regions. Call this function only
  1462. * after all use of the PCI regions has ceased.
  1463. */
  1464. void pci_release_regions(struct pci_dev *pdev)
  1465. {
  1466. pci_release_selected_regions(pdev, (1 << 6) - 1);
  1467. }
  1468. /**
  1469. * pci_request_regions - Reserved PCI I/O and memory resources
  1470. * @pdev: PCI device whose resources are to be reserved
  1471. * @res_name: Name to be associated with resource.
  1472. *
  1473. * Mark all PCI regions associated with PCI device @pdev as
  1474. * being reserved by owner @res_name. Do not access any
  1475. * address inside the PCI regions unless this call returns
  1476. * successfully.
  1477. *
  1478. * Returns 0 on success, or %EBUSY on error. A warning
  1479. * message is also printed on failure.
  1480. */
  1481. int pci_request_regions(struct pci_dev *pdev, const char *res_name)
  1482. {
  1483. return pci_request_selected_regions(pdev, ((1 << 6) - 1), res_name);
  1484. }
  1485. /**
  1486. * pci_request_regions_exclusive - Reserved PCI I/O and memory resources
  1487. * @pdev: PCI device whose resources are to be reserved
  1488. * @res_name: Name to be associated with resource.
  1489. *
  1490. * Mark all PCI regions associated with PCI device @pdev as
  1491. * being reserved by owner @res_name. Do not access any
  1492. * address inside the PCI regions unless this call returns
  1493. * successfully.
  1494. *
  1495. * pci_request_regions_exclusive() will mark the region so that
  1496. * /dev/mem and the sysfs MMIO access will not be allowed.
  1497. *
  1498. * Returns 0 on success, or %EBUSY on error. A warning
  1499. * message is also printed on failure.
  1500. */
  1501. int pci_request_regions_exclusive(struct pci_dev *pdev, const char *res_name)
  1502. {
  1503. return pci_request_selected_regions_exclusive(pdev,
  1504. ((1 << 6) - 1), res_name);
  1505. }
  1506. static void __pci_set_master(struct pci_dev *dev, bool enable)
  1507. {
  1508. u16 old_cmd, cmd;
  1509. pci_read_config_word(dev, PCI_COMMAND, &old_cmd);
  1510. if (enable)
  1511. cmd = old_cmd | PCI_COMMAND_MASTER;
  1512. else
  1513. cmd = old_cmd & ~PCI_COMMAND_MASTER;
  1514. if (cmd != old_cmd) {
  1515. dev_dbg(&dev->dev, "%s bus mastering\n",
  1516. enable ? "enabling" : "disabling");
  1517. pci_write_config_word(dev, PCI_COMMAND, cmd);
  1518. }
  1519. dev->is_busmaster = enable;
  1520. }
  1521. /**
  1522. * pci_set_master - enables bus-mastering for device dev
  1523. * @dev: the PCI device to enable
  1524. *
  1525. * Enables bus-mastering on the device and calls pcibios_set_master()
  1526. * to do the needed arch specific settings.
  1527. */
  1528. void pci_set_master(struct pci_dev *dev)
  1529. {
  1530. __pci_set_master(dev, true);
  1531. pcibios_set_master(dev);
  1532. }
  1533. /**
  1534. * pci_clear_master - disables bus-mastering for device dev
  1535. * @dev: the PCI device to disable
  1536. */
  1537. void pci_clear_master(struct pci_dev *dev)
  1538. {
  1539. __pci_set_master(dev, false);
  1540. }
  1541. #ifdef PCI_DISABLE_MWI
  1542. int pci_set_mwi(struct pci_dev *dev)
  1543. {
  1544. return 0;
  1545. }
  1546. int pci_try_set_mwi(struct pci_dev *dev)
  1547. {
  1548. return 0;
  1549. }
  1550. void pci_clear_mwi(struct pci_dev *dev)
  1551. {
  1552. }
  1553. #else
  1554. #ifndef PCI_CACHE_LINE_BYTES
  1555. #define PCI_CACHE_LINE_BYTES L1_CACHE_BYTES
  1556. #endif
  1557. /* This can be overridden by arch code. */
  1558. /* Don't forget this is measured in 32-bit words, not bytes */
  1559. u8 pci_cache_line_size = PCI_CACHE_LINE_BYTES / 4;
  1560. /**
  1561. * pci_set_cacheline_size - ensure the CACHE_LINE_SIZE register is programmed
  1562. * @dev: the PCI device for which MWI is to be enabled
  1563. *
  1564. * Helper function for pci_set_mwi.
  1565. * Originally copied from drivers/net/acenic.c.
  1566. * Copyright 1998-2001 by Jes Sorensen, <jes@trained-monkey.org>.
  1567. *
  1568. * RETURNS: An appropriate -ERRNO error value on error, or zero for success.
  1569. */
  1570. static int
  1571. pci_set_cacheline_size(struct pci_dev *dev)
  1572. {
  1573. u8 cacheline_size;
  1574. if (!pci_cache_line_size)
  1575. return -EINVAL; /* The system doesn't support MWI. */
  1576. /* Validate current setting: the PCI_CACHE_LINE_SIZE must be
  1577. equal to or multiple of the right value. */
  1578. pci_read_config_byte(dev, PCI_CACHE_LINE_SIZE, &cacheline_size);
  1579. if (cacheline_size >= pci_cache_line_size &&
  1580. (cacheline_size % pci_cache_line_size) == 0)
  1581. return 0;
  1582. /* Write the correct value. */
  1583. pci_write_config_byte(dev, PCI_CACHE_LINE_SIZE, pci_cache_line_size);
  1584. /* Read it back. */
  1585. pci_read_config_byte(dev, PCI_CACHE_LINE_SIZE, &cacheline_size);
  1586. if (cacheline_size == pci_cache_line_size)
  1587. return 0;
  1588. dev_printk(KERN_DEBUG, &dev->dev, "cache line size of %d is not "
  1589. "supported\n", pci_cache_line_size << 2);
  1590. return -EINVAL;
  1591. }
  1592. /**
  1593. * pci_set_mwi - enables memory-write-invalidate PCI transaction
  1594. * @dev: the PCI device for which MWI is enabled
  1595. *
  1596. * Enables the Memory-Write-Invalidate transaction in %PCI_COMMAND.
  1597. *
  1598. * RETURNS: An appropriate -ERRNO error value on error, or zero for success.
  1599. */
  1600. int
  1601. pci_set_mwi(struct pci_dev *dev)
  1602. {
  1603. int rc;
  1604. u16 cmd;
  1605. rc = pci_set_cacheline_size(dev);
  1606. if (rc)
  1607. return rc;
  1608. pci_read_config_word(dev, PCI_COMMAND, &cmd);
  1609. if (! (cmd & PCI_COMMAND_INVALIDATE)) {
  1610. dev_dbg(&dev->dev, "enabling Mem-Wr-Inval\n");
  1611. cmd |= PCI_COMMAND_INVALIDATE;
  1612. pci_write_config_word(dev, PCI_COMMAND, cmd);
  1613. }
  1614. return 0;
  1615. }
  1616. /**
  1617. * pci_try_set_mwi - enables memory-write-invalidate PCI transaction
  1618. * @dev: the PCI device for which MWI is enabled
  1619. *
  1620. * Enables the Memory-Write-Invalidate transaction in %PCI_COMMAND.
  1621. * Callers are not required to check the return value.
  1622. *
  1623. * RETURNS: An appropriate -ERRNO error value on error, or zero for success.
  1624. */
  1625. int pci_try_set_mwi(struct pci_dev *dev)
  1626. {
  1627. int rc = pci_set_mwi(dev);
  1628. return rc;
  1629. }
  1630. /**
  1631. * pci_clear_mwi - disables Memory-Write-Invalidate for device dev
  1632. * @dev: the PCI device to disable
  1633. *
  1634. * Disables PCI Memory-Write-Invalidate transaction on the device
  1635. */
  1636. void
  1637. pci_clear_mwi(struct pci_dev *dev)
  1638. {
  1639. u16 cmd;
  1640. pci_read_config_word(dev, PCI_COMMAND, &cmd);
  1641. if (cmd & PCI_COMMAND_INVALIDATE) {
  1642. cmd &= ~PCI_COMMAND_INVALIDATE;
  1643. pci_write_config_word(dev, PCI_COMMAND, cmd);
  1644. }
  1645. }
  1646. #endif /* ! PCI_DISABLE_MWI */
  1647. /**
  1648. * pci_intx - enables/disables PCI INTx for device dev
  1649. * @pdev: the PCI device to operate on
  1650. * @enable: boolean: whether to enable or disable PCI INTx
  1651. *
  1652. * Enables/disables PCI INTx for device dev
  1653. */
  1654. void
  1655. pci_intx(struct pci_dev *pdev, int enable)
  1656. {
  1657. u16 pci_command, new;
  1658. pci_read_config_word(pdev, PCI_COMMAND, &pci_command);
  1659. if (enable) {
  1660. new = pci_command & ~PCI_COMMAND_INTX_DISABLE;
  1661. } else {
  1662. new = pci_command | PCI_COMMAND_INTX_DISABLE;
  1663. }
  1664. if (new != pci_command) {
  1665. struct pci_devres *dr;
  1666. pci_write_config_word(pdev, PCI_COMMAND, new);
  1667. dr = find_pci_dr(pdev);
  1668. if (dr && !dr->restore_intx) {
  1669. dr->restore_intx = 1;
  1670. dr->orig_intx = !enable;
  1671. }
  1672. }
  1673. }
  1674. /**
  1675. * pci_msi_off - disables any msi or msix capabilities
  1676. * @dev: the PCI device to operate on
  1677. *
  1678. * If you want to use msi see pci_enable_msi and friends.
  1679. * This is a lower level primitive that allows us to disable
  1680. * msi operation at the device level.
  1681. */
  1682. void pci_msi_off(struct pci_dev *dev)
  1683. {
  1684. int pos;
  1685. u16 control;
  1686. pos = pci_find_capability(dev, PCI_CAP_ID_MSI);
  1687. if (pos) {
  1688. pci_read_config_word(dev, pos + PCI_MSI_FLAGS, &control);
  1689. control &= ~PCI_MSI_FLAGS_ENABLE;
  1690. pci_write_config_word(dev, pos + PCI_MSI_FLAGS, control);
  1691. }
  1692. pos = pci_find_capability(dev, PCI_CAP_ID_MSIX);
  1693. if (pos) {
  1694. pci_read_config_word(dev, pos + PCI_MSIX_FLAGS, &control);
  1695. control &= ~PCI_MSIX_FLAGS_ENABLE;
  1696. pci_write_config_word(dev, pos + PCI_MSIX_FLAGS, control);
  1697. }
  1698. }
  1699. #ifndef HAVE_ARCH_PCI_SET_DMA_MASK
  1700. /*
  1701. * These can be overridden by arch-specific implementations
  1702. */
  1703. int
  1704. pci_set_dma_mask(struct pci_dev *dev, u64 mask)
  1705. {
  1706. if (!pci_dma_supported(dev, mask))
  1707. return -EIO;
  1708. dev->dma_mask = mask;
  1709. return 0;
  1710. }
  1711. int
  1712. pci_set_consistent_dma_mask(struct pci_dev *dev, u64 mask)
  1713. {
  1714. if (!pci_dma_supported(dev, mask))
  1715. return -EIO;
  1716. dev->dev.coherent_dma_mask = mask;
  1717. return 0;
  1718. }
  1719. #endif
  1720. #ifndef HAVE_ARCH_PCI_SET_DMA_MAX_SEGMENT_SIZE
  1721. int pci_set_dma_max_seg_size(struct pci_dev *dev, unsigned int size)
  1722. {
  1723. return dma_set_max_seg_size(&dev->dev, size);
  1724. }
  1725. EXPORT_SYMBOL(pci_set_dma_max_seg_size);
  1726. #endif
  1727. #ifndef HAVE_ARCH_PCI_SET_DMA_SEGMENT_BOUNDARY
  1728. int pci_set_dma_seg_boundary(struct pci_dev *dev, unsigned long mask)
  1729. {
  1730. return dma_set_seg_boundary(&dev->dev, mask);
  1731. }
  1732. EXPORT_SYMBOL(pci_set_dma_seg_boundary);
  1733. #endif
  1734. static int __pcie_flr(struct pci_dev *dev, int probe)
  1735. {
  1736. u16 status;
  1737. u32 cap;
  1738. int exppos = pci_find_capability(dev, PCI_CAP_ID_EXP);
  1739. if (!exppos)
  1740. return -ENOTTY;
  1741. pci_read_config_dword(dev, exppos + PCI_EXP_DEVCAP, &cap);
  1742. if (!(cap & PCI_EXP_DEVCAP_FLR))
  1743. return -ENOTTY;
  1744. if (probe)
  1745. return 0;
  1746. pci_block_user_cfg_access(dev);
  1747. /* Wait for Transaction Pending bit clean */
  1748. msleep(100);
  1749. pci_read_config_word(dev, exppos + PCI_EXP_DEVSTA, &status);
  1750. if (status & PCI_EXP_DEVSTA_TRPND) {
  1751. dev_info(&dev->dev, "Busy after 100ms while trying to reset; "
  1752. "sleeping for 1 second\n");
  1753. ssleep(1);
  1754. pci_read_config_word(dev, exppos + PCI_EXP_DEVSTA, &status);
  1755. if (status & PCI_EXP_DEVSTA_TRPND)
  1756. dev_info(&dev->dev, "Still busy after 1s; "
  1757. "proceeding with reset anyway\n");
  1758. }
  1759. pci_write_config_word(dev, exppos + PCI_EXP_DEVCTL,
  1760. PCI_EXP_DEVCTL_BCR_FLR);
  1761. mdelay(100);
  1762. pci_unblock_user_cfg_access(dev);
  1763. return 0;
  1764. }
  1765. static int __pci_af_flr(struct pci_dev *dev, int probe)
  1766. {
  1767. int cappos = pci_find_capability(dev, PCI_CAP_ID_AF);
  1768. u8 status;
  1769. u8 cap;
  1770. if (!cappos)
  1771. return -ENOTTY;
  1772. pci_read_config_byte(dev, cappos + PCI_AF_CAP, &cap);
  1773. if (!(cap & PCI_AF_CAP_TP) || !(cap & PCI_AF_CAP_FLR))
  1774. return -ENOTTY;
  1775. if (probe)
  1776. return 0;
  1777. pci_block_user_cfg_access(dev);
  1778. /* Wait for Transaction Pending bit clean */
  1779. msleep(100);
  1780. pci_read_config_byte(dev, cappos + PCI_AF_STATUS, &status);
  1781. if (status & PCI_AF_STATUS_TP) {
  1782. dev_info(&dev->dev, "Busy after 100ms while trying to"
  1783. " reset; sleeping for 1 second\n");
  1784. ssleep(1);
  1785. pci_read_config_byte(dev,
  1786. cappos + PCI_AF_STATUS, &status);
  1787. if (status & PCI_AF_STATUS_TP)
  1788. dev_info(&dev->dev, "Still busy after 1s; "
  1789. "proceeding with reset anyway\n");
  1790. }
  1791. pci_write_config_byte(dev, cappos + PCI_AF_CTRL, PCI_AF_CTRL_FLR);
  1792. mdelay(100);
  1793. pci_unblock_user_cfg_access(dev);
  1794. return 0;
  1795. }
  1796. static int __pci_reset_function(struct pci_dev *pdev, int probe)
  1797. {
  1798. int res;
  1799. res = __pcie_flr(pdev, probe);
  1800. if (res != -ENOTTY)
  1801. return res;
  1802. res = __pci_af_flr(pdev, probe);
  1803. if (res != -ENOTTY)
  1804. return res;
  1805. return res;
  1806. }
  1807. /**
  1808. * pci_execute_reset_function() - Reset a PCI device function
  1809. * @dev: Device function to reset
  1810. *
  1811. * Some devices allow an individual function to be reset without affecting
  1812. * other functions in the same device. The PCI device must be responsive
  1813. * to PCI config space in order to use this function.
  1814. *
  1815. * The device function is presumed to be unused when this function is called.
  1816. * Resetting the device will make the contents of PCI configuration space
  1817. * random, so any caller of this must be prepared to reinitialise the
  1818. * device including MSI, bus mastering, BARs, decoding IO and memory spaces,
  1819. * etc.
  1820. *
  1821. * Returns 0 if the device function was successfully reset or -ENOTTY if the
  1822. * device doesn't support resetting a single function.
  1823. */
  1824. int pci_execute_reset_function(struct pci_dev *dev)
  1825. {
  1826. return __pci_reset_function(dev, 0);
  1827. }
  1828. EXPORT_SYMBOL_GPL(pci_execute_reset_function);
  1829. /**
  1830. * pci_reset_function() - quiesce and reset a PCI device function
  1831. * @dev: Device function to reset
  1832. *
  1833. * Some devices allow an individual function to be reset without affecting
  1834. * other functions in the same device. The PCI device must be responsive
  1835. * to PCI config space in order to use this function.
  1836. *
  1837. * This function does not just reset the PCI portion of a device, but
  1838. * clears all the state associated with the device. This function differs
  1839. * from pci_execute_reset_function in that it saves and restores device state
  1840. * over the reset.
  1841. *
  1842. * Returns 0 if the device function was successfully reset or -ENOTTY if the
  1843. * device doesn't support resetting a single function.
  1844. */
  1845. int pci_reset_function(struct pci_dev *dev)
  1846. {
  1847. int r = __pci_reset_function(dev, 1);
  1848. if (r < 0)
  1849. return r;
  1850. if (!dev->msi_enabled && !dev->msix_enabled && dev->irq != 0)
  1851. disable_irq(dev->irq);
  1852. pci_save_state(dev);
  1853. pci_write_config_word(dev, PCI_COMMAND, PCI_COMMAND_INTX_DISABLE);
  1854. r = pci_execute_reset_function(dev);
  1855. pci_restore_state(dev);
  1856. if (!dev->msi_enabled && !dev->msix_enabled && dev->irq != 0)
  1857. enable_irq(dev->irq);
  1858. return r;
  1859. }
  1860. EXPORT_SYMBOL_GPL(pci_reset_function);
  1861. /**
  1862. * pcix_get_max_mmrbc - get PCI-X maximum designed memory read byte count
  1863. * @dev: PCI device to query
  1864. *
  1865. * Returns mmrbc: maximum designed memory read count in bytes
  1866. * or appropriate error value.
  1867. */
  1868. int pcix_get_max_mmrbc(struct pci_dev *dev)
  1869. {
  1870. int err, cap;
  1871. u32 stat;
  1872. cap = pci_find_capability(dev, PCI_CAP_ID_PCIX);
  1873. if (!cap)
  1874. return -EINVAL;
  1875. err = pci_read_config_dword(dev, cap + PCI_X_STATUS, &stat);
  1876. if (err)
  1877. return -EINVAL;
  1878. return (stat & PCI_X_STATUS_MAX_READ) >> 12;
  1879. }
  1880. EXPORT_SYMBOL(pcix_get_max_mmrbc);
  1881. /**
  1882. * pcix_get_mmrbc - get PCI-X maximum memory read byte count
  1883. * @dev: PCI device to query
  1884. *
  1885. * Returns mmrbc: maximum memory read count in bytes
  1886. * or appropriate error value.
  1887. */
  1888. int pcix_get_mmrbc(struct pci_dev *dev)
  1889. {
  1890. int ret, cap;
  1891. u32 cmd;
  1892. cap = pci_find_capability(dev, PCI_CAP_ID_PCIX);
  1893. if (!cap)
  1894. return -EINVAL;
  1895. ret = pci_read_config_dword(dev, cap + PCI_X_CMD, &cmd);
  1896. if (!ret)
  1897. ret = 512 << ((cmd & PCI_X_CMD_MAX_READ) >> 2);
  1898. return ret;
  1899. }
  1900. EXPORT_SYMBOL(pcix_get_mmrbc);
  1901. /**
  1902. * pcix_set_mmrbc - set PCI-X maximum memory read byte count
  1903. * @dev: PCI device to query
  1904. * @mmrbc: maximum memory read count in bytes
  1905. * valid values are 512, 1024, 2048, 4096
  1906. *
  1907. * If possible sets maximum memory read byte count, some bridges have erratas
  1908. * that prevent this.
  1909. */
  1910. int pcix_set_mmrbc(struct pci_dev *dev, int mmrbc)
  1911. {
  1912. int cap, err = -EINVAL;
  1913. u32 stat, cmd, v, o;
  1914. if (mmrbc < 512 || mmrbc > 4096 || !is_power_of_2(mmrbc))
  1915. goto out;
  1916. v = ffs(mmrbc) - 10;
  1917. cap = pci_find_capability(dev, PCI_CAP_ID_PCIX);
  1918. if (!cap)
  1919. goto out;
  1920. err = pci_read_config_dword(dev, cap + PCI_X_STATUS, &stat);
  1921. if (err)
  1922. goto out;
  1923. if (v > (stat & PCI_X_STATUS_MAX_READ) >> 21)
  1924. return -E2BIG;
  1925. err = pci_read_config_dword(dev, cap + PCI_X_CMD, &cmd);
  1926. if (err)
  1927. goto out;
  1928. o = (cmd & PCI_X_CMD_MAX_READ) >> 2;
  1929. if (o != v) {
  1930. if (v > o && dev->bus &&
  1931. (dev->bus->bus_flags & PCI_BUS_FLAGS_NO_MMRBC))
  1932. return -EIO;
  1933. cmd &= ~PCI_X_CMD_MAX_READ;
  1934. cmd |= v << 2;
  1935. err = pci_write_config_dword(dev, cap + PCI_X_CMD, cmd);
  1936. }
  1937. out:
  1938. return err;
  1939. }
  1940. EXPORT_SYMBOL(pcix_set_mmrbc);
  1941. /**
  1942. * pcie_get_readrq - get PCI Express read request size
  1943. * @dev: PCI device to query
  1944. *
  1945. * Returns maximum memory read request in bytes
  1946. * or appropriate error value.
  1947. */
  1948. int pcie_get_readrq(struct pci_dev *dev)
  1949. {
  1950. int ret, cap;
  1951. u16 ctl;
  1952. cap = pci_find_capability(dev, PCI_CAP_ID_EXP);
  1953. if (!cap)
  1954. return -EINVAL;
  1955. ret = pci_read_config_word(dev, cap + PCI_EXP_DEVCTL, &ctl);
  1956. if (!ret)
  1957. ret = 128 << ((ctl & PCI_EXP_DEVCTL_READRQ) >> 12);
  1958. return ret;
  1959. }
  1960. EXPORT_SYMBOL(pcie_get_readrq);
  1961. /**
  1962. * pcie_set_readrq - set PCI Express maximum memory read request
  1963. * @dev: PCI device to query
  1964. * @rq: maximum memory read count in bytes
  1965. * valid values are 128, 256, 512, 1024, 2048, 4096
  1966. *
  1967. * If possible sets maximum read byte count
  1968. */
  1969. int pcie_set_readrq(struct pci_dev *dev, int rq)
  1970. {
  1971. int cap, err = -EINVAL;
  1972. u16 ctl, v;
  1973. if (rq < 128 || rq > 4096 || !is_power_of_2(rq))
  1974. goto out;
  1975. v = (ffs(rq) - 8) << 12;
  1976. cap = pci_find_capability(dev, PCI_CAP_ID_EXP);
  1977. if (!cap)
  1978. goto out;
  1979. err = pci_read_config_word(dev, cap + PCI_EXP_DEVCTL, &ctl);
  1980. if (err)
  1981. goto out;
  1982. if ((ctl & PCI_EXP_DEVCTL_READRQ) != v) {
  1983. ctl &= ~PCI_EXP_DEVCTL_READRQ;
  1984. ctl |= v;
  1985. err = pci_write_config_dword(dev, cap + PCI_EXP_DEVCTL, ctl);
  1986. }
  1987. out:
  1988. return err;
  1989. }
  1990. EXPORT_SYMBOL(pcie_set_readrq);
  1991. /**
  1992. * pci_select_bars - Make BAR mask from the type of resource
  1993. * @dev: the PCI device for which BAR mask is made
  1994. * @flags: resource type mask to be selected
  1995. *
  1996. * This helper routine makes bar mask from the type of resource.
  1997. */
  1998. int pci_select_bars(struct pci_dev *dev, unsigned long flags)
  1999. {
  2000. int i, bars = 0;
  2001. for (i = 0; i < PCI_NUM_RESOURCES; i++)
  2002. if (pci_resource_flags(dev, i) & flags)
  2003. bars |= (1 << i);
  2004. return bars;
  2005. }
  2006. /**
  2007. * pci_resource_bar - get position of the BAR associated with a resource
  2008. * @dev: the PCI device
  2009. * @resno: the resource number
  2010. * @type: the BAR type to be filled in
  2011. *
  2012. * Returns BAR position in config space, or 0 if the BAR is invalid.
  2013. */
  2014. int pci_resource_bar(struct pci_dev *dev, int resno, enum pci_bar_type *type)
  2015. {
  2016. if (resno < PCI_ROM_RESOURCE) {
  2017. *type = pci_bar_unknown;
  2018. return PCI_BASE_ADDRESS_0 + 4 * resno;
  2019. } else if (resno == PCI_ROM_RESOURCE) {
  2020. *type = pci_bar_mem32;
  2021. return dev->rom_base_reg;
  2022. }
  2023. dev_err(&dev->dev, "BAR: invalid resource #%d\n", resno);
  2024. return 0;
  2025. }
  2026. static void __devinit pci_no_domains(void)
  2027. {
  2028. #ifdef CONFIG_PCI_DOMAINS
  2029. pci_domains_supported = 0;
  2030. #endif
  2031. }
  2032. /**
  2033. * pci_ext_cfg_enabled - can we access extended PCI config space?
  2034. * @dev: The PCI device of the root bridge.
  2035. *
  2036. * Returns 1 if we can access PCI extended config space (offsets
  2037. * greater than 0xff). This is the default implementation. Architecture
  2038. * implementations can override this.
  2039. */
  2040. int __attribute__ ((weak)) pci_ext_cfg_avail(struct pci_dev *dev)
  2041. {
  2042. return 1;
  2043. }
  2044. static int __devinit pci_init(void)
  2045. {
  2046. struct pci_dev *dev = NULL;
  2047. while ((dev = pci_get_device(PCI_ANY_ID, PCI_ANY_ID, dev)) != NULL) {
  2048. pci_fixup_device(pci_fixup_final, dev);
  2049. }
  2050. return 0;
  2051. }
  2052. static int __init pci_setup(char *str)
  2053. {
  2054. while (str) {
  2055. char *k = strchr(str, ',');
  2056. if (k)
  2057. *k++ = 0;
  2058. if (*str && (str = pcibios_setup(str)) && *str) {
  2059. if (!strcmp(str, "nomsi")) {
  2060. pci_no_msi();
  2061. } else if (!strcmp(str, "noaer")) {
  2062. pci_no_aer();
  2063. } else if (!strcmp(str, "nodomains")) {
  2064. pci_no_domains();
  2065. } else if (!strncmp(str, "cbiosize=", 9)) {
  2066. pci_cardbus_io_size = memparse(str + 9, &str);
  2067. } else if (!strncmp(str, "cbmemsize=", 10)) {
  2068. pci_cardbus_mem_size = memparse(str + 10, &str);
  2069. } else {
  2070. printk(KERN_ERR "PCI: Unknown option `%s'\n",
  2071. str);
  2072. }
  2073. }
  2074. str = k;
  2075. }
  2076. return 0;
  2077. }
  2078. early_param("pci", pci_setup);
  2079. device_initcall(pci_init);
  2080. EXPORT_SYMBOL(pci_reenable_device);
  2081. EXPORT_SYMBOL(pci_enable_device_io);
  2082. EXPORT_SYMBOL(pci_enable_device_mem);
  2083. EXPORT_SYMBOL(pci_enable_device);
  2084. EXPORT_SYMBOL(pcim_enable_device);
  2085. EXPORT_SYMBOL(pcim_pin_device);
  2086. EXPORT_SYMBOL(pci_disable_device);
  2087. EXPORT_SYMBOL(pci_find_capability);
  2088. EXPORT_SYMBOL(pci_bus_find_capability);
  2089. EXPORT_SYMBOL(pci_release_regions);
  2090. EXPORT_SYMBOL(pci_request_regions);
  2091. EXPORT_SYMBOL(pci_request_regions_exclusive);
  2092. EXPORT_SYMBOL(pci_release_region);
  2093. EXPORT_SYMBOL(pci_request_region);
  2094. EXPORT_SYMBOL(pci_request_region_exclusive);
  2095. EXPORT_SYMBOL(pci_release_selected_regions);
  2096. EXPORT_SYMBOL(pci_request_selected_regions);
  2097. EXPORT_SYMBOL(pci_request_selected_regions_exclusive);
  2098. EXPORT_SYMBOL(pci_set_master);
  2099. EXPORT_SYMBOL(pci_clear_master);
  2100. EXPORT_SYMBOL(pci_set_mwi);
  2101. EXPORT_SYMBOL(pci_try_set_mwi);
  2102. EXPORT_SYMBOL(pci_clear_mwi);
  2103. EXPORT_SYMBOL_GPL(pci_intx);
  2104. EXPORT_SYMBOL(pci_set_dma_mask);
  2105. EXPORT_SYMBOL(pci_set_consistent_dma_mask);
  2106. EXPORT_SYMBOL(pci_assign_resource);
  2107. EXPORT_SYMBOL(pci_find_parent_resource);
  2108. EXPORT_SYMBOL(pci_select_bars);
  2109. EXPORT_SYMBOL(pci_set_power_state);
  2110. EXPORT_SYMBOL(pci_save_state);
  2111. EXPORT_SYMBOL(pci_restore_state);
  2112. EXPORT_SYMBOL(pci_pme_capable);
  2113. EXPORT_SYMBOL(pci_pme_active);
  2114. EXPORT_SYMBOL(pci_enable_wake);
  2115. EXPORT_SYMBOL(pci_wake_from_d3);
  2116. EXPORT_SYMBOL(pci_target_state);
  2117. EXPORT_SYMBOL(pci_prepare_to_sleep);
  2118. EXPORT_SYMBOL(pci_back_from_sleep);
  2119. EXPORT_SYMBOL_GPL(pci_set_pcie_reset_state);