diff options
author | Bartlomiej Zolnierkiewicz <bzolnier@gmail.com> | 2009-01-06 11:20:56 -0500 |
---|---|---|
committer | Bartlomiej Zolnierkiewicz <bzolnier@gmail.com> | 2009-01-06 11:20:56 -0500 |
commit | 2bd24a1cfc99d242c2cff9a6b74ca49fcaac3fb6 (patch) | |
tree | d4797f56699e9da367e12b5e1d01b108241424f6 /drivers/ide/ide-probe.c | |
parent | 5e7f3a46690f7f6c9f2781c700ab4370874aa0e8 (diff) |
ide: add port and host iterators
Add ide_port_for_each_dev() / ide_host_for_each_port() iterators
and update IDE code to use them.
While at it:
- s/unit/i/ variable in ide_port_wait_ready(), ide_probe_port(),
ide_port_tune_devices(), ide_port_init_devices_data(), do_reset1(),
ide_acpi_set_state() and scc_dma_end()
- s/d/i/ variable in ide_proc_port_register_devices()
There should be no functional changes caused by this patch.
Signed-off-by: Bartlomiej Zolnierkiewicz <bzolnier@gmail.com>
Diffstat (limited to 'drivers/ide/ide-probe.c')
-rw-r--r-- | drivers/ide/ide-probe.c | 96 |
1 files changed, 38 insertions, 58 deletions
diff --git a/drivers/ide/ide-probe.c b/drivers/ide/ide-probe.c index 006e601cafb8..e688ca1c967c 100644 --- a/drivers/ide/ide-probe.c +++ b/drivers/ide/ide-probe.c | |||
@@ -697,7 +697,8 @@ out: | |||
697 | 697 | ||
698 | static int ide_port_wait_ready(ide_hwif_t *hwif) | 698 | static int ide_port_wait_ready(ide_hwif_t *hwif) |
699 | { | 699 | { |
700 | int unit, rc; | 700 | ide_drive_t *drive; |
701 | int i, rc; | ||
701 | 702 | ||
702 | printk(KERN_DEBUG "Probing IDE interface %s...\n", hwif->name); | 703 | printk(KERN_DEBUG "Probing IDE interface %s...\n", hwif->name); |
703 | 704 | ||
@@ -714,9 +715,7 @@ static int ide_port_wait_ready(ide_hwif_t *hwif) | |||
714 | return rc; | 715 | return rc; |
715 | 716 | ||
716 | /* Now make sure both master & slave are ready */ | 717 | /* Now make sure both master & slave are ready */ |
717 | for (unit = 0; unit < MAX_DRIVES; unit++) { | 718 | ide_port_for_each_dev(i, drive, hwif) { |
718 | ide_drive_t *drive = hwif->devices[unit]; | ||
719 | |||
720 | /* Ignore disks that we will not probe for later. */ | 719 | /* Ignore disks that we will not probe for later. */ |
721 | if ((drive->dev_flags & IDE_DFLAG_NOPROBE) == 0 || | 720 | if ((drive->dev_flags & IDE_DFLAG_NOPROBE) == 0 || |
722 | (drive->dev_flags & IDE_DFLAG_PRESENT)) { | 721 | (drive->dev_flags & IDE_DFLAG_PRESENT)) { |
@@ -732,7 +731,7 @@ static int ide_port_wait_ready(ide_hwif_t *hwif) | |||
732 | } | 731 | } |
733 | out: | 732 | out: |
734 | /* Exit function with master reselected (let's be sane) */ | 733 | /* Exit function with master reselected (let's be sane) */ |
735 | if (unit) | 734 | if (i) |
736 | SELECT_DRIVE(hwif->devices[0]); | 735 | SELECT_DRIVE(hwif->devices[0]); |
737 | 736 | ||
738 | return rc; | 737 | return rc; |
@@ -778,9 +777,10 @@ EXPORT_SYMBOL_GPL(ide_undecoded_slave); | |||
778 | 777 | ||
779 | static int ide_probe_port(ide_hwif_t *hwif) | 778 | static int ide_probe_port(ide_hwif_t *hwif) |
780 | { | 779 | { |
780 | ide_drive_t *drive; | ||
781 | unsigned long flags; | 781 | unsigned long flags; |
782 | unsigned int irqd; | 782 | unsigned int irqd; |
783 | int unit, rc = -ENODEV; | 783 | int i, rc = -ENODEV; |
784 | 784 | ||
785 | BUG_ON(hwif->present); | 785 | BUG_ON(hwif->present); |
786 | 786 | ||
@@ -806,9 +806,7 @@ static int ide_probe_port(ide_hwif_t *hwif) | |||
806 | * Second drive should only exist if first drive was found, | 806 | * Second drive should only exist if first drive was found, |
807 | * but a lot of cdrom drives are configured as single slaves. | 807 | * but a lot of cdrom drives are configured as single slaves. |
808 | */ | 808 | */ |
809 | for (unit = 0; unit < MAX_DRIVES; ++unit) { | 809 | ide_port_for_each_dev(i, drive, hwif) { |
810 | ide_drive_t *drive = hwif->devices[unit]; | ||
811 | |||
812 | (void) probe_for_drive(drive); | 810 | (void) probe_for_drive(drive); |
813 | if (drive->dev_flags & IDE_DFLAG_PRESENT) | 811 | if (drive->dev_flags & IDE_DFLAG_PRESENT) |
814 | rc = 0; | 812 | rc = 0; |
@@ -829,20 +827,17 @@ static int ide_probe_port(ide_hwif_t *hwif) | |||
829 | static void ide_port_tune_devices(ide_hwif_t *hwif) | 827 | static void ide_port_tune_devices(ide_hwif_t *hwif) |
830 | { | 828 | { |
831 | const struct ide_port_ops *port_ops = hwif->port_ops; | 829 | const struct ide_port_ops *port_ops = hwif->port_ops; |
832 | int unit; | 830 | ide_drive_t *drive; |
833 | 831 | int i; | |
834 | for (unit = 0; unit < MAX_DRIVES; unit++) { | ||
835 | ide_drive_t *drive = hwif->devices[unit]; | ||
836 | 832 | ||
833 | ide_port_for_each_dev(i, drive, hwif) { | ||
837 | if (drive->dev_flags & IDE_DFLAG_PRESENT) { | 834 | if (drive->dev_flags & IDE_DFLAG_PRESENT) { |
838 | if (port_ops && port_ops->quirkproc) | 835 | if (port_ops && port_ops->quirkproc) |
839 | port_ops->quirkproc(drive); | 836 | port_ops->quirkproc(drive); |
840 | } | 837 | } |
841 | } | 838 | } |
842 | 839 | ||
843 | for (unit = 0; unit < MAX_DRIVES; ++unit) { | 840 | ide_port_for_each_dev(i, drive, hwif) { |
844 | ide_drive_t *drive = hwif->devices[unit]; | ||
845 | |||
846 | if (drive->dev_flags & IDE_DFLAG_PRESENT) { | 841 | if (drive->dev_flags & IDE_DFLAG_PRESENT) { |
847 | ide_set_max_pio(drive); | 842 | ide_set_max_pio(drive); |
848 | 843 | ||
@@ -853,9 +848,7 @@ static void ide_port_tune_devices(ide_hwif_t *hwif) | |||
853 | } | 848 | } |
854 | } | 849 | } |
855 | 850 | ||
856 | for (unit = 0; unit < MAX_DRIVES; ++unit) { | 851 | ide_port_for_each_dev(i, drive, hwif) { |
857 | ide_drive_t *drive = hwif->devices[unit]; | ||
858 | |||
859 | if ((hwif->host_flags & IDE_HFLAG_NO_IO_32BIT) || | 852 | if ((hwif->host_flags & IDE_HFLAG_NO_IO_32BIT) || |
860 | drive->id[ATA_ID_DWORD_IO]) | 853 | drive->id[ATA_ID_DWORD_IO]) |
861 | drive->dev_flags |= IDE_DFLAG_NO_IO_32BIT; | 854 | drive->dev_flags |= IDE_DFLAG_NO_IO_32BIT; |
@@ -927,12 +920,11 @@ static DEFINE_MUTEX(ide_cfg_mtx); | |||
927 | */ | 920 | */ |
928 | static int ide_port_setup_devices(ide_hwif_t *hwif) | 921 | static int ide_port_setup_devices(ide_hwif_t *hwif) |
929 | { | 922 | { |
923 | ide_drive_t *drive; | ||
930 | int i, j = 0; | 924 | int i, j = 0; |
931 | 925 | ||
932 | mutex_lock(&ide_cfg_mtx); | 926 | mutex_lock(&ide_cfg_mtx); |
933 | for (i = 0; i < MAX_DRIVES; i++) { | 927 | ide_port_for_each_dev(i, drive, hwif) { |
934 | ide_drive_t *drive = hwif->devices[i]; | ||
935 | |||
936 | if ((drive->dev_flags & IDE_DFLAG_PRESENT) == 0) | 928 | if ((drive->dev_flags & IDE_DFLAG_PRESENT) == 0) |
937 | continue; | 929 | continue; |
938 | 930 | ||
@@ -1161,10 +1153,10 @@ out: | |||
1161 | 1153 | ||
1162 | static void hwif_register_devices(ide_hwif_t *hwif) | 1154 | static void hwif_register_devices(ide_hwif_t *hwif) |
1163 | { | 1155 | { |
1156 | ide_drive_t *drive; | ||
1164 | unsigned int i; | 1157 | unsigned int i; |
1165 | 1158 | ||
1166 | for (i = 0; i < MAX_DRIVES; i++) { | 1159 | ide_port_for_each_dev(i, drive, hwif) { |
1167 | ide_drive_t *drive = hwif->devices[i]; | ||
1168 | struct device *dev = &drive->gendev; | 1160 | struct device *dev = &drive->gendev; |
1169 | int ret; | 1161 | int ret; |
1170 | 1162 | ||
@@ -1187,11 +1179,10 @@ static void hwif_register_devices(ide_hwif_t *hwif) | |||
1187 | static void ide_port_init_devices(ide_hwif_t *hwif) | 1179 | static void ide_port_init_devices(ide_hwif_t *hwif) |
1188 | { | 1180 | { |
1189 | const struct ide_port_ops *port_ops = hwif->port_ops; | 1181 | const struct ide_port_ops *port_ops = hwif->port_ops; |
1182 | ide_drive_t *drive; | ||
1190 | int i; | 1183 | int i; |
1191 | 1184 | ||
1192 | for (i = 0; i < MAX_DRIVES; i++) { | 1185 | ide_port_for_each_dev(i, drive, hwif) { |
1193 | ide_drive_t *drive = hwif->devices[i]; | ||
1194 | |||
1195 | drive->dn = i + hwif->channel * 2; | 1186 | drive->dn = i + hwif->channel * 2; |
1196 | 1187 | ||
1197 | if (hwif->host_flags & IDE_HFLAG_IO_32BIT) | 1188 | if (hwif->host_flags & IDE_HFLAG_IO_32BIT) |
@@ -1282,16 +1273,16 @@ static const u8 ide_hwif_to_major[] = | |||
1282 | 1273 | ||
1283 | static void ide_port_init_devices_data(ide_hwif_t *hwif) | 1274 | static void ide_port_init_devices_data(ide_hwif_t *hwif) |
1284 | { | 1275 | { |
1285 | int unit; | 1276 | ide_drive_t *drive; |
1277 | int i; | ||
1286 | 1278 | ||
1287 | for (unit = 0; unit < MAX_DRIVES; ++unit) { | 1279 | ide_port_for_each_dev(i, drive, hwif) { |
1288 | ide_drive_t *drive = hwif->devices[unit]; | 1280 | u8 j = (hwif->index * MAX_DRIVES) + i; |
1289 | u8 j = (hwif->index * MAX_DRIVES) + unit; | ||
1290 | 1281 | ||
1291 | memset(drive, 0, sizeof(*drive)); | 1282 | memset(drive, 0, sizeof(*drive)); |
1292 | 1283 | ||
1293 | drive->media = ide_disk; | 1284 | drive->media = ide_disk; |
1294 | drive->select = (unit << 4) | ATA_DEVICE_OBS; | 1285 | drive->select = (i << 4) | ATA_DEVICE_OBS; |
1295 | drive->hwif = hwif; | 1286 | drive->hwif = hwif; |
1296 | drive->ready_stat = ATA_DRDY; | 1287 | drive->ready_stat = ATA_DRDY; |
1297 | drive->bad_wstat = BAD_W_STAT; | 1288 | drive->bad_wstat = BAD_W_STAT; |
@@ -1387,10 +1378,11 @@ static void ide_free_port_slot(int idx) | |||
1387 | 1378 | ||
1388 | static void ide_port_free_devices(ide_hwif_t *hwif) | 1379 | static void ide_port_free_devices(ide_hwif_t *hwif) |
1389 | { | 1380 | { |
1381 | ide_drive_t *drive; | ||
1390 | int i; | 1382 | int i; |
1391 | 1383 | ||
1392 | for (i = 0; i < MAX_DRIVES; i++) | 1384 | ide_port_for_each_dev(i, drive, hwif) |
1393 | kfree(hwif->devices[i]); | 1385 | kfree(drive); |
1394 | } | 1386 | } |
1395 | 1387 | ||
1396 | static int ide_port_alloc_devices(ide_hwif_t *hwif, int node) | 1388 | static int ide_port_alloc_devices(ide_hwif_t *hwif, int node) |
@@ -1478,9 +1470,7 @@ int ide_host_register(struct ide_host *host, const struct ide_port_info *d, | |||
1478 | ide_hwif_t *hwif, *mate = NULL; | 1470 | ide_hwif_t *hwif, *mate = NULL; |
1479 | int i, j = 0; | 1471 | int i, j = 0; |
1480 | 1472 | ||
1481 | for (i = 0; i < MAX_HOST_PORTS; i++) { | 1473 | ide_host_for_each_port(i, hwif, host) { |
1482 | hwif = host->ports[i]; | ||
1483 | |||
1484 | if (hwif == NULL) { | 1474 | if (hwif == NULL) { |
1485 | mate = NULL; | 1475 | mate = NULL; |
1486 | continue; | 1476 | continue; |
@@ -1506,9 +1496,7 @@ int ide_host_register(struct ide_host *host, const struct ide_port_info *d, | |||
1506 | ide_port_init_devices(hwif); | 1496 | ide_port_init_devices(hwif); |
1507 | } | 1497 | } |
1508 | 1498 | ||
1509 | for (i = 0; i < MAX_HOST_PORTS; i++) { | 1499 | ide_host_for_each_port(i, hwif, host) { |
1510 | hwif = host->ports[i]; | ||
1511 | |||
1512 | if (hwif == NULL) | 1500 | if (hwif == NULL) |
1513 | continue; | 1501 | continue; |
1514 | 1502 | ||
@@ -1523,9 +1511,7 @@ int ide_host_register(struct ide_host *host, const struct ide_port_info *d, | |||
1523 | ide_port_tune_devices(hwif); | 1511 | ide_port_tune_devices(hwif); |
1524 | } | 1512 | } |
1525 | 1513 | ||
1526 | for (i = 0; i < MAX_HOST_PORTS; i++) { | 1514 | ide_host_for_each_port(i, hwif, host) { |
1527 | hwif = host->ports[i]; | ||
1528 | |||
1529 | if (hwif == NULL) | 1515 | if (hwif == NULL) |
1530 | continue; | 1516 | continue; |
1531 | 1517 | ||
@@ -1550,9 +1536,7 @@ int ide_host_register(struct ide_host *host, const struct ide_port_info *d, | |||
1550 | ide_acpi_port_init_devices(hwif); | 1536 | ide_acpi_port_init_devices(hwif); |
1551 | } | 1537 | } |
1552 | 1538 | ||
1553 | for (i = 0; i < MAX_HOST_PORTS; i++) { | 1539 | ide_host_for_each_port(i, hwif, host) { |
1554 | hwif = host->ports[i]; | ||
1555 | |||
1556 | if (hwif == NULL) | 1540 | if (hwif == NULL) |
1557 | continue; | 1541 | continue; |
1558 | 1542 | ||
@@ -1560,9 +1544,7 @@ int ide_host_register(struct ide_host *host, const struct ide_port_info *d, | |||
1560 | hwif_register_devices(hwif); | 1544 | hwif_register_devices(hwif); |
1561 | } | 1545 | } |
1562 | 1546 | ||
1563 | for (i = 0; i < MAX_HOST_PORTS; i++) { | 1547 | ide_host_for_each_port(i, hwif, host) { |
1564 | hwif = host->ports[i]; | ||
1565 | |||
1566 | if (hwif == NULL) | 1548 | if (hwif == NULL) |
1567 | continue; | 1549 | continue; |
1568 | 1550 | ||
@@ -1602,11 +1584,10 @@ EXPORT_SYMBOL_GPL(ide_host_add); | |||
1602 | 1584 | ||
1603 | static void __ide_port_unregister_devices(ide_hwif_t *hwif) | 1585 | static void __ide_port_unregister_devices(ide_hwif_t *hwif) |
1604 | { | 1586 | { |
1587 | ide_drive_t *drive; | ||
1605 | int i; | 1588 | int i; |
1606 | 1589 | ||
1607 | for (i = 0; i < MAX_DRIVES; i++) { | 1590 | ide_port_for_each_dev(i, drive, hwif) { |
1608 | ide_drive_t *drive = hwif->devices[i]; | ||
1609 | |||
1610 | if (drive->dev_flags & IDE_DFLAG_PRESENT) { | 1591 | if (drive->dev_flags & IDE_DFLAG_PRESENT) { |
1611 | device_unregister(&drive->gendev); | 1592 | device_unregister(&drive->gendev); |
1612 | wait_for_completion(&drive->gendev_rel_comp); | 1593 | wait_for_completion(&drive->gendev_rel_comp); |
@@ -1675,9 +1656,7 @@ void ide_host_free(struct ide_host *host) | |||
1675 | ide_hwif_t *hwif; | 1656 | ide_hwif_t *hwif; |
1676 | int i; | 1657 | int i; |
1677 | 1658 | ||
1678 | for (i = 0; i < MAX_HOST_PORTS; i++) { | 1659 | ide_host_for_each_port(i, hwif, host) { |
1679 | hwif = host->ports[i]; | ||
1680 | |||
1681 | if (hwif == NULL) | 1660 | if (hwif == NULL) |
1682 | continue; | 1661 | continue; |
1683 | 1662 | ||
@@ -1692,11 +1671,12 @@ EXPORT_SYMBOL_GPL(ide_host_free); | |||
1692 | 1671 | ||
1693 | void ide_host_remove(struct ide_host *host) | 1672 | void ide_host_remove(struct ide_host *host) |
1694 | { | 1673 | { |
1674 | ide_hwif_t *hwif; | ||
1695 | int i; | 1675 | int i; |
1696 | 1676 | ||
1697 | for (i = 0; i < MAX_HOST_PORTS; i++) { | 1677 | ide_host_for_each_port(i, hwif, host) { |
1698 | if (host->ports[i]) | 1678 | if (hwif) |
1699 | ide_unregister(host->ports[i]); | 1679 | ide_unregister(hwif); |
1700 | } | 1680 | } |
1701 | 1681 | ||
1702 | ide_host_free(host); | 1682 | ide_host_free(host); |