diff options
author | John Crispin <blogic@openwrt.org> | 2013-04-13 07:15:47 -0400 |
---|---|---|
committer | Ralf Baechle <ralf@linux-mips.org> | 2013-05-07 19:19:11 -0400 |
commit | 4d9f77d2526840fc2b3d4dcaedfd2f633a6d5426 (patch) | |
tree | 7efbfc22a32c23dc886855b325b88e7356a4f355 /arch | |
parent | 9d50094dfec829a1361e595d5d09dfa0f2fe5057 (diff) |
MIPS: add detect_memory_region()
Add a generic way of detecting the available RAM. This function is based on the
implementation already used by ath79.
Signed-off-by: John Crispin <blogic@openwrt.org>
Patchwork: http://patchwork.linux-mips.org/patch/5178/
Diffstat (limited to 'arch')
-rw-r--r-- | arch/mips/include/asm/bootinfo.h | 1 | ||||
-rw-r--r-- | arch/mips/kernel/setup.c | 22 |
2 files changed, 23 insertions, 0 deletions
diff --git a/arch/mips/include/asm/bootinfo.h b/arch/mips/include/asm/bootinfo.h index b71dd5b16085..4d2cdea5aa37 100644 --- a/arch/mips/include/asm/bootinfo.h +++ b/arch/mips/include/asm/bootinfo.h | |||
@@ -104,6 +104,7 @@ struct boot_mem_map { | |||
104 | extern struct boot_mem_map boot_mem_map; | 104 | extern struct boot_mem_map boot_mem_map; |
105 | 105 | ||
106 | extern void add_memory_region(phys_t start, phys_t size, long type); | 106 | extern void add_memory_region(phys_t start, phys_t size, long type); |
107 | extern void detect_memory_region(phys_t start, phys_t sz_min, phys_t sz_max); | ||
107 | 108 | ||
108 | extern void prom_init(void); | 109 | extern void prom_init(void); |
109 | extern void prom_free_prom_memory(void); | 110 | extern void prom_free_prom_memory(void); |
diff --git a/arch/mips/kernel/setup.c b/arch/mips/kernel/setup.c index 4c774d5d5087..c7f90519e58c 100644 --- a/arch/mips/kernel/setup.c +++ b/arch/mips/kernel/setup.c | |||
@@ -23,6 +23,7 @@ | |||
23 | #include <linux/pfn.h> | 23 | #include <linux/pfn.h> |
24 | #include <linux/debugfs.h> | 24 | #include <linux/debugfs.h> |
25 | #include <linux/kexec.h> | 25 | #include <linux/kexec.h> |
26 | #include <linux/sizes.h> | ||
26 | 27 | ||
27 | #include <asm/addrspace.h> | 28 | #include <asm/addrspace.h> |
28 | #include <asm/bootinfo.h> | 29 | #include <asm/bootinfo.h> |
@@ -77,6 +78,8 @@ EXPORT_SYMBOL(mips_io_port_base); | |||
77 | static struct resource code_resource = { .name = "Kernel code", }; | 78 | static struct resource code_resource = { .name = "Kernel code", }; |
78 | static struct resource data_resource = { .name = "Kernel data", }; | 79 | static struct resource data_resource = { .name = "Kernel data", }; |
79 | 80 | ||
81 | static void *detect_magic __initdata = detect_memory_region; | ||
82 | |||
80 | void __init add_memory_region(phys_t start, phys_t size, long type) | 83 | void __init add_memory_region(phys_t start, phys_t size, long type) |
81 | { | 84 | { |
82 | int x = boot_mem_map.nr_map; | 85 | int x = boot_mem_map.nr_map; |
@@ -122,6 +125,25 @@ void __init add_memory_region(phys_t start, phys_t size, long type) | |||
122 | boot_mem_map.nr_map++; | 125 | boot_mem_map.nr_map++; |
123 | } | 126 | } |
124 | 127 | ||
128 | void __init detect_memory_region(phys_t start, phys_t sz_min, phys_t sz_max) | ||
129 | { | ||
130 | void *dm = &detect_magic; | ||
131 | phys_t size; | ||
132 | |||
133 | for (size = sz_min; size < sz_max; size <<= 1) { | ||
134 | if (!memcmp(dm, dm + size, sizeof(detect_magic))) | ||
135 | break; | ||
136 | } | ||
137 | |||
138 | pr_debug("Memory: %lluMB of RAM detected at 0x%llx (min: %lluMB, max: %lluMB)\n", | ||
139 | ((unsigned long long) size) / SZ_1M, | ||
140 | (unsigned long long) start, | ||
141 | ((unsigned long long) sz_min) / SZ_1M, | ||
142 | ((unsigned long long) sz_max) / SZ_1M); | ||
143 | |||
144 | add_memory_region(start, size, BOOT_MEM_RAM); | ||
145 | } | ||
146 | |||
125 | static void __init print_memory_map(void) | 147 | static void __init print_memory_map(void) |
126 | { | 148 | { |
127 | int i; | 149 | int i; |