aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLinus Walleij <linus.walleij@linaro.org>2015-10-02 17:26:05 -0400
committerLinus Walleij <linus.walleij@linaro.org>2015-10-20 04:17:35 -0400
commit677b2ff4afd9996eabefc9472c701211b4b49e87 (patch)
tree37916eca6ff57ab9f75b29dd480dfacae9fe8c95
parent85001089a764d6d12b47f33a8c9b49cf06cfe045 (diff)
gpio: add a real time compliance checklist
Add some information about real time compliance to the driver document. Inspired by Grygorii Strashko's real time compliance patches. Cc: Grygorii Strashko <grygorii.strashko@ti.com> Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
-rw-r--r--Documentation/gpio/driver.txt72
1 files changed, 60 insertions, 12 deletions
diff --git a/Documentation/gpio/driver.txt b/Documentation/gpio/driver.txt
index 90d0f6aba7a6..9d7985171f07 100644
--- a/Documentation/gpio/driver.txt
+++ b/Documentation/gpio/driver.txt
@@ -93,22 +93,37 @@ GPIO irqchips usually fall in one of two categories:
93 Chained GPIO irqchips typically can NOT set the .can_sleep flag on 93 Chained GPIO irqchips typically can NOT set the .can_sleep flag on
94 struct gpio_chip, as everything happens directly in the callbacks. 94 struct gpio_chip, as everything happens directly in the callbacks.
95 95
96* NESTED THREADED GPIO irqchips: these are off-chip GPIO expanders and any 96 NOTE: chained IRQ handlers are usually not good for real time. If you
97 other GPIO irqchip residing on the other side of a sleeping bus. Of course 97 are submitting a new driver or refactoring a driver for real time compliance,
98 such drivers that need slow bus traffic to read out IRQ status and similar, 98 consider using creating a nested/threaded irqchip instead, see below.
99 traffic which may in turn incur other IRQs to happen, cannot be handled 99
100 in a quick IRQ handler with IRQs disabled. Instead they need to spawn a 100* NESTED THREADED GPIO irqchips: these are traditionally off-chip GPIO
101 thread and then mask the parent IRQ line until the interrupt is handled 101 expanders and any other GPIO irqchip residing on the other side of a
102 by the driver. The hallmark of this driver is to call something like 102 sleeping bus. Of course such drivers that need slow bus traffic to read
103 this in its interrupt handler: 103 out IRQ status and similar, traffic which may in turn incur other IRQs to
104 happen, cannot be handled in a quick IRQ handler with IRQs disabled.
105
106 With the introduction of real time support in the Linux kernel, also other
107 GPIO irqchips are encouraged to use a nested and threaded IRQ handler.
108 Doing so makes the interrupts naturally preemptible on a real time
109 setup, which means the system can easily be configured for real time with
110 a (usually negligable) performance loss.
111
112 These drivers spawn a thread and then mask the parent IRQ line until the
113 interrupt is handled by the driver. The hallmark of this driver is to call
114 something like this in its interrupt handler:
104 115
105 static irqreturn_t tc3589x_gpio_irq(int irq, void *data) 116 static irqreturn_t tc3589x_gpio_irq(int irq, void *data)
106 ... 117 ...
107 handle_nested_irq(irq); 118 handle_nested_irq(irq);
119 OR
120 generic_handle_irq(irq);
108 121
109 The hallmark of threaded GPIO irqchips is that they set the .can_sleep 122 Threaded GPIO irqchips should set the .can_sleep flag on struct gpio_chip
110 flag on struct gpio_chip to true, indicating that this chip may sleep 123 to true if they are e.g. accessing the chip over I2C or SPI, indicating that
111 when accessing the GPIOs. 124 this chip may sleep when accessing the GPIOs. irqchips that are just made
125 threaded to be preemptible and thus real time compliant need not do this:
126 preemption is not sleeping.
112 127
113To help out in handling the set-up and management of GPIO irqchips and the 128To help out in handling the set-up and management of GPIO irqchips and the
114associated irqdomain and resource allocation callbacks, the gpiolib has 129associated irqdomain and resource allocation callbacks, the gpiolib has
@@ -125,7 +140,7 @@ symbol:
125 gpio_chip from a parent IRQ and passes the struct gpio_chip* as handler 140 gpio_chip from a parent IRQ and passes the struct gpio_chip* as handler
126 data. (Notice handler data, since the irqchip data is likely used by the 141 data. (Notice handler data, since the irqchip data is likely used by the
127 parent irqchip!) This is for the chained type of chip. This is also used 142 parent irqchip!) This is for the chained type of chip. This is also used
128 to set up a nested irqchip if NULL is passed as handler. 143 to set up a threaded/nested irqchip if NULL is passed as handler.
129 144
130To use the helpers please keep the following in mind: 145To use the helpers please keep the following in mind:
131 146
@@ -170,6 +185,39 @@ typically be called in the .startup() and .shutdown() callbacks from the
170irqchip. 185irqchip.
171 186
172 187
188Real-Time compliance for GPIO IRQ chips
189---------------------------------------
190
191Any provider of irqchips needs to be carefully tailored to support Real Time
192preemption. It is desireable that all irqchips in the GPIO subsystem keep this
193in mind and does the proper testing to assure they are real time-enabled. The
194following is a checklist to follow when preparing a driver for real
195time-compliance:
196
197- Nominally use raw_spinlock_t in the IRQ context path of the IRQ handler as
198 we do not want these sections to be preempted.
199
200- Do NOT use chained_irq_enter() or chained_irq_exit() in the IRQ handler,
201 as we want the hotpath to be preemptible.
202
203- Instead use nested IRQs and generic handlers such as handle_bad_irq(),
204 handle_level_irq() and handle_edge_irq(). Consequentally the handler
205 argument of gpiochip_set_chained_irqchip() should be NULL when using the
206 gpiolib irqchip helpers.
207
208- Nominally set all handlers to handle_bad_irq() in the setup call, then
209 set the handler to handle_level_irq() and/or handle_edge_irq() in the irqchip
210 .set_type() callback depending on what your controller supports.
211
212- If you need to use the pm_runtime_get*()/pm_runtime_put*() callbacks in some
213 of the irqchip callbacks, these should be moved to the .irq_bus_lock()
214 and .irq_bus_unlock() callbacks respectively, as these are the only
215 slowpath callbacks on an irqchip. Create the callbacks if need be.
216
217- Test your driver with the apropriate in-kernel real time test cases for both
218 level and edge IRQs.
219
220
173Requesting self-owned GPIO pins 221Requesting self-owned GPIO pins
174------------------------------- 222-------------------------------
175 223