simulated interrupts
Subsystems (4)
v4 cover simulated interrupts
Some frameworks (e.g. iio, gpiolib) use irq_work to implement simulated interrupts that can be 'fired' from process context when needed and requested just like normal interrupts. This is useful for testing and development purposes.
Currently this code is reimplemented by every user. This series proposes to add a new set of functions that can be used by drivers that want to simulate interrupts without having to duplicate any boilerplate code.
The first patch adds a simple irq simulator framework. The second extends it with resource management. The third uses the new functionality in the gpio-mockup testing driver.
NOTE: The next candidate for using this API would be iio-dummy-evgen.
v1 -> v2:
- added a call to irq_work_sync in irq_sim_fini()
v2 -> v3:
- added the license header to new files
- added Acked-by's and Reviewed-by's
v3 -> v4:
- moved the .c file to kernel/irq
Bartosz Golaszewski (3):
irq/irq_sim: add a simple interrupt simulator framework irq/irq_sim: add a devres variant of irq_sim_init()
gpio: mockup: use irq_sim
Documentation/driver-model/devres.txt | 1 + drivers/gpio/Kconfig | 2 +- drivers/gpio/gpio-mockup.c | 77 ++-------------- include/linux/irq_sim.h | 48 ++++++++++ kernel/irq/Kconfig | 5 ++ kernel/irq/Makefile | 1 + kernel/irq/irq_sim.c | 164 ++++++++++++++++++++++++++++++++++ 7 files changed, 227 insertions(+), 71 deletions(-) create mode 100644 include/linux/irq_sim.h create mode 100644 kernel/irq/irq_sim.c
Signature · 1 line
2.13.2
PATCH v4 1/3 irq/irq_sim: add a simple interrupt simulator framework
Implement a simple, irq_work-based framework for simulating interrupts. Currently the API exposes routines for initializing and deinitializing the simulator object, enqueueing the interrupts and retrieving the allocated interrupt numbers based on the offset of the dummy interrupt in the simulator struct.
--- include/linux/irq_sim.h | 44 ++++++++++++++++++ kernel/irq/Kconfig | 5 ++ kernel/irq/Makefile | 1 + kernel/irq/irq_sim.c | 121 ++++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 171 insertions(+) create mode 100644 include/linux/irq_sim.h create mode 100644 kernel/irq/irq_sim.c
include/linux/irq_sim.h new file +44 -0
@@ -0,0 +1,44 @@ +/* +* Copyright (C) 2017 Bartosz Golaszewski <[email protected]> +* +* This program is free software; you can redistribute it and/or modify it +* under the terms of the GNU General Public License as published by the +* Free Software Foundation; either version 2 of the License, or (at your +* option) any later version. +*/ + +#ifndef _LINUX_IRQ_SIM_H +#define _LINUX_IRQ_SIM_H + +#include <linux/irq_work.h> + +/* +* Provides a framework for allocating simulated interrupts which can be +* requested like normal irqs and enqueued from process context. +*/ + +struct irq_sim_work_ctx { +struct irq_work work; +int irq; +}; + +struct irq_sim_irq_ctx { +int irqnum; +bool enabled; +}; + +struct irq_sim { +struct irq_sim_work_ctx work_ctx; +int irq_base; +unsigned int irq_count; +struct irq_sim_irq_ctx *irqs; +}; + +int irq_sim_init (struct irq_sim *sim,unsigned int num_irqs); +void irq_sim_fini (struct irq_sim *sim); + +void irq_sim_fire (struct irq_sim *sim,unsigned int offset); + +int irq_sim_irqnum (struct irq_sim *sim,unsigned int offset); + +#endif /* _LINUX_IRQ_SIM_H */
kernel/irq/Kconfig +5 -0
@@ -63,6 +63,11 @@ config GENERIC_IRQ_CHIP config IRQ_DOMAIN bool +# Support for simulated interrupts +config IRQ_SIM + bool + select IRQ_WORK + # Support for hierarchical irq domains config IRQ_DOMAIN_HIERARCHY bool
kernel/irq/Makefile +1 -0
@@ -4,6 +4,7 @@ obj-$(CONFIG_IRQ_TIMINGS) += timings.o obj-$(CONFIG_GENERIC_IRQ_CHIP) += generic-chip.o obj-$(CONFIG_GENERIC_IRQ_PROBE) += autoprobe.o obj-$(CONFIG_IRQ_DOMAIN) += irqdomain.o +obj-$(CONFIG_IRQ_SIM) += irq_sim.o obj-$(CONFIG_PROC_FS) += proc.o obj-$(CONFIG_GENERIC_PENDING_IRQ) += migration.o obj-$(CONFIG_GENERIC_IRQ_MIGRATION) += cpuhotplug.o
kernel/irq/irq_sim.c new file +121 -0
121 lines not on this page · raw message
Signature · 1 line
2.13.2
PATCH v4 2/3 irq/irq_sim: add a devres variant of irq_sim_init()
In reply to Bartosz GolaszewskiAdd a resource managed version of irq_sim_init(). This can be conveniently used in device drivers.
--- Documentation/driver-model/devres.txt | 1 + include/linux/irq_sim.h | 4 ++++ kernel/irq/irq_sim.c | 43 +++++++++++++++++++++++++++++++++++ 3 files changed, 48 insertions(+)
Documentation/driver-model/devres.txt +1 -0
@@ -312,6 +312,7 @@ IRQ devm_irq_alloc_descs_from() devm_irq_alloc_generic_chip() devm_irq_setup_generic_chip() + devm_irq_sim_init() LED devm_led_classdev_register()
include/linux/irq_sim.h +4 -0
@@ -11,6 +11,7 @@#define _LINUX_IRQ_SIM_H#include <linux/irq_work.h> +#include <linux/device.h> /* * Provides a framework for allocating simulated interrupts which can be
@@ -37,6 +38,9 @@ struct irq_sim {int irq_sim_init (struct irq_sim *sim,unsigned int num_irqs);void irq_sim_fini (struct irq_sim *sim); +int devm_irq_sim_init (struct device *dev, +struct irq_sim *sim,unsigned int num_irqs); +void irq_sim_fire (struct irq_sim *sim,unsigned int offset);int irq_sim_irqnum (struct irq_sim *sim,unsigned int offset);
kernel/irq/irq_sim.c +43 -0
49 lines not on this page · raw message
Signature · 1 line
2.13.2
PATCH v4 3/3 gpio: mockup: use irq_sim
In reply to Bartosz GolaszewskiShrink the driver by removing the code dealing with dummy interrupts and replacing it with calls to the irq_sim API.
--- drivers/gpio/Kconfig | 2 +- drivers/gpio/gpio-mockup.c | 77 +++++----------------------------------------- 2 files changed, 8 insertions(+), 71 deletions(-)
drivers/gpio/Kconfig +1 -1
@@ -311,7 +311,7 @@ config GPIO_MOCKUP depends on GPIOLIB && SYSFS select GPIO_SYSFS select GPIOLIB_IRQCHIP - select IRQ_WORK + select IRQ_SIM help This enables GPIO Testing driver, which provides a way to test GPIO subsystem through sysfs(or char device) and debugfs. GPIO_SYSFS
drivers/gpio/gpio-mockup.c +7 -70
115 lines not on this page · raw message
Signature · 1 line
2.13.2
Quoted 5 lines · Bartosz Golaszewski
Some frameworks (e.g. iio, gpiolib) use
irq_workto implement simulated interrupts that can be 'fired' from process context when needed and requested just like normal interrupts. This is useful for testing and development purposes.
Quoted 8 lines
Currently this code is reimplemented by every user. This series proposes to add a new set of functions that can be used by drivers that want to simulate interrupts without having to duplicate any boilerplate code.
The first patch adds a simple irq simulator framework. The second extends it with resource management. The third uses the new functionality in the gpio-mockup testing driver.
I merged the irq part (1+2) into a separate branch, which can be consumed by the gpio folks so the mockup driver patch can be merged as well.
git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip.git irq/for-gpio
Thanks,
tglx
tip-bot for Bartosz Golaszewski
merge bot[tip:irq/core] genirq/irq_sim: Add a simple interrupt simulator framework
In reply to Bartosz Golaszewskigenirq/irq_sim: Add a simple interrupt simulator framework
Commit-ID: b19af510e67e6ca696b8721f45c148119437307c Gitweb: http://git.kernel.org/tip/b19af510e67e6ca696b8721f45c148119437307c Author: Bartosz Golaszewski <[email protected]> AuthorDate: Mon, 14 Aug 2017 16:53:16 +0200 Committer: Thomas Gleixner <[email protected]> CommitDate: Wed, 16 Aug 2017 16:40:02 +0200
genirq/irq_sim: Add a simple interrupt simulator framework
Implement a simple, irq_work-based framework for simulating interrupts. Currently the API exposes routines for initializing and deinitializing the simulator object, enqueueing the interrupts and retrieving the allocated interrupt numbers based on the offset of the dummy interrupt in the simulator struct.
--- include/linux/irq_sim.h | 41 ++++++++++++++++ kernel/irq/Kconfig | 5 ++ kernel/irq/Makefile | 1 + kernel/irq/irq_sim.c | 121 ++++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 168 insertions(+)
include/linux/irq_sim.h new file +41 -0
@@ -0,0 +1,41 @@ +#ifndef _LINUX_IRQ_SIM_H +#define _LINUX_IRQ_SIM_H +/* +* Copyright (C) 2017 Bartosz Golaszewski <[email protected]> +* +* This program is free software; you can redistribute it and/or modify it +* under the terms of the GNU General Public License as published by the +* Free Software Foundation; either version 2 of the License, or (at your +* option) any later version. +*/ + +#include <linux/irq_work.h> + +/* +* Provides a framework for allocating simulated interrupts which can be +* requested like normal irqs and enqueued from process context. +*/ + +struct irq_sim_work_ctx { +struct irq_work work; +int irq; +}; + +struct irq_sim_irq_ctx { +int irqnum; +bool enabled; +}; + +struct irq_sim { +struct irq_sim_work_ctx work_ctx; +int irq_base; +unsigned int irq_count; +struct irq_sim_irq_ctx *irqs; +}; + +int irq_sim_init (struct irq_sim *sim,unsigned int num_irqs); +void irq_sim_fini (struct irq_sim *sim); +void irq_sim_fire (struct irq_sim *sim,unsigned int offset); +int irq_sim_irqnum (struct irq_sim *sim,unsigned int offset); + +#endif /* _LINUX_IRQ_SIM_H */
kernel/irq/Kconfig +5 -0
@@ -63,6 +63,11 @@ config GENERIC_IRQ_CHIP config IRQ_DOMAIN bool +# Support for simulated interrupts +config IRQ_SIM + bool + select IRQ_WORK + # Support for hierarchical irq domains config IRQ_DOMAIN_HIERARCHY bool
kernel/irq/Makefile +1 -0
@@ -4,6 +4,7 @@ obj-$(CONFIG_IRQ_TIMINGS) += timings.o obj-$(CONFIG_GENERIC_IRQ_CHIP) += generic-chip.o obj-$(CONFIG_GENERIC_IRQ_PROBE) += autoprobe.o obj-$(CONFIG_IRQ_DOMAIN) += irqdomain.o +obj-$(CONFIG_IRQ_SIM) += irq_sim.o obj-$(CONFIG_PROC_FS) += proc.o obj-$(CONFIG_GENERIC_PENDING_IRQ) += migration.o obj-$(CONFIG_GENERIC_IRQ_MIGRATION) += cpuhotplug.o
kernel/irq/irq_sim.c new file +121 -0
121 lines not on this page · raw message
tip-bot for Bartosz Golaszewski
merge bot[tip:irq/core] genirq/irq_sim: Add a devres variant of irq_sim_init()
In reply to Bartosz Golaszewskigenirq/irq_sim: Add a devres variant of irq_sim_init()
Commit-ID: 44e72c7ebf294043cfe276f7328b8c0e6a3e50e9 Gitweb: http://git.kernel.org/tip/44e72c7ebf294043cfe276f7328b8c0e6a3e50e9 Author: Bartosz Golaszewski <[email protected]> AuthorDate: Mon, 14 Aug 2017 16:53:17 +0200 Committer: Thomas Gleixner <[email protected]> CommitDate: Wed, 16 Aug 2017 16:40:02 +0200
genirq/irq_sim: Add a devres variant of irq_sim_init()
Add a resource managed version of irq_sim_init(). This can be conveniently used in device drivers.
--- Documentation/driver-model/devres.txt | 1 + include/linux/irq_sim.h | 3 +++ kernel/irq/irq_sim.c | 43 +++++++++++++++++++++++++++++++++++ 3 files changed, 47 insertions(+)
Documentation/driver-model/devres.txt +1 -0
@@ -312,6 +312,7 @@ IRQ devm_irq_alloc_descs_from() devm_irq_alloc_generic_chip() devm_irq_setup_generic_chip() + devm_irq_sim_init() LED devm_led_classdev_register()
include/linux/irq_sim.h +3 -0
@@ -10,6 +10,7 @@*/ #include <linux/irq_work.h> +#include <linux/device.h> /* * Provides a framework for allocating simulated interrupts which can be
@@ -34,6 +35,8 @@ struct irq_sim { };int irq_sim_init (struct irq_sim *sim,unsigned int num_irqs); +int devm_irq_sim_init (struct device *dev,struct irq_sim *sim, +unsigned int num_irqs);void irq_sim_fini (struct irq_sim *sim);void irq_sim_fire (struct irq_sim *sim,unsigned int offset);int irq_sim_irqnum (struct irq_sim *sim,unsigned int offset);
kernel/irq/irq_sim.c +43 -0
55 lines not on this page · raw message
Quoted 4 lines · Thomas Gleixner
I merged the irq part (1+2) into a separate branch, which can be consumed by the gpio folks so the mockup driver patch can be merged as well.
git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip.gitirq/for-gpio
Awesome, thanks Thomas. I pulled this into the GPIO devel branch.
Yours,
Linus Walleij