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 | 039788e | 2007-10-20 00:32:34 +0200 | [diff] [blame] | 150 | * @d: IDE port info |
| 151 | * @hwif: IDE interface |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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 | 8562043 | 2007-10-20 00:32:34 +0200 | [diff] [blame] | 158 | static unsigned long ide_get_or_set_dma_base(const struct ide_port_info *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 | |
Bartlomiej Zolnierkiewicz | 8562043 | 2007-10-20 00:32:34 +0200 | [diff] [blame] | 228 | void ide_setup_pci_noise(struct pci_dev *dev, const struct ide_port_info *d) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 229 | { |
Bartlomiej Zolnierkiewicz | bde07e5 | 2007-10-20 00:32:36 +0200 | [diff] [blame] | 230 | printk(KERN_INFO "%s: IDE controller (0x%04x:0x%04x rev 0x%02x) at " |
| 231 | " PCI slot %s\n", d->name, dev->vendor, dev->device, |
| 232 | dev->revision, pci_name(dev)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 233 | } |
| 234 | |
| 235 | EXPORT_SYMBOL_GPL(ide_setup_pci_noise); |
| 236 | |
| 237 | |
| 238 | /** |
| 239 | * ide_pci_enable - do PCI enables |
| 240 | * @dev: PCI device |
Bartlomiej Zolnierkiewicz | 039788e | 2007-10-20 00:32:34 +0200 | [diff] [blame] | 241 | * @d: IDE port info |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 242 | * |
| 243 | * Enable the IDE PCI device. We attempt to enable the device in full |
| 244 | * but if that fails then we only need BAR4 so we will enable that. |
| 245 | * |
| 246 | * Returns zero on success or an error code |
| 247 | */ |
Bartlomiej Zolnierkiewicz | 039788e | 2007-10-20 00:32:34 +0200 | [diff] [blame] | 248 | |
Bartlomiej Zolnierkiewicz | 8562043 | 2007-10-20 00:32:34 +0200 | [diff] [blame] | 249 | static int ide_pci_enable(struct pci_dev *dev, const struct ide_port_info *d) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 250 | { |
| 251 | int ret; |
| 252 | |
| 253 | if (pci_enable_device(dev)) { |
| 254 | ret = pci_enable_device_bars(dev, 1 << 4); |
| 255 | if (ret < 0) { |
| 256 | printk(KERN_WARNING "%s: (ide_setup_pci_device:) " |
| 257 | "Could not enable device.\n", d->name); |
| 258 | goto out; |
| 259 | } |
| 260 | printk(KERN_WARNING "%s: BIOS configuration fixed.\n", d->name); |
| 261 | } |
| 262 | |
| 263 | /* |
Bartlomiej Zolnierkiewicz | 039788e | 2007-10-20 00:32:34 +0200 | [diff] [blame] | 264 | * assume all devices can do 32-bit DMA for now, we can add |
| 265 | * a DMA mask field to the struct ide_port_info if we need it |
| 266 | * (or let lower level driver set the DMA mask) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 267 | */ |
| 268 | ret = pci_set_dma_mask(dev, DMA_32BIT_MASK); |
| 269 | if (ret < 0) { |
| 270 | printk(KERN_ERR "%s: can't set dma mask\n", d->name); |
| 271 | goto out; |
| 272 | } |
| 273 | |
| 274 | /* FIXME: Temporary - until we put in the hotplug interface logic |
| 275 | Check that the bits we want are not in use by someone else. */ |
| 276 | ret = pci_request_region(dev, 4, "ide_tmp"); |
| 277 | if (ret < 0) |
| 278 | goto out; |
| 279 | |
| 280 | pci_release_region(dev, 4); |
| 281 | out: |
| 282 | return ret; |
| 283 | } |
| 284 | |
| 285 | /** |
| 286 | * ide_pci_configure - configure an unconfigured device |
| 287 | * @dev: PCI device |
Bartlomiej Zolnierkiewicz | 039788e | 2007-10-20 00:32:34 +0200 | [diff] [blame] | 288 | * @d: IDE port info |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 289 | * |
| 290 | * Enable and configure the PCI device we have been passed. |
| 291 | * Returns zero on success or an error code. |
| 292 | */ |
Bartlomiej Zolnierkiewicz | 039788e | 2007-10-20 00:32:34 +0200 | [diff] [blame] | 293 | |
Bartlomiej Zolnierkiewicz | 8562043 | 2007-10-20 00:32:34 +0200 | [diff] [blame] | 294 | static int ide_pci_configure(struct pci_dev *dev, const struct ide_port_info *d) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 295 | { |
| 296 | u16 pcicmd = 0; |
| 297 | /* |
| 298 | * PnP BIOS was *supposed* to have setup this device, but we |
| 299 | * can do it ourselves, so long as the BIOS has assigned an IRQ |
| 300 | * (or possibly the device is using a "legacy header" for IRQs). |
| 301 | * Maybe the user deliberately *disabled* the device, |
| 302 | * but we'll eventually ignore it again if no drives respond. |
| 303 | */ |
| 304 | if (ide_setup_pci_baseregs(dev, d->name) || pci_write_config_word(dev, PCI_COMMAND, pcicmd|PCI_COMMAND_IO)) |
| 305 | { |
| 306 | printk(KERN_INFO "%s: device disabled (BIOS)\n", d->name); |
| 307 | return -ENODEV; |
| 308 | } |
| 309 | if (pci_read_config_word(dev, PCI_COMMAND, &pcicmd)) { |
| 310 | printk(KERN_ERR "%s: error accessing PCI regs\n", d->name); |
| 311 | return -EIO; |
| 312 | } |
| 313 | if (!(pcicmd & PCI_COMMAND_IO)) { |
| 314 | printk(KERN_ERR "%s: unable to enable IDE controller\n", d->name); |
| 315 | return -ENXIO; |
| 316 | } |
| 317 | return 0; |
| 318 | } |
| 319 | |
| 320 | /** |
| 321 | * ide_pci_check_iomem - check a register is I/O |
Bartlomiej Zolnierkiewicz | 039788e | 2007-10-20 00:32:34 +0200 | [diff] [blame] | 322 | * @dev: PCI device |
| 323 | * @d: IDE port info |
| 324 | * @bar: BAR number |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 325 | * |
| 326 | * Checks if a BAR is configured and points to MMIO space. If so |
| 327 | * print an error and return an error code. Otherwise return 0 |
| 328 | */ |
Bartlomiej Zolnierkiewicz | 039788e | 2007-10-20 00:32:34 +0200 | [diff] [blame] | 329 | |
Bartlomiej Zolnierkiewicz | 8562043 | 2007-10-20 00:32:34 +0200 | [diff] [blame] | 330 | static int ide_pci_check_iomem(struct pci_dev *dev, const struct ide_port_info *d, int bar) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 331 | { |
| 332 | ulong flags = pci_resource_flags(dev, bar); |
| 333 | |
| 334 | /* Unconfigured ? */ |
| 335 | if (!flags || pci_resource_len(dev, bar) == 0) |
| 336 | return 0; |
| 337 | |
| 338 | /* I/O space */ |
| 339 | if(flags & PCI_BASE_ADDRESS_IO_MASK) |
| 340 | return 0; |
| 341 | |
| 342 | /* Bad */ |
| 343 | printk(KERN_ERR "%s: IO baseregs (BIOS) are reported " |
| 344 | "as MEM, report to " |
| 345 | "<andre@linux-ide.org>.\n", d->name); |
| 346 | return -EINVAL; |
| 347 | } |
| 348 | |
| 349 | /** |
| 350 | * ide_hwif_configure - configure an IDE interface |
| 351 | * @dev: PCI device holding interface |
Bartlomiej Zolnierkiewicz | 039788e | 2007-10-20 00:32:34 +0200 | [diff] [blame] | 352 | * @d: IDE port info |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 353 | * @mate: Paired interface if any |
| 354 | * |
| 355 | * Perform the initial set up for the hardware interface structure. This |
| 356 | * is done per interface port rather than per PCI device. There may be |
| 357 | * more than one port per device. |
| 358 | * |
| 359 | * Returns the new hardware interface structure, or NULL on a failure |
| 360 | */ |
Bartlomiej Zolnierkiewicz | 039788e | 2007-10-20 00:32:34 +0200 | [diff] [blame] | 361 | |
Bartlomiej Zolnierkiewicz | 8562043 | 2007-10-20 00:32:34 +0200 | [diff] [blame] | 362 | 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) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 363 | { |
| 364 | unsigned long ctl = 0, base = 0; |
| 365 | ide_hwif_t *hwif; |
Bartlomiej Zolnierkiewicz | 7cab14a | 2007-10-19 00:30:06 +0200 | [diff] [blame] | 366 | u8 bootable = (d->host_flags & IDE_HFLAG_BOOTABLE) ? 1 : 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 367 | |
Bartlomiej Zolnierkiewicz | a5d8c5c | 2007-07-20 01:11:55 +0200 | [diff] [blame] | 368 | if ((d->host_flags & IDE_HFLAG_ISA_PORTS) == 0) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 369 | /* Possibly we should fail if these checks report true */ |
| 370 | ide_pci_check_iomem(dev, d, 2*port); |
| 371 | ide_pci_check_iomem(dev, d, 2*port+1); |
| 372 | |
| 373 | ctl = pci_resource_start(dev, 2*port+1); |
| 374 | base = pci_resource_start(dev, 2*port); |
| 375 | if ((ctl && !base) || (base && !ctl)) { |
| 376 | printk(KERN_ERR "%s: inconsistent baseregs (BIOS) " |
| 377 | "for port %d, skipping\n", d->name, port); |
| 378 | return NULL; |
| 379 | } |
| 380 | } |
| 381 | if (!ctl) |
| 382 | { |
| 383 | /* Use default values */ |
| 384 | ctl = port ? 0x374 : 0x3f4; |
| 385 | base = port ? 0x170 : 0x1f0; |
| 386 | } |
Bartlomiej Zolnierkiewicz | 7cab14a | 2007-10-19 00:30:06 +0200 | [diff] [blame] | 387 | if ((hwif = ide_match_hwif(base, bootable, d->name)) == NULL) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 388 | return NULL; /* no room in ide_hwifs[] */ |
| 389 | if (hwif->io_ports[IDE_DATA_OFFSET] != base || |
| 390 | hwif->io_ports[IDE_CONTROL_OFFSET] != (ctl | 2)) { |
Bartlomiej Zolnierkiewicz | 9239b33 | 2007-10-20 00:32:33 +0200 | [diff] [blame] | 391 | hw_regs_t hw; |
| 392 | |
| 393 | memset(&hw, 0, sizeof(hw)); |
Bartlomiej Zolnierkiewicz | 847ddd2 | 2007-10-20 00:32:32 +0200 | [diff] [blame] | 394 | #ifndef CONFIG_IDE_ARCH_OBSOLETE_INIT |
Bartlomiej Zolnierkiewicz | 9239b33 | 2007-10-20 00:32:33 +0200 | [diff] [blame] | 395 | ide_std_init_ports(&hw, base, ctl | 2); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 396 | #else |
Bartlomiej Zolnierkiewicz | 9239b33 | 2007-10-20 00:32:33 +0200 | [diff] [blame] | 397 | ide_init_hwif_ports(&hw, base, ctl | 2, NULL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 398 | #endif |
Bartlomiej Zolnierkiewicz | 9239b33 | 2007-10-20 00:32:33 +0200 | [diff] [blame] | 399 | memcpy(hwif->io_ports, hw.io_ports, sizeof(hwif->io_ports)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 400 | hwif->noprobe = !hwif->io_ports[IDE_DATA_OFFSET]; |
| 401 | } |
Bartlomiej Zolnierkiewicz | 528a572 | 2007-10-20 00:32:30 +0200 | [diff] [blame] | 402 | hwif->chipset = d->chipset ? d->chipset : ide_pci; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 403 | hwif->pci_dev = dev; |
Bartlomiej Zolnierkiewicz | 039788e | 2007-10-20 00:32:34 +0200 | [diff] [blame] | 404 | hwif->cds = d; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 405 | hwif->channel = port; |
| 406 | |
| 407 | if (!hwif->irq) |
| 408 | hwif->irq = irq; |
| 409 | if (mate) { |
| 410 | hwif->mate = mate; |
| 411 | mate->mate = hwif; |
| 412 | } |
| 413 | return hwif; |
| 414 | } |
| 415 | |
| 416 | /** |
| 417 | * ide_hwif_setup_dma - configure DMA interface |
| 418 | * @dev: PCI device |
Bartlomiej Zolnierkiewicz | 039788e | 2007-10-20 00:32:34 +0200 | [diff] [blame] | 419 | * @d: IDE port info |
| 420 | * @hwif: IDE interface |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 421 | * |
| 422 | * Set up the DMA base for the interface. Enable the master bits as |
| 423 | * necessary and attempt to bring the device DMA into a ready to use |
| 424 | * state |
| 425 | */ |
Bartlomiej Zolnierkiewicz | 039788e | 2007-10-20 00:32:34 +0200 | [diff] [blame] | 426 | |
Bartlomiej Zolnierkiewicz | 8562043 | 2007-10-20 00:32:34 +0200 | [diff] [blame] | 427 | static void ide_hwif_setup_dma(struct pci_dev *dev, const struct ide_port_info *d, ide_hwif_t *hwif) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 428 | { |
Bartlomiej Zolnierkiewicz | 039788e | 2007-10-20 00:32:34 +0200 | [diff] [blame] | 429 | #ifdef CONFIG_BLK_DEV_IDEDMA_PCI |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 430 | u16 pcicmd; |
Bartlomiej Zolnierkiewicz | 47b6878 | 2007-10-19 00:30:06 +0200 | [diff] [blame] | 431 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 432 | pci_read_config_word(dev, PCI_COMMAND, &pcicmd); |
| 433 | |
Bartlomiej Zolnierkiewicz | 47b6878 | 2007-10-19 00:30:06 +0200 | [diff] [blame] | 434 | if ((d->host_flags & IDE_HFLAG_NO_AUTODMA) == 0 || |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 435 | ((dev->class >> 8) == PCI_CLASS_STORAGE_IDE && |
| 436 | (dev->class & 0x80))) { |
Bartlomiej Zolnierkiewicz | 9ffcf36 | 2007-10-19 00:30:07 +0200 | [diff] [blame] | 437 | unsigned long dma_base = ide_get_or_set_dma_base(d, hwif); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 438 | if (dma_base && !(pcicmd & PCI_COMMAND_MASTER)) { |
| 439 | /* |
| 440 | * Set up BM-DMA capability |
| 441 | * (PnP BIOS should have done this) |
| 442 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 443 | pci_set_master(dev); |
| 444 | if (pci_read_config_word(dev, PCI_COMMAND, &pcicmd) || !(pcicmd & PCI_COMMAND_MASTER)) { |
| 445 | printk(KERN_ERR "%s: %s error updating PCICMD\n", |
| 446 | hwif->name, d->name); |
| 447 | dma_base = 0; |
| 448 | } |
| 449 | } |
| 450 | if (dma_base) { |
| 451 | if (d->init_dma) { |
| 452 | d->init_dma(hwif, dma_base); |
| 453 | } else { |
| 454 | ide_setup_dma(hwif, dma_base, 8); |
| 455 | } |
| 456 | } else { |
| 457 | printk(KERN_INFO "%s: %s Bus-Master DMA disabled " |
| 458 | "(BIOS)\n", hwif->name, d->name); |
| 459 | } |
| 460 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 461 | #endif /* CONFIG_BLK_DEV_IDEDMA_PCI*/ |
Bartlomiej Zolnierkiewicz | 039788e | 2007-10-20 00:32:34 +0200 | [diff] [blame] | 462 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 463 | |
| 464 | /** |
| 465 | * ide_setup_pci_controller - set up IDE PCI |
| 466 | * @dev: PCI device |
Bartlomiej Zolnierkiewicz | 039788e | 2007-10-20 00:32:34 +0200 | [diff] [blame] | 467 | * @d: IDE port info |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 468 | * @noisy: verbose flag |
| 469 | * @config: returned as 1 if we configured the hardware |
| 470 | * |
| 471 | * Set up the PCI and controller side of the IDE interface. This brings |
| 472 | * up the PCI side of the device, checks that the device is enabled |
| 473 | * and enables it if need be |
| 474 | */ |
Bartlomiej Zolnierkiewicz | 039788e | 2007-10-20 00:32:34 +0200 | [diff] [blame] | 475 | |
Bartlomiej Zolnierkiewicz | 8562043 | 2007-10-20 00:32:34 +0200 | [diff] [blame] | 476 | static int ide_setup_pci_controller(struct pci_dev *dev, const struct ide_port_info *d, int noisy, int *config) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 477 | { |
| 478 | int ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 479 | u16 pcicmd; |
| 480 | |
| 481 | if (noisy) |
| 482 | ide_setup_pci_noise(dev, d); |
| 483 | |
| 484 | ret = ide_pci_enable(dev, d); |
| 485 | if (ret < 0) |
| 486 | goto out; |
| 487 | |
| 488 | ret = pci_read_config_word(dev, PCI_COMMAND, &pcicmd); |
| 489 | if (ret < 0) { |
| 490 | printk(KERN_ERR "%s: error accessing PCI regs\n", d->name); |
| 491 | goto out; |
| 492 | } |
| 493 | if (!(pcicmd & PCI_COMMAND_IO)) { /* is device disabled? */ |
| 494 | ret = ide_pci_configure(dev, d); |
| 495 | if (ret < 0) |
| 496 | goto out; |
| 497 | *config = 1; |
| 498 | printk(KERN_INFO "%s: device enabled (Linux)\n", d->name); |
| 499 | } |
| 500 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 501 | out: |
| 502 | return ret; |
| 503 | } |
| 504 | |
| 505 | /** |
| 506 | * ide_pci_setup_ports - configure ports/devices on PCI IDE |
| 507 | * @dev: PCI device |
Bartlomiej Zolnierkiewicz | 039788e | 2007-10-20 00:32:34 +0200 | [diff] [blame] | 508 | * @d: IDE port info |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 509 | * @pciirq: IRQ line |
Bartlomiej Zolnierkiewicz | 8447d9d | 2007-10-20 00:32:31 +0200 | [diff] [blame] | 510 | * @idx: ATA index table to update |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 511 | * |
| 512 | * Scan the interfaces attached to this device and do any |
| 513 | * necessary per port setup. Attach the devices and ask the |
| 514 | * generic DMA layer to do its work for us. |
| 515 | * |
| 516 | * Normally called automaticall from do_ide_pci_setup_device, |
| 517 | * but is also used directly as a helper function by some controllers |
| 518 | * where the chipset setup is not the default PCI IDE one. |
| 519 | */ |
Bartlomiej Zolnierkiewicz | 8447d9d | 2007-10-20 00:32:31 +0200 | [diff] [blame] | 520 | |
Bartlomiej Zolnierkiewicz | 8562043 | 2007-10-20 00:32:34 +0200 | [diff] [blame] | 521 | void ide_pci_setup_ports(struct pci_dev *dev, const struct ide_port_info *d, int pciirq, u8 *idx) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 522 | { |
Bartlomiej Zolnierkiewicz | a5d8c5c | 2007-07-20 01:11:55 +0200 | [diff] [blame] | 523 | int channels = (d->host_flags & IDE_HFLAG_SINGLE) ? 1 : 2, port; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 524 | ide_hwif_t *hwif, *mate = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 525 | u8 tmp; |
| 526 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 527 | /* |
| 528 | * Set up the IDE ports |
| 529 | */ |
Bartlomiej Zolnierkiewicz | cf6e854 | 2007-10-20 00:32:29 +0200 | [diff] [blame] | 530 | |
Bartlomiej Zolnierkiewicz | a5d8c5c | 2007-07-20 01:11:55 +0200 | [diff] [blame] | 531 | for (port = 0; port < channels; ++port) { |
Bartlomiej Zolnierkiewicz | 8562043 | 2007-10-20 00:32:34 +0200 | [diff] [blame] | 532 | const ide_pci_enablebit_t *e = &(d->enablebits[port]); |
| 533 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 534 | if (e->reg && (pci_read_config_byte(dev, e->reg, &tmp) || |
Bartlomiej Zolnierkiewicz | cf6e854 | 2007-10-20 00:32:29 +0200 | [diff] [blame] | 535 | (tmp & e->mask) != e->val)) { |
| 536 | printk(KERN_INFO "%s: IDE port disabled\n", d->name); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 537 | continue; /* port not enabled */ |
Bartlomiej Zolnierkiewicz | cf6e854 | 2007-10-20 00:32:29 +0200 | [diff] [blame] | 538 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 539 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 540 | if ((hwif = ide_hwif_configure(dev, d, mate, port, pciirq)) == NULL) |
| 541 | continue; |
| 542 | |
| 543 | /* setup proper ancestral information */ |
| 544 | hwif->gendev.parent = &dev->dev; |
| 545 | |
Bartlomiej Zolnierkiewicz | 8447d9d | 2007-10-20 00:32:31 +0200 | [diff] [blame] | 546 | *(idx + port) = hwif->index; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 547 | |
| 548 | |
| 549 | if (d->init_iops) |
| 550 | d->init_iops(hwif); |
| 551 | |
Bartlomiej Zolnierkiewicz | 9ffcf36 | 2007-10-19 00:30:07 +0200 | [diff] [blame] | 552 | if ((d->host_flags & IDE_HFLAG_NO_DMA) == 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 553 | ide_hwif_setup_dma(dev, d, hwif); |
Bartlomiej Zolnierkiewicz | 9ffcf36 | 2007-10-19 00:30:07 +0200 | [diff] [blame] | 554 | |
Bartlomiej Zolnierkiewicz | 8acf28c | 2007-10-20 00:32:30 +0200 | [diff] [blame] | 555 | if ((!hwif->irq && (d->host_flags & IDE_HFLAG_LEGACY_IRQS)) || |
| 556 | (d->host_flags & IDE_HFLAG_FORCE_LEGACY_IRQS)) |
Bartlomiej Zolnierkiewicz | 3985ee3 | 2007-10-19 00:30:11 +0200 | [diff] [blame] | 557 | hwif->irq = port ? 15 : 14; |
| 558 | |
Bartlomiej Zolnierkiewicz | fd9bb53 | 2007-10-20 00:32:31 +0200 | [diff] [blame] | 559 | hwif->fixup = d->fixup; |
| 560 | |
Bartlomiej Zolnierkiewicz | 6a824c9 | 2007-07-20 01:11:58 +0200 | [diff] [blame] | 561 | hwif->host_flags = d->host_flags; |
Bartlomiej Zolnierkiewicz | 4099d14 | 2007-07-20 01:11:59 +0200 | [diff] [blame] | 562 | hwif->pio_mask = d->pio_mask; |
Bartlomiej Zolnierkiewicz | 6a824c9 | 2007-07-20 01:11:58 +0200 | [diff] [blame] | 563 | |
Bartlomiej Zolnierkiewicz | 1c51361 | 2007-10-19 00:30:10 +0200 | [diff] [blame] | 564 | if ((d->host_flags & IDE_HFLAG_SERIALIZE) && hwif->mate) |
| 565 | hwif->mate->serialized = hwif->serialized = 1; |
| 566 | |
Bartlomiej Zolnierkiewicz | caea760 | 2007-10-20 00:32:30 +0200 | [diff] [blame] | 567 | if (d->host_flags & IDE_HFLAG_IO_32BIT) { |
| 568 | hwif->drives[0].io_32bit = 1; |
| 569 | hwif->drives[1].io_32bit = 1; |
| 570 | } |
| 571 | |
| 572 | if (d->host_flags & IDE_HFLAG_UNMASK_IRQS) { |
| 573 | hwif->drives[0].unmask = 1; |
| 574 | hwif->drives[1].unmask = 1; |
| 575 | } |
| 576 | |
Bartlomiej Zolnierkiewicz | 5f8b6c3 | 2007-10-19 00:30:07 +0200 | [diff] [blame] | 577 | if (hwif->dma_base) { |
| 578 | hwif->swdma_mask = d->swdma_mask; |
| 579 | hwif->mwdma_mask = d->mwdma_mask; |
| 580 | hwif->ultra_mask = d->udma_mask; |
| 581 | } |
| 582 | |
Bartlomiej Zolnierkiewicz | 85ad93a | 2007-10-19 00:30:12 +0200 | [diff] [blame] | 583 | hwif->drives[0].autotune = 1; |
| 584 | hwif->drives[1].autotune = 1; |
| 585 | |
Bartlomiej Zolnierkiewicz | 272a370 | 2007-10-20 00:32:30 +0200 | [diff] [blame] | 586 | if (d->host_flags & IDE_HFLAG_RQSIZE_256) |
| 587 | hwif->rqsize = 256; |
| 588 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 589 | if (d->init_hwif) |
| 590 | /* Call chipset-specific routine |
| 591 | * for each enabled hwif |
| 592 | */ |
| 593 | d->init_hwif(hwif); |
| 594 | |
| 595 | mate = hwif; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 596 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 597 | } |
| 598 | |
| 599 | EXPORT_SYMBOL_GPL(ide_pci_setup_ports); |
| 600 | |
| 601 | /* |
| 602 | * ide_setup_pci_device() looks at the primary/secondary interfaces |
| 603 | * on a PCI IDE device and, if they are enabled, prepares the IDE driver |
| 604 | * for use with them. This generic code works for most PCI chipsets. |
| 605 | * |
| 606 | * One thing that is not standardized is the location of the |
| 607 | * primary/secondary interface "enable/disable" bits. For chipsets that |
Bartlomiej Zolnierkiewicz | 039788e | 2007-10-20 00:32:34 +0200 | [diff] [blame] | 608 | * we "know" about, this information is in the struct ide_port_info; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 609 | * for all other chipsets, we just assume both interfaces are enabled. |
| 610 | */ |
Bartlomiej Zolnierkiewicz | 039788e | 2007-10-20 00:32:34 +0200 | [diff] [blame] | 611 | static int do_ide_setup_pci_device(struct pci_dev *dev, |
Bartlomiej Zolnierkiewicz | 8562043 | 2007-10-20 00:32:34 +0200 | [diff] [blame] | 612 | const struct ide_port_info *d, |
Bartlomiej Zolnierkiewicz | 8447d9d | 2007-10-20 00:32:31 +0200 | [diff] [blame] | 613 | u8 *idx, u8 noisy) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 614 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 615 | int tried_config = 0; |
| 616 | int pciirq, ret; |
| 617 | |
| 618 | ret = ide_setup_pci_controller(dev, d, noisy, &tried_config); |
| 619 | if (ret < 0) |
| 620 | goto out; |
| 621 | |
| 622 | /* |
| 623 | * Can we trust the reported IRQ? |
| 624 | */ |
| 625 | pciirq = dev->irq; |
| 626 | |
| 627 | /* Is it an "IDE storage" device in non-PCI mode? */ |
| 628 | if ((dev->class >> 8) == PCI_CLASS_STORAGE_IDE && (dev->class & 5) != 5) { |
| 629 | if (noisy) |
| 630 | printk(KERN_INFO "%s: not 100%% native mode: " |
| 631 | "will probe irqs later\n", d->name); |
| 632 | /* |
| 633 | * This allows offboard ide-pci cards the enable a BIOS, |
| 634 | * verify interrupt settings of split-mirror pci-config |
| 635 | * space, place chipset into init-mode, and/or preserve |
| 636 | * an interrupt if the card is not native ide support. |
| 637 | */ |
| 638 | ret = d->init_chipset ? d->init_chipset(dev, d->name) : 0; |
| 639 | if (ret < 0) |
| 640 | goto out; |
| 641 | pciirq = ret; |
| 642 | } else if (tried_config) { |
| 643 | if (noisy) |
| 644 | printk(KERN_INFO "%s: will probe irqs later\n", d->name); |
| 645 | pciirq = 0; |
| 646 | } else if (!pciirq) { |
| 647 | if (noisy) |
| 648 | printk(KERN_WARNING "%s: bad irq (%d): will probe later\n", |
| 649 | d->name, pciirq); |
| 650 | pciirq = 0; |
| 651 | } else { |
| 652 | if (d->init_chipset) { |
| 653 | ret = d->init_chipset(dev, d->name); |
| 654 | if (ret < 0) |
| 655 | goto out; |
| 656 | } |
| 657 | if (noisy) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 658 | printk(KERN_INFO "%s: 100%% native mode on irq %d\n", |
| 659 | d->name, pciirq); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 660 | } |
| 661 | |
| 662 | /* FIXME: silent failure can happen */ |
| 663 | |
Bartlomiej Zolnierkiewicz | 8447d9d | 2007-10-20 00:32:31 +0200 | [diff] [blame] | 664 | ide_pci_setup_ports(dev, d, pciirq, idx); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 665 | out: |
| 666 | return ret; |
| 667 | } |
| 668 | |
Bartlomiej Zolnierkiewicz | 8562043 | 2007-10-20 00:32:34 +0200 | [diff] [blame] | 669 | int ide_setup_pci_device(struct pci_dev *dev, const struct ide_port_info *d) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 670 | { |
Bartlomiej Zolnierkiewicz | 8447d9d | 2007-10-20 00:32:31 +0200 | [diff] [blame] | 671 | u8 idx[4] = { 0xff, 0xff, 0xff, 0xff }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 672 | int ret; |
| 673 | |
Bartlomiej Zolnierkiewicz | 8447d9d | 2007-10-20 00:32:31 +0200 | [diff] [blame] | 674 | ret = do_ide_setup_pci_device(dev, d, &idx[0], 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 675 | |
Bartlomiej Zolnierkiewicz | 8447d9d | 2007-10-20 00:32:31 +0200 | [diff] [blame] | 676 | if (ret >= 0) |
| 677 | ide_device_add(idx); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 678 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 679 | return ret; |
| 680 | } |
| 681 | |
| 682 | EXPORT_SYMBOL_GPL(ide_setup_pci_device); |
| 683 | |
| 684 | int ide_setup_pci_devices(struct pci_dev *dev1, struct pci_dev *dev2, |
Bartlomiej Zolnierkiewicz | 8562043 | 2007-10-20 00:32:34 +0200 | [diff] [blame] | 685 | const struct ide_port_info *d) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 686 | { |
| 687 | struct pci_dev *pdev[] = { dev1, dev2 }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 688 | int ret, i; |
Bartlomiej Zolnierkiewicz | 8447d9d | 2007-10-20 00:32:31 +0200 | [diff] [blame] | 689 | u8 idx[4] = { 0xff, 0xff, 0xff, 0xff }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 690 | |
| 691 | for (i = 0; i < 2; i++) { |
Bartlomiej Zolnierkiewicz | 8447d9d | 2007-10-20 00:32:31 +0200 | [diff] [blame] | 692 | 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] | 693 | /* |
| 694 | * FIXME: Mom, mom, they stole me the helper function to undo |
| 695 | * do_ide_setup_pci_device() on the first device! |
| 696 | */ |
| 697 | if (ret < 0) |
| 698 | goto out; |
| 699 | } |
| 700 | |
Bartlomiej Zolnierkiewicz | 8447d9d | 2007-10-20 00:32:31 +0200 | [diff] [blame] | 701 | ide_device_add(idx); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 702 | out: |
| 703 | return ret; |
| 704 | } |
| 705 | |
| 706 | EXPORT_SYMBOL_GPL(ide_setup_pci_devices); |
| 707 | |
Bartlomiej Zolnierkiewicz | 6d208b3 | 2007-05-10 00:01:11 +0200 | [diff] [blame] | 708 | #ifdef CONFIG_IDEPCI_PCIBUS_ORDER |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 709 | /* |
| 710 | * Module interfaces |
| 711 | */ |
| 712 | |
| 713 | static int pre_init = 1; /* Before first ordered IDE scan */ |
| 714 | static LIST_HEAD(ide_pci_drivers); |
| 715 | |
| 716 | /* |
Ralf Baechle | c37ea21 | 2005-11-18 23:11:24 +0100 | [diff] [blame] | 717 | * __ide_pci_register_driver - attach IDE driver |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 718 | * @driver: pci driver |
Laurent riffard | 863b18f | 2005-10-27 23:12:54 +0200 | [diff] [blame] | 719 | * @module: owner module of the driver |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 720 | * |
| 721 | * Registers a driver with the IDE layer. The IDE layer arranges that |
| 722 | * boot time setup is done in the expected device order and then |
| 723 | * hands the controllers off to the core PCI code to do the rest of |
| 724 | * the work. |
| 725 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 726 | * Returns are the same as for pci_register_driver |
| 727 | */ |
| 728 | |
Greg Kroah-Hartman | 725522b | 2007-01-15 11:50:02 -0800 | [diff] [blame] | 729 | int __ide_pci_register_driver(struct pci_driver *driver, struct module *module, |
| 730 | const char *mod_name) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 731 | { |
| 732 | if(!pre_init) |
Greg Kroah-Hartman | 725522b | 2007-01-15 11:50:02 -0800 | [diff] [blame] | 733 | return __pci_register_driver(driver, module, mod_name); |
Laurent riffard | 863b18f | 2005-10-27 23:12:54 +0200 | [diff] [blame] | 734 | driver->driver.owner = module; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 735 | list_add_tail(&driver->node, &ide_pci_drivers); |
| 736 | return 0; |
| 737 | } |
| 738 | |
Laurent riffard | 863b18f | 2005-10-27 23:12:54 +0200 | [diff] [blame] | 739 | EXPORT_SYMBOL_GPL(__ide_pci_register_driver); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 740 | |
| 741 | /** |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 742 | * ide_scan_pcidev - find an IDE driver for a device |
| 743 | * @dev: PCI device to check |
| 744 | * |
| 745 | * Look for an IDE driver to handle the device we are considering. |
| 746 | * This is only used during boot up to get the ordering correct. After |
| 747 | * boot up the pci layer takes over the job. |
| 748 | */ |
| 749 | |
| 750 | static int __init ide_scan_pcidev(struct pci_dev *dev) |
| 751 | { |
| 752 | struct list_head *l; |
| 753 | struct pci_driver *d; |
| 754 | |
Sergei Shtylyov | 0505b55 | 2007-09-11 22:28:34 +0200 | [diff] [blame] | 755 | list_for_each(l, &ide_pci_drivers) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 756 | d = list_entry(l, struct pci_driver, node); |
Sergei Shtylyov | 0505b55 | 2007-09-11 22:28:34 +0200 | [diff] [blame] | 757 | if (d->id_table) { |
| 758 | const struct pci_device_id *id = pci_match_id(d->id_table, |
| 759 | dev); |
| 760 | if (id != NULL && d->probe(dev, id) >= 0) { |
| 761 | dev->driver = d; |
| 762 | pci_dev_get(dev); |
| 763 | return 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 764 | } |
| 765 | } |
| 766 | } |
| 767 | return 0; |
| 768 | } |
| 769 | |
| 770 | /** |
| 771 | * ide_scan_pcibus - perform the initial IDE driver scan |
| 772 | * @scan_direction: set for reverse order scanning |
| 773 | * |
| 774 | * Perform the initial bus rather than driver ordered scan of the |
| 775 | * PCI drivers. After this all IDE pci handling becomes standard |
| 776 | * module ordering not traditionally ordered. |
| 777 | */ |
| 778 | |
| 779 | void __init ide_scan_pcibus (int scan_direction) |
| 780 | { |
| 781 | struct pci_dev *dev = NULL; |
| 782 | struct pci_driver *d; |
| 783 | struct list_head *l, *n; |
| 784 | |
| 785 | pre_init = 0; |
Sergei Shtylyov | 0505b55 | 2007-09-11 22:28:34 +0200 | [diff] [blame] | 786 | if (!scan_direction) |
| 787 | 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] | 788 | ide_scan_pcidev(dev); |
Sergei Shtylyov | 0505b55 | 2007-09-11 22:28:34 +0200 | [diff] [blame] | 789 | else |
| 790 | while ((dev = pci_get_device_reverse(PCI_ANY_ID, PCI_ANY_ID, dev)) |
| 791 | != NULL) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 792 | ide_scan_pcidev(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 793 | |
| 794 | /* |
| 795 | * Hand the drivers over to the PCI layer now we |
| 796 | * are post init. |
| 797 | */ |
| 798 | |
Andrew Morton | d61bcce | 2007-07-03 22:28:36 +0200 | [diff] [blame] | 799 | list_for_each_safe(l, n, &ide_pci_drivers) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 800 | list_del(l); |
| 801 | d = list_entry(l, struct pci_driver, node); |
Sergei Shtylyov | 0505b55 | 2007-09-11 22:28:34 +0200 | [diff] [blame] | 802 | if (__pci_register_driver(d, d->driver.owner, d->driver.mod_name)) |
| 803 | printk(KERN_ERR "%s: failed to register driver for %s\n", |
| 804 | __FUNCTION__, d->driver.mod_name); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 805 | } |
| 806 | } |
Bartlomiej Zolnierkiewicz | 6d208b3 | 2007-05-10 00:01:11 +0200 | [diff] [blame] | 807 | #endif |