ide-proc.c 18 KB

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