0121-MIPS-add-detect_memory_region.patch 1.8 KB

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