1 /* SPDX-License-Identifier: GPL-2.0 */
2 #ifndef LINUX_KEXEC_HANDOVER_H
3 #define LINUX_KEXEC_HANDOVER_H
4
5 #include <linux/types.h>
6 #include <linux/errno.h>
7
8 struct kho_scratch {
9 phys_addr_t addr;
10 phys_addr_t size;
11 };
12
13 /* KHO Notifier index */
14 enum kho_event {
15 KEXEC_KHO_FINALIZE = 0,
16 KEXEC_KHO_ABORT = 1,
17 };
18
19 struct folio;
20 struct notifier_block;
21
22 #define DECLARE_KHOSER_PTR(name, type) \
23 union { \
24 phys_addr_t phys; \
25 type ptr; \
26 } name
27 #define KHOSER_STORE_PTR(dest, val) \
28 ({ \
29 typeof(val) v = val; \
30 typecheck(typeof((dest).ptr), v); \
31 (dest).phys = virt_to_phys(v); \
32 })
33 #define KHOSER_LOAD_PTR(src) \
34 ({ \
35 typeof(src) s = src; \
36 (typeof((s).ptr))((s).phys ? phys_to_virt((s).phys) : NULL); \
37 })
38
39 struct kho_serialization;
40
41 #ifdef CONFIG_KEXEC_HANDOVER
42 bool kho_is_enabled(void);
43
44 int kho_preserve_folio(struct folio *folio);
45 int kho_preserve_phys(phys_addr_t phys, size_t size);
46 struct folio *kho_restore_folio(phys_addr_t phys);
47 int kho_add_subtree(struct kho_serialization *ser, const char *name, void *fdt);
48 int kho_retrieve_subtree(const char *name, phys_addr_t *phys);
49
50 int register_kho_notifier(struct notifier_block *nb);
51 int unregister_kho_notifier(struct notifier_block *nb);
52
53 void kho_memory_init(void);
54
55 void kho_populate(phys_addr_t fdt_phys, u64 fdt_len, phys_addr_t scratch_phys,
56 u64 scratch_len);
57 #else
kho_is_enabled(void)58 static inline bool kho_is_enabled(void)
59 {
60 return false;
61 }
62
kho_preserve_folio(struct folio * folio)63 static inline int kho_preserve_folio(struct folio *folio)
64 {
65 return -EOPNOTSUPP;
66 }
67
kho_preserve_phys(phys_addr_t phys,size_t size)68 static inline int kho_preserve_phys(phys_addr_t phys, size_t size)
69 {
70 return -EOPNOTSUPP;
71 }
72
kho_restore_folio(phys_addr_t phys)73 static inline struct folio *kho_restore_folio(phys_addr_t phys)
74 {
75 return NULL;
76 }
77
kho_add_subtree(struct kho_serialization * ser,const char * name,void * fdt)78 static inline int kho_add_subtree(struct kho_serialization *ser,
79 const char *name, void *fdt)
80 {
81 return -EOPNOTSUPP;
82 }
83
kho_retrieve_subtree(const char * name,phys_addr_t * phys)84 static inline int kho_retrieve_subtree(const char *name, phys_addr_t *phys)
85 {
86 return -EOPNOTSUPP;
87 }
88
register_kho_notifier(struct notifier_block * nb)89 static inline int register_kho_notifier(struct notifier_block *nb)
90 {
91 return -EOPNOTSUPP;
92 }
93
unregister_kho_notifier(struct notifier_block * nb)94 static inline int unregister_kho_notifier(struct notifier_block *nb)
95 {
96 return -EOPNOTSUPP;
97 }
98
kho_memory_init(void)99 static inline void kho_memory_init(void)
100 {
101 }
102
kho_populate(phys_addr_t fdt_phys,u64 fdt_len,phys_addr_t scratch_phys,u64 scratch_len)103 static inline void kho_populate(phys_addr_t fdt_phys, u64 fdt_len,
104 phys_addr_t scratch_phys, u64 scratch_len)
105 {
106 }
107 #endif /* CONFIG_KEXEC_HANDOVER */
108
109 #endif /* LINUX_KEXEC_HANDOVER_H */
110