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.
18 * enum lmb_flags - definition of memory region attributes
19 * @LMB_NONE: no special request
20 * @LMB_NOMAP: don't add to mmu configuration
25 LMB_NOOVERWRITE = BIT(2),
29 * struct lmb_region - Description of one region.
31 * @base: Base address of the region.
32 * @size: Size of the region
33 * @flags: memory region attributes
42 * struct lmb - The LMB structure
44 * @free_mem: List of free memory regions
45 * @used_mem: List of used/reserved memory regions
48 struct alist free_mem;
49 struct alist used_mem;
53 * lmb_init() - Initialise the LMB module
55 * Initialise the LMB lists needed for keeping the memory map. There
56 * are two lists, in form of alloced list data structure. One for the
57 * available memory, and one for the used memory. Initialise the two
58 * lists as part of board init. Add memory to the available memory
59 * list and reserve common areas by adding them to the used memory
62 * Return: 0 on success, -ve on error
67 * lmb_add_memory() - Add memory range for LMB allocations
69 * Add the entire available memory range to the pool of memory that
70 * can be used by the LMB module for allocations.
74 void lmb_add_memory(void);
76 long lmb_add(phys_addr_t base, phys_size_t size);
77 long lmb_reserve(phys_addr_t base, phys_size_t size);
79 * lmb_reserve_flags - Reserve one region with a specific flags bitfield.
81 * @base: base address of the memory region
82 * @size: size of the memory region
83 * @flags: flags for the memory region
84 * Return: 0 if OK, > 0 for coalesced region or a negative error code.
86 long lmb_reserve_flags(phys_addr_t base, phys_size_t size,
87 enum lmb_flags flags);
88 phys_addr_t lmb_alloc(phys_size_t size, ulong align);
89 phys_addr_t lmb_alloc_base(phys_size_t size, ulong align, phys_addr_t max_addr);
90 phys_addr_t lmb_alloc_addr(phys_addr_t base, phys_size_t size);
91 phys_size_t lmb_get_free_size(phys_addr_t addr);
94 * lmb_is_reserved_flags() - test if address is in reserved region with flag bits set
96 * The function checks if a reserved region comprising @addr exists which has
97 * all flag bits set which are set in @flags.
99 * @addr: address to be tested
100 * @flags: bitmap with bits to be tested
101 * Return: 1 if matching reservation exists, 0 otherwise
103 int lmb_is_reserved_flags(phys_addr_t addr, int flags);
105 long lmb_free(phys_addr_t base, phys_size_t size);
107 void lmb_dump_all(void);
108 void lmb_dump_all_force(void);
110 struct lmb *lmb_get(void);
111 int lmb_push(struct lmb *store);
112 void lmb_pop(struct lmb *store);
114 static inline int lmb_read_check(phys_addr_t addr, phys_size_t len)
116 return lmb_alloc_addr(addr, len) == addr ? 0 : -1;
119 #endif /* __KERNEL__ */
121 #endif /* _LINUX_LMB_H */