summaryrefslogtreecommitdiffstats
path: root/sys/dev
diff options
context:
space:
mode:
authorpfg <pfg@FreeBSD.org>2016-04-21 19:57:40 +0000
committerpfg <pfg@FreeBSD.org>2016-04-21 19:57:40 +0000
commit729533413f4e97bb65852c22fb914805e2759b5a (patch)
treecd4dfa8859a5f57124d315ff395b524d7587e1ea /sys/dev
parent0d55061d05ce55d28aff0c06bad831448d172425 (diff)
downloadFreeBSD-src-729533413f4e97bb65852c22fb914805e2759b5a.zip
FreeBSD-src-729533413f4e97bb65852c22fb914805e2759b5a.tar.gz
sys: use our roundup2/rounddown2() macros when param.h is available.
rounddown2 tends to produce longer lines than the original code and when the code has a high indentation level it was not really advantageous to do the replacement. This tries to strike a balance between readability using the macros and flexibility of having the expressions, so not everything is converted.
Diffstat (limited to 'sys/dev')
-rw-r--r--sys/dev/adb/adb_mouse.c2
-rw-r--r--sys/dev/agp/agp_nvidia.c6
-rw-r--r--sys/dev/bce/if_bce.c2
-rw-r--r--sys/dev/cxgbe/common/t4_hw.c4
-rw-r--r--sys/dev/en/midway.c4
-rw-r--r--sys/dev/exca/exca.c2
-rw-r--r--sys/dev/fatm/if_fatm.c4
-rw-r--r--sys/dev/hatm/if_hatm.c6
-rw-r--r--sys/dev/hptmv/gui_lib.c4
-rw-r--r--sys/dev/mpr/mpr.c4
-rw-r--r--sys/dev/mps/mps.c4
-rw-r--r--sys/dev/pccbb/pccbb.c2
-rw-r--r--sys/dev/pms/freebsd/driver/ini/src/agtiapi.c11
-rw-r--r--sys/dev/sym/sym_hipd.c2
-rw-r--r--sys/dev/ti/if_ti.c10
-rw-r--r--sys/dev/usb/usb_busdma.c4
-rw-r--r--sys/dev/vt/hw/efifb/efifb.c2
17 files changed, 35 insertions, 38 deletions
diff --git a/sys/dev/adb/adb_mouse.c b/sys/dev/adb/adb_mouse.c
index 65b3a20..eb7cf33 100644
--- a/sys/dev/adb/adb_mouse.c
+++ b/sys/dev/adb/adb_mouse.c
@@ -403,7 +403,7 @@ adb_mouse_receive_packet(device_t dev, u_char status, u_char command,
* high button events when they are touched.
*/
- if (buttons & ~((1 << sc->hw.buttons) - 1)
+ if (rounddown2(buttons, 1 << sc->hw.buttons)
&& !(sc->flags & AMS_TOUCHPAD)) {
buttons |= 1 << (sc->hw.buttons - 1);
}
diff --git a/sys/dev/agp/agp_nvidia.c b/sys/dev/agp/agp_nvidia.c
index a0098f0..61ae551 100644
--- a/sys/dev/agp/agp_nvidia.c
+++ b/sys/dev/agp/agp_nvidia.c
@@ -216,8 +216,8 @@ agp_nvidia_attach (device_t dev)
if (sc->num_dirs == 0) {
sc->num_dirs = 1;
sc->num_active_entries /= (64 / size);
- sc->pg_offset = (apbase & (64 * 1024 * 1024 - 1) &
- ~(AGP_GET_APERTURE(dev) - 1)) / PAGE_SIZE;
+ sc->pg_offset = rounddown2(apbase & (64 * 1024 * 1024 - 1),
+ AGP_GET_APERTURE(dev)) / PAGE_SIZE;
}
/* (G)ATT Base Address */
@@ -410,7 +410,7 @@ nvidia_init_iorr(u_int32_t addr, u_int32_t size)
}
base = (addr & ~0xfff) | 0x18;
- mask = (0xfULL << 32) | ((~(size - 1)) & 0xfffff000) | 0x800;
+ mask = (0xfULL << 32) | rounddown2(0xfffff000, size) | 0x800;
wrmsr(IORR_BASE0 + 2 * iorr_addr, base);
wrmsr(IORR_MASK0 + 2 * iorr_addr, mask);
diff --git a/sys/dev/bce/if_bce.c b/sys/dev/bce/if_bce.c
index 2f9f459..cfc091f 100644
--- a/sys/dev/bce/if_bce.c
+++ b/sys/dev/bce/if_bce.c
@@ -3047,7 +3047,7 @@ bce_get_rx_buffer_sizes(struct bce_softc *sc, int mtu)
sc->rx_bd_mbuf_alloc_size = MHLEN;
/* Make sure offset is 16 byte aligned for hardware. */
sc->rx_bd_mbuf_align_pad =
- roundup2((MSIZE - MHLEN), 16) - (MSIZE - MHLEN);
+ roundup2(MSIZE - MHLEN, 16) - (MSIZE - MHLEN);
sc->rx_bd_mbuf_data_len = sc->rx_bd_mbuf_alloc_size -
sc->rx_bd_mbuf_align_pad;
} else {
diff --git a/sys/dev/cxgbe/common/t4_hw.c b/sys/dev/cxgbe/common/t4_hw.c
index 8973551..03312b1 100644
--- a/sys/dev/cxgbe/common/t4_hw.c
+++ b/sys/dev/cxgbe/common/t4_hw.c
@@ -607,8 +607,8 @@ int t4_mem_read(struct adapter *adap, int mtype, u32 addr, u32 len,
* need to round down the start and round up the end. We'll start
* copying out of the first line at (addr - start) a word at a time.
*/
- start = addr & ~(64-1);
- end = (addr + len + 64-1) & ~(64-1);
+ start = rounddown2(addr, 64);
+ end = roundup2(addr + len, 64);
offset = (addr - start)/sizeof(__be32);
for (pos = start; pos < end; pos += 64, offset = 0) {
diff --git a/sys/dev/en/midway.c b/sys/dev/en/midway.c
index bc3adf5..bce650b 100644
--- a/sys/dev/en/midway.c
+++ b/sys/dev/en/midway.c
@@ -1487,7 +1487,7 @@ en_init(struct en_softc *sc)
loc = sc->txslot[slot].cur = sc->txslot[slot].start;
loc = loc - MID_RAMOFF;
/* mask, cvt to words */
- loc = (loc & ~((EN_TXSZ * 1024) - 1)) >> 2;
+ loc = rounddown2(loc, EN_TXSZ * 1024) >> 2;
/* top 11 bits */
loc = loc >> MIDV_LOCTOPSHFT;
en_write(sc, MIDX_PLACE(slot), MIDX_MKPLACE(en_k2sz(EN_TXSZ),
@@ -2992,7 +2992,7 @@ en_attach(struct en_softc *sc)
sc->rxslot[lcv].stop = ptr;
midvloc = midvloc - MID_RAMOFF;
/* mask, cvt to words */
- midvloc = (midvloc & ~((EN_RXSZ*1024) - 1)) >> 2;
+ midvloc = rounddown2(midvloc, EN_RXSZ * 1024) >> 2;
/* we only want the top 11 bits */
midvloc = midvloc >> MIDV_LOCTOPSHFT;
midvloc = (midvloc & MIDV_LOCMASK) << MIDV_LOCSHIFT;
diff --git a/sys/dev/exca/exca.c b/sys/dev/exca/exca.c
index ed39ddc..ea611a8 100644
--- a/sys/dev/exca/exca.c
+++ b/sys/dev/exca/exca.c
@@ -402,7 +402,7 @@ exca_mem_set_offset(struct exca_softc *sc, struct resource *res,
"set_memory_offset: specified resource not active\n");
return (ENOENT);
}
- sc->mem[win].cardaddr = cardaddr & ~(EXCA_MEM_PAGESIZE - 1);
+ sc->mem[win].cardaddr = rounddown2(cardaddr, EXCA_MEM_PAGESIZE);
delta = cardaddr % EXCA_MEM_PAGESIZE;
if (deltap)
*deltap = delta;
diff --git a/sys/dev/fatm/if_fatm.c b/sys/dev/fatm/if_fatm.c
index ec85d31..9a42b93 100644
--- a/sys/dev/fatm/if_fatm.c
+++ b/sys/dev/fatm/if_fatm.c
@@ -116,8 +116,8 @@ static const struct utopia_methods fatm_utopia_methods = {
};
#define VC_OK(SC, VPI, VCI) \
- (((VPI) & ~((1 << IFP2IFATM((SC)->ifp)->mib.vpi_bits) - 1)) == 0 && \
- (VCI) != 0 && ((VCI) & ~((1 << IFP2IFATM((SC)->ifp)->mib.vci_bits) - 1)) == 0)
+ (rounddown2(VPI, 1 << IFP2IFATM((SC)->ifp)->mib.vpi_bits) == 0 && \
+ (VCI) != 0 && rounddown2(VCI, 1 << IFP2IFATM((SC)->ifp)->mib.vci_bits) == 0)
static int fatm_load_vc(struct fatm_softc *sc, struct card_vcc *vc);
diff --git a/sys/dev/hatm/if_hatm.c b/sys/dev/hatm/if_hatm.c
index d1dd6b1..c34ee0e 100644
--- a/sys/dev/hatm/if_hatm.c
+++ b/sys/dev/hatm/if_hatm.c
@@ -788,16 +788,14 @@ hatm_init_cm(struct hatm_softc *sc)
rsra = 0;
mlbm = ((rsra + IFP2IFATM(sc->ifp)->mib.max_vccs * 8) + 0x7ff) & ~0x7ff;
rabr = ((mlbm + numbuffs * 2) + 0x7ff) & ~0x7ff;
- sc->rsrb = ((rabr + 2048) + (2 * IFP2IFATM(sc->ifp)->mib.max_vccs - 1)) &
- ~(2 * IFP2IFATM(sc->ifp)->mib.max_vccs - 1);
+ sc->rsrb = roundup2(rabr + 2048, 2 * IFP2IFATM(sc->ifp)->mib.max_vccs);
tsra = 0;
sc->tsrb = tsra + IFP2IFATM(sc->ifp)->mib.max_vccs * 8;
sc->tsrc = sc->tsrb + IFP2IFATM(sc->ifp)->mib.max_vccs * 4;
sc->tsrd = sc->tsrc + IFP2IFATM(sc->ifp)->mib.max_vccs * 2;
tabr = sc->tsrd + IFP2IFATM(sc->ifp)->mib.max_vccs * 1;
- mtpd = ((tabr + 1024) + (16 * IFP2IFATM(sc->ifp)->mib.max_vccs - 1)) &
- ~(16 * IFP2IFATM(sc->ifp)->mib.max_vccs - 1);
+ mtpd = roundup2(tabr + 1024, 16 * IFP2IFATM(sc->ifp)->mib.max_vccs);
DBG(sc, ATTACH, ("rsra=%x mlbm=%x rabr=%x rsrb=%x",
rsra, mlbm, rabr, sc->rsrb));
diff --git a/sys/dev/hptmv/gui_lib.c b/sys/dev/hptmv/gui_lib.c
index a9feb4a..359a41e 100644
--- a/sys/dev/hptmv/gui_lib.c
+++ b/sys/dev/hptmv/gui_lib.c
@@ -783,8 +783,8 @@ simple:
for(i = 0; i < pArray->u.array.bArnMember; i++)
if(pArray->u.array.pMember[i]->VDeviceCapacity < capacity)
capacity = pArray->u.array.pMember[i]->VDeviceCapacity;
- pArray->VDeviceCapacity = (capacity & ~(pArray->u.array.bStripeWitch - 1))
- * (pArray->u.array.bArnMember - 1);
+ pArray->VDeviceCapacity = rounddown2(capacity, pArray->u.array.bStripeWitch) *
+ (pArray->u.array.bArnMember - 1);
break;
default:
diff --git a/sys/dev/mpr/mpr.c b/sys/dev/mpr/mpr.c
index ea8249b..6fe08b0 100644
--- a/sys/dev/mpr/mpr.c
+++ b/sys/dev/mpr/mpr.c
@@ -1084,8 +1084,8 @@ mpr_alloc_queues(struct mpr_softc *sc)
*
* These two queues are allocated together for simplicity.
*/
- sc->fqdepth = roundup2((sc->num_replies + 1), 16);
- sc->pqdepth = roundup2((sc->num_replies + 1), 16);
+ sc->fqdepth = roundup2(sc->num_replies + 1, 16);
+ sc->pqdepth = roundup2(sc->num_replies + 1, 16);
fqsize= sc->fqdepth * 4;
pqsize = sc->pqdepth * 8;
qsize = fqsize + pqsize;
diff --git a/sys/dev/mps/mps.c b/sys/dev/mps/mps.c
index 5f18341..ce24eed 100644
--- a/sys/dev/mps/mps.c
+++ b/sys/dev/mps/mps.c
@@ -1080,8 +1080,8 @@ mps_alloc_queues(struct mps_softc *sc)
*
* These two queues are allocated together for simplicity.
*/
- sc->fqdepth = roundup2((sc->num_replies + 1), 16);
- sc->pqdepth = roundup2((sc->num_replies + 1), 16);
+ sc->fqdepth = roundup2(sc->num_replies + 1, 16);
+ sc->pqdepth = roundup2(sc->num_replies + 1, 16);
fqsize= sc->fqdepth * 4;
pqsize = sc->pqdepth * 8;
qsize = fqsize + pqsize;
diff --git a/sys/dev/pccbb/pccbb.c b/sys/dev/pccbb/pccbb.c
index 067aa5a..c3a30fa 100644
--- a/sys/dev/pccbb/pccbb.c
+++ b/sys/dev/pccbb/pccbb.c
@@ -1155,7 +1155,7 @@ cbb_cardbus_auto_open(struct cbb_softc *sc, int type)
if (starts[i] == START_NONE)
continue;
starts[i] &= ~(align - 1);
- ends[i] = ((ends[i] + align - 1) & ~(align - 1)) - 1;
+ ends[i] = roundup2(ends[i], align) - 1;
}
if (starts[0] != START_NONE && starts[1] != START_NONE) {
if (starts[0] < starts[1]) {
diff --git a/sys/dev/pms/freebsd/driver/ini/src/agtiapi.c b/sys/dev/pms/freebsd/driver/ini/src/agtiapi.c
index fcdf6a3..640d341 100644
--- a/sys/dev/pms/freebsd/driver/ini/src/agtiapi.c
+++ b/sys/dev/pms/freebsd/driver/ini/src/agtiapi.c
@@ -5049,8 +5049,8 @@ STATIC void agtiapi_PrepCCBs( struct agtiapi_softc *pCard,
sizeof(tiSgl_t),
max_ccb );
- ccb_sz = (AGTIAPI_CCB_SIZE + cache_line_size() - 1) & ~(cache_line_size() -1);
- hdr_sz = (sizeof(*hdr) + cache_line_size() - 1) & ~(cache_line_size() - 1);
+ ccb_sz = roundup2(AGTIAPI_CCB_SIZE, cache_line_size());
+ hdr_sz = roundup2(sizeof(*hdr), cache_line_size());
AGTIAPI_PRINTK("agtiapi_PrepCCBs: after cache line\n");
@@ -5174,9 +5174,8 @@ STATIC U32 agtiapi_InitCCBs(struct agtiapi_softc *pCard, int tgtCount, int tid)
#endif
max_ccb = tgtCount * AGTIAPI_CCB_PER_DEVICE;// / 4; // TBR
- ccb_sz = ( (AGTIAPI_CCB_SIZE + cache_line_size() - 1) &
- ~(cache_line_size() -1) );
- hdr_sz = (sizeof(*hdr) + cache_line_size() - 1) & ~(cache_line_size() - 1);
+ ccb_sz = roundup2(AGTIAPI_CCB_SIZE, cache_line_size());
+ hdr_sz = roundup2(sizeof(*hdr), cache_line_size());
size = ccb_sz * max_ccb + hdr_sz;
for (i = 0; i < (1 << no_allocs); i++)
@@ -5854,7 +5853,7 @@ STATIC void agtiapi_ReleaseCCBs( struct agtiapi_softc *pCard )
while ((hdr = pCard->ccbAllocList) != NULL)
{
pCard->ccbAllocList = hdr->next;
- hdr_sz = (sizeof(*hdr) + cache_line_size() - 1) & ~(cache_line_size() - 1);
+ hdr_sz = roundup2(sizeof(*hdr), cache_line_size());
pccb = (ccb_t*) ((char*)hdr + hdr_sz);
if (pCard->buffer_dmat != NULL && pccb->CCB_dmamap != NULL)
{
diff --git a/sys/dev/sym/sym_hipd.c b/sys/dev/sym/sym_hipd.c
index 321fc60..0d0afdf 100644
--- a/sys/dev/sym/sym_hipd.c
+++ b/sys/dev/sym/sym_hipd.c
@@ -7903,7 +7903,7 @@ sym_scatter_sg_physical(hcb_p np, ccb_p cp, bus_dma_segment_t *psegs, int nsegs)
pe = ps + psegs[t].ds_len;
while (s >= 0) {
- pn = (pe - 1) & ~(SYM_CONF_DMA_BOUNDARY - 1);
+ pn = rounddown2(pe - 1, SYM_CONF_DMA_BOUNDARY);
if (pn <= ps)
pn = ps;
k = pe - pn;
diff --git a/sys/dev/ti/if_ti.c b/sys/dev/ti/if_ti.c
index 23ed50b..538d65d 100644
--- a/sys/dev/ti/if_ti.c
+++ b/sys/dev/ti/if_ti.c
@@ -434,7 +434,7 @@ ti_mem_read(struct ti_softc *sc, uint32_t addr, uint32_t len, void *buf)
segsize = cnt;
else
segsize = TI_WINLEN - (segptr % TI_WINLEN);
- CSR_WRITE_4(sc, TI_WINBASE, (segptr & ~(TI_WINLEN - 1)));
+ CSR_WRITE_4(sc, TI_WINBASE, rounddown2(segptr, TI_WINLEN));
bus_space_read_region_4(sc->ti_btag, sc->ti_bhandle,
TI_WINDOW + (segptr & (TI_WINLEN - 1)), (uint32_t *)ptr,
segsize / 4);
@@ -464,7 +464,7 @@ ti_mem_write(struct ti_softc *sc, uint32_t addr, uint32_t len, void *buf)
segsize = cnt;
else
segsize = TI_WINLEN - (segptr % TI_WINLEN);
- CSR_WRITE_4(sc, TI_WINBASE, (segptr & ~(TI_WINLEN - 1)));
+ CSR_WRITE_4(sc, TI_WINBASE, rounddown2(segptr, TI_WINLEN));
bus_space_write_region_4(sc->ti_btag, sc->ti_bhandle,
TI_WINDOW + (segptr & (TI_WINLEN - 1)), (uint32_t *)ptr,
segsize / 4);
@@ -491,7 +491,7 @@ ti_mem_zero(struct ti_softc *sc, uint32_t addr, uint32_t len)
segsize = cnt;
else
segsize = TI_WINLEN - (segptr % TI_WINLEN);
- CSR_WRITE_4(sc, TI_WINBASE, (segptr & ~(TI_WINLEN - 1)));
+ CSR_WRITE_4(sc, TI_WINBASE, rounddown2(segptr, TI_WINLEN));
bus_space_set_region_4(sc->ti_btag, sc->ti_bhandle,
TI_WINDOW + (segptr & (TI_WINLEN - 1)), 0, segsize / 4);
segptr += segsize;
@@ -559,7 +559,7 @@ ti_copy_mem(struct ti_softc *sc, uint32_t tigon_addr, uint32_t len,
segsize = cnt;
else
segsize = TI_WINLEN - (segptr % TI_WINLEN);
- CSR_WRITE_4(sc, TI_WINBASE, (segptr & ~(TI_WINLEN - 1)));
+ CSR_WRITE_4(sc, TI_WINBASE, rounddown2(segptr, TI_WINLEN));
ti_offset = TI_WINDOW + (segptr & (TI_WINLEN -1));
@@ -628,7 +628,7 @@ ti_copy_mem(struct ti_softc *sc, uint32_t tigon_addr, uint32_t len,
/*
* Set the segment pointer.
*/
- CSR_WRITE_4(sc, TI_WINBASE, (segptr & ~(TI_WINLEN - 1)));
+ CSR_WRITE_4(sc, TI_WINBASE, rounddown2(segptr, TI_WINLEN));
ti_offset = TI_WINDOW + (segptr & (TI_WINLEN - 1));
diff --git a/sys/dev/usb/usb_busdma.c b/sys/dev/usb/usb_busdma.c
index 75378a2..a52a909 100644
--- a/sys/dev/usb/usb_busdma.c
+++ b/sys/dev/usb/usb_busdma.c
@@ -467,7 +467,7 @@ usb_pc_common_mem_cb(void *arg, bus_dma_segment_t *segs,
off = 0;
pg = pc->page_start;
- pg->physaddr = segs->ds_addr & ~(USB_PAGE_SIZE - 1);
+ pg->physaddr = rounddown2(segs->ds_addr, USB_PAGE_SIZE);
rem = segs->ds_addr & (USB_PAGE_SIZE - 1);
pc->page_offset_buf = rem;
pc->page_offset_end += rem;
@@ -502,7 +502,7 @@ usb_pc_common_mem_cb(void *arg, bus_dma_segment_t *segs,
break;
}
pg++;
- pg->physaddr = (segs->ds_addr + off) & ~(USB_PAGE_SIZE - 1);
+ pg->physaddr = rounddown2(segs->ds_addr + off, USB_PAGE_SIZE);
}
done:
diff --git a/sys/dev/vt/hw/efifb/efifb.c b/sys/dev/vt/hw/efifb/efifb.c
index 27c10ee..9c99040 100644
--- a/sys/dev/vt/hw/efifb/efifb.c
+++ b/sys/dev/vt/hw/efifb/efifb.c
@@ -116,7 +116,7 @@ vt_efifb_init(struct vt_device *vd)
info->fb_depth = fls(efifb->fb_mask_red | efifb->fb_mask_green |
efifb->fb_mask_blue | efifb->fb_mask_reserved);
/* Round to a multiple of the bits in a byte. */
- info->fb_bpp = (info->fb_depth + NBBY - 1) & ~(NBBY - 1);
+ info->fb_bpp = roundup2(info->fb_depth, NBBY);
/* Stride in bytes, not pixels */
info->fb_stride = efifb->fb_stride * (info->fb_bpp / NBBY);
OpenPOWER on IntegriCloud