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