1 /* SPDX-License-Identifier: GPL-2.0 */
3 * Discontiguous memory support, Kanoj Sarcar, SGI, Nov 1999
5 #ifndef _LINUX_BOOTMEM_H
6 #define _LINUX_BOOTMEM_H
8 #include <linux/mmzone.h>
9 #include <linux/mm_types.h>
11 #include <asm/processor.h>
14 * simple boot-time physical memory area allocator.
17 extern unsigned long max_low_pfn;
18 extern unsigned long min_low_pfn;
23 extern unsigned long max_pfn;
25 * highest possible page
27 extern unsigned long long max_possible_pfn;
29 extern unsigned long memblock_free_all(void);
30 extern void reset_node_managed_pages(pg_data_t *pgdat);
31 extern void reset_all_zones_managed_pages(void);
33 /* We are using top down, so it is safe to use 0 here */
34 #define BOOTMEM_LOW_LIMIT 0
36 #ifndef ARCH_LOW_ADDRESS_LIMIT
37 #define ARCH_LOW_ADDRESS_LIMIT 0xffffffffUL
40 /* FIXME: use MEMBLOCK_ALLOC_* variants here */
41 #define BOOTMEM_ALLOC_ACCESSIBLE 0
42 #define BOOTMEM_ALLOC_ANYWHERE (~(phys_addr_t)0)
44 /* FIXME: Move to memblock.h at a point where we remove nobootmem.c */
45 void *memblock_alloc_try_nid_raw(phys_addr_t size, phys_addr_t align,
47 phys_addr_t max_addr, int nid);
48 void *memblock_alloc_try_nid_nopanic(phys_addr_t size,
49 phys_addr_t align, phys_addr_t min_addr,
50 phys_addr_t max_addr, int nid);
51 void *memblock_alloc_try_nid(phys_addr_t size, phys_addr_t align,
52 phys_addr_t min_addr, phys_addr_t max_addr, int nid);
53 void __memblock_free_early(phys_addr_t base, phys_addr_t size);
54 void __memblock_free_late(phys_addr_t base, phys_addr_t size);
56 static inline void * __init memblock_alloc(
57 phys_addr_t size, phys_addr_t align)
59 return memblock_alloc_try_nid(size, align, BOOTMEM_LOW_LIMIT,
60 BOOTMEM_ALLOC_ACCESSIBLE,
64 static inline void * __init memblock_alloc_raw(
65 phys_addr_t size, phys_addr_t align)
67 return memblock_alloc_try_nid_raw(size, align, BOOTMEM_LOW_LIMIT,
68 BOOTMEM_ALLOC_ACCESSIBLE,
72 static inline void * __init memblock_alloc_from(
73 phys_addr_t size, phys_addr_t align, phys_addr_t min_addr)
75 return memblock_alloc_try_nid(size, align, min_addr,
76 BOOTMEM_ALLOC_ACCESSIBLE,
80 static inline void * __init memblock_alloc_nopanic(
81 phys_addr_t size, phys_addr_t align)
83 return memblock_alloc_try_nid_nopanic(size, align,
85 BOOTMEM_ALLOC_ACCESSIBLE,
89 static inline void * __init memblock_alloc_low(
90 phys_addr_t size, phys_addr_t align)
92 return memblock_alloc_try_nid(size, align,
94 ARCH_LOW_ADDRESS_LIMIT,
97 static inline void * __init memblock_alloc_low_nopanic(
98 phys_addr_t size, phys_addr_t align)
100 return memblock_alloc_try_nid_nopanic(size, align,
102 ARCH_LOW_ADDRESS_LIMIT,
106 static inline void * __init memblock_alloc_from_nopanic(
107 phys_addr_t size, phys_addr_t align, phys_addr_t min_addr)
109 return memblock_alloc_try_nid_nopanic(size, align, min_addr,
110 BOOTMEM_ALLOC_ACCESSIBLE,
114 static inline void * __init memblock_alloc_node(
115 phys_addr_t size, phys_addr_t align, int nid)
117 return memblock_alloc_try_nid(size, align, BOOTMEM_LOW_LIMIT,
118 BOOTMEM_ALLOC_ACCESSIBLE, nid);
121 static inline void * __init memblock_alloc_node_nopanic(
122 phys_addr_t size, int nid)
124 return memblock_alloc_try_nid_nopanic(size, 0, BOOTMEM_LOW_LIMIT,
125 BOOTMEM_ALLOC_ACCESSIBLE,
129 static inline void __init memblock_free_early(
130 phys_addr_t base, phys_addr_t size)
132 __memblock_free_early(base, size);
135 static inline void __init memblock_free_early_nid(
136 phys_addr_t base, phys_addr_t size, int nid)
138 __memblock_free_early(base, size);
141 static inline void __init memblock_free_late(
142 phys_addr_t base, phys_addr_t size)
144 __memblock_free_late(base, size);
147 extern void *alloc_large_system_hash(const char *tablename,
148 unsigned long bucketsize,
149 unsigned long numentries,
152 unsigned int *_hash_shift,
153 unsigned int *_hash_mask,
154 unsigned long low_limit,
155 unsigned long high_limit);
157 #define HASH_EARLY 0x00000001 /* Allocating during early boot? */
158 #define HASH_SMALL 0x00000002 /* sub-page allocation allowed, min
159 * shift passed via *_hash_shift */
160 #define HASH_ZERO 0x00000004 /* Zero allocated hash table */
162 /* Only NUMA needs hash distribution. 64bit NUMA architectures have
163 * sufficient vmalloc space.
166 #define HASHDIST_DEFAULT IS_ENABLED(CONFIG_64BIT)
167 extern int hashdist; /* Distribute hashes across NUMA nodes? */
173 #endif /* _LINUX_BOOTMEM_H */