blob: 988880dcee751a20309250227bd5dbf1f67db23e [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07002 * Procfs interface for the Zorro bus.
3 *
4 * Copyright (C) 1998-2003 Geert Uytterhoeven
5 *
6 * Heavily based on the procfs interface for the PCI bus, which is
7 *
8 * Copyright (C) 1997, 1998 Martin Mares <mj@atrey.karlin.mff.cuni.cz>
9 */
10
11#include <linux/types.h>
12#include <linux/zorro.h>
13#include <linux/proc_fs.h>
Alexey Dobriyan83314382008-04-29 01:01:45 -070014#include <linux/seq_file.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070015#include <linux/init.h>
Paul Gortmaker8aaf7a02011-08-01 10:58:14 -040016#include <linux/export.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070017#include <asm/uaccess.h>
18#include <asm/amigahw.h>
19#include <asm/setup.h>
20
21static loff_t
22proc_bus_zorro_lseek(struct file *file, loff_t off, int whence)
23{
24 loff_t new = -1;
Geert Uytterhoevend50ac462010-06-05 13:28:09 +020025 struct inode *inode = file->f_path.dentry->d_inode;
Linus Torvalds1da177e2005-04-16 15:20:36 -070026
Geert Uytterhoevend50ac462010-06-05 13:28:09 +020027 mutex_lock(&inode->i_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -070028 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 }
Geert Uytterhoevend50ac462010-06-05 13:28:09 +020039 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;
Linus Torvalds1da177e2005-04-16 15:20:36 -070045}
46
47static ssize_t
Al Virod9982652006-01-12 01:06:32 -080048proc_bus_zorro_read(struct file *file, char __user *buf, size_t nbytes, loff_t *ppos)
Linus Torvalds1da177e2005-04-16 15:20:36 -070049{
Josef Sipekb3d7ae52006-12-08 02:37:48 -080050 struct inode *ino = file->f_path.dentry->d_inode;
Linus Torvalds1da177e2005-04-16 15:20:36 -070051 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
Geert Uytterhoeven2190a1e2010-06-09 11:24:32 +020071 if (copy_to_user(buf, (void *)&cd + pos, nbytes))
Linus Torvalds1da177e2005-04-16 15:20:36 -070072 return -EFAULT;
73 *ppos += nbytes;
74
75 return nbytes;
76}
77
Arjan van de Ven00977a52007-02-12 00:55:34 -080078static const struct file_operations proc_bus_zorro_operations = {
Denis V. Lunev659f8652008-04-29 01:02:16 -070079 .owner = THIS_MODULE,
Linus Torvalds1da177e2005-04-16 15:20:36 -070080 .llseek = proc_bus_zorro_lseek,
81 .read = proc_bus_zorro_read,
82};
83
Alexey Dobriyan83314382008-04-29 01:01:45 -070084static void * zorro_seq_start(struct seq_file *m, loff_t *pos)
Linus Torvalds1da177e2005-04-16 15:20:36 -070085{
Alexey Dobriyan83314382008-04-29 01:01:45 -070086 return (*pos < zorro_num_autocon) ? pos : NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -070087}
88
Alexey Dobriyan83314382008-04-29 01:01:45 -070089static void * zorro_seq_next(struct seq_file *m, void *v, loff_t *pos)
90{
91 (*pos)++;
92 return (*pos < zorro_num_autocon) ? pos : NULL;
93}
94
95static void zorro_seq_stop(struct seq_file *m, void *v)
96{
97}
98
99static int zorro_seq_show(struct seq_file *m, void *v)
100{
Geert Uytterhoeven0d305462009-04-05 12:40:41 +0200101 unsigned int slot = *(loff_t *)v;
Alexey Dobriyan83314382008-04-29 01:01:45 -0700102 struct zorro_dev *z = &zorro_autocon[slot];
103
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;
109}
110
111static 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,
116};
117
118static int zorro_devices_proc_open(struct inode *inode, struct file *file)
119{
120 return seq_open(file, &zorro_devices_seq_ops);
121}
122
123static 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,
129};
130
Linus Torvalds1da177e2005-04-16 15:20:36 -0700131static struct proc_dir_entry *proc_bus_zorro_dir;
132
Geert Uytterhoeven0d305462009-04-05 12:40:41 +0200133static int __init zorro_proc_attach_device(unsigned int slot)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700134{
135 struct proc_dir_entry *entry;
136 char name[4];
137
138 sprintf(name, "%02x", slot);
Denis V. Lunev659f8652008-04-29 01:02:16 -0700139 entry = proc_create_data(name, 0, proc_bus_zorro_dir,
140 &proc_bus_zorro_operations,
141 &zorro_autocon[slot]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700142 if (!entry)
143 return -ENOMEM;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700144 entry->size = sizeof(struct zorro_dev);
145 return 0;
146}
147
148static int __init zorro_proc_init(void)
149{
Geert Uytterhoeven0d305462009-04-05 12:40:41 +0200150 unsigned int slot;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700151
152 if (MACH_IS_AMIGA && AMIGAHW_PRESENT(ZORRO)) {
Alexey Dobriyan9c370662008-04-29 01:01:41 -0700153 proc_bus_zorro_dir = proc_mkdir("bus/zorro", NULL);
Alexey Dobriyan83314382008-04-29 01:01:45 -0700154 proc_create("devices", 0, proc_bus_zorro_dir,
155 &zorro_devices_proc_fops);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700156 for (slot = 0; slot < zorro_num_autocon; slot++)
157 zorro_proc_attach_device(slot);
158 }
159 return 0;
160}
161
Robert P. J. Daya6a26a32008-07-17 21:16:16 +0200162device_initcall(zorro_proc_init);