procfs: new helper - PDE_DATA(inode)
[GitHub/mt8127/android_kernel_alcatel_ttab.git] / arch / ia64 / kernel / salinfo.c
CommitLineData
1da177e4
LT
1/*
2 * salinfo.c
3 *
4 * Creates entries in /proc/sal for various system features.
5 *
e026cca0 6 * Copyright (c) 2003, 2006 Silicon Graphics, Inc. All rights reserved.
1da177e4
LT
7 * 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.
289d773e
KO
25 *
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.
e026cca0
KO
30 *
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.
1da177e4
LT
37 */
38
a9415644 39#include <linux/capability.h>
e026cca0 40#include <linux/cpu.h>
1da177e4
LT
41#include <linux/types.h>
42#include <linux/proc_fs.h>
43#include <linux/module.h>
44#include <linux/smp.h>
1da177e4
LT
45#include <linux/timer.h>
46#include <linux/vmalloc.h>
6188e10d 47#include <linux/semaphore.h>
1da177e4 48
1da177e4
LT
49#include <asm/sal.h>
50#include <asm/uaccess.h>
51
52MODULE_AUTHOR("Jesse Barnes <jbarnes@sgi.com>");
53MODULE_DESCRIPTION("/proc interface to IA-64 SAL features");
54MODULE_LICENSE("GPL");
55
56static int salinfo_read(char *page, char **start, off_t off, int count, int *eof, void *data);
57
58typedef struct {
59 const char *name; /* name of the proc entry */
60 unsigned long feature; /* feature bit */
61 struct proc_dir_entry *entry; /* registered entry (removal) */
62} salinfo_entry_t;
63
64/*
65 * List {name,feature} pairs for every entry in /proc/sal/<feature>
66 * that this module exports
67 */
68static salinfo_entry_t salinfo_entries[]={
69 { "bus_lock", IA64_SAL_PLATFORM_FEATURE_BUS_LOCK, },
70 { "irq_redirection", IA64_SAL_PLATFORM_FEATURE_IRQ_REDIR_HINT, },
71 { "ipi_redirection", IA64_SAL_PLATFORM_FEATURE_IPI_REDIR_HINT, },
72 { "itc_drift", IA64_SAL_PLATFORM_FEATURE_ITC_DRIFT, },
73};
74
75#define NR_SALINFO_ENTRIES ARRAY_SIZE(salinfo_entries)
76
77static char *salinfo_log_name[] = {
78 "mca",
79 "init",
80 "cmc",
81 "cpe",
82};
83
84static struct proc_dir_entry *salinfo_proc_entries[
85 ARRAY_SIZE(salinfo_entries) + /* /proc/sal/bus_lock */
86 ARRAY_SIZE(salinfo_log_name) + /* /proc/sal/{mca,...} */
87 (2 * ARRAY_SIZE(salinfo_log_name)) + /* /proc/sal/mca/{event,data} */
88 1]; /* /proc/sal */
89
90/* Some records we get ourselves, some are accessed as saved data in buffers
91 * that are owned by mca.c.
92 */
93struct salinfo_data_saved {
94 u8* buffer;
95 u64 size;
96 u64 id;
97 int cpu;
98};
99
100/* State transitions. Actions are :-
101 * Write "read <cpunum>" to the data file.
102 * Write "clear <cpunum>" to the data file.
103 * Write "oemdata <cpunum> <offset> to the data file.
104 * Read from the data file.
105 * Close the data file.
106 *
107 * Start state is NO_DATA.
108 *
109 * NO_DATA
110 * write "read <cpunum>" -> NO_DATA or LOG_RECORD.
111 * write "clear <cpunum>" -> NO_DATA or LOG_RECORD.
112 * write "oemdata <cpunum> <offset> -> return -EINVAL.
113 * read data -> return EOF.
114 * close -> unchanged. Free record areas.
115 *
116 * LOG_RECORD
117 * write "read <cpunum>" -> NO_DATA or LOG_RECORD.
118 * write "clear <cpunum>" -> NO_DATA or LOG_RECORD.
119 * write "oemdata <cpunum> <offset> -> format the oem data, goto OEMDATA.
120 * read data -> return the INIT/MCA/CMC/CPE record.
121 * close -> unchanged. Keep record areas.
122 *
123 * OEMDATA
124 * write "read <cpunum>" -> NO_DATA or LOG_RECORD.
125 * write "clear <cpunum>" -> NO_DATA or LOG_RECORD.
126 * write "oemdata <cpunum> <offset> -> format the oem data, goto OEMDATA.
127 * read data -> return the formatted oemdata.
128 * close -> unchanged. Keep record areas.
129 *
130 * Closing the data file does not change the state. This allows shell scripts
131 * to manipulate salinfo data, each shell redirection opens the file, does one
132 * action then closes it again. The record areas are only freed at close when
133 * the state is NO_DATA.
134 */
135enum salinfo_state {
136 STATE_NO_DATA,
137 STATE_LOG_RECORD,
138 STATE_OEMDATA,
139};
140
141struct salinfo_data {
e026cca0
KO
142 cpumask_t cpu_event; /* which cpus have outstanding events */
143 struct semaphore mutex;
1da177e4
LT
144 u8 *log_buffer;
145 u64 log_size;
146 u8 *oemdata; /* decoded oem data */
147 u64 oemdata_size;
148 int open; /* single-open to prevent races */
149 u8 type;
150 u8 saved_num; /* using a saved record? */
151 enum salinfo_state state :8; /* processing state */
152 u8 padding;
153 int cpu_check; /* next CPU to check */
154 struct salinfo_data_saved data_saved[5];/* save last 5 records from mca.c, must be < 255 */
155};
156
157static struct salinfo_data salinfo_data[ARRAY_SIZE(salinfo_log_name)];
158
71841b8f
KO
159static DEFINE_SPINLOCK(data_lock);
160static DEFINE_SPINLOCK(data_saved_lock);
1da177e4
LT
161
162/** salinfo_platform_oemdata - optional callback to decode oemdata from an error
163 * record.
164 * @sect_header: pointer to the start of the section to decode.
72fdbdce 165 * @oemdata: returns vmalloc area containing the decoded output.
1da177e4
LT
166 * @oemdata_size: returns length of decoded output (strlen).
167 *
168 * Description: If user space asks for oem data to be decoded by the kernel
169 * and/or prom and the platform has set salinfo_platform_oemdata to the address
170 * of a platform specific routine then call that routine. salinfo_platform_oemdata
171 * vmalloc's and formats its output area, returning the address of the text
172 * and its strlen. Returns 0 for success, -ve for error. The callback is
173 * invoked on the cpu that generated the error record.
174 */
175int (*salinfo_platform_oemdata)(const u8 *sect_header, u8 **oemdata, u64 *oemdata_size);
176
177struct salinfo_platform_oemdata_parms {
178 const u8 *efi_guid;
179 u8 **oemdata;
180 u64 *oemdata_size;
181 int ret;
182};
183
e026cca0
KO
184/* Kick the mutex that tells user space that there is work to do. Instead of
185 * trying to track the state of the mutex across multiple cpus, in user
186 * context, interrupt context, non-maskable interrupt context and hotplug cpu,
187 * it is far easier just to grab the mutex if it is free then release it.
188 *
189 * This routine must be called with data_saved_lock held, to make the down/up
190 * operation atomic.
191 */
192static void
193salinfo_work_to_do(struct salinfo_data *data)
194{
fa276f36 195 (void)(down_trylock(&data->mutex) ?: 0);
e026cca0
KO
196 up(&data->mutex);
197}
198
1da177e4
LT
199static void
200salinfo_platform_oemdata_cpu(void *context)
201{
202 struct salinfo_platform_oemdata_parms *parms = context;
203 parms->ret = salinfo_platform_oemdata(parms->efi_guid, parms->oemdata, parms->oemdata_size);
204}
205
206static void
207shift1_data_saved (struct salinfo_data *data, int shift)
208{
209 memcpy(data->data_saved+shift, data->data_saved+shift+1,
210 (ARRAY_SIZE(data->data_saved) - (shift+1)) * sizeof(data->data_saved[0]));
211 memset(data->data_saved + ARRAY_SIZE(data->data_saved) - 1, 0,
212 sizeof(data->data_saved[0]));
213}
214
215/* This routine is invoked in interrupt context. Note: mca.c enables
216 * interrupts before calling this code for CMC/CPE. MCA and INIT events are
217 * not irq safe, do not call any routines that use spinlocks, they may deadlock.
218 * MCA and INIT records are recorded, a timer event will look for any
219 * outstanding events and wake up the user space code.
220 *
221 * The buffer passed from mca.c points to the output from ia64_log_get. This is
222 * a persistent buffer but its contents can change between the interrupt and
223 * when user space processes the record. Save the record id to identify
289d773e 224 * changes. If the buffer is NULL then just update the bitmap.
1da177e4
LT
225 */
226void
227salinfo_log_wakeup(int type, u8 *buffer, u64 size, int irqsafe)
228{
229 struct salinfo_data *data = salinfo_data + type;
230 struct salinfo_data_saved *data_saved;
231 unsigned long flags = 0;
232 int i;
233 int saved_size = ARRAY_SIZE(data->data_saved);
234
235 BUG_ON(type >= ARRAY_SIZE(salinfo_log_name));
236
e026cca0
KO
237 if (irqsafe)
238 spin_lock_irqsave(&data_saved_lock, flags);
289d773e 239 if (buffer) {
289d773e
KO
240 for (i = 0, data_saved = data->data_saved; i < saved_size; ++i, ++data_saved) {
241 if (!data_saved->buffer)
242 break;
243 }
244 if (i == saved_size) {
245 if (!data->saved_num) {
246 shift1_data_saved(data, 0);
247 data_saved = data->data_saved + saved_size - 1;
248 } else
249 data_saved = NULL;
250 }
251 if (data_saved) {
252 data_saved->cpu = smp_processor_id();
253 data_saved->id = ((sal_log_record_header_t *)buffer)->id;
254 data_saved->size = size;
255 data_saved->buffer = buffer;
256 }
1da177e4 257 }
e026cca0
KO
258 cpu_set(smp_processor_id(), data->cpu_event);
259 if (irqsafe) {
260 salinfo_work_to_do(data);
261 spin_unlock_irqrestore(&data_saved_lock, flags);
1da177e4
LT
262 }
263}
264
265/* Check for outstanding MCA/INIT records every minute (arbitrary) */
266#define SALINFO_TIMER_DELAY (60*HZ)
267static struct timer_list salinfo_timer;
43ed3baf 268extern void ia64_mlogbuf_dump(void);
1da177e4
LT
269
270static void
271salinfo_timeout_check(struct salinfo_data *data)
272{
e026cca0 273 unsigned long flags;
1da177e4
LT
274 if (!data->open)
275 return;
e026cca0
KO
276 if (!cpus_empty(data->cpu_event)) {
277 spin_lock_irqsave(&data_saved_lock, flags);
278 salinfo_work_to_do(data);
279 spin_unlock_irqrestore(&data_saved_lock, flags);
1da177e4
LT
280 }
281}
282
e026cca0 283static void
1da177e4
LT
284salinfo_timeout (unsigned long arg)
285{
43ed3baf 286 ia64_mlogbuf_dump();
1da177e4
LT
287 salinfo_timeout_check(salinfo_data + SAL_INFO_TYPE_MCA);
288 salinfo_timeout_check(salinfo_data + SAL_INFO_TYPE_INIT);
289 salinfo_timer.expires = jiffies + SALINFO_TIMER_DELAY;
290 add_timer(&salinfo_timer);
291}
292
293static int
294salinfo_event_open(struct inode *inode, struct file *file)
295{
296 if (!capable(CAP_SYS_ADMIN))
297 return -EPERM;
298 return 0;
299}
300
301static ssize_t
302salinfo_event_read(struct file *file, char __user *buffer, size_t count, loff_t *ppos)
303{
d9dda78b 304 struct salinfo_data *data = PDE_DATA(file_inode(file));
1da177e4
LT
305 char cmd[32];
306 size_t size;
307 int i, n, cpu = -1;
308
309retry:
e026cca0 310 if (cpus_empty(data->cpu_event) && down_trylock(&data->mutex)) {
1da177e4
LT
311 if (file->f_flags & O_NONBLOCK)
312 return -EAGAIN;
e026cca0 313 if (down_interruptible(&data->mutex))
05f70395 314 return -EINTR;
1da177e4
LT
315 }
316
317 n = data->cpu_check;
5dd3c994 318 for (i = 0; i < nr_cpu_ids; i++) {
e026cca0
KO
319 if (cpu_isset(n, data->cpu_event)) {
320 if (!cpu_online(n)) {
321 cpu_clear(n, data->cpu_event);
322 continue;
323 }
1da177e4
LT
324 cpu = n;
325 break;
326 }
5dd3c994 327 if (++n == nr_cpu_ids)
1da177e4
LT
328 n = 0;
329 }
330
331 if (cpu == -1)
332 goto retry;
333
43ed3baf
HS
334 ia64_mlogbuf_dump();
335
1da177e4
LT
336 /* for next read, start checking at next CPU */
337 data->cpu_check = cpu;
5dd3c994 338 if (++data->cpu_check == nr_cpu_ids)
1da177e4
LT
339 data->cpu_check = 0;
340
341 snprintf(cmd, sizeof(cmd), "read %d\n", cpu);
342
343 size = strlen(cmd);
344 if (size > count)
345 size = count;
346 if (copy_to_user(buffer, cmd, size))
347 return -EFAULT;
348
349 return size;
350}
351
5dfe4c96 352static const struct file_operations salinfo_event_fops = {
1da177e4
LT
353 .open = salinfo_event_open,
354 .read = salinfo_event_read,
6038f373 355 .llseek = noop_llseek,
1da177e4
LT
356};
357
358static int
359salinfo_log_open(struct inode *inode, struct file *file)
360{
d9dda78b 361 struct salinfo_data *data = PDE_DATA(inode);
1da177e4
LT
362
363 if (!capable(CAP_SYS_ADMIN))
364 return -EPERM;
365
366 spin_lock(&data_lock);
367 if (data->open) {
368 spin_unlock(&data_lock);
369 return -EBUSY;
370 }
371 data->open = 1;
372 spin_unlock(&data_lock);
373
374 if (data->state == STATE_NO_DATA &&
375 !(data->log_buffer = vmalloc(ia64_sal_get_state_info_size(data->type)))) {
376 data->open = 0;
377 return -ENOMEM;
378 }
379
380 return 0;
381}
382
383static int
384salinfo_log_release(struct inode *inode, struct file *file)
385{
d9dda78b 386 struct salinfo_data *data = PDE_DATA(inode);
1da177e4
LT
387
388 if (data->state == STATE_NO_DATA) {
389 vfree(data->log_buffer);
390 vfree(data->oemdata);
391 data->log_buffer = NULL;
392 data->oemdata = NULL;
393 }
394 spin_lock(&data_lock);
395 data->open = 0;
396 spin_unlock(&data_lock);
397 return 0;
398}
399
400static void
401call_on_cpu(int cpu, void (*fn)(void *), void *arg)
402{
e026cca0 403 cpumask_t save_cpus_allowed = current->cpus_allowed;
552dce3a 404 set_cpus_allowed_ptr(current, cpumask_of(cpu));
1da177e4 405 (*fn)(arg);
552dce3a 406 set_cpus_allowed_ptr(current, &save_cpus_allowed);
1da177e4
LT
407}
408
409static void
410salinfo_log_read_cpu(void *context)
411{
412 struct salinfo_data *data = context;
413 sal_log_record_header_t *rh;
414 data->log_size = ia64_sal_get_state_info(data->type, (u64 *) data->log_buffer);
415 rh = (sal_log_record_header_t *)(data->log_buffer);
416 /* Clear corrected errors as they are read from SAL */
417 if (rh->severity == sal_log_severity_corrected)
418 ia64_sal_clear_state_info(data->type);
419}
420
421static void
422salinfo_log_new_read(int cpu, struct salinfo_data *data)
423{
424 struct salinfo_data_saved *data_saved;
425 unsigned long flags;
426 int i;
427 int saved_size = ARRAY_SIZE(data->data_saved);
428
429 data->saved_num = 0;
430 spin_lock_irqsave(&data_saved_lock, flags);
431retry:
432 for (i = 0, data_saved = data->data_saved; i < saved_size; ++i, ++data_saved) {
433 if (data_saved->buffer && data_saved->cpu == cpu) {
434 sal_log_record_header_t *rh = (sal_log_record_header_t *)(data_saved->buffer);
435 data->log_size = data_saved->size;
436 memcpy(data->log_buffer, rh, data->log_size);
437 barrier(); /* id check must not be moved */
438 if (rh->id == data_saved->id) {
439 data->saved_num = i+1;
440 break;
441 }
442 /* saved record changed by mca.c since interrupt, discard it */
443 shift1_data_saved(data, i);
444 goto retry;
445 }
446 }
447 spin_unlock_irqrestore(&data_saved_lock, flags);
448
449 if (!data->saved_num)
450 call_on_cpu(cpu, salinfo_log_read_cpu, data);
451 if (!data->log_size) {
e026cca0
KO
452 data->state = STATE_NO_DATA;
453 cpu_clear(cpu, data->cpu_event);
1da177e4 454 } else {
e026cca0 455 data->state = STATE_LOG_RECORD;
1da177e4
LT
456 }
457}
458
459static ssize_t
460salinfo_log_read(struct file *file, char __user *buffer, size_t count, loff_t *ppos)
461{
d9dda78b 462 struct salinfo_data *data = PDE_DATA(file_inode(file));
1da177e4
LT
463 u8 *buf;
464 u64 bufsize;
465
466 if (data->state == STATE_LOG_RECORD) {
467 buf = data->log_buffer;
468 bufsize = data->log_size;
469 } else if (data->state == STATE_OEMDATA) {
470 buf = data->oemdata;
471 bufsize = data->oemdata_size;
472 } else {
473 buf = NULL;
474 bufsize = 0;
475 }
476 return simple_read_from_buffer(buffer, count, ppos, buf, bufsize);
477}
478
479static void
480salinfo_log_clear_cpu(void *context)
481{
482 struct salinfo_data *data = context;
483 ia64_sal_clear_state_info(data->type);
484}
485
486static int
487salinfo_log_clear(struct salinfo_data *data, int cpu)
488{
489 sal_log_record_header_t *rh;
e026cca0
KO
490 unsigned long flags;
491 spin_lock_irqsave(&data_saved_lock, flags);
1da177e4 492 data->state = STATE_NO_DATA;
e026cca0
KO
493 if (!cpu_isset(cpu, data->cpu_event)) {
494 spin_unlock_irqrestore(&data_saved_lock, flags);
1da177e4 495 return 0;
e026cca0
KO
496 }
497 cpu_clear(cpu, data->cpu_event);
1da177e4 498 if (data->saved_num) {
e026cca0 499 shift1_data_saved(data, data->saved_num - 1);
1da177e4 500 data->saved_num = 0;
1da177e4 501 }
e026cca0 502 spin_unlock_irqrestore(&data_saved_lock, flags);
1da177e4
LT
503 rh = (sal_log_record_header_t *)(data->log_buffer);
504 /* Corrected errors have already been cleared from SAL */
505 if (rh->severity != sal_log_severity_corrected)
506 call_on_cpu(cpu, salinfo_log_clear_cpu, data);
507 /* clearing a record may make a new record visible */
508 salinfo_log_new_read(cpu, data);
e026cca0
KO
509 if (data->state == STATE_LOG_RECORD) {
510 spin_lock_irqsave(&data_saved_lock, flags);
511 cpu_set(cpu, data->cpu_event);
512 salinfo_work_to_do(data);
513 spin_unlock_irqrestore(&data_saved_lock, flags);
514 }
1da177e4
LT
515 return 0;
516}
517
518static ssize_t
519salinfo_log_write(struct file *file, const char __user *buffer, size_t count, loff_t *ppos)
520{
d9dda78b 521 struct salinfo_data *data = PDE_DATA(file_inode(file));
1da177e4
LT
522 char cmd[32];
523 size_t size;
524 u32 offset;
525 int cpu;
526
527 size = sizeof(cmd);
528 if (count < size)
529 size = count;
530 if (copy_from_user(cmd, buffer, size))
531 return -EFAULT;
532
533 if (sscanf(cmd, "read %d", &cpu) == 1) {
534 salinfo_log_new_read(cpu, data);
535 } else if (sscanf(cmd, "clear %d", &cpu) == 1) {
536 int ret;
537 if ((ret = salinfo_log_clear(data, cpu)))
538 count = ret;
539 } else if (sscanf(cmd, "oemdata %d %d", &cpu, &offset) == 2) {
540 if (data->state != STATE_LOG_RECORD && data->state != STATE_OEMDATA)
541 return -EINVAL;
542 if (offset > data->log_size - sizeof(efi_guid_t))
543 return -EINVAL;
544 data->state = STATE_OEMDATA;
545 if (salinfo_platform_oemdata) {
546 struct salinfo_platform_oemdata_parms parms = {
547 .efi_guid = data->log_buffer + offset,
548 .oemdata = &data->oemdata,
549 .oemdata_size = &data->oemdata_size
550 };
551 call_on_cpu(cpu, salinfo_platform_oemdata_cpu, &parms);
552 if (parms.ret)
553 count = parms.ret;
554 } else
555 data->oemdata_size = 0;
556 } else
557 return -EINVAL;
558
559 return count;
560}
561
5dfe4c96 562static const struct file_operations salinfo_data_fops = {
1da177e4
LT
563 .open = salinfo_log_open,
564 .release = salinfo_log_release,
565 .read = salinfo_log_read,
566 .write = salinfo_log_write,
6038f373 567 .llseek = default_llseek,
1da177e4
LT
568};
569
db6a5cef 570static int __cpuinit
e026cca0
KO
571salinfo_cpu_callback(struct notifier_block *nb, unsigned long action, void *hcpu)
572{
573 unsigned int i, cpu = (unsigned long)hcpu;
574 unsigned long flags;
575 struct salinfo_data *data;
576 switch (action) {
577 case CPU_ONLINE:
8bb78442 578 case CPU_ONLINE_FROZEN:
e026cca0
KO
579 spin_lock_irqsave(&data_saved_lock, flags);
580 for (i = 0, data = salinfo_data;
581 i < ARRAY_SIZE(salinfo_data);
582 ++i, ++data) {
583 cpu_set(cpu, data->cpu_event);
584 salinfo_work_to_do(data);
585 }
586 spin_unlock_irqrestore(&data_saved_lock, flags);
587 break;
588 case CPU_DEAD:
8bb78442 589 case CPU_DEAD_FROZEN:
e026cca0
KO
590 spin_lock_irqsave(&data_saved_lock, flags);
591 for (i = 0, data = salinfo_data;
592 i < ARRAY_SIZE(salinfo_data);
593 ++i, ++data) {
594 struct salinfo_data_saved *data_saved;
595 int j;
596 for (j = ARRAY_SIZE(data->data_saved) - 1, data_saved = data->data_saved + j;
597 j >= 0;
598 --j, --data_saved) {
599 if (data_saved->buffer && data_saved->cpu == cpu) {
600 shift1_data_saved(data, j);
601 }
602 }
603 cpu_clear(cpu, data->cpu_event);
604 }
605 spin_unlock_irqrestore(&data_saved_lock, flags);
606 break;
607 }
608 return NOTIFY_OK;
609}
610
db6a5cef 611static struct notifier_block salinfo_cpu_notifier __cpuinitdata =
e026cca0
KO
612{
613 .notifier_call = salinfo_cpu_callback,
614 .priority = 0,
615};
e026cca0 616
1da177e4
LT
617static int __init
618salinfo_init(void)
619{
620 struct proc_dir_entry *salinfo_dir; /* /proc/sal dir entry */
621 struct proc_dir_entry **sdir = salinfo_proc_entries; /* keeps track of every entry */
622 struct proc_dir_entry *dir, *entry;
623 struct salinfo_data *data;
e026cca0 624 int i, j;
1da177e4
LT
625
626 salinfo_dir = proc_mkdir("sal", NULL);
627 if (!salinfo_dir)
628 return 0;
629
630 for (i=0; i < NR_SALINFO_ENTRIES; i++) {
631 /* pass the feature bit in question as misc data */
632 *sdir++ = create_proc_read_entry (salinfo_entries[i].name, 0, salinfo_dir,
633 salinfo_read, (void *)salinfo_entries[i].feature);
634 }
635
636 for (i = 0; i < ARRAY_SIZE(salinfo_log_name); i++) {
637 data = salinfo_data + i;
638 data->type = i;
383f9f17 639 sema_init(&data->mutex, 1);
1da177e4
LT
640 dir = proc_mkdir(salinfo_log_name[i], salinfo_dir);
641 if (!dir)
642 continue;
643
e2363768
DL
644 entry = proc_create_data("event", S_IRUSR, dir,
645 &salinfo_event_fops, data);
1da177e4
LT
646 if (!entry)
647 continue;
1da177e4
LT
648 *sdir++ = entry;
649
e2363768
DL
650 entry = proc_create_data("data", S_IRUSR | S_IWUSR, dir,
651 &salinfo_data_fops, data);
1da177e4
LT
652 if (!entry)
653 continue;
1da177e4
LT
654 *sdir++ = entry;
655
656 /* we missed any events before now */
e026cca0
KO
657 for_each_online_cpu(j)
658 cpu_set(j, data->cpu_event);
1da177e4
LT
659
660 *sdir++ = dir;
661 }
662
663 *sdir++ = salinfo_dir;
664
665 init_timer(&salinfo_timer);
666 salinfo_timer.expires = jiffies + SALINFO_TIMER_DELAY;
667 salinfo_timer.function = &salinfo_timeout;
668 add_timer(&salinfo_timer);
669
5a67e4c5 670 register_hotcpu_notifier(&salinfo_cpu_notifier);
e026cca0 671
1da177e4
LT
672 return 0;
673}
674
675/*
676 * 'data' contains an integer that corresponds to the feature we're
677 * testing
678 */
679static int
680salinfo_read(char *page, char **start, off_t off, int count, int *eof, void *data)
681{
682 int len = 0;
683
684 len = sprintf(page, (sal_platform_features & (unsigned long)data) ? "1\n" : "0\n");
685
686 if (len <= off+count) *eof = 1;
687
688 *start = page + off;
689 len -= off;
690
691 if (len>count) len = count;
692 if (len<0) len = 0;
693
694 return len;
695}
696
697module_init(salinfo_init);