setup-pci.c 17 KB

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