1426e5c42SMuchun Song /* SPDX-License-Identifier: GPL-2.0 */
2426e5c42SMuchun Song #ifndef __LINUX_BOOTMEM_INFO_H
3426e5c42SMuchun Song #define __LINUX_BOOTMEM_INFO_H
4426e5c42SMuchun Song
5f41f2ed4SMuchun Song #include <linux/mm.h>
6028725e7SLiu Shixin #include <linux/kmemleak.h>
7426e5c42SMuchun Song
8426e5c42SMuchun Song /*
90386aaa6SMatthew Wilcox (Oracle) * Types for free bootmem stored in the low bits of page->private.
10426e5c42SMuchun Song */
110386aaa6SMatthew Wilcox (Oracle) enum bootmem_type {
120386aaa6SMatthew Wilcox (Oracle) MEMORY_HOTPLUG_MIN_BOOTMEM_TYPE = 1,
13426e5c42SMuchun Song SECTION_INFO = MEMORY_HOTPLUG_MIN_BOOTMEM_TYPE,
14426e5c42SMuchun Song MIX_SECTION_INFO,
15426e5c42SMuchun Song NODE_INFO,
16426e5c42SMuchun Song MEMORY_HOTPLUG_MAX_BOOTMEM_TYPE = NODE_INFO,
17426e5c42SMuchun Song };
18426e5c42SMuchun Song
19426e5c42SMuchun Song #ifdef CONFIG_HAVE_BOOTMEM_INFO_NODE
20426e5c42SMuchun Song void __init register_page_bootmem_info_node(struct pglist_data *pgdat);
21*243a75e2SFrank van der Linden void register_page_bootmem_memmap(unsigned long section_nr, struct page *map,
22*243a75e2SFrank van der Linden unsigned long nr_pages);
23426e5c42SMuchun Song
24426e5c42SMuchun Song void get_page_bootmem(unsigned long info, struct page *page,
250386aaa6SMatthew Wilcox (Oracle) enum bootmem_type type);
26426e5c42SMuchun Song void put_page_bootmem(struct page *page);
27f41f2ed4SMuchun Song
bootmem_type(const struct page * page)280386aaa6SMatthew Wilcox (Oracle) static inline enum bootmem_type bootmem_type(const struct page *page)
290386aaa6SMatthew Wilcox (Oracle) {
300386aaa6SMatthew Wilcox (Oracle) return (unsigned long)page->private & 0xf;
310386aaa6SMatthew Wilcox (Oracle) }
320386aaa6SMatthew Wilcox (Oracle)
bootmem_info(const struct page * page)330386aaa6SMatthew Wilcox (Oracle) static inline unsigned long bootmem_info(const struct page *page)
340386aaa6SMatthew Wilcox (Oracle) {
350386aaa6SMatthew Wilcox (Oracle) return (unsigned long)page->private >> 4;
360386aaa6SMatthew Wilcox (Oracle) }
370386aaa6SMatthew Wilcox (Oracle)
38f41f2ed4SMuchun Song /*
39f41f2ed4SMuchun Song * Any memory allocated via the memblock allocator and not via the
40f41f2ed4SMuchun Song * buddy will be marked reserved already in the memmap. For those
41f41f2ed4SMuchun Song * pages, we can call this function to free it to buddy allocator.
42f41f2ed4SMuchun Song */
free_bootmem_page(struct page * page)43f41f2ed4SMuchun Song static inline void free_bootmem_page(struct page *page)
44f41f2ed4SMuchun Song {
450386aaa6SMatthew Wilcox (Oracle) enum bootmem_type type = bootmem_type(page);
46f41f2ed4SMuchun Song
47f41f2ed4SMuchun Song /*
48f41f2ed4SMuchun Song * The reserve_bootmem_region sets the reserved flag on bootmem
49f41f2ed4SMuchun Song * pages.
50f41f2ed4SMuchun Song */
51f41f2ed4SMuchun Song VM_BUG_ON_PAGE(page_ref_count(page) != 2, page);
52f41f2ed4SMuchun Song
530386aaa6SMatthew Wilcox (Oracle) if (type == SECTION_INFO || type == MIX_SECTION_INFO)
54f41f2ed4SMuchun Song put_page_bootmem(page);
55f41f2ed4SMuchun Song else
56f41f2ed4SMuchun Song VM_BUG_ON_PAGE(1, page);
57f41f2ed4SMuchun Song }
58426e5c42SMuchun Song #else
register_page_bootmem_info_node(struct pglist_data * pgdat)59426e5c42SMuchun Song static inline void register_page_bootmem_info_node(struct pglist_data *pgdat)
60426e5c42SMuchun Song {
61426e5c42SMuchun Song }
62426e5c42SMuchun Song
register_page_bootmem_memmap(unsigned long section_nr,struct page * map,unsigned long nr_pages)63*243a75e2SFrank van der Linden static inline void register_page_bootmem_memmap(unsigned long section_nr,
64*243a75e2SFrank van der Linden struct page *map, unsigned long nr_pages)
65*243a75e2SFrank van der Linden {
66*243a75e2SFrank van der Linden }
67*243a75e2SFrank van der Linden
put_page_bootmem(struct page * page)68426e5c42SMuchun Song static inline void put_page_bootmem(struct page *page)
69426e5c42SMuchun Song {
70426e5c42SMuchun Song }
71426e5c42SMuchun Song
bootmem_type(const struct page * page)720386aaa6SMatthew Wilcox (Oracle) static inline enum bootmem_type bootmem_type(const struct page *page)
730386aaa6SMatthew Wilcox (Oracle) {
740386aaa6SMatthew Wilcox (Oracle) return SECTION_INFO;
750386aaa6SMatthew Wilcox (Oracle) }
760386aaa6SMatthew Wilcox (Oracle)
bootmem_info(const struct page * page)770386aaa6SMatthew Wilcox (Oracle) static inline unsigned long bootmem_info(const struct page *page)
780386aaa6SMatthew Wilcox (Oracle) {
790386aaa6SMatthew Wilcox (Oracle) return 0;
800386aaa6SMatthew Wilcox (Oracle) }
810386aaa6SMatthew Wilcox (Oracle)
get_page_bootmem(unsigned long info,struct page * page,enum bootmem_type type)82426e5c42SMuchun Song static inline void get_page_bootmem(unsigned long info, struct page *page,
830386aaa6SMatthew Wilcox (Oracle) enum bootmem_type type)
84426e5c42SMuchun Song {
85426e5c42SMuchun Song }
86f41f2ed4SMuchun Song
free_bootmem_page(struct page * page)87f41f2ed4SMuchun Song static inline void free_bootmem_page(struct page *page)
88f41f2ed4SMuchun Song {
8980203f1cSLiu Shixin kmemleak_free_part_phys(PFN_PHYS(page_to_pfn(page)), PAGE_SIZE);
90f41f2ed4SMuchun Song free_reserved_page(page);
91f41f2ed4SMuchun Song }
92426e5c42SMuchun Song #endif
93426e5c42SMuchun Song
94426e5c42SMuchun Song #endif /* __LINUX_BOOTMEM_INFO_H */
95