Import 2.3.15pre2
[davej-history.git] / drivers / block / ide-proc.c
blob623ac9268b3148047d41e87f30e503f45e110d5e
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_VIA82C586
77 int (*via_display_info)(char *, char **, off_t, int, int) = NULL;
78 #endif /* CONFIG_BLK_DEV_VIA82C586 */
80 #ifdef CONFIG_BLK_DEV_ALI15X3
81 int (*ali_display_info)(char *, char **, off_t, int, int) = NULL;
82 #endif /* CONFIG_BLK_DEV_ALI15X3 */
84 static int ide_getxdigit(char c)
86 int digit;
87 if (isdigit(c))
88 digit = c - '0';
89 else if (isxdigit(c))
90 digit = tolower(c) - 'a' + 10;
91 else
92 digit = -1;
93 return digit;
96 static int xx_xx_parse_error (const char *data, unsigned long len, const char *msg)
98 char errbuf[16];
99 int i;
100 if (len >= sizeof(errbuf))
101 len = sizeof(errbuf) - 1;
102 for (i = 0; i < len; ++i) {
103 char c = data[i];
104 if (!c || c == '\n')
105 c = '\0';
106 else if (iscntrl(c))
107 c = '?';
108 errbuf[i] = c;
110 errbuf[i] = '\0';
111 printk("proc_ide: error: %s: '%s'\n", msg, errbuf);
112 return -EINVAL;
115 static struct proc_dir_entry * proc_ide_root = NULL;
117 static int proc_ide_write_config
118 (struct file *file, const char *buffer, unsigned long count, void *data)
120 ide_hwif_t *hwif = (ide_hwif_t *)data;
121 int for_real = 0;
122 unsigned long startn = 0, n, flags;
123 const char *start = NULL, *msg = NULL;
125 if (!capable(CAP_SYS_ADMIN))
126 return -EACCES;
128 * Skip over leading whitespace
130 while (count && isspace(*buffer)) {
131 --count;
132 ++buffer;
135 * Do one full pass to verify all parameters,
136 * then do another to actually write the regs.
138 save_flags(flags); /* all CPUs */
139 do {
140 const char *p;
141 if (for_real) {
142 unsigned long timeout = jiffies + (3 * HZ);
143 ide_hwgroup_t *mygroup = (ide_hwgroup_t *)(hwif->hwgroup);
144 ide_hwgroup_t *mategroup = NULL;
145 if (hwif->mate && hwif->mate->hwgroup)
146 mategroup = (ide_hwgroup_t *)(hwif->mate->hwgroup);
147 cli(); /* all CPUs; ensure all writes are done together */
148 while (mygroup->busy || (mategroup && mategroup->busy)) {
149 sti(); /* all CPUs */
150 if (0 < (signed long)(jiffies - timeout)) {
151 printk("/proc/ide/%s/config: channel(s) busy, cannot write\n", hwif->name);
152 restore_flags(flags); /* all CPUs */
153 return -EBUSY;
155 cli(); /* all CPUs */
158 p = buffer;
159 n = count;
160 while (n > 0) {
161 int d, digits;
162 unsigned int reg = 0, val = 0, is_pci;
163 start = p;
164 startn = n--;
165 switch (*p++) {
166 case 'R': is_pci = 0;
167 break;
168 case 'P': is_pci = 1;
169 #ifdef CONFIG_BLK_DEV_IDEPCI
170 if (hwif->pci_dev && !IDE_PCI_DEVID_EQ(hwif->pci_devid, IDE_PCI_DEVID_NULL))
171 break;
172 #endif /* CONFIG_BLK_DEV_IDEPCI */
173 msg = "not a PCI device";
174 goto parse_error;
175 default: msg = "expected 'R' or 'P'";
176 goto parse_error;
178 digits = 0;
179 while (n > 0 && (d = ide_getxdigit(*p)) >= 0) {
180 reg = (reg << 4) | d;
181 --n;
182 ++p;
183 ++digits;
185 if (!digits || (digits > 4) || (is_pci && reg > 0xff)) {
186 msg = "bad/missing register number";
187 goto parse_error;
189 if (n-- == 0 || *p++ != ':') {
190 msg = "missing ':'";
191 goto parse_error;
193 digits = 0;
194 while (n > 0 && (d = ide_getxdigit(*p)) >= 0) {
195 val = (val << 4) | d;
196 --n;
197 ++p;
198 ++digits;
200 if (digits != 2 && digits != 4 && digits != 8) {
201 msg = "bad data, 2/4/8 digits required";
202 goto parse_error;
204 if (n > 0 && !isspace(*p)) {
205 msg = "expected whitespace after data";
206 goto parse_error;
208 while (n > 0 && isspace(*p)) {
209 --n;
210 ++p;
212 #ifdef CONFIG_BLK_DEV_IDEPCI
213 if (is_pci && (reg & ((digits >> 1) - 1))) {
214 msg = "misaligned access";
215 goto parse_error;
217 #endif /* CONFIG_BLK_DEV_IDEPCI */
218 if (for_real) {
219 #if 0
220 printk("proc_ide_write_config: type=%c, reg=0x%x, val=0x%x, digits=%d\n", is_pci ? 'PCI' : 'non-PCI', reg, val, digits);
221 #endif
222 if (is_pci) {
223 #ifdef CONFIG_BLK_DEV_IDEPCI
224 int rc = 0;
225 struct pci_dev *dev = hwif->pci_dev;
226 switch (digits) {
227 case 2: msg = "byte";
228 rc = pci_write_config_byte(dev, reg, val);
229 break;
230 case 4: msg = "word";
231 rc = pci_write_config_word(dev, reg, val);
232 break;
233 case 8: msg = "dword";
234 rc = pci_write_config_dword(dev, reg, val);
235 break;
237 if (rc) {
238 restore_flags(flags); /* all CPUs */
239 printk("proc_ide_write_config: error writing %s at bus %02x dev %02x reg 0x%x value 0x%x\n",
240 msg, dev->bus->number, dev->devfn, reg, val);
241 printk("proc_ide_write_config: error %d\n", rc);
242 return -EIO;
244 #endif /* CONFIG_BLK_DEV_IDEPCI */
245 } else { /* not pci */
246 switch (digits) {
247 case 2: outb(val, reg);
248 break;
249 case 4: outw(val, reg);
250 break;
251 case 8: outl(val, reg);
252 break;
257 } while (!for_real++);
258 restore_flags(flags); /* all CPUs */
259 return count;
260 parse_error:
261 restore_flags(flags); /* all CPUs */
262 printk("parse error\n");
263 return xx_xx_parse_error(start, startn, msg);
266 static int proc_ide_read_config
267 (char *page, char **start, off_t off, int count, int *eof, void *data)
269 char *out = page;
270 int len;
272 #ifdef CONFIG_BLK_DEV_IDEPCI
273 ide_hwif_t *hwif = (ide_hwif_t *)data;
274 struct pci_dev *dev = hwif->pci_dev;
275 if (!IDE_PCI_DEVID_EQ(hwif->pci_devid, IDE_PCI_DEVID_NULL) && dev && dev->bus) {
276 int reg = 0;
278 out += sprintf(out, "pci bus %02x device %02x vid %04x did %04x channel %d\n",
279 dev->bus->number, dev->devfn, hwif->pci_devid.vid, hwif->pci_devid.did, hwif->channel);
280 do {
281 byte val;
282 int rc = pci_read_config_byte(dev, reg, &val);
283 if (rc) {
284 printk("proc_ide_read_config: error %d reading bus %02x dev %02x reg 0x%02x\n",
285 rc, dev->bus->number, dev->devfn, reg);
286 out += sprintf(out, "??%c", (++reg & 0xf) ? ' ' : '\n');
287 } else
288 out += sprintf(out, "%02x%c", val, (++reg & 0xf) ? ' ' : '\n');
289 } while (reg < 0x100);
290 } else
291 #endif /* CONFIG_BLK_DEV_IDEPCI */
292 out += sprintf(out, "(none)\n");
293 len = out - page;
294 PROC_IDE_READ_RETURN(page,start,off,count,eof,len);
298 static int ide_getdigit(char c)
300 int digit;
301 if (isdigit(c))
302 digit = c - '0';
303 else
304 digit = -1;
305 return digit;
308 static int proc_ide_read_drivers
309 (char *page, char **start, off_t off, int count, int *eof, void *data)
311 char *out = page;
312 int len;
313 ide_module_t *p = ide_modules;
314 ide_driver_t *driver;
316 while (p) {
317 driver = (ide_driver_t *) p->info;
318 if (p->type == IDE_DRIVER_MODULE && driver)
319 out += sprintf(out, "%s version %s\n", driver->name, driver->version);
320 p = p->next;
322 len = out - page;
323 PROC_IDE_READ_RETURN(page,start,off,count,eof,len);
326 static int proc_ide_read_imodel
327 (char *page, char **start, off_t off, int count, int *eof, void *data)
329 ide_hwif_t *hwif = (ide_hwif_t *) data;
330 int len;
331 const char *name;
333 switch (hwif->chipset) {
334 case ide_unknown: name = "(none)"; break;
335 case ide_generic: name = "generic"; break;
336 case ide_pci: name = "pci"; break;
337 case ide_cmd640: name = "cmd640"; break;
338 case ide_dtc2278: name = "dtc2278"; break;
339 case ide_ali14xx: name = "ali14xx"; break;
340 case ide_qd6580: name = "qd6580"; break;
341 case ide_umc8672: name = "umc8672"; break;
342 case ide_ht6560b: name = "ht6560b"; break;
343 case ide_pdc4030: name = "pdc4030"; break;
344 case ide_rz1000: name = "rz1000"; break;
345 case ide_trm290: name = "trm290"; break;
346 case ide_4drives: name = "4drives"; break;
347 default: name = "(unknown)"; break;
349 len = sprintf(page, "%s\n", name);
350 PROC_IDE_READ_RETURN(page,start,off,count,eof,len);
353 static int proc_ide_read_mate
354 (char *page, char **start, off_t off, int count, int *eof, void *data)
356 ide_hwif_t *hwif = (ide_hwif_t *) data;
357 int len;
359 if (hwif && hwif->mate && hwif->mate->present)
360 len = sprintf(page, "%s\n", hwif->mate->name);
361 else
362 len = sprintf(page, "(none)\n");
363 PROC_IDE_READ_RETURN(page,start,off,count,eof,len);
366 static int proc_ide_read_channel
367 (char *page, char **start, off_t off, int count, int *eof, void *data)
369 ide_hwif_t *hwif = (ide_hwif_t *) data;
370 int len;
372 page[0] = hwif->channel ? '1' : '0';
373 page[1] = '\n';
374 len = 2;
375 PROC_IDE_READ_RETURN(page,start,off,count,eof,len);
378 static int proc_ide_get_identify(ide_drive_t *drive, byte *buf)
380 return ide_wait_cmd(drive, (drive->media == ide_disk) ? WIN_IDENTIFY : WIN_PIDENTIFY, 0, 0, 1, buf);
383 static int proc_ide_read_identify
384 (char *page, char **start, off_t off, int count, int *eof, void *data)
386 ide_drive_t *drive = (ide_drive_t *)data;
387 int len = 0, i = 0;
389 if (drive && !proc_ide_get_identify(drive, page)) {
390 unsigned short *val = ((unsigned short *)page) + 2;
391 char *out = ((char *)val) + (SECTOR_WORDS * 4);
392 page = out;
393 do {
394 out += sprintf(out, "%04x%c", le16_to_cpu(*val), (++i & 7) ? ' ' : '\n');
395 val += 1;
396 } while (i < (SECTOR_WORDS * 2));
397 len = out - page;
399 else
400 len = sprintf(page, "\n");
401 PROC_IDE_READ_RETURN(page,start,off,count,eof,len);
404 static int proc_ide_read_settings
405 (char *page, char **start, off_t off, int count, int *eof, void *data)
407 ide_drive_t *drive = (ide_drive_t *) data;
408 ide_settings_t *setting = (ide_settings_t *) drive->settings;
409 char *out = page;
410 int len, rc, mul_factor, div_factor;
412 out += sprintf(out, "name\t\t\tvalue\t\tmin\t\tmax\t\tmode\n");
413 out += sprintf(out, "----\t\t\t-----\t\t---\t\t---\t\t----\n");
414 while(setting) {
415 mul_factor = setting->mul_factor;
416 div_factor = setting->div_factor;
417 out += sprintf(out, "%-24s", setting->name);
418 if ((rc = ide_read_setting(drive, setting)) >= 0)
419 out += sprintf(out, "%-16d", rc * mul_factor / div_factor);
420 else
421 out += sprintf(out, "%-16s", "write-only");
422 out += sprintf(out, "%-16d%-16d", (setting->min * mul_factor + div_factor - 1) / div_factor, setting->max * mul_factor / div_factor);
423 if (setting->rw & SETTING_READ)
424 out += sprintf(out, "r");
425 if (setting->rw & SETTING_WRITE)
426 out += sprintf(out, "w");
427 out += sprintf(out, "\n");
428 setting = setting->next;
430 len = out - page;
431 PROC_IDE_READ_RETURN(page,start,off,count,eof,len);
434 #define MAX_LEN 30
436 static int proc_ide_write_settings
437 (struct file *file, const char *buffer, unsigned long count, void *data)
439 ide_drive_t *drive = (ide_drive_t *) data;
440 char name[MAX_LEN + 1];
441 int for_real = 0, len;
442 unsigned long n;
443 const char *start = NULL;
444 ide_settings_t *setting;
446 if (!capable(CAP_SYS_ADMIN))
447 return -EACCES;
449 * Skip over leading whitespace
451 while (count && isspace(*buffer)) {
452 --count;
453 ++buffer;
456 * Do one full pass to verify all parameters,
457 * then do another to actually write the new settings.
459 do {
460 const char *p;
461 p = buffer;
462 n = count;
463 while (n > 0) {
464 int d, digits;
465 unsigned int val = 0;
466 start = p;
468 while (n > 0 && *p != ':') {
469 --n;
470 p++;
472 if (*p != ':')
473 goto parse_error;
474 len = IDE_MIN(p - start, MAX_LEN);
475 strncpy(name, start, IDE_MIN(len, MAX_LEN));
476 name[len] = 0;
478 if (n > 0) {
479 --n;
480 p++;
481 } else
482 goto parse_error;
484 digits = 0;
485 while (n > 0 && (d = ide_getdigit(*p)) >= 0) {
486 val = (val * 10) + d;
487 --n;
488 ++p;
489 ++digits;
491 if (n > 0 && !isspace(*p))
492 goto parse_error;
493 while (n > 0 && isspace(*p)) {
494 --n;
495 ++p;
497 setting = ide_find_setting_by_name(drive, name);
498 if (!setting)
499 goto parse_error;
501 if (for_real)
502 ide_write_setting(drive, setting, val * setting->div_factor / setting->mul_factor);
504 } while (!for_real++);
505 return count;
506 parse_error:
507 printk("proc_ide_write_settings(): parse error\n");
508 return -EINVAL;
511 int proc_ide_read_capacity
512 (char *page, char **start, off_t off, int count, int *eof, void *data)
514 ide_drive_t *drive = (ide_drive_t *) data;
515 ide_driver_t *driver = (ide_driver_t *) drive->driver;
516 int len;
518 if (!driver)
519 len = sprintf(page, "(none)\n");
520 else
521 len = sprintf(page,"%li\n", ((ide_driver_t *)drive->driver)->capacity(drive));
522 PROC_IDE_READ_RETURN(page,start,off,count,eof,len);
525 int proc_ide_read_geometry
526 (char *page, char **start, off_t off, int count, int *eof, void *data)
528 ide_drive_t *drive = (ide_drive_t *) data;
529 char *out = page;
530 int len;
532 out += sprintf(out,"physical %d/%d/%d\n", drive->cyl, drive->head, drive->sect);
533 out += sprintf(out,"logical %d/%d/%d\n", drive->bios_cyl, drive->bios_head, drive->bios_sect);
534 len = out - page;
535 PROC_IDE_READ_RETURN(page,start,off,count,eof,len);
538 static int proc_ide_read_dmodel
539 (char *page, char **start, off_t off, int count, int *eof, void *data)
541 ide_drive_t *drive = (ide_drive_t *) data;
542 struct hd_driveid *id = drive->id;
543 int len;
545 len = sprintf(page, "%.40s\n", (id && id->model[0]) ? (char *)id->model : "(none)");
546 PROC_IDE_READ_RETURN(page,start,off,count,eof,len);
549 static int proc_ide_read_driver
550 (char *page, char **start, off_t off, int count, int *eof, void *data)
552 ide_drive_t *drive = (ide_drive_t *) data;
553 ide_driver_t *driver = (ide_driver_t *) drive->driver;
554 int len;
556 if (!driver)
557 len = sprintf(page, "(none)\n");
558 else
559 len = sprintf(page, "%s version %s\n", driver->name, driver->version);
560 PROC_IDE_READ_RETURN(page,start,off,count,eof,len);
563 static int proc_ide_write_driver
564 (struct file *file, const char *buffer, unsigned long count, void *data)
566 ide_drive_t *drive = (ide_drive_t *) data;
568 if (!capable(CAP_SYS_ADMIN))
569 return -EACCES;
570 if (ide_replace_subdriver(drive, buffer))
571 return -EINVAL;
572 return count;
575 static int proc_ide_read_media
576 (char *page, char **start, off_t off, int count, int *eof, void *data)
578 ide_drive_t *drive = (ide_drive_t *) data;
579 const char *media;
580 int len;
582 switch (drive->media) {
583 case ide_disk: media = "disk\n";
584 break;
585 case ide_cdrom: media = "cdrom\n";
586 break;
587 case ide_tape: media = "tape\n";
588 break;
589 case ide_floppy:media = "floppy\n";
590 break;
591 default: media = "UNKNOWN\n";
592 break;
594 strcpy(page,media);
595 len = strlen(media);
596 PROC_IDE_READ_RETURN(page,start,off,count,eof,len);
599 static ide_proc_entry_t generic_drive_entries[] = {
600 { "driver", S_IFREG|S_IRUGO, proc_ide_read_driver, proc_ide_write_driver },
601 { "identify", S_IFREG|S_IRUSR, proc_ide_read_identify, NULL },
602 { "media", S_IFREG|S_IRUGO, proc_ide_read_media, NULL },
603 { "model", S_IFREG|S_IRUGO, proc_ide_read_dmodel, NULL },
604 { "settings", S_IFREG|S_IRUSR|S_IWUSR,proc_ide_read_settings, proc_ide_write_settings },
605 { NULL, 0, NULL, NULL }
608 void ide_add_proc_entries(struct proc_dir_entry *dir, ide_proc_entry_t *p, void *data)
610 struct proc_dir_entry *ent;
612 if (!dir || !p)
613 return;
614 while (p->name != NULL) {
615 ent = create_proc_entry(p->name, p->mode, dir);
616 if (!ent) return;
617 ent->nlink = 1;
618 ent->data = data;
619 ent->read_proc = p->read_proc;
620 ent->write_proc = p->write_proc;
621 p++;
625 void ide_remove_proc_entries(struct proc_dir_entry *dir, ide_proc_entry_t *p)
627 if (!dir || !p)
628 return;
629 while (p->name != NULL) {
630 remove_proc_entry(p->name, dir);
631 p++;
635 static int proc_ide_readlink(struct proc_dir_entry *de, char *page)
637 int n = (de->name[2] - 'a') / 2;
638 return sprintf(page, "ide%d/%s", n, de->name);
641 static void create_proc_ide_drives(ide_hwif_t *hwif)
643 int d;
644 struct proc_dir_entry *ent;
645 struct proc_dir_entry *parent = hwif->proc;
647 for (d = 0; d < MAX_DRIVES; d++) {
648 ide_drive_t *drive = &hwif->drives[d];
649 ide_driver_t *driver = drive->driver;
651 if (!drive->present)
652 continue;
653 if (drive->proc)
654 continue;
656 drive->proc = create_proc_entry(drive->name, S_IFDIR, parent);
657 if (drive->proc) {
658 ide_add_proc_entries(drive->proc, generic_drive_entries, drive);
659 if (driver) {
660 ide_add_proc_entries(drive->proc, generic_subdriver_entries, drive);
661 ide_add_proc_entries(drive->proc, driver->proc, drive);
664 ent = create_proc_entry(drive->name, S_IFLNK | S_IRUGO | S_IWUGO | S_IXUGO, proc_ide_root);
665 if (!ent) return;
666 ent->data = drive;
667 ent->readlink_proc = proc_ide_readlink;
668 ent->nlink = 1;
672 void destroy_proc_ide_drives(ide_hwif_t *hwif)
674 int d;
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->proc)
681 continue;
682 if (driver)
683 ide_remove_proc_entries(drive->proc, driver->proc);
684 ide_remove_proc_entries(drive->proc, generic_drive_entries);
685 remove_proc_entry(drive->name, proc_ide_root);
686 remove_proc_entry(drive->name, hwif->proc);
687 drive->proc = NULL;
691 static ide_proc_entry_t hwif_entries[] = {
692 { "channel", S_IFREG|S_IRUGO, proc_ide_read_channel, NULL },
693 { "config", S_IFREG|S_IRUGO|S_IWUSR,proc_ide_read_config, proc_ide_write_config },
694 { "mate", S_IFREG|S_IRUGO, proc_ide_read_mate, NULL },
695 { "model", S_IFREG|S_IRUGO, proc_ide_read_imodel, NULL },
696 { NULL, 0, NULL, NULL }
699 void create_proc_ide_interfaces(void)
701 int h;
703 for (h = 0; h < MAX_HWIFS; h++) {
704 ide_hwif_t *hwif = &ide_hwifs[h];
705 int exist = (hwif->proc != NULL);
707 if (!hwif->present)
708 continue;
709 if (!exist)
710 hwif->proc = create_proc_entry(hwif->name, S_IFDIR, proc_ide_root);
711 if (!hwif->proc)
712 return;
713 if (!exist)
714 ide_add_proc_entries(hwif->proc, hwif_entries, hwif);
715 create_proc_ide_drives(hwif);
719 static void destroy_proc_ide_interfaces(void)
721 int h;
723 for (h = 0; h < MAX_HWIFS; h++) {
724 ide_hwif_t *hwif = &ide_hwifs[h];
725 int exist = (hwif->proc != NULL);
727 #if 0
728 if (!hwif->present)
729 continue;
730 #endif
731 if (exist) {
732 destroy_proc_ide_drives(hwif);
733 ide_remove_proc_entries(hwif->proc, hwif_entries);
734 remove_proc_entry(hwif->name, proc_ide_root);
735 hwif->proc = NULL;
736 } else
737 continue;
741 void proc_ide_create(void)
743 struct proc_dir_entry *ent;
744 proc_ide_root = create_proc_entry("ide", S_IFDIR, 0);
745 if (!proc_ide_root) return;
746 create_proc_ide_interfaces();
748 ent = create_proc_entry("drivers", 0, proc_ide_root);
749 if (!ent) return;
750 ent->read_proc = proc_ide_read_drivers;
751 #ifdef CONFIG_BLK_DEV_VIA82C586
752 if (via_display_info) {
753 ent = create_proc_entry("via", 0, proc_ide_root);
754 ent->get_info = via_display_info;
756 #endif /* CONFIG_BLK_DEV_VIA82C586 */
757 #ifdef CONFIG_BLK_DEV_ALI15X3
758 if (ali_display_info) {
759 ent = create_proc_entry("ali", 0, proc_ide_root);
760 ent->get_info = ali_display_info;
762 #endif /* CONFIG_BLK_DEV_ALI15X3 */
765 void proc_ide_destroy(void)
768 * Mmmm.. does this free up all resources,
769 * or do we need to do a more proper cleanup here ??
771 #ifdef CONFIG_BLK_DEV_VIA82C586
772 if (via_display_info)
773 remove_proc_entry("ide/via",0);
774 #endif /* CONFIG_BLK_DEV_VIA82C586 */
775 #ifdef CONFIG_BLK_DEV_ALI15X3
776 if (ali_display_info)
777 remove_proc_entry("ide/ali",0);
778 #endif /* CONFIG_BLK_DEV_ALI15X3 */
779 remove_proc_entry("ide/drivers", 0);
780 destroy_proc_ide_interfaces();
781 remove_proc_entry("ide", 0);