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(void)
29 char *memsize_str, *ptr;
31 static char cmdline[COMMAND_LINE_SIZE] __initdata;
35 /* otherwise look in the environment */
36 memsize_str = fw_getenv("memsize");
38 pr_warn("memsize not set in YAMON, set to default (32Mb)\n");
39 physical_memsize = 0x02000000;
41 tmp = kstrtol(memsize_str, 0, &val);
42 physical_memsize = (unsigned long)val;
45 #ifdef CONFIG_CPU_BIG_ENDIAN
46 /* SOC-it swaps, or perhaps doesn't swap, when DMA'ing the last
47 word of physical memory */
48 physical_memsize -= PAGE_SIZE;
51 /* Check the command line for a memsize directive that overrides
52 the physical/default amount */
53 strcpy(cmdline, arcs_cmdline);
54 ptr = strstr(cmdline, "memsize=");
55 if (ptr && (ptr != cmdline) && (*(ptr - 1) != ' '))
56 ptr = strstr(ptr, " memsize=");
59 memsize = memparse(ptr + 8, &ptr);
61 memsize = physical_memsize;
63 memset(mdesc, 0, sizeof(mdesc));
65 mdesc[0].type = fw_dontuse;
66 mdesc[0].base = 0x00000000;
67 mdesc[0].size = 0x00001000;
69 mdesc[1].type = fw_code;
70 mdesc[1].base = 0x00001000;
71 mdesc[1].size = 0x000ef000;
74 * The area 0x000f0000-0x000fffff is allocated for BIOS memory by the
75 * south bridge and PCI access always forwarded to the ISA Bus and
76 * BIOSCS# is always generated.
77 * This mean that this area can't be used as DMA memory for PCI
80 mdesc[2].type = fw_dontuse;
81 mdesc[2].base = 0x000f0000;
82 mdesc[2].size = 0x00010000;
84 mdesc[3].type = fw_dontuse;
85 mdesc[3].base = 0x00100000;
86 mdesc[3].size = CPHYSADDR(PFN_ALIGN((unsigned long)&_end)) -
89 mdesc[4].type = fw_free;
90 mdesc[4].base = CPHYSADDR(PFN_ALIGN(&_end));
91 mdesc[4].size = memsize - mdesc[4].base;
96 static int __init fw_memtype_classify(unsigned int type)
102 return BOOT_MEM_ROM_DATA;
104 return BOOT_MEM_RESERVED;
108 void __init fw_meminit(void)
116 unsigned long base, size;
118 type = fw_memtype_classify(p->type);
122 add_memory_region(base, size, type);
127 void __init prom_free_prom_memory(void)
132 for (i = 0; i < boot_mem_map.nr_map; i++) {
133 if (boot_mem_map.map[i].type != BOOT_MEM_ROM_DATA)
136 addr = boot_mem_map.map[i].addr;
137 free_init_pages("YAMON memory",
138 addr, addr + boot_mem_map.map[i].size);