1 // SPDX-License-Identifier: GPL-2.0
2 // Copyright (C) 2017 Arm Ltd.
3 #define pr_fmt(fmt) "sdei: " fmt
6 #include <linux/acpi.h>
7 #include <linux/arm_sdei.h>
8 #include <linux/arm-smccc.h>
9 #include <linux/atomic.h>
10 #include <linux/bitops.h>
11 #include <linux/compiler.h>
12 #include <linux/cpuhotplug.h>
13 #include <linux/cpu.h>
14 #include <linux/cpu_pm.h>
15 #include <linux/errno.h>
16 #include <linux/hardirq.h>
17 #include <linux/kernel.h>
18 #include <linux/kprobes.h>
19 #include <linux/kvm_host.h>
20 #include <linux/list.h>
21 #include <linux/mutex.h>
22 #include <linux/notifier.h>
24 #include <linux/of_platform.h>
25 #include <linux/percpu.h>
26 #include <linux/platform_device.h>
28 #include <linux/ptrace.h>
29 #include <linux/preempt.h>
30 #include <linux/reboot.h>
31 #include <linux/slab.h>
32 #include <linux/smp.h>
33 #include <linux/spinlock.h>
36 * The call to use to reach the firmware.
38 static asmlinkage
void (*sdei_firmware_call
)(unsigned long function_id
,
39 unsigned long arg0
, unsigned long arg1
,
40 unsigned long arg2
, unsigned long arg3
,
41 unsigned long arg4
, struct arm_smccc_res
*res
);
43 /* entry point from firmware to arch asm code */
44 static unsigned long sdei_entry_point
;
46 static int sdei_hp_state
;
49 /* These three are protected by the sdei_list_lock */
50 struct list_head list
;
58 /* This pointer is handed to firmware as the event argument. */
61 struct sdei_registered_event
*registered
;
63 /* CPU private events */
64 struct sdei_registered_event __percpu
*private_registered
;
68 /* Take the mutex for any API call or modification. Take the mutex first. */
69 static DEFINE_MUTEX(sdei_events_lock
);
71 /* and then hold this when modifying the list */
72 static DEFINE_SPINLOCK(sdei_list_lock
);
73 static LIST_HEAD(sdei_list
);
75 /* Private events are registered/enabled via IPI passing one of these */
76 struct sdei_crosscall_args
{
77 struct sdei_event
*event
;
82 #define CROSSCALL_INIT(arg, event) \
85 arg.first_error = 0; \
86 atomic_set(&arg.errors, 0); \
89 static inline int sdei_do_local_call(smp_call_func_t fn
,
90 struct sdei_event
*event
)
92 struct sdei_crosscall_args arg
;
94 CROSSCALL_INIT(arg
, event
);
97 return arg
.first_error
;
100 static inline int sdei_do_cross_call(smp_call_func_t fn
,
101 struct sdei_event
*event
)
103 struct sdei_crosscall_args arg
;
105 CROSSCALL_INIT(arg
, event
);
106 on_each_cpu(fn
, &arg
, true);
108 return arg
.first_error
;
112 sdei_cross_call_return(struct sdei_crosscall_args
*arg
, int err
)
114 if (err
&& (atomic_inc_return(&arg
->errors
) == 1))
115 arg
->first_error
= err
;
118 static int sdei_to_linux_errno(unsigned long sdei_err
)
121 case SDEI_NOT_SUPPORTED
:
123 case SDEI_INVALID_PARAMETERS
:
129 case SDEI_OUT_OF_RESOURCE
:
136 static int invoke_sdei_fn(unsigned long function_id
, unsigned long arg0
,
137 unsigned long arg1
, unsigned long arg2
,
138 unsigned long arg3
, unsigned long arg4
,
142 struct arm_smccc_res res
;
144 if (sdei_firmware_call
) {
145 sdei_firmware_call(function_id
, arg0
, arg1
, arg2
, arg3
, arg4
,
147 err
= sdei_to_linux_errno(res
.a0
);
150 * !sdei_firmware_call means we failed to probe or called
151 * sdei_mark_interface_broken(). -EIO is not an error returned
152 * by sdei_to_linux_errno() and is used to suppress messages
156 res
.a0
= SDEI_NOT_SUPPORTED
;
164 NOKPROBE_SYMBOL(invoke_sdei_fn
);
166 static struct sdei_event
*sdei_event_find(u32 event_num
)
168 struct sdei_event
*e
, *found
= NULL
;
170 lockdep_assert_held(&sdei_events_lock
);
172 spin_lock(&sdei_list_lock
);
173 list_for_each_entry(e
, &sdei_list
, list
) {
174 if (e
->event_num
== event_num
) {
179 spin_unlock(&sdei_list_lock
);
184 int sdei_api_event_context(u32 query
, u64
*result
)
186 return invoke_sdei_fn(SDEI_1_0_FN_SDEI_EVENT_CONTEXT
, query
, 0, 0, 0, 0,
189 NOKPROBE_SYMBOL(sdei_api_event_context
);
191 static int sdei_api_event_get_info(u32 event
, u32 info
, u64
*result
)
193 return invoke_sdei_fn(SDEI_1_0_FN_SDEI_EVENT_GET_INFO
, event
, info
, 0,
197 static struct sdei_event
*sdei_event_create(u32 event_num
,
198 sdei_event_callback
*cb
,
203 struct sdei_event
*event
;
204 struct sdei_registered_event
*reg
;
206 lockdep_assert_held(&sdei_events_lock
);
208 event
= kzalloc(sizeof(*event
), GFP_KERNEL
);
214 INIT_LIST_HEAD(&event
->list
);
215 event
->event_num
= event_num
;
217 err
= sdei_api_event_get_info(event_num
, SDEI_EVENT_INFO_EV_PRIORITY
,
221 event
->priority
= result
;
223 err
= sdei_api_event_get_info(event_num
, SDEI_EVENT_INFO_EV_TYPE
,
227 event
->type
= result
;
229 if (event
->type
== SDEI_EVENT_TYPE_SHARED
) {
230 reg
= kzalloc(sizeof(*reg
), GFP_KERNEL
);
236 reg
->event_num
= event
->event_num
;
237 reg
->priority
= event
->priority
;
240 reg
->callback_arg
= cb_arg
;
241 event
->registered
= reg
;
244 struct sdei_registered_event __percpu
*regs
;
246 regs
= alloc_percpu(struct sdei_registered_event
);
252 for_each_possible_cpu(cpu
) {
253 reg
= per_cpu_ptr(regs
, cpu
);
255 reg
->event_num
= event
->event_num
;
256 reg
->priority
= event
->priority
;
258 reg
->callback_arg
= cb_arg
;
261 event
->private_registered
= regs
;
264 spin_lock(&sdei_list_lock
);
265 list_add(&event
->list
, &sdei_list
);
266 spin_unlock(&sdei_list_lock
);
275 static void sdei_event_destroy_llocked(struct sdei_event
*event
)
277 lockdep_assert_held(&sdei_events_lock
);
278 lockdep_assert_held(&sdei_list_lock
);
280 list_del(&event
->list
);
282 if (event
->type
== SDEI_EVENT_TYPE_SHARED
)
283 kfree(event
->registered
);
285 free_percpu(event
->private_registered
);
290 static void sdei_event_destroy(struct sdei_event
*event
)
292 spin_lock(&sdei_list_lock
);
293 sdei_event_destroy_llocked(event
);
294 spin_unlock(&sdei_list_lock
);
297 static int sdei_api_get_version(u64
*version
)
299 return invoke_sdei_fn(SDEI_1_0_FN_SDEI_VERSION
, 0, 0, 0, 0, 0, version
);
302 int sdei_mask_local_cpu(void)
306 err
= invoke_sdei_fn(SDEI_1_0_FN_SDEI_PE_MASK
, 0, 0, 0, 0, 0, NULL
);
307 if (err
&& err
!= -EIO
) {
308 pr_warn_once("failed to mask CPU[%u]: %d\n",
309 smp_processor_id(), err
);
316 static void _ipi_mask_cpu(void *ignored
)
318 WARN_ON_ONCE(preemptible());
319 sdei_mask_local_cpu();
322 int sdei_unmask_local_cpu(void)
326 err
= invoke_sdei_fn(SDEI_1_0_FN_SDEI_PE_UNMASK
, 0, 0, 0, 0, 0, NULL
);
327 if (err
&& err
!= -EIO
) {
328 pr_warn_once("failed to unmask CPU[%u]: %d\n",
329 smp_processor_id(), err
);
336 static void _ipi_unmask_cpu(void *ignored
)
338 WARN_ON_ONCE(preemptible());
339 sdei_unmask_local_cpu();
342 static void _ipi_private_reset(void *ignored
)
346 WARN_ON_ONCE(preemptible());
348 err
= invoke_sdei_fn(SDEI_1_0_FN_SDEI_PRIVATE_RESET
, 0, 0, 0, 0, 0,
350 if (err
&& err
!= -EIO
)
351 pr_warn_once("failed to reset CPU[%u]: %d\n",
352 smp_processor_id(), err
);
355 static int sdei_api_shared_reset(void)
357 return invoke_sdei_fn(SDEI_1_0_FN_SDEI_SHARED_RESET
, 0, 0, 0, 0, 0,
361 static void sdei_mark_interface_broken(void)
363 pr_err("disabling SDEI firmware interface\n");
364 on_each_cpu(&_ipi_mask_cpu
, NULL
, true);
365 sdei_firmware_call
= NULL
;
368 static int sdei_platform_reset(void)
372 on_each_cpu(&_ipi_private_reset
, NULL
, true);
373 err
= sdei_api_shared_reset();
375 pr_err("Failed to reset platform: %d\n", err
);
376 sdei_mark_interface_broken();
382 static int sdei_api_event_enable(u32 event_num
)
384 return invoke_sdei_fn(SDEI_1_0_FN_SDEI_EVENT_ENABLE
, event_num
, 0, 0, 0,
388 /* Called directly by the hotplug callbacks */
389 static void _local_event_enable(void *data
)
392 struct sdei_crosscall_args
*arg
= data
;
394 err
= sdei_api_event_enable(arg
->event
->event_num
);
396 sdei_cross_call_return(arg
, err
);
399 int sdei_event_enable(u32 event_num
)
402 struct sdei_event
*event
;
404 mutex_lock(&sdei_events_lock
);
405 event
= sdei_event_find(event_num
);
407 mutex_unlock(&sdei_events_lock
);
413 if (event
->type
== SDEI_EVENT_TYPE_SHARED
)
414 err
= sdei_api_event_enable(event
->event_num
);
416 err
= sdei_do_cross_call(_local_event_enable
, event
);
419 spin_lock(&sdei_list_lock
);
420 event
->reenable
= true;
421 spin_unlock(&sdei_list_lock
);
424 mutex_unlock(&sdei_events_lock
);
429 static int sdei_api_event_disable(u32 event_num
)
431 return invoke_sdei_fn(SDEI_1_0_FN_SDEI_EVENT_DISABLE
, event_num
, 0, 0,
435 static void _ipi_event_disable(void *data
)
438 struct sdei_crosscall_args
*arg
= data
;
440 err
= sdei_api_event_disable(arg
->event
->event_num
);
442 sdei_cross_call_return(arg
, err
);
445 int sdei_event_disable(u32 event_num
)
448 struct sdei_event
*event
;
450 mutex_lock(&sdei_events_lock
);
451 event
= sdei_event_find(event_num
);
453 mutex_unlock(&sdei_events_lock
);
457 spin_lock(&sdei_list_lock
);
458 event
->reenable
= false;
459 spin_unlock(&sdei_list_lock
);
461 if (event
->type
== SDEI_EVENT_TYPE_SHARED
)
462 err
= sdei_api_event_disable(event
->event_num
);
464 err
= sdei_do_cross_call(_ipi_event_disable
, event
);
465 mutex_unlock(&sdei_events_lock
);
470 static int sdei_api_event_unregister(u32 event_num
)
472 return invoke_sdei_fn(SDEI_1_0_FN_SDEI_EVENT_UNREGISTER
, event_num
, 0,
476 /* Called directly by the hotplug callbacks */
477 static void _local_event_unregister(void *data
)
480 struct sdei_crosscall_args
*arg
= data
;
482 err
= sdei_api_event_unregister(arg
->event
->event_num
);
484 sdei_cross_call_return(arg
, err
);
487 int sdei_event_unregister(u32 event_num
)
490 struct sdei_event
*event
;
494 mutex_lock(&sdei_events_lock
);
495 event
= sdei_event_find(event_num
);
497 pr_warn("Event %u not registered\n", event_num
);
502 spin_lock(&sdei_list_lock
);
503 event
->reregister
= false;
504 event
->reenable
= false;
505 spin_unlock(&sdei_list_lock
);
507 if (event
->type
== SDEI_EVENT_TYPE_SHARED
)
508 err
= sdei_api_event_unregister(event
->event_num
);
510 err
= sdei_do_cross_call(_local_event_unregister
, event
);
515 sdei_event_destroy(event
);
517 mutex_unlock(&sdei_events_lock
);
523 * unregister events, but don't destroy them as they are re-registered by
524 * sdei_reregister_shared().
526 static int sdei_unregister_shared(void)
529 struct sdei_event
*event
;
531 mutex_lock(&sdei_events_lock
);
532 spin_lock(&sdei_list_lock
);
533 list_for_each_entry(event
, &sdei_list
, list
) {
534 if (event
->type
!= SDEI_EVENT_TYPE_SHARED
)
537 err
= sdei_api_event_unregister(event
->event_num
);
541 spin_unlock(&sdei_list_lock
);
542 mutex_unlock(&sdei_events_lock
);
547 static int sdei_api_event_register(u32 event_num
, unsigned long entry_point
,
548 void *arg
, u64 flags
, u64 affinity
)
550 return invoke_sdei_fn(SDEI_1_0_FN_SDEI_EVENT_REGISTER
, event_num
,
551 (unsigned long)entry_point
, (unsigned long)arg
,
552 flags
, affinity
, NULL
);
555 /* Called directly by the hotplug callbacks */
556 static void _local_event_register(void *data
)
559 struct sdei_registered_event
*reg
;
560 struct sdei_crosscall_args
*arg
= data
;
562 reg
= per_cpu_ptr(arg
->event
->private_registered
, smp_processor_id());
563 err
= sdei_api_event_register(arg
->event
->event_num
, sdei_entry_point
,
566 sdei_cross_call_return(arg
, err
);
569 int sdei_event_register(u32 event_num
, sdei_event_callback
*cb
, void *arg
)
572 struct sdei_event
*event
;
576 mutex_lock(&sdei_events_lock
);
577 if (sdei_event_find(event_num
)) {
578 pr_warn("Event %u already registered\n", event_num
);
583 event
= sdei_event_create(event_num
, cb
, arg
);
585 err
= PTR_ERR(event
);
586 pr_warn("Failed to create event %u: %d\n", event_num
, err
);
591 if (event
->type
== SDEI_EVENT_TYPE_SHARED
) {
592 err
= sdei_api_event_register(event
->event_num
,
595 SDEI_EVENT_REGISTER_RM_ANY
, 0);
597 err
= sdei_do_cross_call(_local_event_register
, event
);
599 sdei_do_cross_call(_local_event_unregister
, event
);
603 sdei_event_destroy(event
);
604 pr_warn("Failed to register event %u: %d\n", event_num
, err
);
608 spin_lock(&sdei_list_lock
);
609 event
->reregister
= true;
610 spin_unlock(&sdei_list_lock
);
614 mutex_unlock(&sdei_events_lock
);
618 static int sdei_reregister_shared(void)
621 struct sdei_event
*event
;
623 mutex_lock(&sdei_events_lock
);
624 spin_lock(&sdei_list_lock
);
625 list_for_each_entry(event
, &sdei_list
, list
) {
626 if (event
->type
!= SDEI_EVENT_TYPE_SHARED
)
629 if (event
->reregister
) {
630 err
= sdei_api_event_register(event
->event_num
,
631 sdei_entry_point
, event
->registered
,
632 SDEI_EVENT_REGISTER_RM_ANY
, 0);
634 pr_err("Failed to re-register event %u\n",
636 sdei_event_destroy_llocked(event
);
641 if (event
->reenable
) {
642 err
= sdei_api_event_enable(event
->event_num
);
644 pr_err("Failed to re-enable event %u\n",
650 spin_unlock(&sdei_list_lock
);
651 mutex_unlock(&sdei_events_lock
);
656 static int sdei_cpuhp_down(unsigned int cpu
)
658 struct sdei_event
*event
;
661 /* un-register private events */
662 spin_lock(&sdei_list_lock
);
663 list_for_each_entry(event
, &sdei_list
, list
) {
664 if (event
->type
== SDEI_EVENT_TYPE_SHARED
)
667 err
= sdei_do_local_call(_local_event_unregister
, event
);
669 pr_err("Failed to unregister event %u: %d\n",
670 event
->event_num
, err
);
673 spin_unlock(&sdei_list_lock
);
675 return sdei_mask_local_cpu();
678 static int sdei_cpuhp_up(unsigned int cpu
)
680 struct sdei_event
*event
;
683 /* re-register/enable private events */
684 spin_lock(&sdei_list_lock
);
685 list_for_each_entry(event
, &sdei_list
, list
) {
686 if (event
->type
== SDEI_EVENT_TYPE_SHARED
)
689 if (event
->reregister
) {
690 err
= sdei_do_local_call(_local_event_register
, event
);
692 pr_err("Failed to re-register event %u: %d\n",
693 event
->event_num
, err
);
697 if (event
->reenable
) {
698 err
= sdei_do_local_call(_local_event_enable
, event
);
700 pr_err("Failed to re-enable event %u: %d\n",
701 event
->event_num
, err
);
705 spin_unlock(&sdei_list_lock
);
707 return sdei_unmask_local_cpu();
710 /* When entering idle, mask/unmask events for this cpu */
711 static int sdei_pm_notifier(struct notifier_block
*nb
, unsigned long action
,
716 WARN_ON_ONCE(preemptible());
720 rv
= sdei_mask_local_cpu();
723 case CPU_PM_ENTER_FAILED
:
724 rv
= sdei_unmask_local_cpu();
731 return notifier_from_errno(rv
);
736 static struct notifier_block sdei_pm_nb
= {
737 .notifier_call
= sdei_pm_notifier
,
740 static int sdei_device_suspend(struct device
*dev
)
742 on_each_cpu(_ipi_mask_cpu
, NULL
, true);
747 static int sdei_device_resume(struct device
*dev
)
749 on_each_cpu(_ipi_unmask_cpu
, NULL
, true);
755 * We need all events to be reregistered when we resume from hibernate.
757 * The sequence is freeze->thaw. Reboot. freeze->restore. We unregister
758 * events during freeze, then re-register and re-enable them during thaw
761 static int sdei_device_freeze(struct device
*dev
)
765 /* unregister private events */
766 cpuhp_remove_state(sdei_hp_state
);
768 err
= sdei_unregister_shared();
775 static int sdei_device_thaw(struct device
*dev
)
779 /* re-register shared events */
780 err
= sdei_reregister_shared();
782 pr_warn("Failed to re-register shared events...\n");
783 sdei_mark_interface_broken();
787 err
= cpuhp_setup_state(CPUHP_AP_ONLINE_DYN
, "SDEI",
788 &sdei_cpuhp_up
, &sdei_cpuhp_down
);
790 pr_warn("Failed to re-register CPU hotplug notifier...\n");
798 static int sdei_device_restore(struct device
*dev
)
802 err
= sdei_platform_reset();
806 return sdei_device_thaw(dev
);
809 static const struct dev_pm_ops sdei_pm_ops
= {
810 .suspend
= sdei_device_suspend
,
811 .resume
= sdei_device_resume
,
812 .freeze
= sdei_device_freeze
,
813 .thaw
= sdei_device_thaw
,
814 .restore
= sdei_device_restore
,
818 * Mask all CPUs and unregister all events on panic, reboot or kexec.
820 static int sdei_reboot_notifier(struct notifier_block
*nb
, unsigned long action
,
824 * We are going to reset the interface, after this there is no point
825 * doing work when we take CPUs offline.
827 cpuhp_remove_state(sdei_hp_state
);
829 sdei_platform_reset();
834 static struct notifier_block sdei_reboot_nb
= {
835 .notifier_call
= sdei_reboot_notifier
,
838 static void sdei_smccc_smc(unsigned long function_id
,
839 unsigned long arg0
, unsigned long arg1
,
840 unsigned long arg2
, unsigned long arg3
,
841 unsigned long arg4
, struct arm_smccc_res
*res
)
843 arm_smccc_smc(function_id
, arg0
, arg1
, arg2
, arg3
, arg4
, 0, 0, res
);
845 NOKPROBE_SYMBOL(sdei_smccc_smc
);
847 static void sdei_smccc_hvc(unsigned long function_id
,
848 unsigned long arg0
, unsigned long arg1
,
849 unsigned long arg2
, unsigned long arg3
,
850 unsigned long arg4
, struct arm_smccc_res
*res
)
852 arm_smccc_hvc(function_id
, arg0
, arg1
, arg2
, arg3
, arg4
, 0, 0, res
);
854 NOKPROBE_SYMBOL(sdei_smccc_hvc
);
856 int sdei_register_ghes(struct ghes
*ghes
, sdei_event_callback
*normal_cb
,
857 sdei_event_callback
*critical_cb
)
862 sdei_event_callback
*cb
;
864 if (!IS_ENABLED(CONFIG_ACPI_APEI_GHES
))
867 event_num
= ghes
->generic
->notify
.vector
;
868 if (event_num
== 0) {
870 * Event 0 is reserved by the specification for
876 err
= sdei_api_event_get_info(event_num
, SDEI_EVENT_INFO_EV_PRIORITY
,
881 if (result
== SDEI_EVENT_PRIORITY_CRITICAL
)
886 err
= sdei_event_register(event_num
, cb
, ghes
);
888 err
= sdei_event_enable(event_num
);
893 int sdei_unregister_ghes(struct ghes
*ghes
)
897 u32 event_num
= ghes
->generic
->notify
.vector
;
901 if (!IS_ENABLED(CONFIG_ACPI_APEI_GHES
))
905 * The event may be running on another CPU. Disable it
906 * to stop new events, then try to unregister a few times.
908 err
= sdei_event_disable(event_num
);
912 for (i
= 0; i
< 3; i
++) {
913 err
= sdei_event_unregister(event_num
);
914 if (err
!= -EINPROGRESS
)
923 static int sdei_get_conduit(struct platform_device
*pdev
)
926 struct device_node
*np
= pdev
->dev
.of_node
;
928 sdei_firmware_call
= NULL
;
930 if (of_property_read_string(np
, "method", &method
)) {
931 pr_warn("missing \"method\" property\n");
932 return SMCCC_CONDUIT_NONE
;
935 if (!strcmp("hvc", method
)) {
936 sdei_firmware_call
= &sdei_smccc_hvc
;
937 return SMCCC_CONDUIT_HVC
;
938 } else if (!strcmp("smc", method
)) {
939 sdei_firmware_call
= &sdei_smccc_smc
;
940 return SMCCC_CONDUIT_SMC
;
943 pr_warn("invalid \"method\" property: %s\n", method
);
944 } else if (!acpi_disabled
) {
945 if (acpi_psci_use_hvc()) {
946 sdei_firmware_call
= &sdei_smccc_hvc
;
947 return SMCCC_CONDUIT_HVC
;
949 sdei_firmware_call
= &sdei_smccc_smc
;
950 return SMCCC_CONDUIT_SMC
;
954 return SMCCC_CONDUIT_NONE
;
957 static int sdei_probe(struct platform_device
*pdev
)
963 conduit
= sdei_get_conduit(pdev
);
964 if (!sdei_firmware_call
)
967 err
= sdei_api_get_version(&ver
);
969 pr_err("Failed to get SDEI version: %d\n", err
);
970 sdei_mark_interface_broken();
974 pr_info("SDEIv%d.%d (0x%x) detected in firmware.\n",
975 (int)SDEI_VERSION_MAJOR(ver
), (int)SDEI_VERSION_MINOR(ver
),
976 (int)SDEI_VERSION_VENDOR(ver
));
978 if (SDEI_VERSION_MAJOR(ver
) != 1) {
979 pr_warn("Conflicting SDEI version detected.\n");
980 sdei_mark_interface_broken();
984 err
= sdei_platform_reset();
988 sdei_entry_point
= sdei_arch_get_entry_point(conduit
);
989 if (!sdei_entry_point
) {
990 /* Not supported due to hardware or boot configuration */
991 sdei_mark_interface_broken();
995 err
= cpu_pm_register_notifier(&sdei_pm_nb
);
997 pr_warn("Failed to register CPU PM notifier...\n");
1001 err
= register_reboot_notifier(&sdei_reboot_nb
);
1003 pr_warn("Failed to register reboot notifier...\n");
1007 err
= cpuhp_setup_state(CPUHP_AP_ONLINE_DYN
, "SDEI",
1008 &sdei_cpuhp_up
, &sdei_cpuhp_down
);
1010 pr_warn("Failed to register CPU hotplug notifier...\n");
1014 sdei_hp_state
= err
;
1019 unregister_reboot_notifier(&sdei_reboot_nb
);
1022 cpu_pm_unregister_notifier(&sdei_pm_nb
);
1025 sdei_mark_interface_broken();
1029 static const struct of_device_id sdei_of_match
[] = {
1030 { .compatible
= "arm,sdei-1.0" },
1034 static struct platform_driver sdei_driver
= {
1038 .of_match_table
= sdei_of_match
,
1040 .probe
= sdei_probe
,
1043 static bool __init
sdei_present_acpi(void)
1046 struct acpi_table_header
*sdei_table_header
;
1051 status
= acpi_get_table(ACPI_SIG_SDEI
, 0, &sdei_table_header
);
1052 if (ACPI_FAILURE(status
) && status
!= AE_NOT_FOUND
) {
1053 const char *msg
= acpi_format_exception(status
);
1055 pr_info("Failed to get ACPI:SDEI table, %s\n", msg
);
1057 if (ACPI_FAILURE(status
))
1060 acpi_put_table(sdei_table_header
);
1065 void __init
sdei_init(void)
1067 struct platform_device
*pdev
;
1070 ret
= platform_driver_register(&sdei_driver
);
1071 if (ret
|| !sdei_present_acpi())
1074 pdev
= platform_device_register_simple(sdei_driver
.driver
.name
,
1077 ret
= PTR_ERR(pdev
);
1078 platform_driver_unregister(&sdei_driver
);
1079 pr_info("Failed to register ACPI:SDEI platform device %d\n",
1084 int sdei_event_handler(struct pt_regs
*regs
,
1085 struct sdei_registered_event
*arg
)
1088 u32 event_num
= arg
->event_num
;
1090 err
= arg
->callback(event_num
, regs
, arg
->callback_arg
);
1092 pr_err_ratelimited("event %u on CPU %u failed with error: %d\n",
1093 event_num
, smp_processor_id(), err
);
1097 NOKPROBE_SYMBOL(sdei_event_handler
);
1099 void sdei_handler_abort(void)
1102 * If the crash happened in an SDEI event handler then we need to
1103 * finish the handler with the firmware so that we can have working
1104 * interrupts in the crash kernel.
1106 if (__this_cpu_read(sdei_active_critical_event
)) {
1107 pr_warn("still in SDEI critical event context, attempting to finish handler.\n");
1108 __sdei_handler_abort();
1109 __this_cpu_write(sdei_active_critical_event
, NULL
);
1111 if (__this_cpu_read(sdei_active_normal_event
)) {
1112 pr_warn("still in SDEI normal event context, attempting to finish handler.\n");
1113 __sdei_handler_abort();
1114 __this_cpu_write(sdei_active_normal_event
, NULL
);