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>
19 #include <asm/sections.h>
20 #include <asm/fw/fw.h>
22 static fw_memblock_t mdesc[FW_MAX_MEMBLOCKS];
24 /* determined physical memory size, not overridden by command line args */
25 unsigned long physical_memsize = 0L;
27 fw_memblock_t * __init fw_getmdesc(int eva)
29 char *memsize_str, *ememsize_str __maybe_unused = NULL, *ptr;
30 unsigned long memsize = 0, ememsize __maybe_unused = 0;
31 static char cmdline[COMMAND_LINE_SIZE] __initdata;
34 /* otherwise look in the environment */
36 memsize_str = fw_getenv("memsize");
38 tmp = kstrtol(memsize_str, 0, &memsize);
40 /* Look for ememsize for EVA */
41 ememsize_str = fw_getenv("ememsize");
43 tmp = kstrtol(ememsize_str, 0, &ememsize);
45 if (!memsize && !ememsize) {
46 pr_warn("memsize not set in YAMON, set to default (32Mb)\n");
47 physical_memsize = 0x02000000;
49 /* If ememsize is set, then set physical_memsize to that */
50 physical_memsize = ememsize ? : memsize;
53 #ifdef CONFIG_CPU_BIG_ENDIAN
54 /* SOC-it swaps, or perhaps doesn't swap, when DMA'ing the last
55 word of physical memory */
56 physical_memsize -= PAGE_SIZE;
59 /* Check the command line for a memsize directive that overrides
60 the physical/default amount */
61 strcpy(cmdline, arcs_cmdline);
62 ptr = strstr(cmdline, "memsize=");
63 if (ptr && (ptr != cmdline) && (*(ptr - 1) != ' '))
64 ptr = strstr(ptr, " memsize=");
65 /* And now look for ememsize */
67 ptr = strstr(cmdline, "ememsize=");
68 if (ptr && (ptr != cmdline) && (*(ptr - 1) != ' '))
69 ptr = strstr(ptr, " ememsize=");
73 memsize = memparse(ptr + 8 + (eva ? 1 : 0), &ptr);
75 memsize = physical_memsize;
77 /* Last 64K for HIGHMEM arithmetics */
78 if (memsize > 0x7fff0000)
81 memset(mdesc, 0, sizeof(mdesc));
83 mdesc[0].type = fw_dontuse;
84 mdesc[0].base = PHYS_OFFSET;
85 mdesc[0].size = 0x00001000;
87 mdesc[1].type = fw_code;
88 mdesc[1].base = mdesc[0].base + 0x00001000UL;
89 mdesc[1].size = 0x000ef000;
92 * The area 0x000f0000-0x000fffff is allocated for BIOS memory by the
93 * south bridge and PCI access always forwarded to the ISA Bus and
94 * BIOSCS# is always generated.
95 * This mean that this area can't be used as DMA memory for PCI
98 mdesc[2].type = fw_dontuse;
99 mdesc[2].base = mdesc[0].base + 0x000f0000UL;
100 mdesc[2].size = 0x00010000;
102 mdesc[3].type = fw_dontuse;
103 mdesc[3].base = mdesc[0].base + 0x00100000UL;
104 mdesc[3].size = CPHYSADDR(PFN_ALIGN((unsigned long)&_end)) -
107 mdesc[4].type = fw_free;
108 mdesc[4].base = mdesc[0].base + CPHYSADDR(PFN_ALIGN(&_end));
109 mdesc[4].size = memsize - CPHYSADDR(mdesc[4].base);
114 static void free_init_pages_eva_malta(void *begin, void *end)
116 free_init_pages("unused kernel", __pa_symbol((unsigned long *)begin),
117 __pa_symbol((unsigned long *)end));
120 static int __init fw_memtype_classify(unsigned int type)
126 return BOOT_MEM_ROM_DATA;
128 return BOOT_MEM_RESERVED;
132 void __init fw_meminit(void)
136 p = fw_getmdesc(config_enabled(CONFIG_EVA));
137 free_init_pages_eva = (config_enabled(CONFIG_EVA) ?
138 free_init_pages_eva_malta : NULL);
142 unsigned long base, size;
144 type = fw_memtype_classify(p->type);
148 add_memory_region(base, size, type);
153 void __init prom_free_prom_memory(void)
158 for (i = 0; i < boot_mem_map.nr_map; i++) {
159 if (boot_mem_map.map[i].type != BOOT_MEM_ROM_DATA)
162 addr = boot_mem_map.map[i].addr;
163 free_init_pages("YAMON memory",
164 addr, addr + boot_mem_map.map[i].size);