xref: /openbmc/linux/arch/mips/loongson2ef/common/mem.c (revision 2a598d0b)
1 // SPDX-License-Identifier: GPL-2.0-or-later
2 /*
3  */
4 #include <linux/fs.h>
5 #include <linux/fcntl.h>
6 #include <linux/memblock.h>
7 #include <linux/mm.h>
8 
9 #include <asm/bootinfo.h>
10 
11 #include <loongson.h>
12 #include <mem.h>
13 #include <pci.h>
14 
15 
16 u32 memsize, highmemsize;
17 
18 void __init prom_init_memory(void)
19 {
20 	memblock_add(0x0, (memsize << 20));
21 
22 #ifdef CONFIG_CPU_SUPPORTS_ADDRWINCFG
23 	{
24 		int bit;
25 
26 		bit = fls(memsize + highmemsize);
27 		if (bit != ffs(memsize + highmemsize))
28 			bit += 20;
29 		else
30 			bit = bit + 20 - 1;
31 
32 		/* set cpu window3 to map CPU to DDR: 2G -> 2G */
33 		LOONGSON_ADDRWIN_CPUTODDR(ADDRWIN_WIN3, 0x80000000ul,
34 					  0x80000000ul, (1 << bit));
35 		mmiowb();
36 	}
37 #endif /* !CONFIG_CPU_SUPPORTS_ADDRWINCFG */
38 
39 #ifdef CONFIG_64BIT
40 	if (highmemsize > 0)
41 		memblock_add(LOONGSON_HIGHMEM_START, highmemsize << 20);
42 #endif /* !CONFIG_64BIT */
43 }
44