blob: 541e17093c65bf2a03aa875d934bd6f36a023a0d [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
Patrick Delaunay6d665022021-03-10 10:16:31 +010015/**
16 * struct lmb_property - Description of one region.
17 *
18 * @base: Base address of the region.
19 * @size: Size of the region
20 */
Kumar Gala4ed65522008-02-27 21:51:47 -060021struct lmb_property {
Becky Bruce391fd932008-06-09 20:37:18 -050022 phys_addr_t base;
23 phys_size_t size;
Kumar Gala4ed65522008-02-27 21:51:47 -060024};
25
Patrick Delaunay6d665022021-03-10 10:16:31 +010026/**
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 Gala4ed65522008-02-27 21:51:47 -060033struct lmb_region {
34 unsigned long cnt;
Patrick Delaunay00fd8da2021-03-10 10:16:27 +010035 unsigned long max;
Patrick Delaunay6d665022021-03-10 10:16:31 +010036#if IS_ENABLED(CONFIG_LMB_USE_MAX_REGIONS)
Patrick Delaunaycb1e6192021-03-10 10:16:29 +010037 struct lmb_property region[CONFIG_LMB_MAX_REGIONS];
Patrick Delaunay6d665022021-03-10 10:16:31 +010038#else
39 struct lmb_property *region;
40#endif
Kumar Gala4ed65522008-02-27 21:51:47 -060041};
42
Patrick Delaunay6d665022021-03-10 10:16:31 +010043/**
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 Gala4ed65522008-02-27 21:51:47 -060056struct lmb {
57 struct lmb_region memory;
58 struct lmb_region reserved;
Patrick Delaunay6d665022021-03-10 10:16:31 +010059#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 Gala4ed65522008-02-27 21:51:47 -060063};
64
Kumar Gala4ed65522008-02-27 21:51:47 -060065extern void lmb_init(struct lmb *lmb);
Masahiro Yamadab75d8dc2020-06-26 15:13:33 +090066extern void lmb_init_and_reserve(struct lmb *lmb, struct bd_info *bd,
67 void *fdt_blob);
Simon Goldschmidt9cc23232019-01-26 22:13:04 +010068extern void lmb_init_and_reserve_range(struct lmb *lmb, phys_addr_t base,
69 phys_size_t size, void *fdt_blob);
Becky Bruce391fd932008-06-09 20:37:18 -050070extern long lmb_add(struct lmb *lmb, phys_addr_t base, phys_size_t size);
71extern long lmb_reserve(struct lmb *lmb, phys_addr_t base, phys_size_t size);
72extern phys_addr_t lmb_alloc(struct lmb *lmb, phys_size_t size, ulong align);
73extern phys_addr_t lmb_alloc_base(struct lmb *lmb, phys_size_t size, ulong align,
74 phys_addr_t max_addr);
75extern phys_addr_t __lmb_alloc_base(struct lmb *lmb, phys_size_t size, ulong align,
76 phys_addr_t max_addr);
Simon Goldschmidt4cc8af82019-01-14 22:38:18 +010077extern phys_addr_t lmb_alloc_addr(struct lmb *lmb, phys_addr_t base,
78 phys_size_t size);
Simon Goldschmidt65304aa2019-01-21 20:29:55 +010079extern phys_size_t lmb_get_free_size(struct lmb *lmb, phys_addr_t addr);
Becky Bruce391fd932008-06-09 20:37:18 -050080extern int lmb_is_reserved(struct lmb *lmb, phys_addr_t addr);
Andy Fleming98874ff2008-07-07 14:24:39 -050081extern long lmb_free(struct lmb *lmb, phys_addr_t base, phys_size_t size);
Kumar Gala4ed65522008-02-27 21:51:47 -060082
83extern void lmb_dump_all(struct lmb *lmb);
Tero Kristo9996cea2020-07-20 11:10:45 +030084extern void lmb_dump_all_force(struct lmb *lmb);
Kumar Gala4ed65522008-02-27 21:51:47 -060085
Becky Bruce391fd932008-06-09 20:37:18 -050086static inline phys_size_t
Kumar Gala4ed65522008-02-27 21:51:47 -060087lmb_size_bytes(struct lmb_region *type, unsigned long region_nr)
88{
89 return type->region[region_nr].size;
90}
Mike Frysingera16028d2009-11-03 11:35:59 -050091
92void board_lmb_reserve(struct lmb *lmb);
93void arch_lmb_reserve(struct lmb *lmb);
94
Kumar Gala4ed65522008-02-27 21:51:47 -060095#endif /* __KERNEL__ */
96
97#endif /* _LINUX_LMB_H */