xref: /openbmc/u-boot/arch/x86/cpu/qemu/dram.c (revision 83d290c56fab2d38cd1ab4c4cc7099559c1d5046)
1*83d290c5STom Rini // SPDX-License-Identifier: GPL-2.0+
2a65b25d1SBin Meng /*
3a65b25d1SBin Meng  * Copyright (C) 2015, Bin Meng <bmeng.cn@gmail.com>
4a65b25d1SBin Meng  */
5a65b25d1SBin Meng 
6a65b25d1SBin Meng #include <common.h>
7a65b25d1SBin Meng #include <asm/post.h>
8a65b25d1SBin Meng #include <asm/arch/qemu.h>
9a65b25d1SBin Meng 
10a65b25d1SBin Meng DECLARE_GLOBAL_DATA_PTR;
11a65b25d1SBin Meng 
dram_init(void)12a65b25d1SBin Meng int dram_init(void)
13a65b25d1SBin Meng {
14a65b25d1SBin Meng 	u32 ram;
15a65b25d1SBin Meng 
16a65b25d1SBin Meng 	outb(HIGH_RAM_ADDR, CMOS_ADDR_PORT);
17a65b25d1SBin Meng 	ram = ((u32)inb(CMOS_DATA_PORT)) << 14;
18a65b25d1SBin Meng 	outb(LOW_RAM_ADDR, CMOS_ADDR_PORT);
19a65b25d1SBin Meng 	ram |= ((u32)inb(CMOS_DATA_PORT)) << 6;
20a65b25d1SBin Meng 	ram += 16 * 1024;
21a65b25d1SBin Meng 
22a65b25d1SBin Meng 	gd->ram_size = ram * 1024;
23a65b25d1SBin Meng 	post_code(POST_DRAM);
24a65b25d1SBin Meng 
25a65b25d1SBin Meng 	return 0;
26a65b25d1SBin Meng }
27a65b25d1SBin Meng 
dram_init_banksize(void)2876b00acaSSimon Glass int dram_init_banksize(void)
29a65b25d1SBin Meng {
30a65b25d1SBin Meng 	gd->bd->bi_dram[0].start = 0;
31a65b25d1SBin Meng 	gd->bd->bi_dram[0].size = gd->ram_size;
3276b00acaSSimon Glass 
3376b00acaSSimon Glass 	return 0;
34a65b25d1SBin Meng }
35a65b25d1SBin Meng 
36a65b25d1SBin Meng /*
37a65b25d1SBin Meng  * This function looks for the highest region of memory lower than 4GB which
38a65b25d1SBin Meng  * has enough space for U-Boot where U-Boot is aligned on a page boundary.
39a65b25d1SBin Meng  * It overrides the default implementation found elsewhere which simply
40a65b25d1SBin Meng  * picks the end of ram, wherever that may be. The location of the stack,
41a65b25d1SBin Meng  * the relocation address, and how far U-Boot is moved by relocation are
42a65b25d1SBin Meng  * set in the global data structure.
43a65b25d1SBin Meng  */
board_get_usable_ram_top(ulong total_size)44a65b25d1SBin Meng ulong board_get_usable_ram_top(ulong total_size)
45a65b25d1SBin Meng {
46a65b25d1SBin Meng 	return gd->ram_size;
47a65b25d1SBin Meng }
48