x86/unwinder: Handle stack overflows more gracefully
[linux/fpc-iii.git] / arch / mips / lasat / sysctl.c
blob6f7422400f32aeaca60fc887fcb7d8132b7d9a69
1 /*
2 * Thomas Horsten <thh@lasat.com>
3 * Copyright (C) 2000 LASAT Networks A/S.
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.
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.
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.
18 * Routines specific to the LASAT boards
20 #include <linux/types.h>
21 #include <asm/lasat/lasat.h>
23 #include <linux/sysctl.h>
24 #include <linux/stddef.h>
25 #include <linux/init.h>
26 #include <linux/fs.h>
27 #include <linux/ctype.h>
28 #include <linux/string.h>
29 #include <linux/net.h>
30 #include <linux/inet.h>
31 #include <linux/uaccess.h>
33 #include <asm/time.h>
35 #ifdef CONFIG_DS1603
36 #include "ds1603.h"
37 #endif
40 /* And the same for proc */
41 int proc_dolasatstring(struct ctl_table *table, int write,
42 void *buffer, size_t *lenp, loff_t *ppos)
44 int r;
46 r = proc_dostring(table, write, buffer, lenp, ppos);
47 if ((!write) || r)
48 return r;
50 lasat_write_eeprom_info();
52 return 0;
55 #ifdef CONFIG_DS1603
56 static int rtctmp;
58 /* proc function to read/write RealTime Clock */
59 int proc_dolasatrtc(struct ctl_table *table, int write,
60 void *buffer, size_t *lenp, loff_t *ppos)
62 struct timespec64 ts;
63 int r;
65 if (!write) {
66 read_persistent_clock64(&ts);
67 rtctmp = ts.tv_sec;
68 /* check for time < 0 and set to 0 */
69 if (rtctmp < 0)
70 rtctmp = 0;
72 r = proc_dointvec(table, write, buffer, lenp, ppos);
73 if (r)
74 return r;
76 if (write)
77 rtc_mips_set_mmss(rtctmp);
79 return 0;
81 #endif
83 #ifdef CONFIG_INET
84 int proc_lasat_ip(struct ctl_table *table, int write,
85 void *buffer, size_t *lenp, loff_t *ppos)
87 unsigned int ip;
88 char *p, c;
89 int len;
90 char ipbuf[32];
92 if (!table->data || !table->maxlen || !*lenp ||
93 (*ppos && !write)) {
94 *lenp = 0;
95 return 0;
98 if (write) {
99 len = 0;
100 p = buffer;
101 while (len < *lenp) {
102 if (get_user(c, p++))
103 return -EFAULT;
104 if (c == 0 || c == '\n')
105 break;
106 len++;
108 if (len >= sizeof(ipbuf)-1)
109 len = sizeof(ipbuf) - 1;
110 if (copy_from_user(ipbuf, buffer, len))
111 return -EFAULT;
112 ipbuf[len] = 0;
113 *ppos += *lenp;
114 /* Now see if we can convert it to a valid IP */
115 ip = in_aton(ipbuf);
116 *(unsigned int *)(table->data) = ip;
117 lasat_write_eeprom_info();
118 } else {
119 ip = *(unsigned int *)(table->data);
120 sprintf(ipbuf, "%d.%d.%d.%d",
121 (ip) & 0xff,
122 (ip >> 8) & 0xff,
123 (ip >> 16) & 0xff,
124 (ip >> 24) & 0xff);
125 len = strlen(ipbuf);
126 if (len > *lenp)
127 len = *lenp;
128 if (len)
129 if (copy_to_user(buffer, ipbuf, len))
130 return -EFAULT;
131 if (len < *lenp) {
132 if (put_user('\n', ((char *) buffer) + len))
133 return -EFAULT;
134 len++;
136 *lenp = len;
137 *ppos += len;
140 return 0;
142 #endif
144 int proc_lasat_prid(struct ctl_table *table, int write,
145 void *buffer, size_t *lenp, loff_t *ppos)
147 int r;
149 r = proc_dointvec(table, write, buffer, lenp, ppos);
150 if (r < 0)
151 return r;
152 if (write) {
153 lasat_board_info.li_eeprom_info.prid =
154 lasat_board_info.li_prid;
155 lasat_write_eeprom_info();
156 lasat_init_board_info();
158 return 0;
161 extern int lasat_boot_to_service;
163 static struct ctl_table lasat_table[] = {
165 .procname = "cpu-hz",
166 .data = &lasat_board_info.li_cpu_hz,
167 .maxlen = sizeof(int),
168 .mode = 0444,
169 .proc_handler = proc_dointvec,
172 .procname = "bus-hz",
173 .data = &lasat_board_info.li_bus_hz,
174 .maxlen = sizeof(int),
175 .mode = 0444,
176 .proc_handler = proc_dointvec,
179 .procname = "bmid",
180 .data = &lasat_board_info.li_bmid,
181 .maxlen = sizeof(int),
182 .mode = 0444,
183 .proc_handler = proc_dointvec,
186 .procname = "prid",
187 .data = &lasat_board_info.li_prid,
188 .maxlen = sizeof(int),
189 .mode = 0644,
190 .proc_handler = proc_lasat_prid,
192 #ifdef CONFIG_INET
194 .procname = "ipaddr",
195 .data = &lasat_board_info.li_eeprom_info.ipaddr,
196 .maxlen = sizeof(int),
197 .mode = 0644,
198 .proc_handler = proc_lasat_ip,
201 .procname = "netmask",
202 .data = &lasat_board_info.li_eeprom_info.netmask,
203 .maxlen = sizeof(int),
204 .mode = 0644,
205 .proc_handler = proc_lasat_ip,
207 #endif
209 .procname = "passwd_hash",
210 .data = &lasat_board_info.li_eeprom_info.passwd_hash,
211 .maxlen =
212 sizeof(lasat_board_info.li_eeprom_info.passwd_hash),
213 .mode = 0600,
214 .proc_handler = proc_dolasatstring,
217 .procname = "boot-service",
218 .data = &lasat_boot_to_service,
219 .maxlen = sizeof(int),
220 .mode = 0644,
221 .proc_handler = proc_dointvec,
223 #ifdef CONFIG_DS1603
225 .procname = "rtc",
226 .data = &rtctmp,
227 .maxlen = sizeof(int),
228 .mode = 0644,
229 .proc_handler = proc_dolasatrtc,
231 #endif
233 .procname = "namestr",
234 .data = &lasat_board_info.li_namestr,
235 .maxlen = sizeof(lasat_board_info.li_namestr),
236 .mode = 0444,
237 .proc_handler = proc_dostring,
240 .procname = "typestr",
241 .data = &lasat_board_info.li_typestr,
242 .maxlen = sizeof(lasat_board_info.li_typestr),
243 .mode = 0444,
244 .proc_handler = proc_dostring,
249 static struct ctl_table lasat_root_table[] = {
251 .procname = "lasat",
252 .mode = 0555,
253 .child = lasat_table
258 static int __init lasat_register_sysctl(void)
260 struct ctl_table_header *lasat_table_header;
262 lasat_table_header =
263 register_sysctl_table(lasat_root_table);
264 if (!lasat_table_header) {
265 printk(KERN_ERR "Unable to register LASAT sysctl\n");
266 return -ENOMEM;
269 return 0;
272 arch_initcall(lasat_register_sysctl);