ide-proc.c 18 KB

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