mm: nobootmem: remove dead code
[platform/kernel/linux-starfive.git] / include / linux / bootmem.h
1 /* SPDX-License-Identifier: GPL-2.0 */
2 /*
3  * Discontiguous memory support, Kanoj Sarcar, SGI, Nov 1999
4  */
5 #ifndef _LINUX_BOOTMEM_H
6 #define _LINUX_BOOTMEM_H
7
8 #include <linux/mmzone.h>
9 #include <linux/mm_types.h>
10 #include <asm/dma.h>
11 #include <asm/processor.h>
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;
24 /*
25  * highest possible page
26  */
27 extern unsigned long long max_possible_pfn;
28
29 extern unsigned long free_all_bootmem(void);
30 extern void reset_node_managed_pages(pg_data_t *pgdat);
31 extern void reset_all_zones_managed_pages(void);
32
33 extern void free_bootmem_node(pg_data_t *pgdat,
34                               unsigned long addr,
35                               unsigned long size);
36 extern void free_bootmem(unsigned long physaddr, unsigned long size);
37 extern void free_bootmem_late(unsigned long physaddr, unsigned long size);
38
39 extern void *__alloc_bootmem(unsigned long size,
40                              unsigned long align,
41                              unsigned long goal);
42 extern void *__alloc_bootmem_nopanic(unsigned long size,
43                                      unsigned long align,
44                                      unsigned long goal) __malloc;
45 extern void *__alloc_bootmem_node(pg_data_t *pgdat,
46                                   unsigned long size,
47                                   unsigned long align,
48                                   unsigned long goal) __malloc;
49 void *__alloc_bootmem_node_high(pg_data_t *pgdat,
50                                   unsigned long size,
51                                   unsigned long align,
52                                   unsigned long goal) __malloc;
53 extern void *__alloc_bootmem_node_nopanic(pg_data_t *pgdat,
54                                   unsigned long size,
55                                   unsigned long align,
56                                   unsigned long goal) __malloc;
57 void *___alloc_bootmem_node_nopanic(pg_data_t *pgdat,
58                                   unsigned long size,
59                                   unsigned long align,
60                                   unsigned long goal,
61                                   unsigned long limit) __malloc;
62 extern void *__alloc_bootmem_low(unsigned long size,
63                                  unsigned long align,
64                                  unsigned long goal) __malloc;
65
66 /* We are using top down, so it is safe to use 0 here */
67 #define BOOTMEM_LOW_LIMIT 0
68
69 #ifndef ARCH_LOW_ADDRESS_LIMIT
70 #define ARCH_LOW_ADDRESS_LIMIT  0xffffffffUL
71 #endif
72
73 #define alloc_bootmem(x) \
74         __alloc_bootmem(x, SMP_CACHE_BYTES, BOOTMEM_LOW_LIMIT)
75 #define alloc_bootmem_align(x, align) \
76         __alloc_bootmem(x, align, BOOTMEM_LOW_LIMIT)
77 #define alloc_bootmem_pages(x) \
78         __alloc_bootmem(x, PAGE_SIZE, BOOTMEM_LOW_LIMIT)
79 #define alloc_bootmem_pages_nopanic(x) \
80         __alloc_bootmem_nopanic(x, PAGE_SIZE, BOOTMEM_LOW_LIMIT)
81 #define alloc_bootmem_node(pgdat, x) \
82         __alloc_bootmem_node(pgdat, x, SMP_CACHE_BYTES, BOOTMEM_LOW_LIMIT)
83 #define alloc_bootmem_node_nopanic(pgdat, x) \
84         __alloc_bootmem_node_nopanic(pgdat, x, SMP_CACHE_BYTES, BOOTMEM_LOW_LIMIT)
85 #define alloc_bootmem_pages_node(pgdat, x) \
86         __alloc_bootmem_node(pgdat, x, PAGE_SIZE, BOOTMEM_LOW_LIMIT)
87
88 #define alloc_bootmem_low(x) \
89         __alloc_bootmem_low(x, SMP_CACHE_BYTES, 0)
90 #define alloc_bootmem_low_pages(x) \
91         __alloc_bootmem_low(x, PAGE_SIZE, 0)
92
93 /* FIXME: use MEMBLOCK_ALLOC_* variants here */
94 #define BOOTMEM_ALLOC_ACCESSIBLE        0
95 #define BOOTMEM_ALLOC_ANYWHERE          (~(phys_addr_t)0)
96
97 /* FIXME: Move to memblock.h at a point where we remove nobootmem.c */
98 void *memblock_virt_alloc_try_nid_raw(phys_addr_t size, phys_addr_t align,
99                                       phys_addr_t min_addr,
100                                       phys_addr_t max_addr, int nid);
101 void *memblock_virt_alloc_try_nid_nopanic(phys_addr_t size,
102                 phys_addr_t align, phys_addr_t min_addr,
103                 phys_addr_t max_addr, int nid);
104 void *memblock_virt_alloc_try_nid(phys_addr_t size, phys_addr_t align,
105                 phys_addr_t min_addr, phys_addr_t max_addr, int nid);
106 void __memblock_free_early(phys_addr_t base, phys_addr_t size);
107 void __memblock_free_late(phys_addr_t base, phys_addr_t size);
108
109 static inline void * __init memblock_virt_alloc(
110                                         phys_addr_t size,  phys_addr_t align)
111 {
112         return memblock_virt_alloc_try_nid(size, align, BOOTMEM_LOW_LIMIT,
113                                             BOOTMEM_ALLOC_ACCESSIBLE,
114                                             NUMA_NO_NODE);
115 }
116
117 static inline void * __init memblock_virt_alloc_raw(
118                                         phys_addr_t size,  phys_addr_t align)
119 {
120         return memblock_virt_alloc_try_nid_raw(size, align, BOOTMEM_LOW_LIMIT,
121                                             BOOTMEM_ALLOC_ACCESSIBLE,
122                                             NUMA_NO_NODE);
123 }
124
125 static inline void * __init memblock_virt_alloc_nopanic(
126                                         phys_addr_t size, phys_addr_t align)
127 {
128         return memblock_virt_alloc_try_nid_nopanic(size, align,
129                                                     BOOTMEM_LOW_LIMIT,
130                                                     BOOTMEM_ALLOC_ACCESSIBLE,
131                                                     NUMA_NO_NODE);
132 }
133
134 static inline void * __init memblock_virt_alloc_low(
135                                         phys_addr_t size, phys_addr_t align)
136 {
137         return memblock_virt_alloc_try_nid(size, align,
138                                                    BOOTMEM_LOW_LIMIT,
139                                                    ARCH_LOW_ADDRESS_LIMIT,
140                                                    NUMA_NO_NODE);
141 }
142 static inline void * __init memblock_virt_alloc_low_nopanic(
143                                         phys_addr_t size, phys_addr_t align)
144 {
145         return memblock_virt_alloc_try_nid_nopanic(size, align,
146                                                    BOOTMEM_LOW_LIMIT,
147                                                    ARCH_LOW_ADDRESS_LIMIT,
148                                                    NUMA_NO_NODE);
149 }
150
151 static inline void * __init memblock_virt_alloc_from_nopanic(
152                 phys_addr_t size, phys_addr_t align, phys_addr_t min_addr)
153 {
154         return memblock_virt_alloc_try_nid_nopanic(size, align, min_addr,
155                                                     BOOTMEM_ALLOC_ACCESSIBLE,
156                                                     NUMA_NO_NODE);
157 }
158
159 static inline void * __init memblock_virt_alloc_node(
160                                                 phys_addr_t size, int nid)
161 {
162         return memblock_virt_alloc_try_nid(size, 0, BOOTMEM_LOW_LIMIT,
163                                             BOOTMEM_ALLOC_ACCESSIBLE, nid);
164 }
165
166 static inline void * __init memblock_virt_alloc_node_nopanic(
167                                                 phys_addr_t size, int nid)
168 {
169         return memblock_virt_alloc_try_nid_nopanic(size, 0, BOOTMEM_LOW_LIMIT,
170                                                     BOOTMEM_ALLOC_ACCESSIBLE,
171                                                     nid);
172 }
173
174 static inline void __init memblock_free_early(
175                                         phys_addr_t base, phys_addr_t size)
176 {
177         __memblock_free_early(base, size);
178 }
179
180 static inline void __init memblock_free_early_nid(
181                                 phys_addr_t base, phys_addr_t size, int nid)
182 {
183         __memblock_free_early(base, size);
184 }
185
186 static inline void __init memblock_free_late(
187                                         phys_addr_t base, phys_addr_t size)
188 {
189         __memblock_free_late(base, size);
190 }
191
192 extern void *alloc_large_system_hash(const char *tablename,
193                                      unsigned long bucketsize,
194                                      unsigned long numentries,
195                                      int scale,
196                                      int flags,
197                                      unsigned int *_hash_shift,
198                                      unsigned int *_hash_mask,
199                                      unsigned long low_limit,
200                                      unsigned long high_limit);
201
202 #define HASH_EARLY      0x00000001      /* Allocating during early boot? */
203 #define HASH_SMALL      0x00000002      /* sub-page allocation allowed, min
204                                          * shift passed via *_hash_shift */
205 #define HASH_ZERO       0x00000004      /* Zero allocated hash table */
206
207 /* Only NUMA needs hash distribution. 64bit NUMA architectures have
208  * sufficient vmalloc space.
209  */
210 #ifdef CONFIG_NUMA
211 #define HASHDIST_DEFAULT IS_ENABLED(CONFIG_64BIT)
212 extern int hashdist;            /* Distribute hashes across NUMA nodes? */
213 #else
214 #define hashdist (0)
215 #endif
216
217
218 #endif /* _LINUX_BOOTMEM_H */