]>
Commit | Line | Data |
---|---|---|
83d290c5 | 1 | // SPDX-License-Identifier: GPL-2.0+ |
a65b25d1 BM |
2 | /* |
3 | * Copyright (C) 2015, Bin Meng <bmeng.cn@gmail.com> | |
a65b25d1 BM |
4 | */ |
5 | ||
d678a59d | 6 | #include <common.h> |
67c4e9f8 | 7 | #include <init.h> |
401d1c4f | 8 | #include <asm/global_data.h> |
a65b25d1 BM |
9 | #include <asm/post.h> |
10 | #include <asm/arch/qemu.h> | |
3cc40953 | 11 | #include <linux/sizes.h> |
a65b25d1 BM |
12 | |
13 | DECLARE_GLOBAL_DATA_PTR; | |
14 | ||
f4c00300 | 15 | u32 qemu_get_low_memory_size(void) |
a65b25d1 BM |
16 | { |
17 | u32 ram; | |
18 | ||
19 | outb(HIGH_RAM_ADDR, CMOS_ADDR_PORT); | |
20 | ram = ((u32)inb(CMOS_DATA_PORT)) << 14; | |
21 | outb(LOW_RAM_ADDR, CMOS_ADDR_PORT); | |
22 | ram |= ((u32)inb(CMOS_DATA_PORT)) << 6; | |
23 | ram += 16 * 1024; | |
24 | ||
f4c00300 BM |
25 | return ram * 1024; |
26 | } | |
27 | ||
ea67d549 BM |
28 | u64 qemu_get_high_memory_size(void) |
29 | { | |
30 | u64 ram; | |
31 | ||
32 | outb(HIGH_HIGHRAM_ADDR, CMOS_ADDR_PORT); | |
33 | ram = ((u64)inb(CMOS_DATA_PORT)) << 22; | |
34 | outb(MID_HIGHRAM_ADDR, CMOS_ADDR_PORT); | |
35 | ram |= ((u64)inb(CMOS_DATA_PORT)) << 14; | |
36 | outb(LOW_HIGHRAM_ADDR, CMOS_ADDR_PORT); | |
37 | ram |= ((u64)inb(CMOS_DATA_PORT)) << 6; | |
38 | ||
39 | return ram * 1024; | |
40 | } | |
41 | ||
f4c00300 BM |
42 | int dram_init(void) |
43 | { | |
44 | gd->ram_size = qemu_get_low_memory_size(); | |
ea67d549 | 45 | gd->ram_size += qemu_get_high_memory_size(); |
a65b25d1 BM |
46 | post_code(POST_DRAM); |
47 | ||
48 | return 0; | |
49 | } | |
50 | ||
76b00aca | 51 | int dram_init_banksize(void) |
a65b25d1 | 52 | { |
ea67d549 BM |
53 | u64 high_mem_size; |
54 | ||
a65b25d1 | 55 | gd->bd->bi_dram[0].start = 0; |
ea67d549 BM |
56 | gd->bd->bi_dram[0].size = qemu_get_low_memory_size(); |
57 | ||
58 | high_mem_size = qemu_get_high_memory_size(); | |
59 | if (high_mem_size) { | |
60 | gd->bd->bi_dram[1].start = SZ_4G; | |
61 | gd->bd->bi_dram[1].size = high_mem_size; | |
62 | } | |
76b00aca SG |
63 | |
64 | return 0; | |
a65b25d1 BM |
65 | } |
66 | ||
67 | /* | |
68 | * This function looks for the highest region of memory lower than 4GB which | |
69 | * has enough space for U-Boot where U-Boot is aligned on a page boundary. | |
70 | * It overrides the default implementation found elsewhere which simply | |
71 | * picks the end of ram, wherever that may be. The location of the stack, | |
72 | * the relocation address, and how far U-Boot is moved by relocation are | |
73 | * set in the global data structure. | |
74 | */ | |
d768dd88 | 75 | phys_addr_t board_get_usable_ram_top(phys_size_t total_size) |
a65b25d1 | 76 | { |
ea67d549 | 77 | return qemu_get_low_memory_size(); |
a65b25d1 | 78 | } |