ramips: make rt3883 usb work properly
[openwrt.git] / target / linux / ramips / patches-3.9 / 0121-MIPS-add-detect_memory_region.patch
1 From 2ccca2ac0b54eb21890412c888cf5a5bda656bba Mon Sep 17 00:00:00 2001
2 From: John Crispin <blogic@openwrt.org>
3 Date: Sat, 13 Apr 2013 13:15:47 +0200
4 Subject: [PATCH 121/164] MIPS: add detect_memory_region()
5
6 Add a generic way of detecting the available RAM. This function is based on the
7 implementation already used by ath79.
8
9 Signed-off-by: John Crispin <blogic@openwrt.org>
10 Patchwork: http://patchwork.linux-mips.org/patch/5178/
11 ---
12  arch/mips/include/asm/bootinfo.h |    1 +
13  arch/mips/kernel/setup.c         |   20 ++++++++++++++++++++
14  2 files changed, 21 insertions(+)
15
16 diff --git a/arch/mips/include/asm/bootinfo.h b/arch/mips/include/asm/bootinfo.h
17 index b71dd5b..4d2cdea 100644
18 --- a/arch/mips/include/asm/bootinfo.h
19 +++ b/arch/mips/include/asm/bootinfo.h
20 @@ -104,6 +104,7 @@ struct boot_mem_map {
21  extern struct boot_mem_map boot_mem_map;
22  
23  extern void add_memory_region(phys_t start, phys_t size, long type);
24 +extern void detect_memory_region(phys_t start, phys_t sz_min,  phys_t sz_max);
25  
26  extern void prom_init(void);
27  extern void prom_free_prom_memory(void);
28 diff --git a/arch/mips/kernel/setup.c b/arch/mips/kernel/setup.c
29 index 4c774d5..7325793 100644
30 --- a/arch/mips/kernel/setup.c
31 +++ b/arch/mips/kernel/setup.c
32 @@ -23,6 +23,7 @@
33  #include <linux/pfn.h>
34  #include <linux/debugfs.h>
35  #include <linux/kexec.h>
36 +#include <linux/sizes.h>
37  
38  #include <asm/addrspace.h>
39  #include <asm/bootinfo.h>
40 @@ -122,6 +123,25 @@ void __init add_memory_region(phys_t start, phys_t size, long type)
41         boot_mem_map.nr_map++;
42  }
43  
44 +void __init detect_memory_region(phys_t start, phys_t sz_min, phys_t sz_max)
45 +{
46 +       phys_t size;
47 +
48 +       for (size = sz_min; size < sz_max; size <<= 1) {
49 +               if (!memcmp(detect_memory_region,
50 +                               detect_memory_region + size, 1024))
51 +                       break;
52 +       }
53 +
54 +       pr_debug("Memory: %lluMB of RAM detected at 0x%llx (min: %lluMB, max: %lluMB)\n",
55 +               ((unsigned long long) size) / SZ_1M,
56 +               (unsigned long long) start,
57 +               ((unsigned long long) sz_min) / SZ_1M,
58 +               ((unsigned long long) sz_max) / SZ_1M);
59 +
60 +       add_memory_region(start, size, BOOT_MEM_RAM);
61 +}
62 +
63  static void __init print_memory_map(void)
64  {
65         int i;
66 -- 
67 1.7.10.4
68