]>
Commit | Line | Data |
---|---|---|
1da177e4 LT |
1 | /* |
2 | * Carsten Langgaard, carstenl@mips.com | |
3 | * Copyright (C) 1999,2000 MIPS Technologies, Inc. All rights reserved. | |
4 | * | |
5 | * This program is free software; you can distribute it and/or modify it | |
6 | * under the terms of the GNU General Public License (Version 2) as | |
7 | * published by the Free Software Foundation. | |
8 | * | |
9 | * This program is distributed in the hope it will be useful, but WITHOUT | |
10 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
11 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
12 | * for more details. | |
13 | * | |
14 | * You should have received a copy of the GNU General Public License along | |
15 | * with this program; if not, write to the Free Software Foundation, Inc., | |
16 | * 59 Temple Place - Suite 330, Boston MA 02111-1307, USA. | |
17 | * | |
18 | * PROM library functions for acquiring/using memory descriptors given to | |
19 | * us from the YAMON. | |
20 | */ | |
21 | #include <linux/config.h> | |
22 | #include <linux/init.h> | |
23 | #include <linux/mm.h> | |
24 | #include <linux/bootmem.h> | |
fde3505c | 25 | #include <linux/pfn.h> |
e01402b1 | 26 | #include <linux/string.h> |
1da177e4 LT |
27 | |
28 | #include <asm/bootinfo.h> | |
29 | #include <asm/page.h> | |
9c1f1257 | 30 | #include <asm/sections.h> |
1da177e4 LT |
31 | |
32 | #include <asm/mips-boards/prom.h> | |
33 | ||
34 | /*#define DEBUG*/ | |
35 | ||
36 | enum yamon_memtypes { | |
37 | yamon_dontuse, | |
38 | yamon_prom, | |
39 | yamon_free, | |
40 | }; | |
41 | struct prom_pmemblock mdesc[PROM_MAX_PMEMBLOCKS]; | |
42 | ||
43 | #ifdef DEBUG | |
44 | static char *mtypes[3] = { | |
45 | "Dont use memory", | |
46 | "YAMON PROM memory", | |
47 | "Free memmory", | |
48 | }; | |
49 | #endif | |
50 | ||
1da177e4 LT |
51 | struct prom_pmemblock * __init prom_getmdesc(void) |
52 | { | |
53 | char *memsize_str; | |
54 | unsigned int memsize; | |
e01402b1 | 55 | char cmdline[CL_SIZE], *ptr; |
1da177e4 | 56 | |
e01402b1 RB |
57 | /* Check the command line first for a memsize directive */ |
58 | strcpy(cmdline, arcs_cmdline); | |
59 | ptr = strstr(cmdline, "memsize="); | |
60 | if (ptr && (ptr != cmdline) && (*(ptr - 1) != ' ')) | |
61 | ptr = strstr(ptr, " memsize="); | |
62 | ||
63 | if (ptr) { | |
64 | memsize = memparse(ptr + 8, &ptr); | |
65 | } | |
66 | else { | |
67 | /* otherwise look in the environment */ | |
68 | memsize_str = prom_getenv("memsize"); | |
69 | if (!memsize_str) { | |
70 | prom_printf("memsize not set in boot prom, set to default (32Mb)\n"); | |
71 | memsize = 0x02000000; | |
72 | } else { | |
1da177e4 | 73 | #ifdef DEBUG |
e01402b1 | 74 | prom_printf("prom_memsize = %s\n", memsize_str); |
1da177e4 | 75 | #endif |
e01402b1 RB |
76 | memsize = simple_strtol(memsize_str, NULL, 0); |
77 | } | |
1da177e4 | 78 | } |
1da177e4 LT |
79 | memset(mdesc, 0, sizeof(mdesc)); |
80 | ||
81 | mdesc[0].type = yamon_dontuse; | |
82 | mdesc[0].base = 0x00000000; | |
83 | mdesc[0].size = 0x00001000; | |
84 | ||
85 | mdesc[1].type = yamon_prom; | |
86 | mdesc[1].base = 0x00001000; | |
87 | mdesc[1].size = 0x000ef000; | |
88 | ||
89 | #ifdef CONFIG_MIPS_MALTA | |
90 | /* | |
91 | * The area 0x000f0000-0x000fffff is allocated for BIOS memory by the | |
92 | * south bridge and PCI access always forwarded to the ISA Bus and | |
93 | * BIOSCS# is always generated. | |
94 | * This mean that this area can't be used as DMA memory for PCI | |
95 | * devices. | |
96 | */ | |
97 | mdesc[2].type = yamon_dontuse; | |
98 | mdesc[2].base = 0x000f0000; | |
99 | mdesc[2].size = 0x00010000; | |
100 | #else | |
101 | mdesc[2].type = yamon_prom; | |
102 | mdesc[2].base = 0x000f0000; | |
103 | mdesc[2].size = 0x00010000; | |
104 | #endif | |
105 | ||
106 | mdesc[3].type = yamon_dontuse; | |
107 | mdesc[3].base = 0x00100000; | |
fde3505c | 108 | mdesc[3].size = CPHYSADDR(PFN_ALIGN((unsigned long)&_end)) - mdesc[3].base; |
1da177e4 LT |
109 | |
110 | mdesc[4].type = yamon_free; | |
fde3505c | 111 | mdesc[4].base = CPHYSADDR(PFN_ALIGN(&_end)); |
1da177e4 LT |
112 | mdesc[4].size = memsize - mdesc[4].base; |
113 | ||
114 | return &mdesc[0]; | |
115 | } | |
116 | ||
117 | static int __init prom_memtype_classify (unsigned int type) | |
118 | { | |
119 | switch (type) { | |
120 | case yamon_free: | |
121 | return BOOT_MEM_RAM; | |
122 | case yamon_prom: | |
123 | return BOOT_MEM_ROM_DATA; | |
124 | default: | |
125 | return BOOT_MEM_RESERVED; | |
126 | } | |
127 | } | |
128 | ||
129 | void __init prom_meminit(void) | |
130 | { | |
131 | struct prom_pmemblock *p; | |
132 | ||
133 | #ifdef DEBUG | |
134 | prom_printf("YAMON MEMORY DESCRIPTOR dump:\n"); | |
135 | p = prom_getmdesc(); | |
136 | while (p->size) { | |
137 | int i = 0; | |
138 | prom_printf("[%d,%p]: base<%08lx> size<%08lx> type<%s>\n", | |
139 | i, p, p->base, p->size, mtypes[p->type]); | |
140 | p++; | |
141 | i++; | |
142 | } | |
143 | #endif | |
144 | p = prom_getmdesc(); | |
145 | ||
146 | while (p->size) { | |
147 | long type; | |
148 | unsigned long base, size; | |
149 | ||
150 | type = prom_memtype_classify (p->type); | |
151 | base = p->base; | |
152 | size = p->size; | |
153 | ||
154 | add_memory_region(base, size, type); | |
155 | p++; | |
156 | } | |
157 | } | |
158 | ||
159 | unsigned long __init prom_free_prom_memory(void) | |
160 | { | |
161 | unsigned long freed = 0; | |
162 | unsigned long addr; | |
163 | int i; | |
164 | ||
165 | for (i = 0; i < boot_mem_map.nr_map; i++) { | |
166 | if (boot_mem_map.map[i].type != BOOT_MEM_ROM_DATA) | |
167 | continue; | |
168 | ||
169 | addr = boot_mem_map.map[i].addr; | |
170 | while (addr < boot_mem_map.map[i].addr | |
171 | + boot_mem_map.map[i].size) { | |
172 | ClearPageReserved(virt_to_page(__va(addr))); | |
7835e98b | 173 | init_page_count(virt_to_page(__va(addr))); |
1da177e4 LT |
174 | free_page((unsigned long)__va(addr)); |
175 | addr += PAGE_SIZE; | |
176 | freed += PAGE_SIZE; | |
177 | } | |
178 | } | |
179 | printk("Freeing prom memory: %ldkb freed\n", freed >> 10); | |
180 | ||
181 | return freed; | |
182 | } |