ia64/xen-unstable

view xen/arch/powerpc/memory.c @ 13941:b071a2610abc

[POWERPC][XEN] Fix uninitialized variable warning.
Signed-off-by: Hollis Blanchard <hollisb@us.ibm.com>
author Hollis Blanchard <hollisb@us.ibm.com>
date Tue Jan 23 08:54:41 2007 -0600 (2007-01-23)
parents 741adb202b82
children b75609e1fa81
line source
1 /*
2 * This program is free software; you can redistribute it and/or modify
3 * it under the terms of the GNU General Public License as published by
4 * the Free Software Foundation; either version 2 of the License, or
5 * (at your option) any later version.
6 *
7 * This program is distributed in the hope that it will be useful,
8 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 * GNU General Public License for more details.
11 *
12 * You should have received a copy of the GNU General Public License
13 * along with this program; if not, write to the Free Software
14 * Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
15 *
16 * Copyright IBM Corp. 2006, 2007
17 *
18 * Authors: Dan Poff <poff@us.ibm.com>
19 * Jimi Xenidis <jimix@watson.ibm.com>
20 */
21 #include <xen/sched.h>
22 #include <xen/mm.h>
23 #include <xen/numa.h>
24 #include "of-devtree.h"
25 #include "oftree.h"
26 #include "rtas.h"
28 #define DEBUG
29 #ifdef DEBUG
30 #define DBG(fmt...) printk(fmt)
31 #else
32 #define DBG(fmt...)
33 #endif
35 /*
36 * opt_xenheap_megabytes: Size of Xen heap in megabytes, excluding the
37 * page_info table and allocation bitmap.
38 */
39 static unsigned int opt_xenheap_megabytes = XENHEAP_DEFAULT_MB;
40 integer_param("xenheap_megabytes", opt_xenheap_megabytes);
42 unsigned long xenheap_phys_end;
43 static uint nr_pages;
44 static ulong xenheap_size;
46 struct membuf {
47 ulong start;
48 ulong size;
49 };
51 typedef void (*walk_mem_fn)(struct membuf *, uint);
53 static void set_max_page(struct membuf *mb, uint entries)
54 {
55 int i;
57 for (i = 0; i < entries; i++) {
58 ulong end_page;
60 printk(" %016lx: %016lx\n", mb[i].start, mb[i].size);
61 nr_pages += mb[i].size >> PAGE_SHIFT;
63 end_page = (mb[i].start + mb[i].size) >> PAGE_SHIFT;
64 if (end_page > max_page)
65 max_page = end_page;
66 }
67 }
69 /* mark all memory from modules onward as unused */
70 static void heap_init(struct membuf *mb, uint entries)
71 {
72 int i;
73 ulong start_blk;
74 ulong end_blk = 0;
76 for (i = 0; i < entries; i++) {
77 start_blk = mb[i].start;
78 end_blk = start_blk + mb[i].size;
80 if (start_blk < xenheap_phys_end) {
81 if (xenheap_phys_end > end_blk) {
82 panic("xenheap spans LMB\n");
83 }
84 if (xenheap_phys_end == end_blk)
85 continue;
87 start_blk = xenheap_phys_end;
88 }
90 DBG("boot free: %016lx - %016lx\n", start_blk, end_blk);
91 init_boot_pages(start_blk, end_blk);
92 total_pages += (end_blk - start_blk) >> PAGE_SHIFT;
93 }
94 }
96 static void ofd_walk_mem(void *m, walk_mem_fn fn)
97 {
98 ofdn_t n;
99 uint p_len;
100 struct membuf mb[8];
101 static char name[] = "memory";
103 n = ofd_node_find_by_prop(m, OFD_ROOT, "device_type", name, sizeof(name));
104 while (n > 0) {
106 p_len = ofd_getprop(m, n, "reg", mb, sizeof (mb));
107 if (p_len <= 0) {
108 panic("ofd_getprop(): failed\n");
109 }
110 if (p_len > sizeof(mb))
111 panic("%s: buffer is not big enuff for this firmware: "
112 "0x%lx < 0x%x\n", __func__, sizeof(mb), p_len);
114 fn(mb, p_len / sizeof(mb[0]));
115 n = ofd_node_find_next(m, n);
116 }
117 }
119 void memory_init(module_t *mod, int mcount)
120 {
121 ulong eomem;
122 ulong bitmap_start = ~0UL;
123 ulong bitmap_end = 0;
124 ulong bitmap_size;
125 ulong xh_pages;
126 ulong start;
127 ulong end;
128 int pos;
130 /* lets find out how much memory there is and set max_page */
131 max_page = 0;
132 printk("Physical RAM map:\n");
133 ofd_walk_mem((void *)oftree, set_max_page);
134 eomem = max_page << PAGE_SHIFT;
135 if (eomem == 0) {
136 panic("ofd_walk_mem() failed\n");
137 }
139 xh_pages = opt_xenheap_megabytes << (20 - PAGE_SHIFT);
141 /* While we are allocating HTABS from The Xen Heap we need it to
142 * be larger */
143 xh_pages += nr_pages >> 5;
145 xenheap_phys_end = xh_pages << PAGE_SHIFT;
146 printk("End of Xen Area: %luMiB (%luKiB)\n",
147 xenheap_phys_end >> 20, xenheap_phys_end >> 10);
149 printk("End of RAM: %luMiB (%luKiB)\n", eomem >> 20, eomem >> 10);
151 /* The boot allocator requires one bit per page. Find a spot for it. */
152 bitmap_size = max_page / 8;
153 pos = boot_of_mem_avail(0, &start, &end);
154 while (pos >= 0) {
155 if (end - start >= bitmap_size) {
156 bitmap_start = start;
157 bitmap_end = init_boot_allocator(bitmap_start);
158 printk("boot allocator @ %lx - %lx\n", bitmap_start, bitmap_end);
159 break;
160 }
161 pos = boot_of_mem_avail(pos, &start, &end);
162 }
163 if (bitmap_start == ~0UL)
164 panic("Couldn't find 0x%lx bytes for boot allocator.", bitmap_size);
166 /* allow everything else to be allocated */
167 total_pages = 0;
168 ofd_walk_mem((void *)oftree, heap_init);
169 if (total_pages == 0)
170 panic("heap_init: failed");
172 if (total_pages > max_page)
173 panic("total_pages > max_page: 0x%lx > 0x%lx\n",
174 total_pages, max_page);
176 DBG("total_pages: 0x%016lx\n", total_pages);
178 init_frametable();
180 numa_initmem_init(0, max_page);
182 /* Domain heap gets all the unclaimed memory. */
183 end_boot_allocator();
185 /* Create initial xen heap by finding non-reserved memory. */
186 pos = boot_of_mem_avail(0, &start, &end);
187 while (pos >= 0) {
188 if (end == ~0UL)
189 end = xenheap_phys_end;
191 /* Problem: the bitmap itself is not reserved. */
192 if ((start >= bitmap_start) && (start < bitmap_end)) {
193 /* Start is inside bitmap. */
194 start = bitmap_end;
195 }
196 if ((end > bitmap_start) && (end <= bitmap_end)) {
197 /* End is inside bitmap. */
198 end = bitmap_start;
199 }
200 if ((start < bitmap_start) && (end > bitmap_end)) {
201 /* Range encompasses bitmap. First free low part, then high. */
202 xenheap_size += bitmap_start - start;
203 DBG("xenheap: %016lx - %016lx\n", start, bitmap_start);
204 init_xenheap_pages(start, bitmap_start);
205 start = bitmap_end;
206 }
208 xenheap_size += end - start;
209 DBG("xenheap: %016lx - %016lx\n", start, end);
210 init_xenheap_pages(start, end);
212 pos = boot_of_mem_avail(pos, &start, &end);
213 }
215 printk("Xen Heap: %luMiB (%luKiB)\n",
216 xenheap_size >> 20, xenheap_size >> 10);
218 eomem = avail_domheap_pages();
219 printk("Dom Heap: %luMiB (%luKiB)\n",
220 (eomem << PAGE_SHIFT) >> 20,
221 (eomem << PAGE_SHIFT) >> 10);
222 }