xref: /openbmc/linux/arch/mips/loongson2ef/common/mem.c (revision 55fd7e02)
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 	add_memory_region(0x0, (memsize << 20), BOOT_MEM_RAM);
21 
22 	add_memory_region(memsize << 20, LOONGSON_PCI_MEM_START - (memsize <<
23 				20), BOOT_MEM_RESERVED);
24 
25 #ifdef CONFIG_CPU_SUPPORTS_ADDRWINCFG
26 	{
27 		int bit;
28 
29 		bit = fls(memsize + highmemsize);
30 		if (bit != ffs(memsize + highmemsize))
31 			bit += 20;
32 		else
33 			bit = bit + 20 - 1;
34 
35 		/* set cpu window3 to map CPU to DDR: 2G -> 2G */
36 		LOONGSON_ADDRWIN_CPUTODDR(ADDRWIN_WIN3, 0x80000000ul,
37 					  0x80000000ul, (1 << bit));
38 		mmiowb();
39 	}
40 #endif /* !CONFIG_CPU_SUPPORTS_ADDRWINCFG */
41 
42 #ifdef CONFIG_64BIT
43 	if (highmemsize > 0)
44 		add_memory_region(LOONGSON_HIGHMEM_START,
45 				  highmemsize << 20, BOOT_MEM_RAM);
46 
47 	add_memory_region(LOONGSON_PCI_MEM_END + 1, LOONGSON_HIGHMEM_START -
48 			  LOONGSON_PCI_MEM_END - 1, BOOT_MEM_RESERVED);
49 
50 #endif /* !CONFIG_64BIT */
51 }
52 
53 /* override of arch/mips/mm/cache.c: __uncached_access */
54 int __uncached_access(struct file *file, unsigned long addr)
55 {
56 	if (file->f_flags & O_DSYNC)
57 		return 1;
58 
59 	return addr >= __pa(high_memory) ||
60 		((addr >= LOONGSON_MMIO_MEM_START) &&
61 		 (addr < LOONGSON_MMIO_MEM_END));
62 }
63