setup-pci.c 18 KB

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