hc
2023-12-11 d2ccde1c8e90d38cee87a1b0309ad2827f3fd30d
kernel/drivers/uio/uio_dmem_genirq.c
....@@ -1,3 +1,4 @@
1
+// SPDX-License-Identifier: GPL-2.0-only
12 /*
23 * drivers/uio/uio_dmem_genirq.c
34 *
....@@ -6,10 +7,6 @@
67 * Copyright (C) 2012 Damian Hobson-Garcia
78 *
89 * Based on uio_pdrv_genirq.c by Magnus Damm
9
- *
10
- * This program is free software; you can redistribute it and/or modify it
11
- * under the terms of the GNU General Public License version 2 as published by
12
- * the Free Software Foundation.
1310 */
1411
1512 #include <linux/platform_device.h>
....@@ -23,6 +20,7 @@
2320 #include <linux/pm_runtime.h>
2421 #include <linux/dma-mapping.h>
2522 #include <linux/slab.h>
23
+#include <linux/irq.h>
2624
2725 #include <linux/of.h>
2826 #include <linux/of_platform.h>
....@@ -47,7 +45,6 @@
4745 {
4846 struct uio_dmem_genirq_platdata *priv = info->priv;
4947 struct uio_mem *uiomem;
50
- int ret = 0;
5148 int dmem_region = priv->dmem_region_start;
5249
5350 uiomem = &priv->uioinfo->mem[priv->dmem_region_start];
....@@ -71,7 +68,7 @@
7168 mutex_unlock(&priv->alloc_lock);
7269 /* Wait until the Runtime PM code has woken up the device */
7370 pm_runtime_get_sync(&priv->pdev->dev);
74
- return ret;
71
+ return 0;
7572 }
7673
7774 static int uio_dmem_genirq_release(struct uio_info *info, struct inode *inode)
....@@ -156,8 +153,6 @@
156153 int i;
157154
158155 if (pdev->dev.of_node) {
159
- int irq;
160
-
161156 /* alloc uioinfo for one device */
162157 uioinfo = kzalloc(sizeof(*uioinfo), GFP_KERNEL);
163158 if (!uioinfo) {
....@@ -165,15 +160,9 @@
165160 dev_err(&pdev->dev, "unable to kmalloc\n");
166161 goto bad2;
167162 }
168
- uioinfo->name = pdev->dev.of_node->name;
163
+ uioinfo->name = devm_kasprintf(&pdev->dev, GFP_KERNEL, "%pOFn",
164
+ pdev->dev.of_node);
169165 uioinfo->version = "devicetree";
170
-
171
- /* Multiple IRQs are not supported */
172
- irq = platform_get_irq(pdev, 0);
173
- if (irq == -ENXIO)
174
- uioinfo->irq = UIO_IRQ_NONE;
175
- else
176
- uioinfo->irq = irq;
177166 }
178167
179168 if (!uioinfo || !uioinfo->name || !uioinfo->version) {
....@@ -203,13 +192,32 @@
203192 mutex_init(&priv->alloc_lock);
204193
205194 if (!uioinfo->irq) {
195
+ /* Multiple IRQs are not supported */
206196 ret = platform_get_irq(pdev, 0);
207
- if (ret < 0) {
208
- dev_err(&pdev->dev, "failed to get IRQ\n");
197
+ if (ret == -ENXIO && pdev->dev.of_node)
198
+ ret = UIO_IRQ_NONE;
199
+ else if (ret < 0)
209200 goto bad1;
210
- }
211201 uioinfo->irq = ret;
212202 }
203
+
204
+ if (uioinfo->irq) {
205
+ struct irq_data *irq_data = irq_get_irq_data(uioinfo->irq);
206
+
207
+ /*
208
+ * If a level interrupt, dont do lazy disable. Otherwise the
209
+ * irq will fire again since clearing of the actual cause, on
210
+ * device level, is done in userspace
211
+ * irqd_is_level_type() isn't used since isn't valid until
212
+ * irq is configured.
213
+ */
214
+ if (irq_data &&
215
+ irqd_get_trigger_type(irq_data) & IRQ_TYPE_LEVEL_MASK) {
216
+ dev_dbg(&pdev->dev, "disable lazy unmask\n");
217
+ irq_set_status_flags(uioinfo->irq, IRQ_DISABLE_UNLAZY);
218
+ }
219
+ }
220
+
213221 uiomem = &uioinfo->mem[0];
214222
215223 for (i = 0; i < pdev->num_resources; ++i) {