proc.c 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. // SPDX-License-Identifier: GPL-2.0
  2. /*
  3. * Procfs interface for the Zorro bus.
  4. *
  5. * Copyright (C) 1998-2003 Geert Uytterhoeven
  6. *
  7. * Heavily based on the procfs interface for the PCI bus, which is
  8. *
  9. * Copyright (C) 1997, 1998 Martin Mares <mj@atrey.karlin.mff.cuni.cz>
  10. */
  11. #include <linux/types.h>
  12. #include <linux/zorro.h>
  13. #include <linux/proc_fs.h>
  14. #include <linux/seq_file.h>
  15. #include <linux/init.h>
  16. #include <linux/export.h>
  17. #include <asm/byteorder.h>
  18. #include <linux/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. return fixed_size_llseek(file, off, whence, sizeof(struct ConfigDev));
  25. }
  26. static ssize_t
  27. proc_bus_zorro_read(struct file *file, char __user *buf, size_t nbytes, loff_t *ppos)
  28. {
  29. struct zorro_dev *z = PDE_DATA(file_inode(file));
  30. struct ConfigDev cd;
  31. loff_t pos = *ppos;
  32. if (pos >= sizeof(struct ConfigDev))
  33. return 0;
  34. if (nbytes >= sizeof(struct ConfigDev))
  35. nbytes = sizeof(struct ConfigDev);
  36. if (pos + nbytes > sizeof(struct ConfigDev))
  37. nbytes = sizeof(struct ConfigDev) - pos;
  38. /* Construct a ConfigDev */
  39. memset(&cd, 0, sizeof(cd));
  40. cd.cd_Rom = z->rom;
  41. cd.cd_SlotAddr = cpu_to_be16(z->slotaddr);
  42. cd.cd_SlotSize = cpu_to_be16(z->slotsize);
  43. cd.cd_BoardAddr = cpu_to_be32(zorro_resource_start(z));
  44. cd.cd_BoardSize = cpu_to_be32(zorro_resource_len(z));
  45. if (copy_to_user(buf, (void *)&cd + pos, nbytes))
  46. return -EFAULT;
  47. *ppos += nbytes;
  48. return nbytes;
  49. }
  50. static const struct proc_ops bus_zorro_proc_ops = {
  51. .proc_lseek = proc_bus_zorro_lseek,
  52. .proc_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 struct proc_dir_entry *proc_bus_zorro_dir;
  83. static int __init zorro_proc_attach_device(unsigned int slot)
  84. {
  85. struct proc_dir_entry *entry;
  86. char name[4];
  87. sprintf(name, "%02x", slot);
  88. entry = proc_create_data(name, 0, proc_bus_zorro_dir,
  89. &bus_zorro_proc_ops,
  90. &zorro_autocon[slot]);
  91. if (!entry)
  92. return -ENOMEM;
  93. proc_set_size(entry, sizeof(struct zorro_dev));
  94. return 0;
  95. }
  96. static int __init zorro_proc_init(void)
  97. {
  98. unsigned int slot;
  99. if (MACH_IS_AMIGA && AMIGAHW_PRESENT(ZORRO)) {
  100. proc_bus_zorro_dir = proc_mkdir("bus/zorro", NULL);
  101. proc_create_seq("devices", 0, proc_bus_zorro_dir,
  102. &zorro_devices_seq_ops);
  103. for (slot = 0; slot < zorro_num_autocon; slot++)
  104. zorro_proc_attach_device(slot);
  105. }
  106. return 0;
  107. }
  108. device_initcall(zorro_proc_init);