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 * struct lmb_property - Description of one region.
18 * @base: Base address of the region.
19 * @size: Size of the region
27 * struct lmb_region - Description of a set of region.
29 * @cnt: Number of regions.
30 * @max: Size of the region array, max value of cnt.
31 * @region: Array of the region properties
36 #if IS_ENABLED(CONFIG_LMB_USE_MAX_REGIONS)
37 struct lmb_property region[CONFIG_LMB_MAX_REGIONS];
39 struct lmb_property *region;
44 * struct lmb - Logical memory block handle.
46 * Clients provide storage for Logical memory block (lmb) handles.
47 * The content of the structure is managed by the lmb library.
48 * A lmb struct is initialized by lmb_init() functions.
49 * The lmb struct is passed to all other lmb APIs.
51 * @memory: Description of memory regions.
52 * @reserved: Description of reserved regions.
53 * @memory_regions: Array of the memory regions (statically allocated)
54 * @reserved_regions: Array of the reserved regions (statically allocated)
57 struct lmb_region memory;
58 struct lmb_region reserved;
59 #if !IS_ENABLED(CONFIG_LMB_USE_MAX_REGIONS)
60 struct lmb_property memory_regions[CONFIG_LMB_MEMORY_REGIONS];
61 struct lmb_property reserved_regions[CONFIG_LMB_RESERVED_REGIONS];
65 extern void lmb_init(struct lmb *lmb);
66 extern void lmb_init_and_reserve(struct lmb *lmb, struct bd_info *bd,
68 extern void lmb_init_and_reserve_range(struct lmb *lmb, phys_addr_t base,
69 phys_size_t size, void *fdt_blob);
70 extern long lmb_add(struct lmb *lmb, phys_addr_t base, phys_size_t size);
71 extern long lmb_reserve(struct lmb *lmb, phys_addr_t base, phys_size_t size);
72 extern phys_addr_t lmb_alloc(struct lmb *lmb, phys_size_t size, ulong align);
73 extern phys_addr_t lmb_alloc_base(struct lmb *lmb, phys_size_t size, ulong align,
74 phys_addr_t max_addr);
75 extern phys_addr_t __lmb_alloc_base(struct lmb *lmb, phys_size_t size, ulong align,
76 phys_addr_t max_addr);
77 extern phys_addr_t lmb_alloc_addr(struct lmb *lmb, phys_addr_t base,
79 extern phys_size_t lmb_get_free_size(struct lmb *lmb, phys_addr_t addr);
80 extern int lmb_is_reserved(struct lmb *lmb, phys_addr_t addr);
81 extern long lmb_free(struct lmb *lmb, phys_addr_t base, phys_size_t size);
83 extern void lmb_dump_all(struct lmb *lmb);
84 extern void lmb_dump_all_force(struct lmb *lmb);
86 static inline phys_size_t
87 lmb_size_bytes(struct lmb_region *type, unsigned long region_nr)
89 return type->region[region_nr].size;
92 void board_lmb_reserve(struct lmb *lmb);
93 void arch_lmb_reserve(struct lmb *lmb);
95 #endif /* __KERNEL__ */
97 #endif /* _LINUX_LMB_H */