diff options
Diffstat (limited to 'drivers/ide/ide-probe.c')
-rw-r--r-- | drivers/ide/ide-probe.c | 190 |
1 files changed, 84 insertions, 106 deletions
diff --git a/drivers/ide/ide-probe.c b/drivers/ide/ide-probe.c index edf650b20c67..98a8af44bf64 100644 --- a/drivers/ide/ide-probe.c +++ b/drivers/ide/ide-probe.c | |||
@@ -1,7 +1,6 @@ | |||
1 | /* | 1 | /* |
2 | * linux/drivers/ide/ide-probe.c Version 1.11 Mar 05, 2003 | 2 | * Copyright (C) 1994-1998 Linus Torvalds & authors (see below) |
3 | * | 3 | * Copyright (C) 2005, 2007 Bartlomiej Zolnierkiewicz |
4 | * Copyright (C) 1994-1998 Linus Torvalds & authors (see below) | ||
5 | */ | 4 | */ |
6 | 5 | ||
7 | /* | 6 | /* |
@@ -129,6 +128,10 @@ static inline void do_identify (ide_drive_t *drive, u8 cmd) | |||
129 | 128 | ||
130 | drive->id_read = 1; | 129 | drive->id_read = 1; |
131 | local_irq_enable(); | 130 | local_irq_enable(); |
131 | #ifdef DEBUG | ||
132 | printk(KERN_INFO "%s: dumping identify data\n", drive->name); | ||
133 | ide_dump_identify((u8 *)id); | ||
134 | #endif | ||
132 | ide_fix_driveid(id); | 135 | ide_fix_driveid(id); |
133 | 136 | ||
134 | #if defined (CONFIG_SCSI_EATA_PIO) || defined (CONFIG_SCSI_EATA) | 137 | #if defined (CONFIG_SCSI_EATA_PIO) || defined (CONFIG_SCSI_EATA) |
@@ -610,7 +613,7 @@ static void hwif_release_dev (struct device *dev) | |||
610 | complete(&hwif->gendev_rel_comp); | 613 | complete(&hwif->gendev_rel_comp); |
611 | } | 614 | } |
612 | 615 | ||
613 | static void hwif_register (ide_hwif_t *hwif) | 616 | static void ide_register_port(ide_hwif_t *hwif) |
614 | { | 617 | { |
615 | int ret; | 618 | int ret; |
616 | 619 | ||
@@ -618,8 +621,8 @@ static void hwif_register (ide_hwif_t *hwif) | |||
618 | strlcpy(hwif->gendev.bus_id,hwif->name,BUS_ID_SIZE); | 621 | strlcpy(hwif->gendev.bus_id,hwif->name,BUS_ID_SIZE); |
619 | hwif->gendev.driver_data = hwif; | 622 | hwif->gendev.driver_data = hwif; |
620 | if (hwif->gendev.parent == NULL) { | 623 | if (hwif->gendev.parent == NULL) { |
621 | if (hwif->pci_dev) | 624 | if (hwif->dev) |
622 | hwif->gendev.parent = &hwif->pci_dev->dev; | 625 | hwif->gendev.parent = hwif->dev; |
623 | else | 626 | else |
624 | /* Would like to do = &device_legacy */ | 627 | /* Would like to do = &device_legacy */ |
625 | hwif->gendev.parent = NULL; | 628 | hwif->gendev.parent = NULL; |
@@ -631,7 +634,33 @@ static void hwif_register (ide_hwif_t *hwif) | |||
631 | __FUNCTION__, ret); | 634 | __FUNCTION__, ret); |
632 | } | 635 | } |
633 | 636 | ||
634 | static int wait_hwif_ready(ide_hwif_t *hwif) | 637 | /** |
638 | * ide_port_wait_ready - wait for port to become ready | ||
639 | * @hwif: IDE port | ||
640 | * | ||
641 | * This is needed on some PPCs and a bunch of BIOS-less embedded | ||
642 | * platforms. Typical cases are: | ||
643 | * | ||
644 | * - The firmware hard reset the disk before booting the kernel, | ||
645 | * the drive is still doing it's poweron-reset sequence, that | ||
646 | * can take up to 30 seconds. | ||
647 | * | ||
648 | * - The firmware does nothing (or no firmware), the device is | ||
649 | * still in POST state (same as above actually). | ||
650 | * | ||
651 | * - Some CD/DVD/Writer combo drives tend to drive the bus during | ||
652 | * their reset sequence even when they are non-selected slave | ||
653 | * devices, thus preventing discovery of the main HD. | ||
654 | * | ||
655 | * Doing this wait-for-non-busy should not harm any existing | ||
656 | * configuration and fix some issues like the above. | ||
657 | * | ||
658 | * BenH. | ||
659 | * | ||
660 | * Returns 0 on success, error code (< 0) otherwise. | ||
661 | */ | ||
662 | |||
663 | static int ide_port_wait_ready(ide_hwif_t *hwif) | ||
635 | { | 664 | { |
636 | int unit, rc; | 665 | int unit, rc; |
637 | 666 | ||
@@ -709,36 +738,16 @@ void ide_undecoded_slave(ide_drive_t *drive1) | |||
709 | 738 | ||
710 | EXPORT_SYMBOL_GPL(ide_undecoded_slave); | 739 | EXPORT_SYMBOL_GPL(ide_undecoded_slave); |
711 | 740 | ||
712 | /* | 741 | static int ide_probe_port(ide_hwif_t *hwif) |
713 | * This routine only knows how to look for drive units 0 and 1 | ||
714 | * on an interface, so any setting of MAX_DRIVES > 2 won't work here. | ||
715 | */ | ||
716 | static void probe_hwif(ide_hwif_t *hwif) | ||
717 | { | 742 | { |
718 | unsigned long flags; | 743 | unsigned long flags; |
719 | unsigned int irqd; | 744 | unsigned int irqd; |
720 | int unit; | 745 | int unit, rc = -ENODEV; |
721 | 746 | ||
722 | if (hwif->noprobe) | 747 | BUG_ON(hwif->present); |
723 | return; | ||
724 | 748 | ||
725 | if ((hwif->chipset != ide_4drives || !hwif->mate || !hwif->mate->present) && | 749 | if (hwif->noprobe) |
726 | (ide_hwif_request_regions(hwif))) { | 750 | return -EACCES; |
727 | u16 msgout = 0; | ||
728 | for (unit = 0; unit < MAX_DRIVES; ++unit) { | ||
729 | ide_drive_t *drive = &hwif->drives[unit]; | ||
730 | if (drive->present) { | ||
731 | drive->present = 0; | ||
732 | printk(KERN_ERR "%s: ERROR, PORTS ALREADY IN USE\n", | ||
733 | drive->name); | ||
734 | msgout = 1; | ||
735 | } | ||
736 | } | ||
737 | if (!msgout) | ||
738 | printk(KERN_ERR "%s: ports already in use, skipping probe\n", | ||
739 | hwif->name); | ||
740 | return; | ||
741 | } | ||
742 | 751 | ||
743 | /* | 752 | /* |
744 | * We must always disable IRQ, as probe_for_drive will assert IRQ, but | 753 | * We must always disable IRQ, as probe_for_drive will assert IRQ, but |
@@ -750,26 +759,7 @@ static void probe_hwif(ide_hwif_t *hwif) | |||
750 | 759 | ||
751 | local_irq_set(flags); | 760 | local_irq_set(flags); |
752 | 761 | ||
753 | /* This is needed on some PPCs and a bunch of BIOS-less embedded | 762 | if (ide_port_wait_ready(hwif) == -EBUSY) |
754 | * platforms. Typical cases are: | ||
755 | * | ||
756 | * - The firmware hard reset the disk before booting the kernel, | ||
757 | * the drive is still doing it's poweron-reset sequence, that | ||
758 | * can take up to 30 seconds | ||
759 | * - The firmware does nothing (or no firmware), the device is | ||
760 | * still in POST state (same as above actually). | ||
761 | * - Some CD/DVD/Writer combo drives tend to drive the bus during | ||
762 | * their reset sequence even when they are non-selected slave | ||
763 | * devices, thus preventing discovery of the main HD | ||
764 | * | ||
765 | * Doing this wait-for-busy should not harm any existing configuration | ||
766 | * (at least things won't be worse than what current code does, that | ||
767 | * is blindly go & talk to the drive) and fix some issues like the | ||
768 | * above. | ||
769 | * | ||
770 | * BenH. | ||
771 | */ | ||
772 | if (wait_hwif_ready(hwif) == -EBUSY) | ||
773 | printk(KERN_DEBUG "%s: Wait for ready failed before probe !\n", hwif->name); | 763 | printk(KERN_DEBUG "%s: Wait for ready failed before probe !\n", hwif->name); |
774 | 764 | ||
775 | /* | 765 | /* |
@@ -779,14 +769,8 @@ static void probe_hwif(ide_hwif_t *hwif) | |||
779 | ide_drive_t *drive = &hwif->drives[unit]; | 769 | ide_drive_t *drive = &hwif->drives[unit]; |
780 | drive->dn = (hwif->channel ? 2 : 0) + unit; | 770 | drive->dn = (hwif->channel ? 2 : 0) + unit; |
781 | (void) probe_for_drive(drive); | 771 | (void) probe_for_drive(drive); |
782 | if (drive->present && !hwif->present) { | 772 | if (drive->present) |
783 | hwif->present = 1; | 773 | rc = 0; |
784 | if (hwif->chipset != ide_4drives || | ||
785 | !hwif->mate || | ||
786 | !hwif->mate->present) { | ||
787 | hwif_register(hwif); | ||
788 | } | ||
789 | } | ||
790 | } | 774 | } |
791 | if (hwif->io_ports[IDE_CONTROL_OFFSET] && hwif->reset) { | 775 | if (hwif->io_ports[IDE_CONTROL_OFFSET] && hwif->reset) { |
792 | printk(KERN_WARNING "%s: reset\n", hwif->name); | 776 | printk(KERN_WARNING "%s: reset\n", hwif->name); |
@@ -803,10 +787,12 @@ static void probe_hwif(ide_hwif_t *hwif) | |||
803 | if (irqd) | 787 | if (irqd) |
804 | enable_irq(irqd); | 788 | enable_irq(irqd); |
805 | 789 | ||
806 | if (!hwif->present) { | 790 | return rc; |
807 | ide_hwif_release_regions(hwif); | 791 | } |
808 | return; | 792 | |
809 | } | 793 | static void ide_port_tune_devices(ide_hwif_t *hwif) |
794 | { | ||
795 | int unit; | ||
810 | 796 | ||
811 | for (unit = 0; unit < MAX_DRIVES; unit++) { | 797 | for (unit = 0; unit < MAX_DRIVES; unit++) { |
812 | ide_drive_t *drive = &hwif->drives[unit]; | 798 | ide_drive_t *drive = &hwif->drives[unit]; |
@@ -997,21 +983,17 @@ static int init_irq (ide_hwif_t *hwif) | |||
997 | spin_lock_irq(&ide_lock); | 983 | spin_lock_irq(&ide_lock); |
998 | hwif->next = hwgroup->hwif->next; | 984 | hwif->next = hwgroup->hwif->next; |
999 | hwgroup->hwif->next = hwif; | 985 | hwgroup->hwif->next = hwif; |
986 | BUG_ON(hwif->next == hwif); | ||
1000 | spin_unlock_irq(&ide_lock); | 987 | spin_unlock_irq(&ide_lock); |
1001 | } else { | 988 | } else { |
1002 | hwgroup = kmalloc_node(sizeof(ide_hwgroup_t), | 989 | hwgroup = kmalloc_node(sizeof(*hwgroup), GFP_KERNEL|__GFP_ZERO, |
1003 | GFP_KERNEL | __GFP_ZERO, | 990 | hwif_to_node(hwif)); |
1004 | hwif_to_node(hwif->drives[0].hwif)); | 991 | if (hwgroup == NULL) |
1005 | if (!hwgroup) | 992 | goto out_up; |
1006 | goto out_up; | ||
1007 | 993 | ||
1008 | hwif->hwgroup = hwgroup; | 994 | hwif->hwgroup = hwgroup; |
995 | hwgroup->hwif = hwif->next = hwif; | ||
1009 | 996 | ||
1010 | hwgroup->hwif = hwif->next = hwif; | ||
1011 | hwgroup->rq = NULL; | ||
1012 | hwgroup->handler = NULL; | ||
1013 | hwgroup->drive = NULL; | ||
1014 | hwgroup->busy = 0; | ||
1015 | init_timer(&hwgroup->timer); | 997 | init_timer(&hwgroup->timer); |
1016 | hwgroup->timer.function = &ide_timer_expiry; | 998 | hwgroup->timer.function = &ide_timer_expiry; |
1017 | hwgroup->timer.data = (unsigned long) hwgroup; | 999 | hwgroup->timer.data = (unsigned long) hwgroup; |
@@ -1079,25 +1061,7 @@ static int init_irq (ide_hwif_t *hwif) | |||
1079 | mutex_unlock(&ide_cfg_mtx); | 1061 | mutex_unlock(&ide_cfg_mtx); |
1080 | return 0; | 1062 | return 0; |
1081 | out_unlink: | 1063 | out_unlink: |
1082 | spin_lock_irq(&ide_lock); | 1064 | ide_remove_port_from_hwgroup(hwif); |
1083 | if (hwif->next == hwif) { | ||
1084 | BUG_ON(match); | ||
1085 | BUG_ON(hwgroup->hwif != hwif); | ||
1086 | kfree(hwgroup); | ||
1087 | } else { | ||
1088 | ide_hwif_t *g; | ||
1089 | g = hwgroup->hwif; | ||
1090 | while (g->next != hwif) | ||
1091 | g = g->next; | ||
1092 | g->next = hwif->next; | ||
1093 | if (hwgroup->hwif == hwif) { | ||
1094 | /* Impossible. */ | ||
1095 | printk(KERN_ERR "Duh. Uninitialized hwif listed as active hwif.\n"); | ||
1096 | hwgroup->hwif = g; | ||
1097 | } | ||
1098 | BUG_ON(hwgroup->hwif == hwif); | ||
1099 | } | ||
1100 | spin_unlock_irq(&ide_lock); | ||
1101 | out_up: | 1065 | out_up: |
1102 | mutex_unlock(&ide_cfg_mtx); | 1066 | mutex_unlock(&ide_cfg_mtx); |
1103 | return 1; | 1067 | return 1; |
@@ -1246,28 +1210,21 @@ static int hwif_init(ide_hwif_t *hwif) | |||
1246 | { | 1210 | { |
1247 | int old_irq; | 1211 | int old_irq; |
1248 | 1212 | ||
1249 | /* Return success if no device is connected */ | ||
1250 | if (!hwif->present) | ||
1251 | return 1; | ||
1252 | |||
1253 | if (!hwif->irq) { | 1213 | if (!hwif->irq) { |
1254 | if (!(hwif->irq = ide_default_irq(hwif->io_ports[IDE_DATA_OFFSET]))) | 1214 | if (!(hwif->irq = ide_default_irq(hwif->io_ports[IDE_DATA_OFFSET]))) |
1255 | { | 1215 | { |
1256 | printk("%s: DISABLED, NO IRQ\n", hwif->name); | 1216 | printk("%s: DISABLED, NO IRQ\n", hwif->name); |
1257 | return (hwif->present = 0); | 1217 | return 0; |
1258 | } | 1218 | } |
1259 | } | 1219 | } |
1260 | #ifdef CONFIG_BLK_DEV_HD | 1220 | #ifdef CONFIG_BLK_DEV_HD |
1261 | if (hwif->irq == HD_IRQ && hwif->io_ports[IDE_DATA_OFFSET] != HD_DATA) { | 1221 | if (hwif->irq == HD_IRQ && hwif->io_ports[IDE_DATA_OFFSET] != HD_DATA) { |
1262 | printk("%s: CANNOT SHARE IRQ WITH OLD " | 1222 | printk("%s: CANNOT SHARE IRQ WITH OLD " |
1263 | "HARDDISK DRIVER (hd.c)\n", hwif->name); | 1223 | "HARDDISK DRIVER (hd.c)\n", hwif->name); |
1264 | return (hwif->present = 0); | 1224 | return 0; |
1265 | } | 1225 | } |
1266 | #endif /* CONFIG_BLK_DEV_HD */ | 1226 | #endif /* CONFIG_BLK_DEV_HD */ |
1267 | 1227 | ||
1268 | /* we set it back to 1 if all is ok below */ | ||
1269 | hwif->present = 0; | ||
1270 | |||
1271 | if (register_blkdev(hwif->major, hwif->name)) | 1228 | if (register_blkdev(hwif->major, hwif->name)) |
1272 | return 0; | 1229 | return 0; |
1273 | 1230 | ||
@@ -1306,10 +1263,7 @@ static int hwif_init(ide_hwif_t *hwif) | |||
1306 | 1263 | ||
1307 | done: | 1264 | done: |
1308 | init_gendisk(hwif); | 1265 | init_gendisk(hwif); |
1309 | |||
1310 | ide_acpi_init(hwif); | 1266 | ide_acpi_init(hwif); |
1311 | |||
1312 | hwif->present = 1; /* success */ | ||
1313 | return 1; | 1267 | return 1; |
1314 | 1268 | ||
1315 | out: | 1269 | out: |
@@ -1344,7 +1298,27 @@ int ide_device_add_all(u8 *idx) | |||
1344 | if (idx[i] == 0xff) | 1298 | if (idx[i] == 0xff) |
1345 | continue; | 1299 | continue; |
1346 | 1300 | ||
1347 | probe_hwif(&ide_hwifs[idx[i]]); | 1301 | hwif = &ide_hwifs[idx[i]]; |
1302 | |||
1303 | if ((hwif->chipset != ide_4drives || !hwif->mate || | ||
1304 | !hwif->mate->present) && ide_hwif_request_regions(hwif)) { | ||
1305 | printk(KERN_ERR "%s: ports already in use, " | ||
1306 | "skipping probe\n", hwif->name); | ||
1307 | continue; | ||
1308 | } | ||
1309 | |||
1310 | if (ide_probe_port(hwif) < 0) { | ||
1311 | ide_hwif_release_regions(hwif); | ||
1312 | continue; | ||
1313 | } | ||
1314 | |||
1315 | hwif->present = 1; | ||
1316 | |||
1317 | if (hwif->chipset != ide_4drives || !hwif->mate || | ||
1318 | !hwif->mate->present) | ||
1319 | ide_register_port(hwif); | ||
1320 | |||
1321 | ide_port_tune_devices(hwif); | ||
1348 | } | 1322 | } |
1349 | 1323 | ||
1350 | for (i = 0; i < MAX_HWIFS; i++) { | 1324 | for (i = 0; i < MAX_HWIFS; i++) { |
@@ -1353,9 +1327,13 @@ int ide_device_add_all(u8 *idx) | |||
1353 | 1327 | ||
1354 | hwif = &ide_hwifs[idx[i]]; | 1328 | hwif = &ide_hwifs[idx[i]]; |
1355 | 1329 | ||
1330 | if (!hwif->present) | ||
1331 | continue; | ||
1332 | |||
1356 | if (hwif_init(hwif) == 0) { | 1333 | if (hwif_init(hwif) == 0) { |
1357 | printk(KERN_INFO "%s: failed to initialize IDE " | 1334 | printk(KERN_INFO "%s: failed to initialize IDE " |
1358 | "interface\n", hwif->name); | 1335 | "interface\n", hwif->name); |
1336 | hwif->present = 0; | ||
1359 | rc = -1; | 1337 | rc = -1; |
1360 | continue; | 1338 | continue; |
1361 | } | 1339 | } |