1 /* Copyright 2015 IBM Corp.
2 *
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
12 * implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17 #include <errorlog.h>
18 #include <ipmi.h>
19 #include <pel.h>
20 #include <platform.h>
21 #include <processor.h>
22 #include <skiboot.h>
23 #include <stack.h>
24 #include <timebase.h>
25
26 /* Use same attention SRC for BMC based machine */
27 DEFINE_LOG_ENTRY(OPAL_RC_ATTN, OPAL_PLATFORM_ERR_EVT,
28 OPAL_ATTN, OPAL_PLATFORM_FIRMWARE,
29 OPAL_ERROR_PANIC, OPAL_ABNORMAL_POWER_OFF);
30
31 /* Maximum buffer size to capture backtrace and other useful information */
32 #define IPMI_TI_BUFFER_SIZE (IPMI_MAX_PEL_SIZE - PEL_MIN_SIZE)
33 static char ti_buffer[IPMI_TI_BUFFER_SIZE];
34
35 #define STACK_BUF_ENTRIES 20
36 static struct bt_entry bt_buf[STACK_BUF_ENTRIES];
37
38 /* Log eSEL event with OPAL backtrace */
ipmi_log_terminate_event(const char * msg)39 static void ipmi_log_terminate_event(const char *msg)
40 {
41 struct bt_metadata metadata;
42 unsigned int ti_len;
43 unsigned int ti_size;
44 struct errorlog *elog_buf;
45
46 /* Fill OPAL version */
47 ti_len = snprintf(ti_buffer, IPMI_TI_BUFFER_SIZE,
48 "OPAL version : %s\n", version);
49
50 /* File information */
51 ti_len += snprintf(ti_buffer + ti_len, IPMI_TI_BUFFER_SIZE - ti_len,
52 "File info : %s\n", msg);
53 ti_size = IPMI_TI_BUFFER_SIZE - ti_len;
54
55 /* Backtrace */
56 backtrace_create(bt_buf, STACK_BUF_ENTRIES, &metadata);
57 metadata.token = OPAL_LAST + 1;
58 backtrace_print(bt_buf, &metadata, ti_buffer + ti_len, &ti_size, true);
59
60 /* Create eSEL event and commit */
61 elog_buf = opal_elog_create(&e_info(OPAL_RC_ATTN), 0);
62 log_append_data(elog_buf, (char *)&ti_buffer, ti_len + ti_size);
63 log_commit(elog_buf);
64 }
65
ipmi_terminate(const char * msg)66 void __attribute__((noreturn)) ipmi_terminate(const char *msg)
67 {
68 /* Terminate called before initializing IPMI (early abort) */
69 if (!ipmi_present()) {
70 if (platform.cec_reboot)
71 platform.cec_reboot();
72 goto out;
73 }
74
75 /* Log eSEL event */
76 ipmi_log_terminate_event(msg);
77
78 /* Reboot call */
79 if (platform.cec_reboot)
80 platform.cec_reboot();
81
82 out:
83 while (1)
84 time_wait_ms(100);
85 }
86