setup-pci.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682
  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. * @bars: PCI BARs mask
  155. * @d: IDE port info
  156. *
  157. * Enable the IDE PCI device. We attempt to enable the device in full
  158. * but if that fails then we only need IO space. The PCI code should
  159. * have setup the proper resources for us already for controllers in
  160. * legacy mode.
  161. *
  162. * Returns zero on success or an error code
  163. */
  164. static int ide_pci_enable(struct pci_dev *dev, int bars,
  165. const struct ide_port_info *d)
  166. {
  167. int ret;
  168. if (pci_enable_device(dev)) {
  169. ret = pci_enable_device_io(dev);
  170. if (ret < 0) {
  171. printk(KERN_WARNING "%s %s: couldn't enable device\n",
  172. d->name, pci_name(dev));
  173. goto out;
  174. }
  175. printk(KERN_WARNING "%s %s: BIOS configuration fixed\n",
  176. d->name, pci_name(dev));
  177. }
  178. /*
  179. * assume all devices can do 32-bit DMA for now, we can add
  180. * a DMA mask field to the struct ide_port_info if we need it
  181. * (or let lower level driver set the DMA mask)
  182. */
  183. ret = dma_set_mask(&dev->dev, DMA_BIT_MASK(32));
  184. if (ret < 0) {
  185. printk(KERN_ERR "%s %s: can't set DMA mask\n",
  186. d->name, pci_name(dev));
  187. goto out;
  188. }
  189. ret = pci_request_selected_regions(dev, bars, d->name);
  190. if (ret < 0)
  191. printk(KERN_ERR "%s %s: can't reserve resources\n",
  192. d->name, pci_name(dev));
  193. out:
  194. return ret;
  195. }
  196. /**
  197. * ide_pci_configure - configure an unconfigured device
  198. * @dev: PCI device
  199. * @d: IDE port info
  200. *
  201. * Enable and configure the PCI device we have been passed.
  202. * Returns zero on success or an error code.
  203. */
  204. static int ide_pci_configure(struct pci_dev *dev, const struct ide_port_info *d)
  205. {
  206. u16 pcicmd = 0;
  207. /*
  208. * PnP BIOS was *supposed* to have setup this device, but we
  209. * can do it ourselves, so long as the BIOS has assigned an IRQ
  210. * (or possibly the device is using a "legacy header" for IRQs).
  211. * Maybe the user deliberately *disabled* the device,
  212. * but we'll eventually ignore it again if no drives respond.
  213. */
  214. if (ide_setup_pci_baseregs(dev, d->name) ||
  215. pci_write_config_word(dev, PCI_COMMAND, pcicmd | PCI_COMMAND_IO)) {
  216. printk(KERN_INFO "%s %s: device disabled (BIOS)\n",
  217. d->name, pci_name(dev));
  218. return -ENODEV;
  219. }
  220. if (pci_read_config_word(dev, PCI_COMMAND, &pcicmd)) {
  221. printk(KERN_ERR "%s %s: error accessing PCI regs\n",
  222. d->name, pci_name(dev));
  223. return -EIO;
  224. }
  225. if (!(pcicmd & PCI_COMMAND_IO)) {
  226. printk(KERN_ERR "%s %s: unable to enable IDE controller\n",
  227. d->name, pci_name(dev));
  228. return -ENXIO;
  229. }
  230. return 0;
  231. }
  232. /**
  233. * ide_pci_check_iomem - check a register is I/O
  234. * @dev: PCI device
  235. * @d: IDE port info
  236. * @bar: BAR number
  237. *
  238. * Checks if a BAR is configured and points to MMIO space. If so,
  239. * return an error code. Otherwise return 0
  240. */
  241. static int ide_pci_check_iomem(struct pci_dev *dev, const struct ide_port_info *d,
  242. int bar)
  243. {
  244. ulong flags = pci_resource_flags(dev, bar);
  245. /* Unconfigured ? */
  246. if (!flags || pci_resource_len(dev, bar) == 0)
  247. return 0;
  248. /* I/O space */
  249. if (flags & IORESOURCE_IO)
  250. return 0;
  251. /* Bad */
  252. return -EINVAL;
  253. }
  254. /**
  255. * ide_hw_configure - configure a struct ide_hw instance
  256. * @dev: PCI device holding interface
  257. * @d: IDE port info
  258. * @port: port number
  259. * @hw: struct ide_hw instance corresponding to this port
  260. *
  261. * Perform the initial set up for the hardware interface structure. This
  262. * is done per interface port rather than per PCI device. There may be
  263. * more than one port per device.
  264. *
  265. * Returns zero on success or an error code.
  266. */
  267. static int ide_hw_configure(struct pci_dev *dev, const struct ide_port_info *d,
  268. unsigned int port, struct ide_hw *hw)
  269. {
  270. unsigned long ctl = 0, base = 0;
  271. if ((d->host_flags & IDE_HFLAG_ISA_PORTS) == 0) {
  272. if (ide_pci_check_iomem(dev, d, 2 * port) ||
  273. ide_pci_check_iomem(dev, d, 2 * port + 1)) {
  274. printk(KERN_ERR "%s %s: I/O baseregs (BIOS) are "
  275. "reported as MEM for port %d!\n",
  276. d->name, pci_name(dev), port);
  277. return -EINVAL;
  278. }
  279. ctl = pci_resource_start(dev, 2*port+1);
  280. base = pci_resource_start(dev, 2*port);
  281. } else {
  282. /* Use default values */
  283. ctl = port ? 0x374 : 0x3f4;
  284. base = port ? 0x170 : 0x1f0;
  285. }
  286. if (!base || !ctl) {
  287. printk(KERN_ERR "%s %s: bad PCI BARs for port %d, skipping\n",
  288. d->name, pci_name(dev), port);
  289. return -EINVAL;
  290. }
  291. memset(hw, 0, sizeof(*hw));
  292. hw->dev = &dev->dev;
  293. ide_std_init_ports(hw, base, ctl | 2);
  294. return 0;
  295. }
  296. #ifdef CONFIG_BLK_DEV_IDEDMA_PCI
  297. /**
  298. * ide_hwif_setup_dma - configure DMA interface
  299. * @hwif: IDE interface
  300. * @d: IDE port info
  301. *
  302. * Set up the DMA base for the interface. Enable the master bits as
  303. * necessary and attempt to bring the device DMA into a ready to use
  304. * state
  305. */
  306. int ide_hwif_setup_dma(ide_hwif_t *hwif, const struct ide_port_info *d)
  307. {
  308. struct pci_dev *dev = to_pci_dev(hwif->dev);
  309. if ((d->host_flags & IDE_HFLAG_NO_AUTODMA) == 0 ||
  310. ((dev->class >> 8) == PCI_CLASS_STORAGE_IDE &&
  311. (dev->class & 0x80))) {
  312. unsigned long base = ide_pci_dma_base(hwif, d);
  313. if (base == 0)
  314. return -1;
  315. hwif->dma_base = base;
  316. if (hwif->dma_ops == NULL)
  317. hwif->dma_ops = &sff_dma_ops;
  318. if (ide_pci_check_simplex(hwif, d) < 0)
  319. return -1;
  320. if (ide_pci_set_master(dev, d->name) < 0)
  321. return -1;
  322. if (hwif->host_flags & IDE_HFLAG_MMIO)
  323. printk(KERN_INFO " %s: MMIO-DMA\n", hwif->name);
  324. else
  325. printk(KERN_INFO " %s: BM-DMA at 0x%04lx-0x%04lx\n",
  326. hwif->name, base, base + 7);
  327. hwif->extra_base = base + (hwif->channel ? 8 : 16);
  328. if (ide_allocate_dma_engine(hwif))
  329. return -1;
  330. }
  331. return 0;
  332. }
  333. #endif /* CONFIG_BLK_DEV_IDEDMA_PCI */
  334. /**
  335. * ide_setup_pci_controller - set up IDE PCI
  336. * @dev: PCI device
  337. * @bars: PCI BARs mask
  338. * @d: IDE port info
  339. * @noisy: verbose flag
  340. *
  341. * Set up the PCI and controller side of the IDE interface. This brings
  342. * up the PCI side of the device, checks that the device is enabled
  343. * and enables it if need be
  344. */
  345. static int ide_setup_pci_controller(struct pci_dev *dev, int bars,
  346. const struct ide_port_info *d, int noisy)
  347. {
  348. int ret;
  349. u16 pcicmd;
  350. if (noisy)
  351. ide_setup_pci_noise(dev, d);
  352. ret = ide_pci_enable(dev, bars, d);
  353. if (ret < 0)
  354. goto out;
  355. ret = pci_read_config_word(dev, PCI_COMMAND, &pcicmd);
  356. if (ret < 0) {
  357. printk(KERN_ERR "%s %s: error accessing PCI regs\n",
  358. d->name, pci_name(dev));
  359. goto out_free_bars;
  360. }
  361. if (!(pcicmd & PCI_COMMAND_IO)) { /* is device disabled? */
  362. ret = ide_pci_configure(dev, d);
  363. if (ret < 0)
  364. goto out_free_bars;
  365. printk(KERN_INFO "%s %s: device enabled (Linux)\n",
  366. d->name, pci_name(dev));
  367. }
  368. goto out;
  369. out_free_bars:
  370. pci_release_selected_regions(dev, bars);
  371. out:
  372. return ret;
  373. }
  374. /**
  375. * ide_pci_setup_ports - configure ports/devices on PCI IDE
  376. * @dev: PCI device
  377. * @d: IDE port info
  378. * @hw: struct ide_hw instances corresponding to this PCI IDE device
  379. * @hws: struct ide_hw pointers table to update
  380. *
  381. * Scan the interfaces attached to this device and do any
  382. * necessary per port setup. Attach the devices and ask the
  383. * generic DMA layer to do its work for us.
  384. *
  385. * Normally called automaticall from do_ide_pci_setup_device,
  386. * but is also used directly as a helper function by some controllers
  387. * where the chipset setup is not the default PCI IDE one.
  388. */
  389. void ide_pci_setup_ports(struct pci_dev *dev, const struct ide_port_info *d,
  390. struct ide_hw *hw, struct ide_hw **hws)
  391. {
  392. int channels = (d->host_flags & IDE_HFLAG_SINGLE) ? 1 : 2, port;
  393. u8 tmp;
  394. /*
  395. * Set up the IDE ports
  396. */
  397. for (port = 0; port < channels; ++port) {
  398. const struct ide_pci_enablebit *e = &d->enablebits[port];
  399. if (e->reg && (pci_read_config_byte(dev, e->reg, &tmp) ||
  400. (tmp & e->mask) != e->val)) {
  401. printk(KERN_INFO "%s %s: IDE port disabled\n",
  402. d->name, pci_name(dev));
  403. continue; /* port not enabled */
  404. }
  405. if (ide_hw_configure(dev, d, port, hw + port))
  406. continue;
  407. *(hws + port) = hw + port;
  408. }
  409. }
  410. EXPORT_SYMBOL_GPL(ide_pci_setup_ports);
  411. /*
  412. * ide_setup_pci_device() looks at the primary/secondary interfaces
  413. * on a PCI IDE device and, if they are enabled, prepares the IDE driver
  414. * for use with them. This generic code works for most PCI chipsets.
  415. *
  416. * One thing that is not standardized is the location of the
  417. * primary/secondary interface "enable/disable" bits. For chipsets that
  418. * we "know" about, this information is in the struct ide_port_info;
  419. * for all other chipsets, we just assume both interfaces are enabled.
  420. */
  421. static int do_ide_setup_pci_device(struct pci_dev *dev,
  422. const struct ide_port_info *d,
  423. u8 noisy)
  424. {
  425. int pciirq, ret;
  426. /*
  427. * Can we trust the reported IRQ?
  428. */
  429. pciirq = dev->irq;
  430. /*
  431. * This allows offboard ide-pci cards the enable a BIOS,
  432. * verify interrupt settings of split-mirror pci-config
  433. * space, place chipset into init-mode, and/or preserve
  434. * an interrupt if the card is not native ide support.
  435. */
  436. ret = d->init_chipset ? d->init_chipset(dev) : 0;
  437. if (ret < 0)
  438. goto out;
  439. if (ide_pci_is_in_compatibility_mode(dev)) {
  440. if (noisy)
  441. printk(KERN_INFO "%s %s: not 100%% native mode: will "
  442. "probe irqs later\n", d->name, pci_name(dev));
  443. pciirq = 0;
  444. } else if (!pciirq && noisy) {
  445. printk(KERN_WARNING "%s %s: bad irq (%d): will probe later\n",
  446. d->name, pci_name(dev), pciirq);
  447. } else if (noisy) {
  448. printk(KERN_INFO "%s %s: 100%% native mode on irq %d\n",
  449. d->name, pci_name(dev), pciirq);
  450. }
  451. ret = pciirq;
  452. out:
  453. return ret;
  454. }
  455. int ide_pci_init_two(struct pci_dev *dev1, struct pci_dev *dev2,
  456. const struct ide_port_info *d, void *priv)
  457. {
  458. struct pci_dev *pdev[] = { dev1, dev2 };
  459. struct ide_host *host;
  460. int ret, i, n_ports = dev2 ? 4 : 2, bars;
  461. struct ide_hw hw[4], *hws[] = { NULL, NULL, NULL, NULL };
  462. if (d->host_flags & IDE_HFLAG_SINGLE)
  463. bars = (1 << 2) - 1;
  464. else
  465. bars = (1 << 4) - 1;
  466. if ((d->host_flags & IDE_HFLAG_NO_DMA) == 0) {
  467. if (d->host_flags & IDE_HFLAG_CS5520)
  468. bars |= (1 << 2);
  469. else
  470. bars |= (1 << 4);
  471. }
  472. for (i = 0; i < n_ports / 2; i++) {
  473. ret = ide_setup_pci_controller(pdev[i], bars, d, !i);
  474. if (ret < 0) {
  475. if (i == 1)
  476. pci_release_selected_regions(pdev[0], bars);
  477. goto out;
  478. }
  479. ide_pci_setup_ports(pdev[i], d, &hw[i*2], &hws[i*2]);
  480. }
  481. host = ide_host_alloc(d, hws, n_ports);
  482. if (host == NULL) {
  483. ret = -ENOMEM;
  484. goto out_free_bars;
  485. }
  486. host->dev[0] = &dev1->dev;
  487. if (dev2)
  488. host->dev[1] = &dev2->dev;
  489. host->host_priv = priv;
  490. host->irq_flags = IRQF_SHARED;
  491. pci_set_drvdata(pdev[0], host);
  492. if (dev2)
  493. pci_set_drvdata(pdev[1], host);
  494. for (i = 0; i < n_ports / 2; i++) {
  495. ret = do_ide_setup_pci_device(pdev[i], d, !i);
  496. /*
  497. * FIXME: Mom, mom, they stole me the helper function to undo
  498. * do_ide_setup_pci_device() on the first device!
  499. */
  500. if (ret < 0)
  501. goto out_free_bars;
  502. /* fixup IRQ */
  503. if (ide_pci_is_in_compatibility_mode(pdev[i])) {
  504. hw[i*2].irq = pci_get_legacy_ide_irq(pdev[i], 0);
  505. hw[i*2 + 1].irq = pci_get_legacy_ide_irq(pdev[i], 1);
  506. } else
  507. hw[i*2 + 1].irq = hw[i*2].irq = ret;
  508. }
  509. ret = ide_host_register(host, d, hws);
  510. if (ret)
  511. ide_host_free(host);
  512. else
  513. goto out;
  514. out_free_bars:
  515. i = n_ports / 2;
  516. while (i--)
  517. pci_release_selected_regions(pdev[i], bars);
  518. out:
  519. return ret;
  520. }
  521. EXPORT_SYMBOL_GPL(ide_pci_init_two);
  522. int ide_pci_init_one(struct pci_dev *dev, const struct ide_port_info *d,
  523. void *priv)
  524. {
  525. return ide_pci_init_two(dev, NULL, d, priv);
  526. }
  527. EXPORT_SYMBOL_GPL(ide_pci_init_one);
  528. void ide_pci_remove(struct pci_dev *dev)
  529. {
  530. struct ide_host *host = pci_get_drvdata(dev);
  531. struct pci_dev *dev2 = host->dev[1] ? to_pci_dev(host->dev[1]) : NULL;
  532. int bars;
  533. if (host->host_flags & IDE_HFLAG_SINGLE)
  534. bars = (1 << 2) - 1;
  535. else
  536. bars = (1 << 4) - 1;
  537. if ((host->host_flags & IDE_HFLAG_NO_DMA) == 0) {
  538. if (host->host_flags & IDE_HFLAG_CS5520)
  539. bars |= (1 << 2);
  540. else
  541. bars |= (1 << 4);
  542. }
  543. ide_host_remove(host);
  544. if (dev2)
  545. pci_release_selected_regions(dev2, bars);
  546. pci_release_selected_regions(dev, bars);
  547. if (dev2)
  548. pci_disable_device(dev2);
  549. pci_disable_device(dev);
  550. }
  551. EXPORT_SYMBOL_GPL(ide_pci_remove);
  552. #ifdef CONFIG_PM
  553. int ide_pci_suspend(struct pci_dev *dev, pm_message_t state)
  554. {
  555. pci_save_state(dev);
  556. pci_disable_device(dev);
  557. pci_set_power_state(dev, pci_choose_state(dev, state));
  558. return 0;
  559. }
  560. EXPORT_SYMBOL_GPL(ide_pci_suspend);
  561. int ide_pci_resume(struct pci_dev *dev)
  562. {
  563. struct ide_host *host = pci_get_drvdata(dev);
  564. int rc;
  565. pci_set_power_state(dev, PCI_D0);
  566. rc = pci_enable_device(dev);
  567. if (rc)
  568. return rc;
  569. pci_restore_state(dev);
  570. pci_set_master(dev);
  571. if (host->init_chipset)
  572. host->init_chipset(dev);
  573. return 0;
  574. }
  575. EXPORT_SYMBOL_GPL(ide_pci_resume);
  576. #endif