1 /* SPDX-License-Identifier: GPL-2.0+ */
8 #include <asm/u-boot.h>
9 #include <linux/bitops.h>
12 * Logical memory blocks.
14 * Copyright (C) 2001 Peter Bergner, IBM Corp.
17 #define LMB_ALLOC_ANYWHERE 0
18 #define LMB_ALIST_INITIAL_SIZE 4
21 * enum lmb_flags - definition of memory region attributes
22 * @LMB_NONE: no special request
23 * @LMB_NOMAP: don't add to mmu configuration
24 * @LMB_NOOVERWRITE: the memory region cannot be overwritten/re-reserved
25 * @LMB_NONOTIFY: do not notify other modules of changes to this memory region
30 LMB_NOOVERWRITE = BIT(2),
31 LMB_NONOTIFY = BIT(3),
35 * struct lmb_region - Description of one region.
37 * @base: Base address of the region.
38 * @size: Size of the region
39 * @flags: memory region attributes
48 * struct lmb - The LMB structure
50 * @free_mem: List of free memory regions
51 * @used_mem: List of used/reserved memory regions
52 * @test: Is structure being used for LMB tests
55 struct alist free_mem;
56 struct alist used_mem;
61 * lmb_init() - Initialise the LMB module
63 * Initialise the LMB lists needed for keeping the memory map. There
64 * are two lists, in form of alloced list data structure. One for the
65 * available memory, and one for the used memory. Initialise the two
66 * lists as part of board init. Add memory to the available memory
67 * list and reserve common areas by adding them to the used memory
70 * Return: 0 on success, -ve on error
75 * lmb_add_memory() - Add memory range for LMB allocations
77 * Add the entire available memory range to the pool of memory that
78 * can be used by the LMB module for allocations.
82 void lmb_add_memory(void);
84 long lmb_add(phys_addr_t base, phys_size_t size);
85 long lmb_reserve(phys_addr_t base, phys_size_t size);
87 * lmb_reserve_flags - Reserve one region with a specific flags bitfield.
89 * @base: base address of the memory region
90 * @size: size of the memory region
91 * @flags: flags for the memory region
92 * Return: 0 if OK, > 0 for coalesced region or a negative error code.
94 long lmb_reserve_flags(phys_addr_t base, phys_size_t size,
95 enum lmb_flags flags);
96 phys_addr_t lmb_alloc(phys_size_t size, ulong align);
97 phys_addr_t lmb_alloc_base(phys_size_t size, ulong align, phys_addr_t max_addr);
98 phys_addr_t lmb_alloc_addr(phys_addr_t base, phys_size_t size);
99 phys_size_t lmb_get_free_size(phys_addr_t addr);
101 phys_addr_t lmb_alloc_base_flags(phys_size_t size, ulong align,
102 phys_addr_t max_addr, uint flags);
105 * lmb_alloc_addr_flags() - Allocate specified memory address with specified attributes
106 * @base: Base Address requested
107 * @size: Size of the region requested
108 * @flags: Memory region attributes to be set
110 * Allocate a region of memory with the attributes specified through the
111 * parameter. The base parameter is used to specify the base address
112 * of the requested region.
114 * Return: base address on success, 0 on error
116 phys_addr_t lmb_alloc_addr_flags(phys_addr_t base, phys_size_t size,
120 * lmb_is_reserved_flags() - test if address is in reserved region with flag bits set
122 * The function checks if a reserved region comprising @addr exists which has
123 * all flag bits set which are set in @flags.
125 * @addr: address to be tested
126 * @flags: bitmap with bits to be tested
127 * Return: 1 if matching reservation exists, 0 otherwise
129 int lmb_is_reserved_flags(phys_addr_t addr, int flags);
132 * lmb_free_flags() - Free up a region of memory
133 * @base: Base Address of region to be freed
134 * @size: Size of the region to be freed
135 * @flags: Memory region attributes
137 * Free up a region of memory.
139 * Return: 0 if successful, -1 on failure
141 long lmb_free_flags(phys_addr_t base, phys_size_t size, uint flags);
143 long lmb_free(phys_addr_t base, phys_size_t size);
145 void lmb_dump_all(void);
146 void lmb_dump_all_force(void);
148 void lmb_arch_add_memory(void);
150 struct lmb *lmb_get(void);
151 int lmb_push(struct lmb *store);
152 void lmb_pop(struct lmb *store);
154 static inline int lmb_read_check(phys_addr_t addr, phys_size_t len)
156 return lmb_alloc_addr(addr, len) == addr ? 0 : -1;
159 #endif /* __KERNEL__ */
161 #endif /* _LINUX_LMB_H */