Commit | Line | Data |
---|---|---|
b2441318 | 1 | /* SPDX-License-Identifier: GPL-2.0 */ |
1da177e4 LT |
2 | /* |
3 | * Discontiguous memory support, Kanoj Sarcar, SGI, Nov 1999 | |
4 | */ | |
5 | #ifndef _LINUX_BOOTMEM_H | |
6 | #define _LINUX_BOOTMEM_H | |
7 | ||
1da177e4 | 8 | #include <linux/mmzone.h> |
26f09e9b | 9 | #include <linux/mm_types.h> |
e786e86a | 10 | #include <asm/dma.h> |
2382705f | 11 | #include <asm/processor.h> |
1da177e4 LT |
12 | |
13 | /* | |
14 | * simple boot-time physical memory area allocator. | |
15 | */ | |
16 | ||
17 | extern unsigned long max_low_pfn; | |
18 | extern unsigned long min_low_pfn; | |
19 | ||
20 | /* | |
21 | * highest page | |
22 | */ | |
23 | extern unsigned long max_pfn; | |
8dd33030 IM |
24 | /* |
25 | * highest possible page | |
26 | */ | |
27 | extern unsigned long long max_possible_pfn; | |
1da177e4 | 28 | |
223e8dc9 | 29 | extern unsigned long free_all_bootmem(void); |
f784a3f1 | 30 | extern void reset_node_managed_pages(pg_data_t *pgdat); |
7b4b2a0d | 31 | extern void reset_all_zones_managed_pages(void); |
223e8dc9 | 32 | |
81df9bff | 33 | extern void free_bootmem_late(unsigned long physaddr, unsigned long size); |
223e8dc9 | 34 | |
8bba154e YL |
35 | /* We are using top down, so it is safe to use 0 here */ |
36 | #define BOOTMEM_LOW_LIMIT 0 | |
8bba154e | 37 | |
2382705f | 38 | #ifndef ARCH_LOW_ADDRESS_LIMIT |
39 | #define ARCH_LOW_ADDRESS_LIMIT 0xffffffffUL | |
40 | #endif | |
41 | ||
26f09e9b SS |
42 | /* FIXME: use MEMBLOCK_ALLOC_* variants here */ |
43 | #define BOOTMEM_ALLOC_ACCESSIBLE 0 | |
44 | #define BOOTMEM_ALLOC_ANYWHERE (~(phys_addr_t)0) | |
45 | ||
46 | /* FIXME: Move to memblock.h at a point where we remove nobootmem.c */ | |
eb31d559 | 47 | void *memblock_alloc_try_nid_raw(phys_addr_t size, phys_addr_t align, |
ea1f5f37 PT |
48 | phys_addr_t min_addr, |
49 | phys_addr_t max_addr, int nid); | |
eb31d559 | 50 | void *memblock_alloc_try_nid_nopanic(phys_addr_t size, |
26f09e9b SS |
51 | phys_addr_t align, phys_addr_t min_addr, |
52 | phys_addr_t max_addr, int nid); | |
eb31d559 | 53 | void *memblock_alloc_try_nid(phys_addr_t size, phys_addr_t align, |
26f09e9b SS |
54 | phys_addr_t min_addr, phys_addr_t max_addr, int nid); |
55 | void __memblock_free_early(phys_addr_t base, phys_addr_t size); | |
56 | void __memblock_free_late(phys_addr_t base, phys_addr_t size); | |
57 | ||
eb31d559 | 58 | static inline void * __init memblock_alloc( |
26f09e9b SS |
59 | phys_addr_t size, phys_addr_t align) |
60 | { | |
eb31d559 | 61 | return memblock_alloc_try_nid(size, align, BOOTMEM_LOW_LIMIT, |
26f09e9b SS |
62 | BOOTMEM_ALLOC_ACCESSIBLE, |
63 | NUMA_NO_NODE); | |
64 | } | |
65 | ||
eb31d559 | 66 | static inline void * __init memblock_alloc_raw( |
ea1f5f37 PT |
67 | phys_addr_t size, phys_addr_t align) |
68 | { | |
eb31d559 | 69 | return memblock_alloc_try_nid_raw(size, align, BOOTMEM_LOW_LIMIT, |
ea1f5f37 PT |
70 | BOOTMEM_ALLOC_ACCESSIBLE, |
71 | NUMA_NO_NODE); | |
72 | } | |
73 | ||
4fc4a09e MR |
74 | static inline void * __init memblock_alloc_from( |
75 | phys_addr_t size, phys_addr_t align, phys_addr_t min_addr) | |
76 | { | |
77 | return memblock_alloc_try_nid(size, align, min_addr, | |
78 | BOOTMEM_ALLOC_ACCESSIBLE, | |
79 | NUMA_NO_NODE); | |
80 | } | |
81 | ||
eb31d559 | 82 | static inline void * __init memblock_alloc_nopanic( |
26f09e9b SS |
83 | phys_addr_t size, phys_addr_t align) |
84 | { | |
eb31d559 | 85 | return memblock_alloc_try_nid_nopanic(size, align, |
26f09e9b SS |
86 | BOOTMEM_LOW_LIMIT, |
87 | BOOTMEM_ALLOC_ACCESSIBLE, | |
88 | NUMA_NO_NODE); | |
89 | } | |
90 | ||
eb31d559 | 91 | static inline void * __init memblock_alloc_low( |
ad6492b8 YL |
92 | phys_addr_t size, phys_addr_t align) |
93 | { | |
eb31d559 | 94 | return memblock_alloc_try_nid(size, align, |
ad6492b8 YL |
95 | BOOTMEM_LOW_LIMIT, |
96 | ARCH_LOW_ADDRESS_LIMIT, | |
97 | NUMA_NO_NODE); | |
98 | } | |
eb31d559 | 99 | static inline void * __init memblock_alloc_low_nopanic( |
ad6492b8 YL |
100 | phys_addr_t size, phys_addr_t align) |
101 | { | |
eb31d559 | 102 | return memblock_alloc_try_nid_nopanic(size, align, |
ad6492b8 YL |
103 | BOOTMEM_LOW_LIMIT, |
104 | ARCH_LOW_ADDRESS_LIMIT, | |
105 | NUMA_NO_NODE); | |
106 | } | |
107 | ||
eb31d559 | 108 | static inline void * __init memblock_alloc_from_nopanic( |
26f09e9b SS |
109 | phys_addr_t size, phys_addr_t align, phys_addr_t min_addr) |
110 | { | |
eb31d559 | 111 | return memblock_alloc_try_nid_nopanic(size, align, min_addr, |
26f09e9b SS |
112 | BOOTMEM_ALLOC_ACCESSIBLE, |
113 | NUMA_NO_NODE); | |
114 | } | |
115 | ||
eb31d559 | 116 | static inline void * __init memblock_alloc_node( |
3913c8f9 | 117 | phys_addr_t size, phys_addr_t align, int nid) |
26f09e9b | 118 | { |
3913c8f9 | 119 | return memblock_alloc_try_nid(size, align, BOOTMEM_LOW_LIMIT, |
26f09e9b SS |
120 | BOOTMEM_ALLOC_ACCESSIBLE, nid); |
121 | } | |
122 | ||
eb31d559 | 123 | static inline void * __init memblock_alloc_node_nopanic( |
26f09e9b SS |
124 | phys_addr_t size, int nid) |
125 | { | |
eb31d559 | 126 | return memblock_alloc_try_nid_nopanic(size, 0, BOOTMEM_LOW_LIMIT, |
26f09e9b SS |
127 | BOOTMEM_ALLOC_ACCESSIBLE, |
128 | nid); | |
129 | } | |
130 | ||
131 | static inline void __init memblock_free_early( | |
132 | phys_addr_t base, phys_addr_t size) | |
133 | { | |
134 | __memblock_free_early(base, size); | |
135 | } | |
136 | ||
137 | static inline void __init memblock_free_early_nid( | |
138 | phys_addr_t base, phys_addr_t size, int nid) | |
139 | { | |
140 | __memblock_free_early(base, size); | |
141 | } | |
142 | ||
143 | static inline void __init memblock_free_late( | |
144 | phys_addr_t base, phys_addr_t size) | |
145 | { | |
146 | __memblock_free_late(base, size); | |
147 | } | |
148 | ||
f71bf0ca FBH |
149 | extern void *alloc_large_system_hash(const char *tablename, |
150 | unsigned long bucketsize, | |
151 | unsigned long numentries, | |
152 | int scale, | |
153 | int flags, | |
154 | unsigned int *_hash_shift, | |
155 | unsigned int *_hash_mask, | |
31fe62b9 TB |
156 | unsigned long low_limit, |
157 | unsigned long high_limit); | |
1da177e4 | 158 | |
04903664 | 159 | #define HASH_EARLY 0x00000001 /* Allocating during early boot? */ |
2c85f51d JB |
160 | #define HASH_SMALL 0x00000002 /* sub-page allocation allowed, min |
161 | * shift passed via *_hash_shift */ | |
3749a8f0 | 162 | #define HASH_ZERO 0x00000004 /* Zero allocated hash table */ |
1da177e4 | 163 | |
c2fdf3a9 AB |
164 | /* Only NUMA needs hash distribution. 64bit NUMA architectures have |
165 | * sufficient vmalloc space. | |
1da177e4 | 166 | */ |
a9919c79 RV |
167 | #ifdef CONFIG_NUMA |
168 | #define HASHDIST_DEFAULT IS_ENABLED(CONFIG_64BIT) | |
169 | extern int hashdist; /* Distribute hashes across NUMA nodes? */ | |
1da177e4 | 170 | #else |
a9919c79 | 171 | #define hashdist (0) |
1da177e4 | 172 | #endif |
1da177e4 LT |
173 | |
174 | ||
175 | #endif /* _LINUX_BOOTMEM_H */ |