x86 setup: correct the base in the GDT_ENTRY() macro
[linux-2.6/linux-loongson.git] / drivers / ide / ide-proc.c
blobaa663e7f46f2f4b29ebc3fad6fe612a6166ffc3e
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>
7 * Some code was moved here from ide.c, see it for original copyrights.
8 */
11 * This is the /proc/ide/ filesystem implementation.
13 * Drive/Driver settings can be retrieved by reading the drive's
14 * "settings" files. e.g. "cat /proc/ide0/hda/settings"
15 * To write a new value "val" into a specific setting "name", use:
16 * echo "name:val" >/proc/ide/ide0/hda/settings
18 * Also useful, "cat /proc/ide0/hda/[identify, smart_values,
19 * smart_thresholds, capabilities]" will issue an IDENTIFY /
20 * PACKET_IDENTIFY / SMART_READ_VALUES / SMART_READ_THRESHOLDS /
21 * SENSE CAPABILITIES command to /dev/hda, and then dump out the
22 * returned data as 256 16-bit words. The "hdparm" utility will
23 * be updated someday soon to use this mechanism.
27 #include <linux/module.h>
29 #include <asm/uaccess.h>
30 #include <linux/errno.h>
31 #include <linux/proc_fs.h>
32 #include <linux/stat.h>
33 #include <linux/mm.h>
34 #include <linux/pci.h>
35 #include <linux/ctype.h>
36 #include <linux/hdreg.h>
37 #include <linux/ide.h>
38 #include <linux/seq_file.h>
40 #include <asm/io.h>
42 static struct proc_dir_entry *proc_ide_root;
44 static int proc_ide_read_imodel
45 (char *page, char **start, off_t off, int count, int *eof, void *data)
47 ide_hwif_t *hwif = (ide_hwif_t *) data;
48 int len;
49 const char *name;
52 * Neither ide_unknown nor ide_forced should be set at this point.
54 switch (hwif->chipset) {
55 case ide_generic: name = "generic"; break;
56 case ide_pci: name = "pci"; break;
57 case ide_cmd640: name = "cmd640"; break;
58 case ide_dtc2278: name = "dtc2278"; break;
59 case ide_ali14xx: name = "ali14xx"; break;
60 case ide_qd65xx: name = "qd65xx"; break;
61 case ide_umc8672: name = "umc8672"; break;
62 case ide_ht6560b: name = "ht6560b"; break;
63 case ide_rz1000: name = "rz1000"; break;
64 case ide_trm290: name = "trm290"; break;
65 case ide_cmd646: name = "cmd646"; break;
66 case ide_cy82c693: name = "cy82c693"; break;
67 case ide_4drives: name = "4drives"; break;
68 case ide_pmac: name = "mac-io"; break;
69 case ide_au1xxx: name = "au1xxx"; break;
70 case ide_etrax100: name = "etrax100"; break;
71 case ide_acorn: name = "acorn"; break;
72 default: name = "(unknown)"; break;
74 len = sprintf(page, "%s\n", name);
75 PROC_IDE_READ_RETURN(page,start,off,count,eof,len);
78 static int proc_ide_read_mate
79 (char *page, char **start, off_t off, int count, int *eof, void *data)
81 ide_hwif_t *hwif = (ide_hwif_t *) data;
82 int len;
84 if (hwif && hwif->mate && hwif->mate->present)
85 len = sprintf(page, "%s\n", hwif->mate->name);
86 else
87 len = sprintf(page, "(none)\n");
88 PROC_IDE_READ_RETURN(page,start,off,count,eof,len);
91 static int proc_ide_read_channel
92 (char *page, char **start, off_t off, int count, int *eof, void *data)
94 ide_hwif_t *hwif = (ide_hwif_t *) data;
95 int len;
97 page[0] = hwif->channel ? '1' : '0';
98 page[1] = '\n';
99 len = 2;
100 PROC_IDE_READ_RETURN(page,start,off,count,eof,len);
103 static int proc_ide_read_identify
104 (char *page, char **start, off_t off, int count, int *eof, void *data)
106 ide_drive_t *drive = (ide_drive_t *)data;
107 int len = 0, i = 0;
108 int err = 0;
110 len = sprintf(page, "\n");
112 if (drive) {
113 unsigned short *val = (unsigned short *) page;
115 err = taskfile_lib_get_identify(drive, page);
116 if (!err) {
117 char *out = ((char *)page) + (SECTOR_WORDS * 4);
118 page = out;
119 do {
120 out += sprintf(out, "%04x%c",
121 le16_to_cpu(*val), (++i & 7) ? ' ' : '\n');
122 val += 1;
123 } while (i < (SECTOR_WORDS * 2));
124 len = out - page;
127 PROC_IDE_READ_RETURN(page,start,off,count,eof,len);
131 * __ide_add_setting - add an ide setting option
132 * @drive: drive to use
133 * @name: setting name
134 * @rw: true if the function is read write
135 * @data_type: type of data
136 * @min: range minimum
137 * @max: range maximum
138 * @mul_factor: multiplication scale
139 * @div_factor: divison scale
140 * @data: private data field
141 * @set: setting
142 * @auto_remove: setting auto removal flag
144 * Removes the setting named from the device if it is present.
145 * The function takes the settings_lock to protect against
146 * parallel changes. This function must not be called from IRQ
147 * context. Returns 0 on success or -1 on failure.
149 * BUGS: This code is seriously over-engineered. There is also
150 * magic about how the driver specific features are setup. If
151 * a driver is attached we assume the driver settings are auto
152 * remove.
155 static int __ide_add_setting(ide_drive_t *drive, const char *name, int rw, int data_type, int min, int max, int mul_factor, int div_factor, void *data, ide_procset_t *set, int auto_remove)
157 ide_settings_t **p = (ide_settings_t **) &drive->settings, *setting = NULL;
159 mutex_lock(&ide_setting_mtx);
160 while ((*p) && strcmp((*p)->name, name) < 0)
161 p = &((*p)->next);
162 if ((setting = kzalloc(sizeof(*setting), GFP_KERNEL)) == NULL)
163 goto abort;
164 if ((setting->name = kmalloc(strlen(name) + 1, GFP_KERNEL)) == NULL)
165 goto abort;
166 strcpy(setting->name, name);
167 setting->rw = rw;
168 setting->data_type = data_type;
169 setting->min = min;
170 setting->max = max;
171 setting->mul_factor = mul_factor;
172 setting->div_factor = div_factor;
173 setting->data = data;
174 setting->set = set;
176 setting->next = *p;
177 if (auto_remove)
178 setting->auto_remove = 1;
179 *p = setting;
180 mutex_unlock(&ide_setting_mtx);
181 return 0;
182 abort:
183 mutex_unlock(&ide_setting_mtx);
184 kfree(setting);
185 return -1;
188 int ide_add_setting(ide_drive_t *drive, const char *name, int rw, int data_type, int min, int max, int mul_factor, int div_factor, void *data, ide_procset_t *set)
190 return __ide_add_setting(drive, name, rw, data_type, min, max, mul_factor, div_factor, data, set, 1);
193 EXPORT_SYMBOL(ide_add_setting);
196 * __ide_remove_setting - remove an ide setting option
197 * @drive: drive to use
198 * @name: setting name
200 * Removes the setting named from the device if it is present.
201 * The caller must hold the setting semaphore.
204 static void __ide_remove_setting (ide_drive_t *drive, char *name)
206 ide_settings_t **p, *setting;
208 p = (ide_settings_t **) &drive->settings;
210 while ((*p) && strcmp((*p)->name, name))
211 p = &((*p)->next);
212 if ((setting = (*p)) == NULL)
213 return;
215 (*p) = setting->next;
217 kfree(setting->name);
218 kfree(setting);
222 * auto_remove_settings - remove driver specific settings
223 * @drive: drive
225 * Automatically remove all the driver specific settings for this
226 * drive. This function may not be called from IRQ context. The
227 * caller must hold ide_setting_mtx.
230 static void auto_remove_settings (ide_drive_t *drive)
232 ide_settings_t *setting;
233 repeat:
234 setting = drive->settings;
235 while (setting) {
236 if (setting->auto_remove) {
237 __ide_remove_setting(drive, setting->name);
238 goto repeat;
240 setting = setting->next;
245 * ide_find_setting_by_name - find a drive specific setting
246 * @drive: drive to scan
247 * @name: setting name
249 * Scan's the device setting table for a matching entry and returns
250 * this or NULL if no entry is found. The caller must hold the
251 * setting semaphore
254 static ide_settings_t *ide_find_setting_by_name(ide_drive_t *drive, char *name)
256 ide_settings_t *setting = drive->settings;
258 while (setting) {
259 if (strcmp(setting->name, name) == 0)
260 break;
261 setting = setting->next;
263 return setting;
267 * ide_read_setting - read an IDE setting
268 * @drive: drive to read from
269 * @setting: drive setting
271 * Read a drive setting and return the value. The caller
272 * must hold the ide_setting_mtx when making this call.
274 * BUGS: the data return and error are the same return value
275 * so an error -EINVAL and true return of the same value cannot
276 * be told apart
279 static int ide_read_setting(ide_drive_t *drive, ide_settings_t *setting)
281 int val = -EINVAL;
282 unsigned long flags;
284 if ((setting->rw & SETTING_READ)) {
285 spin_lock_irqsave(&ide_lock, flags);
286 switch(setting->data_type) {
287 case TYPE_BYTE:
288 val = *((u8 *) setting->data);
289 break;
290 case TYPE_SHORT:
291 val = *((u16 *) setting->data);
292 break;
293 case TYPE_INT:
294 val = *((u32 *) setting->data);
295 break;
297 spin_unlock_irqrestore(&ide_lock, flags);
299 return val;
303 * ide_write_setting - read an IDE setting
304 * @drive: drive to read from
305 * @setting: drive setting
306 * @val: value
308 * Write a drive setting if it is possible. The caller
309 * must hold the ide_setting_mtx when making this call.
311 * BUGS: the data return and error are the same return value
312 * so an error -EINVAL and true return of the same value cannot
313 * be told apart
315 * FIXME: This should be changed to enqueue a special request
316 * to the driver to change settings, and then wait on a sema for completion.
317 * The current scheme of polling is kludgy, though safe enough.
320 static int ide_write_setting(ide_drive_t *drive, ide_settings_t *setting, int val)
322 if (!capable(CAP_SYS_ADMIN))
323 return -EACCES;
324 if (setting->set)
325 return setting->set(drive, val);
326 if (!(setting->rw & SETTING_WRITE))
327 return -EPERM;
328 if (val < setting->min || val > setting->max)
329 return -EINVAL;
330 if (ide_spin_wait_hwgroup(drive))
331 return -EBUSY;
332 switch (setting->data_type) {
333 case TYPE_BYTE:
334 *((u8 *) setting->data) = val;
335 break;
336 case TYPE_SHORT:
337 *((u16 *) setting->data) = val;
338 break;
339 case TYPE_INT:
340 *((u32 *) setting->data) = val;
341 break;
343 spin_unlock_irq(&ide_lock);
344 return 0;
347 static int set_xfer_rate (ide_drive_t *drive, int arg)
349 ide_task_t task;
350 int err;
352 if (arg < 0 || arg > 70)
353 return -EINVAL;
355 memset(&task, 0, sizeof(task));
356 task.tf.command = WIN_SETFEATURES;
357 task.tf.feature = SETFEATURES_XFER;
358 task.tf.nsect = (u8)arg;
359 task.tf_flags = IDE_TFLAG_OUT_FEATURE | IDE_TFLAG_OUT_NSECT |
360 IDE_TFLAG_IN_NSECT;
362 err = ide_no_data_taskfile(drive, &task);
364 if (!err && arg) {
365 ide_set_xfer_rate(drive, (u8) arg);
366 ide_driveid_update(drive);
368 return err;
372 * ide_add_generic_settings - generic ide settings
373 * @drive: drive being configured
375 * Add the generic parts of the system settings to the /proc files.
376 * The caller must not be holding the ide_setting_mtx.
379 void ide_add_generic_settings (ide_drive_t *drive)
382 * drive setting name read/write access data type min max mul_factor div_factor data pointer set function
384 __ide_add_setting(drive, "io_32bit", drive->no_io_32bit ? SETTING_READ : SETTING_RW, TYPE_BYTE, 0, 1 + (SUPPORT_VLB_SYNC << 1), 1, 1, &drive->io_32bit, set_io_32bit, 0);
385 __ide_add_setting(drive, "keepsettings", SETTING_RW, TYPE_BYTE, 0, 1, 1, 1, &drive->keep_settings, NULL, 0);
386 __ide_add_setting(drive, "nice1", SETTING_RW, TYPE_BYTE, 0, 1, 1, 1, &drive->nice1, NULL, 0);
387 __ide_add_setting(drive, "pio_mode", SETTING_WRITE, TYPE_BYTE, 0, 255, 1, 1, NULL, set_pio_mode, 0);
388 __ide_add_setting(drive, "unmaskirq", drive->no_unmask ? SETTING_READ : SETTING_RW, TYPE_BYTE, 0, 1, 1, 1, &drive->unmask, NULL, 0);
389 __ide_add_setting(drive, "using_dma", SETTING_RW, TYPE_BYTE, 0, 1, 1, 1, &drive->using_dma, set_using_dma, 0);
390 __ide_add_setting(drive, "init_speed", SETTING_RW, TYPE_BYTE, 0, 70, 1, 1, &drive->init_speed, NULL, 0);
391 __ide_add_setting(drive, "current_speed", SETTING_RW, TYPE_BYTE, 0, 70, 1, 1, &drive->current_speed, set_xfer_rate, 0);
392 __ide_add_setting(drive, "number", SETTING_RW, TYPE_BYTE, 0, 3, 1, 1, &drive->dn, NULL, 0);
395 static void proc_ide_settings_warn(void)
397 static int warned = 0;
399 if (warned)
400 return;
402 printk(KERN_WARNING "Warning: /proc/ide/hd?/settings interface is "
403 "obsolete, and will be removed soon!\n");
404 warned = 1;
407 static int proc_ide_read_settings
408 (char *page, char **start, off_t off, int count, int *eof, void *data)
410 ide_drive_t *drive = (ide_drive_t *) data;
411 ide_settings_t *setting = (ide_settings_t *) drive->settings;
412 char *out = page;
413 int len, rc, mul_factor, div_factor;
415 proc_ide_settings_warn();
417 mutex_lock(&ide_setting_mtx);
418 out += sprintf(out, "name\t\t\tvalue\t\tmin\t\tmax\t\tmode\n");
419 out += sprintf(out, "----\t\t\t-----\t\t---\t\t---\t\t----\n");
420 while(setting) {
421 mul_factor = setting->mul_factor;
422 div_factor = setting->div_factor;
423 out += sprintf(out, "%-24s", setting->name);
424 if ((rc = ide_read_setting(drive, setting)) >= 0)
425 out += sprintf(out, "%-16d", rc * mul_factor / div_factor);
426 else
427 out += sprintf(out, "%-16s", "write-only");
428 out += sprintf(out, "%-16d%-16d", (setting->min * mul_factor + div_factor - 1) / div_factor, setting->max * mul_factor / div_factor);
429 if (setting->rw & SETTING_READ)
430 out += sprintf(out, "r");
431 if (setting->rw & SETTING_WRITE)
432 out += sprintf(out, "w");
433 out += sprintf(out, "\n");
434 setting = setting->next;
436 len = out - page;
437 mutex_unlock(&ide_setting_mtx);
438 PROC_IDE_READ_RETURN(page,start,off,count,eof,len);
441 #define MAX_LEN 30
443 static int proc_ide_write_settings(struct file *file, const char __user *buffer,
444 unsigned long count, void *data)
446 ide_drive_t *drive = (ide_drive_t *) data;
447 char name[MAX_LEN + 1];
448 int for_real = 0;
449 unsigned long n;
450 ide_settings_t *setting;
451 char *buf, *s;
453 if (!capable(CAP_SYS_ADMIN))
454 return -EACCES;
456 proc_ide_settings_warn();
458 if (count >= PAGE_SIZE)
459 return -EINVAL;
461 s = buf = (char *)__get_free_page(GFP_USER);
462 if (!buf)
463 return -ENOMEM;
465 if (copy_from_user(buf, buffer, count)) {
466 free_page((unsigned long)buf);
467 return -EFAULT;
470 buf[count] = '\0';
473 * Skip over leading whitespace
475 while (count && isspace(*s)) {
476 --count;
477 ++s;
480 * Do one full pass to verify all parameters,
481 * then do another to actually write the new settings.
483 do {
484 char *p = s;
485 n = count;
486 while (n > 0) {
487 unsigned val;
488 char *q = p;
490 while (n > 0 && *p != ':') {
491 --n;
492 p++;
494 if (*p != ':')
495 goto parse_error;
496 if (p - q > MAX_LEN)
497 goto parse_error;
498 memcpy(name, q, p - q);
499 name[p - q] = 0;
501 if (n > 0) {
502 --n;
503 p++;
504 } else
505 goto parse_error;
507 val = simple_strtoul(p, &q, 10);
508 n -= q - p;
509 p = q;
510 if (n > 0 && !isspace(*p))
511 goto parse_error;
512 while (n > 0 && isspace(*p)) {
513 --n;
514 ++p;
517 mutex_lock(&ide_setting_mtx);
518 setting = ide_find_setting_by_name(drive, name);
519 if (!setting)
521 mutex_unlock(&ide_setting_mtx);
522 goto parse_error;
524 if (for_real)
525 ide_write_setting(drive, setting, val * setting->div_factor / setting->mul_factor);
526 mutex_unlock(&ide_setting_mtx);
528 } while (!for_real++);
529 free_page((unsigned long)buf);
530 return count;
531 parse_error:
532 free_page((unsigned long)buf);
533 printk("proc_ide_write_settings(): parse error\n");
534 return -EINVAL;
537 int proc_ide_read_capacity
538 (char *page, char **start, off_t off, int count, int *eof, void *data)
540 int len = sprintf(page,"%llu\n", (long long)0x7fffffff);
541 PROC_IDE_READ_RETURN(page,start,off,count,eof,len);
544 EXPORT_SYMBOL_GPL(proc_ide_read_capacity);
546 int proc_ide_read_geometry
547 (char *page, char **start, off_t off, int count, int *eof, void *data)
549 ide_drive_t *drive = (ide_drive_t *) data;
550 char *out = page;
551 int len;
553 out += sprintf(out,"physical %d/%d/%d\n",
554 drive->cyl, drive->head, drive->sect);
555 out += sprintf(out,"logical %d/%d/%d\n",
556 drive->bios_cyl, drive->bios_head, drive->bios_sect);
558 len = out - page;
559 PROC_IDE_READ_RETURN(page,start,off,count,eof,len);
562 EXPORT_SYMBOL(proc_ide_read_geometry);
564 static int proc_ide_read_dmodel
565 (char *page, char **start, off_t off, int count, int *eof, void *data)
567 ide_drive_t *drive = (ide_drive_t *) data;
568 struct hd_driveid *id = drive->id;
569 int len;
571 len = sprintf(page, "%.40s\n",
572 (id && id->model[0]) ? (char *)id->model : "(none)");
573 PROC_IDE_READ_RETURN(page,start,off,count,eof,len);
576 static int proc_ide_read_driver
577 (char *page, char **start, off_t off, int count, int *eof, void *data)
579 ide_drive_t *drive = (ide_drive_t *) data;
580 struct device *dev = &drive->gendev;
581 ide_driver_t *ide_drv;
582 int len;
584 if (dev->driver) {
585 ide_drv = container_of(dev->driver, ide_driver_t, gen_driver);
586 len = sprintf(page, "%s version %s\n",
587 dev->driver->name, ide_drv->version);
588 } else
589 len = sprintf(page, "ide-default version 0.9.newide\n");
590 PROC_IDE_READ_RETURN(page,start,off,count,eof,len);
593 static int ide_replace_subdriver(ide_drive_t *drive, const char *driver)
595 struct device *dev = &drive->gendev;
596 int ret = 1;
597 int err;
599 device_release_driver(dev);
600 /* FIXME: device can still be in use by previous driver */
601 strlcpy(drive->driver_req, driver, sizeof(drive->driver_req));
602 err = device_attach(dev);
603 if (err < 0)
604 printk(KERN_WARNING "IDE: %s: device_attach error: %d\n",
605 __FUNCTION__, err);
606 drive->driver_req[0] = 0;
607 if (dev->driver == NULL) {
608 err = device_attach(dev);
609 if (err < 0)
610 printk(KERN_WARNING
611 "IDE: %s: device_attach(2) error: %d\n",
612 __FUNCTION__, err);
614 if (dev->driver && !strcmp(dev->driver->name, driver))
615 ret = 0;
617 return ret;
620 static int proc_ide_write_driver
621 (struct file *file, const char __user *buffer, unsigned long count, void *data)
623 ide_drive_t *drive = (ide_drive_t *) data;
624 char name[32];
626 if (!capable(CAP_SYS_ADMIN))
627 return -EACCES;
628 if (count > 31)
629 count = 31;
630 if (copy_from_user(name, buffer, count))
631 return -EFAULT;
632 name[count] = '\0';
633 if (ide_replace_subdriver(drive, name))
634 return -EINVAL;
635 return count;
638 static int proc_ide_read_media
639 (char *page, char **start, off_t off, int count, int *eof, void *data)
641 ide_drive_t *drive = (ide_drive_t *) data;
642 const char *media;
643 int len;
645 switch (drive->media) {
646 case ide_disk: media = "disk\n";
647 break;
648 case ide_cdrom: media = "cdrom\n";
649 break;
650 case ide_tape: media = "tape\n";
651 break;
652 case ide_floppy:media = "floppy\n";
653 break;
654 case ide_optical:media = "optical\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 static ide_proc_entry_t generic_drive_entries[] = {
665 { "driver", S_IFREG|S_IRUGO, proc_ide_read_driver, proc_ide_write_driver },
666 { "identify", S_IFREG|S_IRUSR, proc_ide_read_identify, NULL },
667 { "media", S_IFREG|S_IRUGO, proc_ide_read_media, NULL },
668 { "model", S_IFREG|S_IRUGO, proc_ide_read_dmodel, NULL },
669 { "settings", S_IFREG|S_IRUSR|S_IWUSR,proc_ide_read_settings, proc_ide_write_settings },
670 { NULL, 0, NULL, NULL }
673 static void ide_add_proc_entries(struct proc_dir_entry *dir, ide_proc_entry_t *p, void *data)
675 struct proc_dir_entry *ent;
677 if (!dir || !p)
678 return;
679 while (p->name != NULL) {
680 ent = create_proc_entry(p->name, p->mode, dir);
681 if (!ent) return;
682 ent->data = data;
683 ent->read_proc = p->read_proc;
684 ent->write_proc = p->write_proc;
685 p++;
689 static void ide_remove_proc_entries(struct proc_dir_entry *dir, ide_proc_entry_t *p)
691 if (!dir || !p)
692 return;
693 while (p->name != NULL) {
694 remove_proc_entry(p->name, dir);
695 p++;
699 void ide_proc_register_driver(ide_drive_t *drive, ide_driver_t *driver)
701 ide_add_proc_entries(drive->proc, driver->proc, drive);
704 EXPORT_SYMBOL(ide_proc_register_driver);
707 * ide_proc_unregister_driver - remove driver specific data
708 * @drive: drive
709 * @driver: driver
711 * Clean up the driver specific /proc files and IDE settings
712 * for a given drive.
714 * Takes ide_setting_mtx and ide_lock.
715 * Caller must hold none of the locks.
718 void ide_proc_unregister_driver(ide_drive_t *drive, ide_driver_t *driver)
720 unsigned long flags;
722 ide_remove_proc_entries(drive->proc, driver->proc);
724 mutex_lock(&ide_setting_mtx);
725 spin_lock_irqsave(&ide_lock, flags);
727 * ide_setting_mtx protects the settings list
728 * ide_lock protects the use of settings
730 * so we need to hold both, ide_settings_sem because we want to
731 * modify the settings list, and ide_lock because we cannot take
732 * a setting out that is being used.
734 * OTOH both ide_{read,write}_setting are only ever used under
735 * ide_setting_mtx.
737 auto_remove_settings(drive);
738 spin_unlock_irqrestore(&ide_lock, flags);
739 mutex_unlock(&ide_setting_mtx);
742 EXPORT_SYMBOL(ide_proc_unregister_driver);
744 static void create_proc_ide_drives(ide_hwif_t *hwif)
746 int d;
747 struct proc_dir_entry *ent;
748 struct proc_dir_entry *parent = hwif->proc;
749 char name[64];
751 for (d = 0; d < MAX_DRIVES; d++) {
752 ide_drive_t *drive = &hwif->drives[d];
754 if (!drive->present)
755 continue;
756 if (drive->proc)
757 continue;
759 drive->proc = proc_mkdir(drive->name, parent);
760 if (drive->proc)
761 ide_add_proc_entries(drive->proc, generic_drive_entries, drive);
762 sprintf(name,"ide%d/%s", (drive->name[2]-'a')/2, drive->name);
763 ent = proc_symlink(drive->name, proc_ide_root, name);
764 if (!ent) return;
768 static void destroy_proc_ide_device(ide_hwif_t *hwif, ide_drive_t *drive)
770 if (drive->proc) {
771 ide_remove_proc_entries(drive->proc, generic_drive_entries);
772 remove_proc_entry(drive->name, proc_ide_root);
773 remove_proc_entry(drive->name, hwif->proc);
774 drive->proc = NULL;
778 static void destroy_proc_ide_drives(ide_hwif_t *hwif)
780 int d;
782 for (d = 0; d < MAX_DRIVES; d++) {
783 ide_drive_t *drive = &hwif->drives[d];
784 if (drive->proc)
785 destroy_proc_ide_device(hwif, drive);
789 static ide_proc_entry_t hwif_entries[] = {
790 { "channel", S_IFREG|S_IRUGO, proc_ide_read_channel, NULL },
791 { "mate", S_IFREG|S_IRUGO, proc_ide_read_mate, NULL },
792 { "model", S_IFREG|S_IRUGO, proc_ide_read_imodel, NULL },
793 { NULL, 0, NULL, NULL }
796 void ide_proc_register_port(ide_hwif_t *hwif)
798 if (!hwif->present)
799 return;
801 if (!hwif->proc) {
802 hwif->proc = proc_mkdir(hwif->name, proc_ide_root);
804 if (!hwif->proc)
805 return;
807 ide_add_proc_entries(hwif->proc, hwif_entries, hwif);
810 create_proc_ide_drives(hwif);
813 #ifdef CONFIG_BLK_DEV_IDEPCI
814 void ide_pci_create_host_proc(const char *name, get_info_t *get_info)
816 create_proc_info_entry(name, 0, proc_ide_root, get_info);
819 EXPORT_SYMBOL_GPL(ide_pci_create_host_proc);
820 #endif
822 void ide_proc_unregister_port(ide_hwif_t *hwif)
824 if (hwif->proc) {
825 destroy_proc_ide_drives(hwif);
826 ide_remove_proc_entries(hwif->proc, hwif_entries);
827 remove_proc_entry(hwif->name, proc_ide_root);
828 hwif->proc = NULL;
832 static int proc_print_driver(struct device_driver *drv, void *data)
834 ide_driver_t *ide_drv = container_of(drv, ide_driver_t, gen_driver);
835 struct seq_file *s = data;
837 seq_printf(s, "%s version %s\n", drv->name, ide_drv->version);
839 return 0;
842 static int ide_drivers_show(struct seq_file *s, void *p)
844 int err;
846 err = bus_for_each_drv(&ide_bus_type, NULL, s, proc_print_driver);
847 if (err < 0)
848 printk(KERN_WARNING "IDE: %s: bus_for_each_drv error: %d\n",
849 __FUNCTION__, err);
850 return 0;
853 static int ide_drivers_open(struct inode *inode, struct file *file)
855 return single_open(file, &ide_drivers_show, NULL);
858 static const struct file_operations ide_drivers_operations = {
859 .open = ide_drivers_open,
860 .read = seq_read,
861 .llseek = seq_lseek,
862 .release = single_release,
865 void proc_ide_create(void)
867 struct proc_dir_entry *entry;
869 proc_ide_root = proc_mkdir("ide", NULL);
871 if (!proc_ide_root)
872 return;
874 entry = create_proc_entry("drivers", 0, proc_ide_root);
875 if (entry)
876 entry->proc_fops = &ide_drivers_operations;
879 void proc_ide_destroy(void)
881 remove_proc_entry("drivers", proc_ide_root);
882 remove_proc_entry("ide", NULL);