1 // SPDX-License-Identifier: GPL-2.0
3 * Procfs interface for the Zorro bus.
5 * Copyright (C) 1998-2003 Geert Uytterhoeven
7 * Heavily based on the procfs interface for the PCI bus, which is
9 * Copyright (C) 1997, 1998 Martin Mares <mj@atrey.karlin.mff.cuni.cz>
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/export.h>
19 #include <asm/byteorder.h>
20 #include <linux/uaccess.h>
21 #include <asm/amigahw.h>
22 #include <asm/setup.h>
25 proc_bus_zorro_lseek(struct file *file, loff_t off, int whence)
27 return fixed_size_llseek(file, off, whence, sizeof(struct ConfigDev));
31 proc_bus_zorro_read(struct file *file, char __user *buf, size_t nbytes, loff_t *ppos)
33 struct zorro_dev *z = PDE_DATA(file_inode(file));
37 if (pos >= sizeof(struct ConfigDev))
39 if (nbytes >= sizeof(struct ConfigDev))
40 nbytes = sizeof(struct ConfigDev);
41 if (pos + nbytes > sizeof(struct ConfigDev))
42 nbytes = sizeof(struct ConfigDev) - pos;
44 /* Construct a ConfigDev */
45 memset(&cd, 0, sizeof(cd));
47 cd.cd_SlotAddr = cpu_to_be16(z->slotaddr);
48 cd.cd_SlotSize = cpu_to_be16(z->slotsize);
49 cd.cd_BoardAddr = cpu_to_be32(zorro_resource_start(z));
50 cd.cd_BoardSize = cpu_to_be32(zorro_resource_len(z));
52 if (copy_to_user(buf, (void *)&cd + pos, nbytes))
59 static const struct file_operations proc_bus_zorro_operations = {
61 .llseek = proc_bus_zorro_lseek,
62 .read = proc_bus_zorro_read,
65 static void * zorro_seq_start(struct seq_file *m, loff_t *pos)
67 return (*pos < zorro_num_autocon) ? pos : NULL;
70 static void * zorro_seq_next(struct seq_file *m, void *v, loff_t *pos)
73 return (*pos < zorro_num_autocon) ? pos : NULL;
76 static void zorro_seq_stop(struct seq_file *m, void *v)
80 static int zorro_seq_show(struct seq_file *m, void *v)
82 unsigned int slot = *(loff_t *)v;
83 struct zorro_dev *z = &zorro_autocon[slot];
85 seq_printf(m, "%02x\t%08x\t%08lx\t%08lx\t%02x\n", slot, z->id,
86 (unsigned long)zorro_resource_start(z),
87 (unsigned long)zorro_resource_len(z),
92 static const struct seq_operations zorro_devices_seq_ops = {
93 .start = zorro_seq_start,
94 .next = zorro_seq_next,
95 .stop = zorro_seq_stop,
96 .show = zorro_seq_show,
99 static struct proc_dir_entry *proc_bus_zorro_dir;
101 static int __init zorro_proc_attach_device(unsigned int slot)
103 struct proc_dir_entry *entry;
106 sprintf(name, "%02x", slot);
107 entry = proc_create_data(name, 0, proc_bus_zorro_dir,
108 &proc_bus_zorro_operations,
109 &zorro_autocon[slot]);
112 proc_set_size(entry, sizeof(struct zorro_dev));
116 static int __init zorro_proc_init(void)
120 if (MACH_IS_AMIGA && AMIGAHW_PRESENT(ZORRO)) {
121 proc_bus_zorro_dir = proc_mkdir("bus/zorro", NULL);
122 proc_create_seq("devices", 0, proc_bus_zorro_dir,
123 &zorro_devices_seq_ops);
124 for (slot = 0; slot < zorro_num_autocon; slot++)
125 zorro_proc_attach_device(slot);
130 device_initcall(zorro_proc_init);