diff options
Diffstat (limited to 'drivers/ide/ide-proc.c')
-rw-r--r-- | drivers/ide/ide-proc.c | 102 |
1 files changed, 48 insertions, 54 deletions
diff --git a/drivers/ide/ide-proc.c b/drivers/ide/ide-proc.c index 6489c647be82..e7030a491463 100644 --- a/drivers/ide/ide-proc.c +++ b/drivers/ide/ide-proc.c | |||
@@ -124,15 +124,16 @@ static int proc_ide_read_identify | |||
124 | * setting semaphore | 124 | * setting semaphore |
125 | */ | 125 | */ |
126 | 126 | ||
127 | static const struct ide_devset *ide_find_setting(const struct ide_devset **st, | 127 | static |
128 | char *name) | 128 | const struct ide_proc_devset *ide_find_setting(const struct ide_proc_devset *st, |
129 | char *name) | ||
129 | { | 130 | { |
130 | while (*st) { | 131 | while (st->name) { |
131 | if (strcmp((*st)->name, name) == 0) | 132 | if (strcmp(st->name, name) == 0) |
132 | break; | 133 | break; |
133 | st++; | 134 | st++; |
134 | } | 135 | } |
135 | return *st; | 136 | return st->name ? st : NULL; |
136 | } | 137 | } |
137 | 138 | ||
138 | /** | 139 | /** |
@@ -149,15 +150,16 @@ static const struct ide_devset *ide_find_setting(const struct ide_devset **st, | |||
149 | */ | 150 | */ |
150 | 151 | ||
151 | static int ide_read_setting(ide_drive_t *drive, | 152 | static int ide_read_setting(ide_drive_t *drive, |
152 | const struct ide_devset *setting) | 153 | const struct ide_proc_devset *setting) |
153 | { | 154 | { |
155 | const struct ide_devset *ds = setting->setting; | ||
154 | int val = -EINVAL; | 156 | int val = -EINVAL; |
155 | 157 | ||
156 | if ((setting->flags & S_READ)) { | 158 | if (ds->get) { |
157 | unsigned long flags; | 159 | unsigned long flags; |
158 | 160 | ||
159 | spin_lock_irqsave(&ide_lock, flags); | 161 | spin_lock_irqsave(&ide_lock, flags); |
160 | val = setting->get(drive); | 162 | val = ds->get(drive); |
161 | spin_unlock_irqrestore(&ide_lock, flags); | 163 | spin_unlock_irqrestore(&ide_lock, flags); |
162 | } | 164 | } |
163 | 165 | ||
@@ -183,24 +185,21 @@ static int ide_read_setting(ide_drive_t *drive, | |||
183 | */ | 185 | */ |
184 | 186 | ||
185 | static int ide_write_setting(ide_drive_t *drive, | 187 | static int ide_write_setting(ide_drive_t *drive, |
186 | const struct ide_devset *setting, int val) | 188 | const struct ide_proc_devset *setting, int val) |
187 | { | 189 | { |
190 | const struct ide_devset *ds = setting->setting; | ||
191 | |||
188 | if (!capable(CAP_SYS_ADMIN)) | 192 | if (!capable(CAP_SYS_ADMIN)) |
189 | return -EACCES; | 193 | return -EACCES; |
190 | if (setting->set && (setting->flags & S_NOLOCK)) | 194 | if (!ds->set) |
191 | return setting->set(drive, val); | ||
192 | if (!(setting->flags & S_WRITE)) | ||
193 | return -EPERM; | 195 | return -EPERM; |
194 | if (val < setting->min || val > setting->max) | 196 | if ((ds->flags & DS_SYNC) |
197 | && (val < setting->min || val > setting->max)) | ||
195 | return -EINVAL; | 198 | return -EINVAL; |
196 | if (ide_spin_wait_hwgroup(drive)) | 199 | return ide_devset_execute(drive, ds, val); |
197 | return -EBUSY; | ||
198 | setting->set(drive, val); | ||
199 | spin_unlock_irq(&ide_lock); | ||
200 | return 0; | ||
201 | } | 200 | } |
202 | 201 | ||
203 | static ide_devset_get(xfer_rate, current_speed); | 202 | ide_devset_get(xfer_rate, current_speed); |
204 | 203 | ||
205 | static int set_xfer_rate (ide_drive_t *drive, int arg) | 204 | static int set_xfer_rate (ide_drive_t *drive, int arg) |
206 | { | 205 | { |
@@ -226,29 +225,22 @@ static int set_xfer_rate (ide_drive_t *drive, int arg) | |||
226 | return err; | 225 | return err; |
227 | } | 226 | } |
228 | 227 | ||
229 | ide_devset_rw_nolock(current_speed, 0, 70, xfer_rate); | 228 | ide_devset_rw(current_speed, xfer_rate); |
230 | ide_devset_rw_nolock(io_32bit, 0, 1 + (SUPPORT_VLB_SYNC << 1), io_32bit); | 229 | ide_devset_rw_field(init_speed, init_speed); |
231 | ide_devset_rw_nolock(keepsettings, 0, 1, ksettings); | 230 | ide_devset_rw_field(nice1, nice1); |
232 | ide_devset_rw_nolock(unmaskirq, 0, 1, unmaskirq); | 231 | ide_devset_rw_field(number, dn); |
233 | ide_devset_rw_nolock(using_dma, 0, 1, using_dma); | 232 | |
234 | 233 | static const struct ide_proc_devset ide_generic_settings[] = { | |
235 | ide_devset_w_nolock(pio_mode, 0, 255, pio_mode); | 234 | IDE_PROC_DEVSET(current_speed, 0, 70), |
236 | 235 | IDE_PROC_DEVSET(init_speed, 0, 70), | |
237 | ide_devset_rw(init_speed, 0, 70, init_speed); | 236 | IDE_PROC_DEVSET(io_32bit, 0, 1 + (SUPPORT_VLB_SYNC << 1)), |
238 | ide_devset_rw(nice1, 0, 1, nice1); | 237 | IDE_PROC_DEVSET(keepsettings, 0, 1), |
239 | ide_devset_rw(number, 0, 3, dn); | 238 | IDE_PROC_DEVSET(nice1, 0, 1), |
240 | 239 | IDE_PROC_DEVSET(number, 0, 3), | |
241 | static const struct ide_devset *ide_generic_settings[] = { | 240 | IDE_PROC_DEVSET(pio_mode, 0, 255), |
242 | &ide_devset_current_speed, | 241 | IDE_PROC_DEVSET(unmaskirq, 0, 1), |
243 | &ide_devset_init_speed, | 242 | IDE_PROC_DEVSET(using_dma, 0, 1), |
244 | &ide_devset_io_32bit, | 243 | { 0 }, |
245 | &ide_devset_keepsettings, | ||
246 | &ide_devset_nice1, | ||
247 | &ide_devset_number, | ||
248 | &ide_devset_pio_mode, | ||
249 | &ide_devset_unmaskirq, | ||
250 | &ide_devset_using_dma, | ||
251 | NULL | ||
252 | }; | 244 | }; |
253 | 245 | ||
254 | static void proc_ide_settings_warn(void) | 246 | static void proc_ide_settings_warn(void) |
@@ -266,7 +258,8 @@ static void proc_ide_settings_warn(void) | |||
266 | static int proc_ide_read_settings | 258 | static int proc_ide_read_settings |
267 | (char *page, char **start, off_t off, int count, int *eof, void *data) | 259 | (char *page, char **start, off_t off, int count, int *eof, void *data) |
268 | { | 260 | { |
269 | const struct ide_devset *setting, **g, **d; | 261 | const struct ide_proc_devset *setting, *g, *d; |
262 | const struct ide_devset *ds; | ||
270 | ide_drive_t *drive = (ide_drive_t *) data; | 263 | ide_drive_t *drive = (ide_drive_t *) data; |
271 | char *out = page; | 264 | char *out = page; |
272 | int len, rc, mul_factor, div_factor; | 265 | int len, rc, mul_factor, div_factor; |
@@ -278,17 +271,17 @@ static int proc_ide_read_settings | |||
278 | d = drive->settings; | 271 | d = drive->settings; |
279 | out += sprintf(out, "name\t\t\tvalue\t\tmin\t\tmax\t\tmode\n"); | 272 | out += sprintf(out, "name\t\t\tvalue\t\tmin\t\tmax\t\tmode\n"); |
280 | out += sprintf(out, "----\t\t\t-----\t\t---\t\t---\t\t----\n"); | 273 | out += sprintf(out, "----\t\t\t-----\t\t---\t\t---\t\t----\n"); |
281 | while (*g || (d && *d)) { | 274 | while (g->name || (d && d->name)) { |
282 | /* read settings in the alphabetical order */ | 275 | /* read settings in the alphabetical order */ |
283 | if (*g && d && *d) { | 276 | if (g->name && d && d->name) { |
284 | if (strcmp((*d)->name, (*g)->name) < 0) | 277 | if (strcmp(d->name, g->name) < 0) |
285 | setting = *d++; | 278 | setting = d++; |
286 | else | 279 | else |
287 | setting = *g++; | 280 | setting = g++; |
288 | } else if (d && *d) { | 281 | } else if (d && d->name) { |
289 | setting = *d++; | 282 | setting = d++; |
290 | } else | 283 | } else |
291 | setting = *g++; | 284 | setting = g++; |
292 | mul_factor = setting->mulf ? setting->mulf(drive) : 1; | 285 | mul_factor = setting->mulf ? setting->mulf(drive) : 1; |
293 | div_factor = setting->divf ? setting->divf(drive) : 1; | 286 | div_factor = setting->divf ? setting->divf(drive) : 1; |
294 | out += sprintf(out, "%-24s", setting->name); | 287 | out += sprintf(out, "%-24s", setting->name); |
@@ -298,9 +291,10 @@ static int proc_ide_read_settings | |||
298 | else | 291 | else |
299 | out += sprintf(out, "%-16s", "write-only"); | 292 | out += sprintf(out, "%-16s", "write-only"); |
300 | out += sprintf(out, "%-16d%-16d", (setting->min * mul_factor + div_factor - 1) / div_factor, setting->max * mul_factor / div_factor); | 293 | out += sprintf(out, "%-16d%-16d", (setting->min * mul_factor + div_factor - 1) / div_factor, setting->max * mul_factor / div_factor); |
301 | if (setting->flags & S_READ) | 294 | ds = setting->setting; |
295 | if (ds->get) | ||
302 | out += sprintf(out, "r"); | 296 | out += sprintf(out, "r"); |
303 | if (setting->flags & S_WRITE) | 297 | if (ds->set) |
304 | out += sprintf(out, "w"); | 298 | out += sprintf(out, "w"); |
305 | out += sprintf(out, "\n"); | 299 | out += sprintf(out, "\n"); |
306 | } | 300 | } |
@@ -319,7 +313,7 @@ static int proc_ide_write_settings(struct file *file, const char __user *buffer, | |||
319 | int for_real = 0, mul_factor, div_factor; | 313 | int for_real = 0, mul_factor, div_factor; |
320 | unsigned long n; | 314 | unsigned long n; |
321 | 315 | ||
322 | const struct ide_devset *setting; | 316 | const struct ide_proc_devset *setting; |
323 | char *buf, *s; | 317 | char *buf, *s; |
324 | 318 | ||
325 | if (!capable(CAP_SYS_ADMIN)) | 319 | if (!capable(CAP_SYS_ADMIN)) |