blob: 3b338dfee047f2eac753cea511c90afdccb84ad5 [file] [log] [blame]
Tom Rini83d290c2018-05-06 17:58:06 -04001/* SPDX-License-Identifier: GPL-2.0+ */
Kumar Gala4ed65522008-02-27 21:51:47 -06002#ifndef _LINUX_LMB_H
3#define _LINUX_LMB_H
4#ifdef __KERNEL__
5
6#include <asm/types.h>
Simon Goldschmidt9cc23232019-01-26 22:13:04 +01007#include <asm/u-boot.h>
8
Kumar Gala4ed65522008-02-27 21:51:47 -06009/*
10 * Logical memory blocks.
11 *
12 * Copyright (C) 2001 Peter Bergner, IBM Corp.
Kumar Gala4ed65522008-02-27 21:51:47 -060013 */
14
15#define MAX_LMB_REGIONS 8
16
17struct lmb_property {
Becky Bruce391fd932008-06-09 20:37:18 -050018 phys_addr_t base;
19 phys_size_t size;
Kumar Gala4ed65522008-02-27 21:51:47 -060020};
21
22struct lmb_region {
23 unsigned long cnt;
Becky Bruce391fd932008-06-09 20:37:18 -050024 phys_size_t size;
Kumar Gala4ed65522008-02-27 21:51:47 -060025 struct lmb_property region[MAX_LMB_REGIONS+1];
26};
27
28struct lmb {
29 struct lmb_region memory;
30 struct lmb_region reserved;
31};
32
Kumar Gala4ed65522008-02-27 21:51:47 -060033extern void lmb_init(struct lmb *lmb);
Simon Goldschmidt9cc23232019-01-26 22:13:04 +010034extern void lmb_init_and_reserve(struct lmb *lmb, bd_t *bd, void *fdt_blob);
35extern void lmb_init_and_reserve_range(struct lmb *lmb, phys_addr_t base,
36 phys_size_t size, void *fdt_blob);
Becky Bruce391fd932008-06-09 20:37:18 -050037extern long lmb_add(struct lmb *lmb, phys_addr_t base, phys_size_t size);
38extern long lmb_reserve(struct lmb *lmb, phys_addr_t base, phys_size_t size);
39extern phys_addr_t lmb_alloc(struct lmb *lmb, phys_size_t size, ulong align);
40extern phys_addr_t lmb_alloc_base(struct lmb *lmb, phys_size_t size, ulong align,
41 phys_addr_t max_addr);
42extern phys_addr_t __lmb_alloc_base(struct lmb *lmb, phys_size_t size, ulong align,
43 phys_addr_t max_addr);
Simon Goldschmidt4cc8af82019-01-14 22:38:18 +010044extern phys_addr_t lmb_alloc_addr(struct lmb *lmb, phys_addr_t base,
45 phys_size_t size);
Simon Goldschmidt65304aa2019-01-21 20:29:55 +010046extern phys_size_t lmb_get_free_size(struct lmb *lmb, phys_addr_t addr);
Becky Bruce391fd932008-06-09 20:37:18 -050047extern int lmb_is_reserved(struct lmb *lmb, phys_addr_t addr);
Andy Fleming98874ff2008-07-07 14:24:39 -050048extern long lmb_free(struct lmb *lmb, phys_addr_t base, phys_size_t size);
Kumar Gala4ed65522008-02-27 21:51:47 -060049
50extern void lmb_dump_all(struct lmb *lmb);
51
Becky Bruce391fd932008-06-09 20:37:18 -050052static inline phys_size_t
Kumar Gala4ed65522008-02-27 21:51:47 -060053lmb_size_bytes(struct lmb_region *type, unsigned long region_nr)
54{
55 return type->region[region_nr].size;
56}
Mike Frysingera16028d2009-11-03 11:35:59 -050057
58void board_lmb_reserve(struct lmb *lmb);
59void arch_lmb_reserve(struct lmb *lmb);
60
Kumar Gala4ed65522008-02-27 21:51:47 -060061#endif /* __KERNEL__ */
62
63#endif /* _LINUX_LMB_H */