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
6 * Copyright (c) 2000-2004 Silicon Graphics, Inc. All Rights Reserved.
9 #include <linux/types.h>
10 #include <linux/kernel.h>
11 #include <linux/timer.h>
12 #include <linux/vmalloc.h>
15 #include <asm/sn/sn_sal.h>
18 * Interval for calling SAL to poll for errors that do NOT cause error
19 * interrupts. SAL will raise a CPEI if any errors are present that
22 #define CPEI_INTERVAL (5*HZ)
24 struct timer_list sn_cpei_timer
;
25 void sn_init_cpei_timer(void);
27 /* Printing oemdata from mca uses data that is not passed through SAL, it is
28 * global. Only one user at a time.
30 static DECLARE_MUTEX(sn_oemdata_mutex
);
31 static u8
**sn_oemdata
;
32 static u64
*sn_oemdata_size
, sn_oemdata_bufsize
;
37 * This function is the callback routine that SAL calls to log error
38 * info for platform errors. buf is appended to sn_oemdata, resizing as
40 * Note: this is a SAL to OS callback, running under the same rules as the SAL
41 * code. SAL calls are run with preempt disabled so this routine must not
42 * sleep. vmalloc can sleep so print_hook cannot resize the output buffer
43 * itself, instead it must set the required size and return to let the caller
44 * resize the buffer then redrive the SAL call.
46 static int print_hook(const char *fmt
, ...)
52 vsnprintf(buf
, sizeof(buf
), fmt
, args
);
55 if (*sn_oemdata_size
+ len
<= sn_oemdata_bufsize
)
56 memcpy(*sn_oemdata
+ *sn_oemdata_size
, buf
, len
);
57 *sn_oemdata_size
+= len
;
61 static void sn_cpei_handler(int irq
, void *devid
, struct pt_regs
*regs
)
64 * this function's sole purpose is to call SAL when we receive
65 * a CE interrupt from SHUB or when the timer routine decides
66 * we need to call SAL to check for CEs.
71 ia64_sn_plat_cpei_handler();
74 static void sn_cpei_timer_handler(unsigned long dummy
)
76 sn_cpei_handler(-1, NULL
, NULL
);
77 mod_timer(&sn_cpei_timer
, jiffies
+ CPEI_INTERVAL
);
80 void sn_init_cpei_timer(void)
82 init_timer(&sn_cpei_timer
);
83 sn_cpei_timer
.expires
= jiffies
+ CPEI_INTERVAL
;
84 sn_cpei_timer
.function
= sn_cpei_timer_handler
;
85 add_timer(&sn_cpei_timer
);
89 sn_platform_plat_specific_err_print(const u8
* sect_header
, u8
** oemdata
,
92 down(&sn_oemdata_mutex
);
94 sn_oemdata_size
= oemdata_size
;
95 sn_oemdata_bufsize
= 0;
96 *sn_oemdata_size
= PAGE_SIZE
; /* first guess at how much data will be generated */
97 while (*sn_oemdata_size
> sn_oemdata_bufsize
) {
98 u8
*newbuf
= vmalloc(*sn_oemdata_size
);
100 printk(KERN_ERR
"%s: unable to extend sn_oemdata\n",
105 *sn_oemdata
= newbuf
;
106 sn_oemdata_bufsize
= *sn_oemdata_size
;
107 *sn_oemdata_size
= 0;
108 ia64_sn_plat_specific_err_print(print_hook
, (char *)sect_header
);
110 up(&sn_oemdata_mutex
);
114 /* Callback when userspace salinfo wants to decode oem data via the platform
115 * kernel and/or prom.
117 int sn_salinfo_platform_oemdata(const u8
*sect_header
, u8
**oemdata
, u64
*oemdata_size
)
119 efi_guid_t guid
= *(efi_guid_t
*)sect_header
;
124 if (efi_guidcmp(guid
, SAL_PLAT_SPECIFIC_ERR_SECT_GUID
) == 0) {
125 sal_log_plat_specific_err_info_t
*psei
= (sal_log_plat_specific_err_info_t
*)sect_header
;
126 valid
= psei
->valid
.oem_data
;
127 } else if (efi_guidcmp(guid
, SAL_PLAT_MEM_DEV_ERR_SECT_GUID
) == 0) {
128 sal_log_mem_dev_err_info_t
*mdei
= (sal_log_mem_dev_err_info_t
*)sect_header
;
129 valid
= mdei
->valid
.oem_data
;
132 return sn_platform_plat_specific_err_print(sect_header
, oemdata
, oemdata_size
);
137 static int __init
sn_salinfo_init(void)
139 salinfo_platform_oemdata
= &sn_salinfo_platform_oemdata
;
143 module_init(sn_salinfo_init
)