diff options
author | Martin Pieuchot <mpi@cvs.openbsd.org> | 2020-05-23 11:29:38 +0000 |
---|---|---|
committer | Martin Pieuchot <mpi@cvs.openbsd.org> | 2020-05-23 11:29:38 +0000 |
commit | 42ee7e0dbc62637f15933bd1000fd85819be4a65 (patch) | |
tree | 66a60c2b07d108d7af5c28eb07cccdcea382c428 /sys/arch | |
parent | ff4d2418094b88666386a8c284db164bae3b0eee (diff) |
Implement kqueue(2) support.
inputs & ok kettenis@
Diffstat (limited to 'sys/arch')
-rw-r--r-- | sys/arch/sparc64/dev/vldcp.c | 125 | ||||
-rw-r--r-- | sys/arch/sparc64/include/conf.h | 5 |
2 files changed, 127 insertions, 3 deletions
diff --git a/sys/arch/sparc64/dev/vldcp.c b/sys/arch/sparc64/dev/vldcp.c index 91255700c5f..22b63bb15cf 100644 --- a/sys/arch/sparc64/dev/vldcp.c +++ b/sys/arch/sparc64/dev/vldcp.c @@ -1,4 +1,4 @@ -/* $OpenBSD: vldcp.c,v 1.19 2019/12/19 12:04:38 reyk Exp $ */ +/* $OpenBSD: vldcp.c,v 1.20 2020/05/23 11:29:37 mpi Exp $ */ /* * Copyright (c) 2009, 2012 Mark Kettenis * @@ -70,6 +70,11 @@ struct vldcp_softc { int vldcp_match(struct device *, void *, void *); void vldcp_attach(struct device *, struct device *, void *); +void filt_vldcprdetach(struct knote *); +void filt_vldcpwdetach(struct knote *); +int filt_vldcpread(struct knote *, long); +int filt_vldcpwrite(struct knote *, long); +int vldcpkqfilter(dev_t, struct knote *); struct cfattach vldcp_ca = { sizeof(struct vldcp_softc), vldcp_match, vldcp_attach @@ -615,3 +620,121 @@ vldcppoll(dev_t dev, int events, struct proc *p) splx(s); return revents; } + +void +filt_vldcprdetach(struct knote *kn) +{ + struct vldcp_softc *sc = (void *)kn->kn_hook; + int s; + + s = spltty(); + klist_remove(&sc->sc_rsel.si_note, kn); + splx(s); +} + +void +filt_vldcpwdetach(struct knote *kn) +{ + struct vldcp_softc *sc = (void *)kn->kn_hook; + int s; + + s = spltty(); + klist_remove(&sc->sc_wsel.si_note, kn); + splx(s); +} + +int +filt_vldcpread(struct knote *kn, long hint) +{ + struct vldcp_softc *sc = (void *)kn->kn_hook; + struct ldc_conn *lc = &sc->sc_lc; + uint64_t head, tail, avail, state; + int s, err; + + s = spltty(); + err = hv_ldc_rx_get_state(lc->lc_id, &head, &tail, &state); + if (err == 0 && state == LDC_CHANNEL_UP && head != tail) { + avail = (tail - head) / sizeof(struct ldc_pkt) + + lc->lc_rxq->lq_nentries; + avail %= lc->lc_rxq->lq_nentries; + kn->kn_data = avail; + } else { + cbus_intr_setenabled(sc->sc_bustag, sc->sc_rx_ino, + INTR_ENABLED); + } + splx(s); + + return (kn->kn_data > 0); +} + +int +filt_vldcwrite(struct knote *kn, long hint) +{ + struct vldcp_softc *sc = (void *)kn->kn_hook; + struct ldc_conn *lc = &sc->sc_lc; + uint64_t head, tail, avail, state; + int s, err; + + s = spltty(); + err = hv_ldc_tx_get_state(lc->lc_id, &head, &tail, &state); + if (err == 0 && state == LDC_CHANNEL_UP && head != tail) { + avail = (head - tail) / sizeof(struct ldc_pkt) + + lc->lc_txq->lq_nentries - 1; + avail %= lc->lc_txq->lq_nentries; + kn->kn_data = avail; + } else { + cbus_intr_setenabled(sc->sc_bustag, sc->sc_tx_ino, + INTR_ENABLED); + } + splx(s); + + return (kn->kn_data > 0); +} + +const struct filterops vldcpread_filtops = { + .f_flags = FILTEROP_ISFD, + .f_attach = NULL, + .f_detach = filt_vldcprdetach, + .f_event = filt_vldcpread, +}; + +const struct filterops vldcpwrite_filtops = { + .f_flags = FILTEROP_ISFD, + .f_attach = NULL, + .f_detach = filt_vldcpwdetach, + .f_event = filt_vldcwrite, +}; + +int +vldcpkqfilter(dev_t dev, struct knote *kn) +{ + struct vldcp_softc *sc; + struct klist *klist; + int s; + + sc = vldcp_lookup(dev); + if (sc == NULL) + return (ENXIO); + + switch (kn->kn_filter) { + case EVFILT_READ: + klist = &sc->sc_rsel.si_note; + kn->kn_fop = &vldcpread_filtops; + break; + case EVFILT_WRITE: + klist = &sc->sc_wsel.si_note; + kn->kn_fop = &vldcpwrite_filtops; + break; + + default: + return (EINVAL); + } + + kn->kn_hook = sc; + + s = spltty(); + klist_insert(klist, kn); + splx(s); + + return (0); +} diff --git a/sys/arch/sparc64/include/conf.h b/sys/arch/sparc64/include/conf.h index 558c0c22ef7..1e10b53d048 100644 --- a/sys/arch/sparc64/include/conf.h +++ b/sys/arch/sparc64/include/conf.h @@ -1,4 +1,4 @@ -/* $OpenBSD: conf.h,v 1.25 2020/05/13 08:10:03 mpi Exp $ */ +/* $OpenBSD: conf.h,v 1.26 2020/05/23 11:29:37 mpi Exp $ */ /* $NetBSD: conf.h,v 1.9 2001/03/26 12:33:26 lukem Exp $ */ /*- @@ -64,7 +64,8 @@ cdev_decl(vdsp); #define cdev_gen_init(c,n) { \ dev_init(c,n,open), dev_init(c,n,close), dev_init(c,n,read), \ dev_init(c,n,write), dev_init(c,n,ioctl), (dev_type_stop((*))) nullop, \ - 0, dev_init(c,n,poll), (dev_type_mmap((*))) enodev } + 0, dev_init(c,n,poll), (dev_type_mmap((*))) enodev, \ + 0, 0, dev_init(c,n,kqfilter) } cdev_decl(cn); |