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 if (event
->type
== SDEI_EVENT_TYPE_SHARED
)
493 return sdei_api_event_unregister(event
->event_num
);
495 return sdei_do_cross_call(_local_event_unregister
, event
);
498 int sdei_event_unregister(u32 event_num
)
501 struct sdei_event
*event
;
505 mutex_lock(&sdei_events_lock
);
506 event
= sdei_event_find(event_num
);
509 pr_warn("Event %u not registered\n", event_num
);
514 spin_lock(&sdei_list_lock
);
515 event
->reregister
= false;
516 event
->reenable
= false;
517 spin_unlock(&sdei_list_lock
);
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 if (event
->type
== SDEI_EVENT_TYPE_SHARED
)
587 return sdei_api_event_register(event
->event_num
,
590 SDEI_EVENT_REGISTER_RM_ANY
, 0);
592 err
= sdei_do_cross_call(_local_event_register
, event
);
594 sdei_do_cross_call(_local_event_unregister
, event
);
599 int sdei_event_register(u32 event_num
, sdei_event_callback
*cb
, void *arg
)
602 struct sdei_event
*event
;
606 mutex_lock(&sdei_events_lock
);
608 if (sdei_event_find(event_num
)) {
609 pr_warn("Event %u already registered\n", event_num
);
614 event
= sdei_event_create(event_num
, cb
, arg
);
616 err
= PTR_ERR(event
);
617 pr_warn("Failed to create event %u: %d\n", event_num
,
622 spin_lock(&sdei_list_lock
);
623 event
->reregister
= true;
624 spin_unlock(&sdei_list_lock
);
626 err
= _sdei_event_register(event
);
628 spin_lock(&sdei_list_lock
);
629 event
->reregister
= false;
630 event
->reenable
= false;
631 spin_unlock(&sdei_list_lock
);
633 sdei_event_destroy(event
);
634 pr_warn("Failed to register event %u: %d\n", event_num
,
638 mutex_unlock(&sdei_events_lock
);
642 EXPORT_SYMBOL(sdei_event_register
);
644 static int sdei_reregister_event(struct sdei_event
*event
)
648 lockdep_assert_held(&sdei_events_lock
);
650 err
= _sdei_event_register(event
);
652 pr_err("Failed to re-register event %u\n", event
->event_num
);
653 sdei_event_destroy(event
);
657 if (event
->reenable
) {
658 if (event
->type
== SDEI_EVENT_TYPE_SHARED
)
659 err
= sdei_api_event_enable(event
->event_num
);
661 err
= sdei_do_cross_call(_local_event_enable
, event
);
665 pr_err("Failed to re-enable event %u\n", event
->event_num
);
670 static int sdei_reregister_shared(void)
673 struct sdei_event
*event
;
675 mutex_lock(&sdei_events_lock
);
676 spin_lock(&sdei_list_lock
);
677 list_for_each_entry(event
, &sdei_list
, list
) {
678 if (event
->type
!= SDEI_EVENT_TYPE_SHARED
)
681 if (event
->reregister
) {
682 err
= sdei_reregister_event(event
);
687 spin_unlock(&sdei_list_lock
);
688 mutex_unlock(&sdei_events_lock
);
693 static int sdei_cpuhp_down(unsigned int cpu
)
695 struct sdei_event
*event
;
696 struct sdei_crosscall_args arg
;
698 /* un-register private events */
699 spin_lock(&sdei_list_lock
);
700 list_for_each_entry(event
, &sdei_list
, list
) {
701 if (event
->type
== SDEI_EVENT_TYPE_SHARED
)
704 CROSSCALL_INIT(arg
, event
);
705 /* call the cross-call function locally... */
706 _local_event_unregister(&arg
);
708 pr_err("Failed to unregister event %u: %d\n",
709 event
->event_num
, arg
.first_error
);
711 spin_unlock(&sdei_list_lock
);
713 return sdei_mask_local_cpu();
716 static int sdei_cpuhp_up(unsigned int cpu
)
718 struct sdei_event
*event
;
719 struct sdei_crosscall_args arg
;
721 /* re-register/enable private events */
722 spin_lock(&sdei_list_lock
);
723 list_for_each_entry(event
, &sdei_list
, list
) {
724 if (event
->type
== SDEI_EVENT_TYPE_SHARED
)
727 if (event
->reregister
) {
728 CROSSCALL_INIT(arg
, event
);
729 /* call the cross-call function locally... */
730 _local_event_register(&arg
);
732 pr_err("Failed to re-register event %u: %d\n",
733 event
->event_num
, arg
.first_error
);
736 if (event
->reenable
) {
737 CROSSCALL_INIT(arg
, event
);
738 _local_event_enable(&arg
);
740 pr_err("Failed to re-enable event %u: %d\n",
741 event
->event_num
, arg
.first_error
);
744 spin_unlock(&sdei_list_lock
);
746 return sdei_unmask_local_cpu();
749 /* When entering idle, mask/unmask events for this cpu */
750 static int sdei_pm_notifier(struct notifier_block
*nb
, unsigned long action
,
757 rv
= sdei_mask_local_cpu();
760 case CPU_PM_ENTER_FAILED
:
761 rv
= sdei_unmask_local_cpu();
768 return notifier_from_errno(rv
);
773 static struct notifier_block sdei_pm_nb
= {
774 .notifier_call
= sdei_pm_notifier
,
777 static int sdei_device_suspend(struct device
*dev
)
779 on_each_cpu(_ipi_mask_cpu
, NULL
, true);
784 static int sdei_device_resume(struct device
*dev
)
786 on_each_cpu(_ipi_unmask_cpu
, NULL
, true);
792 * We need all events to be reregistered when we resume from hibernate.
794 * The sequence is freeze->thaw. Reboot. freeze->restore. We unregister
795 * events during freeze, then re-register and re-enable them during thaw
798 static int sdei_device_freeze(struct device
*dev
)
802 /* unregister private events */
803 cpuhp_remove_state(CPUHP_AP_ARM_SDEI_STARTING
);
805 err
= sdei_unregister_shared();
812 static int sdei_device_thaw(struct device
*dev
)
816 /* re-register shared events */
817 err
= sdei_reregister_shared();
819 pr_warn("Failed to re-register shared events...\n");
820 sdei_mark_interface_broken();
824 err
= cpuhp_setup_state(CPUHP_AP_ARM_SDEI_STARTING
, "SDEI",
825 &sdei_cpuhp_up
, &sdei_cpuhp_down
);
827 pr_warn("Failed to re-register CPU hotplug notifier...\n");
832 static int sdei_device_restore(struct device
*dev
)
836 err
= sdei_platform_reset();
840 return sdei_device_thaw(dev
);
843 static const struct dev_pm_ops sdei_pm_ops
= {
844 .suspend
= sdei_device_suspend
,
845 .resume
= sdei_device_resume
,
846 .freeze
= sdei_device_freeze
,
847 .thaw
= sdei_device_thaw
,
848 .restore
= sdei_device_restore
,
852 * Mask all CPUs and unregister all events on panic, reboot or kexec.
854 static int sdei_reboot_notifier(struct notifier_block
*nb
, unsigned long action
,
858 * We are going to reset the interface, after this there is no point
859 * doing work when we take CPUs offline.
861 cpuhp_remove_state(CPUHP_AP_ARM_SDEI_STARTING
);
863 sdei_platform_reset();
868 static struct notifier_block sdei_reboot_nb
= {
869 .notifier_call
= sdei_reboot_notifier
,
872 static void sdei_smccc_smc(unsigned long function_id
,
873 unsigned long arg0
, unsigned long arg1
,
874 unsigned long arg2
, unsigned long arg3
,
875 unsigned long arg4
, struct arm_smccc_res
*res
)
877 arm_smccc_smc(function_id
, arg0
, arg1
, arg2
, arg3
, arg4
, 0, 0, res
);
880 static void sdei_smccc_hvc(unsigned long function_id
,
881 unsigned long arg0
, unsigned long arg1
,
882 unsigned long arg2
, unsigned long arg3
,
883 unsigned long arg4
, struct arm_smccc_res
*res
)
885 arm_smccc_hvc(function_id
, arg0
, arg1
, arg2
, arg3
, arg4
, 0, 0, res
);
888 static int sdei_get_conduit(struct platform_device
*pdev
)
891 struct device_node
*np
= pdev
->dev
.of_node
;
893 sdei_firmware_call
= NULL
;
895 if (of_property_read_string(np
, "method", &method
)) {
896 pr_warn("missing \"method\" property\n");
897 return CONDUIT_INVALID
;
900 if (!strcmp("hvc", method
)) {
901 sdei_firmware_call
= &sdei_smccc_hvc
;
903 } else if (!strcmp("smc", method
)) {
904 sdei_firmware_call
= &sdei_smccc_smc
;
908 pr_warn("invalid \"method\" property: %s\n", method
);
909 } else if (IS_ENABLED(CONFIG_ACPI
) && !acpi_disabled
) {
910 if (acpi_psci_use_hvc()) {
911 sdei_firmware_call
= &sdei_smccc_hvc
;
914 sdei_firmware_call
= &sdei_smccc_smc
;
919 return CONDUIT_INVALID
;
922 static int sdei_probe(struct platform_device
*pdev
)
928 conduit
= sdei_get_conduit(pdev
);
929 if (!sdei_firmware_call
)
932 err
= sdei_api_get_version(&ver
);
933 if (err
== -EOPNOTSUPP
)
934 pr_err("advertised but not implemented in platform firmware\n");
936 pr_err("Failed to get SDEI version: %d\n", err
);
937 sdei_mark_interface_broken();
941 pr_info("SDEIv%d.%d (0x%x) detected in firmware.\n",
942 (int)SDEI_VERSION_MAJOR(ver
), (int)SDEI_VERSION_MINOR(ver
),
943 (int)SDEI_VERSION_VENDOR(ver
));
945 if (SDEI_VERSION_MAJOR(ver
) != 1) {
946 pr_warn("Conflicting SDEI version detected.\n");
947 sdei_mark_interface_broken();
951 err
= sdei_platform_reset();
955 sdei_entry_point
= sdei_arch_get_entry_point(conduit
);
956 if (!sdei_entry_point
) {
957 /* Not supported due to hardware or boot configuration */
958 sdei_mark_interface_broken();
962 err
= cpu_pm_register_notifier(&sdei_pm_nb
);
964 pr_warn("Failed to register CPU PM notifier...\n");
968 err
= register_reboot_notifier(&sdei_reboot_nb
);
970 pr_warn("Failed to register reboot notifier...\n");
974 err
= cpuhp_setup_state(CPUHP_AP_ARM_SDEI_STARTING
, "SDEI",
975 &sdei_cpuhp_up
, &sdei_cpuhp_down
);
977 pr_warn("Failed to register CPU hotplug notifier...\n");
984 unregister_reboot_notifier(&sdei_reboot_nb
);
987 cpu_pm_unregister_notifier(&sdei_pm_nb
);
990 sdei_mark_interface_broken();
994 static const struct of_device_id sdei_of_match
[] = {
995 { .compatible
= "arm,sdei-1.0" },
999 static struct platform_driver sdei_driver
= {
1003 .of_match_table
= sdei_of_match
,
1005 .probe
= sdei_probe
,
1008 static bool __init
sdei_present_dt(void)
1010 struct device_node
*np
, *fw_np
;
1012 fw_np
= of_find_node_by_name(NULL
, "firmware");
1016 np
= of_find_matching_node(fw_np
, sdei_of_match
);
1024 static bool __init
sdei_present_acpi(void)
1027 struct platform_device
*pdev
;
1028 struct acpi_table_header
*sdei_table_header
;
1033 status
= acpi_get_table(ACPI_SIG_SDEI
, 0, &sdei_table_header
);
1034 if (ACPI_FAILURE(status
) && status
!= AE_NOT_FOUND
) {
1035 const char *msg
= acpi_format_exception(status
);
1037 pr_info("Failed to get ACPI:SDEI table, %s\n", msg
);
1039 if (ACPI_FAILURE(status
))
1042 pdev
= platform_device_register_simple(sdei_driver
.driver
.name
, 0, NULL
,
1050 static int __init
sdei_init(void)
1052 if (sdei_present_dt() || sdei_present_acpi())
1053 platform_driver_register(&sdei_driver
);
1059 * On an ACPI system SDEI needs to be ready before HEST:GHES tries to register
1060 * its events. ACPI is initialised from a subsys_initcall(), GHES is initialised
1061 * by device_initcall(). We want to be called in the middle.
1063 subsys_initcall_sync(sdei_init
);
1065 int sdei_event_handler(struct pt_regs
*regs
,
1066 struct sdei_registered_event
*arg
)
1069 mm_segment_t orig_addr_limit
;
1070 u32 event_num
= arg
->event_num
;
1072 orig_addr_limit
= get_fs();
1075 err
= arg
->callback(event_num
, regs
, arg
->callback_arg
);
1077 pr_err_ratelimited("event %u on CPU %u failed with error: %d\n",
1078 event_num
, smp_processor_id(), err
);
1080 set_fs(orig_addr_limit
);
1084 NOKPROBE_SYMBOL(sdei_event_handler
);