diff options
author | Paul Mackerras <paulus@samba.org> | 2005-11-02 22:41:19 -0500 |
---|---|---|
committer | Paul Mackerras <paulus@samba.org> | 2005-11-02 22:41:19 -0500 |
commit | f4fcbbe9a7fdf11305fea657202b954bdc2228ec (patch) | |
tree | d3f6a54b82b6d28f7e78cebd8043df2d9b596b5a /arch/ppc64/kernel | |
parent | 398382999bcff46ec1c7e7ab7574b10b087481c7 (diff) |
powerpc: Merge remaining RTAS code
This moves rtas-proc.c and rtas_flash.c into arch/powerpc/kernel, since
cell wants them as well as pseries (and chrp can use rtas-proc.c too,
at least in principle). rtas_fw.c is gone, with its bits moved into
rtas_flash.c and rtas.c.
Signed-off-by: Paul Mackerras <paulus@samba.org>
Diffstat (limited to 'arch/ppc64/kernel')
-rw-r--r-- | arch/ppc64/kernel/Makefile | 4 | ||||
-rw-r--r-- | arch/ppc64/kernel/rtas-proc.c | 808 | ||||
-rw-r--r-- | arch/ppc64/kernel/rtas_flash.c | 725 | ||||
-rw-r--r-- | arch/ppc64/kernel/rtasd.c | 527 |
4 files changed, 1 insertions, 2063 deletions
diff --git a/arch/ppc64/kernel/Makefile b/arch/ppc64/kernel/Makefile index 990df0905c87..74892ad032ba 100644 --- a/arch/ppc64/kernel/Makefile +++ b/arch/ppc64/kernel/Makefile | |||
@@ -29,19 +29,17 @@ ifneq ($(CONFIG_PPC_MERGE),y) | |||
29 | obj-$(CONFIG_PPC_MULTIPLATFORM) += prom_init.o | 29 | obj-$(CONFIG_PPC_MULTIPLATFORM) += prom_init.o |
30 | endif | 30 | endif |
31 | 31 | ||
32 | obj-$(CONFIG_PPC_PSERIES) += rtasd.o udbg_16550.o | 32 | obj-$(CONFIG_PPC_PSERIES) += udbg_16550.o |
33 | 33 | ||
34 | obj-$(CONFIG_KEXEC) += machine_kexec.o | 34 | obj-$(CONFIG_KEXEC) += machine_kexec.o |
35 | obj-$(CONFIG_EEH) += eeh.o | 35 | obj-$(CONFIG_EEH) += eeh.o |
36 | obj-$(CONFIG_PROC_FS) += proc_ppc64.o | 36 | obj-$(CONFIG_PROC_FS) += proc_ppc64.o |
37 | obj-$(CONFIG_RTAS_FLASH) += rtas_flash.o | ||
38 | obj-$(CONFIG_SMP) += smp.o | 37 | obj-$(CONFIG_SMP) += smp.o |
39 | obj-$(CONFIG_MODULES) += module.o | 38 | obj-$(CONFIG_MODULES) += module.o |
40 | ifneq ($(CONFIG_PPC_MERGE),y) | 39 | ifneq ($(CONFIG_PPC_MERGE),y) |
41 | obj-$(CONFIG_MODULES) += ppc_ksyms.o | 40 | obj-$(CONFIG_MODULES) += ppc_ksyms.o |
42 | endif | 41 | endif |
43 | obj-$(CONFIG_PPC_RTAS) += rtas_pci.o | 42 | obj-$(CONFIG_PPC_RTAS) += rtas_pci.o |
44 | obj-$(CONFIG_RTAS_PROC) += rtas-proc.o | ||
45 | obj-$(CONFIG_SCANLOG) += scanlog.o | 43 | obj-$(CONFIG_SCANLOG) += scanlog.o |
46 | obj-$(CONFIG_LPARCFG) += lparcfg.o | 44 | obj-$(CONFIG_LPARCFG) += lparcfg.o |
47 | obj-$(CONFIG_HVC_CONSOLE) += hvconsole.o | 45 | obj-$(CONFIG_HVC_CONSOLE) += hvconsole.o |
diff --git a/arch/ppc64/kernel/rtas-proc.c b/arch/ppc64/kernel/rtas-proc.c deleted file mode 100644 index 5bdd5b079d96..000000000000 --- a/arch/ppc64/kernel/rtas-proc.c +++ /dev/null | |||
@@ -1,808 +0,0 @@ | |||
1 | /* | ||
2 | * arch/ppc64/kernel/rtas-proc.c | ||
3 | * Copyright (C) 2000 Tilmann Bitterberg | ||
4 | * (tilmann@bitterberg.de) | ||
5 | * | ||
6 | * RTAS (Runtime Abstraction Services) stuff | ||
7 | * Intention is to provide a clean user interface | ||
8 | * to use the RTAS. | ||
9 | * | ||
10 | * TODO: | ||
11 | * Split off a header file and maybe move it to a different | ||
12 | * location. Write Documentation on what the /proc/rtas/ entries | ||
13 | * actually do. | ||
14 | */ | ||
15 | |||
16 | #include <linux/errno.h> | ||
17 | #include <linux/sched.h> | ||
18 | #include <linux/proc_fs.h> | ||
19 | #include <linux/stat.h> | ||
20 | #include <linux/ctype.h> | ||
21 | #include <linux/time.h> | ||
22 | #include <linux/string.h> | ||
23 | #include <linux/init.h> | ||
24 | #include <linux/seq_file.h> | ||
25 | #include <linux/bitops.h> | ||
26 | #include <linux/rtc.h> | ||
27 | |||
28 | #include <asm/uaccess.h> | ||
29 | #include <asm/processor.h> | ||
30 | #include <asm/io.h> | ||
31 | #include <asm/prom.h> | ||
32 | #include <asm/rtas.h> | ||
33 | #include <asm/machdep.h> /* for ppc_md */ | ||
34 | #include <asm/time.h> | ||
35 | #include <asm/systemcfg.h> | ||
36 | |||
37 | /* Token for Sensors */ | ||
38 | #define KEY_SWITCH 0x0001 | ||
39 | #define ENCLOSURE_SWITCH 0x0002 | ||
40 | #define THERMAL_SENSOR 0x0003 | ||
41 | #define LID_STATUS 0x0004 | ||
42 | #define POWER_SOURCE 0x0005 | ||
43 | #define BATTERY_VOLTAGE 0x0006 | ||
44 | #define BATTERY_REMAINING 0x0007 | ||
45 | #define BATTERY_PERCENTAGE 0x0008 | ||
46 | #define EPOW_SENSOR 0x0009 | ||
47 | #define BATTERY_CYCLESTATE 0x000a | ||
48 | #define BATTERY_CHARGING 0x000b | ||
49 | |||
50 | /* IBM specific sensors */ | ||
51 | #define IBM_SURVEILLANCE 0x2328 /* 9000 */ | ||
52 | #define IBM_FANRPM 0x2329 /* 9001 */ | ||
53 | #define IBM_VOLTAGE 0x232a /* 9002 */ | ||
54 | #define IBM_DRCONNECTOR 0x232b /* 9003 */ | ||
55 | #define IBM_POWERSUPPLY 0x232c /* 9004 */ | ||
56 | |||
57 | /* Status return values */ | ||
58 | #define SENSOR_CRITICAL_HIGH 13 | ||
59 | #define SENSOR_WARNING_HIGH 12 | ||
60 | #define SENSOR_NORMAL 11 | ||
61 | #define SENSOR_WARNING_LOW 10 | ||
62 | #define SENSOR_CRITICAL_LOW 9 | ||
63 | #define SENSOR_SUCCESS 0 | ||
64 | #define SENSOR_HW_ERROR -1 | ||
65 | #define SENSOR_BUSY -2 | ||
66 | #define SENSOR_NOT_EXIST -3 | ||
67 | #define SENSOR_DR_ENTITY -9000 | ||
68 | |||
69 | /* Location Codes */ | ||
70 | #define LOC_SCSI_DEV_ADDR 'A' | ||
71 | #define LOC_SCSI_DEV_LOC 'B' | ||
72 | #define LOC_CPU 'C' | ||
73 | #define LOC_DISKETTE 'D' | ||
74 | #define LOC_ETHERNET 'E' | ||
75 | #define LOC_FAN 'F' | ||
76 | #define LOC_GRAPHICS 'G' | ||
77 | /* reserved / not used 'H' */ | ||
78 | #define LOC_IO_ADAPTER 'I' | ||
79 | /* reserved / not used 'J' */ | ||
80 | #define LOC_KEYBOARD 'K' | ||
81 | #define LOC_LCD 'L' | ||
82 | #define LOC_MEMORY 'M' | ||
83 | #define LOC_NV_MEMORY 'N' | ||
84 | #define LOC_MOUSE 'O' | ||
85 | #define LOC_PLANAR 'P' | ||
86 | #define LOC_OTHER_IO 'Q' | ||
87 | #define LOC_PARALLEL 'R' | ||
88 | #define LOC_SERIAL 'S' | ||
89 | #define LOC_DEAD_RING 'T' | ||
90 | #define LOC_RACKMOUNTED 'U' /* for _u_nit is rack mounted */ | ||
91 | #define LOC_VOLTAGE 'V' | ||
92 | #define LOC_SWITCH_ADAPTER 'W' | ||
93 | #define LOC_OTHER 'X' | ||
94 | #define LOC_FIRMWARE 'Y' | ||
95 | #define LOC_SCSI 'Z' | ||
96 | |||
97 | /* Tokens for indicators */ | ||
98 | #define TONE_FREQUENCY 0x0001 /* 0 - 1000 (HZ)*/ | ||
99 | #define TONE_VOLUME 0x0002 /* 0 - 100 (%) */ | ||
100 | #define SYSTEM_POWER_STATE 0x0003 | ||
101 | #define WARNING_LIGHT 0x0004 | ||
102 | #define DISK_ACTIVITY_LIGHT 0x0005 | ||
103 | #define HEX_DISPLAY_UNIT 0x0006 | ||
104 | #define BATTERY_WARNING_TIME 0x0007 | ||
105 | #define CONDITION_CYCLE_REQUEST 0x0008 | ||
106 | #define SURVEILLANCE_INDICATOR 0x2328 /* 9000 */ | ||
107 | #define DR_ACTION 0x2329 /* 9001 */ | ||
108 | #define DR_INDICATOR 0x232a /* 9002 */ | ||
109 | /* 9003 - 9004: Vendor specific */ | ||
110 | /* 9006 - 9999: Vendor specific */ | ||
111 | |||
112 | /* other */ | ||
113 | #define MAX_SENSORS 17 /* I only know of 17 sensors */ | ||
114 | #define MAX_LINELENGTH 256 | ||
115 | #define SENSOR_PREFIX "ibm,sensor-" | ||
116 | #define cel_to_fahr(x) ((x*9/5)+32) | ||
117 | |||
118 | |||
119 | /* Globals */ | ||
120 | static struct rtas_sensors sensors; | ||
121 | static struct device_node *rtas_node = NULL; | ||
122 | static unsigned long power_on_time = 0; /* Save the time the user set */ | ||
123 | static char progress_led[MAX_LINELENGTH]; | ||
124 | |||
125 | static unsigned long rtas_tone_frequency = 1000; | ||
126 | static unsigned long rtas_tone_volume = 0; | ||
127 | |||
128 | /* ****************STRUCTS******************************************* */ | ||
129 | struct individual_sensor { | ||
130 | unsigned int token; | ||
131 | unsigned int quant; | ||
132 | }; | ||
133 | |||
134 | struct rtas_sensors { | ||
135 | struct individual_sensor sensor[MAX_SENSORS]; | ||
136 | unsigned int quant; | ||
137 | }; | ||
138 | |||
139 | /* ****************************************************************** */ | ||
140 | /* Declarations */ | ||
141 | static int ppc_rtas_sensors_show(struct seq_file *m, void *v); | ||
142 | static int ppc_rtas_clock_show(struct seq_file *m, void *v); | ||
143 | static ssize_t ppc_rtas_clock_write(struct file *file, | ||
144 | const char __user *buf, size_t count, loff_t *ppos); | ||
145 | static int ppc_rtas_progress_show(struct seq_file *m, void *v); | ||
146 | static ssize_t ppc_rtas_progress_write(struct file *file, | ||
147 | const char __user *buf, size_t count, loff_t *ppos); | ||
148 | static int ppc_rtas_poweron_show(struct seq_file *m, void *v); | ||
149 | static ssize_t ppc_rtas_poweron_write(struct file *file, | ||
150 | const char __user *buf, size_t count, loff_t *ppos); | ||
151 | |||
152 | static ssize_t ppc_rtas_tone_freq_write(struct file *file, | ||
153 | const char __user *buf, size_t count, loff_t *ppos); | ||
154 | static int ppc_rtas_tone_freq_show(struct seq_file *m, void *v); | ||
155 | static ssize_t ppc_rtas_tone_volume_write(struct file *file, | ||
156 | const char __user *buf, size_t count, loff_t *ppos); | ||
157 | static int ppc_rtas_tone_volume_show(struct seq_file *m, void *v); | ||
158 | static int ppc_rtas_rmo_buf_show(struct seq_file *m, void *v); | ||
159 | |||
160 | static int sensors_open(struct inode *inode, struct file *file) | ||
161 | { | ||
162 | return single_open(file, ppc_rtas_sensors_show, NULL); | ||
163 | } | ||
164 | |||
165 | struct file_operations ppc_rtas_sensors_operations = { | ||
166 | .open = sensors_open, | ||
167 | .read = seq_read, | ||
168 | .llseek = seq_lseek, | ||
169 | .release = single_release, | ||
170 | }; | ||
171 | |||
172 | static int poweron_open(struct inode *inode, struct file *file) | ||
173 | { | ||
174 | return single_open(file, ppc_rtas_poweron_show, NULL); | ||
175 | } | ||
176 | |||
177 | struct file_operations ppc_rtas_poweron_operations = { | ||
178 | .open = poweron_open, | ||
179 | .read = seq_read, | ||
180 | .llseek = seq_lseek, | ||
181 | .write = ppc_rtas_poweron_write, | ||
182 | .release = single_release, | ||
183 | }; | ||
184 | |||
185 | static int progress_open(struct inode *inode, struct file *file) | ||
186 | { | ||
187 | return single_open(file, ppc_rtas_progress_show, NULL); | ||
188 | } | ||
189 | |||
190 | struct file_operations ppc_rtas_progress_operations = { | ||
191 | .open = progress_open, | ||
192 | .read = seq_read, | ||
193 | .llseek = seq_lseek, | ||
194 | .write = ppc_rtas_progress_write, | ||
195 | .release = single_release, | ||
196 | }; | ||
197 | |||
198 | static int clock_open(struct inode *inode, struct file *file) | ||
199 | { | ||
200 | return single_open(file, ppc_rtas_clock_show, NULL); | ||
201 | } | ||
202 | |||
203 | struct file_operations ppc_rtas_clock_operations = { | ||
204 | .open = clock_open, | ||
205 | .read = seq_read, | ||
206 | .llseek = seq_lseek, | ||
207 | .write = ppc_rtas_clock_write, | ||
208 | .release = single_release, | ||
209 | }; | ||
210 | |||
211 | static int tone_freq_open(struct inode *inode, struct file *file) | ||
212 | { | ||
213 | return single_open(file, ppc_rtas_tone_freq_show, NULL); | ||
214 | } | ||
215 | |||
216 | struct file_operations ppc_rtas_tone_freq_operations = { | ||
217 | .open = tone_freq_open, | ||
218 | .read = seq_read, | ||
219 | .llseek = seq_lseek, | ||
220 | .write = ppc_rtas_tone_freq_write, | ||
221 | .release = single_release, | ||
222 | }; | ||
223 | |||
224 | static int tone_volume_open(struct inode *inode, struct file *file) | ||
225 | { | ||
226 | return single_open(file, ppc_rtas_tone_volume_show, NULL); | ||
227 | } | ||
228 | |||
229 | struct file_operations ppc_rtas_tone_volume_operations = { | ||
230 | .open = tone_volume_open, | ||
231 | .read = seq_read, | ||
232 | .llseek = seq_lseek, | ||
233 | .write = ppc_rtas_tone_volume_write, | ||
234 | .release = single_release, | ||
235 | }; | ||
236 | |||
237 | static int rmo_buf_open(struct inode *inode, struct file *file) | ||
238 | { | ||
239 | return single_open(file, ppc_rtas_rmo_buf_show, NULL); | ||
240 | } | ||
241 | |||
242 | struct file_operations ppc_rtas_rmo_buf_ops = { | ||
243 | .open = rmo_buf_open, | ||
244 | .read = seq_read, | ||
245 | .llseek = seq_lseek, | ||
246 | .release = single_release, | ||
247 | }; | ||
248 | |||
249 | static int ppc_rtas_find_all_sensors(void); | ||
250 | static void ppc_rtas_process_sensor(struct seq_file *m, | ||
251 | struct individual_sensor *s, int state, int error, char *loc); | ||
252 | static char *ppc_rtas_process_error(int error); | ||
253 | static void get_location_code(struct seq_file *m, | ||
254 | struct individual_sensor *s, char *loc); | ||
255 | static void check_location_string(struct seq_file *m, char *c); | ||
256 | static void check_location(struct seq_file *m, char *c); | ||
257 | |||
258 | static int __init proc_rtas_init(void) | ||
259 | { | ||
260 | struct proc_dir_entry *entry; | ||
261 | |||
262 | if (!(systemcfg->platform & PLATFORM_PSERIES)) | ||
263 | return 1; | ||
264 | |||
265 | rtas_node = of_find_node_by_name(NULL, "rtas"); | ||
266 | if (rtas_node == NULL) | ||
267 | return 1; | ||
268 | |||
269 | entry = create_proc_entry("ppc64/rtas/progress", S_IRUGO|S_IWUSR, NULL); | ||
270 | if (entry) | ||
271 | entry->proc_fops = &ppc_rtas_progress_operations; | ||
272 | |||
273 | entry = create_proc_entry("ppc64/rtas/clock", S_IRUGO|S_IWUSR, NULL); | ||
274 | if (entry) | ||
275 | entry->proc_fops = &ppc_rtas_clock_operations; | ||
276 | |||
277 | entry = create_proc_entry("ppc64/rtas/poweron", S_IWUSR|S_IRUGO, NULL); | ||
278 | if (entry) | ||
279 | entry->proc_fops = &ppc_rtas_poweron_operations; | ||
280 | |||
281 | entry = create_proc_entry("ppc64/rtas/sensors", S_IRUGO, NULL); | ||
282 | if (entry) | ||
283 | entry->proc_fops = &ppc_rtas_sensors_operations; | ||
284 | |||
285 | entry = create_proc_entry("ppc64/rtas/frequency", S_IWUSR|S_IRUGO, | ||
286 | NULL); | ||
287 | if (entry) | ||
288 | entry->proc_fops = &ppc_rtas_tone_freq_operations; | ||
289 | |||
290 | entry = create_proc_entry("ppc64/rtas/volume", S_IWUSR|S_IRUGO, NULL); | ||
291 | if (entry) | ||
292 | entry->proc_fops = &ppc_rtas_tone_volume_operations; | ||
293 | |||
294 | entry = create_proc_entry("ppc64/rtas/rmo_buffer", S_IRUSR, NULL); | ||
295 | if (entry) | ||
296 | entry->proc_fops = &ppc_rtas_rmo_buf_ops; | ||
297 | |||
298 | return 0; | ||
299 | } | ||
300 | |||
301 | __initcall(proc_rtas_init); | ||
302 | |||
303 | static int parse_number(const char __user *p, size_t count, unsigned long *val) | ||
304 | { | ||
305 | char buf[40]; | ||
306 | char *end; | ||
307 | |||
308 | if (count > 39) | ||
309 | return -EINVAL; | ||
310 | |||
311 | if (copy_from_user(buf, p, count)) | ||
312 | return -EFAULT; | ||
313 | |||
314 | buf[count] = 0; | ||
315 | |||
316 | *val = simple_strtoul(buf, &end, 10); | ||
317 | if (*end && *end != '\n') | ||
318 | return -EINVAL; | ||
319 | |||
320 | return 0; | ||
321 | } | ||
322 | |||
323 | /* ****************************************************************** */ | ||
324 | /* POWER-ON-TIME */ | ||
325 | /* ****************************************************************** */ | ||
326 | static ssize_t ppc_rtas_poweron_write(struct file *file, | ||
327 | const char __user *buf, size_t count, loff_t *ppos) | ||
328 | { | ||
329 | struct rtc_time tm; | ||
330 | unsigned long nowtime; | ||
331 | int error = parse_number(buf, count, &nowtime); | ||
332 | if (error) | ||
333 | return error; | ||
334 | |||
335 | power_on_time = nowtime; /* save the time */ | ||
336 | |||
337 | to_tm(nowtime, &tm); | ||
338 | |||
339 | error = rtas_call(rtas_token("set-time-for-power-on"), 7, 1, NULL, | ||
340 | tm.tm_year, tm.tm_mon, tm.tm_mday, | ||
341 | tm.tm_hour, tm.tm_min, tm.tm_sec, 0 /* nano */); | ||
342 | if (error) | ||
343 | printk(KERN_WARNING "error: setting poweron time returned: %s\n", | ||
344 | ppc_rtas_process_error(error)); | ||
345 | return count; | ||
346 | } | ||
347 | /* ****************************************************************** */ | ||
348 | static int ppc_rtas_poweron_show(struct seq_file *m, void *v) | ||
349 | { | ||
350 | if (power_on_time == 0) | ||
351 | seq_printf(m, "Power on time not set\n"); | ||
352 | else | ||
353 | seq_printf(m, "%lu\n",power_on_time); | ||
354 | return 0; | ||
355 | } | ||
356 | |||
357 | /* ****************************************************************** */ | ||
358 | /* PROGRESS */ | ||
359 | /* ****************************************************************** */ | ||
360 | static ssize_t ppc_rtas_progress_write(struct file *file, | ||
361 | const char __user *buf, size_t count, loff_t *ppos) | ||
362 | { | ||
363 | unsigned long hex; | ||
364 | |||
365 | if (count >= MAX_LINELENGTH) | ||
366 | count = MAX_LINELENGTH -1; | ||
367 | if (copy_from_user(progress_led, buf, count)) { /* save the string */ | ||
368 | return -EFAULT; | ||
369 | } | ||
370 | progress_led[count] = 0; | ||
371 | |||
372 | /* Lets see if the user passed hexdigits */ | ||
373 | hex = simple_strtoul(progress_led, NULL, 10); | ||
374 | |||
375 | rtas_progress ((char *)progress_led, hex); | ||
376 | return count; | ||
377 | |||
378 | /* clear the line */ | ||
379 | /* rtas_progress(" ", 0xffff);*/ | ||
380 | } | ||
381 | /* ****************************************************************** */ | ||
382 | static int ppc_rtas_progress_show(struct seq_file *m, void *v) | ||
383 | { | ||
384 | if (progress_led) | ||
385 | seq_printf(m, "%s\n", progress_led); | ||
386 | return 0; | ||
387 | } | ||
388 | |||
389 | /* ****************************************************************** */ | ||
390 | /* CLOCK */ | ||
391 | /* ****************************************************************** */ | ||
392 | static ssize_t ppc_rtas_clock_write(struct file *file, | ||
393 | const char __user *buf, size_t count, loff_t *ppos) | ||
394 | { | ||
395 | struct rtc_time tm; | ||
396 | unsigned long nowtime; | ||
397 | int error = parse_number(buf, count, &nowtime); | ||
398 | if (error) | ||
399 | return error; | ||
400 | |||
401 | to_tm(nowtime, &tm); | ||
402 | error = rtas_call(rtas_token("set-time-of-day"), 7, 1, NULL, | ||
403 | tm.tm_year, tm.tm_mon, tm.tm_mday, | ||
404 | tm.tm_hour, tm.tm_min, tm.tm_sec, 0); | ||
405 | if (error) | ||
406 | printk(KERN_WARNING "error: setting the clock returned: %s\n", | ||
407 | ppc_rtas_process_error(error)); | ||
408 | return count; | ||
409 | } | ||
410 | /* ****************************************************************** */ | ||
411 | static int ppc_rtas_clock_show(struct seq_file *m, void *v) | ||
412 | { | ||
413 | int ret[8]; | ||
414 | int error = rtas_call(rtas_token("get-time-of-day"), 0, 8, ret); | ||
415 | |||
416 | if (error) { | ||
417 | printk(KERN_WARNING "error: reading the clock returned: %s\n", | ||
418 | ppc_rtas_process_error(error)); | ||
419 | seq_printf(m, "0"); | ||
420 | } else { | ||
421 | unsigned int year, mon, day, hour, min, sec; | ||
422 | year = ret[0]; mon = ret[1]; day = ret[2]; | ||
423 | hour = ret[3]; min = ret[4]; sec = ret[5]; | ||
424 | seq_printf(m, "%lu\n", | ||
425 | mktime(year, mon, day, hour, min, sec)); | ||
426 | } | ||
427 | return 0; | ||
428 | } | ||
429 | |||
430 | /* ****************************************************************** */ | ||
431 | /* SENSOR STUFF */ | ||
432 | /* ****************************************************************** */ | ||
433 | static int ppc_rtas_sensors_show(struct seq_file *m, void *v) | ||
434 | { | ||
435 | int i,j; | ||
436 | int state, error; | ||
437 | int get_sensor_state = rtas_token("get-sensor-state"); | ||
438 | |||
439 | seq_printf(m, "RTAS (RunTime Abstraction Services) Sensor Information\n"); | ||
440 | seq_printf(m, "Sensor\t\tValue\t\tCondition\tLocation\n"); | ||
441 | seq_printf(m, "********************************************************\n"); | ||
442 | |||
443 | if (ppc_rtas_find_all_sensors() != 0) { | ||
444 | seq_printf(m, "\nNo sensors are available\n"); | ||
445 | return 0; | ||
446 | } | ||
447 | |||
448 | for (i=0; i<sensors.quant; i++) { | ||
449 | struct individual_sensor *p = &sensors.sensor[i]; | ||
450 | char rstr[64]; | ||
451 | char *loc; | ||
452 | int llen, offs; | ||
453 | |||
454 | sprintf (rstr, SENSOR_PREFIX"%04d", p->token); | ||
455 | loc = (char *) get_property(rtas_node, rstr, &llen); | ||
456 | |||
457 | /* A sensor may have multiple instances */ | ||
458 | for (j = 0, offs = 0; j <= p->quant; j++) { | ||
459 | error = rtas_call(get_sensor_state, 2, 2, &state, | ||
460 | p->token, j); | ||
461 | |||
462 | ppc_rtas_process_sensor(m, p, state, error, loc); | ||
463 | seq_putc(m, '\n'); | ||
464 | if (loc) { | ||
465 | offs += strlen(loc) + 1; | ||
466 | loc += strlen(loc) + 1; | ||
467 | if (offs >= llen) | ||
468 | loc = NULL; | ||
469 | } | ||
470 | } | ||
471 | } | ||
472 | return 0; | ||
473 | } | ||
474 | |||
475 | /* ****************************************************************** */ | ||
476 | |||
477 | static int ppc_rtas_find_all_sensors(void) | ||
478 | { | ||
479 | unsigned int *utmp; | ||
480 | int len, i; | ||
481 | |||
482 | utmp = (unsigned int *) get_property(rtas_node, "rtas-sensors", &len); | ||
483 | if (utmp == NULL) { | ||
484 | printk (KERN_ERR "error: could not get rtas-sensors\n"); | ||
485 | return 1; | ||
486 | } | ||
487 | |||
488 | sensors.quant = len / 8; /* int + int */ | ||
489 | |||
490 | for (i=0; i<sensors.quant; i++) { | ||
491 | sensors.sensor[i].token = *utmp++; | ||
492 | sensors.sensor[i].quant = *utmp++; | ||
493 | } | ||
494 | return 0; | ||
495 | } | ||
496 | |||
497 | /* ****************************************************************** */ | ||
498 | /* | ||
499 | * Builds a string of what rtas returned | ||
500 | */ | ||
501 | static char *ppc_rtas_process_error(int error) | ||
502 | { | ||
503 | switch (error) { | ||
504 | case SENSOR_CRITICAL_HIGH: | ||
505 | return "(critical high)"; | ||
506 | case SENSOR_WARNING_HIGH: | ||
507 | return "(warning high)"; | ||
508 | case SENSOR_NORMAL: | ||
509 | return "(normal)"; | ||
510 | case SENSOR_WARNING_LOW: | ||
511 | return "(warning low)"; | ||
512 | case SENSOR_CRITICAL_LOW: | ||
513 | return "(critical low)"; | ||
514 | case SENSOR_SUCCESS: | ||
515 | return "(read ok)"; | ||
516 | case SENSOR_HW_ERROR: | ||
517 | return "(hardware error)"; | ||
518 | case SENSOR_BUSY: | ||
519 | return "(busy)"; | ||
520 | case SENSOR_NOT_EXIST: | ||
521 | return "(non existent)"; | ||
522 | case SENSOR_DR_ENTITY: | ||
523 | return "(dr entity removed)"; | ||
524 | default: | ||
525 | return "(UNKNOWN)"; | ||
526 | } | ||
527 | } | ||
528 | |||
529 | /* ****************************************************************** */ | ||
530 | /* | ||
531 | * Builds a string out of what the sensor said | ||
532 | */ | ||
533 | |||
534 | static void ppc_rtas_process_sensor(struct seq_file *m, | ||
535 | struct individual_sensor *s, int state, int error, char *loc) | ||
536 | { | ||
537 | /* Defined return vales */ | ||
538 | const char * key_switch[] = { "Off\t", "Normal\t", "Secure\t", | ||
539 | "Maintenance" }; | ||
540 | const char * enclosure_switch[] = { "Closed", "Open" }; | ||
541 | const char * lid_status[] = { " ", "Open", "Closed" }; | ||
542 | const char * power_source[] = { "AC\t", "Battery", | ||
543 | "AC & Battery" }; | ||
544 | const char * battery_remaining[] = { "Very Low", "Low", "Mid", "High" }; | ||
545 | const char * epow_sensor[] = { | ||
546 | "EPOW Reset", "Cooling warning", "Power warning", | ||
547 | "System shutdown", "System halt", "EPOW main enclosure", | ||
548 | "EPOW power off" }; | ||
549 | const char * battery_cyclestate[] = { "None", "In progress", | ||
550 | "Requested" }; | ||
551 | const char * battery_charging[] = { "Charging", "Discharching", | ||
552 | "No current flow" }; | ||
553 | const char * ibm_drconnector[] = { "Empty", "Present", "Unusable", | ||
554 | "Exchange" }; | ||
555 | |||
556 | int have_strings = 0; | ||
557 | int num_states = 0; | ||
558 | int temperature = 0; | ||
559 | int unknown = 0; | ||
560 | |||
561 | /* What kind of sensor do we have here? */ | ||
562 | |||
563 | switch (s->token) { | ||
564 | case KEY_SWITCH: | ||
565 | seq_printf(m, "Key switch:\t"); | ||
566 | num_states = sizeof(key_switch) / sizeof(char *); | ||
567 | if (state < num_states) { | ||
568 | seq_printf(m, "%s\t", key_switch[state]); | ||
569 | have_strings = 1; | ||
570 | } | ||
571 | break; | ||
572 | case ENCLOSURE_SWITCH: | ||
573 | seq_printf(m, "Enclosure switch:\t"); | ||
574 | num_states = sizeof(enclosure_switch) / sizeof(char *); | ||
575 | if (state < num_states) { | ||
576 | seq_printf(m, "%s\t", | ||
577 | enclosure_switch[state]); | ||
578 | have_strings = 1; | ||
579 | } | ||
580 | break; | ||
581 | case THERMAL_SENSOR: | ||
582 | seq_printf(m, "Temp. (C/F):\t"); | ||
583 | temperature = 1; | ||
584 | break; | ||
585 | case LID_STATUS: | ||
586 | seq_printf(m, "Lid status:\t"); | ||
587 | num_states = sizeof(lid_status) / sizeof(char *); | ||
588 | if (state < num_states) { | ||
589 | seq_printf(m, "%s\t", lid_status[state]); | ||
590 | have_strings = 1; | ||
591 | } | ||
592 | break; | ||
593 | case POWER_SOURCE: | ||
594 | seq_printf(m, "Power source:\t"); | ||
595 | num_states = sizeof(power_source) / sizeof(char *); | ||
596 | if (state < num_states) { | ||
597 | seq_printf(m, "%s\t", | ||
598 | power_source[state]); | ||
599 | have_strings = 1; | ||
600 | } | ||
601 | break; | ||
602 | case BATTERY_VOLTAGE: | ||
603 | seq_printf(m, "Battery voltage:\t"); | ||
604 | break; | ||
605 | case BATTERY_REMAINING: | ||
606 | seq_printf(m, "Battery remaining:\t"); | ||
607 | num_states = sizeof(battery_remaining) / sizeof(char *); | ||
608 | if (state < num_states) | ||
609 | { | ||
610 | seq_printf(m, "%s\t", | ||
611 | battery_remaining[state]); | ||
612 | have_strings = 1; | ||
613 | } | ||
614 | break; | ||
615 | case BATTERY_PERCENTAGE: | ||
616 | seq_printf(m, "Battery percentage:\t"); | ||
617 | break; | ||
618 | case EPOW_SENSOR: | ||
619 | seq_printf(m, "EPOW Sensor:\t"); | ||
620 | num_states = sizeof(epow_sensor) / sizeof(char *); | ||
621 | if (state < num_states) { | ||
622 | seq_printf(m, "%s\t", epow_sensor[state]); | ||
623 | have_strings = 1; | ||
624 | } | ||
625 | break; | ||
626 | case BATTERY_CYCLESTATE: | ||
627 | seq_printf(m, "Battery cyclestate:\t"); | ||
628 | num_states = sizeof(battery_cyclestate) / | ||
629 | sizeof(char *); | ||
630 | if (state < num_states) { | ||
631 | seq_printf(m, "%s\t", | ||
632 | battery_cyclestate[state]); | ||
633 | have_strings = 1; | ||
634 | } | ||
635 | break; | ||
636 | case BATTERY_CHARGING: | ||
637 | seq_printf(m, "Battery Charging:\t"); | ||
638 | num_states = sizeof(battery_charging) / sizeof(char *); | ||
639 | if (state < num_states) { | ||
640 | seq_printf(m, "%s\t", | ||
641 | battery_charging[state]); | ||
642 | have_strings = 1; | ||
643 | } | ||
644 | break; | ||
645 | case IBM_SURVEILLANCE: | ||
646 | seq_printf(m, "Surveillance:\t"); | ||
647 | break; | ||
648 | case IBM_FANRPM: | ||
649 | seq_printf(m, "Fan (rpm):\t"); | ||
650 | break; | ||
651 | case IBM_VOLTAGE: | ||
652 | seq_printf(m, "Voltage (mv):\t"); | ||
653 | break; | ||
654 | case IBM_DRCONNECTOR: | ||
655 | seq_printf(m, "DR connector:\t"); | ||
656 | num_states = sizeof(ibm_drconnector) / sizeof(char *); | ||
657 | if (state < num_states) { | ||
658 | seq_printf(m, "%s\t", | ||
659 | ibm_drconnector[state]); | ||
660 | have_strings = 1; | ||
661 | } | ||
662 | break; | ||
663 | case IBM_POWERSUPPLY: | ||
664 | seq_printf(m, "Powersupply:\t"); | ||
665 | break; | ||
666 | default: | ||
667 | seq_printf(m, "Unknown sensor (type %d), ignoring it\n", | ||
668 | s->token); | ||
669 | unknown = 1; | ||
670 | have_strings = 1; | ||
671 | break; | ||
672 | } | ||
673 | if (have_strings == 0) { | ||
674 | if (temperature) { | ||
675 | seq_printf(m, "%4d /%4d\t", state, cel_to_fahr(state)); | ||
676 | } else | ||
677 | seq_printf(m, "%10d\t", state); | ||
678 | } | ||
679 | if (unknown == 0) { | ||
680 | seq_printf(m, "%s\t", ppc_rtas_process_error(error)); | ||
681 | get_location_code(m, s, loc); | ||
682 | } | ||
683 | } | ||
684 | |||
685 | /* ****************************************************************** */ | ||
686 | |||
687 | static void check_location(struct seq_file *m, char *c) | ||
688 | { | ||
689 | switch (c[0]) { | ||
690 | case LOC_PLANAR: | ||
691 | seq_printf(m, "Planar #%c", c[1]); | ||
692 | break; | ||
693 | case LOC_CPU: | ||
694 | seq_printf(m, "CPU #%c", c[1]); | ||
695 | break; | ||
696 | case LOC_FAN: | ||
697 | seq_printf(m, "Fan #%c", c[1]); | ||
698 | break; | ||
699 | case LOC_RACKMOUNTED: | ||
700 | seq_printf(m, "Rack #%c", c[1]); | ||
701 | break; | ||
702 | case LOC_VOLTAGE: | ||
703 | seq_printf(m, "Voltage #%c", c[1]); | ||
704 | break; | ||
705 | case LOC_LCD: | ||
706 | seq_printf(m, "LCD #%c", c[1]); | ||
707 | break; | ||
708 | case '.': | ||
709 | seq_printf(m, "- %c", c[1]); | ||
710 | break; | ||
711 | default: | ||
712 | seq_printf(m, "Unknown location"); | ||
713 | break; | ||
714 | } | ||
715 | } | ||
716 | |||
717 | |||
718 | /* ****************************************************************** */ | ||
719 | /* | ||
720 | * Format: | ||
721 | * ${LETTER}${NUMBER}[[-/]${LETTER}${NUMBER} [ ... ] ] | ||
722 | * the '.' may be an abbrevation | ||
723 | */ | ||
724 | static void check_location_string(struct seq_file *m, char *c) | ||
725 | { | ||
726 | while (*c) { | ||
727 | if (isalpha(*c) || *c == '.') | ||
728 | check_location(m, c); | ||
729 | else if (*c == '/' || *c == '-') | ||
730 | seq_printf(m, " at "); | ||
731 | c++; | ||
732 | } | ||
733 | } | ||
734 | |||
735 | |||
736 | /* ****************************************************************** */ | ||
737 | |||
738 | static void get_location_code(struct seq_file *m, struct individual_sensor *s, char *loc) | ||
739 | { | ||
740 | if (!loc || !*loc) { | ||
741 | seq_printf(m, "---");/* does not have a location */ | ||
742 | } else { | ||
743 | check_location_string(m, loc); | ||
744 | } | ||
745 | seq_putc(m, ' '); | ||
746 | } | ||
747 | /* ****************************************************************** */ | ||
748 | /* INDICATORS - Tone Frequency */ | ||
749 | /* ****************************************************************** */ | ||
750 | static ssize_t ppc_rtas_tone_freq_write(struct file *file, | ||
751 | const char __user *buf, size_t count, loff_t *ppos) | ||
752 | { | ||
753 | unsigned long freq; | ||
754 | int error = parse_number(buf, count, &freq); | ||
755 | if (error) | ||
756 | return error; | ||
757 | |||
758 | rtas_tone_frequency = freq; /* save it for later */ | ||
759 | error = rtas_call(rtas_token("set-indicator"), 3, 1, NULL, | ||
760 | TONE_FREQUENCY, 0, freq); | ||
761 | if (error) | ||
762 | printk(KERN_WARNING "error: setting tone frequency returned: %s\n", | ||
763 | ppc_rtas_process_error(error)); | ||
764 | return count; | ||
765 | } | ||
766 | /* ****************************************************************** */ | ||
767 | static int ppc_rtas_tone_freq_show(struct seq_file *m, void *v) | ||
768 | { | ||
769 | seq_printf(m, "%lu\n", rtas_tone_frequency); | ||
770 | return 0; | ||
771 | } | ||
772 | /* ****************************************************************** */ | ||
773 | /* INDICATORS - Tone Volume */ | ||
774 | /* ****************************************************************** */ | ||
775 | static ssize_t ppc_rtas_tone_volume_write(struct file *file, | ||
776 | const char __user *buf, size_t count, loff_t *ppos) | ||
777 | { | ||
778 | unsigned long volume; | ||
779 | int error = parse_number(buf, count, &volume); | ||
780 | if (error) | ||
781 | return error; | ||
782 | |||
783 | if (volume > 100) | ||
784 | volume = 100; | ||
785 | |||
786 | rtas_tone_volume = volume; /* save it for later */ | ||
787 | error = rtas_call(rtas_token("set-indicator"), 3, 1, NULL, | ||
788 | TONE_VOLUME, 0, volume); | ||
789 | if (error) | ||
790 | printk(KERN_WARNING "error: setting tone volume returned: %s\n", | ||
791 | ppc_rtas_process_error(error)); | ||
792 | return count; | ||
793 | } | ||
794 | /* ****************************************************************** */ | ||
795 | static int ppc_rtas_tone_volume_show(struct seq_file *m, void *v) | ||
796 | { | ||
797 | seq_printf(m, "%lu\n", rtas_tone_volume); | ||
798 | return 0; | ||
799 | } | ||
800 | |||
801 | #define RMO_READ_BUF_MAX 30 | ||
802 | |||
803 | /* RTAS Userspace access */ | ||
804 | static int ppc_rtas_rmo_buf_show(struct seq_file *m, void *v) | ||
805 | { | ||
806 | seq_printf(m, "%016lx %x\n", rtas_rmo_buf, RTAS_RMOBUF_MAX); | ||
807 | return 0; | ||
808 | } | ||
diff --git a/arch/ppc64/kernel/rtas_flash.c b/arch/ppc64/kernel/rtas_flash.c deleted file mode 100644 index 923e2e201a70..000000000000 --- a/arch/ppc64/kernel/rtas_flash.c +++ /dev/null | |||
@@ -1,725 +0,0 @@ | |||
1 | /* | ||
2 | * c 2001 PPC 64 Team, IBM Corp | ||
3 | * | ||
4 | * This program is free software; you can redistribute it and/or | ||
5 | * modify it under the terms of the GNU General Public License | ||
6 | * as published by the Free Software Foundation; either version | ||
7 | * 2 of the License, or (at your option) any later version. | ||
8 | * | ||
9 | * /proc/ppc64/rtas/firmware_flash interface | ||
10 | * | ||
11 | * This file implements a firmware_flash interface to pump a firmware | ||
12 | * image into the kernel. At reboot time rtas_restart() will see the | ||
13 | * firmware image and flash it as it reboots (see rtas.c). | ||
14 | */ | ||
15 | |||
16 | #include <linux/module.h> | ||
17 | #include <linux/init.h> | ||
18 | #include <linux/proc_fs.h> | ||
19 | #include <asm/delay.h> | ||
20 | #include <asm/uaccess.h> | ||
21 | #include <asm/rtas.h> | ||
22 | |||
23 | #define MODULE_VERS "1.0" | ||
24 | #define MODULE_NAME "rtas_flash" | ||
25 | |||
26 | #define FIRMWARE_FLASH_NAME "firmware_flash" | ||
27 | #define FIRMWARE_UPDATE_NAME "firmware_update" | ||
28 | #define MANAGE_FLASH_NAME "manage_flash" | ||
29 | #define VALIDATE_FLASH_NAME "validate_flash" | ||
30 | |||
31 | /* General RTAS Status Codes */ | ||
32 | #define RTAS_RC_SUCCESS 0 | ||
33 | #define RTAS_RC_HW_ERR -1 | ||
34 | #define RTAS_RC_BUSY -2 | ||
35 | |||
36 | /* Flash image status values */ | ||
37 | #define FLASH_AUTH -9002 /* RTAS Not Service Authority Partition */ | ||
38 | #define FLASH_NO_OP -1099 /* No operation initiated by user */ | ||
39 | #define FLASH_IMG_SHORT -1005 /* Flash image shorter than expected */ | ||
40 | #define FLASH_IMG_BAD_LEN -1004 /* Bad length value in flash list block */ | ||
41 | #define FLASH_IMG_NULL_DATA -1003 /* Bad data value in flash list block */ | ||
42 | #define FLASH_IMG_READY 0 /* Firmware img ready for flash on reboot */ | ||
43 | |||
44 | /* Manage image status values */ | ||
45 | #define MANAGE_AUTH -9002 /* RTAS Not Service Authority Partition */ | ||
46 | #define MANAGE_ACTIVE_ERR -9001 /* RTAS Cannot Overwrite Active Img */ | ||
47 | #define MANAGE_NO_OP -1099 /* No operation initiated by user */ | ||
48 | #define MANAGE_PARAM_ERR -3 /* RTAS Parameter Error */ | ||
49 | #define MANAGE_HW_ERR -1 /* RTAS Hardware Error */ | ||
50 | |||
51 | /* Validate image status values */ | ||
52 | #define VALIDATE_AUTH -9002 /* RTAS Not Service Authority Partition */ | ||
53 | #define VALIDATE_NO_OP -1099 /* No operation initiated by the user */ | ||
54 | #define VALIDATE_INCOMPLETE -1002 /* User copied < VALIDATE_BUF_SIZE */ | ||
55 | #define VALIDATE_READY -1001 /* Firmware image ready for validation */ | ||
56 | #define VALIDATE_PARAM_ERR -3 /* RTAS Parameter Error */ | ||
57 | #define VALIDATE_HW_ERR -1 /* RTAS Hardware Error */ | ||
58 | #define VALIDATE_TMP_UPDATE 0 /* Validate Return Status */ | ||
59 | #define VALIDATE_FLASH_AUTH 1 /* Validate Return Status */ | ||
60 | #define VALIDATE_INVALID_IMG 2 /* Validate Return Status */ | ||
61 | #define VALIDATE_CUR_UNKNOWN 3 /* Validate Return Status */ | ||
62 | #define VALIDATE_TMP_COMMIT_DL 4 /* Validate Return Status */ | ||
63 | #define VALIDATE_TMP_COMMIT 5 /* Validate Return Status */ | ||
64 | #define VALIDATE_TMP_UPDATE_DL 6 /* Validate Return Status */ | ||
65 | |||
66 | /* ibm,manage-flash-image operation tokens */ | ||
67 | #define RTAS_REJECT_TMP_IMG 0 | ||
68 | #define RTAS_COMMIT_TMP_IMG 1 | ||
69 | |||
70 | /* Array sizes */ | ||
71 | #define VALIDATE_BUF_SIZE 4096 | ||
72 | #define RTAS_MSG_MAXLEN 64 | ||
73 | |||
74 | /* Local copy of the flash block list. | ||
75 | * We only allow one open of the flash proc file and create this | ||
76 | * list as we go. This list will be put in the kernel's | ||
77 | * rtas_firmware_flash_list global var once it is fully read. | ||
78 | * | ||
79 | * For convenience as we build the list we use virtual addrs, | ||
80 | * we do not fill in the version number, and the length field | ||
81 | * is treated as the number of entries currently in the block | ||
82 | * (i.e. not a byte count). This is all fixed on release. | ||
83 | */ | ||
84 | |||
85 | /* Status int must be first member of struct */ | ||
86 | struct rtas_update_flash_t | ||
87 | { | ||
88 | int status; /* Flash update status */ | ||
89 | struct flash_block_list *flist; /* Local copy of flash block list */ | ||
90 | }; | ||
91 | |||
92 | /* Status int must be first member of struct */ | ||
93 | struct rtas_manage_flash_t | ||
94 | { | ||
95 | int status; /* Returned status */ | ||
96 | unsigned int op; /* Reject or commit image */ | ||
97 | }; | ||
98 | |||
99 | /* Status int must be first member of struct */ | ||
100 | struct rtas_validate_flash_t | ||
101 | { | ||
102 | int status; /* Returned status */ | ||
103 | char buf[VALIDATE_BUF_SIZE]; /* Candidate image buffer */ | ||
104 | unsigned int buf_size; /* Size of image buf */ | ||
105 | unsigned int update_results; /* Update results token */ | ||
106 | }; | ||
107 | |||
108 | static DEFINE_SPINLOCK(flash_file_open_lock); | ||
109 | static struct proc_dir_entry *firmware_flash_pde; | ||
110 | static struct proc_dir_entry *firmware_update_pde; | ||
111 | static struct proc_dir_entry *validate_pde; | ||
112 | static struct proc_dir_entry *manage_pde; | ||
113 | |||
114 | /* Do simple sanity checks on the flash image. */ | ||
115 | static int flash_list_valid(struct flash_block_list *flist) | ||
116 | { | ||
117 | struct flash_block_list *f; | ||
118 | int i; | ||
119 | unsigned long block_size, image_size; | ||
120 | |||
121 | /* Paranoid self test here. We also collect the image size. */ | ||
122 | image_size = 0; | ||
123 | for (f = flist; f; f = f->next) { | ||
124 | for (i = 0; i < f->num_blocks; i++) { | ||
125 | if (f->blocks[i].data == NULL) { | ||
126 | return FLASH_IMG_NULL_DATA; | ||
127 | } | ||
128 | block_size = f->blocks[i].length; | ||
129 | if (block_size <= 0 || block_size > PAGE_SIZE) { | ||
130 | return FLASH_IMG_BAD_LEN; | ||
131 | } | ||
132 | image_size += block_size; | ||
133 | } | ||
134 | } | ||
135 | |||
136 | if (image_size < (256 << 10)) { | ||
137 | if (image_size < 2) | ||
138 | return FLASH_NO_OP; | ||
139 | } | ||
140 | |||
141 | printk(KERN_INFO "FLASH: flash image with %ld bytes stored for hardware flash on reboot\n", image_size); | ||
142 | |||
143 | return FLASH_IMG_READY; | ||
144 | } | ||
145 | |||
146 | static void free_flash_list(struct flash_block_list *f) | ||
147 | { | ||
148 | struct flash_block_list *next; | ||
149 | int i; | ||
150 | |||
151 | while (f) { | ||
152 | for (i = 0; i < f->num_blocks; i++) | ||
153 | free_page((unsigned long)(f->blocks[i].data)); | ||
154 | next = f->next; | ||
155 | free_page((unsigned long)f); | ||
156 | f = next; | ||
157 | } | ||
158 | } | ||
159 | |||
160 | static int rtas_flash_release(struct inode *inode, struct file *file) | ||
161 | { | ||
162 | struct proc_dir_entry *dp = PDE(file->f_dentry->d_inode); | ||
163 | struct rtas_update_flash_t *uf; | ||
164 | |||
165 | uf = (struct rtas_update_flash_t *) dp->data; | ||
166 | if (uf->flist) { | ||
167 | /* File was opened in write mode for a new flash attempt */ | ||
168 | /* Clear saved list */ | ||
169 | if (rtas_firmware_flash_list.next) { | ||
170 | free_flash_list(rtas_firmware_flash_list.next); | ||
171 | rtas_firmware_flash_list.next = NULL; | ||
172 | } | ||
173 | |||
174 | if (uf->status != FLASH_AUTH) | ||
175 | uf->status = flash_list_valid(uf->flist); | ||
176 | |||
177 | if (uf->status == FLASH_IMG_READY) | ||
178 | rtas_firmware_flash_list.next = uf->flist; | ||
179 | else | ||
180 | free_flash_list(uf->flist); | ||
181 | |||
182 | uf->flist = NULL; | ||
183 | } | ||
184 | |||
185 | atomic_dec(&dp->count); | ||
186 | return 0; | ||
187 | } | ||
188 | |||
189 | static void get_flash_status_msg(int status, char *buf) | ||
190 | { | ||
191 | char *msg; | ||
192 | |||
193 | switch (status) { | ||
194 | case FLASH_AUTH: | ||
195 | msg = "error: this partition does not have service authority\n"; | ||
196 | break; | ||
197 | case FLASH_NO_OP: | ||
198 | msg = "info: no firmware image for flash\n"; | ||
199 | break; | ||
200 | case FLASH_IMG_SHORT: | ||
201 | msg = "error: flash image short\n"; | ||
202 | break; | ||
203 | case FLASH_IMG_BAD_LEN: | ||
204 | msg = "error: internal error bad length\n"; | ||
205 | break; | ||
206 | case FLASH_IMG_NULL_DATA: | ||
207 | msg = "error: internal error null data\n"; | ||
208 | break; | ||
209 | case FLASH_IMG_READY: | ||
210 | msg = "ready: firmware image ready for flash on reboot\n"; | ||
211 | break; | ||
212 | default: | ||
213 | sprintf(buf, "error: unexpected status value %d\n", status); | ||
214 | return; | ||
215 | } | ||
216 | |||
217 | strcpy(buf, msg); | ||
218 | } | ||
219 | |||
220 | /* Reading the proc file will show status (not the firmware contents) */ | ||
221 | static ssize_t rtas_flash_read(struct file *file, char __user *buf, | ||
222 | size_t count, loff_t *ppos) | ||
223 | { | ||
224 | struct proc_dir_entry *dp = PDE(file->f_dentry->d_inode); | ||
225 | struct rtas_update_flash_t *uf; | ||
226 | char msg[RTAS_MSG_MAXLEN]; | ||
227 | int msglen; | ||
228 | |||
229 | uf = (struct rtas_update_flash_t *) dp->data; | ||
230 | |||
231 | if (!strcmp(dp->name, FIRMWARE_FLASH_NAME)) { | ||
232 | get_flash_status_msg(uf->status, msg); | ||
233 | } else { /* FIRMWARE_UPDATE_NAME */ | ||
234 | sprintf(msg, "%d\n", uf->status); | ||
235 | } | ||
236 | msglen = strlen(msg); | ||
237 | if (msglen > count) | ||
238 | msglen = count; | ||
239 | |||
240 | if (ppos && *ppos != 0) | ||
241 | return 0; /* be cheap */ | ||
242 | |||
243 | if (!access_ok(VERIFY_WRITE, buf, msglen)) | ||
244 | return -EINVAL; | ||
245 | |||
246 | if (copy_to_user(buf, msg, msglen)) | ||
247 | return -EFAULT; | ||
248 | |||
249 | if (ppos) | ||
250 | *ppos = msglen; | ||
251 | return msglen; | ||
252 | } | ||
253 | |||
254 | /* We could be much more efficient here. But to keep this function | ||
255 | * simple we allocate a page to the block list no matter how small the | ||
256 | * count is. If the system is low on memory it will be just as well | ||
257 | * that we fail.... | ||
258 | */ | ||
259 | static ssize_t rtas_flash_write(struct file *file, const char __user *buffer, | ||
260 | size_t count, loff_t *off) | ||
261 | { | ||
262 | struct proc_dir_entry *dp = PDE(file->f_dentry->d_inode); | ||
263 | struct rtas_update_flash_t *uf; | ||
264 | char *p; | ||
265 | int next_free; | ||
266 | struct flash_block_list *fl; | ||
267 | |||
268 | uf = (struct rtas_update_flash_t *) dp->data; | ||
269 | |||
270 | if (uf->status == FLASH_AUTH || count == 0) | ||
271 | return count; /* discard data */ | ||
272 | |||
273 | /* In the case that the image is not ready for flashing, the memory | ||
274 | * allocated for the block list will be freed upon the release of the | ||
275 | * proc file | ||
276 | */ | ||
277 | if (uf->flist == NULL) { | ||
278 | uf->flist = (struct flash_block_list *) get_zeroed_page(GFP_KERNEL); | ||
279 | if (!uf->flist) | ||
280 | return -ENOMEM; | ||
281 | } | ||
282 | |||
283 | fl = uf->flist; | ||
284 | while (fl->next) | ||
285 | fl = fl->next; /* seek to last block_list for append */ | ||
286 | next_free = fl->num_blocks; | ||
287 | if (next_free == FLASH_BLOCKS_PER_NODE) { | ||
288 | /* Need to allocate another block_list */ | ||
289 | fl->next = (struct flash_block_list *)get_zeroed_page(GFP_KERNEL); | ||
290 | if (!fl->next) | ||
291 | return -ENOMEM; | ||
292 | fl = fl->next; | ||
293 | next_free = 0; | ||
294 | } | ||
295 | |||
296 | if (count > PAGE_SIZE) | ||
297 | count = PAGE_SIZE; | ||
298 | p = (char *)get_zeroed_page(GFP_KERNEL); | ||
299 | if (!p) | ||
300 | return -ENOMEM; | ||
301 | |||
302 | if(copy_from_user(p, buffer, count)) { | ||
303 | free_page((unsigned long)p); | ||
304 | return -EFAULT; | ||
305 | } | ||
306 | fl->blocks[next_free].data = p; | ||
307 | fl->blocks[next_free].length = count; | ||
308 | fl->num_blocks++; | ||
309 | |||
310 | return count; | ||
311 | } | ||
312 | |||
313 | static int rtas_excl_open(struct inode *inode, struct file *file) | ||
314 | { | ||
315 | struct proc_dir_entry *dp = PDE(inode); | ||
316 | |||
317 | /* Enforce exclusive open with use count of PDE */ | ||
318 | spin_lock(&flash_file_open_lock); | ||
319 | if (atomic_read(&dp->count) > 1) { | ||
320 | spin_unlock(&flash_file_open_lock); | ||
321 | return -EBUSY; | ||
322 | } | ||
323 | |||
324 | atomic_inc(&dp->count); | ||
325 | spin_unlock(&flash_file_open_lock); | ||
326 | |||
327 | return 0; | ||
328 | } | ||
329 | |||
330 | static int rtas_excl_release(struct inode *inode, struct file *file) | ||
331 | { | ||
332 | struct proc_dir_entry *dp = PDE(inode); | ||
333 | |||
334 | atomic_dec(&dp->count); | ||
335 | |||
336 | return 0; | ||
337 | } | ||
338 | |||
339 | static void manage_flash(struct rtas_manage_flash_t *args_buf) | ||
340 | { | ||
341 | unsigned int wait_time; | ||
342 | s32 rc; | ||
343 | |||
344 | while (1) { | ||
345 | rc = rtas_call(rtas_token("ibm,manage-flash-image"), 1, | ||
346 | 1, NULL, args_buf->op); | ||
347 | if (rc == RTAS_RC_BUSY) | ||
348 | udelay(1); | ||
349 | else if (rtas_is_extended_busy(rc)) { | ||
350 | wait_time = rtas_extended_busy_delay_time(rc); | ||
351 | udelay(wait_time * 1000); | ||
352 | } else | ||
353 | break; | ||
354 | } | ||
355 | |||
356 | args_buf->status = rc; | ||
357 | } | ||
358 | |||
359 | static ssize_t manage_flash_read(struct file *file, char __user *buf, | ||
360 | size_t count, loff_t *ppos) | ||
361 | { | ||
362 | struct proc_dir_entry *dp = PDE(file->f_dentry->d_inode); | ||
363 | struct rtas_manage_flash_t *args_buf; | ||
364 | char msg[RTAS_MSG_MAXLEN]; | ||
365 | int msglen; | ||
366 | |||
367 | args_buf = (struct rtas_manage_flash_t *) dp->data; | ||
368 | if (args_buf == NULL) | ||
369 | return 0; | ||
370 | |||
371 | msglen = sprintf(msg, "%d\n", args_buf->status); | ||
372 | if (msglen > count) | ||
373 | msglen = count; | ||
374 | |||
375 | if (ppos && *ppos != 0) | ||
376 | return 0; /* be cheap */ | ||
377 | |||
378 | if (!access_ok(VERIFY_WRITE, buf, msglen)) | ||
379 | return -EINVAL; | ||
380 | |||
381 | if (copy_to_user(buf, msg, msglen)) | ||
382 | return -EFAULT; | ||
383 | |||
384 | if (ppos) | ||
385 | *ppos = msglen; | ||
386 | return msglen; | ||
387 | } | ||
388 | |||
389 | static ssize_t manage_flash_write(struct file *file, const char __user *buf, | ||
390 | size_t count, loff_t *off) | ||
391 | { | ||
392 | struct proc_dir_entry *dp = PDE(file->f_dentry->d_inode); | ||
393 | struct rtas_manage_flash_t *args_buf; | ||
394 | const char reject_str[] = "0"; | ||
395 | const char commit_str[] = "1"; | ||
396 | char stkbuf[10]; | ||
397 | int op; | ||
398 | |||
399 | args_buf = (struct rtas_manage_flash_t *) dp->data; | ||
400 | if ((args_buf->status == MANAGE_AUTH) || (count == 0)) | ||
401 | return count; | ||
402 | |||
403 | op = -1; | ||
404 | if (buf) { | ||
405 | if (count > 9) count = 9; | ||
406 | if (copy_from_user (stkbuf, buf, count)) { | ||
407 | return -EFAULT; | ||
408 | } | ||
409 | if (strncmp(stkbuf, reject_str, strlen(reject_str)) == 0) | ||
410 | op = RTAS_REJECT_TMP_IMG; | ||
411 | else if (strncmp(stkbuf, commit_str, strlen(commit_str)) == 0) | ||
412 | op = RTAS_COMMIT_TMP_IMG; | ||
413 | } | ||
414 | |||
415 | if (op == -1) /* buf is empty, or contains invalid string */ | ||
416 | return -EINVAL; | ||
417 | |||
418 | args_buf->op = op; | ||
419 | manage_flash(args_buf); | ||
420 | |||
421 | return count; | ||
422 | } | ||
423 | |||
424 | static void validate_flash(struct rtas_validate_flash_t *args_buf) | ||
425 | { | ||
426 | int token = rtas_token("ibm,validate-flash-image"); | ||
427 | unsigned int wait_time; | ||
428 | int update_results; | ||
429 | s32 rc; | ||
430 | |||
431 | rc = 0; | ||
432 | while(1) { | ||
433 | spin_lock(&rtas_data_buf_lock); | ||
434 | memcpy(rtas_data_buf, args_buf->buf, VALIDATE_BUF_SIZE); | ||
435 | rc = rtas_call(token, 2, 2, &update_results, | ||
436 | (u32) __pa(rtas_data_buf), args_buf->buf_size); | ||
437 | memcpy(args_buf->buf, rtas_data_buf, VALIDATE_BUF_SIZE); | ||
438 | spin_unlock(&rtas_data_buf_lock); | ||
439 | |||
440 | if (rc == RTAS_RC_BUSY) | ||
441 | udelay(1); | ||
442 | else if (rtas_is_extended_busy(rc)) { | ||
443 | wait_time = rtas_extended_busy_delay_time(rc); | ||
444 | udelay(wait_time * 1000); | ||
445 | } else | ||
446 | break; | ||
447 | } | ||
448 | |||
449 | args_buf->status = rc; | ||
450 | args_buf->update_results = update_results; | ||
451 | } | ||
452 | |||
453 | static int get_validate_flash_msg(struct rtas_validate_flash_t *args_buf, | ||
454 | char *msg) | ||
455 | { | ||
456 | int n; | ||
457 | |||
458 | if (args_buf->status >= VALIDATE_TMP_UPDATE) { | ||
459 | n = sprintf(msg, "%d\n", args_buf->update_results); | ||
460 | if ((args_buf->update_results >= VALIDATE_CUR_UNKNOWN) || | ||
461 | (args_buf->update_results == VALIDATE_TMP_UPDATE)) | ||
462 | n += sprintf(msg + n, "%s\n", args_buf->buf); | ||
463 | } else { | ||
464 | n = sprintf(msg, "%d\n", args_buf->status); | ||
465 | } | ||
466 | return n; | ||
467 | } | ||
468 | |||
469 | static ssize_t validate_flash_read(struct file *file, char __user *buf, | ||
470 | size_t count, loff_t *ppos) | ||
471 | { | ||
472 | struct proc_dir_entry *dp = PDE(file->f_dentry->d_inode); | ||
473 | struct rtas_validate_flash_t *args_buf; | ||
474 | char msg[RTAS_MSG_MAXLEN]; | ||
475 | int msglen; | ||
476 | |||
477 | args_buf = (struct rtas_validate_flash_t *) dp->data; | ||
478 | |||
479 | if (ppos && *ppos != 0) | ||
480 | return 0; /* be cheap */ | ||
481 | |||
482 | msglen = get_validate_flash_msg(args_buf, msg); | ||
483 | if (msglen > count) | ||
484 | msglen = count; | ||
485 | |||
486 | if (!access_ok(VERIFY_WRITE, buf, msglen)) | ||
487 | return -EINVAL; | ||
488 | |||
489 | if (copy_to_user(buf, msg, msglen)) | ||
490 | return -EFAULT; | ||
491 | |||
492 | if (ppos) | ||
493 | *ppos = msglen; | ||
494 | return msglen; | ||
495 | } | ||
496 | |||
497 | static ssize_t validate_flash_write(struct file *file, const char __user *buf, | ||
498 | size_t count, loff_t *off) | ||
499 | { | ||
500 | struct proc_dir_entry *dp = PDE(file->f_dentry->d_inode); | ||
501 | struct rtas_validate_flash_t *args_buf; | ||
502 | int rc; | ||
503 | |||
504 | args_buf = (struct rtas_validate_flash_t *) dp->data; | ||
505 | |||
506 | if (dp->data == NULL) { | ||
507 | dp->data = kmalloc(sizeof(struct rtas_validate_flash_t), | ||
508 | GFP_KERNEL); | ||
509 | if (dp->data == NULL) | ||
510 | return -ENOMEM; | ||
511 | } | ||
512 | |||
513 | /* We are only interested in the first 4K of the | ||
514 | * candidate image */ | ||
515 | if ((*off >= VALIDATE_BUF_SIZE) || | ||
516 | (args_buf->status == VALIDATE_AUTH)) { | ||
517 | *off += count; | ||
518 | return count; | ||
519 | } | ||
520 | |||
521 | if (*off + count >= VALIDATE_BUF_SIZE) { | ||
522 | count = VALIDATE_BUF_SIZE - *off; | ||
523 | args_buf->status = VALIDATE_READY; | ||
524 | } else { | ||
525 | args_buf->status = VALIDATE_INCOMPLETE; | ||
526 | } | ||
527 | |||
528 | if (!access_ok(VERIFY_READ, buf, count)) { | ||
529 | rc = -EFAULT; | ||
530 | goto done; | ||
531 | } | ||
532 | if (copy_from_user(args_buf->buf + *off, buf, count)) { | ||
533 | rc = -EFAULT; | ||
534 | goto done; | ||
535 | } | ||
536 | |||
537 | *off += count; | ||
538 | rc = count; | ||
539 | done: | ||
540 | if (rc < 0) { | ||
541 | kfree(dp->data); | ||
542 | dp->data = NULL; | ||
543 | } | ||
544 | return rc; | ||
545 | } | ||
546 | |||
547 | static int validate_flash_release(struct inode *inode, struct file *file) | ||
548 | { | ||
549 | struct proc_dir_entry *dp = PDE(file->f_dentry->d_inode); | ||
550 | struct rtas_validate_flash_t *args_buf; | ||
551 | |||
552 | args_buf = (struct rtas_validate_flash_t *) dp->data; | ||
553 | |||
554 | if (args_buf->status == VALIDATE_READY) { | ||
555 | args_buf->buf_size = VALIDATE_BUF_SIZE; | ||
556 | validate_flash(args_buf); | ||
557 | } | ||
558 | |||
559 | /* The matching atomic_inc was in rtas_excl_open() */ | ||
560 | atomic_dec(&dp->count); | ||
561 | |||
562 | return 0; | ||
563 | } | ||
564 | |||
565 | static void remove_flash_pde(struct proc_dir_entry *dp) | ||
566 | { | ||
567 | if (dp) { | ||
568 | if (dp->data != NULL) | ||
569 | kfree(dp->data); | ||
570 | dp->owner = NULL; | ||
571 | remove_proc_entry(dp->name, dp->parent); | ||
572 | } | ||
573 | } | ||
574 | |||
575 | static int initialize_flash_pde_data(const char *rtas_call_name, | ||
576 | size_t buf_size, | ||
577 | struct proc_dir_entry *dp) | ||
578 | { | ||
579 | int *status; | ||
580 | int token; | ||
581 | |||
582 | dp->data = kmalloc(buf_size, GFP_KERNEL); | ||
583 | if (dp->data == NULL) { | ||
584 | remove_flash_pde(dp); | ||
585 | return -ENOMEM; | ||
586 | } | ||
587 | |||
588 | memset(dp->data, 0, buf_size); | ||
589 | |||
590 | /* | ||
591 | * This code assumes that the status int is the first member of the | ||
592 | * struct | ||
593 | */ | ||
594 | status = (int *) dp->data; | ||
595 | token = rtas_token(rtas_call_name); | ||
596 | if (token == RTAS_UNKNOWN_SERVICE) | ||
597 | *status = FLASH_AUTH; | ||
598 | else | ||
599 | *status = FLASH_NO_OP; | ||
600 | |||
601 | return 0; | ||
602 | } | ||
603 | |||
604 | static struct proc_dir_entry *create_flash_pde(const char *filename, | ||
605 | struct file_operations *fops) | ||
606 | { | ||
607 | struct proc_dir_entry *ent = NULL; | ||
608 | |||
609 | ent = create_proc_entry(filename, S_IRUSR | S_IWUSR, NULL); | ||
610 | if (ent != NULL) { | ||
611 | ent->nlink = 1; | ||
612 | ent->proc_fops = fops; | ||
613 | ent->owner = THIS_MODULE; | ||
614 | } | ||
615 | |||
616 | return ent; | ||
617 | } | ||
618 | |||
619 | static struct file_operations rtas_flash_operations = { | ||
620 | .read = rtas_flash_read, | ||
621 | .write = rtas_flash_write, | ||
622 | .open = rtas_excl_open, | ||
623 | .release = rtas_flash_release, | ||
624 | }; | ||
625 | |||
626 | static struct file_operations manage_flash_operations = { | ||
627 | .read = manage_flash_read, | ||
628 | .write = manage_flash_write, | ||
629 | .open = rtas_excl_open, | ||
630 | .release = rtas_excl_release, | ||
631 | }; | ||
632 | |||
633 | static struct file_operations validate_flash_operations = { | ||
634 | .read = validate_flash_read, | ||
635 | .write = validate_flash_write, | ||
636 | .open = rtas_excl_open, | ||
637 | .release = validate_flash_release, | ||
638 | }; | ||
639 | |||
640 | int __init rtas_flash_init(void) | ||
641 | { | ||
642 | int rc; | ||
643 | |||
644 | if (rtas_token("ibm,update-flash-64-and-reboot") == | ||
645 | RTAS_UNKNOWN_SERVICE) { | ||
646 | printk(KERN_ERR "rtas_flash: no firmware flash support\n"); | ||
647 | return 1; | ||
648 | } | ||
649 | |||
650 | firmware_flash_pde = create_flash_pde("ppc64/rtas/" | ||
651 | FIRMWARE_FLASH_NAME, | ||
652 | &rtas_flash_operations); | ||
653 | if (firmware_flash_pde == NULL) { | ||
654 | rc = -ENOMEM; | ||
655 | goto cleanup; | ||
656 | } | ||
657 | |||
658 | rc = initialize_flash_pde_data("ibm,update-flash-64-and-reboot", | ||
659 | sizeof(struct rtas_update_flash_t), | ||
660 | firmware_flash_pde); | ||
661 | if (rc != 0) | ||
662 | goto cleanup; | ||
663 | |||
664 | firmware_update_pde = create_flash_pde("ppc64/rtas/" | ||
665 | FIRMWARE_UPDATE_NAME, | ||
666 | &rtas_flash_operations); | ||
667 | if (firmware_update_pde == NULL) { | ||
668 | rc = -ENOMEM; | ||
669 | goto cleanup; | ||
670 | } | ||
671 | |||
672 | rc = initialize_flash_pde_data("ibm,update-flash-64-and-reboot", | ||
673 | sizeof(struct rtas_update_flash_t), | ||
674 | firmware_update_pde); | ||
675 | if (rc != 0) | ||
676 | goto cleanup; | ||
677 | |||
678 | validate_pde = create_flash_pde("ppc64/rtas/" VALIDATE_FLASH_NAME, | ||
679 | &validate_flash_operations); | ||
680 | if (validate_pde == NULL) { | ||
681 | rc = -ENOMEM; | ||
682 | goto cleanup; | ||
683 | } | ||
684 | |||
685 | rc = initialize_flash_pde_data("ibm,validate-flash-image", | ||
686 | sizeof(struct rtas_validate_flash_t), | ||
687 | validate_pde); | ||
688 | if (rc != 0) | ||
689 | goto cleanup; | ||
690 | |||
691 | manage_pde = create_flash_pde("ppc64/rtas/" MANAGE_FLASH_NAME, | ||
692 | &manage_flash_operations); | ||
693 | if (manage_pde == NULL) { | ||
694 | rc = -ENOMEM; | ||
695 | goto cleanup; | ||
696 | } | ||
697 | |||
698 | rc = initialize_flash_pde_data("ibm,manage-flash-image", | ||
699 | sizeof(struct rtas_manage_flash_t), | ||
700 | manage_pde); | ||
701 | if (rc != 0) | ||
702 | goto cleanup; | ||
703 | |||
704 | return 0; | ||
705 | |||
706 | cleanup: | ||
707 | remove_flash_pde(firmware_flash_pde); | ||
708 | remove_flash_pde(firmware_update_pde); | ||
709 | remove_flash_pde(validate_pde); | ||
710 | remove_flash_pde(manage_pde); | ||
711 | |||
712 | return rc; | ||
713 | } | ||
714 | |||
715 | void __exit rtas_flash_cleanup(void) | ||
716 | { | ||
717 | remove_flash_pde(firmware_flash_pde); | ||
718 | remove_flash_pde(firmware_update_pde); | ||
719 | remove_flash_pde(validate_pde); | ||
720 | remove_flash_pde(manage_pde); | ||
721 | } | ||
722 | |||
723 | module_init(rtas_flash_init); | ||
724 | module_exit(rtas_flash_cleanup); | ||
725 | MODULE_LICENSE("GPL"); | ||
diff --git a/arch/ppc64/kernel/rtasd.c b/arch/ppc64/kernel/rtasd.c deleted file mode 100644 index e26b0420b6dd..000000000000 --- a/arch/ppc64/kernel/rtasd.c +++ /dev/null | |||
@@ -1,527 +0,0 @@ | |||
1 | /* | ||
2 | * Copyright (C) 2001 Anton Blanchard <anton@au.ibm.com>, IBM | ||
3 | * | ||
4 | * This program is free software; you can redistribute it and/or | ||
5 | * modify it under the terms of the GNU General Public License | ||
6 | * as published by the Free Software Foundation; either version | ||
7 | * 2 of the License, or (at your option) any later version. | ||
8 | * | ||
9 | * Communication to userspace based on kernel/printk.c | ||
10 | */ | ||
11 | |||
12 | #include <linux/types.h> | ||
13 | #include <linux/errno.h> | ||
14 | #include <linux/sched.h> | ||
15 | #include <linux/kernel.h> | ||
16 | #include <linux/poll.h> | ||
17 | #include <linux/proc_fs.h> | ||
18 | #include <linux/init.h> | ||
19 | #include <linux/vmalloc.h> | ||
20 | #include <linux/spinlock.h> | ||
21 | #include <linux/cpu.h> | ||
22 | #include <linux/delay.h> | ||
23 | |||
24 | #include <asm/uaccess.h> | ||
25 | #include <asm/io.h> | ||
26 | #include <asm/rtas.h> | ||
27 | #include <asm/prom.h> | ||
28 | #include <asm/nvram.h> | ||
29 | #include <asm/atomic.h> | ||
30 | #include <asm/systemcfg.h> | ||
31 | |||
32 | #if 0 | ||
33 | #define DEBUG(A...) printk(KERN_ERR A) | ||
34 | #else | ||
35 | #define DEBUG(A...) | ||
36 | #endif | ||
37 | |||
38 | static DEFINE_SPINLOCK(rtasd_log_lock); | ||
39 | |||
40 | DECLARE_WAIT_QUEUE_HEAD(rtas_log_wait); | ||
41 | |||
42 | static char *rtas_log_buf; | ||
43 | static unsigned long rtas_log_start; | ||
44 | static unsigned long rtas_log_size; | ||
45 | |||
46 | static int surveillance_timeout = -1; | ||
47 | static unsigned int rtas_event_scan_rate; | ||
48 | static unsigned int rtas_error_log_max; | ||
49 | static unsigned int rtas_error_log_buffer_max; | ||
50 | |||
51 | static int full_rtas_msgs = 0; | ||
52 | |||
53 | extern int no_logging; | ||
54 | |||
55 | volatile int error_log_cnt = 0; | ||
56 | |||
57 | /* | ||
58 | * Since we use 32 bit RTAS, the physical address of this must be below | ||
59 | * 4G or else bad things happen. Allocate this in the kernel data and | ||
60 | * make it big enough. | ||
61 | */ | ||
62 | static unsigned char logdata[RTAS_ERROR_LOG_MAX]; | ||
63 | |||
64 | static int get_eventscan_parms(void); | ||
65 | |||
66 | static char *rtas_type[] = { | ||
67 | "Unknown", "Retry", "TCE Error", "Internal Device Failure", | ||
68 | "Timeout", "Data Parity", "Address Parity", "Cache Parity", | ||
69 | "Address Invalid", "ECC Uncorrected", "ECC Corrupted", | ||
70 | }; | ||
71 | |||
72 | static char *rtas_event_type(int type) | ||
73 | { | ||
74 | if ((type > 0) && (type < 11)) | ||
75 | return rtas_type[type]; | ||
76 | |||
77 | switch (type) { | ||
78 | case RTAS_TYPE_EPOW: | ||
79 | return "EPOW"; | ||
80 | case RTAS_TYPE_PLATFORM: | ||
81 | return "Platform Error"; | ||
82 | case RTAS_TYPE_IO: | ||
83 | return "I/O Event"; | ||
84 | case RTAS_TYPE_INFO: | ||
85 | return "Platform Information Event"; | ||
86 | case RTAS_TYPE_DEALLOC: | ||
87 | return "Resource Deallocation Event"; | ||
88 | case RTAS_TYPE_DUMP: | ||
89 | return "Dump Notification Event"; | ||
90 | } | ||
91 | |||
92 | return rtas_type[0]; | ||
93 | } | ||
94 | |||
95 | /* To see this info, grep RTAS /var/log/messages and each entry | ||
96 | * will be collected together with obvious begin/end. | ||
97 | * There will be a unique identifier on the begin and end lines. | ||
98 | * This will persist across reboots. | ||
99 | * | ||
100 | * format of error logs returned from RTAS: | ||
101 | * bytes (size) : contents | ||
102 | * -------------------------------------------------------- | ||
103 | * 0-7 (8) : rtas_error_log | ||
104 | * 8-47 (40) : extended info | ||
105 | * 48-51 (4) : vendor id | ||
106 | * 52-1023 (vendor specific) : location code and debug data | ||
107 | */ | ||
108 | static void printk_log_rtas(char *buf, int len) | ||
109 | { | ||
110 | |||
111 | int i,j,n = 0; | ||
112 | int perline = 16; | ||
113 | char buffer[64]; | ||
114 | char * str = "RTAS event"; | ||
115 | |||
116 | if (full_rtas_msgs) { | ||
117 | printk(RTAS_DEBUG "%d -------- %s begin --------\n", | ||
118 | error_log_cnt, str); | ||
119 | |||
120 | /* | ||
121 | * Print perline bytes on each line, each line will start | ||
122 | * with RTAS and a changing number, so syslogd will | ||
123 | * print lines that are otherwise the same. Separate every | ||
124 | * 4 bytes with a space. | ||
125 | */ | ||
126 | for (i = 0; i < len; i++) { | ||
127 | j = i % perline; | ||
128 | if (j == 0) { | ||
129 | memset(buffer, 0, sizeof(buffer)); | ||
130 | n = sprintf(buffer, "RTAS %d:", i/perline); | ||
131 | } | ||
132 | |||
133 | if ((i % 4) == 0) | ||
134 | n += sprintf(buffer+n, " "); | ||
135 | |||
136 | n += sprintf(buffer+n, "%02x", (unsigned char)buf[i]); | ||
137 | |||
138 | if (j == (perline-1)) | ||
139 | printk(KERN_DEBUG "%s\n", buffer); | ||
140 | } | ||
141 | if ((i % perline) != 0) | ||
142 | printk(KERN_DEBUG "%s\n", buffer); | ||
143 | |||
144 | printk(RTAS_DEBUG "%d -------- %s end ----------\n", | ||
145 | error_log_cnt, str); | ||
146 | } else { | ||
147 | struct rtas_error_log *errlog = (struct rtas_error_log *)buf; | ||
148 | |||
149 | printk(RTAS_DEBUG "event: %d, Type: %s, Severity: %d\n", | ||
150 | error_log_cnt, rtas_event_type(errlog->type), | ||
151 | errlog->severity); | ||
152 | } | ||
153 | } | ||
154 | |||
155 | static int log_rtas_len(char * buf) | ||
156 | { | ||
157 | int len; | ||
158 | struct rtas_error_log *err; | ||
159 | |||
160 | /* rtas fixed header */ | ||
161 | len = 8; | ||
162 | err = (struct rtas_error_log *)buf; | ||
163 | if (err->extended_log_length) { | ||
164 | |||
165 | /* extended header */ | ||
166 | len += err->extended_log_length; | ||
167 | } | ||
168 | |||
169 | if (rtas_error_log_max == 0) { | ||
170 | get_eventscan_parms(); | ||
171 | } | ||
172 | if (len > rtas_error_log_max) | ||
173 | len = rtas_error_log_max; | ||
174 | |||
175 | return len; | ||
176 | } | ||
177 | |||
178 | /* | ||
179 | * First write to nvram, if fatal error, that is the only | ||
180 | * place we log the info. The error will be picked up | ||
181 | * on the next reboot by rtasd. If not fatal, run the | ||
182 | * method for the type of error. Currently, only RTAS | ||
183 | * errors have methods implemented, but in the future | ||
184 | * there might be a need to store data in nvram before a | ||
185 | * call to panic(). | ||
186 | * | ||
187 | * XXX We write to nvram periodically, to indicate error has | ||
188 | * been written and sync'd, but there is a possibility | ||
189 | * that if we don't shutdown correctly, a duplicate error | ||
190 | * record will be created on next reboot. | ||
191 | */ | ||
192 | void pSeries_log_error(char *buf, unsigned int err_type, int fatal) | ||
193 | { | ||
194 | unsigned long offset; | ||
195 | unsigned long s; | ||
196 | int len = 0; | ||
197 | |||
198 | DEBUG("logging event\n"); | ||
199 | if (buf == NULL) | ||
200 | return; | ||
201 | |||
202 | spin_lock_irqsave(&rtasd_log_lock, s); | ||
203 | |||
204 | /* get length and increase count */ | ||
205 | switch (err_type & ERR_TYPE_MASK) { | ||
206 | case ERR_TYPE_RTAS_LOG: | ||
207 | len = log_rtas_len(buf); | ||
208 | if (!(err_type & ERR_FLAG_BOOT)) | ||
209 | error_log_cnt++; | ||
210 | break; | ||
211 | case ERR_TYPE_KERNEL_PANIC: | ||
212 | default: | ||
213 | spin_unlock_irqrestore(&rtasd_log_lock, s); | ||
214 | return; | ||
215 | } | ||
216 | |||
217 | /* Write error to NVRAM */ | ||
218 | if (!no_logging && !(err_type & ERR_FLAG_BOOT)) | ||
219 | nvram_write_error_log(buf, len, err_type); | ||
220 | |||
221 | /* | ||
222 | * rtas errors can occur during boot, and we do want to capture | ||
223 | * those somewhere, even if nvram isn't ready (why not?), and even | ||
224 | * if rtasd isn't ready. Put them into the boot log, at least. | ||
225 | */ | ||
226 | if ((err_type & ERR_TYPE_MASK) == ERR_TYPE_RTAS_LOG) | ||
227 | printk_log_rtas(buf, len); | ||
228 | |||
229 | /* Check to see if we need to or have stopped logging */ | ||
230 | if (fatal || no_logging) { | ||
231 | no_logging = 1; | ||
232 | spin_unlock_irqrestore(&rtasd_log_lock, s); | ||
233 | return; | ||
234 | } | ||
235 | |||
236 | /* call type specific method for error */ | ||
237 | switch (err_type & ERR_TYPE_MASK) { | ||
238 | case ERR_TYPE_RTAS_LOG: | ||
239 | offset = rtas_error_log_buffer_max * | ||
240 | ((rtas_log_start+rtas_log_size) & LOG_NUMBER_MASK); | ||
241 | |||
242 | /* First copy over sequence number */ | ||
243 | memcpy(&rtas_log_buf[offset], (void *) &error_log_cnt, sizeof(int)); | ||
244 | |||
245 | /* Second copy over error log data */ | ||
246 | offset += sizeof(int); | ||
247 | memcpy(&rtas_log_buf[offset], buf, len); | ||
248 | |||
249 | if (rtas_log_size < LOG_NUMBER) | ||
250 | rtas_log_size += 1; | ||
251 | else | ||
252 | rtas_log_start += 1; | ||
253 | |||
254 | spin_unlock_irqrestore(&rtasd_log_lock, s); | ||
255 | wake_up_interruptible(&rtas_log_wait); | ||
256 | break; | ||
257 | case ERR_TYPE_KERNEL_PANIC: | ||
258 | default: | ||
259 | spin_unlock_irqrestore(&rtasd_log_lock, s); | ||
260 | return; | ||
261 | } | ||
262 | |||
263 | } | ||
264 | |||
265 | |||
266 | static int rtas_log_open(struct inode * inode, struct file * file) | ||
267 | { | ||
268 | return 0; | ||
269 | } | ||
270 | |||
271 | static int rtas_log_release(struct inode * inode, struct file * file) | ||
272 | { | ||
273 | return 0; | ||
274 | } | ||
275 | |||
276 | /* This will check if all events are logged, if they are then, we | ||
277 | * know that we can safely clear the events in NVRAM. | ||
278 | * Next we'll sit and wait for something else to log. | ||
279 | */ | ||
280 | static ssize_t rtas_log_read(struct file * file, char __user * buf, | ||
281 | size_t count, loff_t *ppos) | ||
282 | { | ||
283 | int error; | ||
284 | char *tmp; | ||
285 | unsigned long s; | ||
286 | unsigned long offset; | ||
287 | |||
288 | if (!buf || count < rtas_error_log_buffer_max) | ||
289 | return -EINVAL; | ||
290 | |||
291 | count = rtas_error_log_buffer_max; | ||
292 | |||
293 | if (!access_ok(VERIFY_WRITE, buf, count)) | ||
294 | return -EFAULT; | ||
295 | |||
296 | tmp = kmalloc(count, GFP_KERNEL); | ||
297 | if (!tmp) | ||
298 | return -ENOMEM; | ||
299 | |||
300 | |||
301 | spin_lock_irqsave(&rtasd_log_lock, s); | ||
302 | /* if it's 0, then we know we got the last one (the one in NVRAM) */ | ||
303 | if (rtas_log_size == 0 && !no_logging) | ||
304 | nvram_clear_error_log(); | ||
305 | spin_unlock_irqrestore(&rtasd_log_lock, s); | ||
306 | |||
307 | |||
308 | error = wait_event_interruptible(rtas_log_wait, rtas_log_size); | ||
309 | if (error) | ||
310 | goto out; | ||
311 | |||
312 | spin_lock_irqsave(&rtasd_log_lock, s); | ||
313 | offset = rtas_error_log_buffer_max * (rtas_log_start & LOG_NUMBER_MASK); | ||
314 | memcpy(tmp, &rtas_log_buf[offset], count); | ||
315 | |||
316 | rtas_log_start += 1; | ||
317 | rtas_log_size -= 1; | ||
318 | spin_unlock_irqrestore(&rtasd_log_lock, s); | ||
319 | |||
320 | error = copy_to_user(buf, tmp, count) ? -EFAULT : count; | ||
321 | out: | ||
322 | kfree(tmp); | ||
323 | return error; | ||
324 | } | ||
325 | |||
326 | static unsigned int rtas_log_poll(struct file *file, poll_table * wait) | ||
327 | { | ||
328 | poll_wait(file, &rtas_log_wait, wait); | ||
329 | if (rtas_log_size) | ||
330 | return POLLIN | POLLRDNORM; | ||
331 | return 0; | ||
332 | } | ||
333 | |||
334 | struct file_operations proc_rtas_log_operations = { | ||
335 | .read = rtas_log_read, | ||
336 | .poll = rtas_log_poll, | ||
337 | .open = rtas_log_open, | ||
338 | .release = rtas_log_release, | ||
339 | }; | ||
340 | |||
341 | static int enable_surveillance(int timeout) | ||
342 | { | ||
343 | int error; | ||
344 | |||
345 | error = rtas_set_indicator(SURVEILLANCE_TOKEN, 0, timeout); | ||
346 | |||
347 | if (error == 0) | ||
348 | return 0; | ||
349 | |||
350 | if (error == -EINVAL) { | ||
351 | printk(KERN_INFO "rtasd: surveillance not supported\n"); | ||
352 | return 0; | ||
353 | } | ||
354 | |||
355 | printk(KERN_ERR "rtasd: could not update surveillance\n"); | ||
356 | return -1; | ||
357 | } | ||
358 | |||
359 | static int get_eventscan_parms(void) | ||
360 | { | ||
361 | struct device_node *node; | ||
362 | int *ip; | ||
363 | |||
364 | node = of_find_node_by_path("/rtas"); | ||
365 | |||
366 | ip = (int *)get_property(node, "rtas-event-scan-rate", NULL); | ||
367 | if (ip == NULL) { | ||
368 | printk(KERN_ERR "rtasd: no rtas-event-scan-rate\n"); | ||
369 | of_node_put(node); | ||
370 | return -1; | ||
371 | } | ||
372 | rtas_event_scan_rate = *ip; | ||
373 | DEBUG("rtas-event-scan-rate %d\n", rtas_event_scan_rate); | ||
374 | |||
375 | /* Make room for the sequence number */ | ||
376 | rtas_error_log_max = rtas_get_error_log_max(); | ||
377 | rtas_error_log_buffer_max = rtas_error_log_max + sizeof(int); | ||
378 | |||
379 | of_node_put(node); | ||
380 | |||
381 | return 0; | ||
382 | } | ||
383 | |||
384 | static void do_event_scan(int event_scan) | ||
385 | { | ||
386 | int error; | ||
387 | do { | ||
388 | memset(logdata, 0, rtas_error_log_max); | ||
389 | error = rtas_call(event_scan, 4, 1, NULL, | ||
390 | RTAS_EVENT_SCAN_ALL_EVENTS, 0, | ||
391 | __pa(logdata), rtas_error_log_max); | ||
392 | if (error == -1) { | ||
393 | printk(KERN_ERR "event-scan failed\n"); | ||
394 | break; | ||
395 | } | ||
396 | |||
397 | if (error == 0) | ||
398 | pSeries_log_error(logdata, ERR_TYPE_RTAS_LOG, 0); | ||
399 | |||
400 | } while(error == 0); | ||
401 | } | ||
402 | |||
403 | static void do_event_scan_all_cpus(long delay) | ||
404 | { | ||
405 | int cpu; | ||
406 | |||
407 | lock_cpu_hotplug(); | ||
408 | cpu = first_cpu(cpu_online_map); | ||
409 | for (;;) { | ||
410 | set_cpus_allowed(current, cpumask_of_cpu(cpu)); | ||
411 | do_event_scan(rtas_token("event-scan")); | ||
412 | set_cpus_allowed(current, CPU_MASK_ALL); | ||
413 | |||
414 | /* Drop hotplug lock, and sleep for the specified delay */ | ||
415 | unlock_cpu_hotplug(); | ||
416 | msleep_interruptible(delay); | ||
417 | lock_cpu_hotplug(); | ||
418 | |||
419 | cpu = next_cpu(cpu, cpu_online_map); | ||
420 | if (cpu == NR_CPUS) | ||
421 | break; | ||
422 | } | ||
423 | unlock_cpu_hotplug(); | ||
424 | } | ||
425 | |||
426 | static int rtasd(void *unused) | ||
427 | { | ||
428 | unsigned int err_type; | ||
429 | int event_scan = rtas_token("event-scan"); | ||
430 | int rc; | ||
431 | |||
432 | daemonize("rtasd"); | ||
433 | |||
434 | if (event_scan == RTAS_UNKNOWN_SERVICE || get_eventscan_parms() == -1) | ||
435 | goto error; | ||
436 | |||
437 | rtas_log_buf = vmalloc(rtas_error_log_buffer_max*LOG_NUMBER); | ||
438 | if (!rtas_log_buf) { | ||
439 | printk(KERN_ERR "rtasd: no memory\n"); | ||
440 | goto error; | ||
441 | } | ||
442 | |||
443 | printk(KERN_INFO "RTAS daemon started\n"); | ||
444 | |||
445 | DEBUG("will sleep for %d milliseconds\n", (30000/rtas_event_scan_rate)); | ||
446 | |||
447 | /* See if we have any error stored in NVRAM */ | ||
448 | memset(logdata, 0, rtas_error_log_max); | ||
449 | |||
450 | rc = nvram_read_error_log(logdata, rtas_error_log_max, &err_type); | ||
451 | |||
452 | /* We can use rtas_log_buf now */ | ||
453 | no_logging = 0; | ||
454 | |||
455 | if (!rc) { | ||
456 | if (err_type != ERR_FLAG_ALREADY_LOGGED) { | ||
457 | pSeries_log_error(logdata, err_type | ERR_FLAG_BOOT, 0); | ||
458 | } | ||
459 | } | ||
460 | |||
461 | /* First pass. */ | ||
462 | do_event_scan_all_cpus(1000); | ||
463 | |||
464 | if (surveillance_timeout != -1) { | ||
465 | DEBUG("enabling surveillance\n"); | ||
466 | enable_surveillance(surveillance_timeout); | ||
467 | DEBUG("surveillance enabled\n"); | ||
468 | } | ||
469 | |||
470 | /* Delay should be at least one second since some | ||
471 | * machines have problems if we call event-scan too | ||
472 | * quickly. */ | ||
473 | for (;;) | ||
474 | do_event_scan_all_cpus(30000/rtas_event_scan_rate); | ||
475 | |||
476 | error: | ||
477 | /* Should delete proc entries */ | ||
478 | return -EINVAL; | ||
479 | } | ||
480 | |||
481 | static int __init rtas_init(void) | ||
482 | { | ||
483 | struct proc_dir_entry *entry; | ||
484 | |||
485 | /* No RTAS, only warn if we are on a pSeries box */ | ||
486 | if (rtas_token("event-scan") == RTAS_UNKNOWN_SERVICE) { | ||
487 | if (systemcfg->platform & PLATFORM_PSERIES) | ||
488 | printk(KERN_INFO "rtasd: no event-scan on system\n"); | ||
489 | return 1; | ||
490 | } | ||
491 | |||
492 | entry = create_proc_entry("ppc64/rtas/error_log", S_IRUSR, NULL); | ||
493 | if (entry) | ||
494 | entry->proc_fops = &proc_rtas_log_operations; | ||
495 | else | ||
496 | printk(KERN_ERR "Failed to create error_log proc entry\n"); | ||
497 | |||
498 | if (kernel_thread(rtasd, NULL, CLONE_FS) < 0) | ||
499 | printk(KERN_ERR "Failed to start RTAS daemon\n"); | ||
500 | |||
501 | return 0; | ||
502 | } | ||
503 | |||
504 | static int __init surveillance_setup(char *str) | ||
505 | { | ||
506 | int i; | ||
507 | |||
508 | if (get_option(&str,&i)) { | ||
509 | if (i >= 0 && i <= 255) | ||
510 | surveillance_timeout = i; | ||
511 | } | ||
512 | |||
513 | return 1; | ||
514 | } | ||
515 | |||
516 | static int __init rtasmsgs_setup(char *str) | ||
517 | { | ||
518 | if (strcmp(str, "on") == 0) | ||
519 | full_rtas_msgs = 1; | ||
520 | else if (strcmp(str, "off") == 0) | ||
521 | full_rtas_msgs = 0; | ||
522 | |||
523 | return 1; | ||
524 | } | ||
525 | __initcall(rtas_init); | ||
526 | __setup("surveillance=", surveillance_setup); | ||
527 | __setup("rtasmsgs=", rtasmsgs_setup); | ||