blob: 32c9210373ac864e5faab2c8789dff848f3c5322 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
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>
Ralf Baechlee01402b2005-07-14 15:57:16 +000025#include <linux/string.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070026
27#include <asm/bootinfo.h>
28#include <asm/page.h>
29
30#include <asm/mips-boards/prom.h>
31
32/*#define DEBUG*/
33
34enum yamon_memtypes {
35 yamon_dontuse,
36 yamon_prom,
37 yamon_free,
38};
39struct prom_pmemblock mdesc[PROM_MAX_PMEMBLOCKS];
40
41#ifdef DEBUG
42static char *mtypes[3] = {
43 "Dont use memory",
44 "YAMON PROM memory",
45 "Free memmory",
46};
47#endif
48
49/* References to section boundaries */
50extern char _end;
51
Linus Torvalds1da177e2005-04-16 15:20:36 -070052struct prom_pmemblock * __init prom_getmdesc(void)
53{
54 char *memsize_str;
55 unsigned int memsize;
Ralf Baechlee01402b2005-07-14 15:57:16 +000056 char cmdline[CL_SIZE], *ptr;
Linus Torvalds1da177e2005-04-16 15:20:36 -070057
Ralf Baechlee01402b2005-07-14 15:57:16 +000058 /* Check the command line first for a memsize directive */
59 strcpy(cmdline, arcs_cmdline);
60 ptr = strstr(cmdline, "memsize=");
61 if (ptr && (ptr != cmdline) && (*(ptr - 1) != ' '))
62 ptr = strstr(ptr, " memsize=");
63
64 if (ptr) {
65 memsize = memparse(ptr + 8, &ptr);
Linus Torvalds1da177e2005-04-16 15:20:36 -070066 }
Ralf Baechlee01402b2005-07-14 15:57:16 +000067 else {
68 /* otherwise look in the environment */
69 memsize_str = prom_getenv("memsize");
70 if (!memsize_str) {
71 prom_printf("memsize not set in boot prom, set to default (32Mb)\n");
72 memsize = 0x02000000;
73 } else {
74#ifdef DEBUG
75 prom_printf("prom_memsize = %s\n", memsize_str);
76#endif
77 memsize = simple_strtol(memsize_str, NULL, 0);
78 }
79 }
Linus Torvalds1da177e2005-04-16 15:20:36 -070080 memset(mdesc, 0, sizeof(mdesc));
81
82 mdesc[0].type = yamon_dontuse;
83 mdesc[0].base = 0x00000000;
84 mdesc[0].size = 0x00001000;
85
86 mdesc[1].type = yamon_prom;
87 mdesc[1].base = 0x00001000;
88 mdesc[1].size = 0x000ef000;
89
90#ifdef CONFIG_MIPS_MALTA
91 /*
92 * The area 0x000f0000-0x000fffff is allocated for BIOS memory by the
93 * south bridge and PCI access always forwarded to the ISA Bus and
94 * BIOSCS# is always generated.
95 * This mean that this area can't be used as DMA memory for PCI
96 * devices.
97 */
98 mdesc[2].type = yamon_dontuse;
99 mdesc[2].base = 0x000f0000;
100 mdesc[2].size = 0x00010000;
101#else
102 mdesc[2].type = yamon_prom;
103 mdesc[2].base = 0x000f0000;
104 mdesc[2].size = 0x00010000;
105#endif
106
107 mdesc[3].type = yamon_dontuse;
108 mdesc[3].base = 0x00100000;
Dave Hansen22a98352006-03-27 01:16:04 -0800109 mdesc[3].size = CPHYSADDR(PAGE_ALIGN(&_end)) - mdesc[3].base;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700110
111 mdesc[4].type = yamon_free;
Dave Hansen22a98352006-03-27 01:16:04 -0800112 mdesc[4].base = CPHYSADDR(PAGE_ALIGN(&_end));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700113 mdesc[4].size = memsize - mdesc[4].base;
114
115 return &mdesc[0];
116}
117
118static int __init prom_memtype_classify (unsigned int type)
119{
120 switch (type) {
121 case yamon_free:
122 return BOOT_MEM_RAM;
123 case yamon_prom:
124 return BOOT_MEM_ROM_DATA;
125 default:
126 return BOOT_MEM_RESERVED;
127 }
128}
129
130void __init prom_meminit(void)
131{
132 struct prom_pmemblock *p;
133
134#ifdef DEBUG
135 prom_printf("YAMON MEMORY DESCRIPTOR dump:\n");
136 p = prom_getmdesc();
137 while (p->size) {
138 int i = 0;
139 prom_printf("[%d,%p]: base<%08lx> size<%08lx> type<%s>\n",
140 i, p, p->base, p->size, mtypes[p->type]);
141 p++;
142 i++;
143 }
144#endif
145 p = prom_getmdesc();
146
147 while (p->size) {
148 long type;
149 unsigned long base, size;
150
151 type = prom_memtype_classify (p->type);
152 base = p->base;
153 size = p->size;
154
155 add_memory_region(base, size, type);
156 p++;
157 }
158}
159
160unsigned long __init prom_free_prom_memory(void)
161{
162 unsigned long freed = 0;
163 unsigned long addr;
164 int i;
165
166 for (i = 0; i < boot_mem_map.nr_map; i++) {
167 if (boot_mem_map.map[i].type != BOOT_MEM_ROM_DATA)
168 continue;
169
170 addr = boot_mem_map.map[i].addr;
171 while (addr < boot_mem_map.map[i].addr
172 + boot_mem_map.map[i].size) {
173 ClearPageReserved(virt_to_page(__va(addr)));
Nick Piggin7835e982006-03-22 00:08:40 -0800174 init_page_count(virt_to_page(__va(addr)));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700175 free_page((unsigned long)__va(addr));
176 addr += PAGE_SIZE;
177 freed += PAGE_SIZE;
178 }
179 }
180 printk("Freeing prom memory: %ldkb freed\n", freed >> 10);
181
182 return freed;
183}