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/config.h>
26 #include <linux/module.h>
28 #include <asm/uaccess.h>
29 #include <linux/errno.h>
30 #include <linux/sched.h>
31 #include <linux/proc_fs.h>
32 #include <linux/stat.h>
34 #include <linux/pci.h>
35 #include <linux/ctype.h>
36 #include <linux/hdreg.h>
37 #include <linux/ide.h>
38 #include <linux/seq_file.h>
42 static int proc_ide_read_imodel
43 (char *page, char **start, off_t off, int count, int *eof, void *data)
47 const char *name = "";
50 hwif = ide_hwif_from_key(data);
53 * Neither ide_unknown nor ide_forced should be set at this point.
55 switch (hwif->chipset) {
56 case ide_generic: name = "generic"; break;
57 case ide_pci: name = "pci"; break;
58 case ide_cmd640: name = "cmd640"; break;
59 case ide_dtc2278: name = "dtc2278"; break;
60 case ide_ali14xx: name = "ali14xx"; break;
61 case ide_qd65xx: name = "qd65xx"; break;
62 case ide_umc8672: name = "umc8672"; break;
63 case ide_ht6560b: name = "ht6560b"; break;
64 case ide_rz1000: name = "rz1000"; break;
65 case ide_trm290: name = "trm290"; break;
66 case ide_cmd646: name = "cmd646"; break;
67 case ide_cy82c693: name = "cy82c693"; break;
68 case ide_4drives: name = "4drives"; break;
69 case ide_pmac: name = "mac-io"; break;
70 default: name = "(unknown)"; break;
73 len = sprintf(page, "%s\n", name);
75 PROC_IDE_READ_RETURN(page,start,off,count,eof,len);
78 static int proc_ide_read_mate
79 (char *page, char **start, off_t off, int count, int *eof, void *data)
85 hwif = ide_hwif_from_key(data);
86 if (hwif && hwif->mate && hwif->mate->present)
87 len = sprintf(page, "%s\n", hwif->mate->name);
89 len = sprintf(page, "(none)\n");
91 PROC_IDE_READ_RETURN(page,start,off,count,eof,len);
94 static int proc_ide_read_channel
95 (char *page, char **start, off_t off, int count, int *eof, void *data)
101 hwif = ide_hwif_from_key(data);
103 page[0] = hwif->channel ? '1' : '0';
110 PROC_IDE_READ_RETURN(page,start,off,count,eof,len);
113 static int proc_ide_read_identify
114 (char *page, char **start, off_t off, int count, int *eof, void *data)
120 len = sprintf(page, "\n");
123 drive = ide_drive_from_key(data);
126 unsigned short *val = (unsigned short *) page;
128 BUG_ON(!drive->driver);
130 err = taskfile_lib_get_identify(drive, page);
132 char *out = ((char *)page) + (SECTOR_WORDS * 4);
135 out += sprintf(out, "%04x%c",
136 le16_to_cpu(*val), (++i & 7) ? ' ' : '\n');
138 } while (i < (SECTOR_WORDS * 2));
143 PROC_IDE_READ_RETURN(page,start,off,count,eof,len);
146 static void proc_ide_settings_warn(void)
148 static int warned = 0;
153 printk(KERN_WARNING "Warning: /proc/ide/hd?/settings interface is "
154 "obsolete, and will be removed soon!\n");
158 static int proc_ide_read_settings
159 (char *page, char **start, off_t off, int count, int *eof, void *data)
162 ide_settings_t *setting;
164 int len, rc, mul_factor, div_factor;
166 proc_ide_settings_warn();
169 drive = ide_drive_from_key(data);
176 setting = (ide_settings_t *) drive->settings;
177 down(&ide_setting_sem);
178 out += sprintf(out, "name\t\t\tvalue\t\tmin\t\tmax\t\tmode\n");
179 out += sprintf(out, "----\t\t\t-----\t\t---\t\t---\t\t----\n");
181 mul_factor = setting->mul_factor;
182 div_factor = setting->div_factor;
183 out += sprintf(out, "%-24s", setting->name);
184 if ((rc = ide_read_setting(drive, setting)) >= 0)
185 out += sprintf(out, "%-16d", rc * mul_factor / div_factor);
187 out += sprintf(out, "%-16s", "write-only");
188 out += sprintf(out, "%-16d%-16d", (setting->min * mul_factor + div_factor - 1) / div_factor, setting->max * mul_factor / div_factor);
189 if (setting->rw & SETTING_READ)
190 out += sprintf(out, "r");
191 if (setting->rw & SETTING_WRITE)
192 out += sprintf(out, "w");
193 out += sprintf(out, "\n");
194 setting = setting->next;
197 up(&ide_setting_sem);
199 PROC_IDE_READ_RETURN(page,start,off,count,eof,len);
204 static int do_proc_ide_write_settings(struct file *file, const char __user *buffer,
205 unsigned long count, void *data)
207 ide_drive_t *drive = ide_drive_from_key(data);
208 char name[MAX_LEN + 1];
211 ide_settings_t *setting;
214 if (!capable(CAP_SYS_ADMIN))
220 proc_ide_settings_warn();
222 if (count >= PAGE_SIZE)
225 s = buf = (char *)__get_free_page(GFP_USER);
229 if (copy_from_user(buf, buffer, count)) {
230 free_page((unsigned long)buf);
237 * Skip over leading whitespace
239 while (count && isspace(*s)) {
244 * Do one full pass to verify all parameters,
245 * then do another to actually write the new settings.
254 while (n > 0 && *p != ':') {
262 memcpy(name, q, p - q);
271 val = simple_strtoul(p, &q, 10);
274 if (n > 0 && !isspace(*p))
276 while (n > 0 && isspace(*p)) {
281 down(&ide_setting_sem);
282 setting = ide_find_setting_by_name(drive, name);
285 up(&ide_setting_sem);
289 ide_write_setting(drive, setting, val * setting->div_factor / setting->mul_factor);
290 up(&ide_setting_sem);
292 } while (!for_real++);
293 free_page((unsigned long)buf);
296 free_page((unsigned long)buf);
297 printk("proc_ide_write_settings(): parse error\n");
301 static int proc_ide_write_settings(struct file *file, const char __user *buffer,
302 unsigned long count, void *data)
307 ret = do_proc_ide_write_settings(file, buffer, count, data);
312 int proc_ide_read_capacity
313 (char *page, char **start, off_t off, int count, int *eof, void *data)
318 drive = ide_drive_from_key(data);
324 len = sprintf(page,"%llu\n",
325 (long long) (DRIVER(drive)->capacity(drive)));
327 PROC_IDE_READ_RETURN(page,start,off,count,eof,len);
330 int proc_ide_read_geometry
331 (char *page, char **start, off_t off, int count, int *eof, void *data)
338 drive = ide_drive_from_key(data);
343 out += sprintf(out,"physical %d/%d/%d\n",
344 drive->cyl, drive->head, drive->sect);
345 out += sprintf(out,"logical %d/%d/%d\n",
346 drive->bios_cyl, drive->bios_head, drive->bios_sect);
350 PROC_IDE_READ_RETURN(page,start,off,count,eof,len);
353 EXPORT_SYMBOL(proc_ide_read_geometry);
355 static int proc_ide_read_dmodel
356 (char *page, char **start, off_t off, int count, int *eof, void *data)
359 struct hd_driveid *id;
363 drive = ide_drive_from_key(data);
370 len = sprintf(page, "%.40s\n",
371 (id && id->model[0]) ? (char *)id->model : "(none)");
373 PROC_IDE_READ_RETURN(page,start,off,count,eof,len);
376 static int proc_ide_read_driver
377 (char *page, char **start, off_t off, int count, int *eof, void *data)
380 ide_driver_t *driver;
384 drive = ide_drive_from_key(data);
390 driver = drive->driver;
392 len = sprintf(page, "%s version %s\n",
393 driver->name, driver->version);
395 PROC_IDE_READ_RETURN(page,start,off,count,eof,len);
398 static int proc_ide_read_media
399 (char *page, char **start, off_t off, int count, int *eof, void *data)
406 drive = ide_drive_from_key(data);
412 switch (drive->media) {
413 case ide_disk: media = "disk\n";
415 case ide_cdrom: media = "cdrom\n";
417 case ide_tape: media = "tape\n";
419 case ide_floppy:media = "floppy\n";
421 default: media = "UNKNOWN\n";
427 PROC_IDE_READ_RETURN(page,start,off,count,eof,len);
430 static ide_proc_entry_t generic_drive_entries[] = {
431 { "driver", S_IFREG|S_IRUGO, proc_ide_read_driver, NULL },
432 { "identify", S_IFREG|S_IRUSR, proc_ide_read_identify, NULL },
433 { "media", S_IFREG|S_IRUGO, proc_ide_read_media, NULL },
434 { "model", S_IFREG|S_IRUGO, proc_ide_read_dmodel, NULL },
435 { "settings", S_IFREG|S_IRUSR|S_IWUSR,proc_ide_read_settings, proc_ide_write_settings },
436 { NULL, 0, NULL, NULL }
439 void ide_add_proc_entries(struct proc_dir_entry *dir, ide_proc_entry_t *p, void *data)
441 struct proc_dir_entry *ent;
445 while (p->name != NULL) {
446 ent = create_proc_entry(p->name, p->mode, dir);
450 ent->read_proc = p->read_proc;
451 ent->write_proc = p->write_proc;
456 void ide_remove_proc_entries(struct proc_dir_entry *dir, ide_proc_entry_t *p)
460 while (p->name != NULL) {
461 remove_proc_entry(p->name, dir);
466 static void create_proc_ide_drives(ide_hwif_t *hwif)
469 struct proc_dir_entry *ent;
470 struct proc_dir_entry *parent = hwif->proc;
473 for (d = 0; d < MAX_DRIVES; d++) {
474 ide_drive_t *drive = &hwif->drives[d];
481 drive->proc = proc_mkdir(drive->name, parent);
483 ide_add_proc_entries(drive->proc, generic_drive_entries, ide_drive_to_key(drive));
484 sprintf(name,"ide%d/%s", (drive->name[2]-'a')/2, drive->name);
485 ent = proc_symlink(drive->name, proc_ide_root, name);
490 static void destroy_proc_ide_device(ide_hwif_t *hwif, ide_drive_t *drive)
492 ide_driver_t *driver = drive->driver;
495 ide_remove_proc_entries(drive->proc, driver->proc);
496 ide_remove_proc_entries(drive->proc, generic_drive_entries);
497 remove_proc_entry(drive->name, proc_ide_root);
498 remove_proc_entry(drive->name, hwif->proc);
503 static void destroy_proc_ide_drives(ide_hwif_t *hwif)
507 for (d = 0; d < MAX_DRIVES; d++) {
508 ide_drive_t *drive = &hwif->drives[d];
510 destroy_proc_ide_device(hwif, drive);
514 static ide_proc_entry_t hwif_entries[] = {
515 { "channel", S_IFREG|S_IRUGO, proc_ide_read_channel, NULL },
516 { "mate", S_IFREG|S_IRUGO, proc_ide_read_mate, NULL },
517 { "model", S_IFREG|S_IRUGO, proc_ide_read_imodel, NULL },
518 { NULL, 0, NULL, NULL }
521 void create_proc_ide_interfaces(void)
525 for (h = 0; h < MAX_HWIFS; h++) {
526 ide_hwif_t *hwif = &ide_hwifs[h];
531 hwif->proc = proc_mkdir(hwif->name, proc_ide_root);
534 ide_add_proc_entries(hwif->proc, hwif_entries, ide_hwif_to_key(hwif));
536 create_proc_ide_drives(hwif);
540 EXPORT_SYMBOL(create_proc_ide_interfaces);
542 #ifdef CONFIG_BLK_DEV_IDEPCI
543 void ide_pci_create_host_proc(const char *name, get_info_t *get_info)
545 create_proc_info_entry(name, 0, proc_ide_root, get_info);
548 EXPORT_SYMBOL_GPL(ide_pci_create_host_proc);
551 void destroy_proc_ide_interface(ide_hwif_t *hwif)
554 destroy_proc_ide_drives(hwif);
555 ide_remove_proc_entries(hwif->proc, hwif_entries);
556 remove_proc_entry(hwif->name, proc_ide_root);
561 EXPORT_SYMBOL(destroy_proc_ide_interface);
563 static void destroy_proc_ide_interfaces(void)
567 for (h = 0; h < MAX_HWIFS; h++) {
568 ide_hwif_t *hwif = &ide_hwifs[h];
573 destroy_proc_ide_interface(hwif);
577 extern struct seq_operations ide_drivers_op;
578 static int ide_drivers_open(struct inode *inode, struct file *file)
580 return seq_open(file, &ide_drivers_op);
582 static struct file_operations ide_drivers_operations = {
583 .open = ide_drivers_open,
586 .release = seq_release,
589 void proc_ide_create(void)
591 struct proc_dir_entry *entry;
596 create_proc_ide_interfaces();
598 entry = create_proc_entry("drivers", 0, proc_ide_root);
600 entry->proc_fops = &ide_drivers_operations;
603 void proc_ide_destroy(void)
605 remove_proc_entry("ide/drivers", proc_ide_root);
606 destroy_proc_ide_interfaces();
607 remove_proc_entry("ide", NULL);