1 // SPDX-License-Identifier: GPL-2.0+ 2 /* 3 * Copyright (C) 2015, Bin Meng <bmeng.cn@gmail.com> 4 */ 5 6 #include <common.h> 7 #include <init.h> 8 #include <asm/post.h> 9 #include <asm/arch/qemu.h> 10 11 DECLARE_GLOBAL_DATA_PTR; 12 qemu_get_low_memory_size(void)13u32 qemu_get_low_memory_size(void) 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 23 return ram * 1024; 24 } 25 qemu_get_high_memory_size(void)26u64 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 dram_init(void)40int dram_init(void) 41 { 42 gd->ram_size = qemu_get_low_memory_size(); 43 gd->ram_size += qemu_get_high_memory_size(); 44 post_code(POST_DRAM); 45 46 return 0; 47 } 48 dram_init_banksize(void)49int dram_init_banksize(void) 50 { 51 u64 high_mem_size; 52 53 gd->bd->bi_dram[0].start = 0; 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 } 61 62 return 0; 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 */ board_get_usable_ram_top(ulong total_size)73ulong board_get_usable_ram_top(ulong total_size) 74 { 75 return qemu_get_low_memory_size(); 76 } 77