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
;
23 int err
= -EOPNOTSUPP
;
25 for (; (ds
= s
->setting
); s
++) {
26 if (ds
->get
&& s
->get_ioctl
== cmd
)
28 else if (ds
->set
&& s
->set_ioctl
== cmd
)
35 mutex_lock(&ide_setting_mtx
);
36 spin_lock_irqsave(&ide_lock
, flags
);
38 spin_unlock_irqrestore(&ide_lock
, flags
);
39 mutex_unlock(&ide_setting_mtx
);
40 return err
>= 0 ? put_user(err
, (long __user
*)arg
) : err
;
43 if (bdev
!= bdev
->bd_contains
)
46 if (!capable(CAP_SYS_ADMIN
))
49 mutex_lock(&ide_setting_mtx
);
50 err
= ide_devset_execute(drive
, ds
, arg
);
51 mutex_unlock(&ide_setting_mtx
);
56 EXPORT_SYMBOL_GPL(ide_setting_ioctl
);
58 static int ide_get_identity_ioctl(ide_drive_t
*drive
, unsigned int cmd
,
62 int size
= (cmd
== HDIO_GET_IDENTITY
) ? (ATA_ID_WORDS
* 2) : 142;
65 if ((drive
->dev_flags
& IDE_DFLAG_ID_READ
) == 0) {
70 id
= kmalloc(size
, GFP_KERNEL
);
76 memcpy(id
, drive
->id
, size
);
77 ata_id_to_hd_driveid(id
);
79 if (copy_to_user((void __user
*)arg
, id
, size
))
87 static int ide_get_nice_ioctl(ide_drive_t
*drive
, unsigned long arg
)
89 return put_user((!!(drive
->dev_flags
& IDE_DFLAG_DSC_OVERLAP
)
90 << IDE_NICE_DSC_OVERLAP
) |
91 (!!(drive
->dev_flags
& IDE_DFLAG_NICE1
)
92 << IDE_NICE_1
), (long __user
*)arg
);
95 static int ide_set_nice_ioctl(ide_drive_t
*drive
, unsigned long arg
)
97 if (arg
!= (arg
& ((1 << IDE_NICE_DSC_OVERLAP
) | (1 << IDE_NICE_1
))))
100 if (((arg
>> IDE_NICE_DSC_OVERLAP
) & 1) &&
101 (drive
->media
== ide_disk
|| drive
->media
== ide_floppy
||
102 (drive
->dev_flags
& IDE_DFLAG_SCSI
)))
105 if ((arg
>> IDE_NICE_DSC_OVERLAP
) & 1)
106 drive
->dev_flags
|= IDE_DFLAG_DSC_OVERLAP
;
108 drive
->dev_flags
&= ~IDE_DFLAG_DSC_OVERLAP
;
110 if ((arg
>> IDE_NICE_1
) & 1)
111 drive
->dev_flags
|= IDE_DFLAG_NICE1
;
113 drive
->dev_flags
&= ~IDE_DFLAG_NICE1
;
118 static int ide_cmd_ioctl(ide_drive_t
*drive
, unsigned cmd
, unsigned long arg
)
121 int bufsize
= 0, err
= 0;
122 u8 args
[4], xfer_rate
= 0;
124 struct ide_taskfile
*tf
= &tfargs
.tf
;
127 if (NULL
== (void *) arg
) {
130 rq
= blk_get_request(drive
->queue
, READ
, __GFP_WAIT
);
131 rq
->cmd_type
= REQ_TYPE_ATA_TASKFILE
;
132 err
= blk_execute_rq(drive
->queue
, NULL
, rq
, 0);
138 if (copy_from_user(args
, (void __user
*)arg
, 4))
141 memset(&tfargs
, 0, sizeof(ide_task_t
));
142 tf
->feature
= args
[2];
143 if (args
[0] == ATA_CMD_SMART
) {
148 tfargs
.tf_flags
= IDE_TFLAG_OUT_TF
| IDE_TFLAG_IN_NSECT
;
151 tfargs
.tf_flags
= IDE_TFLAG_OUT_FEATURE
|
152 IDE_TFLAG_OUT_NSECT
| IDE_TFLAG_IN_NSECT
;
154 tf
->command
= args
[0];
155 tfargs
.data_phase
= args
[3] ? TASKFILE_IN
: TASKFILE_NO_DATA
;
158 tfargs
.tf_flags
|= IDE_TFLAG_IO_16BIT
;
159 bufsize
= SECTOR_SIZE
* args
[3];
160 buf
= kzalloc(bufsize
, GFP_KERNEL
);
165 if (tf
->command
== ATA_CMD_SET_FEATURES
&&
166 tf
->feature
== SETFEATURES_XFER
&&
167 tf
->nsect
>= XFER_SW_DMA_0
&&
168 (id
[ATA_ID_UDMA_MODES
] ||
169 id
[ATA_ID_MWDMA_MODES
] ||
170 id
[ATA_ID_SWDMA_MODES
])) {
172 if (tf
->nsect
> XFER_UDMA_2
&& !eighty_ninty_three(drive
)) {
173 printk(KERN_WARNING
"%s: UDMA speeds >UDMA33 cannot "
174 "be set\n", drive
->name
);
179 err
= ide_raw_taskfile(drive
, &tfargs
, buf
, args
[3]);
181 args
[0] = tf
->status
;
185 if (!err
&& xfer_rate
) {
186 /* active-retuning-calls future */
187 ide_set_xfer_rate(drive
, xfer_rate
);
188 ide_driveid_update(drive
);
191 if (copy_to_user((void __user
*)arg
, &args
, 4))
194 if (copy_to_user((void __user
*)(arg
+ 4), buf
, bufsize
))
201 static int ide_task_ioctl(ide_drive_t
*drive
, unsigned cmd
, unsigned long arg
)
203 void __user
*p
= (void __user
*)arg
;
208 if (copy_from_user(args
, p
, 7))
211 memset(&task
, 0, sizeof(task
));
212 memcpy(&task
.tf_array
[7], &args
[1], 6);
213 task
.tf
.command
= args
[0];
214 task
.tf_flags
= IDE_TFLAG_TF
| IDE_TFLAG_DEVICE
;
216 err
= ide_no_data_taskfile(drive
, &task
);
218 args
[0] = task
.tf
.command
;
219 memcpy(&args
[1], &task
.tf_array
[7], 6);
221 if (copy_to_user(p
, args
, 7))
227 static int generic_drive_reset(ide_drive_t
*drive
)
232 rq
= blk_get_request(drive
->queue
, READ
, __GFP_WAIT
);
233 rq
->cmd_type
= REQ_TYPE_SPECIAL
;
235 rq
->cmd
[0] = REQ_DRIVE_RESET
;
236 rq
->cmd_flags
|= REQ_SOFTBARRIER
;
237 if (blk_execute_rq(drive
->queue
, NULL
, rq
, 1))
243 int generic_ide_ioctl(ide_drive_t
*drive
, struct block_device
*bdev
,
244 unsigned int cmd
, unsigned long arg
)
248 err
= ide_setting_ioctl(drive
, bdev
, cmd
, arg
, ide_ioctl_settings
);
249 if (err
!= -EOPNOTSUPP
)
253 case HDIO_OBSOLETE_IDENTITY
:
254 case HDIO_GET_IDENTITY
:
255 if (bdev
!= bdev
->bd_contains
)
257 return ide_get_identity_ioctl(drive
, cmd
, arg
);
259 return ide_get_nice_ioctl(drive
, arg
);
261 if (!capable(CAP_SYS_ADMIN
))
263 return ide_set_nice_ioctl(drive
, arg
);
264 #ifdef CONFIG_IDE_TASK_IOCTL
265 case HDIO_DRIVE_TASKFILE
:
266 if (!capable(CAP_SYS_ADMIN
) || !capable(CAP_SYS_RAWIO
))
268 if (drive
->media
== ide_disk
)
269 return ide_taskfile_ioctl(drive
, cmd
, arg
);
273 if (!capable(CAP_SYS_RAWIO
))
275 return ide_cmd_ioctl(drive
, cmd
, arg
);
276 case HDIO_DRIVE_TASK
:
277 if (!capable(CAP_SYS_RAWIO
))
279 return ide_task_ioctl(drive
, cmd
, arg
);
280 case HDIO_DRIVE_RESET
:
281 if (!capable(CAP_SYS_ADMIN
))
283 return generic_drive_reset(drive
);
284 case HDIO_GET_BUSSTATE
:
285 if (!capable(CAP_SYS_ADMIN
))
287 if (put_user(BUSSTATE_ON
, (long __user
*)arg
))
290 case HDIO_SET_BUSSTATE
:
291 if (!capable(CAP_SYS_ADMIN
))
298 EXPORT_SYMBOL(generic_ide_ioctl
);