setup-pci.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666
  1. /*
  2. * Copyright (C) 1998-2000 Andre Hedrick <andre@linux-ide.org>
  3. * Copyright (C) 1995-1998 Mark Lord
  4. * Copyright (C) 2007-2009 Bartlomiej Zolnierkiewicz
  5. *
  6. * May be copied or modified under the terms of the GNU General Public License
  7. */
  8. #include <linux/types.h>
  9. #include <linux/kernel.h>
  10. #include <linux/export.h>
  11. #include <linux/pci.h>
  12. #include <linux/init.h>
  13. #include <linux/interrupt.h>
  14. #include <linux/ide.h>
  15. #include <linux/dma-mapping.h>
  16. #include <asm/io.h>
  17. /**
  18. * ide_setup_pci_baseregs - place a PCI IDE controller native
  19. * @dev: PCI device of interface to switch native
  20. * @name: Name of interface
  21. *
  22. * We attempt to place the PCI interface into PCI native mode. If
  23. * we succeed the BARs are ok and the controller is in PCI mode.
  24. * Returns 0 on success or an errno code.
  25. *
  26. * FIXME: if we program the interface and then fail to set the BARS
  27. * we don't switch it back to legacy mode. Do we actually care ??
  28. */
  29. static int ide_setup_pci_baseregs(struct pci_dev *dev, const char *name)
  30. {
  31. u8 progif = 0;
  32. /*
  33. * Place both IDE interfaces into PCI "native" mode:
  34. */
  35. if (pci_read_config_byte(dev, PCI_CLASS_PROG, &progif) ||
  36. (progif & 5) != 5) {
  37. if ((progif & 0xa) != 0xa) {
  38. printk(KERN_INFO "%s %s: device not capable of full "
  39. "native PCI mode\n", name, pci_name(dev));
  40. return -EOPNOTSUPP;
  41. }
  42. printk(KERN_INFO "%s %s: placing both ports into native PCI "
  43. "mode\n", name, pci_name(dev));
  44. (void) pci_write_config_byte(dev, PCI_CLASS_PROG, progif|5);
  45. if (pci_read_config_byte(dev, PCI_CLASS_PROG, &progif) ||
  46. (progif & 5) != 5) {
  47. printk(KERN_ERR "%s %s: rewrite of PROGIF failed, "
  48. "wanted 0x%04x, got 0x%04x\n",
  49. name, pci_name(dev), progif | 5, progif);
  50. return -EOPNOTSUPP;
  51. }
  52. }
  53. return 0;
  54. }
  55. #ifdef CONFIG_BLK_DEV_IDEDMA_PCI
  56. static int ide_pci_clear_simplex(unsigned long dma_base, const char *name)
  57. {
  58. u8 dma_stat = inb(dma_base + 2);
  59. outb(dma_stat & 0x60, dma_base + 2);
  60. dma_stat = inb(dma_base + 2);
  61. return (dma_stat & 0x80) ? 1 : 0;
  62. }
  63. /**
  64. * ide_pci_dma_base - setup BMIBA
  65. * @hwif: IDE interface
  66. * @d: IDE port info
  67. *
  68. * Fetch the DMA Bus-Master-I/O-Base-Address (BMIBA) from PCI space.
  69. */
  70. unsigned long ide_pci_dma_base(ide_hwif_t *hwif, const struct ide_port_info *d)
  71. {
  72. struct pci_dev *dev = to_pci_dev(hwif->dev);
  73. unsigned long dma_base = 0;
  74. if (hwif->host_flags & IDE_HFLAG_MMIO)
  75. return hwif->dma_base;
  76. if (hwif->mate && hwif->mate->dma_base) {
  77. dma_base = hwif->mate->dma_base - (hwif->channel ? 0 : 8);
  78. } else {
  79. u8 baridx = (d->host_flags & IDE_HFLAG_CS5520) ? 2 : 4;
  80. dma_base = pci_resource_start(dev, baridx);
  81. if (dma_base == 0) {
  82. printk(KERN_ERR "%s %s: DMA base is invalid\n",
  83. d->name, pci_name(dev));
  84. return 0;
  85. }
  86. }
  87. if (hwif->channel)
  88. dma_base += 8;
  89. return dma_base;
  90. }
  91. EXPORT_SYMBOL_GPL(ide_pci_dma_base);
  92. int ide_pci_check_simplex(ide_hwif_t *hwif, const struct ide_port_info *d)
  93. {
  94. struct pci_dev *dev = to_pci_dev(hwif->dev);
  95. u8 dma_stat;
  96. if (d->host_flags & (IDE_HFLAG_MMIO | IDE_HFLAG_CS5520))
  97. goto out;
  98. if (d->host_flags & IDE_HFLAG_CLEAR_SIMPLEX) {
  99. if (ide_pci_clear_simplex(hwif->dma_base, d->name))
  100. printk(KERN_INFO "%s %s: simplex device: DMA forced\n",
  101. d->name, pci_name(dev));
  102. goto out;
  103. }
  104. /*
  105. * If the device claims "simplex" DMA, this means that only one of
  106. * the two interfaces can be trusted with DMA at any point in time
  107. * (so we should enable DMA only on one of the two interfaces).
  108. *
  109. * FIXME: At this point we haven't probed the drives so we can't make
  110. * the appropriate decision. Really we should defer this problem until
  111. * we tune the drive then try to grab DMA ownership if we want to be
  112. * the DMA end. This has to be become dynamic to handle hot-plug.
  113. */
  114. dma_stat = hwif->dma_ops->dma_sff_read_status(hwif);
  115. if ((dma_stat & 0x80) && hwif->mate && hwif->mate->dma_base) {
  116. printk(KERN_INFO "%s %s: simplex device: DMA disabled\n",
  117. d->name, pci_name(dev));
  118. return -1;
  119. }
  120. out:
  121. return 0;
  122. }
  123. EXPORT_SYMBOL_GPL(ide_pci_check_simplex);
  124. /*
  125. * Set up BM-DMA capability (PnP BIOS should have done this)
  126. */
  127. int ide_pci_set_master(struct pci_dev *dev, const char *name)
  128. {
  129. u16 pcicmd;
  130. pci_read_config_word(dev, PCI_COMMAND, &pcicmd);
  131. if ((pcicmd & PCI_COMMAND_MASTER) == 0) {
  132. pci_set_master(dev);
  133. if (pci_read_config_word(dev, PCI_COMMAND, &pcicmd) ||
  134. (pcicmd & PCI_COMMAND_MASTER) == 0) {
  135. printk(KERN_ERR "%s %s: error updating PCICMD\n",
  136. name, pci_name(dev));
  137. return -EIO;
  138. }
  139. }
  140. return 0;
  141. }
  142. EXPORT_SYMBOL_GPL(ide_pci_set_master);
  143. #endif /* CONFIG_BLK_DEV_IDEDMA_PCI */
  144. void ide_setup_pci_noise(struct pci_dev *dev, const struct ide_port_info *d)
  145. {
  146. printk(KERN_INFO "%s %s: IDE controller (0x%04x:0x%04x rev 0x%02x)\n",
  147. d->name, pci_name(dev),
  148. dev->vendor, dev->device, dev->revision);
  149. }
  150. EXPORT_SYMBOL_GPL(ide_setup_pci_noise);
  151. /**
  152. * ide_pci_enable - do PCI enables
  153. * @dev: PCI device
  154. * @d: IDE port info
  155. *
  156. * Enable the IDE PCI device. We attempt to enable the device in full
  157. * but if that fails then we only need IO space. The PCI code should
  158. * have setup the proper resources for us already for controllers in
  159. * legacy mode.
  160. *
  161. * Returns zero on success or an error code
  162. */
  163. static int ide_pci_enable(struct pci_dev *dev, const struct ide_port_info *d)
  164. {
  165. int ret, bars;
  166. if (pci_enable_device(dev)) {
  167. ret = pci_enable_device_io(dev);
  168. if (ret < 0) {
  169. printk(KERN_WARNING "%s %s: couldn't enable device\n",
  170. d->name, pci_name(dev));
  171. goto out;
  172. }
  173. printk(KERN_WARNING "%s %s: BIOS configuration fixed\n",
  174. d->name, pci_name(dev));
  175. }
  176. /*
  177. * assume all devices can do 32-bit DMA for now, we can add
  178. * a DMA mask field to the struct ide_port_info if we need it
  179. * (or let lower level driver set the DMA mask)
  180. */
  181. ret = dma_set_mask(&dev->dev, DMA_BIT_MASK(32));
  182. if (ret < 0) {
  183. printk(KERN_ERR "%s %s: can't set DMA mask\n",
  184. d->name, pci_name(dev));
  185. goto out;
  186. }
  187. if (d->host_flags & IDE_HFLAG_SINGLE)
  188. bars = (1 << 2) - 1;
  189. else
  190. bars = (1 << 4) - 1;
  191. if ((d->host_flags & IDE_HFLAG_NO_DMA) == 0) {
  192. if (d->host_flags & IDE_HFLAG_CS5520)
  193. bars |= (1 << 2);
  194. else
  195. bars |= (1 << 4);
  196. }
  197. ret = pci_request_selected_regions(dev, bars, d->name);
  198. if (ret < 0)
  199. printk(KERN_ERR "%s %s: can't reserve resources\n",
  200. d->name, pci_name(dev));
  201. out:
  202. return ret;
  203. }
  204. /**
  205. * ide_pci_configure - configure an unconfigured device
  206. * @dev: PCI device
  207. * @d: IDE port info
  208. *
  209. * Enable and configure the PCI device we have been passed.
  210. * Returns zero on success or an error code.
  211. */
  212. static int ide_pci_configure(struct pci_dev *dev, const struct ide_port_info *d)
  213. {
  214. u16 pcicmd = 0;
  215. /*
  216. * PnP BIOS was *supposed* to have setup this device, but we
  217. * can do it ourselves, so long as the BIOS has assigned an IRQ
  218. * (or possibly the device is using a "legacy header" for IRQs).
  219. * Maybe the user deliberately *disabled* the device,
  220. * but we'll eventually ignore it again if no drives respond.
  221. */
  222. if (ide_setup_pci_baseregs(dev, d->name) ||
  223. pci_write_config_word(dev, PCI_COMMAND, pcicmd | PCI_COMMAND_IO)) {
  224. printk(KERN_INFO "%s %s: device disabled (BIOS)\n",
  225. d->name, pci_name(dev));
  226. return -ENODEV;
  227. }
  228. if (pci_read_config_word(dev, PCI_COMMAND, &pcicmd)) {
  229. printk(KERN_ERR "%s %s: error accessing PCI regs\n",
  230. d->name, pci_name(dev));
  231. return -EIO;
  232. }
  233. if (!(pcicmd & PCI_COMMAND_IO)) {
  234. printk(KERN_ERR "%s %s: unable to enable IDE controller\n",
  235. d->name, pci_name(dev));
  236. return -ENXIO;
  237. }
  238. return 0;
  239. }
  240. /**
  241. * ide_pci_check_iomem - check a register is I/O
  242. * @dev: PCI device
  243. * @d: IDE port info
  244. * @bar: BAR number
  245. *
  246. * Checks if a BAR is configured and points to MMIO space. If so,
  247. * return an error code. Otherwise return 0
  248. */
  249. static int ide_pci_check_iomem(struct pci_dev *dev, const struct ide_port_info *d,
  250. int bar)
  251. {
  252. ulong flags = pci_resource_flags(dev, bar);
  253. /* Unconfigured ? */
  254. if (!flags || pci_resource_len(dev, bar) == 0)
  255. return 0;
  256. /* I/O space */
  257. if (flags & IORESOURCE_IO)
  258. return 0;
  259. /* Bad */
  260. return -EINVAL;
  261. }
  262. /**
  263. * ide_hw_configure - configure a struct ide_hw instance
  264. * @dev: PCI device holding interface
  265. * @d: IDE port info
  266. * @port: port number
  267. * @hw: struct ide_hw instance corresponding to this port
  268. *
  269. * Perform the initial set up for the hardware interface structure. This
  270. * is done per interface port rather than per PCI device. There may be
  271. * more than one port per device.
  272. *
  273. * Returns zero on success or an error code.
  274. */
  275. static int ide_hw_configure(struct pci_dev *dev, const struct ide_port_info *d,
  276. unsigned int port, struct ide_hw *hw)
  277. {
  278. unsigned long ctl = 0, base = 0;
  279. if ((d->host_flags & IDE_HFLAG_ISA_PORTS) == 0) {
  280. if (ide_pci_check_iomem(dev, d, 2 * port) ||
  281. ide_pci_check_iomem(dev, d, 2 * port + 1)) {
  282. printk(KERN_ERR "%s %s: I/O baseregs (BIOS) are "
  283. "reported as MEM for port %d!\n",
  284. d->name, pci_name(dev), port);
  285. return -EINVAL;
  286. }
  287. ctl = pci_resource_start(dev, 2*port+1);
  288. base = pci_resource_start(dev, 2*port);
  289. } else {
  290. /* Use default values */
  291. ctl = port ? 0x374 : 0x3f4;
  292. base = port ? 0x170 : 0x1f0;
  293. }
  294. if (!base || !ctl) {
  295. printk(KERN_ERR "%s %s: bad PCI BARs for port %d, skipping\n",
  296. d->name, pci_name(dev), port);
  297. return -EINVAL;
  298. }
  299. memset(hw, 0, sizeof(*hw));
  300. hw->dev = &dev->dev;
  301. ide_std_init_ports(hw, base, ctl | 2);
  302. return 0;
  303. }
  304. #ifdef CONFIG_BLK_DEV_IDEDMA_PCI
  305. /**
  306. * ide_hwif_setup_dma - configure DMA interface
  307. * @hwif: IDE interface
  308. * @d: IDE port info
  309. *
  310. * Set up the DMA base for the interface. Enable the master bits as
  311. * necessary and attempt to bring the device DMA into a ready to use
  312. * state
  313. */
  314. int ide_hwif_setup_dma(ide_hwif_t *hwif, const struct ide_port_info *d)
  315. {
  316. struct pci_dev *dev = to_pci_dev(hwif->dev);
  317. if ((d->host_flags & IDE_HFLAG_NO_AUTODMA) == 0 ||
  318. ((dev->class >> 8) == PCI_CLASS_STORAGE_IDE &&
  319. (dev->class & 0x80))) {
  320. unsigned long base = ide_pci_dma_base(hwif, d);
  321. if (base == 0)
  322. return -1;
  323. hwif->dma_base = base;
  324. if (hwif->dma_ops == NULL)
  325. hwif->dma_ops = &sff_dma_ops;
  326. if (ide_pci_check_simplex(hwif, d) < 0)
  327. return -1;
  328. if (ide_pci_set_master(dev, d->name) < 0)
  329. return -1;
  330. if (hwif->host_flags & IDE_HFLAG_MMIO)
  331. printk(KERN_INFO " %s: MMIO-DMA\n", hwif->name);
  332. else
  333. printk(KERN_INFO " %s: BM-DMA at 0x%04lx-0x%04lx\n",
  334. hwif->name, base, base + 7);
  335. hwif->extra_base = base + (hwif->channel ? 8 : 16);
  336. if (ide_allocate_dma_engine(hwif))
  337. return -1;
  338. }
  339. return 0;
  340. }
  341. #endif /* CONFIG_BLK_DEV_IDEDMA_PCI */
  342. /**
  343. * ide_setup_pci_controller - set up IDE PCI
  344. * @dev: PCI device
  345. * @d: IDE port info
  346. * @noisy: verbose flag
  347. *
  348. * Set up the PCI and controller side of the IDE interface. This brings
  349. * up the PCI side of the device, checks that the device is enabled
  350. * and enables it if need be
  351. */
  352. static int ide_setup_pci_controller(struct pci_dev *dev,
  353. const struct ide_port_info *d, int noisy)
  354. {
  355. int ret;
  356. u16 pcicmd;
  357. if (noisy)
  358. ide_setup_pci_noise(dev, d);
  359. ret = ide_pci_enable(dev, d);
  360. if (ret < 0)
  361. goto out;
  362. ret = pci_read_config_word(dev, PCI_COMMAND, &pcicmd);
  363. if (ret < 0) {
  364. printk(KERN_ERR "%s %s: error accessing PCI regs\n",
  365. d->name, pci_name(dev));
  366. goto out;
  367. }
  368. if (!(pcicmd & PCI_COMMAND_IO)) { /* is device disabled? */
  369. ret = ide_pci_configure(dev, d);
  370. if (ret < 0)
  371. goto out;
  372. printk(KERN_INFO "%s %s: device enabled (Linux)\n",
  373. d->name, pci_name(dev));
  374. }
  375. out:
  376. return ret;
  377. }
  378. /**
  379. * ide_pci_setup_ports - configure ports/devices on PCI IDE
  380. * @dev: PCI device
  381. * @d: IDE port info
  382. * @hw: struct ide_hw instances corresponding to this PCI IDE device
  383. * @hws: struct ide_hw pointers table to update
  384. *
  385. * Scan the interfaces attached to this device and do any
  386. * necessary per port setup. Attach the devices and ask the
  387. * generic DMA layer to do its work for us.
  388. *
  389. * Normally called automaticall from do_ide_pci_setup_device,
  390. * but is also used directly as a helper function by some controllers
  391. * where the chipset setup is not the default PCI IDE one.
  392. */
  393. void ide_pci_setup_ports(struct pci_dev *dev, const struct ide_port_info *d,
  394. struct ide_hw *hw, struct ide_hw **hws)
  395. {
  396. int channels = (d->host_flags & IDE_HFLAG_SINGLE) ? 1 : 2, port;
  397. u8 tmp;
  398. /*
  399. * Set up the IDE ports
  400. */
  401. for (port = 0; port < channels; ++port) {
  402. const struct ide_pci_enablebit *e = &d->enablebits[port];
  403. if (e->reg && (pci_read_config_byte(dev, e->reg, &tmp) ||
  404. (tmp & e->mask) != e->val)) {
  405. printk(KERN_INFO "%s %s: IDE port disabled\n",
  406. d->name, pci_name(dev));
  407. continue; /* port not enabled */
  408. }
  409. if (ide_hw_configure(dev, d, port, hw + port))
  410. continue;
  411. *(hws + port) = hw + port;
  412. }
  413. }
  414. EXPORT_SYMBOL_GPL(ide_pci_setup_ports);
  415. /*
  416. * ide_setup_pci_device() looks at the primary/secondary interfaces
  417. * on a PCI IDE device and, if they are enabled, prepares the IDE driver
  418. * for use with them. This generic code works for most PCI chipsets.
  419. *
  420. * One thing that is not standardized is the location of the
  421. * primary/secondary interface "enable/disable" bits. For chipsets that
  422. * we "know" about, this information is in the struct ide_port_info;
  423. * for all other chipsets, we just assume both interfaces are enabled.
  424. */
  425. static int do_ide_setup_pci_device(struct pci_dev *dev,
  426. const struct ide_port_info *d,
  427. u8 noisy)
  428. {
  429. int pciirq, ret;
  430. /*
  431. * Can we trust the reported IRQ?
  432. */
  433. pciirq = dev->irq;
  434. /*
  435. * This allows offboard ide-pci cards the enable a BIOS,
  436. * verify interrupt settings of split-mirror pci-config
  437. * space, place chipset into init-mode, and/or preserve
  438. * an interrupt if the card is not native ide support.
  439. */
  440. ret = d->init_chipset ? d->init_chipset(dev) : 0;
  441. if (ret < 0)
  442. goto out;
  443. if (ide_pci_is_in_compatibility_mode(dev)) {
  444. if (noisy)
  445. printk(KERN_INFO "%s %s: not 100%% native mode: will "
  446. "probe irqs later\n", d->name, pci_name(dev));
  447. pciirq = 0;
  448. } else if (!pciirq && noisy) {
  449. printk(KERN_WARNING "%s %s: bad irq (%d): will probe later\n",
  450. d->name, pci_name(dev), pciirq);
  451. } else if (noisy) {
  452. printk(KERN_INFO "%s %s: 100%% native mode on irq %d\n",
  453. d->name, pci_name(dev), pciirq);
  454. }
  455. ret = pciirq;
  456. out:
  457. return ret;
  458. }
  459. int ide_pci_init_two(struct pci_dev *dev1, struct pci_dev *dev2,
  460. const struct ide_port_info *d, void *priv)
  461. {
  462. struct pci_dev *pdev[] = { dev1, dev2 };
  463. struct ide_host *host;
  464. int ret, i, n_ports = dev2 ? 4 : 2;
  465. struct ide_hw hw[4], *hws[] = { NULL, NULL, NULL, NULL };
  466. for (i = 0; i < n_ports / 2; i++) {
  467. ret = ide_setup_pci_controller(pdev[i], d, !i);
  468. if (ret < 0)
  469. goto out;
  470. ide_pci_setup_ports(pdev[i], d, &hw[i*2], &hws[i*2]);
  471. }
  472. host = ide_host_alloc(d, hws, n_ports);
  473. if (host == NULL) {
  474. ret = -ENOMEM;
  475. goto out;
  476. }
  477. host->dev[0] = &dev1->dev;
  478. if (dev2)
  479. host->dev[1] = &dev2->dev;
  480. host->host_priv = priv;
  481. host->irq_flags = IRQF_SHARED;
  482. pci_set_drvdata(pdev[0], host);
  483. if (dev2)
  484. pci_set_drvdata(pdev[1], host);
  485. for (i = 0; i < n_ports / 2; i++) {
  486. ret = do_ide_setup_pci_device(pdev[i], d, !i);
  487. /*
  488. * FIXME: Mom, mom, they stole me the helper function to undo
  489. * do_ide_setup_pci_device() on the first device!
  490. */
  491. if (ret < 0)
  492. goto out;
  493. /* fixup IRQ */
  494. if (ide_pci_is_in_compatibility_mode(pdev[i])) {
  495. hw[i*2].irq = pci_get_legacy_ide_irq(pdev[i], 0);
  496. hw[i*2 + 1].irq = pci_get_legacy_ide_irq(pdev[i], 1);
  497. } else
  498. hw[i*2 + 1].irq = hw[i*2].irq = ret;
  499. }
  500. ret = ide_host_register(host, d, hws);
  501. if (ret)
  502. ide_host_free(host);
  503. out:
  504. return ret;
  505. }
  506. EXPORT_SYMBOL_GPL(ide_pci_init_two);
  507. int ide_pci_init_one(struct pci_dev *dev, const struct ide_port_info *d,
  508. void *priv)
  509. {
  510. return ide_pci_init_two(dev, NULL, d, priv);
  511. }
  512. EXPORT_SYMBOL_GPL(ide_pci_init_one);
  513. void ide_pci_remove(struct pci_dev *dev)
  514. {
  515. struct ide_host *host = pci_get_drvdata(dev);
  516. struct pci_dev *dev2 = host->dev[1] ? to_pci_dev(host->dev[1]) : NULL;
  517. int bars;
  518. if (host->host_flags & IDE_HFLAG_SINGLE)
  519. bars = (1 << 2) - 1;
  520. else
  521. bars = (1 << 4) - 1;
  522. if ((host->host_flags & IDE_HFLAG_NO_DMA) == 0) {
  523. if (host->host_flags & IDE_HFLAG_CS5520)
  524. bars |= (1 << 2);
  525. else
  526. bars |= (1 << 4);
  527. }
  528. ide_host_remove(host);
  529. if (dev2)
  530. pci_release_selected_regions(dev2, bars);
  531. pci_release_selected_regions(dev, bars);
  532. if (dev2)
  533. pci_disable_device(dev2);
  534. pci_disable_device(dev);
  535. }
  536. EXPORT_SYMBOL_GPL(ide_pci_remove);
  537. #ifdef CONFIG_PM
  538. int ide_pci_suspend(struct pci_dev *dev, pm_message_t state)
  539. {
  540. pci_save_state(dev);
  541. pci_disable_device(dev);
  542. pci_set_power_state(dev, pci_choose_state(dev, state));
  543. return 0;
  544. }
  545. EXPORT_SYMBOL_GPL(ide_pci_suspend);
  546. int ide_pci_resume(struct pci_dev *dev)
  547. {
  548. struct ide_host *host = pci_get_drvdata(dev);
  549. int rc;
  550. pci_set_power_state(dev, PCI_D0);
  551. rc = pci_enable_device(dev);
  552. if (rc)
  553. return rc;
  554. pci_restore_state(dev);
  555. pci_set_master(dev);
  556. if (host->init_chipset)
  557. host->init_chipset(dev);
  558. return 0;
  559. }
  560. EXPORT_SYMBOL_GPL(ide_pci_resume);
  561. #endif