[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20240412045536.1909897-3-chris.packham@alliedtelesis.co.nz>
Date: Fri, 12 Apr 2024 16:55:36 +1200
From: Chris Packham <chris.packham@...iedtelesis.co.nz>
To: gregkh@...uxfoundation.org,
guanghuifeng@...ux.alibaba.com,
cleech@...hat.com,
njavali@...vell.com
Cc: linux-kernel@...r.kernel.org,
Chris Packham <chris.packham@...iedtelesis.co.nz>
Subject: [PATCH v3 2/2] 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.
Changes in v3:
- Update kerneldoc comment for uio_interrupt_handler()
- Add kerneldoc comment for uio_interrupt_thread()
Changes in v2:
- None
drivers/uio/uio.c | 24 +++++++++++++++++++-----
1 file changed, 19 insertions(+), 5 deletions(-)
diff --git a/drivers/uio/uio.c b/drivers/uio/uio.c
index bb77de6fa067..b424f004404f 100644
--- a/drivers/uio/uio.c
+++ b/drivers/uio/uio.c
@@ -438,22 +438,36 @@ void uio_event_notify(struct uio_info *info)
EXPORT_SYMBOL_GPL(uio_event_notify);
/**
- * uio_interrupt - hardware interrupt handler
+ * uio_interrupt_handler - hardware interrupt handler
* @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;
}
+/**
+ * uio_interrupt_thread - irq thread handler
+ * @irq: IRQ number
+ * @dev_id: Pointer to the devices uio_device structure
+ */
+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 +1038,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