pci.c 33 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253
  1. /*
  2. * $Id: pci.c,v 1.91 1999/01/21 13:34:01 davem Exp $
  3. *
  4. * PCI Bus Services, see include/linux/pci.h for further explanation.
  5. *
  6. * Copyright 1993 -- 1997 Drew Eckhardt, Frederic Potter,
  7. * David Mosberger-Tang
  8. *
  9. * Copyright 1997 -- 2000 Martin Mares <mj@ucw.cz>
  10. */
  11. #include <linux/kernel.h>
  12. #include <linux/delay.h>
  13. #include <linux/init.h>
  14. #include <linux/pci.h>
  15. #include <linux/module.h>
  16. #include <linux/spinlock.h>
  17. #include <linux/string.h>
  18. #include <asm/dma.h> /* isa_dma_bridge_buggy */
  19. #include "pci.h"
  20. unsigned int pci_pm_d3_delay = 10;
  21. /**
  22. * pci_bus_max_busnr - returns maximum PCI bus number of given bus' children
  23. * @bus: pointer to PCI bus structure to search
  24. *
  25. * Given a PCI bus, returns the highest PCI bus number present in the set
  26. * including the given PCI bus and its list of child PCI buses.
  27. */
  28. unsigned char __devinit
  29. pci_bus_max_busnr(struct pci_bus* bus)
  30. {
  31. struct list_head *tmp;
  32. unsigned char max, n;
  33. max = bus->subordinate;
  34. list_for_each(tmp, &bus->children) {
  35. n = pci_bus_max_busnr(pci_bus_b(tmp));
  36. if(n > max)
  37. max = n;
  38. }
  39. return max;
  40. }
  41. EXPORT_SYMBOL_GPL(pci_bus_max_busnr);
  42. #if 0
  43. /**
  44. * pci_max_busnr - returns maximum PCI bus number
  45. *
  46. * Returns the highest PCI bus number present in the system global list of
  47. * PCI buses.
  48. */
  49. unsigned char __devinit
  50. pci_max_busnr(void)
  51. {
  52. struct pci_bus *bus = NULL;
  53. unsigned char max, n;
  54. max = 0;
  55. while ((bus = pci_find_next_bus(bus)) != NULL) {
  56. n = pci_bus_max_busnr(bus);
  57. if(n > max)
  58. max = n;
  59. }
  60. return max;
  61. }
  62. #endif /* 0 */
  63. #define PCI_FIND_CAP_TTL 48
  64. static int __pci_find_next_cap_ttl(struct pci_bus *bus, unsigned int devfn,
  65. u8 pos, int cap, int *ttl)
  66. {
  67. u8 id;
  68. while ((*ttl)--) {
  69. pci_bus_read_config_byte(bus, devfn, pos, &pos);
  70. if (pos < 0x40)
  71. break;
  72. pos &= ~3;
  73. pci_bus_read_config_byte(bus, devfn, pos + PCI_CAP_LIST_ID,
  74. &id);
  75. if (id == 0xff)
  76. break;
  77. if (id == cap)
  78. return pos;
  79. pos += PCI_CAP_LIST_NEXT;
  80. }
  81. return 0;
  82. }
  83. static int __pci_find_next_cap(struct pci_bus *bus, unsigned int devfn,
  84. u8 pos, int cap)
  85. {
  86. int ttl = PCI_FIND_CAP_TTL;
  87. return __pci_find_next_cap_ttl(bus, devfn, pos, cap, &ttl);
  88. }
  89. int pci_find_next_capability(struct pci_dev *dev, u8 pos, int cap)
  90. {
  91. return __pci_find_next_cap(dev->bus, dev->devfn,
  92. pos + PCI_CAP_LIST_NEXT, cap);
  93. }
  94. EXPORT_SYMBOL_GPL(pci_find_next_capability);
  95. static int __pci_bus_find_cap_start(struct pci_bus *bus,
  96. unsigned int devfn, u8 hdr_type)
  97. {
  98. u16 status;
  99. pci_bus_read_config_word(bus, devfn, PCI_STATUS, &status);
  100. if (!(status & PCI_STATUS_CAP_LIST))
  101. return 0;
  102. switch (hdr_type) {
  103. case PCI_HEADER_TYPE_NORMAL:
  104. case PCI_HEADER_TYPE_BRIDGE:
  105. return PCI_CAPABILITY_LIST;
  106. case PCI_HEADER_TYPE_CARDBUS:
  107. return PCI_CB_CAPABILITY_LIST;
  108. default:
  109. return 0;
  110. }
  111. return 0;
  112. }
  113. /**
  114. * pci_find_capability - query for devices' capabilities
  115. * @dev: PCI device to query
  116. * @cap: capability code
  117. *
  118. * Tell if a device supports a given PCI capability.
  119. * Returns the address of the requested capability structure within the
  120. * device's PCI configuration space or 0 in case the device does not
  121. * support it. Possible values for @cap:
  122. *
  123. * %PCI_CAP_ID_PM Power Management
  124. * %PCI_CAP_ID_AGP Accelerated Graphics Port
  125. * %PCI_CAP_ID_VPD Vital Product Data
  126. * %PCI_CAP_ID_SLOTID Slot Identification
  127. * %PCI_CAP_ID_MSI Message Signalled Interrupts
  128. * %PCI_CAP_ID_CHSWP CompactPCI HotSwap
  129. * %PCI_CAP_ID_PCIX PCI-X
  130. * %PCI_CAP_ID_EXP PCI Express
  131. */
  132. int pci_find_capability(struct pci_dev *dev, int cap)
  133. {
  134. int pos;
  135. pos = __pci_bus_find_cap_start(dev->bus, dev->devfn, dev->hdr_type);
  136. if (pos)
  137. pos = __pci_find_next_cap(dev->bus, dev->devfn, pos, cap);
  138. return pos;
  139. }
  140. /**
  141. * pci_bus_find_capability - query for devices' capabilities
  142. * @bus: the PCI bus to query
  143. * @devfn: PCI device to query
  144. * @cap: capability code
  145. *
  146. * Like pci_find_capability() but works for pci devices that do not have a
  147. * pci_dev structure set up yet.
  148. *
  149. * Returns the address of the requested capability structure within the
  150. * device's PCI configuration space or 0 in case the device does not
  151. * support it.
  152. */
  153. int pci_bus_find_capability(struct pci_bus *bus, unsigned int devfn, int cap)
  154. {
  155. int pos;
  156. u8 hdr_type;
  157. pci_bus_read_config_byte(bus, devfn, PCI_HEADER_TYPE, &hdr_type);
  158. pos = __pci_bus_find_cap_start(bus, devfn, hdr_type & 0x7f);
  159. if (pos)
  160. pos = __pci_find_next_cap(bus, devfn, pos, cap);
  161. return pos;
  162. }
  163. /**
  164. * pci_find_ext_capability - Find an extended capability
  165. * @dev: PCI device to query
  166. * @cap: capability code
  167. *
  168. * Returns the address of the requested extended capability structure
  169. * within the device's PCI configuration space or 0 if the device does
  170. * not support it. Possible values for @cap:
  171. *
  172. * %PCI_EXT_CAP_ID_ERR Advanced Error Reporting
  173. * %PCI_EXT_CAP_ID_VC Virtual Channel
  174. * %PCI_EXT_CAP_ID_DSN Device Serial Number
  175. * %PCI_EXT_CAP_ID_PWR Power Budgeting
  176. */
  177. int pci_find_ext_capability(struct pci_dev *dev, int cap)
  178. {
  179. u32 header;
  180. int ttl = 480; /* 3840 bytes, minimum 8 bytes per capability */
  181. int pos = 0x100;
  182. if (dev->cfg_size <= 256)
  183. return 0;
  184. if (pci_read_config_dword(dev, pos, &header) != PCIBIOS_SUCCESSFUL)
  185. return 0;
  186. /*
  187. * If we have no capabilities, this is indicated by cap ID,
  188. * cap version and next pointer all being 0.
  189. */
  190. if (header == 0)
  191. return 0;
  192. while (ttl-- > 0) {
  193. if (PCI_EXT_CAP_ID(header) == cap)
  194. return pos;
  195. pos = PCI_EXT_CAP_NEXT(header);
  196. if (pos < 0x100)
  197. break;
  198. if (pci_read_config_dword(dev, pos, &header) != PCIBIOS_SUCCESSFUL)
  199. break;
  200. }
  201. return 0;
  202. }
  203. EXPORT_SYMBOL_GPL(pci_find_ext_capability);
  204. static int __pci_find_next_ht_cap(struct pci_dev *dev, int pos, int ht_cap)
  205. {
  206. int rc, ttl = PCI_FIND_CAP_TTL;
  207. u8 cap, mask;
  208. if (ht_cap == HT_CAPTYPE_SLAVE || ht_cap == HT_CAPTYPE_HOST)
  209. mask = HT_3BIT_CAP_MASK;
  210. else
  211. mask = HT_5BIT_CAP_MASK;
  212. pos = __pci_find_next_cap_ttl(dev->bus, dev->devfn, pos,
  213. PCI_CAP_ID_HT, &ttl);
  214. while (pos) {
  215. rc = pci_read_config_byte(dev, pos + 3, &cap);
  216. if (rc != PCIBIOS_SUCCESSFUL)
  217. return 0;
  218. if ((cap & mask) == ht_cap)
  219. return pos;
  220. pos = __pci_find_next_cap_ttl(dev->bus, dev->devfn,
  221. pos + PCI_CAP_LIST_NEXT,
  222. PCI_CAP_ID_HT, &ttl);
  223. }
  224. return 0;
  225. }
  226. /**
  227. * pci_find_next_ht_capability - query a device's Hypertransport capabilities
  228. * @dev: PCI device to query
  229. * @pos: Position from which to continue searching
  230. * @ht_cap: Hypertransport capability code
  231. *
  232. * To be used in conjunction with pci_find_ht_capability() to search for
  233. * all capabilities matching @ht_cap. @pos should always be a value returned
  234. * from pci_find_ht_capability().
  235. *
  236. * NB. To be 100% safe against broken PCI devices, the caller should take
  237. * steps to avoid an infinite loop.
  238. */
  239. int pci_find_next_ht_capability(struct pci_dev *dev, int pos, int ht_cap)
  240. {
  241. return __pci_find_next_ht_cap(dev, pos + PCI_CAP_LIST_NEXT, ht_cap);
  242. }
  243. EXPORT_SYMBOL_GPL(pci_find_next_ht_capability);
  244. /**
  245. * pci_find_ht_capability - query a device's Hypertransport capabilities
  246. * @dev: PCI device to query
  247. * @ht_cap: Hypertransport capability code
  248. *
  249. * Tell if a device supports a given Hypertransport capability.
  250. * Returns an address within the device's PCI configuration space
  251. * or 0 in case the device does not support the request capability.
  252. * The address points to the PCI capability, of type PCI_CAP_ID_HT,
  253. * which has a Hypertransport capability matching @ht_cap.
  254. */
  255. int pci_find_ht_capability(struct pci_dev *dev, int ht_cap)
  256. {
  257. int pos;
  258. pos = __pci_bus_find_cap_start(dev->bus, dev->devfn, dev->hdr_type);
  259. if (pos)
  260. pos = __pci_find_next_ht_cap(dev, pos, ht_cap);
  261. return pos;
  262. }
  263. EXPORT_SYMBOL_GPL(pci_find_ht_capability);
  264. /**
  265. * pci_find_parent_resource - return resource region of parent bus of given region
  266. * @dev: PCI device structure contains resources to be searched
  267. * @res: child resource record for which parent is sought
  268. *
  269. * For given resource region of given device, return the resource
  270. * region of parent bus the given region is contained in or where
  271. * it should be allocated from.
  272. */
  273. struct resource *
  274. pci_find_parent_resource(const struct pci_dev *dev, struct resource *res)
  275. {
  276. const struct pci_bus *bus = dev->bus;
  277. int i;
  278. struct resource *best = NULL;
  279. for(i = 0; i < PCI_BUS_NUM_RESOURCES; i++) {
  280. struct resource *r = bus->resource[i];
  281. if (!r)
  282. continue;
  283. if (res->start && !(res->start >= r->start && res->end <= r->end))
  284. continue; /* Not contained */
  285. if ((res->flags ^ r->flags) & (IORESOURCE_IO | IORESOURCE_MEM))
  286. continue; /* Wrong type */
  287. if (!((res->flags ^ r->flags) & IORESOURCE_PREFETCH))
  288. return r; /* Exact match */
  289. if ((res->flags & IORESOURCE_PREFETCH) && !(r->flags & IORESOURCE_PREFETCH))
  290. best = r; /* Approximating prefetchable by non-prefetchable */
  291. }
  292. return best;
  293. }
  294. /**
  295. * pci_restore_bars - restore a devices BAR values (e.g. after wake-up)
  296. * @dev: PCI device to have its BARs restored
  297. *
  298. * Restore the BAR values for a given device, so as to make it
  299. * accessible by its driver.
  300. */
  301. void
  302. pci_restore_bars(struct pci_dev *dev)
  303. {
  304. int i, numres;
  305. switch (dev->hdr_type) {
  306. case PCI_HEADER_TYPE_NORMAL:
  307. numres = 6;
  308. break;
  309. case PCI_HEADER_TYPE_BRIDGE:
  310. numres = 2;
  311. break;
  312. case PCI_HEADER_TYPE_CARDBUS:
  313. numres = 1;
  314. break;
  315. default:
  316. /* Should never get here, but just in case... */
  317. return;
  318. }
  319. for (i = 0; i < numres; i ++)
  320. pci_update_resource(dev, &dev->resource[i], i);
  321. }
  322. int (*platform_pci_set_power_state)(struct pci_dev *dev, pci_power_t t);
  323. /**
  324. * pci_set_power_state - Set the power state of a PCI device
  325. * @dev: PCI device to be suspended
  326. * @state: PCI power state (D0, D1, D2, D3hot, D3cold) we're entering
  327. *
  328. * Transition a device to a new power state, using the Power Management
  329. * Capabilities in the device's config space.
  330. *
  331. * RETURN VALUE:
  332. * -EINVAL if trying to enter a lower state than we're already in.
  333. * 0 if we're already in the requested state.
  334. * -EIO if device does not support PCI PM.
  335. * 0 if we can successfully change the power state.
  336. */
  337. int
  338. pci_set_power_state(struct pci_dev *dev, pci_power_t state)
  339. {
  340. int pm, need_restore = 0;
  341. u16 pmcsr, pmc;
  342. /* bound the state we're entering */
  343. if (state > PCI_D3hot)
  344. state = PCI_D3hot;
  345. /* Validate current state:
  346. * Can enter D0 from any state, but if we can only go deeper
  347. * to sleep if we're already in a low power state
  348. */
  349. if (state != PCI_D0 && dev->current_state > state) {
  350. printk(KERN_ERR "%s(): %s: state=%d, current state=%d\n",
  351. __FUNCTION__, pci_name(dev), state, dev->current_state);
  352. return -EINVAL;
  353. } else if (dev->current_state == state)
  354. return 0; /* we're already there */
  355. /*
  356. * If the device or the parent bridge can't support PCI PM, ignore
  357. * the request if we're doing anything besides putting it into D0
  358. * (which would only happen on boot).
  359. */
  360. if ((state == PCI_D1 || state == PCI_D2) && pci_no_d1d2(dev))
  361. return 0;
  362. /* find PCI PM capability in list */
  363. pm = pci_find_capability(dev, PCI_CAP_ID_PM);
  364. /* abort if the device doesn't support PM capabilities */
  365. if (!pm)
  366. return -EIO;
  367. pci_read_config_word(dev,pm + PCI_PM_PMC,&pmc);
  368. if ((pmc & PCI_PM_CAP_VER_MASK) > 3) {
  369. printk(KERN_DEBUG
  370. "PCI: %s has unsupported PM cap regs version (%u)\n",
  371. pci_name(dev), pmc & PCI_PM_CAP_VER_MASK);
  372. return -EIO;
  373. }
  374. /* check if this device supports the desired state */
  375. if (state == PCI_D1 && !(pmc & PCI_PM_CAP_D1))
  376. return -EIO;
  377. else if (state == PCI_D2 && !(pmc & PCI_PM_CAP_D2))
  378. return -EIO;
  379. pci_read_config_word(dev, pm + PCI_PM_CTRL, &pmcsr);
  380. /* If we're (effectively) in D3, force entire word to 0.
  381. * This doesn't affect PME_Status, disables PME_En, and
  382. * sets PowerState to 0.
  383. */
  384. switch (dev->current_state) {
  385. case PCI_D0:
  386. case PCI_D1:
  387. case PCI_D2:
  388. pmcsr &= ~PCI_PM_CTRL_STATE_MASK;
  389. pmcsr |= state;
  390. break;
  391. case PCI_UNKNOWN: /* Boot-up */
  392. if ((pmcsr & PCI_PM_CTRL_STATE_MASK) == PCI_D3hot
  393. && !(pmcsr & PCI_PM_CTRL_NO_SOFT_RESET))
  394. need_restore = 1;
  395. /* Fall-through: force to D0 */
  396. default:
  397. pmcsr = 0;
  398. break;
  399. }
  400. /* enter specified state */
  401. pci_write_config_word(dev, pm + PCI_PM_CTRL, pmcsr);
  402. /* Mandatory power management transition delays */
  403. /* see PCI PM 1.1 5.6.1 table 18 */
  404. if (state == PCI_D3hot || dev->current_state == PCI_D3hot)
  405. msleep(pci_pm_d3_delay);
  406. else if (state == PCI_D2 || dev->current_state == PCI_D2)
  407. udelay(200);
  408. /*
  409. * Give firmware a chance to be called, such as ACPI _PRx, _PSx
  410. * Firmware method after native method ?
  411. */
  412. if (platform_pci_set_power_state)
  413. platform_pci_set_power_state(dev, state);
  414. dev->current_state = state;
  415. /* According to section 5.4.1 of the "PCI BUS POWER MANAGEMENT
  416. * INTERFACE SPECIFICATION, REV. 1.2", a device transitioning
  417. * from D3hot to D0 _may_ perform an internal reset, thereby
  418. * going to "D0 Uninitialized" rather than "D0 Initialized".
  419. * For example, at least some versions of the 3c905B and the
  420. * 3c556B exhibit this behaviour.
  421. *
  422. * At least some laptop BIOSen (e.g. the Thinkpad T21) leave
  423. * devices in a D3hot state at boot. Consequently, we need to
  424. * restore at least the BARs so that the device will be
  425. * accessible to its driver.
  426. */
  427. if (need_restore)
  428. pci_restore_bars(dev);
  429. return 0;
  430. }
  431. int (*platform_pci_choose_state)(struct pci_dev *dev, pm_message_t state);
  432. /**
  433. * pci_choose_state - Choose the power state of a PCI device
  434. * @dev: PCI device to be suspended
  435. * @state: target sleep state for the whole system. This is the value
  436. * that is passed to suspend() function.
  437. *
  438. * Returns PCI power state suitable for given device and given system
  439. * message.
  440. */
  441. pci_power_t pci_choose_state(struct pci_dev *dev, pm_message_t state)
  442. {
  443. int ret;
  444. if (!pci_find_capability(dev, PCI_CAP_ID_PM))
  445. return PCI_D0;
  446. if (platform_pci_choose_state) {
  447. ret = platform_pci_choose_state(dev, state);
  448. if (ret >= 0)
  449. state.event = ret;
  450. }
  451. switch (state.event) {
  452. case PM_EVENT_ON:
  453. return PCI_D0;
  454. case PM_EVENT_FREEZE:
  455. case PM_EVENT_PRETHAW:
  456. /* REVISIT both freeze and pre-thaw "should" use D0 */
  457. case PM_EVENT_SUSPEND:
  458. return PCI_D3hot;
  459. default:
  460. printk("Unrecognized suspend event %d\n", state.event);
  461. BUG();
  462. }
  463. return PCI_D0;
  464. }
  465. EXPORT_SYMBOL(pci_choose_state);
  466. static int pci_save_pcie_state(struct pci_dev *dev)
  467. {
  468. int pos, i = 0;
  469. struct pci_cap_saved_state *save_state;
  470. u16 *cap;
  471. pos = pci_find_capability(dev, PCI_CAP_ID_EXP);
  472. if (pos <= 0)
  473. return 0;
  474. save_state = kzalloc(sizeof(*save_state) + sizeof(u16) * 4, GFP_KERNEL);
  475. if (!save_state) {
  476. dev_err(&dev->dev, "Out of memory in pci_save_pcie_state\n");
  477. return -ENOMEM;
  478. }
  479. cap = (u16 *)&save_state->data[0];
  480. pci_read_config_word(dev, pos + PCI_EXP_DEVCTL, &cap[i++]);
  481. pci_read_config_word(dev, pos + PCI_EXP_LNKCTL, &cap[i++]);
  482. pci_read_config_word(dev, pos + PCI_EXP_SLTCTL, &cap[i++]);
  483. pci_read_config_word(dev, pos + PCI_EXP_RTCTL, &cap[i++]);
  484. pci_add_saved_cap(dev, save_state);
  485. return 0;
  486. }
  487. static void pci_restore_pcie_state(struct pci_dev *dev)
  488. {
  489. int i = 0, pos;
  490. struct pci_cap_saved_state *save_state;
  491. u16 *cap;
  492. save_state = pci_find_saved_cap(dev, PCI_CAP_ID_EXP);
  493. pos = pci_find_capability(dev, PCI_CAP_ID_EXP);
  494. if (!save_state || pos <= 0)
  495. return;
  496. cap = (u16 *)&save_state->data[0];
  497. pci_write_config_word(dev, pos + PCI_EXP_DEVCTL, cap[i++]);
  498. pci_write_config_word(dev, pos + PCI_EXP_LNKCTL, cap[i++]);
  499. pci_write_config_word(dev, pos + PCI_EXP_SLTCTL, cap[i++]);
  500. pci_write_config_word(dev, pos + PCI_EXP_RTCTL, cap[i++]);
  501. pci_remove_saved_cap(save_state);
  502. kfree(save_state);
  503. }
  504. static int pci_save_pcix_state(struct pci_dev *dev)
  505. {
  506. int pos, i = 0;
  507. struct pci_cap_saved_state *save_state;
  508. u16 *cap;
  509. pos = pci_find_capability(dev, PCI_CAP_ID_PCIX);
  510. if (pos <= 0)
  511. return 0;
  512. save_state = kzalloc(sizeof(*save_state) + sizeof(u16), GFP_KERNEL);
  513. if (!save_state) {
  514. dev_err(&dev->dev, "Out of memory in pci_save_pcie_state\n");
  515. return -ENOMEM;
  516. }
  517. cap = (u16 *)&save_state->data[0];
  518. pci_read_config_word(dev, pos + PCI_X_CMD, &cap[i++]);
  519. pci_add_saved_cap(dev, save_state);
  520. return 0;
  521. }
  522. static void pci_restore_pcix_state(struct pci_dev *dev)
  523. {
  524. int i = 0, pos;
  525. struct pci_cap_saved_state *save_state;
  526. u16 *cap;
  527. save_state = pci_find_saved_cap(dev, PCI_CAP_ID_PCIX);
  528. pos = pci_find_capability(dev, PCI_CAP_ID_PCIX);
  529. if (!save_state || pos <= 0)
  530. return;
  531. cap = (u16 *)&save_state->data[0];
  532. pci_write_config_word(dev, pos + PCI_X_CMD, cap[i++]);
  533. pci_remove_saved_cap(save_state);
  534. kfree(save_state);
  535. }
  536. /**
  537. * pci_save_state - save the PCI configuration space of a device before suspending
  538. * @dev: - PCI device that we're dealing with
  539. */
  540. int
  541. pci_save_state(struct pci_dev *dev)
  542. {
  543. int i;
  544. /* XXX: 100% dword access ok here? */
  545. for (i = 0; i < 16; i++)
  546. pci_read_config_dword(dev, i * 4,&dev->saved_config_space[i]);
  547. if ((i = pci_save_msi_state(dev)) != 0)
  548. return i;
  549. if ((i = pci_save_msix_state(dev)) != 0)
  550. return i;
  551. if ((i = pci_save_pcie_state(dev)) != 0)
  552. return i;
  553. if ((i = pci_save_pcix_state(dev)) != 0)
  554. return i;
  555. return 0;
  556. }
  557. /**
  558. * pci_restore_state - Restore the saved state of a PCI device
  559. * @dev: - PCI device that we're dealing with
  560. */
  561. int
  562. pci_restore_state(struct pci_dev *dev)
  563. {
  564. int i;
  565. int val;
  566. /* PCI Express register must be restored first */
  567. pci_restore_pcie_state(dev);
  568. /*
  569. * The Base Address register should be programmed before the command
  570. * register(s)
  571. */
  572. for (i = 15; i >= 0; i--) {
  573. pci_read_config_dword(dev, i * 4, &val);
  574. if (val != dev->saved_config_space[i]) {
  575. printk(KERN_DEBUG "PM: Writing back config space on "
  576. "device %s at offset %x (was %x, writing %x)\n",
  577. pci_name(dev), i,
  578. val, (int)dev->saved_config_space[i]);
  579. pci_write_config_dword(dev,i * 4,
  580. dev->saved_config_space[i]);
  581. }
  582. }
  583. pci_restore_pcix_state(dev);
  584. pci_restore_msi_state(dev);
  585. pci_restore_msix_state(dev);
  586. return 0;
  587. }
  588. static int do_pci_enable_device(struct pci_dev *dev, int bars)
  589. {
  590. int err;
  591. err = pci_set_power_state(dev, PCI_D0);
  592. if (err < 0 && err != -EIO)
  593. return err;
  594. err = pcibios_enable_device(dev, bars);
  595. if (err < 0)
  596. return err;
  597. pci_fixup_device(pci_fixup_enable, dev);
  598. return 0;
  599. }
  600. /**
  601. * __pci_reenable_device - Resume abandoned device
  602. * @dev: PCI device to be resumed
  603. *
  604. * Note this function is a backend of pci_default_resume and is not supposed
  605. * to be called by normal code, write proper resume handler and use it instead.
  606. */
  607. int
  608. __pci_reenable_device(struct pci_dev *dev)
  609. {
  610. if (atomic_read(&dev->enable_cnt))
  611. return do_pci_enable_device(dev, (1 << PCI_NUM_RESOURCES) - 1);
  612. return 0;
  613. }
  614. /**
  615. * pci_enable_device_bars - Initialize some of a device for use
  616. * @dev: PCI device to be initialized
  617. * @bars: bitmask of BAR's that must be configured
  618. *
  619. * Initialize device before it's used by a driver. Ask low-level code
  620. * to enable selected I/O and memory resources. Wake up the device if it
  621. * was suspended. Beware, this function can fail.
  622. */
  623. int
  624. pci_enable_device_bars(struct pci_dev *dev, int bars)
  625. {
  626. int err;
  627. if (atomic_add_return(1, &dev->enable_cnt) > 1)
  628. return 0; /* already enabled */
  629. err = do_pci_enable_device(dev, bars);
  630. if (err < 0)
  631. atomic_dec(&dev->enable_cnt);
  632. return err;
  633. }
  634. /**
  635. * pci_enable_device - Initialize device before it's used by a driver.
  636. * @dev: PCI device to be initialized
  637. *
  638. * Initialize device before it's used by a driver. Ask low-level code
  639. * to enable I/O and memory. Wake up the device if it was suspended.
  640. * Beware, this function can fail.
  641. *
  642. * Note we don't actually enable the device many times if we call
  643. * this function repeatedly (we just increment the count).
  644. */
  645. int pci_enable_device(struct pci_dev *dev)
  646. {
  647. return pci_enable_device_bars(dev, (1 << PCI_NUM_RESOURCES) - 1);
  648. }
  649. /**
  650. * pcibios_disable_device - disable arch specific PCI resources for device dev
  651. * @dev: the PCI device to disable
  652. *
  653. * Disables architecture specific PCI resources for the device. This
  654. * is the default implementation. Architecture implementations can
  655. * override this.
  656. */
  657. void __attribute__ ((weak)) pcibios_disable_device (struct pci_dev *dev) {}
  658. /**
  659. * pci_disable_device - Disable PCI device after use
  660. * @dev: PCI device to be disabled
  661. *
  662. * Signal to the system that the PCI device is not in use by the system
  663. * anymore. This only involves disabling PCI bus-mastering, if active.
  664. *
  665. * Note we don't actually disable the device until all callers of
  666. * pci_device_enable() have called pci_device_disable().
  667. */
  668. void
  669. pci_disable_device(struct pci_dev *dev)
  670. {
  671. u16 pci_command;
  672. if (atomic_sub_return(1, &dev->enable_cnt) != 0)
  673. return;
  674. if (dev->msi_enabled)
  675. disable_msi_mode(dev, pci_find_capability(dev, PCI_CAP_ID_MSI),
  676. PCI_CAP_ID_MSI);
  677. if (dev->msix_enabled)
  678. disable_msi_mode(dev, pci_find_capability(dev, PCI_CAP_ID_MSI),
  679. PCI_CAP_ID_MSIX);
  680. pci_read_config_word(dev, PCI_COMMAND, &pci_command);
  681. if (pci_command & PCI_COMMAND_MASTER) {
  682. pci_command &= ~PCI_COMMAND_MASTER;
  683. pci_write_config_word(dev, PCI_COMMAND, pci_command);
  684. }
  685. dev->is_busmaster = 0;
  686. pcibios_disable_device(dev);
  687. }
  688. /**
  689. * pci_enable_wake - enable device to generate PME# when suspended
  690. * @dev: - PCI device to operate on
  691. * @state: - Current state of device.
  692. * @enable: - Flag to enable or disable generation
  693. *
  694. * Set the bits in the device's PM Capabilities to generate PME# when
  695. * the system is suspended.
  696. *
  697. * -EIO is returned if device doesn't have PM Capabilities.
  698. * -EINVAL is returned if device supports it, but can't generate wake events.
  699. * 0 if operation is successful.
  700. *
  701. */
  702. int pci_enable_wake(struct pci_dev *dev, pci_power_t state, int enable)
  703. {
  704. int pm;
  705. u16 value;
  706. /* find PCI PM capability in list */
  707. pm = pci_find_capability(dev, PCI_CAP_ID_PM);
  708. /* If device doesn't support PM Capabilities, but request is to disable
  709. * wake events, it's a nop; otherwise fail */
  710. if (!pm)
  711. return enable ? -EIO : 0;
  712. /* Check device's ability to generate PME# */
  713. pci_read_config_word(dev,pm+PCI_PM_PMC,&value);
  714. value &= PCI_PM_CAP_PME_MASK;
  715. value >>= ffs(PCI_PM_CAP_PME_MASK) - 1; /* First bit of mask */
  716. /* Check if it can generate PME# from requested state. */
  717. if (!value || !(value & (1 << state)))
  718. return enable ? -EINVAL : 0;
  719. pci_read_config_word(dev, pm + PCI_PM_CTRL, &value);
  720. /* Clear PME_Status by writing 1 to it and enable PME# */
  721. value |= PCI_PM_CTRL_PME_STATUS | PCI_PM_CTRL_PME_ENABLE;
  722. if (!enable)
  723. value &= ~PCI_PM_CTRL_PME_ENABLE;
  724. pci_write_config_word(dev, pm + PCI_PM_CTRL, value);
  725. return 0;
  726. }
  727. int
  728. pci_get_interrupt_pin(struct pci_dev *dev, struct pci_dev **bridge)
  729. {
  730. u8 pin;
  731. pin = dev->pin;
  732. if (!pin)
  733. return -1;
  734. pin--;
  735. while (dev->bus->self) {
  736. pin = (pin + PCI_SLOT(dev->devfn)) % 4;
  737. dev = dev->bus->self;
  738. }
  739. *bridge = dev;
  740. return pin;
  741. }
  742. /**
  743. * pci_release_region - Release a PCI bar
  744. * @pdev: PCI device whose resources were previously reserved by pci_request_region
  745. * @bar: BAR to release
  746. *
  747. * Releases the PCI I/O and memory resources previously reserved by a
  748. * successful call to pci_request_region. Call this function only
  749. * after all use of the PCI regions has ceased.
  750. */
  751. void pci_release_region(struct pci_dev *pdev, int bar)
  752. {
  753. if (pci_resource_len(pdev, bar) == 0)
  754. return;
  755. if (pci_resource_flags(pdev, bar) & IORESOURCE_IO)
  756. release_region(pci_resource_start(pdev, bar),
  757. pci_resource_len(pdev, bar));
  758. else if (pci_resource_flags(pdev, bar) & IORESOURCE_MEM)
  759. release_mem_region(pci_resource_start(pdev, bar),
  760. pci_resource_len(pdev, bar));
  761. }
  762. /**
  763. * pci_request_region - Reserved PCI I/O and memory resource
  764. * @pdev: PCI device whose resources are to be reserved
  765. * @bar: BAR to be reserved
  766. * @res_name: Name to be associated with resource.
  767. *
  768. * Mark the PCI region associated with PCI device @pdev BR @bar as
  769. * being reserved by owner @res_name. Do not access any
  770. * address inside the PCI regions unless this call returns
  771. * successfully.
  772. *
  773. * Returns 0 on success, or %EBUSY on error. A warning
  774. * message is also printed on failure.
  775. */
  776. int pci_request_region(struct pci_dev *pdev, int bar, const char *res_name)
  777. {
  778. if (pci_resource_len(pdev, bar) == 0)
  779. return 0;
  780. if (pci_resource_flags(pdev, bar) & IORESOURCE_IO) {
  781. if (!request_region(pci_resource_start(pdev, bar),
  782. pci_resource_len(pdev, bar), res_name))
  783. goto err_out;
  784. }
  785. else if (pci_resource_flags(pdev, bar) & IORESOURCE_MEM) {
  786. if (!request_mem_region(pci_resource_start(pdev, bar),
  787. pci_resource_len(pdev, bar), res_name))
  788. goto err_out;
  789. }
  790. return 0;
  791. err_out:
  792. printk (KERN_WARNING "PCI: Unable to reserve %s region #%d:%llx@%llx "
  793. "for device %s\n",
  794. pci_resource_flags(pdev, bar) & IORESOURCE_IO ? "I/O" : "mem",
  795. bar + 1, /* PCI BAR # */
  796. (unsigned long long)pci_resource_len(pdev, bar),
  797. (unsigned long long)pci_resource_start(pdev, bar),
  798. pci_name(pdev));
  799. return -EBUSY;
  800. }
  801. /**
  802. * pci_release_selected_regions - Release selected PCI I/O and memory resources
  803. * @pdev: PCI device whose resources were previously reserved
  804. * @bars: Bitmask of BARs to be released
  805. *
  806. * Release selected PCI I/O and memory resources previously reserved.
  807. * Call this function only after all use of the PCI regions has ceased.
  808. */
  809. void pci_release_selected_regions(struct pci_dev *pdev, int bars)
  810. {
  811. int i;
  812. for (i = 0; i < 6; i++)
  813. if (bars & (1 << i))
  814. pci_release_region(pdev, i);
  815. }
  816. /**
  817. * pci_request_selected_regions - Reserve selected PCI I/O and memory resources
  818. * @pdev: PCI device whose resources are to be reserved
  819. * @bars: Bitmask of BARs to be requested
  820. * @res_name: Name to be associated with resource
  821. */
  822. int pci_request_selected_regions(struct pci_dev *pdev, int bars,
  823. const char *res_name)
  824. {
  825. int i;
  826. for (i = 0; i < 6; i++)
  827. if (bars & (1 << i))
  828. if(pci_request_region(pdev, i, res_name))
  829. goto err_out;
  830. return 0;
  831. err_out:
  832. while(--i >= 0)
  833. if (bars & (1 << i))
  834. pci_release_region(pdev, i);
  835. return -EBUSY;
  836. }
  837. /**
  838. * pci_release_regions - Release reserved PCI I/O and memory resources
  839. * @pdev: PCI device whose resources were previously reserved by pci_request_regions
  840. *
  841. * Releases all PCI I/O and memory resources previously reserved by a
  842. * successful call to pci_request_regions. Call this function only
  843. * after all use of the PCI regions has ceased.
  844. */
  845. void pci_release_regions(struct pci_dev *pdev)
  846. {
  847. pci_release_selected_regions(pdev, (1 << 6) - 1);
  848. }
  849. /**
  850. * pci_request_regions - Reserved PCI I/O and memory resources
  851. * @pdev: PCI device whose resources are to be reserved
  852. * @res_name: Name to be associated with resource.
  853. *
  854. * Mark all PCI regions associated with PCI device @pdev as
  855. * being reserved by owner @res_name. Do not access any
  856. * address inside the PCI regions unless this call returns
  857. * successfully.
  858. *
  859. * Returns 0 on success, or %EBUSY on error. A warning
  860. * message is also printed on failure.
  861. */
  862. int pci_request_regions(struct pci_dev *pdev, const char *res_name)
  863. {
  864. return pci_request_selected_regions(pdev, ((1 << 6) - 1), res_name);
  865. }
  866. /**
  867. * pci_set_master - enables bus-mastering for device dev
  868. * @dev: the PCI device to enable
  869. *
  870. * Enables bus-mastering on the device and calls pcibios_set_master()
  871. * to do the needed arch specific settings.
  872. */
  873. void
  874. pci_set_master(struct pci_dev *dev)
  875. {
  876. u16 cmd;
  877. pci_read_config_word(dev, PCI_COMMAND, &cmd);
  878. if (! (cmd & PCI_COMMAND_MASTER)) {
  879. pr_debug("PCI: Enabling bus mastering for device %s\n", pci_name(dev));
  880. cmd |= PCI_COMMAND_MASTER;
  881. pci_write_config_word(dev, PCI_COMMAND, cmd);
  882. }
  883. dev->is_busmaster = 1;
  884. pcibios_set_master(dev);
  885. }
  886. #ifdef PCI_DISABLE_MWI
  887. int pci_set_mwi(struct pci_dev *dev)
  888. {
  889. return 0;
  890. }
  891. void pci_clear_mwi(struct pci_dev *dev)
  892. {
  893. }
  894. #else
  895. #ifndef PCI_CACHE_LINE_BYTES
  896. #define PCI_CACHE_LINE_BYTES L1_CACHE_BYTES
  897. #endif
  898. /* This can be overridden by arch code. */
  899. /* Don't forget this is measured in 32-bit words, not bytes */
  900. u8 pci_cache_line_size = PCI_CACHE_LINE_BYTES / 4;
  901. /**
  902. * pci_set_cacheline_size - ensure the CACHE_LINE_SIZE register is programmed
  903. * @dev: the PCI device for which MWI is to be enabled
  904. *
  905. * Helper function for pci_set_mwi.
  906. * Originally copied from drivers/net/acenic.c.
  907. * Copyright 1998-2001 by Jes Sorensen, <jes@trained-monkey.org>.
  908. *
  909. * RETURNS: An appropriate -ERRNO error value on error, or zero for success.
  910. */
  911. static int
  912. pci_set_cacheline_size(struct pci_dev *dev)
  913. {
  914. u8 cacheline_size;
  915. if (!pci_cache_line_size)
  916. return -EINVAL; /* The system doesn't support MWI. */
  917. /* Validate current setting: the PCI_CACHE_LINE_SIZE must be
  918. equal to or multiple of the right value. */
  919. pci_read_config_byte(dev, PCI_CACHE_LINE_SIZE, &cacheline_size);
  920. if (cacheline_size >= pci_cache_line_size &&
  921. (cacheline_size % pci_cache_line_size) == 0)
  922. return 0;
  923. /* Write the correct value. */
  924. pci_write_config_byte(dev, PCI_CACHE_LINE_SIZE, pci_cache_line_size);
  925. /* Read it back. */
  926. pci_read_config_byte(dev, PCI_CACHE_LINE_SIZE, &cacheline_size);
  927. if (cacheline_size == pci_cache_line_size)
  928. return 0;
  929. printk(KERN_DEBUG "PCI: cache line size of %d is not supported "
  930. "by device %s\n", pci_cache_line_size << 2, pci_name(dev));
  931. return -EINVAL;
  932. }
  933. /**
  934. * pci_set_mwi - enables memory-write-invalidate PCI transaction
  935. * @dev: the PCI device for which MWI is enabled
  936. *
  937. * Enables the Memory-Write-Invalidate transaction in %PCI_COMMAND,
  938. * and then calls @pcibios_set_mwi to do the needed arch specific
  939. * operations or a generic mwi-prep function.
  940. *
  941. * RETURNS: An appropriate -ERRNO error value on error, or zero for success.
  942. */
  943. int
  944. pci_set_mwi(struct pci_dev *dev)
  945. {
  946. int rc;
  947. u16 cmd;
  948. rc = pci_set_cacheline_size(dev);
  949. if (rc)
  950. return rc;
  951. pci_read_config_word(dev, PCI_COMMAND, &cmd);
  952. if (! (cmd & PCI_COMMAND_INVALIDATE)) {
  953. pr_debug("PCI: Enabling Mem-Wr-Inval for device %s\n", pci_name(dev));
  954. cmd |= PCI_COMMAND_INVALIDATE;
  955. pci_write_config_word(dev, PCI_COMMAND, cmd);
  956. }
  957. return 0;
  958. }
  959. /**
  960. * pci_clear_mwi - disables Memory-Write-Invalidate for device dev
  961. * @dev: the PCI device to disable
  962. *
  963. * Disables PCI Memory-Write-Invalidate transaction on the device
  964. */
  965. void
  966. pci_clear_mwi(struct pci_dev *dev)
  967. {
  968. u16 cmd;
  969. pci_read_config_word(dev, PCI_COMMAND, &cmd);
  970. if (cmd & PCI_COMMAND_INVALIDATE) {
  971. cmd &= ~PCI_COMMAND_INVALIDATE;
  972. pci_write_config_word(dev, PCI_COMMAND, cmd);
  973. }
  974. }
  975. #endif /* ! PCI_DISABLE_MWI */
  976. /**
  977. * pci_intx - enables/disables PCI INTx for device dev
  978. * @pdev: the PCI device to operate on
  979. * @enable: boolean: whether to enable or disable PCI INTx
  980. *
  981. * Enables/disables PCI INTx for device dev
  982. */
  983. void
  984. pci_intx(struct pci_dev *pdev, int enable)
  985. {
  986. u16 pci_command, new;
  987. pci_read_config_word(pdev, PCI_COMMAND, &pci_command);
  988. if (enable) {
  989. new = pci_command & ~PCI_COMMAND_INTX_DISABLE;
  990. } else {
  991. new = pci_command | PCI_COMMAND_INTX_DISABLE;
  992. }
  993. if (new != pci_command) {
  994. pci_write_config_word(pdev, PCI_COMMAND, new);
  995. }
  996. }
  997. #ifndef HAVE_ARCH_PCI_SET_DMA_MASK
  998. /*
  999. * These can be overridden by arch-specific implementations
  1000. */
  1001. int
  1002. pci_set_dma_mask(struct pci_dev *dev, u64 mask)
  1003. {
  1004. if (!pci_dma_supported(dev, mask))
  1005. return -EIO;
  1006. dev->dma_mask = mask;
  1007. return 0;
  1008. }
  1009. int
  1010. pci_set_consistent_dma_mask(struct pci_dev *dev, u64 mask)
  1011. {
  1012. if (!pci_dma_supported(dev, mask))
  1013. return -EIO;
  1014. dev->dev.coherent_dma_mask = mask;
  1015. return 0;
  1016. }
  1017. #endif
  1018. /**
  1019. * pci_select_bars - Make BAR mask from the type of resource
  1020. * @pdev: the PCI device for which BAR mask is made
  1021. * @flags: resource type mask to be selected
  1022. *
  1023. * This helper routine makes bar mask from the type of resource.
  1024. */
  1025. int pci_select_bars(struct pci_dev *dev, unsigned long flags)
  1026. {
  1027. int i, bars = 0;
  1028. for (i = 0; i < PCI_NUM_RESOURCES; i++)
  1029. if (pci_resource_flags(dev, i) & flags)
  1030. bars |= (1 << i);
  1031. return bars;
  1032. }
  1033. static int __devinit pci_init(void)
  1034. {
  1035. struct pci_dev *dev = NULL;
  1036. while ((dev = pci_get_device(PCI_ANY_ID, PCI_ANY_ID, dev)) != NULL) {
  1037. pci_fixup_device(pci_fixup_final, dev);
  1038. }
  1039. return 0;
  1040. }
  1041. static int __devinit pci_setup(char *str)
  1042. {
  1043. while (str) {
  1044. char *k = strchr(str, ',');
  1045. if (k)
  1046. *k++ = 0;
  1047. if (*str && (str = pcibios_setup(str)) && *str) {
  1048. if (!strcmp(str, "nomsi")) {
  1049. pci_no_msi();
  1050. } else {
  1051. printk(KERN_ERR "PCI: Unknown option `%s'\n",
  1052. str);
  1053. }
  1054. }
  1055. str = k;
  1056. }
  1057. return 0;
  1058. }
  1059. early_param("pci", pci_setup);
  1060. device_initcall(pci_init);
  1061. EXPORT_SYMBOL_GPL(pci_restore_bars);
  1062. EXPORT_SYMBOL(pci_enable_device_bars);
  1063. EXPORT_SYMBOL(pci_enable_device);
  1064. EXPORT_SYMBOL(pci_disable_device);
  1065. EXPORT_SYMBOL(pci_find_capability);
  1066. EXPORT_SYMBOL(pci_bus_find_capability);
  1067. EXPORT_SYMBOL(pci_release_regions);
  1068. EXPORT_SYMBOL(pci_request_regions);
  1069. EXPORT_SYMBOL(pci_release_region);
  1070. EXPORT_SYMBOL(pci_request_region);
  1071. EXPORT_SYMBOL(pci_release_selected_regions);
  1072. EXPORT_SYMBOL(pci_request_selected_regions);
  1073. EXPORT_SYMBOL(pci_set_master);
  1074. EXPORT_SYMBOL(pci_set_mwi);
  1075. EXPORT_SYMBOL(pci_clear_mwi);
  1076. EXPORT_SYMBOL_GPL(pci_intx);
  1077. EXPORT_SYMBOL(pci_set_dma_mask);
  1078. EXPORT_SYMBOL(pci_set_consistent_dma_mask);
  1079. EXPORT_SYMBOL(pci_assign_resource);
  1080. EXPORT_SYMBOL(pci_find_parent_resource);
  1081. EXPORT_SYMBOL(pci_select_bars);
  1082. EXPORT_SYMBOL(pci_set_power_state);
  1083. EXPORT_SYMBOL(pci_save_state);
  1084. EXPORT_SYMBOL(pci_restore_state);
  1085. EXPORT_SYMBOL(pci_enable_wake);