Import 2.3.25pre1
[davej-history.git] / drivers / block / ide-proc.c
blobb6807242854054d8a9a3c4fb5771c77eb122a3d9
1 /*
2 * linux/drivers/block/ide-proc.c Version 1.03 January 2, 1998
4 * Copyright (C) 1997-1998 Mark Lord
5 */
7 /*
8 * This is the /proc/ide/ filesystem implementation.
10 * The major reason this exists is to provide sufficient access
11 * to driver and config data, such that user-mode programs can
12 * be developed to handle chipset tuning for most PCI interfaces.
13 * This should provide better utilities, and less kernel bloat.
15 * The entire pci config space for a PCI interface chipset can be
16 * retrieved by just reading it. e.g. "cat /proc/ide3/config"
18 * To modify registers *safely*, do something like:
19 * echo "P40:88" >/proc/ide/ide3/config
20 * That expression writes 0x88 to pci config register 0x40
21 * on the chip which controls ide3. Multiple tuples can be issued,
22 * and the writes will be completed as an atomic set:
23 * echo "P40:88 P41:35 P42:00 P43:00" >/proc/ide/ide3/config
25 * All numbers must be specified using pairs of ascii hex digits.
26 * It is important to note that these writes will be performed
27 * after waiting for the IDE controller (both interfaces)
28 * to be completely idle, to ensure no corruption of I/O in progress.
30 * Non-PCI registers can also be written, using "R" in place of "P"
31 * in the above examples. The size of the port transfer is determined
32 * by the number of pairs of hex digits given for the data. If a two
33 * digit value is given, the write will be a byte operation; if four
34 * digits are used, the write will be performed as a 16-bit operation;
35 * and if eight digits are specified, a 32-bit "dword" write will be
36 * performed. Odd numbers of digits are not permitted.
38 * If there is an error *anywhere* in the string of registers/data
39 * then *none* of the writes will be performed.
41 * Drive/Driver settings can be retrieved by reading the drive's
42 * "settings" files. e.g. "cat /proc/ide0/hda/settings"
43 * To write a new value "val" into a specific setting "name", use:
44 * echo "name:val" >/proc/ide/ide0/hda/settings
46 * Also useful, "cat /proc/ide0/hda/[identify, smart_values,
47 * smart_thresholds, capabilities]" will issue an IDENTIFY /
48 * PACKET_IDENTIFY / SMART_READ_VALUES / SMART_READ_THRESHOLDS /
49 * SENSE CAPABILITIES command to /dev/hda, and then dump out the
50 * returned data as 256 16-bit words. The "hdparm" utility will
51 * be updated someday soon to use this mechanism.
53 * Feel free to develop and distribute fancy GUI configuration
54 * utilities for you favorite PCI chipsets. I'll be working on
55 * one for the Promise 20246 someday soon. -ml
59 #include <linux/config.h>
60 #include <asm/uaccess.h>
61 #include <linux/errno.h>
62 #include <linux/sched.h>
63 #include <linux/proc_fs.h>
64 #include <linux/stat.h>
65 #include <linux/mm.h>
66 #include <linux/pci.h>
67 #include <linux/ctype.h>
68 #include <linux/ide.h>
70 #include <asm/io.h>
72 #ifndef MIN
73 #define MIN(a,b) (((a) < (b)) ? (a) : (b))
74 #endif
76 #ifdef CONFIG_BLK_DEV_ALI15X3
77 extern byte ali_proc;
78 int (*ali_display_info)(char *, char **, off_t, int, int) = NULL;
79 #endif /* CONFIG_BLK_DEV_ALI15X3 */
81 #ifdef CONFIG_BLK_DEV_SIS5513
82 extern byte sis_proc;
83 int (*sis_display_info)(char *, char **, off_t, int, int) = NULL;
84 #endif /* CONFIG_BLK_DEV_SIS5513 */
86 #ifdef CONFIG_BLK_DEV_VIA82CXXX
87 extern byte via_proc;
88 int (*via_display_info)(char *, char **, off_t, int, int) = NULL;
89 #endif /* CONFIG_BLK_DEV_VIA82CXXX */
91 static int ide_getxdigit(char c)
93 int digit;
94 if (isdigit(c))
95 digit = c - '0';
96 else if (isxdigit(c))
97 digit = tolower(c) - 'a' + 10;
98 else
99 digit = -1;
100 return digit;
103 static int xx_xx_parse_error (const char *data, unsigned long len, const char *msg)
105 char errbuf[16];
106 int i;
107 if (len >= sizeof(errbuf))
108 len = sizeof(errbuf) - 1;
109 for (i = 0; i < len; ++i) {
110 char c = data[i];
111 if (!c || c == '\n')
112 c = '\0';
113 else if (iscntrl(c))
114 c = '?';
115 errbuf[i] = c;
117 errbuf[i] = '\0';
118 printk("proc_ide: error: %s: '%s'\n", msg, errbuf);
119 return -EINVAL;
122 static struct proc_dir_entry * proc_ide_root = NULL;
124 static int proc_ide_write_config
125 (struct file *file, const char *buffer, unsigned long count, void *data)
127 ide_hwif_t *hwif = (ide_hwif_t *)data;
128 int for_real = 0;
129 unsigned long startn = 0, n, flags;
130 const char *start = NULL, *msg = NULL;
132 if (!capable(CAP_SYS_ADMIN))
133 return -EACCES;
135 * Skip over leading whitespace
137 while (count && isspace(*buffer)) {
138 --count;
139 ++buffer;
142 * Do one full pass to verify all parameters,
143 * then do another to actually write the regs.
145 save_flags(flags); /* all CPUs */
146 do {
147 const char *p;
148 if (for_real) {
149 unsigned long timeout = jiffies + (3 * HZ);
150 ide_hwgroup_t *mygroup = (ide_hwgroup_t *)(hwif->hwgroup);
151 ide_hwgroup_t *mategroup = NULL;
152 if (hwif->mate && hwif->mate->hwgroup)
153 mategroup = (ide_hwgroup_t *)(hwif->mate->hwgroup);
154 cli(); /* all CPUs; ensure all writes are done together */
155 while (mygroup->busy || (mategroup && mategroup->busy)) {
156 sti(); /* all CPUs */
157 if (0 < (signed long)(jiffies - timeout)) {
158 printk("/proc/ide/%s/config: channel(s) busy, cannot write\n", hwif->name);
159 restore_flags(flags); /* all CPUs */
160 return -EBUSY;
162 cli(); /* all CPUs */
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 && !IDE_PCI_DEVID_EQ(hwif->pci_devid, IDE_PCI_DEVID_NULL))
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 restore_flags(flags); /* all CPUs */
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: outb(val, reg);
276 break;
277 case 4: outw(val, reg);
278 break;
279 case 8: outl(val, reg);
280 break;
282 #endif /* !__mc68000__ && !CONFIG_APUS */
286 } while (!for_real++);
287 restore_flags(flags); /* all CPUs */
288 return count;
289 parse_error:
290 restore_flags(flags); /* all CPUs */
291 printk("parse error\n");
292 return xx_xx_parse_error(start, startn, msg);
295 static 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 (!IDE_PCI_DEVID_EQ(hwif->pci_devid, IDE_PCI_DEVID_NULL) && dev && dev->bus) {
305 int reg = 0;
307 out += sprintf(out, "pci bus %02x device %02x vid %04x did %04x channel %d\n",
308 dev->bus->number, dev->devfn, hwif->pci_devid.vid, hwif->pci_devid.did, hwif->channel);
309 do {
310 byte val;
311 int rc = pci_read_config_byte(dev, reg, &val);
312 if (rc) {
313 printk("proc_ide_read_config: error %d reading bus %02x dev %02x reg 0x%02x\n",
314 rc, dev->bus->number, dev->devfn, reg);
315 out += sprintf(out, "??%c", (++reg & 0xf) ? ' ' : '\n');
316 } else
317 out += sprintf(out, "%02x%c", val, (++reg & 0xf) ? ' ' : '\n');
318 } while (reg < 0x100);
319 } else
320 #endif /* CONFIG_BLK_DEV_IDEPCI */
321 out += sprintf(out, "(none)\n");
322 len = out - page;
323 PROC_IDE_READ_RETURN(page,start,off,count,eof,len);
327 static int ide_getdigit(char c)
329 int digit;
330 if (isdigit(c))
331 digit = c - '0';
332 else
333 digit = -1;
334 return digit;
337 static int proc_ide_read_drivers
338 (char *page, char **start, off_t off, int count, int *eof, void *data)
340 char *out = page;
341 int len;
342 ide_module_t *p = ide_modules;
343 ide_driver_t *driver;
345 while (p) {
346 driver = (ide_driver_t *) p->info;
347 if (p->type == IDE_DRIVER_MODULE && driver)
348 out += sprintf(out, "%s version %s\n", driver->name, driver->version);
349 p = p->next;
351 len = out - page;
352 PROC_IDE_READ_RETURN(page,start,off,count,eof,len);
355 static int proc_ide_read_imodel
356 (char *page, char **start, off_t off, int count, int *eof, void *data)
358 ide_hwif_t *hwif = (ide_hwif_t *) data;
359 int len;
360 const char *name;
362 switch (hwif->chipset) {
363 case ide_unknown: name = "(none)"; break;
364 case ide_generic: name = "generic"; break;
365 case ide_pci: name = "pci"; break;
366 case ide_cmd640: name = "cmd640"; break;
367 case ide_dtc2278: name = "dtc2278"; break;
368 case ide_ali14xx: name = "ali14xx"; break;
369 case ide_qd6580: name = "qd6580"; break;
370 case ide_umc8672: name = "umc8672"; break;
371 case ide_ht6560b: name = "ht6560b"; break;
372 case ide_pdc4030: name = "pdc4030"; break;
373 case ide_rz1000: name = "rz1000"; break;
374 case ide_trm290: name = "trm290"; break;
375 case ide_4drives: name = "4drives"; break;
376 default: name = "(unknown)"; break;
378 len = sprintf(page, "%s\n", name);
379 PROC_IDE_READ_RETURN(page,start,off,count,eof,len);
382 static int proc_ide_read_mate
383 (char *page, char **start, off_t off, int count, int *eof, void *data)
385 ide_hwif_t *hwif = (ide_hwif_t *) data;
386 int len;
388 if (hwif && hwif->mate && hwif->mate->present)
389 len = sprintf(page, "%s\n", hwif->mate->name);
390 else
391 len = sprintf(page, "(none)\n");
392 PROC_IDE_READ_RETURN(page,start,off,count,eof,len);
395 static int proc_ide_read_channel
396 (char *page, char **start, off_t off, int count, int *eof, void *data)
398 ide_hwif_t *hwif = (ide_hwif_t *) data;
399 int len;
401 page[0] = hwif->channel ? '1' : '0';
402 page[1] = '\n';
403 len = 2;
404 PROC_IDE_READ_RETURN(page,start,off,count,eof,len);
407 static int proc_ide_get_identify(ide_drive_t *drive, byte *buf)
409 return ide_wait_cmd(drive, (drive->media == ide_disk) ? WIN_IDENTIFY : WIN_PIDENTIFY, 0, 0, 1, buf);
412 static int proc_ide_read_identify
413 (char *page, char **start, off_t off, int count, int *eof, void *data)
415 ide_drive_t *drive = (ide_drive_t *)data;
416 int len = 0, i = 0;
418 if (drive && !proc_ide_get_identify(drive, page)) {
419 unsigned short *val = ((unsigned short *)page) + 2;
420 char *out = ((char *)val) + (SECTOR_WORDS * 4);
421 page = out;
422 do {
423 out += sprintf(out, "%04x%c", le16_to_cpu(*val), (++i & 7) ? ' ' : '\n');
424 val += 1;
425 } while (i < (SECTOR_WORDS * 2));
426 len = out - page;
428 else
429 len = sprintf(page, "\n");
430 PROC_IDE_READ_RETURN(page,start,off,count,eof,len);
433 static int proc_ide_read_settings
434 (char *page, char **start, off_t off, int count, int *eof, void *data)
436 ide_drive_t *drive = (ide_drive_t *) data;
437 ide_settings_t *setting = (ide_settings_t *) drive->settings;
438 char *out = page;
439 int len, rc, mul_factor, div_factor;
441 out += sprintf(out, "name\t\t\tvalue\t\tmin\t\tmax\t\tmode\n");
442 out += sprintf(out, "----\t\t\t-----\t\t---\t\t---\t\t----\n");
443 while(setting) {
444 mul_factor = setting->mul_factor;
445 div_factor = setting->div_factor;
446 out += sprintf(out, "%-24s", setting->name);
447 if ((rc = ide_read_setting(drive, setting)) >= 0)
448 out += sprintf(out, "%-16d", rc * mul_factor / div_factor);
449 else
450 out += sprintf(out, "%-16s", "write-only");
451 out += sprintf(out, "%-16d%-16d", (setting->min * mul_factor + div_factor - 1) / div_factor, setting->max * mul_factor / div_factor);
452 if (setting->rw & SETTING_READ)
453 out += sprintf(out, "r");
454 if (setting->rw & SETTING_WRITE)
455 out += sprintf(out, "w");
456 out += sprintf(out, "\n");
457 setting = setting->next;
459 len = out - page;
460 PROC_IDE_READ_RETURN(page,start,off,count,eof,len);
463 #define MAX_LEN 30
465 static int proc_ide_write_settings
466 (struct file *file, const char *buffer, unsigned long count, void *data)
468 ide_drive_t *drive = (ide_drive_t *) data;
469 char name[MAX_LEN + 1];
470 int for_real = 0, len;
471 unsigned long n;
472 const char *start = NULL;
473 ide_settings_t *setting;
475 if (!capable(CAP_SYS_ADMIN))
476 return -EACCES;
478 * Skip over leading whitespace
480 while (count && isspace(*buffer)) {
481 --count;
482 ++buffer;
485 * Do one full pass to verify all parameters,
486 * then do another to actually write the new settings.
488 do {
489 const char *p;
490 p = buffer;
491 n = count;
492 while (n > 0) {
493 int d, digits;
494 unsigned int val = 0;
495 start = p;
497 while (n > 0 && *p != ':') {
498 --n;
499 p++;
501 if (*p != ':')
502 goto parse_error;
503 len = IDE_MIN(p - start, MAX_LEN);
504 strncpy(name, start, IDE_MIN(len, MAX_LEN));
505 name[len] = 0;
507 if (n > 0) {
508 --n;
509 p++;
510 } else
511 goto parse_error;
513 digits = 0;
514 while (n > 0 && (d = ide_getdigit(*p)) >= 0) {
515 val = (val * 10) + d;
516 --n;
517 ++p;
518 ++digits;
520 if (n > 0 && !isspace(*p))
521 goto parse_error;
522 while (n > 0 && isspace(*p)) {
523 --n;
524 ++p;
526 setting = ide_find_setting_by_name(drive, name);
527 if (!setting)
528 goto parse_error;
530 if (for_real)
531 ide_write_setting(drive, setting, val * setting->div_factor / setting->mul_factor);
533 } while (!for_real++);
534 return count;
535 parse_error:
536 printk("proc_ide_write_settings(): parse error\n");
537 return -EINVAL;
540 int proc_ide_read_capacity
541 (char *page, char **start, off_t off, int count, int *eof, void *data)
543 ide_drive_t *drive = (ide_drive_t *) data;
544 ide_driver_t *driver = (ide_driver_t *) drive->driver;
545 int len;
547 if (!driver)
548 len = sprintf(page, "(none)\n");
549 else
550 len = sprintf(page,"%li\n", ((ide_driver_t *)drive->driver)->capacity(drive));
551 PROC_IDE_READ_RETURN(page,start,off,count,eof,len);
554 int proc_ide_read_geometry
555 (char *page, char **start, off_t off, int count, int *eof, void *data)
557 ide_drive_t *drive = (ide_drive_t *) data;
558 char *out = page;
559 int len;
561 out += sprintf(out,"physical %d/%d/%d\n", drive->cyl, drive->head, drive->sect);
562 out += sprintf(out,"logical %d/%d/%d\n", drive->bios_cyl, drive->bios_head, drive->bios_sect);
563 len = out - page;
564 PROC_IDE_READ_RETURN(page,start,off,count,eof,len);
567 static int proc_ide_read_dmodel
568 (char *page, char **start, off_t off, int count, int *eof, void *data)
570 ide_drive_t *drive = (ide_drive_t *) data;
571 struct hd_driveid *id = drive->id;
572 int len;
574 len = sprintf(page, "%.40s\n", (id && id->model[0]) ? (char *)id->model : "(none)");
575 PROC_IDE_READ_RETURN(page,start,off,count,eof,len);
578 static int proc_ide_read_driver
579 (char *page, char **start, off_t off, int count, int *eof, void *data)
581 ide_drive_t *drive = (ide_drive_t *) data;
582 ide_driver_t *driver = (ide_driver_t *) drive->driver;
583 int len;
585 if (!driver)
586 len = sprintf(page, "(none)\n");
587 else
588 len = sprintf(page, "%s version %s\n", driver->name, driver->version);
589 PROC_IDE_READ_RETURN(page,start,off,count,eof,len);
592 static int proc_ide_write_driver
593 (struct file *file, const char *buffer, unsigned long count, void *data)
595 ide_drive_t *drive = (ide_drive_t *) data;
597 if (!capable(CAP_SYS_ADMIN))
598 return -EACCES;
599 if (ide_replace_subdriver(drive, buffer))
600 return -EINVAL;
601 return count;
604 static int proc_ide_read_media
605 (char *page, char **start, off_t off, int count, int *eof, void *data)
607 ide_drive_t *drive = (ide_drive_t *) data;
608 const char *media;
609 int len;
611 switch (drive->media) {
612 case ide_disk: media = "disk\n";
613 break;
614 case ide_cdrom: media = "cdrom\n";
615 break;
616 case ide_tape: media = "tape\n";
617 break;
618 case ide_floppy:media = "floppy\n";
619 break;
620 default: media = "UNKNOWN\n";
621 break;
623 strcpy(page,media);
624 len = strlen(media);
625 PROC_IDE_READ_RETURN(page,start,off,count,eof,len);
628 static ide_proc_entry_t generic_drive_entries[] = {
629 { "driver", S_IFREG|S_IRUGO, proc_ide_read_driver, proc_ide_write_driver },
630 { "identify", S_IFREG|S_IRUSR, proc_ide_read_identify, NULL },
631 { "media", S_IFREG|S_IRUGO, proc_ide_read_media, NULL },
632 { "model", S_IFREG|S_IRUGO, proc_ide_read_dmodel, NULL },
633 { "settings", S_IFREG|S_IRUSR|S_IWUSR,proc_ide_read_settings, proc_ide_write_settings },
634 { NULL, 0, NULL, NULL }
637 void ide_add_proc_entries(struct proc_dir_entry *dir, ide_proc_entry_t *p, void *data)
639 struct proc_dir_entry *ent;
641 if (!dir || !p)
642 return;
643 while (p->name != NULL) {
644 ent = create_proc_entry(p->name, p->mode, dir);
645 if (!ent) return;
646 ent->nlink = 1;
647 ent->data = data;
648 ent->read_proc = p->read_proc;
649 ent->write_proc = p->write_proc;
650 p++;
654 void ide_remove_proc_entries(struct proc_dir_entry *dir, ide_proc_entry_t *p)
656 if (!dir || !p)
657 return;
658 while (p->name != NULL) {
659 remove_proc_entry(p->name, dir);
660 p++;
664 static int proc_ide_readlink(struct proc_dir_entry *de, char *page)
666 int n = (de->name[2] - 'a') / 2;
667 return sprintf(page, "ide%d/%s", n, de->name);
670 static void create_proc_ide_drives(ide_hwif_t *hwif)
672 int d;
673 struct proc_dir_entry *ent;
674 struct proc_dir_entry *parent = hwif->proc;
676 for (d = 0; d < MAX_DRIVES; d++) {
677 ide_drive_t *drive = &hwif->drives[d];
678 ide_driver_t *driver = drive->driver;
680 if (!drive->present)
681 continue;
682 if (drive->proc)
683 continue;
685 drive->proc = create_proc_entry(drive->name, S_IFDIR, parent);
686 if (drive->proc) {
687 ide_add_proc_entries(drive->proc, generic_drive_entries, drive);
688 if (driver) {
689 ide_add_proc_entries(drive->proc, generic_subdriver_entries, drive);
690 ide_add_proc_entries(drive->proc, driver->proc, drive);
693 ent = create_proc_entry(drive->name, S_IFLNK | S_IRUGO | S_IWUGO | S_IXUGO, proc_ide_root);
694 if (!ent) return;
695 ent->data = drive;
696 ent->readlink_proc = proc_ide_readlink;
697 ent->nlink = 1;
701 void destroy_proc_ide_drives(ide_hwif_t *hwif)
703 int d;
705 for (d = 0; d < MAX_DRIVES; d++) {
706 ide_drive_t *drive = &hwif->drives[d];
707 ide_driver_t *driver = drive->driver;
709 if (!drive->proc)
710 continue;
711 if (driver)
712 ide_remove_proc_entries(drive->proc, driver->proc);
713 ide_remove_proc_entries(drive->proc, generic_drive_entries);
714 remove_proc_entry(drive->name, proc_ide_root);
715 remove_proc_entry(drive->name, hwif->proc);
716 drive->proc = NULL;
720 static ide_proc_entry_t hwif_entries[] = {
721 { "channel", S_IFREG|S_IRUGO, proc_ide_read_channel, NULL },
722 { "config", S_IFREG|S_IRUGO|S_IWUSR,proc_ide_read_config, proc_ide_write_config },
723 { "mate", S_IFREG|S_IRUGO, proc_ide_read_mate, NULL },
724 { "model", S_IFREG|S_IRUGO, proc_ide_read_imodel, NULL },
725 { NULL, 0, NULL, NULL }
728 void create_proc_ide_interfaces(void)
730 int h;
732 for (h = 0; h < MAX_HWIFS; h++) {
733 ide_hwif_t *hwif = &ide_hwifs[h];
734 int exist = (hwif->proc != NULL);
736 if (!hwif->present)
737 continue;
738 if (!exist)
739 hwif->proc = create_proc_entry(hwif->name, S_IFDIR, proc_ide_root);
740 if (!hwif->proc)
741 return;
742 if (!exist)
743 ide_add_proc_entries(hwif->proc, hwif_entries, hwif);
744 create_proc_ide_drives(hwif);
748 static void destroy_proc_ide_interfaces(void)
750 int h;
752 for (h = 0; h < MAX_HWIFS; h++) {
753 ide_hwif_t *hwif = &ide_hwifs[h];
754 int exist = (hwif->proc != NULL);
756 #if 0
757 if (!hwif->present)
758 continue;
759 #endif
760 if (exist) {
761 destroy_proc_ide_drives(hwif);
762 ide_remove_proc_entries(hwif->proc, hwif_entries);
763 remove_proc_entry(hwif->name, proc_ide_root);
764 hwif->proc = NULL;
765 } else
766 continue;
770 void proc_ide_create(void)
772 proc_ide_root = create_proc_entry("ide", S_IFDIR, 0);
773 if (!proc_ide_root) return;
775 create_proc_ide_interfaces();
777 create_proc_read_entry("drivers",0,proc_ide_root,
778 proc_ide_read_drivers, NULL);
780 #ifdef CONFIG_BLK_DEV_ALI15X3
781 if ((ali_display_info) && (ali_proc))
782 create_proc_info_entry("ali", 0, proc_ide_root, ali_display_info);
783 #endif /* CONFIG_BLK_DEV_ALI15X3 */
784 #ifdef CONFIG_BLK_DEV_SIS5513
785 if ((sis_display_info) && (sis_proc))
786 create_proc_info_entry("sis", 0, proc_ide_root, sis_display_info);
787 #endif /* CONFIG_BLK_DEV_SIS5513 */
788 #ifdef CONFIG_BLK_DEV_VIA82CXXX
789 if ((via_display_info) && (via_proc))
790 create_proc_info_entry("via", 0, proc_ide_root, via_display_info);
791 #endif /* CONFIG_BLK_DEV_VIA82CXXX */
794 void proc_ide_destroy(void)
797 * Mmmm.. does this free up all resources,
798 * or do we need to do a more proper cleanup here ??
800 #ifdef CONFIG_BLK_DEV_ALI15X3
801 if ((ali_display_info) && (ali_proc))
802 remove_proc_entry("ide/ali",0);
803 #endif /* CONFIG_BLK_DEV_ALI15X3 */
804 #ifdef CONFIG_BLK_DEV_SIS5513
805 if ((sis_display_info) && (sis_proc))
806 remove_proc_entry("ide/sis", 0);
807 #endif /* CONFIG_BLK_DEV_SIS5513 */
808 #ifdef CONFIG_BLK_DEV_VIA82CXXX
809 if ((via_display_info) && (via_proc))
810 remove_proc_entry("ide/via",0);
811 #endif /* CONFIG_BLK_DEV_VIA82CXXX */
812 remove_proc_entry("ide/drivers", 0);
813 destroy_proc_ide_interfaces();
814 remove_proc_entry("ide", 0);