blob: 595c397d4a4fe009d498ef0e61b5cc505c76cf39 [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>
Simon Glass6980b6b2019-11-14 12:57:45 -07007#include <init.h>
Simon Glass3ba929a2020-10-30 21:38:53 -06008#include <asm/global_data.h>
Bin Meng2229c4c2015-05-07 21:34:08 +08009#include <asm/post.h>
10#include <asm/arch/qemu.h>
11
12DECLARE_GLOBAL_DATA_PTR;
13
Bin Meng38502eb2019-08-29 02:53:04 -070014u32 qemu_get_low_memory_size(void)
Bin Meng2229c4c2015-05-07 21:34:08 +080015{
16 u32 ram;
17
18 outb(HIGH_RAM_ADDR, CMOS_ADDR_PORT);
19 ram = ((u32)inb(CMOS_DATA_PORT)) << 14;
20 outb(LOW_RAM_ADDR, CMOS_ADDR_PORT);
21 ram |= ((u32)inb(CMOS_DATA_PORT)) << 6;
22 ram += 16 * 1024;
23
Bin Meng38502eb2019-08-29 02:53:04 -070024 return ram * 1024;
25}
26
Bin Mengfc7f57f2019-08-29 02:53:05 -070027u64 qemu_get_high_memory_size(void)
28{
29 u64 ram;
30
31 outb(HIGH_HIGHRAM_ADDR, CMOS_ADDR_PORT);
32 ram = ((u64)inb(CMOS_DATA_PORT)) << 22;
33 outb(MID_HIGHRAM_ADDR, CMOS_ADDR_PORT);
34 ram |= ((u64)inb(CMOS_DATA_PORT)) << 14;
35 outb(LOW_HIGHRAM_ADDR, CMOS_ADDR_PORT);
36 ram |= ((u64)inb(CMOS_DATA_PORT)) << 6;
37
38 return ram * 1024;
39}
40
Bin Meng38502eb2019-08-29 02:53:04 -070041int dram_init(void)
42{
43 gd->ram_size = qemu_get_low_memory_size();
Bin Mengfc7f57f2019-08-29 02:53:05 -070044 gd->ram_size += qemu_get_high_memory_size();
Bin Meng2229c4c2015-05-07 21:34:08 +080045 post_code(POST_DRAM);
46
47 return 0;
48}
49
Simon Glass2f949c32017-03-31 08:40:32 -060050int dram_init_banksize(void)
Bin Meng2229c4c2015-05-07 21:34:08 +080051{
Bin Mengfc7f57f2019-08-29 02:53:05 -070052 u64 high_mem_size;
53
Bin Meng2229c4c2015-05-07 21:34:08 +080054 gd->bd->bi_dram[0].start = 0;
Bin Mengfc7f57f2019-08-29 02:53:05 -070055 gd->bd->bi_dram[0].size = qemu_get_low_memory_size();
56
57 high_mem_size = qemu_get_high_memory_size();
58 if (high_mem_size) {
59 gd->bd->bi_dram[1].start = SZ_4G;
60 gd->bd->bi_dram[1].size = high_mem_size;
61 }
Simon Glass2f949c32017-03-31 08:40:32 -060062
63 return 0;
Bin Meng2229c4c2015-05-07 21:34:08 +080064}
65
66/*
67 * This function looks for the highest region of memory lower than 4GB which
68 * has enough space for U-Boot where U-Boot is aligned on a page boundary.
69 * It overrides the default implementation found elsewhere which simply
70 * picks the end of ram, wherever that may be. The location of the stack,
71 * the relocation address, and how far U-Boot is moved by relocation are
72 * set in the global data structure.
73 */
Pali Rohár4f4f5832022-09-09 17:32:40 +020074phys_size_t board_get_usable_ram_top(phys_size_t total_size)
Bin Meng2229c4c2015-05-07 21:34:08 +080075{
Bin Mengfc7f57f2019-08-29 02:53:05 -070076 return qemu_get_low_memory_size();
Bin Meng2229c4c2015-05-07 21:34:08 +080077}