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