Tom Rini | 83d290c | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Bin Meng | a65b25d | 2015-05-07 21:34:08 +0800 | [diff] [blame] | 2 | /* |
| 3 | * Copyright (C) 2015, Bin Meng <bmeng.cn@gmail.com> |
Bin Meng | a65b25d | 2015-05-07 21:34:08 +0800 | [diff] [blame] | 4 | */ |
| 5 | |
| 6 | #include <common.h> |
Simon Glass | 67c4e9f | 2019-11-14 12:57:45 -0700 | [diff] [blame] | 7 | #include <init.h> |
Bin Meng | a65b25d | 2015-05-07 21:34:08 +0800 | [diff] [blame] | 8 | #include <asm/post.h> |
| 9 | #include <asm/arch/qemu.h> |
| 10 | |
| 11 | DECLARE_GLOBAL_DATA_PTR; |
| 12 | |
Bin Meng | f4c0030 | 2019-08-29 02:53:04 -0700 | [diff] [blame] | 13 | u32 qemu_get_low_memory_size(void) |
Bin Meng | a65b25d | 2015-05-07 21:34:08 +0800 | [diff] [blame] | 14 | { |
| 15 | u32 ram; |
| 16 | |
| 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; |
| 21 | ram += 16 * 1024; |
| 22 | |
Bin Meng | f4c0030 | 2019-08-29 02:53:04 -0700 | [diff] [blame] | 23 | return ram * 1024; |
| 24 | } |
| 25 | |
Bin Meng | ea67d54 | 2019-08-29 02:53:05 -0700 | [diff] [blame] | 26 | u64 qemu_get_high_memory_size(void) |
| 27 | { |
| 28 | u64 ram; |
| 29 | |
| 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; |
| 36 | |
| 37 | return ram * 1024; |
| 38 | } |
| 39 | |
Bin Meng | f4c0030 | 2019-08-29 02:53:04 -0700 | [diff] [blame] | 40 | int dram_init(void) |
| 41 | { |
| 42 | gd->ram_size = qemu_get_low_memory_size(); |
Bin Meng | ea67d54 | 2019-08-29 02:53:05 -0700 | [diff] [blame] | 43 | gd->ram_size += qemu_get_high_memory_size(); |
Bin Meng | a65b25d | 2015-05-07 21:34:08 +0800 | [diff] [blame] | 44 | post_code(POST_DRAM); |
| 45 | |
| 46 | return 0; |
| 47 | } |
| 48 | |
Simon Glass | 76b00ac | 2017-03-31 08:40:32 -0600 | [diff] [blame] | 49 | int dram_init_banksize(void) |
Bin Meng | a65b25d | 2015-05-07 21:34:08 +0800 | [diff] [blame] | 50 | { |
Bin Meng | ea67d54 | 2019-08-29 02:53:05 -0700 | [diff] [blame] | 51 | u64 high_mem_size; |
| 52 | |
Bin Meng | a65b25d | 2015-05-07 21:34:08 +0800 | [diff] [blame] | 53 | gd->bd->bi_dram[0].start = 0; |
Bin Meng | ea67d54 | 2019-08-29 02:53:05 -0700 | [diff] [blame] | 54 | gd->bd->bi_dram[0].size = qemu_get_low_memory_size(); |
| 55 | |
| 56 | high_mem_size = qemu_get_high_memory_size(); |
| 57 | if (high_mem_size) { |
| 58 | gd->bd->bi_dram[1].start = SZ_4G; |
| 59 | gd->bd->bi_dram[1].size = high_mem_size; |
| 60 | } |
Simon Glass | 76b00ac | 2017-03-31 08:40:32 -0600 | [diff] [blame] | 61 | |
| 62 | return 0; |
Bin Meng | a65b25d | 2015-05-07 21:34:08 +0800 | [diff] [blame] | 63 | } |
| 64 | |
| 65 | /* |
| 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. |
| 72 | */ |
| 73 | ulong board_get_usable_ram_top(ulong total_size) |
| 74 | { |
Bin Meng | ea67d54 | 2019-08-29 02:53:05 -0700 | [diff] [blame] | 75 | return qemu_get_low_memory_size(); |
Bin Meng | a65b25d | 2015-05-07 21:34:08 +0800 | [diff] [blame] | 76 | } |