ide-proc.c 17 KB

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