Deleted Added
full compact
18c18
< __FBSDID("$FreeBSD: head/sys/dev/ppbus/pps.c 185003 2008-11-16 17:42:02Z jhb $");
---
> __FBSDID("$FreeBSD: head/sys/dev/ppbus/pps.c 187576 2009-01-21 23:10:06Z jhb $");
20a21
> #include <sys/lock.h>
23a25
> #include <sys/sx.h>
46c48
< struct callout_handle timeout;
---
> struct callout timeout;
49c51
< struct mtx mtx;
---
> struct sx lock;
54c56
< static int ppsintr(void *arg);
---
> static void ppsintr(void *arg);
110c112
< int i, unit, rid = 0;
---
> int error, i, unit, rid = 0;
112,113d113
< mtx_init(&sc->mtx, device_get_nameunit(dev), "pps", MTX_SPIN);
<
119c119,120
< if (sc->intr_resource == NULL)
---
> if (sc->intr_resource == NULL) {
> device_printf(dev, "Unable to allocate interrupt resource\n");
120a122
> }
121a124,134
> error = bus_setup_intr(dev, sc->intr_resource,
> INTR_TYPE_TTY | INTR_MPSAFE, NULL, ppsintr,
> sc, &sc->intr_cookie);
> if (error) {
> bus_release_resource(dev, SYS_RES_IRQ, 0, sc->intr_resource);
> device_printf(dev, "Unable to register interrupt handler\n");
> return (error);
> }
>
> sx_init(&sc->lock, "pps");
> ppb_init_callout(ppbus, &sc->timeout, 0);
133c146,148
< if (ppb_request_bus(ppbus, dev, PPB_DONTWAIT))
---
> ppb_lock(ppbus);
> if (ppb_request_bus(ppbus, dev, PPB_DONTWAIT)) {
> ppb_unlock(ppbus);
134a150
> }
170a187
> ppb_unlock(ppbus);
180a198
> ppb_lock(ppbus);
183a202
> ppb_unlock(ppbus);
191a211
> device_t ppbus = sc->ppbus;
193c213
< int error, i;
---
> int i;
194a215,221
> /*
> * The sx lock is here solely to serialize open()'s to close
> * the race of concurrent open()'s when pps(4) doesn't own the
> * ppbus.
> */
> sx_xlock(&sc->lock);
> ppb_lock(ppbus);
197d223
< device_t ppbus = sc->ppbus;
199c225,227
< if (ppb_request_bus(ppbus, ppsdev, PPB_WAIT|PPB_INTR))
---
> if (ppb_request_bus(ppbus, ppsdev, PPB_WAIT|PPB_INTR)) {
> ppb_unlock(ppbus);
> sx_xunlock(&sc->lock);
201,207d228
<
< /* attach the interrupt handler */
< if ((error = bus_setup_intr(ppsdev, sc->intr_resource,
< (INTR_TYPE_TTY | INTR_MPSAFE), ppsintr, NULL,
< sc, &sc->intr_cookie))) {
< ppb_release_bus(ppbus, ppsdev);
< return (error);
217c238,239
< sc->timeout = timeout(ppshcpoll, sc, 1);
---
> /* XXX: Timeout of 1? hz/100 instead perhaps? */
> callout_reset(&sc->timeout, 1, ppshcpoll, sc);
220a243,244
> ppb_unlock(ppbus);
> sx_xunlock(&sc->lock);
229a254
> sx_xlock(&sc->lock);
230a256
> ppb_lock(sc->ppbus);
233c259
< untimeout(ppshcpoll, sc, sc->timeout);
---
> callout_stop(&sc->timeout);
241d266
< /* Note: the interrupt handler is automatically detached */
244a270,271
> ppb_unlock(sc->ppbus);
> sx_xunlock(&sc->lock);
254,257c281
< if (!(sc->busy & ~1))
< return;
< mtx_lock_spin(&sc->mtx);
< sc->timeout = timeout(ppshcpoll, sc, 1);
---
> KASSERT(sc->busy & ~1, ("pps polling w/o opened devices"));
272c296
< mtx_unlock_spin(&sc->mtx);
---
> callout_reset(&sc->timeout, 1, ppshcpoll, sc);
275c299
< static int
---
> static void
279a304
> ppb_assert_locked(sc->ppbus);
282c307,308
< return (FILTER_STRAY);
---
> return;
>
285d310
< mtx_lock_spin(&sc->mtx);
287d311
< mtx_unlock_spin(&sc->mtx);
290d313
< return (FILTER_HANDLED);
300c323
< mtx_lock_spin(&sc->mtx);
---
> ppb_lock(sc->ppbus);
302c325
< mtx_unlock_spin(&sc->mtx);
---
> ppb_unlock(sc->ppbus);