Greg Kroah-Hartman | b244131 | 2017-11-01 15:07:57 +0100 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0 */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2 | /* |
| 3 | * Discontiguous memory support, Kanoj Sarcar, SGI, Nov 1999 |
| 4 | */ |
| 5 | #ifndef _LINUX_BOOTMEM_H |
| 6 | #define _LINUX_BOOTMEM_H |
| 7 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8 | #include <linux/mmzone.h> |
Santosh Shilimkar | 26f09e9 | 2014-01-21 15:50:19 -0800 | [diff] [blame] | 9 | #include <linux/mm_types.h> |
Franck Bui-Huu | e786e86 | 2006-09-25 23:31:06 -0700 | [diff] [blame] | 10 | #include <asm/dma.h> |
zijun_hu | 2382705 | 2016-10-07 16:59:24 -0700 | [diff] [blame] | 11 | #include <asm/processor.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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; |
Igor Mammedov | 8dd3303 | 2015-12-04 14:07:05 +0100 | [diff] [blame] | 24 | /* |
| 25 | * highest possible page |
| 26 | */ |
| 27 | extern unsigned long long max_possible_pfn; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 28 | |
Mike Rapoport | c6ffc5c | 2018-10-30 15:09:30 -0700 | [diff] [blame] | 29 | extern unsigned long memblock_free_all(void); |
Tang Chen | f784a3f | 2014-11-13 15:19:39 -0800 | [diff] [blame] | 30 | extern void reset_node_managed_pages(pg_data_t *pgdat); |
Jiang Liu | 7b4b2a0 | 2013-07-03 15:03:11 -0700 | [diff] [blame] | 31 | extern void reset_all_zones_managed_pages(void); |
Johannes Weiner | 223e8dc | 2008-07-23 21:28:00 -0700 | [diff] [blame] | 32 | |
Yinghai Lu | 8bba154 | 2011-05-24 17:12:37 -0700 | [diff] [blame] | 33 | /* We are using top down, so it is safe to use 0 here */ |
| 34 | #define BOOTMEM_LOW_LIMIT 0 |
Yinghai Lu | 8bba154 | 2011-05-24 17:12:37 -0700 | [diff] [blame] | 35 | |
zijun_hu | 2382705 | 2016-10-07 16:59:24 -0700 | [diff] [blame] | 36 | #ifndef ARCH_LOW_ADDRESS_LIMIT |
| 37 | #define ARCH_LOW_ADDRESS_LIMIT 0xffffffffUL |
| 38 | #endif |
| 39 | |
Santosh Shilimkar | 26f09e9 | 2014-01-21 15:50:19 -0800 | [diff] [blame] | 40 | /* 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 Rapoport | eb31d55 | 2018-10-30 15:08:04 -0700 | [diff] [blame] | 45 | void *memblock_alloc_try_nid_raw(phys_addr_t size, phys_addr_t align, |
Pavel Tatashin | ea1f5f3 | 2017-11-15 17:36:27 -0800 | [diff] [blame] | 46 | phys_addr_t min_addr, |
| 47 | phys_addr_t max_addr, int nid); |
Mike Rapoport | eb31d55 | 2018-10-30 15:08:04 -0700 | [diff] [blame] | 48 | void *memblock_alloc_try_nid_nopanic(phys_addr_t size, |
Santosh Shilimkar | 26f09e9 | 2014-01-21 15:50:19 -0800 | [diff] [blame] | 49 | phys_addr_t align, phys_addr_t min_addr, |
| 50 | phys_addr_t max_addr, int nid); |
Mike Rapoport | eb31d55 | 2018-10-30 15:08:04 -0700 | [diff] [blame] | 51 | void *memblock_alloc_try_nid(phys_addr_t size, phys_addr_t align, |
Santosh Shilimkar | 26f09e9 | 2014-01-21 15:50:19 -0800 | [diff] [blame] | 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); |
| 55 | |
Mike Rapoport | eb31d55 | 2018-10-30 15:08:04 -0700 | [diff] [blame] | 56 | static inline void * __init memblock_alloc( |
Santosh Shilimkar | 26f09e9 | 2014-01-21 15:50:19 -0800 | [diff] [blame] | 57 | phys_addr_t size, phys_addr_t align) |
| 58 | { |
Mike Rapoport | eb31d55 | 2018-10-30 15:08:04 -0700 | [diff] [blame] | 59 | return memblock_alloc_try_nid(size, align, BOOTMEM_LOW_LIMIT, |
Santosh Shilimkar | 26f09e9 | 2014-01-21 15:50:19 -0800 | [diff] [blame] | 60 | BOOTMEM_ALLOC_ACCESSIBLE, |
| 61 | NUMA_NO_NODE); |
| 62 | } |
| 63 | |
Mike Rapoport | eb31d55 | 2018-10-30 15:08:04 -0700 | [diff] [blame] | 64 | static inline void * __init memblock_alloc_raw( |
Pavel Tatashin | ea1f5f3 | 2017-11-15 17:36:27 -0800 | [diff] [blame] | 65 | phys_addr_t size, phys_addr_t align) |
| 66 | { |
Mike Rapoport | eb31d55 | 2018-10-30 15:08:04 -0700 | [diff] [blame] | 67 | return memblock_alloc_try_nid_raw(size, align, BOOTMEM_LOW_LIMIT, |
Pavel Tatashin | ea1f5f3 | 2017-11-15 17:36:27 -0800 | [diff] [blame] | 68 | BOOTMEM_ALLOC_ACCESSIBLE, |
| 69 | NUMA_NO_NODE); |
| 70 | } |
| 71 | |
Mike Rapoport | 4fc4a09 | 2018-10-30 15:09:03 -0700 | [diff] [blame] | 72 | static 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 Rapoport | eb31d55 | 2018-10-30 15:08:04 -0700 | [diff] [blame] | 80 | static inline void * __init memblock_alloc_nopanic( |
Santosh Shilimkar | 26f09e9 | 2014-01-21 15:50:19 -0800 | [diff] [blame] | 81 | phys_addr_t size, phys_addr_t align) |
| 82 | { |
Mike Rapoport | eb31d55 | 2018-10-30 15:08:04 -0700 | [diff] [blame] | 83 | return memblock_alloc_try_nid_nopanic(size, align, |
Santosh Shilimkar | 26f09e9 | 2014-01-21 15:50:19 -0800 | [diff] [blame] | 84 | BOOTMEM_LOW_LIMIT, |
| 85 | BOOTMEM_ALLOC_ACCESSIBLE, |
| 86 | NUMA_NO_NODE); |
| 87 | } |
| 88 | |
Mike Rapoport | eb31d55 | 2018-10-30 15:08:04 -0700 | [diff] [blame] | 89 | static inline void * __init memblock_alloc_low( |
Yinghai Lu | ad6492b | 2014-01-27 17:06:49 -0800 | [diff] [blame] | 90 | phys_addr_t size, phys_addr_t align) |
| 91 | { |
Mike Rapoport | eb31d55 | 2018-10-30 15:08:04 -0700 | [diff] [blame] | 92 | return memblock_alloc_try_nid(size, align, |
Yinghai Lu | ad6492b | 2014-01-27 17:06:49 -0800 | [diff] [blame] | 93 | BOOTMEM_LOW_LIMIT, |
| 94 | ARCH_LOW_ADDRESS_LIMIT, |
| 95 | NUMA_NO_NODE); |
| 96 | } |
Mike Rapoport | eb31d55 | 2018-10-30 15:08:04 -0700 | [diff] [blame] | 97 | static inline void * __init memblock_alloc_low_nopanic( |
Yinghai Lu | ad6492b | 2014-01-27 17:06:49 -0800 | [diff] [blame] | 98 | phys_addr_t size, phys_addr_t align) |
| 99 | { |
Mike Rapoport | eb31d55 | 2018-10-30 15:08:04 -0700 | [diff] [blame] | 100 | return memblock_alloc_try_nid_nopanic(size, align, |
Yinghai Lu | ad6492b | 2014-01-27 17:06:49 -0800 | [diff] [blame] | 101 | BOOTMEM_LOW_LIMIT, |
| 102 | ARCH_LOW_ADDRESS_LIMIT, |
| 103 | NUMA_NO_NODE); |
| 104 | } |
| 105 | |
Mike Rapoport | eb31d55 | 2018-10-30 15:08:04 -0700 | [diff] [blame] | 106 | static inline void * __init memblock_alloc_from_nopanic( |
Santosh Shilimkar | 26f09e9 | 2014-01-21 15:50:19 -0800 | [diff] [blame] | 107 | phys_addr_t size, phys_addr_t align, phys_addr_t min_addr) |
| 108 | { |
Mike Rapoport | eb31d55 | 2018-10-30 15:08:04 -0700 | [diff] [blame] | 109 | return memblock_alloc_try_nid_nopanic(size, align, min_addr, |
Santosh Shilimkar | 26f09e9 | 2014-01-21 15:50:19 -0800 | [diff] [blame] | 110 | BOOTMEM_ALLOC_ACCESSIBLE, |
| 111 | NUMA_NO_NODE); |
| 112 | } |
| 113 | |
Mike Rapoport | eb31d55 | 2018-10-30 15:08:04 -0700 | [diff] [blame] | 114 | static inline void * __init memblock_alloc_node( |
Mike Rapoport | 3913c8f | 2018-10-30 15:08:36 -0700 | [diff] [blame] | 115 | phys_addr_t size, phys_addr_t align, int nid) |
Santosh Shilimkar | 26f09e9 | 2014-01-21 15:50:19 -0800 | [diff] [blame] | 116 | { |
Mike Rapoport | 3913c8f | 2018-10-30 15:08:36 -0700 | [diff] [blame] | 117 | return memblock_alloc_try_nid(size, align, BOOTMEM_LOW_LIMIT, |
Santosh Shilimkar | 26f09e9 | 2014-01-21 15:50:19 -0800 | [diff] [blame] | 118 | BOOTMEM_ALLOC_ACCESSIBLE, nid); |
| 119 | } |
| 120 | |
Mike Rapoport | eb31d55 | 2018-10-30 15:08:04 -0700 | [diff] [blame] | 121 | static inline void * __init memblock_alloc_node_nopanic( |
Santosh Shilimkar | 26f09e9 | 2014-01-21 15:50:19 -0800 | [diff] [blame] | 122 | phys_addr_t size, int nid) |
| 123 | { |
Mike Rapoport | eb31d55 | 2018-10-30 15:08:04 -0700 | [diff] [blame] | 124 | return memblock_alloc_try_nid_nopanic(size, 0, BOOTMEM_LOW_LIMIT, |
Santosh Shilimkar | 26f09e9 | 2014-01-21 15:50:19 -0800 | [diff] [blame] | 125 | BOOTMEM_ALLOC_ACCESSIBLE, |
| 126 | nid); |
| 127 | } |
| 128 | |
| 129 | static inline void __init memblock_free_early( |
| 130 | phys_addr_t base, phys_addr_t size) |
| 131 | { |
| 132 | __memblock_free_early(base, size); |
| 133 | } |
| 134 | |
| 135 | static 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 | |
| 141 | static 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-Huu | f71bf0c | 2006-09-25 23:31:08 -0700 | [diff] [blame] | 147 | extern 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 Bird | 31fe62b | 2012-05-23 13:33:35 +0000 | [diff] [blame] | 154 | unsigned long low_limit, |
| 155 | unsigned long high_limit); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 156 | |
Andrew Morton | 0490366 | 2006-12-06 20:37:33 -0800 | [diff] [blame] | 157 | #define HASH_EARLY 0x00000001 /* Allocating during early boot? */ |
Jan Beulich | 2c85f51 | 2009-09-21 17:03:07 -0700 | [diff] [blame] | 158 | #define HASH_SMALL 0x00000002 /* sub-page allocation allowed, min |
| 159 | * shift passed via *_hash_shift */ |
Pavel Tatashin | 3749a8f | 2017-07-06 15:39:08 -0700 | [diff] [blame] | 160 | #define HASH_ZERO 0x00000004 /* Zero allocated hash table */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 161 | |
Anton Blanchard | c2fdf3a | 2009-03-31 15:23:19 -0700 | [diff] [blame] | 162 | /* Only NUMA needs hash distribution. 64bit NUMA architectures have |
| 163 | * sufficient vmalloc space. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 164 | */ |
Rasmus Villemoes | a9919c7 | 2015-06-24 16:56:28 -0700 | [diff] [blame] | 165 | #ifdef CONFIG_NUMA |
| 166 | #define HASHDIST_DEFAULT IS_ENABLED(CONFIG_64BIT) |
David S. Miller | f034b5d | 2006-08-24 03:08:07 -0700 | [diff] [blame] | 167 | extern int hashdist; /* Distribute hashes across NUMA nodes? */ |
Rasmus Villemoes | a9919c7 | 2015-06-24 16:56:28 -0700 | [diff] [blame] | 168 | #else |
| 169 | #define hashdist (0) |
| 170 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 171 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 172 | |
| 173 | #endif /* _LINUX_BOOTMEM_H */ |