1 /* SPDX-License-Identifier: GPL-2.0 */ 2 #ifndef __LINUX_PAGE_EXT_H 3 #define __LINUX_PAGE_EXT_H 4 5 #include <linux/types.h> 6 #include <linux/stacktrace.h> 7 8 struct pglist_data; 9 10 #ifdef CONFIG_PAGE_EXTENSION 11 /** 12 * struct page_ext_operations - per page_ext client operations 13 * @offset: Offset to the client's data within page_ext. Offset is returned to 14 * the client by page_ext_init. 15 * @size: The size of the client data within page_ext. 16 * @need: Function that returns true if client requires page_ext. 17 * @init: (optional) Called to initialize client once page_exts are allocated. 18 * @need_shared_flags: True when client is using shared page_ext->flags 19 * field. 20 * 21 * Each Page Extension client must define page_ext_operations in 22 * page_ext_ops array. 23 */ 24 struct page_ext_operations { 25 size_t offset; 26 size_t size; 27 bool (*need)(void); 28 void (*init)(void); 29 bool need_shared_flags; 30 }; 31 32 /* 33 * The page_ext_flags users must set need_shared_flags to true. 34 */ 35 enum page_ext_flags { 36 PAGE_EXT_OWNER, 37 PAGE_EXT_OWNER_ALLOCATED, 38 #if defined(CONFIG_PAGE_PINNER) 39 /* page migration failed */ 40 PAGE_EXT_PINNER_MIGRATION_FAILED, 41 #endif 42 #if defined(CONFIG_PAGE_IDLE_FLAG) && !defined(CONFIG_64BIT) 43 PAGE_EXT_YOUNG, 44 PAGE_EXT_IDLE, 45 #endif 46 }; 47 48 /* 49 * Page Extension can be considered as an extended mem_map. 50 * A page_ext page is associated with every page descriptor. The 51 * page_ext helps us add more information about the page. 52 * All page_ext are allocated at boot or memory hotplug event, 53 * then the page_ext for pfn always exists. 54 */ 55 struct page_ext { 56 unsigned long flags; 57 }; 58 59 extern bool early_page_ext; 60 extern unsigned long page_ext_size; 61 extern void pgdat_page_ext_init(struct pglist_data *pgdat); 62 early_page_ext_enabled(void)63static inline bool early_page_ext_enabled(void) 64 { 65 return early_page_ext; 66 } 67 68 #ifdef CONFIG_SPARSEMEM page_ext_init_flatmem(void)69static inline void page_ext_init_flatmem(void) 70 { 71 } 72 extern void page_ext_init(void); page_ext_init_flatmem_late(void)73static inline void page_ext_init_flatmem_late(void) 74 { 75 } 76 #else 77 extern void page_ext_init_flatmem(void); 78 extern void page_ext_init_flatmem_late(void); page_ext_init(void)79static inline void page_ext_init(void) 80 { 81 } 82 #endif 83 84 extern struct page_ext *page_ext_get(const struct page *page); 85 extern void page_ext_put(struct page_ext *page_ext); 86 page_ext_data(struct page_ext * page_ext,struct page_ext_operations * ops)87static inline void *page_ext_data(struct page_ext *page_ext, 88 struct page_ext_operations *ops) 89 { 90 return (void *)(page_ext) + ops->offset; 91 } 92 page_ext_next(struct page_ext * curr)93static inline struct page_ext *page_ext_next(struct page_ext *curr) 94 { 95 void *next = curr; 96 next += page_ext_size; 97 return next; 98 } 99 100 #else /* !CONFIG_PAGE_EXTENSION */ 101 struct page_ext; 102 early_page_ext_enabled(void)103static inline bool early_page_ext_enabled(void) 104 { 105 return false; 106 } 107 pgdat_page_ext_init(struct pglist_data * pgdat)108static inline void pgdat_page_ext_init(struct pglist_data *pgdat) 109 { 110 } 111 page_ext_init(void)112static inline void page_ext_init(void) 113 { 114 } 115 page_ext_init_flatmem_late(void)116static inline void page_ext_init_flatmem_late(void) 117 { 118 } 119 page_ext_init_flatmem(void)120static inline void page_ext_init_flatmem(void) 121 { 122 } 123 page_ext_get(const struct page * page)124static inline struct page_ext *page_ext_get(const struct page *page) 125 { 126 return NULL; 127 } 128 page_ext_put(struct page_ext * page_ext)129static inline void page_ext_put(struct page_ext *page_ext) 130 { 131 } 132 #endif /* CONFIG_PAGE_EXTENSION */ 133 #endif /* __LINUX_PAGE_EXT_H */ 134