aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/ide/ide.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/ide/ide.c')
-rw-r--r--drivers/ide/ide.c89
1 files changed, 3 insertions, 86 deletions
diff --git a/drivers/ide/ide.c b/drivers/ide/ide.c
index 04f8f13cb9d7..f0f09f702e9c 100644
--- a/drivers/ide/ide.c
+++ b/drivers/ide/ide.c
@@ -74,9 +74,6 @@ static const u8 ide_hwif_to_major[] = { IDE0_MAJOR, IDE1_MAJOR,
74 74
75DEFINE_MUTEX(ide_cfg_mtx); 75DEFINE_MUTEX(ide_cfg_mtx);
76 76
77__cacheline_aligned_in_smp DEFINE_SPINLOCK(ide_lock);
78EXPORT_SYMBOL(ide_lock);
79
80static void ide_port_init_devices_data(ide_hwif_t *); 77static void ide_port_init_devices_data(ide_hwif_t *);
81 78
82/* 79/*
@@ -130,7 +127,6 @@ static void ide_port_init_devices_data(ide_hwif_t *hwif)
130 } 127 }
131} 128}
132 129
133/* Called with ide_lock held. */
134static void __ide_port_unregister_devices(ide_hwif_t *hwif) 130static void __ide_port_unregister_devices(ide_hwif_t *hwif)
135{ 131{
136 int i; 132 int i;
@@ -139,10 +135,8 @@ static void __ide_port_unregister_devices(ide_hwif_t *hwif)
139 ide_drive_t *drive = &hwif->drives[i]; 135 ide_drive_t *drive = &hwif->drives[i];
140 136
141 if (drive->dev_flags & IDE_DFLAG_PRESENT) { 137 if (drive->dev_flags & IDE_DFLAG_PRESENT) {
142 spin_unlock_irq(&ide_lock);
143 device_unregister(&drive->gendev); 138 device_unregister(&drive->gendev);
144 wait_for_completion(&drive->gendev_rel_comp); 139 wait_for_completion(&drive->gendev_rel_comp);
145 spin_lock_irq(&ide_lock);
146 } 140 }
147 } 141 }
148} 142}
@@ -150,11 +144,9 @@ static void __ide_port_unregister_devices(ide_hwif_t *hwif)
150void ide_port_unregister_devices(ide_hwif_t *hwif) 144void ide_port_unregister_devices(ide_hwif_t *hwif)
151{ 145{
152 mutex_lock(&ide_cfg_mtx); 146 mutex_lock(&ide_cfg_mtx);
153 spin_lock_irq(&ide_lock);
154 __ide_port_unregister_devices(hwif); 147 __ide_port_unregister_devices(hwif);
155 hwif->present = 0; 148 hwif->present = 0;
156 ide_port_init_devices_data(hwif); 149 ide_port_init_devices_data(hwif);
157 spin_unlock_irq(&ide_lock);
158 mutex_unlock(&ide_cfg_mtx); 150 mutex_unlock(&ide_cfg_mtx);
159} 151}
160EXPORT_SYMBOL_GPL(ide_port_unregister_devices); 152EXPORT_SYMBOL_GPL(ide_port_unregister_devices);
@@ -192,12 +184,10 @@ void ide_unregister(ide_hwif_t *hwif)
192 184
193 mutex_lock(&ide_cfg_mtx); 185 mutex_lock(&ide_cfg_mtx);
194 186
195 spin_lock_irq(&ide_lock);
196 if (hwif->present) { 187 if (hwif->present) {
197 __ide_port_unregister_devices(hwif); 188 __ide_port_unregister_devices(hwif);
198 hwif->present = 0; 189 hwif->present = 0;
199 } 190 }
200 spin_unlock_irq(&ide_lock);
201 191
202 ide_proc_unregister_port(hwif); 192 ide_proc_unregister_port(hwif);
203 193
@@ -340,6 +330,7 @@ static int set_pio_mode_abuse(ide_hwif_t *hwif, u8 req_pio)
340static int set_pio_mode(ide_drive_t *drive, int arg) 330static int set_pio_mode(ide_drive_t *drive, int arg)
341{ 331{
342 ide_hwif_t *hwif = drive->hwif; 332 ide_hwif_t *hwif = drive->hwif;
333 ide_hwgroup_t *hwgroup = hwif->hwgroup;
343 const struct ide_port_ops *port_ops = hwif->port_ops; 334 const struct ide_port_ops *port_ops = hwif->port_ops;
344 335
345 if (arg < 0 || arg > 255) 336 if (arg < 0 || arg > 255)
@@ -354,9 +345,9 @@ static int set_pio_mode(ide_drive_t *drive, int arg)
354 unsigned long flags; 345 unsigned long flags;
355 346
356 /* take lock for IDE_DFLAG_[NO_]UNMASK/[NO_]IO_32BIT */ 347 /* take lock for IDE_DFLAG_[NO_]UNMASK/[NO_]IO_32BIT */
357 spin_lock_irqsave(&ide_lock, flags); 348 spin_lock_irqsave(&hwgroup->lock, flags);
358 port_ops->set_pio_mode(drive, arg); 349 port_ops->set_pio_mode(drive, arg);
359 spin_unlock_irqrestore(&ide_lock, flags); 350 spin_unlock_irqrestore(&hwgroup->lock, flags);
360 } else 351 } else
361 port_ops->set_pio_mode(drive, arg); 352 port_ops->set_pio_mode(drive, arg);
362 } else { 353 } else {
@@ -397,80 +388,6 @@ ide_ext_devset_rw_sync(unmaskirq, unmaskirq);
397ide_ext_devset_rw_sync(using_dma, using_dma); 388ide_ext_devset_rw_sync(using_dma, using_dma);
398__IDE_DEVSET(pio_mode, DS_SYNC, NULL, set_pio_mode); 389__IDE_DEVSET(pio_mode, DS_SYNC, NULL, set_pio_mode);
399 390
400static int generic_ide_suspend(struct device *dev, pm_message_t mesg)
401{
402 ide_drive_t *drive = dev->driver_data, *pair = ide_get_pair_dev(drive);
403 ide_hwif_t *hwif = HWIF(drive);
404 struct request *rq;
405 struct request_pm_state rqpm;
406 ide_task_t args;
407 int ret;
408
409 /* call ACPI _GTM only once */
410 if ((drive->dn & 1) == 0 || pair == NULL)
411 ide_acpi_get_timing(hwif);
412
413 memset(&rqpm, 0, sizeof(rqpm));
414 memset(&args, 0, sizeof(args));
415 rq = blk_get_request(drive->queue, READ, __GFP_WAIT);
416 rq->cmd_type = REQ_TYPE_PM_SUSPEND;
417 rq->special = &args;
418 rq->data = &rqpm;
419 rqpm.pm_step = IDE_PM_START_SUSPEND;
420 if (mesg.event == PM_EVENT_PRETHAW)
421 mesg.event = PM_EVENT_FREEZE;
422 rqpm.pm_state = mesg.event;
423
424 ret = blk_execute_rq(drive->queue, NULL, rq, 0);
425 blk_put_request(rq);
426
427 /* call ACPI _PS3 only after both devices are suspended */
428 if (ret == 0 && ((drive->dn & 1) || pair == NULL))
429 ide_acpi_set_state(hwif, 0);
430
431 return ret;
432}
433
434static int generic_ide_resume(struct device *dev)
435{
436 ide_drive_t *drive = dev->driver_data, *pair = ide_get_pair_dev(drive);
437 ide_hwif_t *hwif = HWIF(drive);
438 struct request *rq;
439 struct request_pm_state rqpm;
440 ide_task_t args;
441 int err;
442
443 /* call ACPI _PS0 / _STM only once */
444 if ((drive->dn & 1) == 0 || pair == NULL) {
445 ide_acpi_set_state(hwif, 1);
446 ide_acpi_push_timing(hwif);
447 }
448
449 ide_acpi_exec_tfs(drive);
450
451 memset(&rqpm, 0, sizeof(rqpm));
452 memset(&args, 0, sizeof(args));
453 rq = blk_get_request(drive->queue, READ, __GFP_WAIT);
454 rq->cmd_type = REQ_TYPE_PM_RESUME;
455 rq->cmd_flags |= REQ_PREEMPT;
456 rq->special = &args;
457 rq->data = &rqpm;
458 rqpm.pm_step = IDE_PM_START_RESUME;
459 rqpm.pm_state = PM_EVENT_ON;
460
461 err = blk_execute_rq(drive->queue, NULL, rq, 1);
462 blk_put_request(rq);
463
464 if (err == 0 && dev->driver) {
465 ide_driver_t *drv = to_ide_driver(dev->driver);
466
467 if (drv->resume)
468 drv->resume(drive);
469 }
470
471 return err;
472}
473
474/** 391/**
475 * ide_device_get - get an additional reference to a ide_drive_t 392 * ide_device_get - get an additional reference to a ide_drive_t
476 * @drive: device to get a reference to 393 * @drive: device to get a reference to