1
2
3
4
5
6
7
8
9
10
11
12
13
14#include <linux/init.h>
15#include <linux/bootmem.h>
16#include <linux/string.h>
17
18#include <asm/bootinfo.h>
19#include <asm/sections.h>
20#include <asm/fw/fw.h>
21
22static fw_memblock_t mdesc[FW_MAX_MEMBLOCKS];
23
24
25unsigned long physical_memsize = 0L;
26
27fw_memblock_t * __init fw_getmdesc(void)
28{
29 char *memsize_str, *ptr;
30 unsigned int memsize;
31 static char cmdline[COMMAND_LINE_SIZE] __initdata;
32 long val;
33 int tmp;
34
35
36 memsize_str = fw_getenv("memsize");
37 if (!memsize_str) {
38 pr_warn("memsize not set in YAMON, set to default (32Mb)\n");
39 physical_memsize = 0x02000000;
40 } else {
41 tmp = kstrtol(memsize_str, 0, &val);
42 physical_memsize = (unsigned long)val;
43 }
44
45#ifdef CONFIG_CPU_BIG_ENDIAN
46
47
48 physical_memsize -= PAGE_SIZE;
49#endif
50
51
52
53 strcpy(cmdline, arcs_cmdline);
54 ptr = strstr(cmdline, "memsize=");
55 if (ptr && (ptr != cmdline) && (*(ptr - 1) != ' '))
56 ptr = strstr(ptr, " memsize=");
57
58 if (ptr)
59 memsize = memparse(ptr + 8, &ptr);
60 else
61 memsize = physical_memsize;
62
63 memset(mdesc, 0, sizeof(mdesc));
64
65 mdesc[0].type = fw_dontuse;
66 mdesc[0].base = 0x00000000;
67 mdesc[0].size = 0x00001000;
68
69 mdesc[1].type = fw_code;
70 mdesc[1].base = 0x00001000;
71 mdesc[1].size = 0x000ef000;
72
73
74
75
76
77
78
79
80 mdesc[2].type = fw_dontuse;
81 mdesc[2].base = 0x000f0000;
82 mdesc[2].size = 0x00010000;
83
84 mdesc[3].type = fw_dontuse;
85 mdesc[3].base = 0x00100000;
86 mdesc[3].size = CPHYSADDR(PFN_ALIGN((unsigned long)&_end)) -
87 mdesc[3].base;
88
89 mdesc[4].type = fw_free;
90 mdesc[4].base = CPHYSADDR(PFN_ALIGN(&_end));
91 mdesc[4].size = memsize - mdesc[4].base;
92
93 return &mdesc[0];
94}
95
96static int __init fw_memtype_classify(unsigned int type)
97{
98 switch (type) {
99 case fw_free:
100 return BOOT_MEM_RAM;
101 case fw_code:
102 return BOOT_MEM_ROM_DATA;
103 default:
104 return BOOT_MEM_RESERVED;
105 }
106}
107
108void __init fw_meminit(void)
109{
110 fw_memblock_t *p;
111
112 p = fw_getmdesc();
113
114 while (p->size) {
115 long type;
116 unsigned long base, size;
117
118 type = fw_memtype_classify(p->type);
119 base = p->base;
120 size = p->size;
121
122 add_memory_region(base, size, type);
123 p++;
124 }
125}
126
127void __init prom_free_prom_memory(void)
128{
129 unsigned long addr;
130 int i;
131
132 for (i = 0; i < boot_mem_map.nr_map; i++) {
133 if (boot_mem_map.map[i].type != BOOT_MEM_ROM_DATA)
134 continue;
135
136 addr = boot_mem_map.map[i].addr;
137 free_init_pages("YAMON memory",
138 addr, addr + boot_mem_map.map[i].size);
139 }
140}
141