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