proc.c 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  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->f_path.dentry->d_inode;
  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 inode *ino = file->f_path.dentry->d_inode;
  47. struct proc_dir_entry *dp = PDE(ino);
  48. struct zorro_dev *z = dp->data;
  49. struct ConfigDev cd;
  50. loff_t pos = *ppos;
  51. if (pos >= sizeof(struct ConfigDev))
  52. return 0;
  53. if (nbytes >= sizeof(struct ConfigDev))
  54. nbytes = sizeof(struct ConfigDev);
  55. if (pos + nbytes > sizeof(struct ConfigDev))
  56. nbytes = sizeof(struct ConfigDev) - pos;
  57. /* Construct a ConfigDev */
  58. memset(&cd, 0, sizeof(cd));
  59. cd.cd_Rom = z->rom;
  60. cd.cd_SlotAddr = z->slotaddr;
  61. cd.cd_SlotSize = z->slotsize;
  62. cd.cd_BoardAddr = (void *)zorro_resource_start(z);
  63. cd.cd_BoardSize = zorro_resource_len(z);
  64. if (copy_to_user(buf, (void *)&cd + pos, nbytes))
  65. return -EFAULT;
  66. *ppos += nbytes;
  67. return nbytes;
  68. }
  69. static const struct file_operations proc_bus_zorro_operations = {
  70. .owner = THIS_MODULE,
  71. .llseek = proc_bus_zorro_lseek,
  72. .read = proc_bus_zorro_read,
  73. };
  74. static void * zorro_seq_start(struct seq_file *m, loff_t *pos)
  75. {
  76. return (*pos < zorro_num_autocon) ? pos : NULL;
  77. }
  78. static void * zorro_seq_next(struct seq_file *m, void *v, loff_t *pos)
  79. {
  80. (*pos)++;
  81. return (*pos < zorro_num_autocon) ? pos : NULL;
  82. }
  83. static void zorro_seq_stop(struct seq_file *m, void *v)
  84. {
  85. }
  86. static int zorro_seq_show(struct seq_file *m, void *v)
  87. {
  88. unsigned int slot = *(loff_t *)v;
  89. struct zorro_dev *z = &zorro_autocon[slot];
  90. seq_printf(m, "%02x\t%08x\t%08lx\t%08lx\t%02x\n", slot, z->id,
  91. (unsigned long)zorro_resource_start(z),
  92. (unsigned long)zorro_resource_len(z),
  93. z->rom.er_Type);
  94. return 0;
  95. }
  96. static const struct seq_operations zorro_devices_seq_ops = {
  97. .start = zorro_seq_start,
  98. .next = zorro_seq_next,
  99. .stop = zorro_seq_stop,
  100. .show = zorro_seq_show,
  101. };
  102. static int zorro_devices_proc_open(struct inode *inode, struct file *file)
  103. {
  104. return seq_open(file, &zorro_devices_seq_ops);
  105. }
  106. static const struct file_operations zorro_devices_proc_fops = {
  107. .owner = THIS_MODULE,
  108. .open = zorro_devices_proc_open,
  109. .read = seq_read,
  110. .llseek = seq_lseek,
  111. .release = seq_release,
  112. };
  113. static struct proc_dir_entry *proc_bus_zorro_dir;
  114. static int __init zorro_proc_attach_device(unsigned int slot)
  115. {
  116. struct proc_dir_entry *entry;
  117. char name[4];
  118. sprintf(name, "%02x", slot);
  119. entry = proc_create_data(name, 0, proc_bus_zorro_dir,
  120. &proc_bus_zorro_operations,
  121. &zorro_autocon[slot]);
  122. if (!entry)
  123. return -ENOMEM;
  124. entry->size = sizeof(struct zorro_dev);
  125. return 0;
  126. }
  127. static int __init zorro_proc_init(void)
  128. {
  129. unsigned int slot;
  130. if (MACH_IS_AMIGA && AMIGAHW_PRESENT(ZORRO)) {
  131. proc_bus_zorro_dir = proc_mkdir("bus/zorro", NULL);
  132. proc_create("devices", 0, proc_bus_zorro_dir,
  133. &zorro_devices_proc_fops);
  134. for (slot = 0; slot < zorro_num_autocon; slot++)
  135. zorro_proc_attach_device(slot);
  136. }
  137. return 0;
  138. }
  139. device_initcall(zorro_proc_init);