proc.c 3.7 KB

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