]>
Commit | Line | Data |
---|---|---|
83d290c5 | 1 | /* SPDX-License-Identifier: GPL-2.0+ */ |
4ed6552f KG |
2 | #ifndef _LINUX_LMB_H |
3 | #define _LINUX_LMB_H | |
4 | #ifdef __KERNEL__ | |
5 | ||
6 | #include <asm/types.h> | |
9cc2323f SG |
7 | #include <asm/u-boot.h> |
8 | ||
4ed6552f KG |
9 | /* |
10 | * Logical memory blocks. | |
11 | * | |
12 | * Copyright (C) 2001 Peter Bergner, IBM Corp. | |
4ed6552f KG |
13 | */ |
14 | ||
59c0ea5d PD |
15 | /** |
16 | * enum lmb_flags - definition of memory region attributes | |
17 | * @LMB_NONE: no special request | |
18 | * @LMB_NOMAP: don't add to mmu configuration | |
19 | */ | |
20 | enum lmb_flags { | |
21 | LMB_NONE = 0x0, | |
22 | LMB_NOMAP = 0x4, | |
23 | }; | |
24 | ||
6d66502b PD |
25 | /** |
26 | * struct lmb_property - Description of one region. | |
27 | * | |
28 | * @base: Base address of the region. | |
29 | * @size: Size of the region | |
30 | */ | |
4ed6552f | 31 | struct lmb_property { |
391fd93a BB |
32 | phys_addr_t base; |
33 | phys_size_t size; | |
59c0ea5d | 34 | enum lmb_flags flags; |
4ed6552f KG |
35 | }; |
36 | ||
6d66502b PD |
37 | /** |
38 | * struct lmb_region - Description of a set of region. | |
39 | * | |
40 | * @cnt: Number of regions. | |
41 | * @max: Size of the region array, max value of cnt. | |
42 | * @region: Array of the region properties | |
43 | */ | |
4ed6552f KG |
44 | struct lmb_region { |
45 | unsigned long cnt; | |
00fd8dad | 46 | unsigned long max; |
6d66502b | 47 | #if IS_ENABLED(CONFIG_LMB_USE_MAX_REGIONS) |
cb1e6198 | 48 | struct lmb_property region[CONFIG_LMB_MAX_REGIONS]; |
6d66502b PD |
49 | #else |
50 | struct lmb_property *region; | |
51 | #endif | |
4ed6552f KG |
52 | }; |
53 | ||
6d66502b PD |
54 | /** |
55 | * struct lmb - Logical memory block handle. | |
56 | * | |
57 | * Clients provide storage for Logical memory block (lmb) handles. | |
58 | * The content of the structure is managed by the lmb library. | |
59 | * A lmb struct is initialized by lmb_init() functions. | |
60 | * The lmb struct is passed to all other lmb APIs. | |
61 | * | |
62 | * @memory: Description of memory regions. | |
63 | * @reserved: Description of reserved regions. | |
64 | * @memory_regions: Array of the memory regions (statically allocated) | |
65 | * @reserved_regions: Array of the reserved regions (statically allocated) | |
66 | */ | |
4ed6552f KG |
67 | struct lmb { |
68 | struct lmb_region memory; | |
69 | struct lmb_region reserved; | |
6d66502b PD |
70 | #if !IS_ENABLED(CONFIG_LMB_USE_MAX_REGIONS) |
71 | struct lmb_property memory_regions[CONFIG_LMB_MEMORY_REGIONS]; | |
72 | struct lmb_property reserved_regions[CONFIG_LMB_RESERVED_REGIONS]; | |
73 | #endif | |
4ed6552f KG |
74 | }; |
75 | ||
4ed6552f | 76 | extern void lmb_init(struct lmb *lmb); |
b75d8dc5 MY |
77 | extern void lmb_init_and_reserve(struct lmb *lmb, struct bd_info *bd, |
78 | void *fdt_blob); | |
9cc2323f SG |
79 | extern void lmb_init_and_reserve_range(struct lmb *lmb, phys_addr_t base, |
80 | phys_size_t size, void *fdt_blob); | |
391fd93a BB |
81 | extern long lmb_add(struct lmb *lmb, phys_addr_t base, phys_size_t size); |
82 | extern long lmb_reserve(struct lmb *lmb, phys_addr_t base, phys_size_t size); | |
59c0ea5d PD |
83 | /** |
84 | * lmb_reserve_flags - Reserve one region with a specific flags bitfield. | |
85 | * | |
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. | |
91 | */ | |
92 | long lmb_reserve_flags(struct lmb *lmb, phys_addr_t base, | |
93 | phys_size_t size, enum lmb_flags flags); | |
391fd93a BB |
94 | extern phys_addr_t lmb_alloc(struct lmb *lmb, phys_size_t size, ulong align); |
95 | extern phys_addr_t lmb_alloc_base(struct lmb *lmb, phys_size_t size, ulong align, | |
96 | phys_addr_t max_addr); | |
97 | extern phys_addr_t __lmb_alloc_base(struct lmb *lmb, phys_size_t size, ulong align, | |
98 | phys_addr_t max_addr); | |
4cc8af80 SG |
99 | extern phys_addr_t lmb_alloc_addr(struct lmb *lmb, phys_addr_t base, |
100 | phys_size_t size); | |
65304aad | 101 | extern phys_size_t lmb_get_free_size(struct lmb *lmb, phys_addr_t addr); |
391fd93a | 102 | extern int lmb_is_reserved(struct lmb *lmb, phys_addr_t addr); |
98874ff3 | 103 | extern long lmb_free(struct lmb *lmb, phys_addr_t base, phys_size_t size); |
4ed6552f KG |
104 | |
105 | extern void lmb_dump_all(struct lmb *lmb); | |
9996cea7 | 106 | extern void lmb_dump_all_force(struct lmb *lmb); |
4ed6552f | 107 | |
391fd93a | 108 | static inline phys_size_t |
4ed6552f KG |
109 | lmb_size_bytes(struct lmb_region *type, unsigned long region_nr) |
110 | { | |
111 | return type->region[region_nr].size; | |
112 | } | |
a16028da MF |
113 | |
114 | void board_lmb_reserve(struct lmb *lmb); | |
115 | void arch_lmb_reserve(struct lmb *lmb); | |
116 | ||
59c0ea5d PD |
117 | /* Low level functions */ |
118 | ||
119 | static inline bool lmb_is_nomap(struct lmb_property *m) | |
120 | { | |
121 | return m->flags & LMB_NOMAP; | |
122 | } | |
123 | ||
4ed6552f KG |
124 | #endif /* __KERNEL__ */ |
125 | ||
126 | #endif /* _LINUX_LMB_H */ |