1 /* SPDX-License-Identifier: GPL-2.0 */ 2 #ifndef __LINUX_BOOTMEM_INFO_H 3 #define __LINUX_BOOTMEM_INFO_H 4 5 #include <linux/mm.h> 6 #include <linux/kmemleak.h> 7 8 /* 9 * Types for free bootmem stored in the low bits of page->private. 10 */ 11 enum bootmem_type { 12 MEMORY_HOTPLUG_MIN_BOOTMEM_TYPE = 1, 13 SECTION_INFO = MEMORY_HOTPLUG_MIN_BOOTMEM_TYPE, 14 MIX_SECTION_INFO, 15 NODE_INFO, 16 MEMORY_HOTPLUG_MAX_BOOTMEM_TYPE = NODE_INFO, 17 }; 18 19 #ifdef CONFIG_HAVE_BOOTMEM_INFO_NODE 20 void __init register_page_bootmem_info_node(struct pglist_data *pgdat); 21 22 void get_page_bootmem(unsigned long info, struct page *page, 23 enum bootmem_type type); 24 void put_page_bootmem(struct page *page); 25 26 static inline enum bootmem_type bootmem_type(const struct page *page) 27 { 28 return (unsigned long)page->private & 0xf; 29 } 30 31 static inline unsigned long bootmem_info(const struct page *page) 32 { 33 return (unsigned long)page->private >> 4; 34 } 35 36 /* 37 * Any memory allocated via the memblock allocator and not via the 38 * buddy will be marked reserved already in the memmap. For those 39 * pages, we can call this function to free it to buddy allocator. 40 */ 41 static inline void free_bootmem_page(struct page *page) 42 { 43 enum bootmem_type type = bootmem_type(page); 44 45 /* 46 * The reserve_bootmem_region sets the reserved flag on bootmem 47 * pages. 48 */ 49 VM_BUG_ON_PAGE(page_ref_count(page) != 2, page); 50 51 if (type == SECTION_INFO || type == MIX_SECTION_INFO) 52 put_page_bootmem(page); 53 else 54 VM_BUG_ON_PAGE(1, page); 55 } 56 #else 57 static inline void register_page_bootmem_info_node(struct pglist_data *pgdat) 58 { 59 } 60 61 static inline void put_page_bootmem(struct page *page) 62 { 63 } 64 65 static inline enum bootmem_type bootmem_type(const struct page *page) 66 { 67 return SECTION_INFO; 68 } 69 70 static inline unsigned long bootmem_info(const struct page *page) 71 { 72 return 0; 73 } 74 75 static inline void get_page_bootmem(unsigned long info, struct page *page, 76 enum bootmem_type type) 77 { 78 } 79 80 static inline void free_bootmem_page(struct page *page) 81 { 82 kmemleak_free_part_phys(PFN_PHYS(page_to_pfn(page)), PAGE_SIZE); 83 free_reserved_page(page); 84 } 85 #endif 86 87 #endif /* __LINUX_BOOTMEM_INFO_H */ 88