proc.c 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. /*
  2. * ISA Plug & Play support
  3. * Copyright (c) by Jaroslav Kysela <perex@perex.cz>
  4. *
  5. * This program is free software; you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation; either version 2 of the License, or
  8. * (at your option) any later version.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with this program; if not, write to the Free Software
  17. * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  18. */
  19. #include <linux/module.h>
  20. #include <linux/isapnp.h>
  21. #include <linux/proc_fs.h>
  22. #include <linux/init.h>
  23. #include <asm/uaccess.h>
  24. extern struct pnp_protocol isapnp_protocol;
  25. static struct proc_dir_entry *isapnp_proc_bus_dir = NULL;
  26. static loff_t isapnp_proc_bus_lseek(struct file *file, loff_t off, int whence)
  27. {
  28. return fixed_size_llseek(file, off, whence, 256);
  29. }
  30. static ssize_t isapnp_proc_bus_read(struct file *file, char __user * buf,
  31. size_t nbytes, loff_t * ppos)
  32. {
  33. struct pnp_dev *dev = PDE_DATA(file_inode(file));
  34. int pos = *ppos;
  35. int cnt, size = 256;
  36. if (pos >= size)
  37. return 0;
  38. if (nbytes >= size)
  39. nbytes = size;
  40. if (pos + nbytes > size)
  41. nbytes = size - pos;
  42. cnt = nbytes;
  43. if (!access_ok(VERIFY_WRITE, buf, cnt))
  44. return -EINVAL;
  45. isapnp_cfg_begin(dev->card->number, dev->number);
  46. for (; pos < 256 && cnt > 0; pos++, buf++, cnt--) {
  47. unsigned char val;
  48. val = isapnp_read_byte(pos);
  49. __put_user(val, buf);
  50. }
  51. isapnp_cfg_end();
  52. *ppos = pos;
  53. return nbytes;
  54. }
  55. static const struct file_operations isapnp_proc_bus_file_operations = {
  56. .owner = THIS_MODULE,
  57. .llseek = isapnp_proc_bus_lseek,
  58. .read = isapnp_proc_bus_read,
  59. };
  60. static int isapnp_proc_attach_device(struct pnp_dev *dev)
  61. {
  62. struct pnp_card *bus = dev->card;
  63. struct proc_dir_entry *de, *e;
  64. char name[16];
  65. if (!(de = bus->procdir)) {
  66. sprintf(name, "%02x", bus->number);
  67. de = bus->procdir = proc_mkdir(name, isapnp_proc_bus_dir);
  68. if (!de)
  69. return -ENOMEM;
  70. }
  71. sprintf(name, "%02x", dev->number);
  72. e = dev->procent = proc_create_data(name, S_IFREG | S_IRUGO, de,
  73. &isapnp_proc_bus_file_operations, dev);
  74. if (!e)
  75. return -ENOMEM;
  76. proc_set_size(e, 256);
  77. return 0;
  78. }
  79. int __init isapnp_proc_init(void)
  80. {
  81. struct pnp_dev *dev;
  82. isapnp_proc_bus_dir = proc_mkdir("bus/isapnp", NULL);
  83. protocol_for_each_dev(&isapnp_protocol, dev) {
  84. isapnp_proc_attach_device(dev);
  85. }
  86. return 0;
  87. }