285c60c7136d28c339cf2057583afad476f4e6a4
[openwrt.git] / target / linux / brcm47xx / patches-3.6 / 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;
16         struct cpuinfo_mips *c = &current_cpu_data;
17  
18         /* Figure out memory size by finding aliases.
19 @@ -77,15 +79,15 @@ 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 +       max = off | ((128 << 20) - 1);
26         for (mem = (1 << 20); mem < (128 << 20); mem += (1 << 20)) {
27 -               if (((unsigned long)(prom_init) + mem) > max) {
28 +               if ((off + mem) > max) {
29                         mem = (128 << 20);
30                         printk(KERN_DEBUG "assume 128MB RAM\n");
31                         break;
32                 }
33 -               if (*(unsigned long *)((unsigned long)(prom_init) + mem) ==
34 -                   *(unsigned long *)(prom_init))
35 +               if (!memcmp(prom_init, prom_init + mem, 32))
36                         break;
37         }
38