2 * linux/drivers/ide/ide-proc.c Version 1.05 Mar 05, 2003
4 * Copyright (C) 1997-1998 Mark Lord
5 * Copyright (C) 2003 Red Hat <alan@redhat.com>
9 * This is the /proc/ide/ filesystem implementation.
11 * Drive/Driver settings can be retrieved by reading the drive's
12 * "settings" files. e.g. "cat /proc/ide0/hda/settings"
13 * To write a new value "val" into a specific setting "name", use:
14 * echo "name:val" >/proc/ide/ide0/hda/settings
16 * Also useful, "cat /proc/ide0/hda/[identify, smart_values,
17 * smart_thresholds, capabilities]" will issue an IDENTIFY /
18 * PACKET_IDENTIFY / SMART_READ_VALUES / SMART_READ_THRESHOLDS /
19 * SENSE CAPABILITIES command to /dev/hda, and then dump out the
20 * returned data as 256 16-bit words. The "hdparm" utility will
21 * be updated someday soon to use this mechanism.
25 #include <linux/module.h>
27 #include <asm/uaccess.h>
28 #include <linux/errno.h>
29 #include <linux/proc_fs.h>
30 #include <linux/stat.h>
32 #include <linux/pci.h>
33 #include <linux/ctype.h>
34 #include <linux/hdreg.h>
35 #include <linux/ide.h>
36 #include <linux/seq_file.h>
40 static int proc_ide_read_imodel
41 (char *page
, char **start
, off_t off
, int count
, int *eof
, void *data
)
43 ide_hwif_t
*hwif
= (ide_hwif_t
*) data
;
48 * Neither ide_unknown nor ide_forced should be set at this point.
50 switch (hwif
->chipset
) {
51 case ide_generic
: name
= "generic"; break;
52 case ide_pci
: name
= "pci"; break;
53 case ide_cmd640
: name
= "cmd640"; break;
54 case ide_dtc2278
: name
= "dtc2278"; break;
55 case ide_ali14xx
: name
= "ali14xx"; break;
56 case ide_qd65xx
: name
= "qd65xx"; break;
57 case ide_umc8672
: name
= "umc8672"; break;
58 case ide_ht6560b
: name
= "ht6560b"; break;
59 case ide_rz1000
: name
= "rz1000"; break;
60 case ide_trm290
: name
= "trm290"; break;
61 case ide_cmd646
: name
= "cmd646"; break;
62 case ide_cy82c693
: name
= "cy82c693"; break;
63 case ide_4drives
: name
= "4drives"; break;
64 case ide_pmac
: name
= "mac-io"; break;
65 case ide_au1xxx
: name
= "au1xxx"; break;
66 default: name
= "(unknown)"; break;
68 len
= sprintf(page
, "%s\n", name
);
69 PROC_IDE_READ_RETURN(page
,start
,off
,count
,eof
,len
);
72 static int proc_ide_read_mate
73 (char *page
, char **start
, off_t off
, int count
, int *eof
, void *data
)
75 ide_hwif_t
*hwif
= (ide_hwif_t
*) data
;
78 if (hwif
&& hwif
->mate
&& hwif
->mate
->present
)
79 len
= sprintf(page
, "%s\n", hwif
->mate
->name
);
81 len
= sprintf(page
, "(none)\n");
82 PROC_IDE_READ_RETURN(page
,start
,off
,count
,eof
,len
);
85 static int proc_ide_read_channel
86 (char *page
, char **start
, off_t off
, int count
, int *eof
, void *data
)
88 ide_hwif_t
*hwif
= (ide_hwif_t
*) data
;
91 page
[0] = hwif
->channel
? '1' : '0';
94 PROC_IDE_READ_RETURN(page
,start
,off
,count
,eof
,len
);
97 static int proc_ide_read_identify
98 (char *page
, char **start
, off_t off
, int count
, int *eof
, void *data
)
100 ide_drive_t
*drive
= (ide_drive_t
*)data
;
104 len
= sprintf(page
, "\n");
107 unsigned short *val
= (unsigned short *) page
;
109 err
= taskfile_lib_get_identify(drive
, page
);
111 char *out
= ((char *)page
) + (SECTOR_WORDS
* 4);
114 out
+= sprintf(out
, "%04x%c",
115 le16_to_cpu(*val
), (++i
& 7) ? ' ' : '\n');
117 } while (i
< (SECTOR_WORDS
* 2));
121 PROC_IDE_READ_RETURN(page
,start
,off
,count
,eof
,len
);
124 static void proc_ide_settings_warn(void)
126 static int warned
= 0;
131 printk(KERN_WARNING
"Warning: /proc/ide/hd?/settings interface is "
132 "obsolete, and will be removed soon!\n");
136 static int proc_ide_read_settings
137 (char *page
, char **start
, off_t off
, int count
, int *eof
, void *data
)
139 ide_drive_t
*drive
= (ide_drive_t
*) data
;
140 ide_settings_t
*setting
= (ide_settings_t
*) drive
->settings
;
142 int len
, rc
, mul_factor
, div_factor
;
144 proc_ide_settings_warn();
146 down(&ide_setting_sem
);
147 out
+= sprintf(out
, "name\t\t\tvalue\t\tmin\t\tmax\t\tmode\n");
148 out
+= sprintf(out
, "----\t\t\t-----\t\t---\t\t---\t\t----\n");
150 mul_factor
= setting
->mul_factor
;
151 div_factor
= setting
->div_factor
;
152 out
+= sprintf(out
, "%-24s", setting
->name
);
153 if ((rc
= ide_read_setting(drive
, setting
)) >= 0)
154 out
+= sprintf(out
, "%-16d", rc
* mul_factor
/ div_factor
);
156 out
+= sprintf(out
, "%-16s", "write-only");
157 out
+= sprintf(out
, "%-16d%-16d", (setting
->min
* mul_factor
+ div_factor
- 1) / div_factor
, setting
->max
* mul_factor
/ div_factor
);
158 if (setting
->rw
& SETTING_READ
)
159 out
+= sprintf(out
, "r");
160 if (setting
->rw
& SETTING_WRITE
)
161 out
+= sprintf(out
, "w");
162 out
+= sprintf(out
, "\n");
163 setting
= setting
->next
;
166 up(&ide_setting_sem
);
167 PROC_IDE_READ_RETURN(page
,start
,off
,count
,eof
,len
);
172 static int proc_ide_write_settings(struct file
*file
, const char __user
*buffer
,
173 unsigned long count
, void *data
)
175 ide_drive_t
*drive
= (ide_drive_t
*) data
;
176 char name
[MAX_LEN
+ 1];
179 ide_settings_t
*setting
;
182 if (!capable(CAP_SYS_ADMIN
))
185 proc_ide_settings_warn();
187 if (count
>= PAGE_SIZE
)
190 s
= buf
= (char *)__get_free_page(GFP_USER
);
194 if (copy_from_user(buf
, buffer
, count
)) {
195 free_page((unsigned long)buf
);
202 * Skip over leading whitespace
204 while (count
&& isspace(*s
)) {
209 * Do one full pass to verify all parameters,
210 * then do another to actually write the new settings.
219 while (n
> 0 && *p
!= ':') {
227 memcpy(name
, q
, p
- q
);
236 val
= simple_strtoul(p
, &q
, 10);
239 if (n
> 0 && !isspace(*p
))
241 while (n
> 0 && isspace(*p
)) {
246 down(&ide_setting_sem
);
247 setting
= ide_find_setting_by_name(drive
, name
);
250 up(&ide_setting_sem
);
254 ide_write_setting(drive
, setting
, val
* setting
->div_factor
/ setting
->mul_factor
);
255 up(&ide_setting_sem
);
257 } while (!for_real
++);
258 free_page((unsigned long)buf
);
261 free_page((unsigned long)buf
);
262 printk("proc_ide_write_settings(): parse error\n");
266 int proc_ide_read_capacity
267 (char *page
, char **start
, off_t off
, int count
, int *eof
, void *data
)
269 int len
= sprintf(page
,"%llu\n", (long long)0x7fffffff);
270 PROC_IDE_READ_RETURN(page
,start
,off
,count
,eof
,len
);
273 EXPORT_SYMBOL_GPL(proc_ide_read_capacity
);
275 int proc_ide_read_geometry
276 (char *page
, char **start
, off_t off
, int count
, int *eof
, void *data
)
278 ide_drive_t
*drive
= (ide_drive_t
*) data
;
282 out
+= sprintf(out
,"physical %d/%d/%d\n",
283 drive
->cyl
, drive
->head
, drive
->sect
);
284 out
+= sprintf(out
,"logical %d/%d/%d\n",
285 drive
->bios_cyl
, drive
->bios_head
, drive
->bios_sect
);
288 PROC_IDE_READ_RETURN(page
,start
,off
,count
,eof
,len
);
291 EXPORT_SYMBOL(proc_ide_read_geometry
);
293 static int proc_ide_read_dmodel
294 (char *page
, char **start
, off_t off
, int count
, int *eof
, void *data
)
296 ide_drive_t
*drive
= (ide_drive_t
*) data
;
297 struct hd_driveid
*id
= drive
->id
;
300 len
= sprintf(page
, "%.40s\n",
301 (id
&& id
->model
[0]) ? (char *)id
->model
: "(none)");
302 PROC_IDE_READ_RETURN(page
,start
,off
,count
,eof
,len
);
305 static int proc_ide_read_driver
306 (char *page
, char **start
, off_t off
, int count
, int *eof
, void *data
)
308 ide_drive_t
*drive
= (ide_drive_t
*) data
;
309 struct device
*dev
= &drive
->gendev
;
310 ide_driver_t
*ide_drv
;
313 down_read(&dev
->bus
->subsys
.rwsem
);
315 ide_drv
= container_of(dev
->driver
, ide_driver_t
, gen_driver
);
316 len
= sprintf(page
, "%s version %s\n",
317 dev
->driver
->name
, ide_drv
->version
);
319 len
= sprintf(page
, "ide-default version 0.9.newide\n");
320 up_read(&dev
->bus
->subsys
.rwsem
);
321 PROC_IDE_READ_RETURN(page
,start
,off
,count
,eof
,len
);
324 static int ide_replace_subdriver(ide_drive_t
*drive
, const char *driver
)
326 struct device
*dev
= &drive
->gendev
;
330 down_write(&dev
->bus
->subsys
.rwsem
);
331 device_release_driver(dev
);
332 /* FIXME: device can still be in use by previous driver */
333 strlcpy(drive
->driver_req
, driver
, sizeof(drive
->driver_req
));
334 err
= device_attach(dev
);
336 printk(KERN_WARNING
"IDE: %s: device_attach error: %d\n",
338 drive
->driver_req
[0] = 0;
339 if (dev
->driver
== NULL
) {
340 err
= device_attach(dev
);
343 "IDE: %s: device_attach(2) error: %d\n",
346 if (dev
->driver
&& !strcmp(dev
->driver
->name
, driver
))
348 up_write(&dev
->bus
->subsys
.rwsem
);
353 static int proc_ide_write_driver
354 (struct file
*file
, const char __user
*buffer
, unsigned long count
, void *data
)
356 ide_drive_t
*drive
= (ide_drive_t
*) data
;
359 if (!capable(CAP_SYS_ADMIN
))
363 if (copy_from_user(name
, buffer
, count
))
366 if (ide_replace_subdriver(drive
, name
))
371 static int proc_ide_read_media
372 (char *page
, char **start
, off_t off
, int count
, int *eof
, void *data
)
374 ide_drive_t
*drive
= (ide_drive_t
*) data
;
378 switch (drive
->media
) {
379 case ide_disk
: media
= "disk\n";
381 case ide_cdrom
: media
= "cdrom\n";
383 case ide_tape
: media
= "tape\n";
385 case ide_floppy
:media
= "floppy\n";
387 case ide_optical
:media
= "optical\n";
389 default: media
= "UNKNOWN\n";
394 PROC_IDE_READ_RETURN(page
,start
,off
,count
,eof
,len
);
397 static ide_proc_entry_t generic_drive_entries
[] = {
398 { "driver", S_IFREG
|S_IRUGO
, proc_ide_read_driver
, proc_ide_write_driver
},
399 { "identify", S_IFREG
|S_IRUSR
, proc_ide_read_identify
, NULL
},
400 { "media", S_IFREG
|S_IRUGO
, proc_ide_read_media
, NULL
},
401 { "model", S_IFREG
|S_IRUGO
, proc_ide_read_dmodel
, NULL
},
402 { "settings", S_IFREG
|S_IRUSR
|S_IWUSR
,proc_ide_read_settings
, proc_ide_write_settings
},
403 { NULL
, 0, NULL
, NULL
}
406 void ide_add_proc_entries(struct proc_dir_entry
*dir
, ide_proc_entry_t
*p
, void *data
)
408 struct proc_dir_entry
*ent
;
412 while (p
->name
!= NULL
) {
413 ent
= create_proc_entry(p
->name
, p
->mode
, dir
);
416 ent
->read_proc
= p
->read_proc
;
417 ent
->write_proc
= p
->write_proc
;
422 void ide_remove_proc_entries(struct proc_dir_entry
*dir
, ide_proc_entry_t
*p
)
426 while (p
->name
!= NULL
) {
427 remove_proc_entry(p
->name
, dir
);
432 static void create_proc_ide_drives(ide_hwif_t
*hwif
)
435 struct proc_dir_entry
*ent
;
436 struct proc_dir_entry
*parent
= hwif
->proc
;
439 for (d
= 0; d
< MAX_DRIVES
; d
++) {
440 ide_drive_t
*drive
= &hwif
->drives
[d
];
447 drive
->proc
= proc_mkdir(drive
->name
, parent
);
449 ide_add_proc_entries(drive
->proc
, generic_drive_entries
, drive
);
450 sprintf(name
,"ide%d/%s", (drive
->name
[2]-'a')/2, drive
->name
);
451 ent
= proc_symlink(drive
->name
, proc_ide_root
, name
);
456 static void destroy_proc_ide_device(ide_hwif_t
*hwif
, ide_drive_t
*drive
)
459 ide_remove_proc_entries(drive
->proc
, generic_drive_entries
);
460 remove_proc_entry(drive
->name
, proc_ide_root
);
461 remove_proc_entry(drive
->name
, hwif
->proc
);
466 static void destroy_proc_ide_drives(ide_hwif_t
*hwif
)
470 for (d
= 0; d
< MAX_DRIVES
; d
++) {
471 ide_drive_t
*drive
= &hwif
->drives
[d
];
473 destroy_proc_ide_device(hwif
, drive
);
477 static ide_proc_entry_t hwif_entries
[] = {
478 { "channel", S_IFREG
|S_IRUGO
, proc_ide_read_channel
, NULL
},
479 { "mate", S_IFREG
|S_IRUGO
, proc_ide_read_mate
, NULL
},
480 { "model", S_IFREG
|S_IRUGO
, proc_ide_read_imodel
, NULL
},
481 { NULL
, 0, NULL
, NULL
}
484 void create_proc_ide_interfaces(void)
488 for (h
= 0; h
< MAX_HWIFS
; h
++) {
489 ide_hwif_t
*hwif
= &ide_hwifs
[h
];
494 hwif
->proc
= proc_mkdir(hwif
->name
, proc_ide_root
);
497 ide_add_proc_entries(hwif
->proc
, hwif_entries
, hwif
);
499 create_proc_ide_drives(hwif
);
503 EXPORT_SYMBOL(create_proc_ide_interfaces
);
505 #ifdef CONFIG_BLK_DEV_IDEPCI
506 void ide_pci_create_host_proc(const char *name
, get_info_t
*get_info
)
508 create_proc_info_entry(name
, 0, proc_ide_root
, get_info
);
511 EXPORT_SYMBOL_GPL(ide_pci_create_host_proc
);
514 void destroy_proc_ide_interface(ide_hwif_t
*hwif
)
517 destroy_proc_ide_drives(hwif
);
518 ide_remove_proc_entries(hwif
->proc
, hwif_entries
);
519 remove_proc_entry(hwif
->name
, proc_ide_root
);
524 static int proc_print_driver(struct device_driver
*drv
, void *data
)
526 ide_driver_t
*ide_drv
= container_of(drv
, ide_driver_t
, gen_driver
);
527 struct seq_file
*s
= data
;
529 seq_printf(s
, "%s version %s\n", drv
->name
, ide_drv
->version
);
534 static int ide_drivers_show(struct seq_file
*s
, void *p
)
538 err
= bus_for_each_drv(&ide_bus_type
, NULL
, s
, proc_print_driver
);
540 printk(KERN_WARNING
"IDE: %s: bus_for_each_drv error: %d\n",
545 static int ide_drivers_open(struct inode
*inode
, struct file
*file
)
547 return single_open(file
, &ide_drivers_show
, NULL
);
550 static const struct file_operations ide_drivers_operations
= {
551 .open
= ide_drivers_open
,
554 .release
= single_release
,
557 void proc_ide_create(void)
559 struct proc_dir_entry
*entry
;
564 create_proc_ide_interfaces();
566 entry
= create_proc_entry("drivers", 0, proc_ide_root
);
568 entry
->proc_fops
= &ide_drivers_operations
;
571 void proc_ide_destroy(void)
573 remove_proc_entry("drivers", proc_ide_root
);
574 remove_proc_entry("ide", NULL
);