proc.c 3.5 KB

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