2 * Procfs interface for the Zorro bus.
4 * Copyright (C) 1998-2003 Geert Uytterhoeven
6 * Heavily based on the procfs interface for the PCI bus, which is
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/uaccess.h>
18 #include <asm/amigahw.h>
19 #include <asm/setup.h>
22 proc_bus_zorro_lseek(struct file *file, loff_t off, int whence)
25 struct inode *inode = file_inode(file);
27 mutex_lock(&inode->i_mutex);
33 new = file->f_pos + off;
36 new = sizeof(struct ConfigDev) + off;
39 if (new < 0 || new > sizeof(struct ConfigDev))
43 mutex_unlock(&inode->i_mutex);
48 proc_bus_zorro_read(struct file *file, char __user *buf, size_t nbytes, loff_t *ppos)
50 struct zorro_dev *z = PDE_DATA(file_inode(file));
54 if (pos >= sizeof(struct ConfigDev))
56 if (nbytes >= sizeof(struct ConfigDev))
57 nbytes = sizeof(struct ConfigDev);
58 if (pos + nbytes > sizeof(struct ConfigDev))
59 nbytes = sizeof(struct ConfigDev) - pos;
61 /* Construct a ConfigDev */
62 memset(&cd, 0, sizeof(cd));
64 cd.cd_SlotAddr = z->slotaddr;
65 cd.cd_SlotSize = z->slotsize;
66 cd.cd_BoardAddr = (void *)zorro_resource_start(z);
67 cd.cd_BoardSize = zorro_resource_len(z);
69 if (copy_to_user(buf, (void *)&cd + pos, nbytes))
76 static const struct file_operations proc_bus_zorro_operations = {
78 .llseek = proc_bus_zorro_lseek,
79 .read = proc_bus_zorro_read,
82 static void * zorro_seq_start(struct seq_file *m, loff_t *pos)
84 return (*pos < zorro_num_autocon) ? pos : NULL;
87 static void * zorro_seq_next(struct seq_file *m, void *v, loff_t *pos)
90 return (*pos < zorro_num_autocon) ? pos : NULL;
93 static void zorro_seq_stop(struct seq_file *m, void *v)
97 static int zorro_seq_show(struct seq_file *m, void *v)
99 unsigned int slot = *(loff_t *)v;
100 struct zorro_dev *z = &zorro_autocon[slot];
102 seq_printf(m, "%02x\t%08x\t%08lx\t%08lx\t%02x\n", slot, z->id,
103 (unsigned long)zorro_resource_start(z),
104 (unsigned long)zorro_resource_len(z),
109 static const struct seq_operations zorro_devices_seq_ops = {
110 .start = zorro_seq_start,
111 .next = zorro_seq_next,
112 .stop = zorro_seq_stop,
113 .show = zorro_seq_show,
116 static int zorro_devices_proc_open(struct inode *inode, struct file *file)
118 return seq_open(file, &zorro_devices_seq_ops);
121 static const struct file_operations zorro_devices_proc_fops = {
122 .owner = THIS_MODULE,
123 .open = zorro_devices_proc_open,
126 .release = seq_release,
129 static struct proc_dir_entry *proc_bus_zorro_dir;
131 static int __init zorro_proc_attach_device(unsigned int slot)
133 struct proc_dir_entry *entry;
136 sprintf(name, "%02x", slot);
137 entry = proc_create_data(name, 0, proc_bus_zorro_dir,
138 &proc_bus_zorro_operations,
139 &zorro_autocon[slot]);
142 proc_set_size(entry, sizeof(struct zorro_dev));
146 static int __init zorro_proc_init(void)
150 if (MACH_IS_AMIGA && AMIGAHW_PRESENT(ZORRO)) {
151 proc_bus_zorro_dir = proc_mkdir("bus/zorro", NULL);
152 proc_create("devices", 0, proc_bus_zorro_dir,
153 &zorro_devices_proc_fops);
154 for (slot = 0; slot < zorro_num_autocon; slot++)
155 zorro_proc_attach_device(slot);
160 device_initcall(zorro_proc_init);