Convert ltsleep() in atppc(4) to modern interfaces.

Reviewed by rmind@.
This commit is contained in:
jakllsch 2011-05-26 02:29:23 +00:00
parent ab866f07da
commit c0d7afac87
3 changed files with 62 additions and 117 deletions

View File

@ -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 @@ static void atppc_fifo_write_error(struct atppc_softc * const,
/* 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 @@ atppc_sc_attach(struct atppc_softc *lsc)
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 @@ atppc_sc_attach(struct atppc_softc *lsc)
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 @@ atppcintr(void *arg)
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 @@ atppcintr(void *arg)
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 @@ atppcintr(void *arg)
}
}
mutex_exit(&atppc->sc_lock);
return claim;
}
@ -736,18 +737,15 @@ static int
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 @@ atppc_read(device_t dev, char *buf, int len, int ioflag,
{
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 @@ atppc_read(device_t dev, char *buf, int len, int ioflag,
if (!(error))
error = atppc->sc_inerr;
ATPPC_UNLOCK(atppc);
splx(s);
mutex_exit(&atppc->sc_lock);
return (error);
}
@ -847,12 +842,10 @@ atppc_write(device_t dev, char *buf, int len, int ioflag, size_t *cnt)
{
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 @@ atppc_write(device_t dev, char *buf, int len, int ioflag, size_t *cnt)
if (!(error))
error = atppc->sc_outerr;
ATPPC_UNLOCK(atppc);
splx(s);
mutex_exit(&atppc->sc_lock);
return (error);
}
@ -919,11 +911,9 @@ atppc_setmode(device_t dev, int mode)
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 @@ atppc_setmode(device_t dev, int mode)
}
end:
ATPPC_UNLOCK(atppc);
splx(s);
mutex_exit(&atppc->sc_lock);
return rval;
}
@ -1052,10 +1041,8 @@ atppc_getmode(device_t dev)
{
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 @@ atppc_getmode(device_t dev)
break;
}
ATPPC_UNLOCK(atppc);
splx(s);
mutex_exit(&atppc->sc_lock);
return mode;
}
@ -1102,11 +1088,9 @@ atppc_ecp_sync(device_t dev)
{
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 @@ atppc_ecp_sync(device_t dev)
device_xname(dev)));
end:
ATPPC_UNLOCK(atppc);
splx(s);
mutex_exit(&atppc->sc_lock);
return;
}
@ -1149,15 +1132,13 @@ atppc_exec_microseq(device_t dev, struct ppbus_microseq **p_msq)
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 @@ atppc_exec_microseq(device_t dev, struct ppbus_microseq **p_msq)
*/
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 @@ atppc_exec_microseq(device_t dev, struct ppbus_microseq **p_msq)
/* 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 @@ atppc_io(device_t dev, int iop, u_char *addr, int cnt, u_char byte)
{
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_io(device_t dev, int iop, u_char *addr, int cnt, u_char byte)
atppc_barrier(atppc);
ATPPC_UNLOCK(atppc);
splx(s);
mutex_exit(&atppc->sc_lock);
return val;
}
@ -1489,10 +1465,8 @@ atppc_read_ivar(device_t dev, int index, unsigned int *val)
{
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 @@ atppc_read_ivar(device_t dev, int index, unsigned int *val)
rval = ENODEV;
}
ATPPC_UNLOCK(atppc);
splx(s);
mutex_exit(&atppc->sc_lock);
return rval;
}
@ -1527,10 +1500,8 @@ atppc_write_ivar(device_t dev, int index, unsigned int *val)
{
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 @@ atppc_write_ivar(device_t dev, int index, unsigned int *val)
rval = ENODEV;
}
ATPPC_UNLOCK(atppc);
splx(s);
mutex_exit(&atppc->sc_lock);
return rval;
}
@ -1575,10 +1545,6 @@ atppc_add_handler(device_t dev, void (*handler)(void *), void *arg)
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 @@ atppc_add_handler(device_t dev, void (*handler)(void *), void *arg)
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 @@ atppc_remove_handler(device_t dev, void (*handler)(void *))
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 @@ atppc_remove_handler(device_t dev, void (*handler)(void *))
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 @@ atppc_nibble_read(struct atppc_softc *atppc)
/* 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 @@ atppc_byte_read(struct atppc_softc * const atppc)
/* 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_ecp_read(struct atppc_softc *atppc)
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_ecp_read_dma(struct atppc_softc *atppc, unsigned int *length,
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 @@ atppc_std_write(struct atppc_softc * const atppc)
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_fifo_write_dma(struct atppc_softc * const atppc, unsigned char ecr,
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_fifo_write_dma(struct atppc_softc * const atppc, unsigned char ecr,
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_fifo_write_pio(struct atppc_softc * const atppc, unsigned char ecr,
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 @@ atppc_poll_str(const struct atppc_softc * const atppc, const u_int8_t status,
/* 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_wait_interrupt(struct atppc_softc * const atppc, const void *where,
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;

View File

@ -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 @@ extern int atppc_verbose;
#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 @@ struct atppc_softc {
/* 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;

View File

@ -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 @@ atppc_isa_attach(device_t parent, device_t self, void *aux)
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;
}