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 /** 23 * bidram_initr() - Initial bidram after relocation. 24 * 25 * @return 0 on success, otherwise error 26 */ 27 int bidram_initr(void); 28 29 /** 30 * bidram_get_ram_size() - Initial bidram and get ram size. 31 * 32 * @parse_fn: function to parse ddr memory regions 33 * 34 * @return ram size, 0 on success, otherwise the effect ram size. 35 */ 36 phys_size_t bidram_get_ram_size(void); 37 38 /** 39 * bidram_gen_gd_bi_dram() - Update gd->bd->bi_dram[] according to bidram state. 40 */ 41 void bidram_gen_gd_bi_dram(void); 42 43 /** 44 * bidram_reserve() - Reserve bidram region 45 * 46 * @id: memblk id 47 * @base: region base address 48 * @size: region size 49 * 50 * @return 0 on success, otherwise error 51 */ 52 int bidram_reserve(enum memblk_id id, phys_addr_t base, phys_size_t size); 53 54 /** 55 * bidram_reserve_by_name() - Reserve bidram region by name 56 * 57 * @name: region name 58 * @base: region base address 59 * @size: region size 60 * 61 * @return 0 on success, otherwise error 62 */ 63 int bidram_reserve_by_name(const char *name, phys_addr_t base, phys_size_t size); 64 65 /** 66 * bidram_dump_all() - Dump all bidram stat 67 */ 68 void bidram_dump(void); 69 70 /** 71 * bidram_fixup() - Fixup bi_dram[] for 4GB+ memory 72 * 73 * @return 0 on success, otherwise error 74 */ 75 int bidram_fixup(void); 76 77 /** 78 * bidram_append_size() - Append 4GB+ memory 79 * 80 * @return 4GB+ size 81 */ 82 u64 bidram_append_size(void); 83 84 /** 85 * bidram_reserved_is_overlap() - Check outside memory is overlap with reserved 86 * 87 * @base: region base address 88 * @size: region size 89 * 90 * @return memblk struct when overlap, otherwise NULL 91 */ 92 struct memblock *bidram_reserved_is_overlap(phys_addr_t base, phys_size_t size); 93 94 /** 95 * board_bidram_parse_fn() - Weak function for board to implement 96 */ 97 parse_fn_t board_bidram_parse_fn(void); 98 99 /** 100 * board_bidram_reserve() - Weak function for board to implement 101 * 102 * @bidram: global bidram point, ignored 103 * 104 * @return 0 on success, otherwise error 105 */ 106 int board_bidram_reserve(struct bidram *bidram); 107 108 #endif /* _BIDRAM_H */ 109