]> git.proxmox.com Git - mirror_ubuntu-bionic-kernel.git/blob - arch/mips/mips-boards/generic/memory.c
Linux-2.6.12-rc2
[mirror_ubuntu-bionic-kernel.git] / arch / mips / mips-boards / generic / memory.c
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>
25
26 #include <asm/bootinfo.h>
27 #include <asm/page.h>
28
29 #include <asm/mips-boards/prom.h>
30
31 /*#define DEBUG*/
32
33 enum yamon_memtypes {
34 yamon_dontuse,
35 yamon_prom,
36 yamon_free,
37 };
38 struct prom_pmemblock mdesc[PROM_MAX_PMEMBLOCKS];
39
40 #ifdef DEBUG
41 static char *mtypes[3] = {
42 "Dont use memory",
43 "YAMON PROM memory",
44 "Free memmory",
45 };
46 #endif
47
48 /* References to section boundaries */
49 extern char _end;
50
51 #define PFN_ALIGN(x) (((unsigned long)(x) + (PAGE_SIZE - 1)) & PAGE_MASK)
52
53
54 struct prom_pmemblock * __init prom_getmdesc(void)
55 {
56 char *memsize_str;
57 unsigned int memsize;
58
59 memsize_str = prom_getenv("memsize");
60 if (!memsize_str) {
61 prom_printf("memsize not set in boot prom, set to default (32Mb)\n");
62 memsize = 0x02000000;
63 } else {
64 #ifdef DEBUG
65 prom_printf("prom_memsize = %s\n", memsize_str);
66 #endif
67 memsize = simple_strtol(memsize_str, NULL, 0);
68 }
69
70 memset(mdesc, 0, sizeof(mdesc));
71
72 mdesc[0].type = yamon_dontuse;
73 mdesc[0].base = 0x00000000;
74 mdesc[0].size = 0x00001000;
75
76 mdesc[1].type = yamon_prom;
77 mdesc[1].base = 0x00001000;
78 mdesc[1].size = 0x000ef000;
79
80 #ifdef CONFIG_MIPS_MALTA
81 /*
82 * The area 0x000f0000-0x000fffff is allocated for BIOS memory by the
83 * south bridge and PCI access always forwarded to the ISA Bus and
84 * BIOSCS# is always generated.
85 * This mean that this area can't be used as DMA memory for PCI
86 * devices.
87 */
88 mdesc[2].type = yamon_dontuse;
89 mdesc[2].base = 0x000f0000;
90 mdesc[2].size = 0x00010000;
91 #else
92 mdesc[2].type = yamon_prom;
93 mdesc[2].base = 0x000f0000;
94 mdesc[2].size = 0x00010000;
95 #endif
96
97 mdesc[3].type = yamon_dontuse;
98 mdesc[3].base = 0x00100000;
99 mdesc[3].size = CPHYSADDR(PFN_ALIGN(&_end)) - mdesc[3].base;
100
101 mdesc[4].type = yamon_free;
102 mdesc[4].base = CPHYSADDR(PFN_ALIGN(&_end));
103 mdesc[4].size = memsize - mdesc[4].base;
104
105 return &mdesc[0];
106 }
107
108 static int __init prom_memtype_classify (unsigned int type)
109 {
110 switch (type) {
111 case yamon_free:
112 return BOOT_MEM_RAM;
113 case yamon_prom:
114 return BOOT_MEM_ROM_DATA;
115 default:
116 return BOOT_MEM_RESERVED;
117 }
118 }
119
120 void __init prom_meminit(void)
121 {
122 struct prom_pmemblock *p;
123
124 #ifdef DEBUG
125 prom_printf("YAMON MEMORY DESCRIPTOR dump:\n");
126 p = prom_getmdesc();
127 while (p->size) {
128 int i = 0;
129 prom_printf("[%d,%p]: base<%08lx> size<%08lx> type<%s>\n",
130 i, p, p->base, p->size, mtypes[p->type]);
131 p++;
132 i++;
133 }
134 #endif
135 p = prom_getmdesc();
136
137 while (p->size) {
138 long type;
139 unsigned long base, size;
140
141 type = prom_memtype_classify (p->type);
142 base = p->base;
143 size = p->size;
144
145 add_memory_region(base, size, type);
146 p++;
147 }
148 }
149
150 unsigned long __init prom_free_prom_memory(void)
151 {
152 unsigned long freed = 0;
153 unsigned long addr;
154 int i;
155
156 for (i = 0; i < boot_mem_map.nr_map; i++) {
157 if (boot_mem_map.map[i].type != BOOT_MEM_ROM_DATA)
158 continue;
159
160 addr = boot_mem_map.map[i].addr;
161 while (addr < boot_mem_map.map[i].addr
162 + boot_mem_map.map[i].size) {
163 ClearPageReserved(virt_to_page(__va(addr)));
164 set_page_count(virt_to_page(__va(addr)), 1);
165 free_page((unsigned long)__va(addr));
166 addr += PAGE_SIZE;
167 freed += PAGE_SIZE;
168 }
169 }
170 printk("Freeing prom memory: %ldkb freed\n", freed >> 10);
171
172 return freed;
173 }