2018-05-06 21:58:06 +00:00
|
|
|
/* SPDX-License-Identifier: GPL-2.0+ */
|
2008-02-28 03:51:47 +00:00
|
|
|
#ifndef _LINUX_LMB_H
|
|
|
|
#define _LINUX_LMB_H
|
|
|
|
#ifdef __KERNEL__
|
|
|
|
|
|
|
|
#include <asm/types.h>
|
2019-01-26 21:13:04 +00:00
|
|
|
#include <asm/u-boot.h>
|
|
|
|
|
2008-02-28 03:51:47 +00:00
|
|
|
/*
|
|
|
|
* Logical memory blocks.
|
|
|
|
*
|
|
|
|
* Copyright (C) 2001 Peter Bergner, IBM Corp.
|
|
|
|
*/
|
|
|
|
|
2021-03-10 09:16:31 +00:00
|
|
|
/**
|
|
|
|
* struct lmb_property - Description of one region.
|
|
|
|
*
|
|
|
|
* @base: Base address of the region.
|
|
|
|
* @size: Size of the region
|
|
|
|
*/
|
2008-02-28 03:51:47 +00:00
|
|
|
struct lmb_property {
|
2008-06-10 01:37:18 +00:00
|
|
|
phys_addr_t base;
|
|
|
|
phys_size_t size;
|
2008-02-28 03:51:47 +00:00
|
|
|
};
|
|
|
|
|
2021-03-10 09:16:31 +00:00
|
|
|
/**
|
|
|
|
* struct lmb_region - Description of a set of region.
|
|
|
|
*
|
|
|
|
* @cnt: Number of regions.
|
|
|
|
* @max: Size of the region array, max value of cnt.
|
|
|
|
* @region: Array of the region properties
|
|
|
|
*/
|
2008-02-28 03:51:47 +00:00
|
|
|
struct lmb_region {
|
|
|
|
unsigned long cnt;
|
2021-03-10 09:16:27 +00:00
|
|
|
unsigned long max;
|
2021-03-10 09:16:31 +00:00
|
|
|
#if IS_ENABLED(CONFIG_LMB_USE_MAX_REGIONS)
|
2021-03-10 09:16:29 +00:00
|
|
|
struct lmb_property region[CONFIG_LMB_MAX_REGIONS];
|
2021-03-10 09:16:31 +00:00
|
|
|
#else
|
|
|
|
struct lmb_property *region;
|
|
|
|
#endif
|
2008-02-28 03:51:47 +00:00
|
|
|
};
|
|
|
|
|
2021-03-10 09:16:31 +00:00
|
|
|
/**
|
|
|
|
* struct lmb - Logical memory block handle.
|
|
|
|
*
|
|
|
|
* Clients provide storage for Logical memory block (lmb) handles.
|
|
|
|
* The content of the structure is managed by the lmb library.
|
|
|
|
* A lmb struct is initialized by lmb_init() functions.
|
|
|
|
* The lmb struct is passed to all other lmb APIs.
|
|
|
|
*
|
|
|
|
* @memory: Description of memory regions.
|
|
|
|
* @reserved: Description of reserved regions.
|
|
|
|
* @memory_regions: Array of the memory regions (statically allocated)
|
|
|
|
* @reserved_regions: Array of the reserved regions (statically allocated)
|
|
|
|
*/
|
2008-02-28 03:51:47 +00:00
|
|
|
struct lmb {
|
|
|
|
struct lmb_region memory;
|
|
|
|
struct lmb_region reserved;
|
2021-03-10 09:16:31 +00:00
|
|
|
#if !IS_ENABLED(CONFIG_LMB_USE_MAX_REGIONS)
|
|
|
|
struct lmb_property memory_regions[CONFIG_LMB_MEMORY_REGIONS];
|
|
|
|
struct lmb_property reserved_regions[CONFIG_LMB_RESERVED_REGIONS];
|
|
|
|
#endif
|
2008-02-28 03:51:47 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
extern void lmb_init(struct lmb *lmb);
|
2020-06-26 06:13:33 +00:00
|
|
|
extern void lmb_init_and_reserve(struct lmb *lmb, struct bd_info *bd,
|
|
|
|
void *fdt_blob);
|
2019-01-26 21:13:04 +00:00
|
|
|
extern void lmb_init_and_reserve_range(struct lmb *lmb, phys_addr_t base,
|
|
|
|
phys_size_t size, void *fdt_blob);
|
2008-06-10 01:37:18 +00:00
|
|
|
extern long lmb_add(struct lmb *lmb, phys_addr_t base, phys_size_t size);
|
|
|
|
extern long lmb_reserve(struct lmb *lmb, phys_addr_t base, phys_size_t size);
|
|
|
|
extern phys_addr_t lmb_alloc(struct lmb *lmb, phys_size_t size, ulong align);
|
|
|
|
extern phys_addr_t lmb_alloc_base(struct lmb *lmb, phys_size_t size, ulong align,
|
|
|
|
phys_addr_t max_addr);
|
|
|
|
extern phys_addr_t __lmb_alloc_base(struct lmb *lmb, phys_size_t size, ulong align,
|
|
|
|
phys_addr_t max_addr);
|
2019-01-14 21:38:18 +00:00
|
|
|
extern phys_addr_t lmb_alloc_addr(struct lmb *lmb, phys_addr_t base,
|
|
|
|
phys_size_t size);
|
2019-01-21 19:29:55 +00:00
|
|
|
extern phys_size_t lmb_get_free_size(struct lmb *lmb, phys_addr_t addr);
|
2008-06-10 01:37:18 +00:00
|
|
|
extern int lmb_is_reserved(struct lmb *lmb, phys_addr_t addr);
|
2008-07-07 19:24:39 +00:00
|
|
|
extern long lmb_free(struct lmb *lmb, phys_addr_t base, phys_size_t size);
|
2008-02-28 03:51:47 +00:00
|
|
|
|
|
|
|
extern void lmb_dump_all(struct lmb *lmb);
|
2020-07-20 08:10:45 +00:00
|
|
|
extern void lmb_dump_all_force(struct lmb *lmb);
|
2008-02-28 03:51:47 +00:00
|
|
|
|
2008-06-10 01:37:18 +00:00
|
|
|
static inline phys_size_t
|
2008-02-28 03:51:47 +00:00
|
|
|
lmb_size_bytes(struct lmb_region *type, unsigned long region_nr)
|
|
|
|
{
|
|
|
|
return type->region[region_nr].size;
|
|
|
|
}
|
2009-11-03 16:35:59 +00:00
|
|
|
|
|
|
|
void board_lmb_reserve(struct lmb *lmb);
|
|
|
|
void arch_lmb_reserve(struct lmb *lmb);
|
|
|
|
|
2008-02-28 03:51:47 +00:00
|
|
|
#endif /* __KERNEL__ */
|
|
|
|
|
|
|
|
#endif /* _LINUX_LMB_H */
|