Date: Mon, 9 Jun 2025 12:15:21 +0300 From: Vladimir Kondratyev <wulf@FreeBSD.org> To: freebsd-current@freebsd.org Subject: Re: Adding kqueue to /dev/dsp Message-ID: <914a8f32-3e82-4ec6-bba7-1ae1d812f9ac@FreeBSD.org> In-Reply-To: <5a32b28b-97eb-43c1-82e0-e38e22a63822@tilda.center>
index | next in thread | previous in thread | raw e-mail
[-- Attachment #1 --]
On 6/4/25 20:01, Goran Mekić wrote:
> Hello,
>
> I already talked to christos@ and he's OK with me adding the support for kqueue
> to /dev/dsp, but I never saw any docs on how to implement it in the kernel.
> Could somebody advise on how to add kqueue support to existing device? I mean,
> if you could point out the simple device code with kqueue support, I would be
> glad to follow the logic there and learn, for start. Thank you!
>
> Regards,
> meka
>
>
Hi Goran,
See attached patch. It enables kqueue support for psm(4)
--
WBR
Vladimir Kondratyev
[-- Attachment #2 --]
From 2d4efd265bfeaea8e44c34ee796b69d99d3b12c5 Mon Sep 17 00:00:00 2001
From: Vladimir Kondratyev <wulf@FreeBSD.org>
Date: Thu, 15 May 2025 07:53:59 +0300
Subject: [PATCH] psm(4): Add kqueue support
---
sys/dev/atkbdc/psm.c | 45 ++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 45 insertions(+)
diff --git a/sys/dev/atkbdc/psm.c b/sys/dev/atkbdc/psm.c
index fbd9eb61fee..b429777a9d0 100644
--- a/sys/dev/atkbdc/psm.c
+++ b/sys/dev/atkbdc/psm.c
@@ -614,6 +614,7 @@ static d_read_t psmread;
static d_write_t psmwrite;
static d_ioctl_t psmioctl;
static d_poll_t psmpoll;
+static d_kqfilter_t psmkqfilter;
static int psmopen(struct psm_softc *);
static int psmclose(struct psm_softc *);
@@ -766,6 +767,7 @@ static struct cdevsw psm_cdevsw = {
.d_write = psmwrite,
.d_ioctl = psmioctl,
.d_poll = psmpoll,
+ .d_kqfilter = psmkqfilter,
.d_name = PSM_DRIVER_NAME,
};
@@ -1962,6 +1964,7 @@ psmattach(device_t dev)
sc->state = PSM_VALID;
callout_init(&sc->callout, 0);
callout_init(&sc->softcallout, 0);
+ knlist_init_mtx(&sc->rsel.si_note, &Giant);
/* Setup our interrupt handler */
rid = KBDC_RID_AUX;
@@ -2073,6 +2076,8 @@ psmdetach(device_t dev)
destroy_dev(sc->cdev);
destroy_dev(sc->bdev);
+ knlist_clear(&sc->rsel.si_note, 1);
+ knlist_destroy(&sc->rsel.si_note);
callout_drain(&sc->callout);
callout_drain(&sc->softcallout);
@@ -5229,6 +5234,7 @@ psmsoftintr(void *arg)
wakeup(sc);
}
selwakeuppri(&sc->rsel, PZERO);
+ KNOTE_LOCKED(&sc->rsel.si_note, 0);
if (sc->async != NULL) {
pgsigio(&sc->async, SIGIO, 0);
}
@@ -5266,6 +5272,45 @@ psmpoll(struct cdev *dev, int events, struct thread *td)
return (revents);
}
+static void
+psmfilter_detach(struct knote *kn)
+{
+ struct psm_softc *sc = kn->kn_hook;
+
+ knlist_remove(&sc->rsel.si_note, kn, 0);
+}
+
+static int
+psmfilter(struct knote *kn, long hint)
+{
+ struct psm_softc *sc = kn->kn_hook;
+
+ GIANT_REQUIRED;
+
+ return (sc->queue.count != 0 ? 1 : 0);
+}
+
+static const struct filterops psmfiltops = {
+ .f_isfd = 1,
+ .f_detach = psmfilter_detach,
+ .f_event = psmfilter,
+};
+
+static int
+psmkqfilter(struct cdev *dev, struct knote *kn)
+{
+ struct psm_softc *sc = dev->si_drv1;
+
+ if (kn->kn_filter != EVFILT_READ)
+ return(EOPNOTSUPP);
+
+ kn->kn_fop = &psmfiltops;
+ kn->kn_hook = sc;
+ knlist_add(&sc->rsel.si_note, kn, 1);
+
+ return (0);
+}
+
/* vendor/model specific routines */
static int mouse_id_proc1(KBDC kbdc, int res, int scale, int *status)
--
2.49.0
home |
help
Want to link to this message? Use this
URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?914a8f32-3e82-4ec6-bba7-1ae1d812f9ac>
