1 // SPDX-License-Identifier: GPL-2.0+
3 * Copyright (C) 2015, Bin Meng <bmeng.cn@gmail.com>
9 #include <asm/arch/qemu.h>
11 DECLARE_GLOBAL_DATA_PTR;
13 u32 qemu_get_low_memory_size(void)
17 outb(HIGH_RAM_ADDR, CMOS_ADDR_PORT);
18 ram = ((u32)inb(CMOS_DATA_PORT)) << 14;
19 outb(LOW_RAM_ADDR, CMOS_ADDR_PORT);
20 ram |= ((u32)inb(CMOS_DATA_PORT)) << 6;
26 u64 qemu_get_high_memory_size(void)
30 outb(HIGH_HIGHRAM_ADDR, CMOS_ADDR_PORT);
31 ram = ((u64)inb(CMOS_DATA_PORT)) << 22;
32 outb(MID_HIGHRAM_ADDR, CMOS_ADDR_PORT);
33 ram |= ((u64)inb(CMOS_DATA_PORT)) << 14;
34 outb(LOW_HIGHRAM_ADDR, CMOS_ADDR_PORT);
35 ram |= ((u64)inb(CMOS_DATA_PORT)) << 6;
42 gd->ram_size = qemu_get_low_memory_size();
43 gd->ram_size += qemu_get_high_memory_size();
49 int dram_init_banksize(void)
53 gd->bd->bi_dram[0].start = 0;
54 gd->bd->bi_dram[0].size = qemu_get_low_memory_size();
56 high_mem_size = qemu_get_high_memory_size();
58 gd->bd->bi_dram[1].start = SZ_4G;
59 gd->bd->bi_dram[1].size = high_mem_size;
66 * This function looks for the highest region of memory lower than 4GB which
67 * has enough space for U-Boot where U-Boot is aligned on a page boundary.
68 * It overrides the default implementation found elsewhere which simply
69 * picks the end of ram, wherever that may be. The location of the stack,
70 * the relocation address, and how far U-Boot is moved by relocation are
71 * set in the global data structure.
73 ulong board_get_usable_ram_top(ulong total_size)
75 return qemu_get_low_memory_size();