xref: /OK3568_Linux_fs/kernel/include/linux/arm_sdei.h (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1 // SPDX-License-Identifier: GPL-2.0
2 // Copyright (C) 2017 Arm Ltd.
3 #ifndef __LINUX_ARM_SDEI_H
4 #define __LINUX_ARM_SDEI_H
5 
6 #include <uapi/linux/arm_sdei.h>
7 
8 #include <acpi/ghes.h>
9 
10 #ifdef CONFIG_ARM_SDE_INTERFACE
11 #include <asm/sdei.h>
12 #endif
13 
14 /* Arch code should override this to set the entry point from firmware... */
15 #ifndef sdei_arch_get_entry_point
16 #define sdei_arch_get_entry_point(conduit)	(0)
17 #endif
18 
19 /*
20  * When an event occurs sdei_event_handler() will call a user-provided callback
21  * like this in NMI context on the CPU that received the event.
22  */
23 typedef int (sdei_event_callback)(u32 event, struct pt_regs *regs, void *arg);
24 
25 /*
26  * Register your callback to claim an event. The event must be described
27  * by firmware.
28  */
29 int sdei_event_register(u32 event_num, sdei_event_callback *cb, void *arg);
30 
31 /*
32  * Calls to sdei_event_unregister() may return EINPROGRESS. Keep calling
33  * it until it succeeds.
34  */
35 int sdei_event_unregister(u32 event_num);
36 
37 int sdei_event_enable(u32 event_num);
38 int sdei_event_disable(u32 event_num);
39 
40 #ifdef CONFIG_FIQ_DEBUGGER_TRUST_ZONE
41 #ifdef CONFIG_ARM_SDE_INTERFACE
42 int sdei_event_enable_nolock(u32 event_num);
43 int sdei_event_disable_nolock(u32 event_num);
44 int sdei_event_routing_set_nolock(u32 event_num, unsigned long flags,
45 				  unsigned long affinity);
46 int sdei_event_routing_set(u32 event_num, unsigned long flags,
47 			   unsigned long affinity);
48 int sdei_interrupt_bind(u32 intr_num, u32 *event_num);
49 int sdei_interrupt_release(u32 event_num);
50 #else
sdei_event_enable_nolock(u32 event_num)51 static inline int sdei_event_enable_nolock(u32 event_num)
52 {
53 	return SDEI_NOT_SUPPORTED;
54 }
55 
sdei_event_disable_nolock(u32 event_num)56 static inline int sdei_event_disable_nolock(u32 event_num)
57 {
58 	return SDEI_NOT_SUPPORTED;
59 }
60 
sdei_event_routing_set_nolock(u32 event_num,unsigned long flags,unsigned long affinity)61 static inline int sdei_event_routing_set_nolock(u32 event_num,
62 						unsigned long flags,
63 						unsigned long affinity)
64 {
65 	return SDEI_NOT_SUPPORTED;
66 }
67 
sdei_event_routing_set(u32 event_num,unsigned long flags,unsigned long affinity)68 static inline int sdei_event_routing_set(u32 event_num,
69 					 unsigned long flags,
70 					 unsigned long affinity)
71 {
72 	return SDEI_NOT_SUPPORTED;
73 }
74 
sdei_interrupt_bind(u32 intr_num,u32 * event_num)75 static inline int sdei_interrupt_bind(u32 intr_num, u32 *event_num)
76 {
77 	return SDEI_NOT_SUPPORTED;
78 }
79 
sdei_interrupt_release(u32 event_num)80 static inline int sdei_interrupt_release(u32 event_num)
81 {
82 	return SDEI_NOT_SUPPORTED;
83 }
84 #endif /* CONFIG_ARM_SDE_INTERFACE */
85 #endif /* CONFIG_FIQ_DEBUGGER_TRUST_ZONE */
86 
87 /* GHES register/unregister helpers */
88 int sdei_register_ghes(struct ghes *ghes, sdei_event_callback *normal_cb,
89 		       sdei_event_callback *critical_cb);
90 int sdei_unregister_ghes(struct ghes *ghes);
91 
92 #ifdef CONFIG_ARM_SDE_INTERFACE
93 /* For use by arch code when CPU hotplug notifiers are not appropriate. */
94 int sdei_mask_local_cpu(void);
95 int sdei_unmask_local_cpu(void);
96 #else
sdei_mask_local_cpu(void)97 static inline int sdei_mask_local_cpu(void) { return 0; }
sdei_unmask_local_cpu(void)98 static inline int sdei_unmask_local_cpu(void) { return 0; }
99 #endif /* CONFIG_ARM_SDE_INTERFACE */
100 
101 
102 /*
103  * This struct represents an event that has been registered. The driver
104  * maintains a list of all events, and which ones are registered. (Private
105  * events have one entry in the list, but are registered on each CPU).
106  * A pointer to this struct is passed to firmware, and back to the event
107  * handler. The event handler can then use this to invoke the registered
108  * callback, without having to walk the list.
109  *
110  * For CPU private events, this structure is per-cpu.
111  */
112 struct sdei_registered_event {
113 	/* For use by arch code: */
114 	struct pt_regs          interrupted_regs;
115 
116 	sdei_event_callback	*callback;
117 	void			*callback_arg;
118 	u32			 event_num;
119 	u8			 priority;
120 };
121 
122 /* The arch code entry point should then call this when an event arrives. */
123 int notrace sdei_event_handler(struct pt_regs *regs,
124 			       struct sdei_registered_event *arg);
125 
126 /* arch code may use this to retrieve the extra registers. */
127 int sdei_api_event_context(u32 query, u64 *result);
128 
129 #endif /* __LINUX_ARM_SDEI_H */
130