Tom Rini | 83d290c | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0+ */ |
Kumar Gala | 4ed6552 | 2008-02-27 21:51:47 -0600 | [diff] [blame] | 2 | #ifndef _LINUX_LMB_H |
| 3 | #define _LINUX_LMB_H |
| 4 | #ifdef __KERNEL__ |
| 5 | |
| 6 | #include <asm/types.h> |
Simon Goldschmidt | 9cc2323 | 2019-01-26 22:13:04 +0100 | [diff] [blame] | 7 | #include <asm/u-boot.h> |
| 8 | |
Kumar Gala | 4ed6552 | 2008-02-27 21:51:47 -0600 | [diff] [blame] | 9 | /* |
| 10 | * Logical memory blocks. |
| 11 | * |
| 12 | * Copyright (C) 2001 Peter Bergner, IBM Corp. |
Kumar Gala | 4ed6552 | 2008-02-27 21:51:47 -0600 | [diff] [blame] | 13 | */ |
| 14 | |
Patrick Delaunay | 6d66502 | 2021-03-10 10:16:31 +0100 | [diff] [blame] | 15 | /** |
| 16 | * struct lmb_property - Description of one region. |
| 17 | * |
| 18 | * @base: Base address of the region. |
| 19 | * @size: Size of the region |
| 20 | */ |
Kumar Gala | 4ed6552 | 2008-02-27 21:51:47 -0600 | [diff] [blame] | 21 | struct lmb_property { |
Becky Bruce | 391fd93 | 2008-06-09 20:37:18 -0500 | [diff] [blame] | 22 | phys_addr_t base; |
| 23 | phys_size_t size; |
Kumar Gala | 4ed6552 | 2008-02-27 21:51:47 -0600 | [diff] [blame] | 24 | }; |
| 25 | |
Patrick Delaunay | 6d66502 | 2021-03-10 10:16:31 +0100 | [diff] [blame] | 26 | /** |
| 27 | * struct lmb_region - Description of a set of region. |
| 28 | * |
| 29 | * @cnt: Number of regions. |
| 30 | * @max: Size of the region array, max value of cnt. |
| 31 | * @region: Array of the region properties |
| 32 | */ |
Kumar Gala | 4ed6552 | 2008-02-27 21:51:47 -0600 | [diff] [blame] | 33 | struct lmb_region { |
| 34 | unsigned long cnt; |
Patrick Delaunay | 00fd8da | 2021-03-10 10:16:27 +0100 | [diff] [blame] | 35 | unsigned long max; |
Patrick Delaunay | 6d66502 | 2021-03-10 10:16:31 +0100 | [diff] [blame] | 36 | #if IS_ENABLED(CONFIG_LMB_USE_MAX_REGIONS) |
Patrick Delaunay | cb1e619 | 2021-03-10 10:16:29 +0100 | [diff] [blame] | 37 | struct lmb_property region[CONFIG_LMB_MAX_REGIONS]; |
Patrick Delaunay | 6d66502 | 2021-03-10 10:16:31 +0100 | [diff] [blame] | 38 | #else |
| 39 | struct lmb_property *region; |
| 40 | #endif |
Kumar Gala | 4ed6552 | 2008-02-27 21:51:47 -0600 | [diff] [blame] | 41 | }; |
| 42 | |
Patrick Delaunay | 6d66502 | 2021-03-10 10:16:31 +0100 | [diff] [blame] | 43 | /** |
| 44 | * struct lmb - Logical memory block handle. |
| 45 | * |
| 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. |
| 50 | * |
| 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) |
| 55 | */ |
Kumar Gala | 4ed6552 | 2008-02-27 21:51:47 -0600 | [diff] [blame] | 56 | struct lmb { |
| 57 | struct lmb_region memory; |
| 58 | struct lmb_region reserved; |
Patrick Delaunay | 6d66502 | 2021-03-10 10:16:31 +0100 | [diff] [blame] | 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]; |
| 62 | #endif |
Kumar Gala | 4ed6552 | 2008-02-27 21:51:47 -0600 | [diff] [blame] | 63 | }; |
| 64 | |
Kumar Gala | 4ed6552 | 2008-02-27 21:51:47 -0600 | [diff] [blame] | 65 | extern void lmb_init(struct lmb *lmb); |
Masahiro Yamada | b75d8dc | 2020-06-26 15:13:33 +0900 | [diff] [blame] | 66 | extern void lmb_init_and_reserve(struct lmb *lmb, struct bd_info *bd, |
| 67 | void *fdt_blob); |
Simon Goldschmidt | 9cc2323 | 2019-01-26 22:13:04 +0100 | [diff] [blame] | 68 | extern void lmb_init_and_reserve_range(struct lmb *lmb, phys_addr_t base, |
| 69 | phys_size_t size, void *fdt_blob); |
Becky Bruce | 391fd93 | 2008-06-09 20:37:18 -0500 | [diff] [blame] | 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); |
Simon Goldschmidt | 4cc8af8 | 2019-01-14 22:38:18 +0100 | [diff] [blame] | 77 | extern phys_addr_t lmb_alloc_addr(struct lmb *lmb, phys_addr_t base, |
| 78 | phys_size_t size); |
Simon Goldschmidt | 65304aa | 2019-01-21 20:29:55 +0100 | [diff] [blame] | 79 | extern phys_size_t lmb_get_free_size(struct lmb *lmb, phys_addr_t addr); |
Becky Bruce | 391fd93 | 2008-06-09 20:37:18 -0500 | [diff] [blame] | 80 | extern int lmb_is_reserved(struct lmb *lmb, phys_addr_t addr); |
Andy Fleming | 98874ff | 2008-07-07 14:24:39 -0500 | [diff] [blame] | 81 | extern long lmb_free(struct lmb *lmb, phys_addr_t base, phys_size_t size); |
Kumar Gala | 4ed6552 | 2008-02-27 21:51:47 -0600 | [diff] [blame] | 82 | |
| 83 | extern void lmb_dump_all(struct lmb *lmb); |
Tero Kristo | 9996cea | 2020-07-20 11:10:45 +0300 | [diff] [blame] | 84 | extern void lmb_dump_all_force(struct lmb *lmb); |
Kumar Gala | 4ed6552 | 2008-02-27 21:51:47 -0600 | [diff] [blame] | 85 | |
Becky Bruce | 391fd93 | 2008-06-09 20:37:18 -0500 | [diff] [blame] | 86 | static inline phys_size_t |
Kumar Gala | 4ed6552 | 2008-02-27 21:51:47 -0600 | [diff] [blame] | 87 | lmb_size_bytes(struct lmb_region *type, unsigned long region_nr) |
| 88 | { |
| 89 | return type->region[region_nr].size; |
| 90 | } |
Mike Frysinger | a16028d | 2009-11-03 11:35:59 -0500 | [diff] [blame] | 91 | |
| 92 | void board_lmb_reserve(struct lmb *lmb); |
| 93 | void arch_lmb_reserve(struct lmb *lmb); |
| 94 | |
Kumar Gala | 4ed6552 | 2008-02-27 21:51:47 -0600 | [diff] [blame] | 95 | #endif /* __KERNEL__ */ |
| 96 | |
| 97 | #endif /* _LINUX_LMB_H */ |