ftp://ftp.kernel.org/pub/linux/kernel/v2.6/linux-2.6.6.tar.bz2
[linux-2.6.git] / arch / ia64 / sn / kernel / mca.c
1 /*
2  * This file is subject to the terms and conditions of the GNU General Public
3  * License.  See the file "COPYING" in the main directory of this archive
4  * for more details.
5  *
6  * Copyright (c) 2000-2004 Silicon Graphics, Inc.  All Rights Reserved.
7  */
8
9 #include <linux/types.h>
10 #include <linux/kernel.h>
11 #include <linux/timer.h>
12 #include <linux/vmalloc.h>
13 #include <asm/sn/sgi.h>
14 #include <asm/mca.h>
15 #include <asm/sal.h>
16 #include <asm/sn/sn_sal.h>
17
18
19
20 /*
21  * Interval for calling SAL to poll for errors that do NOT cause error
22  * interrupts. SAL will raise a CPEI if any errors are present that
23  * need to be logged.
24  */
25 #define CPEI_INTERVAL   (5*HZ)
26
27
28 struct timer_list sn_cpei_timer;
29 void sn_init_cpei_timer(void);
30
31 /* Printing oemdata from mca uses data that is not passed through SAL, it is
32  * global.  Only one user at a time.
33  */
34 static DECLARE_MUTEX(sn_oemdata_mutex);
35 static u8 **sn_oemdata;
36 static u64 *sn_oemdata_size, sn_oemdata_bufsize;
37
38 /*
39  * print_hook
40  *
41  * This function is the callback routine that SAL calls to log error
42  * info for platform errors.  buf is appended to sn_oemdata, resizing as
43  * required.
44  */
45 static int
46 print_hook(const char *fmt, ...)
47 {
48         char buf[400];
49         int len;
50         va_list args;
51         va_start(args, fmt);
52         vsnprintf(buf, sizeof(buf), fmt, args);
53         va_end(args);
54         len = strlen(buf);
55         while (*sn_oemdata_size + len + 1 > sn_oemdata_bufsize) {
56                 u8 *newbuf = vmalloc(sn_oemdata_bufsize += 1000);
57                 if (!newbuf) {
58                         printk(KERN_ERR "%s: unable to extend sn_oemdata\n", __FUNCTION__);
59                         return 0;
60                 }
61                 memcpy(newbuf, *sn_oemdata, *sn_oemdata_size);
62                 vfree(*sn_oemdata);
63                 *sn_oemdata = newbuf;
64         }
65         memcpy(*sn_oemdata + *sn_oemdata_size, buf, len + 1);
66         *sn_oemdata_size += len;
67         return 0;
68 }
69
70
71 static void
72 sn_cpei_handler(int irq, void *devid, struct pt_regs *regs)
73 {
74         /*
75          * this function's sole purpose is to call SAL when we receive
76          * a CE interrupt from SHUB or when the timer routine decides
77          * we need to call SAL to check for CEs.
78          */
79
80         /* CALL SAL_LOG_CE */
81
82         ia64_sn_plat_cpei_handler();
83 }
84
85
86 static void
87 sn_cpei_timer_handler(unsigned long dummy)
88 {
89         sn_cpei_handler(-1, NULL, NULL);
90         mod_timer(&sn_cpei_timer, jiffies + CPEI_INTERVAL);
91 }
92
93 void
94 sn_init_cpei_timer(void)
95 {
96         init_timer(&sn_cpei_timer);
97         sn_cpei_timer.expires = jiffies + CPEI_INTERVAL;
98         sn_cpei_timer.function = sn_cpei_timer_handler;
99         add_timer(&sn_cpei_timer);
100 }
101
102 static int
103 sn_platform_plat_specific_err_print(const u8 *sect_header, u8 **oemdata, u64 *oemdata_size)
104 {
105         sal_log_plat_specific_err_info_t *psei = (sal_log_plat_specific_err_info_t *)sect_header;
106         if (!psei->valid.oem_data)
107                 return 0;
108         down(&sn_oemdata_mutex);
109         sn_oemdata = oemdata;
110         sn_oemdata_size = oemdata_size;
111         sn_oemdata_bufsize = 0;
112         ia64_sn_plat_specific_err_print(print_hook, (char *)psei);
113         up(&sn_oemdata_mutex);
114         return 0;
115 }
116
117 /* Callback when userspace salinfo wants to decode oem data via the platform
118  * kernel and/or prom.
119  */
120 int sn_salinfo_platform_oemdata(const u8 *sect_header, u8 **oemdata, u64 *oemdata_size)
121 {
122         efi_guid_t guid = *(efi_guid_t *)sect_header;
123         *oemdata_size = 0;
124         vfree(*oemdata);
125         *oemdata = NULL;
126         if (efi_guidcmp(guid, SAL_PLAT_SPECIFIC_ERR_SECT_GUID) == 0)
127                 return sn_platform_plat_specific_err_print(sect_header, oemdata, oemdata_size);
128         return 0;
129 }
130
131 static int __init sn_salinfo_init(void)
132 {
133         salinfo_platform_oemdata = &sn_salinfo_platform_oemdata;
134         return 0;
135 }
136
137 module_init(sn_salinfo_init)