ide-proc.c 17 KB

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