at master 3.7 kB view raw
1/* SPDX-License-Identifier: GPL-2.0 */ 2#ifndef LINUX_KEXEC_HANDOVER_H 3#define LINUX_KEXEC_HANDOVER_H 4 5#include <linux/err.h> 6#include <linux/errno.h> 7#include <linux/types.h> 8 9struct kho_scratch { 10 phys_addr_t addr; 11 phys_addr_t size; 12}; 13 14struct folio; 15struct page; 16 17#define DECLARE_KHOSER_PTR(name, type) \ 18 union { \ 19 phys_addr_t phys; \ 20 type ptr; \ 21 } name 22#define KHOSER_STORE_PTR(dest, val) \ 23 ({ \ 24 typeof(val) v = val; \ 25 typecheck(typeof((dest).ptr), v); \ 26 (dest).phys = virt_to_phys(v); \ 27 }) 28#define KHOSER_LOAD_PTR(src) \ 29 ({ \ 30 typeof(src) s = src; \ 31 (typeof((s).ptr))((s).phys ? phys_to_virt((s).phys) : NULL); \ 32 }) 33 34struct kho_vmalloc_chunk; 35struct kho_vmalloc { 36 DECLARE_KHOSER_PTR(first, struct kho_vmalloc_chunk *); 37 unsigned int total_pages; 38 unsigned short flags; 39 unsigned short order; 40}; 41 42#ifdef CONFIG_KEXEC_HANDOVER 43bool kho_is_enabled(void); 44bool is_kho_boot(void); 45 46int kho_preserve_folio(struct folio *folio); 47void kho_unpreserve_folio(struct folio *folio); 48int kho_preserve_pages(struct page *page, unsigned int nr_pages); 49void kho_unpreserve_pages(struct page *page, unsigned int nr_pages); 50int kho_preserve_vmalloc(void *ptr, struct kho_vmalloc *preservation); 51void kho_unpreserve_vmalloc(struct kho_vmalloc *preservation); 52void *kho_alloc_preserve(size_t size); 53void kho_unpreserve_free(void *mem); 54void kho_restore_free(void *mem); 55struct folio *kho_restore_folio(phys_addr_t phys); 56struct page *kho_restore_pages(phys_addr_t phys, unsigned int nr_pages); 57void *kho_restore_vmalloc(const struct kho_vmalloc *preservation); 58int kho_add_subtree(const char *name, void *fdt); 59void kho_remove_subtree(void *fdt); 60int kho_retrieve_subtree(const char *name, phys_addr_t *phys); 61 62void kho_memory_init(void); 63 64void kho_populate(phys_addr_t fdt_phys, u64 fdt_len, phys_addr_t scratch_phys, 65 u64 scratch_len); 66#else 67static inline bool kho_is_enabled(void) 68{ 69 return false; 70} 71 72static inline bool is_kho_boot(void) 73{ 74 return false; 75} 76 77static inline int kho_preserve_folio(struct folio *folio) 78{ 79 return -EOPNOTSUPP; 80} 81 82static inline void kho_unpreserve_folio(struct folio *folio) { } 83 84static inline int kho_preserve_pages(struct page *page, unsigned int nr_pages) 85{ 86 return -EOPNOTSUPP; 87} 88 89static inline void kho_unpreserve_pages(struct page *page, unsigned int nr_pages) { } 90 91static inline int kho_preserve_vmalloc(void *ptr, 92 struct kho_vmalloc *preservation) 93{ 94 return -EOPNOTSUPP; 95} 96 97static inline void kho_unpreserve_vmalloc(struct kho_vmalloc *preservation) { } 98 99static inline void *kho_alloc_preserve(size_t size) 100{ 101 return ERR_PTR(-EOPNOTSUPP); 102} 103 104static inline void kho_unpreserve_free(void *mem) { } 105static inline void kho_restore_free(void *mem) { } 106 107static inline struct folio *kho_restore_folio(phys_addr_t phys) 108{ 109 return NULL; 110} 111 112static inline struct page *kho_restore_pages(phys_addr_t phys, 113 unsigned int nr_pages) 114{ 115 return NULL; 116} 117 118static inline void *kho_restore_vmalloc(const struct kho_vmalloc *preservation) 119{ 120 return NULL; 121} 122 123static inline int kho_add_subtree(const char *name, void *fdt) 124{ 125 return -EOPNOTSUPP; 126} 127 128static inline void kho_remove_subtree(void *fdt) { } 129 130static inline int kho_retrieve_subtree(const char *name, phys_addr_t *phys) 131{ 132 return -EOPNOTSUPP; 133} 134 135static inline void kho_memory_init(void) { } 136 137static inline void kho_populate(phys_addr_t fdt_phys, u64 fdt_len, 138 phys_addr_t scratch_phys, u64 scratch_len) 139{ 140} 141#endif /* CONFIG_KEXEC_HANDOVER */ 142 143#endif /* LINUX_KEXEC_HANDOVER_H */