aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/zorro/proc.c
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@ppc970.osdl.org>2005-04-16 18:20:36 -0400
committerLinus Torvalds <torvalds@ppc970.osdl.org>2005-04-16 18:20:36 -0400
commit1da177e4c3f41524e886b7f1b8a0c1fc7321cac2 (patch)
tree0bba044c4ce775e45a88a51686b5d9f90697ea9d /drivers/zorro/proc.c
Linux-2.6.12-rc2
Initial git repository build. I'm not bothering with the full history, even though we have it. We can create a separate "historical" git archive of that later if we want to, and in the meantime it's about 3.2GB when imported into git - space that would just make the early git days unnecessarily complicated, when we don't have a lot of good infrastructure for it. Let it rip!
Diffstat (limited to 'drivers/zorro/proc.c')
-rw-r--r--drivers/zorro/proc.c139
1 files changed, 139 insertions, 0 deletions
diff --git a/drivers/zorro/proc.c b/drivers/zorro/proc.c
new file mode 100644
index 00000000000..1a409c2c320
--- /dev/null
+++ b/drivers/zorro/proc.c
@@ -0,0 +1,139 @@
1/*
2 * $Id: proc.c,v 1.1.2.1 1998/06/07 23:21:01 geert Exp $
3 *
4 * Procfs interface for the Zorro bus.
5 *
6 * Copyright (C) 1998-2003 Geert Uytterhoeven
7 *
8 * Heavily based on the procfs interface for the PCI bus, which is
9 *
10 * Copyright (C) 1997, 1998 Martin Mares <mj@atrey.karlin.mff.cuni.cz>
11 */
12
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>
21
22static loff_t
23proc_bus_zorro_lseek(struct file *file, loff_t off, int whence)
24{
25 loff_t new = -1;
26
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;
38 }
39 if (new < 0 || new > sizeof(struct ConfigDev)) {
40 unlock_kernel();
41 return -EINVAL;
42 }
43 unlock_kernel();
44 return (file->f_pos = new);
45}
46
47static ssize_t
48proc_bus_zorro_read(struct file *file, char *buf, size_t nbytes, loff_t *ppos)
49{
50 struct inode *ino = file->f_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;
55
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;
62
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);
70
71 if (copy_to_user(buf, &cd, nbytes))
72 return -EFAULT;
73 *ppos += nbytes;
74
75 return nbytes;
76}
77
78static struct file_operations proc_bus_zorro_operations = {
79 .llseek = proc_bus_zorro_lseek,
80 .read = proc_bus_zorro_read,
81};
82
83static int
84get_zorro_dev_info(char *buf, char **start, off_t pos, int count)
85{
86 u_int slot;
87 off_t at = 0;
88 int len, cnt;
89
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, zorro_resource_start(z),
94 zorro_resource_len(z), z->rom.er_Type);
95 at += len;
96 if (at >= pos) {
97 if (!*start) {
98 *start = buf + (pos - (at - len));
99 cnt = at - pos;
100 } else
101 cnt += len;
102 buf += len;
103 }
104 }
105 return (count > cnt) ? cnt : count;
106}
107
108static struct proc_dir_entry *proc_bus_zorro_dir;
109
110static int __init zorro_proc_attach_device(u_int slot)
111{
112 struct proc_dir_entry *entry;
113 char name[4];
114
115 sprintf(name, "%02x", slot);
116 entry = create_proc_entry(name, 0, proc_bus_zorro_dir);
117 if (!entry)
118 return -ENOMEM;
119 entry->proc_fops = &proc_bus_zorro_operations;
120 entry->data = &zorro_autocon[slot];
121 entry->size = sizeof(struct zorro_dev);
122 return 0;
123}
124
125static int __init zorro_proc_init(void)
126{
127 u_int slot;
128
129 if (MACH_IS_AMIGA && AMIGAHW_PRESENT(ZORRO)) {
130 proc_bus_zorro_dir = proc_mkdir("zorro", proc_bus);
131 create_proc_info_entry("devices", 0, proc_bus_zorro_dir,
132 get_zorro_dev_info);
133 for (slot = 0; slot < zorro_num_autocon; slot++)
134 zorro_proc_attach_device(slot);
135 }
136 return 0;
137}
138
139__initcall(zorro_proc_init);