pci.c 49 KB

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