Skip to content

Commit 139c949

Browse files
981213tsbogend
authored andcommitted
MIPS: ralink: mt7621: add memory detection support
mt7621 has the following memory map: 0x0-0x1c000000: lower 448m memory 0x1c000000-0x2000000: peripheral registers 0x20000000-0x2400000: higher 64m memory detect_memory_region in arch/mips/kernel/setup.c only adds the first memory region and isn't suitable for 512m memory detection because it may accidentally read the memory area for peripheral registers. This commit adds memory detection capability for mt7621: 1. Add the highmem area when 512m is detected. 2. Guard memcmp from accessing peripheral registers: This only happens when a user decided to change kernel load address to 256m or higher address. Since this is a quite unusual case, we just skip 512m testing and return 256m as memory size. Signed-off-by: Chuanhong Guo <[email protected]> [Minor commit message reword, make mt7621_memory_detect static] Signed-off-by: Ilya Lipnitskiy <[email protected]> Signed-off-by: Thomas Bogendoerfer <[email protected]>
1 parent 8eb6eb4 commit 139c949

File tree

4 files changed

+32
-7
lines changed

4 files changed

+32
-7
lines changed

arch/mips/include/asm/mach-ralink/mt7621.h

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,10 @@
2424
#define CHIP_REV_VER_SHIFT 8
2525
#define CHIP_REV_ECO_MASK 0xf
2626

27-
#define MT7621_DRAM_BASE 0x0
28-
#define MT7621_DDR2_SIZE_MIN 32
29-
#define MT7621_DDR2_SIZE_MAX 256
27+
#define MT7621_LOWMEM_BASE 0x0
28+
#define MT7621_LOWMEM_MAX_SIZE 0x1C000000
29+
#define MT7621_HIGHMEM_BASE 0x20000000
30+
#define MT7621_HIGHMEM_SIZE 0x4000000
3031

3132
#define MT7621_CHIP_NAME0 0x3637544D
3233
#define MT7621_CHIP_NAME1 0x20203132

arch/mips/ralink/common.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ struct ralink_soc_info {
1717
unsigned long mem_size;
1818
unsigned long mem_size_min;
1919
unsigned long mem_size_max;
20+
void (*mem_detect)(void);
2021
};
2122
extern struct ralink_soc_info soc_info;
2223

arch/mips/ralink/mt7621.c

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,9 @@
99
#include <linux/init.h>
1010
#include <linux/slab.h>
1111
#include <linux/sys_soc.h>
12+
#include <linux/memblock.h>
1213

14+
#include <asm/bootinfo.h>
1315
#include <asm/mipsregs.h>
1416
#include <asm/smp-ops.h>
1517
#include <asm/mips-cps.h>
@@ -49,6 +51,8 @@
4951
#define MT7621_GPIO_MODE_SDHCI_SHIFT 18
5052
#define MT7621_GPIO_MODE_SDHCI_GPIO 1
5153

54+
static void *detect_magic __initdata = detect_memory_region;
55+
5256
static struct rt2880_pmx_func uart1_grp[] = { FUNC("uart1", 0, 1, 2) };
5357
static struct rt2880_pmx_func i2c_grp[] = { FUNC("i2c", 0, 3, 2) };
5458
static struct rt2880_pmx_func uart3_grp[] = {
@@ -110,6 +114,26 @@ phys_addr_t mips_cpc_default_phys_base(void)
110114
panic("Cannot detect cpc address");
111115
}
112116

117+
static void __init mt7621_memory_detect(void)
118+
{
119+
void *dm = &detect_magic;
120+
phys_addr_t size;
121+
122+
for (size = 32 * SZ_1M; size < 256 * SZ_1M; size <<= 1) {
123+
if (!__builtin_memcmp(dm, dm + size, sizeof(detect_magic)))
124+
break;
125+
}
126+
127+
if ((size == 256 * SZ_1M) &&
128+
(CPHYSADDR(dm + size) < MT7621_LOWMEM_MAX_SIZE) &&
129+
__builtin_memcmp(dm, dm + size, sizeof(detect_magic))) {
130+
memblock_add(MT7621_LOWMEM_BASE, MT7621_LOWMEM_MAX_SIZE);
131+
memblock_add(MT7621_HIGHMEM_BASE, MT7621_HIGHMEM_SIZE);
132+
} else {
133+
memblock_add(MT7621_LOWMEM_BASE, size);
134+
}
135+
}
136+
113137
void __init ralink_of_remap(void)
114138
{
115139
rt_sysc_membase = plat_of_remap_node("mtk,mt7621-sysc");
@@ -194,10 +218,7 @@ void __init prom_soc_init(struct ralink_soc_info *soc_info)
194218
(rev >> CHIP_REV_VER_SHIFT) & CHIP_REV_VER_MASK,
195219
(rev & CHIP_REV_ECO_MASK));
196220

197-
soc_info->mem_size_min = MT7621_DDR2_SIZE_MIN;
198-
soc_info->mem_size_max = MT7621_DDR2_SIZE_MAX;
199-
soc_info->mem_base = MT7621_DRAM_BASE;
200-
221+
soc_info->mem_detect = mt7621_memory_detect;
201222
rt2880_pinmux_data = mt7621_pinmux_data;
202223

203224
soc_dev_init(soc_info, rev);

arch/mips/ralink/of.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,8 @@ void __init plat_mem_setup(void)
7878
of_scan_flat_dt(early_init_dt_find_memory, NULL);
7979
if (memory_dtb)
8080
of_scan_flat_dt(early_init_dt_scan_memory, NULL);
81+
else if (soc_info.mem_detect)
82+
soc_info.mem_detect();
8183
else if (soc_info.mem_size)
8284
memblock_add(soc_info.mem_base, soc_info.mem_size * SZ_1M);
8385
else

0 commit comments

Comments
 (0)