2 * OPAL hypervisor Maintenance interrupt handling support in PowreNV.
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; If not, see <http://www.gnu.org/licenses/>.
17 * Copyright 2014 IBM Corporation
18 * Author: Mahesh Salgaonkar <mahesh@linux.vnet.ibm.com>
23 #include <linux/kernel.h>
24 #include <linux/init.h>
27 #include <linux/slab.h>
30 #include <asm/cputable.h>
31 #include <asm/machdep.h>
33 static int opal_hmi_handler_nb_init
;
34 struct OpalHmiEvtNode
{
35 struct list_head list
;
36 struct OpalHMIEvent hmi_evt
;
38 static LIST_HEAD(opal_hmi_evt_list
);
39 static DEFINE_SPINLOCK(opal_hmi_evt_lock
);
41 static void print_hmi_event_info(struct OpalHMIEvent
*hmi_evt
)
43 const char *level
, *sevstr
, *error_info
;
44 static const char *hmi_error_types
[] = {
46 "Processor Recovery done",
47 "Processor recovery occurred again",
48 "Processor recovery occurred for masked error",
49 "Timer facility experienced an error",
50 "TFMR SPR is corrupted",
51 "UPS (Uniterrupted Power System) Overflow indication",
52 "An XSCOM operation failure",
53 "An XSCOM operation completed",
54 "SCOM has set a reserved FIR bit to cause recovery",
55 "Debug trigger has set a reserved FIR bit to cause recovery",
56 "A hypervisor resource error occurred"
59 /* Print things out */
60 if (hmi_evt
->version
< OpalHMIEvt_V1
) {
61 pr_err("HMI Interrupt, Unknown event version %d !\n",
65 switch (hmi_evt
->severity
) {
66 case OpalHMI_SEV_NO_ERROR
:
70 case OpalHMI_SEV_WARNING
:
74 case OpalHMI_SEV_ERROR_SYNC
:
78 case OpalHMI_SEV_FATAL
:
85 printk("%s%s Hypervisor Maintenance interrupt [%s]\n",
87 hmi_evt
->disposition
== OpalHMI_DISPOSITION_RECOVERED
?
88 "Recovered" : "Not recovered");
89 error_info
= hmi_evt
->type
< ARRAY_SIZE(hmi_error_types
) ?
90 hmi_error_types
[hmi_evt
->type
]
92 printk("%s Error detail: %s\n", level
, error_info
);
93 printk("%s HMER: %016llx\n", level
, be64_to_cpu(hmi_evt
->hmer
));
94 if ((hmi_evt
->type
== OpalHMI_ERROR_TFAC
) ||
95 (hmi_evt
->type
== OpalHMI_ERROR_TFMR_PARITY
))
96 printk("%s TFMR: %016llx\n", level
,
97 be64_to_cpu(hmi_evt
->tfmr
));
100 static void hmi_event_handler(struct work_struct
*work
)
103 struct OpalHMIEvent
*hmi_evt
;
104 struct OpalHmiEvtNode
*msg_node
;
107 spin_lock_irqsave(&opal_hmi_evt_lock
, flags
);
108 while (!list_empty(&opal_hmi_evt_list
)) {
109 msg_node
= list_entry(opal_hmi_evt_list
.next
,
110 struct OpalHmiEvtNode
, list
);
111 list_del(&msg_node
->list
);
112 spin_unlock_irqrestore(&opal_hmi_evt_lock
, flags
);
114 hmi_evt
= (struct OpalHMIEvent
*) &msg_node
->hmi_evt
;
115 print_hmi_event_info(hmi_evt
);
116 disposition
= hmi_evt
->disposition
;
120 * Check if HMI event has been recovered or not. If not
121 * then we can't continue, invoke panic.
123 if (disposition
!= OpalHMI_DISPOSITION_RECOVERED
)
124 panic("Unrecoverable HMI exception");
126 spin_lock_irqsave(&opal_hmi_evt_lock
, flags
);
128 spin_unlock_irqrestore(&opal_hmi_evt_lock
, flags
);
131 static DECLARE_WORK(hmi_event_work
, hmi_event_handler
);
133 * opal_handle_hmi_event - notifier handler that queues up HMI events
134 * to be preocessed later.
136 static int opal_handle_hmi_event(struct notifier_block
*nb
,
137 unsigned long msg_type
, void *msg
)
140 struct OpalHMIEvent
*hmi_evt
;
141 struct opal_msg
*hmi_msg
= msg
;
142 struct OpalHmiEvtNode
*msg_node
;
145 if (msg_type
!= OPAL_MSG_HMI_EVT
)
148 /* HMI event info starts from param[0] */
149 hmi_evt
= (struct OpalHMIEvent
*)&hmi_msg
->params
[0];
151 /* Delay the logging of HMI events to workqueue. */
152 msg_node
= kzalloc(sizeof(*msg_node
), GFP_ATOMIC
);
154 pr_err("HMI: out of memory, Opal message event not handled\n");
157 memcpy(&msg_node
->hmi_evt
, hmi_evt
, sizeof(struct OpalHMIEvent
));
159 spin_lock_irqsave(&opal_hmi_evt_lock
, flags
);
160 list_add(&msg_node
->list
, &opal_hmi_evt_list
);
161 spin_unlock_irqrestore(&opal_hmi_evt_lock
, flags
);
163 schedule_work(&hmi_event_work
);
167 static struct notifier_block opal_hmi_handler_nb
= {
168 .notifier_call
= opal_handle_hmi_event
,
173 int __init
opal_hmi_handler_init(void)
177 if (!opal_hmi_handler_nb_init
) {
178 ret
= opal_message_notifier_register(
179 OPAL_MSG_HMI_EVT
, &opal_hmi_handler_nb
);
181 pr_err("%s: Can't register OPAL event notifier (%d)\n",
185 opal_hmi_handler_nb_init
= 1;