ide-proc.c 19 KB

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