1*4882a593Smuzhiyun // SPDX-License-Identifier: GPL-2.0-or-later
2*4882a593Smuzhiyun /*
3*4882a593Smuzhiyun * OPAL hypervisor Maintenance interrupt handling support in PowerNV.
4*4882a593Smuzhiyun *
5*4882a593Smuzhiyun * Copyright 2014 IBM Corporation
6*4882a593Smuzhiyun * Author: Mahesh Salgaonkar <mahesh@linux.vnet.ibm.com>
7*4882a593Smuzhiyun */
8*4882a593Smuzhiyun
9*4882a593Smuzhiyun #undef DEBUG
10*4882a593Smuzhiyun
11*4882a593Smuzhiyun #include <linux/kernel.h>
12*4882a593Smuzhiyun #include <linux/init.h>
13*4882a593Smuzhiyun #include <linux/of.h>
14*4882a593Smuzhiyun #include <linux/mm.h>
15*4882a593Smuzhiyun #include <linux/slab.h>
16*4882a593Smuzhiyun
17*4882a593Smuzhiyun #include <asm/opal.h>
18*4882a593Smuzhiyun #include <asm/cputable.h>
19*4882a593Smuzhiyun #include <asm/machdep.h>
20*4882a593Smuzhiyun
21*4882a593Smuzhiyun #include "powernv.h"
22*4882a593Smuzhiyun
23*4882a593Smuzhiyun static int opal_hmi_handler_nb_init;
24*4882a593Smuzhiyun struct OpalHmiEvtNode {
25*4882a593Smuzhiyun struct list_head list;
26*4882a593Smuzhiyun struct OpalHMIEvent hmi_evt;
27*4882a593Smuzhiyun };
28*4882a593Smuzhiyun
29*4882a593Smuzhiyun struct xstop_reason {
30*4882a593Smuzhiyun uint32_t xstop_reason;
31*4882a593Smuzhiyun const char *unit_failed;
32*4882a593Smuzhiyun const char *description;
33*4882a593Smuzhiyun };
34*4882a593Smuzhiyun
35*4882a593Smuzhiyun static LIST_HEAD(opal_hmi_evt_list);
36*4882a593Smuzhiyun static DEFINE_SPINLOCK(opal_hmi_evt_lock);
37*4882a593Smuzhiyun
print_core_checkstop_reason(const char * level,struct OpalHMIEvent * hmi_evt)38*4882a593Smuzhiyun static void print_core_checkstop_reason(const char *level,
39*4882a593Smuzhiyun struct OpalHMIEvent *hmi_evt)
40*4882a593Smuzhiyun {
41*4882a593Smuzhiyun int i;
42*4882a593Smuzhiyun static const struct xstop_reason xstop_reason[] = {
43*4882a593Smuzhiyun { CORE_CHECKSTOP_IFU_REGFILE, "IFU",
44*4882a593Smuzhiyun "RegFile core check stop" },
45*4882a593Smuzhiyun { CORE_CHECKSTOP_IFU_LOGIC, "IFU", "Logic core check stop" },
46*4882a593Smuzhiyun { CORE_CHECKSTOP_PC_DURING_RECOV, "PC",
47*4882a593Smuzhiyun "Core checkstop during recovery" },
48*4882a593Smuzhiyun { CORE_CHECKSTOP_ISU_REGFILE, "ISU",
49*4882a593Smuzhiyun "RegFile core check stop (mapper error)" },
50*4882a593Smuzhiyun { CORE_CHECKSTOP_ISU_LOGIC, "ISU", "Logic core check stop" },
51*4882a593Smuzhiyun { CORE_CHECKSTOP_FXU_LOGIC, "FXU", "Logic core check stop" },
52*4882a593Smuzhiyun { CORE_CHECKSTOP_VSU_LOGIC, "VSU", "Logic core check stop" },
53*4882a593Smuzhiyun { CORE_CHECKSTOP_PC_RECOV_IN_MAINT_MODE, "PC",
54*4882a593Smuzhiyun "Recovery in maintenance mode" },
55*4882a593Smuzhiyun { CORE_CHECKSTOP_LSU_REGFILE, "LSU",
56*4882a593Smuzhiyun "RegFile core check stop" },
57*4882a593Smuzhiyun { CORE_CHECKSTOP_PC_FWD_PROGRESS, "PC",
58*4882a593Smuzhiyun "Forward Progress Error" },
59*4882a593Smuzhiyun { CORE_CHECKSTOP_LSU_LOGIC, "LSU", "Logic core check stop" },
60*4882a593Smuzhiyun { CORE_CHECKSTOP_PC_LOGIC, "PC", "Logic core check stop" },
61*4882a593Smuzhiyun { CORE_CHECKSTOP_PC_HYP_RESOURCE, "PC",
62*4882a593Smuzhiyun "Hypervisor Resource error - core check stop" },
63*4882a593Smuzhiyun { CORE_CHECKSTOP_PC_HANG_RECOV_FAILED, "PC",
64*4882a593Smuzhiyun "Hang Recovery Failed (core check stop)" },
65*4882a593Smuzhiyun { CORE_CHECKSTOP_PC_AMBI_HANG_DETECTED, "PC",
66*4882a593Smuzhiyun "Ambiguous Hang Detected (unknown source)" },
67*4882a593Smuzhiyun { CORE_CHECKSTOP_PC_DEBUG_TRIG_ERR_INJ, "PC",
68*4882a593Smuzhiyun "Debug Trigger Error inject" },
69*4882a593Smuzhiyun { CORE_CHECKSTOP_PC_SPRD_HYP_ERR_INJ, "PC",
70*4882a593Smuzhiyun "Hypervisor check stop via SPRC/SPRD" },
71*4882a593Smuzhiyun };
72*4882a593Smuzhiyun
73*4882a593Smuzhiyun /* Validity check */
74*4882a593Smuzhiyun if (!hmi_evt->u.xstop_error.xstop_reason) {
75*4882a593Smuzhiyun printk("%s Unknown Core check stop.\n", level);
76*4882a593Smuzhiyun return;
77*4882a593Smuzhiyun }
78*4882a593Smuzhiyun
79*4882a593Smuzhiyun printk("%s CPU PIR: %08x\n", level,
80*4882a593Smuzhiyun be32_to_cpu(hmi_evt->u.xstop_error.u.pir));
81*4882a593Smuzhiyun for (i = 0; i < ARRAY_SIZE(xstop_reason); i++)
82*4882a593Smuzhiyun if (be32_to_cpu(hmi_evt->u.xstop_error.xstop_reason) &
83*4882a593Smuzhiyun xstop_reason[i].xstop_reason)
84*4882a593Smuzhiyun printk("%s [Unit: %-3s] %s\n", level,
85*4882a593Smuzhiyun xstop_reason[i].unit_failed,
86*4882a593Smuzhiyun xstop_reason[i].description);
87*4882a593Smuzhiyun }
88*4882a593Smuzhiyun
print_nx_checkstop_reason(const char * level,struct OpalHMIEvent * hmi_evt)89*4882a593Smuzhiyun static void print_nx_checkstop_reason(const char *level,
90*4882a593Smuzhiyun struct OpalHMIEvent *hmi_evt)
91*4882a593Smuzhiyun {
92*4882a593Smuzhiyun int i;
93*4882a593Smuzhiyun static const struct xstop_reason xstop_reason[] = {
94*4882a593Smuzhiyun { NX_CHECKSTOP_SHM_INVAL_STATE_ERR, "DMA & Engine",
95*4882a593Smuzhiyun "SHM invalid state error" },
96*4882a593Smuzhiyun { NX_CHECKSTOP_DMA_INVAL_STATE_ERR_1, "DMA & Engine",
97*4882a593Smuzhiyun "DMA invalid state error bit 15" },
98*4882a593Smuzhiyun { NX_CHECKSTOP_DMA_INVAL_STATE_ERR_2, "DMA & Engine",
99*4882a593Smuzhiyun "DMA invalid state error bit 16" },
100*4882a593Smuzhiyun { NX_CHECKSTOP_DMA_CH0_INVAL_STATE_ERR, "DMA & Engine",
101*4882a593Smuzhiyun "Channel 0 invalid state error" },
102*4882a593Smuzhiyun { NX_CHECKSTOP_DMA_CH1_INVAL_STATE_ERR, "DMA & Engine",
103*4882a593Smuzhiyun "Channel 1 invalid state error" },
104*4882a593Smuzhiyun { NX_CHECKSTOP_DMA_CH2_INVAL_STATE_ERR, "DMA & Engine",
105*4882a593Smuzhiyun "Channel 2 invalid state error" },
106*4882a593Smuzhiyun { NX_CHECKSTOP_DMA_CH3_INVAL_STATE_ERR, "DMA & Engine",
107*4882a593Smuzhiyun "Channel 3 invalid state error" },
108*4882a593Smuzhiyun { NX_CHECKSTOP_DMA_CH4_INVAL_STATE_ERR, "DMA & Engine",
109*4882a593Smuzhiyun "Channel 4 invalid state error" },
110*4882a593Smuzhiyun { NX_CHECKSTOP_DMA_CH5_INVAL_STATE_ERR, "DMA & Engine",
111*4882a593Smuzhiyun "Channel 5 invalid state error" },
112*4882a593Smuzhiyun { NX_CHECKSTOP_DMA_CH6_INVAL_STATE_ERR, "DMA & Engine",
113*4882a593Smuzhiyun "Channel 6 invalid state error" },
114*4882a593Smuzhiyun { NX_CHECKSTOP_DMA_CH7_INVAL_STATE_ERR, "DMA & Engine",
115*4882a593Smuzhiyun "Channel 7 invalid state error" },
116*4882a593Smuzhiyun { NX_CHECKSTOP_DMA_CRB_UE, "DMA & Engine",
117*4882a593Smuzhiyun "UE error on CRB(CSB address, CCB)" },
118*4882a593Smuzhiyun { NX_CHECKSTOP_DMA_CRB_SUE, "DMA & Engine",
119*4882a593Smuzhiyun "SUE error on CRB(CSB address, CCB)" },
120*4882a593Smuzhiyun { NX_CHECKSTOP_PBI_ISN_UE, "PowerBus Interface",
121*4882a593Smuzhiyun "CRB Kill ISN received while holding ISN with UE error" },
122*4882a593Smuzhiyun };
123*4882a593Smuzhiyun
124*4882a593Smuzhiyun /* Validity check */
125*4882a593Smuzhiyun if (!hmi_evt->u.xstop_error.xstop_reason) {
126*4882a593Smuzhiyun printk("%s Unknown NX check stop.\n", level);
127*4882a593Smuzhiyun return;
128*4882a593Smuzhiyun }
129*4882a593Smuzhiyun
130*4882a593Smuzhiyun printk("%s NX checkstop on CHIP ID: %x\n", level,
131*4882a593Smuzhiyun be32_to_cpu(hmi_evt->u.xstop_error.u.chip_id));
132*4882a593Smuzhiyun for (i = 0; i < ARRAY_SIZE(xstop_reason); i++)
133*4882a593Smuzhiyun if (be32_to_cpu(hmi_evt->u.xstop_error.xstop_reason) &
134*4882a593Smuzhiyun xstop_reason[i].xstop_reason)
135*4882a593Smuzhiyun printk("%s [Unit: %-3s] %s\n", level,
136*4882a593Smuzhiyun xstop_reason[i].unit_failed,
137*4882a593Smuzhiyun xstop_reason[i].description);
138*4882a593Smuzhiyun }
139*4882a593Smuzhiyun
print_npu_checkstop_reason(const char * level,struct OpalHMIEvent * hmi_evt)140*4882a593Smuzhiyun static void print_npu_checkstop_reason(const char *level,
141*4882a593Smuzhiyun struct OpalHMIEvent *hmi_evt)
142*4882a593Smuzhiyun {
143*4882a593Smuzhiyun uint8_t reason, reason_count, i;
144*4882a593Smuzhiyun
145*4882a593Smuzhiyun /*
146*4882a593Smuzhiyun * We may not have a checkstop reason on some combination of
147*4882a593Smuzhiyun * hardware and/or skiboot version
148*4882a593Smuzhiyun */
149*4882a593Smuzhiyun if (!hmi_evt->u.xstop_error.xstop_reason) {
150*4882a593Smuzhiyun printk("%s NPU checkstop on chip %x\n", level,
151*4882a593Smuzhiyun be32_to_cpu(hmi_evt->u.xstop_error.u.chip_id));
152*4882a593Smuzhiyun return;
153*4882a593Smuzhiyun }
154*4882a593Smuzhiyun
155*4882a593Smuzhiyun /*
156*4882a593Smuzhiyun * NPU2 has 3 FIRs. Reason encoded on a byte as:
157*4882a593Smuzhiyun * 2 bits for the FIR number
158*4882a593Smuzhiyun * 6 bits for the bit number
159*4882a593Smuzhiyun * It may be possible to find several reasons.
160*4882a593Smuzhiyun *
161*4882a593Smuzhiyun * We don't display a specific message per FIR bit as there
162*4882a593Smuzhiyun * are too many and most are meaningless without the workbook
163*4882a593Smuzhiyun * and/or hw team help anyway.
164*4882a593Smuzhiyun */
165*4882a593Smuzhiyun reason_count = sizeof(hmi_evt->u.xstop_error.xstop_reason) /
166*4882a593Smuzhiyun sizeof(reason);
167*4882a593Smuzhiyun for (i = 0; i < reason_count; i++) {
168*4882a593Smuzhiyun reason = (hmi_evt->u.xstop_error.xstop_reason >> (8 * i)) & 0xFF;
169*4882a593Smuzhiyun if (reason)
170*4882a593Smuzhiyun printk("%s NPU checkstop on chip %x: FIR%d bit %d is set\n",
171*4882a593Smuzhiyun level,
172*4882a593Smuzhiyun be32_to_cpu(hmi_evt->u.xstop_error.u.chip_id),
173*4882a593Smuzhiyun reason >> 6, reason & 0x3F);
174*4882a593Smuzhiyun }
175*4882a593Smuzhiyun }
176*4882a593Smuzhiyun
print_checkstop_reason(const char * level,struct OpalHMIEvent * hmi_evt)177*4882a593Smuzhiyun static void print_checkstop_reason(const char *level,
178*4882a593Smuzhiyun struct OpalHMIEvent *hmi_evt)
179*4882a593Smuzhiyun {
180*4882a593Smuzhiyun uint8_t type = hmi_evt->u.xstop_error.xstop_type;
181*4882a593Smuzhiyun switch (type) {
182*4882a593Smuzhiyun case CHECKSTOP_TYPE_CORE:
183*4882a593Smuzhiyun print_core_checkstop_reason(level, hmi_evt);
184*4882a593Smuzhiyun break;
185*4882a593Smuzhiyun case CHECKSTOP_TYPE_NX:
186*4882a593Smuzhiyun print_nx_checkstop_reason(level, hmi_evt);
187*4882a593Smuzhiyun break;
188*4882a593Smuzhiyun case CHECKSTOP_TYPE_NPU:
189*4882a593Smuzhiyun print_npu_checkstop_reason(level, hmi_evt);
190*4882a593Smuzhiyun break;
191*4882a593Smuzhiyun default:
192*4882a593Smuzhiyun printk("%s Unknown Malfunction Alert of type %d\n",
193*4882a593Smuzhiyun level, type);
194*4882a593Smuzhiyun break;
195*4882a593Smuzhiyun }
196*4882a593Smuzhiyun }
197*4882a593Smuzhiyun
print_hmi_event_info(struct OpalHMIEvent * hmi_evt)198*4882a593Smuzhiyun static void print_hmi_event_info(struct OpalHMIEvent *hmi_evt)
199*4882a593Smuzhiyun {
200*4882a593Smuzhiyun const char *level, *sevstr, *error_info;
201*4882a593Smuzhiyun static const char *hmi_error_types[] = {
202*4882a593Smuzhiyun "Malfunction Alert",
203*4882a593Smuzhiyun "Processor Recovery done",
204*4882a593Smuzhiyun "Processor recovery occurred again",
205*4882a593Smuzhiyun "Processor recovery occurred for masked error",
206*4882a593Smuzhiyun "Timer facility experienced an error",
207*4882a593Smuzhiyun "TFMR SPR is corrupted",
208*4882a593Smuzhiyun "UPS (Uninterrupted Power System) Overflow indication",
209*4882a593Smuzhiyun "An XSCOM operation failure",
210*4882a593Smuzhiyun "An XSCOM operation completed",
211*4882a593Smuzhiyun "SCOM has set a reserved FIR bit to cause recovery",
212*4882a593Smuzhiyun "Debug trigger has set a reserved FIR bit to cause recovery",
213*4882a593Smuzhiyun "A hypervisor resource error occurred",
214*4882a593Smuzhiyun "CAPP recovery process is in progress",
215*4882a593Smuzhiyun };
216*4882a593Smuzhiyun
217*4882a593Smuzhiyun /* Print things out */
218*4882a593Smuzhiyun if (hmi_evt->version < OpalHMIEvt_V1) {
219*4882a593Smuzhiyun pr_err("HMI Interrupt, Unknown event version %d !\n",
220*4882a593Smuzhiyun hmi_evt->version);
221*4882a593Smuzhiyun return;
222*4882a593Smuzhiyun }
223*4882a593Smuzhiyun switch (hmi_evt->severity) {
224*4882a593Smuzhiyun case OpalHMI_SEV_NO_ERROR:
225*4882a593Smuzhiyun level = KERN_INFO;
226*4882a593Smuzhiyun sevstr = "Harmless";
227*4882a593Smuzhiyun break;
228*4882a593Smuzhiyun case OpalHMI_SEV_WARNING:
229*4882a593Smuzhiyun level = KERN_WARNING;
230*4882a593Smuzhiyun sevstr = "";
231*4882a593Smuzhiyun break;
232*4882a593Smuzhiyun case OpalHMI_SEV_ERROR_SYNC:
233*4882a593Smuzhiyun level = KERN_ERR;
234*4882a593Smuzhiyun sevstr = "Severe";
235*4882a593Smuzhiyun break;
236*4882a593Smuzhiyun case OpalHMI_SEV_FATAL:
237*4882a593Smuzhiyun default:
238*4882a593Smuzhiyun level = KERN_ERR;
239*4882a593Smuzhiyun sevstr = "Fatal";
240*4882a593Smuzhiyun break;
241*4882a593Smuzhiyun }
242*4882a593Smuzhiyun
243*4882a593Smuzhiyun printk("%s%s Hypervisor Maintenance interrupt [%s]\n",
244*4882a593Smuzhiyun level, sevstr,
245*4882a593Smuzhiyun hmi_evt->disposition == OpalHMI_DISPOSITION_RECOVERED ?
246*4882a593Smuzhiyun "Recovered" : "Not recovered");
247*4882a593Smuzhiyun error_info = hmi_evt->type < ARRAY_SIZE(hmi_error_types) ?
248*4882a593Smuzhiyun hmi_error_types[hmi_evt->type]
249*4882a593Smuzhiyun : "Unknown";
250*4882a593Smuzhiyun printk("%s Error detail: %s\n", level, error_info);
251*4882a593Smuzhiyun printk("%s HMER: %016llx\n", level, be64_to_cpu(hmi_evt->hmer));
252*4882a593Smuzhiyun if ((hmi_evt->type == OpalHMI_ERROR_TFAC) ||
253*4882a593Smuzhiyun (hmi_evt->type == OpalHMI_ERROR_TFMR_PARITY))
254*4882a593Smuzhiyun printk("%s TFMR: %016llx\n", level,
255*4882a593Smuzhiyun be64_to_cpu(hmi_evt->tfmr));
256*4882a593Smuzhiyun
257*4882a593Smuzhiyun if (hmi_evt->version < OpalHMIEvt_V2)
258*4882a593Smuzhiyun return;
259*4882a593Smuzhiyun
260*4882a593Smuzhiyun /* OpalHMIEvt_V2 and above provides reason for malfunction alert. */
261*4882a593Smuzhiyun if (hmi_evt->type == OpalHMI_ERROR_MALFUNC_ALERT)
262*4882a593Smuzhiyun print_checkstop_reason(level, hmi_evt);
263*4882a593Smuzhiyun }
264*4882a593Smuzhiyun
hmi_event_handler(struct work_struct * work)265*4882a593Smuzhiyun static void hmi_event_handler(struct work_struct *work)
266*4882a593Smuzhiyun {
267*4882a593Smuzhiyun unsigned long flags;
268*4882a593Smuzhiyun struct OpalHMIEvent *hmi_evt;
269*4882a593Smuzhiyun struct OpalHmiEvtNode *msg_node;
270*4882a593Smuzhiyun uint8_t disposition;
271*4882a593Smuzhiyun struct opal_msg msg;
272*4882a593Smuzhiyun int unrecoverable = 0;
273*4882a593Smuzhiyun
274*4882a593Smuzhiyun spin_lock_irqsave(&opal_hmi_evt_lock, flags);
275*4882a593Smuzhiyun while (!list_empty(&opal_hmi_evt_list)) {
276*4882a593Smuzhiyun msg_node = list_entry(opal_hmi_evt_list.next,
277*4882a593Smuzhiyun struct OpalHmiEvtNode, list);
278*4882a593Smuzhiyun list_del(&msg_node->list);
279*4882a593Smuzhiyun spin_unlock_irqrestore(&opal_hmi_evt_lock, flags);
280*4882a593Smuzhiyun
281*4882a593Smuzhiyun hmi_evt = (struct OpalHMIEvent *) &msg_node->hmi_evt;
282*4882a593Smuzhiyun print_hmi_event_info(hmi_evt);
283*4882a593Smuzhiyun disposition = hmi_evt->disposition;
284*4882a593Smuzhiyun kfree(msg_node);
285*4882a593Smuzhiyun
286*4882a593Smuzhiyun /*
287*4882a593Smuzhiyun * Check if HMI event has been recovered or not. If not
288*4882a593Smuzhiyun * then kernel can't continue, we need to panic.
289*4882a593Smuzhiyun * But before we do that, display all the HMI event
290*4882a593Smuzhiyun * available on the list and set unrecoverable flag to 1.
291*4882a593Smuzhiyun */
292*4882a593Smuzhiyun if (disposition != OpalHMI_DISPOSITION_RECOVERED)
293*4882a593Smuzhiyun unrecoverable = 1;
294*4882a593Smuzhiyun
295*4882a593Smuzhiyun spin_lock_irqsave(&opal_hmi_evt_lock, flags);
296*4882a593Smuzhiyun }
297*4882a593Smuzhiyun spin_unlock_irqrestore(&opal_hmi_evt_lock, flags);
298*4882a593Smuzhiyun
299*4882a593Smuzhiyun if (unrecoverable) {
300*4882a593Smuzhiyun /* Pull all HMI events from OPAL before we panic. */
301*4882a593Smuzhiyun while (opal_get_msg(__pa(&msg), sizeof(msg)) == OPAL_SUCCESS) {
302*4882a593Smuzhiyun u32 type;
303*4882a593Smuzhiyun
304*4882a593Smuzhiyun type = be32_to_cpu(msg.msg_type);
305*4882a593Smuzhiyun
306*4882a593Smuzhiyun /* skip if not HMI event */
307*4882a593Smuzhiyun if (type != OPAL_MSG_HMI_EVT)
308*4882a593Smuzhiyun continue;
309*4882a593Smuzhiyun
310*4882a593Smuzhiyun /* HMI event info starts from param[0] */
311*4882a593Smuzhiyun hmi_evt = (struct OpalHMIEvent *)&msg.params[0];
312*4882a593Smuzhiyun print_hmi_event_info(hmi_evt);
313*4882a593Smuzhiyun }
314*4882a593Smuzhiyun
315*4882a593Smuzhiyun pnv_platform_error_reboot(NULL, "Unrecoverable HMI exception");
316*4882a593Smuzhiyun }
317*4882a593Smuzhiyun }
318*4882a593Smuzhiyun
319*4882a593Smuzhiyun static DECLARE_WORK(hmi_event_work, hmi_event_handler);
320*4882a593Smuzhiyun /*
321*4882a593Smuzhiyun * opal_handle_hmi_event - notifier handler that queues up HMI events
322*4882a593Smuzhiyun * to be preocessed later.
323*4882a593Smuzhiyun */
opal_handle_hmi_event(struct notifier_block * nb,unsigned long msg_type,void * msg)324*4882a593Smuzhiyun static int opal_handle_hmi_event(struct notifier_block *nb,
325*4882a593Smuzhiyun unsigned long msg_type, void *msg)
326*4882a593Smuzhiyun {
327*4882a593Smuzhiyun unsigned long flags;
328*4882a593Smuzhiyun struct OpalHMIEvent *hmi_evt;
329*4882a593Smuzhiyun struct opal_msg *hmi_msg = msg;
330*4882a593Smuzhiyun struct OpalHmiEvtNode *msg_node;
331*4882a593Smuzhiyun
332*4882a593Smuzhiyun /* Sanity Checks */
333*4882a593Smuzhiyun if (msg_type != OPAL_MSG_HMI_EVT)
334*4882a593Smuzhiyun return 0;
335*4882a593Smuzhiyun
336*4882a593Smuzhiyun /* HMI event info starts from param[0] */
337*4882a593Smuzhiyun hmi_evt = (struct OpalHMIEvent *)&hmi_msg->params[0];
338*4882a593Smuzhiyun
339*4882a593Smuzhiyun /* Delay the logging of HMI events to workqueue. */
340*4882a593Smuzhiyun msg_node = kzalloc(sizeof(*msg_node), GFP_ATOMIC);
341*4882a593Smuzhiyun if (!msg_node) {
342*4882a593Smuzhiyun pr_err("HMI: out of memory, Opal message event not handled\n");
343*4882a593Smuzhiyun return -ENOMEM;
344*4882a593Smuzhiyun }
345*4882a593Smuzhiyun memcpy(&msg_node->hmi_evt, hmi_evt, sizeof(*hmi_evt));
346*4882a593Smuzhiyun
347*4882a593Smuzhiyun spin_lock_irqsave(&opal_hmi_evt_lock, flags);
348*4882a593Smuzhiyun list_add(&msg_node->list, &opal_hmi_evt_list);
349*4882a593Smuzhiyun spin_unlock_irqrestore(&opal_hmi_evt_lock, flags);
350*4882a593Smuzhiyun
351*4882a593Smuzhiyun schedule_work(&hmi_event_work);
352*4882a593Smuzhiyun return 0;
353*4882a593Smuzhiyun }
354*4882a593Smuzhiyun
355*4882a593Smuzhiyun static struct notifier_block opal_hmi_handler_nb = {
356*4882a593Smuzhiyun .notifier_call = opal_handle_hmi_event,
357*4882a593Smuzhiyun .next = NULL,
358*4882a593Smuzhiyun .priority = 0,
359*4882a593Smuzhiyun };
360*4882a593Smuzhiyun
opal_hmi_handler_init(void)361*4882a593Smuzhiyun int __init opal_hmi_handler_init(void)
362*4882a593Smuzhiyun {
363*4882a593Smuzhiyun int ret;
364*4882a593Smuzhiyun
365*4882a593Smuzhiyun if (!opal_hmi_handler_nb_init) {
366*4882a593Smuzhiyun ret = opal_message_notifier_register(
367*4882a593Smuzhiyun OPAL_MSG_HMI_EVT, &opal_hmi_handler_nb);
368*4882a593Smuzhiyun if (ret) {
369*4882a593Smuzhiyun pr_err("%s: Can't register OPAL event notifier (%d)\n",
370*4882a593Smuzhiyun __func__, ret);
371*4882a593Smuzhiyun return ret;
372*4882a593Smuzhiyun }
373*4882a593Smuzhiyun opal_hmi_handler_nb_init = 1;
374*4882a593Smuzhiyun }
375*4882a593Smuzhiyun return 0;
376*4882a593Smuzhiyun }
377