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>
20 #include <asm/sections.h>
21 #include <asm/fw/fw.h>
23 static fw_memblock_t mdesc
[FW_MAX_MEMBLOCKS
];
25 /* determined physical memory size, not overridden by command line args */
26 unsigned long physical_memsize
= 0L;
28 fw_memblock_t
* __init
fw_getmdesc(int eva
)
30 char *memsize_str
, *ememsize_str
= NULL
, *ptr
;
31 unsigned long memsize
= 0, ememsize
= 0;
32 static char cmdline
[COMMAND_LINE_SIZE
] __initdata
;
35 /* otherwise look in the environment */
37 memsize_str
= fw_getenv("memsize");
39 tmp
= kstrtol(memsize_str
, 0, &memsize
);
41 /* Look for ememsize for EVA */
42 ememsize_str
= fw_getenv("ememsize");
44 tmp
= kstrtol(ememsize_str
, 0, &ememsize
);
46 if (!memsize
&& !ememsize
) {
47 pr_warn("memsize not set in YAMON, set to default (32Mb)\n");
48 physical_memsize
= 0x02000000;
50 /* If ememsize is set, then set physical_memsize to that */
51 physical_memsize
= ememsize
? : memsize
;
54 #ifdef CONFIG_CPU_BIG_ENDIAN
55 /* SOC-it swaps, or perhaps doesn't swap, when DMA'ing the last
56 word of physical memory */
57 physical_memsize
-= PAGE_SIZE
;
60 /* Check the command line for a memsize directive that overrides
61 the physical/default amount */
62 strcpy(cmdline
, arcs_cmdline
);
63 ptr
= strstr(cmdline
, "memsize=");
64 if (ptr
&& (ptr
!= cmdline
) && (*(ptr
- 1) != ' '))
65 ptr
= strstr(ptr
, " memsize=");
66 /* And now look for ememsize */
68 ptr
= strstr(cmdline
, "ememsize=");
69 if (ptr
&& (ptr
!= cmdline
) && (*(ptr
- 1) != ' '))
70 ptr
= strstr(ptr
, " ememsize=");
74 memsize
= memparse(ptr
+ 8 + (eva
? 1 : 0), &ptr
);
76 memsize
= physical_memsize
;
78 /* Last 64K for HIGHMEM arithmetics */
79 if (memsize
> 0x7fff0000)
82 memset(mdesc
, 0, sizeof(mdesc
));
84 mdesc
[0].type
= fw_dontuse
;
85 mdesc
[0].base
= PHYS_OFFSET
;
86 mdesc
[0].size
= 0x00001000;
88 mdesc
[1].type
= fw_code
;
89 mdesc
[1].base
= mdesc
[0].base
+ 0x00001000UL
;
90 mdesc
[1].size
= 0x000ef000;
93 * The area 0x000f0000-0x000fffff is allocated for BIOS memory by the
94 * south bridge and PCI access always forwarded to the ISA Bus and
95 * BIOSCS# is always generated.
96 * This mean that this area can't be used as DMA memory for PCI
99 mdesc
[2].type
= fw_dontuse
;
100 mdesc
[2].base
= mdesc
[0].base
+ 0x000f0000UL
;
101 mdesc
[2].size
= 0x00010000;
103 mdesc
[3].type
= fw_dontuse
;
104 mdesc
[3].base
= mdesc
[0].base
+ 0x00100000UL
;
105 mdesc
[3].size
= CPHYSADDR(PFN_ALIGN((unsigned long)&_end
)) -
108 mdesc
[4].type
= fw_free
;
109 mdesc
[4].base
= mdesc
[0].base
+ CPHYSADDR(PFN_ALIGN(&_end
));
110 mdesc
[4].size
= memsize
- CPHYSADDR(mdesc
[4].base
);
115 static void free_init_pages_eva_malta(void *begin
, void *end
)
117 free_init_pages("unused kernel", __pa_symbol((unsigned long *)begin
),
118 __pa_symbol((unsigned long *)end
));
121 static int __init
fw_memtype_classify(unsigned int type
)
127 return BOOT_MEM_ROM_DATA
;
129 return BOOT_MEM_RESERVED
;
133 void __init
fw_meminit(void)
137 p
= fw_getmdesc(config_enabled(CONFIG_EVA
));
138 free_init_pages_eva
= (config_enabled(CONFIG_EVA
) ?
139 free_init_pages_eva_malta
: NULL
);
143 unsigned long base
, size
;
145 type
= fw_memtype_classify(p
->type
);
149 add_memory_region(base
, size
, type
);
154 void __init
prom_free_prom_memory(void)
159 for (i
= 0; i
< boot_mem_map
.nr_map
; i
++) {
160 if (boot_mem_map
.map
[i
].type
!= BOOT_MEM_ROM_DATA
)
163 addr
= boot_mem_map
.map
[i
].addr
;
164 free_init_pages("YAMON memory",
165 addr
, addr
+ boot_mem_map
.map
[i
].size
);
169 unsigned platform_maar_init(unsigned num_pairs
)
171 phys_addr_t mem_end
= (physical_memsize
& ~0xffffull
) - 1;
172 struct maar_config cfg
[] = {
173 /* DRAM preceding I/O */
174 { 0x00000000, 0x0fffffff, MIPS_MAAR_S
},
176 /* DRAM following I/O */
177 { 0x20000000, mem_end
, MIPS_MAAR_S
},
179 /* DRAM alias in upper half of physical */
180 { 0x80000000, 0x80000000 + mem_end
, MIPS_MAAR_S
},
182 unsigned i
, num_cfg
= ARRAY_SIZE(cfg
);
184 /* If DRAM fits before I/O, drop the region following it */
185 if (physical_memsize
<= 0x10000000) {
187 for (i
= 1; i
< num_cfg
; i
++)
191 return maar_config(cfg
, num_cfg
, num_pairs
);