Add ar7-2.6 port (marked as broken for now).
[openwrt/staging/chunkeey.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/initrd.h>
29 #include <linux/mm.h>
30 #include <linux/module.h>
31 #include <linux/pfn.h>
32 #include <linux/proc_fs.h>
33 #include <linux/string.h>
34 #include <linux/swap.h>
35
36 #include <asm/bootinfo.h>
37 #include <asm/page.h>
38 #include <asm/sections.h>
39
40 #include <asm/mips-boards/prom.h>
41
42 #warning FIXME: use sdram control regs and/or autodetection
43 static int __init memsize(void)
44 {
45 char *memsize_str;
46 unsigned int result;
47 char cmdline[CL_SIZE], *ptr;
48
49 /* Check the command line first for a memsize directive */
50 strcpy(cmdline, arcs_cmdline);
51 ptr = strstr(cmdline, "memsize=");
52 if (ptr && (ptr != cmdline) && (*(ptr - 1) != ' '))
53 ptr = strstr(ptr, " memsize=");
54
55 if (ptr) {
56 result = memparse(ptr + 8, &ptr);
57 } else {
58 /* otherwise look in the environment */
59 memsize_str = prom_getenv("memsize");
60 if (!memsize_str) {
61 prom_printf("memsize not set in boot prom, set to default (8Mb)\n");
62 result = 0x00800000;
63 } else {
64 result = simple_strtol(memsize_str, NULL, 0);
65 }
66 }
67
68 return result;
69 }
70
71 extern unsigned long __initramfs_start, __initramfs_end;
72
73 #ifdef CONFIG_NEED_MULTIPLE_NODES
74 static bootmem_data_t node_bootmem_data;
75 pg_data_t __node_data[1] = {
76 {
77 .bdata = &node_bootmem_data
78 },
79 };
80 EXPORT_SYMBOL(__node_data);
81
82 unsigned long max_mapnr;
83 struct page *mem_map;
84 EXPORT_SYMBOL(max_mapnr);
85 EXPORT_SYMBOL(mem_map);
86
87 static unsigned long setup_zero_pages(void)
88 {
89 unsigned int order = 3;
90 unsigned long size;
91 struct page *page;
92
93 empty_zero_page = __get_free_pages(GFP_KERNEL | __GFP_ZERO, order);
94 if (!empty_zero_page)
95 panic("Oh boy, that early out of memory?");
96
97 page = virt_to_page(empty_zero_page);
98 split_page(page, order);
99 while (page < virt_to_page(empty_zero_page + (PAGE_SIZE << order))) {
100 SetPageReserved(page);
101 page++;
102 }
103
104 size = PAGE_SIZE << order;
105 zero_page_mask = (size - 1) & PAGE_MASK;
106
107 return 1UL << order;
108 }
109
110 extern void pagetable_init(void);
111
112 void __init paging_init(void)
113 {
114 unsigned long zones_size[MAX_NR_ZONES] = { 0, };
115
116 pagetable_init();
117
118 zones_size[ZONE_DMA] = max_low_pfn - min_low_pfn;
119
120 free_area_init_node(0, NODE_DATA(0), zones_size, ARCH_PFN_OFFSET, NULL);
121 }
122
123 static struct kcore_list kcore_mem, kcore_vmalloc;
124
125 void __init mem_init(void)
126 {
127 unsigned long codesize, reservedpages, datasize, initsize;
128 unsigned long tmp, ram;
129 unsigned long kernel_start, kernel_end;
130
131 kernel_start = PFN_DOWN(CPHYSADDR((unsigned long)&_text));
132 kernel_end = PFN_UP(CPHYSADDR((unsigned long)&_end));
133 for (tmp = min_low_pfn + 1; tmp < kernel_start; tmp++) {
134 ClearPageReserved(pfn_to_page(tmp));
135 init_page_count(pfn_to_page(tmp));
136 free_page((unsigned long)__va(tmp << PAGE_SHIFT));
137 }
138
139 totalram_pages += free_all_bootmem();
140 totalram_pages -= setup_zero_pages(); /* Setup zeroed pages. */
141
142 reservedpages = ram = 0;
143 for (tmp = min_low_pfn; tmp <= max_low_pfn; tmp++) {
144 ram++;
145 if (PageReserved(pfn_to_page(tmp)))
146 if ((tmp < kernel_start) || (tmp > kernel_end))
147 reservedpages++;
148 }
149 num_physpages = ram;
150
151 codesize = (unsigned long) &_etext - (unsigned long) &_text;
152 datasize = (unsigned long) &_edata - (unsigned long) &_etext;
153 initsize = (unsigned long) &__init_end - (unsigned long) &__init_begin;
154
155 kclist_add(&kcore_mem, __va(min_low_pfn),
156 (max_low_pfn - min_low_pfn) << PAGE_SHIFT);
157 kclist_add(&kcore_vmalloc, (void *)VMALLOC_START,
158 VMALLOC_END - VMALLOC_START);
159
160 printk(KERN_INFO "Memory: %luk/%luk available (%ldk kernel code, "
161 "%ldk reserved, %ldk data, %ldk init)\n",
162 (unsigned long) nr_free_pages() << (PAGE_SHIFT-10),
163 ram << (PAGE_SHIFT-10),
164 codesize >> 10,
165 reservedpages << (PAGE_SHIFT-10),
166 datasize >> 10,
167 initsize >> 10);
168 }
169 #endif
170
171 void __init prom_meminit(void)
172 {
173 #ifdef CONFIG_NEED_MULTIPLE_NODES
174 unsigned long kernel_start, kernel_end;
175 unsigned long pages, free_pages;
176 unsigned long bootmap_size;
177 #endif
178
179 #ifdef CONFIG_BLK_DEV_INITRD
180 initrd_start = (unsigned long)&__initramfs_start;
181 initrd_end = (unsigned long)&__initramfs_end;
182 #endif
183
184 pages = memsize() >> PAGE_SHIFT;
185 add_memory_region(ARCH_PFN_OFFSET << PAGE_SHIFT, pages <<
186 PAGE_SHIFT, BOOT_MEM_RAM);
187
188 #ifdef CONFIG_NEED_MULTIPLE_NODES
189 kernel_start = PFN_DOWN(CPHYSADDR((unsigned long)&_text));
190 kernel_end = PFN_UP(CPHYSADDR((unsigned long)&_end));
191 min_low_pfn = ARCH_PFN_OFFSET;
192 max_low_pfn = ARCH_PFN_OFFSET + pages;
193 max_mapnr = max_low_pfn;
194 free_pages = pages - (kernel_end - min_low_pfn);
195 bootmap_size = init_bootmem_node(NODE_DATA(0), kernel_end,
196 ARCH_PFN_OFFSET, max_low_pfn);
197
198 free_bootmem(PFN_PHYS(kernel_end), free_pages << PAGE_SHIFT);
199 memory_present(0, min_low_pfn, max_low_pfn);
200 reserve_bootmem(PFN_PHYS(kernel_end), bootmap_size);
201 mem_map = NODE_DATA(0)->node_mem_map;
202 #endif
203 }
204
205 unsigned long __init prom_free_prom_memory(void)
206 {
207 /* return freed;
208 */
209 return 0;
210 }