Skip to content

Commit

Permalink
---
Browse files Browse the repository at this point in the history
yaml
---
r: 91534
b: refs/heads/master
c: d9024df
h: refs/heads/master
v: v3
  • Loading branch information
Paul Mackerras committed Apr 15, 2008
1 parent f84ef46 commit 0426cdf
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 27 deletions.
2 changes: 1 addition & 1 deletion [refs]
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
---
refs/heads/master: 300613e523d53f346f8ff0256921e289da39ed7b
refs/heads/master: d9024df02ffe74d723d97d552f86de3b34beb8cc
56 changes: 30 additions & 26 deletions trunk/lib/lmb.c
Original file line number Diff line number Diff line change
Expand Up @@ -230,20 +230,23 @@ static u64 lmb_align_up(u64 addr, u64 size)
static u64 __init lmb_alloc_nid_unreserved(u64 start, u64 end,
u64 size, u64 align)
{
u64 base;
u64 base, res_base;
long j;

base = lmb_align_down((end - size), align);
while (start <= base &&
((j = lmb_overlaps_region(&lmb.reserved, base, size)) >= 0))
base = lmb_align_down(lmb.reserved.region[j].base - size,
align);

if (base != 0 && start <= base) {
if (lmb_add_region(&lmb.reserved, base,
lmb_align_up(size, align)) < 0)
base = ~(u64)0;
return base;
while (start <= base) {
j = lmb_overlaps_region(&lmb.reserved, base, size);
if (j < 0) {
/* this area isn't reserved, take it */
if (lmb_add_region(&lmb.reserved, base,
lmb_align_up(size, align)) < 0)
base = ~(u64)0;
return base;
}
res_base = lmb.reserved.region[j].base;
if (res_base < size)
break;
base = lmb_align_down(res_base - size, align);
}

return ~(u64)0;
Expand Down Expand Up @@ -315,17 +318,21 @@ u64 __init __lmb_alloc_base(u64 size, u64 align, u64 max_addr)
{
long i, j;
u64 base = 0;
u64 res_base;

BUG_ON(0 == size);

/* On some platforms, make sure we allocate lowmem */
/* Note that LMB_REAL_LIMIT may be LMB_ALLOC_ANYWHERE */
if (max_addr == LMB_ALLOC_ANYWHERE)
max_addr = LMB_REAL_LIMIT;

for (i = lmb.memory.cnt - 1; i >= 0; i--) {
u64 lmbbase = lmb.memory.region[i].base;
u64 lmbsize = lmb.memory.region[i].size;

if (lmbsize < size)
continue;
if (max_addr == LMB_ALLOC_ANYWHERE)
base = lmb_align_down(lmbbase + lmbsize - size, align);
else if (lmbbase < max_addr) {
Expand All @@ -334,25 +341,22 @@ u64 __init __lmb_alloc_base(u64 size, u64 align, u64 max_addr)
} else
continue;

while (lmbbase <= base) {
while (base && lmbbase <= base) {
j = lmb_overlaps_region(&lmb.reserved, base, size);
if (j < 0)
if (j < 0) {
/* this area isn't reserved, take it */
if (lmb_add_region(&lmb.reserved, base,
size) < 0)
return 0;
return base;
}
res_base = lmb.reserved.region[j].base;
if (res_base < size)
break;
base = lmb_align_down(lmb.reserved.region[j].base - size,
align);
base = lmb_align_down(res_base - size, align);
}

if ((base != 0) && (lmbbase <= base))
break;
}

if (i < 0)
return 0;

if (lmb_add_region(&lmb.reserved, base, lmb_align_up(size, align)) < 0)
return 0;

return base;
return 0;
}

/* You must call lmb_analyze() before this. */
Expand Down

0 comments on commit 0426cdf

Please sign in to comment.