ide-proc.c 18 KB

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