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)
45 ide_hwif_t *hwif = (ide_hwif_t *) data;
50 * Neither ide_unknown nor ide_forced should be set at this point.
52 switch (hwif->chipset) {
53 case ide_generic: name = "generic"; break;
54 case ide_pci: name = "pci"; break;
55 case ide_cmd640: name = "cmd640"; break;
56 case ide_dtc2278: name = "dtc2278"; break;
57 case ide_ali14xx: name = "ali14xx"; break;
58 case ide_qd65xx: name = "qd65xx"; break;
59 case ide_umc8672: name = "umc8672"; break;
60 case ide_ht6560b: name = "ht6560b"; break;
61 case ide_rz1000: name = "rz1000"; break;
62 case ide_trm290: name = "trm290"; break;
63 case ide_cmd646: name = "cmd646"; break;
64 case ide_cy82c693: name = "cy82c693"; break;
65 case ide_4drives: name = "4drives"; break;
66 case ide_pmac: name = "mac-io"; break;
67 default: name = "(unknown)"; break;
69 len = sprintf(page, "%s\n", name);
70 PROC_IDE_READ_RETURN(page,start,off,count,eof,len);
73 static int proc_ide_read_mate
74 (char *page, char **start, off_t off, int count, int *eof, void *data)
76 ide_hwif_t *hwif = (ide_hwif_t *) data;
79 if (hwif && hwif->mate && hwif->mate->present)
80 len = sprintf(page, "%s\n", hwif->mate->name);
82 len = sprintf(page, "(none)\n");
83 PROC_IDE_READ_RETURN(page,start,off,count,eof,len);
86 static int proc_ide_read_channel
87 (char *page, char **start, off_t off, int count, int *eof, void *data)
89 ide_hwif_t *hwif = (ide_hwif_t *) data;
92 page[0] = hwif->channel ? '1' : '0';
95 PROC_IDE_READ_RETURN(page,start,off,count,eof,len);
98 static int proc_ide_read_identify
99 (char *page, char **start, off_t off, int count, int *eof, void *data)
101 ide_drive_t *drive = (ide_drive_t *)data;
105 len = sprintf(page, "\n");
108 unsigned short *val = (unsigned short *) page;
110 BUG_ON(!drive->driver);
112 err = taskfile_lib_get_identify(drive, page);
114 char *out = ((char *)page) + (SECTOR_WORDS * 4);
117 out += sprintf(out, "%04x%c",
118 le16_to_cpu(*val), (++i & 7) ? ' ' : '\n');
120 } while (i < (SECTOR_WORDS * 2));
124 PROC_IDE_READ_RETURN(page,start,off,count,eof,len);
127 static void proc_ide_settings_warn(void)
129 static int warned = 0;
134 printk(KERN_WARNING "Warning: /proc/ide/hd?/settings interface is "
135 "obsolete, and will be removed soon!\n");
139 static int proc_ide_read_settings
140 (char *page, char **start, off_t off, int count, int *eof, void *data)
142 ide_drive_t *drive = (ide_drive_t *) data;
143 ide_settings_t *setting = (ide_settings_t *) drive->settings;
145 int len, rc, mul_factor, div_factor;
147 proc_ide_settings_warn();
149 down(&ide_setting_sem);
150 out += sprintf(out, "name\t\t\tvalue\t\tmin\t\tmax\t\tmode\n");
151 out += sprintf(out, "----\t\t\t-----\t\t---\t\t---\t\t----\n");
153 mul_factor = setting->mul_factor;
154 div_factor = setting->div_factor;
155 out += sprintf(out, "%-24s", setting->name);
156 if ((rc = ide_read_setting(drive, setting)) >= 0)
157 out += sprintf(out, "%-16d", rc * mul_factor / div_factor);
159 out += sprintf(out, "%-16s", "write-only");
160 out += sprintf(out, "%-16d%-16d", (setting->min * mul_factor + div_factor - 1) / div_factor, setting->max * mul_factor / div_factor);
161 if (setting->rw & SETTING_READ)
162 out += sprintf(out, "r");
163 if (setting->rw & SETTING_WRITE)
164 out += sprintf(out, "w");
165 out += sprintf(out, "\n");
166 setting = setting->next;
169 up(&ide_setting_sem);
170 PROC_IDE_READ_RETURN(page,start,off,count,eof,len);
175 static int proc_ide_write_settings(struct file *file, const char __user *buffer,
176 unsigned long count, void *data)
178 ide_drive_t *drive = (ide_drive_t *) data;
179 char name[MAX_LEN + 1];
182 ide_settings_t *setting;
185 if (!capable(CAP_SYS_ADMIN))
188 proc_ide_settings_warn();
190 if (count >= PAGE_SIZE)
193 s = buf = (char *)__get_free_page(GFP_USER);
197 if (copy_from_user(buf, buffer, count)) {
198 free_page((unsigned long)buf);
205 * Skip over leading whitespace
207 while (count && isspace(*s)) {
212 * Do one full pass to verify all parameters,
213 * then do another to actually write the new settings.
222 while (n > 0 && *p != ':') {
230 memcpy(name, q, p - q);
239 val = simple_strtoul(p, &q, 10);
242 if (n > 0 && !isspace(*p))
244 while (n > 0 && isspace(*p)) {
249 down(&ide_setting_sem);
250 setting = ide_find_setting_by_name(drive, name);
253 up(&ide_setting_sem);
257 ide_write_setting(drive, setting, val * setting->div_factor / setting->mul_factor);
258 up(&ide_setting_sem);
260 } while (!for_real++);
261 free_page((unsigned long)buf);
264 free_page((unsigned long)buf);
265 printk("proc_ide_write_settings(): parse error\n");
269 int proc_ide_read_capacity
270 (char *page, char **start, off_t off, int count, int *eof, void *data)
272 ide_drive_t *drive = (ide_drive_t *) data;
275 len = sprintf(page,"%llu\n",
276 (long long) (DRIVER(drive)->capacity(drive)));
277 PROC_IDE_READ_RETURN(page,start,off,count,eof,len);
280 int proc_ide_read_geometry
281 (char *page, char **start, off_t off, int count, int *eof, void *data)
283 ide_drive_t *drive = (ide_drive_t *) data;
287 out += sprintf(out,"physical %d/%d/%d\n",
288 drive->cyl, drive->head, drive->sect);
289 out += sprintf(out,"logical %d/%d/%d\n",
290 drive->bios_cyl, drive->bios_head, drive->bios_sect);
293 PROC_IDE_READ_RETURN(page,start,off,count,eof,len);
296 EXPORT_SYMBOL(proc_ide_read_geometry);
298 static int proc_ide_read_dmodel
299 (char *page, char **start, off_t off, int count, int *eof, void *data)
301 ide_drive_t *drive = (ide_drive_t *) data;
302 struct hd_driveid *id = drive->id;
305 len = sprintf(page, "%.40s\n",
306 (id && id->model[0]) ? (char *)id->model : "(none)");
307 PROC_IDE_READ_RETURN(page,start,off,count,eof,len);
310 static int proc_ide_read_driver
311 (char *page, char **start, off_t off, int count, int *eof, void *data)
313 ide_drive_t *drive = (ide_drive_t *) data;
314 ide_driver_t *driver = drive->driver;
317 len = sprintf(page, "%s version %s\n",
318 driver->name, driver->version);
319 PROC_IDE_READ_RETURN(page,start,off,count,eof,len);
322 static int proc_ide_write_driver
323 (struct file *file, const char __user *buffer, unsigned long count, void *data)
325 ide_drive_t *drive = (ide_drive_t *) data;
328 if (!capable(CAP_SYS_ADMIN))
332 if (copy_from_user(name, buffer, count))
335 if (ide_replace_subdriver(drive, name))
340 static int proc_ide_read_media
341 (char *page, char **start, off_t off, int count, int *eof, void *data)
343 ide_drive_t *drive = (ide_drive_t *) data;
347 switch (drive->media) {
348 case ide_disk: media = "disk\n";
350 case ide_cdrom: media = "cdrom\n";
352 case ide_tape: media = "tape\n";
354 case ide_floppy:media = "floppy\n";
356 default: media = "UNKNOWN\n";
361 PROC_IDE_READ_RETURN(page,start,off,count,eof,len);
364 static ide_proc_entry_t generic_drive_entries[] = {
365 { "driver", S_IFREG|S_IRUGO, proc_ide_read_driver, proc_ide_write_driver },
366 { "identify", S_IFREG|S_IRUSR, proc_ide_read_identify, NULL },
367 { "media", S_IFREG|S_IRUGO, proc_ide_read_media, NULL },
368 { "model", S_IFREG|S_IRUGO, proc_ide_read_dmodel, NULL },
369 { "settings", S_IFREG|S_IRUSR|S_IWUSR,proc_ide_read_settings, proc_ide_write_settings },
370 { NULL, 0, NULL, NULL }
373 void ide_add_proc_entries(struct proc_dir_entry *dir, ide_proc_entry_t *p, void *data)
375 struct proc_dir_entry *ent;
379 while (p->name != NULL) {
380 ent = create_proc_entry(p->name, p->mode, dir);
384 ent->read_proc = p->read_proc;
385 ent->write_proc = p->write_proc;
390 void ide_remove_proc_entries(struct proc_dir_entry *dir, ide_proc_entry_t *p)
394 while (p->name != NULL) {
395 remove_proc_entry(p->name, dir);
400 static void create_proc_ide_drives(ide_hwif_t *hwif)
403 struct proc_dir_entry *ent;
404 struct proc_dir_entry *parent = hwif->proc;
407 for (d = 0; d < MAX_DRIVES; d++) {
408 ide_drive_t *drive = &hwif->drives[d];
415 drive->proc = proc_mkdir(drive->name, parent);
417 ide_add_proc_entries(drive->proc, generic_drive_entries, drive);
418 sprintf(name,"ide%d/%s", (drive->name[2]-'a')/2, drive->name);
419 ent = proc_symlink(drive->name, proc_ide_root, name);
424 static void destroy_proc_ide_device(ide_hwif_t *hwif, ide_drive_t *drive)
426 ide_driver_t *driver = drive->driver;
429 ide_remove_proc_entries(drive->proc, driver->proc);
430 ide_remove_proc_entries(drive->proc, generic_drive_entries);
431 remove_proc_entry(drive->name, proc_ide_root);
432 remove_proc_entry(drive->name, hwif->proc);
437 static void destroy_proc_ide_drives(ide_hwif_t *hwif)
441 for (d = 0; d < MAX_DRIVES; d++) {
442 ide_drive_t *drive = &hwif->drives[d];
444 destroy_proc_ide_device(hwif, drive);
448 static ide_proc_entry_t hwif_entries[] = {
449 { "channel", S_IFREG|S_IRUGO, proc_ide_read_channel, NULL },
450 { "mate", S_IFREG|S_IRUGO, proc_ide_read_mate, NULL },
451 { "model", S_IFREG|S_IRUGO, proc_ide_read_imodel, NULL },
452 { NULL, 0, NULL, NULL }
455 void create_proc_ide_interfaces(void)
459 for (h = 0; h < MAX_HWIFS; h++) {
460 ide_hwif_t *hwif = &ide_hwifs[h];
465 hwif->proc = proc_mkdir(hwif->name, proc_ide_root);
468 ide_add_proc_entries(hwif->proc, hwif_entries, hwif);
470 create_proc_ide_drives(hwif);
474 EXPORT_SYMBOL(create_proc_ide_interfaces);
476 #ifdef CONFIG_BLK_DEV_IDEPCI
477 void ide_pci_create_host_proc(const char *name, get_info_t *get_info)
479 create_proc_info_entry(name, 0, proc_ide_root, get_info);
482 EXPORT_SYMBOL_GPL(ide_pci_create_host_proc);
485 void destroy_proc_ide_interface(ide_hwif_t *hwif)
488 destroy_proc_ide_drives(hwif);
489 ide_remove_proc_entries(hwif->proc, hwif_entries);
490 remove_proc_entry(hwif->name, proc_ide_root);
495 extern struct seq_operations ide_drivers_op;
496 static int ide_drivers_open(struct inode *inode, struct file *file)
498 return seq_open(file, &ide_drivers_op);
500 static struct file_operations ide_drivers_operations = {
501 .open = ide_drivers_open,
504 .release = seq_release,
507 void proc_ide_create(void)
509 struct proc_dir_entry *entry;
514 create_proc_ide_interfaces();
516 entry = create_proc_entry("drivers", 0, proc_ide_root);
518 entry->proc_fops = &ide_drivers_operations;
521 void proc_ide_destroy(void)
523 remove_proc_entry("ide/drivers", proc_ide_root);
524 remove_proc_entry("ide", NULL);