blob: b58873a567b2d87432cb5cbf1feb5a3b4a234025 [file] [log] [blame]
Greg Kroah-Hartmanb2441312017-11-01 15:07:57 +01001/* SPDX-License-Identifier: GPL-2.0 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002/*
3 * Discontiguous memory support, Kanoj Sarcar, SGI, Nov 1999
4 */
5#ifndef _LINUX_BOOTMEM_H
6#define _LINUX_BOOTMEM_H
7
Linus Torvalds1da177e2005-04-16 15:20:36 -07008#include <linux/mmzone.h>
Santosh Shilimkar26f09e92014-01-21 15:50:19 -08009#include <linux/mm_types.h>
Franck Bui-Huue786e862006-09-25 23:31:06 -070010#include <asm/dma.h>
zijun_hu23827052016-10-07 16:59:24 -070011#include <asm/processor.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070012
13/*
14 * simple boot-time physical memory area allocator.
15 */
16
17extern unsigned long max_low_pfn;
18extern unsigned long min_low_pfn;
19
20/*
21 * highest page
22 */
23extern unsigned long max_pfn;
Igor Mammedov8dd33032015-12-04 14:07:05 +010024/*
25 * highest possible page
26 */
27extern unsigned long long max_possible_pfn;
Linus Torvalds1da177e2005-04-16 15:20:36 -070028
Mike Rapoportc6ffc5c2018-10-30 15:09:30 -070029extern unsigned long memblock_free_all(void);
Tang Chenf784a3f2014-11-13 15:19:39 -080030extern void reset_node_managed_pages(pg_data_t *pgdat);
Jiang Liu7b4b2a02013-07-03 15:03:11 -070031extern void reset_all_zones_managed_pages(void);
Johannes Weiner223e8dc2008-07-23 21:28:00 -070032
Yinghai Lu8bba1542011-05-24 17:12:37 -070033/* We are using top down, so it is safe to use 0 here */
34#define BOOTMEM_LOW_LIMIT 0
Yinghai Lu8bba1542011-05-24 17:12:37 -070035
zijun_hu23827052016-10-07 16:59:24 -070036#ifndef ARCH_LOW_ADDRESS_LIMIT
37#define ARCH_LOW_ADDRESS_LIMIT 0xffffffffUL
38#endif
39
Santosh Shilimkar26f09e92014-01-21 15:50:19 -080040/* FIXME: use MEMBLOCK_ALLOC_* variants here */
41#define BOOTMEM_ALLOC_ACCESSIBLE 0
42#define BOOTMEM_ALLOC_ANYWHERE (~(phys_addr_t)0)
43
44/* FIXME: Move to memblock.h at a point where we remove nobootmem.c */
Mike Rapoporteb31d552018-10-30 15:08:04 -070045void *memblock_alloc_try_nid_raw(phys_addr_t size, phys_addr_t align,
Pavel Tatashinea1f5f32017-11-15 17:36:27 -080046 phys_addr_t min_addr,
47 phys_addr_t max_addr, int nid);
Mike Rapoporteb31d552018-10-30 15:08:04 -070048void *memblock_alloc_try_nid_nopanic(phys_addr_t size,
Santosh Shilimkar26f09e92014-01-21 15:50:19 -080049 phys_addr_t align, phys_addr_t min_addr,
50 phys_addr_t max_addr, int nid);
Mike Rapoporteb31d552018-10-30 15:08:04 -070051void *memblock_alloc_try_nid(phys_addr_t size, phys_addr_t align,
Santosh Shilimkar26f09e92014-01-21 15:50:19 -080052 phys_addr_t min_addr, phys_addr_t max_addr, int nid);
53void __memblock_free_early(phys_addr_t base, phys_addr_t size);
54void __memblock_free_late(phys_addr_t base, phys_addr_t size);
55
Mike Rapoporteb31d552018-10-30 15:08:04 -070056static inline void * __init memblock_alloc(
Santosh Shilimkar26f09e92014-01-21 15:50:19 -080057 phys_addr_t size, phys_addr_t align)
58{
Mike Rapoporteb31d552018-10-30 15:08:04 -070059 return memblock_alloc_try_nid(size, align, BOOTMEM_LOW_LIMIT,
Santosh Shilimkar26f09e92014-01-21 15:50:19 -080060 BOOTMEM_ALLOC_ACCESSIBLE,
61 NUMA_NO_NODE);
62}
63
Mike Rapoporteb31d552018-10-30 15:08:04 -070064static inline void * __init memblock_alloc_raw(
Pavel Tatashinea1f5f32017-11-15 17:36:27 -080065 phys_addr_t size, phys_addr_t align)
66{
Mike Rapoporteb31d552018-10-30 15:08:04 -070067 return memblock_alloc_try_nid_raw(size, align, BOOTMEM_LOW_LIMIT,
Pavel Tatashinea1f5f32017-11-15 17:36:27 -080068 BOOTMEM_ALLOC_ACCESSIBLE,
69 NUMA_NO_NODE);
70}
71
Mike Rapoport4fc4a092018-10-30 15:09:03 -070072static inline void * __init memblock_alloc_from(
73 phys_addr_t size, phys_addr_t align, phys_addr_t min_addr)
74{
75 return memblock_alloc_try_nid(size, align, min_addr,
76 BOOTMEM_ALLOC_ACCESSIBLE,
77 NUMA_NO_NODE);
78}
79
Mike Rapoporteb31d552018-10-30 15:08:04 -070080static inline void * __init memblock_alloc_nopanic(
Santosh Shilimkar26f09e92014-01-21 15:50:19 -080081 phys_addr_t size, phys_addr_t align)
82{
Mike Rapoporteb31d552018-10-30 15:08:04 -070083 return memblock_alloc_try_nid_nopanic(size, align,
Santosh Shilimkar26f09e92014-01-21 15:50:19 -080084 BOOTMEM_LOW_LIMIT,
85 BOOTMEM_ALLOC_ACCESSIBLE,
86 NUMA_NO_NODE);
87}
88
Mike Rapoporteb31d552018-10-30 15:08:04 -070089static inline void * __init memblock_alloc_low(
Yinghai Luad6492b2014-01-27 17:06:49 -080090 phys_addr_t size, phys_addr_t align)
91{
Mike Rapoporteb31d552018-10-30 15:08:04 -070092 return memblock_alloc_try_nid(size, align,
Yinghai Luad6492b2014-01-27 17:06:49 -080093 BOOTMEM_LOW_LIMIT,
94 ARCH_LOW_ADDRESS_LIMIT,
95 NUMA_NO_NODE);
96}
Mike Rapoporteb31d552018-10-30 15:08:04 -070097static inline void * __init memblock_alloc_low_nopanic(
Yinghai Luad6492b2014-01-27 17:06:49 -080098 phys_addr_t size, phys_addr_t align)
99{
Mike Rapoporteb31d552018-10-30 15:08:04 -0700100 return memblock_alloc_try_nid_nopanic(size, align,
Yinghai Luad6492b2014-01-27 17:06:49 -0800101 BOOTMEM_LOW_LIMIT,
102 ARCH_LOW_ADDRESS_LIMIT,
103 NUMA_NO_NODE);
104}
105
Mike Rapoporteb31d552018-10-30 15:08:04 -0700106static inline void * __init memblock_alloc_from_nopanic(
Santosh Shilimkar26f09e92014-01-21 15:50:19 -0800107 phys_addr_t size, phys_addr_t align, phys_addr_t min_addr)
108{
Mike Rapoporteb31d552018-10-30 15:08:04 -0700109 return memblock_alloc_try_nid_nopanic(size, align, min_addr,
Santosh Shilimkar26f09e92014-01-21 15:50:19 -0800110 BOOTMEM_ALLOC_ACCESSIBLE,
111 NUMA_NO_NODE);
112}
113
Mike Rapoporteb31d552018-10-30 15:08:04 -0700114static inline void * __init memblock_alloc_node(
Mike Rapoport3913c8f2018-10-30 15:08:36 -0700115 phys_addr_t size, phys_addr_t align, int nid)
Santosh Shilimkar26f09e92014-01-21 15:50:19 -0800116{
Mike Rapoport3913c8f2018-10-30 15:08:36 -0700117 return memblock_alloc_try_nid(size, align, BOOTMEM_LOW_LIMIT,
Santosh Shilimkar26f09e92014-01-21 15:50:19 -0800118 BOOTMEM_ALLOC_ACCESSIBLE, nid);
119}
120
Mike Rapoporteb31d552018-10-30 15:08:04 -0700121static inline void * __init memblock_alloc_node_nopanic(
Santosh Shilimkar26f09e92014-01-21 15:50:19 -0800122 phys_addr_t size, int nid)
123{
Mike Rapoporteb31d552018-10-30 15:08:04 -0700124 return memblock_alloc_try_nid_nopanic(size, 0, BOOTMEM_LOW_LIMIT,
Santosh Shilimkar26f09e92014-01-21 15:50:19 -0800125 BOOTMEM_ALLOC_ACCESSIBLE,
126 nid);
127}
128
129static inline void __init memblock_free_early(
130 phys_addr_t base, phys_addr_t size)
131{
132 __memblock_free_early(base, size);
133}
134
135static inline void __init memblock_free_early_nid(
136 phys_addr_t base, phys_addr_t size, int nid)
137{
138 __memblock_free_early(base, size);
139}
140
141static inline void __init memblock_free_late(
142 phys_addr_t base, phys_addr_t size)
143{
144 __memblock_free_late(base, size);
145}
146
Franck Bui-Huuf71bf0c2006-09-25 23:31:08 -0700147extern void *alloc_large_system_hash(const char *tablename,
148 unsigned long bucketsize,
149 unsigned long numentries,
150 int scale,
151 int flags,
152 unsigned int *_hash_shift,
153 unsigned int *_hash_mask,
Tim Bird31fe62b2012-05-23 13:33:35 +0000154 unsigned long low_limit,
155 unsigned long high_limit);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700156
Andrew Morton04903662006-12-06 20:37:33 -0800157#define HASH_EARLY 0x00000001 /* Allocating during early boot? */
Jan Beulich2c85f512009-09-21 17:03:07 -0700158#define HASH_SMALL 0x00000002 /* sub-page allocation allowed, min
159 * shift passed via *_hash_shift */
Pavel Tatashin3749a8f2017-07-06 15:39:08 -0700160#define HASH_ZERO 0x00000004 /* Zero allocated hash table */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700161
Anton Blanchardc2fdf3a2009-03-31 15:23:19 -0700162/* Only NUMA needs hash distribution. 64bit NUMA architectures have
163 * sufficient vmalloc space.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700164 */
Rasmus Villemoesa9919c72015-06-24 16:56:28 -0700165#ifdef CONFIG_NUMA
166#define HASHDIST_DEFAULT IS_ENABLED(CONFIG_64BIT)
David S. Millerf034b5d2006-08-24 03:08:07 -0700167extern int hashdist; /* Distribute hashes across NUMA nodes? */
Rasmus Villemoesa9919c72015-06-24 16:56:28 -0700168#else
169#define hashdist (0)
170#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700171
Linus Torvalds1da177e2005-04-16 15:20:36 -0700172
173#endif /* _LINUX_BOOTMEM_H */