Import 2.1.118
[davej-history.git] / drivers / zorro / proc.c
blobb208392a9ce470a6dac791b6870c6a286d11e120
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 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>
21 static loff_t
22 proc_bus_zorro_lseek(struct file *file, loff_t off, int whence)
24 loff_t new;
26 switch (whence) {
27 case 0:
28 new = off;
29 break;
30 case 1:
31 new = file->f_pos + off;
32 break;
33 case 2:
34 new = sizeof(struct ConfigDev) + off;
35 break;
36 default:
37 return -EINVAL;
39 if (new < 0 || new > sizeof(struct ConfigDev))
40 return -EINVAL;
41 return (file->f_pos = new);
44 static ssize_t
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 ConfigDev *cd = dp->data;
50 int pos = *ppos;
52 if (pos >= sizeof(struct ConfigDev))
53 return 0;
54 if (nbytes >= sizeof(struct ConfigDev))
55 nbytes = sizeof(struct ConfigDev);
56 if (pos + nbytes > sizeof(struct ConfigDev))
57 nbytes = sizeof(struct ConfigDev) - pos;
58 if (copy_to_user(buf, cd, nbytes))
59 return -EFAULT;
60 *ppos += nbytes;
62 return nbytes;
65 static struct file_operations proc_bus_zorro_operations = {
66 proc_bus_zorro_lseek,
67 proc_bus_zorro_read,
68 NULL, /* write */
69 NULL, /* readdir */
70 NULL, /* poll */
71 NULL, /* ioctl */
72 NULL, /* mmap */
73 NULL, /* no special open code */
74 NULL, /* flush */
75 NULL, /* no special release code */
76 NULL /* can't fsync */
79 static struct inode_operations proc_bus_zorro_inode_operations = {
80 &proc_bus_zorro_operations, /* default base directory file-ops */
81 NULL, /* create */
82 NULL, /* lookup */
83 NULL, /* link */
84 NULL, /* unlink */
85 NULL, /* symlink */
86 NULL, /* mkdir */
87 NULL, /* rmdir */
88 NULL, /* mknod */
89 NULL, /* rename */
90 NULL, /* readlink */
91 NULL, /* follow_link */
92 NULL, /* readpage */
93 NULL, /* writepage */
94 NULL, /* bmap */
95 NULL, /* truncate */
96 NULL /* permission */
99 int
100 get_zorro_dev_info(char *buf, char **start, off_t pos, int count, int wr)
102 u_int slot;
103 off_t at = 0;
104 int len, cnt;
106 for (slot = cnt = 0; slot < zorro_num_autocon && count > cnt; slot++) {
107 struct ConfigDev *cd = &zorro_autocon[slot];
108 u16 manuf = cd->cd_Rom.er_Manufacturer;
109 u8 prod = cd->cd_Rom.er_Product;
110 u8 epc;
111 if (manuf == ZORRO_MANUF(ZORRO_PROD_GVP_EPC_BASE) &&
112 prod == ZORRO_PROD(ZORRO_PROD_GVP_EPC_BASE)) {
113 /* GVP quirk */
114 u32 addr = (u32)cd->cd_BoardAddr;
115 epc = (*(u16 *)ZTWO_VADDR(addr+0x8000)) & GVP_PRODMASK;
116 } else
117 epc = 0;
118 len = sprintf(buf, "%02x\t%04x%02x%02x\t%08x\t%08x\t%02x\n",
119 slot, manuf, prod, epc, (u32)cd->cd_BoardAddr,
120 cd->cd_BoardSize, cd->cd_Rom.er_Type);
121 at += len;
122 if (at >= pos) {
123 if (!*start) {
124 *start = buf + (pos - (at - len));
125 cnt = at - pos;
126 } else
127 cnt += len;
128 buf += len;
131 return (count > cnt) ? cnt : count;
134 static struct proc_dir_entry proc_zorro_devices = {
135 PROC_BUS_ZORRO_DEVICES, 7, "devices",
136 S_IFREG | S_IRUGO, 1, 0, 0,
137 0, &proc_array_inode_operations,
138 get_zorro_dev_info
141 static struct proc_dir_entry *proc_bus_zorro_dir;
143 __initfunc(static int zorro_proc_attach_device(u_int slot))
145 struct proc_dir_entry *entry;
146 char name[4];
148 sprintf(name, "%02x", slot);
149 entry = create_proc_entry(name, S_IFREG | S_IRUGO, proc_bus_zorro_dir);
150 if (!entry)
151 return -ENOMEM;
152 entry->ops = &proc_bus_zorro_inode_operations;
153 entry->data = &zorro_autocon[slot];
154 entry->size = sizeof(struct ConfigDev);
155 return 0;
158 __initfunc(void zorro_proc_init(void))
160 u_int slot;
162 if (!MACH_IS_AMIGA || !AMIGAHW_PRESENT(ZORRO))
163 return;
164 proc_bus_zorro_dir = create_proc_entry("zorro", S_IFDIR, proc_bus);
165 proc_register(proc_bus_zorro_dir, &proc_zorro_devices);
166 for (slot = 0; slot < zorro_num_autocon; slot++)
167 zorro_proc_attach_device(slot);