proc.c 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  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 file_operations proc_bus_zorro_operations = {
  51. .owner = THIS_MODULE,
  52. .llseek = proc_bus_zorro_lseek,
  53. .read = proc_bus_zorro_read,
  54. };
  55. static void * zorro_seq_start(struct seq_file *m, loff_t *pos)
  56. {
  57. return (*pos < zorro_num_autocon) ? pos : NULL;
  58. }
  59. static void * zorro_seq_next(struct seq_file *m, void *v, loff_t *pos)
  60. {
  61. (*pos)++;
  62. return (*pos < zorro_num_autocon) ? pos : NULL;
  63. }
  64. static void zorro_seq_stop(struct seq_file *m, void *v)
  65. {
  66. }
  67. static int zorro_seq_show(struct seq_file *m, void *v)
  68. {
  69. unsigned int slot = *(loff_t *)v;
  70. struct zorro_dev *z = &zorro_autocon[slot];
  71. seq_printf(m, "%02x\t%08x\t%08lx\t%08lx\t%02x\n", slot, z->id,
  72. (unsigned long)zorro_resource_start(z),
  73. (unsigned long)zorro_resource_len(z),
  74. z->rom.er_Type);
  75. return 0;
  76. }
  77. static const struct seq_operations zorro_devices_seq_ops = {
  78. .start = zorro_seq_start,
  79. .next = zorro_seq_next,
  80. .stop = zorro_seq_stop,
  81. .show = zorro_seq_show,
  82. };
  83. static struct proc_dir_entry *proc_bus_zorro_dir;
  84. static int __init zorro_proc_attach_device(unsigned int slot)
  85. {
  86. struct proc_dir_entry *entry;
  87. char name[4];
  88. sprintf(name, "%02x", slot);
  89. entry = proc_create_data(name, 0, proc_bus_zorro_dir,
  90. &proc_bus_zorro_operations,
  91. &zorro_autocon[slot]);
  92. if (!entry)
  93. return -ENOMEM;
  94. proc_set_size(entry, sizeof(struct zorro_dev));
  95. return 0;
  96. }
  97. static int __init zorro_proc_init(void)
  98. {
  99. unsigned int slot;
  100. if (MACH_IS_AMIGA && AMIGAHW_PRESENT(ZORRO)) {
  101. proc_bus_zorro_dir = proc_mkdir("bus/zorro", NULL);
  102. proc_create_seq("devices", 0, proc_bus_zorro_dir,
  103. &zorro_devices_seq_ops);
  104. for (slot = 0; slot < zorro_num_autocon; slot++)
  105. zorro_proc_attach_device(slot);
  106. }
  107. return 0;
  108. }
  109. device_initcall(zorro_proc_init);