ide: factor out adding drive to hwgroup from init_irq()
[deliverable/linux.git] / drivers / ide / ide-probe.c
index 84810aa57a67daeef7c99f26e7a91a534ba1d124..4d940d1a80edd4dc836620fb3afb98c336c15aa7 100644 (file)
@@ -613,7 +613,7 @@ static void hwif_release_dev (struct device *dev)
        complete(&hwif->gendev_rel_comp);
 }
 
-static void hwif_register (ide_hwif_t *hwif)
+static void ide_register_port(ide_hwif_t *hwif)
 {
        int ret;
 
@@ -738,25 +738,16 @@ void ide_undecoded_slave(ide_drive_t *drive1)
 
 EXPORT_SYMBOL_GPL(ide_undecoded_slave);
 
-/*
- * This routine only knows how to look for drive units 0 and 1
- * on an interface, so any setting of MAX_DRIVES > 2 won't work here.
- */
-static void probe_hwif(ide_hwif_t *hwif)
+static int ide_probe_port(ide_hwif_t *hwif)
 {
        unsigned long flags;
        unsigned int irqd;
-       int unit;
+       int unit, rc = -ENODEV;
 
-       if (hwif->noprobe)
-               return;
+       BUG_ON(hwif->present);
 
-       if ((hwif->chipset != ide_4drives || !hwif->mate || !hwif->mate->present) &&
-           (ide_hwif_request_regions(hwif))) {
-               printk(KERN_ERR "%s: ports already in use, skipping probe\n",
-                               hwif->name);
-               return; 
-       }
+       if (hwif->noprobe)
+               return -EACCES;
 
        /*
         * We must always disable IRQ, as probe_for_drive will assert IRQ, but
@@ -778,14 +769,8 @@ static void probe_hwif(ide_hwif_t *hwif)
                ide_drive_t *drive = &hwif->drives[unit];
                drive->dn = (hwif->channel ? 2 : 0) + unit;
                (void) probe_for_drive(drive);
-               if (drive->present && !hwif->present) {
-                       hwif->present = 1;
-                       if (hwif->chipset != ide_4drives ||
-                           !hwif->mate || 
-                           !hwif->mate->present) {
-                               hwif_register(hwif);
-                       }
-               }
+               if (drive->present)
+                       rc = 0;
        }
        if (hwif->io_ports[IDE_CONTROL_OFFSET] && hwif->reset) {
                printk(KERN_WARNING "%s: reset\n", hwif->name);
@@ -802,10 +787,12 @@ static void probe_hwif(ide_hwif_t *hwif)
        if (irqd)
                enable_irq(irqd);
 
-       if (!hwif->present) {
-               ide_hwif_release_regions(hwif);
-               return;
-       }
+       return rc;
+}
+
+static void ide_port_tune_devices(ide_hwif_t *hwif)
+{
+       int unit;
 
        for (unit = 0; unit < MAX_DRIVES; unit++) {
                ide_drive_t *drive = &hwif->drives[unit];
@@ -835,7 +822,7 @@ static void probe_hwif(ide_hwif_t *hwif)
        for (unit = 0; unit < MAX_DRIVES; ++unit) {
                ide_drive_t *drive = &hwif->drives[unit];
 
-               if (hwif->no_io_32bit)
+               if (hwif->host_flags & IDE_HFLAG_NO_IO_32BIT)
                        drive->no_io_32bit = 1;
                else
                        drive->no_io_32bit = drive->id->dword_io ? 1 : 0;
@@ -894,13 +881,6 @@ static int ide_init_queue(ide_drive_t *drive)
        q->queuedata = drive;
        blk_queue_segment_boundary(q, 0xffff);
 
-       if (!hwif->rqsize) {
-               if ((hwif->host_flags & IDE_HFLAG_NO_LBA48) ||
-                   (hwif->host_flags & IDE_HFLAG_NO_LBA48_DMA))
-                       hwif->rqsize = 256;
-               else
-                       hwif->rqsize = 65536;
-       }
        if (hwif->rqsize < max_sectors)
                max_sectors = hwif->rqsize;
        blk_queue_max_sectors(q, max_sectors);
@@ -931,6 +911,23 @@ static int ide_init_queue(ide_drive_t *drive)
        return 0;
 }
 
+static void ide_add_drive_to_hwgroup(ide_drive_t *drive)
+{
+       ide_hwgroup_t *hwgroup = drive->hwif->hwgroup;
+
+       spin_lock_irq(&ide_lock);
+       if (!hwgroup->drive) {
+               /* first drive for hwgroup. */
+               drive->next = drive;
+               hwgroup->drive = drive;
+               hwgroup->hwif = HWIF(hwgroup->drive);
+       } else {
+               drive->next = hwgroup->drive->next;
+               hwgroup->drive->next = drive;
+       }
+       spin_unlock_irq(&ide_lock);
+}
+
 /*
  * This routine sets up the irq for an ide interface, and creates a new
  * hwgroup for the irq/hwif if none was previously assigned.
@@ -996,6 +993,7 @@ static int init_irq (ide_hwif_t *hwif)
                spin_lock_irq(&ide_lock);
                hwif->next = hwgroup->hwif->next;
                hwgroup->hwif->next = hwif;
+               BUG_ON(hwif->next == hwif);
                spin_unlock_irq(&ide_lock);
        } else {
                hwgroup = kmalloc_node(sizeof(*hwgroup), GFP_KERNEL|__GFP_ZERO,
@@ -1031,6 +1029,14 @@ static int init_irq (ide_hwif_t *hwif)
                        goto out_unlink;
        }
 
+       if (!hwif->rqsize) {
+               if ((hwif->host_flags & IDE_HFLAG_NO_LBA48) ||
+                   (hwif->host_flags & IDE_HFLAG_NO_LBA48_DMA))
+                       hwif->rqsize = 256;
+               else
+                       hwif->rqsize = 65536;
+       }
+
        /*
         * For any present drive:
         * - allocate the block device queue
@@ -1044,17 +1050,7 @@ static int init_irq (ide_hwif_t *hwif)
                        printk(KERN_ERR "ide: failed to init %s\n",drive->name);
                        continue;
                }
-               spin_lock_irq(&ide_lock);
-               if (!hwgroup->drive) {
-                       /* first drive for hwgroup. */
-                       drive->next = drive;
-                       hwgroup->drive = drive;
-                       hwgroup->hwif = HWIF(hwgroup->drive);
-               } else {
-                       drive->next = hwgroup->drive->next;
-                       hwgroup->drive->next = drive;
-               }
-               spin_unlock_irq(&ide_lock);
+               ide_add_drive_to_hwgroup(drive);
        }
 
 #if !defined(__mc68000__) && !defined(CONFIG_APUS)
@@ -1073,25 +1069,7 @@ static int init_irq (ide_hwif_t *hwif)
        mutex_unlock(&ide_cfg_mtx);
        return 0;
 out_unlink:
-       spin_lock_irq(&ide_lock);
-       if (hwif->next == hwif) {
-               BUG_ON(match);
-               BUG_ON(hwgroup->hwif != hwif);
-               kfree(hwgroup);
-       } else {
-               ide_hwif_t *g;
-               g = hwgroup->hwif;
-               while (g->next != hwif)
-                       g = g->next;
-               g->next = hwif->next;
-               if (hwgroup->hwif == hwif) {
-                       /* Impossible. */
-                       printk(KERN_ERR "Duh. Uninitialized hwif listed as active hwif.\n");
-                       hwgroup->hwif = g;
-               }
-               BUG_ON(hwgroup->hwif == hwif);
-       }
-       spin_unlock_irq(&ide_lock);
+       ide_remove_port_from_hwgroup(hwif);
 out_up:
        mutex_unlock(&ide_cfg_mtx);
        return 1;
@@ -1212,30 +1190,6 @@ static void drive_release_dev (struct device *dev)
        complete(&drive->gendev_rel_comp);
 }
 
-/*
- * init_gendisk() (as opposed to ide_geninit) is called for each major device,
- * after probing for drives, to allocate partition tables and other data
- * structures needed for the routines in genhd.c.  ide_geninit() gets called
- * somewhat later, during the partition check.
- */
-static void init_gendisk (ide_hwif_t *hwif)
-{
-       unsigned int unit;
-
-       for (unit = 0; unit < MAX_DRIVES; ++unit) {
-               ide_drive_t * drive = &hwif->drives[unit];
-               ide_add_generic_settings(drive);
-               snprintf(drive->gendev.bus_id,BUS_ID_SIZE,"%u.%u",
-                        hwif->index,unit);
-               drive->gendev.parent = &hwif->gendev;
-               drive->gendev.bus = &ide_bus_type;
-               drive->gendev.driver_data = drive;
-               drive->gendev.release = drive_release_dev;
-       }
-       blk_register_region(MKDEV(hwif->major, 0), MAX_DRIVES << PARTN_BITS,
-                       THIS_MODULE, ata_probe, ata_lock, hwif);
-}
-
 static int hwif_init(ide_hwif_t *hwif)
 {
        int old_irq;
@@ -1292,7 +1246,8 @@ static int hwif_init(ide_hwif_t *hwif)
                hwif->name, hwif->irq);
 
 done:
-       init_gendisk(hwif);
+       blk_register_region(MKDEV(hwif->major, 0), MAX_DRIVES << PARTN_BITS,
+                           THIS_MODULE, ata_probe, ata_lock, hwif);
        ide_acpi_init(hwif);
        return 1;
 
@@ -1307,28 +1262,143 @@ static void hwif_register_devices(ide_hwif_t *hwif)
 
        for (i = 0; i < MAX_DRIVES; i++) {
                ide_drive_t *drive = &hwif->drives[i];
+               struct device *dev = &drive->gendev;
+               int ret;
 
-               if (drive->present) {
-                       int ret = device_register(&drive->gendev);
+               if (!drive->present)
+                       continue;
 
-                       if (ret < 0)
-                               printk(KERN_WARNING "IDE: %s: "
-                                       "device_register error: %d\n",
-                                       __FUNCTION__, ret);
-               }
+               ide_add_generic_settings(drive);
+
+               snprintf(dev->bus_id, BUS_ID_SIZE, "%u.%u", hwif->index, i);
+               dev->parent = &hwif->gendev;
+               dev->bus = &ide_bus_type;
+               dev->driver_data = drive;
+               dev->release = drive_release_dev;
+
+               ret = device_register(dev);
+               if (ret < 0)
+                       printk(KERN_WARNING "IDE: %s: device_register error: "
+                                           "%d\n", __func__, ret);
+       }
+}
+
+static void ide_port_init_devices(ide_hwif_t *hwif)
+{
+       int i;
+
+       for (i = 0; i < MAX_DRIVES; i++) {
+               ide_drive_t *drive = &hwif->drives[i];
+
+               if (hwif->host_flags & IDE_HFLAG_IO_32BIT)
+                       drive->io_32bit = 1;
+               if (hwif->host_flags & IDE_HFLAG_UNMASK_IRQS)
+                       drive->unmask = 1;
+               if (hwif->host_flags & IDE_HFLAG_NO_UNMASK_IRQS)
+                       drive->no_unmask = 1;
+               if ((hwif->host_flags & IDE_HFLAG_NO_AUTOTUNE) == 0)
+                       drive->autotune = 1;
+       }
+
+       if (hwif->port_init_devs)
+               hwif->port_init_devs(hwif);
+}
+
+static void ide_init_port(ide_hwif_t *hwif, unsigned int port,
+                         const struct ide_port_info *d)
+{
+       if (d->chipset != ide_etrax100)
+               hwif->channel = port;
+
+       if (d->chipset)
+               hwif->chipset = d->chipset;
+
+       if (d->init_iops)
+               d->init_iops(hwif);
+
+       if ((d->host_flags & IDE_HFLAG_NO_DMA) == 0)
+               ide_hwif_setup_dma(hwif, d);
+
+       if ((!hwif->irq && (d->host_flags & IDE_HFLAG_LEGACY_IRQS)) ||
+           (d->host_flags & IDE_HFLAG_FORCE_LEGACY_IRQS))
+               hwif->irq = port ? 15 : 14;
+
+       hwif->host_flags = d->host_flags;
+       hwif->pio_mask = d->pio_mask;
+
+       if ((d->host_flags & IDE_HFLAG_SERIALIZE) && hwif->mate)
+               hwif->mate->serialized = hwif->serialized = 1;
+
+       hwif->swdma_mask = d->swdma_mask;
+       hwif->mwdma_mask = d->mwdma_mask;
+       hwif->ultra_mask = d->udma_mask;
+
+       /* reset DMA masks only for SFF-style DMA controllers */
+       if ((d->host_flags && IDE_HFLAG_NO_DMA) == 0 && hwif->dma_base == 0)
+               hwif->swdma_mask = hwif->mwdma_mask = hwif->ultra_mask = 0;
+
+       if (d->host_flags & IDE_HFLAG_RQSIZE_256)
+               hwif->rqsize = 256;
+
+       /* call chipset specific routine for each enabled port */
+       if (d->init_hwif)
+               d->init_hwif(hwif);
+
+       if (hwif->cable_detect && (hwif->ultra_mask & 0x78)) {
+               if (hwif->cbl != ATA_CBL_PATA40_SHORT)
+                       hwif->cbl = hwif->cable_detect(hwif);
        }
 }
 
-int ide_device_add_all(u8 *idx)
+int ide_device_add_all(u8 *idx, const struct ide_port_info *d)
 {
-       ide_hwif_t *hwif;
+       ide_hwif_t *hwif, *mate = NULL;
        int i, rc = 0;
 
+       for (i = 0; i < MAX_HWIFS; i++) {
+               if (d == NULL || idx[i] == 0xff) {
+                       mate = NULL;
+                       continue;
+               }
+
+               hwif = &ide_hwifs[idx[i]];
+
+               if (d->chipset != ide_etrax100 && (i & 1) && mate) {
+                       hwif->mate = mate;
+                       mate->mate = hwif;
+               }
+
+               mate = (i & 1) ? NULL : hwif;
+
+               ide_init_port(hwif, i & 1, d);
+               ide_port_init_devices(hwif);
+       }
+
        for (i = 0; i < MAX_HWIFS; i++) {
                if (idx[i] == 0xff)
                        continue;
 
-               probe_hwif(&ide_hwifs[idx[i]]);
+               hwif = &ide_hwifs[idx[i]];
+
+               if ((hwif->chipset != ide_4drives || !hwif->mate ||
+                    !hwif->mate->present) && ide_hwif_request_regions(hwif)) {
+                       printk(KERN_ERR "%s: ports already in use, "
+                                       "skipping probe\n", hwif->name);
+                       continue;
+               }
+
+               if (ide_probe_port(hwif) < 0) {
+                       ide_hwif_release_regions(hwif);
+                       continue;
+               }
+
+               hwif->present = 1;
+
+               if (hwif->chipset != ide_4drives || !hwif->mate ||
+                   !hwif->mate->present)
+                       ide_register_port(hwif);
+
+               ide_port_tune_devices(hwif);
        }
 
        for (i = 0; i < MAX_HWIFS; i++) {
@@ -1372,7 +1442,7 @@ int ide_device_add_all(u8 *idx)
 }
 EXPORT_SYMBOL_GPL(ide_device_add_all);
 
-int ide_device_add(u8 idx[4])
+int ide_device_add(u8 idx[4], const struct ide_port_info *d)
 {
        u8 idx_all[MAX_HWIFS];
        int i;
@@ -1380,6 +1450,6 @@ int ide_device_add(u8 idx[4])
        for (i = 0; i < MAX_HWIFS; i++)
                idx_all[i] = (i < 4) ? idx[i] : 0xff;
 
-       return ide_device_add_all(idx_all);
+       return ide_device_add_all(idx_all, d);
 }
 EXPORT_SYMBOL_GPL(ide_device_add);
This page took 0.030812 seconds and 5 git commands to generate.