ide-proc.c 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789
  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. printk_once(KERN_WARNING "Warning: /proc/ide/hd?/settings interface is "
  237. "obsolete, and will be removed soon!\n");
  238. }
  239. static int ide_settings_proc_show(struct seq_file *m, void *v)
  240. {
  241. const struct ide_proc_devset *setting, *g, *d;
  242. const struct ide_devset *ds;
  243. ide_drive_t *drive = (ide_drive_t *) m->private;
  244. int rc, mul_factor, div_factor;
  245. proc_ide_settings_warn();
  246. mutex_lock(&ide_setting_mtx);
  247. g = ide_generic_settings;
  248. d = drive->settings;
  249. seq_printf(m, "name\t\t\tvalue\t\tmin\t\tmax\t\tmode\n");
  250. seq_printf(m, "----\t\t\t-----\t\t---\t\t---\t\t----\n");
  251. while (g->name || (d && d->name)) {
  252. /* read settings in the alphabetical order */
  253. if (g->name && d && d->name) {
  254. if (strcmp(d->name, g->name) < 0)
  255. setting = d++;
  256. else
  257. setting = g++;
  258. } else if (d && d->name) {
  259. setting = d++;
  260. } else
  261. setting = g++;
  262. mul_factor = setting->mulf ? setting->mulf(drive) : 1;
  263. div_factor = setting->divf ? setting->divf(drive) : 1;
  264. seq_printf(m, "%-24s", setting->name);
  265. rc = ide_read_setting(drive, setting);
  266. if (rc >= 0)
  267. seq_printf(m, "%-16d", rc * mul_factor / div_factor);
  268. else
  269. seq_printf(m, "%-16s", "write-only");
  270. seq_printf(m, "%-16d%-16d", (setting->min * mul_factor + div_factor - 1) / div_factor, setting->max * mul_factor / div_factor);
  271. ds = setting->setting;
  272. if (ds->get)
  273. seq_printf(m, "r");
  274. if (ds->set)
  275. seq_printf(m, "w");
  276. seq_printf(m, "\n");
  277. }
  278. mutex_unlock(&ide_setting_mtx);
  279. return 0;
  280. }
  281. static int ide_settings_proc_open(struct inode *inode, struct file *file)
  282. {
  283. return single_open(file, ide_settings_proc_show, PDE(inode)->data);
  284. }
  285. #define MAX_LEN 30
  286. static ssize_t ide_settings_proc_write(struct file *file, const char __user *buffer,
  287. size_t count, loff_t *pos)
  288. {
  289. ide_drive_t *drive = (ide_drive_t *) PDE(file->f_path.dentry->d_inode)->data;
  290. char name[MAX_LEN + 1];
  291. int for_real = 0, mul_factor, div_factor;
  292. unsigned long n;
  293. const struct ide_proc_devset *setting;
  294. char *buf, *s;
  295. if (!capable(CAP_SYS_ADMIN))
  296. return -EACCES;
  297. proc_ide_settings_warn();
  298. if (count >= PAGE_SIZE)
  299. return -EINVAL;
  300. s = buf = (char *)__get_free_page(GFP_USER);
  301. if (!buf)
  302. return -ENOMEM;
  303. if (copy_from_user(buf, buffer, count)) {
  304. free_page((unsigned long)buf);
  305. return -EFAULT;
  306. }
  307. buf[count] = '\0';
  308. /*
  309. * Skip over leading whitespace
  310. */
  311. while (count && isspace(*s)) {
  312. --count;
  313. ++s;
  314. }
  315. /*
  316. * Do one full pass to verify all parameters,
  317. * then do another to actually write the new settings.
  318. */
  319. do {
  320. char *p = s;
  321. n = count;
  322. while (n > 0) {
  323. unsigned val;
  324. char *q = p;
  325. while (n > 0 && *p != ':') {
  326. --n;
  327. p++;
  328. }
  329. if (*p != ':')
  330. goto parse_error;
  331. if (p - q > MAX_LEN)
  332. goto parse_error;
  333. memcpy(name, q, p - q);
  334. name[p - q] = 0;
  335. if (n > 0) {
  336. --n;
  337. p++;
  338. } else
  339. goto parse_error;
  340. val = simple_strtoul(p, &q, 10);
  341. n -= q - p;
  342. p = q;
  343. if (n > 0 && !isspace(*p))
  344. goto parse_error;
  345. while (n > 0 && isspace(*p)) {
  346. --n;
  347. ++p;
  348. }
  349. mutex_lock(&ide_setting_mtx);
  350. /* generic settings first, then driver specific ones */
  351. setting = ide_find_setting(ide_generic_settings, name);
  352. if (!setting) {
  353. if (drive->settings)
  354. setting = ide_find_setting(drive->settings, name);
  355. if (!setting) {
  356. mutex_unlock(&ide_setting_mtx);
  357. goto parse_error;
  358. }
  359. }
  360. if (for_real) {
  361. mul_factor = setting->mulf ? setting->mulf(drive) : 1;
  362. div_factor = setting->divf ? setting->divf(drive) : 1;
  363. ide_write_setting(drive, setting, val * div_factor / mul_factor);
  364. }
  365. mutex_unlock(&ide_setting_mtx);
  366. }
  367. } while (!for_real++);
  368. free_page((unsigned long)buf);
  369. return count;
  370. parse_error:
  371. free_page((unsigned long)buf);
  372. printk("%s(): parse error\n", __func__);
  373. return -EINVAL;
  374. }
  375. static const struct file_operations ide_settings_proc_fops = {
  376. .owner = THIS_MODULE,
  377. .open = ide_settings_proc_open,
  378. .read = seq_read,
  379. .llseek = seq_lseek,
  380. .release = single_release,
  381. .write = ide_settings_proc_write,
  382. };
  383. static int ide_capacity_proc_show(struct seq_file *m, void *v)
  384. {
  385. seq_printf(m, "%llu\n", (long long)0x7fffffff);
  386. return 0;
  387. }
  388. static int ide_capacity_proc_open(struct inode *inode, struct file *file)
  389. {
  390. return single_open(file, ide_capacity_proc_show, NULL);
  391. }
  392. const struct file_operations ide_capacity_proc_fops = {
  393. .owner = THIS_MODULE,
  394. .open = ide_capacity_proc_open,
  395. .read = seq_read,
  396. .llseek = seq_lseek,
  397. .release = single_release,
  398. };
  399. EXPORT_SYMBOL_GPL(ide_capacity_proc_fops);
  400. static int ide_geometry_proc_show(struct seq_file *m, void *v)
  401. {
  402. ide_drive_t *drive = (ide_drive_t *) m->private;
  403. seq_printf(m, "physical %d/%d/%d\n",
  404. drive->cyl, drive->head, drive->sect);
  405. seq_printf(m, "logical %d/%d/%d\n",
  406. drive->bios_cyl, drive->bios_head, drive->bios_sect);
  407. return 0;
  408. }
  409. static int ide_geometry_proc_open(struct inode *inode, struct file *file)
  410. {
  411. return single_open(file, ide_geometry_proc_show, PDE(inode)->data);
  412. }
  413. const struct file_operations ide_geometry_proc_fops = {
  414. .owner = THIS_MODULE,
  415. .open = ide_geometry_proc_open,
  416. .read = seq_read,
  417. .llseek = seq_lseek,
  418. .release = single_release,
  419. };
  420. EXPORT_SYMBOL(ide_geometry_proc_fops);
  421. static int ide_dmodel_proc_show(struct seq_file *seq, void *v)
  422. {
  423. ide_drive_t *drive = (ide_drive_t *) seq->private;
  424. char *m = (char *)&drive->id[ATA_ID_PROD];
  425. seq_printf(seq, "%.40s\n", m[0] ? m : "(none)");
  426. return 0;
  427. }
  428. static int ide_dmodel_proc_open(struct inode *inode, struct file *file)
  429. {
  430. return single_open(file, ide_dmodel_proc_show, PDE(inode)->data);
  431. }
  432. static const struct file_operations ide_dmodel_proc_fops = {
  433. .owner = THIS_MODULE,
  434. .open = ide_dmodel_proc_open,
  435. .read = seq_read,
  436. .llseek = seq_lseek,
  437. .release = single_release,
  438. };
  439. static int ide_driver_proc_show(struct seq_file *m, void *v)
  440. {
  441. ide_drive_t *drive = (ide_drive_t *)m->private;
  442. struct device *dev = &drive->gendev;
  443. struct ide_driver *ide_drv;
  444. if (dev->driver) {
  445. ide_drv = to_ide_driver(dev->driver);
  446. seq_printf(m, "%s version %s\n",
  447. dev->driver->name, ide_drv->version);
  448. } else
  449. seq_printf(m, "ide-default version 0.9.newide\n");
  450. return 0;
  451. }
  452. static int ide_driver_proc_open(struct inode *inode, struct file *file)
  453. {
  454. return single_open(file, ide_driver_proc_show, PDE(inode)->data);
  455. }
  456. static int ide_replace_subdriver(ide_drive_t *drive, const char *driver)
  457. {
  458. struct device *dev = &drive->gendev;
  459. int ret = 1;
  460. int err;
  461. device_release_driver(dev);
  462. /* FIXME: device can still be in use by previous driver */
  463. strlcpy(drive->driver_req, driver, sizeof(drive->driver_req));
  464. err = device_attach(dev);
  465. if (err < 0)
  466. printk(KERN_WARNING "IDE: %s: device_attach error: %d\n",
  467. __func__, err);
  468. drive->driver_req[0] = 0;
  469. if (dev->driver == NULL) {
  470. err = device_attach(dev);
  471. if (err < 0)
  472. printk(KERN_WARNING
  473. "IDE: %s: device_attach(2) error: %d\n",
  474. __func__, err);
  475. }
  476. if (dev->driver && !strcmp(dev->driver->name, driver))
  477. ret = 0;
  478. return ret;
  479. }
  480. static ssize_t ide_driver_proc_write(struct file *file, const char __user *buffer,
  481. size_t count, loff_t *pos)
  482. {
  483. ide_drive_t *drive = (ide_drive_t *) PDE(file->f_path.dentry->d_inode)->data;
  484. char name[32];
  485. if (!capable(CAP_SYS_ADMIN))
  486. return -EACCES;
  487. if (count > 31)
  488. count = 31;
  489. if (copy_from_user(name, buffer, count))
  490. return -EFAULT;
  491. name[count] = '\0';
  492. if (ide_replace_subdriver(drive, name))
  493. return -EINVAL;
  494. return count;
  495. }
  496. static const struct file_operations ide_driver_proc_fops = {
  497. .owner = THIS_MODULE,
  498. .open = ide_driver_proc_open,
  499. .read = seq_read,
  500. .llseek = seq_lseek,
  501. .release = single_release,
  502. .write = ide_driver_proc_write,
  503. };
  504. static int ide_media_proc_show(struct seq_file *m, void *v)
  505. {
  506. ide_drive_t *drive = (ide_drive_t *) m->private;
  507. const char *media;
  508. switch (drive->media) {
  509. case ide_disk: media = "disk\n"; break;
  510. case ide_cdrom: media = "cdrom\n"; break;
  511. case ide_tape: media = "tape\n"; break;
  512. case ide_floppy: media = "floppy\n"; break;
  513. case ide_optical: media = "optical\n"; break;
  514. default: media = "UNKNOWN\n"; break;
  515. }
  516. seq_puts(m, media);
  517. return 0;
  518. }
  519. static int ide_media_proc_open(struct inode *inode, struct file *file)
  520. {
  521. return single_open(file, ide_media_proc_show, PDE(inode)->data);
  522. }
  523. static const struct file_operations ide_media_proc_fops = {
  524. .owner = THIS_MODULE,
  525. .open = ide_media_proc_open,
  526. .read = seq_read,
  527. .llseek = seq_lseek,
  528. .release = single_release,
  529. };
  530. static ide_proc_entry_t generic_drive_entries[] = {
  531. { "driver", S_IFREG|S_IRUGO, &ide_driver_proc_fops },
  532. { "identify", S_IFREG|S_IRUSR, &ide_identify_proc_fops},
  533. { "media", S_IFREG|S_IRUGO, &ide_media_proc_fops },
  534. { "model", S_IFREG|S_IRUGO, &ide_dmodel_proc_fops },
  535. { "settings", S_IFREG|S_IRUSR|S_IWUSR, &ide_settings_proc_fops},
  536. {}
  537. };
  538. static void ide_add_proc_entries(struct proc_dir_entry *dir, ide_proc_entry_t *p, void *data)
  539. {
  540. struct proc_dir_entry *ent;
  541. if (!dir || !p)
  542. return;
  543. while (p->name != NULL) {
  544. ent = proc_create_data(p->name, p->mode, dir, p->proc_fops, data);
  545. if (!ent) return;
  546. p++;
  547. }
  548. }
  549. static void ide_remove_proc_entries(struct proc_dir_entry *dir, ide_proc_entry_t *p)
  550. {
  551. if (!dir || !p)
  552. return;
  553. while (p->name != NULL) {
  554. remove_proc_entry(p->name, dir);
  555. p++;
  556. }
  557. }
  558. void ide_proc_register_driver(ide_drive_t *drive, struct ide_driver *driver)
  559. {
  560. mutex_lock(&ide_setting_mtx);
  561. drive->settings = driver->proc_devsets(drive);
  562. mutex_unlock(&ide_setting_mtx);
  563. ide_add_proc_entries(drive->proc, driver->proc_entries(drive), drive);
  564. }
  565. EXPORT_SYMBOL(ide_proc_register_driver);
  566. /**
  567. * ide_proc_unregister_driver - remove driver specific data
  568. * @drive: drive
  569. * @driver: driver
  570. *
  571. * Clean up the driver specific /proc files and IDE settings
  572. * for a given drive.
  573. *
  574. * Takes ide_setting_mtx.
  575. */
  576. void ide_proc_unregister_driver(ide_drive_t *drive, struct ide_driver *driver)
  577. {
  578. ide_remove_proc_entries(drive->proc, driver->proc_entries(drive));
  579. mutex_lock(&ide_setting_mtx);
  580. /*
  581. * ide_setting_mtx protects both the settings list and the use
  582. * of settings (we cannot take a setting out that is being used).
  583. */
  584. drive->settings = NULL;
  585. mutex_unlock(&ide_setting_mtx);
  586. }
  587. EXPORT_SYMBOL(ide_proc_unregister_driver);
  588. void ide_proc_port_register_devices(ide_hwif_t *hwif)
  589. {
  590. struct proc_dir_entry *ent;
  591. struct proc_dir_entry *parent = hwif->proc;
  592. ide_drive_t *drive;
  593. char name[64];
  594. int i;
  595. ide_port_for_each_dev(i, drive, hwif) {
  596. if ((drive->dev_flags & IDE_DFLAG_PRESENT) == 0)
  597. continue;
  598. drive->proc = proc_mkdir(drive->name, parent);
  599. if (drive->proc)
  600. ide_add_proc_entries(drive->proc, generic_drive_entries, drive);
  601. sprintf(name, "ide%d/%s", (drive->name[2]-'a')/2, drive->name);
  602. ent = proc_symlink(drive->name, proc_ide_root, name);
  603. if (!ent) return;
  604. }
  605. }
  606. void ide_proc_unregister_device(ide_drive_t *drive)
  607. {
  608. if (drive->proc) {
  609. ide_remove_proc_entries(drive->proc, generic_drive_entries);
  610. remove_proc_entry(drive->name, proc_ide_root);
  611. remove_proc_entry(drive->name, drive->hwif->proc);
  612. drive->proc = NULL;
  613. }
  614. }
  615. static ide_proc_entry_t hwif_entries[] = {
  616. { "channel", S_IFREG|S_IRUGO, &ide_channel_proc_fops },
  617. { "mate", S_IFREG|S_IRUGO, &ide_mate_proc_fops },
  618. { "model", S_IFREG|S_IRUGO, &ide_imodel_proc_fops },
  619. {}
  620. };
  621. void ide_proc_register_port(ide_hwif_t *hwif)
  622. {
  623. if (!hwif->proc) {
  624. hwif->proc = proc_mkdir(hwif->name, proc_ide_root);
  625. if (!hwif->proc)
  626. return;
  627. ide_add_proc_entries(hwif->proc, hwif_entries, hwif);
  628. }
  629. }
  630. void ide_proc_unregister_port(ide_hwif_t *hwif)
  631. {
  632. if (hwif->proc) {
  633. ide_remove_proc_entries(hwif->proc, hwif_entries);
  634. remove_proc_entry(hwif->name, proc_ide_root);
  635. hwif->proc = NULL;
  636. }
  637. }
  638. static int proc_print_driver(struct device_driver *drv, void *data)
  639. {
  640. struct ide_driver *ide_drv = to_ide_driver(drv);
  641. struct seq_file *s = data;
  642. seq_printf(s, "%s version %s\n", drv->name, ide_drv->version);
  643. return 0;
  644. }
  645. static int ide_drivers_show(struct seq_file *s, void *p)
  646. {
  647. int err;
  648. err = bus_for_each_drv(&ide_bus_type, NULL, s, proc_print_driver);
  649. if (err < 0)
  650. printk(KERN_WARNING "IDE: %s: bus_for_each_drv error: %d\n",
  651. __func__, err);
  652. return 0;
  653. }
  654. static int ide_drivers_open(struct inode *inode, struct file *file)
  655. {
  656. return single_open(file, &ide_drivers_show, NULL);
  657. }
  658. static const struct file_operations ide_drivers_operations = {
  659. .owner = THIS_MODULE,
  660. .open = ide_drivers_open,
  661. .read = seq_read,
  662. .llseek = seq_lseek,
  663. .release = single_release,
  664. };
  665. void proc_ide_create(void)
  666. {
  667. proc_ide_root = proc_mkdir("ide", NULL);
  668. if (!proc_ide_root)
  669. return;
  670. proc_create("drivers", 0, proc_ide_root, &ide_drivers_operations);
  671. }
  672. void proc_ide_destroy(void)
  673. {
  674. remove_proc_entry("drivers", proc_ide_root);
  675. remove_proc_entry("ide", NULL);
  676. }