Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2 | * Copyright (C) 1997-1998 Mark Lord |
Alan Cox | ccd32e2 | 2008-11-02 21:40:08 +0100 | [diff] [blame] | 3 | * Copyright (C) 2003 Red Hat |
Bartlomiej Zolnierkiewicz | 7662d04 | 2007-05-10 00:01:10 +0200 | [diff] [blame] | 4 | * |
| 5 | * Some code was moved here from ide.c, see it for original copyrights. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6 | */ |
| 7 | |
| 8 | /* |
| 9 | * This is the /proc/ide/ filesystem implementation. |
| 10 | * |
| 11 | * Drive/Driver settings can be retrieved by reading the drive's |
| 12 | * "settings" files. e.g. "cat /proc/ide0/hda/settings" |
| 13 | * To write a new value "val" into a specific setting "name", use: |
| 14 | * echo "name:val" >/proc/ide/ide0/hda/settings |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15 | */ |
| 16 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 17 | #include <linux/module.h> |
| 18 | |
| 19 | #include <asm/uaccess.h> |
| 20 | #include <linux/errno.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 21 | #include <linux/proc_fs.h> |
| 22 | #include <linux/stat.h> |
| 23 | #include <linux/mm.h> |
| 24 | #include <linux/pci.h> |
| 25 | #include <linux/ctype.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 26 | #include <linux/ide.h> |
| 27 | #include <linux/seq_file.h> |
| 28 | |
| 29 | #include <asm/io.h> |
| 30 | |
Bartlomiej Zolnierkiewicz | 5cbf79c | 2007-05-10 00:01:11 +0200 | [diff] [blame] | 31 | static struct proc_dir_entry *proc_ide_root; |
| 32 | |
Alexey Dobriyan | 6d703a8 | 2009-09-01 17:52:57 -0700 | [diff] [blame] | 33 | static int ide_imodel_proc_show(struct seq_file *m, void *v) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 34 | { |
Alexey Dobriyan | 6d703a8 | 2009-09-01 17:52:57 -0700 | [diff] [blame] | 35 | ide_hwif_t *hwif = (ide_hwif_t *) m->private; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 36 | const char *name; |
| 37 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 38 | switch (hwif->chipset) { |
Paolo Ciarrocchi | 441e92d | 2008-04-26 17:36:40 +0200 | [diff] [blame] | 39 | case ide_generic: name = "generic"; break; |
| 40 | case ide_pci: name = "pci"; break; |
| 41 | case ide_cmd640: name = "cmd640"; break; |
| 42 | case ide_dtc2278: name = "dtc2278"; break; |
| 43 | case ide_ali14xx: name = "ali14xx"; break; |
| 44 | case ide_qd65xx: name = "qd65xx"; break; |
| 45 | case ide_umc8672: name = "umc8672"; break; |
| 46 | case ide_ht6560b: name = "ht6560b"; break; |
Paolo Ciarrocchi | 441e92d | 2008-04-26 17:36:40 +0200 | [diff] [blame] | 47 | case ide_4drives: name = "4drives"; break; |
| 48 | case ide_pmac: name = "mac-io"; break; |
| 49 | case ide_au1xxx: name = "au1xxx"; break; |
| 50 | case ide_palm3710: name = "palm3710"; break; |
Paolo Ciarrocchi | 441e92d | 2008-04-26 17:36:40 +0200 | [diff] [blame] | 51 | case ide_acorn: name = "acorn"; break; |
| 52 | default: name = "(unknown)"; break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 53 | } |
Alexey Dobriyan | 6d703a8 | 2009-09-01 17:52:57 -0700 | [diff] [blame] | 54 | seq_printf(m, "%s\n", name); |
| 55 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 56 | } |
| 57 | |
Alexey Dobriyan | 6d703a8 | 2009-09-01 17:52:57 -0700 | [diff] [blame] | 58 | static int ide_imodel_proc_open(struct inode *inode, struct file *file) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 59 | { |
Alexey Dobriyan | 6d703a8 | 2009-09-01 17:52:57 -0700 | [diff] [blame] | 60 | return single_open(file, ide_imodel_proc_show, PDE(inode)->data); |
| 61 | } |
| 62 | |
| 63 | static const struct file_operations ide_imodel_proc_fops = { |
| 64 | .owner = THIS_MODULE, |
| 65 | .open = ide_imodel_proc_open, |
| 66 | .read = seq_read, |
| 67 | .llseek = seq_lseek, |
| 68 | .release = single_release, |
| 69 | }; |
| 70 | |
| 71 | static int ide_mate_proc_show(struct seq_file *m, void *v) |
| 72 | { |
| 73 | ide_hwif_t *hwif = (ide_hwif_t *) m->private; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 74 | |
Bartlomiej Zolnierkiewicz | 4283e1b | 2008-06-30 20:14:45 +0200 | [diff] [blame] | 75 | if (hwif && hwif->mate) |
Alexey Dobriyan | 6d703a8 | 2009-09-01 17:52:57 -0700 | [diff] [blame] | 76 | seq_printf(m, "%s\n", hwif->mate->name); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 77 | else |
Alexey Dobriyan | 6d703a8 | 2009-09-01 17:52:57 -0700 | [diff] [blame] | 78 | seq_printf(m, "(none)\n"); |
| 79 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 80 | } |
| 81 | |
Alexey Dobriyan | 6d703a8 | 2009-09-01 17:52:57 -0700 | [diff] [blame] | 82 | static int ide_mate_proc_open(struct inode *inode, struct file *file) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 83 | { |
Alexey Dobriyan | 6d703a8 | 2009-09-01 17:52:57 -0700 | [diff] [blame] | 84 | return single_open(file, ide_mate_proc_show, PDE(inode)->data); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 85 | } |
| 86 | |
Alexey Dobriyan | 6d703a8 | 2009-09-01 17:52:57 -0700 | [diff] [blame] | 87 | static const struct file_operations ide_mate_proc_fops = { |
| 88 | .owner = THIS_MODULE, |
| 89 | .open = ide_mate_proc_open, |
| 90 | .read = seq_read, |
| 91 | .llseek = seq_lseek, |
| 92 | .release = single_release, |
| 93 | }; |
| 94 | |
| 95 | static int ide_channel_proc_show(struct seq_file *m, void *v) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 96 | { |
Alexey Dobriyan | 6d703a8 | 2009-09-01 17:52:57 -0700 | [diff] [blame] | 97 | ide_hwif_t *hwif = (ide_hwif_t *) m->private; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 98 | |
Alexey Dobriyan | 6d703a8 | 2009-09-01 17:52:57 -0700 | [diff] [blame] | 99 | seq_printf(m, "%c\n", hwif->channel ? '1' : '0'); |
| 100 | return 0; |
| 101 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 102 | |
Alexey Dobriyan | 6d703a8 | 2009-09-01 17:52:57 -0700 | [diff] [blame] | 103 | static int ide_channel_proc_open(struct inode *inode, struct file *file) |
| 104 | { |
| 105 | return single_open(file, ide_channel_proc_show, PDE(inode)->data); |
| 106 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 107 | |
Alexey Dobriyan | 6d703a8 | 2009-09-01 17:52:57 -0700 | [diff] [blame] | 108 | static const struct file_operations ide_channel_proc_fops = { |
| 109 | .owner = THIS_MODULE, |
| 110 | .open = ide_channel_proc_open, |
| 111 | .read = seq_read, |
| 112 | .llseek = seq_lseek, |
| 113 | .release = single_release, |
| 114 | }; |
Bartlomiej Zolnierkiewicz | 151a670 | 2008-10-10 22:39:28 +0200 | [diff] [blame] | 115 | |
Alexey Dobriyan | 6d703a8 | 2009-09-01 17:52:57 -0700 | [diff] [blame] | 116 | static int ide_identify_proc_show(struct seq_file *m, void *v) |
| 117 | { |
| 118 | ide_drive_t *drive = (ide_drive_t *)m->private; |
| 119 | u8 *buf; |
| 120 | |
| 121 | if (!drive) { |
| 122 | seq_putc(m, '\n'); |
| 123 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 124 | } |
Alexey Dobriyan | 6d703a8 | 2009-09-01 17:52:57 -0700 | [diff] [blame] | 125 | |
| 126 | buf = kmalloc(SECTOR_SIZE, GFP_KERNEL); |
| 127 | if (!buf) |
| 128 | return -ENOMEM; |
| 129 | if (taskfile_lib_get_identify(drive, buf) == 0) { |
| 130 | __le16 *val = (__le16 *)buf; |
| 131 | int i; |
| 132 | |
| 133 | for (i = 0; i < SECTOR_SIZE / 2; i++) { |
| 134 | seq_printf(m, "%04x%c", le16_to_cpu(val[i]), |
| 135 | (i % 8) == 7 ? '\n' : ' '); |
| 136 | } |
| 137 | } else |
| 138 | seq_putc(m, buf[0]); |
| 139 | kfree(buf); |
| 140 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 141 | } |
| 142 | |
Alexey Dobriyan | 6d703a8 | 2009-09-01 17:52:57 -0700 | [diff] [blame] | 143 | static int ide_identify_proc_open(struct inode *inode, struct file *file) |
| 144 | { |
| 145 | return single_open(file, ide_identify_proc_show, PDE(inode)->data); |
| 146 | } |
| 147 | |
| 148 | static const struct file_operations ide_identify_proc_fops = { |
| 149 | .owner = THIS_MODULE, |
| 150 | .open = ide_identify_proc_open, |
| 151 | .read = seq_read, |
| 152 | .llseek = seq_lseek, |
| 153 | .release = single_release, |
| 154 | }; |
| 155 | |
Bartlomiej Zolnierkiewicz | 7662d04 | 2007-05-10 00:01:10 +0200 | [diff] [blame] | 156 | /** |
Bartlomiej Zolnierkiewicz | 8185d5a | 2008-10-10 22:39:28 +0200 | [diff] [blame] | 157 | * ide_find_setting - find a specific setting |
| 158 | * @st: setting table pointer |
Bartlomiej Zolnierkiewicz | 7662d04 | 2007-05-10 00:01:10 +0200 | [diff] [blame] | 159 | * @name: setting name |
| 160 | * |
Bartlomiej Zolnierkiewicz | 8185d5a | 2008-10-10 22:39:28 +0200 | [diff] [blame] | 161 | * Scan's the setting table for a matching entry and returns |
Bartlomiej Zolnierkiewicz | 7662d04 | 2007-05-10 00:01:10 +0200 | [diff] [blame] | 162 | * this or NULL if no entry is found. The caller must hold the |
| 163 | * setting semaphore |
| 164 | */ |
| 165 | |
Elias Oltmanns | 92f1f8f | 2008-10-10 22:39:40 +0200 | [diff] [blame] | 166 | static |
| 167 | const struct ide_proc_devset *ide_find_setting(const struct ide_proc_devset *st, |
| 168 | char *name) |
Bartlomiej Zolnierkiewicz | 7662d04 | 2007-05-10 00:01:10 +0200 | [diff] [blame] | 169 | { |
Elias Oltmanns | 92f1f8f | 2008-10-10 22:39:40 +0200 | [diff] [blame] | 170 | while (st->name) { |
| 171 | if (strcmp(st->name, name) == 0) |
Bartlomiej Zolnierkiewicz | 7662d04 | 2007-05-10 00:01:10 +0200 | [diff] [blame] | 172 | break; |
Bartlomiej Zolnierkiewicz | 8185d5a | 2008-10-10 22:39:28 +0200 | [diff] [blame] | 173 | st++; |
Bartlomiej Zolnierkiewicz | 7662d04 | 2007-05-10 00:01:10 +0200 | [diff] [blame] | 174 | } |
Elias Oltmanns | 92f1f8f | 2008-10-10 22:39:40 +0200 | [diff] [blame] | 175 | return st->name ? st : NULL; |
Bartlomiej Zolnierkiewicz | 7662d04 | 2007-05-10 00:01:10 +0200 | [diff] [blame] | 176 | } |
| 177 | |
| 178 | /** |
| 179 | * ide_read_setting - read an IDE setting |
| 180 | * @drive: drive to read from |
| 181 | * @setting: drive setting |
| 182 | * |
| 183 | * Read a drive setting and return the value. The caller |
Matthias Kaehlcke | f9383c4 | 2007-07-09 23:17:56 +0200 | [diff] [blame] | 184 | * must hold the ide_setting_mtx when making this call. |
Bartlomiej Zolnierkiewicz | 7662d04 | 2007-05-10 00:01:10 +0200 | [diff] [blame] | 185 | * |
| 186 | * BUGS: the data return and error are the same return value |
| 187 | * so an error -EINVAL and true return of the same value cannot |
| 188 | * be told apart |
| 189 | */ |
| 190 | |
Bartlomiej Zolnierkiewicz | 8185d5a | 2008-10-10 22:39:28 +0200 | [diff] [blame] | 191 | static int ide_read_setting(ide_drive_t *drive, |
Elias Oltmanns | 92f1f8f | 2008-10-10 22:39:40 +0200 | [diff] [blame] | 192 | const struct ide_proc_devset *setting) |
Bartlomiej Zolnierkiewicz | 7662d04 | 2007-05-10 00:01:10 +0200 | [diff] [blame] | 193 | { |
Elias Oltmanns | 92f1f8f | 2008-10-10 22:39:40 +0200 | [diff] [blame] | 194 | const struct ide_devset *ds = setting->setting; |
Bartlomiej Zolnierkiewicz | 8185d5a | 2008-10-10 22:39:28 +0200 | [diff] [blame] | 195 | int val = -EINVAL; |
Bartlomiej Zolnierkiewicz | 7662d04 | 2007-05-10 00:01:10 +0200 | [diff] [blame] | 196 | |
Bartlomiej Zolnierkiewicz | 1f473e9 | 2008-12-29 20:27:29 +0100 | [diff] [blame] | 197 | if (ds->get) |
Elias Oltmanns | 92f1f8f | 2008-10-10 22:39:40 +0200 | [diff] [blame] | 198 | val = ds->get(drive); |
Bartlomiej Zolnierkiewicz | 8185d5a | 2008-10-10 22:39:28 +0200 | [diff] [blame] | 199 | |
Bartlomiej Zolnierkiewicz | 7662d04 | 2007-05-10 00:01:10 +0200 | [diff] [blame] | 200 | return val; |
| 201 | } |
| 202 | |
| 203 | /** |
| 204 | * ide_write_setting - read an IDE setting |
| 205 | * @drive: drive to read from |
| 206 | * @setting: drive setting |
| 207 | * @val: value |
| 208 | * |
| 209 | * Write a drive setting if it is possible. The caller |
Matthias Kaehlcke | f9383c4 | 2007-07-09 23:17:56 +0200 | [diff] [blame] | 210 | * must hold the ide_setting_mtx when making this call. |
Bartlomiej Zolnierkiewicz | 7662d04 | 2007-05-10 00:01:10 +0200 | [diff] [blame] | 211 | * |
| 212 | * BUGS: the data return and error are the same return value |
| 213 | * so an error -EINVAL and true return of the same value cannot |
| 214 | * be told apart |
| 215 | * |
| 216 | * FIXME: This should be changed to enqueue a special request |
| 217 | * to the driver to change settings, and then wait on a sema for completion. |
| 218 | * The current scheme of polling is kludgy, though safe enough. |
| 219 | */ |
| 220 | |
Bartlomiej Zolnierkiewicz | 8185d5a | 2008-10-10 22:39:28 +0200 | [diff] [blame] | 221 | static int ide_write_setting(ide_drive_t *drive, |
Elias Oltmanns | 92f1f8f | 2008-10-10 22:39:40 +0200 | [diff] [blame] | 222 | const struct ide_proc_devset *setting, int val) |
Bartlomiej Zolnierkiewicz | 7662d04 | 2007-05-10 00:01:10 +0200 | [diff] [blame] | 223 | { |
Elias Oltmanns | 92f1f8f | 2008-10-10 22:39:40 +0200 | [diff] [blame] | 224 | const struct ide_devset *ds = setting->setting; |
| 225 | |
Bartlomiej Zolnierkiewicz | 7662d04 | 2007-05-10 00:01:10 +0200 | [diff] [blame] | 226 | if (!capable(CAP_SYS_ADMIN)) |
| 227 | return -EACCES; |
Elias Oltmanns | 92f1f8f | 2008-10-10 22:39:40 +0200 | [diff] [blame] | 228 | if (!ds->set) |
Bartlomiej Zolnierkiewicz | 7662d04 | 2007-05-10 00:01:10 +0200 | [diff] [blame] | 229 | return -EPERM; |
Elias Oltmanns | 92f1f8f | 2008-10-10 22:39:40 +0200 | [diff] [blame] | 230 | if ((ds->flags & DS_SYNC) |
| 231 | && (val < setting->min || val > setting->max)) |
Bartlomiej Zolnierkiewicz | 7662d04 | 2007-05-10 00:01:10 +0200 | [diff] [blame] | 232 | return -EINVAL; |
Elias Oltmanns | 92f1f8f | 2008-10-10 22:39:40 +0200 | [diff] [blame] | 233 | return ide_devset_execute(drive, ds, val); |
Bartlomiej Zolnierkiewicz | 7662d04 | 2007-05-10 00:01:10 +0200 | [diff] [blame] | 234 | } |
| 235 | |
Elias Oltmanns | 92f1f8f | 2008-10-10 22:39:40 +0200 | [diff] [blame] | 236 | ide_devset_get(xfer_rate, current_speed); |
Bartlomiej Zolnierkiewicz | 8185d5a | 2008-10-10 22:39:28 +0200 | [diff] [blame] | 237 | |
Bartlomiej Zolnierkiewicz | 7662d04 | 2007-05-10 00:01:10 +0200 | [diff] [blame] | 238 | static int set_xfer_rate (ide_drive_t *drive, int arg) |
| 239 | { |
Bartlomiej Zolnierkiewicz | 22aa4b3 | 2009-03-27 12:46:37 +0100 | [diff] [blame] | 240 | struct ide_cmd cmd; |
Bartlomiej Zolnierkiewicz | 7662d04 | 2007-05-10 00:01:10 +0200 | [diff] [blame] | 241 | |
Bartlomiej Zolnierkiewicz | 3b2a5c7 | 2008-07-23 19:55:56 +0200 | [diff] [blame] | 242 | if (arg < XFER_PIO_0 || arg > XFER_UDMA_6) |
Bartlomiej Zolnierkiewicz | 7662d04 | 2007-05-10 00:01:10 +0200 | [diff] [blame] | 243 | return -EINVAL; |
| 244 | |
Bartlomiej Zolnierkiewicz | 22aa4b3 | 2009-03-27 12:46:37 +0100 | [diff] [blame] | 245 | memset(&cmd, 0, sizeof(cmd)); |
| 246 | cmd.tf.command = ATA_CMD_SET_FEATURES; |
| 247 | cmd.tf.feature = SETFEATURES_XFER; |
| 248 | cmd.tf.nsect = (u8)arg; |
Sergei Shtylyov | 60f8501 | 2009-04-08 14:13:01 +0200 | [diff] [blame] | 249 | cmd.valid.out.tf = IDE_VALID_FEATURE | IDE_VALID_NSECT; |
| 250 | cmd.valid.in.tf = IDE_VALID_NSECT; |
Bartlomiej Zolnierkiewicz | 665d66e | 2009-06-23 11:35:51 +0000 | [diff] [blame] | 251 | cmd.tf_flags = IDE_TFLAG_SET_XFER; |
Bartlomiej Zolnierkiewicz | 34f5d5a | 2008-01-26 20:13:12 +0100 | [diff] [blame] | 252 | |
Bartlomiej Zolnierkiewicz | 665d66e | 2009-06-23 11:35:51 +0000 | [diff] [blame] | 253 | return ide_no_data_taskfile(drive, &cmd); |
Bartlomiej Zolnierkiewicz | 7662d04 | 2007-05-10 00:01:10 +0200 | [diff] [blame] | 254 | } |
| 255 | |
Elias Oltmanns | 92f1f8f | 2008-10-10 22:39:40 +0200 | [diff] [blame] | 256 | ide_devset_rw(current_speed, xfer_rate); |
| 257 | ide_devset_rw_field(init_speed, init_speed); |
Bartlomiej Zolnierkiewicz | 97100fc | 2008-10-13 21:39:36 +0200 | [diff] [blame] | 258 | ide_devset_rw_flag(nice1, IDE_DFLAG_NICE1); |
Elias Oltmanns | 92f1f8f | 2008-10-10 22:39:40 +0200 | [diff] [blame] | 259 | ide_devset_rw_field(number, dn); |
Bartlomiej Zolnierkiewicz | 7662d04 | 2007-05-10 00:01:10 +0200 | [diff] [blame] | 260 | |
Elias Oltmanns | 92f1f8f | 2008-10-10 22:39:40 +0200 | [diff] [blame] | 261 | static const struct ide_proc_devset ide_generic_settings[] = { |
| 262 | IDE_PROC_DEVSET(current_speed, 0, 70), |
| 263 | IDE_PROC_DEVSET(init_speed, 0, 70), |
| 264 | IDE_PROC_DEVSET(io_32bit, 0, 1 + (SUPPORT_VLB_SYNC << 1)), |
| 265 | IDE_PROC_DEVSET(keepsettings, 0, 1), |
| 266 | IDE_PROC_DEVSET(nice1, 0, 1), |
| 267 | IDE_PROC_DEVSET(number, 0, 3), |
| 268 | IDE_PROC_DEVSET(pio_mode, 0, 255), |
| 269 | IDE_PROC_DEVSET(unmaskirq, 0, 1), |
| 270 | IDE_PROC_DEVSET(using_dma, 0, 1), |
Hannes Eder | 71bfc7a | 2009-03-05 16:10:56 +0100 | [diff] [blame] | 271 | { NULL }, |
Bartlomiej Zolnierkiewicz | 8185d5a | 2008-10-10 22:39:28 +0200 | [diff] [blame] | 272 | }; |
Bartlomiej Zolnierkiewicz | 7662d04 | 2007-05-10 00:01:10 +0200 | [diff] [blame] | 273 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 274 | static void proc_ide_settings_warn(void) |
| 275 | { |
Paolo Ciarrocchi | 441e92d | 2008-04-26 17:36:40 +0200 | [diff] [blame] | 276 | static int warned; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 277 | |
| 278 | if (warned) |
| 279 | return; |
| 280 | |
| 281 | printk(KERN_WARNING "Warning: /proc/ide/hd?/settings interface is " |
| 282 | "obsolete, and will be removed soon!\n"); |
| 283 | warned = 1; |
| 284 | } |
| 285 | |
Alexey Dobriyan | 6d703a8 | 2009-09-01 17:52:57 -0700 | [diff] [blame] | 286 | static int ide_settings_proc_show(struct seq_file *m, void *v) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 287 | { |
Elias Oltmanns | 92f1f8f | 2008-10-10 22:39:40 +0200 | [diff] [blame] | 288 | const struct ide_proc_devset *setting, *g, *d; |
| 289 | const struct ide_devset *ds; |
Alexey Dobriyan | 6d703a8 | 2009-09-01 17:52:57 -0700 | [diff] [blame] | 290 | ide_drive_t *drive = (ide_drive_t *) m->private; |
| 291 | int rc, mul_factor, div_factor; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 292 | |
| 293 | proc_ide_settings_warn(); |
| 294 | |
Matthias Kaehlcke | f9383c4 | 2007-07-09 23:17:56 +0200 | [diff] [blame] | 295 | mutex_lock(&ide_setting_mtx); |
Bartlomiej Zolnierkiewicz | 8185d5a | 2008-10-10 22:39:28 +0200 | [diff] [blame] | 296 | g = ide_generic_settings; |
| 297 | d = drive->settings; |
Alexey Dobriyan | 6d703a8 | 2009-09-01 17:52:57 -0700 | [diff] [blame] | 298 | seq_printf(m, "name\t\t\tvalue\t\tmin\t\tmax\t\tmode\n"); |
| 299 | seq_printf(m, "----\t\t\t-----\t\t---\t\t---\t\t----\n"); |
Elias Oltmanns | 92f1f8f | 2008-10-10 22:39:40 +0200 | [diff] [blame] | 300 | while (g->name || (d && d->name)) { |
Bartlomiej Zolnierkiewicz | 8185d5a | 2008-10-10 22:39:28 +0200 | [diff] [blame] | 301 | /* read settings in the alphabetical order */ |
Elias Oltmanns | 92f1f8f | 2008-10-10 22:39:40 +0200 | [diff] [blame] | 302 | if (g->name && d && d->name) { |
| 303 | if (strcmp(d->name, g->name) < 0) |
| 304 | setting = d++; |
Bartlomiej Zolnierkiewicz | 8185d5a | 2008-10-10 22:39:28 +0200 | [diff] [blame] | 305 | else |
Elias Oltmanns | 92f1f8f | 2008-10-10 22:39:40 +0200 | [diff] [blame] | 306 | setting = g++; |
| 307 | } else if (d && d->name) { |
| 308 | setting = d++; |
Bartlomiej Zolnierkiewicz | 8185d5a | 2008-10-10 22:39:28 +0200 | [diff] [blame] | 309 | } else |
Elias Oltmanns | 92f1f8f | 2008-10-10 22:39:40 +0200 | [diff] [blame] | 310 | setting = g++; |
Bartlomiej Zolnierkiewicz | 8185d5a | 2008-10-10 22:39:28 +0200 | [diff] [blame] | 311 | mul_factor = setting->mulf ? setting->mulf(drive) : 1; |
| 312 | div_factor = setting->divf ? setting->divf(drive) : 1; |
Alexey Dobriyan | 6d703a8 | 2009-09-01 17:52:57 -0700 | [diff] [blame] | 313 | seq_printf(m, "%-24s", setting->name); |
Paolo Ciarrocchi | 441e92d | 2008-04-26 17:36:40 +0200 | [diff] [blame] | 314 | rc = ide_read_setting(drive, setting); |
| 315 | if (rc >= 0) |
Alexey Dobriyan | 6d703a8 | 2009-09-01 17:52:57 -0700 | [diff] [blame] | 316 | seq_printf(m, "%-16d", rc * mul_factor / div_factor); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 317 | else |
Alexey Dobriyan | 6d703a8 | 2009-09-01 17:52:57 -0700 | [diff] [blame] | 318 | seq_printf(m, "%-16s", "write-only"); |
| 319 | seq_printf(m, "%-16d%-16d", (setting->min * mul_factor + div_factor - 1) / div_factor, setting->max * mul_factor / div_factor); |
Elias Oltmanns | 92f1f8f | 2008-10-10 22:39:40 +0200 | [diff] [blame] | 320 | ds = setting->setting; |
| 321 | if (ds->get) |
Alexey Dobriyan | 6d703a8 | 2009-09-01 17:52:57 -0700 | [diff] [blame] | 322 | seq_printf(m, "r"); |
Elias Oltmanns | 92f1f8f | 2008-10-10 22:39:40 +0200 | [diff] [blame] | 323 | if (ds->set) |
Alexey Dobriyan | 6d703a8 | 2009-09-01 17:52:57 -0700 | [diff] [blame] | 324 | seq_printf(m, "w"); |
| 325 | seq_printf(m, "\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 326 | } |
Matthias Kaehlcke | f9383c4 | 2007-07-09 23:17:56 +0200 | [diff] [blame] | 327 | mutex_unlock(&ide_setting_mtx); |
Alexey Dobriyan | 6d703a8 | 2009-09-01 17:52:57 -0700 | [diff] [blame] | 328 | return 0; |
| 329 | } |
| 330 | |
| 331 | static int ide_settings_proc_open(struct inode *inode, struct file *file) |
| 332 | { |
| 333 | return single_open(file, ide_settings_proc_show, PDE(inode)->data); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 334 | } |
| 335 | |
| 336 | #define MAX_LEN 30 |
| 337 | |
Alexey Dobriyan | 6d703a8 | 2009-09-01 17:52:57 -0700 | [diff] [blame] | 338 | static ssize_t ide_settings_proc_write(struct file *file, const char __user *buffer, |
| 339 | size_t count, loff_t *pos) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 340 | { |
Alexey Dobriyan | 6d703a8 | 2009-09-01 17:52:57 -0700 | [diff] [blame] | 341 | ide_drive_t *drive = (ide_drive_t *) PDE(file->f_path.dentry->d_inode)->data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 342 | char name[MAX_LEN + 1]; |
Bartlomiej Zolnierkiewicz | 8185d5a | 2008-10-10 22:39:28 +0200 | [diff] [blame] | 343 | int for_real = 0, mul_factor, div_factor; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 344 | unsigned long n; |
Bartlomiej Zolnierkiewicz | 8185d5a | 2008-10-10 22:39:28 +0200 | [diff] [blame] | 345 | |
Elias Oltmanns | 92f1f8f | 2008-10-10 22:39:40 +0200 | [diff] [blame] | 346 | const struct ide_proc_devset *setting; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 347 | char *buf, *s; |
| 348 | |
| 349 | if (!capable(CAP_SYS_ADMIN)) |
| 350 | return -EACCES; |
| 351 | |
| 352 | proc_ide_settings_warn(); |
| 353 | |
| 354 | if (count >= PAGE_SIZE) |
| 355 | return -EINVAL; |
| 356 | |
| 357 | s = buf = (char *)__get_free_page(GFP_USER); |
| 358 | if (!buf) |
| 359 | return -ENOMEM; |
| 360 | |
| 361 | if (copy_from_user(buf, buffer, count)) { |
| 362 | free_page((unsigned long)buf); |
| 363 | return -EFAULT; |
| 364 | } |
| 365 | |
| 366 | buf[count] = '\0'; |
| 367 | |
| 368 | /* |
| 369 | * Skip over leading whitespace |
| 370 | */ |
| 371 | while (count && isspace(*s)) { |
| 372 | --count; |
| 373 | ++s; |
| 374 | } |
| 375 | /* |
| 376 | * Do one full pass to verify all parameters, |
| 377 | * then do another to actually write the new settings. |
| 378 | */ |
| 379 | do { |
| 380 | char *p = s; |
| 381 | n = count; |
| 382 | while (n > 0) { |
| 383 | unsigned val; |
| 384 | char *q = p; |
| 385 | |
| 386 | while (n > 0 && *p != ':') { |
| 387 | --n; |
| 388 | p++; |
| 389 | } |
| 390 | if (*p != ':') |
| 391 | goto parse_error; |
| 392 | if (p - q > MAX_LEN) |
| 393 | goto parse_error; |
| 394 | memcpy(name, q, p - q); |
| 395 | name[p - q] = 0; |
| 396 | |
| 397 | if (n > 0) { |
| 398 | --n; |
| 399 | p++; |
| 400 | } else |
| 401 | goto parse_error; |
| 402 | |
| 403 | val = simple_strtoul(p, &q, 10); |
| 404 | n -= q - p; |
| 405 | p = q; |
| 406 | if (n > 0 && !isspace(*p)) |
| 407 | goto parse_error; |
| 408 | while (n > 0 && isspace(*p)) { |
| 409 | --n; |
| 410 | ++p; |
| 411 | } |
| 412 | |
Matthias Kaehlcke | f9383c4 | 2007-07-09 23:17:56 +0200 | [diff] [blame] | 413 | mutex_lock(&ide_setting_mtx); |
Bartlomiej Zolnierkiewicz | 8185d5a | 2008-10-10 22:39:28 +0200 | [diff] [blame] | 414 | /* generic settings first, then driver specific ones */ |
| 415 | setting = ide_find_setting(ide_generic_settings, name); |
Paolo Ciarrocchi | 441e92d | 2008-04-26 17:36:40 +0200 | [diff] [blame] | 416 | if (!setting) { |
Bartlomiej Zolnierkiewicz | 8185d5a | 2008-10-10 22:39:28 +0200 | [diff] [blame] | 417 | if (drive->settings) |
| 418 | setting = ide_find_setting(drive->settings, name); |
| 419 | if (!setting) { |
| 420 | mutex_unlock(&ide_setting_mtx); |
| 421 | goto parse_error; |
| 422 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 423 | } |
Bartlomiej Zolnierkiewicz | 8185d5a | 2008-10-10 22:39:28 +0200 | [diff] [blame] | 424 | if (for_real) { |
| 425 | mul_factor = setting->mulf ? setting->mulf(drive) : 1; |
| 426 | div_factor = setting->divf ? setting->divf(drive) : 1; |
| 427 | ide_write_setting(drive, setting, val * div_factor / mul_factor); |
| 428 | } |
Matthias Kaehlcke | f9383c4 | 2007-07-09 23:17:56 +0200 | [diff] [blame] | 429 | mutex_unlock(&ide_setting_mtx); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 430 | } |
| 431 | } while (!for_real++); |
| 432 | free_page((unsigned long)buf); |
| 433 | return count; |
| 434 | parse_error: |
| 435 | free_page((unsigned long)buf); |
Alexey Dobriyan | 6d703a8 | 2009-09-01 17:52:57 -0700 | [diff] [blame] | 436 | printk("%s(): parse error\n", __func__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 437 | return -EINVAL; |
| 438 | } |
| 439 | |
Alexey Dobriyan | 6d703a8 | 2009-09-01 17:52:57 -0700 | [diff] [blame] | 440 | static const struct file_operations ide_settings_proc_fops = { |
| 441 | .owner = THIS_MODULE, |
| 442 | .open = ide_settings_proc_open, |
| 443 | .read = seq_read, |
| 444 | .llseek = seq_lseek, |
| 445 | .release = single_release, |
| 446 | .write = ide_settings_proc_write, |
| 447 | }; |
| 448 | |
| 449 | static int ide_capacity_proc_show(struct seq_file *m, void *v) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 450 | { |
Alexey Dobriyan | 6d703a8 | 2009-09-01 17:52:57 -0700 | [diff] [blame] | 451 | seq_printf(m, "%llu\n", (long long)0x7fffffff); |
| 452 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 453 | } |
| 454 | |
Alexey Dobriyan | 6d703a8 | 2009-09-01 17:52:57 -0700 | [diff] [blame] | 455 | static int ide_capacity_proc_open(struct inode *inode, struct file *file) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 456 | { |
Alexey Dobriyan | 6d703a8 | 2009-09-01 17:52:57 -0700 | [diff] [blame] | 457 | return single_open(file, ide_capacity_proc_show, NULL); |
| 458 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 459 | |
Alexey Dobriyan | 6d703a8 | 2009-09-01 17:52:57 -0700 | [diff] [blame] | 460 | const struct file_operations ide_capacity_proc_fops = { |
| 461 | .owner = THIS_MODULE, |
| 462 | .open = ide_capacity_proc_open, |
| 463 | .read = seq_read, |
| 464 | .llseek = seq_lseek, |
| 465 | .release = single_release, |
| 466 | }; |
| 467 | EXPORT_SYMBOL_GPL(ide_capacity_proc_fops); |
| 468 | |
| 469 | static int ide_geometry_proc_show(struct seq_file *m, void *v) |
| 470 | { |
| 471 | ide_drive_t *drive = (ide_drive_t *) m->private; |
| 472 | |
| 473 | seq_printf(m, "physical %d/%d/%d\n", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 474 | drive->cyl, drive->head, drive->sect); |
Alexey Dobriyan | 6d703a8 | 2009-09-01 17:52:57 -0700 | [diff] [blame] | 475 | seq_printf(m, "logical %d/%d/%d\n", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 476 | drive->bios_cyl, drive->bios_head, drive->bios_sect); |
Alexey Dobriyan | 6d703a8 | 2009-09-01 17:52:57 -0700 | [diff] [blame] | 477 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 478 | } |
| 479 | |
Alexey Dobriyan | 6d703a8 | 2009-09-01 17:52:57 -0700 | [diff] [blame] | 480 | static int ide_geometry_proc_open(struct inode *inode, struct file *file) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 481 | { |
Alexey Dobriyan | 6d703a8 | 2009-09-01 17:52:57 -0700 | [diff] [blame] | 482 | return single_open(file, ide_geometry_proc_show, PDE(inode)->data); |
| 483 | } |
| 484 | |
| 485 | const struct file_operations ide_geometry_proc_fops = { |
| 486 | .owner = THIS_MODULE, |
| 487 | .open = ide_geometry_proc_open, |
| 488 | .read = seq_read, |
| 489 | .llseek = seq_lseek, |
| 490 | .release = single_release, |
| 491 | }; |
| 492 | EXPORT_SYMBOL(ide_geometry_proc_fops); |
| 493 | |
| 494 | static int ide_dmodel_proc_show(struct seq_file *seq, void *v) |
| 495 | { |
| 496 | ide_drive_t *drive = (ide_drive_t *) seq->private; |
Bartlomiej Zolnierkiewicz | 4dde449 | 2008-10-10 22:39:19 +0200 | [diff] [blame] | 497 | char *m = (char *)&drive->id[ATA_ID_PROD]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 498 | |
Alexey Dobriyan | 6d703a8 | 2009-09-01 17:52:57 -0700 | [diff] [blame] | 499 | seq_printf(seq, "%.40s\n", m[0] ? m : "(none)"); |
| 500 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 501 | } |
| 502 | |
Alexey Dobriyan | 6d703a8 | 2009-09-01 17:52:57 -0700 | [diff] [blame] | 503 | static int ide_dmodel_proc_open(struct inode *inode, struct file *file) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 504 | { |
Alexey Dobriyan | 6d703a8 | 2009-09-01 17:52:57 -0700 | [diff] [blame] | 505 | return single_open(file, ide_dmodel_proc_show, PDE(inode)->data); |
| 506 | } |
| 507 | |
| 508 | static const struct file_operations ide_dmodel_proc_fops = { |
| 509 | .owner = THIS_MODULE, |
| 510 | .open = ide_dmodel_proc_open, |
| 511 | .read = seq_read, |
| 512 | .llseek = seq_lseek, |
| 513 | .release = single_release, |
| 514 | }; |
| 515 | |
| 516 | static int ide_driver_proc_show(struct seq_file *m, void *v) |
| 517 | { |
| 518 | ide_drive_t *drive = (ide_drive_t *)m->private; |
Bartlomiej Zolnierkiewicz | 7f3c868 | 2009-01-06 17:20:53 +0100 | [diff] [blame] | 519 | struct device *dev = &drive->gendev; |
| 520 | struct ide_driver *ide_drv; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 521 | |
Bartlomiej Zolnierkiewicz | 8604aff | 2005-05-26 14:55:34 +0200 | [diff] [blame] | 522 | if (dev->driver) { |
Bartlomiej Zolnierkiewicz | 7f3c868 | 2009-01-06 17:20:53 +0100 | [diff] [blame] | 523 | ide_drv = to_ide_driver(dev->driver); |
Alexey Dobriyan | 6d703a8 | 2009-09-01 17:52:57 -0700 | [diff] [blame] | 524 | seq_printf(m, "%s version %s\n", |
Bartlomiej Zolnierkiewicz | 8604aff | 2005-05-26 14:55:34 +0200 | [diff] [blame] | 525 | dev->driver->name, ide_drv->version); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 526 | } else |
Alexey Dobriyan | 6d703a8 | 2009-09-01 17:52:57 -0700 | [diff] [blame] | 527 | seq_printf(m, "ide-default version 0.9.newide\n"); |
| 528 | return 0; |
| 529 | } |
| 530 | |
| 531 | static int ide_driver_proc_open(struct inode *inode, struct file *file) |
| 532 | { |
| 533 | return single_open(file, ide_driver_proc_show, PDE(inode)->data); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 534 | } |
| 535 | |
Bartlomiej Zolnierkiewicz | 8604aff | 2005-05-26 14:55:34 +0200 | [diff] [blame] | 536 | static int ide_replace_subdriver(ide_drive_t *drive, const char *driver) |
| 537 | { |
| 538 | struct device *dev = &drive->gendev; |
| 539 | int ret = 1; |
Randy Dunlap | 349ae23 | 2006-10-03 01:14:23 -0700 | [diff] [blame] | 540 | int err; |
Bartlomiej Zolnierkiewicz | 8604aff | 2005-05-26 14:55:34 +0200 | [diff] [blame] | 541 | |
Bartlomiej Zolnierkiewicz | 8604aff | 2005-05-26 14:55:34 +0200 | [diff] [blame] | 542 | device_release_driver(dev); |
| 543 | /* FIXME: device can still be in use by previous driver */ |
| 544 | strlcpy(drive->driver_req, driver, sizeof(drive->driver_req)); |
Randy Dunlap | 349ae23 | 2006-10-03 01:14:23 -0700 | [diff] [blame] | 545 | err = device_attach(dev); |
| 546 | if (err < 0) |
| 547 | printk(KERN_WARNING "IDE: %s: device_attach error: %d\n", |
Harvey Harrison | eb63963 | 2008-04-26 22:25:20 +0200 | [diff] [blame] | 548 | __func__, err); |
Bartlomiej Zolnierkiewicz | 8604aff | 2005-05-26 14:55:34 +0200 | [diff] [blame] | 549 | drive->driver_req[0] = 0; |
Randy Dunlap | 349ae23 | 2006-10-03 01:14:23 -0700 | [diff] [blame] | 550 | if (dev->driver == NULL) { |
| 551 | err = device_attach(dev); |
| 552 | if (err < 0) |
| 553 | printk(KERN_WARNING |
| 554 | "IDE: %s: device_attach(2) error: %d\n", |
Harvey Harrison | eb63963 | 2008-04-26 22:25:20 +0200 | [diff] [blame] | 555 | __func__, err); |
Randy Dunlap | 349ae23 | 2006-10-03 01:14:23 -0700 | [diff] [blame] | 556 | } |
Bartlomiej Zolnierkiewicz | 8604aff | 2005-05-26 14:55:34 +0200 | [diff] [blame] | 557 | if (dev->driver && !strcmp(dev->driver->name, driver)) |
| 558 | ret = 0; |
Bartlomiej Zolnierkiewicz | 8604aff | 2005-05-26 14:55:34 +0200 | [diff] [blame] | 559 | |
| 560 | return ret; |
| 561 | } |
| 562 | |
Alexey Dobriyan | 6d703a8 | 2009-09-01 17:52:57 -0700 | [diff] [blame] | 563 | static ssize_t ide_driver_proc_write(struct file *file, const char __user *buffer, |
| 564 | size_t count, loff_t *pos) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 565 | { |
Alexey Dobriyan | 6d703a8 | 2009-09-01 17:52:57 -0700 | [diff] [blame] | 566 | ide_drive_t *drive = (ide_drive_t *) PDE(file->f_path.dentry->d_inode)->data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 567 | char name[32]; |
| 568 | |
| 569 | if (!capable(CAP_SYS_ADMIN)) |
| 570 | return -EACCES; |
| 571 | if (count > 31) |
| 572 | count = 31; |
| 573 | if (copy_from_user(name, buffer, count)) |
| 574 | return -EFAULT; |
| 575 | name[count] = '\0'; |
| 576 | if (ide_replace_subdriver(drive, name)) |
| 577 | return -EINVAL; |
| 578 | return count; |
| 579 | } |
| 580 | |
Alexey Dobriyan | 6d703a8 | 2009-09-01 17:52:57 -0700 | [diff] [blame] | 581 | static const struct file_operations ide_driver_proc_fops = { |
| 582 | .owner = THIS_MODULE, |
| 583 | .open = ide_driver_proc_open, |
| 584 | .read = seq_read, |
| 585 | .llseek = seq_lseek, |
| 586 | .release = single_release, |
| 587 | .write = ide_driver_proc_write, |
| 588 | }; |
| 589 | |
| 590 | static int ide_media_proc_show(struct seq_file *m, void *v) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 591 | { |
Alexey Dobriyan | 6d703a8 | 2009-09-01 17:52:57 -0700 | [diff] [blame] | 592 | ide_drive_t *drive = (ide_drive_t *) m->private; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 593 | const char *media; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 594 | |
| 595 | switch (drive->media) { |
Paolo Ciarrocchi | 441e92d | 2008-04-26 17:36:40 +0200 | [diff] [blame] | 596 | case ide_disk: media = "disk\n"; break; |
| 597 | case ide_cdrom: media = "cdrom\n"; break; |
| 598 | case ide_tape: media = "tape\n"; break; |
| 599 | case ide_floppy: media = "floppy\n"; break; |
| 600 | case ide_optical: media = "optical\n"; break; |
| 601 | default: media = "UNKNOWN\n"; break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 602 | } |
Alexey Dobriyan | 6d703a8 | 2009-09-01 17:52:57 -0700 | [diff] [blame] | 603 | seq_puts(m, media); |
| 604 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 605 | } |
| 606 | |
Alexey Dobriyan | 6d703a8 | 2009-09-01 17:52:57 -0700 | [diff] [blame] | 607 | static int ide_media_proc_open(struct inode *inode, struct file *file) |
| 608 | { |
| 609 | return single_open(file, ide_media_proc_show, PDE(inode)->data); |
| 610 | } |
| 611 | |
| 612 | static const struct file_operations ide_media_proc_fops = { |
| 613 | .owner = THIS_MODULE, |
| 614 | .open = ide_media_proc_open, |
| 615 | .read = seq_read, |
| 616 | .llseek = seq_lseek, |
| 617 | .release = single_release, |
| 618 | }; |
| 619 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 620 | static ide_proc_entry_t generic_drive_entries[] = { |
Alexey Dobriyan | 6d703a8 | 2009-09-01 17:52:57 -0700 | [diff] [blame] | 621 | { "driver", S_IFREG|S_IRUGO, &ide_driver_proc_fops }, |
| 622 | { "identify", S_IFREG|S_IRUSR, &ide_identify_proc_fops}, |
| 623 | { "media", S_IFREG|S_IRUGO, &ide_media_proc_fops }, |
| 624 | { "model", S_IFREG|S_IRUGO, &ide_dmodel_proc_fops }, |
| 625 | { "settings", S_IFREG|S_IRUSR|S_IWUSR, &ide_settings_proc_fops}, |
| 626 | {} |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 627 | }; |
| 628 | |
Bartlomiej Zolnierkiewicz | 7662d04 | 2007-05-10 00:01:10 +0200 | [diff] [blame] | 629 | static void ide_add_proc_entries(struct proc_dir_entry *dir, ide_proc_entry_t *p, void *data) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 630 | { |
| 631 | struct proc_dir_entry *ent; |
| 632 | |
| 633 | if (!dir || !p) |
| 634 | return; |
| 635 | while (p->name != NULL) { |
Alexey Dobriyan | 6d703a8 | 2009-09-01 17:52:57 -0700 | [diff] [blame] | 636 | ent = proc_create_data(p->name, p->mode, dir, p->proc_fops, data); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 637 | if (!ent) return; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 638 | p++; |
| 639 | } |
| 640 | } |
| 641 | |
Bartlomiej Zolnierkiewicz | 7662d04 | 2007-05-10 00:01:10 +0200 | [diff] [blame] | 642 | static void ide_remove_proc_entries(struct proc_dir_entry *dir, ide_proc_entry_t *p) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 643 | { |
| 644 | if (!dir || !p) |
| 645 | return; |
| 646 | while (p->name != NULL) { |
| 647 | remove_proc_entry(p->name, dir); |
| 648 | p++; |
| 649 | } |
| 650 | } |
| 651 | |
Bartlomiej Zolnierkiewicz | 7f3c868 | 2009-01-06 17:20:53 +0100 | [diff] [blame] | 652 | void ide_proc_register_driver(ide_drive_t *drive, struct ide_driver *driver) |
Bartlomiej Zolnierkiewicz | 7662d04 | 2007-05-10 00:01:10 +0200 | [diff] [blame] | 653 | { |
Bartlomiej Zolnierkiewicz | 8185d5a | 2008-10-10 22:39:28 +0200 | [diff] [blame] | 654 | mutex_lock(&ide_setting_mtx); |
Bartlomiej Zolnierkiewicz | 79cb380 | 2008-10-17 18:09:13 +0200 | [diff] [blame] | 655 | drive->settings = driver->proc_devsets(drive); |
Bartlomiej Zolnierkiewicz | 8185d5a | 2008-10-10 22:39:28 +0200 | [diff] [blame] | 656 | mutex_unlock(&ide_setting_mtx); |
| 657 | |
Bartlomiej Zolnierkiewicz | 79cb380 | 2008-10-17 18:09:13 +0200 | [diff] [blame] | 658 | ide_add_proc_entries(drive->proc, driver->proc_entries(drive), drive); |
Bartlomiej Zolnierkiewicz | 7662d04 | 2007-05-10 00:01:10 +0200 | [diff] [blame] | 659 | } |
| 660 | |
| 661 | EXPORT_SYMBOL(ide_proc_register_driver); |
| 662 | |
| 663 | /** |
| 664 | * ide_proc_unregister_driver - remove driver specific data |
| 665 | * @drive: drive |
| 666 | * @driver: driver |
| 667 | * |
| 668 | * Clean up the driver specific /proc files and IDE settings |
| 669 | * for a given drive. |
| 670 | * |
Bartlomiej Zolnierkiewicz | 1f473e9 | 2008-12-29 20:27:29 +0100 | [diff] [blame] | 671 | * Takes ide_setting_mtx. |
Bartlomiej Zolnierkiewicz | 7662d04 | 2007-05-10 00:01:10 +0200 | [diff] [blame] | 672 | */ |
| 673 | |
Bartlomiej Zolnierkiewicz | 7f3c868 | 2009-01-06 17:20:53 +0100 | [diff] [blame] | 674 | void ide_proc_unregister_driver(ide_drive_t *drive, struct ide_driver *driver) |
Bartlomiej Zolnierkiewicz | 7662d04 | 2007-05-10 00:01:10 +0200 | [diff] [blame] | 675 | { |
Bartlomiej Zolnierkiewicz | 79cb380 | 2008-10-17 18:09:13 +0200 | [diff] [blame] | 676 | ide_remove_proc_entries(drive->proc, driver->proc_entries(drive)); |
Bartlomiej Zolnierkiewicz | 7662d04 | 2007-05-10 00:01:10 +0200 | [diff] [blame] | 677 | |
Matthias Kaehlcke | f9383c4 | 2007-07-09 23:17:56 +0200 | [diff] [blame] | 678 | mutex_lock(&ide_setting_mtx); |
Bartlomiej Zolnierkiewicz | 7662d04 | 2007-05-10 00:01:10 +0200 | [diff] [blame] | 679 | /* |
Bartlomiej Zolnierkiewicz | 1f473e9 | 2008-12-29 20:27:29 +0100 | [diff] [blame] | 680 | * ide_setting_mtx protects both the settings list and the use |
| 681 | * of settings (we cannot take a setting out that is being used). |
Bartlomiej Zolnierkiewicz | 7662d04 | 2007-05-10 00:01:10 +0200 | [diff] [blame] | 682 | */ |
Bartlomiej Zolnierkiewicz | 8185d5a | 2008-10-10 22:39:28 +0200 | [diff] [blame] | 683 | drive->settings = NULL; |
Matthias Kaehlcke | f9383c4 | 2007-07-09 23:17:56 +0200 | [diff] [blame] | 684 | mutex_unlock(&ide_setting_mtx); |
Bartlomiej Zolnierkiewicz | 7662d04 | 2007-05-10 00:01:10 +0200 | [diff] [blame] | 685 | } |
Bartlomiej Zolnierkiewicz | 7662d04 | 2007-05-10 00:01:10 +0200 | [diff] [blame] | 686 | EXPORT_SYMBOL(ide_proc_unregister_driver); |
| 687 | |
Bartlomiej Zolnierkiewicz | d9270a3 | 2008-02-02 19:56:43 +0100 | [diff] [blame] | 688 | void ide_proc_port_register_devices(ide_hwif_t *hwif) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 689 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 690 | struct proc_dir_entry *ent; |
| 691 | struct proc_dir_entry *parent = hwif->proc; |
Bartlomiej Zolnierkiewicz | 2bd24a1 | 2009-01-06 17:20:56 +0100 | [diff] [blame] | 692 | ide_drive_t *drive; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 693 | char name[64]; |
Bartlomiej Zolnierkiewicz | 2bd24a1 | 2009-01-06 17:20:56 +0100 | [diff] [blame] | 694 | int i; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 695 | |
Bartlomiej Zolnierkiewicz | 2bd24a1 | 2009-01-06 17:20:56 +0100 | [diff] [blame] | 696 | ide_port_for_each_dev(i, drive, hwif) { |
Bartlomiej Zolnierkiewicz | 1902a25 | 2009-03-24 23:22:40 +0100 | [diff] [blame] | 697 | if ((drive->dev_flags & IDE_DFLAG_PRESENT) == 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 698 | continue; |
| 699 | |
| 700 | drive->proc = proc_mkdir(drive->name, parent); |
| 701 | if (drive->proc) |
| 702 | ide_add_proc_entries(drive->proc, generic_drive_entries, drive); |
Paolo Ciarrocchi | 441e92d | 2008-04-26 17:36:40 +0200 | [diff] [blame] | 703 | sprintf(name, "ide%d/%s", (drive->name[2]-'a')/2, drive->name); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 704 | ent = proc_symlink(drive->name, proc_ide_root, name); |
| 705 | if (!ent) return; |
| 706 | } |
| 707 | } |
| 708 | |
Bartlomiej Zolnierkiewicz | 5b0c4b3 | 2008-04-18 00:46:22 +0200 | [diff] [blame] | 709 | void ide_proc_unregister_device(ide_drive_t *drive) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 710 | { |
| 711 | if (drive->proc) { |
| 712 | ide_remove_proc_entries(drive->proc, generic_drive_entries); |
| 713 | remove_proc_entry(drive->name, proc_ide_root); |
Bartlomiej Zolnierkiewicz | 5b0c4b3 | 2008-04-18 00:46:22 +0200 | [diff] [blame] | 714 | remove_proc_entry(drive->name, drive->hwif->proc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 715 | drive->proc = NULL; |
| 716 | } |
| 717 | } |
| 718 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 719 | static ide_proc_entry_t hwif_entries[] = { |
Alexey Dobriyan | 6d703a8 | 2009-09-01 17:52:57 -0700 | [diff] [blame] | 720 | { "channel", S_IFREG|S_IRUGO, &ide_channel_proc_fops }, |
| 721 | { "mate", S_IFREG|S_IRUGO, &ide_mate_proc_fops }, |
| 722 | { "model", S_IFREG|S_IRUGO, &ide_imodel_proc_fops }, |
| 723 | {} |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 724 | }; |
| 725 | |
Bartlomiej Zolnierkiewicz | 5cbf79c | 2007-05-10 00:01:11 +0200 | [diff] [blame] | 726 | void ide_proc_register_port(ide_hwif_t *hwif) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 727 | { |
Bartlomiej Zolnierkiewicz | 5cbf79c | 2007-05-10 00:01:11 +0200 | [diff] [blame] | 728 | if (!hwif->proc) { |
| 729 | hwif->proc = proc_mkdir(hwif->name, proc_ide_root); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 730 | |
Bartlomiej Zolnierkiewicz | 5cbf79c | 2007-05-10 00:01:11 +0200 | [diff] [blame] | 731 | if (!hwif->proc) |
| 732 | return; |
| 733 | |
| 734 | ide_add_proc_entries(hwif->proc, hwif_entries, hwif); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 735 | } |
| 736 | } |
| 737 | |
Bartlomiej Zolnierkiewicz | 5cbf79c | 2007-05-10 00:01:11 +0200 | [diff] [blame] | 738 | void ide_proc_unregister_port(ide_hwif_t *hwif) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 739 | { |
| 740 | if (hwif->proc) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 741 | ide_remove_proc_entries(hwif->proc, hwif_entries); |
| 742 | remove_proc_entry(hwif->name, proc_ide_root); |
| 743 | hwif->proc = NULL; |
| 744 | } |
| 745 | } |
| 746 | |
Bartlomiej Zolnierkiewicz | 8604aff | 2005-05-26 14:55:34 +0200 | [diff] [blame] | 747 | static int proc_print_driver(struct device_driver *drv, void *data) |
| 748 | { |
Bartlomiej Zolnierkiewicz | 7f3c868 | 2009-01-06 17:20:53 +0100 | [diff] [blame] | 749 | struct ide_driver *ide_drv = to_ide_driver(drv); |
Bartlomiej Zolnierkiewicz | 8604aff | 2005-05-26 14:55:34 +0200 | [diff] [blame] | 750 | struct seq_file *s = data; |
| 751 | |
| 752 | seq_printf(s, "%s version %s\n", drv->name, ide_drv->version); |
| 753 | |
| 754 | return 0; |
| 755 | } |
| 756 | |
| 757 | static int ide_drivers_show(struct seq_file *s, void *p) |
| 758 | { |
Randy Dunlap | 349ae23 | 2006-10-03 01:14:23 -0700 | [diff] [blame] | 759 | int err; |
| 760 | |
| 761 | err = bus_for_each_drv(&ide_bus_type, NULL, s, proc_print_driver); |
| 762 | if (err < 0) |
| 763 | printk(KERN_WARNING "IDE: %s: bus_for_each_drv error: %d\n", |
Harvey Harrison | eb63963 | 2008-04-26 22:25:20 +0200 | [diff] [blame] | 764 | __func__, err); |
Bartlomiej Zolnierkiewicz | 8604aff | 2005-05-26 14:55:34 +0200 | [diff] [blame] | 765 | return 0; |
| 766 | } |
| 767 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 768 | static int ide_drivers_open(struct inode *inode, struct file *file) |
| 769 | { |
Bartlomiej Zolnierkiewicz | 8604aff | 2005-05-26 14:55:34 +0200 | [diff] [blame] | 770 | return single_open(file, &ide_drivers_show, NULL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 771 | } |
Bartlomiej Zolnierkiewicz | 8604aff | 2005-05-26 14:55:34 +0200 | [diff] [blame] | 772 | |
Arjan van de Ven | 2b8693c | 2007-02-12 00:55:32 -0800 | [diff] [blame] | 773 | static const struct file_operations ide_drivers_operations = { |
Denis V. Lunev | c7705f3 | 2008-04-29 01:02:35 -0700 | [diff] [blame] | 774 | .owner = THIS_MODULE, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 775 | .open = ide_drivers_open, |
| 776 | .read = seq_read, |
| 777 | .llseek = seq_lseek, |
Bartlomiej Zolnierkiewicz | 8604aff | 2005-05-26 14:55:34 +0200 | [diff] [blame] | 778 | .release = single_release, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 779 | }; |
| 780 | |
| 781 | void proc_ide_create(void) |
| 782 | { |
Bartlomiej Zolnierkiewicz | 5cbf79c | 2007-05-10 00:01:11 +0200 | [diff] [blame] | 783 | proc_ide_root = proc_mkdir("ide", NULL); |
| 784 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 785 | if (!proc_ide_root) |
| 786 | return; |
| 787 | |
Denis V. Lunev | c7705f3 | 2008-04-29 01:02:35 -0700 | [diff] [blame] | 788 | proc_create("drivers", 0, proc_ide_root, &ide_drivers_operations); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 789 | } |
| 790 | |
| 791 | void proc_ide_destroy(void) |
| 792 | { |
Zhang, Yanmin | 643bdc6 | 2005-05-16 21:53:11 -0700 | [diff] [blame] | 793 | remove_proc_entry("drivers", proc_ide_root); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 794 | remove_proc_entry("ide", NULL); |
| 795 | } |