summaryrefslogtreecommitdiffstats
path: root/sys/pc98/cbus/sio.c
diff options
context:
space:
mode:
authorbmilekic <bmilekic@FreeBSD.org>2001-02-09 06:11:45 +0000
committerbmilekic <bmilekic@FreeBSD.org>2001-02-09 06:11:45 +0000
commitf364d4ac3621ae2689a3cc1b82c73eb491475a24 (patch)
tree84444d0341ce519800ed7913d826f5f38c622d6d /sys/pc98/cbus/sio.c
parent363bdddf694863339f6629340cfb324771b8ffe7 (diff)
downloadFreeBSD-src-f364d4ac3621ae2689a3cc1b82c73eb491475a24.zip
FreeBSD-src-f364d4ac3621ae2689a3cc1b82c73eb491475a24.tar.gz
Change and clean the mutex lock interface.
mtx_enter(lock, type) becomes: mtx_lock(lock) for sleep locks (MTX_DEF-initialized locks) mtx_lock_spin(lock) for spin locks (MTX_SPIN-initialized) similarily, for releasing a lock, we now have: mtx_unlock(lock) for MTX_DEF and mtx_unlock_spin(lock) for MTX_SPIN. We change the caller interface for the two different types of locks because the semantics are entirely different for each case, and this makes it explicitly clear and, at the same time, it rids us of the extra `type' argument. The enter->lock and exit->unlock change has been made with the idea that we're "locking data" and not "entering locked code" in mind. Further, remove all additional "flags" previously passed to the lock acquire/release routines with the exception of two: MTX_QUIET and MTX_NOSWITCH The functionality of these flags is preserved and they can be passed to the lock/unlock routines by calling the corresponding wrappers: mtx_{lock, unlock}_flags(lock, flag(s)) and mtx_{lock, unlock}_spin_flags(lock, flag(s)) for MTX_DEF and MTX_SPIN locks, respectively. Re-inline some lock acq/rel code; in the sleep lock case, we only inline the _obtain_lock()s in order to ensure that the inlined code fits into a cache line. In the spin lock case, we inline recursion and actually only perform a function call if we need to spin. This change has been made with the idea that we generally tend to avoid spin locks and that also the spin locks that we do have and are heavily used (i.e. sched_lock) do recurse, and therefore in an effort to reduce function call overhead for some architectures (such as alpha), we inline recursion for this case. Create a new malloc type for the witness code and retire from using the M_DEV type. The new type is called M_WITNESS and is only declared if WITNESS is enabled. Begin cleaning up some machdep/mutex.h code - specifically updated the "optimized" inlined code in alpha/mutex.h and wrote MTX_LOCK_SPIN and MTX_UNLOCK_SPIN asm macros for the i386/mutex.h as we presently need those. Finally, caught up to the interface changes in all sys code. Contributors: jake, jhb, jasone (in no particular order)
Diffstat (limited to 'sys/pc98/cbus/sio.c')
-rw-r--r--sys/pc98/cbus/sio.c86
1 files changed, 43 insertions, 43 deletions
diff --git a/sys/pc98/cbus/sio.c b/sys/pc98/cbus/sio.c
index fbc78bc..31914fe 100644
--- a/sys/pc98/cbus/sio.c
+++ b/sys/pc98/cbus/sio.c
@@ -1418,7 +1418,7 @@ sioprobe(dev, xrid)
* but mask them in the processor as well in case there are some
* (misconfigured) shared interrupts.
*/
- mtx_enter(&sio_lock, MTX_SPIN);
+ mtx_lock_spin(&sio_lock);
/* EXTRA DELAY? */
/*
@@ -1528,7 +1528,7 @@ sioprobe(dev, xrid)
CLR_FLAG(dev, COM_C_IIR_TXRDYBUG);
}
sio_setreg(com, com_cfcr, CFCR_8BITS);
- mtx_exit(&sio_lock, MTX_SPIN);
+ mtx_unlock_spin(&sio_lock);
bus_release_resource(dev, SYS_RES_IOPORT, rid, port);
return (iobase == siocniobase ? 0 : result);
}
@@ -1586,7 +1586,7 @@ sioprobe(dev, xrid)
}
#endif
- mtx_exit(&sio_lock, MTX_SPIN);
+ mtx_unlock_spin(&sio_lock);
irqs = irqmap[1] & ~irqmap[0];
if (bus_get_resource(idev, SYS_RES_IRQ, 0, &xirq, NULL) == 0 &&
@@ -1864,7 +1864,7 @@ sioattach(dev, xrid)
} else
com->it_in.c_ispeed = com->it_in.c_ospeed = TTYDEF_SPEED;
if (siosetwater(com, com->it_in.c_ispeed) != 0) {
- mtx_exit(&sio_lock, MTX_SPIN);
+ mtx_unlock_spin(&sio_lock);
/*
* Leave i/o resources allocated if this is a `cn'-level
* console, so that other devices can't snarf them.
@@ -1873,7 +1873,7 @@ sioattach(dev, xrid)
bus_release_resource(dev, SYS_RES_IOPORT, rid, port);
return (ENOMEM);
}
- mtx_exit(&sio_lock, MTX_SPIN);
+ mtx_unlock_spin(&sio_lock);
termioschars(&com->it_in);
com->it_out = com->it_in;
@@ -2274,7 +2274,7 @@ open_top:
}
}
- mtx_enter(&sio_lock, MTX_SPIN);
+ mtx_lock_spin(&sio_lock);
#ifdef PC98
if (IS_8251(com->pc98_if_type)) {
com_tiocm_bis(com, TIOCM_LE);
@@ -2302,7 +2302,7 @@ open_top:
#ifdef PC98
}
#endif
- mtx_exit(&sio_lock, MTX_SPIN);
+ mtx_unlock_spin(&sio_lock);
/*
* Handle initial DCD. Callout devices get a fake initial
* DCD (trapdoor DCD). If we are callout, then any sleeping
@@ -2625,7 +2625,7 @@ sioinput(com)
* semantics instead of the save-and-disable semantics
* that are used everywhere else.
*/
- mtx_exit(&sio_lock, MTX_SPIN);
+ mtx_unlock_spin(&sio_lock);
incc = com->iptr - buf;
if (tp->t_rawq.c_cc + incc > tp->t_ihiwat
&& (com->state & CS_RTS_IFLOW
@@ -2646,7 +2646,7 @@ sioinput(com)
tp->t_lflag &= ~FLUSHO;
comstart(tp);
}
- mtx_enter(&sio_lock, MTX_SPIN);
+ mtx_lock_spin(&sio_lock);
} while (buf < com->iptr);
} else {
do {
@@ -2655,7 +2655,7 @@ sioinput(com)
* semantics instead of the save-and-disable semantics
* that are used everywhere else.
*/
- mtx_exit(&sio_lock, MTX_SPIN);
+ mtx_unlock_spin(&sio_lock);
line_status = buf[com->ierroff];
recv_data = *buf++;
if (line_status
@@ -2670,7 +2670,7 @@ sioinput(com)
recv_data |= TTY_PE;
}
(*linesw[tp->t_line].l_rint)(recv_data, tp);
- mtx_enter(&sio_lock, MTX_SPIN);
+ mtx_lock_spin(&sio_lock);
} while (buf < com->iptr);
}
com_events -= (com->iptr - com->ibuf);
@@ -2712,9 +2712,9 @@ siointr(arg)
#ifndef COM_MULTIPORT
com = (struct com_s *)arg;
- mtx_enter(&sio_lock, MTX_SPIN);
+ mtx_lock_spin(&sio_lock);
siointr1(com);
- mtx_exit(&sio_lock, MTX_SPIN);
+ mtx_unlock_spin(&sio_lock);
#else /* COM_MULTIPORT */
bool_t possibly_more_intrs;
int unit;
@@ -2726,7 +2726,7 @@ siointr(arg)
* devices, then the edge from one may be lost because another is
* on.
*/
- mtx_enter(&sio_lock, MTX_SPIN);
+ mtx_lock_spin(&sio_lock);
do {
possibly_more_intrs = FALSE;
for (unit = 0; unit < sio_numunits; ++unit) {
@@ -2764,7 +2764,7 @@ siointr(arg)
/* XXX COM_UNLOCK(); */
}
} while (possibly_more_intrs);
- mtx_exit(&sio_lock, MTX_SPIN);
+ mtx_unlock_spin(&sio_lock);
#endif /* COM_MULTIPORT */
}
@@ -3361,7 +3361,7 @@ repeat:
* Discard any events related to never-opened or
* going-away devices.
*/
- mtx_enter(&sio_lock, MTX_SPIN);
+ mtx_lock_spin(&sio_lock);
incc = com->iptr - com->ibuf;
com->iptr = com->ibuf;
if (com->state & CS_CHECKMSR) {
@@ -3369,13 +3369,13 @@ repeat:
com->state &= ~CS_CHECKMSR;
}
com_events -= incc;
- mtx_exit(&sio_lock, MTX_SPIN);
+ mtx_unlock_spin(&sio_lock);
continue;
}
if (com->iptr != com->ibuf) {
- mtx_enter(&sio_lock, MTX_SPIN);
+ mtx_lock_spin(&sio_lock);
sioinput(com);
- mtx_exit(&sio_lock, MTX_SPIN);
+ mtx_unlock_spin(&sio_lock);
}
if (com->state & CS_CHECKMSR) {
u_char delta_modem_status;
@@ -3383,13 +3383,13 @@ repeat:
#ifdef PC98
if (!IS_8251(com->pc98_if_type)) {
#endif
- mtx_enter(&sio_lock, MTX_SPIN);
+ mtx_lock_spin(&sio_lock);
delta_modem_status = com->last_modem_status
^ com->prev_modem_status;
com->prev_modem_status = com->last_modem_status;
com_events -= LOTS_OF_EVENTS;
com->state &= ~CS_CHECKMSR;
- mtx_exit(&sio_lock, MTX_SPIN);
+ mtx_unlock_spin(&sio_lock);
if (delta_modem_status & MSR_DCD)
(*linesw[tp->t_line].l_modem)
(tp, com->prev_modem_status & MSR_DCD);
@@ -3398,10 +3398,10 @@ repeat:
#endif
}
if (com->state & CS_ODONE) {
- mtx_enter(&sio_lock, MTX_SPIN);
+ mtx_lock_spin(&sio_lock);
com_events -= LOTS_OF_EVENTS;
com->state &= ~CS_ODONE;
- mtx_exit(&sio_lock, MTX_SPIN);
+ mtx_unlock_spin(&sio_lock);
if (!(com->state & CS_BUSY)
&& !(com->extra_state & CSE_BUSYCHECK)) {
timeout(siobusycheck, com, hz / 100);
@@ -3665,7 +3665,7 @@ comparam(tp, t)
if (com->state >= (CS_BUSY | CS_TTGO))
siointr1(com);
- mtx_exit(&sio_lock, MTX_SPIN);
+ mtx_unlock_spin(&sio_lock);
splx(s);
comstart(tp);
if (com->ibufold != NULL) {
@@ -3703,7 +3703,7 @@ siosetwater(com, speed)
ibufsize = 2048;
#endif
if (ibufsize == com->ibufsize) {
- mtx_enter(&sio_lock, MTX_SPIN);
+ mtx_lock_spin(&sio_lock);
return (0);
}
@@ -3713,7 +3713,7 @@ siosetwater(com, speed)
*/
ibuf = malloc(2 * ibufsize, M_DEVBUF, M_NOWAIT);
if (ibuf == NULL) {
- mtx_enter(&sio_lock, MTX_SPIN);
+ mtx_lock_spin(&sio_lock);
return (ENOMEM);
}
@@ -3731,7 +3731,7 @@ siosetwater(com, speed)
* Read current input buffer, if any. Continue with interrupts
* disabled.
*/
- mtx_enter(&sio_lock, MTX_SPIN);
+ mtx_lock_spin(&sio_lock);
if (com->iptr != com->ibuf)
sioinput(com);
@@ -3766,7 +3766,7 @@ comstart(tp)
if (com == NULL)
return;
s = spltty();
- mtx_enter(&sio_lock, MTX_SPIN);
+ mtx_lock_spin(&sio_lock);
if (tp->t_state & TS_TTSTOP)
com->state &= ~CS_TTGO;
else
@@ -3805,7 +3805,7 @@ comstart(tp)
outb(com->modem_ctl_port, com->mcr_image |= MCR_RTS);
#endif
}
- mtx_exit(&sio_lock, MTX_SPIN);
+ mtx_unlock_spin(&sio_lock);
if (tp->t_state & (TS_TIMEOUT | TS_TTSTOP)) {
ttwwakeup(tp);
splx(s);
@@ -3825,7 +3825,7 @@ comstart(tp)
#endif
com->obufs[0].l_next = NULL;
com->obufs[0].l_queued = TRUE;
- mtx_enter(&sio_lock, MTX_SPIN);
+ mtx_lock_spin(&sio_lock);
if (com->state & CS_BUSY) {
qp = com->obufq.l_next;
while ((next = qp->l_next) != NULL)
@@ -3837,7 +3837,7 @@ comstart(tp)
com->obufq.l_next = &com->obufs[0];
com->state |= CS_BUSY;
}
- mtx_exit(&sio_lock, MTX_SPIN);
+ mtx_unlock_spin(&sio_lock);
}
if (tp->t_outq.c_cc != 0 && !com->obufs[1].l_queued) {
com->obufs[1].l_tail
@@ -3849,7 +3849,7 @@ comstart(tp)
#endif
com->obufs[1].l_next = NULL;
com->obufs[1].l_queued = TRUE;
- mtx_enter(&sio_lock, MTX_SPIN);
+ mtx_lock_spin(&sio_lock);
if (com->state & CS_BUSY) {
qp = com->obufq.l_next;
while ((next = qp->l_next) != NULL)
@@ -3861,14 +3861,14 @@ comstart(tp)
com->obufq.l_next = &com->obufs[1];
com->state |= CS_BUSY;
}
- mtx_exit(&sio_lock, MTX_SPIN);
+ mtx_unlock_spin(&sio_lock);
}
tp->t_state |= TS_BUSY;
}
- mtx_enter(&sio_lock, MTX_SPIN);
+ mtx_lock_spin(&sio_lock);
if (com->state >= (CS_BUSY | CS_TTGO))
siointr1(com); /* fake interrupt to start output */
- mtx_exit(&sio_lock, MTX_SPIN);
+ mtx_unlock_spin(&sio_lock);
ttwwakeup(tp);
splx(s);
}
@@ -3886,7 +3886,7 @@ comstop(tp, rw)
com = com_addr(DEV_TO_UNIT(tp->t_dev));
if (com == NULL || com->gone)
return;
- mtx_enter(&sio_lock, MTX_SPIN);
+ mtx_lock_spin(&sio_lock);
if (rw & FWRITE) {
#ifdef PC98
if (!IS_8251(com->pc98_if_type)) {
@@ -3932,7 +3932,7 @@ comstop(tp, rw)
com_events -= (com->iptr - com->ibuf);
com->iptr = com->ibuf;
}
- mtx_exit(&sio_lock, MTX_SPIN);
+ mtx_unlock_spin(&sio_lock);
comstart(tp);
}
@@ -3975,7 +3975,7 @@ commctl(com, bits, how)
mcr |= MCR_RTS;
if (com->gone)
return(0);
- mtx_enter(&sio_lock, MTX_SPIN);
+ mtx_lock_spin(&sio_lock);
switch (how) {
case DMSET:
outb(com->modem_ctl_port,
@@ -3988,7 +3988,7 @@ commctl(com, bits, how)
outb(com->modem_ctl_port, com->mcr_image &= ~mcr);
break;
}
- mtx_exit(&sio_lock, MTX_SPIN);
+ mtx_unlock_spin(&sio_lock);
return (0);
}
@@ -4047,9 +4047,9 @@ comwakeup(chan)
com = com_addr(unit);
if (com != NULL && !com->gone
&& (com->state >= (CS_BUSY | CS_TTGO) || com->poll)) {
- mtx_enter(&sio_lock, MTX_SPIN);
+ mtx_lock_spin(&sio_lock);
siointr1(com);
- mtx_exit(&sio_lock, MTX_SPIN);
+ mtx_unlock_spin(&sio_lock);
}
}
@@ -4071,10 +4071,10 @@ comwakeup(chan)
u_int delta;
u_long total;
- mtx_enter(&sio_lock, MTX_SPIN);
+ mtx_lock_spin(&sio_lock);
delta = com->delta_error_counts[errnum];
com->delta_error_counts[errnum] = 0;
- mtx_exit(&sio_lock, MTX_SPIN);
+ mtx_unlock_spin(&sio_lock);
if (delta == 0)
continue;
total = com->error_counts[errnum] += delta;
OpenPOWER on IntegriCloud