2 #include <linux/kernel.h>
6 DEFINE_MUTEX(ide_setting_mtx
);
8 ide_devset_get(io_32bit
, io_32bit
);
10 static int set_io_32bit(ide_drive_t
*drive
, int arg
)
12 if (drive
->dev_flags
& IDE_DFLAG_NO_IO_32BIT
)
15 if (arg
< 0 || arg
> 1 + (SUPPORT_VLB_SYNC
<< 1))
18 drive
->io_32bit
= arg
;
23 ide_devset_get_flag(ksettings
, IDE_DFLAG_KEEP_SETTINGS
);
25 static int set_ksettings(ide_drive_t
*drive
, int arg
)
27 if (arg
< 0 || arg
> 1)
31 drive
->dev_flags
|= IDE_DFLAG_KEEP_SETTINGS
;
33 drive
->dev_flags
&= ~IDE_DFLAG_KEEP_SETTINGS
;
38 ide_devset_get_flag(using_dma
, IDE_DFLAG_USING_DMA
);
40 static int set_using_dma(ide_drive_t
*drive
, int arg
)
42 #ifdef CONFIG_BLK_DEV_IDEDMA
45 if (arg
< 0 || arg
> 1)
48 if (ata_id_has_dma(drive
->id
) == 0)
51 if (drive
->hwif
->dma_ops
== NULL
)
57 if (ide_set_dma(drive
))
65 if (arg
< 0 || arg
> 1)
73 * handle HDIO_SET_PIO_MODE ioctl abusers here, eventually it will go away
75 static int set_pio_mode_abuse(ide_hwif_t
*hwif
, u8 req_pio
)
84 return (hwif
->host_flags
& IDE_HFLAG_ABUSE_DMA_MODES
) ? 1 : 0;
87 return (hwif
->host_flags
& IDE_HFLAG_ABUSE_PREFETCH
) ? 1 : 0;
90 return (hwif
->host_flags
& IDE_HFLAG_ABUSE_FAST_DEVSEL
) ? 1 : 0;
96 static int set_pio_mode(ide_drive_t
*drive
, int arg
)
98 ide_hwif_t
*hwif
= drive
->hwif
;
99 const struct ide_port_ops
*port_ops
= hwif
->port_ops
;
101 if (arg
< 0 || arg
> 255)
104 if (port_ops
== NULL
|| port_ops
->set_pio_mode
== NULL
||
105 (hwif
->host_flags
& IDE_HFLAG_NO_SET_MODE
))
108 if (set_pio_mode_abuse(drive
->hwif
, arg
)) {
109 drive
->pio_mode
= arg
+ XFER_PIO_0
;
111 if (arg
== 8 || arg
== 9) {
114 /* take lock for IDE_DFLAG_[NO_]UNMASK/[NO_]IO_32BIT */
115 spin_lock_irqsave(&hwif
->lock
, flags
);
116 port_ops
->set_pio_mode(hwif
, drive
);
117 spin_unlock_irqrestore(&hwif
->lock
, flags
);
119 port_ops
->set_pio_mode(hwif
, drive
);
121 int keep_dma
= !!(drive
->dev_flags
& IDE_DFLAG_USING_DMA
);
123 ide_set_pio(drive
, arg
);
125 if (hwif
->host_flags
& IDE_HFLAG_SET_PIO_MODE_KEEP_DMA
) {
134 ide_devset_get_flag(unmaskirq
, IDE_DFLAG_UNMASK
);
136 static int set_unmaskirq(ide_drive_t
*drive
, int arg
)
138 if (drive
->dev_flags
& IDE_DFLAG_NO_UNMASK
)
141 if (arg
< 0 || arg
> 1)
145 drive
->dev_flags
|= IDE_DFLAG_UNMASK
;
147 drive
->dev_flags
&= ~IDE_DFLAG_UNMASK
;
152 ide_ext_devset_rw_sync(io_32bit
, io_32bit
);
153 ide_ext_devset_rw_sync(keepsettings
, ksettings
);
154 ide_ext_devset_rw_sync(unmaskirq
, unmaskirq
);
155 ide_ext_devset_rw_sync(using_dma
, using_dma
);
156 __IDE_DEVSET(pio_mode
, DS_SYNC
, NULL
, set_pio_mode
);
158 int ide_devset_execute(ide_drive_t
*drive
, const struct ide_devset
*setting
,
161 struct request_queue
*q
= drive
->queue
;
165 if (!(setting
->flags
& DS_SYNC
))
166 return setting
->set(drive
, arg
);
168 rq
= blk_get_request(q
, READ
, __GFP_WAIT
);
169 rq
->cmd_type
= REQ_TYPE_SPECIAL
;
171 rq
->cmd
[0] = REQ_DEVSET_EXEC
;
172 *(int *)&rq
->cmd
[1] = arg
;
173 rq
->special
= setting
->set
;
175 if (blk_execute_rq(q
, NULL
, rq
, 0))
182 ide_startstop_t
ide_do_devset(ide_drive_t
*drive
, struct request
*rq
)
184 int err
, (*setfunc
)(ide_drive_t
*, int) = rq
->special
;
186 err
= setfunc(drive
, *(int *)&rq
->cmd
[1]);
189 ide_complete_rq(drive
, err
, blk_rq_bytes(rq
));