Merge git://git.kernel.org/pub/scm/linux/kernel/git/davem/net
[linux/fpc-iii.git] / drivers / zorro / proc.c
blob73b33837e12c43d717153d985f1310e9b248dc84
1 /*
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
8 * Copyright (C) 1997, 1998 Martin Mares <mj@atrey.karlin.mff.cuni.cz>
9 */
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>
21 static loff_t
22 proc_bus_zorro_lseek(struct file *file, loff_t off, int whence)
24 loff_t new = -1;
25 struct inode *inode = file_inode(file);
27 mutex_lock(&inode->i_mutex);
28 switch (whence) {
29 case 0:
30 new = off;
31 break;
32 case 1:
33 new = file->f_pos + off;
34 break;
35 case 2:
36 new = sizeof(struct ConfigDev) + off;
37 break;
39 if (new < 0 || new > sizeof(struct ConfigDev))
40 new = -EINVAL;
41 else
42 file->f_pos = new;
43 mutex_unlock(&inode->i_mutex);
44 return new;
47 static ssize_t
48 proc_bus_zorro_read(struct file *file, char __user *buf, size_t nbytes, loff_t *ppos)
50 struct inode *ino = file_inode(file);
51 struct proc_dir_entry *dp = PDE(ino);
52 struct zorro_dev *z = dp->data;
53 struct ConfigDev cd;
54 loff_t pos = *ppos;
56 if (pos >= sizeof(struct ConfigDev))
57 return 0;
58 if (nbytes >= sizeof(struct ConfigDev))
59 nbytes = sizeof(struct ConfigDev);
60 if (pos + nbytes > sizeof(struct ConfigDev))
61 nbytes = sizeof(struct ConfigDev) - pos;
63 /* Construct a ConfigDev */
64 memset(&cd, 0, sizeof(cd));
65 cd.cd_Rom = z->rom;
66 cd.cd_SlotAddr = z->slotaddr;
67 cd.cd_SlotSize = z->slotsize;
68 cd.cd_BoardAddr = (void *)zorro_resource_start(z);
69 cd.cd_BoardSize = zorro_resource_len(z);
71 if (copy_to_user(buf, (void *)&cd + pos, nbytes))
72 return -EFAULT;
73 *ppos += nbytes;
75 return nbytes;
78 static const struct file_operations proc_bus_zorro_operations = {
79 .owner = THIS_MODULE,
80 .llseek = proc_bus_zorro_lseek,
81 .read = proc_bus_zorro_read,
84 static void * zorro_seq_start(struct seq_file *m, loff_t *pos)
86 return (*pos < zorro_num_autocon) ? pos : NULL;
89 static void * zorro_seq_next(struct seq_file *m, void *v, loff_t *pos)
91 (*pos)++;
92 return (*pos < zorro_num_autocon) ? pos : NULL;
95 static void zorro_seq_stop(struct seq_file *m, void *v)
99 static int zorro_seq_show(struct seq_file *m, void *v)
101 unsigned int slot = *(loff_t *)v;
102 struct zorro_dev *z = &zorro_autocon[slot];
104 seq_printf(m, "%02x\t%08x\t%08lx\t%08lx\t%02x\n", slot, z->id,
105 (unsigned long)zorro_resource_start(z),
106 (unsigned long)zorro_resource_len(z),
107 z->rom.er_Type);
108 return 0;
111 static const struct seq_operations zorro_devices_seq_ops = {
112 .start = zorro_seq_start,
113 .next = zorro_seq_next,
114 .stop = zorro_seq_stop,
115 .show = zorro_seq_show,
118 static int zorro_devices_proc_open(struct inode *inode, struct file *file)
120 return seq_open(file, &zorro_devices_seq_ops);
123 static const struct file_operations zorro_devices_proc_fops = {
124 .owner = THIS_MODULE,
125 .open = zorro_devices_proc_open,
126 .read = seq_read,
127 .llseek = seq_lseek,
128 .release = seq_release,
131 static struct proc_dir_entry *proc_bus_zorro_dir;
133 static int __init zorro_proc_attach_device(unsigned int slot)
135 struct proc_dir_entry *entry;
136 char name[4];
138 sprintf(name, "%02x", slot);
139 entry = proc_create_data(name, 0, proc_bus_zorro_dir,
140 &proc_bus_zorro_operations,
141 &zorro_autocon[slot]);
142 if (!entry)
143 return -ENOMEM;
144 entry->size = sizeof(struct zorro_dev);
145 return 0;
148 static int __init zorro_proc_init(void)
150 unsigned int slot;
152 if (MACH_IS_AMIGA && AMIGAHW_PRESENT(ZORRO)) {
153 proc_bus_zorro_dir = proc_mkdir("bus/zorro", NULL);
154 proc_create("devices", 0, proc_bus_zorro_dir,
155 &zorro_devices_proc_fops);
156 for (slot = 0; slot < zorro_num_autocon; slot++)
157 zorro_proc_attach_device(slot);
159 return 0;
162 device_initcall(zorro_proc_init);