Tom Rini | 10e4779 | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0+ */ |
Kumar Gala | 6d7bfa8 | 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> |
| 7 | /* |
| 8 | * Logical memory blocks. |
| 9 | * |
| 10 | * Copyright (C) 2001 Peter Bergner, IBM Corp. |
Kumar Gala | 6d7bfa8 | 2008-02-27 21:51:47 -0600 | [diff] [blame] | 11 | */ |
| 12 | |
| 13 | #define MAX_LMB_REGIONS 8 |
| 14 | |
| 15 | struct lmb_property { |
Becky Bruce | d26d67c | 2008-06-09 20:37:18 -0500 | [diff] [blame] | 16 | phys_addr_t base; |
| 17 | phys_size_t size; |
Kumar Gala | 6d7bfa8 | 2008-02-27 21:51:47 -0600 | [diff] [blame] | 18 | }; |
| 19 | |
| 20 | struct lmb_region { |
| 21 | unsigned long cnt; |
Becky Bruce | d26d67c | 2008-06-09 20:37:18 -0500 | [diff] [blame] | 22 | phys_size_t size; |
Kumar Gala | 6d7bfa8 | 2008-02-27 21:51:47 -0600 | [diff] [blame] | 23 | struct lmb_property region[MAX_LMB_REGIONS+1]; |
| 24 | }; |
| 25 | |
| 26 | struct lmb { |
| 27 | struct lmb_region memory; |
| 28 | struct lmb_region reserved; |
| 29 | }; |
| 30 | |
Kumar Gala | 6d7bfa8 | 2008-02-27 21:51:47 -0600 | [diff] [blame] | 31 | extern void lmb_init(struct lmb *lmb); |
Simon Goldschmidt | 5b2c687 | 2019-01-14 22:38:19 +0100 | [diff] [blame] | 32 | extern void lmb_init_and_reserve(struct lmb *lmb, phys_addr_t base, |
| 33 | phys_size_t size, void *fdt_blob); |
Becky Bruce | d26d67c | 2008-06-09 20:37:18 -0500 | [diff] [blame] | 34 | extern long lmb_add(struct lmb *lmb, phys_addr_t base, phys_size_t size); |
| 35 | extern long lmb_reserve(struct lmb *lmb, phys_addr_t base, phys_size_t size); |
| 36 | extern phys_addr_t lmb_alloc(struct lmb *lmb, phys_size_t size, ulong align); |
| 37 | extern phys_addr_t lmb_alloc_base(struct lmb *lmb, phys_size_t size, ulong align, |
| 38 | phys_addr_t max_addr); |
| 39 | extern phys_addr_t __lmb_alloc_base(struct lmb *lmb, phys_size_t size, ulong align, |
| 40 | phys_addr_t max_addr); |
Simon Goldschmidt | 7a6ee46 | 2019-01-14 22:38:18 +0100 | [diff] [blame] | 41 | extern phys_addr_t lmb_alloc_addr(struct lmb *lmb, phys_addr_t base, |
| 42 | phys_size_t size); |
Simon Goldschmidt | 7510a56 | 2019-01-21 20:29:55 +0100 | [diff] [blame] | 43 | extern phys_size_t lmb_get_free_size(struct lmb *lmb, phys_addr_t addr); |
Becky Bruce | d26d67c | 2008-06-09 20:37:18 -0500 | [diff] [blame] | 44 | extern int lmb_is_reserved(struct lmb *lmb, phys_addr_t addr); |
Andy Fleming | 09d2a71 | 2008-07-07 14:24:39 -0500 | [diff] [blame] | 45 | extern long lmb_free(struct lmb *lmb, phys_addr_t base, phys_size_t size); |
Kumar Gala | 6d7bfa8 | 2008-02-27 21:51:47 -0600 | [diff] [blame] | 46 | |
| 47 | extern void lmb_dump_all(struct lmb *lmb); |
| 48 | |
Becky Bruce | d26d67c | 2008-06-09 20:37:18 -0500 | [diff] [blame] | 49 | static inline phys_size_t |
Kumar Gala | 6d7bfa8 | 2008-02-27 21:51:47 -0600 | [diff] [blame] | 50 | lmb_size_bytes(struct lmb_region *type, unsigned long region_nr) |
| 51 | { |
| 52 | return type->region[region_nr].size; |
| 53 | } |
Mike Frysinger | a0dadf8 | 2009-11-03 11:35:59 -0500 | [diff] [blame] | 54 | |
| 55 | void board_lmb_reserve(struct lmb *lmb); |
| 56 | void arch_lmb_reserve(struct lmb *lmb); |
| 57 | |
Kumar Gala | 6d7bfa8 | 2008-02-27 21:51:47 -0600 | [diff] [blame] | 58 | #endif /* __KERNEL__ */ |
| 59 | |
| 60 | #endif /* _LINUX_LMB_H */ |