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
6 * PROM library functions for acquiring/using memory descriptors given to
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>
14 #include <linux/init.h>
15 #include <linux/bootmem.h>
16 #include <linux/string.h>
18 #include <asm/bootinfo.h>
21 #include <asm/sections.h>
22 #include <asm/fw/fw.h>
24 /* determined physical memory size, not overridden by command line args */
25 unsigned long physical_memsize = 0L;
27 static void free_init_pages_eva_malta(void *begin, void *end)
29 free_init_pages("unused kernel", __pa_symbol((unsigned long *)begin),
30 __pa_symbol((unsigned long *)end));
33 void __init fw_meminit(void)
35 char *memsize_str, *ememsize_str = NULL, *ptr;
36 unsigned long memsize = 0, ememsize = 0;
37 unsigned long kernel_start_phys, kernel_end_phys;
38 static char cmdline[COMMAND_LINE_SIZE] __initdata;
39 bool eva = config_enabled(CONFIG_EVA);
42 free_init_pages_eva = eva ? free_init_pages_eva_malta : NULL;
44 memsize_str = fw_getenv("memsize");
46 tmp = kstrtoul(memsize_str, 0, &memsize);
48 pr_warn("Failed to read the 'memsize' env variable.\n");
51 /* Look for ememsize for EVA */
52 ememsize_str = fw_getenv("ememsize");
54 tmp = kstrtoul(ememsize_str, 0, &ememsize);
56 pr_warn("Failed to read the 'ememsize' env variable.\n");
59 if (!memsize && !ememsize) {
60 pr_warn("memsize not set in YAMON, set to default (32Mb)\n");
61 physical_memsize = 0x02000000;
63 if (memsize > (256 << 20)) { /* memsize should be capped to 256M */
64 pr_warn("Unsupported memsize value (0x%lx) detected! "
65 "Using 0x10000000 (256M) instead\n",
69 /* If ememsize is set, then set physical_memsize to that */
70 physical_memsize = ememsize ? : memsize;
73 #ifdef CONFIG_CPU_BIG_ENDIAN
74 /* SOC-it swaps, or perhaps doesn't swap, when DMA'ing the last
75 word of physical memory */
76 physical_memsize -= PAGE_SIZE;
79 /* Check the command line for a memsize directive that overrides
80 the physical/default amount */
81 strcpy(cmdline, arcs_cmdline);
82 ptr = strstr(cmdline, "memsize=");
83 if (ptr && (ptr != cmdline) && (*(ptr - 1) != ' '))
84 ptr = strstr(ptr, " memsize=");
85 /* And now look for ememsize */
87 ptr = strstr(cmdline, "ememsize=");
88 if (ptr && (ptr != cmdline) && (*(ptr - 1) != ' '))
89 ptr = strstr(ptr, " ememsize=");
93 memsize = memparse(ptr + 8 + (eva ? 1 : 0), &ptr);
95 memsize = physical_memsize;
97 /* Last 64K for HIGHMEM arithmetics */
98 if (memsize > 0x7fff0000)
101 add_memory_region(PHYS_OFFSET, 0x00001000, BOOT_MEM_RESERVED);
104 * YAMON may still be using the region of memory from 0x1000 to 0xfffff
105 * if it has started secondary CPUs.
107 add_memory_region(PHYS_OFFSET + 0x00001000, 0x000ef000,
111 * The area 0x000f0000-0x000fffff is allocated for BIOS memory by the
112 * south bridge and PCI access always forwarded to the ISA Bus and
113 * BIOSCS# is always generated.
114 * This mean that this area can't be used as DMA memory for PCI
117 add_memory_region(PHYS_OFFSET + 0x000f0000, 0x00010000,
121 * Reserve the memory used by kernel code, and allow the rest of RAM to
124 kernel_start_phys = PHYS_OFFSET + 0x00100000;
125 kernel_end_phys = PHYS_OFFSET + CPHYSADDR(PFN_ALIGN(&_end));
126 add_memory_region(kernel_start_phys, kernel_end_phys,
128 add_memory_region(kernel_end_phys, memsize - kernel_end_phys,
132 void __init prom_free_prom_memory(void)
137 for (i = 0; i < boot_mem_map.nr_map; i++) {
138 if (boot_mem_map.map[i].type != BOOT_MEM_ROM_DATA)
141 addr = boot_mem_map.map[i].addr;
142 free_init_pages("YAMON memory",
143 addr, addr + boot_mem_map.map[i].size);
147 phys_addr_t mips_cdmm_phys_base(void)
149 /* This address is "typically unused" */