1
1
===============================================
2
- The irq_domain interrupt number mapping library
2
+ The irq_domain Interrupt Number Mapping Library
3
3
===============================================
4
4
5
5
The current design of the Linux kernel uses a single large number
6
- space where each separate IRQ source is assigned a different number.
7
- This is simple when there is only one interrupt controller, but in
8
- systems with multiple interrupt controllers the kernel must ensure
6
+ space where each separate IRQ source is assigned a unique number.
7
+ This is simple when there is only one interrupt controller. But in
8
+ systems with multiple interrupt controllers, the kernel must ensure
9
9
that each one gets assigned non-overlapping allocations of Linux
10
10
IRQ numbers.
11
11
12
12
The number of interrupt controllers registered as unique irqchips
13
- show a rising tendency: for example subdrivers of different kinds
13
+ shows a rising tendency. For example, subdrivers of different kinds
14
14
such as GPIO controllers avoid reimplementing identical callback
15
15
mechanisms as the IRQ core system by modelling their interrupt
16
- handlers as irqchips, i .e. in effect cascading interrupt controllers.
16
+ handlers as irqchips. I .e. in effect cascading interrupt controllers.
17
17
18
- Here the interrupt number loose all kind of correspondence to
19
- hardware interrupt numbers: whereas in the past, IRQ numbers could
20
- be chosen so they matched the hardware IRQ line into the root
21
- interrupt controller (i.e. the component actually fireing the
22
- interrupt line to the CPU) nowadays this number is just a number .
18
+ So in the past, IRQ numbers could be chosen so that they match the
19
+ hardware IRQ line into the root interrupt controller (i.e. the
20
+ component actually firing the interrupt line to the CPU). Nowadays,
21
+ this number is just a number and the number loose all kind of
22
+ correspondence to hardware interrupt numbers .
23
23
24
- For this reason we need a mechanism to separate controller-local
25
- interrupt numbers, called hardware irq's , from Linux IRQ numbers.
24
+ For this reason, we need a mechanism to separate controller-local
25
+ interrupt numbers, called hardware IRQs , from Linux IRQ numbers.
26
26
27
27
The irq_alloc_desc*() and irq_free_desc*() APIs provide allocation of
28
- irq numbers, but they don't provide any support for reverse mapping of
28
+ IRQ numbers, but they don't provide any support for reverse mapping of
29
29
the controller-local IRQ (hwirq) number into the Linux IRQ number
30
30
space.
31
31
32
- The irq_domain library adds mapping between hwirq and IRQ numbers on
33
- top of the irq_alloc_desc*() API. An irq_domain to manage mapping is
34
- preferred over interrupt controller drivers open coding their own
32
+ The irq_domain library adds a mapping between hwirq and IRQ numbers on
33
+ top of the irq_alloc_desc*() API. An irq_domain to manage the mapping
34
+ is preferred over interrupt controller drivers open coding their own
35
35
reverse mapping scheme.
36
36
37
- irq_domain also implements translation from an abstract irq_fwspec
38
- structure to hwirq numbers (Device Tree and ACPI GSI so far), and can
39
- be easily extended to support other IRQ topology data sources.
37
+ irq_domain also implements a translation from an abstract struct
38
+ irq_fwspec to hwirq numbers (Device Tree, non-DT firmware node, ACPI
39
+ GSI, and software node so far), and can be easily extended to support
40
+ other IRQ topology data sources. The implementation is performed
41
+ without any extra platform support code.
40
42
41
- irq_domain usage
43
+ irq_domain Usage
42
44
================
43
-
44
- An interrupt controller driver creates and registers an irq_domain by
45
- calling one of the irq_domain_add_*() or irq_domain_create_*() functions
46
- (each mapping method has a different allocator function, more on that later).
47
- The function will return a pointer to the irq_domain on success. The caller
48
- must provide the allocator function with an irq_domain_ops structure.
45
+ struct irq_domain could be defined as an irq domain controller. That
46
+ is, it handles the mapping between hardware and virtual interrupt
47
+ numbers for a given interrupt domain. The domain structure is
48
+ generally created by the PIC code for a given PIC instance (though a
49
+ domain can cover more than one PIC if they have a flat number model).
50
+ It is the domain callbacks that are responsible for setting the
51
+ irq_chip on a given irq_desc after it has been mapped.
52
+
53
+ The host code and data structures use a fwnode_handle pointer to
54
+ identify the domain. In some cases, and in order to preserve source
55
+ code compatibility, this fwnode pointer is "upgraded" to a DT
56
+ device_node. For those firmware infrastructures that do not provide a
57
+ unique identifier for an interrupt controller, the irq_domain code
58
+ offers a fwnode allocator.
59
+
60
+ An interrupt controller driver creates and registers a struct irq_domain
61
+ by calling one of the irq_domain_create_*() functions (each mapping
62
+ method has a different allocator function, more on that later). The
63
+ function will return a pointer to the struct irq_domain on success. The
64
+ caller must provide the allocator function with a struct irq_domain_ops
65
+ pointer.
49
66
50
67
In most cases, the irq_domain will begin empty without any mappings
51
68
between hwirq and IRQ numbers. Mappings are added to the irq_domain
52
69
by calling irq_create_mapping() which accepts the irq_domain and a
53
- hwirq number as arguments. If a mapping for the hwirq doesn't already
54
- exist then it will allocate a new Linux irq_desc, associate it with
55
- the hwirq, and call the .map() callback so the driver can perform any
56
- required hardware setup.
70
+ hwirq number as arguments. If a mapping for the hwirq doesn't already
71
+ exist, irq_create_mapping() allocates a new Linux irq_desc, associates
72
+ it with the hwirq, and calls the :c:member: `irq_domain_ops.map() `
73
+ callback. In there, the driver can perform any required hardware
74
+ setup.
57
75
58
76
Once a mapping has been established, it can be retrieved or used via a
59
77
variety of methods:
@@ -63,8 +81,6 @@ variety of methods:
63
81
mapping.
64
82
- irq_find_mapping() returns a Linux IRQ number for a given domain and
65
83
hwirq number, and 0 if there was no mapping
66
- - irq_linear_revmap() is now identical to irq_find_mapping(), and is
67
- deprecated
68
84
- generic_handle_domain_irq() handles an interrupt described by a
69
85
domain and a hwirq number
70
86
@@ -77,9 +93,10 @@ be allocated.
77
93
78
94
If the driver has the Linux IRQ number or the irq_data pointer, and
79
95
needs to know the associated hwirq number (such as in the irq_chip
80
- callbacks) then it can be directly obtained from irq_data->hwirq.
96
+ callbacks) then it can be directly obtained from
97
+ :c:member: `irq_data.hwirq `.
81
98
82
- Types of irq_domain mappings
99
+ Types of irq_domain Mappings
83
100
============================
84
101
85
102
There are several mechanisms available for reverse mapping from hwirq
@@ -92,7 +109,6 @@ Linear
92
109
93
110
::
94
111
95
- irq_domain_add_linear()
96
112
irq_domain_create_linear()
97
113
98
114
The linear reverse map maintains a fixed size table indexed by the
@@ -105,19 +121,13 @@ map are fixed time lookup for IRQ numbers, and irq_descs are only
105
121
allocated for in-use IRQs. The disadvantage is that the table must be
106
122
as large as the largest possible hwirq number.
107
123
108
- irq_domain_add_linear() and irq_domain_create_linear() are functionally
109
- equivalent, except for the first argument is different - the former
110
- accepts an Open Firmware specific 'struct device_node', while the latter
111
- accepts a more general abstraction 'struct fwnode_handle'.
112
-
113
- The majority of drivers should use the linear map.
124
+ The majority of drivers should use the Linear map.
114
125
115
126
Tree
116
127
----
117
128
118
129
::
119
130
120
- irq_domain_add_tree()
121
131
irq_domain_create_tree()
122
132
123
133
The irq_domain maintains a radix tree map from hwirq numbers to Linux
@@ -129,19 +139,14 @@ since it doesn't need to allocate a table as large as the largest
129
139
hwirq number. The disadvantage is that hwirq to IRQ number lookup is
130
140
dependent on how many entries are in the table.
131
141
132
- irq_domain_add_tree() and irq_domain_create_tree() are functionally
133
- equivalent, except for the first argument is different - the former
134
- accepts an Open Firmware specific 'struct device_node', while the latter
135
- accepts a more general abstraction 'struct fwnode_handle'.
136
-
137
142
Very few drivers should need this mapping.
138
143
139
144
No Map
140
145
------
141
146
142
147
::
143
148
144
- irq_domain_add_nomap ()
149
+ irq_domain_create_nomap ()
145
150
146
151
The No Map mapping is to be used when the hwirq number is
147
152
programmable in the hardware. In this case it is best to program the
@@ -159,8 +164,6 @@ Legacy
159
164
160
165
::
161
166
162
- irq_domain_add_simple()
163
- irq_domain_add_legacy()
164
167
irq_domain_create_simple()
165
168
irq_domain_create_legacy()
166
169
@@ -189,13 +192,13 @@ supported. For example, ISA controllers would use the legacy map for
189
192
mapping Linux IRQs 0-15 so that existing ISA drivers get the correct IRQ
190
193
numbers.
191
194
192
- Most users of legacy mappings should use irq_domain_add_simple() or
193
- irq_domain_create_simple() which will use a legacy domain only if an IRQ range
194
- is supplied by the system and will otherwise use a linear domain mapping.
195
- The semantics of this call are such that if an IRQ range is specified then
196
- descriptors will be allocated on-the-fly for it, and if no range is
197
- specified it will fall through to irq_domain_add_linear () or
198
- irq_domain_create_linear() which means * no * irq descriptors will be allocated.
195
+ Most users of legacy mappings should use irq_domain_create_simple()
196
+ which will use a legacy domain only if an IRQ range is supplied by the
197
+ system and will otherwise use a linear domain mapping. The semantics of
198
+ this call are such that if an IRQ range is specified then descriptors
199
+ will be allocated on-the-fly for it, and if no range is specified it
200
+ will fall through to irq_domain_create_linear () which means * no * irq
201
+ descriptors will be allocated.
199
202
200
203
A typical use case for simple domains is where an irqchip provider
201
204
is supporting both dynamic and static IRQ assignments.
@@ -206,13 +209,7 @@ that the driver using the simple domain call irq_create_mapping()
206
209
before any irq_find_mapping() since the latter will actually work
207
210
for the static IRQ assignment case.
208
211
209
- irq_domain_add_simple() and irq_domain_create_simple() as well as
210
- irq_domain_add_legacy() and irq_domain_create_legacy() are functionally
211
- equivalent, except for the first argument is different - the former
212
- accepts an Open Firmware specific 'struct device_node', while the latter
213
- accepts a more general abstraction 'struct fwnode_handle'.
214
-
215
- Hierarchy IRQ domain
212
+ Hierarchy IRQ Domain
216
213
--------------------
217
214
218
215
On some architectures, there may be multiple interrupt controllers
@@ -253,20 +250,40 @@ There are four major interfaces to use hierarchy irq_domain:
253
250
4) irq_domain_deactivate_irq(): deactivate interrupt controller hardware
254
251
to stop delivering the interrupt.
255
252
256
- Following changes are needed to support hierarchy irq_domain:
253
+ The following is needed to support hierarchy irq_domain:
257
254
258
- 1) a new field 'parent' is added to struct irq_domain; it's used to
255
+ 1) The :c:member: ` parent ` field in struct irq_domain is used to
259
256
maintain irq_domain hierarchy information.
260
- 2) a new field 'parent_data' is added to struct irq_data; it's used to
261
- build hierarchy irq_data to match hierarchy irq_domains. The irq_data
262
- is used to store irq_domain pointer and hardware irq number.
263
- 3) new callbacks are added to struct irq_domain_ops to support hierarchy
264
- irq_domain operations.
265
-
266
- With support of hierarchy irq_domain and hierarchy irq_data ready, an
267
- irq_domain structure is built for each interrupt controller, and an
257
+ 2) The :c:member: `parent_data ` field in struct irq_data is used to
258
+ build hierarchy irq_data to match hierarchy irq_domains. The
259
+ irq_data is used to store irq_domain pointer and hardware irq
260
+ number.
261
+ 3) The :c:member: `alloc() `, :c:member: `free() `, and other callbacks in
262
+ struct irq_domain_ops to support hierarchy irq_domain operations.
263
+
264
+ With the support of hierarchy irq_domain and hierarchy irq_data ready,
265
+ an irq_domain structure is built for each interrupt controller, and an
268
266
irq_data structure is allocated for each irq_domain associated with an
269
- IRQ. Now we could go one step further to support stacked(hierarchy)
267
+ IRQ.
268
+
269
+ For an interrupt controller driver to support hierarchy irq_domain, it
270
+ needs to:
271
+
272
+ 1) Implement irq_domain_ops.alloc() and irq_domain_ops.free()
273
+ 2) Optionally, implement irq_domain_ops.activate() and
274
+ irq_domain_ops.deactivate().
275
+ 3) Optionally, implement an irq_chip to manage the interrupt controller
276
+ hardware.
277
+ 4) There is no need to implement irq_domain_ops.map() and
278
+ irq_domain_ops.unmap(). They are unused with hierarchy irq_domain.
279
+
280
+ Note the hierarchy irq_domain is in no way x86-specific, and is
281
+ heavily used to support other architectures, such as ARM, ARM64 etc.
282
+
283
+ Stacked irq_chip
284
+ ~~~~~~~~~~~~~~~~
285
+
286
+ Now, we could go one step further to support stacked (hierarchy)
270
287
irq_chip. That is, an irq_chip is associated with each irq_data along
271
288
the hierarchy. A child irq_chip may implement a required action by
272
289
itself or by cooperating with its parent irq_chip.
@@ -276,22 +293,28 @@ with the hardware managed by itself and may ask for services from its
276
293
parent irq_chip when needed. So we could achieve a much cleaner
277
294
software architecture.
278
295
279
- For an interrupt controller driver to support hierarchy irq_domain, it
280
- needs to:
281
-
282
- 1) Implement irq_domain_ops.alloc and irq_domain_ops.free
283
- 2) Optionally implement irq_domain_ops.activate and
284
- irq_domain_ops.deactivate.
285
- 3) Optionally implement an irq_chip to manage the interrupt controller
286
- hardware.
287
- 4) No need to implement irq_domain_ops.map and irq_domain_ops.unmap,
288
- they are unused with hierarchy irq_domain.
289
-
290
- Hierarchy irq_domain is in no way x86 specific, and is heavily used to
291
- support other architectures, such as ARM, ARM64 etc.
292
-
293
296
Debugging
294
297
=========
295
298
296
299
Most of the internals of the IRQ subsystem are exposed in debugfs by
297
300
turning CONFIG_GENERIC_IRQ_DEBUGFS on.
301
+
302
+ Structures and Public Functions Provided
303
+ ========================================
304
+
305
+ This chapter contains the autogenerated documentation of the structures
306
+ and exported kernel API functions which are used for IRQ domains.
307
+
308
+ .. kernel-doc :: include/linux/irqdomain.h
309
+
310
+ .. kernel-doc :: kernel/irq/irqdomain.c
311
+ :export:
312
+
313
+ Internal Functions Provided
314
+ ===========================
315
+
316
+ This chapter contains the autogenerated documentation of the internal
317
+ functions.
318
+
319
+ .. kernel-doc :: kernel/irq/irqdomain.c
320
+ :internal:
0 commit comments