more changes on original files
[linux-2.4.git] / arch / ia64 / sn / kernel / mca.c
1 /*
2  * File:        mca.c
3  * Purpose:     SN specific MCA code.
4  *
5  * Copyright (C) 2001-2003 Silicon Graphics, Inc.  All Rights Reserved.
6  * 
7  * This program is free software; you can redistribute it and/or modify it 
8  * under the terms of version 2 of the GNU General Public License 
9  * as published by the Free Software Foundation.
10  * 
11  * This program is distributed in the hope that it would be useful, but 
12  * WITHOUT ANY WARRANTY; without even the implied warranty of 
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 
14  * 
15  * Further, this software is distributed without any warranty that it is 
16  * free of the rightful claim of any third person regarding infringement 
17  * or the like.  Any license provided herein, whether implied or 
18  * otherwise, applies only to this software file.  Patent licenses, if 
19  * any, provided herein do not apply to combinations of this program with 
20  * other software, or any other product whatsoever.
21  * 
22  * You should have received a copy of the GNU General Public 
23  * License along with this program; if not, write the Free Software 
24  * Foundation, Inc., 59 Temple Place - Suite 330, Boston MA 02111-1307, USA.
25  * 
26  * Contact information:  Silicon Graphics, Inc., 1600 Amphitheatre Pkwy, 
27  * Mountain View, CA  94043, or:
28  * 
29  * http://www.sgi.com 
30  * 
31  * For further information regarding this notice, see: 
32  * 
33  * http://oss.sgi.com/projects/GenInfo/NoticeExplan
34  */
35
36 #include <linux/types.h>
37 #include <linux/kernel.h>
38 #include <linux/timer.h>
39 #include <linux/vmalloc.h>
40 #include <asm/machvec.h>
41 #include <asm/mca.h>
42 #include <asm/sal.h>
43 #include <asm/sn/sn_sal.h>
44
45
46
47 /*
48  * Interval for calling SAL to poll for errors that do NOT cause error
49  * interrupts. SAL will raise a CPEI if any errors are present that
50  * need to be logged.
51  */
52 #define CPEI_INTERVAL   (5*HZ)
53
54
55 struct timer_list sn_cpei_timer;
56 void sn_init_cpei_timer(void);
57
58 /* Printing oemdata from mca uses data that is not passed through SAL, it is
59  * global.  Only one user at a time.
60  */
61 static DECLARE_MUTEX(sn_oemdata_mutex);
62 static u8 **sn_oemdata;
63 static u64 *sn_oemdata_size, sn_oemdata_bufsize;
64
65 /* Called as the "printk" routine via sn_platform_plat_specific_err_print,
66  * ia64_sn_plat_specific_err_print through SAL to print_hook.  It only handles
67  * a print of '"%s", buf'.  buf is appended to sn_oemdata, resizing as required.
68  */
69 static int
70 sn_oemdata_print(const char *fmt, ...)
71 {
72         va_list args;
73         char *buf;
74         int len;
75         va_start(args, fmt);
76         buf = va_arg(args, char *);
77         va_end(args);
78         len = strlen(buf);
79         while (*sn_oemdata_size + len + 1 > sn_oemdata_bufsize) {
80                 u8 *newbuf = vmalloc(sn_oemdata_bufsize += 1000);
81                 if (!newbuf) {
82                         printk(KERN_ERR "%s: unable to extend sn_oemdata\n", __FUNCTION__);
83                         return 0;
84                 }
85                 memcpy(newbuf, *sn_oemdata, *sn_oemdata_size);
86                 vfree(*sn_oemdata);
87                 *sn_oemdata = newbuf;
88         }
89         memcpy(*sn_oemdata + *sn_oemdata_size, buf, len + 1);
90         *sn_oemdata_size += len;
91         return len;
92 }
93
94 /*
95  * print_hook
96  *
97  * This function is the callback routine that SAL calls to log error
98  * info for platform errors. 
99  */
100 static int
101 print_hook(const char *fmt, ...)
102 {
103         static int      newline=1;
104         char            buf[400], *p;
105         va_list         args;
106         int             len=0;
107
108
109         va_start(args, fmt);
110         if (newline) {
111                 strcpy(buf, "+ ");
112                 len += 2;
113         }
114         len += vsnprintf(buf+len, sizeof(buf)-len, fmt, args);
115
116         /* Prefix each line with "+ " to be consistent with mca.c. */
117         p = buf;
118         while ((p=strchr(p, '\n')) && *++p != '\0') {
119                 memmove(p+2, p, 1+strlen(p));
120                 strncpy(p, "+ ", 2);
121                 len += 2;
122         }
123         newline = (p != 0);
124
125         va_end(args);
126         sn_oemdata_print("%s", buf);    /* args must be '"%s", buf' */
127         return len;
128 }
129
130
131 static void
132 sn_cpei_handler(int irq, void *devid, struct pt_regs *regs)
133 {
134         /*
135          * this function's sole purpose is to call SAL when we receive
136          * a CE interrupt from SHUB or when the timer routine decides
137          * we need to call SAL to check for CEs.
138          */
139
140         /* CALL SAL_LOG_CE */
141
142         ia64_sn_plat_cpei_handler();
143 }
144
145
146 static void
147 sn_cpei_timer_handler(unsigned long dummy) {
148         sn_cpei_handler(-1, NULL, NULL);
149         mod_timer(&sn_cpei_timer, jiffies + CPEI_INTERVAL);
150 }
151
152 void
153 sn_init_cpei_timer() {
154         sn_cpei_timer.expires = jiffies + CPEI_INTERVAL;
155         sn_cpei_timer.function = sn_cpei_timer_handler;
156         add_timer(&sn_cpei_timer);
157 }
158
159 static int
160 sn_platform_plat_specific_err_print(const u8 *sect_header, u8 **oemdata, u64 *oemdata_size)
161 {
162         sal_log_plat_specific_err_info_t *psei = (sal_log_plat_specific_err_info_t *)sect_header;
163         if (!psei->valid.oem_data)
164                 return 0;
165         down(&sn_oemdata_mutex);
166         sn_oemdata = oemdata;
167         sn_oemdata_size = oemdata_size;
168         ia64_sn_plat_specific_err_print(print_hook, (char *)psei);
169         up(&sn_oemdata_mutex);
170         return 0;
171 }
172
173 /* Callback when userspace salinfo wants to decode oem data via the platform
174  * kernel and/or prom.
175  */
176 int sn_salinfo_platform_oemdata(const u8 *sect_header, u8 **oemdata, u64 *oemdata_size)
177 {
178         efi_guid_t guid = *(efi_guid_t *)sect_header;
179         *oemdata_size = 0;
180         sn_oemdata_bufsize = 0;
181         vfree(*oemdata);
182         *oemdata = NULL;
183         if (efi_guidcmp(guid, SAL_PLAT_SPECIFIC_ERR_SECT_GUID) == 0)
184                 return sn_platform_plat_specific_err_print(sect_header, oemdata, oemdata_size);
185         return 0;
186 }
187
188 static int __init sn_salinfo_init(void)
189 {
190         salinfo_platform_oemdata = &sn_salinfo_platform_oemdata;
191         return 0;
192 }
193
194 module_init(sn_salinfo_init)
195
196