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