2 * $Id: proc.c,v 1.1.2.1 1998/06/07 23:21:01 geert Exp $
4 * Procfs interface for the Zorro bus.
6 * Copyright (C) 1998-2000 Geert Uytterhoeven
8 * Heavily based on the procfs interface for the PCI bus, which is
10 * Copyright (C) 1997, 1998 Martin Mares <mj@atrey.karlin.mff.cuni.cz>
13 #include <linux/types.h>
14 #include <linux/zorro.h>
15 #include <linux/proc_fs.h>
16 #include <linux/init.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)
31 new = file->f_pos + off;
34 new = sizeof(struct ConfigDev) + off;
39 if (new < 0 || new > sizeof(struct ConfigDev))
41 return (file->f_pos = new);
45 proc_bus_zorro_read(struct file *file, char *buf, size_t nbytes, loff_t *ppos)
47 struct inode *ino = file->f_dentry->d_inode;
48 struct proc_dir_entry *dp = ino->u.generic_ip;
49 struct zorro_dev *dev = dp->data;
53 if (pos < 0 || pos >= sizeof(struct ConfigDev))
55 if (nbytes > sizeof(struct ConfigDev) - pos)
56 nbytes = sizeof(struct ConfigDev) - pos;
58 /* Construct a ConfigDev */
59 memset(&cd, 0, sizeof(cd));
61 cd.cd_SlotAddr = dev->slotaddr;
62 cd.cd_SlotSize = dev->slotsize;
63 cd.cd_BoardAddr = (void *)dev->resource.start;
64 cd.cd_BoardSize = dev->resource.end-dev->resource.start+1;
66 if (copy_to_user(buf, &cd, nbytes))
73 static struct file_operations proc_bus_zorro_operations = {
74 llseek: proc_bus_zorro_lseek,
75 read: proc_bus_zorro_read,
79 get_zorro_dev_info(char *buf, char **start, off_t pos, int count)
85 for (slot = cnt = 0; slot < zorro_num_autocon && count > cnt; slot++) {
86 struct zorro_dev *dev = &zorro_autocon[slot];
87 len = sprintf(buf, "%02x\t%08x\t%08lx\t%08lx\t%02x\n", slot,
88 dev->id, dev->resource.start,
89 dev->resource.end-dev->resource.start+1,
94 *start = buf + (pos - (at - len));
101 return (count > cnt) ? cnt : count;
104 static struct proc_dir_entry *proc_bus_zorro_dir;
106 static int __init zorro_proc_attach_device(u_int slot)
108 struct proc_dir_entry *entry;
111 sprintf(name, "%02x", slot);
112 entry = create_proc_entry(name, 0, proc_bus_zorro_dir);
115 entry->proc_fops = &proc_bus_zorro_operations;
116 entry->data = &zorro_autocon[slot];
117 entry->size = sizeof(struct zorro_dev);
121 static int __init zorro_proc_init(void)
125 if (MACH_IS_AMIGA && AMIGAHW_PRESENT(ZORRO)) {
126 proc_bus_zorro_dir = proc_mkdir("zorro", proc_bus);
127 create_proc_info_entry("devices", 0, proc_bus_zorro_dir,
129 for (slot = 0; slot < zorro_num_autocon; slot++)
130 zorro_proc_attach_device(slot);
135 __initcall(zorro_proc_init);