Add a 'wmask' variable to hold the expression '(1ul << w->step) - 1' in

pcib_grow_window().  This makes the code slightly easier to read and
prevents the type of bug fixed in r237271.

MFC after:	3 days
This commit is contained in:
John Baldwin 2012-06-19 16:06:27 +00:00
parent 1ba9eae287
commit a7b5acac1a

View File

@ -815,7 +815,7 @@ static int
pcib_grow_window(struct pcib_softc *sc, struct pcib_window *w, int type,
u_long start, u_long end, u_long count, u_int flags)
{
u_long align, start_free, end_free, front, back;
u_long align, start_free, end_free, front, back, wmask;
int error, rid;
/*
@ -828,6 +828,7 @@ pcib_grow_window(struct pcib_softc *sc, struct pcib_window *w, int type,
end = w->rman.rm_end;
if (start + count - 1 > end || start + count < start)
return (EINVAL);
wmask = (1ul << w->step) - 1;
/*
* If there is no resource at all, just try to allocate enough
@ -838,8 +839,8 @@ pcib_grow_window(struct pcib_softc *sc, struct pcib_window *w, int type,
flags &= ~RF_ALIGNMENT_MASK;
flags |= RF_ALIGNMENT_LOG2(w->step);
}
start &= ~((1ul << w->step) - 1);
end |= ((1ul << w->step) - 1);
start &= ~wmask;
end |= wmask;
count = roundup2(count, 1ul << w->step);
rid = w->reg;
w->res = bus_alloc_resource(sc->dev, type, &rid, start, end,
@ -913,7 +914,7 @@ pcib_grow_window(struct pcib_softc *sc, struct pcib_window *w, int type,
if (bootverbose)
printf("\tfront candidate range: %#lx-%#lx\n",
front, end_free);
front &= ~((1ul << w->step) - 1);
front &= ~wmask;
front = rman_get_start(w->res) - front;
} else
front = 0;
@ -941,7 +942,7 @@ pcib_grow_window(struct pcib_softc *sc, struct pcib_window *w, int type,
if (bootverbose)
printf("\tback candidate range: %#lx-%#lx\n",
start_free, back);
back |= (1ul << w->step) - 1;
back |= wmask;
back -= rman_get_end(w->res);
} else
back = 0;
@ -1000,10 +1001,8 @@ pcib_grow_window(struct pcib_softc *sc, struct pcib_window *w, int type,
/* Save the new window. */
w->base = rman_get_start(w->res);
w->limit = rman_get_end(w->res);
KASSERT((w->base & ((1ul << w->step) - 1)) == 0,
("start address is not aligned"));
KASSERT((w->limit & ((1ul << w->step) - 1)) == (1ul << w->step) - 1,
("end address is not aligned"));
KASSERT((w->base & wmask) == 0, ("start address is not aligned"));
KASSERT((w->limit & wmask) == wmask, ("end address is not aligned"));
pcib_write_windows(sc, w->mask);
return (0);
}