Commit | Line | Data |
---|---|---|
b2441318 | 1 | // SPDX-License-Identifier: GPL-2.0 |
1da177e4 LT |
2 | /* drivers/nubus/proc.c: Proc FS interface for NuBus. |
3 | ||
4 | By David Huggins-Daines <dhd@debian.org> | |
5 | ||
6 | Much code and many ideas from drivers/pci/proc.c: | |
7 | Copyright (c) 1997, 1998 Martin Mares <mj@atrey.karlin.mff.cuni.cz> | |
8 | ||
9 | This is initially based on the Zorro and PCI interfaces. However, | |
10 | it works somewhat differently. The intent is to provide a | |
11 | structure in /proc analogous to the structure of the NuBus ROM | |
12 | resources. | |
13 | ||
2f7dd07e FT |
14 | Therefore each board function gets a directory, which may in turn |
15 | contain subdirectories. Each slot resource is a file. Unrecognized | |
16 | resources are empty files, since every resource ID requires a special | |
17 | case (e.g. if the resource ID implies a directory or block, then its | |
18 | value has to be interpreted as a slot ROM pointer etc.). | |
19 | */ | |
1da177e4 LT |
20 | |
21 | #include <linux/types.h> | |
22 | #include <linux/kernel.h> | |
23 | #include <linux/nubus.h> | |
24 | #include <linux/proc_fs.h> | |
076ec04b | 25 | #include <linux/seq_file.h> |
2f7dd07e | 26 | #include <linux/slab.h> |
1da177e4 | 27 | #include <linux/init.h> |
99ffab81 | 28 | #include <linux/module.h> |
7c0f6ba6 | 29 | #include <linux/uaccess.h> |
1da177e4 LT |
30 | #include <asm/byteorder.h> |
31 | ||
2f7dd07e FT |
32 | /* |
33 | * /proc/bus/nubus/devices stuff | |
34 | */ | |
35 | ||
1da177e4 | 36 | static int |
076ec04b | 37 | nubus_devices_proc_show(struct seq_file *m, void *v) |
1da177e4 | 38 | { |
41b84816 | 39 | struct nubus_rsrc *fres; |
1da177e4 | 40 | |
41b84816 FT |
41 | for_each_func_rsrc(fres) |
42 | seq_printf(m, "%x\t%04x %04x %04x %04x\t%08lx\n", | |
189e19e8 | 43 | fres->board->slot, fres->category, fres->type, |
41b84816 | 44 | fres->dr_sw, fres->dr_hw, fres->board->slot_addr); |
076ec04b AD |
45 | return 0; |
46 | } | |
47 | ||
1da177e4 LT |
48 | static struct proc_dir_entry *proc_bus_nubus_dir; |
49 | ||
2f7dd07e FT |
50 | /* |
51 | * /proc/bus/nubus/x/ stuff | |
52 | */ | |
53 | ||
54 | struct proc_dir_entry *nubus_proc_add_board(struct nubus_board *board) | |
55 | { | |
56 | char name[2]; | |
57 | ||
72b44f65 | 58 | if (!proc_bus_nubus_dir || !nubus_populate_procfs) |
2f7dd07e FT |
59 | return NULL; |
60 | snprintf(name, sizeof(name), "%x", board->slot); | |
61 | return proc_mkdir(name, proc_bus_nubus_dir); | |
62 | } | |
63 | ||
64 | /* The PDE private data for any directory under /proc/bus/nubus/x/ | |
65 | * is the bytelanes value for the board in slot x. | |
66 | */ | |
67 | ||
68 | struct 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 | ||
72b44f65 | 75 | if (!procdir || !nubus_populate_procfs) |
2f7dd07e FT |
76 | return NULL; |
77 | snprintf(name, sizeof(name), "%x", ent->type); | |
b7629ce6 | 78 | remove_proc_subtree(name, procdir); |
2f7dd07e FT |
79 | return proc_mkdir_data(name, 0555, procdir, (void *)lanes); |
80 | } | |
81 | ||
82 | /* The PDE private data for a file under /proc/bus/nubus/x/ is a pointer to | |
83 | * an instance of the following structure, which gives the location and size | |
84 | * of the resource data in the slot ROM. For slot resources which hold only a | |
85 | * small integer, this integer value is stored directly and size is set to 0. | |
86 | * A NULL private data pointer indicates an unrecognized resource. | |
87 | */ | |
88 | ||
89 | struct nubus_proc_pde_data { | |
90 | unsigned char *res_ptr; | |
91 | unsigned int res_size; | |
11db656a DH |
92 | }; |
93 | ||
2f7dd07e FT |
94 | static struct nubus_proc_pde_data * |
95 | nubus_proc_alloc_pde_data(unsigned char *ptr, unsigned int size) | |
1da177e4 | 96 | { |
359745d7 | 97 | struct nubus_proc_pde_data *pded; |
2f7dd07e | 98 | |
359745d7 MS |
99 | pded = kmalloc(sizeof(*pded), GFP_KERNEL); |
100 | if (!pded) | |
2f7dd07e FT |
101 | return NULL; |
102 | ||
359745d7 MS |
103 | pded->res_ptr = ptr; |
104 | pded->res_size = size; | |
105 | return pded; | |
1da177e4 LT |
106 | } |
107 | ||
2f7dd07e | 108 | static int nubus_proc_rsrc_show(struct seq_file *m, void *v) |
1da177e4 | 109 | { |
2f7dd07e | 110 | struct inode *inode = m->private; |
359745d7 | 111 | struct nubus_proc_pde_data *pded; |
2f7dd07e | 112 | |
359745d7 MS |
113 | pded = pde_data(inode); |
114 | if (!pded) | |
2f7dd07e FT |
115 | return 0; |
116 | ||
359745d7 | 117 | if (pded->res_size > m->size) |
2f7dd07e FT |
118 | return -EFBIG; |
119 | ||
359745d7 | 120 | if (pded->res_size) { |
2f7dd07e FT |
121 | int lanes = (int)proc_get_parent_data(inode); |
122 | struct nubus_dirent ent; | |
123 | ||
124 | if (!lanes) | |
125 | return 0; | |
126 | ||
127 | ent.mask = lanes; | |
359745d7 | 128 | ent.base = pded->res_ptr; |
2f7dd07e | 129 | ent.data = 0; |
359745d7 | 130 | nubus_seq_write_rsrc_mem(m, &ent, pded->res_size); |
2f7dd07e | 131 | } else { |
359745d7 | 132 | unsigned int data = (unsigned int)pded->res_ptr; |
2f7dd07e FT |
133 | |
134 | seq_putc(m, data >> 16); | |
135 | seq_putc(m, data >> 8); | |
136 | seq_putc(m, data >> 0); | |
1da177e4 | 137 | } |
2f7dd07e | 138 | return 0; |
1da177e4 LT |
139 | } |
140 | ||
0e96647c FT |
141 | static int nubus_rsrc_proc_open(struct inode *inode, struct file *file) |
142 | { | |
143 | return single_open(file, nubus_proc_rsrc_show, inode); | |
144 | } | |
145 | ||
146 | static const struct proc_ops nubus_rsrc_proc_ops = { | |
147 | .proc_open = nubus_rsrc_proc_open, | |
148 | .proc_read = seq_read, | |
149 | .proc_lseek = seq_lseek, | |
150 | .proc_release = single_release, | |
151 | }; | |
152 | ||
2f7dd07e FT |
153 | void nubus_proc_add_rsrc_mem(struct proc_dir_entry *procdir, |
154 | const struct nubus_dirent *ent, | |
155 | unsigned int size) | |
1da177e4 | 156 | { |
2f828fb2 | 157 | char name[9]; |
359745d7 | 158 | struct nubus_proc_pde_data *pded; |
1da177e4 | 159 | |
72b44f65 | 160 | if (!procdir || !nubus_populate_procfs) |
2f7dd07e | 161 | return; |
6c8b89ea | 162 | |
2f7dd07e FT |
163 | snprintf(name, sizeof(name), "%x", ent->type); |
164 | if (size) | |
359745d7 | 165 | pded = nubus_proc_alloc_pde_data(nubus_dirptr(ent), size); |
2f7dd07e | 166 | else |
359745d7 | 167 | pded = NULL; |
b7629ce6 | 168 | remove_proc_subtree(name, procdir); |
0e96647c FT |
169 | proc_create_data(name, S_IFREG | 0444, procdir, |
170 | &nubus_rsrc_proc_ops, pded); | |
2f7dd07e | 171 | } |
1da177e4 | 172 | |
2f7dd07e FT |
173 | void nubus_proc_add_rsrc(struct proc_dir_entry *procdir, |
174 | const struct nubus_dirent *ent) | |
175 | { | |
176 | char name[9]; | |
177 | unsigned char *data = (unsigned char *)ent->data; | |
1da177e4 | 178 | |
72b44f65 | 179 | if (!procdir || !nubus_populate_procfs) |
2f7dd07e FT |
180 | return; |
181 | ||
182 | snprintf(name, sizeof(name), "%x", ent->type); | |
b7629ce6 | 183 | remove_proc_subtree(name, procdir); |
0e96647c FT |
184 | proc_create_data(name, S_IFREG | 0444, procdir, |
185 | &nubus_rsrc_proc_ops, | |
186 | nubus_proc_alloc_pde_data(data, 0)); | |
1da177e4 LT |
187 | } |
188 | ||
11db656a DH |
189 | /* |
190 | * /proc/nubus stuff | |
191 | */ | |
11db656a | 192 | |
1da177e4 LT |
193 | void __init nubus_proc_init(void) |
194 | { | |
3f3942ac | 195 | proc_create_single("nubus", 0, NULL, nubus_proc_show); |
9c37066d | 196 | proc_bus_nubus_dir = proc_mkdir("bus/nubus", NULL); |
2f7dd07e FT |
197 | if (!proc_bus_nubus_dir) |
198 | return; | |
3f3942ac CH |
199 | proc_create_single("devices", 0, proc_bus_nubus_dir, |
200 | nubus_devices_proc_show); | |
1da177e4 | 201 | } |