162306a36Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0 */
262306a36Sopenharmony_ci#ifndef __LINUX_BOOTMEM_INFO_H
362306a36Sopenharmony_ci#define __LINUX_BOOTMEM_INFO_H
462306a36Sopenharmony_ci
562306a36Sopenharmony_ci#include <linux/mm.h>
662306a36Sopenharmony_ci#include <linux/kmemleak.h>
762306a36Sopenharmony_ci
862306a36Sopenharmony_ci/*
962306a36Sopenharmony_ci * Types for free bootmem stored in page->lru.next. These have to be in
1062306a36Sopenharmony_ci * some random range in unsigned long space for debugging purposes.
1162306a36Sopenharmony_ci */
1262306a36Sopenharmony_cienum {
1362306a36Sopenharmony_ci	MEMORY_HOTPLUG_MIN_BOOTMEM_TYPE = 12,
1462306a36Sopenharmony_ci	SECTION_INFO = MEMORY_HOTPLUG_MIN_BOOTMEM_TYPE,
1562306a36Sopenharmony_ci	MIX_SECTION_INFO,
1662306a36Sopenharmony_ci	NODE_INFO,
1762306a36Sopenharmony_ci	MEMORY_HOTPLUG_MAX_BOOTMEM_TYPE = NODE_INFO,
1862306a36Sopenharmony_ci};
1962306a36Sopenharmony_ci
2062306a36Sopenharmony_ci#ifdef CONFIG_HAVE_BOOTMEM_INFO_NODE
2162306a36Sopenharmony_civoid __init register_page_bootmem_info_node(struct pglist_data *pgdat);
2262306a36Sopenharmony_ci
2362306a36Sopenharmony_civoid get_page_bootmem(unsigned long info, struct page *page,
2462306a36Sopenharmony_ci		      unsigned long type);
2562306a36Sopenharmony_civoid put_page_bootmem(struct page *page);
2662306a36Sopenharmony_ci
2762306a36Sopenharmony_ci/*
2862306a36Sopenharmony_ci * Any memory allocated via the memblock allocator and not via the
2962306a36Sopenharmony_ci * buddy will be marked reserved already in the memmap. For those
3062306a36Sopenharmony_ci * pages, we can call this function to free it to buddy allocator.
3162306a36Sopenharmony_ci */
3262306a36Sopenharmony_cistatic inline void free_bootmem_page(struct page *page)
3362306a36Sopenharmony_ci{
3462306a36Sopenharmony_ci	unsigned long magic = page->index;
3562306a36Sopenharmony_ci
3662306a36Sopenharmony_ci	/*
3762306a36Sopenharmony_ci	 * The reserve_bootmem_region sets the reserved flag on bootmem
3862306a36Sopenharmony_ci	 * pages.
3962306a36Sopenharmony_ci	 */
4062306a36Sopenharmony_ci	VM_BUG_ON_PAGE(page_ref_count(page) != 2, page);
4162306a36Sopenharmony_ci
4262306a36Sopenharmony_ci	if (magic == SECTION_INFO || magic == MIX_SECTION_INFO)
4362306a36Sopenharmony_ci		put_page_bootmem(page);
4462306a36Sopenharmony_ci	else
4562306a36Sopenharmony_ci		VM_BUG_ON_PAGE(1, page);
4662306a36Sopenharmony_ci}
4762306a36Sopenharmony_ci#else
4862306a36Sopenharmony_cistatic inline void register_page_bootmem_info_node(struct pglist_data *pgdat)
4962306a36Sopenharmony_ci{
5062306a36Sopenharmony_ci}
5162306a36Sopenharmony_ci
5262306a36Sopenharmony_cistatic inline void put_page_bootmem(struct page *page)
5362306a36Sopenharmony_ci{
5462306a36Sopenharmony_ci}
5562306a36Sopenharmony_ci
5662306a36Sopenharmony_cistatic inline void get_page_bootmem(unsigned long info, struct page *page,
5762306a36Sopenharmony_ci				    unsigned long type)
5862306a36Sopenharmony_ci{
5962306a36Sopenharmony_ci}
6062306a36Sopenharmony_ci
6162306a36Sopenharmony_cistatic inline void free_bootmem_page(struct page *page)
6262306a36Sopenharmony_ci{
6362306a36Sopenharmony_ci	kmemleak_free_part(page_to_virt(page), PAGE_SIZE);
6462306a36Sopenharmony_ci	free_reserved_page(page);
6562306a36Sopenharmony_ci}
6662306a36Sopenharmony_ci#endif
6762306a36Sopenharmony_ci
6862306a36Sopenharmony_ci#endif /* __LINUX_BOOTMEM_INFO_H */
69