blob: fd492562584aabea44489f7ad622d49ebdacc90e [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 Baechlefde35052006-04-03 14:44:50 +010025#include <linux/pfn.h>
Ralf Baechlee01402b2005-07-14 15:57:16 +000026#include <linux/string.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070027
28#include <asm/bootinfo.h>
29#include <asm/page.h>
Ralf Baechle9c1f1252006-04-03 10:17:21 +010030#include <asm/sections.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070031
32#include <asm/mips-boards/prom.h>
33
34/*#define DEBUG*/
35
36enum yamon_memtypes {
37 yamon_dontuse,
38 yamon_prom,
39 yamon_free,
40};
41struct prom_pmemblock mdesc[PROM_MAX_PMEMBLOCKS];
42
43#ifdef DEBUG
44static char *mtypes[3] = {
45 "Dont use memory",
46 "YAMON PROM memory",
47 "Free memmory",
48};
49#endif
50
Linus Torvalds1da177e2005-04-16 15:20:36 -070051struct prom_pmemblock * __init prom_getmdesc(void)
52{
53 char *memsize_str;
54 unsigned int memsize;
Ralf Baechlee01402b2005-07-14 15:57:16 +000055 char cmdline[CL_SIZE], *ptr;
Linus Torvalds1da177e2005-04-16 15:20:36 -070056
Ralf Baechlee01402b2005-07-14 15:57:16 +000057 /* 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);
Linus Torvalds1da177e2005-04-16 15:20:36 -070065 }
Ralf Baechlee01402b2005-07-14 15:57:16 +000066 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 {
73#ifdef DEBUG
74 prom_printf("prom_memsize = %s\n", memsize_str);
75#endif
76 memsize = simple_strtol(memsize_str, NULL, 0);
77 }
78 }
Elizabeth Oldham73499682006-06-06 10:57:09 +010079
80#ifdef CONFIG_CPU_BIG_ENDIAN
81 /*
82 * SOC-it swaps, or perhaps doesn't swap, when DMA'ing the last
83 * word of physical memory
84 */
85 memsize -= PAGE_SIZE;
86#endif
87
Linus Torvalds1da177e2005-04-16 15:20:36 -070088 memset(mdesc, 0, sizeof(mdesc));
89
90 mdesc[0].type = yamon_dontuse;
91 mdesc[0].base = 0x00000000;
92 mdesc[0].size = 0x00001000;
93
94 mdesc[1].type = yamon_prom;
95 mdesc[1].base = 0x00001000;
96 mdesc[1].size = 0x000ef000;
97
98#ifdef CONFIG_MIPS_MALTA
99 /*
100 * The area 0x000f0000-0x000fffff is allocated for BIOS memory by the
101 * south bridge and PCI access always forwarded to the ISA Bus and
102 * BIOSCS# is always generated.
103 * This mean that this area can't be used as DMA memory for PCI
104 * devices.
105 */
106 mdesc[2].type = yamon_dontuse;
107 mdesc[2].base = 0x000f0000;
108 mdesc[2].size = 0x00010000;
109#else
110 mdesc[2].type = yamon_prom;
111 mdesc[2].base = 0x000f0000;
112 mdesc[2].size = 0x00010000;
113#endif
114
115 mdesc[3].type = yamon_dontuse;
116 mdesc[3].base = 0x00100000;
Ralf Baechlefde35052006-04-03 14:44:50 +0100117 mdesc[3].size = CPHYSADDR(PFN_ALIGN((unsigned long)&_end)) - mdesc[3].base;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700118
119 mdesc[4].type = yamon_free;
Ralf Baechlefde35052006-04-03 14:44:50 +0100120 mdesc[4].base = CPHYSADDR(PFN_ALIGN(&_end));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700121 mdesc[4].size = memsize - mdesc[4].base;
122
123 return &mdesc[0];
124}
125
126static int __init prom_memtype_classify (unsigned int type)
127{
128 switch (type) {
129 case yamon_free:
130 return BOOT_MEM_RAM;
131 case yamon_prom:
132 return BOOT_MEM_ROM_DATA;
133 default:
134 return BOOT_MEM_RESERVED;
135 }
136}
137
138void __init prom_meminit(void)
139{
140 struct prom_pmemblock *p;
141
142#ifdef DEBUG
143 prom_printf("YAMON MEMORY DESCRIPTOR dump:\n");
144 p = prom_getmdesc();
145 while (p->size) {
146 int i = 0;
147 prom_printf("[%d,%p]: base<%08lx> size<%08lx> type<%s>\n",
148 i, p, p->base, p->size, mtypes[p->type]);
149 p++;
150 i++;
151 }
152#endif
153 p = prom_getmdesc();
154
155 while (p->size) {
156 long type;
157 unsigned long base, size;
158
159 type = prom_memtype_classify (p->type);
160 base = p->base;
161 size = p->size;
162
163 add_memory_region(base, size, type);
164 p++;
165 }
166}
167
168unsigned long __init prom_free_prom_memory(void)
169{
170 unsigned long freed = 0;
171 unsigned long addr;
172 int i;
173
174 for (i = 0; i < boot_mem_map.nr_map; i++) {
175 if (boot_mem_map.map[i].type != BOOT_MEM_ROM_DATA)
176 continue;
177
178 addr = boot_mem_map.map[i].addr;
179 while (addr < boot_mem_map.map[i].addr
180 + boot_mem_map.map[i].size) {
181 ClearPageReserved(virt_to_page(__va(addr)));
Nick Piggin7835e982006-03-22 00:08:40 -0800182 init_page_count(virt_to_page(__va(addr)));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700183 free_page((unsigned long)__va(addr));
184 addr += PAGE_SIZE;
185 freed += PAGE_SIZE;
186 }
187 }
188 printk("Freeing prom memory: %ldkb freed\n", freed >> 10);
189
190 return freed;
191}