]>
Commit | Line | Data |
---|---|---|
457c8996 | 1 | // SPDX-License-Identifier: GPL-2.0-only |
1da177e4 | 2 | /* |
1da177e4 | 3 | * Copyright (C) 1997-1998 Mark Lord |
ccd32e22 | 4 | * Copyright (C) 2003 Red Hat |
7662d046 BZ |
5 | * |
6 | * Some code was moved here from ide.c, see it for original copyrights. | |
1da177e4 LT |
7 | */ |
8 | ||
9 | /* | |
10 | * This is the /proc/ide/ filesystem implementation. | |
11 | * | |
12 | * Drive/Driver settings can be retrieved by reading the drive's | |
13 | * "settings" files. e.g. "cat /proc/ide0/hda/settings" | |
14 | * To write a new value "val" into a specific setting "name", use: | |
15 | * echo "name:val" >/proc/ide/ide0/hda/settings | |
1da177e4 LT |
16 | */ |
17 | ||
1da177e4 LT |
18 | #include <linux/module.h> |
19 | ||
7c0f6ba6 | 20 | #include <linux/uaccess.h> |
1da177e4 | 21 | #include <linux/errno.h> |
1da177e4 LT |
22 | #include <linux/proc_fs.h> |
23 | #include <linux/stat.h> | |
24 | #include <linux/mm.h> | |
25 | #include <linux/pci.h> | |
26 | #include <linux/ctype.h> | |
1da177e4 LT |
27 | #include <linux/ide.h> |
28 | #include <linux/seq_file.h> | |
5a0e3ad6 | 29 | #include <linux/slab.h> |
1da177e4 LT |
30 | |
31 | #include <asm/io.h> | |
32 | ||
5cbf79cd BZ |
33 | static struct proc_dir_entry *proc_ide_root; |
34 | ||
6d703a81 | 35 | static int ide_imodel_proc_show(struct seq_file *m, void *v) |
1da177e4 | 36 | { |
6d703a81 | 37 | ide_hwif_t *hwif = (ide_hwif_t *) m->private; |
1da177e4 LT |
38 | const char *name; |
39 | ||
1da177e4 | 40 | switch (hwif->chipset) { |
441e92da PC |
41 | case ide_generic: name = "generic"; break; |
42 | case ide_pci: name = "pci"; break; | |
43 | case ide_cmd640: name = "cmd640"; break; | |
44 | case ide_dtc2278: name = "dtc2278"; break; | |
45 | case ide_ali14xx: name = "ali14xx"; break; | |
46 | case ide_qd65xx: name = "qd65xx"; break; | |
47 | case ide_umc8672: name = "umc8672"; break; | |
48 | case ide_ht6560b: name = "ht6560b"; break; | |
441e92da PC |
49 | case ide_4drives: name = "4drives"; break; |
50 | case ide_pmac: name = "mac-io"; break; | |
51 | case ide_au1xxx: name = "au1xxx"; break; | |
52 | case ide_palm3710: name = "palm3710"; break; | |
441e92da PC |
53 | case ide_acorn: name = "acorn"; break; |
54 | default: name = "(unknown)"; break; | |
1da177e4 | 55 | } |
6d703a81 AD |
56 | seq_printf(m, "%s\n", name); |
57 | return 0; | |
1da177e4 LT |
58 | } |
59 | ||
6d703a81 AD |
60 | static int ide_mate_proc_show(struct seq_file *m, void *v) |
61 | { | |
62 | ide_hwif_t *hwif = (ide_hwif_t *) m->private; | |
1da177e4 | 63 | |
4283e1ba | 64 | if (hwif && hwif->mate) |
6d703a81 | 65 | seq_printf(m, "%s\n", hwif->mate->name); |
1da177e4 | 66 | else |
6d703a81 AD |
67 | seq_printf(m, "(none)\n"); |
68 | return 0; | |
1da177e4 LT |
69 | } |
70 | ||
6d703a81 AD |
71 | static int ide_channel_proc_show(struct seq_file *m, void *v) |
72 | { | |
73 | ide_hwif_t *hwif = (ide_hwif_t *) m->private; | |
74 | ||
75 | seq_printf(m, "%c\n", hwif->channel ? '1' : '0'); | |
76 | return 0; | |
1da177e4 LT |
77 | } |
78 | ||
6d703a81 AD |
79 | static int ide_identify_proc_show(struct seq_file *m, void *v) |
80 | { | |
81 | ide_drive_t *drive = (ide_drive_t *)m->private; | |
82 | u8 *buf; | |
1da177e4 | 83 | |
6d703a81 AD |
84 | if (!drive) { |
85 | seq_putc(m, '\n'); | |
86 | return 0; | |
87 | } | |
1da177e4 | 88 | |
6d703a81 AD |
89 | buf = kmalloc(SECTOR_SIZE, GFP_KERNEL); |
90 | if (!buf) | |
91 | return -ENOMEM; | |
92 | if (taskfile_lib_get_identify(drive, buf) == 0) { | |
93 | __le16 *val = (__le16 *)buf; | |
94 | int i; | |
151a6701 | 95 | |
6d703a81 AD |
96 | for (i = 0; i < SECTOR_SIZE / 2; i++) { |
97 | seq_printf(m, "%04x%c", le16_to_cpu(val[i]), | |
98 | (i % 8) == 7 ? '\n' : ' '); | |
1da177e4 | 99 | } |
6d703a81 AD |
100 | } else |
101 | seq_putc(m, buf[0]); | |
102 | kfree(buf); | |
103 | return 0; | |
1da177e4 LT |
104 | } |
105 | ||
7662d046 | 106 | /** |
8185d5aa BZ |
107 | * ide_find_setting - find a specific setting |
108 | * @st: setting table pointer | |
7662d046 | 109 | * @name: setting name |
7662d046 | 110 | * |
8185d5aa | 111 | * Scan's the setting table for a matching entry and returns |
7662d046 BZ |
112 | * this or NULL if no entry is found. The caller must hold the |
113 | * setting semaphore | |
114 | */ | |
115 | ||
92f1f8fd EO |
116 | static |
117 | const struct ide_proc_devset *ide_find_setting(const struct ide_proc_devset *st, | |
118 | char *name) | |
7662d046 | 119 | { |
92f1f8fd EO |
120 | while (st->name) { |
121 | if (strcmp(st->name, name) == 0) | |
7662d046 | 122 | break; |
8185d5aa | 123 | st++; |
7662d046 | 124 | } |
92f1f8fd | 125 | return st->name ? st : NULL; |
7662d046 BZ |
126 | } |
127 | ||
128 | /** | |
129 | * ide_read_setting - read an IDE setting | |
130 | * @drive: drive to read from | |
131 | * @setting: drive setting | |
132 | * | |
133 | * Read a drive setting and return the value. The caller | |
f9383c42 | 134 | * must hold the ide_setting_mtx when making this call. |
7662d046 BZ |
135 | * |
136 | * BUGS: the data return and error are the same return value | |
137 | * so an error -EINVAL and true return of the same value cannot | |
138 | * be told apart | |
139 | */ | |
140 | ||
8185d5aa | 141 | static int ide_read_setting(ide_drive_t *drive, |
92f1f8fd | 142 | const struct ide_proc_devset *setting) |
7662d046 | 143 | { |
92f1f8fd | 144 | const struct ide_devset *ds = setting->setting; |
8185d5aa BZ |
145 | int val = -EINVAL; |
146 | ||
1f473e9c | 147 | if (ds->get) |
92f1f8fd | 148 | val = ds->get(drive); |
8185d5aa | 149 | |
7662d046 BZ |
150 | return val; |
151 | } | |
152 | ||
153 | /** | |
154 | * ide_write_setting - read an IDE setting | |
155 | * @drive: drive to read from | |
156 | * @setting: drive setting | |
157 | * @val: value | |
158 | * | |
159 | * Write a drive setting if it is possible. The caller | |
f9383c42 | 160 | * must hold the ide_setting_mtx when making this call. |
7662d046 BZ |
161 | * |
162 | * BUGS: the data return and error are the same return value | |
163 | * so an error -EINVAL and true return of the same value cannot | |
164 | * be told apart | |
165 | * | |
166 | * FIXME: This should be changed to enqueue a special request | |
167 | * to the driver to change settings, and then wait on a sema for completion. | |
168 | * The current scheme of polling is kludgy, though safe enough. | |
169 | */ | |
170 | ||
8185d5aa | 171 | static int ide_write_setting(ide_drive_t *drive, |
92f1f8fd | 172 | const struct ide_proc_devset *setting, int val) |
7662d046 | 173 | { |
92f1f8fd EO |
174 | const struct ide_devset *ds = setting->setting; |
175 | ||
7662d046 BZ |
176 | if (!capable(CAP_SYS_ADMIN)) |
177 | return -EACCES; | |
92f1f8fd | 178 | if (!ds->set) |
7662d046 | 179 | return -EPERM; |
92f1f8fd EO |
180 | if ((ds->flags & DS_SYNC) |
181 | && (val < setting->min || val > setting->max)) | |
7662d046 | 182 | return -EINVAL; |
92f1f8fd | 183 | return ide_devset_execute(drive, ds, val); |
7662d046 BZ |
184 | } |
185 | ||
92f1f8fd | 186 | ide_devset_get(xfer_rate, current_speed); |
8185d5aa | 187 | |
7662d046 BZ |
188 | static int set_xfer_rate (ide_drive_t *drive, int arg) |
189 | { | |
22aa4b32 | 190 | struct ide_cmd cmd; |
7662d046 | 191 | |
3b2a5c71 | 192 | if (arg < XFER_PIO_0 || arg > XFER_UDMA_6) |
7662d046 BZ |
193 | return -EINVAL; |
194 | ||
22aa4b32 BZ |
195 | memset(&cmd, 0, sizeof(cmd)); |
196 | cmd.tf.command = ATA_CMD_SET_FEATURES; | |
197 | cmd.tf.feature = SETFEATURES_XFER; | |
198 | cmd.tf.nsect = (u8)arg; | |
60f85019 SS |
199 | cmd.valid.out.tf = IDE_VALID_FEATURE | IDE_VALID_NSECT; |
200 | cmd.valid.in.tf = IDE_VALID_NSECT; | |
665d66e8 | 201 | cmd.tf_flags = IDE_TFLAG_SET_XFER; |
34f5d5ae | 202 | |
665d66e8 | 203 | return ide_no_data_taskfile(drive, &cmd); |
7662d046 BZ |
204 | } |
205 | ||
92f1f8fd EO |
206 | ide_devset_rw(current_speed, xfer_rate); |
207 | ide_devset_rw_field(init_speed, init_speed); | |
97100fc8 | 208 | ide_devset_rw_flag(nice1, IDE_DFLAG_NICE1); |
92f1f8fd EO |
209 | ide_devset_rw_field(number, dn); |
210 | ||
211 | static const struct ide_proc_devset ide_generic_settings[] = { | |
212 | IDE_PROC_DEVSET(current_speed, 0, 70), | |
213 | IDE_PROC_DEVSET(init_speed, 0, 70), | |
214 | IDE_PROC_DEVSET(io_32bit, 0, 1 + (SUPPORT_VLB_SYNC << 1)), | |
215 | IDE_PROC_DEVSET(keepsettings, 0, 1), | |
216 | IDE_PROC_DEVSET(nice1, 0, 1), | |
217 | IDE_PROC_DEVSET(number, 0, 3), | |
218 | IDE_PROC_DEVSET(pio_mode, 0, 255), | |
219 | IDE_PROC_DEVSET(unmaskirq, 0, 1), | |
220 | IDE_PROC_DEVSET(using_dma, 0, 1), | |
71bfc7a7 | 221 | { NULL }, |
8185d5aa | 222 | }; |
7662d046 | 223 | |
1da177e4 LT |
224 | static void proc_ide_settings_warn(void) |
225 | { | |
01f1afaf | 226 | printk_once(KERN_WARNING "Warning: /proc/ide/hd?/settings interface is " |
1da177e4 | 227 | "obsolete, and will be removed soon!\n"); |
1da177e4 LT |
228 | } |
229 | ||
6d703a81 | 230 | static int ide_settings_proc_show(struct seq_file *m, void *v) |
1da177e4 | 231 | { |
92f1f8fd EO |
232 | const struct ide_proc_devset *setting, *g, *d; |
233 | const struct ide_devset *ds; | |
6d703a81 AD |
234 | ide_drive_t *drive = (ide_drive_t *) m->private; |
235 | int rc, mul_factor, div_factor; | |
1da177e4 LT |
236 | |
237 | proc_ide_settings_warn(); | |
238 | ||
f9383c42 | 239 | mutex_lock(&ide_setting_mtx); |
8185d5aa BZ |
240 | g = ide_generic_settings; |
241 | d = drive->settings; | |
6d703a81 AD |
242 | seq_printf(m, "name\t\t\tvalue\t\tmin\t\tmax\t\tmode\n"); |
243 | seq_printf(m, "----\t\t\t-----\t\t---\t\t---\t\t----\n"); | |
92f1f8fd | 244 | while (g->name || (d && d->name)) { |
8185d5aa | 245 | /* read settings in the alphabetical order */ |
92f1f8fd EO |
246 | if (g->name && d && d->name) { |
247 | if (strcmp(d->name, g->name) < 0) | |
248 | setting = d++; | |
8185d5aa | 249 | else |
92f1f8fd EO |
250 | setting = g++; |
251 | } else if (d && d->name) { | |
252 | setting = d++; | |
8185d5aa | 253 | } else |
92f1f8fd | 254 | setting = g++; |
8185d5aa BZ |
255 | mul_factor = setting->mulf ? setting->mulf(drive) : 1; |
256 | div_factor = setting->divf ? setting->divf(drive) : 1; | |
6d703a81 | 257 | seq_printf(m, "%-24s", setting->name); |
441e92da PC |
258 | rc = ide_read_setting(drive, setting); |
259 | if (rc >= 0) | |
6d703a81 | 260 | seq_printf(m, "%-16d", rc * mul_factor / div_factor); |
1da177e4 | 261 | else |
6d703a81 AD |
262 | seq_printf(m, "%-16s", "write-only"); |
263 | seq_printf(m, "%-16d%-16d", (setting->min * mul_factor + div_factor - 1) / div_factor, setting->max * mul_factor / div_factor); | |
92f1f8fd EO |
264 | ds = setting->setting; |
265 | if (ds->get) | |
6d703a81 | 266 | seq_printf(m, "r"); |
92f1f8fd | 267 | if (ds->set) |
6d703a81 AD |
268 | seq_printf(m, "w"); |
269 | seq_printf(m, "\n"); | |
1da177e4 | 270 | } |
f9383c42 | 271 | mutex_unlock(&ide_setting_mtx); |
6d703a81 AD |
272 | return 0; |
273 | } | |
274 | ||
275 | static int ide_settings_proc_open(struct inode *inode, struct file *file) | |
276 | { | |
d9dda78b | 277 | return single_open(file, ide_settings_proc_show, PDE_DATA(inode)); |
1da177e4 LT |
278 | } |
279 | ||
280 | #define MAX_LEN 30 | |
281 | ||
6d703a81 AD |
282 | static ssize_t ide_settings_proc_write(struct file *file, const char __user *buffer, |
283 | size_t count, loff_t *pos) | |
1da177e4 | 284 | { |
d9dda78b | 285 | ide_drive_t *drive = PDE_DATA(file_inode(file)); |
1da177e4 | 286 | char name[MAX_LEN + 1]; |
8185d5aa | 287 | int for_real = 0, mul_factor, div_factor; |
1da177e4 | 288 | unsigned long n; |
8185d5aa | 289 | |
92f1f8fd | 290 | const struct ide_proc_devset *setting; |
1da177e4 LT |
291 | char *buf, *s; |
292 | ||
293 | if (!capable(CAP_SYS_ADMIN)) | |
294 | return -EACCES; | |
295 | ||
296 | proc_ide_settings_warn(); | |
297 | ||
298 | if (count >= PAGE_SIZE) | |
299 | return -EINVAL; | |
300 | ||
301 | s = buf = (char *)__get_free_page(GFP_USER); | |
302 | if (!buf) | |
303 | return -ENOMEM; | |
304 | ||
305 | if (copy_from_user(buf, buffer, count)) { | |
306 | free_page((unsigned long)buf); | |
307 | return -EFAULT; | |
308 | } | |
309 | ||
310 | buf[count] = '\0'; | |
311 | ||
312 | /* | |
313 | * Skip over leading whitespace | |
314 | */ | |
315 | while (count && isspace(*s)) { | |
316 | --count; | |
317 | ++s; | |
318 | } | |
319 | /* | |
320 | * Do one full pass to verify all parameters, | |
321 | * then do another to actually write the new settings. | |
322 | */ | |
323 | do { | |
324 | char *p = s; | |
325 | n = count; | |
326 | while (n > 0) { | |
327 | unsigned val; | |
328 | char *q = p; | |
329 | ||
330 | while (n > 0 && *p != ':') { | |
331 | --n; | |
332 | p++; | |
333 | } | |
334 | if (*p != ':') | |
335 | goto parse_error; | |
336 | if (p - q > MAX_LEN) | |
337 | goto parse_error; | |
338 | memcpy(name, q, p - q); | |
339 | name[p - q] = 0; | |
340 | ||
341 | if (n > 0) { | |
342 | --n; | |
343 | p++; | |
344 | } else | |
345 | goto parse_error; | |
346 | ||
347 | val = simple_strtoul(p, &q, 10); | |
348 | n -= q - p; | |
349 | p = q; | |
350 | if (n > 0 && !isspace(*p)) | |
351 | goto parse_error; | |
352 | while (n > 0 && isspace(*p)) { | |
353 | --n; | |
354 | ++p; | |
355 | } | |
356 | ||
f9383c42 | 357 | mutex_lock(&ide_setting_mtx); |
8185d5aa BZ |
358 | /* generic settings first, then driver specific ones */ |
359 | setting = ide_find_setting(ide_generic_settings, name); | |
441e92da | 360 | if (!setting) { |
8185d5aa BZ |
361 | if (drive->settings) |
362 | setting = ide_find_setting(drive->settings, name); | |
363 | if (!setting) { | |
364 | mutex_unlock(&ide_setting_mtx); | |
365 | goto parse_error; | |
366 | } | |
367 | } | |
368 | if (for_real) { | |
369 | mul_factor = setting->mulf ? setting->mulf(drive) : 1; | |
370 | div_factor = setting->divf ? setting->divf(drive) : 1; | |
371 | ide_write_setting(drive, setting, val * div_factor / mul_factor); | |
1da177e4 | 372 | } |
f9383c42 | 373 | mutex_unlock(&ide_setting_mtx); |
1da177e4 LT |
374 | } |
375 | } while (!for_real++); | |
376 | free_page((unsigned long)buf); | |
377 | return count; | |
378 | parse_error: | |
379 | free_page((unsigned long)buf); | |
6d703a81 | 380 | printk("%s(): parse error\n", __func__); |
1da177e4 LT |
381 | return -EINVAL; |
382 | } | |
383 | ||
6d703a81 AD |
384 | static const struct file_operations ide_settings_proc_fops = { |
385 | .owner = THIS_MODULE, | |
386 | .open = ide_settings_proc_open, | |
387 | .read = seq_read, | |
388 | .llseek = seq_lseek, | |
389 | .release = single_release, | |
390 | .write = ide_settings_proc_write, | |
391 | }; | |
392 | ||
ec7d9c9c | 393 | int ide_capacity_proc_show(struct seq_file *m, void *v) |
1da177e4 | 394 | { |
6d703a81 AD |
395 | seq_printf(m, "%llu\n", (long long)0x7fffffff); |
396 | return 0; | |
1da177e4 | 397 | } |
ec7d9c9c | 398 | EXPORT_SYMBOL_GPL(ide_capacity_proc_show); |
1da177e4 | 399 | |
ec7d9c9c | 400 | int ide_geometry_proc_show(struct seq_file *m, void *v) |
1da177e4 | 401 | { |
6d703a81 | 402 | ide_drive_t *drive = (ide_drive_t *) m->private; |
1da177e4 | 403 | |
6d703a81 | 404 | seq_printf(m, "physical %d/%d/%d\n", |
1da177e4 | 405 | drive->cyl, drive->head, drive->sect); |
6d703a81 | 406 | seq_printf(m, "logical %d/%d/%d\n", |
1da177e4 | 407 | drive->bios_cyl, drive->bios_head, drive->bios_sect); |
6d703a81 AD |
408 | return 0; |
409 | } | |
ec7d9c9c | 410 | EXPORT_SYMBOL(ide_geometry_proc_show); |
1da177e4 | 411 | |
6d703a81 | 412 | static int ide_dmodel_proc_show(struct seq_file *seq, void *v) |
1da177e4 | 413 | { |
6d703a81 | 414 | ide_drive_t *drive = (ide_drive_t *) seq->private; |
4dde4492 | 415 | char *m = (char *)&drive->id[ATA_ID_PROD]; |
1da177e4 | 416 | |
6d703a81 AD |
417 | seq_printf(seq, "%.40s\n", m[0] ? m : "(none)"); |
418 | return 0; | |
1da177e4 LT |
419 | } |
420 | ||
6d703a81 AD |
421 | static int ide_driver_proc_show(struct seq_file *m, void *v) |
422 | { | |
423 | ide_drive_t *drive = (ide_drive_t *)m->private; | |
7f3c868b BZ |
424 | struct device *dev = &drive->gendev; |
425 | struct ide_driver *ide_drv; | |
1da177e4 | 426 | |
8604affd | 427 | if (dev->driver) { |
7f3c868b | 428 | ide_drv = to_ide_driver(dev->driver); |
6d703a81 | 429 | seq_printf(m, "%s version %s\n", |
8604affd | 430 | dev->driver->name, ide_drv->version); |
1da177e4 | 431 | } else |
6d703a81 AD |
432 | seq_printf(m, "ide-default version 0.9.newide\n"); |
433 | return 0; | |
434 | } | |
435 | ||
6d703a81 | 436 | static int ide_media_proc_show(struct seq_file *m, void *v) |
1da177e4 | 437 | { |
6d703a81 | 438 | ide_drive_t *drive = (ide_drive_t *) m->private; |
1da177e4 | 439 | const char *media; |
1da177e4 LT |
440 | |
441 | switch (drive->media) { | |
441e92da PC |
442 | case ide_disk: media = "disk\n"; break; |
443 | case ide_cdrom: media = "cdrom\n"; break; | |
444 | case ide_tape: media = "tape\n"; break; | |
445 | case ide_floppy: media = "floppy\n"; break; | |
446 | case ide_optical: media = "optical\n"; break; | |
447 | default: media = "UNKNOWN\n"; break; | |
1da177e4 | 448 | } |
6d703a81 AD |
449 | seq_puts(m, media); |
450 | return 0; | |
451 | } | |
452 | ||
453 | static int ide_media_proc_open(struct inode *inode, struct file *file) | |
454 | { | |
d9dda78b | 455 | return single_open(file, ide_media_proc_show, PDE_DATA(inode)); |
1da177e4 LT |
456 | } |
457 | ||
6d703a81 AD |
458 | static const struct file_operations ide_media_proc_fops = { |
459 | .owner = THIS_MODULE, | |
460 | .open = ide_media_proc_open, | |
461 | .read = seq_read, | |
462 | .llseek = seq_lseek, | |
463 | .release = single_release, | |
464 | }; | |
465 | ||
1da177e4 | 466 | static ide_proc_entry_t generic_drive_entries[] = { |
ec7d9c9c CH |
467 | { "driver", S_IFREG|S_IRUGO, ide_driver_proc_show }, |
468 | { "identify", S_IFREG|S_IRUSR, ide_identify_proc_show }, | |
469 | { "media", S_IFREG|S_IRUGO, ide_media_proc_show }, | |
470 | { "model", S_IFREG|S_IRUGO, ide_dmodel_proc_show }, | |
6d703a81 | 471 | {} |
1da177e4 LT |
472 | }; |
473 | ||
7662d046 | 474 | static void ide_add_proc_entries(struct proc_dir_entry *dir, ide_proc_entry_t *p, void *data) |
1da177e4 LT |
475 | { |
476 | struct proc_dir_entry *ent; | |
477 | ||
478 | if (!dir || !p) | |
479 | return; | |
480 | while (p->name != NULL) { | |
ec7d9c9c | 481 | ent = proc_create_single_data(p->name, p->mode, dir, p->show, data); |
1da177e4 | 482 | if (!ent) return; |
1da177e4 LT |
483 | p++; |
484 | } | |
485 | } | |
486 | ||
7662d046 | 487 | static void ide_remove_proc_entries(struct proc_dir_entry *dir, ide_proc_entry_t *p) |
1da177e4 LT |
488 | { |
489 | if (!dir || !p) | |
490 | return; | |
491 | while (p->name != NULL) { | |
492 | remove_proc_entry(p->name, dir); | |
493 | p++; | |
494 | } | |
495 | } | |
496 | ||
7f3c868b | 497 | void ide_proc_register_driver(ide_drive_t *drive, struct ide_driver *driver) |
7662d046 | 498 | { |
8185d5aa | 499 | mutex_lock(&ide_setting_mtx); |
79cb3803 | 500 | drive->settings = driver->proc_devsets(drive); |
8185d5aa BZ |
501 | mutex_unlock(&ide_setting_mtx); |
502 | ||
79cb3803 | 503 | ide_add_proc_entries(drive->proc, driver->proc_entries(drive), drive); |
7662d046 BZ |
504 | } |
505 | ||
506 | EXPORT_SYMBOL(ide_proc_register_driver); | |
507 | ||
508 | /** | |
509 | * ide_proc_unregister_driver - remove driver specific data | |
510 | * @drive: drive | |
511 | * @driver: driver | |
512 | * | |
513 | * Clean up the driver specific /proc files and IDE settings | |
514 | * for a given drive. | |
515 | * | |
1f473e9c | 516 | * Takes ide_setting_mtx. |
7662d046 BZ |
517 | */ |
518 | ||
7f3c868b | 519 | void ide_proc_unregister_driver(ide_drive_t *drive, struct ide_driver *driver) |
7662d046 | 520 | { |
79cb3803 | 521 | ide_remove_proc_entries(drive->proc, driver->proc_entries(drive)); |
7662d046 | 522 | |
f9383c42 | 523 | mutex_lock(&ide_setting_mtx); |
7662d046 | 524 | /* |
1f473e9c BZ |
525 | * ide_setting_mtx protects both the settings list and the use |
526 | * of settings (we cannot take a setting out that is being used). | |
7662d046 | 527 | */ |
8185d5aa | 528 | drive->settings = NULL; |
f9383c42 | 529 | mutex_unlock(&ide_setting_mtx); |
7662d046 | 530 | } |
7662d046 BZ |
531 | EXPORT_SYMBOL(ide_proc_unregister_driver); |
532 | ||
d9270a3f | 533 | void ide_proc_port_register_devices(ide_hwif_t *hwif) |
1da177e4 | 534 | { |
1da177e4 LT |
535 | struct proc_dir_entry *ent; |
536 | struct proc_dir_entry *parent = hwif->proc; | |
2bd24a1c | 537 | ide_drive_t *drive; |
1da177e4 | 538 | char name[64]; |
2bd24a1c | 539 | int i; |
1da177e4 | 540 | |
2bd24a1c | 541 | ide_port_for_each_dev(i, drive, hwif) { |
1902a253 | 542 | if ((drive->dev_flags & IDE_DFLAG_PRESENT) == 0) |
1da177e4 LT |
543 | continue; |
544 | ||
545 | drive->proc = proc_mkdir(drive->name, parent); | |
ec7d9c9c | 546 | if (drive->proc) { |
1da177e4 | 547 | ide_add_proc_entries(drive->proc, generic_drive_entries, drive); |
f8ff6c73 | 548 | proc_create_data("settings", S_IFREG|S_IRUSR|S_IWUSR, |
ec7d9c9c CH |
549 | drive->proc, &ide_settings_proc_fops, |
550 | drive); | |
551 | } | |
441e92da | 552 | sprintf(name, "ide%d/%s", (drive->name[2]-'a')/2, drive->name); |
1da177e4 LT |
553 | ent = proc_symlink(drive->name, proc_ide_root, name); |
554 | if (!ent) return; | |
555 | } | |
556 | } | |
557 | ||
5b0c4b30 | 558 | void ide_proc_unregister_device(ide_drive_t *drive) |
1da177e4 LT |
559 | { |
560 | if (drive->proc) { | |
ec7d9c9c | 561 | remove_proc_entry("settings", drive->proc); |
1da177e4 LT |
562 | ide_remove_proc_entries(drive->proc, generic_drive_entries); |
563 | remove_proc_entry(drive->name, proc_ide_root); | |
5b0c4b30 | 564 | remove_proc_entry(drive->name, drive->hwif->proc); |
1da177e4 LT |
565 | drive->proc = NULL; |
566 | } | |
567 | } | |
568 | ||
1da177e4 | 569 | static ide_proc_entry_t hwif_entries[] = { |
ec7d9c9c CH |
570 | { "channel", S_IFREG|S_IRUGO, ide_channel_proc_show }, |
571 | { "mate", S_IFREG|S_IRUGO, ide_mate_proc_show }, | |
572 | { "model", S_IFREG|S_IRUGO, ide_imodel_proc_show }, | |
6d703a81 | 573 | {} |
1da177e4 LT |
574 | }; |
575 | ||
5cbf79cd | 576 | void ide_proc_register_port(ide_hwif_t *hwif) |
1da177e4 | 577 | { |
5cbf79cd BZ |
578 | if (!hwif->proc) { |
579 | hwif->proc = proc_mkdir(hwif->name, proc_ide_root); | |
1da177e4 | 580 | |
5cbf79cd BZ |
581 | if (!hwif->proc) |
582 | return; | |
583 | ||
584 | ide_add_proc_entries(hwif->proc, hwif_entries, hwif); | |
1da177e4 LT |
585 | } |
586 | } | |
587 | ||
5cbf79cd | 588 | void ide_proc_unregister_port(ide_hwif_t *hwif) |
1da177e4 LT |
589 | { |
590 | if (hwif->proc) { | |
1da177e4 LT |
591 | ide_remove_proc_entries(hwif->proc, hwif_entries); |
592 | remove_proc_entry(hwif->name, proc_ide_root); | |
593 | hwif->proc = NULL; | |
594 | } | |
595 | } | |
596 | ||
8604affd BZ |
597 | static int proc_print_driver(struct device_driver *drv, void *data) |
598 | { | |
7f3c868b | 599 | struct ide_driver *ide_drv = to_ide_driver(drv); |
8604affd BZ |
600 | struct seq_file *s = data; |
601 | ||
602 | seq_printf(s, "%s version %s\n", drv->name, ide_drv->version); | |
603 | ||
604 | return 0; | |
605 | } | |
606 | ||
607 | static int ide_drivers_show(struct seq_file *s, void *p) | |
608 | { | |
349ae23f RD |
609 | int err; |
610 | ||
611 | err = bus_for_each_drv(&ide_bus_type, NULL, s, proc_print_driver); | |
612 | if (err < 0) | |
613 | printk(KERN_WARNING "IDE: %s: bus_for_each_drv error: %d\n", | |
eb63963a | 614 | __func__, err); |
8604affd BZ |
615 | return 0; |
616 | } | |
617 | ||
94d0fb15 | 618 | DEFINE_SHOW_ATTRIBUTE(ide_drivers); |
1da177e4 LT |
619 | |
620 | void proc_ide_create(void) | |
621 | { | |
5cbf79cd BZ |
622 | proc_ide_root = proc_mkdir("ide", NULL); |
623 | ||
1da177e4 LT |
624 | if (!proc_ide_root) |
625 | return; | |
626 | ||
94d0fb15 | 627 | proc_create("drivers", 0, proc_ide_root, &ide_drivers_fops); |
1da177e4 LT |
628 | } |
629 | ||
630 | void proc_ide_destroy(void) | |
631 | { | |
643bdc6f | 632 | remove_proc_entry("drivers", proc_ide_root); |
1da177e4 LT |
633 | remove_proc_entry("ide", NULL); |
634 | } |