proc.c 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  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/init.h>
  16. #include <linux/smp_lock.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. loff_t new = -1;
  24. lock_kernel();
  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. unlock_kernel();
  38. return -EINVAL;
  39. }
  40. unlock_kernel();
  41. return (file->f_pos = 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_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, &cd, nbytes))
  65. return -EFAULT;
  66. *ppos += nbytes;
  67. return nbytes;
  68. }
  69. static struct file_operations proc_bus_zorro_operations = {
  70. .llseek = proc_bus_zorro_lseek,
  71. .read = proc_bus_zorro_read,
  72. };
  73. static int
  74. get_zorro_dev_info(char *buf, char **start, off_t pos, int count)
  75. {
  76. u_int slot;
  77. off_t at = 0;
  78. int len, cnt;
  79. for (slot = cnt = 0; slot < zorro_num_autocon && count > cnt; slot++) {
  80. struct zorro_dev *z = &zorro_autocon[slot];
  81. len = sprintf(buf, "%02x\t%08x\t%08lx\t%08lx\t%02x\n", slot,
  82. z->id, zorro_resource_start(z),
  83. zorro_resource_len(z), z->rom.er_Type);
  84. at += len;
  85. if (at >= pos) {
  86. if (!*start) {
  87. *start = buf + (pos - (at - len));
  88. cnt = at - pos;
  89. } else
  90. cnt += len;
  91. buf += len;
  92. }
  93. }
  94. return (count > cnt) ? cnt : count;
  95. }
  96. static struct proc_dir_entry *proc_bus_zorro_dir;
  97. static int __init zorro_proc_attach_device(u_int slot)
  98. {
  99. struct proc_dir_entry *entry;
  100. char name[4];
  101. sprintf(name, "%02x", slot);
  102. entry = create_proc_entry(name, 0, proc_bus_zorro_dir);
  103. if (!entry)
  104. return -ENOMEM;
  105. entry->proc_fops = &proc_bus_zorro_operations;
  106. entry->data = &zorro_autocon[slot];
  107. entry->size = sizeof(struct zorro_dev);
  108. return 0;
  109. }
  110. static int __init zorro_proc_init(void)
  111. {
  112. u_int slot;
  113. if (MACH_IS_AMIGA && AMIGAHW_PRESENT(ZORRO)) {
  114. proc_bus_zorro_dir = proc_mkdir("zorro", proc_bus);
  115. create_proc_info_entry("devices", 0, proc_bus_zorro_dir,
  116. get_zorro_dev_info);
  117. for (slot = 0; slot < zorro_num_autocon; slot++)
  118. zorro_proc_attach_device(slot);
  119. }
  120. return 0;
  121. }
  122. __initcall(zorro_proc_init);