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
;
47 /* These three are protected by the sdei_list_lock */
48 struct list_head list
;
56 /* This pointer is handed to firmware as the event argument. */
59 struct sdei_registered_event
*registered
;
61 /* CPU private events */
62 struct sdei_registered_event __percpu
*private_registered
;
66 /* Take the mutex for any API call or modification. Take the mutex first. */
67 static DEFINE_MUTEX(sdei_events_lock
);
69 /* and then hold this when modifying the list */
70 static DEFINE_SPINLOCK(sdei_list_lock
);
71 static LIST_HEAD(sdei_list
);
73 /* Private events are registered/enabled via IPI passing one of these */
74 struct sdei_crosscall_args
{
75 struct sdei_event
*event
;
80 #define CROSSCALL_INIT(arg, event) \
83 arg.first_error = 0; \
84 atomic_set(&arg.errors, 0); \
87 static inline int sdei_do_local_call(smp_call_func_t fn
,
88 struct sdei_event
*event
)
90 struct sdei_crosscall_args arg
;
92 CROSSCALL_INIT(arg
, event
);
95 return arg
.first_error
;
98 static inline int sdei_do_cross_call(smp_call_func_t fn
,
99 struct sdei_event
*event
)
101 struct sdei_crosscall_args arg
;
103 CROSSCALL_INIT(arg
, event
);
104 on_each_cpu(fn
, &arg
, true);
106 return arg
.first_error
;
110 sdei_cross_call_return(struct sdei_crosscall_args
*arg
, int err
)
112 if (err
&& (atomic_inc_return(&arg
->errors
) == 1))
113 arg
->first_error
= err
;
116 static int sdei_to_linux_errno(unsigned long sdei_err
)
119 case SDEI_NOT_SUPPORTED
:
121 case SDEI_INVALID_PARAMETERS
:
127 case SDEI_OUT_OF_RESOURCE
:
134 static int invoke_sdei_fn(unsigned long function_id
, unsigned long arg0
,
135 unsigned long arg1
, unsigned long arg2
,
136 unsigned long arg3
, unsigned long arg4
,
140 struct arm_smccc_res res
;
142 if (sdei_firmware_call
) {
143 sdei_firmware_call(function_id
, arg0
, arg1
, arg2
, arg3
, arg4
,
145 err
= sdei_to_linux_errno(res
.a0
);
148 * !sdei_firmware_call means we failed to probe or called
149 * sdei_mark_interface_broken(). -EIO is not an error returned
150 * by sdei_to_linux_errno() and is used to suppress messages
154 res
.a0
= SDEI_NOT_SUPPORTED
;
162 NOKPROBE_SYMBOL(invoke_sdei_fn
);
164 static struct sdei_event
*sdei_event_find(u32 event_num
)
166 struct sdei_event
*e
, *found
= NULL
;
168 lockdep_assert_held(&sdei_events_lock
);
170 spin_lock(&sdei_list_lock
);
171 list_for_each_entry(e
, &sdei_list
, list
) {
172 if (e
->event_num
== event_num
) {
177 spin_unlock(&sdei_list_lock
);
182 int sdei_api_event_context(u32 query
, u64
*result
)
184 return invoke_sdei_fn(SDEI_1_0_FN_SDEI_EVENT_CONTEXT
, query
, 0, 0, 0, 0,
187 NOKPROBE_SYMBOL(sdei_api_event_context
);
189 static int sdei_api_event_get_info(u32 event
, u32 info
, u64
*result
)
191 return invoke_sdei_fn(SDEI_1_0_FN_SDEI_EVENT_GET_INFO
, event
, info
, 0,
195 static struct sdei_event
*sdei_event_create(u32 event_num
,
196 sdei_event_callback
*cb
,
201 struct sdei_event
*event
;
202 struct sdei_registered_event
*reg
;
204 lockdep_assert_held(&sdei_events_lock
);
206 event
= kzalloc(sizeof(*event
), GFP_KERNEL
);
212 INIT_LIST_HEAD(&event
->list
);
213 event
->event_num
= event_num
;
215 err
= sdei_api_event_get_info(event_num
, SDEI_EVENT_INFO_EV_PRIORITY
,
219 event
->priority
= result
;
221 err
= sdei_api_event_get_info(event_num
, SDEI_EVENT_INFO_EV_TYPE
,
225 event
->type
= result
;
227 if (event
->type
== SDEI_EVENT_TYPE_SHARED
) {
228 reg
= kzalloc(sizeof(*reg
), GFP_KERNEL
);
234 reg
->event_num
= event
->event_num
;
235 reg
->priority
= event
->priority
;
238 reg
->callback_arg
= cb_arg
;
239 event
->registered
= reg
;
242 struct sdei_registered_event __percpu
*regs
;
244 regs
= alloc_percpu(struct sdei_registered_event
);
250 for_each_possible_cpu(cpu
) {
251 reg
= per_cpu_ptr(regs
, cpu
);
253 reg
->event_num
= event
->event_num
;
254 reg
->priority
= event
->priority
;
256 reg
->callback_arg
= cb_arg
;
259 event
->private_registered
= regs
;
262 spin_lock(&sdei_list_lock
);
263 list_add(&event
->list
, &sdei_list
);
264 spin_unlock(&sdei_list_lock
);
273 static void sdei_event_destroy_llocked(struct sdei_event
*event
)
275 lockdep_assert_held(&sdei_events_lock
);
276 lockdep_assert_held(&sdei_list_lock
);
278 list_del(&event
->list
);
280 if (event
->type
== SDEI_EVENT_TYPE_SHARED
)
281 kfree(event
->registered
);
283 free_percpu(event
->private_registered
);
288 static void sdei_event_destroy(struct sdei_event
*event
)
290 spin_lock(&sdei_list_lock
);
291 sdei_event_destroy_llocked(event
);
292 spin_unlock(&sdei_list_lock
);
295 static int sdei_api_get_version(u64
*version
)
297 return invoke_sdei_fn(SDEI_1_0_FN_SDEI_VERSION
, 0, 0, 0, 0, 0, version
);
300 int sdei_mask_local_cpu(void)
304 WARN_ON_ONCE(preemptible());
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 sdei_mask_local_cpu();
321 int sdei_unmask_local_cpu(void)
325 WARN_ON_ONCE(preemptible());
327 err
= invoke_sdei_fn(SDEI_1_0_FN_SDEI_PE_UNMASK
, 0, 0, 0, 0, 0, NULL
);
328 if (err
&& err
!= -EIO
) {
329 pr_warn_once("failed to unmask CPU[%u]: %d\n",
330 smp_processor_id(), err
);
337 static void _ipi_unmask_cpu(void *ignored
)
339 sdei_unmask_local_cpu();
342 static void _ipi_private_reset(void *ignored
)
346 err
= invoke_sdei_fn(SDEI_1_0_FN_SDEI_PRIVATE_RESET
, 0, 0, 0, 0, 0,
348 if (err
&& err
!= -EIO
)
349 pr_warn_once("failed to reset CPU[%u]: %d\n",
350 smp_processor_id(), err
);
353 static int sdei_api_shared_reset(void)
355 return invoke_sdei_fn(SDEI_1_0_FN_SDEI_SHARED_RESET
, 0, 0, 0, 0, 0,
359 static void sdei_mark_interface_broken(void)
361 pr_err("disabling SDEI firmware interface\n");
362 on_each_cpu(&_ipi_mask_cpu
, NULL
, true);
363 sdei_firmware_call
= NULL
;
366 static int sdei_platform_reset(void)
370 on_each_cpu(&_ipi_private_reset
, NULL
, true);
371 err
= sdei_api_shared_reset();
373 pr_err("Failed to reset platform: %d\n", err
);
374 sdei_mark_interface_broken();
380 static int sdei_api_event_enable(u32 event_num
)
382 return invoke_sdei_fn(SDEI_1_0_FN_SDEI_EVENT_ENABLE
, event_num
, 0, 0, 0,
386 /* Called directly by the hotplug callbacks */
387 static void _local_event_enable(void *data
)
390 struct sdei_crosscall_args
*arg
= data
;
392 WARN_ON_ONCE(preemptible());
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 WARN_ON_ONCE(preemptible());
484 err
= sdei_api_event_unregister(arg
->event
->event_num
);
486 sdei_cross_call_return(arg
, err
);
489 int sdei_event_unregister(u32 event_num
)
492 struct sdei_event
*event
;
496 mutex_lock(&sdei_events_lock
);
497 event
= sdei_event_find(event_num
);
499 pr_warn("Event %u not registered\n", event_num
);
504 spin_lock(&sdei_list_lock
);
505 event
->reregister
= false;
506 event
->reenable
= false;
507 spin_unlock(&sdei_list_lock
);
509 if (event
->type
== SDEI_EVENT_TYPE_SHARED
)
510 err
= sdei_api_event_unregister(event
->event_num
);
512 err
= sdei_do_cross_call(_local_event_unregister
, event
);
517 sdei_event_destroy(event
);
519 mutex_unlock(&sdei_events_lock
);
525 * unregister events, but don't destroy them as they are re-registered by
526 * sdei_reregister_shared().
528 static int sdei_unregister_shared(void)
531 struct sdei_event
*event
;
533 mutex_lock(&sdei_events_lock
);
534 spin_lock(&sdei_list_lock
);
535 list_for_each_entry(event
, &sdei_list
, list
) {
536 if (event
->type
!= SDEI_EVENT_TYPE_SHARED
)
539 err
= sdei_api_event_unregister(event
->event_num
);
543 spin_unlock(&sdei_list_lock
);
544 mutex_unlock(&sdei_events_lock
);
549 static int sdei_api_event_register(u32 event_num
, unsigned long entry_point
,
550 void *arg
, u64 flags
, u64 affinity
)
552 return invoke_sdei_fn(SDEI_1_0_FN_SDEI_EVENT_REGISTER
, event_num
,
553 (unsigned long)entry_point
, (unsigned long)arg
,
554 flags
, affinity
, NULL
);
557 /* Called directly by the hotplug callbacks */
558 static void _local_event_register(void *data
)
561 struct sdei_registered_event
*reg
;
562 struct sdei_crosscall_args
*arg
= data
;
564 WARN_ON(preemptible());
566 reg
= per_cpu_ptr(arg
->event
->private_registered
, smp_processor_id());
567 err
= sdei_api_event_register(arg
->event
->event_num
, sdei_entry_point
,
570 sdei_cross_call_return(arg
, err
);
573 int sdei_event_register(u32 event_num
, sdei_event_callback
*cb
, void *arg
)
576 struct sdei_event
*event
;
580 mutex_lock(&sdei_events_lock
);
581 if (sdei_event_find(event_num
)) {
582 pr_warn("Event %u already registered\n", event_num
);
587 event
= sdei_event_create(event_num
, cb
, arg
);
589 err
= PTR_ERR(event
);
590 pr_warn("Failed to create event %u: %d\n", event_num
, err
);
595 if (event
->type
== SDEI_EVENT_TYPE_SHARED
) {
596 err
= sdei_api_event_register(event
->event_num
,
599 SDEI_EVENT_REGISTER_RM_ANY
, 0);
601 err
= sdei_do_cross_call(_local_event_register
, event
);
603 sdei_do_cross_call(_local_event_unregister
, event
);
607 sdei_event_destroy(event
);
608 pr_warn("Failed to register event %u: %d\n", event_num
, err
);
612 spin_lock(&sdei_list_lock
);
613 event
->reregister
= true;
614 spin_unlock(&sdei_list_lock
);
618 mutex_unlock(&sdei_events_lock
);
622 static int sdei_reregister_shared(void)
625 struct sdei_event
*event
;
627 mutex_lock(&sdei_events_lock
);
628 spin_lock(&sdei_list_lock
);
629 list_for_each_entry(event
, &sdei_list
, list
) {
630 if (event
->type
!= SDEI_EVENT_TYPE_SHARED
)
633 if (event
->reregister
) {
634 err
= sdei_api_event_register(event
->event_num
,
635 sdei_entry_point
, event
->registered
,
636 SDEI_EVENT_REGISTER_RM_ANY
, 0);
638 pr_err("Failed to re-register event %u\n",
640 sdei_event_destroy_llocked(event
);
645 if (event
->reenable
) {
646 err
= sdei_api_event_enable(event
->event_num
);
648 pr_err("Failed to re-enable event %u\n",
654 spin_unlock(&sdei_list_lock
);
655 mutex_unlock(&sdei_events_lock
);
660 static int sdei_cpuhp_down(unsigned int cpu
)
662 struct sdei_event
*event
;
665 /* un-register private events */
666 spin_lock(&sdei_list_lock
);
667 list_for_each_entry(event
, &sdei_list
, list
) {
668 if (event
->type
== SDEI_EVENT_TYPE_SHARED
)
671 err
= sdei_do_local_call(_local_event_unregister
, event
);
673 pr_err("Failed to unregister event %u: %d\n",
674 event
->event_num
, err
);
677 spin_unlock(&sdei_list_lock
);
679 return sdei_mask_local_cpu();
682 static int sdei_cpuhp_up(unsigned int cpu
)
684 struct sdei_event
*event
;
687 /* re-register/enable private events */
688 spin_lock(&sdei_list_lock
);
689 list_for_each_entry(event
, &sdei_list
, list
) {
690 if (event
->type
== SDEI_EVENT_TYPE_SHARED
)
693 if (event
->reregister
) {
694 err
= sdei_do_local_call(_local_event_register
, event
);
696 pr_err("Failed to re-register event %u: %d\n",
697 event
->event_num
, err
);
701 if (event
->reenable
) {
702 err
= sdei_do_local_call(_local_event_enable
, event
);
704 pr_err("Failed to re-enable event %u: %d\n",
705 event
->event_num
, err
);
709 spin_unlock(&sdei_list_lock
);
711 return sdei_unmask_local_cpu();
714 /* When entering idle, mask/unmask events for this cpu */
715 static int sdei_pm_notifier(struct notifier_block
*nb
, unsigned long action
,
722 rv
= sdei_mask_local_cpu();
725 case CPU_PM_ENTER_FAILED
:
726 rv
= sdei_unmask_local_cpu();
733 return notifier_from_errno(rv
);
738 static struct notifier_block sdei_pm_nb
= {
739 .notifier_call
= sdei_pm_notifier
,
742 static int sdei_device_suspend(struct device
*dev
)
744 on_each_cpu(_ipi_mask_cpu
, NULL
, true);
749 static int sdei_device_resume(struct device
*dev
)
751 on_each_cpu(_ipi_unmask_cpu
, NULL
, true);
757 * We need all events to be reregistered when we resume from hibernate.
759 * The sequence is freeze->thaw. Reboot. freeze->restore. We unregister
760 * events during freeze, then re-register and re-enable them during thaw
763 static int sdei_device_freeze(struct device
*dev
)
767 /* unregister private events */
768 cpuhp_remove_state(CPUHP_AP_ARM_SDEI_STARTING
);
770 err
= sdei_unregister_shared();
777 static int sdei_device_thaw(struct device
*dev
)
781 /* re-register shared events */
782 err
= sdei_reregister_shared();
784 pr_warn("Failed to re-register shared events...\n");
785 sdei_mark_interface_broken();
789 err
= cpuhp_setup_state(CPUHP_AP_ARM_SDEI_STARTING
, "SDEI",
790 &sdei_cpuhp_up
, &sdei_cpuhp_down
);
792 pr_warn("Failed to re-register CPU hotplug notifier...\n");
797 static int sdei_device_restore(struct device
*dev
)
801 err
= sdei_platform_reset();
805 return sdei_device_thaw(dev
);
808 static const struct dev_pm_ops sdei_pm_ops
= {
809 .suspend
= sdei_device_suspend
,
810 .resume
= sdei_device_resume
,
811 .freeze
= sdei_device_freeze
,
812 .thaw
= sdei_device_thaw
,
813 .restore
= sdei_device_restore
,
817 * Mask all CPUs and unregister all events on panic, reboot or kexec.
819 static int sdei_reboot_notifier(struct notifier_block
*nb
, unsigned long action
,
823 * We are going to reset the interface, after this there is no point
824 * doing work when we take CPUs offline.
826 cpuhp_remove_state(CPUHP_AP_ARM_SDEI_STARTING
);
828 sdei_platform_reset();
833 static struct notifier_block sdei_reboot_nb
= {
834 .notifier_call
= sdei_reboot_notifier
,
837 static void sdei_smccc_smc(unsigned long function_id
,
838 unsigned long arg0
, unsigned long arg1
,
839 unsigned long arg2
, unsigned long arg3
,
840 unsigned long arg4
, struct arm_smccc_res
*res
)
842 arm_smccc_smc(function_id
, arg0
, arg1
, arg2
, arg3
, arg4
, 0, 0, res
);
844 NOKPROBE_SYMBOL(sdei_smccc_smc
);
846 static void sdei_smccc_hvc(unsigned long function_id
,
847 unsigned long arg0
, unsigned long arg1
,
848 unsigned long arg2
, unsigned long arg3
,
849 unsigned long arg4
, struct arm_smccc_res
*res
)
851 arm_smccc_hvc(function_id
, arg0
, arg1
, arg2
, arg3
, arg4
, 0, 0, res
);
853 NOKPROBE_SYMBOL(sdei_smccc_hvc
);
855 int sdei_register_ghes(struct ghes
*ghes
, sdei_event_callback
*normal_cb
,
856 sdei_event_callback
*critical_cb
)
861 sdei_event_callback
*cb
;
863 if (!IS_ENABLED(CONFIG_ACPI_APEI_GHES
))
866 event_num
= ghes
->generic
->notify
.vector
;
867 if (event_num
== 0) {
869 * Event 0 is reserved by the specification for
875 err
= sdei_api_event_get_info(event_num
, SDEI_EVENT_INFO_EV_PRIORITY
,
880 if (result
== SDEI_EVENT_PRIORITY_CRITICAL
)
885 err
= sdei_event_register(event_num
, cb
, ghes
);
887 err
= sdei_event_enable(event_num
);
892 int sdei_unregister_ghes(struct ghes
*ghes
)
896 u32 event_num
= ghes
->generic
->notify
.vector
;
900 if (!IS_ENABLED(CONFIG_ACPI_APEI_GHES
))
904 * The event may be running on another CPU. Disable it
905 * to stop new events, then try to unregister a few times.
907 err
= sdei_event_disable(event_num
);
911 for (i
= 0; i
< 3; i
++) {
912 err
= sdei_event_unregister(event_num
);
913 if (err
!= -EINPROGRESS
)
922 static int sdei_get_conduit(struct platform_device
*pdev
)
925 struct device_node
*np
= pdev
->dev
.of_node
;
927 sdei_firmware_call
= NULL
;
929 if (of_property_read_string(np
, "method", &method
)) {
930 pr_warn("missing \"method\" property\n");
931 return SMCCC_CONDUIT_NONE
;
934 if (!strcmp("hvc", method
)) {
935 sdei_firmware_call
= &sdei_smccc_hvc
;
936 return SMCCC_CONDUIT_HVC
;
937 } else if (!strcmp("smc", method
)) {
938 sdei_firmware_call
= &sdei_smccc_smc
;
939 return SMCCC_CONDUIT_SMC
;
942 pr_warn("invalid \"method\" property: %s\n", method
);
943 } else if (!acpi_disabled
) {
944 if (acpi_psci_use_hvc()) {
945 sdei_firmware_call
= &sdei_smccc_hvc
;
946 return SMCCC_CONDUIT_HVC
;
948 sdei_firmware_call
= &sdei_smccc_smc
;
949 return SMCCC_CONDUIT_SMC
;
953 return SMCCC_CONDUIT_NONE
;
956 static int sdei_probe(struct platform_device
*pdev
)
962 conduit
= sdei_get_conduit(pdev
);
963 if (!sdei_firmware_call
)
966 err
= sdei_api_get_version(&ver
);
968 pr_err("Failed to get SDEI version: %d\n", err
);
969 sdei_mark_interface_broken();
973 pr_info("SDEIv%d.%d (0x%x) detected in firmware.\n",
974 (int)SDEI_VERSION_MAJOR(ver
), (int)SDEI_VERSION_MINOR(ver
),
975 (int)SDEI_VERSION_VENDOR(ver
));
977 if (SDEI_VERSION_MAJOR(ver
) != 1) {
978 pr_warn("Conflicting SDEI version detected.\n");
979 sdei_mark_interface_broken();
983 err
= sdei_platform_reset();
987 sdei_entry_point
= sdei_arch_get_entry_point(conduit
);
988 if (!sdei_entry_point
) {
989 /* Not supported due to hardware or boot configuration */
990 sdei_mark_interface_broken();
994 err
= cpu_pm_register_notifier(&sdei_pm_nb
);
996 pr_warn("Failed to register CPU PM notifier...\n");
1000 err
= register_reboot_notifier(&sdei_reboot_nb
);
1002 pr_warn("Failed to register reboot notifier...\n");
1006 err
= cpuhp_setup_state(CPUHP_AP_ARM_SDEI_STARTING
, "SDEI",
1007 &sdei_cpuhp_up
, &sdei_cpuhp_down
);
1009 pr_warn("Failed to register CPU hotplug notifier...\n");
1016 unregister_reboot_notifier(&sdei_reboot_nb
);
1019 cpu_pm_unregister_notifier(&sdei_pm_nb
);
1022 sdei_mark_interface_broken();
1026 static const struct of_device_id sdei_of_match
[] = {
1027 { .compatible
= "arm,sdei-1.0" },
1031 static struct platform_driver sdei_driver
= {
1035 .of_match_table
= sdei_of_match
,
1037 .probe
= sdei_probe
,
1040 static bool __init
sdei_present_acpi(void)
1043 struct acpi_table_header
*sdei_table_header
;
1048 status
= acpi_get_table(ACPI_SIG_SDEI
, 0, &sdei_table_header
);
1049 if (ACPI_FAILURE(status
) && status
!= AE_NOT_FOUND
) {
1050 const char *msg
= acpi_format_exception(status
);
1052 pr_info("Failed to get ACPI:SDEI table, %s\n", msg
);
1054 if (ACPI_FAILURE(status
))
1057 acpi_put_table(sdei_table_header
);
1062 static int __init
sdei_init(void)
1064 struct platform_device
*pdev
;
1067 ret
= platform_driver_register(&sdei_driver
);
1068 if (ret
|| !sdei_present_acpi())
1071 pdev
= platform_device_register_simple(sdei_driver
.driver
.name
,
1074 ret
= PTR_ERR(pdev
);
1075 platform_driver_unregister(&sdei_driver
);
1076 pr_info("Failed to register ACPI:SDEI platform device %d\n",
1084 * On an ACPI system SDEI needs to be ready before HEST:GHES tries to register
1085 * its events. ACPI is initialised from a subsys_initcall(), GHES is initialised
1086 * by device_initcall(). We want to be called in the middle.
1088 subsys_initcall_sync(sdei_init
);
1090 int sdei_event_handler(struct pt_regs
*regs
,
1091 struct sdei_registered_event
*arg
)
1094 u32 event_num
= arg
->event_num
;
1096 err
= arg
->callback(event_num
, regs
, arg
->callback_arg
);
1098 pr_err_ratelimited("event %u on CPU %u failed with error: %d\n",
1099 event_num
, smp_processor_id(), err
);
1103 NOKPROBE_SYMBOL(sdei_event_handler
);