blob: e63b8ca5344a202d85b8cb1d25a4edb08c486894 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * salinfo.c
3 *
4 * Creates entries in /proc/sal for various system features.
5 *
Keith Owense026cca2006-01-06 10:36:06 +11006 * Copyright (c) 2003, 2006 Silicon Graphics, Inc. All rights reserved.
Linus Torvalds1da177e2005-04-16 15:20:36 -07007 * Copyright (c) 2003 Hewlett-Packard Co
8 * Bjorn Helgaas <bjorn.helgaas@hp.com>
9 *
10 * 10/30/2001 jbarnes@sgi.com copied much of Stephane's palinfo
11 * code to create this file
12 * Oct 23 2003 kaos@sgi.com
13 * Replace IPI with set_cpus_allowed() to read a record from the required cpu.
14 * Redesign salinfo log processing to separate interrupt and user space
15 * contexts.
16 * Cache the record across multi-block reads from user space.
17 * Support > 64 cpus.
18 * Delete module_exit and MOD_INC/DEC_COUNT, salinfo cannot be a module.
19 *
20 * Jan 28 2004 kaos@sgi.com
21 * Periodically check for outstanding MCA or INIT records.
22 *
23 * Dec 5 2004 kaos@sgi.com
24 * Standardize which records are cleared automatically.
Keith Owens289d7732005-09-11 17:21:46 +100025 *
26 * Aug 18 2005 kaos@sgi.com
27 * mca.c may not pass a buffer, a NULL buffer just indicates that a new
28 * record is available in SAL.
29 * Replace some NR_CPUS by cpus_online, for hotplug cpu.
Keith Owense026cca2006-01-06 10:36:06 +110030 *
31 * Jan 5 2006 kaos@sgi.com
32 * Handle hotplug cpus coming online.
33 * Handle hotplug cpus going offline while they still have outstanding records.
34 * Use the cpu_* macros consistently.
35 * Replace the counting semaphore with a mutex and a test if the cpumask is non-empty.
36 * Modify the locking to make the test for "work to do" an atomic operation.
Linus Torvalds1da177e2005-04-16 15:20:36 -070037 */
38
Randy Dunlapa9415642006-01-11 12:17:48 -080039#include <linux/capability.h>
Keith Owense026cca2006-01-06 10:36:06 +110040#include <linux/cpu.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070041#include <linux/types.h>
42#include <linux/proc_fs.h>
43#include <linux/module.h>
44#include <linux/smp.h>
45#include <linux/smp_lock.h>
46#include <linux/timer.h>
47#include <linux/vmalloc.h>
48
49#include <asm/semaphore.h>
50#include <asm/sal.h>
51#include <asm/uaccess.h>
52
53MODULE_AUTHOR("Jesse Barnes <jbarnes@sgi.com>");
54MODULE_DESCRIPTION("/proc interface to IA-64 SAL features");
55MODULE_LICENSE("GPL");
56
57static int salinfo_read(char *page, char **start, off_t off, int count, int *eof, void *data);
58
59typedef struct {
60 const char *name; /* name of the proc entry */
61 unsigned long feature; /* feature bit */
62 struct proc_dir_entry *entry; /* registered entry (removal) */
63} salinfo_entry_t;
64
65/*
66 * List {name,feature} pairs for every entry in /proc/sal/<feature>
67 * that this module exports
68 */
69static salinfo_entry_t salinfo_entries[]={
70 { "bus_lock", IA64_SAL_PLATFORM_FEATURE_BUS_LOCK, },
71 { "irq_redirection", IA64_SAL_PLATFORM_FEATURE_IRQ_REDIR_HINT, },
72 { "ipi_redirection", IA64_SAL_PLATFORM_FEATURE_IPI_REDIR_HINT, },
73 { "itc_drift", IA64_SAL_PLATFORM_FEATURE_ITC_DRIFT, },
74};
75
76#define NR_SALINFO_ENTRIES ARRAY_SIZE(salinfo_entries)
77
78static char *salinfo_log_name[] = {
79 "mca",
80 "init",
81 "cmc",
82 "cpe",
83};
84
85static struct proc_dir_entry *salinfo_proc_entries[
86 ARRAY_SIZE(salinfo_entries) + /* /proc/sal/bus_lock */
87 ARRAY_SIZE(salinfo_log_name) + /* /proc/sal/{mca,...} */
88 (2 * ARRAY_SIZE(salinfo_log_name)) + /* /proc/sal/mca/{event,data} */
89 1]; /* /proc/sal */
90
91/* Some records we get ourselves, some are accessed as saved data in buffers
92 * that are owned by mca.c.
93 */
94struct salinfo_data_saved {
95 u8* buffer;
96 u64 size;
97 u64 id;
98 int cpu;
99};
100
101/* State transitions. Actions are :-
102 * Write "read <cpunum>" to the data file.
103 * Write "clear <cpunum>" to the data file.
104 * Write "oemdata <cpunum> <offset> to the data file.
105 * Read from the data file.
106 * Close the data file.
107 *
108 * Start state is NO_DATA.
109 *
110 * NO_DATA
111 * write "read <cpunum>" -> NO_DATA or LOG_RECORD.
112 * write "clear <cpunum>" -> NO_DATA or LOG_RECORD.
113 * write "oemdata <cpunum> <offset> -> return -EINVAL.
114 * read data -> return EOF.
115 * close -> unchanged. Free record areas.
116 *
117 * LOG_RECORD
118 * write "read <cpunum>" -> NO_DATA or LOG_RECORD.
119 * write "clear <cpunum>" -> NO_DATA or LOG_RECORD.
120 * write "oemdata <cpunum> <offset> -> format the oem data, goto OEMDATA.
121 * read data -> return the INIT/MCA/CMC/CPE record.
122 * close -> unchanged. Keep record areas.
123 *
124 * OEMDATA
125 * write "read <cpunum>" -> NO_DATA or LOG_RECORD.
126 * write "clear <cpunum>" -> NO_DATA or LOG_RECORD.
127 * write "oemdata <cpunum> <offset> -> format the oem data, goto OEMDATA.
128 * read data -> return the formatted oemdata.
129 * close -> unchanged. Keep record areas.
130 *
131 * Closing the data file does not change the state. This allows shell scripts
132 * to manipulate salinfo data, each shell redirection opens the file, does one
133 * action then closes it again. The record areas are only freed at close when
134 * the state is NO_DATA.
135 */
136enum salinfo_state {
137 STATE_NO_DATA,
138 STATE_LOG_RECORD,
139 STATE_OEMDATA,
140};
141
142struct salinfo_data {
Keith Owense026cca2006-01-06 10:36:06 +1100143 cpumask_t cpu_event; /* which cpus have outstanding events */
144 struct semaphore mutex;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700145 u8 *log_buffer;
146 u64 log_size;
147 u8 *oemdata; /* decoded oem data */
148 u64 oemdata_size;
149 int open; /* single-open to prevent races */
150 u8 type;
151 u8 saved_num; /* using a saved record? */
152 enum salinfo_state state :8; /* processing state */
153 u8 padding;
154 int cpu_check; /* next CPU to check */
155 struct salinfo_data_saved data_saved[5];/* save last 5 records from mca.c, must be < 255 */
156};
157
158static struct salinfo_data salinfo_data[ARRAY_SIZE(salinfo_log_name)];
159
Keith Owens71841b82005-07-30 17:52:00 -0700160static DEFINE_SPINLOCK(data_lock);
161static DEFINE_SPINLOCK(data_saved_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700162
163/** salinfo_platform_oemdata - optional callback to decode oemdata from an error
164 * record.
165 * @sect_header: pointer to the start of the section to decode.
166 * @oemdata: returns vmalloc area containing the decded output.
167 * @oemdata_size: returns length of decoded output (strlen).
168 *
169 * Description: If user space asks for oem data to be decoded by the kernel
170 * and/or prom and the platform has set salinfo_platform_oemdata to the address
171 * of a platform specific routine then call that routine. salinfo_platform_oemdata
172 * vmalloc's and formats its output area, returning the address of the text
173 * and its strlen. Returns 0 for success, -ve for error. The callback is
174 * invoked on the cpu that generated the error record.
175 */
176int (*salinfo_platform_oemdata)(const u8 *sect_header, u8 **oemdata, u64 *oemdata_size);
177
178struct salinfo_platform_oemdata_parms {
179 const u8 *efi_guid;
180 u8 **oemdata;
181 u64 *oemdata_size;
182 int ret;
183};
184
Keith Owense026cca2006-01-06 10:36:06 +1100185/* Kick the mutex that tells user space that there is work to do. Instead of
186 * trying to track the state of the mutex across multiple cpus, in user
187 * context, interrupt context, non-maskable interrupt context and hotplug cpu,
188 * it is far easier just to grab the mutex if it is free then release it.
189 *
190 * This routine must be called with data_saved_lock held, to make the down/up
191 * operation atomic.
192 */
193static void
194salinfo_work_to_do(struct salinfo_data *data)
195{
196 down_trylock(&data->mutex);
197 up(&data->mutex);
198}
199
Linus Torvalds1da177e2005-04-16 15:20:36 -0700200static void
201salinfo_platform_oemdata_cpu(void *context)
202{
203 struct salinfo_platform_oemdata_parms *parms = context;
204 parms->ret = salinfo_platform_oemdata(parms->efi_guid, parms->oemdata, parms->oemdata_size);
205}
206
207static void
208shift1_data_saved (struct salinfo_data *data, int shift)
209{
210 memcpy(data->data_saved+shift, data->data_saved+shift+1,
211 (ARRAY_SIZE(data->data_saved) - (shift+1)) * sizeof(data->data_saved[0]));
212 memset(data->data_saved + ARRAY_SIZE(data->data_saved) - 1, 0,
213 sizeof(data->data_saved[0]));
214}
215
216/* This routine is invoked in interrupt context. Note: mca.c enables
217 * interrupts before calling this code for CMC/CPE. MCA and INIT events are
218 * not irq safe, do not call any routines that use spinlocks, they may deadlock.
219 * MCA and INIT records are recorded, a timer event will look for any
220 * outstanding events and wake up the user space code.
221 *
222 * The buffer passed from mca.c points to the output from ia64_log_get. This is
223 * a persistent buffer but its contents can change between the interrupt and
224 * when user space processes the record. Save the record id to identify
Keith Owens289d7732005-09-11 17:21:46 +1000225 * changes. If the buffer is NULL then just update the bitmap.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700226 */
227void
228salinfo_log_wakeup(int type, u8 *buffer, u64 size, int irqsafe)
229{
230 struct salinfo_data *data = salinfo_data + type;
231 struct salinfo_data_saved *data_saved;
232 unsigned long flags = 0;
233 int i;
234 int saved_size = ARRAY_SIZE(data->data_saved);
235
236 BUG_ON(type >= ARRAY_SIZE(salinfo_log_name));
237
Keith Owense026cca2006-01-06 10:36:06 +1100238 if (irqsafe)
239 spin_lock_irqsave(&data_saved_lock, flags);
Keith Owens289d7732005-09-11 17:21:46 +1000240 if (buffer) {
Keith Owens289d7732005-09-11 17:21:46 +1000241 for (i = 0, data_saved = data->data_saved; i < saved_size; ++i, ++data_saved) {
242 if (!data_saved->buffer)
243 break;
244 }
245 if (i == saved_size) {
246 if (!data->saved_num) {
247 shift1_data_saved(data, 0);
248 data_saved = data->data_saved + saved_size - 1;
249 } else
250 data_saved = NULL;
251 }
252 if (data_saved) {
253 data_saved->cpu = smp_processor_id();
254 data_saved->id = ((sal_log_record_header_t *)buffer)->id;
255 data_saved->size = size;
256 data_saved->buffer = buffer;
257 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700258 }
Keith Owense026cca2006-01-06 10:36:06 +1100259 cpu_set(smp_processor_id(), data->cpu_event);
260 if (irqsafe) {
261 salinfo_work_to_do(data);
262 spin_unlock_irqrestore(&data_saved_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700263 }
264}
265
266/* Check for outstanding MCA/INIT records every minute (arbitrary) */
267#define SALINFO_TIMER_DELAY (60*HZ)
268static struct timer_list salinfo_timer;
Hidetoshi Seto43ed3ba2006-09-26 14:44:37 -0700269extern void ia64_mlogbuf_dump(void);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700270
271static void
272salinfo_timeout_check(struct salinfo_data *data)
273{
Keith Owense026cca2006-01-06 10:36:06 +1100274 unsigned long flags;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700275 if (!data->open)
276 return;
Keith Owense026cca2006-01-06 10:36:06 +1100277 if (!cpus_empty(data->cpu_event)) {
278 spin_lock_irqsave(&data_saved_lock, flags);
279 salinfo_work_to_do(data);
280 spin_unlock_irqrestore(&data_saved_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700281 }
282}
283
Keith Owense026cca2006-01-06 10:36:06 +1100284static void
Linus Torvalds1da177e2005-04-16 15:20:36 -0700285salinfo_timeout (unsigned long arg)
286{
Hidetoshi Seto43ed3ba2006-09-26 14:44:37 -0700287 ia64_mlogbuf_dump();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700288 salinfo_timeout_check(salinfo_data + SAL_INFO_TYPE_MCA);
289 salinfo_timeout_check(salinfo_data + SAL_INFO_TYPE_INIT);
290 salinfo_timer.expires = jiffies + SALINFO_TIMER_DELAY;
291 add_timer(&salinfo_timer);
292}
293
294static int
295salinfo_event_open(struct inode *inode, struct file *file)
296{
297 if (!capable(CAP_SYS_ADMIN))
298 return -EPERM;
299 return 0;
300}
301
302static ssize_t
303salinfo_event_read(struct file *file, char __user *buffer, size_t count, loff_t *ppos)
304{
305 struct inode *inode = file->f_dentry->d_inode;
306 struct proc_dir_entry *entry = PDE(inode);
307 struct salinfo_data *data = entry->data;
308 char cmd[32];
309 size_t size;
310 int i, n, cpu = -1;
311
312retry:
Keith Owense026cca2006-01-06 10:36:06 +1100313 if (cpus_empty(data->cpu_event) && down_trylock(&data->mutex)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700314 if (file->f_flags & O_NONBLOCK)
315 return -EAGAIN;
Keith Owense026cca2006-01-06 10:36:06 +1100316 if (down_interruptible(&data->mutex))
Keith Owens05f70392005-12-02 13:40:15 +1100317 return -EINTR;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700318 }
319
320 n = data->cpu_check;
321 for (i = 0; i < NR_CPUS; i++) {
Keith Owense026cca2006-01-06 10:36:06 +1100322 if (cpu_isset(n, data->cpu_event)) {
323 if (!cpu_online(n)) {
324 cpu_clear(n, data->cpu_event);
325 continue;
326 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700327 cpu = n;
328 break;
329 }
330 if (++n == NR_CPUS)
331 n = 0;
332 }
333
334 if (cpu == -1)
335 goto retry;
336
Hidetoshi Seto43ed3ba2006-09-26 14:44:37 -0700337 ia64_mlogbuf_dump();
338
Linus Torvalds1da177e2005-04-16 15:20:36 -0700339 /* for next read, start checking at next CPU */
340 data->cpu_check = cpu;
341 if (++data->cpu_check == NR_CPUS)
342 data->cpu_check = 0;
343
344 snprintf(cmd, sizeof(cmd), "read %d\n", cpu);
345
346 size = strlen(cmd);
347 if (size > count)
348 size = count;
349 if (copy_to_user(buffer, cmd, size))
350 return -EFAULT;
351
352 return size;
353}
354
355static struct file_operations salinfo_event_fops = {
356 .open = salinfo_event_open,
357 .read = salinfo_event_read,
358};
359
360static int
361salinfo_log_open(struct inode *inode, struct file *file)
362{
363 struct proc_dir_entry *entry = PDE(inode);
364 struct salinfo_data *data = entry->data;
365
366 if (!capable(CAP_SYS_ADMIN))
367 return -EPERM;
368
369 spin_lock(&data_lock);
370 if (data->open) {
371 spin_unlock(&data_lock);
372 return -EBUSY;
373 }
374 data->open = 1;
375 spin_unlock(&data_lock);
376
377 if (data->state == STATE_NO_DATA &&
378 !(data->log_buffer = vmalloc(ia64_sal_get_state_info_size(data->type)))) {
379 data->open = 0;
380 return -ENOMEM;
381 }
382
383 return 0;
384}
385
386static int
387salinfo_log_release(struct inode *inode, struct file *file)
388{
389 struct proc_dir_entry *entry = PDE(inode);
390 struct salinfo_data *data = entry->data;
391
392 if (data->state == STATE_NO_DATA) {
393 vfree(data->log_buffer);
394 vfree(data->oemdata);
395 data->log_buffer = NULL;
396 data->oemdata = NULL;
397 }
398 spin_lock(&data_lock);
399 data->open = 0;
400 spin_unlock(&data_lock);
401 return 0;
402}
403
404static void
405call_on_cpu(int cpu, void (*fn)(void *), void *arg)
406{
Keith Owense026cca2006-01-06 10:36:06 +1100407 cpumask_t save_cpus_allowed = current->cpus_allowed;
408 cpumask_t new_cpus_allowed = cpumask_of_cpu(cpu);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700409 set_cpus_allowed(current, new_cpus_allowed);
410 (*fn)(arg);
411 set_cpus_allowed(current, save_cpus_allowed);
412}
413
414static void
415salinfo_log_read_cpu(void *context)
416{
417 struct salinfo_data *data = context;
418 sal_log_record_header_t *rh;
419 data->log_size = ia64_sal_get_state_info(data->type, (u64 *) data->log_buffer);
420 rh = (sal_log_record_header_t *)(data->log_buffer);
421 /* Clear corrected errors as they are read from SAL */
422 if (rh->severity == sal_log_severity_corrected)
423 ia64_sal_clear_state_info(data->type);
424}
425
426static void
427salinfo_log_new_read(int cpu, struct salinfo_data *data)
428{
429 struct salinfo_data_saved *data_saved;
430 unsigned long flags;
431 int i;
432 int saved_size = ARRAY_SIZE(data->data_saved);
433
434 data->saved_num = 0;
435 spin_lock_irqsave(&data_saved_lock, flags);
436retry:
437 for (i = 0, data_saved = data->data_saved; i < saved_size; ++i, ++data_saved) {
438 if (data_saved->buffer && data_saved->cpu == cpu) {
439 sal_log_record_header_t *rh = (sal_log_record_header_t *)(data_saved->buffer);
440 data->log_size = data_saved->size;
441 memcpy(data->log_buffer, rh, data->log_size);
442 barrier(); /* id check must not be moved */
443 if (rh->id == data_saved->id) {
444 data->saved_num = i+1;
445 break;
446 }
447 /* saved record changed by mca.c since interrupt, discard it */
448 shift1_data_saved(data, i);
449 goto retry;
450 }
451 }
452 spin_unlock_irqrestore(&data_saved_lock, flags);
453
454 if (!data->saved_num)
455 call_on_cpu(cpu, salinfo_log_read_cpu, data);
456 if (!data->log_size) {
Keith Owense026cca2006-01-06 10:36:06 +1100457 data->state = STATE_NO_DATA;
458 cpu_clear(cpu, data->cpu_event);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700459 } else {
Keith Owense026cca2006-01-06 10:36:06 +1100460 data->state = STATE_LOG_RECORD;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700461 }
462}
463
464static ssize_t
465salinfo_log_read(struct file *file, char __user *buffer, size_t count, loff_t *ppos)
466{
467 struct inode *inode = file->f_dentry->d_inode;
468 struct proc_dir_entry *entry = PDE(inode);
469 struct salinfo_data *data = entry->data;
470 u8 *buf;
471 u64 bufsize;
472
473 if (data->state == STATE_LOG_RECORD) {
474 buf = data->log_buffer;
475 bufsize = data->log_size;
476 } else if (data->state == STATE_OEMDATA) {
477 buf = data->oemdata;
478 bufsize = data->oemdata_size;
479 } else {
480 buf = NULL;
481 bufsize = 0;
482 }
483 return simple_read_from_buffer(buffer, count, ppos, buf, bufsize);
484}
485
486static void
487salinfo_log_clear_cpu(void *context)
488{
489 struct salinfo_data *data = context;
490 ia64_sal_clear_state_info(data->type);
491}
492
493static int
494salinfo_log_clear(struct salinfo_data *data, int cpu)
495{
496 sal_log_record_header_t *rh;
Keith Owense026cca2006-01-06 10:36:06 +1100497 unsigned long flags;
498 spin_lock_irqsave(&data_saved_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700499 data->state = STATE_NO_DATA;
Keith Owense026cca2006-01-06 10:36:06 +1100500 if (!cpu_isset(cpu, data->cpu_event)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700501 spin_unlock_irqrestore(&data_saved_lock, flags);
Keith Owense026cca2006-01-06 10:36:06 +1100502 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700503 }
Keith Owense026cca2006-01-06 10:36:06 +1100504 cpu_clear(cpu, data->cpu_event);
505 if (data->saved_num) {
506 shift1_data_saved(data, data->saved_num - 1);
507 data->saved_num = 0;
508 }
509 spin_unlock_irqrestore(&data_saved_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700510 rh = (sal_log_record_header_t *)(data->log_buffer);
511 /* Corrected errors have already been cleared from SAL */
512 if (rh->severity != sal_log_severity_corrected)
513 call_on_cpu(cpu, salinfo_log_clear_cpu, data);
514 /* clearing a record may make a new record visible */
515 salinfo_log_new_read(cpu, data);
Keith Owense026cca2006-01-06 10:36:06 +1100516 if (data->state == STATE_LOG_RECORD) {
517 spin_lock_irqsave(&data_saved_lock, flags);
518 cpu_set(cpu, data->cpu_event);
519 salinfo_work_to_do(data);
520 spin_unlock_irqrestore(&data_saved_lock, flags);
521 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700522 return 0;
523}
524
525static ssize_t
526salinfo_log_write(struct file *file, const char __user *buffer, size_t count, loff_t *ppos)
527{
528 struct inode *inode = file->f_dentry->d_inode;
529 struct proc_dir_entry *entry = PDE(inode);
530 struct salinfo_data *data = entry->data;
531 char cmd[32];
532 size_t size;
533 u32 offset;
534 int cpu;
535
536 size = sizeof(cmd);
537 if (count < size)
538 size = count;
539 if (copy_from_user(cmd, buffer, size))
540 return -EFAULT;
541
542 if (sscanf(cmd, "read %d", &cpu) == 1) {
543 salinfo_log_new_read(cpu, data);
544 } else if (sscanf(cmd, "clear %d", &cpu) == 1) {
545 int ret;
546 if ((ret = salinfo_log_clear(data, cpu)))
547 count = ret;
548 } else if (sscanf(cmd, "oemdata %d %d", &cpu, &offset) == 2) {
549 if (data->state != STATE_LOG_RECORD && data->state != STATE_OEMDATA)
550 return -EINVAL;
551 if (offset > data->log_size - sizeof(efi_guid_t))
552 return -EINVAL;
553 data->state = STATE_OEMDATA;
554 if (salinfo_platform_oemdata) {
555 struct salinfo_platform_oemdata_parms parms = {
556 .efi_guid = data->log_buffer + offset,
557 .oemdata = &data->oemdata,
558 .oemdata_size = &data->oemdata_size
559 };
560 call_on_cpu(cpu, salinfo_platform_oemdata_cpu, &parms);
561 if (parms.ret)
562 count = parms.ret;
563 } else
564 data->oemdata_size = 0;
565 } else
566 return -EINVAL;
567
568 return count;
569}
570
571static struct file_operations salinfo_data_fops = {
572 .open = salinfo_log_open,
573 .release = salinfo_log_release,
574 .read = salinfo_log_read,
575 .write = salinfo_log_write,
576};
577
Keith Owense026cca2006-01-06 10:36:06 +1100578#ifdef CONFIG_HOTPLUG_CPU
Chandra Seetharaman9c7b2162006-06-27 02:54:07 -0700579static int __devinit
Keith Owense026cca2006-01-06 10:36:06 +1100580salinfo_cpu_callback(struct notifier_block *nb, unsigned long action, void *hcpu)
581{
582 unsigned int i, cpu = (unsigned long)hcpu;
583 unsigned long flags;
584 struct salinfo_data *data;
585 switch (action) {
586 case CPU_ONLINE:
587 spin_lock_irqsave(&data_saved_lock, flags);
588 for (i = 0, data = salinfo_data;
589 i < ARRAY_SIZE(salinfo_data);
590 ++i, ++data) {
591 cpu_set(cpu, data->cpu_event);
592 salinfo_work_to_do(data);
593 }
594 spin_unlock_irqrestore(&data_saved_lock, flags);
595 break;
596 case CPU_DEAD:
597 spin_lock_irqsave(&data_saved_lock, flags);
598 for (i = 0, data = salinfo_data;
599 i < ARRAY_SIZE(salinfo_data);
600 ++i, ++data) {
601 struct salinfo_data_saved *data_saved;
602 int j;
603 for (j = ARRAY_SIZE(data->data_saved) - 1, data_saved = data->data_saved + j;
604 j >= 0;
605 --j, --data_saved) {
606 if (data_saved->buffer && data_saved->cpu == cpu) {
607 shift1_data_saved(data, j);
608 }
609 }
610 cpu_clear(cpu, data->cpu_event);
611 }
612 spin_unlock_irqrestore(&data_saved_lock, flags);
613 break;
614 }
615 return NOTIFY_OK;
616}
617
618static struct notifier_block salinfo_cpu_notifier =
619{
620 .notifier_call = salinfo_cpu_callback,
621 .priority = 0,
622};
623#endif /* CONFIG_HOTPLUG_CPU */
624
Linus Torvalds1da177e2005-04-16 15:20:36 -0700625static int __init
626salinfo_init(void)
627{
628 struct proc_dir_entry *salinfo_dir; /* /proc/sal dir entry */
629 struct proc_dir_entry **sdir = salinfo_proc_entries; /* keeps track of every entry */
630 struct proc_dir_entry *dir, *entry;
631 struct salinfo_data *data;
Keith Owense026cca2006-01-06 10:36:06 +1100632 int i, j;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700633
634 salinfo_dir = proc_mkdir("sal", NULL);
635 if (!salinfo_dir)
636 return 0;
637
638 for (i=0; i < NR_SALINFO_ENTRIES; i++) {
639 /* pass the feature bit in question as misc data */
640 *sdir++ = create_proc_read_entry (salinfo_entries[i].name, 0, salinfo_dir,
641 salinfo_read, (void *)salinfo_entries[i].feature);
642 }
643
644 for (i = 0; i < ARRAY_SIZE(salinfo_log_name); i++) {
645 data = salinfo_data + i;
646 data->type = i;
Keith Owense026cca2006-01-06 10:36:06 +1100647 init_MUTEX(&data->mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700648 dir = proc_mkdir(salinfo_log_name[i], salinfo_dir);
649 if (!dir)
650 continue;
651
652 entry = create_proc_entry("event", S_IRUSR, dir);
653 if (!entry)
654 continue;
655 entry->data = data;
656 entry->proc_fops = &salinfo_event_fops;
657 *sdir++ = entry;
658
659 entry = create_proc_entry("data", S_IRUSR | S_IWUSR, dir);
660 if (!entry)
661 continue;
662 entry->data = data;
663 entry->proc_fops = &salinfo_data_fops;
664 *sdir++ = entry;
665
666 /* we missed any events before now */
Keith Owense026cca2006-01-06 10:36:06 +1100667 for_each_online_cpu(j)
668 cpu_set(j, data->cpu_event);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700669
670 *sdir++ = dir;
671 }
672
673 *sdir++ = salinfo_dir;
674
675 init_timer(&salinfo_timer);
676 salinfo_timer.expires = jiffies + SALINFO_TIMER_DELAY;
677 salinfo_timer.function = &salinfo_timeout;
678 add_timer(&salinfo_timer);
679
Chandra Seetharaman5a67e4c2006-06-27 02:54:11 -0700680 register_hotcpu_notifier(&salinfo_cpu_notifier);
Keith Owense026cca2006-01-06 10:36:06 +1100681
Linus Torvalds1da177e2005-04-16 15:20:36 -0700682 return 0;
683}
684
685/*
686 * 'data' contains an integer that corresponds to the feature we're
687 * testing
688 */
689static int
690salinfo_read(char *page, char **start, off_t off, int count, int *eof, void *data)
691{
692 int len = 0;
693
694 len = sprintf(page, (sal_platform_features & (unsigned long)data) ? "1\n" : "0\n");
695
696 if (len <= off+count) *eof = 1;
697
698 *start = page + off;
699 len -= off;
700
701 if (len>count) len = count;
702 if (len<0) len = 0;
703
704 return len;
705}
706
707module_init(salinfo_init);