1 // SPDX-License-Identifier: GPL-2.0+
3 * Copyright (c) 2015 Google, Inc
4 * Written by Simon Glass <sjg@chromium.org>
13 DECLARE_GLOBAL_DATA_PTR;
16 * This function looks for the highest region of memory lower than 4GB which
17 * has enough space for U-Boot where U-Boot is aligned on a page boundary.
18 * It overrides the default implementation found elsewhere which simply
19 * picks the end of ram, wherever that may be. The location of the stack,
20 * the relocation address, and how far U-Boot is moved by relocation are
21 * set in the global data structure.
23 ulong board_get_usable_ram_top(ulong total_size)
25 struct efi_mem_desc *desc, *end;
26 struct efi_entry_memmap *map;
28 uintptr_t dest_addr = 0;
29 struct efi_mem_desc *largest = NULL;
32 * Find largest area of memory below 4GB. We could
33 * call efi_build_mem_table() for a more accurate picture since it
34 * merges areas together where possible. But that function uses more
35 * pre-relocation memory, and it's not critical that we find the
36 * absolute largest region.
38 ret = efi_info_get(EFIET_MEMORY_MAP, (void **)&map, &size);
40 /* We should have stopped in dram_init(), something is wrong */
41 debug("%s: Missing memory map\n", __func__);
45 end = (struct efi_mem_desc *)((ulong)map + size);
47 for (; desc < end; desc = efi_get_next_mem_desc(map, desc)) {
48 if (desc->type != EFI_CONVENTIONAL_MEMORY ||
49 desc->physical_start >= 1ULL << 32)
51 if (!largest || desc->num_pages > largest->num_pages)
55 /* If no suitable area was found, return an error. */
57 if (!largest || (largest->num_pages << EFI_PAGE_SHIFT) < (2 << 20))
60 dest_addr = largest->physical_start + (largest->num_pages <<
63 return (ulong)dest_addr;
65 panic("No available memory found for relocation");
71 struct efi_mem_desc *desc, *end;
72 struct efi_entry_memmap *map;
75 ret = efi_info_get(EFIET_MEMORY_MAP, (void **)&map, &size);
77 printf("Cannot find EFI memory map tables, ret=%d\n", ret);
82 end = (struct efi_mem_desc *)((ulong)map + size);
85 for (; desc < end; desc = efi_get_next_mem_desc(map, desc)) {
86 if (desc->type < EFI_MMAP_IO)
87 gd->ram_size += desc->num_pages << EFI_PAGE_SHIFT;
93 int dram_init_banksize(void)
95 struct efi_mem_desc *desc, *end;
96 struct efi_entry_memmap *map;
100 ret = efi_info_get(EFIET_MEMORY_MAP, (void **)&map, &size);
102 /* We should have stopped in dram_init(), something is wrong */
103 debug("%s: Missing memory map\n", __func__);
106 end = (struct efi_mem_desc *)((ulong)map + size);
109 desc < end && num_banks < CONFIG_NR_DRAM_BANKS;
110 desc = efi_get_next_mem_desc(map, desc)) {
112 * We only use conventional memory and ignore
113 * anything less than 1MB.
115 if (desc->type != EFI_CONVENTIONAL_MEMORY ||
116 (desc->num_pages << EFI_PAGE_SHIFT) < 1 << 20)
118 gd->bd->bi_dram[num_banks].start = desc->physical_start;
119 gd->bd->bi_dram[num_banks].size = desc->num_pages <<
127 int arch_cpu_init(void)
129 post_code(POST_CPU_INIT);
131 return x86_cpu_init_f();
139 int print_cpuinfo(void)
141 return default_print_cpuinfo();
144 /* Find any available tables and copy them to a safe place */
145 int reserve_arch(void)
147 struct efi_info_hdr *hdr;
149 debug("table=%lx\n", gd->arch.table);
153 hdr = (struct efi_info_hdr *)gd->arch.table;
155 gd->start_addr_sp -= hdr->total_size;
156 memcpy((void *)gd->start_addr_sp, hdr, hdr->total_size);
157 debug("Stashing EFI table at %lx to %lx, size %x\n",
158 gd->arch.table, gd->start_addr_sp, hdr->total_size);
159 gd->arch.table = gd->start_addr_sp;
164 int last_stage_init(void)
166 /* start usb so that usb keyboard can be used as input device */