Input: fix misspelling of Hangeul key
[linux-2.6/openmoko-kernel.git] / drivers / ide / setup-pci.c
blobc11e3b2e67a6b46711a16fea70e1abdc47e49b74
1 /*
2 * linux/drivers/ide/setup-pci.c Version 1.10 2002/08/19
4 * Copyright (c) 1998-2000 Andre Hedrick <andre@linux-ide.org>
6 * Copyright (c) 1995-1998 Mark Lord
7 * May be copied or modified under the terms of the GNU General Public License
9 * Recent Changes
10 * Split the set up function into multiple functions
11 * Use pci_set_master
12 * Fix misreporting of I/O v MMIO problems
13 * Initial fixups for simplex devices
17 * This module provides support for automatic detection and
18 * configuration of all PCI IDE interfaces present in a system.
21 #include <linux/config.h>
22 #include <linux/module.h>
23 #include <linux/types.h>
24 #include <linux/kernel.h>
25 #include <linux/pci.h>
26 #include <linux/init.h>
27 #include <linux/timer.h>
28 #include <linux/mm.h>
29 #include <linux/interrupt.h>
30 #include <linux/ide.h>
31 #include <linux/dma-mapping.h>
33 #include <asm/io.h>
34 #include <asm/irq.h>
37 /**
38 * ide_match_hwif - match a PCI IDE against an ide_hwif
39 * @io_base: I/O base of device
40 * @bootable: set if its bootable
41 * @name: name of device
43 * Match a PCI IDE port against an entry in ide_hwifs[],
44 * based on io_base port if possible. Return the matching hwif,
45 * or a new hwif. If we find an error (clashing, out of devices, etc)
46 * return NULL
48 * FIXME: we need to handle mmio matches here too
51 static ide_hwif_t *ide_match_hwif(unsigned long io_base, u8 bootable, const char *name)
53 int h;
54 ide_hwif_t *hwif;
57 * Look for a hwif with matching io_base specified using
58 * parameters to ide_setup().
60 for (h = 0; h < MAX_HWIFS; ++h) {
61 hwif = &ide_hwifs[h];
62 if (hwif->io_ports[IDE_DATA_OFFSET] == io_base) {
63 if (hwif->chipset == ide_forced)
64 return hwif; /* a perfect match */
68 * Look for a hwif with matching io_base default value.
69 * If chipset is "ide_unknown", then claim that hwif slot.
70 * Otherwise, some other chipset has already claimed it.. :(
72 for (h = 0; h < MAX_HWIFS; ++h) {
73 hwif = &ide_hwifs[h];
74 if (hwif->io_ports[IDE_DATA_OFFSET] == io_base) {
75 if (hwif->chipset == ide_unknown)
76 return hwif; /* match */
77 printk(KERN_ERR "%s: port 0x%04lx already claimed by %s\n",
78 name, io_base, hwif->name);
79 return NULL; /* already claimed */
83 * Okay, there is no hwif matching our io_base,
84 * so we'll just claim an unassigned slot.
85 * Give preference to claiming other slots before claiming ide0/ide1,
86 * just in case there's another interface yet-to-be-scanned
87 * which uses ports 1f0/170 (the ide0/ide1 defaults).
89 * Unless there is a bootable card that does not use the standard
90 * ports 1f0/170 (the ide0/ide1 defaults). The (bootable) flag.
92 if (bootable) {
93 for (h = 0; h < MAX_HWIFS; ++h) {
94 hwif = &ide_hwifs[h];
95 if (hwif->chipset == ide_unknown)
96 return hwif; /* pick an unused entry */
98 } else {
99 for (h = 2; h < MAX_HWIFS; ++h) {
100 hwif = ide_hwifs + h;
101 if (hwif->chipset == ide_unknown)
102 return hwif; /* pick an unused entry */
105 for (h = 0; h < 2; ++h) {
106 hwif = ide_hwifs + h;
107 if (hwif->chipset == ide_unknown)
108 return hwif; /* pick an unused entry */
110 printk(KERN_ERR "%s: too many IDE interfaces, no room in table\n", name);
111 return NULL;
115 * ide_setup_pci_baseregs - place a PCI IDE controller native
116 * @dev: PCI device of interface to switch native
117 * @name: Name of interface
119 * We attempt to place the PCI interface into PCI native mode. If
120 * we succeed the BARs are ok and the controller is in PCI mode.
121 * Returns 0 on success or an errno code.
123 * FIXME: if we program the interface and then fail to set the BARS
124 * we don't switch it back to legacy mode. Do we actually care ??
127 static int ide_setup_pci_baseregs (struct pci_dev *dev, const char *name)
129 u8 progif = 0;
132 * Place both IDE interfaces into PCI "native" mode:
134 if (pci_read_config_byte(dev, PCI_CLASS_PROG, &progif) ||
135 (progif & 5) != 5) {
136 if ((progif & 0xa) != 0xa) {
137 printk(KERN_INFO "%s: device not capable of full "
138 "native PCI mode\n", name);
139 return -EOPNOTSUPP;
141 printk("%s: placing both ports into native PCI mode\n", name);
142 (void) pci_write_config_byte(dev, PCI_CLASS_PROG, progif|5);
143 if (pci_read_config_byte(dev, PCI_CLASS_PROG, &progif) ||
144 (progif & 5) != 5) {
145 printk(KERN_ERR "%s: rewrite of PROGIF failed, wanted "
146 "0x%04x, got 0x%04x\n",
147 name, progif|5, progif);
148 return -EOPNOTSUPP;
151 return 0;
154 #ifdef CONFIG_BLK_DEV_IDEDMA_PCI
156 #ifdef CONFIG_BLK_DEV_IDEDMA_FORCED
158 * Long lost data from 2.0.34 that is now in 2.0.39
160 * This was used in ./drivers/block/triton.c to do DMA Base address setup
161 * when PnP failed. Oh the things we forget. I believe this was part
162 * of SFF-8038i that has been withdrawn from public access... :-((
164 #define DEFAULT_BMIBA 0xe800 /* in case BIOS did not init it */
165 #define DEFAULT_BMCRBA 0xcc00 /* VIA's default value */
166 #define DEFAULT_BMALIBA 0xd400 /* ALI's default value */
167 #endif /* CONFIG_BLK_DEV_IDEDMA_FORCED */
170 * ide_get_or_set_dma_base - setup BMIBA
171 * @hwif: Interface
173 * Fetch the DMA Bus-Master-I/O-Base-Address (BMIBA) from PCI space:
174 * If need be we set up the DMA base. Where a device has a partner that
175 * is already in DMA mode we check and enforce IDE simplex rules.
178 static unsigned long ide_get_or_set_dma_base (ide_hwif_t *hwif)
180 unsigned long dma_base = 0;
181 struct pci_dev *dev = hwif->pci_dev;
183 #ifdef CONFIG_BLK_DEV_IDEDMA_FORCED
184 int second_chance = 0;
186 second_chance_to_dma:
187 #endif /* CONFIG_BLK_DEV_IDEDMA_FORCED */
189 if (hwif->mmio)
190 return hwif->dma_base;
192 if (hwif->mate && hwif->mate->dma_base) {
193 dma_base = hwif->mate->dma_base - (hwif->channel ? 0 : 8);
194 } else {
195 dma_base = pci_resource_start(dev, 4);
196 if (!dma_base) {
197 printk(KERN_ERR "%s: dma_base is invalid\n",
198 hwif->cds->name);
202 #ifdef CONFIG_BLK_DEV_IDEDMA_FORCED
203 /* FIXME - should use pci_assign_resource surely */
204 if ((!dma_base) && (!second_chance)) {
205 unsigned long set_bmiba = 0;
206 second_chance++;
207 switch(dev->vendor) {
208 case PCI_VENDOR_ID_AL:
209 set_bmiba = DEFAULT_BMALIBA; break;
210 case PCI_VENDOR_ID_VIA:
211 set_bmiba = DEFAULT_BMCRBA; break;
212 case PCI_VENDOR_ID_INTEL:
213 set_bmiba = DEFAULT_BMIBA; break;
214 default:
215 return dma_base;
217 pci_write_config_dword(dev, 0x20, set_bmiba|1);
218 goto second_chance_to_dma;
220 #endif /* CONFIG_BLK_DEV_IDEDMA_FORCED */
222 if (dma_base) {
223 u8 simplex_stat = 0;
224 dma_base += hwif->channel ? 8 : 0;
226 switch(dev->device) {
227 case PCI_DEVICE_ID_AL_M5219:
228 case PCI_DEVICE_ID_AL_M5229:
229 case PCI_DEVICE_ID_AMD_VIPER_7409:
230 case PCI_DEVICE_ID_CMD_643:
231 case PCI_DEVICE_ID_SERVERWORKS_CSB5IDE:
232 case PCI_DEVICE_ID_REVOLUTION:
233 simplex_stat = hwif->INB(dma_base + 2);
234 hwif->OUTB((simplex_stat&0x60),(dma_base + 2));
235 simplex_stat = hwif->INB(dma_base + 2);
236 if (simplex_stat & 0x80) {
237 printk(KERN_INFO "%s: simplex device: "
238 "DMA forced\n",
239 hwif->cds->name);
241 break;
242 default:
244 * If the device claims "simplex" DMA,
245 * this means only one of the two interfaces
246 * can be trusted with DMA at any point in time.
247 * So we should enable DMA only on one of the
248 * two interfaces.
250 simplex_stat = hwif->INB(dma_base + 2);
251 if (simplex_stat & 0x80) {
252 /* simplex device? */
254 * At this point we haven't probed the drives so we can't make the
255 * appropriate decision. Really we should defer this problem
256 * until we tune the drive then try to grab DMA ownership if we want
257 * to be the DMA end. This has to be become dynamic to handle hot
258 * plug.
260 if (hwif->mate && hwif->mate->dma_base) {
261 printk(KERN_INFO "%s: simplex device: "
262 "DMA disabled\n",
263 hwif->cds->name);
264 dma_base = 0;
269 return dma_base;
271 #endif /* CONFIG_BLK_DEV_IDEDMA_PCI */
273 void ide_setup_pci_noise (struct pci_dev *dev, ide_pci_device_t *d)
275 printk(KERN_INFO "%s: IDE controller at PCI slot %s\n",
276 d->name, pci_name(dev));
279 EXPORT_SYMBOL_GPL(ide_setup_pci_noise);
283 * ide_pci_enable - do PCI enables
284 * @dev: PCI device
285 * @d: IDE pci device data
287 * Enable the IDE PCI device. We attempt to enable the device in full
288 * but if that fails then we only need BAR4 so we will enable that.
290 * Returns zero on success or an error code
293 static int ide_pci_enable(struct pci_dev *dev, ide_pci_device_t *d)
295 int ret;
297 if (pci_enable_device(dev)) {
298 ret = pci_enable_device_bars(dev, 1 << 4);
299 if (ret < 0) {
300 printk(KERN_WARNING "%s: (ide_setup_pci_device:) "
301 "Could not enable device.\n", d->name);
302 goto out;
304 printk(KERN_WARNING "%s: BIOS configuration fixed.\n", d->name);
308 * assume all devices can do 32-bit dma for now. we can add a
309 * dma mask field to the ide_pci_device_t if we need it (or let
310 * lower level driver set the dma mask)
312 ret = pci_set_dma_mask(dev, DMA_32BIT_MASK);
313 if (ret < 0) {
314 printk(KERN_ERR "%s: can't set dma mask\n", d->name);
315 goto out;
318 /* FIXME: Temporary - until we put in the hotplug interface logic
319 Check that the bits we want are not in use by someone else. */
320 ret = pci_request_region(dev, 4, "ide_tmp");
321 if (ret < 0)
322 goto out;
324 pci_release_region(dev, 4);
325 out:
326 return ret;
330 * ide_pci_configure - configure an unconfigured device
331 * @dev: PCI device
332 * @d: IDE pci device data
334 * Enable and configure the PCI device we have been passed.
335 * Returns zero on success or an error code.
338 static int ide_pci_configure(struct pci_dev *dev, ide_pci_device_t *d)
340 u16 pcicmd = 0;
342 * PnP BIOS was *supposed* to have setup this device, but we
343 * can do it ourselves, so long as the BIOS has assigned an IRQ
344 * (or possibly the device is using a "legacy header" for IRQs).
345 * Maybe the user deliberately *disabled* the device,
346 * but we'll eventually ignore it again if no drives respond.
348 if (ide_setup_pci_baseregs(dev, d->name) || pci_write_config_word(dev, PCI_COMMAND, pcicmd|PCI_COMMAND_IO))
350 printk(KERN_INFO "%s: device disabled (BIOS)\n", d->name);
351 return -ENODEV;
353 if (pci_read_config_word(dev, PCI_COMMAND, &pcicmd)) {
354 printk(KERN_ERR "%s: error accessing PCI regs\n", d->name);
355 return -EIO;
357 if (!(pcicmd & PCI_COMMAND_IO)) {
358 printk(KERN_ERR "%s: unable to enable IDE controller\n", d->name);
359 return -ENXIO;
361 return 0;
365 * ide_pci_check_iomem - check a register is I/O
366 * @dev: pci device
367 * @d: ide_pci_device
368 * @bar: bar number
370 * Checks if a BAR is configured and points to MMIO space. If so
371 * print an error and return an error code. Otherwise return 0
374 static int ide_pci_check_iomem(struct pci_dev *dev, ide_pci_device_t *d, int bar)
376 ulong flags = pci_resource_flags(dev, bar);
378 /* Unconfigured ? */
379 if (!flags || pci_resource_len(dev, bar) == 0)
380 return 0;
382 /* I/O space */
383 if(flags & PCI_BASE_ADDRESS_IO_MASK)
384 return 0;
386 /* Bad */
387 printk(KERN_ERR "%s: IO baseregs (BIOS) are reported "
388 "as MEM, report to "
389 "<andre@linux-ide.org>.\n", d->name);
390 return -EINVAL;
394 * ide_hwif_configure - configure an IDE interface
395 * @dev: PCI device holding interface
396 * @d: IDE pci data
397 * @mate: Paired interface if any
399 * Perform the initial set up for the hardware interface structure. This
400 * is done per interface port rather than per PCI device. There may be
401 * more than one port per device.
403 * Returns the new hardware interface structure, or NULL on a failure
406 static ide_hwif_t *ide_hwif_configure(struct pci_dev *dev, ide_pci_device_t *d, ide_hwif_t *mate, int port, int irq)
408 unsigned long ctl = 0, base = 0;
409 ide_hwif_t *hwif;
411 if ((d->flags & IDEPCI_FLAG_ISA_PORTS) == 0) {
412 /* Possibly we should fail if these checks report true */
413 ide_pci_check_iomem(dev, d, 2*port);
414 ide_pci_check_iomem(dev, d, 2*port+1);
416 ctl = pci_resource_start(dev, 2*port+1);
417 base = pci_resource_start(dev, 2*port);
418 if ((ctl && !base) || (base && !ctl)) {
419 printk(KERN_ERR "%s: inconsistent baseregs (BIOS) "
420 "for port %d, skipping\n", d->name, port);
421 return NULL;
424 if (!ctl)
426 /* Use default values */
427 ctl = port ? 0x374 : 0x3f4;
428 base = port ? 0x170 : 0x1f0;
430 if ((hwif = ide_match_hwif(base, d->bootable, d->name)) == NULL)
431 return NULL; /* no room in ide_hwifs[] */
432 if (hwif->io_ports[IDE_DATA_OFFSET] != base ||
433 hwif->io_ports[IDE_CONTROL_OFFSET] != (ctl | 2)) {
434 memset(&hwif->hw, 0, sizeof(hwif->hw));
435 #ifndef IDE_ARCH_OBSOLETE_INIT
436 ide_std_init_ports(&hwif->hw, base, (ctl | 2));
437 hwif->hw.io_ports[IDE_IRQ_OFFSET] = 0;
438 #else
439 ide_init_hwif_ports(&hwif->hw, base, (ctl | 2), NULL);
440 #endif
441 memcpy(hwif->io_ports, hwif->hw.io_ports, sizeof(hwif->io_ports));
442 hwif->noprobe = !hwif->io_ports[IDE_DATA_OFFSET];
444 hwif->chipset = ide_pci;
445 hwif->pci_dev = dev;
446 hwif->cds = (struct ide_pci_device_s *) d;
447 hwif->channel = port;
449 if (!hwif->irq)
450 hwif->irq = irq;
451 if (mate) {
452 hwif->mate = mate;
453 mate->mate = hwif;
455 return hwif;
459 * ide_hwif_setup_dma - configure DMA interface
460 * @dev: PCI device
461 * @d: IDE pci data
462 * @hwif: Hardware interface we are configuring
464 * Set up the DMA base for the interface. Enable the master bits as
465 * necessary and attempt to bring the device DMA into a ready to use
466 * state
469 #ifndef CONFIG_BLK_DEV_IDEDMA_PCI
470 static void ide_hwif_setup_dma(struct pci_dev *dev, ide_pci_device_t *d, ide_hwif_t *hwif)
473 #else
474 static void ide_hwif_setup_dma(struct pci_dev *dev, ide_pci_device_t *d, ide_hwif_t *hwif)
476 u16 pcicmd;
477 pci_read_config_word(dev, PCI_COMMAND, &pcicmd);
479 if ((d->autodma == AUTODMA) ||
480 ((dev->class >> 8) == PCI_CLASS_STORAGE_IDE &&
481 (dev->class & 0x80))) {
482 unsigned long dma_base = ide_get_or_set_dma_base(hwif);
483 if (dma_base && !(pcicmd & PCI_COMMAND_MASTER)) {
485 * Set up BM-DMA capability
486 * (PnP BIOS should have done this)
488 /* default DMA off if we had to configure it here */
489 hwif->autodma = 0;
490 pci_set_master(dev);
491 if (pci_read_config_word(dev, PCI_COMMAND, &pcicmd) || !(pcicmd & PCI_COMMAND_MASTER)) {
492 printk(KERN_ERR "%s: %s error updating PCICMD\n",
493 hwif->name, d->name);
494 dma_base = 0;
497 if (dma_base) {
498 if (d->init_dma) {
499 d->init_dma(hwif, dma_base);
500 } else {
501 ide_setup_dma(hwif, dma_base, 8);
503 } else {
504 printk(KERN_INFO "%s: %s Bus-Master DMA disabled "
505 "(BIOS)\n", hwif->name, d->name);
510 #ifndef CONFIG_IDEDMA_PCI_AUTO
511 #warning CONFIG_IDEDMA_PCI_AUTO=n support is obsolete, and will be removed soon.
512 #endif
514 #endif /* CONFIG_BLK_DEV_IDEDMA_PCI*/
517 * ide_setup_pci_controller - set up IDE PCI
518 * @dev: PCI device
519 * @d: IDE PCI data
520 * @noisy: verbose flag
521 * @config: returned as 1 if we configured the hardware
523 * Set up the PCI and controller side of the IDE interface. This brings
524 * up the PCI side of the device, checks that the device is enabled
525 * and enables it if need be
528 static int ide_setup_pci_controller(struct pci_dev *dev, ide_pci_device_t *d, int noisy, int *config)
530 int ret;
531 u32 class_rev;
532 u16 pcicmd;
534 if (noisy)
535 ide_setup_pci_noise(dev, d);
537 ret = ide_pci_enable(dev, d);
538 if (ret < 0)
539 goto out;
541 ret = pci_read_config_word(dev, PCI_COMMAND, &pcicmd);
542 if (ret < 0) {
543 printk(KERN_ERR "%s: error accessing PCI regs\n", d->name);
544 goto out;
546 if (!(pcicmd & PCI_COMMAND_IO)) { /* is device disabled? */
547 ret = ide_pci_configure(dev, d);
548 if (ret < 0)
549 goto out;
550 *config = 1;
551 printk(KERN_INFO "%s: device enabled (Linux)\n", d->name);
554 pci_read_config_dword(dev, PCI_CLASS_REVISION, &class_rev);
555 class_rev &= 0xff;
556 if (noisy)
557 printk(KERN_INFO "%s: chipset revision %d\n", d->name, class_rev);
558 out:
559 return ret;
563 * ide_pci_setup_ports - configure ports/devices on PCI IDE
564 * @dev: PCI device
565 * @d: IDE pci device info
566 * @pciirq: IRQ line
567 * @index: ata index to update
569 * Scan the interfaces attached to this device and do any
570 * necessary per port setup. Attach the devices and ask the
571 * generic DMA layer to do its work for us.
573 * Normally called automaticall from do_ide_pci_setup_device,
574 * but is also used directly as a helper function by some controllers
575 * where the chipset setup is not the default PCI IDE one.
578 void ide_pci_setup_ports(struct pci_dev *dev, ide_pci_device_t *d, int pciirq, ata_index_t *index)
580 int port;
581 int at_least_one_hwif_enabled = 0;
582 ide_hwif_t *hwif, *mate = NULL;
583 u8 tmp;
585 index->all = 0xf0f0;
588 * Set up the IDE ports
591 for (port = 0; port <= 1; ++port) {
592 ide_pci_enablebit_t *e = &(d->enablebits[port]);
594 if (e->reg && (pci_read_config_byte(dev, e->reg, &tmp) ||
595 (tmp & e->mask) != e->val))
596 continue; /* port not enabled */
598 if (d->channels <= port)
599 break;
601 if ((hwif = ide_hwif_configure(dev, d, mate, port, pciirq)) == NULL)
602 continue;
604 /* setup proper ancestral information */
605 hwif->gendev.parent = &dev->dev;
607 if (hwif->channel) {
608 index->b.high = hwif->index;
609 } else {
610 index->b.low = hwif->index;
614 if (d->init_iops)
615 d->init_iops(hwif);
617 if (d->autodma == NODMA)
618 goto bypass_legacy_dma;
620 if(d->init_setup_dma)
621 d->init_setup_dma(dev, d, hwif);
622 else
623 ide_hwif_setup_dma(dev, d, hwif);
624 bypass_legacy_dma:
625 if (d->init_hwif)
626 /* Call chipset-specific routine
627 * for each enabled hwif
629 d->init_hwif(hwif);
631 mate = hwif;
632 at_least_one_hwif_enabled = 1;
634 if (!at_least_one_hwif_enabled)
635 printk(KERN_INFO "%s: neither IDE port enabled (BIOS)\n", d->name);
638 EXPORT_SYMBOL_GPL(ide_pci_setup_ports);
641 * ide_setup_pci_device() looks at the primary/secondary interfaces
642 * on a PCI IDE device and, if they are enabled, prepares the IDE driver
643 * for use with them. This generic code works for most PCI chipsets.
645 * One thing that is not standardized is the location of the
646 * primary/secondary interface "enable/disable" bits. For chipsets that
647 * we "know" about, this information is in the ide_pci_device_t struct;
648 * for all other chipsets, we just assume both interfaces are enabled.
650 static int do_ide_setup_pci_device(struct pci_dev *dev, ide_pci_device_t *d,
651 ata_index_t *index, u8 noisy)
653 static ata_index_t ata_index = { .b = { .low = 0xff, .high = 0xff } };
654 int tried_config = 0;
655 int pciirq, ret;
657 ret = ide_setup_pci_controller(dev, d, noisy, &tried_config);
658 if (ret < 0)
659 goto out;
662 * Can we trust the reported IRQ?
664 pciirq = dev->irq;
666 /* Is it an "IDE storage" device in non-PCI mode? */
667 if ((dev->class >> 8) == PCI_CLASS_STORAGE_IDE && (dev->class & 5) != 5) {
668 if (noisy)
669 printk(KERN_INFO "%s: not 100%% native mode: "
670 "will probe irqs later\n", d->name);
672 * This allows offboard ide-pci cards the enable a BIOS,
673 * verify interrupt settings of split-mirror pci-config
674 * space, place chipset into init-mode, and/or preserve
675 * an interrupt if the card is not native ide support.
677 ret = d->init_chipset ? d->init_chipset(dev, d->name) : 0;
678 if (ret < 0)
679 goto out;
680 pciirq = ret;
681 } else if (tried_config) {
682 if (noisy)
683 printk(KERN_INFO "%s: will probe irqs later\n", d->name);
684 pciirq = 0;
685 } else if (!pciirq) {
686 if (noisy)
687 printk(KERN_WARNING "%s: bad irq (%d): will probe later\n",
688 d->name, pciirq);
689 pciirq = 0;
690 } else {
691 if (d->init_chipset) {
692 ret = d->init_chipset(dev, d->name);
693 if (ret < 0)
694 goto out;
696 if (noisy)
697 printk(KERN_INFO "%s: 100%% native mode on irq %d\n",
698 d->name, pciirq);
701 /* FIXME: silent failure can happen */
703 *index = ata_index;
704 ide_pci_setup_ports(dev, d, pciirq, index);
705 out:
706 return ret;
709 int ide_setup_pci_device(struct pci_dev *dev, ide_pci_device_t *d)
711 ata_index_t index_list;
712 int ret;
714 ret = do_ide_setup_pci_device(dev, d, &index_list, 1);
715 if (ret < 0)
716 goto out;
718 if ((index_list.b.low & 0xf0) != 0xf0)
719 probe_hwif_init_with_fixup(&ide_hwifs[index_list.b.low], d->fixup);
720 if ((index_list.b.high & 0xf0) != 0xf0)
721 probe_hwif_init_with_fixup(&ide_hwifs[index_list.b.high], d->fixup);
723 create_proc_ide_interfaces();
724 out:
725 return ret;
728 EXPORT_SYMBOL_GPL(ide_setup_pci_device);
730 int ide_setup_pci_devices(struct pci_dev *dev1, struct pci_dev *dev2,
731 ide_pci_device_t *d)
733 struct pci_dev *pdev[] = { dev1, dev2 };
734 ata_index_t index_list[2];
735 int ret, i;
737 for (i = 0; i < 2; i++) {
738 ret = do_ide_setup_pci_device(pdev[i], d, index_list + i, !i);
740 * FIXME: Mom, mom, they stole me the helper function to undo
741 * do_ide_setup_pci_device() on the first device!
743 if (ret < 0)
744 goto out;
747 for (i = 0; i < 2; i++) {
748 u8 idx[2] = { index_list[i].b.low, index_list[i].b.high };
749 int j;
751 for (j = 0; j < 2; j++) {
752 if ((idx[j] & 0xf0) != 0xf0)
753 probe_hwif_init(ide_hwifs + idx[j]);
757 create_proc_ide_interfaces();
758 out:
759 return ret;
762 EXPORT_SYMBOL_GPL(ide_setup_pci_devices);
765 * Module interfaces
768 static int pre_init = 1; /* Before first ordered IDE scan */
769 static LIST_HEAD(ide_pci_drivers);
772 * __ide_pci_register_driver - attach IDE driver
773 * @driver: pci driver
774 * @module: owner module of the driver
776 * Registers a driver with the IDE layer. The IDE layer arranges that
777 * boot time setup is done in the expected device order and then
778 * hands the controllers off to the core PCI code to do the rest of
779 * the work.
781 * The driver_data of the driver table must point to an ide_pci_device_t
782 * describing the interface.
784 * Returns are the same as for pci_register_driver
787 int __ide_pci_register_driver(struct pci_driver *driver, struct module *module)
789 if(!pre_init)
790 return __pci_register_driver(driver, module);
791 driver->driver.owner = module;
792 list_add_tail(&driver->node, &ide_pci_drivers);
793 return 0;
796 EXPORT_SYMBOL_GPL(__ide_pci_register_driver);
799 * ide_unregister_pci_driver - unregister an IDE driver
800 * @driver: driver to remove
802 * Unregister a currently installed IDE driver. Returns are the same
803 * as for pci_unregister_driver
806 void ide_pci_unregister_driver(struct pci_driver *driver)
808 if(!pre_init)
809 pci_unregister_driver(driver);
810 else
811 list_del(&driver->node);
814 EXPORT_SYMBOL_GPL(ide_pci_unregister_driver);
817 * ide_scan_pcidev - find an IDE driver for a device
818 * @dev: PCI device to check
820 * Look for an IDE driver to handle the device we are considering.
821 * This is only used during boot up to get the ordering correct. After
822 * boot up the pci layer takes over the job.
825 static int __init ide_scan_pcidev(struct pci_dev *dev)
827 struct list_head *l;
828 struct pci_driver *d;
830 list_for_each(l, &ide_pci_drivers)
832 d = list_entry(l, struct pci_driver, node);
833 if(d->id_table)
835 const struct pci_device_id *id = pci_match_id(d->id_table, dev);
836 if(id != NULL)
838 if(d->probe(dev, id) >= 0)
840 dev->driver = d;
841 return 1;
846 return 0;
850 * ide_scan_pcibus - perform the initial IDE driver scan
851 * @scan_direction: set for reverse order scanning
853 * Perform the initial bus rather than driver ordered scan of the
854 * PCI drivers. After this all IDE pci handling becomes standard
855 * module ordering not traditionally ordered.
858 void __init ide_scan_pcibus (int scan_direction)
860 struct pci_dev *dev = NULL;
861 struct pci_driver *d;
862 struct list_head *l, *n;
864 pre_init = 0;
865 if (!scan_direction) {
866 while ((dev = pci_find_device(PCI_ANY_ID, PCI_ANY_ID, dev)) != NULL) {
867 ide_scan_pcidev(dev);
869 } else {
870 while ((dev = pci_find_device_reverse(PCI_ANY_ID, PCI_ANY_ID, dev)) != NULL) {
871 ide_scan_pcidev(dev);
876 * Hand the drivers over to the PCI layer now we
877 * are post init.
880 list_for_each_safe(l, n, &ide_pci_drivers)
882 list_del(l);
883 d = list_entry(l, struct pci_driver, node);
884 __pci_register_driver(d, d->driver.owner);