malta-memory.c 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. /*
  2. * This file is subject to the terms and conditions of the GNU General Public
  3. * License. See the file "COPYING" in the main directory of this archive
  4. * for more details.
  5. *
  6. * PROM library functions for acquiring/using memory descriptors given to
  7. * us from the YAMON.
  8. *
  9. * Copyright (C) 1999,2000,2012 MIPS Technologies, Inc.
  10. * All rights reserved.
  11. * Authors: Carsten Langgaard <carstenl@mips.com>
  12. * Steven J. Hill <sjhill@mips.com>
  13. */
  14. #include <linux/init.h>
  15. #include <linux/bootmem.h>
  16. #include <linux/string.h>
  17. #include <asm/bootinfo.h>
  18. #include <asm/sections.h>
  19. #include <asm/fw/fw.h>
  20. static fw_memblock_t mdesc[FW_MAX_MEMBLOCKS];
  21. /* determined physical memory size, not overridden by command line args */
  22. unsigned long physical_memsize = 0L;
  23. fw_memblock_t * __init fw_getmdesc(void)
  24. {
  25. char *memsize_str, *ptr;
  26. unsigned int memsize;
  27. static char cmdline[COMMAND_LINE_SIZE] __initdata;
  28. long val;
  29. int tmp;
  30. /* otherwise look in the environment */
  31. memsize_str = fw_getenv("memsize");
  32. if (!memsize_str) {
  33. pr_warn("memsize not set in YAMON, set to default (32Mb)\n");
  34. physical_memsize = 0x02000000;
  35. } else {
  36. tmp = kstrtol(memsize_str, 0, &val);
  37. physical_memsize = (unsigned long)val;
  38. }
  39. #ifdef CONFIG_CPU_BIG_ENDIAN
  40. /* SOC-it swaps, or perhaps doesn't swap, when DMA'ing the last
  41. word of physical memory */
  42. physical_memsize -= PAGE_SIZE;
  43. #endif
  44. /* Check the command line for a memsize directive that overrides
  45. the physical/default amount */
  46. strcpy(cmdline, arcs_cmdline);
  47. ptr = strstr(cmdline, "memsize=");
  48. if (ptr && (ptr != cmdline) && (*(ptr - 1) != ' '))
  49. ptr = strstr(ptr, " memsize=");
  50. if (ptr)
  51. memsize = memparse(ptr + 8, &ptr);
  52. else
  53. memsize = physical_memsize;
  54. memset(mdesc, 0, sizeof(mdesc));
  55. mdesc[0].type = fw_dontuse;
  56. mdesc[0].base = 0x00000000;
  57. mdesc[0].size = 0x00001000;
  58. mdesc[1].type = fw_code;
  59. mdesc[1].base = 0x00001000;
  60. mdesc[1].size = 0x000ef000;
  61. /*
  62. * The area 0x000f0000-0x000fffff is allocated for BIOS memory by the
  63. * south bridge and PCI access always forwarded to the ISA Bus and
  64. * BIOSCS# is always generated.
  65. * This mean that this area can't be used as DMA memory for PCI
  66. * devices.
  67. */
  68. mdesc[2].type = fw_dontuse;
  69. mdesc[2].base = 0x000f0000;
  70. mdesc[2].size = 0x00010000;
  71. mdesc[3].type = fw_dontuse;
  72. mdesc[3].base = 0x00100000;
  73. mdesc[3].size = CPHYSADDR(PFN_ALIGN((unsigned long)&_end)) -
  74. mdesc[3].base;
  75. mdesc[4].type = fw_free;
  76. mdesc[4].base = CPHYSADDR(PFN_ALIGN(&_end));
  77. mdesc[4].size = memsize - mdesc[4].base;
  78. return &mdesc[0];
  79. }
  80. static int __init fw_memtype_classify(unsigned int type)
  81. {
  82. switch (type) {
  83. case fw_free:
  84. return BOOT_MEM_RAM;
  85. case fw_code:
  86. return BOOT_MEM_ROM_DATA;
  87. default:
  88. return BOOT_MEM_RESERVED;
  89. }
  90. }
  91. void __init fw_meminit(void)
  92. {
  93. fw_memblock_t *p;
  94. p = fw_getmdesc();
  95. while (p->size) {
  96. long type;
  97. unsigned long base, size;
  98. type = fw_memtype_classify(p->type);
  99. base = p->base;
  100. size = p->size;
  101. add_memory_region(base, size, type);
  102. p++;
  103. }
  104. }
  105. void __init prom_free_prom_memory(void)
  106. {
  107. unsigned long addr;
  108. int i;
  109. for (i = 0; i < boot_mem_map.nr_map; i++) {
  110. if (boot_mem_map.map[i].type != BOOT_MEM_ROM_DATA)
  111. continue;
  112. addr = boot_mem_map.map[i].addr;
  113. free_init_pages("YAMON memory",
  114. addr, addr + boot_mem_map.map[i].size);
  115. }
  116. }