[<prev] [next>] [day] [month] [year] [list]
Message-ID: <20240326195927.3265297-1-chris.packham@alliedtelesis.co.nz>
Date: Wed, 27 Mar 2024 08:59:27 +1300
From: Chris Packham <chris.packham@...iedtelesis.co.nz>
To: gregkh@...uxfoundation.org
Cc: linux-kernel@...r.kernel.org,
Chris Packham <chris.packham@...iedtelesis.co.nz>
Subject: [PATCH] uio: use threaded interrupts
Split the existing uio_interrupt into a hardirq handler and a thread
function. The hardirq handler deals with the interrupt source in
hardware, the thread function notifies userspace that there is an event
to be handled.
Signed-off-by: Chris Packham <chris.packham@...iedtelesis.co.nz>
---
Notes:
I find myself needing to have a UIO interrupt associated with an
interrupt pin on a PCA9539 (yes I know, it's a terrible chip but HW
engineers love it because it's cheap).
Prior to this the UIO registration fails with:
[ 6.484699] uio_pdrv_genirq detect-gpio-9: unable to register uio device
[ 6.484722] uio_pdrv_genirq detect-gpio-9: probe with driver uio_pdrv_genirq failed with error -22
The -EINVAL ultimately comes from __setup_irq() where it knows the
interrupt descriptor is nested but we haven't provided a thread_fn.
drivers/uio/uio.c | 17 +++++++++++++----
1 file changed, 13 insertions(+), 4 deletions(-)
diff --git a/drivers/uio/uio.c b/drivers/uio/uio.c
index bb77de6fa067..a86cf2e4f200 100644
--- a/drivers/uio/uio.c
+++ b/drivers/uio/uio.c
@@ -442,18 +442,27 @@ EXPORT_SYMBOL_GPL(uio_event_notify);
* @irq: IRQ number, can be UIO_IRQ_CYCLIC for cyclic timer
* @dev_id: Pointer to the devices uio_device structure
*/
-static irqreturn_t uio_interrupt(int irq, void *dev_id)
+static irqreturn_t uio_interrupt_handler(int irq, void *dev_id)
{
struct uio_device *idev = (struct uio_device *)dev_id;
irqreturn_t ret;
ret = idev->info->handler(irq, idev->info);
if (ret == IRQ_HANDLED)
- uio_event_notify(idev->info);
+ ret = IRQ_WAKE_THREAD;
return ret;
}
+static irqreturn_t uio_interrupt_thread(int irq, void *dev_id)
+{
+ struct uio_device *idev = (struct uio_device *)dev_id;
+
+ uio_event_notify(idev->info);
+
+ return IRQ_HANDLED;
+}
+
struct uio_listener {
struct uio_device *dev;
s32 event_count;
@@ -1024,8 +1033,8 @@ int __uio_register_device(struct module *owner,
* FDs at the time of unregister and therefore may not be
* freed until they are released.
*/
- ret = request_irq(info->irq, uio_interrupt,
- info->irq_flags, info->name, idev);
+ ret = request_threaded_irq(info->irq, uio_interrupt_handler, uio_interrupt_thread,
+ info->irq_flags, info->name, idev);
if (ret) {
info->uio_dev = NULL;
goto err_request_irq;
--
2.43.2
Powered by blists - more mailing lists