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 * Copyright (C) 2012 MIPS Technologies, Inc. All rights reserved.
8 #include <linux/bootmem.h>
10 #include <asm/bootinfo.h>
11 #include <asm/sections.h>
12 #include <asm/mips-boards/prom.h>
20 static struct prom_pmemblock mdesc[PROM_MAX_PMEMBLOCKS];
22 /* determined physical memory size, not overridden by command line args */
23 unsigned long physical_memsize = 0L;
25 struct prom_pmemblock * __init prom_getmdesc(void)
27 char *memsize_str, *ptr;
29 static char cmdline[COMMAND_LINE_SIZE] __initdata;
33 /* otherwise look in the environment */
34 memsize_str = prom_getenv("memsize");
36 pr_warn("memsize not set in boot prom, set to default 32Mb\n");
37 physical_memsize = 0x02000000;
39 tmp = kstrtol(memsize_str, 0, &val);
40 physical_memsize = (unsigned long)val;
43 #ifdef CONFIG_CPU_BIG_ENDIAN
44 /* SOC-it swaps, or perhaps doesn't swap, when DMA'ing the last
45 word of physical memory */
46 physical_memsize -= PAGE_SIZE;
49 /* Check the command line for a memsize directive that overrides
50 the physical/default amount */
51 strcpy(cmdline, arcs_cmdline);
52 ptr = strstr(cmdline, "memsize=");
53 if (ptr && (ptr != cmdline) && (*(ptr - 1) != ' '))
54 ptr = strstr(ptr, " memsize=");
57 memsize = memparse(ptr + 8, &ptr);
59 memsize = physical_memsize;
61 memset(mdesc, 0, sizeof(mdesc));
63 mdesc[0].type = yamon_dontuse;
64 mdesc[0].base = 0x00000000;
65 mdesc[0].size = 0x00001000;
67 mdesc[1].type = yamon_prom;
68 mdesc[1].base = 0x00001000;
69 mdesc[1].size = 0x000ef000;
72 * The area 0x000f0000-0x000fffff is allocated for BIOS memory by the
73 * south bridge and PCI access always forwarded to the ISA Bus and
74 * BIOSCS# is always generated.
75 * This mean that this area can't be used as DMA memory for PCI
78 mdesc[2].type = yamon_dontuse;
79 mdesc[2].base = 0x000f0000;
80 mdesc[2].size = 0x00010000;
82 mdesc[3].type = yamon_dontuse;
83 mdesc[3].base = 0x00100000;
84 mdesc[3].size = CPHYSADDR(PFN_ALIGN((unsigned long)&_end)) -
87 mdesc[4].type = yamon_free;
88 mdesc[4].base = CPHYSADDR(PFN_ALIGN(&_end));
89 mdesc[4].size = memsize - mdesc[4].base;
94 static int __init prom_memtype_classify(unsigned int type)
100 return BOOT_MEM_ROM_DATA;
102 return BOOT_MEM_RESERVED;
106 void __init prom_meminit(void)
108 struct prom_pmemblock *p;
114 unsigned long base, size;
116 type = prom_memtype_classify(p->type);
120 add_memory_region(base, size, type);
125 void __init prom_free_prom_memory(void)
130 for (i = 0; i < boot_mem_map.nr_map; i++) {
131 if (boot_mem_map.map[i].type != BOOT_MEM_ROM_DATA)
134 addr = boot_mem_map.map[i].addr;
135 free_init_pages("prom memory",
136 addr, addr + boot_mem_map.map[i].size);