ide-proc.c 18 KB

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