xref: /linux/include/linux/kexec_handover.h (revision ae13bd23102805383bf04f26e0b043f3d02c9b15)
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 struct page;
22 
23 #define DECLARE_KHOSER_PTR(name, type) \
24 	union {                        \
25 		phys_addr_t phys;      \
26 		type ptr;              \
27 	} name
28 #define KHOSER_STORE_PTR(dest, val)               \
29 	({                                        \
30 		typeof(val) v = val;              \
31 		typecheck(typeof((dest).ptr), v); \
32 		(dest).phys = virt_to_phys(v);    \
33 	})
34 #define KHOSER_LOAD_PTR(src)                                                 \
35 	({                                                                   \
36 		typeof(src) s = src;                                         \
37 		(typeof((s).ptr))((s).phys ? phys_to_virt((s).phys) : NULL); \
38 	})
39 
40 struct kho_serialization;
41 
42 struct kho_vmalloc_chunk;
43 struct kho_vmalloc {
44 	DECLARE_KHOSER_PTR(first, struct kho_vmalloc_chunk *);
45 	unsigned int total_pages;
46 	unsigned short flags;
47 	unsigned short order;
48 };
49 
50 #ifdef CONFIG_KEXEC_HANDOVER
51 bool kho_is_enabled(void);
52 bool is_kho_boot(void);
53 
54 int kho_preserve_folio(struct folio *folio);
55 int kho_preserve_pages(struct page *page, unsigned int nr_pages);
56 int kho_preserve_vmalloc(void *ptr, struct kho_vmalloc *preservation);
57 struct folio *kho_restore_folio(phys_addr_t phys);
58 struct page *kho_restore_pages(phys_addr_t phys, unsigned int nr_pages);
59 void *kho_restore_vmalloc(const struct kho_vmalloc *preservation);
60 int kho_add_subtree(struct kho_serialization *ser, const char *name, void *fdt);
61 int kho_retrieve_subtree(const char *name, phys_addr_t *phys);
62 
63 int register_kho_notifier(struct notifier_block *nb);
64 int unregister_kho_notifier(struct notifier_block *nb);
65 
66 void kho_memory_init(void);
67 
68 void kho_populate(phys_addr_t fdt_phys, u64 fdt_len, phys_addr_t scratch_phys,
69 		  u64 scratch_len);
70 #else
kho_is_enabled(void)71 static inline bool kho_is_enabled(void)
72 {
73 	return false;
74 }
75 
is_kho_boot(void)76 static inline bool is_kho_boot(void)
77 {
78 	return false;
79 }
80 
kho_preserve_folio(struct folio * folio)81 static inline int kho_preserve_folio(struct folio *folio)
82 {
83 	return -EOPNOTSUPP;
84 }
85 
kho_preserve_pages(struct page * page,unsigned int nr_pages)86 static inline int kho_preserve_pages(struct page *page, unsigned int nr_pages)
87 {
88 	return -EOPNOTSUPP;
89 }
90 
kho_preserve_vmalloc(void * ptr,struct kho_vmalloc * preservation)91 static inline int kho_preserve_vmalloc(void *ptr,
92 				       struct kho_vmalloc *preservation)
93 {
94 	return -EOPNOTSUPP;
95 }
96 
kho_restore_folio(phys_addr_t phys)97 static inline struct folio *kho_restore_folio(phys_addr_t phys)
98 {
99 	return NULL;
100 }
101 
kho_restore_pages(phys_addr_t phys,unsigned int nr_pages)102 static inline struct page *kho_restore_pages(phys_addr_t phys,
103 					     unsigned int nr_pages)
104 {
105 	return NULL;
106 }
107 
kho_restore_vmalloc(const struct kho_vmalloc * preservation)108 static inline void *kho_restore_vmalloc(const struct kho_vmalloc *preservation)
109 {
110 	return NULL;
111 }
112 
kho_add_subtree(struct kho_serialization * ser,const char * name,void * fdt)113 static inline int kho_add_subtree(struct kho_serialization *ser,
114 				  const char *name, void *fdt)
115 {
116 	return -EOPNOTSUPP;
117 }
118 
kho_retrieve_subtree(const char * name,phys_addr_t * phys)119 static inline int kho_retrieve_subtree(const char *name, phys_addr_t *phys)
120 {
121 	return -EOPNOTSUPP;
122 }
123 
register_kho_notifier(struct notifier_block * nb)124 static inline int register_kho_notifier(struct notifier_block *nb)
125 {
126 	return -EOPNOTSUPP;
127 }
128 
unregister_kho_notifier(struct notifier_block * nb)129 static inline int unregister_kho_notifier(struct notifier_block *nb)
130 {
131 	return -EOPNOTSUPP;
132 }
133 
kho_memory_init(void)134 static inline void kho_memory_init(void)
135 {
136 }
137 
kho_populate(phys_addr_t fdt_phys,u64 fdt_len,phys_addr_t scratch_phys,u64 scratch_len)138 static inline void kho_populate(phys_addr_t fdt_phys, u64 fdt_len,
139 				phys_addr_t scratch_phys, u64 scratch_len)
140 {
141 }
142 #endif /* CONFIG_KEXEC_HANDOVER */
143 
144 #endif /* LINUX_KEXEC_HANDOVER_H */
145