setup-pci.c 17 KB

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