Tom Rini | 10e4779 | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Bin Meng | 08e484c | 2014-12-17 15:50:36 +0800 | [diff] [blame] | 2 | /* |
| 3 | * Copyright (C) 2014, Bin Meng <bmeng.cn@gmail.com> |
Bin Meng | 08e484c | 2014-12-17 15:50:36 +0800 | [diff] [blame] | 4 | */ |
| 5 | |
| 6 | #include <common.h> |
Simon Glass | b93abfc | 2015-01-27 22:13:36 -0700 | [diff] [blame] | 7 | #include <asm/fsp/fsp_support.h> |
Bin Meng | 08e484c | 2014-12-17 15:50:36 +0800 | [diff] [blame] | 8 | #include <asm/e820.h> |
Bin Meng | 07793c08 | 2015-10-11 21:37:42 -0700 | [diff] [blame] | 9 | #include <asm/mrccache.h> |
Bin Meng | 08e484c | 2014-12-17 15:50:36 +0800 | [diff] [blame] | 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 | 2b21598 | 2014-12-30 16:02:05 +0800 | [diff] [blame] | 17 | const struct hob_header *hdr; |
| 18 | struct hob_res_desc *res_desc; |
Bin Meng | 08e484c | 2014-12-17 15:50:36 +0800 | [diff] [blame] | 19 | |
Bin Meng | 2b21598 | 2014-12-30 16:02:05 +0800 | [diff] [blame] | 20 | hdr = gd->arch.hob_list; |
| 21 | while (!end_of_hob(hdr)) { |
Bin Meng | 2f848bc | 2015-01-06 14:04:36 +0800 | [diff] [blame] | 22 | if (hdr->type == HOB_TYPE_RES_DESC) { |
Bin Meng | 2b21598 | 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 | 08e484c | 2014-12-17 15:50:36 +0800 | [diff] [blame] | 27 | } |
| 28 | } |
Bin Meng | 2b21598 | 2014-12-30 16:02:05 +0800 | [diff] [blame] | 29 | hdr = get_next_hob(hdr); |
Bin Meng | 08e484c | 2014-12-17 15:50:36 +0800 | [diff] [blame] | 30 | } |
| 31 | |
| 32 | gd->ram_size = ram_size; |
| 33 | post_code(POST_DRAM); |
| 34 | |
Bin Meng | 07793c08 | 2015-10-11 21:37:42 -0700 | [diff] [blame] | 35 | #ifdef CONFIG_ENABLE_MRC_CACHE |
| 36 | gd->arch.mrc_output = fsp_get_nvs_data(gd->arch.hob_list, |
| 37 | &gd->arch.mrc_output_len); |
| 38 | #endif |
| 39 | |
Bin Meng | 08e484c | 2014-12-17 15:50:36 +0800 | [diff] [blame] | 40 | return 0; |
| 41 | } |
| 42 | |
Simon Glass | 2f949c3 | 2017-03-31 08:40:32 -0600 | [diff] [blame] | 43 | int dram_init_banksize(void) |
Bin Meng | 08e484c | 2014-12-17 15:50:36 +0800 | [diff] [blame] | 44 | { |
| 45 | gd->bd->bi_dram[0].start = 0; |
| 46 | gd->bd->bi_dram[0].size = gd->ram_size; |
Simon Glass | 2f949c3 | 2017-03-31 08:40:32 -0600 | [diff] [blame] | 47 | |
| 48 | return 0; |
Bin Meng | 08e484c | 2014-12-17 15:50:36 +0800 | [diff] [blame] | 49 | } |
| 50 | |
| 51 | /* |
| 52 | * This function looks for the highest region of memory lower than 4GB which |
| 53 | * has enough space for U-Boot where U-Boot is aligned on a page boundary. |
| 54 | * It overrides the default implementation found elsewhere which simply |
| 55 | * picks the end of ram, wherever that may be. The location of the stack, |
| 56 | * the relocation address, and how far U-Boot is moved by relocation are |
| 57 | * set in the global data structure. |
| 58 | */ |
| 59 | ulong board_get_usable_ram_top(ulong total_size) |
| 60 | { |
Bin Meng | db60d86 | 2014-12-17 15:50:49 +0800 | [diff] [blame] | 61 | return fsp_get_usable_lowmem_top(gd->arch.hob_list); |
Bin Meng | 08e484c | 2014-12-17 15:50:36 +0800 | [diff] [blame] | 62 | } |
| 63 | |
Bin Meng | 3838d71 | 2018-04-11 22:02:10 -0700 | [diff] [blame] | 64 | unsigned int install_e820_map(unsigned int max_entries, |
Bin Meng | 4b8fc74 | 2018-04-11 22:02:11 -0700 | [diff] [blame] | 65 | struct e820_entry *entries) |
Bin Meng | 08e484c | 2014-12-17 15:50:36 +0800 | [diff] [blame] | 66 | { |
Bin Meng | 3838d71 | 2018-04-11 22:02:10 -0700 | [diff] [blame] | 67 | unsigned int num_entries = 0; |
Bin Meng | 2b21598 | 2014-12-30 16:02:05 +0800 | [diff] [blame] | 68 | const struct hob_header *hdr; |
| 69 | struct hob_res_desc *res_desc; |
Bin Meng | 08e484c | 2014-12-17 15:50:36 +0800 | [diff] [blame] | 70 | |
Bin Meng | 2b21598 | 2014-12-30 16:02:05 +0800 | [diff] [blame] | 71 | hdr = gd->arch.hob_list; |
Bin Meng | 08e484c | 2014-12-17 15:50:36 +0800 | [diff] [blame] | 72 | |
Bin Meng | 2b21598 | 2014-12-30 16:02:05 +0800 | [diff] [blame] | 73 | while (!end_of_hob(hdr)) { |
Bin Meng | 2f848bc | 2015-01-06 14:04:36 +0800 | [diff] [blame] | 74 | if (hdr->type == HOB_TYPE_RES_DESC) { |
Bin Meng | 2b21598 | 2014-12-30 16:02:05 +0800 | [diff] [blame] | 75 | res_desc = (struct hob_res_desc *)hdr; |
| 76 | entries[num_entries].addr = res_desc->phys_start; |
| 77 | entries[num_entries].size = res_desc->len; |
Bin Meng | 08e484c | 2014-12-17 15:50:36 +0800 | [diff] [blame] | 78 | |
Bin Meng | 2b21598 | 2014-12-30 16:02:05 +0800 | [diff] [blame] | 79 | if (res_desc->type == RES_SYS_MEM) |
Bin Meng | 08e484c | 2014-12-17 15:50:36 +0800 | [diff] [blame] | 80 | entries[num_entries].type = E820_RAM; |
Bin Meng | 2b21598 | 2014-12-30 16:02:05 +0800 | [diff] [blame] | 81 | else if (res_desc->type == RES_MEM_RESERVED) |
Bin Meng | 08e484c | 2014-12-17 15:50:36 +0800 | [diff] [blame] | 82 | entries[num_entries].type = E820_RESERVED; |
Bin Meng | c71c482 | 2015-09-28 02:11:59 -0700 | [diff] [blame] | 83 | |
| 84 | num_entries++; |
Bin Meng | 08e484c | 2014-12-17 15:50:36 +0800 | [diff] [blame] | 85 | } |
Bin Meng | 2b21598 | 2014-12-30 16:02:05 +0800 | [diff] [blame] | 86 | hdr = get_next_hob(hdr); |
Bin Meng | 08e484c | 2014-12-17 15:50:36 +0800 | [diff] [blame] | 87 | } |
| 88 | |
Bin Meng | cf40bd4 | 2015-07-22 01:21:15 -0700 | [diff] [blame] | 89 | /* Mark PCIe ECAM address range as reserved */ |
| 90 | entries[num_entries].addr = CONFIG_PCIE_ECAM_BASE; |
| 91 | entries[num_entries].size = CONFIG_PCIE_ECAM_SIZE; |
| 92 | entries[num_entries].type = E820_RESERVED; |
| 93 | num_entries++; |
| 94 | |
Bin Meng | 212c7b2 | 2017-04-21 07:24:34 -0700 | [diff] [blame] | 95 | #ifdef CONFIG_HAVE_ACPI_RESUME |
| 96 | /* |
| 97 | * Everything between U-Boot's stack and ram top needs to be |
| 98 | * reserved in order for ACPI S3 resume to work. |
| 99 | */ |
| 100 | entries[num_entries].addr = gd->start_addr_sp - CONFIG_STACK_SIZE; |
| 101 | entries[num_entries].size = gd->ram_top - gd->start_addr_sp + \ |
| 102 | CONFIG_STACK_SIZE; |
| 103 | entries[num_entries].type = E820_RESERVED; |
| 104 | num_entries++; |
| 105 | #endif |
| 106 | |
Bin Meng | 08e484c | 2014-12-17 15:50:36 +0800 | [diff] [blame] | 107 | return num_entries; |
| 108 | } |