ar7 misc fixes: - serial - memory probing
[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/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 static int __init memsize(void)
42 {
43 u32 size = (64 << 20);
44 volatile u32 *addr = (u32 *)KSEG1ADDR(0x14000000 + size - 4);
45 u32 *kernel_end = (u32 *)KSEG1ADDR(CPHYSADDR((u32)&_end));
46
47 while (addr > kernel_end) {
48 *addr = (u32)addr;
49 size >>= 1;
50 addr -= size >> 2;
51 }
52
53 do {
54 addr += size >> 2;
55 if (*addr != (u32)addr)
56 break;
57 size <<= 1;
58 } while (size < (64 << 20));
59
60 return size;
61 }
62
63 #ifdef CONFIG_NEED_MULTIPLE_NODES
64 static bootmem_data_t node_bootmem_data;
65 pg_data_t __node_data[1] = {
66 {
67 .bdata = &node_bootmem_data
68 },
69 };
70 EXPORT_SYMBOL(__node_data);
71
72 unsigned long max_mapnr;
73 struct page *mem_map;
74 EXPORT_SYMBOL(max_mapnr);
75 EXPORT_SYMBOL(mem_map);
76
77 static unsigned long setup_zero_pages(void)
78 {
79 unsigned int order = 3;
80 unsigned long size;
81 struct page *page;
82
83 empty_zero_page = __get_free_pages(GFP_KERNEL | __GFP_ZERO, order);
84 if (!empty_zero_page)
85 panic("Oh boy, that early out of memory?");
86
87 page = virt_to_page(empty_zero_page);
88 split_page(page, order);
89 while (page < virt_to_page(empty_zero_page + (PAGE_SIZE << order))) {
90 SetPageReserved(page);
91 page++;
92 }
93
94 size = PAGE_SIZE << order;
95 zero_page_mask = (size - 1) & PAGE_MASK;
96
97 return 1UL << order;
98 }
99
100 extern void pagetable_init(void);
101
102 void __init paging_init(void)
103 {
104 unsigned long zones_size[MAX_NR_ZONES] = { 0, };
105
106 pagetable_init();
107
108 zones_size[ZONE_DMA] = max_low_pfn - min_low_pfn;
109
110 free_area_init_node(0, NODE_DATA(0), zones_size, ARCH_PFN_OFFSET, NULL);
111 }
112
113 static struct kcore_list kcore_mem, kcore_vmalloc;
114
115 void __init mem_init(void)
116 {
117 unsigned long codesize, reservedpages, datasize, initsize;
118 unsigned long tmp, ram;
119 unsigned long kernel_start, kernel_end;
120
121 kernel_start = PFN_DOWN(CPHYSADDR((unsigned long)&_text));
122 kernel_end = PFN_UP(CPHYSADDR((unsigned long)&_end));
123 for (tmp = min_low_pfn + 1; tmp < kernel_start; tmp++) {
124 ClearPageReserved(pfn_to_page(tmp));
125 init_page_count(pfn_to_page(tmp));
126 free_page((unsigned long)__va(tmp << PAGE_SHIFT));
127 }
128
129 totalram_pages += free_all_bootmem();
130 totalram_pages -= setup_zero_pages(); /* Setup zeroed pages. */
131
132 reservedpages = ram = 0;
133 for (tmp = min_low_pfn; tmp <= max_low_pfn; tmp++) {
134 ram++;
135 if (PageReserved(pfn_to_page(tmp)))
136 if ((tmp < kernel_start) || (tmp > kernel_end))
137 reservedpages++;
138 }
139 num_physpages = ram;
140
141 codesize = (unsigned long) &_etext - (unsigned long) &_text;
142 datasize = (unsigned long) &_edata - (unsigned long) &_etext;
143 initsize = (unsigned long) &__init_end - (unsigned long) &__init_begin;
144
145 kclist_add(&kcore_mem, __va(min_low_pfn),
146 (max_low_pfn - min_low_pfn) << PAGE_SHIFT);
147 kclist_add(&kcore_vmalloc, (void *)VMALLOC_START,
148 VMALLOC_END - VMALLOC_START);
149
150 printk(KERN_INFO "Memory: %luk/%luk available (%ldk kernel code, "
151 "%ldk reserved, %ldk data, %ldk init)\n",
152 (unsigned long) nr_free_pages() << (PAGE_SHIFT-10),
153 ram << (PAGE_SHIFT-10),
154 codesize >> 10,
155 reservedpages << (PAGE_SHIFT-10),
156 datasize >> 10,
157 initsize >> 10);
158 }
159 #endif
160
161 void __init prom_meminit(void)
162 {
163 unsigned long pages;
164 #ifdef CONFIG_NEED_MULTIPLE_NODES
165 unsigned long kernel_start, kernel_end;
166 unsigned long free_pages;
167 unsigned long bootmap_size;
168 #endif
169
170 pages = memsize() >> PAGE_SHIFT;
171 add_memory_region(ARCH_PFN_OFFSET << PAGE_SHIFT, pages <<
172 PAGE_SHIFT, BOOT_MEM_RAM);
173
174 #ifdef CONFIG_NEED_MULTIPLE_NODES
175 kernel_start = PFN_DOWN(CPHYSADDR((unsigned long)&_text));
176 kernel_end = PFN_UP(CPHYSADDR((unsigned long)&_end));
177 min_low_pfn = ARCH_PFN_OFFSET;
178 max_low_pfn = ARCH_PFN_OFFSET + pages;
179 max_mapnr = max_low_pfn;
180 free_pages = pages - (kernel_end - min_low_pfn);
181 bootmap_size = init_bootmem_node(NODE_DATA(0), kernel_end,
182 ARCH_PFN_OFFSET, max_low_pfn);
183
184 free_bootmem(PFN_PHYS(kernel_end), free_pages << PAGE_SHIFT);
185 memory_present(0, min_low_pfn, max_low_pfn);
186 reserve_bootmem(PFN_PHYS(kernel_end), bootmap_size);
187 mem_map = NODE_DATA(0)->node_mem_map;
188 #endif
189 }
190
191 unsigned long __init prom_free_prom_memory(void)
192 {
193 return 0;
194 }