setup-pci.c 17 KB

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