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