diff options
author | Bartlomiej Zolnierkiewicz <bzolnier@gmail.com> | 2009-03-24 18:22:44 -0400 |
---|---|---|
committer | Bartlomiej Zolnierkiewicz <bzolnier@gmail.com> | 2009-03-24 18:22:44 -0400 |
commit | 11938c929022bb92b1a42f5e1289524a1e465dc0 (patch) | |
tree | 7698cdcb8b45d30d7e4831cfa884c1ed13e1fe4c /drivers/ide | |
parent | c4e66c36cce3f23d68013c4112013123ffe80bdb (diff) |
ide: move device settings code to ide-devsets.c
Remove stale comment from ide.c while at it.
Signed-off-by: Bartlomiej Zolnierkiewicz <bzolnier@gmail.com>
Diffstat (limited to 'drivers/ide')
-rw-r--r-- | drivers/ide/Makefile | 3 | ||||
-rw-r--r-- | drivers/ide/ide-devsets.c | 190 | ||||
-rw-r--r-- | drivers/ide/ide-io.c | 37 | ||||
-rw-r--r-- | drivers/ide/ide.c | 154 |
4 files changed, 192 insertions, 192 deletions
diff --git a/drivers/ide/Makefile b/drivers/ide/Makefile index 1c326d94aa6..83a970ee4bf 100644 --- a/drivers/ide/Makefile +++ b/drivers/ide/Makefile | |||
@@ -5,7 +5,8 @@ | |||
5 | EXTRA_CFLAGS += -Idrivers/ide | 5 | EXTRA_CFLAGS += -Idrivers/ide |
6 | 6 | ||
7 | ide-core-y += ide.o ide-ioctls.o ide-io.o ide-iops.o ide-lib.o ide-probe.o \ | 7 | ide-core-y += ide.o ide-ioctls.o ide-io.o ide-iops.o ide-lib.o ide-probe.o \ |
8 | ide-taskfile.o ide-pm.o ide-park.o ide-pio-blacklist.o ide-sysfs.o | 8 | ide-taskfile.o ide-pm.o ide-park.o ide-pio-blacklist.o \ |
9 | ide-sysfs.o ide-devsets.o | ||
9 | 10 | ||
10 | # core IDE code | 11 | # core IDE code |
11 | ide-core-$(CONFIG_IDE_TIMINGS) += ide-timings.o | 12 | ide-core-$(CONFIG_IDE_TIMINGS) += ide-timings.o |
diff --git a/drivers/ide/ide-devsets.c b/drivers/ide/ide-devsets.c new file mode 100644 index 00000000000..7c3953414d4 --- /dev/null +++ b/drivers/ide/ide-devsets.c | |||
@@ -0,0 +1,190 @@ | |||
1 | |||
2 | #include <linux/kernel.h> | ||
3 | #include <linux/ide.h> | ||
4 | |||
5 | DEFINE_MUTEX(ide_setting_mtx); | ||
6 | |||
7 | ide_devset_get(io_32bit, io_32bit); | ||
8 | |||
9 | static int set_io_32bit(ide_drive_t *drive, int arg) | ||
10 | { | ||
11 | if (drive->dev_flags & IDE_DFLAG_NO_IO_32BIT) | ||
12 | return -EPERM; | ||
13 | |||
14 | if (arg < 0 || arg > 1 + (SUPPORT_VLB_SYNC << 1)) | ||
15 | return -EINVAL; | ||
16 | |||
17 | drive->io_32bit = arg; | ||
18 | |||
19 | return 0; | ||
20 | } | ||
21 | |||
22 | ide_devset_get_flag(ksettings, IDE_DFLAG_KEEP_SETTINGS); | ||
23 | |||
24 | static int set_ksettings(ide_drive_t *drive, int arg) | ||
25 | { | ||
26 | if (arg < 0 || arg > 1) | ||
27 | return -EINVAL; | ||
28 | |||
29 | if (arg) | ||
30 | drive->dev_flags |= IDE_DFLAG_KEEP_SETTINGS; | ||
31 | else | ||
32 | drive->dev_flags &= ~IDE_DFLAG_KEEP_SETTINGS; | ||
33 | |||
34 | return 0; | ||
35 | } | ||
36 | |||
37 | ide_devset_get_flag(using_dma, IDE_DFLAG_USING_DMA); | ||
38 | |||
39 | static int set_using_dma(ide_drive_t *drive, int arg) | ||
40 | { | ||
41 | #ifdef CONFIG_BLK_DEV_IDEDMA | ||
42 | int err = -EPERM; | ||
43 | |||
44 | if (arg < 0 || arg > 1) | ||
45 | return -EINVAL; | ||
46 | |||
47 | if (ata_id_has_dma(drive->id) == 0) | ||
48 | goto out; | ||
49 | |||
50 | if (drive->hwif->dma_ops == NULL) | ||
51 | goto out; | ||
52 | |||
53 | err = 0; | ||
54 | |||
55 | if (arg) { | ||
56 | if (ide_set_dma(drive)) | ||
57 | err = -EIO; | ||
58 | } else | ||
59 | ide_dma_off(drive); | ||
60 | |||
61 | out: | ||
62 | return err; | ||
63 | #else | ||
64 | if (arg < 0 || arg > 1) | ||
65 | return -EINVAL; | ||
66 | |||
67 | return -EPERM; | ||
68 | #endif | ||
69 | } | ||
70 | |||
71 | /* | ||
72 | * handle HDIO_SET_PIO_MODE ioctl abusers here, eventually it will go away | ||
73 | */ | ||
74 | static int set_pio_mode_abuse(ide_hwif_t *hwif, u8 req_pio) | ||
75 | { | ||
76 | switch (req_pio) { | ||
77 | case 202: | ||
78 | case 201: | ||
79 | case 200: | ||
80 | case 102: | ||
81 | case 101: | ||
82 | case 100: | ||
83 | return (hwif->host_flags & IDE_HFLAG_ABUSE_DMA_MODES) ? 1 : 0; | ||
84 | case 9: | ||
85 | case 8: | ||
86 | return (hwif->host_flags & IDE_HFLAG_ABUSE_PREFETCH) ? 1 : 0; | ||
87 | case 7: | ||
88 | case 6: | ||
89 | return (hwif->host_flags & IDE_HFLAG_ABUSE_FAST_DEVSEL) ? 1 : 0; | ||
90 | default: | ||
91 | return 0; | ||
92 | } | ||
93 | } | ||
94 | |||
95 | static int set_pio_mode(ide_drive_t *drive, int arg) | ||
96 | { | ||
97 | ide_hwif_t *hwif = drive->hwif; | ||
98 | const struct ide_port_ops *port_ops = hwif->port_ops; | ||
99 | |||
100 | if (arg < 0 || arg > 255) | ||
101 | return -EINVAL; | ||
102 | |||
103 | if (port_ops == NULL || port_ops->set_pio_mode == NULL || | ||
104 | (hwif->host_flags & IDE_HFLAG_NO_SET_MODE)) | ||
105 | return -ENOSYS; | ||
106 | |||
107 | if (set_pio_mode_abuse(drive->hwif, arg)) { | ||
108 | if (arg == 8 || arg == 9) { | ||
109 | unsigned long flags; | ||
110 | |||
111 | /* take lock for IDE_DFLAG_[NO_]UNMASK/[NO_]IO_32BIT */ | ||
112 | spin_lock_irqsave(&hwif->lock, flags); | ||
113 | port_ops->set_pio_mode(drive, arg); | ||
114 | spin_unlock_irqrestore(&hwif->lock, flags); | ||
115 | } else | ||
116 | port_ops->set_pio_mode(drive, arg); | ||
117 | } else { | ||
118 | int keep_dma = !!(drive->dev_flags & IDE_DFLAG_USING_DMA); | ||
119 | |||
120 | ide_set_pio(drive, arg); | ||
121 | |||
122 | if (hwif->host_flags & IDE_HFLAG_SET_PIO_MODE_KEEP_DMA) { | ||
123 | if (keep_dma) | ||
124 | ide_dma_on(drive); | ||
125 | } | ||
126 | } | ||
127 | |||
128 | return 0; | ||
129 | } | ||
130 | |||
131 | ide_devset_get_flag(unmaskirq, IDE_DFLAG_UNMASK); | ||
132 | |||
133 | static int set_unmaskirq(ide_drive_t *drive, int arg) | ||
134 | { | ||
135 | if (drive->dev_flags & IDE_DFLAG_NO_UNMASK) | ||
136 | return -EPERM; | ||
137 | |||
138 | if (arg < 0 || arg > 1) | ||
139 | return -EINVAL; | ||
140 | |||
141 | if (arg) | ||
142 | drive->dev_flags |= IDE_DFLAG_UNMASK; | ||
143 | else | ||
144 | drive->dev_flags &= ~IDE_DFLAG_UNMASK; | ||
145 | |||
146 | return 0; | ||
147 | } | ||
148 | |||
149 | ide_ext_devset_rw_sync(io_32bit, io_32bit); | ||
150 | ide_ext_devset_rw_sync(keepsettings, ksettings); | ||
151 | ide_ext_devset_rw_sync(unmaskirq, unmaskirq); | ||
152 | ide_ext_devset_rw_sync(using_dma, using_dma); | ||
153 | __IDE_DEVSET(pio_mode, DS_SYNC, NULL, set_pio_mode); | ||
154 | |||
155 | int ide_devset_execute(ide_drive_t *drive, const struct ide_devset *setting, | ||
156 | int arg) | ||
157 | { | ||
158 | struct request_queue *q = drive->queue; | ||
159 | struct request *rq; | ||
160 | int ret = 0; | ||
161 | |||
162 | if (!(setting->flags & DS_SYNC)) | ||
163 | return setting->set(drive, arg); | ||
164 | |||
165 | rq = blk_get_request(q, READ, __GFP_WAIT); | ||
166 | rq->cmd_type = REQ_TYPE_SPECIAL; | ||
167 | rq->cmd_len = 5; | ||
168 | rq->cmd[0] = REQ_DEVSET_EXEC; | ||
169 | *(int *)&rq->cmd[1] = arg; | ||
170 | rq->special = setting->set; | ||
171 | |||
172 | if (blk_execute_rq(q, NULL, rq, 0)) | ||
173 | ret = rq->errors; | ||
174 | blk_put_request(rq); | ||
175 | |||
176 | return ret; | ||
177 | } | ||
178 | |||
179 | ide_startstop_t ide_do_devset(ide_drive_t *drive, struct request *rq) | ||
180 | { | ||
181 | int err, (*setfunc)(ide_drive_t *, int) = rq->special; | ||
182 | |||
183 | err = setfunc(drive, *(int *)&rq->cmd[1]); | ||
184 | if (err) | ||
185 | rq->errors = err; | ||
186 | else | ||
187 | err = 1; | ||
188 | ide_end_request(drive, err, 0); | ||
189 | return ide_stopped; | ||
190 | } | ||
diff --git a/drivers/ide/ide-io.c b/drivers/ide/ide-io.c index 16e47989fcf..74d1a3e6825 100644 --- a/drivers/ide/ide-io.c +++ b/drivers/ide/ide-io.c | |||
@@ -490,43 +490,6 @@ static ide_startstop_t execute_drive_cmd (ide_drive_t *drive, | |||
490 | return ide_stopped; | 490 | return ide_stopped; |
491 | } | 491 | } |
492 | 492 | ||
493 | int ide_devset_execute(ide_drive_t *drive, const struct ide_devset *setting, | ||
494 | int arg) | ||
495 | { | ||
496 | struct request_queue *q = drive->queue; | ||
497 | struct request *rq; | ||
498 | int ret = 0; | ||
499 | |||
500 | if (!(setting->flags & DS_SYNC)) | ||
501 | return setting->set(drive, arg); | ||
502 | |||
503 | rq = blk_get_request(q, READ, __GFP_WAIT); | ||
504 | rq->cmd_type = REQ_TYPE_SPECIAL; | ||
505 | rq->cmd_len = 5; | ||
506 | rq->cmd[0] = REQ_DEVSET_EXEC; | ||
507 | *(int *)&rq->cmd[1] = arg; | ||
508 | rq->special = setting->set; | ||
509 | |||
510 | if (blk_execute_rq(q, NULL, rq, 0)) | ||
511 | ret = rq->errors; | ||
512 | blk_put_request(rq); | ||
513 | |||
514 | return ret; | ||
515 | } | ||
516 | |||
517 | static ide_startstop_t ide_do_devset(ide_drive_t *drive, struct request *rq) | ||
518 | { | ||
519 | int err, (*setfunc)(ide_drive_t *, int) = rq->special; | ||
520 | |||
521 | err = setfunc(drive, *(int *)&rq->cmd[1]); | ||
522 | if (err) | ||
523 | rq->errors = err; | ||
524 | else | ||
525 | err = 1; | ||
526 | ide_end_request(drive, err, 0); | ||
527 | return ide_stopped; | ||
528 | } | ||
529 | |||
530 | static ide_startstop_t ide_special_rq(ide_drive_t *drive, struct request *rq) | 493 | static ide_startstop_t ide_special_rq(ide_drive_t *drive, struct request *rq) |
531 | { | 494 | { |
532 | u8 cmd = rq->cmd[0]; | 495 | u8 cmd = rq->cmd[0]; |
diff --git a/drivers/ide/ide.c b/drivers/ide/ide.c index c779aa24dbe..92c9b90931e 100644 --- a/drivers/ide/ide.c +++ b/drivers/ide/ide.c | |||
@@ -62,160 +62,6 @@ | |||
62 | 62 | ||
63 | struct class *ide_port_class; | 63 | struct class *ide_port_class; |
64 | 64 | ||
65 | /* | ||
66 | * Locks for IDE setting functionality | ||
67 | */ | ||
68 | |||
69 | DEFINE_MUTEX(ide_setting_mtx); | ||
70 | |||
71 | ide_devset_get(io_32bit, io_32bit); | ||
72 | |||
73 | static int set_io_32bit(ide_drive_t *drive, int arg) | ||
74 | { | ||
75 | if (drive->dev_flags & IDE_DFLAG_NO_IO_32BIT) | ||
76 | return -EPERM; | ||
77 | |||
78 | if (arg < 0 || arg > 1 + (SUPPORT_VLB_SYNC << 1)) | ||
79 | return -EINVAL; | ||
80 | |||
81 | drive->io_32bit = arg; | ||
82 | |||
83 | return 0; | ||
84 | } | ||
85 | |||
86 | ide_devset_get_flag(ksettings, IDE_DFLAG_KEEP_SETTINGS); | ||
87 | |||
88 | static int set_ksettings(ide_drive_t *drive, int arg) | ||
89 | { | ||
90 | if (arg < 0 || arg > 1) | ||
91 | return -EINVAL; | ||
92 | |||
93 | if (arg) | ||
94 | drive->dev_flags |= IDE_DFLAG_KEEP_SETTINGS; | ||
95 | else | ||
96 | drive->dev_flags &= ~IDE_DFLAG_KEEP_SETTINGS; | ||
97 | |||
98 | return 0; | ||
99 | } | ||
100 | |||
101 | ide_devset_get_flag(using_dma, IDE_DFLAG_USING_DMA); | ||
102 | |||
103 | static int set_using_dma(ide_drive_t *drive, int arg) | ||
104 | { | ||
105 | #ifdef CONFIG_BLK_DEV_IDEDMA | ||
106 | int err = -EPERM; | ||
107 | |||
108 | if (arg < 0 || arg > 1) | ||
109 | return -EINVAL; | ||
110 | |||
111 | if (ata_id_has_dma(drive->id) == 0) | ||
112 | goto out; | ||
113 | |||
114 | if (drive->hwif->dma_ops == NULL) | ||
115 | goto out; | ||
116 | |||
117 | err = 0; | ||
118 | |||
119 | if (arg) { | ||
120 | if (ide_set_dma(drive)) | ||
121 | err = -EIO; | ||
122 | } else | ||
123 | ide_dma_off(drive); | ||
124 | |||
125 | out: | ||
126 | return err; | ||
127 | #else | ||
128 | if (arg < 0 || arg > 1) | ||
129 | return -EINVAL; | ||
130 | |||
131 | return -EPERM; | ||
132 | #endif | ||
133 | } | ||
134 | |||
135 | /* | ||
136 | * handle HDIO_SET_PIO_MODE ioctl abusers here, eventually it will go away | ||
137 | */ | ||
138 | static int set_pio_mode_abuse(ide_hwif_t *hwif, u8 req_pio) | ||
139 | { | ||
140 | switch (req_pio) { | ||
141 | case 202: | ||
142 | case 201: | ||
143 | case 200: | ||
144 | case 102: | ||
145 | case 101: | ||
146 | case 100: | ||
147 | return (hwif->host_flags & IDE_HFLAG_ABUSE_DMA_MODES) ? 1 : 0; | ||
148 | case 9: | ||
149 | case 8: | ||
150 | return (hwif->host_flags & IDE_HFLAG_ABUSE_PREFETCH) ? 1 : 0; | ||
151 | case 7: | ||
152 | case 6: | ||
153 | return (hwif->host_flags & IDE_HFLAG_ABUSE_FAST_DEVSEL) ? 1 : 0; | ||
154 | default: | ||
155 | return 0; | ||
156 | } | ||
157 | } | ||
158 | |||
159 | static int set_pio_mode(ide_drive_t *drive, int arg) | ||
160 | { | ||
161 | ide_hwif_t *hwif = drive->hwif; | ||
162 | const struct ide_port_ops *port_ops = hwif->port_ops; | ||
163 | |||
164 | if (arg < 0 || arg > 255) | ||
165 | return -EINVAL; | ||
166 | |||
167 | if (port_ops == NULL || port_ops->set_pio_mode == NULL || | ||
168 | (hwif->host_flags & IDE_HFLAG_NO_SET_MODE)) | ||
169 | return -ENOSYS; | ||
170 | |||
171 | if (set_pio_mode_abuse(drive->hwif, arg)) { | ||
172 | if (arg == 8 || arg == 9) { | ||
173 | unsigned long flags; | ||
174 | |||
175 | /* take lock for IDE_DFLAG_[NO_]UNMASK/[NO_]IO_32BIT */ | ||
176 | spin_lock_irqsave(&hwif->lock, flags); | ||
177 | port_ops->set_pio_mode(drive, arg); | ||
178 | spin_unlock_irqrestore(&hwif->lock, flags); | ||
179 | } else | ||
180 | port_ops->set_pio_mode(drive, arg); | ||
181 | } else { | ||
182 | int keep_dma = !!(drive->dev_flags & IDE_DFLAG_USING_DMA); | ||
183 | |||
184 | ide_set_pio(drive, arg); | ||
185 | |||
186 | if (hwif->host_flags & IDE_HFLAG_SET_PIO_MODE_KEEP_DMA) { | ||
187 | if (keep_dma) | ||
188 | ide_dma_on(drive); | ||
189 | } | ||
190 | } | ||
191 | |||
192 | return 0; | ||
193 | } | ||
194 | |||
195 | ide_devset_get_flag(unmaskirq, IDE_DFLAG_UNMASK); | ||
196 | |||
197 | static int set_unmaskirq(ide_drive_t *drive, int arg) | ||
198 | { | ||
199 | if (drive->dev_flags & IDE_DFLAG_NO_UNMASK) | ||
200 | return -EPERM; | ||
201 | |||
202 | if (arg < 0 || arg > 1) | ||
203 | return -EINVAL; | ||
204 | |||
205 | if (arg) | ||
206 | drive->dev_flags |= IDE_DFLAG_UNMASK; | ||
207 | else | ||
208 | drive->dev_flags &= ~IDE_DFLAG_UNMASK; | ||
209 | |||
210 | return 0; | ||
211 | } | ||
212 | |||
213 | ide_ext_devset_rw_sync(io_32bit, io_32bit); | ||
214 | ide_ext_devset_rw_sync(keepsettings, ksettings); | ||
215 | ide_ext_devset_rw_sync(unmaskirq, unmaskirq); | ||
216 | ide_ext_devset_rw_sync(using_dma, using_dma); | ||
217 | __IDE_DEVSET(pio_mode, DS_SYNC, NULL, set_pio_mode); | ||
218 | |||
219 | /** | 65 | /** |
220 | * ide_device_get - get an additional reference to a ide_drive_t | 66 | * ide_device_get - get an additional reference to a ide_drive_t |
221 | * @drive: device to get a reference to | 67 | * @drive: device to get a reference to |