1 // SPDX-License-Identifier: GPL-2.0
2 // Copyright (C) 2017 Arm Ltd.
3 #define pr_fmt(fmt) "sdei: " fmt
5 #include <linux/acpi.h>
6 #include <linux/arm_sdei.h>
7 #include <linux/arm-smccc.h>
8 #include <linux/atomic.h>
9 #include <linux/bitops.h>
10 #include <linux/compiler.h>
11 #include <linux/cpuhotplug.h>
12 #include <linux/cpu.h>
13 #include <linux/cpu_pm.h>
14 #include <linux/errno.h>
15 #include <linux/hardirq.h>
16 #include <linux/kernel.h>
17 #include <linux/kprobes.h>
18 #include <linux/kvm_host.h>
19 #include <linux/list.h>
20 #include <linux/mutex.h>
21 #include <linux/notifier.h>
23 #include <linux/of_platform.h>
24 #include <linux/percpu.h>
25 #include <linux/platform_device.h>
27 #include <linux/ptrace.h>
28 #include <linux/preempt.h>
29 #include <linux/reboot.h>
30 #include <linux/slab.h>
31 #include <linux/smp.h>
32 #include <linux/spinlock.h>
33 #include <linux/uaccess.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) (arg.event = event, \
81 arg.first_error = 0, \
82 atomic_set(&arg.errors, 0))
84 static inline int sdei_do_cross_call(void *fn
, struct sdei_event
* event
)
86 struct sdei_crosscall_args arg
;
88 CROSSCALL_INIT(arg
, event
);
89 on_each_cpu(fn
, &arg
, true);
91 return arg
.first_error
;
95 sdei_cross_call_return(struct sdei_crosscall_args
*arg
, int err
)
97 if (err
&& (atomic_inc_return(&arg
->errors
) == 1))
98 arg
->first_error
= err
;
101 static int sdei_to_linux_errno(unsigned long sdei_err
)
104 case SDEI_NOT_SUPPORTED
:
106 case SDEI_INVALID_PARAMETERS
:
112 case SDEI_OUT_OF_RESOURCE
:
116 /* Not an error value ... */
121 * If x0 is any of these values, then the call failed, use sdei_to_linux_errno()
124 static int sdei_is_err(struct arm_smccc_res
*res
)
127 case SDEI_NOT_SUPPORTED
:
128 case SDEI_INVALID_PARAMETERS
:
131 case SDEI_OUT_OF_RESOURCE
:
138 static int invoke_sdei_fn(unsigned long function_id
, unsigned long arg0
,
139 unsigned long arg1
, unsigned long arg2
,
140 unsigned long arg3
, unsigned long arg4
,
144 struct arm_smccc_res res
;
146 if (sdei_firmware_call
) {
147 sdei_firmware_call(function_id
, arg0
, arg1
, arg2
, arg3
, arg4
,
149 if (sdei_is_err(&res
))
150 err
= sdei_to_linux_errno(res
.a0
);
153 * !sdei_firmware_call means we failed to probe or called
154 * sdei_mark_interface_broken(). -EIO is not an error returned
155 * by sdei_to_linux_errno() and is used to suppress messages
159 res
.a0
= SDEI_NOT_SUPPORTED
;
168 static struct sdei_event
*sdei_event_find(u32 event_num
)
170 struct sdei_event
*e
, *found
= NULL
;
172 lockdep_assert_held(&sdei_events_lock
);
174 spin_lock(&sdei_list_lock
);
175 list_for_each_entry(e
, &sdei_list
, list
) {
176 if (e
->event_num
== event_num
) {
181 spin_unlock(&sdei_list_lock
);
186 int sdei_api_event_context(u32 query
, u64
*result
)
188 return invoke_sdei_fn(SDEI_1_0_FN_SDEI_EVENT_CONTEXT
, query
, 0, 0, 0, 0,
191 NOKPROBE_SYMBOL(sdei_api_event_context
);
193 static int sdei_api_event_get_info(u32 event
, u32 info
, u64
*result
)
195 return invoke_sdei_fn(SDEI_1_0_FN_SDEI_EVENT_GET_INFO
, event
, info
, 0,
199 static struct sdei_event
*sdei_event_create(u32 event_num
,
200 sdei_event_callback
*cb
,
205 struct sdei_event
*event
;
206 struct sdei_registered_event
*reg
;
208 lockdep_assert_held(&sdei_events_lock
);
210 event
= kzalloc(sizeof(*event
), GFP_KERNEL
);
212 return ERR_PTR(-ENOMEM
);
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
,
223 event
->priority
= result
;
225 err
= sdei_api_event_get_info(event_num
, SDEI_EVENT_INFO_EV_TYPE
,
231 event
->type
= result
;
233 if (event
->type
== SDEI_EVENT_TYPE_SHARED
) {
234 reg
= kzalloc(sizeof(*reg
), GFP_KERNEL
);
237 return ERR_PTR(-ENOMEM
);
240 reg
->event_num
= event_num
;
241 reg
->priority
= event
->priority
;
244 reg
->callback_arg
= cb_arg
;
245 event
->registered
= reg
;
248 struct sdei_registered_event __percpu
*regs
;
250 regs
= alloc_percpu(struct sdei_registered_event
);
253 return ERR_PTR(-ENOMEM
);
256 for_each_possible_cpu(cpu
) {
257 reg
= per_cpu_ptr(regs
, cpu
);
259 reg
->event_num
= event
->event_num
;
260 reg
->priority
= event
->priority
;
262 reg
->callback_arg
= cb_arg
;
265 event
->private_registered
= regs
;
268 if (sdei_event_find(event_num
)) {
269 kfree(event
->registered
);
271 event
= ERR_PTR(-EBUSY
);
273 spin_lock(&sdei_list_lock
);
274 list_add(&event
->list
, &sdei_list
);
275 spin_unlock(&sdei_list_lock
);
281 static void sdei_event_destroy(struct sdei_event
*event
)
283 lockdep_assert_held(&sdei_events_lock
);
285 spin_lock(&sdei_list_lock
);
286 list_del(&event
->list
);
287 spin_unlock(&sdei_list_lock
);
289 if (event
->type
== SDEI_EVENT_TYPE_SHARED
)
290 kfree(event
->registered
);
292 free_percpu(event
->private_registered
);
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 WARN_ON_ONCE(preemptible());
308 err
= invoke_sdei_fn(SDEI_1_0_FN_SDEI_PE_MASK
, 0, 0, 0, 0, 0, NULL
);
309 if (err
&& err
!= -EIO
) {
310 pr_warn_once("failed to mask CPU[%u]: %d\n",
311 smp_processor_id(), err
);
318 static void _ipi_mask_cpu(void *ignored
)
320 sdei_mask_local_cpu();
323 int sdei_unmask_local_cpu(void)
327 WARN_ON_ONCE(preemptible());
329 err
= invoke_sdei_fn(SDEI_1_0_FN_SDEI_PE_UNMASK
, 0, 0, 0, 0, 0, NULL
);
330 if (err
&& err
!= -EIO
) {
331 pr_warn_once("failed to unmask CPU[%u]: %d\n",
332 smp_processor_id(), err
);
339 static void _ipi_unmask_cpu(void *ignored
)
341 sdei_unmask_local_cpu();
344 static void _ipi_private_reset(void *ignored
)
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 WARN_ON_ONCE(preemptible());
396 err
= sdei_api_event_enable(arg
->event
->event_num
);
398 sdei_cross_call_return(arg
, err
);
401 int sdei_event_enable(u32 event_num
)
404 struct sdei_event
*event
;
406 mutex_lock(&sdei_events_lock
);
407 event
= sdei_event_find(event_num
);
409 mutex_unlock(&sdei_events_lock
);
413 spin_lock(&sdei_list_lock
);
414 event
->reenable
= true;
415 spin_unlock(&sdei_list_lock
);
417 if (event
->type
== SDEI_EVENT_TYPE_SHARED
)
418 err
= sdei_api_event_enable(event
->event_num
);
420 err
= sdei_do_cross_call(_local_event_enable
, event
);
421 mutex_unlock(&sdei_events_lock
);
425 EXPORT_SYMBOL(sdei_event_enable
);
427 static int sdei_api_event_disable(u32 event_num
)
429 return invoke_sdei_fn(SDEI_1_0_FN_SDEI_EVENT_DISABLE
, event_num
, 0, 0,
433 static void _ipi_event_disable(void *data
)
436 struct sdei_crosscall_args
*arg
= data
;
438 err
= sdei_api_event_disable(arg
->event
->event_num
);
440 sdei_cross_call_return(arg
, err
);
443 int sdei_event_disable(u32 event_num
)
446 struct sdei_event
*event
;
448 mutex_lock(&sdei_events_lock
);
449 event
= sdei_event_find(event_num
);
451 mutex_unlock(&sdei_events_lock
);
455 spin_lock(&sdei_list_lock
);
456 event
->reenable
= false;
457 spin_unlock(&sdei_list_lock
);
459 if (event
->type
== SDEI_EVENT_TYPE_SHARED
)
460 err
= sdei_api_event_disable(event
->event_num
);
462 err
= sdei_do_cross_call(_ipi_event_disable
, event
);
463 mutex_unlock(&sdei_events_lock
);
467 EXPORT_SYMBOL(sdei_event_disable
);
469 static int sdei_api_event_unregister(u32 event_num
)
471 return invoke_sdei_fn(SDEI_1_0_FN_SDEI_EVENT_UNREGISTER
, event_num
, 0,
475 /* Called directly by the hotplug callbacks */
476 static void _local_event_unregister(void *data
)
479 struct sdei_crosscall_args
*arg
= data
;
481 WARN_ON_ONCE(preemptible());
483 err
= sdei_api_event_unregister(arg
->event
->event_num
);
485 sdei_cross_call_return(arg
, err
);
488 static int _sdei_event_unregister(struct sdei_event
*event
)
490 lockdep_assert_held(&sdei_events_lock
);
492 spin_lock(&sdei_list_lock
);
493 event
->reregister
= false;
494 event
->reenable
= false;
495 spin_unlock(&sdei_list_lock
);
497 if (event
->type
== SDEI_EVENT_TYPE_SHARED
)
498 return sdei_api_event_unregister(event
->event_num
);
500 return sdei_do_cross_call(_local_event_unregister
, event
);
503 int sdei_event_unregister(u32 event_num
)
506 struct sdei_event
*event
;
510 mutex_lock(&sdei_events_lock
);
511 event
= sdei_event_find(event_num
);
514 pr_warn("Event %u not registered\n", event_num
);
519 err
= _sdei_event_unregister(event
);
523 sdei_event_destroy(event
);
525 mutex_unlock(&sdei_events_lock
);
529 EXPORT_SYMBOL(sdei_event_unregister
);
532 * unregister events, but don't destroy them as they are re-registered by
533 * sdei_reregister_shared().
535 static int sdei_unregister_shared(void)
538 struct sdei_event
*event
;
540 mutex_lock(&sdei_events_lock
);
541 spin_lock(&sdei_list_lock
);
542 list_for_each_entry(event
, &sdei_list
, list
) {
543 if (event
->type
!= SDEI_EVENT_TYPE_SHARED
)
546 err
= _sdei_event_unregister(event
);
550 spin_unlock(&sdei_list_lock
);
551 mutex_unlock(&sdei_events_lock
);
556 static int sdei_api_event_register(u32 event_num
, unsigned long entry_point
,
557 void *arg
, u64 flags
, u64 affinity
)
559 return invoke_sdei_fn(SDEI_1_0_FN_SDEI_EVENT_REGISTER
, event_num
,
560 (unsigned long)entry_point
, (unsigned long)arg
,
561 flags
, affinity
, NULL
);
564 /* Called directly by the hotplug callbacks */
565 static void _local_event_register(void *data
)
568 struct sdei_registered_event
*reg
;
569 struct sdei_crosscall_args
*arg
= data
;
571 WARN_ON(preemptible());
573 reg
= per_cpu_ptr(arg
->event
->private_registered
, smp_processor_id());
574 err
= sdei_api_event_register(arg
->event
->event_num
, sdei_entry_point
,
577 sdei_cross_call_return(arg
, err
);
580 static int _sdei_event_register(struct sdei_event
*event
)
584 lockdep_assert_held(&sdei_events_lock
);
586 spin_lock(&sdei_list_lock
);
587 event
->reregister
= true;
588 spin_unlock(&sdei_list_lock
);
590 if (event
->type
== SDEI_EVENT_TYPE_SHARED
)
591 return sdei_api_event_register(event
->event_num
,
594 SDEI_EVENT_REGISTER_RM_ANY
, 0);
597 err
= sdei_do_cross_call(_local_event_register
, event
);
599 spin_lock(&sdei_list_lock
);
600 event
->reregister
= false;
601 event
->reenable
= false;
602 spin_unlock(&sdei_list_lock
);
604 sdei_do_cross_call(_local_event_unregister
, event
);
610 int sdei_event_register(u32 event_num
, sdei_event_callback
*cb
, void *arg
)
613 struct sdei_event
*event
;
617 mutex_lock(&sdei_events_lock
);
619 if (sdei_event_find(event_num
)) {
620 pr_warn("Event %u already registered\n", event_num
);
625 event
= sdei_event_create(event_num
, cb
, arg
);
627 err
= PTR_ERR(event
);
628 pr_warn("Failed to create event %u: %d\n", event_num
,
633 err
= _sdei_event_register(event
);
635 sdei_event_destroy(event
);
636 pr_warn("Failed to register event %u: %d\n", event_num
,
640 mutex_unlock(&sdei_events_lock
);
644 EXPORT_SYMBOL(sdei_event_register
);
646 static int sdei_reregister_event(struct sdei_event
*event
)
650 lockdep_assert_held(&sdei_events_lock
);
652 err
= _sdei_event_register(event
);
654 pr_err("Failed to re-register event %u\n", event
->event_num
);
655 sdei_event_destroy(event
);
659 if (event
->reenable
) {
660 if (event
->type
== SDEI_EVENT_TYPE_SHARED
)
661 err
= sdei_api_event_enable(event
->event_num
);
663 err
= sdei_do_cross_call(_local_event_enable
, event
);
667 pr_err("Failed to re-enable event %u\n", event
->event_num
);
672 static int sdei_reregister_shared(void)
675 struct sdei_event
*event
;
677 mutex_lock(&sdei_events_lock
);
678 spin_lock(&sdei_list_lock
);
679 list_for_each_entry(event
, &sdei_list
, list
) {
680 if (event
->type
!= SDEI_EVENT_TYPE_SHARED
)
683 if (event
->reregister
) {
684 err
= sdei_reregister_event(event
);
689 spin_unlock(&sdei_list_lock
);
690 mutex_unlock(&sdei_events_lock
);
695 static int sdei_cpuhp_down(unsigned int cpu
)
697 struct sdei_event
*event
;
698 struct sdei_crosscall_args arg
;
700 /* un-register private events */
701 spin_lock(&sdei_list_lock
);
702 list_for_each_entry(event
, &sdei_list
, list
) {
703 if (event
->type
== SDEI_EVENT_TYPE_SHARED
)
706 CROSSCALL_INIT(arg
, event
);
707 /* call the cross-call function locally... */
708 _local_event_unregister(&arg
);
710 pr_err("Failed to unregister event %u: %d\n",
711 event
->event_num
, arg
.first_error
);
713 spin_unlock(&sdei_list_lock
);
715 return sdei_mask_local_cpu();
718 static int sdei_cpuhp_up(unsigned int cpu
)
720 struct sdei_event
*event
;
721 struct sdei_crosscall_args arg
;
723 /* re-register/enable private events */
724 spin_lock(&sdei_list_lock
);
725 list_for_each_entry(event
, &sdei_list
, list
) {
726 if (event
->type
== SDEI_EVENT_TYPE_SHARED
)
729 if (event
->reregister
) {
730 CROSSCALL_INIT(arg
, event
);
731 /* call the cross-call function locally... */
732 _local_event_register(&arg
);
734 pr_err("Failed to re-register event %u: %d\n",
735 event
->event_num
, arg
.first_error
);
738 if (event
->reenable
) {
739 CROSSCALL_INIT(arg
, event
);
740 _local_event_enable(&arg
);
742 pr_err("Failed to re-enable event %u: %d\n",
743 event
->event_num
, arg
.first_error
);
746 spin_unlock(&sdei_list_lock
);
748 return sdei_unmask_local_cpu();
751 /* When entering idle, mask/unmask events for this cpu */
752 static int sdei_pm_notifier(struct notifier_block
*nb
, unsigned long action
,
759 rv
= sdei_mask_local_cpu();
762 case CPU_PM_ENTER_FAILED
:
763 rv
= sdei_unmask_local_cpu();
770 return notifier_from_errno(rv
);
775 static struct notifier_block sdei_pm_nb
= {
776 .notifier_call
= sdei_pm_notifier
,
779 static int sdei_device_suspend(struct device
*dev
)
781 on_each_cpu(_ipi_mask_cpu
, NULL
, true);
786 static int sdei_device_resume(struct device
*dev
)
788 on_each_cpu(_ipi_unmask_cpu
, NULL
, true);
794 * We need all events to be reregistered when we resume from hibernate.
796 * The sequence is freeze->thaw. Reboot. freeze->restore. We unregister
797 * events during freeze, then re-register and re-enable them during thaw
800 static int sdei_device_freeze(struct device
*dev
)
804 /* unregister private events */
805 cpuhp_remove_state(CPUHP_AP_ARM_SDEI_STARTING
);
807 err
= sdei_unregister_shared();
814 static int sdei_device_thaw(struct device
*dev
)
818 /* re-register shared events */
819 err
= sdei_reregister_shared();
821 pr_warn("Failed to re-register shared events...\n");
822 sdei_mark_interface_broken();
826 err
= cpuhp_setup_state(CPUHP_AP_ARM_SDEI_STARTING
, "SDEI",
827 &sdei_cpuhp_up
, &sdei_cpuhp_down
);
829 pr_warn("Failed to re-register CPU hotplug notifier...\n");
834 static int sdei_device_restore(struct device
*dev
)
838 err
= sdei_platform_reset();
842 return sdei_device_thaw(dev
);
845 static const struct dev_pm_ops sdei_pm_ops
= {
846 .suspend
= sdei_device_suspend
,
847 .resume
= sdei_device_resume
,
848 .freeze
= sdei_device_freeze
,
849 .thaw
= sdei_device_thaw
,
850 .restore
= sdei_device_restore
,
854 * Mask all CPUs and unregister all events on panic, reboot or kexec.
856 static int sdei_reboot_notifier(struct notifier_block
*nb
, unsigned long action
,
860 * We are going to reset the interface, after this there is no point
861 * doing work when we take CPUs offline.
863 cpuhp_remove_state(CPUHP_AP_ARM_SDEI_STARTING
);
865 sdei_platform_reset();
870 static struct notifier_block sdei_reboot_nb
= {
871 .notifier_call
= sdei_reboot_notifier
,
874 static void sdei_smccc_smc(unsigned long function_id
,
875 unsigned long arg0
, unsigned long arg1
,
876 unsigned long arg2
, unsigned long arg3
,
877 unsigned long arg4
, struct arm_smccc_res
*res
)
879 arm_smccc_smc(function_id
, arg0
, arg1
, arg2
, arg3
, arg4
, 0, 0, res
);
882 static void sdei_smccc_hvc(unsigned long function_id
,
883 unsigned long arg0
, unsigned long arg1
,
884 unsigned long arg2
, unsigned long arg3
,
885 unsigned long arg4
, struct arm_smccc_res
*res
)
887 arm_smccc_hvc(function_id
, arg0
, arg1
, arg2
, arg3
, arg4
, 0, 0, res
);
890 static int sdei_get_conduit(struct platform_device
*pdev
)
893 struct device_node
*np
= pdev
->dev
.of_node
;
895 sdei_firmware_call
= NULL
;
897 if (of_property_read_string(np
, "method", &method
)) {
898 pr_warn("missing \"method\" property\n");
899 return CONDUIT_INVALID
;
902 if (!strcmp("hvc", method
)) {
903 sdei_firmware_call
= &sdei_smccc_hvc
;
905 } else if (!strcmp("smc", method
)) {
906 sdei_firmware_call
= &sdei_smccc_smc
;
910 pr_warn("invalid \"method\" property: %s\n", method
);
911 } else if (IS_ENABLED(CONFIG_ACPI
) && !acpi_disabled
) {
912 if (acpi_psci_use_hvc()) {
913 sdei_firmware_call
= &sdei_smccc_hvc
;
916 sdei_firmware_call
= &sdei_smccc_smc
;
921 return CONDUIT_INVALID
;
924 static int sdei_probe(struct platform_device
*pdev
)
930 conduit
= sdei_get_conduit(pdev
);
931 if (!sdei_firmware_call
)
934 err
= sdei_api_get_version(&ver
);
935 if (err
== -EOPNOTSUPP
)
936 pr_err("advertised but not implemented in platform firmware\n");
938 pr_err("Failed to get SDEI version: %d\n", err
);
939 sdei_mark_interface_broken();
943 pr_info("SDEIv%d.%d (0x%x) detected in firmware.\n",
944 (int)SDEI_VERSION_MAJOR(ver
), (int)SDEI_VERSION_MINOR(ver
),
945 (int)SDEI_VERSION_VENDOR(ver
));
947 if (SDEI_VERSION_MAJOR(ver
) != 1) {
948 pr_warn("Conflicting SDEI version detected.\n");
949 sdei_mark_interface_broken();
953 err
= sdei_platform_reset();
957 sdei_entry_point
= sdei_arch_get_entry_point(conduit
);
958 if (!sdei_entry_point
) {
959 /* Not supported due to hardware or boot configuration */
960 sdei_mark_interface_broken();
964 err
= cpu_pm_register_notifier(&sdei_pm_nb
);
966 pr_warn("Failed to register CPU PM notifier...\n");
970 err
= register_reboot_notifier(&sdei_reboot_nb
);
972 pr_warn("Failed to register reboot notifier...\n");
976 err
= cpuhp_setup_state(CPUHP_AP_ARM_SDEI_STARTING
, "SDEI",
977 &sdei_cpuhp_up
, &sdei_cpuhp_down
);
979 pr_warn("Failed to register CPU hotplug notifier...\n");
986 unregister_reboot_notifier(&sdei_reboot_nb
);
989 cpu_pm_unregister_notifier(&sdei_pm_nb
);
992 sdei_mark_interface_broken();
996 static const struct of_device_id sdei_of_match
[] = {
997 { .compatible
= "arm,sdei-1.0" },
1001 static struct platform_driver sdei_driver
= {
1005 .of_match_table
= sdei_of_match
,
1007 .probe
= sdei_probe
,
1010 static bool __init
sdei_present_dt(void)
1012 struct device_node
*np
, *fw_np
;
1014 fw_np
= of_find_node_by_name(NULL
, "firmware");
1018 np
= of_find_matching_node(fw_np
, sdei_of_match
);
1026 static bool __init
sdei_present_acpi(void)
1029 struct platform_device
*pdev
;
1030 struct acpi_table_header
*sdei_table_header
;
1035 status
= acpi_get_table(ACPI_SIG_SDEI
, 0, &sdei_table_header
);
1036 if (ACPI_FAILURE(status
) && status
!= AE_NOT_FOUND
) {
1037 const char *msg
= acpi_format_exception(status
);
1039 pr_info("Failed to get ACPI:SDEI table, %s\n", msg
);
1041 if (ACPI_FAILURE(status
))
1044 pdev
= platform_device_register_simple(sdei_driver
.driver
.name
, 0, NULL
,
1052 static int __init
sdei_init(void)
1054 if (sdei_present_dt() || sdei_present_acpi())
1055 platform_driver_register(&sdei_driver
);
1061 * On an ACPI system SDEI needs to be ready before HEST:GHES tries to register
1062 * its events. ACPI is initialised from a subsys_initcall(), GHES is initialised
1063 * by device_initcall(). We want to be called in the middle.
1065 subsys_initcall_sync(sdei_init
);
1067 int sdei_event_handler(struct pt_regs
*regs
,
1068 struct sdei_registered_event
*arg
)
1071 mm_segment_t orig_addr_limit
;
1072 u32 event_num
= arg
->event_num
;
1074 orig_addr_limit
= get_fs();
1077 err
= arg
->callback(event_num
, regs
, arg
->callback_arg
);
1079 pr_err_ratelimited("event %u on CPU %u failed with error: %d\n",
1080 event_num
, smp_processor_id(), err
);
1082 set_fs(orig_addr_limit
);
1086 NOKPROBE_SYMBOL(sdei_event_handler
);