ide: add ide_for_each_present_dev() iterator

* Add ide_for_each_present_dev() iterator and convert IDE code to use it.

* Do some drive-by CodingStyle fixups in ide-acpi.c while at it.

There should be no functional changes caused by this patch.
Signed-off-by: NBartlomiej Zolnierkiewicz <bzolnier@gmail.com>
上级 8cd3c605
...@@ -608,17 +608,17 @@ void ide_acpi_set_state(ide_hwif_t *hwif, int on) ...@@ -608,17 +608,17 @@ void ide_acpi_set_state(ide_hwif_t *hwif, int on)
DEBPRINT("no ACPI data for %s\n", hwif->name); DEBPRINT("no ACPI data for %s\n", hwif->name);
return; return;
} }
/* channel first and then drives for power on and verse versa for power off */ /* channel first and then drives for power on and verse versa for power off */
if (on) if (on)
acpi_bus_set_power(hwif->acpidata->obj_handle, ACPI_STATE_D0); acpi_bus_set_power(hwif->acpidata->obj_handle, ACPI_STATE_D0);
ide_port_for_each_dev(i, drive, hwif) { ide_port_for_each_present_dev(i, drive, hwif) {
if (drive->acpidata->obj_handle && if (drive->acpidata->obj_handle)
(drive->dev_flags & IDE_DFLAG_PRESENT)) {
acpi_bus_set_power(drive->acpidata->obj_handle, acpi_bus_set_power(drive->acpidata->obj_handle,
on? ACPI_STATE_D0: ACPI_STATE_D3); on ? ACPI_STATE_D0 : ACPI_STATE_D3);
}
} }
if (!on) if (!on)
acpi_bus_set_power(hwif->acpidata->obj_handle, ACPI_STATE_D3); acpi_bus_set_power(hwif->acpidata->obj_handle, ACPI_STATE_D3);
} }
...@@ -667,12 +667,9 @@ void ide_acpi_port_init_devices(ide_hwif_t *hwif) ...@@ -667,12 +667,9 @@ void ide_acpi_port_init_devices(ide_hwif_t *hwif)
hwif->devices[1]->acpidata = &hwif->acpidata->slave; hwif->devices[1]->acpidata = &hwif->acpidata->slave;
/* get _ADR info for each device */ /* get _ADR info for each device */
ide_port_for_each_dev(i, drive, hwif) { ide_port_for_each_present_dev(i, drive, hwif) {
acpi_handle dev_handle; acpi_handle dev_handle;
if ((drive->dev_flags & IDE_DFLAG_PRESENT) == 0)
continue;
DEBPRINT("ENTER: %s at channel#: %d port#: %d\n", DEBPRINT("ENTER: %s at channel#: %d port#: %d\n",
drive->name, hwif->channel, drive->dn & 1); drive->name, hwif->channel, drive->dn & 1);
...@@ -685,13 +682,8 @@ void ide_acpi_port_init_devices(ide_hwif_t *hwif) ...@@ -685,13 +682,8 @@ void ide_acpi_port_init_devices(ide_hwif_t *hwif)
drive->acpidata->obj_handle = dev_handle; drive->acpidata->obj_handle = dev_handle;
} }
/* /* send IDENTIFY for each device */
* Send IDENTIFY for each drive ide_port_for_each_present_dev(i, drive, hwif) {
*/
ide_port_for_each_dev(i, drive, hwif) {
if ((drive->dev_flags & IDE_DFLAG_PRESENT) == 0)
continue;
err = taskfile_lib_get_identify(drive, drive->acpidata->idbuff); err = taskfile_lib_get_identify(drive, drive->acpidata->idbuff);
if (err) if (err)
DEBPRINT("identify device %s failed (%d)\n", DEBPRINT("identify device %s failed (%d)\n",
...@@ -711,9 +703,7 @@ void ide_acpi_port_init_devices(ide_hwif_t *hwif) ...@@ -711,9 +703,7 @@ void ide_acpi_port_init_devices(ide_hwif_t *hwif)
ide_acpi_get_timing(hwif); ide_acpi_get_timing(hwif);
ide_acpi_push_timing(hwif); ide_acpi_push_timing(hwif);
ide_port_for_each_dev(i, drive, hwif) { ide_port_for_each_present_dev(i, drive, hwif) {
if (drive->dev_flags & IDE_DFLAG_PRESENT)
/* Execute ACPI startup code */
ide_acpi_exec_tfs(drive); ide_acpi_exec_tfs(drive);
} }
} }
...@@ -1103,9 +1103,8 @@ static ide_startstop_t do_reset1 (ide_drive_t *drive, int do_not_try_atapi) ...@@ -1103,9 +1103,8 @@ static ide_startstop_t do_reset1 (ide_drive_t *drive, int do_not_try_atapi)
prepare_to_wait(&ide_park_wq, &wait, TASK_UNINTERRUPTIBLE); prepare_to_wait(&ide_park_wq, &wait, TASK_UNINTERRUPTIBLE);
timeout = jiffies; timeout = jiffies;
ide_port_for_each_dev(i, tdrive, hwif) { ide_port_for_each_present_dev(i, tdrive, hwif) {
if (tdrive->dev_flags & IDE_DFLAG_PRESENT && if ((tdrive->dev_flags & IDE_DFLAG_PARKED) &&
tdrive->dev_flags & IDE_DFLAG_PARKED &&
time_after(tdrive->sleep, timeout)) time_after(tdrive->sleep, timeout))
timeout = tdrive->sleep; timeout = tdrive->sleep;
} }
......
...@@ -825,15 +825,12 @@ static void ide_port_tune_devices(ide_hwif_t *hwif) ...@@ -825,15 +825,12 @@ static void ide_port_tune_devices(ide_hwif_t *hwif)
ide_drive_t *drive; ide_drive_t *drive;
int i; int i;
ide_port_for_each_dev(i, drive, hwif) { ide_port_for_each_present_dev(i, drive, hwif) {
if (drive->dev_flags & IDE_DFLAG_PRESENT) {
if (port_ops && port_ops->quirkproc) if (port_ops && port_ops->quirkproc)
port_ops->quirkproc(drive); port_ops->quirkproc(drive);
} }
}
ide_port_for_each_dev(i, drive, hwif) { ide_port_for_each_present_dev(i, drive, hwif) {
if (drive->dev_flags & IDE_DFLAG_PRESENT) {
ide_set_max_pio(drive); ide_set_max_pio(drive);
drive->dev_flags |= IDE_DFLAG_NICE1; drive->dev_flags |= IDE_DFLAG_NICE1;
...@@ -841,7 +838,6 @@ static void ide_port_tune_devices(ide_hwif_t *hwif) ...@@ -841,7 +838,6 @@ static void ide_port_tune_devices(ide_hwif_t *hwif)
if (hwif->dma_ops) if (hwif->dma_ops)
ide_set_dma(drive); ide_set_dma(drive);
} }
}
} }
/* /*
...@@ -911,10 +907,7 @@ static int ide_port_setup_devices(ide_hwif_t *hwif) ...@@ -911,10 +907,7 @@ static int ide_port_setup_devices(ide_hwif_t *hwif)
int i, j = 0; int i, j = 0;
mutex_lock(&ide_cfg_mtx); mutex_lock(&ide_cfg_mtx);
ide_port_for_each_dev(i, drive, hwif) { ide_port_for_each_present_dev(i, drive, hwif) {
if ((drive->dev_flags & IDE_DFLAG_PRESENT) == 0)
continue;
if (ide_init_queue(drive)) { if (ide_init_queue(drive)) {
printk(KERN_ERR "ide: failed to init %s\n", printk(KERN_ERR "ide: failed to init %s\n",
drive->name); drive->name);
...@@ -1139,13 +1132,10 @@ static void hwif_register_devices(ide_hwif_t *hwif) ...@@ -1139,13 +1132,10 @@ static void hwif_register_devices(ide_hwif_t *hwif)
ide_drive_t *drive; ide_drive_t *drive;
unsigned int i; unsigned int i;
ide_port_for_each_dev(i, drive, hwif) { ide_port_for_each_present_dev(i, drive, hwif) {
struct device *dev = &drive->gendev; struct device *dev = &drive->gendev;
int ret; int ret;
if ((drive->dev_flags & IDE_DFLAG_PRESENT) == 0)
continue;
dev_set_name(dev, "%u.%u", hwif->index, i); dev_set_name(dev, "%u.%u", hwif->index, i);
dev->parent = &hwif->gendev; dev->parent = &hwif->gendev;
dev->bus = &ide_bus_type; dev->bus = &ide_bus_type;
...@@ -1610,12 +1600,10 @@ static void __ide_port_unregister_devices(ide_hwif_t *hwif) ...@@ -1610,12 +1600,10 @@ static void __ide_port_unregister_devices(ide_hwif_t *hwif)
ide_drive_t *drive; ide_drive_t *drive;
int i; int i;
ide_port_for_each_dev(i, drive, hwif) { ide_port_for_each_present_dev(i, drive, hwif) {
if (drive->dev_flags & IDE_DFLAG_PRESENT) {
device_unregister(&drive->gendev); device_unregister(&drive->gendev);
wait_for_completion(&drive->gendev_rel_comp); wait_for_completion(&drive->gendev_rel_comp);
} }
}
} }
void ide_port_unregister_devices(ide_hwif_t *hwif) void ide_port_unregister_devices(ide_hwif_t *hwif)
......
...@@ -1609,6 +1609,10 @@ static inline ide_drive_t *ide_get_pair_dev(ide_drive_t *drive) ...@@ -1609,6 +1609,10 @@ static inline ide_drive_t *ide_get_pair_dev(ide_drive_t *drive)
#define ide_port_for_each_dev(i, dev, port) \ #define ide_port_for_each_dev(i, dev, port) \
for ((i) = 0; ((dev) = (port)->devices[i]) || (i) < MAX_DRIVES; (i)++) for ((i) = 0; ((dev) = (port)->devices[i]) || (i) < MAX_DRIVES; (i)++)
#define ide_port_for_each_present_dev(i, dev, port) \
for ((i) = 0; ((dev) = (port)->devices[i]) || (i) < MAX_DRIVES; (i)++) \
if ((dev)->dev_flags & IDE_DFLAG_PRESENT)
#define ide_host_for_each_port(i, port, host) \ #define ide_host_for_each_port(i, port, host) \
for ((i) = 0; ((port) = (host)->ports[i]) || (i) < MAX_HOST_PORTS; (i)++) for ((i) = 0; ((port) = (host)->ports[i]) || (i) < MAX_HOST_PORTS; (i)++)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册