VFS: swap do_ioctl and vfs_ioctl names
[pv_ops_mirror.git] / drivers / zorro / proc.c
blob2ce4cebc31d9d47e6465783a0fd11b06082ee7e9
1 /*
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-2003 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 <linux/smp_lock.h>
18 #include <asm/uaccess.h>
19 #include <asm/amigahw.h>
20 #include <asm/setup.h>
22 static loff_t
23 proc_bus_zorro_lseek(struct file *file, loff_t off, int whence)
25 loff_t new = -1;
27 lock_kernel();
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 unlock_kernel();
41 return -EINVAL;
43 unlock_kernel();
44 return (file->f_pos = 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->f_path.dentry->d_inode;
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, &cd, nbytes))
72 return -EFAULT;
73 *ppos += nbytes;
75 return nbytes;
78 static const struct file_operations proc_bus_zorro_operations = {
79 .llseek = proc_bus_zorro_lseek,
80 .read = proc_bus_zorro_read,
83 static int
84 get_zorro_dev_info(char *buf, char **start, off_t pos, int count)
86 u_int slot;
87 off_t at = 0;
88 int len, cnt;
90 for (slot = cnt = 0; slot < zorro_num_autocon && count > cnt; slot++) {
91 struct zorro_dev *z = &zorro_autocon[slot];
92 len = sprintf(buf, "%02x\t%08x\t%08lx\t%08lx\t%02x\n", slot,
93 z->id, (unsigned long)zorro_resource_start(z),
94 (unsigned long)zorro_resource_len(z),
95 z->rom.er_Type);
96 at += len;
97 if (at >= pos) {
98 if (!*start) {
99 *start = buf + (pos - (at - len));
100 cnt = at - pos;
101 } else
102 cnt += len;
103 buf += len;
106 return (count > cnt) ? cnt : count;
109 static struct proc_dir_entry *proc_bus_zorro_dir;
111 static int __init zorro_proc_attach_device(u_int slot)
113 struct proc_dir_entry *entry;
114 char name[4];
116 sprintf(name, "%02x", slot);
117 entry = create_proc_entry(name, 0, proc_bus_zorro_dir);
118 if (!entry)
119 return -ENOMEM;
120 entry->proc_fops = &proc_bus_zorro_operations;
121 entry->data = &zorro_autocon[slot];
122 entry->size = sizeof(struct zorro_dev);
123 return 0;
126 static int __init zorro_proc_init(void)
128 u_int slot;
130 if (MACH_IS_AMIGA && AMIGAHW_PRESENT(ZORRO)) {
131 proc_bus_zorro_dir = proc_mkdir("zorro", proc_bus);
132 create_proc_info_entry("devices", 0, proc_bus_zorro_dir,
133 get_zorro_dev_info);
134 for (slot = 0; slot < zorro_num_autocon; slot++)
135 zorro_proc_attach_device(slot);
137 return 0;
140 __initcall(zorro_proc_init);