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 * bidram_append_size() - Append 4GB+ memory 80 * 81 * @return 4GB+ size 82 */ 83 u64 bidram_append_size(void); 84 85 /** 86 * bidram_reserved_is_overlap() - Check outside memory is overlap with reserved 87 * 88 * @base: region base address 89 * @size: region size 90 * 91 * @return memblk struct when overlap, otherwise NULL 92 */ 93 struct memblock *bidram_reserved_is_overlap(phys_addr_t base, phys_size_t size); 94 95 /** 96 * board_bidram_parse_fn() - Weak function for board to implement 97 */ 98 parse_fn_t board_bidram_parse_fn(void); 99 100 /** 101 * board_bidram_reserve() - Weak function for board to implement 102 * 103 * @bidram: global bidram point, ignored 104 * 105 * @return 0 on success, otherwise error 106 */ 107 int board_bidram_reserve(struct bidram *bidram); 108 #else 109 static inline int bidram_initr(void) { return 0; } 110 static inline phys_size_t bidram_get_ram_size(void) { return 0; } 111 static inline void bidram_gen_gd_bi_dram(void) { } 112 static inline int bidram_reserve(enum memblk_id id, phys_addr_t base, 113 phys_size_t size) { return 0; } 114 static inline int bidram_reserve_by_name(const char *name, phys_addr_t base, 115 phys_size_t size) { return 0; } 116 static inline void bidram_dump(void) {} 117 static inline int bidram_fixup(void) { return 0; } 118 static inline u64 bidram_append_size(void) { return 0; } 119 static inline parse_fn_t board_bidram_parse_fn(void) { return NULL; } 120 static inline int board_bidram_reserve(struct bidram *bidram) { return 0; } 121 static inline struct memblock * 122 bidram_reserved_is_overlap(phys_addr_t base, phys_size_t size) 123 { 124 return NULL; 125 } 126 127 #endif 128 129 #endif /* _BIDRAM_H */ 130