xref: /rk3399_rockchip-uboot/include/bidram.h (revision 79283ba6e7dc3f688061585818d9476fc95e4067)
1 /* SPDX-License-Identifier:     GPL-2.0+ */
2 /*
3  * (C) Copyright 2019 Rockchip Electronics Co., Ltd
4  */
5 
6 #ifndef _BIDRAM_H
7 #define _BIDRAM_H
8 
9 #include <memblk.h>
10 
11 typedef struct memblock *(*parse_fn_t)(int *);
12 
13 struct bidram {
14 	struct lmb lmb;
15 	struct list_head reserved_head;
16 	bool has_init;
17 	bool fixup;
18 	u64 base_u64[MEM_RESV_COUNT]; /* 4GB+ */
19 	u64 size_u64[MEM_RESV_COUNT];
20 };
21 
22 #ifdef CONFIG_BIDRAM
23 /**
24  * bidram_initr() - Initial bidram after relocation.
25  *
26  * @return 0 on success, otherwise error
27  */
28 int bidram_initr(void);
29 
30 /**
31  * bidram_get_ram_size() - Initial bidram and get ram size.
32  *
33  * @parse_fn: function to parse ddr memory regions
34  *
35  * @return ram size, 0 on success, otherwise the effect ram size.
36  */
37 phys_size_t bidram_get_ram_size(void);
38 
39 /**
40  * bidram_gen_gd_bi_dram() - Update gd->bd->bi_dram[] according to bidram state.
41  */
42 void bidram_gen_gd_bi_dram(void);
43 
44 /**
45  * bidram_reserve() - Reserve bidram region
46  *
47  * @id: memblk id
48  * @base: region base address
49  * @size: region size
50  *
51  * @return 0 on success, otherwise error
52  */
53 int bidram_reserve(enum memblk_id id, phys_addr_t base, phys_size_t size);
54 
55 /**
56  * bidram_reserve_by_name() - Reserve bidram region by name
57  *
58  * @name: region name
59  * @base: region base address
60  * @size: region size
61  *
62  * @return 0 on success, otherwise error
63  */
64 int bidram_reserve_by_name(const char *name, phys_addr_t base, phys_size_t size);
65 
66 /**
67  * bidram_dump_all() - Dump all bidram stat
68  */
69 void bidram_dump(void);
70 
71 /**
72  * bidram_fixup() - Fixup bi_dram[] for 4GB+ memory
73  *
74  * @return 0 on success, otherwise error
75  */
76 int bidram_fixup(void);
77 
78 /**
79  * board_bidram_fixup() - Fixup bi_dram[] based on Soc boards.
80  */
81 void board_bidram_fixup(void);
82 
83 /**
84  * bidram_append_size() - Append 4GB+ memory
85  *
86  * @return 4GB+ size
87  */
88 u64 bidram_append_size(void);
89 
90 /**
91  * board_bidram_append_size() - Append board specific memory
92  *
93  * @return board specific size
94  */
95 u64 board_bidram_append_size(void);
96 
97 /**
98  * bidram_reserved_is_overlap() - Check outside memory is overlap with reserved
99  *
100  * @base: region base address
101  * @size: region size
102  *
103  * @return memblk struct when overlap, otherwise NULL
104  */
105 struct memblock *bidram_reserved_is_overlap(phys_addr_t base, phys_size_t size);
106 
107 /**
108  * board_bidram_parse_fn() - Weak function for board to implement
109  */
110 parse_fn_t board_bidram_parse_fn(void);
111 
112 /**
113  * board_bidram_reserve() - Weak function for board to implement
114  *
115  * @bidram: global bidram point, ignored
116  *
117  * @return 0 on success, otherwise error
118  */
119 int board_bidram_reserve(struct bidram *bidram);
120 #else
121 static inline int bidram_initr(void) { return 0; }
122 static inline phys_size_t bidram_get_ram_size(void) { return 0; }
123 static inline void bidram_gen_gd_bi_dram(void) { }
124 static inline int bidram_reserve(enum memblk_id id, phys_addr_t base,
125 				 phys_size_t size) { return 0; }
126 static inline int bidram_reserve_by_name(const char *name, phys_addr_t base,
127 					 phys_size_t size) { return 0; }
128 static inline void bidram_dump(void) {}
129 static inline int bidram_fixup(void) { return 0; }
130 static inline u64 bidram_append_size(void) { return 0; }
131 static inline parse_fn_t board_bidram_parse_fn(void) { return NULL; }
132 static inline int board_bidram_reserve(struct bidram *bidram) { return 0; }
133 static inline struct memblock *
134 	bidram_reserved_is_overlap(phys_addr_t base, phys_size_t size)
135 {
136 	return NULL;
137 }
138 
139 #endif
140 
141 #endif /* _BIDRAM_H */
142