blob: e9f19b16ea0bd637bfbb0a9dc0457933c1dd0037 [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>
Simon Goldschmidt8890e7d2019-01-26 22:13:04 +01007#include <asm/u-boot.h>
8
Kumar Gala6d7bfa82008-02-27 21:51:47 -06009/*
10 * Logical memory blocks.
11 *
12 * Copyright (C) 2001 Peter Bergner, IBM Corp.
Kumar Gala6d7bfa82008-02-27 21:51:47 -060013 */
14
15#define MAX_LMB_REGIONS 8
16
17struct lmb_property {
Becky Bruced26d67c2008-06-09 20:37:18 -050018 phys_addr_t base;
19 phys_size_t size;
Kumar Gala6d7bfa82008-02-27 21:51:47 -060020};
21
22struct lmb_region {
23 unsigned long cnt;
Becky Bruced26d67c2008-06-09 20:37:18 -050024 phys_size_t size;
Kumar Gala6d7bfa82008-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 Gala6d7bfa82008-02-27 21:51:47 -060033extern void lmb_init(struct lmb *lmb);
Masahiro Yamadaf7ed78b2020-06-26 15:13:33 +090034extern void lmb_init_and_reserve(struct lmb *lmb, struct bd_info *bd,
35 void *fdt_blob);
Simon Goldschmidt8890e7d2019-01-26 22:13:04 +010036extern void lmb_init_and_reserve_range(struct lmb *lmb, phys_addr_t base,
37 phys_size_t size, void *fdt_blob);
Becky Bruced26d67c2008-06-09 20:37:18 -050038extern long lmb_add(struct lmb *lmb, phys_addr_t base, phys_size_t size);
39extern long lmb_reserve(struct lmb *lmb, phys_addr_t base, phys_size_t size);
40extern phys_addr_t lmb_alloc(struct lmb *lmb, phys_size_t size, ulong align);
41extern phys_addr_t lmb_alloc_base(struct lmb *lmb, phys_size_t size, ulong align,
42 phys_addr_t max_addr);
43extern phys_addr_t __lmb_alloc_base(struct lmb *lmb, phys_size_t size, ulong align,
44 phys_addr_t max_addr);
Simon Goldschmidt7a6ee462019-01-14 22:38:18 +010045extern phys_addr_t lmb_alloc_addr(struct lmb *lmb, phys_addr_t base,
46 phys_size_t size);
Simon Goldschmidt7510a562019-01-21 20:29:55 +010047extern phys_size_t lmb_get_free_size(struct lmb *lmb, phys_addr_t addr);
Becky Bruced26d67c2008-06-09 20:37:18 -050048extern int lmb_is_reserved(struct lmb *lmb, phys_addr_t addr);
Andy Fleming09d2a712008-07-07 14:24:39 -050049extern long lmb_free(struct lmb *lmb, phys_addr_t base, phys_size_t size);
Kumar Gala6d7bfa82008-02-27 21:51:47 -060050
51extern void lmb_dump_all(struct lmb *lmb);
Tero Kristo97c418b2020-07-20 11:10:45 +030052extern void lmb_dump_all_force(struct lmb *lmb);
Kumar Gala6d7bfa82008-02-27 21:51:47 -060053
Becky Bruced26d67c2008-06-09 20:37:18 -050054static inline phys_size_t
Kumar Gala6d7bfa82008-02-27 21:51:47 -060055lmb_size_bytes(struct lmb_region *type, unsigned long region_nr)
56{
57 return type->region[region_nr].size;
58}
Mike Frysingera0dadf82009-11-03 11:35:59 -050059
60void board_lmb_reserve(struct lmb *lmb);
61void arch_lmb_reserve(struct lmb *lmb);
62
Kumar Gala6d7bfa82008-02-27 21:51:47 -060063#endif /* __KERNEL__ */
64
65#endif /* _LINUX_LMB_H */