2 * linux/drivers/ide/setup-pci.c Version 1.14 2004/08/10
4 * Copyright (c) 1998-2000 Andre Hedrick <andre@linux-ide.org>
5 * Copyright (c) 2004 Red Hat <alan@redhat.com>
7 * Copyright (c) 1995-1998 Mark Lord
8 * May be copied or modified under the terms of the GNU General Public License
11 * Split the set up function into multiple functions
13 * Fix misreporting of I/O v MMIO problems
14 * Initial fixups for simplex devices
19 * This module provides support for automatic detection and
20 * configuration of all PCI IDE interfaces present in a system.
23 #include <linux/config.h>
24 #include <linux/module.h>
25 #include <linux/types.h>
26 #include <linux/kernel.h>
27 #include <linux/pci.h>
28 #include <linux/init.h>
29 #include <linux/timer.h>
31 #include <linux/interrupt.h>
32 #include <linux/ide.h>
39 * ide_match_hwif - match a PCI IDE against an ide_hwif
40 * @io_base: I/O base of device
41 * @bootable: set if its bootable
42 * @name: name of device
44 * Match a PCI IDE port against an entry in ide_hwifs[],
45 * based on io_base port if possible. Return the matching hwif,
46 * or a new hwif. If we find an error (clashing, out of devices, etc)
47 * return NULL. The caller must hold the ide_cfg_sem.
49 * FIXME: we need to handle mmio matches here too
52 static ide_hwif_t *ide_match_hwif(unsigned long io_base, u8 bootable, const char *name)
58 * Look for a hwif with matching io_base specified using
59 * parameters to ide_setup().
61 for (h = 0; h < MAX_HWIFS; ++h) {
63 if (hwif->io_ports[IDE_DATA_OFFSET] == io_base) {
64 if (hwif->chipset == ide_forced)
65 return hwif; /* a perfect match */
69 * Look for a hwif with matching io_base default value.
70 * If chipset is "ide_unknown", then claim that hwif slot.
71 * Otherwise, some other chipset has already claimed it.. :(
73 for (h = 0; h < MAX_HWIFS; ++h) {
75 if (hwif->io_ports[IDE_DATA_OFFSET] == io_base) {
76 if (hwif->chipset == ide_unknown)
77 return hwif; /* match */
78 printk(KERN_ERR "%s: port 0x%04lx already claimed by %s\n",
79 name, io_base, hwif->name);
80 return NULL; /* already claimed */
84 * Okay, there is no hwif matching our io_base,
85 * so we'll just claim an unassigned slot.
86 * Give preference to claiming other slots before claiming ide0/ide1,
87 * just in case there's another interface yet-to-be-scanned
88 * which uses ports 1f0/170 (the ide0/ide1 defaults).
90 * Unless there is a bootable card that does not use the standard
91 * ports 1f0/170 (the ide0/ide1 defaults). The (bootable) flag.
93 * FIXME: migrate use of ide_unknown to also use ->configured
96 for (h = 0; h < MAX_HWIFS; ++h) {
98 if (hwif->chipset == ide_unknown)
99 return hwif; /* pick an unused entry */
102 for (h = 2; h < MAX_HWIFS; ++h) {
103 hwif = ide_hwifs + h;
104 if (hwif->chipset == ide_unknown)
105 return hwif; /* pick an unused entry */
108 for (h = 0; h < 2; ++h) {
109 hwif = ide_hwifs + h;
110 if (hwif->chipset == ide_unknown)
111 return hwif; /* pick an unused entry */
113 printk(KERN_ERR "%s: too many IDE interfaces, no room in table\n", name);
118 * ide_setup_pci_baseregs - place a PCI IDE controller native
119 * @dev: PCI device of interface to switch native
120 * @name: Name of interface
122 * We attempt to place the PCI interface into PCI native mode. If
123 * we succeed the BARs are ok and the controller is in PCI mode.
124 * Returns 0 on success or an errno code.
126 * FIXME: if we program the interface and then fail to set the BARS
127 * we don't switch it back to legacy mode. Do we actually care ??
130 static int ide_setup_pci_baseregs (struct pci_dev *dev, const char *name)
135 * Place both IDE interfaces into PCI "native" mode:
137 if (pci_read_config_byte(dev, PCI_CLASS_PROG, &progif) ||
139 if ((progif & 0xa) != 0xa) {
140 printk(KERN_INFO "%s: device not capable of full "
141 "native PCI mode\n", name);
144 printk("%s: placing both ports into native PCI mode\n", name);
145 (void) pci_write_config_byte(dev, PCI_CLASS_PROG, progif|5);
146 if (pci_read_config_byte(dev, PCI_CLASS_PROG, &progif) ||
148 printk(KERN_ERR "%s: rewrite of PROGIF failed, wanted "
149 "0x%04x, got 0x%04x\n",
150 name, progif|5, progif);
157 #ifdef CONFIG_BLK_DEV_IDEDMA_PCI
159 #ifdef CONFIG_BLK_DEV_IDEDMA_FORCED
161 * Long lost data from 2.0.34 that is now in 2.0.39
163 * This was used in ./drivers/block/triton.c to do DMA Base address setup
164 * when PnP failed. Oh the things we forget. I believe this was part
165 * of SFF-8038i that has been withdrawn from public access... :-((
167 #define DEFAULT_BMIBA 0xe800 /* in case BIOS did not init it */
168 #define DEFAULT_BMCRBA 0xcc00 /* VIA's default value */
169 #define DEFAULT_BMALIBA 0xd400 /* ALI's default value */
170 #endif /* CONFIG_BLK_DEV_IDEDMA_FORCED */
173 * ide_get_or_set_dma_base - setup BMIBA
176 * Fetch the DMA Bus-Master-I/O-Base-Address (BMIBA) from PCI space:
177 * If need be we set up the DMA base. Where a device has a partner that
178 * is already in DMA mode we check and enforce IDE simplex rules.
181 static unsigned long ide_get_or_set_dma_base (ide_hwif_t *hwif)
183 unsigned long dma_base = 0;
184 struct pci_dev *dev = hwif->pci_dev;
186 #ifdef CONFIG_BLK_DEV_IDEDMA_FORCED
187 int second_chance = 0;
189 second_chance_to_dma:
190 #endif /* CONFIG_BLK_DEV_IDEDMA_FORCED */
192 if ((hwif->mmio) && (hwif->dma_base))
193 return hwif->dma_base;
195 if (hwif->mate && hwif->mate->dma_base) {
196 dma_base = hwif->mate->dma_base - (hwif->channel ? 0 : 8);
198 dma_base = (hwif->mmio) ?
199 ((unsigned long) hwif->hwif_data) :
200 (pci_resource_start(dev, 4));
202 printk(KERN_ERR "%s: dma_base is invalid (0x%04lx)\n",
203 hwif->cds->name, dma_base);
208 #ifdef CONFIG_BLK_DEV_IDEDMA_FORCED
209 /* FIXME - should use pci_assign_resource surely */
210 if ((!dma_base) && (!second_chance)) {
211 unsigned long set_bmiba = 0;
213 switch(dev->vendor) {
214 case PCI_VENDOR_ID_AL:
215 set_bmiba = DEFAULT_BMALIBA; break;
216 case PCI_VENDOR_ID_VIA:
217 set_bmiba = DEFAULT_BMCRBA; break;
218 case PCI_VENDOR_ID_INTEL:
219 set_bmiba = DEFAULT_BMIBA; break;
223 pci_write_config_dword(dev, 0x20, set_bmiba|1);
224 goto second_chance_to_dma;
226 #endif /* CONFIG_BLK_DEV_IDEDMA_FORCED */
230 dma_base += hwif->channel ? 8 : 0;
232 switch(dev->device) {
233 case PCI_DEVICE_ID_AL_M5219:
234 case PCI_DEVICE_ID_AL_M5229:
235 case PCI_DEVICE_ID_AMD_VIPER_7409:
236 case PCI_DEVICE_ID_CMD_643:
237 case PCI_DEVICE_ID_SERVERWORKS_CSB5IDE:
238 simplex_stat = hwif->INB(dma_base + 2);
239 hwif->OUTB((simplex_stat&0x60),(dma_base + 2));
240 simplex_stat = hwif->INB(dma_base + 2);
241 if (simplex_stat & 0x80) {
242 printk(KERN_INFO "%s: simplex device: "
249 * If the device claims "simplex" DMA,
250 * this means only one of the two interfaces
251 * can be trusted with DMA at any point in time.
252 * So we should enable DMA only on one of the
255 simplex_stat = hwif->INB(dma_base + 2);
256 if (simplex_stat & 0x80) {
257 /* simplex device? */
260 * At this point we haven't probed the drives so we can't make the
261 * appropriate decision. Really we should defer this problem
262 * until we tune the drive then try to grab DMA ownership if we want
263 * to be the DMA end. This has to be become dynamic to handle hot
266 /* Don't enable DMA on a simplex channel with no drives */
267 if (!hwif->drives[0].present && !hwif->drives[1].present)
269 printk(KERN_INFO "%s: simplex device with no drives: DMA disabled\n",
273 /* If our other channel has DMA then we cannot */
276 if(hwif->mate && hwif->mate->dma_base)
278 printk(KERN_INFO "%s: simplex device: "
288 #endif /* CONFIG_BLK_DEV_IDEDMA_PCI */
290 void ide_setup_pci_noise (struct pci_dev *dev, ide_pci_device_t *d)
292 printk(KERN_INFO "%s: IDE controller at PCI slot %s\n",
293 d->name, pci_name(dev));
296 EXPORT_SYMBOL_GPL(ide_setup_pci_noise);
300 * ide_pci_enable - do PCI enables
302 * @d: IDE pci device data
304 * Enable the IDE PCI device. We attempt to enable the device in full
305 * but if that fails then we only need BAR4 so we will enable that.
307 * Returns zero on success or an error code
310 static int ide_pci_enable(struct pci_dev *dev, ide_pci_device_t *d)
313 if (pci_enable_device(dev)) {
314 if (pci_enable_device_bars(dev, 1 << 4)) {
315 printk(KERN_WARNING "%s: (ide_setup_pci_device:) "
316 "Could not enable device.\n", d->name);
319 printk(KERN_WARNING "%s: BIOS configuration fixed.\n", d->name);
323 * assume all devices can do 32-bit dma for now. we can add a
324 * dma mask field to the ide_pci_device_t if we need it (or let
325 * lower level driver set the dma mask)
327 if (pci_set_dma_mask(dev, 0xffffffff)) {
328 printk(KERN_ERR "%s: can't set dma mask\n", d->name);
332 /* FIXME: Temporary - until we put in the hotplug interface logic
333 Check that the bits we want are not in use by someone else */
334 if (pci_request_region(dev, 4, "ide_tmp"))
336 pci_release_region(dev, 4);
342 * ide_pci_configure - configure an unconfigured device
344 * @d: IDE pci device data
346 * Enable and configure the PCI device we have been passed.
347 * Returns zero on success or an error code.
350 static int ide_pci_configure(struct pci_dev *dev, ide_pci_device_t *d)
354 * PnP BIOS was *supposed* to have setup this device, but we
355 * can do it ourselves, so long as the BIOS has assigned an IRQ
356 * (or possibly the device is using a "legacy header" for IRQs).
357 * Maybe the user deliberately *disabled* the device,
358 * but we'll eventually ignore it again if no drives respond.
360 if (ide_setup_pci_baseregs(dev, d->name) || pci_write_config_word(dev, PCI_COMMAND, pcicmd|PCI_COMMAND_IO))
362 printk(KERN_INFO "%s: device disabled (BIOS)\n", d->name);
365 if (pci_read_config_word(dev, PCI_COMMAND, &pcicmd)) {
366 printk(KERN_ERR "%s: error accessing PCI regs\n", d->name);
369 if (!(pcicmd & PCI_COMMAND_IO)) {
370 printk(KERN_ERR "%s: unable to enable IDE controller\n", d->name);
377 * ide_pci_check_iomem - check a register is I/O
382 * Checks if a BAR is configured and points to MMIO space. If so
383 * print an error and return an error code. Otherwise return 0
386 static int ide_pci_check_iomem(struct pci_dev *dev, ide_pci_device_t *d, int bar)
388 ulong flags = pci_resource_flags(dev, bar);
391 if (!flags || pci_resource_len(dev, bar) == 0)
395 if(flags & PCI_BASE_ADDRESS_IO_MASK)
399 printk(KERN_ERR "%s: IO baseregs (BIOS) are reported "
401 "<andre@linux-ide.org>.\n", d->name);
406 * ide_hwif_configure - configure an IDE interface
407 * @dev: PCI device holding interface
409 * @mate: Paired interface if any
411 * Perform the initial set up for the hardware interface structure. This
412 * is done per interface port rather than per PCI device. There may be
413 * more than one port per device.
415 * Returns the new hardware interface structure, or NULL on a failure
418 static ide_hwif_t *ide_hwif_configure(struct pci_dev *dev, ide_pci_device_t *d, ide_hwif_t *mate, int port, int irq)
420 unsigned long ctl = 0, base = 0;
423 if ((d->flags & IDEPCI_FLAG_ISA_PORTS) == 0) {
424 /* Possibly we should fail if these checks report true */
425 ide_pci_check_iomem(dev, d, 2*port);
426 ide_pci_check_iomem(dev, d, 2*port+1);
428 ctl = pci_resource_start(dev, 2*port+1);
429 base = pci_resource_start(dev, 2*port);
430 if ((ctl && !base) || (base && !ctl)) {
431 printk(KERN_ERR "%s: inconsistent baseregs (BIOS) "
432 "for port %d, skipping\n", d->name, port);
438 /* Use default values */
439 ctl = port ? 0x374 : 0x3f4;
440 base = port ? 0x170 : 0x1f0;
444 * Protect against a hwif being unloaded as we attach to it
448 if ((hwif = ide_match_hwif(base, d->bootable, d->name)) == NULL)
451 return NULL; /* no room in ide_hwifs[] */
454 if (hwif->io_ports[IDE_DATA_OFFSET] != base ||
455 hwif->io_ports[IDE_CONTROL_OFFSET] != (ctl | 2)) {
456 memset(&hwif->hw, 0, sizeof(hwif->hw));
457 ide_init_hwif_ports(&hwif->hw, base, (ctl | 2), NULL);
458 memcpy(hwif->io_ports, hwif->hw.io_ports, sizeof(hwif->io_ports));
459 hwif->noprobe = !hwif->io_ports[IDE_DATA_OFFSET];
461 hwif->chipset = ide_pci;
463 hwif->cds = (struct ide_pci_device_s *) d;
464 hwif->channel = port;
465 hwif->configured = 1;
479 * ide_hwif_setup_dma - configure DMA interface
482 * @hwif: Hardware interface we are configuring
484 * Set up the DMA base for the interface. Enable the master bits as
485 * necessary and attempt to bring the device DMA into a ready to use
489 #ifndef CONFIG_BLK_DEV_IDEDMA_PCI
490 static void ide_hwif_setup_dma(struct pci_dev *dev, ide_pci_device_t *d, ide_hwif_t *hwif)
494 static void ide_hwif_setup_dma(struct pci_dev *dev, ide_pci_device_t *d, ide_hwif_t *hwif)
497 pci_read_config_word(dev, PCI_COMMAND, &pcicmd);
499 if ((d->autodma == AUTODMA) ||
500 ((dev->class >> 8) == PCI_CLASS_STORAGE_IDE &&
501 (dev->class & 0x80))) {
502 unsigned long dma_base = ide_get_or_set_dma_base(hwif);
503 if (dma_base && !(pcicmd & PCI_COMMAND_MASTER)) {
505 * Set up BM-DMA capability
506 * (PnP BIOS should have done this)
508 if ((d->flags & IDEPCI_FLAG_FORCE_MASTER) == 0) {
510 * default DMA off if we had to
516 if (pci_read_config_word(dev, PCI_COMMAND, &pcicmd) || !(pcicmd & PCI_COMMAND_MASTER)) {
517 printk(KERN_ERR "%s: %s error updating PCICMD\n",
518 hwif->name, d->name);
524 d->init_dma(hwif, dma_base);
526 ide_setup_dma(hwif, dma_base, 8);
529 printk(KERN_INFO "%s: %s Bus-Master DMA disabled "
530 "(BIOS)\n", hwif->name, d->name);
534 #endif /* CONFIG_BLK_DEV_IDEDMA_PCI*/
537 * ide_setup_pci_controller - set up IDE PCI
540 * @noisy: verbose flag
541 * @config: returned as 1 if we configured the hardware
543 * Set up the PCI and controller side of the IDE interface. This brings
544 * up the PCI side of the device, checks that the device is enabled
545 * and enables it if need be
548 static int ide_setup_pci_controller(struct pci_dev *dev, ide_pci_device_t *d, int noisy, int *config)
558 ide_setup_pci_noise(dev, d);
560 if (ide_pci_enable(dev, d))
563 if (pci_read_config_word(dev, PCI_COMMAND, &pcicmd)) {
564 printk(KERN_ERR "%s: error accessing PCI regs\n", d->name);
567 if (!(pcicmd & PCI_COMMAND_IO)) { /* is device disabled? */
568 if (ide_pci_configure(dev, d))
570 /* default DMA off if we had to configure it here */
573 printk(KERN_INFO "%s: device enabled (Linux)\n", d->name);
576 pci_read_config_dword(dev, PCI_CLASS_REVISION, &class_rev);
579 printk(KERN_INFO "%s: chipset revision %d\n", d->name, class_rev);
584 * ide_pci_setup_ports - configure ports/devices on PCI IDE
586 * @d: IDE pci device info
587 * @autodma: Should we enable DMA
589 * @index: ata index to update
591 * Scan the interfaces attached to this device and do any
592 * necessary per port setup. Attach the devices and ask the
593 * generic DMA layer to do its work for us.
595 * Normally called automaticall from do_ide_pci_setup_device,
596 * but is also used directly as a helper function by some controllers
597 * where the chipset setup is not the default PCI IDE one.
600 void ide_pci_setup_ports(struct pci_dev *dev, ide_pci_device_t *d, int autodma, int pciirq, ata_index_t *index)
603 int at_least_one_hwif_enabled = 0;
604 ide_hwif_t *hwif, *mate = NULL;
605 static int secondpdc = 0;
611 * Set up the IDE ports
614 for (port = 0; port <= 1; ++port) {
615 ide_pci_enablebit_t *e = &(d->enablebits[port]);
618 * If this is a Promise FakeRaid controller,
619 * the 2nd controller will be marked as
620 * disabled while it is actually there and enabled
621 * by the bios for raid purposes.
622 * Skip the normal "is it enabled" test for those.
624 if ((d->flags & IDEPCI_FLAG_FORCE_PDC) &&
625 (secondpdc++==1) && (port==1))
628 if (e->reg && (pci_read_config_byte(dev, e->reg, &tmp) ||
629 (tmp & e->mask) != e->val))
630 continue; /* port not enabled */
633 if (d->channels <= port)
636 if ((hwif = ide_hwif_configure(dev, d, mate, port, pciirq)) == NULL)
639 /* setup proper ancestral information */
640 hwif->gendev.parent = &dev->dev;
643 index->b.high = hwif->index;
645 index->b.low = hwif->index;
652 if (d->autodma == NODMA)
653 goto bypass_legacy_dma;
654 if (d->autodma == NOAUTODMA)
659 if(d->init_setup_dma)
660 d->init_setup_dma(dev, d, hwif);
662 ide_hwif_setup_dma(dev, d, hwif);
665 /* Call chipset-specific routine
666 * for each enabled hwif
671 at_least_one_hwif_enabled = 1;
673 if (!at_least_one_hwif_enabled)
674 printk(KERN_INFO "%s: neither IDE port enabled (BIOS)\n", d->name);
677 EXPORT_SYMBOL_GPL(ide_pci_setup_ports);
680 * ide_setup_pci_device() looks at the primary/secondary interfaces
681 * on a PCI IDE device and, if they are enabled, prepares the IDE driver
682 * for use with them. This generic code works for most PCI chipsets.
684 * One thing that is not standardized is the location of the
685 * primary/secondary interface "enable/disable" bits. For chipsets that
686 * we "know" about, this information is in the ide_pci_device_t struct;
687 * for all other chipsets, we just assume both interfaces are enabled.
689 static ata_index_t do_ide_setup_pci_device (struct pci_dev *dev, ide_pci_device_t *d, u8 noisy)
693 int tried_config = 0;
694 ata_index_t index = { .b = { .low = 0xff, .high = 0xff } };
696 if((autodma = ide_setup_pci_controller(dev, d, noisy, &tried_config)) < 0)
700 * Can we trust the reported IRQ?
704 /* Is it an "IDE storage" device in non-PCI mode? */
705 if ((dev->class >> 8) == PCI_CLASS_STORAGE_IDE && (dev->class & 5) != 5) {
707 printk(KERN_INFO "%s: not 100%% native mode: "
708 "will probe irqs later\n", d->name);
710 * This allows offboard ide-pci cards the enable a BIOS,
711 * verify interrupt settings of split-mirror pci-config
712 * space, place chipset into init-mode, and/or preserve
713 * an interrupt if the card is not native ide support.
715 pciirq = (d->init_chipset) ? d->init_chipset(dev, d->name) : 0;
716 } else if (tried_config) {
718 printk(KERN_INFO "%s: will probe irqs later\n", d->name);
720 } else if (!pciirq) {
722 printk(KERN_WARNING "%s: bad irq (%d): will probe later\n",
728 if(d->init_chipset(dev, d->name) < 0)
733 printk(KERN_INFO "%s: 100%% native mode on irq %s\n",
734 d->name, __irq_itoa(pciirq));
736 printk(KERN_INFO "%s: 100%% native mode on irq %d\n",
741 if(pciirq < 0) /* Error not an IRQ */
744 ide_pci_setup_ports(dev, d, autodma, pciirq, &index);
750 * probe_pci_hwif_init - probe the hwif then allow fixups
751 * @hwif: interface to probe
754 * Perform the generic probe and if it is successful invoke any
755 * remaining post probe fixup logic in the driver itself.
757 static void probe_pci_hwif_init(ide_hwif_t *hwif, ide_pci_device_t *d) {
758 probe_hwif_init_with_fixup(hwif, d->fixup);
761 void ide_setup_pci_device (struct pci_dev *dev, ide_pci_device_t *d)
763 ata_index_t index_list = do_ide_setup_pci_device(dev, d, 1);
765 if ((index_list.b.low & 0xf0) != 0xf0)
766 probe_pci_hwif_init(&ide_hwifs[index_list.b.low], d);
767 if ((index_list.b.high & 0xf0) != 0xf0)
768 probe_pci_hwif_init(&ide_hwifs[index_list.b.high], d);
770 create_proc_ide_interfaces();
773 EXPORT_SYMBOL_GPL(ide_setup_pci_device);
775 void ide_setup_pci_devices (struct pci_dev *dev, struct pci_dev *dev2, ide_pci_device_t *d)
777 ata_index_t index_list = do_ide_setup_pci_device(dev, d, 1);
778 ata_index_t index_list2 = do_ide_setup_pci_device(dev2, d, 0);
780 if ((index_list.b.low & 0xf0) != 0xf0)
781 probe_pci_hwif_init(&ide_hwifs[index_list.b.low], d);
782 if ((index_list.b.high & 0xf0) != 0xf0)
783 probe_pci_hwif_init(&ide_hwifs[index_list.b.high], d);
784 if ((index_list2.b.low & 0xf0) != 0xf0)
785 probe_pci_hwif_init(&ide_hwifs[index_list2.b.low], d);
786 if ((index_list2.b.high & 0xf0) != 0xf0)
787 probe_pci_hwif_init(&ide_hwifs[index_list2.b.high], d);
789 create_proc_ide_interfaces();
792 EXPORT_SYMBOL_GPL(ide_setup_pci_devices);
795 * ide_pci_remove_hwifs - remove PCI interfaces
798 * Remove any hwif attached to this PCI device. This will call
799 * back the various hwif->remove functions. In order to get the
800 * best results when delays occur we kill the iops before we
801 * potentially start blocking for long periods untangling the
804 * Takes the ide_cfg_sem in order to protect against races with
805 * new/old hwifs. Calls functions that take all the other locks
806 * so should be called with no locks held.
809 void ide_pci_remove_hwifs(struct pci_dev *dev)
812 ide_hwif_t *hwif = ide_hwifs;
816 for(i = 0; i < MAX_HWIFS; i++)
818 if(hwif->configured && hwif->pci_dev == dev)
820 removed_hwif_iops(hwif);
828 for(i = 0; i < MAX_HWIFS; i++)
830 if(hwif->configured && hwif->pci_dev == dev)
831 __ide_unregister_hwif(hwif);
838 EXPORT_SYMBOL_GPL(ide_pci_remove_hwifs);
845 static int pre_init = 1; /* Before first ordered IDE scan */
846 static LIST_HEAD(ide_pci_drivers);
849 * ide_register_pci_driver - attach IDE driver
850 * @driver: pci driver
852 * Registers a driver with the IDE layer. The IDE layer arranges that
853 * boot time setup is done in the expected device order and then
854 * hands the controllers off to the core PCI code to do the rest of
857 * The driver_data of the driver table must point to an ide_pci_device_t
858 * describing the interface.
860 * Returns are the same as for pci_register_driver
863 int ide_pci_register_driver(struct pci_driver *driver)
866 return pci_module_init(driver);
867 list_add_tail(&driver->node, &ide_pci_drivers);
871 EXPORT_SYMBOL_GPL(ide_pci_register_driver);
874 * ide_unregister_pci_driver - unregister an IDE driver
875 * @driver: driver to remove
877 * Unregister a currently installed IDE driver. Returns are the same
878 * as for pci_unregister_driver
881 void ide_pci_unregister_driver(struct pci_driver *driver)
884 pci_unregister_driver(driver);
886 list_del(&driver->node);
889 EXPORT_SYMBOL_GPL(ide_pci_unregister_driver);
892 * ide_scan_pcidev - find an IDE driver for a device
893 * @dev: PCI device to check
895 * Look for an IDE driver to handle the device we are considering.
896 * This is only used during boot up to get the ordering correct. After
897 * boot up the pci layer takes over the job.
900 static int __init ide_scan_pcidev(struct pci_dev *dev)
903 struct pci_driver *d;
905 list_for_each(l, &ide_pci_drivers)
907 d = list_entry(l, struct pci_driver, node);
910 const struct pci_device_id *id = pci_match_device(d->id_table, dev);
913 if(d->probe(dev, id) >= 0)
925 * ide_scan_pcibus - perform the initial IDE driver scan
926 * @scan_direction: set for reverse order scanning
928 * Perform the initial bus rather than driver ordered scan of the
929 * PCI drivers. After this all IDE pci handling becomes standard
930 * module ordering not traditionally ordered.
933 void __init ide_scan_pcibus (int scan_direction)
935 struct pci_dev *dev = NULL;
936 struct pci_driver *d;
937 struct list_head *l, *n;
940 if (!scan_direction) {
941 while ((dev = pci_find_device(PCI_ANY_ID, PCI_ANY_ID, dev)) != NULL) {
942 ide_scan_pcidev(dev);
945 while ((dev = pci_find_device_reverse(PCI_ANY_ID, PCI_ANY_ID, dev)) != NULL) {
946 ide_scan_pcidev(dev);
951 * Hand the drivers over to the PCI layer now we
955 list_for_each_safe(l, n, &ide_pci_drivers)
958 d = list_entry(l, struct pci_driver, node);
959 pci_register_driver(d);