[MIPS] Replace redundant declarations of _end by <asm/sections.h>.
[pandora-kernel.git] / arch / mips / mips-boards / sim / sim_mem.c
1 /*
2  * Copyright (C) 2005 MIPS Technologies, Inc.  All rights reserved.
3  *
4  *  This program is free software; you can distribute it and/or modify it
5  *  under the terms of the GNU General Public License (Version 2) as
6  *  published by the Free Software Foundation.
7  *
8  *  This program is distributed in the hope it will be useful, but WITHOUT
9  *  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
10  *  FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
11  *  for more details.
12  *
13  *  You should have received a copy of the GNU General Public License along
14  *  with this program; if not, write to the Free Software Foundation, Inc.,
15  *  59 Temple Place - Suite 330, Boston MA 02111-1307, USA.
16  *
17  */
18 #include <linux/init.h>
19 #include <linux/mm.h>
20 #include <linux/bootmem.h>
21
22 #include <asm/bootinfo.h>
23 #include <asm/page.h>
24 #include <asm/sections.h>
25
26 #include <asm/mips-boards/prom.h>
27
28 /*#define DEBUG*/
29
30 enum simmem_memtypes {
31         simmem_reserved = 0,
32         simmem_free,
33 };
34 struct prom_pmemblock mdesc[PROM_MAX_PMEMBLOCKS];
35
36 #ifdef DEBUG
37 static char *mtypes[3] = {
38         "SIM reserved memory",
39         "SIM free memory",
40 };
41 #endif
42
43 struct prom_pmemblock * __init prom_getmdesc(void)
44 {
45         unsigned int memsize;
46
47         memsize = 0x02000000;
48         prom_printf("Setting default memory size 0x%08x\n", memsize);
49
50         memset(mdesc, 0, sizeof(mdesc));
51
52         mdesc[0].type = simmem_reserved;
53         mdesc[0].base = 0x00000000;
54         mdesc[0].size = 0x00001000;
55
56         mdesc[1].type = simmem_free;
57         mdesc[1].base = 0x00001000;
58         mdesc[1].size = 0x000ff000;
59
60         mdesc[2].type = simmem_reserved;
61         mdesc[2].base = 0x00100000;
62         mdesc[2].size = CPHYSADDR(PAGE_ALIGN(&_end)) - mdesc[2].base;
63
64         mdesc[3].type = simmem_free;
65         mdesc[3].base = CPHYSADDR(PAGE_ALIGN(&_end));
66         mdesc[3].size = memsize - mdesc[3].base;
67
68         return &mdesc[0];
69 }
70
71 static int __init prom_memtype_classify (unsigned int type)
72 {
73         switch (type) {
74         case simmem_free:
75                 return BOOT_MEM_RAM;
76         case simmem_reserved:
77         default:
78                 return BOOT_MEM_RESERVED;
79         }
80 }
81
82 void __init prom_meminit(void)
83 {
84         struct prom_pmemblock *p;
85
86         p = prom_getmdesc();
87
88         while (p->size) {
89                 long type;
90                 unsigned long base, size;
91
92                 type = prom_memtype_classify (p->type);
93                 base = p->base;
94                 size = p->size;
95
96                 add_memory_region(base, size, type);
97                 p++;
98         }
99 }
100
101 unsigned long __init prom_free_prom_memory(void)
102 {
103         int i;
104         unsigned long freed = 0;
105         unsigned long addr;
106
107         for (i = 0; i < boot_mem_map.nr_map; i++) {
108                 if (boot_mem_map.map[i].type != BOOT_MEM_ROM_DATA)
109                         continue;
110
111                 addr = boot_mem_map.map[i].addr;
112                 while (addr < boot_mem_map.map[i].addr
113                               + boot_mem_map.map[i].size) {
114                         ClearPageReserved(virt_to_page(__va(addr)));
115                         init_page_count(virt_to_page(__va(addr)));
116                         free_page((unsigned long)__va(addr));
117                         addr += PAGE_SIZE;
118                         freed += PAGE_SIZE;
119                 }
120         }
121         printk("Freeing prom memory: %ldkb freed\n", freed >> 10);
122
123         return freed;
124 }