1 /* SPDX-License-Identifier: GPL-2.0+ */
7 #include <asm/u-boot.h>
10 * Logical memory blocks.
12 * Copyright (C) 2001 Peter Bergner, IBM Corp.
16 * enum lmb_flags - definition of memory region attributes
17 * @LMB_NONE: no special request
18 * @LMB_NOMAP: don't add to mmu configuration
26 * struct lmb_property - Description of one region.
28 * @base: Base address of the region.
29 * @size: Size of the region
30 * @flags: memory region attributes
39 * struct lmb_region - Description of a set of region.
41 * @cnt: Number of regions.
42 * @max: Size of the region array, max value of cnt.
43 * @region: Array of the region properties
48 #if IS_ENABLED(CONFIG_LMB_USE_MAX_REGIONS)
49 struct lmb_property region[CONFIG_LMB_MAX_REGIONS];
51 struct lmb_property *region;
56 * struct lmb - Logical memory block handle.
58 * Clients provide storage for Logical memory block (lmb) handles.
59 * The content of the structure is managed by the lmb library.
60 * A lmb struct is initialized by lmb_init() functions.
61 * The lmb struct is passed to all other lmb APIs.
63 * @memory: Description of memory regions.
64 * @reserved: Description of reserved regions.
65 * @memory_regions: Array of the memory regions (statically allocated)
66 * @reserved_regions: Array of the reserved regions (statically allocated)
69 struct lmb_region memory;
70 struct lmb_region reserved;
71 #ifdef CONFIG_LMB_MEMORY_REGIONS
72 struct lmb_property memory_regions[CONFIG_LMB_MEMORY_REGIONS];
73 struct lmb_property reserved_regions[CONFIG_LMB_RESERVED_REGIONS];
77 void lmb_init(struct lmb *lmb);
78 void lmb_init_and_reserve(struct lmb *lmb, struct bd_info *bd, void *fdt_blob);
79 void lmb_init_and_reserve_range(struct lmb *lmb, phys_addr_t base,
80 phys_size_t size, void *fdt_blob);
81 long lmb_add(struct lmb *lmb, phys_addr_t base, phys_size_t size);
82 long lmb_reserve(struct lmb *lmb, phys_addr_t base, phys_size_t size);
84 * lmb_reserve_flags - Reserve one region with a specific flags bitfield.
86 * @lmb: the logical memory block struct
87 * @base: base address of the memory region
88 * @size: size of the memory region
89 * @flags: flags for the memory region
90 * Return: 0 if OK, > 0 for coalesced region or a negative error code.
92 long lmb_reserve_flags(struct lmb *lmb, phys_addr_t base,
93 phys_size_t size, enum lmb_flags flags);
94 phys_addr_t lmb_alloc(struct lmb *lmb, phys_size_t size, ulong align);
95 phys_addr_t lmb_alloc_base(struct lmb *lmb, phys_size_t size, ulong align,
96 phys_addr_t max_addr);
97 phys_addr_t __lmb_alloc_base(struct lmb *lmb, phys_size_t size, ulong align,
98 phys_addr_t max_addr);
99 phys_addr_t lmb_alloc_addr(struct lmb *lmb, phys_addr_t base, phys_size_t size);
100 phys_size_t lmb_get_free_size(struct lmb *lmb, phys_addr_t addr);
101 int lmb_is_reserved(struct lmb *lmb, phys_addr_t addr);
103 * lmb_is_reserved_flags - test if tha address is in reserved region with a bitfield flag
105 * @lmb: the logical memory block struct
106 * @addr: address to be tested
107 * @flags: flags bitfied to be tested
108 * Return: if not reserved or reserved without the requested flag else 1
110 int lmb_is_reserved_flags(struct lmb *lmb, phys_addr_t addr, int flags);
111 long lmb_free(struct lmb *lmb, phys_addr_t base, phys_size_t size);
113 void lmb_dump_all(struct lmb *lmb);
114 void lmb_dump_all_force(struct lmb *lmb);
116 void board_lmb_reserve(struct lmb *lmb);
117 void arch_lmb_reserve(struct lmb *lmb);
118 void arch_lmb_reserve_generic(struct lmb *lmb, ulong sp, ulong end, ulong align);
120 #endif /* __KERNEL__ */
122 #endif /* _LINUX_LMB_H */