1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21#include <linux/types.h>
22#include <linux/kernel.h>
23#include <linux/nubus.h>
24#include <linux/proc_fs.h>
25#include <linux/seq_file.h>
26#include <linux/slab.h>
27#include <linux/init.h>
28#include <linux/module.h>
29#include <linux/uaccess.h>
30#include <asm/byteorder.h>
31
32
33
34
35
36static int
37nubus_devices_proc_show(struct seq_file *m, void *v)
38{
39 struct nubus_rsrc *fres;
40
41 for_each_func_rsrc(fres)
42 seq_printf(m, "%x\t%04x %04x %04x %04x\t%08lx\n",
43 fres->board->slot, fres->category, fres->type,
44 fres->dr_sw, fres->dr_hw, fres->board->slot_addr);
45 return 0;
46}
47
48static struct proc_dir_entry *proc_bus_nubus_dir;
49
50
51
52
53
54struct proc_dir_entry *nubus_proc_add_board(struct nubus_board *board)
55{
56 char name[2];
57
58 if (!proc_bus_nubus_dir)
59 return NULL;
60 snprintf(name, sizeof(name), "%x", board->slot);
61 return proc_mkdir(name, proc_bus_nubus_dir);
62}
63
64
65
66
67
68struct proc_dir_entry *nubus_proc_add_rsrc_dir(struct proc_dir_entry *procdir,
69 const struct nubus_dirent *ent,
70 struct nubus_board *board)
71{
72 char name[9];
73 int lanes = board->lanes;
74
75 if (!procdir)
76 return NULL;
77 snprintf(name, sizeof(name), "%x", ent->type);
78 return proc_mkdir_data(name, 0555, procdir, (void *)lanes);
79}
80
81
82
83
84
85
86
87
88struct nubus_proc_pde_data {
89 unsigned char *res_ptr;
90 unsigned int res_size;
91};
92
93static struct nubus_proc_pde_data *
94nubus_proc_alloc_pde_data(unsigned char *ptr, unsigned int size)
95{
96 struct nubus_proc_pde_data *pde_data;
97
98 pde_data = kmalloc(sizeof(*pde_data), GFP_KERNEL);
99 if (!pde_data)
100 return NULL;
101
102 pde_data->res_ptr = ptr;
103 pde_data->res_size = size;
104 return pde_data;
105}
106
107static int nubus_proc_rsrc_show(struct seq_file *m, void *v)
108{
109 struct inode *inode = m->private;
110 struct nubus_proc_pde_data *pde_data;
111
112 pde_data = PDE_DATA(inode);
113 if (!pde_data)
114 return 0;
115
116 if (pde_data->res_size > m->size)
117 return -EFBIG;
118
119 if (pde_data->res_size) {
120 int lanes = (int)proc_get_parent_data(inode);
121 struct nubus_dirent ent;
122
123 if (!lanes)
124 return 0;
125
126 ent.mask = lanes;
127 ent.base = pde_data->res_ptr;
128 ent.data = 0;
129 nubus_seq_write_rsrc_mem(m, &ent, pde_data->res_size);
130 } else {
131 unsigned int data = (unsigned int)pde_data->res_ptr;
132
133 seq_putc(m, data >> 16);
134 seq_putc(m, data >> 8);
135 seq_putc(m, data >> 0);
136 }
137 return 0;
138}
139
140void nubus_proc_add_rsrc_mem(struct proc_dir_entry *procdir,
141 const struct nubus_dirent *ent,
142 unsigned int size)
143{
144 char name[9];
145 struct nubus_proc_pde_data *pde_data;
146
147 if (!procdir)
148 return;
149
150 snprintf(name, sizeof(name), "%x", ent->type);
151 if (size)
152 pde_data = nubus_proc_alloc_pde_data(nubus_dirptr(ent), size);
153 else
154 pde_data = NULL;
155 proc_create_single_data(name, S_IFREG | 0444, procdir,
156 nubus_proc_rsrc_show, pde_data);
157}
158
159void nubus_proc_add_rsrc(struct proc_dir_entry *procdir,
160 const struct nubus_dirent *ent)
161{
162 char name[9];
163 unsigned char *data = (unsigned char *)ent->data;
164
165 if (!procdir)
166 return;
167
168 snprintf(name, sizeof(name), "%x", ent->type);
169 proc_create_single_data(name, S_IFREG | 0444, procdir,
170 nubus_proc_rsrc_show,
171 nubus_proc_alloc_pde_data(data, 0));
172}
173
174
175
176
177
178void __init nubus_proc_init(void)
179{
180 proc_create_single("nubus", 0, NULL, nubus_proc_show);
181 proc_bus_nubus_dir = proc_mkdir("bus/nubus", NULL);
182 if (!proc_bus_nubus_dir)
183 return;
184 proc_create_single("devices", 0, proc_bus_nubus_dir,
185 nubus_devices_proc_show);
186}
187