proc.c 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  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. loff_t new = -1;
  23. struct inode *inode = file_inode(file);
  24. mutex_lock(&inode->i_mutex);
  25. switch (whence) {
  26. case 0:
  27. new = off;
  28. break;
  29. case 1:
  30. new = file->f_pos + off;
  31. break;
  32. case 2:
  33. new = sizeof(struct ConfigDev) + off;
  34. break;
  35. }
  36. if (new < 0 || new > sizeof(struct ConfigDev))
  37. new = -EINVAL;
  38. else
  39. file->f_pos = new;
  40. mutex_unlock(&inode->i_mutex);
  41. return new;
  42. }
  43. static ssize_t
  44. proc_bus_zorro_read(struct file *file, char __user *buf, size_t nbytes, loff_t *ppos)
  45. {
  46. struct zorro_dev *z = PDE_DATA(file_inode(file));
  47. struct ConfigDev cd;
  48. loff_t pos = *ppos;
  49. if (pos >= sizeof(struct ConfigDev))
  50. return 0;
  51. if (nbytes >= sizeof(struct ConfigDev))
  52. nbytes = sizeof(struct ConfigDev);
  53. if (pos + nbytes > sizeof(struct ConfigDev))
  54. nbytes = sizeof(struct ConfigDev) - pos;
  55. /* Construct a ConfigDev */
  56. memset(&cd, 0, sizeof(cd));
  57. cd.cd_Rom = z->rom;
  58. cd.cd_SlotAddr = z->slotaddr;
  59. cd.cd_SlotSize = z->slotsize;
  60. cd.cd_BoardAddr = (void *)zorro_resource_start(z);
  61. cd.cd_BoardSize = zorro_resource_len(z);
  62. if (copy_to_user(buf, (void *)&cd + pos, nbytes))
  63. return -EFAULT;
  64. *ppos += nbytes;
  65. return nbytes;
  66. }
  67. static const struct file_operations proc_bus_zorro_operations = {
  68. .owner = THIS_MODULE,
  69. .llseek = proc_bus_zorro_lseek,
  70. .read = proc_bus_zorro_read,
  71. };
  72. static void * zorro_seq_start(struct seq_file *m, loff_t *pos)
  73. {
  74. return (*pos < zorro_num_autocon) ? pos : NULL;
  75. }
  76. static void * zorro_seq_next(struct seq_file *m, void *v, loff_t *pos)
  77. {
  78. (*pos)++;
  79. return (*pos < zorro_num_autocon) ? pos : NULL;
  80. }
  81. static void zorro_seq_stop(struct seq_file *m, void *v)
  82. {
  83. }
  84. static int zorro_seq_show(struct seq_file *m, void *v)
  85. {
  86. unsigned int slot = *(loff_t *)v;
  87. struct zorro_dev *z = &zorro_autocon[slot];
  88. seq_printf(m, "%02x\t%08x\t%08lx\t%08lx\t%02x\n", slot, z->id,
  89. (unsigned long)zorro_resource_start(z),
  90. (unsigned long)zorro_resource_len(z),
  91. z->rom.er_Type);
  92. return 0;
  93. }
  94. static const struct seq_operations zorro_devices_seq_ops = {
  95. .start = zorro_seq_start,
  96. .next = zorro_seq_next,
  97. .stop = zorro_seq_stop,
  98. .show = zorro_seq_show,
  99. };
  100. static int zorro_devices_proc_open(struct inode *inode, struct file *file)
  101. {
  102. return seq_open(file, &zorro_devices_seq_ops);
  103. }
  104. static const struct file_operations zorro_devices_proc_fops = {
  105. .owner = THIS_MODULE,
  106. .open = zorro_devices_proc_open,
  107. .read = seq_read,
  108. .llseek = seq_lseek,
  109. .release = seq_release,
  110. };
  111. static struct proc_dir_entry *proc_bus_zorro_dir;
  112. static int __init zorro_proc_attach_device(unsigned int slot)
  113. {
  114. struct proc_dir_entry *entry;
  115. char name[4];
  116. sprintf(name, "%02x", slot);
  117. entry = proc_create_data(name, 0, proc_bus_zorro_dir,
  118. &proc_bus_zorro_operations,
  119. &zorro_autocon[slot]);
  120. if (!entry)
  121. return -ENOMEM;
  122. proc_set_size(entry, sizeof(struct zorro_dev));
  123. return 0;
  124. }
  125. static int __init zorro_proc_init(void)
  126. {
  127. unsigned int slot;
  128. if (MACH_IS_AMIGA && AMIGAHW_PRESENT(ZORRO)) {
  129. proc_bus_zorro_dir = proc_mkdir("bus/zorro", NULL);
  130. proc_create("devices", 0, proc_bus_zorro_dir,
  131. &zorro_devices_proc_fops);
  132. for (slot = 0; slot < zorro_num_autocon; slot++)
  133. zorro_proc_attach_device(slot);
  134. }
  135. return 0;
  136. }
  137. device_initcall(zorro_proc_init);