setup-pci.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661
  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->tp_ops->read_sff_dma_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_32BIT_MASK);
  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. * @irq: PCI IRQ
  267. * @hw: hw_regs_t 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, int irq, hw_regs_t *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->irq = irq;
  301. hw->dev = &dev->dev;
  302. hw->chipset = d->chipset ? d->chipset : ide_pci;
  303. ide_std_init_ports(hw, base, ctl | 2);
  304. return 0;
  305. }
  306. #ifdef CONFIG_BLK_DEV_IDEDMA_PCI
  307. /**
  308. * ide_hwif_setup_dma - configure DMA interface
  309. * @hwif: IDE interface
  310. * @d: IDE port info
  311. *
  312. * Set up the DMA base for the interface. Enable the master bits as
  313. * necessary and attempt to bring the device DMA into a ready to use
  314. * state
  315. */
  316. int ide_hwif_setup_dma(ide_hwif_t *hwif, const struct ide_port_info *d)
  317. {
  318. struct pci_dev *dev = to_pci_dev(hwif->dev);
  319. if ((d->host_flags & IDE_HFLAG_NO_AUTODMA) == 0 ||
  320. ((dev->class >> 8) == PCI_CLASS_STORAGE_IDE &&
  321. (dev->class & 0x80))) {
  322. unsigned long base = ide_pci_dma_base(hwif, d);
  323. if (base == 0)
  324. return -1;
  325. hwif->dma_base = base;
  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. hwif->dma_ops = &sff_dma_ops;
  339. }
  340. return 0;
  341. }
  342. #endif /* CONFIG_BLK_DEV_IDEDMA_PCI */
  343. /**
  344. * ide_setup_pci_controller - set up IDE PCI
  345. * @dev: PCI device
  346. * @d: IDE port info
  347. * @noisy: verbose flag
  348. *
  349. * Set up the PCI and controller side of the IDE interface. This brings
  350. * up the PCI side of the device, checks that the device is enabled
  351. * and enables it if need be
  352. */
  353. static int ide_setup_pci_controller(struct pci_dev *dev,
  354. const struct ide_port_info *d, int noisy)
  355. {
  356. int ret;
  357. u16 pcicmd;
  358. if (noisy)
  359. ide_setup_pci_noise(dev, d);
  360. ret = ide_pci_enable(dev, d);
  361. if (ret < 0)
  362. goto out;
  363. ret = pci_read_config_word(dev, PCI_COMMAND, &pcicmd);
  364. if (ret < 0) {
  365. printk(KERN_ERR "%s %s: error accessing PCI regs\n",
  366. d->name, pci_name(dev));
  367. goto out;
  368. }
  369. if (!(pcicmd & PCI_COMMAND_IO)) { /* is device disabled? */
  370. ret = ide_pci_configure(dev, d);
  371. if (ret < 0)
  372. goto out;
  373. printk(KERN_INFO "%s %s: device enabled (Linux)\n",
  374. d->name, pci_name(dev));
  375. }
  376. out:
  377. return ret;
  378. }
  379. /**
  380. * ide_pci_setup_ports - configure ports/devices on PCI IDE
  381. * @dev: PCI device
  382. * @d: IDE port info
  383. * @pciirq: IRQ line
  384. * @hw: hw_regs_t instances corresponding to this PCI IDE device
  385. * @hws: hw_regs_t pointers table to update
  386. *
  387. * Scan the interfaces attached to this device and do any
  388. * necessary per port setup. Attach the devices and ask the
  389. * generic DMA layer to do its work for us.
  390. *
  391. * Normally called automaticall from do_ide_pci_setup_device,
  392. * but is also used directly as a helper function by some controllers
  393. * where the chipset setup is not the default PCI IDE one.
  394. */
  395. void ide_pci_setup_ports(struct pci_dev *dev, const struct ide_port_info *d,
  396. int pciirq, hw_regs_t *hw, hw_regs_t **hws)
  397. {
  398. int channels = (d->host_flags & IDE_HFLAG_SINGLE) ? 1 : 2, port;
  399. u8 tmp;
  400. /*
  401. * Set up the IDE ports
  402. */
  403. for (port = 0; port < channels; ++port) {
  404. const ide_pci_enablebit_t *e = &(d->enablebits[port]);
  405. if (e->reg && (pci_read_config_byte(dev, e->reg, &tmp) ||
  406. (tmp & e->mask) != e->val)) {
  407. printk(KERN_INFO "%s %s: IDE port disabled\n",
  408. d->name, pci_name(dev));
  409. continue; /* port not enabled */
  410. }
  411. if (ide_hw_configure(dev, d, port, pciirq, hw + port))
  412. continue;
  413. *(hws + port) = hw + port;
  414. }
  415. }
  416. EXPORT_SYMBOL_GPL(ide_pci_setup_ports);
  417. /*
  418. * ide_setup_pci_device() looks at the primary/secondary interfaces
  419. * on a PCI IDE device and, if they are enabled, prepares the IDE driver
  420. * for use with them. This generic code works for most PCI chipsets.
  421. *
  422. * One thing that is not standardized is the location of the
  423. * primary/secondary interface "enable/disable" bits. For chipsets that
  424. * we "know" about, this information is in the struct ide_port_info;
  425. * for all other chipsets, we just assume both interfaces are enabled.
  426. */
  427. static int do_ide_setup_pci_device(struct pci_dev *dev,
  428. const struct ide_port_info *d,
  429. u8 noisy)
  430. {
  431. int pciirq, ret;
  432. /*
  433. * Can we trust the reported IRQ?
  434. */
  435. pciirq = dev->irq;
  436. /*
  437. * This allows offboard ide-pci cards the enable a BIOS,
  438. * verify interrupt settings of split-mirror pci-config
  439. * space, place chipset into init-mode, and/or preserve
  440. * an interrupt if the card is not native ide support.
  441. */
  442. ret = d->init_chipset ? d->init_chipset(dev) : 0;
  443. if (ret < 0)
  444. goto out;
  445. /* Is it an "IDE storage" device in non-PCI mode? */
  446. if ((dev->class >> 8) == PCI_CLASS_STORAGE_IDE && (dev->class & 5) != 5) {
  447. if (noisy)
  448. printk(KERN_INFO "%s %s: not 100%% native mode: will "
  449. "probe irqs later\n", d->name, pci_name(dev));
  450. pciirq = ret;
  451. } else if (!pciirq && noisy) {
  452. printk(KERN_WARNING "%s %s: bad irq (%d): will probe later\n",
  453. d->name, pci_name(dev), pciirq);
  454. } else if (noisy) {
  455. printk(KERN_INFO "%s %s: 100%% native mode on irq %d\n",
  456. d->name, pci_name(dev), pciirq);
  457. }
  458. ret = pciirq;
  459. out:
  460. return ret;
  461. }
  462. int ide_pci_init_one(struct pci_dev *dev, const struct ide_port_info *d,
  463. void *priv)
  464. {
  465. struct ide_host *host;
  466. hw_regs_t hw[4], *hws[] = { NULL, NULL, NULL, NULL };
  467. int ret;
  468. ret = ide_setup_pci_controller(dev, d, 1);
  469. if (ret < 0)
  470. goto out;
  471. ide_pci_setup_ports(dev, d, 0, &hw[0], &hws[0]);
  472. host = ide_host_alloc(d, hws);
  473. if (host == NULL) {
  474. ret = -ENOMEM;
  475. goto out;
  476. }
  477. host->dev[0] = &dev->dev;
  478. host->host_priv = priv;
  479. pci_set_drvdata(dev, host);
  480. ret = do_ide_setup_pci_device(dev, d, 1);
  481. if (ret < 0)
  482. goto out;
  483. /* fixup IRQ */
  484. hw[1].irq = hw[0].irq = ret;
  485. ret = ide_host_register(host, d, hws);
  486. if (ret)
  487. ide_host_free(host);
  488. out:
  489. return ret;
  490. }
  491. EXPORT_SYMBOL_GPL(ide_pci_init_one);
  492. int ide_pci_init_two(struct pci_dev *dev1, struct pci_dev *dev2,
  493. const struct ide_port_info *d, void *priv)
  494. {
  495. struct pci_dev *pdev[] = { dev1, dev2 };
  496. struct ide_host *host;
  497. int ret, i;
  498. hw_regs_t hw[4], *hws[] = { NULL, NULL, NULL, NULL };
  499. for (i = 0; i < 2; i++) {
  500. ret = ide_setup_pci_controller(pdev[i], d, !i);
  501. if (ret < 0)
  502. goto out;
  503. ide_pci_setup_ports(pdev[i], d, 0, &hw[i*2], &hws[i*2]);
  504. }
  505. host = ide_host_alloc(d, hws);
  506. if (host == NULL) {
  507. ret = -ENOMEM;
  508. goto out;
  509. }
  510. host->dev[0] = &dev1->dev;
  511. host->dev[1] = &dev2->dev;
  512. host->host_priv = priv;
  513. pci_set_drvdata(pdev[0], host);
  514. pci_set_drvdata(pdev[1], host);
  515. for (i = 0; i < 2; i++) {
  516. ret = do_ide_setup_pci_device(pdev[i], d, !i);
  517. /*
  518. * FIXME: Mom, mom, they stole me the helper function to undo
  519. * do_ide_setup_pci_device() on the first device!
  520. */
  521. if (ret < 0)
  522. goto out;
  523. /* fixup IRQ */
  524. hw[i*2 + 1].irq = hw[i*2].irq = ret;
  525. }
  526. ret = ide_host_register(host, d, hws);
  527. if (ret)
  528. ide_host_free(host);
  529. out:
  530. return ret;
  531. }
  532. EXPORT_SYMBOL_GPL(ide_pci_init_two);
  533. void ide_pci_remove(struct pci_dev *dev)
  534. {
  535. struct ide_host *host = pci_get_drvdata(dev);
  536. struct pci_dev *dev2 = host->dev[1] ? to_pci_dev(host->dev[1]) : NULL;
  537. int bars;
  538. if (host->host_flags & IDE_HFLAG_SINGLE)
  539. bars = (1 << 2) - 1;
  540. else
  541. bars = (1 << 4) - 1;
  542. if ((host->host_flags & IDE_HFLAG_NO_DMA) == 0) {
  543. if (host->host_flags & IDE_HFLAG_CS5520)
  544. bars |= (1 << 2);
  545. else
  546. bars |= (1 << 4);
  547. }
  548. ide_host_remove(host);
  549. if (dev2)
  550. pci_release_selected_regions(dev2, bars);
  551. pci_release_selected_regions(dev, bars);
  552. if (dev2)
  553. pci_disable_device(dev2);
  554. pci_disable_device(dev);
  555. }
  556. EXPORT_SYMBOL_GPL(ide_pci_remove);