2 * Carsten Langgaard, carstenl@mips.com
3 * Copyright (C) 1999,2000 MIPS Technologies, Inc. All rights reserved.
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.
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
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.
18 * PROM library functions for acquiring/using memory descriptors given to
21 #include <linux/init.h>
23 #include <linux/bootmem.h>
24 #include <linux/pfn.h>
25 #include <linux/string.h>
27 #include <asm/bootinfo.h>
29 #include <asm/sections.h>
31 #include <asm/mips-boards/prom.h>
40 struct prom_pmemblock mdesc[PROM_MAX_PMEMBLOCKS];
43 static char *mtypes[3] = {
50 struct prom_pmemblock * __init prom_getmdesc(void)
54 char cmdline[CL_SIZE], *ptr;
56 /* Check the command line first for a memsize directive */
57 strcpy(cmdline, arcs_cmdline);
58 ptr = strstr(cmdline, "memsize=");
59 if (ptr && (ptr != cmdline) && (*(ptr - 1) != ' '))
60 ptr = strstr(ptr, " memsize=");
63 memsize = memparse(ptr + 8, &ptr);
66 /* otherwise look in the environment */
67 memsize_str = prom_getenv("memsize");
69 prom_printf("memsize not set in boot prom, set to default (32Mb)\n");
73 prom_printf("prom_memsize = %s\n", memsize_str);
75 memsize = simple_strtol(memsize_str, NULL, 0);
79 #ifdef CONFIG_CPU_BIG_ENDIAN
81 * SOC-it swaps, or perhaps doesn't swap, when DMA'ing the last
82 * word of physical memory
87 memset(mdesc, 0, sizeof(mdesc));
89 mdesc[0].type = yamon_dontuse;
90 mdesc[0].base = 0x00000000;
91 mdesc[0].size = 0x00001000;
93 mdesc[1].type = yamon_prom;
94 mdesc[1].base = 0x00001000;
95 mdesc[1].size = 0x000ef000;
97 #ifdef CONFIG_MIPS_MALTA
99 * The area 0x000f0000-0x000fffff is allocated for BIOS memory by the
100 * south bridge and PCI access always forwarded to the ISA Bus and
101 * BIOSCS# is always generated.
102 * This mean that this area can't be used as DMA memory for PCI
105 mdesc[2].type = yamon_dontuse;
106 mdesc[2].base = 0x000f0000;
107 mdesc[2].size = 0x00010000;
109 mdesc[2].type = yamon_prom;
110 mdesc[2].base = 0x000f0000;
111 mdesc[2].size = 0x00010000;
114 mdesc[3].type = yamon_dontuse;
115 mdesc[3].base = 0x00100000;
116 mdesc[3].size = CPHYSADDR(PFN_ALIGN((unsigned long)&_end)) - mdesc[3].base;
118 mdesc[4].type = yamon_free;
119 mdesc[4].base = CPHYSADDR(PFN_ALIGN(&_end));
120 mdesc[4].size = memsize - mdesc[4].base;
125 static int __init prom_memtype_classify (unsigned int type)
131 return BOOT_MEM_ROM_DATA;
133 return BOOT_MEM_RESERVED;
137 void __init prom_meminit(void)
139 struct prom_pmemblock *p;
142 prom_printf("YAMON MEMORY DESCRIPTOR dump:\n");
146 prom_printf("[%d,%p]: base<%08lx> size<%08lx> type<%s>\n",
147 i, p, p->base, p->size, mtypes[p->type]);
156 unsigned long base, size;
158 type = prom_memtype_classify (p->type);
162 add_memory_region(base, size, type);
167 unsigned long __init prom_free_prom_memory(void)
169 unsigned long freed = 0;
173 for (i = 0; i < boot_mem_map.nr_map; i++) {
174 if (boot_mem_map.map[i].type != BOOT_MEM_ROM_DATA)
177 addr = boot_mem_map.map[i].addr;
178 while (addr < boot_mem_map.map[i].addr
179 + boot_mem_map.map[i].size) {
180 ClearPageReserved(virt_to_page(__va(addr)));
181 init_page_count(virt_to_page(__va(addr)));
182 free_page((unsigned long)__va(addr));
187 printk("Freeing prom memory: %ldkb freed\n", freed >> 10);