548178c29e44c089bb9c064d20642ec240f194d8
[openwrt/staging/mkresin.git] / target / linux / brcm47xx / patches-3.3 / 192-MIPS-BCM47XX-improve-memory-size-detection.patch
1 --- a/arch/mips/bcm47xx/prom.c
2 +++ b/arch/mips/bcm47xx/prom.c
3 @@ -1,6 +1,7 @@
4 /*
5 * Copyright (C) 2004 Florian Schirmer <jolt@tuxbox.org>
6 * Copyright (C) 2007 Aurelien Jarno <aurelien@aurel32.net>
7 + * Copyright (C) 2010-2012 Hauke Mehrtens <hauke@hauke-m.de>
8 *
9 * This program is free software; you can redistribute it and/or modify it
10 * under the terms of the GNU General Public License as published by the
11 @@ -60,6 +61,7 @@ static __init void prom_init_mem(void)
12 {
13 unsigned long mem;
14 unsigned long max;
15 + unsigned long off, data, off1, data1;
16 struct cpuinfo_mips *c = &current_cpu_data;
17
18 /* Figure out memory size by finding aliases.
19 @@ -77,15 +79,19 @@ static __init void prom_init_mem(void)
20 * max contains the biggest possible address supported by the platform.
21 * If the method wants to try something above we assume 128MB ram.
22 */
23 - max = ((unsigned long)(prom_init) | ((128 << 20) - 1));
24 + off = (unsigned long)prom_init;
25 + data = *(unsigned long *)prom_init;
26 + off1 = off + 4;
27 + data1 = *(unsigned long *)off1;
28 + max = off | ((128 << 20) - 1);
29 for (mem = (1 << 20); mem < (128 << 20); mem += (1 << 20)) {
30 - if (((unsigned long)(prom_init) + mem) > max) {
31 + if ((off + mem) > max) {
32 mem = (128 << 20);
33 printk(KERN_DEBUG "assume 128MB RAM\n");
34 break;
35 }
36 - if (*(unsigned long *)((unsigned long)(prom_init) + mem) ==
37 - *(unsigned long *)(prom_init))
38 + if ((*(unsigned long *)(off + mem) == data) &&
39 + (*(unsigned long *)(off1 + mem) == data1))
40 break;
41 }
42