Tom Rini | 10e4779 | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Bin Meng | 2229c4c | 2015-05-07 21:34:08 +0800 | [diff] [blame] | 2 | /* |
| 3 | * Copyright (C) 2015, Bin Meng <bmeng.cn@gmail.com> |
Bin Meng | 2229c4c | 2015-05-07 21:34:08 +0800 | [diff] [blame] | 4 | */ |
| 5 | |
| 6 | #include <common.h> |
Simon Glass | 6980b6b | 2019-11-14 12:57:45 -0700 | [diff] [blame] | 7 | #include <init.h> |
Simon Glass | 3ba929a | 2020-10-30 21:38:53 -0600 | [diff] [blame] | 8 | #include <asm/global_data.h> |
Bin Meng | 2229c4c | 2015-05-07 21:34:08 +0800 | [diff] [blame] | 9 | #include <asm/post.h> |
| 10 | #include <asm/arch/qemu.h> |
| 11 | |
| 12 | DECLARE_GLOBAL_DATA_PTR; |
| 13 | |
Bin Meng | 38502eb | 2019-08-29 02:53:04 -0700 | [diff] [blame] | 14 | u32 qemu_get_low_memory_size(void) |
Bin Meng | 2229c4c | 2015-05-07 21:34:08 +0800 | [diff] [blame] | 15 | { |
| 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 Meng | 38502eb | 2019-08-29 02:53:04 -0700 | [diff] [blame] | 24 | return ram * 1024; |
| 25 | } |
| 26 | |
Bin Meng | fc7f57f | 2019-08-29 02:53:05 -0700 | [diff] [blame] | 27 | u64 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 Meng | 38502eb | 2019-08-29 02:53:04 -0700 | [diff] [blame] | 41 | int dram_init(void) |
| 42 | { |
| 43 | gd->ram_size = qemu_get_low_memory_size(); |
Bin Meng | fc7f57f | 2019-08-29 02:53:05 -0700 | [diff] [blame] | 44 | gd->ram_size += qemu_get_high_memory_size(); |
Bin Meng | 2229c4c | 2015-05-07 21:34:08 +0800 | [diff] [blame] | 45 | post_code(POST_DRAM); |
| 46 | |
| 47 | return 0; |
| 48 | } |
| 49 | |
Simon Glass | 2f949c3 | 2017-03-31 08:40:32 -0600 | [diff] [blame] | 50 | int dram_init_banksize(void) |
Bin Meng | 2229c4c | 2015-05-07 21:34:08 +0800 | [diff] [blame] | 51 | { |
Bin Meng | fc7f57f | 2019-08-29 02:53:05 -0700 | [diff] [blame] | 52 | u64 high_mem_size; |
| 53 | |
Bin Meng | 2229c4c | 2015-05-07 21:34:08 +0800 | [diff] [blame] | 54 | gd->bd->bi_dram[0].start = 0; |
Bin Meng | fc7f57f | 2019-08-29 02:53:05 -0700 | [diff] [blame] | 55 | 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 Glass | 2f949c3 | 2017-03-31 08:40:32 -0600 | [diff] [blame] | 62 | |
| 63 | return 0; |
Bin Meng | 2229c4c | 2015-05-07 21:34:08 +0800 | [diff] [blame] | 64 | } |
| 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ár | 4f4f583 | 2022-09-09 17:32:40 +0200 | [diff] [blame] | 74 | phys_size_t board_get_usable_ram_top(phys_size_t total_size) |
Bin Meng | 2229c4c | 2015-05-07 21:34:08 +0800 | [diff] [blame] | 75 | { |
Bin Meng | fc7f57f | 2019-08-29 02:53:05 -0700 | [diff] [blame] | 76 | return qemu_get_low_memory_size(); |
Bin Meng | 2229c4c | 2015-05-07 21:34:08 +0800 | [diff] [blame] | 77 | } |