Bin Meng | b2e02d2 | 2014-12-17 15:50:36 +0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2014, Bin Meng <bmeng.cn@gmail.com> |
| 3 | * |
| 4 | * SPDX-License-Identifier: GPL-2.0+ |
| 5 | */ |
| 6 | |
| 7 | #include <common.h> |
Simon Glass | 1021af4 | 2015-01-27 22:13:36 -0700 | [diff] [blame^] | 8 | #include <asm/fsp/fsp_support.h> |
Bin Meng | b2e02d2 | 2014-12-17 15:50:36 +0800 | [diff] [blame] | 9 | #include <asm/e820.h> |
| 10 | #include <asm/post.h> |
| 11 | |
| 12 | DECLARE_GLOBAL_DATA_PTR; |
| 13 | |
| 14 | int dram_init(void) |
| 15 | { |
| 16 | phys_size_t ram_size = 0; |
Bin Meng | 949dbc1 | 2014-12-30 16:02:05 +0800 | [diff] [blame] | 17 | const struct hob_header *hdr; |
| 18 | struct hob_res_desc *res_desc; |
Bin Meng | b2e02d2 | 2014-12-17 15:50:36 +0800 | [diff] [blame] | 19 | |
Bin Meng | 949dbc1 | 2014-12-30 16:02:05 +0800 | [diff] [blame] | 20 | hdr = gd->arch.hob_list; |
| 21 | while (!end_of_hob(hdr)) { |
Bin Meng | b2439ae | 2015-01-06 14:04:36 +0800 | [diff] [blame] | 22 | if (hdr->type == HOB_TYPE_RES_DESC) { |
Bin Meng | 949dbc1 | 2014-12-30 16:02:05 +0800 | [diff] [blame] | 23 | res_desc = (struct hob_res_desc *)hdr; |
| 24 | if (res_desc->type == RES_SYS_MEM || |
| 25 | res_desc->type == RES_MEM_RESERVED) { |
| 26 | ram_size += res_desc->len; |
Bin Meng | b2e02d2 | 2014-12-17 15:50:36 +0800 | [diff] [blame] | 27 | } |
| 28 | } |
Bin Meng | 949dbc1 | 2014-12-30 16:02:05 +0800 | [diff] [blame] | 29 | hdr = get_next_hob(hdr); |
Bin Meng | b2e02d2 | 2014-12-17 15:50:36 +0800 | [diff] [blame] | 30 | } |
| 31 | |
| 32 | gd->ram_size = ram_size; |
| 33 | post_code(POST_DRAM); |
| 34 | |
| 35 | return 0; |
| 36 | } |
| 37 | |
| 38 | void dram_init_banksize(void) |
| 39 | { |
| 40 | gd->bd->bi_dram[0].start = 0; |
| 41 | gd->bd->bi_dram[0].size = gd->ram_size; |
| 42 | } |
| 43 | |
| 44 | /* |
| 45 | * This function looks for the highest region of memory lower than 4GB which |
| 46 | * has enough space for U-Boot where U-Boot is aligned on a page boundary. |
| 47 | * It overrides the default implementation found elsewhere which simply |
| 48 | * picks the end of ram, wherever that may be. The location of the stack, |
| 49 | * the relocation address, and how far U-Boot is moved by relocation are |
| 50 | * set in the global data structure. |
| 51 | */ |
| 52 | ulong board_get_usable_ram_top(ulong total_size) |
| 53 | { |
Bin Meng | 255fd5c | 2014-12-17 15:50:49 +0800 | [diff] [blame] | 54 | return fsp_get_usable_lowmem_top(gd->arch.hob_list); |
Bin Meng | b2e02d2 | 2014-12-17 15:50:36 +0800 | [diff] [blame] | 55 | } |
| 56 | |
| 57 | unsigned install_e820_map(unsigned max_entries, struct e820entry *entries) |
| 58 | { |
| 59 | unsigned num_entries = 0; |
Bin Meng | 949dbc1 | 2014-12-30 16:02:05 +0800 | [diff] [blame] | 60 | const struct hob_header *hdr; |
| 61 | struct hob_res_desc *res_desc; |
Bin Meng | b2e02d2 | 2014-12-17 15:50:36 +0800 | [diff] [blame] | 62 | |
Bin Meng | 949dbc1 | 2014-12-30 16:02:05 +0800 | [diff] [blame] | 63 | hdr = gd->arch.hob_list; |
Bin Meng | b2e02d2 | 2014-12-17 15:50:36 +0800 | [diff] [blame] | 64 | |
Bin Meng | 949dbc1 | 2014-12-30 16:02:05 +0800 | [diff] [blame] | 65 | while (!end_of_hob(hdr)) { |
Bin Meng | b2439ae | 2015-01-06 14:04:36 +0800 | [diff] [blame] | 66 | if (hdr->type == HOB_TYPE_RES_DESC) { |
Bin Meng | 949dbc1 | 2014-12-30 16:02:05 +0800 | [diff] [blame] | 67 | res_desc = (struct hob_res_desc *)hdr; |
| 68 | entries[num_entries].addr = res_desc->phys_start; |
| 69 | entries[num_entries].size = res_desc->len; |
Bin Meng | b2e02d2 | 2014-12-17 15:50:36 +0800 | [diff] [blame] | 70 | |
Bin Meng | 949dbc1 | 2014-12-30 16:02:05 +0800 | [diff] [blame] | 71 | if (res_desc->type == RES_SYS_MEM) |
Bin Meng | b2e02d2 | 2014-12-17 15:50:36 +0800 | [diff] [blame] | 72 | entries[num_entries].type = E820_RAM; |
Bin Meng | 949dbc1 | 2014-12-30 16:02:05 +0800 | [diff] [blame] | 73 | else if (res_desc->type == RES_MEM_RESERVED) |
Bin Meng | b2e02d2 | 2014-12-17 15:50:36 +0800 | [diff] [blame] | 74 | entries[num_entries].type = E820_RESERVED; |
| 75 | } |
Bin Meng | 949dbc1 | 2014-12-30 16:02:05 +0800 | [diff] [blame] | 76 | hdr = get_next_hob(hdr); |
Bin Meng | b2e02d2 | 2014-12-17 15:50:36 +0800 | [diff] [blame] | 77 | num_entries++; |
| 78 | } |
| 79 | |
| 80 | return num_entries; |
| 81 | } |