5 #include <linux/hdreg.h>
8 static const struct ide_ioctl_devset ide_ioctl_settings
[] = {
9 { HDIO_GET_32BIT
, HDIO_SET_32BIT
, &ide_devset_io_32bit
},
10 { HDIO_GET_KEEPSETTINGS
, HDIO_SET_KEEPSETTINGS
, &ide_devset_keepsettings
},
11 { HDIO_GET_UNMASKINTR
, HDIO_SET_UNMASKINTR
, &ide_devset_unmaskirq
},
12 { HDIO_GET_DMA
, HDIO_SET_DMA
, &ide_devset_using_dma
},
13 { -1, HDIO_SET_PIO_MODE
, &ide_devset_pio_mode
},
17 int ide_setting_ioctl(ide_drive_t
*drive
, struct block_device
*bdev
,
18 unsigned int cmd
, unsigned long arg
,
19 const struct ide_ioctl_devset
*s
)
21 const struct ide_devset
*ds
;
22 int err
= -EOPNOTSUPP
;
24 for (; (ds
= s
->setting
); s
++) {
25 if (ds
->get
&& s
->get_ioctl
== cmd
)
27 else if (ds
->set
&& s
->set_ioctl
== cmd
)
34 mutex_lock(&ide_setting_mtx
);
36 mutex_unlock(&ide_setting_mtx
);
37 return err
>= 0 ? put_user(err
, (long __user
*)arg
) : err
;
40 if (bdev
!= bdev
->bd_contains
)
43 if (!capable(CAP_SYS_ADMIN
))
46 mutex_lock(&ide_setting_mtx
);
47 err
= ide_devset_execute(drive
, ds
, arg
);
48 mutex_unlock(&ide_setting_mtx
);
53 EXPORT_SYMBOL_GPL(ide_setting_ioctl
);
55 static int ide_get_identity_ioctl(ide_drive_t
*drive
, unsigned int cmd
,
59 int size
= (cmd
== HDIO_GET_IDENTITY
) ? (ATA_ID_WORDS
* 2) : 142;
62 if ((drive
->dev_flags
& IDE_DFLAG_ID_READ
) == 0) {
67 id
= kmalloc(size
, GFP_KERNEL
);
73 memcpy(id
, drive
->id
, size
);
74 ata_id_to_hd_driveid(id
);
76 if (copy_to_user((void __user
*)arg
, id
, size
))
84 static int ide_get_nice_ioctl(ide_drive_t
*drive
, unsigned long arg
)
86 return put_user((!!(drive
->dev_flags
& IDE_DFLAG_DSC_OVERLAP
)
87 << IDE_NICE_DSC_OVERLAP
) |
88 (!!(drive
->dev_flags
& IDE_DFLAG_NICE1
)
89 << IDE_NICE_1
), (long __user
*)arg
);
92 static int ide_set_nice_ioctl(ide_drive_t
*drive
, unsigned long arg
)
94 if (arg
!= (arg
& ((1 << IDE_NICE_DSC_OVERLAP
) | (1 << IDE_NICE_1
))))
97 if (((arg
>> IDE_NICE_DSC_OVERLAP
) & 1) &&
98 (drive
->media
!= ide_tape
))
101 if ((arg
>> IDE_NICE_DSC_OVERLAP
) & 1)
102 drive
->dev_flags
|= IDE_DFLAG_DSC_OVERLAP
;
104 drive
->dev_flags
&= ~IDE_DFLAG_DSC_OVERLAP
;
106 if ((arg
>> IDE_NICE_1
) & 1)
107 drive
->dev_flags
|= IDE_DFLAG_NICE1
;
109 drive
->dev_flags
&= ~IDE_DFLAG_NICE1
;
114 static int ide_cmd_ioctl(ide_drive_t
*drive
, unsigned long arg
)
117 int bufsize
= 0, err
= 0;
118 u8 args
[4], xfer_rate
= 0;
120 struct ide_taskfile
*tf
= &cmd
.tf
;
123 if (NULL
== (void *) arg
) {
126 rq
= blk_get_request(drive
->queue
, READ
, __GFP_WAIT
);
127 rq
->cmd_type
= REQ_TYPE_ATA_TASKFILE
;
128 err
= blk_execute_rq(drive
->queue
, NULL
, rq
, 0);
134 if (copy_from_user(args
, (void __user
*)arg
, 4))
137 memset(&cmd
, 0, sizeof(cmd
));
138 tf
->feature
= args
[2];
139 if (args
[0] == ATA_CMD_SMART
) {
144 cmd
.tf_flags
= IDE_TFLAG_OUT_TF
| IDE_TFLAG_IN_NSECT
;
147 cmd
.tf_flags
= IDE_TFLAG_OUT_FEATURE
| IDE_TFLAG_OUT_NSECT
|
150 tf
->command
= args
[0];
151 cmd
.protocol
= args
[3] ? ATA_PROT_PIO
: ATA_PROT_NODATA
;
154 cmd
.tf_flags
|= IDE_TFLAG_IO_16BIT
;
155 bufsize
= SECTOR_SIZE
* args
[3];
156 buf
= kzalloc(bufsize
, GFP_KERNEL
);
161 if (tf
->command
== ATA_CMD_SET_FEATURES
&&
162 tf
->feature
== SETFEATURES_XFER
&&
163 tf
->nsect
>= XFER_SW_DMA_0
&&
164 (id
[ATA_ID_UDMA_MODES
] ||
165 id
[ATA_ID_MWDMA_MODES
] ||
166 id
[ATA_ID_SWDMA_MODES
])) {
168 if (tf
->nsect
> XFER_UDMA_2
&& !eighty_ninty_three(drive
)) {
169 printk(KERN_WARNING
"%s: UDMA speeds >UDMA33 cannot "
170 "be set\n", drive
->name
);
175 err
= ide_raw_taskfile(drive
, &cmd
, buf
, args
[3]);
177 args
[0] = tf
->status
;
181 if (!err
&& xfer_rate
) {
182 /* active-retuning-calls future */
183 ide_set_xfer_rate(drive
, xfer_rate
);
184 ide_driveid_update(drive
);
187 if (copy_to_user((void __user
*)arg
, &args
, 4))
190 if (copy_to_user((void __user
*)(arg
+ 4), buf
, bufsize
))
197 static int ide_task_ioctl(ide_drive_t
*drive
, unsigned long arg
)
199 void __user
*p
= (void __user
*)arg
;
204 if (copy_from_user(args
, p
, 7))
207 memset(&cmd
, 0, sizeof(cmd
));
208 memcpy(&cmd
.tf_array
[7], &args
[1], 6);
209 cmd
.tf
.command
= args
[0];
210 cmd
.tf_flags
= IDE_TFLAG_TF
| IDE_TFLAG_DEVICE
;
212 err
= ide_no_data_taskfile(drive
, &cmd
);
214 args
[0] = cmd
.tf
.command
;
215 memcpy(&args
[1], &cmd
.tf_array
[7], 6);
217 if (copy_to_user(p
, args
, 7))
223 static int generic_drive_reset(ide_drive_t
*drive
)
228 rq
= blk_get_request(drive
->queue
, READ
, __GFP_WAIT
);
229 rq
->cmd_type
= REQ_TYPE_SPECIAL
;
231 rq
->cmd
[0] = REQ_DRIVE_RESET
;
232 rq
->cmd_flags
|= REQ_SOFTBARRIER
;
233 if (blk_execute_rq(drive
->queue
, NULL
, rq
, 1))
239 int generic_ide_ioctl(ide_drive_t
*drive
, struct block_device
*bdev
,
240 unsigned int cmd
, unsigned long arg
)
244 err
= ide_setting_ioctl(drive
, bdev
, cmd
, arg
, ide_ioctl_settings
);
245 if (err
!= -EOPNOTSUPP
)
249 case HDIO_OBSOLETE_IDENTITY
:
250 case HDIO_GET_IDENTITY
:
251 if (bdev
!= bdev
->bd_contains
)
253 return ide_get_identity_ioctl(drive
, cmd
, arg
);
255 return ide_get_nice_ioctl(drive
, arg
);
257 if (!capable(CAP_SYS_ADMIN
))
259 return ide_set_nice_ioctl(drive
, arg
);
260 #ifdef CONFIG_IDE_TASK_IOCTL
261 case HDIO_DRIVE_TASKFILE
:
262 if (!capable(CAP_SYS_ADMIN
) || !capable(CAP_SYS_RAWIO
))
264 if (drive
->media
== ide_disk
)
265 return ide_taskfile_ioctl(drive
, arg
);
269 if (!capable(CAP_SYS_RAWIO
))
271 return ide_cmd_ioctl(drive
, arg
);
272 case HDIO_DRIVE_TASK
:
273 if (!capable(CAP_SYS_RAWIO
))
275 return ide_task_ioctl(drive
, arg
);
276 case HDIO_DRIVE_RESET
:
277 if (!capable(CAP_SYS_ADMIN
))
279 return generic_drive_reset(drive
);
280 case HDIO_GET_BUSSTATE
:
281 if (!capable(CAP_SYS_ADMIN
))
283 if (put_user(BUSSTATE_ON
, (long __user
*)arg
))
286 case HDIO_SET_BUSSTATE
:
287 if (!capable(CAP_SYS_ADMIN
))
294 EXPORT_SYMBOL(generic_ide_ioctl
);