diff options
author | Linus Torvalds <torvalds@ppc970.osdl.org> | 2005-04-16 18:20:36 -0400 |
---|---|---|
committer | Linus Torvalds <torvalds@ppc970.osdl.org> | 2005-04-16 18:20:36 -0400 |
commit | 1da177e4c3f41524e886b7f1b8a0c1fc7321cac2 (patch) | |
tree | 0bba044c4ce775e45a88a51686b5d9f90697ea9d /arch/mips/lasat/sysctl.c |
Linux-2.6.12-rc2v2.6.12-rc2
Initial git repository build. I'm not bothering with the full history,
even though we have it. We can create a separate "historical" git
archive of that later if we want to, and in the meantime it's about
3.2GB when imported into git - space that would just make the early
git days unnecessarily complicated, when we don't have a lot of good
infrastructure for it.
Let it rip!
Diffstat (limited to 'arch/mips/lasat/sysctl.c')
-rw-r--r-- | arch/mips/lasat/sysctl.c | 355 |
1 files changed, 355 insertions, 0 deletions
diff --git a/arch/mips/lasat/sysctl.c b/arch/mips/lasat/sysctl.c new file mode 100644 index 000000000000..1c0cc620a43f --- /dev/null +++ b/arch/mips/lasat/sysctl.c | |||
@@ -0,0 +1,355 @@ | |||
1 | /* | ||
2 | * Thomas Horsten <thh@lasat.com> | ||
3 | * Copyright (C) 2000 LASAT Networks A/S. | ||
4 | * | ||
5 | * This program is free software; you can distribute it and/or modify it | ||
6 | * under the terms of the GNU General Public License (Version 2) as | ||
7 | * published by the Free Software Foundation. | ||
8 | * | ||
9 | * This program is distributed in the hope it will be useful, but WITHOUT | ||
10 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | ||
11 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | ||
12 | * for more details. | ||
13 | * | ||
14 | * You should have received a copy of the GNU General Public License along | ||
15 | * with this program; if not, write to the Free Software Foundation, Inc., | ||
16 | * 59 Temple Place - Suite 330, Boston MA 02111-1307, USA. | ||
17 | * | ||
18 | * Routines specific to the LASAT boards | ||
19 | */ | ||
20 | #include <linux/types.h> | ||
21 | #include <asm/lasat/lasat.h> | ||
22 | |||
23 | #include <linux/config.h> | ||
24 | #include <linux/module.h> | ||
25 | #include <linux/sysctl.h> | ||
26 | #include <linux/stddef.h> | ||
27 | #include <linux/init.h> | ||
28 | #include <linux/fs.h> | ||
29 | #include <linux/ctype.h> | ||
30 | #include <linux/string.h> | ||
31 | #include <linux/net.h> | ||
32 | #include <linux/inet.h> | ||
33 | #include <asm/uaccess.h> | ||
34 | |||
35 | #include "sysctl.h" | ||
36 | #include "ds1603.h" | ||
37 | |||
38 | static DECLARE_MUTEX(lasat_info_sem); | ||
39 | |||
40 | /* Strategy function to write EEPROM after changing string entry */ | ||
41 | int sysctl_lasatstring(ctl_table *table, int *name, int nlen, | ||
42 | void *oldval, size_t *oldlenp, | ||
43 | void *newval, size_t newlen, void **context) | ||
44 | { | ||
45 | int r; | ||
46 | down(&lasat_info_sem); | ||
47 | r = sysctl_string(table, name, | ||
48 | nlen, oldval, oldlenp, newval, newlen, context); | ||
49 | if (r < 0) { | ||
50 | up(&lasat_info_sem); | ||
51 | return r; | ||
52 | } | ||
53 | if (newval && newlen) { | ||
54 | lasat_write_eeprom_info(); | ||
55 | } | ||
56 | up(&lasat_info_sem); | ||
57 | return 1; | ||
58 | } | ||
59 | |||
60 | |||
61 | /* And the same for proc */ | ||
62 | int proc_dolasatstring(ctl_table *table, int write, struct file *filp, | ||
63 | void *buffer, size_t *lenp, loff_t *ppos) | ||
64 | { | ||
65 | int r; | ||
66 | down(&lasat_info_sem); | ||
67 | r = proc_dostring(table, write, filp, buffer, lenp, ppos); | ||
68 | if ( (!write) || r) { | ||
69 | up(&lasat_info_sem); | ||
70 | return r; | ||
71 | } | ||
72 | lasat_write_eeprom_info(); | ||
73 | up(&lasat_info_sem); | ||
74 | return 0; | ||
75 | } | ||
76 | |||
77 | /* proc function to write EEPROM after changing int entry */ | ||
78 | int proc_dolasatint(ctl_table *table, int write, struct file *filp, | ||
79 | void *buffer, size_t *lenp, loff_t *ppos) | ||
80 | { | ||
81 | int r; | ||
82 | down(&lasat_info_sem); | ||
83 | r = proc_dointvec(table, write, filp, buffer, lenp, ppos); | ||
84 | if ( (!write) || r) { | ||
85 | up(&lasat_info_sem); | ||
86 | return r; | ||
87 | } | ||
88 | lasat_write_eeprom_info(); | ||
89 | up(&lasat_info_sem); | ||
90 | return 0; | ||
91 | } | ||
92 | |||
93 | static int rtctmp; | ||
94 | |||
95 | #ifdef CONFIG_DS1603 | ||
96 | /* proc function to read/write RealTime Clock */ | ||
97 | int proc_dolasatrtc(ctl_table *table, int write, struct file *filp, | ||
98 | void *buffer, size_t *lenp, loff_t *ppos) | ||
99 | { | ||
100 | int r; | ||
101 | down(&lasat_info_sem); | ||
102 | if (!write) { | ||
103 | rtctmp = ds1603_read(); | ||
104 | /* check for time < 0 and set to 0 */ | ||
105 | if (rtctmp < 0) | ||
106 | rtctmp = 0; | ||
107 | } | ||
108 | r = proc_dointvec(table, write, filp, buffer, lenp, ppos); | ||
109 | if ( (!write) || r) { | ||
110 | up(&lasat_info_sem); | ||
111 | return r; | ||
112 | } | ||
113 | ds1603_set(rtctmp); | ||
114 | up(&lasat_info_sem); | ||
115 | return 0; | ||
116 | } | ||
117 | #endif | ||
118 | |||
119 | /* Sysctl for setting the IP addresses */ | ||
120 | int sysctl_lasat_intvec(ctl_table *table, int *name, int nlen, | ||
121 | void *oldval, size_t *oldlenp, | ||
122 | void *newval, size_t newlen, void **context) | ||
123 | { | ||
124 | int r; | ||
125 | down(&lasat_info_sem); | ||
126 | r = sysctl_intvec(table, name, nlen, oldval, oldlenp, newval, newlen, context); | ||
127 | if (r < 0) { | ||
128 | up(&lasat_info_sem); | ||
129 | return r; | ||
130 | } | ||
131 | if (newval && newlen) { | ||
132 | lasat_write_eeprom_info(); | ||
133 | } | ||
134 | up(&lasat_info_sem); | ||
135 | return 1; | ||
136 | } | ||
137 | |||
138 | #ifdef CONFIG_DS1603 | ||
139 | /* Same for RTC */ | ||
140 | int sysctl_lasat_rtc(ctl_table *table, int *name, int nlen, | ||
141 | void *oldval, size_t *oldlenp, | ||
142 | void *newval, size_t newlen, void **context) | ||
143 | { | ||
144 | int r; | ||
145 | down(&lasat_info_sem); | ||
146 | rtctmp = ds1603_read(); | ||
147 | if (rtctmp < 0) | ||
148 | rtctmp = 0; | ||
149 | r = sysctl_intvec(table, name, nlen, oldval, oldlenp, newval, newlen, context); | ||
150 | if (r < 0) { | ||
151 | up(&lasat_info_sem); | ||
152 | return r; | ||
153 | } | ||
154 | if (newval && newlen) { | ||
155 | ds1603_set(rtctmp); | ||
156 | } | ||
157 | up(&lasat_info_sem); | ||
158 | return 1; | ||
159 | } | ||
160 | #endif | ||
161 | |||
162 | #ifdef CONFIG_INET | ||
163 | static char lasat_bcastaddr[16]; | ||
164 | |||
165 | void update_bcastaddr(void) | ||
166 | { | ||
167 | unsigned int ip; | ||
168 | |||
169 | ip = (lasat_board_info.li_eeprom_info.ipaddr & | ||
170 | lasat_board_info.li_eeprom_info.netmask) | | ||
171 | ~lasat_board_info.li_eeprom_info.netmask; | ||
172 | |||
173 | sprintf(lasat_bcastaddr, "%d.%d.%d.%d", | ||
174 | (ip ) & 0xff, | ||
175 | (ip >> 8) & 0xff, | ||
176 | (ip >> 16) & 0xff, | ||
177 | (ip >> 24) & 0xff); | ||
178 | } | ||
179 | |||
180 | static char proc_lasat_ipbuf[32]; | ||
181 | /* Parsing of IP address */ | ||
182 | int proc_lasat_ip(ctl_table *table, int write, struct file *filp, | ||
183 | void *buffer, size_t *lenp, loff_t *ppos) | ||
184 | { | ||
185 | int len; | ||
186 | unsigned int ip; | ||
187 | char *p, c; | ||
188 | |||
189 | if (!table->data || !table->maxlen || !*lenp || | ||
190 | (*ppos && !write)) { | ||
191 | *lenp = 0; | ||
192 | return 0; | ||
193 | } | ||
194 | |||
195 | down(&lasat_info_sem); | ||
196 | if (write) { | ||
197 | len = 0; | ||
198 | p = buffer; | ||
199 | while (len < *lenp) { | ||
200 | if(get_user(c, p++)) { | ||
201 | up(&lasat_info_sem); | ||
202 | return -EFAULT; | ||
203 | } | ||
204 | if (c == 0 || c == '\n') | ||
205 | break; | ||
206 | len++; | ||
207 | } | ||
208 | if (len >= sizeof(proc_lasat_ipbuf)-1) | ||
209 | len = sizeof(proc_lasat_ipbuf) - 1; | ||
210 | if (copy_from_user(proc_lasat_ipbuf, buffer, len)) | ||
211 | { | ||
212 | up(&lasat_info_sem); | ||
213 | return -EFAULT; | ||
214 | } | ||
215 | proc_lasat_ipbuf[len] = 0; | ||
216 | *ppos += *lenp; | ||
217 | /* Now see if we can convert it to a valid IP */ | ||
218 | ip = in_aton(proc_lasat_ipbuf); | ||
219 | *(unsigned int *)(table->data) = ip; | ||
220 | lasat_write_eeprom_info(); | ||
221 | } else { | ||
222 | ip = *(unsigned int *)(table->data); | ||
223 | sprintf(proc_lasat_ipbuf, "%d.%d.%d.%d", | ||
224 | (ip ) & 0xff, | ||
225 | (ip >> 8) & 0xff, | ||
226 | (ip >> 16) & 0xff, | ||
227 | (ip >> 24) & 0xff); | ||
228 | len = strlen(proc_lasat_ipbuf); | ||
229 | if (len > *lenp) | ||
230 | len = *lenp; | ||
231 | if (len) | ||
232 | if(copy_to_user(buffer, proc_lasat_ipbuf, len)) { | ||
233 | up(&lasat_info_sem); | ||
234 | return -EFAULT; | ||
235 | } | ||
236 | if (len < *lenp) { | ||
237 | if(put_user('\n', ((char *) buffer) + len)) { | ||
238 | up(&lasat_info_sem); | ||
239 | return -EFAULT; | ||
240 | } | ||
241 | len++; | ||
242 | } | ||
243 | *lenp = len; | ||
244 | *ppos += len; | ||
245 | } | ||
246 | update_bcastaddr(); | ||
247 | up(&lasat_info_sem); | ||
248 | return 0; | ||
249 | } | ||
250 | #endif /* defined(CONFIG_INET) */ | ||
251 | |||
252 | static int sysctl_lasat_eeprom_value(ctl_table *table, int *name, int nlen, | ||
253 | void *oldval, size_t *oldlenp, | ||
254 | void *newval, size_t newlen, | ||
255 | void **context) | ||
256 | { | ||
257 | int r; | ||
258 | |||
259 | down(&lasat_info_sem); | ||
260 | r = sysctl_intvec(table, name, nlen, oldval, oldlenp, newval, newlen, context); | ||
261 | if (r < 0) { | ||
262 | up(&lasat_info_sem); | ||
263 | return r; | ||
264 | } | ||
265 | |||
266 | if (newval && newlen) | ||
267 | { | ||
268 | if (name && *name == LASAT_PRID) | ||
269 | lasat_board_info.li_eeprom_info.prid = *(int*)newval; | ||
270 | |||
271 | lasat_write_eeprom_info(); | ||
272 | lasat_init_board_info(); | ||
273 | } | ||
274 | up(&lasat_info_sem); | ||
275 | |||
276 | return 0; | ||
277 | } | ||
278 | |||
279 | int proc_lasat_eeprom_value(ctl_table *table, int write, struct file *filp, | ||
280 | void *buffer, size_t *lenp, loff_t *ppos) | ||
281 | { | ||
282 | int r; | ||
283 | down(&lasat_info_sem); | ||
284 | r = proc_dointvec(table, write, filp, buffer, lenp, ppos); | ||
285 | if ( (!write) || r) { | ||
286 | up(&lasat_info_sem); | ||
287 | return r; | ||
288 | } | ||
289 | if (filp && filp->f_dentry) | ||
290 | { | ||
291 | if (!strcmp(filp->f_dentry->d_name.name, "prid")) | ||
292 | lasat_board_info.li_eeprom_info.prid = lasat_board_info.li_prid; | ||
293 | if (!strcmp(filp->f_dentry->d_name.name, "debugaccess")) | ||
294 | lasat_board_info.li_eeprom_info.debugaccess = lasat_board_info.li_debugaccess; | ||
295 | } | ||
296 | lasat_write_eeprom_info(); | ||
297 | up(&lasat_info_sem); | ||
298 | return 0; | ||
299 | } | ||
300 | |||
301 | extern int lasat_boot_to_service; | ||
302 | |||
303 | #ifdef CONFIG_SYSCTL | ||
304 | |||
305 | static ctl_table lasat_table[] = { | ||
306 | {LASAT_CPU_HZ, "cpu-hz", &lasat_board_info.li_cpu_hz, sizeof(int), | ||
307 | 0444, NULL, &proc_dointvec, &sysctl_intvec}, | ||
308 | {LASAT_BUS_HZ, "bus-hz", &lasat_board_info.li_bus_hz, sizeof(int), | ||
309 | 0444, NULL, &proc_dointvec, &sysctl_intvec}, | ||
310 | {LASAT_MODEL, "bmid", &lasat_board_info.li_bmid, sizeof(int), | ||
311 | 0444, NULL, &proc_dointvec, &sysctl_intvec}, | ||
312 | {LASAT_PRID, "prid", &lasat_board_info.li_prid, sizeof(int), | ||
313 | 0644, NULL, &proc_lasat_eeprom_value, &sysctl_lasat_eeprom_value}, | ||
314 | #ifdef CONFIG_INET | ||
315 | {LASAT_IPADDR, "ipaddr", &lasat_board_info.li_eeprom_info.ipaddr, sizeof(int), | ||
316 | 0644, NULL, &proc_lasat_ip, &sysctl_lasat_intvec}, | ||
317 | {LASAT_NETMASK, "netmask", &lasat_board_info.li_eeprom_info.netmask, sizeof(int), | ||
318 | 0644, NULL, &proc_lasat_ip, &sysctl_lasat_intvec}, | ||
319 | {LASAT_BCAST, "bcastaddr", &lasat_bcastaddr, | ||
320 | sizeof(lasat_bcastaddr), 0600, NULL, | ||
321 | &proc_dostring, &sysctl_string}, | ||
322 | #endif | ||
323 | {LASAT_PASSWORD, "passwd_hash", &lasat_board_info.li_eeprom_info.passwd_hash, sizeof(lasat_board_info.li_eeprom_info.passwd_hash), | ||
324 | 0600, NULL, &proc_dolasatstring, &sysctl_lasatstring}, | ||
325 | {LASAT_SBOOT, "boot-service", &lasat_boot_to_service, sizeof(int), | ||
326 | 0644, NULL, &proc_dointvec, &sysctl_intvec}, | ||
327 | #ifdef CONFIG_DS1603 | ||
328 | {LASAT_RTC, "rtc", &rtctmp, sizeof(int), | ||
329 | 0644, NULL, &proc_dolasatrtc, &sysctl_lasat_rtc}, | ||
330 | #endif | ||
331 | {LASAT_NAMESTR, "namestr", &lasat_board_info.li_namestr, sizeof(lasat_board_info.li_namestr), | ||
332 | 0444, NULL, &proc_dostring, &sysctl_string}, | ||
333 | {LASAT_TYPESTR, "typestr", &lasat_board_info.li_typestr, sizeof(lasat_board_info.li_typestr), | ||
334 | 0444, NULL, &proc_dostring, &sysctl_string}, | ||
335 | {0} | ||
336 | }; | ||
337 | |||
338 | #define CTL_LASAT 1 // CTL_ANY ??? | ||
339 | static ctl_table lasat_root_table[] = { | ||
340 | { CTL_LASAT, "lasat", NULL, 0, 0555, lasat_table }, | ||
341 | { 0 } | ||
342 | }; | ||
343 | |||
344 | static int __init lasat_register_sysctl(void) | ||
345 | { | ||
346 | struct ctl_table_header *lasat_table_header; | ||
347 | |||
348 | lasat_table_header = | ||
349 | register_sysctl_table(lasat_root_table, 0); | ||
350 | |||
351 | return 0; | ||
352 | } | ||
353 | |||
354 | __initcall(lasat_register_sysctl); | ||
355 | #endif /* CONFIG_SYSCTL */ | ||