More meth updates.
[linux-2.6/linux-mips.git] / drivers / ide / ide-proc.c
blobc506c043d882a737a56580e115ba3b85b4b752fa
1 /*
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>
6 */
8 /*
9 * This is the /proc/ide/ filesystem implementation.
11 * The major reason this exists is to provide sufficient access
12 * to driver and config data, such that user-mode programs can
13 * be developed to handle chipset tuning for most PCI interfaces.
14 * This should provide better utilities, and less kernel bloat.
16 * The entire pci config space for a PCI interface chipset can be
17 * retrieved by just reading it. e.g. "cat /proc/ide3/config"
19 * To modify registers *safely*, do something like:
20 * echo "P40:88" >/proc/ide/ide3/config
21 * That expression writes 0x88 to pci config register 0x40
22 * on the chip which controls ide3. Multiple tuples can be issued,
23 * and the writes will be completed as an atomic set:
24 * echo "P40:88 P41:35 P42:00 P43:00" >/proc/ide/ide3/config
26 * All numbers must be specified using pairs of ascii hex digits.
27 * It is important to note that these writes will be performed
28 * after waiting for the IDE controller (both interfaces)
29 * to be completely idle, to ensure no corruption of I/O in progress.
31 * Non-PCI registers can also be written, using "R" in place of "P"
32 * in the above examples. The size of the port transfer is determined
33 * by the number of pairs of hex digits given for the data. If a two
34 * digit value is given, the write will be a byte operation; if four
35 * digits are used, the write will be performed as a 16-bit operation;
36 * and if eight digits are specified, a 32-bit "dword" write will be
37 * performed. Odd numbers of digits are not permitted.
39 * If there is an error *anywhere* in the string of registers/data
40 * then *none* of the writes will be performed.
42 * Drive/Driver settings can be retrieved by reading the drive's
43 * "settings" files. e.g. "cat /proc/ide0/hda/settings"
44 * To write a new value "val" into a specific setting "name", use:
45 * echo "name:val" >/proc/ide/ide0/hda/settings
47 * Also useful, "cat /proc/ide0/hda/[identify, smart_values,
48 * smart_thresholds, capabilities]" will issue an IDENTIFY /
49 * PACKET_IDENTIFY / SMART_READ_VALUES / SMART_READ_THRESHOLDS /
50 * SENSE CAPABILITIES command to /dev/hda, and then dump out the
51 * returned data as 256 16-bit words. The "hdparm" utility will
52 * be updated someday soon to use this mechanism.
54 * Feel free to develop and distribute fancy GUI configuration
55 * utilities for your favorite PCI chipsets. I'll be working on
56 * one for the Promise 20246 someday soon. -ml
60 #include <linux/config.h>
61 #include <linux/module.h>
63 #include <asm/uaccess.h>
64 #include <linux/errno.h>
65 #include <linux/sched.h>
66 #include <linux/proc_fs.h>
67 #include <linux/stat.h>
68 #include <linux/mm.h>
69 #include <linux/pci.h>
70 #include <linux/ctype.h>
71 #include <linux/hdreg.h>
72 #include <linux/ide.h>
73 #include <linux/seq_file.h>
75 #include <asm/io.h>
77 #ifndef MIN
78 #define MIN(a,b) (((a) < (b)) ? (a) : (b))
79 #endif
81 static int ide_getxdigit(char c)
83 int digit;
84 if (isdigit(c))
85 digit = c - '0';
86 else if (isxdigit(c))
87 digit = tolower(c) - 'a' + 10;
88 else
89 digit = -1;
90 return digit;
93 static int xx_xx_parse_error (const char *data, unsigned long len, const char *msg)
95 char errbuf[16];
96 int i;
97 if (len >= sizeof(errbuf))
98 len = sizeof(errbuf) - 1;
99 for (i = 0; i < len; ++i) {
100 char c = data[i];
101 if (!c || c == '\n')
102 c = '\0';
103 else if (iscntrl(c))
104 c = '?';
105 errbuf[i] = c;
107 errbuf[i] = '\0';
108 printk("proc_ide: error: %s: '%s'\n", msg, errbuf);
109 return -EINVAL;
112 static struct proc_dir_entry * proc_ide_root = NULL;
114 #ifdef CONFIG_BLK_DEV_IDEPCI
115 #include <linux/delay.h>
117 * This is the list of registered PCI chipset driver data structures.
119 static ide_pci_host_proc_t * ide_pci_host_proc_list;
121 #endif /* CONFIG_BLK_DEV_IDEPCI */
123 static int proc_ide_write_config
124 (struct file *file, const char *buffer, unsigned long count, void *data)
126 ide_hwif_t *hwif = (ide_hwif_t *)data;
127 int for_real = 0;
128 unsigned long startn = 0, n, flags;
129 const char *start = NULL, *msg = NULL;
131 if (!capable(CAP_SYS_ADMIN) || !capable(CAP_SYS_RAWIO))
132 return -EACCES;
134 * Skip over leading whitespace
136 while (count && isspace(*buffer)) {
137 --count;
138 ++buffer;
141 * Do one full pass to verify all parameters,
142 * then do another to actually write the regs.
144 spin_lock_irqsave(&ide_lock, flags);
145 do {
146 const char *p;
147 if (for_real) {
148 unsigned long timeout = jiffies + (3 * HZ);
149 ide_hwgroup_t *mygroup = (ide_hwgroup_t *)(hwif->hwgroup);
150 ide_hwgroup_t *mategroup = NULL;
151 if (hwif->mate && hwif->mate->hwgroup)
152 mategroup = (ide_hwgroup_t *)(hwif->mate->hwgroup);
153 spin_lock_irqsave(&ide_lock, flags);
154 while (mygroup->busy ||
155 (mategroup && mategroup->busy)) {
156 spin_unlock_irqrestore(&ide_lock, flags);
157 if (time_after(jiffies, timeout)) {
158 printk("/proc/ide/%s/config: channel(s) busy, cannot write\n", hwif->name);
159 spin_unlock_irqrestore(&ide_lock, flags);
160 return -EBUSY;
162 spin_lock_irqsave(&ide_lock, flags);
165 p = buffer;
166 n = count;
167 while (n > 0) {
168 int d, digits;
169 unsigned int reg = 0, val = 0, is_pci;
170 start = p;
171 startn = n--;
172 switch (*p++) {
173 case 'R': is_pci = 0;
174 break;
175 case 'P': is_pci = 1;
176 #ifdef CONFIG_BLK_DEV_IDEPCI
177 if (hwif->pci_dev && !hwif->pci_dev->vendor)
178 break;
179 #endif /* CONFIG_BLK_DEV_IDEPCI */
180 msg = "not a PCI device";
181 goto parse_error;
182 default: msg = "expected 'R' or 'P'";
183 goto parse_error;
185 digits = 0;
186 while (n > 0 && (d = ide_getxdigit(*p)) >= 0) {
187 reg = (reg << 4) | d;
188 --n;
189 ++p;
190 ++digits;
192 if (!digits || (digits > 4) || (is_pci && reg > 0xff)) {
193 msg = "bad/missing register number";
194 goto parse_error;
196 if (n-- == 0 || *p++ != ':') {
197 msg = "missing ':'";
198 goto parse_error;
200 digits = 0;
201 while (n > 0 && (d = ide_getxdigit(*p)) >= 0) {
202 val = (val << 4) | d;
203 --n;
204 ++p;
205 ++digits;
207 if (digits != 2 && digits != 4 && digits != 8) {
208 msg = "bad data, 2/4/8 digits required";
209 goto parse_error;
211 if (n > 0 && !isspace(*p)) {
212 msg = "expected whitespace after data";
213 goto parse_error;
215 while (n > 0 && isspace(*p)) {
216 --n;
217 ++p;
219 #ifdef CONFIG_BLK_DEV_IDEPCI
220 if (is_pci && (reg & ((digits >> 1) - 1))) {
221 msg = "misaligned access";
222 goto parse_error;
224 #endif /* CONFIG_BLK_DEV_IDEPCI */
225 if (for_real) {
226 #if 0
227 printk("proc_ide_write_config: type=%c, reg=0x%x, val=0x%x, digits=%d\n", is_pci ? "PCI" : "non-PCI", reg, val, digits);
228 #endif
229 if (is_pci) {
230 #ifdef CONFIG_BLK_DEV_IDEPCI
231 int rc = 0;
232 struct pci_dev *dev = hwif->pci_dev;
233 switch (digits) {
234 case 2: msg = "byte";
235 rc = pci_write_config_byte(dev, reg, val);
236 break;
237 case 4: msg = "word";
238 rc = pci_write_config_word(dev, reg, val);
239 break;
240 case 8: msg = "dword";
241 rc = pci_write_config_dword(dev, reg, val);
242 break;
244 if (rc) {
245 spin_unlock_irqrestore(&ide_lock, flags);
246 printk("proc_ide_write_config: error writing %s at bus %02x dev %02x reg 0x%x value 0x%x\n",
247 msg, dev->bus->number, dev->devfn, reg, val);
248 printk("proc_ide_write_config: error %d\n", rc);
249 return -EIO;
251 #endif /* CONFIG_BLK_DEV_IDEPCI */
252 } else { /* not pci */
253 #if !defined(__mc68000__) && !defined(CONFIG_APUS)
256 * Geert Uytterhoeven
258 * unless you can explain me what it really does.
259 * On m68k, we don't have outw() and outl() yet,
260 * and I need a good reason to implement it.
262 * BTW, IMHO the main remaining portability problem with the IDE driver
263 * is that it mixes IO (ioport) and MMIO (iomem) access on different platforms.
265 * I think all accesses should be done using
267 * ide_in[bwl](ide_device_instance, offset)
268 * ide_out[bwl](ide_device_instance, value, offset)
270 * so the architecture specific code can #define ide_{in,out}[bwl] to the
271 * appropriate function.
274 switch (digits) {
275 case 2: hwif->OUTB(val, reg);
276 break;
277 case 4: hwif->OUTW(val, reg);
278 break;
279 case 8: hwif->OUTL(val, reg);
280 break;
282 #endif /* !__mc68000__ && !CONFIG_APUS */
286 } while (!for_real++);
287 spin_unlock_irqrestore(&ide_lock, flags);
288 return count;
289 parse_error:
290 spin_unlock_irqrestore(&ide_lock, flags);
291 printk("parse error\n");
292 return xx_xx_parse_error(start, startn, msg);
295 int proc_ide_read_config
296 (char *page, char **start, off_t off, int count, int *eof, void *data)
298 char *out = page;
299 int len;
301 #ifdef CONFIG_BLK_DEV_IDEPCI
302 ide_hwif_t *hwif = (ide_hwif_t *)data;
303 struct pci_dev *dev = hwif->pci_dev;
304 if ((hwif->pci_dev && hwif->pci_dev->vendor) && dev && dev->bus) {
305 int reg = 0;
307 out += sprintf(out, "pci bus %02x device %02x vendor %04x "
308 "device %04x channel %d\n",
309 dev->bus->number, dev->devfn,
310 hwif->pci_dev->vendor, hwif->pci_dev->device,
311 hwif->channel);
312 do {
313 u8 val;
314 int rc = pci_read_config_byte(dev, reg, &val);
315 if (rc) {
316 printk("proc_ide_read_config: error %d reading"
317 " bus %02x dev %02x reg 0x%02x\n",
318 rc, dev->bus->number, dev->devfn, reg);
319 out += sprintf(out, "??%c",
320 (++reg & 0xf) ? ' ' : '\n');
321 } else
322 out += sprintf(out, "%02x%c",
323 val, (++reg & 0xf) ? ' ' : '\n');
324 } while (reg < 0x100);
325 } else
326 #endif /* CONFIG_BLK_DEV_IDEPCI */
327 out += sprintf(out, "(none)\n");
328 len = out - page;
329 PROC_IDE_READ_RETURN(page,start,off,count,eof,len);
332 EXPORT_SYMBOL(proc_ide_read_config);
334 static int ide_getdigit(char c)
336 int digit;
337 if (isdigit(c))
338 digit = c - '0';
339 else
340 digit = -1;
341 return digit;
344 static int proc_ide_read_imodel
345 (char *page, char **start, off_t off, int count, int *eof, void *data)
347 ide_hwif_t *hwif = (ide_hwif_t *) data;
348 int len;
349 const char *name;
351 switch (hwif->chipset) {
352 case ide_unknown: name = "(none)"; break;
353 case ide_generic: name = "generic"; break;
354 case ide_pci: name = "pci"; break;
355 case ide_cmd640: name = "cmd640"; break;
356 case ide_dtc2278: name = "dtc2278"; break;
357 case ide_ali14xx: name = "ali14xx"; break;
358 case ide_qd65xx: name = "qd65xx"; break;
359 case ide_umc8672: name = "umc8672"; break;
360 case ide_ht6560b: name = "ht6560b"; break;
361 case ide_pdc4030: name = "pdc4030"; break;
362 case ide_rz1000: name = "rz1000"; break;
363 case ide_trm290: name = "trm290"; break;
364 case ide_cmd646: name = "cmd646"; break;
365 case ide_cy82c693: name = "cy82c693"; break;
366 case ide_4drives: name = "4drives"; break;
367 case ide_pmac: name = "mac-io"; break;
368 case ide_pc9800: name = "pc9800"; break;
369 default: name = "(unknown)"; break;
371 len = sprintf(page, "%s\n", name);
372 PROC_IDE_READ_RETURN(page,start,off,count,eof,len);
375 EXPORT_SYMBOL(proc_ide_read_imodel);
377 int proc_ide_read_mate
378 (char *page, char **start, off_t off, int count, int *eof, void *data)
380 ide_hwif_t *hwif = (ide_hwif_t *) data;
381 int len;
383 if (hwif && hwif->mate && hwif->mate->present)
384 len = sprintf(page, "%s\n", hwif->mate->name);
385 else
386 len = sprintf(page, "(none)\n");
387 PROC_IDE_READ_RETURN(page,start,off,count,eof,len);
390 EXPORT_SYMBOL(proc_ide_read_mate);
392 int proc_ide_read_channel
393 (char *page, char **start, off_t off, int count, int *eof, void *data)
395 ide_hwif_t *hwif = (ide_hwif_t *) data;
396 int len;
398 page[0] = hwif->channel ? '1' : '0';
399 page[1] = '\n';
400 len = 2;
401 PROC_IDE_READ_RETURN(page,start,off,count,eof,len);
404 EXPORT_SYMBOL(proc_ide_read_channel);
406 int proc_ide_read_identify
407 (char *page, char **start, off_t off, int count, int *eof, void *data)
409 ide_drive_t *drive = (ide_drive_t *)data;
410 int len = 0, i = 0;
411 int err = 0;
413 len = sprintf(page, "\n");
415 if (drive)
417 unsigned short *val = (unsigned short *) page;
420 * The current code can't handle a driverless
421 * identify query taskfile. Now the right fix is
422 * to add a 'default' driver but that is a bit
423 * more work.
425 * FIXME: this has to be fixed for hotswap devices
428 if(DRIVER(drive))
429 err = taskfile_lib_get_identify(drive, page);
430 else /* This relies on the ID changes */
431 val = (unsigned short *)drive->id;
433 if(!err)
435 char *out = ((char *)page) + (SECTOR_WORDS * 4);
436 page = out;
437 do {
438 out += sprintf(out, "%04x%c",
439 le16_to_cpu(*val), (++i & 7) ? ' ' : '\n');
440 val += 1;
441 } while (i < (SECTOR_WORDS * 2));
442 len = out - page;
445 PROC_IDE_READ_RETURN(page,start,off,count,eof,len);
448 EXPORT_SYMBOL(proc_ide_read_identify);
450 int proc_ide_read_settings
451 (char *page, char **start, off_t off, int count, int *eof, void *data)
453 ide_drive_t *drive = (ide_drive_t *) data;
454 ide_settings_t *setting = (ide_settings_t *) drive->settings;
455 char *out = page;
456 int len, rc, mul_factor, div_factor;
458 down(&ide_setting_sem);
459 out += sprintf(out, "name\t\t\tvalue\t\tmin\t\tmax\t\tmode\n");
460 out += sprintf(out, "----\t\t\t-----\t\t---\t\t---\t\t----\n");
461 while(setting) {
462 mul_factor = setting->mul_factor;
463 div_factor = setting->div_factor;
464 out += sprintf(out, "%-24s", setting->name);
465 if ((rc = ide_read_setting(drive, setting)) >= 0)
466 out += sprintf(out, "%-16d", rc * mul_factor / div_factor);
467 else
468 out += sprintf(out, "%-16s", "write-only");
469 out += sprintf(out, "%-16d%-16d", (setting->min * mul_factor + div_factor - 1) / div_factor, setting->max * mul_factor / div_factor);
470 if (setting->rw & SETTING_READ)
471 out += sprintf(out, "r");
472 if (setting->rw & SETTING_WRITE)
473 out += sprintf(out, "w");
474 out += sprintf(out, "\n");
475 setting = setting->next;
477 len = out - page;
478 up(&ide_setting_sem);
479 PROC_IDE_READ_RETURN(page,start,off,count,eof,len);
482 EXPORT_SYMBOL(proc_ide_read_settings);
484 #define MAX_LEN 30
486 int proc_ide_write_settings
487 (struct file *file, const char *buffer, unsigned long count, void *data)
489 ide_drive_t *drive = (ide_drive_t *) data;
490 char name[MAX_LEN + 1];
491 int for_real = 0, len;
492 unsigned long n;
493 const char *start = NULL;
494 ide_settings_t *setting;
496 if (!capable(CAP_SYS_ADMIN))
497 return -EACCES;
499 * Skip over leading whitespace
501 while (count && isspace(*buffer)) {
502 --count;
503 ++buffer;
506 * Do one full pass to verify all parameters,
507 * then do another to actually write the new settings.
509 do {
510 const char *p;
511 p = buffer;
512 n = count;
513 while (n > 0) {
514 int d, digits;
515 unsigned int val = 0;
516 start = p;
518 while (n > 0 && *p != ':') {
519 --n;
520 p++;
522 if (*p != ':')
523 goto parse_error;
524 len = IDE_MIN(p - start, MAX_LEN);
525 strlcpy(name, start, IDE_MIN(len, MAX_LEN));
527 if (n > 0) {
528 --n;
529 p++;
530 } else
531 goto parse_error;
533 digits = 0;
534 while (n > 0 && (d = ide_getdigit(*p)) >= 0) {
535 val = (val * 10) + d;
536 --n;
537 ++p;
538 ++digits;
540 if (n > 0 && !isspace(*p))
541 goto parse_error;
542 while (n > 0 && isspace(*p)) {
543 --n;
544 ++p;
547 down(&ide_setting_sem);
548 setting = ide_find_setting_by_name(drive, name);
549 if (!setting)
551 up(&ide_setting_sem);
552 goto parse_error;
554 if (for_real)
555 ide_write_setting(drive, setting, val * setting->div_factor / setting->mul_factor);
556 up(&ide_setting_sem);
558 } while (!for_real++);
559 return count;
560 parse_error:
561 printk("proc_ide_write_settings(): parse error\n");
562 return -EINVAL;
565 EXPORT_SYMBOL(proc_ide_write_settings);
567 int proc_ide_read_capacity
568 (char *page, char **start, off_t off, int count, int *eof, void *data)
570 ide_drive_t *drive = (ide_drive_t *) data;
571 int len;
573 len = sprintf(page,"%llu\n",
574 (long long) (DRIVER(drive)->capacity(drive)));
575 PROC_IDE_READ_RETURN(page,start,off,count,eof,len);
578 EXPORT_SYMBOL(proc_ide_read_capacity);
580 int proc_ide_read_geometry
581 (char *page, char **start, off_t off, int count, int *eof, void *data)
583 ide_drive_t *drive = (ide_drive_t *) data;
584 char *out = page;
585 int len;
587 out += sprintf(out,"physical %d/%d/%d\n",
588 drive->cyl, drive->head, drive->sect);
589 out += sprintf(out,"logical %d/%d/%d\n",
590 drive->bios_cyl, drive->bios_head, drive->bios_sect);
592 len = out - page;
593 PROC_IDE_READ_RETURN(page,start,off,count,eof,len);
596 EXPORT_SYMBOL(proc_ide_read_geometry);
598 int proc_ide_read_dmodel
599 (char *page, char **start, off_t off, int count, int *eof, void *data)
601 ide_drive_t *drive = (ide_drive_t *) data;
602 struct hd_driveid *id = drive->id;
603 int len;
605 len = sprintf(page, "%.40s\n",
606 (id && id->model[0]) ? (char *)id->model : "(none)");
607 PROC_IDE_READ_RETURN(page,start,off,count,eof,len);
610 EXPORT_SYMBOL(proc_ide_read_dmodel);
612 int proc_ide_read_driver
613 (char *page, char **start, off_t off, int count, int *eof, void *data)
615 ide_drive_t *drive = (ide_drive_t *) data;
616 ide_driver_t *driver = drive->driver;
617 int len;
619 len = sprintf(page, "%s version %s\n",
620 driver->name, driver->version);
621 PROC_IDE_READ_RETURN(page,start,off,count,eof,len);
624 EXPORT_SYMBOL(proc_ide_read_driver);
626 int proc_ide_write_driver
627 (struct file *file, const char *buffer, unsigned long count, void *data)
629 ide_drive_t *drive = (ide_drive_t *) data;
631 if (!capable(CAP_SYS_ADMIN))
632 return -EACCES;
633 if (ide_replace_subdriver(drive, buffer))
634 return -EINVAL;
635 return count;
638 EXPORT_SYMBOL(proc_ide_write_driver);
640 int proc_ide_read_media
641 (char *page, char **start, off_t off, int count, int *eof, void *data)
643 ide_drive_t *drive = (ide_drive_t *) data;
644 const char *media;
645 int len;
647 switch (drive->media) {
648 case ide_disk: media = "disk\n";
649 break;
650 case ide_cdrom: media = "cdrom\n";
651 break;
652 case ide_tape: media = "tape\n";
653 break;
654 case ide_floppy:media = "floppy\n";
655 break;
656 default: media = "UNKNOWN\n";
657 break;
659 strcpy(page,media);
660 len = strlen(media);
661 PROC_IDE_READ_RETURN(page,start,off,count,eof,len);
664 EXPORT_SYMBOL(proc_ide_read_media);
666 static ide_proc_entry_t generic_drive_entries[] = {
667 { "driver", S_IFREG|S_IRUGO, proc_ide_read_driver, proc_ide_write_driver },
668 { "identify", S_IFREG|S_IRUSR, proc_ide_read_identify, NULL },
669 { "media", S_IFREG|S_IRUGO, proc_ide_read_media, NULL },
670 { "model", S_IFREG|S_IRUGO, proc_ide_read_dmodel, NULL },
671 { "settings", S_IFREG|S_IRUSR|S_IWUSR,proc_ide_read_settings, proc_ide_write_settings },
672 { NULL, 0, NULL, NULL }
675 void ide_add_proc_entries(struct proc_dir_entry *dir, ide_proc_entry_t *p, void *data)
677 struct proc_dir_entry *ent;
679 if (!dir || !p)
680 return;
681 while (p->name != NULL) {
682 ent = create_proc_entry(p->name, p->mode, dir);
683 if (!ent) return;
684 ent->nlink = 1;
685 ent->data = data;
686 ent->read_proc = p->read_proc;
687 ent->write_proc = p->write_proc;
688 p++;
692 EXPORT_SYMBOL(ide_add_proc_entries);
694 void ide_remove_proc_entries(struct proc_dir_entry *dir, ide_proc_entry_t *p)
696 if (!dir || !p)
697 return;
698 while (p->name != NULL) {
699 remove_proc_entry(p->name, dir);
700 p++;
704 EXPORT_SYMBOL(ide_remove_proc_entries);
706 void create_proc_ide_drives(ide_hwif_t *hwif)
708 int d;
709 struct proc_dir_entry *ent;
710 struct proc_dir_entry *parent = hwif->proc;
711 char name[64];
713 for (d = 0; d < MAX_DRIVES; d++) {
714 ide_drive_t *drive = &hwif->drives[d];
716 if (!drive->present)
717 continue;
718 if (drive->proc)
719 continue;
721 drive->proc = proc_mkdir(drive->name, parent);
722 if (drive->proc)
723 ide_add_proc_entries(drive->proc, generic_drive_entries, drive);
724 sprintf(name,"ide%d/%s", (drive->name[2]-'a')/2, drive->name);
725 ent = proc_symlink(drive->name, proc_ide_root, name);
726 if (!ent) return;
730 EXPORT_SYMBOL(create_proc_ide_drives);
732 void destroy_proc_ide_device(ide_hwif_t *hwif, ide_drive_t *drive)
734 ide_driver_t *driver = drive->driver;
736 if (drive->proc) {
737 ide_remove_proc_entries(drive->proc, driver->proc);
738 ide_remove_proc_entries(drive->proc, generic_drive_entries);
739 remove_proc_entry(drive->name, proc_ide_root);
740 remove_proc_entry(drive->name, hwif->proc);
741 drive->proc = NULL;
745 EXPORT_SYMBOL(destroy_proc_ide_device);
747 void destroy_proc_ide_drives(ide_hwif_t *hwif)
749 int d;
751 for (d = 0; d < MAX_DRIVES; d++) {
752 ide_drive_t *drive = &hwif->drives[d];
753 if (drive->proc)
754 destroy_proc_ide_device(hwif, drive);
758 EXPORT_SYMBOL(destroy_proc_ide_drives);
760 static ide_proc_entry_t hwif_entries[] = {
761 { "channel", S_IFREG|S_IRUGO, proc_ide_read_channel, NULL },
762 { "config", S_IFREG|S_IRUGO|S_IWUSR,proc_ide_read_config, proc_ide_write_config },
763 { "mate", S_IFREG|S_IRUGO, proc_ide_read_mate, NULL },
764 { "model", S_IFREG|S_IRUGO, proc_ide_read_imodel, NULL },
765 { NULL, 0, NULL, NULL }
768 void create_proc_ide_interfaces(void)
770 int h;
772 for (h = 0; h < MAX_HWIFS; h++) {
773 ide_hwif_t *hwif = &ide_hwifs[h];
775 if (!hwif->present)
776 continue;
777 if (!hwif->proc) {
778 hwif->proc = proc_mkdir(hwif->name, proc_ide_root);
779 if (!hwif->proc)
780 return;
781 ide_add_proc_entries(hwif->proc, hwif_entries, hwif);
783 create_proc_ide_drives(hwif);
787 #ifdef CONFIG_BLK_DEV_IDEPCI
788 void ide_pci_register_host_proc (ide_pci_host_proc_t *p)
790 ide_pci_host_proc_t *tmp;
792 if (!p) return;
793 p->next = NULL;
794 p->set = 1;
795 if (ide_pci_host_proc_list) {
796 tmp = ide_pci_host_proc_list;
797 while (tmp->next) tmp = tmp->next;
798 tmp->next = p;
799 } else
800 ide_pci_host_proc_list = p;
803 EXPORT_SYMBOL(ide_pci_register_host_proc);
805 #endif /* CONFIG_BLK_DEV_IDEPCI */
807 EXPORT_SYMBOL(create_proc_ide_interfaces);
809 void destroy_proc_ide_interfaces(void)
811 int h;
813 for (h = 0; h < MAX_HWIFS; h++) {
814 ide_hwif_t *hwif = &ide_hwifs[h];
815 int exist = (hwif->proc != NULL);
816 #if 0
817 if (!hwif->present)
818 continue;
819 #endif
820 if (exist) {
821 destroy_proc_ide_drives(hwif);
822 ide_remove_proc_entries(hwif->proc, hwif_entries);
823 remove_proc_entry(hwif->name, proc_ide_root);
824 hwif->proc = NULL;
825 } else
826 continue;
830 EXPORT_SYMBOL(destroy_proc_ide_interfaces);
832 extern struct seq_operations ide_drivers_op;
833 static int ide_drivers_open(struct inode *inode, struct file *file)
835 return seq_open(file, &ide_drivers_op);
837 static struct file_operations ide_drivers_operations = {
838 .open = ide_drivers_open,
839 .read = seq_read,
840 .llseek = seq_lseek,
841 .release = seq_release,
844 void proc_ide_create(void)
846 #ifdef CONFIG_BLK_DEV_IDEPCI
847 ide_pci_host_proc_t *p = ide_pci_host_proc_list;
848 #endif /* CONFIG_BLK_DEV_IDEPCI */
849 struct proc_dir_entry *entry;
850 proc_ide_root = proc_mkdir("ide", 0);
851 if (!proc_ide_root) return;
853 create_proc_ide_interfaces();
855 entry = create_proc_entry("drivers", 0, proc_ide_root);
856 if (entry)
857 entry->proc_fops = &ide_drivers_operations;
859 #ifdef CONFIG_BLK_DEV_IDEPCI
860 while (p != NULL)
862 if (p->name != NULL && p->set == 1 && p->get_info != NULL)
864 p->parent = proc_ide_root;
865 create_proc_info_entry(p->name, 0, p->parent, p->get_info);
866 p->set = 2;
868 p = p->next;
870 #endif /* CONFIG_BLK_DEV_IDEPCI */
873 EXPORT_SYMBOL(proc_ide_create);
875 void proc_ide_destroy(void)
877 #ifdef CONFIG_BLK_DEV_IDEPCI
878 ide_pci_host_proc_t *p;
880 for (p = ide_pci_host_proc_list; p; p = p->next) {
881 if (p->set == 2)
882 remove_proc_entry(p->name, p->parent);
884 #endif /* CONFIG_BLK_DEV_IDEPCI */
885 remove_proc_entry("ide/drivers", proc_ide_root);
886 destroy_proc_ide_interfaces();
887 remove_proc_entry("ide", 0);
890 EXPORT_SYMBOL(proc_ide_destroy);