1 /* SPDX-License-Identifier: GPL-2.0+ */ 2 /* 3 * (C) Copyright 2019 Rockchip Electronics Co., Ltd 4 */ 5 6 #ifndef _SYSMEM_H 7 #define _SYSMEM_H 8 9 #include <memblk.h> 10 11 /* 12 * CONFIG_SYS_FDT_PAD default value is sync with bootm framework in: 13 * common/image-fdt.c 14 */ 15 #ifndef CONFIG_SYS_FDT_PAD 16 #define CONFIG_SYS_FDT_PAD 0x3000 17 #endif 18 19 struct sysmem { 20 struct lmb lmb; 21 struct list_head allocated_head; 22 ulong allocated_cnt; 23 bool has_initf; 24 bool has_initr; 25 }; 26 27 #ifdef CONFIG_SYSMEM 28 /** 29 * sysmem_has_init() - Is sysmem initialized 30 * 31 * @return true or false 32 */ 33 bool sysmem_has_init(void); 34 35 /** 36 * sysmem_init() - Sysmem initialization 37 * 38 * @return 0 on success, otherwise error 39 */ 40 int sysmem_init(void); 41 42 /** 43 * sysmem_initr() - Sysmem initialization after relocation 44 * 45 * @return 0 on success, otherwise error 46 */ 47 int sysmem_initr(void); 48 49 /** 50 * sysmem_alloc() - Alloc sysmem region at anywhere 51 * 52 * @id: memblk id 53 * @size: region size 54 * 55 * @return NULL on error, otherwise the allocated region address ptr 56 */ 57 void *sysmem_alloc(enum memblk_id id, phys_size_t size); 58 59 /** 60 * sysmem_alloc_base() - Alloc sysmem region at the expect addr 61 * 62 * @id: memblk id 63 * @base: region base 64 * @size: region size 65 * 66 * @return NULL on error, otherwise the allocated region address ptr 67 */ 68 void *sysmem_alloc_base(enum memblk_id id, phys_addr_t base, phys_size_t size); 69 70 /** 71 * sysmem_alloc_base_by_name() - Alloc sysmem region at the expect addr by name 72 * 73 * @name: memblk name 74 * @base: region base 75 * @size: region size 76 * 77 * @return NULL on error, otherwise the allocated region address ptr 78 */ 79 void *sysmem_alloc_base_by_name(const char *name, 80 phys_addr_t base, phys_size_t size); 81 82 /** 83 * sysmem_fdt_reserve_alloc_base() - Alloc sysmem region at the expect addr by name, 84 * called only for reserve memory from fdt. 85 * 86 * @name: memblk name 87 * @base: region base 88 * @size: region size 89 * 90 * @return NULL on error, otherwise the allocated region address ptr 91 */ 92 void *sysmem_fdt_reserve_alloc_base(const char *name, 93 phys_addr_t base, phys_size_t size); 94 95 /** 96 * sysmem_free() - Free allocated sysmem region 97 * 98 * @base: region base 99 * 100 * @return 0 on success, otherwise error 101 */ 102 int sysmem_free(phys_addr_t base); 103 104 /** 105 * sysmem_dump() - Dump all sysmem region state and check overflow 106 */ 107 void sysmem_dump(void); 108 109 /** 110 * board_sysmem_reserve() - Weak function for board to implement 111 * 112 * @sysmem: global sysmem point, ignored 113 * 114 * @return 0 on success, otherwise error 115 */ 116 int board_sysmem_reserve(struct sysmem *sysmem); 117 #else 118 static inline bool sysmem_has_init(void) { return false; } 119 static inline int sysmem_init(void) { return 0; } 120 static inline int sysmem_initr(void) { return 0; } 121 static inline int sysmem_free(phys_addr_t base) { return 0; } 122 static inline void sysmem_dump(void) {} 123 __weak int board_sysmem_reserve(struct sysmem *sysmem) { return 0; } 124 static inline void *sysmem_alloc_base(enum memblk_id id, 125 phys_addr_t base, phys_size_t size) 126 { 127 return (void *)base; 128 } 129 static inline void *sysmem_alloc_base_by_name(const char *name, 130 phys_addr_t base, 131 phys_size_t size) 132 { 133 return (void *)base; 134 } 135 static inline void *sysmem_fdt_reserve_alloc_base(const char *name, 136 phys_addr_t base, 137 phys_size_t size) 138 { 139 return (void *)base; 140 } 141 #endif /* CONFIG_SYSMEM */ 142 #endif /* _SYSMEM_H */ 143