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