ide-proc.c 18 KB

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