diff options
author | jhb <jhb@FreeBSD.org> | 2012-06-19 16:06:27 +0000 |
---|---|---|
committer | jhb <jhb@FreeBSD.org> | 2012-06-19 16:06:27 +0000 |
commit | ec398928923afa6edd4aa8ada94387db8950b61e (patch) | |
tree | 2f67ae01ca44c00f9b29e3174ce05c8b8975f54c | |
parent | 7a9968597c3b0607f5ee88254b24687d2da64e39 (diff) | |
download | FreeBSD-src-ec398928923afa6edd4aa8ada94387db8950b61e.zip FreeBSD-src-ec398928923afa6edd4aa8ada94387db8950b61e.tar.gz |
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
-rw-r--r-- | sys/dev/pci/pci_pci.c | 17 |
1 files changed, 8 insertions, 9 deletions
diff --git a/sys/dev/pci/pci_pci.c b/sys/dev/pci/pci_pci.c index 4901c1d..9dc72ef 100644 --- a/sys/dev/pci/pci_pci.c +++ b/sys/dev/pci/pci_pci.c @@ -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 @@ updatewin: /* 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); } |