xref: /openbmc/u-boot/include/lmb.h (revision b9553986)
1 /* SPDX-License-Identifier: GPL-2.0+ */
2 #ifndef _LINUX_LMB_H
3 #define _LINUX_LMB_H
4 #ifdef __KERNEL__
5 
6 #include <asm/types.h>
7 #include <asm/u-boot.h>
8 
9 /*
10  * Logical memory blocks.
11  *
12  * Copyright (C) 2001 Peter Bergner, IBM Corp.
13  */
14 
15 #define MAX_LMB_REGIONS 8
16 
17 struct lmb_property {
18 	phys_addr_t base;
19 	phys_size_t size;
20 };
21 
22 struct lmb_region {
23 	unsigned long cnt;
24 	phys_size_t size;
25 	struct lmb_property region[MAX_LMB_REGIONS+1];
26 };
27 
28 struct lmb {
29 	struct lmb_region memory;
30 	struct lmb_region reserved;
31 };
32 
33 extern void lmb_init(struct lmb *lmb);
34 extern void lmb_init_and_reserve(struct lmb *lmb, bd_t *bd, void *fdt_blob);
35 extern void lmb_init_and_reserve_range(struct lmb *lmb, phys_addr_t base,
36 				       phys_size_t size, void *fdt_blob);
37 extern long lmb_add(struct lmb *lmb, phys_addr_t base, phys_size_t size);
38 extern long lmb_reserve(struct lmb *lmb, phys_addr_t base, phys_size_t size);
39 extern phys_addr_t lmb_alloc(struct lmb *lmb, phys_size_t size, ulong align);
40 extern phys_addr_t lmb_alloc_base(struct lmb *lmb, phys_size_t size, ulong align,
41 			    phys_addr_t max_addr);
42 extern phys_addr_t __lmb_alloc_base(struct lmb *lmb, phys_size_t size, ulong align,
43 			      phys_addr_t max_addr);
44 extern phys_addr_t lmb_alloc_addr(struct lmb *lmb, phys_addr_t base,
45 				  phys_size_t size);
46 extern phys_size_t lmb_get_free_size(struct lmb *lmb, phys_addr_t addr);
47 extern int lmb_is_reserved(struct lmb *lmb, phys_addr_t addr);
48 extern long lmb_free(struct lmb *lmb, phys_addr_t base, phys_size_t size);
49 
50 extern void lmb_dump_all(struct lmb *lmb);
51 
52 static inline phys_size_t
53 lmb_size_bytes(struct lmb_region *type, unsigned long region_nr)
54 {
55 	return type->region[region_nr].size;
56 }
57 
58 void board_lmb_reserve(struct lmb *lmb);
59 void arch_lmb_reserve(struct lmb *lmb);
60 
61 #endif /* __KERNEL__ */
62 
63 #endif /* _LINUX_LMB_H */
64