Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > linux.kernel > #1654392 > unrolled thread
| Started by | Bartosz Golaszewski <brgl@bgdev.pl> |
|---|---|
| First post | 2017-05-31 18:10 +0200 |
| Last post | 2017-05-31 18:10 +0200 |
| Articles | 5 — 1 participant |
Back to article view | Back to linux.kernel
[PATCH 0/5] irq: generic-chip: resource management improvements Bartosz Golaszewski <brgl@bgdev.pl> - 2017-05-31 18:10 +0200
[PATCH 2/5] irq: generic-chip: provide irq_destroy_generic_chip() Bartosz Golaszewski <brgl@bgdev.pl> - 2017-05-31 18:10 +0200
[PATCH 3/5] irq: generic-chip: export irq_init_generic_chip() locally Bartosz Golaszewski <brgl@bgdev.pl> - 2017-05-31 18:10 +0200
[PATCH 1/5] irq: generic-chip: provide irq_free_generic_chip() Bartosz Golaszewski <brgl@bgdev.pl> - 2017-05-31 18:10 +0200
[PATCH 5/5] irq: generic-chip: provide devm_irq_setup_generic_chip() Bartosz Golaszewski <brgl@bgdev.pl> - 2017-05-31 18:10 +0200
| From | Bartosz Golaszewski <brgl@bgdev.pl> |
|---|---|
| Date | 2017-05-31 18:10 +0200 |
| Subject | [PATCH 0/5] irq: generic-chip: resource management improvements |
| Message-ID | <tNem6-73N-15@gated-at.bofh.it> |
This series is a follow-up to [1]. Some users of irq_alloc_generic_chip() are modules which can be removed (e.g. gpio-ml-ioh) but have no means of freeing the allocated generic chip. Last time it was suggested to provide irq_destroy_generic_chip() which would undo both irq_remove_generic_chip() and irq_alloc_generic_chip(). This functionality is provided by patch 2/5 with 1/5 adding the option to only free the allocated memory. Patch 3/5 exports a function that will be used in the devres variant of irq_alloc_generic_chip(). Patches 4/5 and 5/5 add resource managed versions of irq_alloc_generic_chip() & irq_setup_generic_chip(). They will be used in drivers where applicable. Device resources are released in reverse order so it's ok to call devm_irq_alloc_generic_chip() and then devm_irq_setup_generic_chip(). [1] https://lkml.org/lkml/2017/3/8/550 Bartosz Golaszewski (5): irq: generic-chip: provide irq_free_generic_chip() irq: generic-chip: provide irq_destroy_generic_chip() irq: generic-chip: export irq_init_generic_chip() locally irq: generic-chip: provide devm_irq_alloc_generic_chip() irq: generic-chip: provide devm_irq_setup_generic_chip() Documentation/driver-model/devres.txt | 2 + include/linux/irq.h | 22 +++++++++ kernel/irq/devres.c | 86 +++++++++++++++++++++++++++++++++++ kernel/irq/generic-chip.c | 7 ++- kernel/irq/internals.h | 11 +++++ 5 files changed, 124 insertions(+), 4 deletions(-) -- 2.9.3
[toc] | [next] | [standalone]
| From | Bartosz Golaszewski <brgl@bgdev.pl> |
|---|---|
| Date | 2017-05-31 18:10 +0200 |
| Subject | [PATCH 2/5] irq: generic-chip: provide irq_destroy_generic_chip() |
| Message-ID | <tNem6-73N-17@gated-at.bofh.it> |
| In reply to | #1654392 |
Most users of irq_alloc_generic_chip() call irq_setup_generic_chip()
too. To simplify the cleanup provide a function that both removes a
generic chip and frees its memory.
Signed-off-by: Bartosz Golaszewski <brgl@bgdev.pl>
---
include/linux/irq.h | 8 ++++++++
1 file changed, 8 insertions(+)
diff --git a/include/linux/irq.h b/include/linux/irq.h
index cba41a4..a5d298e 100644
--- a/include/linux/irq.h
+++ b/include/linux/irq.h
@@ -973,6 +973,14 @@ static inline void irq_free_generic_chip(struct irq_chip_generic *gc)
kfree(gc);
}
+static inline void irq_destroy_generic_chip(struct irq_chip_generic *gc,
+ u32 msk, unsigned int clr,
+ unsigned int set)
+{
+ irq_remove_generic_chip(gc, msk, clr, set);
+ irq_free_generic_chip(gc);
+}
+
static inline struct irq_chip_type *irq_data_get_chip_type(struct irq_data *d)
{
return container_of(d->chip, struct irq_chip_type, chip);
--
2.9.3
[toc] | [prev] | [next] | [standalone]
| From | Bartosz Golaszewski <brgl@bgdev.pl> |
|---|---|
| Date | 2017-05-31 18:10 +0200 |
| Subject | [PATCH 3/5] irq: generic-chip: export irq_init_generic_chip() locally |
| Message-ID | <tNem6-73N-21@gated-at.bofh.it> |
| In reply to | #1654392 |
This function will be used in the devres variant of
irq_alloc_generic_chip().
Signed-off-by: Bartosz Golaszewski <brgl@bgdev.pl>
---
kernel/irq/generic-chip.c | 7 +++----
kernel/irq/internals.h | 11 +++++++++++
2 files changed, 14 insertions(+), 4 deletions(-)
diff --git a/kernel/irq/generic-chip.c b/kernel/irq/generic-chip.c
index ee32870..f7086b7 100644
--- a/kernel/irq/generic-chip.c
+++ b/kernel/irq/generic-chip.c
@@ -201,10 +201,9 @@ static void irq_writel_be(u32 val, void __iomem *addr)
iowrite32be(val, addr);
}
-static void
-irq_init_generic_chip(struct irq_chip_generic *gc, const char *name,
- int num_ct, unsigned int irq_base,
- void __iomem *reg_base, irq_flow_handler_t handler)
+void irq_init_generic_chip(struct irq_chip_generic *gc, const char *name,
+ int num_ct, unsigned int irq_base,
+ void __iomem *reg_base, irq_flow_handler_t handler)
{
raw_spin_lock_init(&gc->lock);
gc->num_ct = num_ct;
diff --git a/kernel/irq/internals.h b/kernel/irq/internals.h
index bc226e7..921a241 100644
--- a/kernel/irq/internals.h
+++ b/kernel/irq/internals.h
@@ -226,3 +226,14 @@ irq_pm_install_action(struct irq_desc *desc, struct irqaction *action) { }
static inline void
irq_pm_remove_action(struct irq_desc *desc, struct irqaction *action) { }
#endif
+
+#ifdef CONFIG_GENERIC_IRQ_CHIP
+void irq_init_generic_chip(struct irq_chip_generic *gc, const char *name,
+ int num_ct, unsigned int irq_base,
+ void __iomem *reg_base, irq_flow_handler_t handler);
+#else
+static inline void
+irq_init_generic_chip(struct irq_chip_generic *gc, const char *name,
+ int num_ct, unsigned int irq_base,
+ void __iomem *reg_base, irq_flow_handler_t handler) { }
+#endif /* CONFIG_GENERIC_IRQ_CHIP */
--
2.9.3
[toc] | [prev] | [next] | [standalone]
| From | Bartosz Golaszewski <brgl@bgdev.pl> |
|---|---|
| Date | 2017-05-31 18:10 +0200 |
| Subject | [PATCH 1/5] irq: generic-chip: provide irq_free_generic_chip() |
| Message-ID | <tNem6-73N-23@gated-at.bofh.it> |
| In reply to | #1654392 |
Currently there's no way for users of irq_alloc_generic_chip() to free
the allocated memory other than calling kfree() manually on the
returned pointer. This may lead to errors if the internals of
irq_alloc_generic_chip() ever change. Provide a routine to free the
generic chip.
Signed-off-by: Bartosz Golaszewski <brgl@bgdev.pl>
---
include/linux/irq.h | 6 ++++++
1 file changed, 6 insertions(+)
diff --git a/include/linux/irq.h b/include/linux/irq.h
index f887351..cba41a4 100644
--- a/include/linux/irq.h
+++ b/include/linux/irq.h
@@ -22,6 +22,7 @@
#include <linux/topology.h>
#include <linux/wait.h>
#include <linux/io.h>
+#include <linux/slab.h>
#include <asm/irq.h>
#include <asm/ptrace.h>
@@ -967,6 +968,11 @@ int __irq_alloc_domain_generic_chips(struct irq_domain *d, int irqs_per_chip,
handler, clr, set, flags); \
})
+static inline void irq_free_generic_chip(struct irq_chip_generic *gc)
+{
+ kfree(gc);
+}
+
static inline struct irq_chip_type *irq_data_get_chip_type(struct irq_data *d)
{
return container_of(d->chip, struct irq_chip_type, chip);
--
2.9.3
[toc] | [prev] | [next] | [standalone]
| From | Bartosz Golaszewski <brgl@bgdev.pl> |
|---|---|
| Date | 2017-05-31 18:10 +0200 |
| Subject | [PATCH 5/5] irq: generic-chip: provide devm_irq_setup_generic_chip() |
| Message-ID | <tNem7-73N-29@gated-at.bofh.it> |
| In reply to | #1654392 |
Provide a resource managed variant of irq_setup_generic_chip().
Signed-off-by: Bartosz Golaszewski <brgl@bgdev.pl>
---
Documentation/driver-model/devres.txt | 1 +
include/linux/irq.h | 3 ++
kernel/irq/devres.c | 52 +++++++++++++++++++++++++++++++++++
3 files changed, 56 insertions(+)
diff --git a/Documentation/driver-model/devres.txt b/Documentation/driver-model/devres.txt
index d473be8..6a6618f 100644
--- a/Documentation/driver-model/devres.txt
+++ b/Documentation/driver-model/devres.txt
@@ -312,6 +312,7 @@ IRQ
devm_irq_alloc_desc_from()
devm_irq_alloc_descs_from()
devm_irq_alloc_generic_chip()
+ devm_irq_setup_generic_chip()
LED
devm_led_classdev_register()
diff --git a/include/linux/irq.h b/include/linux/irq.h
index c6e70e9..4006ba1 100644
--- a/include/linux/irq.h
+++ b/include/linux/irq.h
@@ -956,6 +956,9 @@ struct irq_chip_generic *
devm_irq_alloc_generic_chip(struct device *dev, const char *name, int num_ct,
unsigned int irq_base, void __iomem *reg_base,
irq_flow_handler_t handler);
+int devm_irq_setup_generic_chip(struct device *dev, struct irq_chip_generic *gc,
+ u32 msk, enum irq_gc_flags flags,
+ unsigned int clr, unsigned int set);
struct irq_chip_generic *irq_get_domain_generic_chip(struct irq_domain *d, unsigned int hw_irq);
diff --git a/kernel/irq/devres.c b/kernel/irq/devres.c
index 21ee0ae..194c506 100644
--- a/kernel/irq/devres.c
+++ b/kernel/irq/devres.c
@@ -231,4 +231,56 @@ devm_irq_alloc_generic_chip(struct device *dev, const char *name, int num_ct,
return gc;
}
EXPORT_SYMBOL_GPL(devm_irq_alloc_generic_chip);
+
+struct irq_generic_chip_devres {
+ struct irq_chip_generic *gc;
+ u32 msk;
+ unsigned int clr;
+ unsigned int set;
+};
+
+static void devm_irq_remove_generic_chip(struct device *dev, void *res)
+{
+ struct irq_generic_chip_devres *this = res;
+
+ irq_remove_generic_chip(this->gc, this->msk, this->clr, this->set);
+}
+
+/**
+ * devm_irq_setup_generic_chip - Setup a range of interrupts with a generic
+ * chip for a managed device
+ *
+ * @dev: Device to setup the generic chip for
+ * @gc: Generic irq chip holding all data
+ * @msk: Bitmask holding the irqs to initialize relative to gc->irq_base
+ * @flags: Flags for initialization
+ * @clr: IRQ_* bits to clear
+ * @set: IRQ_* bits to set
+ *
+ * Set up max. 32 interrupts starting from gc->irq_base. Note, this
+ * initializes all interrupts to the primary irq_chip_type and its
+ * associated handler.
+ */
+int devm_irq_setup_generic_chip(struct device *dev, struct irq_chip_generic *gc,
+ u32 msk, enum irq_gc_flags flags,
+ unsigned int clr, unsigned int set)
+{
+ struct irq_generic_chip_devres *dr;
+
+ dr = devres_alloc(devm_irq_remove_generic_chip,
+ sizeof(*dr), GFP_KERNEL);
+ if (!dr)
+ return -ENOMEM;
+
+ irq_setup_generic_chip(gc, msk, flags, clr, set);
+
+ dr->gc = gc;
+ dr->msk = msk;
+ dr->clr = clr;
+ dr->set = set;
+ devres_add(dev, dr);
+
+ return 0;
+}
+EXPORT_SYMBOL_GPL(devm_irq_setup_generic_chip);
#endif /* CONFIG_GENERIC_IRQ_CHIP */
--
2.9.3
[toc] | [prev] | [standalone]
Back to top | Article view | linux.kernel
csiph-web