17cb740b3f0063d661544b5e288e337ef0d58d29
[openwrt/svn-archive/archive.git] / target / linux / ar7-2.6 / files / arch / mips / ar7 / memory.c
1 /*
2 * $Id$
3 *
4 * Copyright (C) 2007 OpenWrt.org
5 *
6 * Based on arch/mips/mm/init.c
7 * Copyright (C) 1994 - 2000 Ralf Baechle
8 * Copyright (C) 1999, 2000 Silicon Graphics, Inc.
9 * Kevin D. Kissell, kevink@mips.com and Carsten Langgaard, carstenl@mips.com
10 * Copyright (C) 2000 MIPS Technologies, Inc. All rights reserved.
11 *
12 * This program is free software; you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License as published by
14 * the Free Software Foundation; either version 2 of the License, or
15 * (at your option) any later version.
16 *
17 * This program is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
21 *
22 * You should have received a copy of the GNU General Public License
23 * along with this program; if not, write to the Free Software
24 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
25 */
26 #include <linux/bootmem.h>
27 #include <linux/init.h>
28 #include <linux/mm.h>
29 #include <linux/module.h>
30 #include <linux/pfn.h>
31 #include <linux/proc_fs.h>
32 #include <linux/string.h>
33 #include <linux/swap.h>
34
35 #include <asm/bootinfo.h>
36 #include <asm/page.h>
37 #include <asm/sections.h>
38
39 #include <asm/mips-boards/prom.h>
40
41 #warning FIXME: use sdram control regs and/or autodetection
42 static int __init memsize(void)
43 {
44 char *memsize_str;
45 unsigned int result;
46 char cmdline[CL_SIZE], *ptr;
47
48 /* Check the command line first for a memsize directive */
49 strcpy(cmdline, arcs_cmdline);
50 ptr = strstr(cmdline, "memsize=");
51 if (ptr && (ptr != cmdline) && (*(ptr - 1) != ' '))
52 ptr = strstr(ptr, " memsize=");
53
54 if (ptr) {
55 result = memparse(ptr + 8, &ptr);
56 } else {
57 /* otherwise look in the environment */
58 memsize_str = prom_getenv("memsize");
59 if (!memsize_str) {
60 prom_printf("memsize not set in boot prom, set to default (8Mb)\n");
61 result = 0x00800000;
62 } else {
63 result = simple_strtol(memsize_str, NULL, 0);
64 }
65 }
66
67 return result;
68 }
69
70 #ifdef CONFIG_NEED_MULTIPLE_NODES
71 static bootmem_data_t node_bootmem_data;
72 pg_data_t __node_data[1] = {
73 {
74 .bdata = &node_bootmem_data
75 },
76 };
77 EXPORT_SYMBOL(__node_data);
78
79 unsigned long max_mapnr;
80 struct page *mem_map;
81 EXPORT_SYMBOL(max_mapnr);
82 EXPORT_SYMBOL(mem_map);
83
84 static unsigned long setup_zero_pages(void)
85 {
86 unsigned int order = 3;
87 unsigned long size;
88 struct page *page;
89
90 empty_zero_page = __get_free_pages(GFP_KERNEL | __GFP_ZERO, order);
91 if (!empty_zero_page)
92 panic("Oh boy, that early out of memory?");
93
94 page = virt_to_page(empty_zero_page);
95 split_page(page, order);
96 while (page < virt_to_page(empty_zero_page + (PAGE_SIZE << order))) {
97 SetPageReserved(page);
98 page++;
99 }
100
101 size = PAGE_SIZE << order;
102 zero_page_mask = (size - 1) & PAGE_MASK;
103
104 return 1UL << order;
105 }
106
107 extern void pagetable_init(void);
108
109 void __init paging_init(void)
110 {
111 unsigned long zones_size[MAX_NR_ZONES] = { 0, };
112
113 pagetable_init();
114
115 zones_size[ZONE_DMA] = max_low_pfn - min_low_pfn;
116
117 free_area_init_node(0, NODE_DATA(0), zones_size, ARCH_PFN_OFFSET, NULL);
118 }
119
120 static struct kcore_list kcore_mem, kcore_vmalloc;
121
122 void __init mem_init(void)
123 {
124 unsigned long codesize, reservedpages, datasize, initsize;
125 unsigned long tmp, ram;
126 unsigned long kernel_start, kernel_end;
127
128 kernel_start = PFN_DOWN(CPHYSADDR((unsigned long)&_text));
129 kernel_end = PFN_UP(CPHYSADDR((unsigned long)&_end));
130 for (tmp = min_low_pfn + 1; tmp < kernel_start; tmp++) {
131 ClearPageReserved(pfn_to_page(tmp));
132 init_page_count(pfn_to_page(tmp));
133 free_page((unsigned long)__va(tmp << PAGE_SHIFT));
134 }
135
136 totalram_pages += free_all_bootmem();
137 totalram_pages -= setup_zero_pages(); /* Setup zeroed pages. */
138
139 reservedpages = ram = 0;
140 for (tmp = min_low_pfn; tmp <= max_low_pfn; tmp++) {
141 ram++;
142 if (PageReserved(pfn_to_page(tmp)))
143 if ((tmp < kernel_start) || (tmp > kernel_end))
144 reservedpages++;
145 }
146 num_physpages = ram;
147
148 codesize = (unsigned long) &_etext - (unsigned long) &_text;
149 datasize = (unsigned long) &_edata - (unsigned long) &_etext;
150 initsize = (unsigned long) &__init_end - (unsigned long) &__init_begin;
151
152 kclist_add(&kcore_mem, __va(min_low_pfn),
153 (max_low_pfn - min_low_pfn) << PAGE_SHIFT);
154 kclist_add(&kcore_vmalloc, (void *)VMALLOC_START,
155 VMALLOC_END - VMALLOC_START);
156
157 printk(KERN_INFO "Memory: %luk/%luk available (%ldk kernel code, "
158 "%ldk reserved, %ldk data, %ldk init)\n",
159 (unsigned long) nr_free_pages() << (PAGE_SHIFT-10),
160 ram << (PAGE_SHIFT-10),
161 codesize >> 10,
162 reservedpages << (PAGE_SHIFT-10),
163 datasize >> 10,
164 initsize >> 10);
165 }
166 #endif
167
168 void __init prom_meminit(void)
169 {
170 #ifdef CONFIG_NEED_MULTIPLE_NODES
171 unsigned long kernel_start, kernel_end;
172 unsigned long pages, free_pages;
173 unsigned long bootmap_size;
174 #endif
175
176 pages = memsize() >> PAGE_SHIFT;
177 add_memory_region(ARCH_PFN_OFFSET << PAGE_SHIFT, pages <<
178 PAGE_SHIFT, BOOT_MEM_RAM);
179
180 #ifdef CONFIG_NEED_MULTIPLE_NODES
181 kernel_start = PFN_DOWN(CPHYSADDR((unsigned long)&_text));
182 kernel_end = PFN_UP(CPHYSADDR((unsigned long)&_end));
183 min_low_pfn = ARCH_PFN_OFFSET;
184 max_low_pfn = ARCH_PFN_OFFSET + pages;
185 max_mapnr = max_low_pfn;
186 free_pages = pages - (kernel_end - min_low_pfn);
187 bootmap_size = init_bootmem_node(NODE_DATA(0), kernel_end,
188 ARCH_PFN_OFFSET, max_low_pfn);
189
190 free_bootmem(PFN_PHYS(kernel_end), free_pages << PAGE_SHIFT);
191 memory_present(0, min_low_pfn, max_low_pfn);
192 reserve_bootmem(PFN_PHYS(kernel_end), bootmap_size);
193 mem_map = NODE_DATA(0)->node_mem_map;
194 #endif
195 }
196
197 unsigned long __init prom_free_prom_memory(void)
198 {
199 /* return freed;
200 */
201 return 0;
202 }