ide-proc.c 19 KB

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