Commit | Line | Data |
---|---|---|
1da177e4 | 1 | /* |
1da177e4 LT |
2 | * 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> | |
8331438b | 14 | #include <linux/seq_file.h> |
1da177e4 | 15 | #include <linux/init.h> |
8aaf7a0e | 16 | #include <linux/export.h> |
1da177e4 LT |
17 | #include <asm/uaccess.h> |
18 | #include <asm/amigahw.h> | |
19 | #include <asm/setup.h> | |
20 | ||
21 | static loff_t | |
22 | proc_bus_zorro_lseek(struct file *file, loff_t off, int whence) | |
23 | { | |
3be1f2b8 | 24 | return fixed_size_llseek(file, off, whence, sizeof(struct ConfigDev)); |
1da177e4 LT |
25 | } |
26 | ||
27 | static ssize_t | |
d998265f | 28 | proc_bus_zorro_read(struct file *file, char __user *buf, size_t nbytes, loff_t *ppos) |
1da177e4 | 29 | { |
d9dda78b | 30 | struct zorro_dev *z = PDE_DATA(file_inode(file)); |
1da177e4 LT |
31 | struct ConfigDev cd; |
32 | loff_t pos = *ppos; | |
33 | ||
34 | if (pos >= sizeof(struct ConfigDev)) | |
35 | return 0; | |
36 | if (nbytes >= sizeof(struct ConfigDev)) | |
37 | nbytes = sizeof(struct ConfigDev); | |
38 | if (pos + nbytes > sizeof(struct ConfigDev)) | |
39 | nbytes = sizeof(struct ConfigDev) - pos; | |
40 | ||
41 | /* Construct a ConfigDev */ | |
42 | memset(&cd, 0, sizeof(cd)); | |
43 | cd.cd_Rom = z->rom; | |
44 | cd.cd_SlotAddr = z->slotaddr; | |
45 | cd.cd_SlotSize = z->slotsize; | |
46 | cd.cd_BoardAddr = (void *)zorro_resource_start(z); | |
47 | cd.cd_BoardSize = zorro_resource_len(z); | |
48 | ||
2190a1e7 | 49 | if (copy_to_user(buf, (void *)&cd + pos, nbytes)) |
1da177e4 LT |
50 | return -EFAULT; |
51 | *ppos += nbytes; | |
52 | ||
53 | return nbytes; | |
54 | } | |
55 | ||
00977a59 | 56 | static const struct file_operations proc_bus_zorro_operations = { |
659f865e | 57 | .owner = THIS_MODULE, |
1da177e4 LT |
58 | .llseek = proc_bus_zorro_lseek, |
59 | .read = proc_bus_zorro_read, | |
60 | }; | |
61 | ||
8331438b | 62 | static void * zorro_seq_start(struct seq_file *m, loff_t *pos) |
1da177e4 | 63 | { |
8331438b AD |
64 | return (*pos < zorro_num_autocon) ? pos : NULL; |
65 | } | |
66 | ||
67 | static void * zorro_seq_next(struct seq_file *m, void *v, loff_t *pos) | |
68 | { | |
69 | (*pos)++; | |
70 | return (*pos < zorro_num_autocon) ? pos : NULL; | |
71 | } | |
72 | ||
73 | static void zorro_seq_stop(struct seq_file *m, void *v) | |
74 | { | |
75 | } | |
76 | ||
77 | static int zorro_seq_show(struct seq_file *m, void *v) | |
78 | { | |
0d305464 | 79 | unsigned int slot = *(loff_t *)v; |
8331438b AD |
80 | struct zorro_dev *z = &zorro_autocon[slot]; |
81 | ||
82 | seq_printf(m, "%02x\t%08x\t%08lx\t%08lx\t%02x\n", slot, z->id, | |
83 | (unsigned long)zorro_resource_start(z), | |
84 | (unsigned long)zorro_resource_len(z), | |
85 | z->rom.er_Type); | |
86 | return 0; | |
87 | } | |
88 | ||
89 | static const struct seq_operations zorro_devices_seq_ops = { | |
90 | .start = zorro_seq_start, | |
91 | .next = zorro_seq_next, | |
92 | .stop = zorro_seq_stop, | |
93 | .show = zorro_seq_show, | |
94 | }; | |
95 | ||
96 | static int zorro_devices_proc_open(struct inode *inode, struct file *file) | |
97 | { | |
98 | return seq_open(file, &zorro_devices_seq_ops); | |
1da177e4 LT |
99 | } |
100 | ||
8331438b AD |
101 | static const struct file_operations zorro_devices_proc_fops = { |
102 | .owner = THIS_MODULE, | |
103 | .open = zorro_devices_proc_open, | |
104 | .read = seq_read, | |
105 | .llseek = seq_lseek, | |
106 | .release = seq_release, | |
107 | }; | |
108 | ||
1da177e4 LT |
109 | static struct proc_dir_entry *proc_bus_zorro_dir; |
110 | ||
0d305464 | 111 | static int __init zorro_proc_attach_device(unsigned int slot) |
1da177e4 LT |
112 | { |
113 | struct proc_dir_entry *entry; | |
114 | char name[4]; | |
115 | ||
116 | sprintf(name, "%02x", slot); | |
659f865e DL |
117 | entry = proc_create_data(name, 0, proc_bus_zorro_dir, |
118 | &proc_bus_zorro_operations, | |
119 | &zorro_autocon[slot]); | |
1da177e4 LT |
120 | if (!entry) |
121 | return -ENOMEM; | |
271a15ea | 122 | proc_set_size(entry, sizeof(struct zorro_dev)); |
1da177e4 LT |
123 | return 0; |
124 | } | |
125 | ||
126 | static int __init zorro_proc_init(void) | |
127 | { | |
0d305464 | 128 | unsigned int slot; |
1da177e4 LT |
129 | |
130 | if (MACH_IS_AMIGA && AMIGAHW_PRESENT(ZORRO)) { | |
9c37066d | 131 | proc_bus_zorro_dir = proc_mkdir("bus/zorro", NULL); |
8331438b AD |
132 | proc_create("devices", 0, proc_bus_zorro_dir, |
133 | &zorro_devices_proc_fops); | |
1da177e4 LT |
134 | for (slot = 0; slot < zorro_num_autocon; slot++) |
135 | zorro_proc_attach_device(slot); | |
136 | } | |
137 | return 0; | |
138 | } | |
139 | ||
a6a26a3e | 140 | device_initcall(zorro_proc_init); |