Module Name: src
Committed By: jakllsch
Date: Thu May 26 02:29:23 UTC 2011
Modified Files:
src/sys/dev/ic: atppc.c atppcvar.h
src/sys/dev/isa: atppc_isa.c
Log Message:
Convert ltsleep() in atppc(4) to modern interfaces.
Reviewed by rmind@.
To generate a diff of this commit:
cvs rdiff -u -r1.28 -r1.29 src/sys/dev/ic/atppc.c
cvs rdiff -u -r1.11 -r1.12 src/sys/dev/ic/atppcvar.h
cvs rdiff -u -r1.14 -r1.15 src/sys/dev/isa/atppc_isa.c
Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.
Modified files:
Index: src/sys/dev/ic/atppc.c
diff -u src/sys/dev/ic/atppc.c:1.28 src/sys/dev/ic/atppc.c:1.29
--- src/sys/dev/ic/atppc.c:1.28 Tue Dec 16 22:35:30 2008
+++ src/sys/dev/ic/atppc.c Thu May 26 02:29:23 2011
@@ -1,4 +1,4 @@
-/* $NetBSD: atppc.c,v 1.28 2008/12/16 22:35:30 christos Exp $ */
+/* $NetBSD: atppc.c,v 1.29 2011/05/26 02:29:23 jakllsch Exp $ */
/*
* Copyright (c) 2001 Alcove - Nicolas Souchu
@@ -31,7 +31,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: atppc.c,v 1.28 2008/12/16 22:35:30 christos Exp $");
+__KERNEL_RCSID(0, "$NetBSD: atppc.c,v 1.29 2011/05/26 02:29:23 jakllsch Exp $");
#include "opt_atppc.h"
@@ -131,7 +131,7 @@
/* Miscellaneous */
static int atppc_poll_str(const struct atppc_softc * const, const u_int8_t,
const u_int8_t);
-static int atppc_wait_interrupt(struct atppc_softc * const, const void *,
+static int atppc_wait_interrupt(struct atppc_softc * const, kcondvar_t *,
const u_int8_t);
@@ -148,7 +148,9 @@
struct parport_adapter sc_parport_adapter;
char buf[64];
- ATPPC_LOCK_INIT(lsc);
+ mutex_init(&lsc->sc_lock, MUTEX_DEFAULT, IPL_TTY);
+ cv_init(&lsc->sc_out_cv, "atppcout");
+ cv_init(&lsc->sc_in_cv, "atppcin");
/* Probe and set up chipset */
if (atppc_detect_chipset(lsc) != 0) {
@@ -181,11 +183,6 @@
device_xname(lsc->sc_dev)));
}
-#if defined (MULTIPROCESSOR) || defined (LOCKDEBUG)
- /* Initialize lock structure */
- simple_lock_init(&(lsc->sc_lock));
-#endif
-
/* Set up parport_adapter structure */
/* Set capabilites */
@@ -616,6 +613,8 @@
int claim = 1;
enum { NONE, READER, WRITER } wake_up = NONE;
+ mutex_enter(&atppc->sc_lock);
+
/* Record registers' status */
atppc->sc_str_intr = atppc_r_str(atppc);
atppc->sc_ctr_intr = atppc_r_ctr(atppc);
@@ -706,11 +705,11 @@
break;
case READER:
- wakeup(atppc->sc_inb);
+ cv_broadcast(&atppc->sc_in_cv);
break;
case WRITER:
- wakeup(atppc->sc_outb);
+ cv_broadcast(&atppc->sc_out_cv);
break;
}
}
@@ -724,6 +723,8 @@
}
}
+ mutex_exit(&atppc->sc_lock);
+
return claim;
}
@@ -736,18 +737,15 @@
atppc_check_epp_timeout(device_t dev)
{
struct atppc_softc *atppc = device_private(dev);
- int s;
int error;
- s = splatppc();
- ATPPC_LOCK(atppc);
+ mutex_enter(&atppc->sc_lock);
atppc_reset_epp_timeout(dev);
error = !(atppc_r_str(atppc) & TIMEOUT);
atppc_barrier_r(atppc);
- ATPPC_UNLOCK(atppc);
- splx(s);
+ mutex_exit(&atppc->sc_lock);
return (error);
}
@@ -783,10 +781,8 @@
{
struct atppc_softc *atppc = device_private(dev);
int error = 0;
- int s;
- s = splatppc();
- ATPPC_LOCK(atppc);
+ mutex_enter(&atppc->sc_lock);
*cnt = 0;
@@ -835,8 +831,7 @@
if (!(error))
error = atppc->sc_inerr;
- ATPPC_UNLOCK(atppc);
- splx(s);
+ mutex_exit(&atppc->sc_lock);
return (error);
}
@@ -847,12 +842,10 @@
{
struct atppc_softc * const atppc = device_private(dev);
int error = 0;
- int s;
*cnt = 0;
- s = splatppc();
- ATPPC_LOCK(atppc);
+ mutex_enter(&atppc->sc_lock);
/* Set up line buffer */
atppc->sc_outb = atppc->sc_outbstart = buf;
@@ -896,8 +889,7 @@
if (!(error))
error = atppc->sc_outerr;
- ATPPC_UNLOCK(atppc);
- splx(s);
+ mutex_exit(&atppc->sc_lock);
return (error);
}
@@ -919,11 +911,9 @@
struct atppc_softc *atppc = device_private(dev);
u_int8_t ecr;
u_int8_t chipset_mode;
- int s;
int rval = 0;
- s = splatppc();
- ATPPC_LOCK(atppc);
+ mutex_enter(&atppc->sc_lock);
/* If ECP capable, configure ecr register */
if (atppc->sc_has & ATPPC_HAS_ECP) {
@@ -1040,8 +1030,7 @@
}
end:
- ATPPC_UNLOCK(atppc);
- splx(s);
+ mutex_exit(&atppc->sc_lock);
return rval;
}
@@ -1052,10 +1041,8 @@
{
struct atppc_softc *atppc = device_private(dev);
int mode;
- int s;
- s = splatppc();
- ATPPC_LOCK(atppc);
+ mutex_enter(&atppc->sc_lock);
/* The chipset can only be in one mode at a time logically */
switch (atppc->sc_mode) {
@@ -1089,8 +1076,7 @@
break;
}
- ATPPC_UNLOCK(atppc);
- splx(s);
+ mutex_exit(&atppc->sc_lock);
return mode;
}
@@ -1102,11 +1088,9 @@
{
struct atppc_softc *atppc = device_private(dev);
int i;
- int s;
u_int8_t r;
- s = splatppc();
- ATPPC_LOCK(atppc);
+ mutex_enter(&atppc->sc_lock);
/*
* Only wait for FIFO to empty if mode is chipset is ECP-capable AND
@@ -1134,8 +1118,7 @@
device_xname(dev)));
end:
- ATPPC_UNLOCK(atppc);
- splx(s);
+ mutex_exit(&atppc->sc_lock);
return;
}
@@ -1149,15 +1132,13 @@
char cc, *p;
int i, iter, len;
int error;
- int s;
register int reg;
register unsigned char mask;
register int accum = 0;
register char *ptr = NULL;
struct ppbus_microseq *stack = NULL;
- s = splatppc();
- ATPPC_LOCK(atppc);
+ mutex_enter(&atppc->sc_lock);
/* microsequence registers are equivalent to PC-like port registers */
@@ -1318,8 +1299,7 @@
*/
if ((error = mi->arg[0].f(mi->arg[1].p,
atppc->sc_ptr))) {
- ATPPC_UNLOCK(atppc);
- splx(s);
+ mutex_exit(&atppc->sc_lock);
return (error);
}
mi++;
@@ -1373,8 +1353,7 @@
/* update pc for atppc level of execution */
*p_msq = mi;
- ATPPC_UNLOCK(atppc);
- splx(s);
+ mutex_exit(&atppc->sc_lock);
return (0);
break;
@@ -1397,10 +1376,8 @@
{
struct atppc_softc *atppc = device_private(dev);
u_int8_t val = 0;
- int s;
- s = splatppc();
- ATPPC_LOCK(atppc);
+ mutex_enter(&atppc->sc_lock);
switch (iop) {
case PPBUS_OUTSB_EPP:
@@ -1477,8 +1454,7 @@
atppc_barrier(atppc);
- ATPPC_UNLOCK(atppc);
- splx(s);
+ mutex_exit(&atppc->sc_lock);
return val;
}
@@ -1489,10 +1465,8 @@
{
struct atppc_softc *atppc = device_private(dev);
int rval = 0;
- int s;
- s = splatppc();
- ATPPC_LOCK(atppc);
+ mutex_enter(&atppc->sc_lock);
switch(index) {
case PPBUS_IVAR_EPP_PROTO:
@@ -1515,8 +1489,7 @@
rval = ENODEV;
}
- ATPPC_UNLOCK(atppc);
- splx(s);
+ mutex_exit(&atppc->sc_lock);
return rval;
}
@@ -1527,10 +1500,8 @@
{
struct atppc_softc *atppc = device_private(dev);
int rval = 0;
- int s;
- s = splatppc();
- ATPPC_LOCK(atppc);
+ mutex_enter(&atppc->sc_lock);
switch(index) {
case PPBUS_IVAR_EPP_PROTO:
@@ -1562,8 +1533,7 @@
rval = ENODEV;
}
- ATPPC_UNLOCK(atppc);
- splx(s);
+ mutex_exit(&atppc->sc_lock);
return rval;
}
@@ -1575,10 +1545,6 @@
struct atppc_softc *atppc = device_private(dev);
struct atppc_handler_node *callback;
int rval = 0;
- int s;
-
- s = splatppc();
- ATPPC_LOCK(atppc);
if (handler == NULL) {
ATPPC_DPRINTF(("%s(%s): attempt to register NULL handler.\n",
@@ -1590,16 +1556,15 @@
if (callback) {
callback->func = handler;
callback->arg = arg;
+ mutex_enter(&atppc->sc_lock);
SLIST_INSERT_HEAD(&(atppc->sc_handler_listhead),
callback, entries);
+ mutex_exit(&atppc->sc_lock);
} else {
rval = ENOMEM;
}
}
- ATPPC_UNLOCK(atppc);
- splx(s);
-
return rval;
}
@@ -1610,10 +1575,8 @@
struct atppc_softc *atppc = device_private(dev);
struct atppc_handler_node *callback;
int rval = EINVAL;
- int s;
- s = splatppc();
- ATPPC_LOCK(atppc);
+ mutex_enter(&atppc->sc_lock);
if (SLIST_EMPTY(&(atppc->sc_handler_listhead)))
panic("%s(%s): attempt to remove handler from empty list.\n",
@@ -1624,14 +1587,16 @@
if (callback->func == handler) {
SLIST_REMOVE(&(atppc->sc_handler_listhead), callback,
atppc_handler_node, entries);
- free(callback, M_DEVBUF);
rval = 0;
break;
}
}
- ATPPC_UNLOCK(atppc);
- splx(s);
+ mutex_exit(&atppc->sc_lock);
+
+ if (rval == 0) {
+ free(callback, M_DEVBUF);
+ }
return rval;
}
@@ -1702,7 +1667,7 @@
/* Event 11 - wait ack from peripherial */
if (atppc->sc_use & ATPPC_USE_INTR)
atppc->sc_inerr = atppc_wait_interrupt(atppc,
- atppc->sc_inb, ATPPC_IRQ_nACK);
+ &atppc->sc_in_cv, ATPPC_IRQ_nACK);
else
atppc->sc_inerr = atppc_poll_str(atppc, PTRCLK,
PTRCLK);
@@ -1773,7 +1738,7 @@
/* Event 11 - peripheral ack */
if (atppc->sc_use & ATPPC_USE_INTR)
atppc->sc_inerr = atppc_wait_interrupt(atppc,
- atppc->sc_inb, ATPPC_IRQ_nACK);
+ &atppc->sc_in_cv, ATPPC_IRQ_nACK);
else
atppc->sc_inerr = atppc_poll_str(atppc, PTRCLK, PTRCLK);
if (atppc->sc_inerr)
@@ -1876,7 +1841,7 @@
atppc_barrier_w(atppc);
/* Wait for FIFO to fill */
atppc->sc_inerr = atppc_wait_interrupt(atppc,
- atppc->sc_inb, ATPPC_IRQ_FIFO);
+ &atppc->sc_in_cv, ATPPC_IRQ_FIFO);
if (atppc->sc_inerr)
break;
} else {
@@ -1938,7 +1903,7 @@
atppc_barrier_w(atppc);
/* Wait for DMA completion */
- atppc->sc_inerr = atppc_wait_interrupt(atppc, atppc->sc_inb,
+ atppc->sc_inerr = atppc_wait_interrupt(atppc, &atppc->sc_in_cv,
ATPPC_IRQ_DMA);
if (atppc->sc_inerr)
return;
@@ -2036,7 +2001,7 @@
timecount = 0;
if (atppc->sc_use & ATPPC_USE_INTR) {
atppc->sc_outerr = atppc_wait_interrupt(atppc,
- atppc->sc_outb, ATPPC_IRQ_nACK);
+ &atppc->sc_out_cv, ATPPC_IRQ_nACK);
if (atppc->sc_outerr)
return;
} else {
@@ -2165,8 +2130,8 @@
atppc_barrier_w(atppc);
/* Wait for DMA completion */
- atppc->sc_outerr = atppc_wait_interrupt(atppc, atppc->sc_outb,
- ATPPC_IRQ_DMA);
+ atppc->sc_outerr = atppc_wait_interrupt(atppc,
+ &atppc->sc_out_cv, ATPPC_IRQ_DMA);
if (atppc->sc_outerr) {
atppc_fifo_write_error(atppc, worklen);
return;
@@ -2199,7 +2164,7 @@
atppc_barrier_w(atppc);
atppc->sc_outerr = atppc_wait_interrupt(atppc,
- atppc->sc_outb, ATPPC_IRQ_FIFO);
+ &atppc->sc_out_cv, ATPPC_IRQ_FIFO);
if (atppc->sc_outerr) {
atppc_fifo_write_error(atppc, worklen);
return;
@@ -2266,7 +2231,7 @@
atppc_barrier_w(atppc);
atppc->sc_outerr = atppc_wait_interrupt(atppc,
- atppc->sc_outb, ATPPC_IRQ_FIFO);
+ &atppc->sc_out_cv, ATPPC_IRQ_FIFO);
if (atppc->sc_outerr) {
atppc_fifo_write_error(atppc, worklen);
return;
@@ -2388,7 +2353,7 @@
/* Wait for interrupt for MAXBUSYWAIT: returns 0 if acknowledge received. */
static int
-atppc_wait_interrupt(struct atppc_softc * const atppc, const void *where,
+atppc_wait_interrupt(struct atppc_softc * const atppc, kcondvar_t *cv,
const u_int8_t irqstat)
{
int error = EIO;
@@ -2396,8 +2361,7 @@
atppc->sc_irqstat &= ~irqstat;
/* Wait for interrupt for MAXBUSYWAIT */
- error = ltsleep(where, PPBUSPRI | PCATCH, __func__, MAXBUSYWAIT,
- ATPPC_SC_LOCK(atppc));
+ error = cv_timedwait_sig(cv, &atppc->sc_lock, MAXBUSYWAIT);
if (!(error) && (atppc->sc_irqstat & irqstat)) {
atppc->sc_irqstat &= ~irqstat;
Index: src/sys/dev/ic/atppcvar.h
diff -u src/sys/dev/ic/atppcvar.h:1.11 src/sys/dev/ic/atppcvar.h:1.12
--- src/sys/dev/ic/atppcvar.h:1.11 Thu May 1 12:06:28 2008
+++ src/sys/dev/ic/atppcvar.h Thu May 26 02:29:23 2011
@@ -1,4 +1,4 @@
-/* $NetBSD: atppcvar.h,v 1.11 2008/05/01 12:06:28 cegger Exp $ */
+/* $NetBSD: atppcvar.h,v 1.12 2011/05/26 02:29:23 jakllsch Exp $ */
/*-
* Copyright (c) 2001 Alcove - Nicolas Souchu
@@ -36,7 +36,8 @@
#include <machine/types.h>
#include <sys/device.h>
#include <sys/callout.h>
-#include <sys/simplelock.h>
+#include <sys/mutex.h>
+#include <sys/condvar.h>
#include <dev/ppbus/ppbus_conf.h>
@@ -44,13 +45,9 @@
/* Maximum time to wait for device response */
#define MAXBUSYWAIT (5 * (hz))
-/* Poll interval when wating for device to become ready */
+/* Poll interval when waiting for device to become ready */
#define ATPPC_POLL ((hz)/10)
-/* Interrupt priority level for atppc device */
-#define IPL_ATPPC IPL_TTY
-#define splatppc spltty
-
/* Diagnostic and verbose printing macros */
@@ -78,21 +75,6 @@
#define ATPPC_FLAG_DISABLE_INTR 0x01
#define ATPPC_FLAG_DISABLE_DMA 0x02
-
-/* Locking for atppc device */
-#if defined(MULTIPROCESSOR) || defined (LOCKDEBUG)
-#include <sys/lock.h>
-#define ATPPC_SC_LOCK(sc) (&((sc)->sc_lock))
-#define ATPPC_LOCK_INIT(sc) simple_lock_init(ATPPC_SC_LOCK((sc)))
-#define ATPPC_LOCK(sc) simple_lock(ATPPC_SC_LOCK((sc)))
-#define ATPPC_UNLOCK(sc) simple_unlock(ATPPC_SC_LOCK((sc)))
-#else /* !(MULTIPROCESSOR) && !(LOCKDEBUG) */
-#define ATPPC_LOCK_INIT(sc)
-#define ATPPC_LOCK(sc)
-#define ATPPC_UNLOCK(sc)
-#define ATPPC_SC_LOCK(sc) NULL
-#endif /* MULTIPROCESSOR || LOCKDEBUG */
-
/* Single softintr callback entry */
struct atppc_handler_node {
void (*func)(void *);
@@ -105,10 +87,9 @@
/* Generic device attributes */
device_t sc_dev;
-#if defined(MULTIPROCESSOR) || defined(LOCKDEBUG)
- /* Simple lock */
- struct simplelock sc_lock;
-#endif
+ kmutex_t sc_lock;
+ kcondvar_t sc_out_cv;
+ kcondvar_t sc_in_cv;
/* Machine independent bus infrastructure */
bus_space_tag_t sc_iot;
Index: src/sys/dev/isa/atppc_isa.c
diff -u src/sys/dev/isa/atppc_isa.c:1.14 src/sys/dev/isa/atppc_isa.c:1.15
--- src/sys/dev/isa/atppc_isa.c:1.14 Wed Apr 16 09:39:01 2008
+++ src/sys/dev/isa/atppc_isa.c Thu May 26 02:29:23 2011
@@ -1,4 +1,4 @@
-/* $NetBSD: atppc_isa.c,v 1.14 2008/04/16 09:39:01 cegger Exp $ */
+/* $NetBSD: atppc_isa.c,v 1.15 2011/05/26 02:29:23 jakllsch Exp $ */
/*-
* Copyright (c) 2001 Alcove - Nicolas Souchu
@@ -30,7 +30,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: atppc_isa.c,v 1.14 2008/04/16 09:39:01 cegger Exp $");
+__KERNEL_RCSID(0, "$NetBSD: atppc_isa.c,v 1.15 2011/05/26 02:29:23 jakllsch Exp $");
#include "opt_atppc.h"
@@ -166,7 +166,7 @@
if (sc->sc_irq > 0) {
/* Establish interrupt handler. */
lsc->sc_ieh = isa_intr_establish(sc->sc_ic, sc->sc_irq,
- IST_EDGE, IPL_ATPPC, atppcintr, lsc->sc_dev);
+ IST_EDGE, IPL_TTY, atppcintr, lsc->sc_dev);
lsc->sc_has |= ATPPC_HAS_INTR;
}