setup-pci.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703
  1. /*
  2. * Copyright (C) 1998-2000 Andre Hedrick <andre@linux-ide.org>
  3. * Copyright (C) 1995-1998 Mark Lord
  4. * Copyright (C) 2007 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 hw_regs_t instance
  263. * @dev: PCI device holding interface
  264. * @d: IDE port info
  265. * @port: port number
  266. * @hw: hw_regs_t 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, hw_regs_t *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. hw->chipset = d->chipset ? d->chipset : ide_pci;
  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: hw_regs_t instances corresponding to this PCI IDE device
  383. * @hws: hw_regs_t 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. hw_regs_t *hw, hw_regs_t **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_one(struct pci_dev *dev, const struct ide_port_info *d,
  460. void *priv)
  461. {
  462. struct ide_host *host;
  463. hw_regs_t hw[4], *hws[] = { NULL, NULL, NULL, NULL };
  464. int ret;
  465. ret = ide_setup_pci_controller(dev, d, 1);
  466. if (ret < 0)
  467. goto out;
  468. ide_pci_setup_ports(dev, d, &hw[0], &hws[0]);
  469. host = ide_host_alloc(d, hws);
  470. if (host == NULL) {
  471. ret = -ENOMEM;
  472. goto out;
  473. }
  474. host->dev[0] = &dev->dev;
  475. host->host_priv = priv;
  476. host->irq_flags = IRQF_SHARED;
  477. pci_set_drvdata(dev, host);
  478. ret = do_ide_setup_pci_device(dev, d, 1);
  479. if (ret < 0)
  480. goto out;
  481. /* fixup IRQ */
  482. if (ide_pci_is_in_compatibility_mode(dev)) {
  483. hw[0].irq = pci_get_legacy_ide_irq(dev, 0);
  484. hw[1].irq = pci_get_legacy_ide_irq(dev, 1);
  485. } else
  486. hw[1].irq = hw[0].irq = ret;
  487. ret = ide_host_register(host, d, hws);
  488. if (ret)
  489. ide_host_free(host);
  490. out:
  491. return ret;
  492. }
  493. EXPORT_SYMBOL_GPL(ide_pci_init_one);
  494. int ide_pci_init_two(struct pci_dev *dev1, struct pci_dev *dev2,
  495. const struct ide_port_info *d, void *priv)
  496. {
  497. struct pci_dev *pdev[] = { dev1, dev2 };
  498. struct ide_host *host;
  499. int ret, i;
  500. hw_regs_t hw[4], *hws[] = { NULL, NULL, NULL, NULL };
  501. for (i = 0; i < 2; i++) {
  502. ret = ide_setup_pci_controller(pdev[i], d, !i);
  503. if (ret < 0)
  504. goto out;
  505. ide_pci_setup_ports(pdev[i], d, &hw[i*2], &hws[i*2]);
  506. }
  507. host = ide_host_alloc(d, hws);
  508. if (host == NULL) {
  509. ret = -ENOMEM;
  510. goto out;
  511. }
  512. host->dev[0] = &dev1->dev;
  513. host->dev[1] = &dev2->dev;
  514. host->host_priv = priv;
  515. host->irq_flags = IRQF_SHARED;
  516. pci_set_drvdata(pdev[0], host);
  517. pci_set_drvdata(pdev[1], host);
  518. for (i = 0; i < 2; i++) {
  519. ret = do_ide_setup_pci_device(pdev[i], d, !i);
  520. /*
  521. * FIXME: Mom, mom, they stole me the helper function to undo
  522. * do_ide_setup_pci_device() on the first device!
  523. */
  524. if (ret < 0)
  525. goto out;
  526. /* fixup IRQ */
  527. if (ide_pci_is_in_compatibility_mode(pdev[i])) {
  528. hw[i*2].irq = pci_get_legacy_ide_irq(pdev[i], 0);
  529. hw[i*2 + 1].irq = pci_get_legacy_ide_irq(pdev[i], 1);
  530. } else
  531. hw[i*2 + 1].irq = hw[i*2].irq = ret;
  532. }
  533. ret = ide_host_register(host, d, hws);
  534. if (ret)
  535. ide_host_free(host);
  536. out:
  537. return ret;
  538. }
  539. EXPORT_SYMBOL_GPL(ide_pci_init_two);
  540. void ide_pci_remove(struct pci_dev *dev)
  541. {
  542. struct ide_host *host = pci_get_drvdata(dev);
  543. struct pci_dev *dev2 = host->dev[1] ? to_pci_dev(host->dev[1]) : NULL;
  544. int bars;
  545. if (host->host_flags & IDE_HFLAG_SINGLE)
  546. bars = (1 << 2) - 1;
  547. else
  548. bars = (1 << 4) - 1;
  549. if ((host->host_flags & IDE_HFLAG_NO_DMA) == 0) {
  550. if (host->host_flags & IDE_HFLAG_CS5520)
  551. bars |= (1 << 2);
  552. else
  553. bars |= (1 << 4);
  554. }
  555. ide_host_remove(host);
  556. if (dev2)
  557. pci_release_selected_regions(dev2, bars);
  558. pci_release_selected_regions(dev, bars);
  559. if (dev2)
  560. pci_disable_device(dev2);
  561. pci_disable_device(dev);
  562. }
  563. EXPORT_SYMBOL_GPL(ide_pci_remove);
  564. #ifdef CONFIG_PM
  565. int ide_pci_suspend(struct pci_dev *dev, pm_message_t state)
  566. {
  567. pci_save_state(dev);
  568. pci_disable_device(dev);
  569. pci_set_power_state(dev, pci_choose_state(dev, state));
  570. return 0;
  571. }
  572. EXPORT_SYMBOL_GPL(ide_pci_suspend);
  573. int ide_pci_resume(struct pci_dev *dev)
  574. {
  575. struct ide_host *host = pci_get_drvdata(dev);
  576. int rc;
  577. pci_set_power_state(dev, PCI_D0);
  578. rc = pci_enable_device(dev);
  579. if (rc)
  580. return rc;
  581. pci_restore_state(dev);
  582. pci_set_master(dev);
  583. if (host->init_chipset)
  584. host->init_chipset(dev);
  585. return 0;
  586. }
  587. EXPORT_SYMBOL_GPL(ide_pci_resume);
  588. #endif