blob: 6707b7b363493b4cad1efed46f76cbf99a80cdc6 [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Bin Meng2229c4c2015-05-07 21:34:08 +08002/*
3 * Copyright (C) 2015, Bin Meng <bmeng.cn@gmail.com>
Bin Meng2229c4c2015-05-07 21:34:08 +08004 */
5
6#include <common.h>
7#include <asm/post.h>
8#include <asm/arch/qemu.h>
9
10DECLARE_GLOBAL_DATA_PTR;
11
Bin Meng38502eb2019-08-29 02:53:04 -070012u32 qemu_get_low_memory_size(void)
Bin Meng2229c4c2015-05-07 21:34:08 +080013{
14 u32 ram;
15
16 outb(HIGH_RAM_ADDR, CMOS_ADDR_PORT);
17 ram = ((u32)inb(CMOS_DATA_PORT)) << 14;
18 outb(LOW_RAM_ADDR, CMOS_ADDR_PORT);
19 ram |= ((u32)inb(CMOS_DATA_PORT)) << 6;
20 ram += 16 * 1024;
21
Bin Meng38502eb2019-08-29 02:53:04 -070022 return ram * 1024;
23}
24
Bin Mengfc7f57f2019-08-29 02:53:05 -070025u64 qemu_get_high_memory_size(void)
26{
27 u64 ram;
28
29 outb(HIGH_HIGHRAM_ADDR, CMOS_ADDR_PORT);
30 ram = ((u64)inb(CMOS_DATA_PORT)) << 22;
31 outb(MID_HIGHRAM_ADDR, CMOS_ADDR_PORT);
32 ram |= ((u64)inb(CMOS_DATA_PORT)) << 14;
33 outb(LOW_HIGHRAM_ADDR, CMOS_ADDR_PORT);
34 ram |= ((u64)inb(CMOS_DATA_PORT)) << 6;
35
36 return ram * 1024;
37}
38
Bin Meng38502eb2019-08-29 02:53:04 -070039int dram_init(void)
40{
41 gd->ram_size = qemu_get_low_memory_size();
Bin Mengfc7f57f2019-08-29 02:53:05 -070042 gd->ram_size += qemu_get_high_memory_size();
Bin Meng2229c4c2015-05-07 21:34:08 +080043 post_code(POST_DRAM);
44
45 return 0;
46}
47
Simon Glass2f949c32017-03-31 08:40:32 -060048int dram_init_banksize(void)
Bin Meng2229c4c2015-05-07 21:34:08 +080049{
Bin Mengfc7f57f2019-08-29 02:53:05 -070050 u64 high_mem_size;
51
Bin Meng2229c4c2015-05-07 21:34:08 +080052 gd->bd->bi_dram[0].start = 0;
Bin Mengfc7f57f2019-08-29 02:53:05 -070053 gd->bd->bi_dram[0].size = qemu_get_low_memory_size();
54
55 high_mem_size = qemu_get_high_memory_size();
56 if (high_mem_size) {
57 gd->bd->bi_dram[1].start = SZ_4G;
58 gd->bd->bi_dram[1].size = high_mem_size;
59 }
Simon Glass2f949c32017-03-31 08:40:32 -060060
61 return 0;
Bin Meng2229c4c2015-05-07 21:34:08 +080062}
63
64/*
65 * This function looks for the highest region of memory lower than 4GB which
66 * has enough space for U-Boot where U-Boot is aligned on a page boundary.
67 * It overrides the default implementation found elsewhere which simply
68 * picks the end of ram, wherever that may be. The location of the stack,
69 * the relocation address, and how far U-Boot is moved by relocation are
70 * set in the global data structure.
71 */
72ulong board_get_usable_ram_top(ulong total_size)
73{
Bin Mengfc7f57f2019-08-29 02:53:05 -070074 return qemu_get_low_memory_size();
Bin Meng2229c4c2015-05-07 21:34:08 +080075}