diff options
Diffstat (limited to 'arch/ppc64/kernel/lmb.c')
-rw-r--r-- | arch/ppc64/kernel/lmb.c | 151 |
1 files changed, 39 insertions, 112 deletions
diff --git a/arch/ppc64/kernel/lmb.c b/arch/ppc64/kernel/lmb.c index d6c6bd03d2a4..5adaca2ddc9d 100644 --- a/arch/ppc64/kernel/lmb.c +++ b/arch/ppc64/kernel/lmb.c | |||
@@ -28,33 +28,28 @@ void lmb_dump_all(void) | |||
28 | { | 28 | { |
29 | #ifdef DEBUG | 29 | #ifdef DEBUG |
30 | unsigned long i; | 30 | unsigned long i; |
31 | struct lmb *_lmb = &lmb; | ||
32 | 31 | ||
33 | udbg_printf("lmb_dump_all:\n"); | 32 | udbg_printf("lmb_dump_all:\n"); |
34 | udbg_printf(" memory.cnt = 0x%lx\n", | 33 | udbg_printf(" memory.cnt = 0x%lx\n", |
35 | _lmb->memory.cnt); | 34 | lmb.memory.cnt); |
36 | udbg_printf(" memory.size = 0x%lx\n", | 35 | udbg_printf(" memory.size = 0x%lx\n", |
37 | _lmb->memory.size); | 36 | lmb.memory.size); |
38 | for (i=0; i < _lmb->memory.cnt ;i++) { | 37 | for (i=0; i < lmb.memory.cnt ;i++) { |
39 | udbg_printf(" memory.region[0x%x].base = 0x%lx\n", | 38 | udbg_printf(" memory.region[0x%x].base = 0x%lx\n", |
40 | i, _lmb->memory.region[i].base); | 39 | i, lmb.memory.region[i].base); |
41 | udbg_printf(" .physbase = 0x%lx\n", | ||
42 | _lmb->memory.region[i].physbase); | ||
43 | udbg_printf(" .size = 0x%lx\n", | 40 | udbg_printf(" .size = 0x%lx\n", |
44 | _lmb->memory.region[i].size); | 41 | lmb.memory.region[i].size); |
45 | } | 42 | } |
46 | 43 | ||
47 | udbg_printf("\n reserved.cnt = 0x%lx\n", | 44 | udbg_printf("\n reserved.cnt = 0x%lx\n", |
48 | _lmb->reserved.cnt); | 45 | lmb.reserved.cnt); |
49 | udbg_printf(" reserved.size = 0x%lx\n", | 46 | udbg_printf(" reserved.size = 0x%lx\n", |
50 | _lmb->reserved.size); | 47 | lmb.reserved.size); |
51 | for (i=0; i < _lmb->reserved.cnt ;i++) { | 48 | for (i=0; i < lmb.reserved.cnt ;i++) { |
52 | udbg_printf(" reserved.region[0x%x].base = 0x%lx\n", | 49 | udbg_printf(" reserved.region[0x%x].base = 0x%lx\n", |
53 | i, _lmb->reserved.region[i].base); | 50 | i, lmb.reserved.region[i].base); |
54 | udbg_printf(" .physbase = 0x%lx\n", | ||
55 | _lmb->reserved.region[i].physbase); | ||
56 | udbg_printf(" .size = 0x%lx\n", | 51 | udbg_printf(" .size = 0x%lx\n", |
57 | _lmb->reserved.region[i].size); | 52 | lmb.reserved.region[i].size); |
58 | } | 53 | } |
59 | #endif /* DEBUG */ | 54 | #endif /* DEBUG */ |
60 | } | 55 | } |
@@ -98,7 +93,6 @@ lmb_coalesce_regions(struct lmb_region *rgn, unsigned long r1, unsigned long r2) | |||
98 | rgn->region[r1].size += rgn->region[r2].size; | 93 | rgn->region[r1].size += rgn->region[r2].size; |
99 | for (i=r2; i < rgn->cnt-1; i++) { | 94 | for (i=r2; i < rgn->cnt-1; i++) { |
100 | rgn->region[i].base = rgn->region[i+1].base; | 95 | rgn->region[i].base = rgn->region[i+1].base; |
101 | rgn->region[i].physbase = rgn->region[i+1].physbase; | ||
102 | rgn->region[i].size = rgn->region[i+1].size; | 96 | rgn->region[i].size = rgn->region[i+1].size; |
103 | } | 97 | } |
104 | rgn->cnt--; | 98 | rgn->cnt--; |
@@ -108,49 +102,29 @@ lmb_coalesce_regions(struct lmb_region *rgn, unsigned long r1, unsigned long r2) | |||
108 | void __init | 102 | void __init |
109 | lmb_init(void) | 103 | lmb_init(void) |
110 | { | 104 | { |
111 | struct lmb *_lmb = &lmb; | ||
112 | |||
113 | /* Create a dummy zero size LMB which will get coalesced away later. | 105 | /* Create a dummy zero size LMB which will get coalesced away later. |
114 | * This simplifies the lmb_add() code below... | 106 | * This simplifies the lmb_add() code below... |
115 | */ | 107 | */ |
116 | _lmb->memory.region[0].base = 0; | 108 | lmb.memory.region[0].base = 0; |
117 | _lmb->memory.region[0].size = 0; | 109 | lmb.memory.region[0].size = 0; |
118 | _lmb->memory.cnt = 1; | 110 | lmb.memory.cnt = 1; |
119 | 111 | ||
120 | /* Ditto. */ | 112 | /* Ditto. */ |
121 | _lmb->reserved.region[0].base = 0; | 113 | lmb.reserved.region[0].base = 0; |
122 | _lmb->reserved.region[0].size = 0; | 114 | lmb.reserved.region[0].size = 0; |
123 | _lmb->reserved.cnt = 1; | 115 | lmb.reserved.cnt = 1; |
124 | } | 116 | } |
125 | 117 | ||
126 | /* This routine called with relocation disabled. */ | 118 | /* This routine called with relocation disabled. */ |
127 | void __init | 119 | void __init |
128 | lmb_analyze(void) | 120 | lmb_analyze(void) |
129 | { | 121 | { |
130 | unsigned long i; | 122 | int i; |
131 | unsigned long mem_size = 0; | 123 | |
132 | unsigned long size_mask = 0; | 124 | lmb.memory.size = 0; |
133 | struct lmb *_lmb = &lmb; | ||
134 | #ifdef CONFIG_MSCHUNKS | ||
135 | unsigned long physbase = 0; | ||
136 | #endif | ||
137 | |||
138 | for (i=0; i < _lmb->memory.cnt; i++) { | ||
139 | unsigned long lmb_size; | ||
140 | |||
141 | lmb_size = _lmb->memory.region[i].size; | ||
142 | |||
143 | #ifdef CONFIG_MSCHUNKS | ||
144 | _lmb->memory.region[i].physbase = physbase; | ||
145 | physbase += lmb_size; | ||
146 | #else | ||
147 | _lmb->memory.region[i].physbase = _lmb->memory.region[i].base; | ||
148 | #endif | ||
149 | mem_size += lmb_size; | ||
150 | size_mask |= lmb_size; | ||
151 | } | ||
152 | 125 | ||
153 | _lmb->memory.size = mem_size; | 126 | for (i = 0; i < lmb.memory.cnt; i++) |
127 | lmb.memory.size += lmb.memory.region[i].size; | ||
154 | } | 128 | } |
155 | 129 | ||
156 | /* This routine called with relocation disabled. */ | 130 | /* This routine called with relocation disabled. */ |
@@ -168,7 +142,6 @@ lmb_add_region(struct lmb_region *rgn, unsigned long base, unsigned long size) | |||
168 | adjacent = lmb_addrs_adjacent(base,size,rgnbase,rgnsize); | 142 | adjacent = lmb_addrs_adjacent(base,size,rgnbase,rgnsize); |
169 | if ( adjacent > 0 ) { | 143 | if ( adjacent > 0 ) { |
170 | rgn->region[i].base -= size; | 144 | rgn->region[i].base -= size; |
171 | rgn->region[i].physbase -= size; | ||
172 | rgn->region[i].size += size; | 145 | rgn->region[i].size += size; |
173 | coalesced++; | 146 | coalesced++; |
174 | break; | 147 | break; |
@@ -195,11 +168,9 @@ lmb_add_region(struct lmb_region *rgn, unsigned long base, unsigned long size) | |||
195 | for (i=rgn->cnt-1; i >= 0; i--) { | 168 | for (i=rgn->cnt-1; i >= 0; i--) { |
196 | if (base < rgn->region[i].base) { | 169 | if (base < rgn->region[i].base) { |
197 | rgn->region[i+1].base = rgn->region[i].base; | 170 | rgn->region[i+1].base = rgn->region[i].base; |
198 | rgn->region[i+1].physbase = rgn->region[i].physbase; | ||
199 | rgn->region[i+1].size = rgn->region[i].size; | 171 | rgn->region[i+1].size = rgn->region[i].size; |
200 | } else { | 172 | } else { |
201 | rgn->region[i+1].base = base; | 173 | rgn->region[i+1].base = base; |
202 | rgn->region[i+1].physbase = lmb_abs_to_phys(base); | ||
203 | rgn->region[i+1].size = size; | 174 | rgn->region[i+1].size = size; |
204 | break; | 175 | break; |
205 | } | 176 | } |
@@ -213,12 +184,11 @@ lmb_add_region(struct lmb_region *rgn, unsigned long base, unsigned long size) | |||
213 | long __init | 184 | long __init |
214 | lmb_add(unsigned long base, unsigned long size) | 185 | lmb_add(unsigned long base, unsigned long size) |
215 | { | 186 | { |
216 | struct lmb *_lmb = &lmb; | 187 | struct lmb_region *_rgn = &(lmb.memory); |
217 | struct lmb_region *_rgn = &(_lmb->memory); | ||
218 | 188 | ||
219 | /* On pSeries LPAR systems, the first LMB is our RMO region. */ | 189 | /* On pSeries LPAR systems, the first LMB is our RMO region. */ |
220 | if ( base == 0 ) | 190 | if ( base == 0 ) |
221 | _lmb->rmo_size = size; | 191 | lmb.rmo_size = size; |
222 | 192 | ||
223 | return lmb_add_region(_rgn, base, size); | 193 | return lmb_add_region(_rgn, base, size); |
224 | 194 | ||
@@ -227,8 +197,7 @@ lmb_add(unsigned long base, unsigned long size) | |||
227 | long __init | 197 | long __init |
228 | lmb_reserve(unsigned long base, unsigned long size) | 198 | lmb_reserve(unsigned long base, unsigned long size) |
229 | { | 199 | { |
230 | struct lmb *_lmb = &lmb; | 200 | struct lmb_region *_rgn = &(lmb.reserved); |
231 | struct lmb_region *_rgn = &(_lmb->reserved); | ||
232 | 201 | ||
233 | return lmb_add_region(_rgn, base, size); | 202 | return lmb_add_region(_rgn, base, size); |
234 | } | 203 | } |
@@ -260,13 +229,10 @@ lmb_alloc_base(unsigned long size, unsigned long align, unsigned long max_addr) | |||
260 | { | 229 | { |
261 | long i, j; | 230 | long i, j; |
262 | unsigned long base = 0; | 231 | unsigned long base = 0; |
263 | struct lmb *_lmb = &lmb; | ||
264 | struct lmb_region *_mem = &(_lmb->memory); | ||
265 | struct lmb_region *_rsv = &(_lmb->reserved); | ||
266 | 232 | ||
267 | for (i=_mem->cnt-1; i >= 0; i--) { | 233 | for (i=lmb.memory.cnt-1; i >= 0; i--) { |
268 | unsigned long lmbbase = _mem->region[i].base; | 234 | unsigned long lmbbase = lmb.memory.region[i].base; |
269 | unsigned long lmbsize = _mem->region[i].size; | 235 | unsigned long lmbsize = lmb.memory.region[i].size; |
270 | 236 | ||
271 | if ( max_addr == LMB_ALLOC_ANYWHERE ) | 237 | if ( max_addr == LMB_ALLOC_ANYWHERE ) |
272 | base = _ALIGN_DOWN(lmbbase+lmbsize-size, align); | 238 | base = _ALIGN_DOWN(lmbbase+lmbsize-size, align); |
@@ -276,8 +242,8 @@ lmb_alloc_base(unsigned long size, unsigned long align, unsigned long max_addr) | |||
276 | continue; | 242 | continue; |
277 | 243 | ||
278 | while ( (lmbbase <= base) && | 244 | while ( (lmbbase <= base) && |
279 | ((j = lmb_overlaps_region(_rsv,base,size)) >= 0) ) { | 245 | ((j = lmb_overlaps_region(&lmb.reserved,base,size)) >= 0) ) { |
280 | base = _ALIGN_DOWN(_rsv->region[j].base-size, align); | 246 | base = _ALIGN_DOWN(lmb.reserved.region[j].base-size, align); |
281 | } | 247 | } |
282 | 248 | ||
283 | if ( (base != 0) && (lmbbase <= base) ) | 249 | if ( (base != 0) && (lmbbase <= base) ) |
@@ -287,62 +253,24 @@ lmb_alloc_base(unsigned long size, unsigned long align, unsigned long max_addr) | |||
287 | if ( i < 0 ) | 253 | if ( i < 0 ) |
288 | return 0; | 254 | return 0; |
289 | 255 | ||
290 | lmb_add_region(_rsv, base, size); | 256 | lmb_add_region(&lmb.reserved, base, size); |
291 | 257 | ||
292 | return base; | 258 | return base; |
293 | } | 259 | } |
294 | 260 | ||
261 | /* You must call lmb_analyze() before this. */ | ||
295 | unsigned long __init | 262 | unsigned long __init |
296 | lmb_phys_mem_size(void) | 263 | lmb_phys_mem_size(void) |
297 | { | 264 | { |
298 | struct lmb *_lmb = &lmb; | 265 | return lmb.memory.size; |
299 | #ifdef CONFIG_MSCHUNKS | ||
300 | return _lmb->memory.size; | ||
301 | #else | ||
302 | struct lmb_region *_mem = &(_lmb->memory); | ||
303 | unsigned long total = 0; | ||
304 | int i; | ||
305 | |||
306 | /* add all physical memory to the bootmem map */ | ||
307 | for (i=0; i < _mem->cnt; i++) | ||
308 | total += _mem->region[i].size; | ||
309 | return total; | ||
310 | #endif /* CONFIG_MSCHUNKS */ | ||
311 | } | 266 | } |
312 | 267 | ||
313 | unsigned long __init | 268 | unsigned long __init |
314 | lmb_end_of_DRAM(void) | 269 | lmb_end_of_DRAM(void) |
315 | { | 270 | { |
316 | struct lmb *_lmb = &lmb; | 271 | int idx = lmb.memory.cnt - 1; |
317 | struct lmb_region *_mem = &(_lmb->memory); | ||
318 | int idx = _mem->cnt - 1; | ||
319 | |||
320 | #ifdef CONFIG_MSCHUNKS | ||
321 | return (_mem->region[idx].physbase + _mem->region[idx].size); | ||
322 | #else | ||
323 | return (_mem->region[idx].base + _mem->region[idx].size); | ||
324 | #endif /* CONFIG_MSCHUNKS */ | ||
325 | |||
326 | return 0; | ||
327 | } | ||
328 | |||
329 | unsigned long __init | ||
330 | lmb_abs_to_phys(unsigned long aa) | ||
331 | { | ||
332 | unsigned long i, pa = aa; | ||
333 | struct lmb *_lmb = &lmb; | ||
334 | struct lmb_region *_mem = &(_lmb->memory); | ||
335 | |||
336 | for (i=0; i < _mem->cnt; i++) { | ||
337 | unsigned long lmbbase = _mem->region[i].base; | ||
338 | unsigned long lmbsize = _mem->region[i].size; | ||
339 | if ( lmb_addrs_overlap(aa,1,lmbbase,lmbsize) ) { | ||
340 | pa = _mem->region[i].physbase + (aa - lmbbase); | ||
341 | break; | ||
342 | } | ||
343 | } | ||
344 | 272 | ||
345 | return pa; | 273 | return (lmb.memory.region[idx].base + lmb.memory.region[idx].size); |
346 | } | 274 | } |
347 | 275 | ||
348 | /* | 276 | /* |
@@ -353,20 +281,19 @@ void __init lmb_enforce_memory_limit(void) | |||
353 | { | 281 | { |
354 | extern unsigned long memory_limit; | 282 | extern unsigned long memory_limit; |
355 | unsigned long i, limit; | 283 | unsigned long i, limit; |
356 | struct lmb_region *mem = &(lmb.memory); | ||
357 | 284 | ||
358 | if (! memory_limit) | 285 | if (! memory_limit) |
359 | return; | 286 | return; |
360 | 287 | ||
361 | limit = memory_limit; | 288 | limit = memory_limit; |
362 | for (i = 0; i < mem->cnt; i++) { | 289 | for (i = 0; i < lmb.memory.cnt; i++) { |
363 | if (limit > mem->region[i].size) { | 290 | if (limit > lmb.memory.region[i].size) { |
364 | limit -= mem->region[i].size; | 291 | limit -= lmb.memory.region[i].size; |
365 | continue; | 292 | continue; |
366 | } | 293 | } |
367 | 294 | ||
368 | mem->region[i].size = limit; | 295 | lmb.memory.region[i].size = limit; |
369 | mem->cnt = i + 1; | 296 | lmb.memory.cnt = i + 1; |
370 | break; | 297 | break; |
371 | } | 298 | } |
372 | } | 299 | } |