Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8 | */ |
| 9 | |
| 10 | /* |
| 11 | * This module provides support for automatic detection and |
| 12 | * configuration of all PCI IDE interfaces present in a system. |
| 13 | */ |
| 14 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15 | #include <linux/module.h> |
| 16 | #include <linux/types.h> |
| 17 | #include <linux/kernel.h> |
| 18 | #include <linux/pci.h> |
| 19 | #include <linux/init.h> |
| 20 | #include <linux/timer.h> |
| 21 | #include <linux/mm.h> |
| 22 | #include <linux/interrupt.h> |
| 23 | #include <linux/ide.h> |
| 24 | #include <linux/dma-mapping.h> |
| 25 | |
| 26 | #include <asm/io.h> |
| 27 | #include <asm/irq.h> |
| 28 | |
| 29 | |
| 30 | /** |
| 31 | * ide_match_hwif - match a PCI IDE against an ide_hwif |
| 32 | * @io_base: I/O base of device |
| 33 | * @bootable: set if its bootable |
| 34 | * @name: name of device |
| 35 | * |
| 36 | * Match a PCI IDE port against an entry in ide_hwifs[], |
| 37 | * based on io_base port if possible. Return the matching hwif, |
| 38 | * or a new hwif. If we find an error (clashing, out of devices, etc) |
| 39 | * return NULL |
| 40 | * |
| 41 | * FIXME: we need to handle mmio matches here too |
| 42 | */ |
| 43 | |
| 44 | static ide_hwif_t *ide_match_hwif(unsigned long io_base, u8 bootable, const char *name) |
| 45 | { |
| 46 | int h; |
| 47 | ide_hwif_t *hwif; |
| 48 | |
| 49 | /* |
| 50 | * Look for a hwif with matching io_base specified using |
| 51 | * parameters to ide_setup(). |
| 52 | */ |
| 53 | for (h = 0; h < MAX_HWIFS; ++h) { |
| 54 | hwif = &ide_hwifs[h]; |
| 55 | if (hwif->io_ports[IDE_DATA_OFFSET] == io_base) { |
| 56 | if (hwif->chipset == ide_forced) |
| 57 | return hwif; /* a perfect match */ |
| 58 | } |
| 59 | } |
| 60 | /* |
| 61 | * Look for a hwif with matching io_base default value. |
| 62 | * If chipset is "ide_unknown", then claim that hwif slot. |
| 63 | * Otherwise, some other chipset has already claimed it.. :( |
| 64 | */ |
| 65 | for (h = 0; h < MAX_HWIFS; ++h) { |
| 66 | hwif = &ide_hwifs[h]; |
| 67 | if (hwif->io_ports[IDE_DATA_OFFSET] == io_base) { |
| 68 | if (hwif->chipset == ide_unknown) |
| 69 | return hwif; /* match */ |
| 70 | printk(KERN_ERR "%s: port 0x%04lx already claimed by %s\n", |
| 71 | name, io_base, hwif->name); |
| 72 | return NULL; /* already claimed */ |
| 73 | } |
| 74 | } |
| 75 | /* |
| 76 | * Okay, there is no hwif matching our io_base, |
| 77 | * so we'll just claim an unassigned slot. |
| 78 | * Give preference to claiming other slots before claiming ide0/ide1, |
| 79 | * just in case there's another interface yet-to-be-scanned |
| 80 | * which uses ports 1f0/170 (the ide0/ide1 defaults). |
| 81 | * |
| 82 | * Unless there is a bootable card that does not use the standard |
| 83 | * ports 1f0/170 (the ide0/ide1 defaults). The (bootable) flag. |
| 84 | */ |
| 85 | if (bootable) { |
| 86 | for (h = 0; h < MAX_HWIFS; ++h) { |
| 87 | hwif = &ide_hwifs[h]; |
| 88 | if (hwif->chipset == ide_unknown) |
| 89 | return hwif; /* pick an unused entry */ |
| 90 | } |
| 91 | } else { |
| 92 | for (h = 2; h < MAX_HWIFS; ++h) { |
| 93 | hwif = ide_hwifs + h; |
| 94 | if (hwif->chipset == ide_unknown) |
| 95 | return hwif; /* pick an unused entry */ |
| 96 | } |
| 97 | } |
Matt Mackall | 83d7dbc | 2006-10-03 01:14:16 -0700 | [diff] [blame] | 98 | for (h = 0; h < 2 && h < MAX_HWIFS; ++h) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 99 | hwif = ide_hwifs + h; |
| 100 | if (hwif->chipset == ide_unknown) |
| 101 | return hwif; /* pick an unused entry */ |
| 102 | } |
| 103 | printk(KERN_ERR "%s: too many IDE interfaces, no room in table\n", name); |
| 104 | return NULL; |
| 105 | } |
| 106 | |
| 107 | /** |
| 108 | * ide_setup_pci_baseregs - place a PCI IDE controller native |
| 109 | * @dev: PCI device of interface to switch native |
| 110 | * @name: Name of interface |
| 111 | * |
| 112 | * We attempt to place the PCI interface into PCI native mode. If |
| 113 | * we succeed the BARs are ok and the controller is in PCI mode. |
| 114 | * Returns 0 on success or an errno code. |
| 115 | * |
| 116 | * FIXME: if we program the interface and then fail to set the BARS |
| 117 | * we don't switch it back to legacy mode. Do we actually care ?? |
| 118 | */ |
| 119 | |
| 120 | static int ide_setup_pci_baseregs (struct pci_dev *dev, const char *name) |
| 121 | { |
| 122 | u8 progif = 0; |
| 123 | |
| 124 | /* |
| 125 | * Place both IDE interfaces into PCI "native" mode: |
| 126 | */ |
| 127 | if (pci_read_config_byte(dev, PCI_CLASS_PROG, &progif) || |
| 128 | (progif & 5) != 5) { |
| 129 | if ((progif & 0xa) != 0xa) { |
| 130 | printk(KERN_INFO "%s: device not capable of full " |
| 131 | "native PCI mode\n", name); |
| 132 | return -EOPNOTSUPP; |
| 133 | } |
| 134 | printk("%s: placing both ports into native PCI mode\n", name); |
| 135 | (void) pci_write_config_byte(dev, PCI_CLASS_PROG, progif|5); |
| 136 | if (pci_read_config_byte(dev, PCI_CLASS_PROG, &progif) || |
| 137 | (progif & 5) != 5) { |
| 138 | printk(KERN_ERR "%s: rewrite of PROGIF failed, wanted " |
| 139 | "0x%04x, got 0x%04x\n", |
| 140 | name, progif|5, progif); |
| 141 | return -EOPNOTSUPP; |
| 142 | } |
| 143 | } |
| 144 | return 0; |
| 145 | } |
| 146 | |
| 147 | #ifdef CONFIG_BLK_DEV_IDEDMA_PCI |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 148 | /** |
| 149 | * ide_get_or_set_dma_base - setup BMIBA |
Bartlomiej Zolnierkiewicz | 9ffcf36 | 2007-10-19 00:30:07 +0200 | [diff] [blame] | 150 | * @d: IDE pci device data |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 151 | * @hwif: Interface |
| 152 | * |
Bartlomiej Zolnierkiewicz | c58e79d | 2007-10-16 22:29:56 +0200 | [diff] [blame] | 153 | * Fetch the DMA Bus-Master-I/O-Base-Address (BMIBA) from PCI space. |
| 154 | * Where a device has a partner that is already in DMA mode we check |
| 155 | * and enforce IDE simplex rules. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 156 | */ |
| 157 | |
Bartlomiej Zolnierkiewicz | 9ffcf36 | 2007-10-19 00:30:07 +0200 | [diff] [blame] | 158 | static unsigned long ide_get_or_set_dma_base(ide_pci_device_t *d, ide_hwif_t *hwif) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 159 | { |
| 160 | unsigned long dma_base = 0; |
| 161 | struct pci_dev *dev = hwif->pci_dev; |
| 162 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 163 | if (hwif->mmio) |
| 164 | return hwif->dma_base; |
| 165 | |
| 166 | if (hwif->mate && hwif->mate->dma_base) { |
| 167 | dma_base = hwif->mate->dma_base - (hwif->channel ? 0 : 8); |
| 168 | } else { |
Bartlomiej Zolnierkiewicz | 9ffcf36 | 2007-10-19 00:30:07 +0200 | [diff] [blame] | 169 | u8 baridx = (d->host_flags & IDE_HFLAG_CS5520) ? 2 : 4; |
| 170 | |
| 171 | dma_base = pci_resource_start(dev, baridx); |
| 172 | |
| 173 | if (dma_base == 0) |
| 174 | printk(KERN_ERR "%s: DMA base is invalid\n", d->name); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 175 | } |
| 176 | |
Bartlomiej Zolnierkiewicz | 9ffcf36 | 2007-10-19 00:30:07 +0200 | [diff] [blame] | 177 | if ((d->host_flags & IDE_HFLAG_CS5520) == 0 && dma_base) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 178 | u8 simplex_stat = 0; |
| 179 | dma_base += hwif->channel ? 8 : 0; |
| 180 | |
| 181 | switch(dev->device) { |
| 182 | case PCI_DEVICE_ID_AL_M5219: |
| 183 | case PCI_DEVICE_ID_AL_M5229: |
| 184 | case PCI_DEVICE_ID_AMD_VIPER_7409: |
| 185 | case PCI_DEVICE_ID_CMD_643: |
| 186 | case PCI_DEVICE_ID_SERVERWORKS_CSB5IDE: |
Matt Gillette | 2f09a7f | 2005-08-18 22:27:07 +0200 | [diff] [blame] | 187 | case PCI_DEVICE_ID_REVOLUTION: |
Bartlomiej Zolnierkiewicz | 31e8a46 | 2007-10-19 00:30:08 +0200 | [diff] [blame] | 188 | simplex_stat = inb(dma_base + 2); |
| 189 | outb(simplex_stat & 0x60, dma_base + 2); |
| 190 | simplex_stat = inb(dma_base + 2); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 191 | if (simplex_stat & 0x80) { |
| 192 | printk(KERN_INFO "%s: simplex device: " |
Bartlomiej Zolnierkiewicz | 9ffcf36 | 2007-10-19 00:30:07 +0200 | [diff] [blame] | 193 | "DMA forced\n", |
| 194 | d->name); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 195 | } |
| 196 | break; |
| 197 | default: |
| 198 | /* |
| 199 | * If the device claims "simplex" DMA, |
| 200 | * this means only one of the two interfaces |
| 201 | * can be trusted with DMA at any point in time. |
| 202 | * So we should enable DMA only on one of the |
| 203 | * two interfaces. |
| 204 | */ |
| 205 | simplex_stat = hwif->INB(dma_base + 2); |
| 206 | if (simplex_stat & 0x80) { |
| 207 | /* simplex device? */ |
| 208 | /* |
| 209 | * At this point we haven't probed the drives so we can't make the |
| 210 | * appropriate decision. Really we should defer this problem |
| 211 | * until we tune the drive then try to grab DMA ownership if we want |
| 212 | * to be the DMA end. This has to be become dynamic to handle hot |
| 213 | * plug. |
| 214 | */ |
| 215 | if (hwif->mate && hwif->mate->dma_base) { |
| 216 | printk(KERN_INFO "%s: simplex device: " |
Bartlomiej Zolnierkiewicz | 9ffcf36 | 2007-10-19 00:30:07 +0200 | [diff] [blame] | 217 | "DMA disabled\n", |
| 218 | d->name); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 219 | dma_base = 0; |
| 220 | } |
| 221 | } |
| 222 | } |
| 223 | } |
| 224 | return dma_base; |
| 225 | } |
| 226 | #endif /* CONFIG_BLK_DEV_IDEDMA_PCI */ |
| 227 | |
| 228 | void ide_setup_pci_noise (struct pci_dev *dev, ide_pci_device_t *d) |
| 229 | { |
| 230 | printk(KERN_INFO "%s: IDE controller at PCI slot %s\n", |
| 231 | d->name, pci_name(dev)); |
| 232 | } |
| 233 | |
| 234 | EXPORT_SYMBOL_GPL(ide_setup_pci_noise); |
| 235 | |
| 236 | |
| 237 | /** |
| 238 | * ide_pci_enable - do PCI enables |
| 239 | * @dev: PCI device |
| 240 | * @d: IDE pci device data |
| 241 | * |
| 242 | * Enable the IDE PCI device. We attempt to enable the device in full |
| 243 | * but if that fails then we only need BAR4 so we will enable that. |
| 244 | * |
| 245 | * Returns zero on success or an error code |
| 246 | */ |
| 247 | |
| 248 | static int ide_pci_enable(struct pci_dev *dev, ide_pci_device_t *d) |
| 249 | { |
| 250 | int ret; |
| 251 | |
| 252 | if (pci_enable_device(dev)) { |
| 253 | ret = pci_enable_device_bars(dev, 1 << 4); |
| 254 | if (ret < 0) { |
| 255 | printk(KERN_WARNING "%s: (ide_setup_pci_device:) " |
| 256 | "Could not enable device.\n", d->name); |
| 257 | goto out; |
| 258 | } |
| 259 | printk(KERN_WARNING "%s: BIOS configuration fixed.\n", d->name); |
| 260 | } |
| 261 | |
| 262 | /* |
| 263 | * assume all devices can do 32-bit dma for now. we can add a |
| 264 | * dma mask field to the ide_pci_device_t if we need it (or let |
| 265 | * lower level driver set the dma mask) |
| 266 | */ |
| 267 | ret = pci_set_dma_mask(dev, DMA_32BIT_MASK); |
| 268 | if (ret < 0) { |
| 269 | printk(KERN_ERR "%s: can't set dma mask\n", d->name); |
| 270 | goto out; |
| 271 | } |
| 272 | |
| 273 | /* FIXME: Temporary - until we put in the hotplug interface logic |
| 274 | Check that the bits we want are not in use by someone else. */ |
| 275 | ret = pci_request_region(dev, 4, "ide_tmp"); |
| 276 | if (ret < 0) |
| 277 | goto out; |
| 278 | |
| 279 | pci_release_region(dev, 4); |
| 280 | out: |
| 281 | return ret; |
| 282 | } |
| 283 | |
| 284 | /** |
| 285 | * ide_pci_configure - configure an unconfigured device |
| 286 | * @dev: PCI device |
| 287 | * @d: IDE pci device data |
| 288 | * |
| 289 | * Enable and configure the PCI device we have been passed. |
| 290 | * Returns zero on success or an error code. |
| 291 | */ |
| 292 | |
| 293 | static int ide_pci_configure(struct pci_dev *dev, ide_pci_device_t *d) |
| 294 | { |
| 295 | u16 pcicmd = 0; |
| 296 | /* |
| 297 | * PnP BIOS was *supposed* to have setup this device, but we |
| 298 | * can do it ourselves, so long as the BIOS has assigned an IRQ |
| 299 | * (or possibly the device is using a "legacy header" for IRQs). |
| 300 | * Maybe the user deliberately *disabled* the device, |
| 301 | * but we'll eventually ignore it again if no drives respond. |
| 302 | */ |
| 303 | if (ide_setup_pci_baseregs(dev, d->name) || pci_write_config_word(dev, PCI_COMMAND, pcicmd|PCI_COMMAND_IO)) |
| 304 | { |
| 305 | printk(KERN_INFO "%s: device disabled (BIOS)\n", d->name); |
| 306 | return -ENODEV; |
| 307 | } |
| 308 | if (pci_read_config_word(dev, PCI_COMMAND, &pcicmd)) { |
| 309 | printk(KERN_ERR "%s: error accessing PCI regs\n", d->name); |
| 310 | return -EIO; |
| 311 | } |
| 312 | if (!(pcicmd & PCI_COMMAND_IO)) { |
| 313 | printk(KERN_ERR "%s: unable to enable IDE controller\n", d->name); |
| 314 | return -ENXIO; |
| 315 | } |
| 316 | return 0; |
| 317 | } |
| 318 | |
| 319 | /** |
| 320 | * ide_pci_check_iomem - check a register is I/O |
| 321 | * @dev: pci device |
| 322 | * @d: ide_pci_device |
| 323 | * @bar: bar number |
| 324 | * |
| 325 | * Checks if a BAR is configured and points to MMIO space. If so |
| 326 | * print an error and return an error code. Otherwise return 0 |
| 327 | */ |
| 328 | |
| 329 | static int ide_pci_check_iomem(struct pci_dev *dev, ide_pci_device_t *d, int bar) |
| 330 | { |
| 331 | ulong flags = pci_resource_flags(dev, bar); |
| 332 | |
| 333 | /* Unconfigured ? */ |
| 334 | if (!flags || pci_resource_len(dev, bar) == 0) |
| 335 | return 0; |
| 336 | |
| 337 | /* I/O space */ |
| 338 | if(flags & PCI_BASE_ADDRESS_IO_MASK) |
| 339 | return 0; |
| 340 | |
| 341 | /* Bad */ |
| 342 | printk(KERN_ERR "%s: IO baseregs (BIOS) are reported " |
| 343 | "as MEM, report to " |
| 344 | "<andre@linux-ide.org>.\n", d->name); |
| 345 | return -EINVAL; |
| 346 | } |
| 347 | |
| 348 | /** |
| 349 | * ide_hwif_configure - configure an IDE interface |
| 350 | * @dev: PCI device holding interface |
| 351 | * @d: IDE pci data |
| 352 | * @mate: Paired interface if any |
| 353 | * |
| 354 | * Perform the initial set up for the hardware interface structure. This |
| 355 | * is done per interface port rather than per PCI device. There may be |
| 356 | * more than one port per device. |
| 357 | * |
| 358 | * Returns the new hardware interface structure, or NULL on a failure |
| 359 | */ |
| 360 | |
| 361 | static ide_hwif_t *ide_hwif_configure(struct pci_dev *dev, ide_pci_device_t *d, ide_hwif_t *mate, int port, int irq) |
| 362 | { |
| 363 | unsigned long ctl = 0, base = 0; |
| 364 | ide_hwif_t *hwif; |
Bartlomiej Zolnierkiewicz | 7cab14a | 2007-10-19 00:30:06 +0200 | [diff] [blame] | 365 | u8 bootable = (d->host_flags & IDE_HFLAG_BOOTABLE) ? 1 : 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 366 | |
Bartlomiej Zolnierkiewicz | a5d8c5c | 2007-07-20 01:11:55 +0200 | [diff] [blame] | 367 | if ((d->host_flags & IDE_HFLAG_ISA_PORTS) == 0) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 368 | /* Possibly we should fail if these checks report true */ |
| 369 | ide_pci_check_iomem(dev, d, 2*port); |
| 370 | ide_pci_check_iomem(dev, d, 2*port+1); |
| 371 | |
| 372 | ctl = pci_resource_start(dev, 2*port+1); |
| 373 | base = pci_resource_start(dev, 2*port); |
| 374 | if ((ctl && !base) || (base && !ctl)) { |
| 375 | printk(KERN_ERR "%s: inconsistent baseregs (BIOS) " |
| 376 | "for port %d, skipping\n", d->name, port); |
| 377 | return NULL; |
| 378 | } |
| 379 | } |
| 380 | if (!ctl) |
| 381 | { |
| 382 | /* Use default values */ |
| 383 | ctl = port ? 0x374 : 0x3f4; |
| 384 | base = port ? 0x170 : 0x1f0; |
| 385 | } |
Bartlomiej Zolnierkiewicz | 7cab14a | 2007-10-19 00:30:06 +0200 | [diff] [blame] | 386 | if ((hwif = ide_match_hwif(base, bootable, d->name)) == NULL) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 387 | return NULL; /* no room in ide_hwifs[] */ |
| 388 | if (hwif->io_ports[IDE_DATA_OFFSET] != base || |
| 389 | hwif->io_ports[IDE_CONTROL_OFFSET] != (ctl | 2)) { |
Bartlomiej Zolnierkiewicz | 9239b33 | 2007-10-20 00:32:33 +0200 | [diff] [blame^] | 390 | hw_regs_t hw; |
| 391 | |
| 392 | memset(&hw, 0, sizeof(hw)); |
Bartlomiej Zolnierkiewicz | 847ddd2 | 2007-10-20 00:32:32 +0200 | [diff] [blame] | 393 | #ifndef CONFIG_IDE_ARCH_OBSOLETE_INIT |
Bartlomiej Zolnierkiewicz | 9239b33 | 2007-10-20 00:32:33 +0200 | [diff] [blame^] | 394 | ide_std_init_ports(&hw, base, ctl | 2); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 395 | #else |
Bartlomiej Zolnierkiewicz | 9239b33 | 2007-10-20 00:32:33 +0200 | [diff] [blame^] | 396 | ide_init_hwif_ports(&hw, base, ctl | 2, NULL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 397 | #endif |
Bartlomiej Zolnierkiewicz | 9239b33 | 2007-10-20 00:32:33 +0200 | [diff] [blame^] | 398 | memcpy(hwif->io_ports, hw.io_ports, sizeof(hwif->io_ports)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 399 | hwif->noprobe = !hwif->io_ports[IDE_DATA_OFFSET]; |
| 400 | } |
Bartlomiej Zolnierkiewicz | 528a572 | 2007-10-20 00:32:30 +0200 | [diff] [blame] | 401 | hwif->chipset = d->chipset ? d->chipset : ide_pci; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 402 | hwif->pci_dev = dev; |
| 403 | hwif->cds = (struct ide_pci_device_s *) d; |
| 404 | hwif->channel = port; |
| 405 | |
| 406 | if (!hwif->irq) |
| 407 | hwif->irq = irq; |
| 408 | if (mate) { |
| 409 | hwif->mate = mate; |
| 410 | mate->mate = hwif; |
| 411 | } |
| 412 | return hwif; |
| 413 | } |
| 414 | |
| 415 | /** |
| 416 | * ide_hwif_setup_dma - configure DMA interface |
| 417 | * @dev: PCI device |
| 418 | * @d: IDE pci data |
| 419 | * @hwif: Hardware interface we are configuring |
| 420 | * |
| 421 | * Set up the DMA base for the interface. Enable the master bits as |
| 422 | * necessary and attempt to bring the device DMA into a ready to use |
| 423 | * state |
| 424 | */ |
| 425 | |
| 426 | #ifndef CONFIG_BLK_DEV_IDEDMA_PCI |
| 427 | static void ide_hwif_setup_dma(struct pci_dev *dev, ide_pci_device_t *d, ide_hwif_t *hwif) |
| 428 | { |
| 429 | } |
| 430 | #else |
| 431 | static void ide_hwif_setup_dma(struct pci_dev *dev, ide_pci_device_t *d, ide_hwif_t *hwif) |
| 432 | { |
| 433 | u16 pcicmd; |
Bartlomiej Zolnierkiewicz | 47b6878 | 2007-10-19 00:30:06 +0200 | [diff] [blame] | 434 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 435 | pci_read_config_word(dev, PCI_COMMAND, &pcicmd); |
| 436 | |
Bartlomiej Zolnierkiewicz | 47b6878 | 2007-10-19 00:30:06 +0200 | [diff] [blame] | 437 | if ((d->host_flags & IDE_HFLAG_NO_AUTODMA) == 0 || |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 438 | ((dev->class >> 8) == PCI_CLASS_STORAGE_IDE && |
| 439 | (dev->class & 0x80))) { |
Bartlomiej Zolnierkiewicz | 9ffcf36 | 2007-10-19 00:30:07 +0200 | [diff] [blame] | 440 | unsigned long dma_base = ide_get_or_set_dma_base(d, hwif); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 441 | if (dma_base && !(pcicmd & PCI_COMMAND_MASTER)) { |
| 442 | /* |
| 443 | * Set up BM-DMA capability |
| 444 | * (PnP BIOS should have done this) |
| 445 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 446 | pci_set_master(dev); |
| 447 | if (pci_read_config_word(dev, PCI_COMMAND, &pcicmd) || !(pcicmd & PCI_COMMAND_MASTER)) { |
| 448 | printk(KERN_ERR "%s: %s error updating PCICMD\n", |
| 449 | hwif->name, d->name); |
| 450 | dma_base = 0; |
| 451 | } |
| 452 | } |
| 453 | if (dma_base) { |
| 454 | if (d->init_dma) { |
| 455 | d->init_dma(hwif, dma_base); |
| 456 | } else { |
| 457 | ide_setup_dma(hwif, dma_base, 8); |
| 458 | } |
| 459 | } else { |
| 460 | printk(KERN_INFO "%s: %s Bus-Master DMA disabled " |
| 461 | "(BIOS)\n", hwif->name, d->name); |
| 462 | } |
| 463 | } |
| 464 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 465 | #endif /* CONFIG_BLK_DEV_IDEDMA_PCI*/ |
| 466 | |
| 467 | /** |
| 468 | * ide_setup_pci_controller - set up IDE PCI |
| 469 | * @dev: PCI device |
| 470 | * @d: IDE PCI data |
| 471 | * @noisy: verbose flag |
| 472 | * @config: returned as 1 if we configured the hardware |
| 473 | * |
| 474 | * Set up the PCI and controller side of the IDE interface. This brings |
| 475 | * up the PCI side of the device, checks that the device is enabled |
| 476 | * and enables it if need be |
| 477 | */ |
| 478 | |
| 479 | static int ide_setup_pci_controller(struct pci_dev *dev, ide_pci_device_t *d, int noisy, int *config) |
| 480 | { |
| 481 | int ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 482 | u16 pcicmd; |
| 483 | |
| 484 | if (noisy) |
| 485 | ide_setup_pci_noise(dev, d); |
| 486 | |
| 487 | ret = ide_pci_enable(dev, d); |
| 488 | if (ret < 0) |
| 489 | goto out; |
| 490 | |
| 491 | ret = pci_read_config_word(dev, PCI_COMMAND, &pcicmd); |
| 492 | if (ret < 0) { |
| 493 | printk(KERN_ERR "%s: error accessing PCI regs\n", d->name); |
| 494 | goto out; |
| 495 | } |
| 496 | if (!(pcicmd & PCI_COMMAND_IO)) { /* is device disabled? */ |
| 497 | ret = ide_pci_configure(dev, d); |
| 498 | if (ret < 0) |
| 499 | goto out; |
| 500 | *config = 1; |
| 501 | printk(KERN_INFO "%s: device enabled (Linux)\n", d->name); |
| 502 | } |
| 503 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 504 | if (noisy) |
Bartlomiej Zolnierkiewicz | fc212bb | 2007-10-19 00:30:08 +0200 | [diff] [blame] | 505 | printk(KERN_INFO "%s: chipset revision %d\n", |
| 506 | d->name, dev->revision); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 507 | out: |
| 508 | return ret; |
| 509 | } |
| 510 | |
| 511 | /** |
| 512 | * ide_pci_setup_ports - configure ports/devices on PCI IDE |
| 513 | * @dev: PCI device |
| 514 | * @d: IDE pci device info |
| 515 | * @pciirq: IRQ line |
Bartlomiej Zolnierkiewicz | 8447d9d | 2007-10-20 00:32:31 +0200 | [diff] [blame] | 516 | * @idx: ATA index table to update |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 517 | * |
| 518 | * Scan the interfaces attached to this device and do any |
| 519 | * necessary per port setup. Attach the devices and ask the |
| 520 | * generic DMA layer to do its work for us. |
| 521 | * |
| 522 | * Normally called automaticall from do_ide_pci_setup_device, |
| 523 | * but is also used directly as a helper function by some controllers |
| 524 | * where the chipset setup is not the default PCI IDE one. |
| 525 | */ |
Bartlomiej Zolnierkiewicz | 8447d9d | 2007-10-20 00:32:31 +0200 | [diff] [blame] | 526 | |
| 527 | void ide_pci_setup_ports(struct pci_dev *dev, ide_pci_device_t *d, int pciirq, u8 *idx) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 528 | { |
Bartlomiej Zolnierkiewicz | a5d8c5c | 2007-07-20 01:11:55 +0200 | [diff] [blame] | 529 | int channels = (d->host_flags & IDE_HFLAG_SINGLE) ? 1 : 2, port; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 530 | ide_hwif_t *hwif, *mate = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 531 | u8 tmp; |
| 532 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 533 | /* |
| 534 | * Set up the IDE ports |
| 535 | */ |
Bartlomiej Zolnierkiewicz | cf6e854 | 2007-10-20 00:32:29 +0200 | [diff] [blame] | 536 | |
Bartlomiej Zolnierkiewicz | a5d8c5c | 2007-07-20 01:11:55 +0200 | [diff] [blame] | 537 | for (port = 0; port < channels; ++port) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 538 | ide_pci_enablebit_t *e = &(d->enablebits[port]); |
| 539 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 540 | if (e->reg && (pci_read_config_byte(dev, e->reg, &tmp) || |
Bartlomiej Zolnierkiewicz | cf6e854 | 2007-10-20 00:32:29 +0200 | [diff] [blame] | 541 | (tmp & e->mask) != e->val)) { |
| 542 | printk(KERN_INFO "%s: IDE port disabled\n", d->name); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 543 | continue; /* port not enabled */ |
Bartlomiej Zolnierkiewicz | cf6e854 | 2007-10-20 00:32:29 +0200 | [diff] [blame] | 544 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 545 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 546 | if ((hwif = ide_hwif_configure(dev, d, mate, port, pciirq)) == NULL) |
| 547 | continue; |
| 548 | |
| 549 | /* setup proper ancestral information */ |
| 550 | hwif->gendev.parent = &dev->dev; |
| 551 | |
Bartlomiej Zolnierkiewicz | 8447d9d | 2007-10-20 00:32:31 +0200 | [diff] [blame] | 552 | *(idx + port) = hwif->index; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 553 | |
| 554 | |
| 555 | if (d->init_iops) |
| 556 | d->init_iops(hwif); |
| 557 | |
Bartlomiej Zolnierkiewicz | 9ffcf36 | 2007-10-19 00:30:07 +0200 | [diff] [blame] | 558 | if ((d->host_flags & IDE_HFLAG_NO_DMA) == 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 559 | ide_hwif_setup_dma(dev, d, hwif); |
Bartlomiej Zolnierkiewicz | 9ffcf36 | 2007-10-19 00:30:07 +0200 | [diff] [blame] | 560 | |
Bartlomiej Zolnierkiewicz | 8acf28c | 2007-10-20 00:32:30 +0200 | [diff] [blame] | 561 | if ((!hwif->irq && (d->host_flags & IDE_HFLAG_LEGACY_IRQS)) || |
| 562 | (d->host_flags & IDE_HFLAG_FORCE_LEGACY_IRQS)) |
Bartlomiej Zolnierkiewicz | 3985ee3 | 2007-10-19 00:30:11 +0200 | [diff] [blame] | 563 | hwif->irq = port ? 15 : 14; |
| 564 | |
Bartlomiej Zolnierkiewicz | fd9bb53 | 2007-10-20 00:32:31 +0200 | [diff] [blame] | 565 | hwif->fixup = d->fixup; |
| 566 | |
Bartlomiej Zolnierkiewicz | 6a824c9 | 2007-07-20 01:11:58 +0200 | [diff] [blame] | 567 | hwif->host_flags = d->host_flags; |
Bartlomiej Zolnierkiewicz | 4099d14 | 2007-07-20 01:11:59 +0200 | [diff] [blame] | 568 | hwif->pio_mask = d->pio_mask; |
Bartlomiej Zolnierkiewicz | 6a824c9 | 2007-07-20 01:11:58 +0200 | [diff] [blame] | 569 | |
Bartlomiej Zolnierkiewicz | 1c51361 | 2007-10-19 00:30:10 +0200 | [diff] [blame] | 570 | if ((d->host_flags & IDE_HFLAG_SERIALIZE) && hwif->mate) |
| 571 | hwif->mate->serialized = hwif->serialized = 1; |
| 572 | |
Bartlomiej Zolnierkiewicz | caea760 | 2007-10-20 00:32:30 +0200 | [diff] [blame] | 573 | if (d->host_flags & IDE_HFLAG_IO_32BIT) { |
| 574 | hwif->drives[0].io_32bit = 1; |
| 575 | hwif->drives[1].io_32bit = 1; |
| 576 | } |
| 577 | |
| 578 | if (d->host_flags & IDE_HFLAG_UNMASK_IRQS) { |
| 579 | hwif->drives[0].unmask = 1; |
| 580 | hwif->drives[1].unmask = 1; |
| 581 | } |
| 582 | |
Bartlomiej Zolnierkiewicz | 5f8b6c3 | 2007-10-19 00:30:07 +0200 | [diff] [blame] | 583 | if (hwif->dma_base) { |
| 584 | hwif->swdma_mask = d->swdma_mask; |
| 585 | hwif->mwdma_mask = d->mwdma_mask; |
| 586 | hwif->ultra_mask = d->udma_mask; |
| 587 | } |
| 588 | |
Bartlomiej Zolnierkiewicz | 85ad93a | 2007-10-19 00:30:12 +0200 | [diff] [blame] | 589 | hwif->drives[0].autotune = 1; |
| 590 | hwif->drives[1].autotune = 1; |
| 591 | |
Bartlomiej Zolnierkiewicz | 272a370 | 2007-10-20 00:32:30 +0200 | [diff] [blame] | 592 | if (d->host_flags & IDE_HFLAG_RQSIZE_256) |
| 593 | hwif->rqsize = 256; |
| 594 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 595 | if (d->init_hwif) |
| 596 | /* Call chipset-specific routine |
| 597 | * for each enabled hwif |
| 598 | */ |
| 599 | d->init_hwif(hwif); |
| 600 | |
| 601 | mate = hwif; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 602 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 603 | } |
| 604 | |
| 605 | EXPORT_SYMBOL_GPL(ide_pci_setup_ports); |
| 606 | |
| 607 | /* |
| 608 | * ide_setup_pci_device() looks at the primary/secondary interfaces |
| 609 | * on a PCI IDE device and, if they are enabled, prepares the IDE driver |
| 610 | * for use with them. This generic code works for most PCI chipsets. |
| 611 | * |
| 612 | * One thing that is not standardized is the location of the |
| 613 | * primary/secondary interface "enable/disable" bits. For chipsets that |
| 614 | * we "know" about, this information is in the ide_pci_device_t struct; |
| 615 | * for all other chipsets, we just assume both interfaces are enabled. |
| 616 | */ |
| 617 | static int do_ide_setup_pci_device(struct pci_dev *dev, ide_pci_device_t *d, |
Bartlomiej Zolnierkiewicz | 8447d9d | 2007-10-20 00:32:31 +0200 | [diff] [blame] | 618 | u8 *idx, u8 noisy) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 619 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 620 | int tried_config = 0; |
| 621 | int pciirq, ret; |
| 622 | |
| 623 | ret = ide_setup_pci_controller(dev, d, noisy, &tried_config); |
| 624 | if (ret < 0) |
| 625 | goto out; |
| 626 | |
| 627 | /* |
| 628 | * Can we trust the reported IRQ? |
| 629 | */ |
| 630 | pciirq = dev->irq; |
| 631 | |
| 632 | /* Is it an "IDE storage" device in non-PCI mode? */ |
| 633 | if ((dev->class >> 8) == PCI_CLASS_STORAGE_IDE && (dev->class & 5) != 5) { |
| 634 | if (noisy) |
| 635 | printk(KERN_INFO "%s: not 100%% native mode: " |
| 636 | "will probe irqs later\n", d->name); |
| 637 | /* |
| 638 | * This allows offboard ide-pci cards the enable a BIOS, |
| 639 | * verify interrupt settings of split-mirror pci-config |
| 640 | * space, place chipset into init-mode, and/or preserve |
| 641 | * an interrupt if the card is not native ide support. |
| 642 | */ |
| 643 | ret = d->init_chipset ? d->init_chipset(dev, d->name) : 0; |
| 644 | if (ret < 0) |
| 645 | goto out; |
| 646 | pciirq = ret; |
| 647 | } else if (tried_config) { |
| 648 | if (noisy) |
| 649 | printk(KERN_INFO "%s: will probe irqs later\n", d->name); |
| 650 | pciirq = 0; |
| 651 | } else if (!pciirq) { |
| 652 | if (noisy) |
| 653 | printk(KERN_WARNING "%s: bad irq (%d): will probe later\n", |
| 654 | d->name, pciirq); |
| 655 | pciirq = 0; |
| 656 | } else { |
| 657 | if (d->init_chipset) { |
| 658 | ret = d->init_chipset(dev, d->name); |
| 659 | if (ret < 0) |
| 660 | goto out; |
| 661 | } |
| 662 | if (noisy) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 663 | printk(KERN_INFO "%s: 100%% native mode on irq %d\n", |
| 664 | d->name, pciirq); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 665 | } |
| 666 | |
| 667 | /* FIXME: silent failure can happen */ |
| 668 | |
Bartlomiej Zolnierkiewicz | 8447d9d | 2007-10-20 00:32:31 +0200 | [diff] [blame] | 669 | ide_pci_setup_ports(dev, d, pciirq, idx); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 670 | out: |
| 671 | return ret; |
| 672 | } |
| 673 | |
| 674 | int ide_setup_pci_device(struct pci_dev *dev, ide_pci_device_t *d) |
| 675 | { |
Bartlomiej Zolnierkiewicz | 8447d9d | 2007-10-20 00:32:31 +0200 | [diff] [blame] | 676 | u8 idx[4] = { 0xff, 0xff, 0xff, 0xff }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 677 | int ret; |
| 678 | |
Bartlomiej Zolnierkiewicz | 8447d9d | 2007-10-20 00:32:31 +0200 | [diff] [blame] | 679 | ret = do_ide_setup_pci_device(dev, d, &idx[0], 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 680 | |
Bartlomiej Zolnierkiewicz | 8447d9d | 2007-10-20 00:32:31 +0200 | [diff] [blame] | 681 | if (ret >= 0) |
| 682 | ide_device_add(idx); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 683 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 684 | return ret; |
| 685 | } |
| 686 | |
| 687 | EXPORT_SYMBOL_GPL(ide_setup_pci_device); |
| 688 | |
| 689 | int ide_setup_pci_devices(struct pci_dev *dev1, struct pci_dev *dev2, |
| 690 | ide_pci_device_t *d) |
| 691 | { |
| 692 | struct pci_dev *pdev[] = { dev1, dev2 }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 693 | int ret, i; |
Bartlomiej Zolnierkiewicz | 8447d9d | 2007-10-20 00:32:31 +0200 | [diff] [blame] | 694 | u8 idx[4] = { 0xff, 0xff, 0xff, 0xff }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 695 | |
| 696 | for (i = 0; i < 2; i++) { |
Bartlomiej Zolnierkiewicz | 8447d9d | 2007-10-20 00:32:31 +0200 | [diff] [blame] | 697 | ret = do_ide_setup_pci_device(pdev[i], d, &idx[i*2], !i); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 698 | /* |
| 699 | * FIXME: Mom, mom, they stole me the helper function to undo |
| 700 | * do_ide_setup_pci_device() on the first device! |
| 701 | */ |
| 702 | if (ret < 0) |
| 703 | goto out; |
| 704 | } |
| 705 | |
Bartlomiej Zolnierkiewicz | 8447d9d | 2007-10-20 00:32:31 +0200 | [diff] [blame] | 706 | ide_device_add(idx); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 707 | out: |
| 708 | return ret; |
| 709 | } |
| 710 | |
| 711 | EXPORT_SYMBOL_GPL(ide_setup_pci_devices); |
| 712 | |
Bartlomiej Zolnierkiewicz | 6d208b3 | 2007-05-10 00:01:11 +0200 | [diff] [blame] | 713 | #ifdef CONFIG_IDEPCI_PCIBUS_ORDER |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 714 | /* |
| 715 | * Module interfaces |
| 716 | */ |
| 717 | |
| 718 | static int pre_init = 1; /* Before first ordered IDE scan */ |
| 719 | static LIST_HEAD(ide_pci_drivers); |
| 720 | |
| 721 | /* |
Ralf Baechle | c37ea21 | 2005-11-18 23:11:24 +0100 | [diff] [blame] | 722 | * __ide_pci_register_driver - attach IDE driver |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 723 | * @driver: pci driver |
Laurent riffard | 863b18f | 2005-10-27 23:12:54 +0200 | [diff] [blame] | 724 | * @module: owner module of the driver |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 725 | * |
| 726 | * Registers a driver with the IDE layer. The IDE layer arranges that |
| 727 | * boot time setup is done in the expected device order and then |
| 728 | * hands the controllers off to the core PCI code to do the rest of |
| 729 | * the work. |
| 730 | * |
| 731 | * The driver_data of the driver table must point to an ide_pci_device_t |
| 732 | * describing the interface. |
| 733 | * |
| 734 | * Returns are the same as for pci_register_driver |
| 735 | */ |
| 736 | |
Greg Kroah-Hartman | 725522b | 2007-01-15 11:50:02 -0800 | [diff] [blame] | 737 | int __ide_pci_register_driver(struct pci_driver *driver, struct module *module, |
| 738 | const char *mod_name) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 739 | { |
| 740 | if(!pre_init) |
Greg Kroah-Hartman | 725522b | 2007-01-15 11:50:02 -0800 | [diff] [blame] | 741 | return __pci_register_driver(driver, module, mod_name); |
Laurent riffard | 863b18f | 2005-10-27 23:12:54 +0200 | [diff] [blame] | 742 | driver->driver.owner = module; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 743 | list_add_tail(&driver->node, &ide_pci_drivers); |
| 744 | return 0; |
| 745 | } |
| 746 | |
Laurent riffard | 863b18f | 2005-10-27 23:12:54 +0200 | [diff] [blame] | 747 | EXPORT_SYMBOL_GPL(__ide_pci_register_driver); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 748 | |
| 749 | /** |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 750 | * ide_scan_pcidev - find an IDE driver for a device |
| 751 | * @dev: PCI device to check |
| 752 | * |
| 753 | * Look for an IDE driver to handle the device we are considering. |
| 754 | * This is only used during boot up to get the ordering correct. After |
| 755 | * boot up the pci layer takes over the job. |
| 756 | */ |
| 757 | |
| 758 | static int __init ide_scan_pcidev(struct pci_dev *dev) |
| 759 | { |
| 760 | struct list_head *l; |
| 761 | struct pci_driver *d; |
| 762 | |
Sergei Shtylyov | 0505b55 | 2007-09-11 22:28:34 +0200 | [diff] [blame] | 763 | list_for_each(l, &ide_pci_drivers) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 764 | d = list_entry(l, struct pci_driver, node); |
Sergei Shtylyov | 0505b55 | 2007-09-11 22:28:34 +0200 | [diff] [blame] | 765 | if (d->id_table) { |
| 766 | const struct pci_device_id *id = pci_match_id(d->id_table, |
| 767 | dev); |
| 768 | if (id != NULL && d->probe(dev, id) >= 0) { |
| 769 | dev->driver = d; |
| 770 | pci_dev_get(dev); |
| 771 | return 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 772 | } |
| 773 | } |
| 774 | } |
| 775 | return 0; |
| 776 | } |
| 777 | |
| 778 | /** |
| 779 | * ide_scan_pcibus - perform the initial IDE driver scan |
| 780 | * @scan_direction: set for reverse order scanning |
| 781 | * |
| 782 | * Perform the initial bus rather than driver ordered scan of the |
| 783 | * PCI drivers. After this all IDE pci handling becomes standard |
| 784 | * module ordering not traditionally ordered. |
| 785 | */ |
| 786 | |
| 787 | void __init ide_scan_pcibus (int scan_direction) |
| 788 | { |
| 789 | struct pci_dev *dev = NULL; |
| 790 | struct pci_driver *d; |
| 791 | struct list_head *l, *n; |
| 792 | |
| 793 | pre_init = 0; |
Sergei Shtylyov | 0505b55 | 2007-09-11 22:28:34 +0200 | [diff] [blame] | 794 | if (!scan_direction) |
| 795 | while ((dev = pci_get_device(PCI_ANY_ID, PCI_ANY_ID, dev)) != NULL) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 796 | ide_scan_pcidev(dev); |
Sergei Shtylyov | 0505b55 | 2007-09-11 22:28:34 +0200 | [diff] [blame] | 797 | else |
| 798 | while ((dev = pci_get_device_reverse(PCI_ANY_ID, PCI_ANY_ID, dev)) |
| 799 | != NULL) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 800 | ide_scan_pcidev(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 801 | |
| 802 | /* |
| 803 | * Hand the drivers over to the PCI layer now we |
| 804 | * are post init. |
| 805 | */ |
| 806 | |
Andrew Morton | d61bcce | 2007-07-03 22:28:36 +0200 | [diff] [blame] | 807 | list_for_each_safe(l, n, &ide_pci_drivers) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 808 | list_del(l); |
| 809 | d = list_entry(l, struct pci_driver, node); |
Sergei Shtylyov | 0505b55 | 2007-09-11 22:28:34 +0200 | [diff] [blame] | 810 | if (__pci_register_driver(d, d->driver.owner, d->driver.mod_name)) |
| 811 | printk(KERN_ERR "%s: failed to register driver for %s\n", |
| 812 | __FUNCTION__, d->driver.mod_name); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 813 | } |
| 814 | } |
Bartlomiej Zolnierkiewicz | 6d208b3 | 2007-05-10 00:01:11 +0200 | [diff] [blame] | 815 | #endif |