2 * linux/drivers/block/ide-proc.c Version 1.03 January 2, 1998
4 * Copyright (C) 1997-1998 Mark Lord
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 your 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>
66 #include <linux/pci.h>
67 #include <linux/ctype.h>
68 #include <linux/ide.h>
73 #define MIN(a,b) (((a) < (b)) ? (a) : (b))
76 #ifdef CONFIG_BLK_DEV_AEC6210
77 extern byte aec6210_proc
;
78 int (*aec6210_display_info
)(char *, char **, off_t
, int) = NULL
;
79 #endif /* CONFIG_BLK_DEV_AEC6210 */
80 #ifdef CONFIG_BLK_DEV_ALI15X3
82 int (*ali_display_info
)(char *, char **, off_t
, int) = NULL
;
83 #endif /* CONFIG_BLK_DEV_ALI15X3 */
84 #ifdef CONFIG_BLK_DEV_AMD7409
85 extern byte amd7409_proc
;
86 int (*amd7409_display_info
)(char *, char **, off_t
, int) = NULL
;
87 #endif /* CONFIG_BLK_DEV_AMD7409 */
88 #ifdef CONFIG_BLK_DEV_CMD64X
89 extern byte cmd64x_proc
;
90 int (*cmd64x_display_info
)(char *, char **, off_t
, int) = NULL
;
91 #endif /* CONFIG_BLK_DEV_CMD64X */
92 #ifdef CONFIG_BLK_DEV_CS5530
93 extern byte cs5530_proc
;
94 int (*cs5530_display_info
)(char *, char **, off_t
, int) = NULL
;
95 #endif /* CONFIG_BLK_DEV_CS5530 */
96 #ifdef CONFIG_BLK_DEV_HPT34X
97 extern byte hpt34x_proc
;
98 int (*hpt34x_display_info
)(char *, char **, off_t
, int) = NULL
;
99 #endif /* CONFIG_BLK_DEV_HPT34X */
100 #ifdef CONFIG_BLK_DEV_HPT366
101 extern byte hpt366_proc
;
102 int (*hpt366_display_info
)(char *, char **, off_t
, int) = NULL
;
103 #endif /* CONFIG_BLK_DEV_HPT366 */
104 #ifdef CONFIG_BLK_DEV_PDC202XX
105 extern byte pdc202xx_proc
;
106 int (*pdc202xx_display_info
)(char *, char **, off_t
, int) = NULL
;
107 #endif /* CONFIG_BLK_DEV_PDC202XX */
108 #ifdef CONFIG_BLK_DEV_PIIX
109 extern byte piix_proc
;
110 int (*piix_display_info
)(char *, char **, off_t
, int) = NULL
;
111 #endif /* CONFIG_BLK_DEV_PIIX */
112 #ifdef CONFIG_BLK_DEV_SIS5513
113 extern byte sis_proc
;
114 int (*sis_display_info
)(char *, char **, off_t
, int) = NULL
;
115 #endif /* CONFIG_BLK_DEV_SIS5513 */
116 #ifdef CONFIG_BLK_DEV_VIA82CXXX
117 extern byte via_proc
;
118 int (*via_display_info
)(char *, char **, off_t
, int) = NULL
;
119 #endif /* CONFIG_BLK_DEV_VIA82CXXX */
121 static int ide_getxdigit(char c
)
126 else if (isxdigit(c
))
127 digit
= tolower(c
) - 'a' + 10;
133 static int xx_xx_parse_error (const char *data
, unsigned long len
, const char *msg
)
137 if (len
>= sizeof(errbuf
))
138 len
= sizeof(errbuf
) - 1;
139 for (i
= 0; i
< len
; ++i
) {
148 printk("proc_ide: error: %s: '%s'\n", msg
, errbuf
);
152 static struct proc_dir_entry
* proc_ide_root
= NULL
;
154 static int proc_ide_write_config
155 (struct file
*file
, const char *buffer
, unsigned long count
, void *data
)
157 ide_hwif_t
*hwif
= (ide_hwif_t
*)data
;
159 unsigned long startn
= 0, n
, flags
;
160 const char *start
= NULL
, *msg
= NULL
;
162 if (!capable(CAP_SYS_ADMIN
))
165 * Skip over leading whitespace
167 while (count
&& isspace(*buffer
)) {
172 * Do one full pass to verify all parameters,
173 * then do another to actually write the regs.
175 save_flags(flags
); /* all CPUs */
179 unsigned long timeout
= jiffies
+ (3 * HZ
);
180 ide_hwgroup_t
*mygroup
= (ide_hwgroup_t
*)(hwif
->hwgroup
);
181 ide_hwgroup_t
*mategroup
= NULL
;
182 if (hwif
->mate
&& hwif
->mate
->hwgroup
)
183 mategroup
= (ide_hwgroup_t
*)(hwif
->mate
->hwgroup
);
184 cli(); /* all CPUs; ensure all writes are done together */
185 while (mygroup
->busy
|| (mategroup
&& mategroup
->busy
)) {
186 sti(); /* all CPUs */
187 if (0 < (signed long)(jiffies
- timeout
)) {
188 printk("/proc/ide/%s/config: channel(s) busy, cannot write\n", hwif
->name
);
189 restore_flags(flags
); /* all CPUs */
192 cli(); /* all CPUs */
199 unsigned int reg
= 0, val
= 0, is_pci
;
203 case 'R': is_pci
= 0;
205 case 'P': is_pci
= 1;
206 #ifdef CONFIG_BLK_DEV_IDEPCI
207 if (hwif
->pci_dev
&& !IDE_PCI_DEVID_EQ(hwif
->pci_devid
, IDE_PCI_DEVID_NULL
))
209 #endif /* CONFIG_BLK_DEV_IDEPCI */
210 msg
= "not a PCI device";
212 default: msg
= "expected 'R' or 'P'";
216 while (n
> 0 && (d
= ide_getxdigit(*p
)) >= 0) {
217 reg
= (reg
<< 4) | d
;
222 if (!digits
|| (digits
> 4) || (is_pci
&& reg
> 0xff)) {
223 msg
= "bad/missing register number";
226 if (n
-- == 0 || *p
++ != ':') {
231 while (n
> 0 && (d
= ide_getxdigit(*p
)) >= 0) {
232 val
= (val
<< 4) | d
;
237 if (digits
!= 2 && digits
!= 4 && digits
!= 8) {
238 msg
= "bad data, 2/4/8 digits required";
241 if (n
> 0 && !isspace(*p
)) {
242 msg
= "expected whitespace after data";
245 while (n
> 0 && isspace(*p
)) {
249 #ifdef CONFIG_BLK_DEV_IDEPCI
250 if (is_pci
&& (reg
& ((digits
>> 1) - 1))) {
251 msg
= "misaligned access";
254 #endif /* CONFIG_BLK_DEV_IDEPCI */
257 printk("proc_ide_write_config: type=%c, reg=0x%x, val=0x%x, digits=%d\n", is_pci
? "PCI" : "non-PCI", reg
, val
, digits
);
260 #ifdef CONFIG_BLK_DEV_IDEPCI
262 struct pci_dev
*dev
= hwif
->pci_dev
;
264 case 2: msg
= "byte";
265 rc
= pci_write_config_byte(dev
, reg
, val
);
267 case 4: msg
= "word";
268 rc
= pci_write_config_word(dev
, reg
, val
);
270 case 8: msg
= "dword";
271 rc
= pci_write_config_dword(dev
, reg
, val
);
275 restore_flags(flags
); /* all CPUs */
276 printk("proc_ide_write_config: error writing %s at bus %02x dev %02x reg 0x%x value 0x%x\n",
277 msg
, dev
->bus
->number
, dev
->devfn
, reg
, val
);
278 printk("proc_ide_write_config: error %d\n", rc
);
281 #endif /* CONFIG_BLK_DEV_IDEPCI */
282 } else { /* not pci */
283 #if !defined(__mc68000__) && !defined(CONFIG_APUS)
288 * unless you can explain me what it really does.
289 * On m68k, we don't have outw() and outl() yet,
290 * and I need a good reason to implement it.
292 * BTW, IMHO the main remaining portability problem with the IDE driver
293 * is that it mixes IO (ioport) and MMIO (iomem) access on different platforms.
295 * I think all accesses should be done using
297 * ide_in[bwl](ide_device_instance, offset)
298 * ide_out[bwl](ide_device_instance, value, offset)
300 * so the architecture specific code can #define ide_{in,out}[bwl] to the
301 * appropriate function.
305 case 2: outb(val
, reg
);
307 case 4: outw(val
, reg
);
309 case 8: outl(val
, reg
);
312 #endif /* !__mc68000__ && !CONFIG_APUS */
316 } while (!for_real
++);
317 restore_flags(flags
); /* all CPUs */
320 restore_flags(flags
); /* all CPUs */
321 printk("parse error\n");
322 return xx_xx_parse_error(start
, startn
, msg
);
325 static int proc_ide_read_config
326 (char *page
, char **start
, off_t off
, int count
, int *eof
, void *data
)
331 #ifdef CONFIG_BLK_DEV_IDEPCI
332 ide_hwif_t
*hwif
= (ide_hwif_t
*)data
;
333 struct pci_dev
*dev
= hwif
->pci_dev
;
334 if (!IDE_PCI_DEVID_EQ(hwif
->pci_devid
, IDE_PCI_DEVID_NULL
) && dev
&& dev
->bus
) {
337 out
+= sprintf(out
, "pci bus %02x device %02x vid %04x did %04x channel %d\n",
338 dev
->bus
->number
, dev
->devfn
, hwif
->pci_devid
.vid
, hwif
->pci_devid
.did
, hwif
->channel
);
341 int rc
= pci_read_config_byte(dev
, reg
, &val
);
343 printk("proc_ide_read_config: error %d reading bus %02x dev %02x reg 0x%02x\n",
344 rc
, dev
->bus
->number
, dev
->devfn
, reg
);
345 out
+= sprintf(out
, "??%c", (++reg
& 0xf) ? ' ' : '\n');
347 out
+= sprintf(out
, "%02x%c", val
, (++reg
& 0xf) ? ' ' : '\n');
348 } while (reg
< 0x100);
350 #endif /* CONFIG_BLK_DEV_IDEPCI */
351 out
+= sprintf(out
, "(none)\n");
353 PROC_IDE_READ_RETURN(page
,start
,off
,count
,eof
,len
);
357 static int ide_getdigit(char c
)
367 static int proc_ide_read_drivers
368 (char *page
, char **start
, off_t off
, int count
, int *eof
, void *data
)
372 ide_module_t
*p
= ide_modules
;
373 ide_driver_t
*driver
;
376 driver
= (ide_driver_t
*) p
->info
;
378 out
+= sprintf(out
, "%s version %s\n", driver
->name
, driver
->version
);
382 PROC_IDE_READ_RETURN(page
,start
,off
,count
,eof
,len
);
385 static int proc_ide_read_imodel
386 (char *page
, char **start
, off_t off
, int count
, int *eof
, void *data
)
388 ide_hwif_t
*hwif
= (ide_hwif_t
*) data
;
392 switch (hwif
->chipset
) {
393 case ide_unknown
: name
= "(none)"; break;
394 case ide_generic
: name
= "generic"; break;
395 case ide_pci
: name
= "pci"; break;
396 case ide_cmd640
: name
= "cmd640"; break;
397 case ide_dtc2278
: name
= "dtc2278"; break;
398 case ide_ali14xx
: name
= "ali14xx"; break;
399 case ide_qd6580
: name
= "qd6580"; break;
400 case ide_umc8672
: name
= "umc8672"; break;
401 case ide_ht6560b
: name
= "ht6560b"; break;
402 case ide_pdc4030
: name
= "pdc4030"; break;
403 case ide_rz1000
: name
= "rz1000"; break;
404 case ide_trm290
: name
= "trm290"; break;
405 case ide_cmd646
: name
= "cmd646"; break;
406 case ide_cy82c693
: name
= "cy82c693"; break;
407 case ide_4drives
: name
= "4drives"; break;
408 case ide_pmac
: name
= "mac-io"; break;
409 default: name
= "(unknown)"; break;
411 len
= sprintf(page
, "%s\n", name
);
412 PROC_IDE_READ_RETURN(page
,start
,off
,count
,eof
,len
);
415 static int proc_ide_read_mate
416 (char *page
, char **start
, off_t off
, int count
, int *eof
, void *data
)
418 ide_hwif_t
*hwif
= (ide_hwif_t
*) data
;
421 if (hwif
&& hwif
->mate
&& hwif
->mate
->present
)
422 len
= sprintf(page
, "%s\n", hwif
->mate
->name
);
424 len
= sprintf(page
, "(none)\n");
425 PROC_IDE_READ_RETURN(page
,start
,off
,count
,eof
,len
);
428 static int proc_ide_read_channel
429 (char *page
, char **start
, off_t off
, int count
, int *eof
, void *data
)
431 ide_hwif_t
*hwif
= (ide_hwif_t
*) data
;
434 page
[0] = hwif
->channel
? '1' : '0';
437 PROC_IDE_READ_RETURN(page
,start
,off
,count
,eof
,len
);
440 static int proc_ide_get_identify(ide_drive_t
*drive
, byte
*buf
)
442 return ide_wait_cmd(drive
, (drive
->media
== ide_disk
) ? WIN_IDENTIFY
: WIN_PIDENTIFY
, 0, 0, 1, buf
);
445 static int proc_ide_read_identify
446 (char *page
, char **start
, off_t off
, int count
, int *eof
, void *data
)
448 ide_drive_t
*drive
= (ide_drive_t
*)data
;
451 if (drive
&& !proc_ide_get_identify(drive
, page
)) {
452 unsigned short *val
= ((unsigned short *)page
) + 2;
453 char *out
= ((char *)val
) + (SECTOR_WORDS
* 4);
456 out
+= sprintf(out
, "%04x%c", le16_to_cpu(*val
), (++i
& 7) ? ' ' : '\n');
458 } while (i
< (SECTOR_WORDS
* 2));
462 len
= sprintf(page
, "\n");
463 PROC_IDE_READ_RETURN(page
,start
,off
,count
,eof
,len
);
466 static int proc_ide_read_settings
467 (char *page
, char **start
, off_t off
, int count
, int *eof
, void *data
)
469 ide_drive_t
*drive
= (ide_drive_t
*) data
;
470 ide_settings_t
*setting
= (ide_settings_t
*) drive
->settings
;
472 int len
, rc
, mul_factor
, div_factor
;
474 out
+= sprintf(out
, "name\t\t\tvalue\t\tmin\t\tmax\t\tmode\n");
475 out
+= sprintf(out
, "----\t\t\t-----\t\t---\t\t---\t\t----\n");
477 mul_factor
= setting
->mul_factor
;
478 div_factor
= setting
->div_factor
;
479 out
+= sprintf(out
, "%-24s", setting
->name
);
480 if ((rc
= ide_read_setting(drive
, setting
)) >= 0)
481 out
+= sprintf(out
, "%-16d", rc
* mul_factor
/ div_factor
);
483 out
+= sprintf(out
, "%-16s", "write-only");
484 out
+= sprintf(out
, "%-16d%-16d", (setting
->min
* mul_factor
+ div_factor
- 1) / div_factor
, setting
->max
* mul_factor
/ div_factor
);
485 if (setting
->rw
& SETTING_READ
)
486 out
+= sprintf(out
, "r");
487 if (setting
->rw
& SETTING_WRITE
)
488 out
+= sprintf(out
, "w");
489 out
+= sprintf(out
, "\n");
490 setting
= setting
->next
;
493 PROC_IDE_READ_RETURN(page
,start
,off
,count
,eof
,len
);
498 static int proc_ide_write_settings
499 (struct file
*file
, const char *buffer
, unsigned long count
, void *data
)
501 ide_drive_t
*drive
= (ide_drive_t
*) data
;
502 char name
[MAX_LEN
+ 1];
503 int for_real
= 0, len
;
505 const char *start
= NULL
;
506 ide_settings_t
*setting
;
508 if (!capable(CAP_SYS_ADMIN
))
511 * Skip over leading whitespace
513 while (count
&& isspace(*buffer
)) {
518 * Do one full pass to verify all parameters,
519 * then do another to actually write the new settings.
527 unsigned int val
= 0;
530 while (n
> 0 && *p
!= ':') {
536 len
= IDE_MIN(p
- start
, MAX_LEN
);
537 strncpy(name
, start
, IDE_MIN(len
, MAX_LEN
));
547 while (n
> 0 && (d
= ide_getdigit(*p
)) >= 0) {
548 val
= (val
* 10) + d
;
553 if (n
> 0 && !isspace(*p
))
555 while (n
> 0 && isspace(*p
)) {
559 setting
= ide_find_setting_by_name(drive
, name
);
564 ide_write_setting(drive
, setting
, val
* setting
->div_factor
/ setting
->mul_factor
);
566 } while (!for_real
++);
569 printk("proc_ide_write_settings(): parse error\n");
573 int proc_ide_read_capacity
574 (char *page
, char **start
, off_t off
, int count
, int *eof
, void *data
)
576 ide_drive_t
*drive
= (ide_drive_t
*) data
;
577 ide_driver_t
*driver
= (ide_driver_t
*) drive
->driver
;
581 len
= sprintf(page
, "(none)\n");
583 len
= sprintf(page
,"%li\n", ((ide_driver_t
*)drive
->driver
)->capacity(drive
));
584 PROC_IDE_READ_RETURN(page
,start
,off
,count
,eof
,len
);
587 int proc_ide_read_geometry
588 (char *page
, char **start
, off_t off
, int count
, int *eof
, void *data
)
590 ide_drive_t
*drive
= (ide_drive_t
*) data
;
594 out
+= sprintf(out
,"physical %d/%d/%d\n", drive
->cyl
, drive
->head
, drive
->sect
);
595 out
+= sprintf(out
,"logical %d/%d/%d\n", drive
->bios_cyl
, drive
->bios_head
, drive
->bios_sect
);
597 PROC_IDE_READ_RETURN(page
,start
,off
,count
,eof
,len
);
600 static int proc_ide_read_dmodel
601 (char *page
, char **start
, off_t off
, int count
, int *eof
, void *data
)
603 ide_drive_t
*drive
= (ide_drive_t
*) data
;
604 struct hd_driveid
*id
= drive
->id
;
607 len
= sprintf(page
, "%.40s\n", (id
&& id
->model
[0]) ? (char *)id
->model
: "(none)");
608 PROC_IDE_READ_RETURN(page
,start
,off
,count
,eof
,len
);
611 static int proc_ide_read_driver
612 (char *page
, char **start
, off_t off
, int count
, int *eof
, void *data
)
614 ide_drive_t
*drive
= (ide_drive_t
*) data
;
615 ide_driver_t
*driver
= (ide_driver_t
*) drive
->driver
;
619 len
= sprintf(page
, "(none)\n");
621 len
= sprintf(page
, "%s version %s\n", driver
->name
, driver
->version
);
622 PROC_IDE_READ_RETURN(page
,start
,off
,count
,eof
,len
);
625 static int proc_ide_write_driver
626 (struct file
*file
, const char *buffer
, unsigned long count
, void *data
)
628 ide_drive_t
*drive
= (ide_drive_t
*) data
;
630 if (!capable(CAP_SYS_ADMIN
))
632 if (ide_replace_subdriver(drive
, buffer
))
637 static int proc_ide_read_media
638 (char *page
, char **start
, off_t off
, int count
, int *eof
, void *data
)
640 ide_drive_t
*drive
= (ide_drive_t
*) data
;
644 switch (drive
->media
) {
645 case ide_disk
: media
= "disk\n";
647 case ide_cdrom
: media
= "cdrom\n";
649 case ide_tape
: media
= "tape\n";
651 case ide_floppy
:media
= "floppy\n";
653 default: media
= "UNKNOWN\n";
658 PROC_IDE_READ_RETURN(page
,start
,off
,count
,eof
,len
);
661 static ide_proc_entry_t generic_drive_entries
[] = {
662 { "driver", S_IFREG
|S_IRUGO
, proc_ide_read_driver
, proc_ide_write_driver
},
663 { "identify", S_IFREG
|S_IRUSR
, proc_ide_read_identify
, NULL
},
664 { "media", S_IFREG
|S_IRUGO
, proc_ide_read_media
, NULL
},
665 { "model", S_IFREG
|S_IRUGO
, proc_ide_read_dmodel
, NULL
},
666 { "settings", S_IFREG
|S_IRUSR
|S_IWUSR
,proc_ide_read_settings
, proc_ide_write_settings
},
667 { NULL
, 0, NULL
, NULL
}
670 void ide_add_proc_entries(struct proc_dir_entry
*dir
, ide_proc_entry_t
*p
, void *data
)
672 struct proc_dir_entry
*ent
;
676 while (p
->name
!= NULL
) {
677 ent
= create_proc_entry(p
->name
, p
->mode
, dir
);
681 ent
->read_proc
= p
->read_proc
;
682 ent
->write_proc
= p
->write_proc
;
687 void ide_remove_proc_entries(struct proc_dir_entry
*dir
, ide_proc_entry_t
*p
)
691 while (p
->name
!= NULL
) {
692 remove_proc_entry(p
->name
, dir
);
697 static void create_proc_ide_drives(ide_hwif_t
*hwif
)
700 struct proc_dir_entry
*ent
;
701 struct proc_dir_entry
*parent
= hwif
->proc
;
704 for (d
= 0; d
< MAX_DRIVES
; d
++) {
705 ide_drive_t
*drive
= &hwif
->drives
[d
];
706 ide_driver_t
*driver
= drive
->driver
;
713 drive
->proc
= proc_mkdir(drive
->name
, parent
);
715 ide_add_proc_entries(drive
->proc
, generic_drive_entries
, drive
);
717 ide_add_proc_entries(drive
->proc
, generic_subdriver_entries
, drive
);
718 ide_add_proc_entries(drive
->proc
, driver
->proc
, drive
);
721 sprintf(name
,"ide%d/%s", (drive
->name
[2]-'a')/2, drive
->name
);
722 ent
= proc_symlink(drive
->name
, proc_ide_root
, name
);
727 void destroy_proc_ide_drives(ide_hwif_t
*hwif
)
731 for (d
= 0; d
< MAX_DRIVES
; d
++) {
732 ide_drive_t
*drive
= &hwif
->drives
[d
];
733 ide_driver_t
*driver
= drive
->driver
;
738 ide_remove_proc_entries(drive
->proc
, driver
->proc
);
739 ide_remove_proc_entries(drive
->proc
, generic_drive_entries
);
740 remove_proc_entry(drive
->name
, proc_ide_root
);
741 remove_proc_entry(drive
->name
, hwif
->proc
);
746 static ide_proc_entry_t hwif_entries
[] = {
747 { "channel", S_IFREG
|S_IRUGO
, proc_ide_read_channel
, NULL
},
748 { "config", S_IFREG
|S_IRUGO
|S_IWUSR
,proc_ide_read_config
, proc_ide_write_config
},
749 { "mate", S_IFREG
|S_IRUGO
, proc_ide_read_mate
, NULL
},
750 { "model", S_IFREG
|S_IRUGO
, proc_ide_read_imodel
, NULL
},
751 { NULL
, 0, NULL
, NULL
}
754 void create_proc_ide_interfaces(void)
758 for (h
= 0; h
< MAX_HWIFS
; h
++) {
759 ide_hwif_t
*hwif
= &ide_hwifs
[h
];
764 hwif
->proc
= proc_mkdir(hwif
->name
, proc_ide_root
);
767 ide_add_proc_entries(hwif
->proc
, hwif_entries
, hwif
);
769 create_proc_ide_drives(hwif
);
773 static void destroy_proc_ide_interfaces(void)
777 for (h
= 0; h
< MAX_HWIFS
; h
++) {
778 ide_hwif_t
*hwif
= &ide_hwifs
[h
];
779 int exist
= (hwif
->proc
!= NULL
);
785 destroy_proc_ide_drives(hwif
);
786 ide_remove_proc_entries(hwif
->proc
, hwif_entries
);
787 remove_proc_entry(hwif
->name
, proc_ide_root
);
794 void proc_ide_create(void)
796 proc_ide_root
= proc_mkdir("ide", 0);
797 if (!proc_ide_root
) return;
799 create_proc_ide_interfaces();
801 create_proc_read_entry("drivers", 0, proc_ide_root
,
802 proc_ide_read_drivers
, NULL
);
804 #ifdef CONFIG_BLK_DEV_AEC6210
805 if ((aec6210_display_info
) && (aec6210_proc
))
806 create_proc_info_entry("aec6210", 0, proc_ide_root
, aec6210_display_info
);
807 #endif /* CONFIG_BLK_DEV_AEC6210 */
808 #ifdef CONFIG_BLK_DEV_ALI15X3
809 if ((ali_display_info
) && (ali_proc
))
810 create_proc_info_entry("ali", 0, proc_ide_root
, ali_display_info
);
811 #endif /* CONFIG_BLK_DEV_ALI15X3 */
812 #ifdef CONFIG_BLK_DEV_AMD7409
813 if ((amd7409_display_info
) && (amd7409_proc
))
814 create_proc_info_entry("amd7409", 0, proc_ide_root
, amd7409_display_info
);
815 #endif /* CONFIG_BLK_DEV_AMD7409 */
816 #ifdef CONFIG_BLK_DEV_CMD64X
817 if ((cmd64x_display_info
) && (cmd64x_proc
))
818 create_proc_info_entry("cmd64x", 0, proc_ide_root
, cmd64x_display_info
);
819 #endif /* CONFIG_BLK_DEV_CMD64X */
820 #ifdef CONFIG_BLK_DEV_CS5530
821 if ((cs5530_display_info
) && (cs5530_proc
))
822 create_proc_info_entry("cs5530", 0, proc_ide_root
, cs5530_display_info
);
823 #endif /* CONFIG_BLK_DEV_CS5530 */
824 #ifdef CONFIG_BLK_DEV_HPT34X
825 if ((hpt34x_display_info
) && (hpt34x_proc
))
826 create_proc_info_entry("hpt34x", 0, proc_ide_root
, hpt34x_display_info
);
827 #endif /* CONFIG_BLK_DEV_HPT34X */
828 #ifdef CONFIG_BLK_DEV_HPT366
829 if ((hpt366_display_info
) && (hpt366_proc
))
830 create_proc_info_entry("hpt366", 0, proc_ide_root
, hpt366_display_info
);
831 #endif /* CONFIG_BLK_DEV_HPT366 */
832 #ifdef CONFIG_BLK_DEV_PDC202XX
833 if ((pdc202xx_display_info
) && (pdc202xx_proc
))
834 create_proc_info_entry("pdc202xx", 0, proc_ide_root
, pdc202xx_display_info
);
835 #endif /* CONFIG_BLK_DEV_PDC202XX */
836 #ifdef CONFIG_BLK_DEV_PIIX
837 if ((piix_display_info
) && (piix_proc
))
838 create_proc_info_entry("piix", 0, proc_ide_root
, piix_display_info
);
839 #endif /* CONFIG_BLK_DEV_PIIX */
840 #ifdef CONFIG_BLK_DEV_SIS5513
841 if ((sis_display_info
) && (sis_proc
))
842 create_proc_info_entry("sis", 0, proc_ide_root
, sis_display_info
);
843 #endif /* CONFIG_BLK_DEV_SIS5513 */
844 #ifdef CONFIG_BLK_DEV_VIA82CXXX
845 if ((via_display_info
) && (via_proc
))
846 create_proc_info_entry("via", 0, proc_ide_root
, via_display_info
);
847 #endif /* CONFIG_BLK_DEV_VIA82CXXX */
850 void proc_ide_destroy(void)
853 * Mmmm.. does this free up all resources,
854 * or do we need to do a more proper cleanup here ??
856 #ifdef CONFIG_BLK_DEV_AEC6210
857 if ((aec6210_display_info
) && (aec6210_proc
))
858 remove_proc_entry("ide/aec6210",0);
859 #endif /* CONFIG_BLK_DEV_AEC6210 */
860 #ifdef CONFIG_BLK_DEV_ALI15X3
861 if ((ali_display_info
) && (ali_proc
))
862 remove_proc_entry("ide/ali",0);
863 #endif /* CONFIG_BLK_DEV_ALI15X3 */
864 #ifdef CONFIG_BLK_DEV_AMD7409
865 if ((amd7409_display_info
) && (amd7409_proc
))
866 remove_proc_entry("ide/amd7409",0);
867 #endif /* CONFIG_BLK_DEV_AMD7409 */
868 #ifdef CONFIG_BLK_DEV_CMD64X
869 if ((cmd64x_display_info
) && (cmd64x_proc
))
870 remove_proc_entry("ide/cmd64x",0);
871 #endif /* CONFIG_BLK_DEV_CMD64X */
872 #ifdef CONFIG_BLK_DEV_CS5530
873 if ((cs5530_display_info
) && (cs5530_proc
))
874 remove_proc_entry("ide/cs5530",0);
875 #endif /* CONFIG_BLK_DEV_CS5530 */
876 #ifdef CONFIG_BLK_DEV_HPT34X
877 if ((hpt34x_display_info
) && (hpt34x_proc
))
878 remove_proc_entry("ide/hpt34x",0);
879 #endif /* CONFIG_BLK_DEV_HPT34X */
880 #ifdef CONFIG_BLK_DEV_HPT366
881 if ((hpt366_display_info
) && (hpt366_proc
))
882 remove_proc_entry("ide/hpt366",0);
883 #endif /* CONFIG_BLK_DEV_HPT366 */
884 #ifdef CONFIG_BLK_DEV_PDC202XX
885 if ((pdc202xx_display_info
) && (pdc202xx_proc
))
886 remove_proc_entry("ide/pdc202xx",0);
887 #endif /* CONFIG_BLK_DEV_PDC202XX */
888 #ifdef CONFIG_BLK_DEV_PIIX
889 if ((piix_display_info
) && (piix_proc
))
890 remove_proc_entry("ide/piix",0);
891 #endif /* CONFIG_BLK_DEV_PIIX */
892 #ifdef CONFIG_BLK_DEV_SIS5513
893 if ((sis_display_info
) && (sis_proc
))
894 remove_proc_entry("ide/sis", 0);
895 #endif /* CONFIG_BLK_DEV_SIS5513 */
896 #ifdef CONFIG_BLK_DEV_VIA82CXXX
897 if ((via_display_info
) && (via_proc
))
898 remove_proc_entry("ide/via",0);
899 #endif /* CONFIG_BLK_DEV_VIA82CXXX */
901 remove_proc_entry("ide/drivers", 0);
902 destroy_proc_ide_interfaces();
903 remove_proc_entry("ide", 0);