blob: e87c0b0ada0fc969a767848cf3ae82af7d85d12c [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001/* SPDX-License-Identifier: GPL-2.0+ */
Kumar Gala6d7bfa82008-02-27 21:51:47 -06002#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 Gala6d7bfa82008-02-27 21:51:47 -060011 */
12
13#define MAX_LMB_REGIONS 8
14
15struct lmb_property {
Becky Bruced26d67c2008-06-09 20:37:18 -050016 phys_addr_t base;
17 phys_size_t size;
Kumar Gala6d7bfa82008-02-27 21:51:47 -060018};
19
20struct lmb_region {
21 unsigned long cnt;
Becky Bruced26d67c2008-06-09 20:37:18 -050022 phys_size_t size;
Kumar Gala6d7bfa82008-02-27 21:51:47 -060023 struct lmb_property region[MAX_LMB_REGIONS+1];
24};
25
26struct lmb {
27 struct lmb_region memory;
28 struct lmb_region reserved;
29};
30
Kumar Gala6d7bfa82008-02-27 21:51:47 -060031extern void lmb_init(struct lmb *lmb);
Simon Goldschmidt5b2c6872019-01-14 22:38:19 +010032extern void lmb_init_and_reserve(struct lmb *lmb, phys_addr_t base,
33 phys_size_t size, void *fdt_blob);
Becky Bruced26d67c2008-06-09 20:37:18 -050034extern long lmb_add(struct lmb *lmb, phys_addr_t base, phys_size_t size);
35extern long lmb_reserve(struct lmb *lmb, phys_addr_t base, phys_size_t size);
36extern phys_addr_t lmb_alloc(struct lmb *lmb, phys_size_t size, ulong align);
37extern phys_addr_t lmb_alloc_base(struct lmb *lmb, phys_size_t size, ulong align,
38 phys_addr_t max_addr);
39extern phys_addr_t __lmb_alloc_base(struct lmb *lmb, phys_size_t size, ulong align,
40 phys_addr_t max_addr);
Simon Goldschmidt7a6ee462019-01-14 22:38:18 +010041extern phys_addr_t lmb_alloc_addr(struct lmb *lmb, phys_addr_t base,
42 phys_size_t size);
Simon Goldschmidt7510a562019-01-21 20:29:55 +010043extern phys_size_t lmb_get_free_size(struct lmb *lmb, phys_addr_t addr);
Becky Bruced26d67c2008-06-09 20:37:18 -050044extern int lmb_is_reserved(struct lmb *lmb, phys_addr_t addr);
Andy Fleming09d2a712008-07-07 14:24:39 -050045extern long lmb_free(struct lmb *lmb, phys_addr_t base, phys_size_t size);
Kumar Gala6d7bfa82008-02-27 21:51:47 -060046
47extern void lmb_dump_all(struct lmb *lmb);
48
Becky Bruced26d67c2008-06-09 20:37:18 -050049static inline phys_size_t
Kumar Gala6d7bfa82008-02-27 21:51:47 -060050lmb_size_bytes(struct lmb_region *type, unsigned long region_nr)
51{
52 return type->region[region_nr].size;
53}
Mike Frysingera0dadf82009-11-03 11:35:59 -050054
55void board_lmb_reserve(struct lmb *lmb);
56void arch_lmb_reserve(struct lmb *lmb);
57
Kumar Gala6d7bfa82008-02-27 21:51:47 -060058#endif /* __KERNEL__ */
59
60#endif /* _LINUX_LMB_H */