^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) // SPDX-License-Identifier: GPL-2.0-only
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) * Copyright (C) 1997-1998 Mark Lord
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) * Copyright (C) 2003 Red Hat
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) * Some code was moved here from ide.c, see it for original copyrights.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) * This is the /proc/ide/ filesystem implementation.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) * Drive/Driver settings can be retrieved by reading the drive's
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) * "settings" files. e.g. "cat /proc/ide0/hda/settings"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) * To write a new value "val" into a specific setting "name", use:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) * echo "name:val" >/proc/ide/ide0/hda/settings
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) #include <linux/uaccess.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) #include <linux/errno.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) #include <linux/proc_fs.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) #include <linux/stat.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) #include <linux/mm.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) #include <linux/pci.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) #include <linux/ctype.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) #include <linux/ide.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) #include <linux/seq_file.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) #include <linux/slab.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) #include <asm/io.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) static struct proc_dir_entry *proc_ide_root;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) static int ide_imodel_proc_show(struct seq_file *m, void *v)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) ide_hwif_t *hwif = (ide_hwif_t *) m->private;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) const char *name;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) switch (hwif->chipset) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) case ide_generic: name = "generic"; break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) case ide_pci: name = "pci"; break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) case ide_cmd640: name = "cmd640"; break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) case ide_dtc2278: name = "dtc2278"; break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) case ide_ali14xx: name = "ali14xx"; break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) case ide_qd65xx: name = "qd65xx"; break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) case ide_umc8672: name = "umc8672"; break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) case ide_ht6560b: name = "ht6560b"; break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) case ide_4drives: name = "4drives"; break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) case ide_pmac: name = "mac-io"; break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) case ide_au1xxx: name = "au1xxx"; break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) case ide_palm3710: name = "palm3710"; break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) case ide_acorn: name = "acorn"; break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) default: name = "(unknown)"; break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) seq_printf(m, "%s\n", name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) static int ide_mate_proc_show(struct seq_file *m, void *v)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) ide_hwif_t *hwif = (ide_hwif_t *) m->private;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) if (hwif && hwif->mate)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) seq_printf(m, "%s\n", hwif->mate->name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) seq_printf(m, "(none)\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) static int ide_channel_proc_show(struct seq_file *m, void *v)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) ide_hwif_t *hwif = (ide_hwif_t *) m->private;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) seq_printf(m, "%c\n", hwif->channel ? '1' : '0');
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) static int ide_identify_proc_show(struct seq_file *m, void *v)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) ide_drive_t *drive = (ide_drive_t *)m->private;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) u8 *buf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) if (!drive) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) seq_putc(m, '\n');
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89) buf = kmalloc(SECTOR_SIZE, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90) if (!buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92) if (taskfile_lib_get_identify(drive, buf) == 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93) __le16 *val = (__le16 *)buf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94) int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96) for (i = 0; i < SECTOR_SIZE / 2; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97) seq_printf(m, "%04x%c", le16_to_cpu(val[i]),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98) (i % 8) == 7 ? '\n' : ' ');
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) } else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) seq_putc(m, buf[0]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) kfree(buf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) * ide_find_setting - find a specific setting
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) * @st: setting table pointer
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) * @name: setting name
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) * Scan's the setting table for a matching entry and returns
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) * this or NULL if no entry is found. The caller must hold the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) * setting semaphore
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) static
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) const struct ide_proc_devset *ide_find_setting(const struct ide_proc_devset *st,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) char *name)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) while (st->name) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) if (strcmp(st->name, name) == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) st++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) return st->name ? st : NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) * ide_read_setting - read an IDE setting
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) * @drive: drive to read from
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) * @setting: drive setting
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) * Read a drive setting and return the value. The caller
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) * must hold the ide_setting_mtx when making this call.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) * BUGS: the data return and error are the same return value
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) * so an error -EINVAL and true return of the same value cannot
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) * be told apart
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) static int ide_read_setting(ide_drive_t *drive,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) const struct ide_proc_devset *setting)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) const struct ide_devset *ds = setting->setting;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) int val = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) if (ds->get)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) val = ds->get(drive);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) return val;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) * ide_write_setting - read an IDE setting
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) * @drive: drive to read from
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) * @setting: drive setting
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) * @val: value
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) * Write a drive setting if it is possible. The caller
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) * must hold the ide_setting_mtx when making this call.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) * BUGS: the data return and error are the same return value
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) * so an error -EINVAL and true return of the same value cannot
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) * be told apart
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) * FIXME: This should be changed to enqueue a special request
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) * to the driver to change settings, and then wait on a sema for completion.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) * The current scheme of polling is kludgy, though safe enough.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) static int ide_write_setting(ide_drive_t *drive,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) const struct ide_proc_devset *setting, int val)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) const struct ide_devset *ds = setting->setting;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) if (!capable(CAP_SYS_ADMIN))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) return -EACCES;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) if (!ds->set)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) return -EPERM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) if ((ds->flags & DS_SYNC)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) && (val < setting->min || val > setting->max))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) return ide_devset_execute(drive, ds, val);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) ide_devset_get(xfer_rate, current_speed);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) static int set_xfer_rate (ide_drive_t *drive, int arg)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) struct ide_cmd cmd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) if (arg < XFER_PIO_0 || arg > XFER_UDMA_6)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) memset(&cmd, 0, sizeof(cmd));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) cmd.tf.command = ATA_CMD_SET_FEATURES;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) cmd.tf.feature = SETFEATURES_XFER;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) cmd.tf.nsect = (u8)arg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) cmd.valid.out.tf = IDE_VALID_FEATURE | IDE_VALID_NSECT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) cmd.valid.in.tf = IDE_VALID_NSECT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) cmd.tf_flags = IDE_TFLAG_SET_XFER;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) return ide_no_data_taskfile(drive, &cmd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) ide_devset_rw(current_speed, xfer_rate);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) ide_devset_rw_field(init_speed, init_speed);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) ide_devset_rw_flag(nice1, IDE_DFLAG_NICE1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) ide_devset_ro_field(number, dn);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) static const struct ide_proc_devset ide_generic_settings[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) IDE_PROC_DEVSET(current_speed, 0, 70),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) IDE_PROC_DEVSET(init_speed, 0, 70),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) IDE_PROC_DEVSET(io_32bit, 0, 1 + (SUPPORT_VLB_SYNC << 1)),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) IDE_PROC_DEVSET(keepsettings, 0, 1),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) IDE_PROC_DEVSET(nice1, 0, 1),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) IDE_PROC_DEVSET(number, 0, 3),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) IDE_PROC_DEVSET(pio_mode, 0, 255),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) IDE_PROC_DEVSET(unmaskirq, 0, 1),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) IDE_PROC_DEVSET(using_dma, 0, 1),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) { NULL },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) static void proc_ide_settings_warn(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) printk_once(KERN_WARNING "Warning: /proc/ide/hd?/settings interface is "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) "obsolete, and will be removed soon!\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) static int ide_settings_proc_show(struct seq_file *m, void *v)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) const struct ide_proc_devset *setting, *g, *d;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) const struct ide_devset *ds;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) ide_drive_t *drive = (ide_drive_t *) m->private;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) int rc, mul_factor, div_factor;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) proc_ide_settings_warn();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) mutex_lock(&ide_setting_mtx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) g = ide_generic_settings;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) d = drive->settings;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) seq_printf(m, "name\t\t\tvalue\t\tmin\t\tmax\t\tmode\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) seq_printf(m, "----\t\t\t-----\t\t---\t\t---\t\t----\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) while (g->name || (d && d->name)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) /* read settings in the alphabetical order */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) if (g->name && d && d->name) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) if (strcmp(d->name, g->name) < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) setting = d++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) setting = g++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) } else if (d && d->name) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) setting = d++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) } else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) setting = g++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) mul_factor = setting->mulf ? setting->mulf(drive) : 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) div_factor = setting->divf ? setting->divf(drive) : 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) seq_printf(m, "%-24s", setting->name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) rc = ide_read_setting(drive, setting);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) if (rc >= 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) seq_printf(m, "%-16d", rc * mul_factor / div_factor);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) seq_printf(m, "%-16s", "write-only");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) seq_printf(m, "%-16d%-16d", (setting->min * mul_factor + div_factor - 1) / div_factor, setting->max * mul_factor / div_factor);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) ds = setting->setting;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) if (ds->get)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) seq_printf(m, "r");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) if (ds->set)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) seq_printf(m, "w");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) seq_printf(m, "\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) mutex_unlock(&ide_setting_mtx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) static int ide_settings_proc_open(struct inode *inode, struct file *file)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) return single_open(file, ide_settings_proc_show, PDE_DATA(inode));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) #define MAX_LEN 30
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) static ssize_t ide_settings_proc_write(struct file *file, const char __user *buffer,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) size_t count, loff_t *pos)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) ide_drive_t *drive = PDE_DATA(file_inode(file));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) char name[MAX_LEN + 1];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) int for_real = 0, mul_factor, div_factor;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) unsigned long n;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) const struct ide_proc_devset *setting;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) char *buf, *s;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) if (!capable(CAP_SYS_ADMIN))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) return -EACCES;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) proc_ide_settings_warn();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) if (count >= PAGE_SIZE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) s = buf = (char *)__get_free_page(GFP_USER);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) if (!buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) if (copy_from_user(buf, buffer, count)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) free_page((unsigned long)buf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) return -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) buf[count] = '\0';
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) * Skip over leading whitespace
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) while (count && isspace(*s)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) --count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317) ++s;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) * Do one full pass to verify all parameters,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321) * then do another to actually write the new settings.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323) do {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324) char *p = s;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325) n = count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326) while (n > 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327) unsigned val;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328) char *q = p;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330) while (n > 0 && *p != ':') {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331) --n;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332) p++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334) if (*p != ':')
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335) goto parse_error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336) if (p - q > MAX_LEN)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337) goto parse_error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338) memcpy(name, q, p - q);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339) name[p - q] = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341) if (n > 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342) --n;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343) p++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344) } else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345) goto parse_error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347) val = simple_strtoul(p, &q, 10);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348) n -= q - p;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349) p = q;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350) if (n > 0 && !isspace(*p))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 351) goto parse_error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 352) while (n > 0 && isspace(*p)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 353) --n;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 354) ++p;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 355) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 356)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 357) mutex_lock(&ide_setting_mtx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 358) /* generic settings first, then driver specific ones */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 359) setting = ide_find_setting(ide_generic_settings, name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 360) if (!setting) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 361) if (drive->settings)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 362) setting = ide_find_setting(drive->settings, name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 363) if (!setting) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 364) mutex_unlock(&ide_setting_mtx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 365) goto parse_error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 366) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 367) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 368) if (for_real) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 369) mul_factor = setting->mulf ? setting->mulf(drive) : 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 370) div_factor = setting->divf ? setting->divf(drive) : 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 371) ide_write_setting(drive, setting, val * div_factor / mul_factor);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 372) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 373) mutex_unlock(&ide_setting_mtx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 374) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 375) } while (!for_real++);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 376) free_page((unsigned long)buf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 377) return count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 378) parse_error:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 379) free_page((unsigned long)buf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 380) printk("%s(): parse error\n", __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 381) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 382) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 383)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 384) static const struct proc_ops ide_settings_proc_ops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 385) .proc_open = ide_settings_proc_open,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 386) .proc_read = seq_read,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 387) .proc_lseek = seq_lseek,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 388) .proc_release = single_release,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 389) .proc_write = ide_settings_proc_write,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 390) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 391)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 392) int ide_capacity_proc_show(struct seq_file *m, void *v)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 393) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 394) seq_printf(m, "%llu\n", (long long)0x7fffffff);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 395) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 396) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 397) EXPORT_SYMBOL_GPL(ide_capacity_proc_show);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 398)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 399) int ide_geometry_proc_show(struct seq_file *m, void *v)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 400) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 401) ide_drive_t *drive = (ide_drive_t *) m->private;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 402)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 403) seq_printf(m, "physical %d/%d/%d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 404) drive->cyl, drive->head, drive->sect);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 405) seq_printf(m, "logical %d/%d/%d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 406) drive->bios_cyl, drive->bios_head, drive->bios_sect);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 407) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 408) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 409) EXPORT_SYMBOL(ide_geometry_proc_show);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 410)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 411) static int ide_dmodel_proc_show(struct seq_file *seq, void *v)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 412) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 413) ide_drive_t *drive = (ide_drive_t *) seq->private;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 414) char *m = (char *)&drive->id[ATA_ID_PROD];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 415)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 416) seq_printf(seq, "%.40s\n", m[0] ? m : "(none)");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 417) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 418) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 419)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 420) static int ide_driver_proc_show(struct seq_file *m, void *v)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 421) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 422) ide_drive_t *drive = (ide_drive_t *)m->private;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 423) struct device *dev = &drive->gendev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 424) struct ide_driver *ide_drv;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 425)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 426) if (dev->driver) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 427) ide_drv = to_ide_driver(dev->driver);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 428) seq_printf(m, "%s version %s\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 429) dev->driver->name, ide_drv->version);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 430) } else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 431) seq_printf(m, "ide-default version 0.9.newide\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 432) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 433) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 434)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 435) static int ide_media_proc_show(struct seq_file *m, void *v)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 436) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 437) ide_drive_t *drive = (ide_drive_t *) m->private;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 438) const char *media;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 439)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 440) switch (drive->media) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 441) case ide_disk: media = "disk\n"; break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 442) case ide_cdrom: media = "cdrom\n"; break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 443) case ide_tape: media = "tape\n"; break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 444) case ide_floppy: media = "floppy\n"; break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 445) case ide_optical: media = "optical\n"; break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 446) default: media = "UNKNOWN\n"; break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 447) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 448) seq_puts(m, media);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 449) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 450) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 451)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 452) static int ide_media_proc_open(struct inode *inode, struct file *file)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 453) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 454) return single_open(file, ide_media_proc_show, PDE_DATA(inode));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 455) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 456)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 457) static const struct file_operations ide_media_proc_fops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 458) .owner = THIS_MODULE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 459) .open = ide_media_proc_open,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 460) .read = seq_read,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 461) .llseek = seq_lseek,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 462) .release = single_release,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 463) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 464)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 465) static ide_proc_entry_t generic_drive_entries[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 466) { "driver", S_IFREG|S_IRUGO, ide_driver_proc_show },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 467) { "identify", S_IFREG|S_IRUSR, ide_identify_proc_show },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 468) { "media", S_IFREG|S_IRUGO, ide_media_proc_show },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 469) { "model", S_IFREG|S_IRUGO, ide_dmodel_proc_show },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 470) {}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 471) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 472)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 473) static void ide_add_proc_entries(struct proc_dir_entry *dir, ide_proc_entry_t *p, void *data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 474) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 475) struct proc_dir_entry *ent;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 476)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 477) if (!dir || !p)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 478) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 479) while (p->name != NULL) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 480) ent = proc_create_single_data(p->name, p->mode, dir, p->show, data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 481) if (!ent) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 482) p++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 483) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 484) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 485)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 486) static void ide_remove_proc_entries(struct proc_dir_entry *dir, ide_proc_entry_t *p)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 487) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 488) if (!dir || !p)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 489) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 490) while (p->name != NULL) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 491) remove_proc_entry(p->name, dir);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 492) p++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 493) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 494) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 495)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 496) void ide_proc_register_driver(ide_drive_t *drive, struct ide_driver *driver)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 497) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 498) mutex_lock(&ide_setting_mtx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 499) drive->settings = driver->proc_devsets(drive);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 500) mutex_unlock(&ide_setting_mtx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 501)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 502) ide_add_proc_entries(drive->proc, driver->proc_entries(drive), drive);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 503) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 504)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 505) EXPORT_SYMBOL(ide_proc_register_driver);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 506)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 507) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 508) * ide_proc_unregister_driver - remove driver specific data
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 509) * @drive: drive
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 510) * @driver: driver
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 511) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 512) * Clean up the driver specific /proc files and IDE settings
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 513) * for a given drive.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 514) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 515) * Takes ide_setting_mtx.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 516) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 517)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 518) void ide_proc_unregister_driver(ide_drive_t *drive, struct ide_driver *driver)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 519) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 520) ide_remove_proc_entries(drive->proc, driver->proc_entries(drive));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 521)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 522) mutex_lock(&ide_setting_mtx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 523) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 524) * ide_setting_mtx protects both the settings list and the use
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 525) * of settings (we cannot take a setting out that is being used).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 526) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 527) drive->settings = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 528) mutex_unlock(&ide_setting_mtx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 529) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 530) EXPORT_SYMBOL(ide_proc_unregister_driver);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 531)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 532) void ide_proc_port_register_devices(ide_hwif_t *hwif)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 533) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 534) struct proc_dir_entry *ent;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 535) struct proc_dir_entry *parent = hwif->proc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 536) ide_drive_t *drive;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 537) char name[64];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 538) int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 539)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 540) ide_port_for_each_dev(i, drive, hwif) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 541) if ((drive->dev_flags & IDE_DFLAG_PRESENT) == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 542) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 543)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 544) drive->proc = proc_mkdir(drive->name, parent);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 545) if (drive->proc) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 546) ide_add_proc_entries(drive->proc, generic_drive_entries, drive);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 547) proc_create_data("settings", S_IFREG|S_IRUSR|S_IWUSR,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 548) drive->proc, &ide_settings_proc_ops,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 549) drive);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 550) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 551) sprintf(name, "ide%d/%s", (drive->name[2]-'a')/2, drive->name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 552) ent = proc_symlink(drive->name, proc_ide_root, name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 553) if (!ent) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 554) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 555) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 556)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 557) void ide_proc_unregister_device(ide_drive_t *drive)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 558) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 559) if (drive->proc) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 560) remove_proc_entry("settings", drive->proc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 561) ide_remove_proc_entries(drive->proc, generic_drive_entries);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 562) remove_proc_entry(drive->name, proc_ide_root);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 563) remove_proc_entry(drive->name, drive->hwif->proc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 564) drive->proc = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 565) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 566) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 567)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 568) static ide_proc_entry_t hwif_entries[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 569) { "channel", S_IFREG|S_IRUGO, ide_channel_proc_show },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 570) { "mate", S_IFREG|S_IRUGO, ide_mate_proc_show },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 571) { "model", S_IFREG|S_IRUGO, ide_imodel_proc_show },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 572) {}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 573) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 574)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 575) void ide_proc_register_port(ide_hwif_t *hwif)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 576) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 577) if (!hwif->proc) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 578) hwif->proc = proc_mkdir(hwif->name, proc_ide_root);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 579)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 580) if (!hwif->proc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 581) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 582)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 583) ide_add_proc_entries(hwif->proc, hwif_entries, hwif);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 584) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 585) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 586)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 587) void ide_proc_unregister_port(ide_hwif_t *hwif)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 588) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 589) if (hwif->proc) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 590) ide_remove_proc_entries(hwif->proc, hwif_entries);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 591) remove_proc_entry(hwif->name, proc_ide_root);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 592) hwif->proc = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 593) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 594) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 595)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 596) static int proc_print_driver(struct device_driver *drv, void *data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 597) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 598) struct ide_driver *ide_drv = to_ide_driver(drv);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 599) struct seq_file *s = data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 600)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 601) seq_printf(s, "%s version %s\n", drv->name, ide_drv->version);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 602)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 603) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 604) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 605)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 606) static int ide_drivers_show(struct seq_file *s, void *p)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 607) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 608) int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 609)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 610) err = bus_for_each_drv(&ide_bus_type, NULL, s, proc_print_driver);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 611) if (err < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 612) printk(KERN_WARNING "IDE: %s: bus_for_each_drv error: %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 613) __func__, err);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 614) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 615) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 616)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 617) DEFINE_PROC_SHOW_ATTRIBUTE(ide_drivers);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 618)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 619) void proc_ide_create(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 620) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 621) proc_ide_root = proc_mkdir("ide", NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 622)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 623) if (!proc_ide_root)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 624) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 625)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 626) proc_create("drivers", 0, proc_ide_root, &ide_drivers_proc_ops);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 627) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 628)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 629) void proc_ide_destroy(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 630) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 631) remove_proc_entry("drivers", proc_ide_root);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 632) remove_proc_entry("ide", NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 633) }