proc.c 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. /*
  2. * Procfs interface for the Zorro bus.
  3. *
  4. * Copyright (C) 1998-2003 Geert Uytterhoeven
  5. *
  6. * Heavily based on the procfs interface for the PCI bus, which is
  7. *
  8. * Copyright (C) 1997, 1998 Martin Mares <mj@atrey.karlin.mff.cuni.cz>
  9. */
  10. #include <linux/types.h>
  11. #include <linux/zorro.h>
  12. #include <linux/proc_fs.h>
  13. #include <linux/seq_file.h>
  14. #include <linux/init.h>
  15. #include <linux/export.h>
  16. #include <asm/uaccess.h>
  17. #include <asm/amigahw.h>
  18. #include <asm/setup.h>
  19. static loff_t
  20. proc_bus_zorro_lseek(struct file *file, loff_t off, int whence)
  21. {
  22. return fixed_size_llseek(file, off, whence, sizeof(struct ConfigDev));
  23. }
  24. static ssize_t
  25. proc_bus_zorro_read(struct file *file, char __user *buf, size_t nbytes, loff_t *ppos)
  26. {
  27. struct zorro_dev *z = PDE_DATA(file_inode(file));
  28. struct ConfigDev cd;
  29. loff_t pos = *ppos;
  30. if (pos >= sizeof(struct ConfigDev))
  31. return 0;
  32. if (nbytes >= sizeof(struct ConfigDev))
  33. nbytes = sizeof(struct ConfigDev);
  34. if (pos + nbytes > sizeof(struct ConfigDev))
  35. nbytes = sizeof(struct ConfigDev) - pos;
  36. /* Construct a ConfigDev */
  37. memset(&cd, 0, sizeof(cd));
  38. cd.cd_Rom = z->rom;
  39. cd.cd_SlotAddr = z->slotaddr;
  40. cd.cd_SlotSize = z->slotsize;
  41. cd.cd_BoardAddr = (void *)zorro_resource_start(z);
  42. cd.cd_BoardSize = zorro_resource_len(z);
  43. if (copy_to_user(buf, (void *)&cd + pos, nbytes))
  44. return -EFAULT;
  45. *ppos += nbytes;
  46. return nbytes;
  47. }
  48. static const struct file_operations proc_bus_zorro_operations = {
  49. .owner = THIS_MODULE,
  50. .llseek = proc_bus_zorro_lseek,
  51. .read = proc_bus_zorro_read,
  52. };
  53. static void * zorro_seq_start(struct seq_file *m, loff_t *pos)
  54. {
  55. return (*pos < zorro_num_autocon) ? pos : NULL;
  56. }
  57. static void * zorro_seq_next(struct seq_file *m, void *v, loff_t *pos)
  58. {
  59. (*pos)++;
  60. return (*pos < zorro_num_autocon) ? pos : NULL;
  61. }
  62. static void zorro_seq_stop(struct seq_file *m, void *v)
  63. {
  64. }
  65. static int zorro_seq_show(struct seq_file *m, void *v)
  66. {
  67. unsigned int slot = *(loff_t *)v;
  68. struct zorro_dev *z = &zorro_autocon[slot];
  69. seq_printf(m, "%02x\t%08x\t%08lx\t%08lx\t%02x\n", slot, z->id,
  70. (unsigned long)zorro_resource_start(z),
  71. (unsigned long)zorro_resource_len(z),
  72. z->rom.er_Type);
  73. return 0;
  74. }
  75. static const struct seq_operations zorro_devices_seq_ops = {
  76. .start = zorro_seq_start,
  77. .next = zorro_seq_next,
  78. .stop = zorro_seq_stop,
  79. .show = zorro_seq_show,
  80. };
  81. static int zorro_devices_proc_open(struct inode *inode, struct file *file)
  82. {
  83. return seq_open(file, &zorro_devices_seq_ops);
  84. }
  85. static const struct file_operations zorro_devices_proc_fops = {
  86. .owner = THIS_MODULE,
  87. .open = zorro_devices_proc_open,
  88. .read = seq_read,
  89. .llseek = seq_lseek,
  90. .release = seq_release,
  91. };
  92. static struct proc_dir_entry *proc_bus_zorro_dir;
  93. static int __init zorro_proc_attach_device(unsigned int slot)
  94. {
  95. struct proc_dir_entry *entry;
  96. char name[4];
  97. sprintf(name, "%02x", slot);
  98. entry = proc_create_data(name, 0, proc_bus_zorro_dir,
  99. &proc_bus_zorro_operations,
  100. &zorro_autocon[slot]);
  101. if (!entry)
  102. return -ENOMEM;
  103. proc_set_size(entry, sizeof(struct zorro_dev));
  104. return 0;
  105. }
  106. static int __init zorro_proc_init(void)
  107. {
  108. unsigned int slot;
  109. if (MACH_IS_AMIGA && AMIGAHW_PRESENT(ZORRO)) {
  110. proc_bus_zorro_dir = proc_mkdir("bus/zorro", NULL);
  111. proc_create("devices", 0, proc_bus_zorro_dir,
  112. &zorro_devices_proc_fops);
  113. for (slot = 0; slot < zorro_num_autocon; slot++)
  114. zorro_proc_attach_device(slot);
  115. }
  116. return 0;
  117. }
  118. device_initcall(zorro_proc_init);