package: fix insmod on install
[openwrt/openwrt.git] / target / linux / ramips / patches-3.8 / 0121-MIPS-add-detect_memory_region.patch
1 From 9041c96ab5bd29d85ca95cffa44c755f68ae6bb1 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/137] 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 --- a/arch/mips/include/asm/bootinfo.h
17 +++ b/arch/mips/include/asm/bootinfo.h
18 @@ -104,6 +104,7 @@ struct boot_mem_map {
19 extern struct boot_mem_map boot_mem_map;
20
21 extern void add_memory_region(phys_t start, phys_t size, long type);
22 +extern void detect_memory_region(phys_t start, phys_t sz_min, phys_t sz_max);
23
24 extern void prom_init(void);
25 extern void prom_free_prom_memory(void);
26 --- a/arch/mips/kernel/setup.c
27 +++ b/arch/mips/kernel/setup.c
28 @@ -23,6 +23,7 @@
29 #include <linux/pfn.h>
30 #include <linux/debugfs.h>
31 #include <linux/kexec.h>
32 +#include <linux/sizes.h>
33
34 #include <asm/addrspace.h>
35 #include <asm/bootinfo.h>
36 @@ -122,6 +123,25 @@ void __init add_memory_region(phys_t sta
37 boot_mem_map.nr_map++;
38 }
39
40 +void __init detect_memory_region(phys_t start, phys_t sz_min, phys_t sz_max)
41 +{
42 + phys_t size;
43 +
44 + for (size = sz_min; size < sz_max; size <<= 1) {
45 + if (!memcmp(detect_memory_region,
46 + detect_memory_region + size, 1024))
47 + break;
48 + }
49 +
50 + pr_debug("Memory: %lluMB of RAM detected at 0x%llx (min: %lluMB, max: %lluMB)\n",
51 + ((unsigned long long) size) / SZ_1M,
52 + (unsigned long long) start,
53 + ((unsigned long long) sz_min) / SZ_1M,
54 + ((unsigned long long) sz_max) / SZ_1M);
55 +
56 + add_memory_region(start, size, BOOT_MEM_RAM);
57 +}
58 +
59 static void __init print_memory_map(void)
60 {
61 int i;