11===============================================
2- The irq_domain interrupt number mapping library
2+ The irq_domain Interrupt Number Mapping Library
33===============================================
44
55The 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
99that each one gets assigned non-overlapping allocations of Linux
1010IRQ numbers.
1111
1212The 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
1414such as GPIO controllers avoid reimplementing identical callback
1515mechanisms 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.
1717
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 .
2323
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.
2626
2727The 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
2929the controller-local IRQ (hwirq) number into the Linux IRQ number
3030space.
3131
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
3535reverse mapping scheme.
3636
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.
4042
41- irq_domain usage
43+ irq_domain Usage
4244================
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.
4966
5067In most cases, the irq_domain will begin empty without any mappings
5168between hwirq and IRQ numbers. Mappings are added to the irq_domain
5269by 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.
5775
5876Once a mapping has been established, it can be retrieved or used via a
5977variety of methods:
@@ -63,8 +81,6 @@ variety of methods:
6381 mapping.
6482- irq_find_mapping() returns a Linux IRQ number for a given domain and
6583 hwirq number, and 0 if there was no mapping
66- - irq_linear_revmap() is now identical to irq_find_mapping(), and is
67- deprecated
6884- generic_handle_domain_irq() handles an interrupt described by a
6985 domain and a hwirq number
7086
@@ -77,9 +93,10 @@ be allocated.
7793
7894If the driver has the Linux IRQ number or the irq_data pointer, and
7995needs 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 `.
8198
82- Types of irq_domain mappings
99+ Types of irq_domain Mappings
83100============================
84101
85102There are several mechanisms available for reverse mapping from hwirq
@@ -92,7 +109,6 @@ Linear
92109
93110::
94111
95- irq_domain_add_linear()
96112 irq_domain_create_linear()
97113
98114The 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
105121allocated for in-use IRQs. The disadvantage is that the table must be
106122as large as the largest possible hwirq number.
107123
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.
114125
115126Tree
116127----
117128
118129::
119130
120- irq_domain_add_tree()
121131 irq_domain_create_tree()
122132
123133The 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
129139hwirq number. The disadvantage is that hwirq to IRQ number lookup is
130140dependent on how many entries are in the table.
131141
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-
137142Very few drivers should need this mapping.
138143
139144No Map
140145------
141146
142147::
143148
144- irq_domain_add_nomap ()
149+ irq_domain_create_nomap ()
145150
146151The No Map mapping is to be used when the hwirq number is
147152programmable in the hardware. In this case it is best to program the
@@ -159,8 +164,6 @@ Legacy
159164
160165::
161166
162- irq_domain_add_simple()
163- irq_domain_add_legacy()
164167 irq_domain_create_simple()
165168 irq_domain_create_legacy()
166169
@@ -189,13 +192,13 @@ supported. For example, ISA controllers would use the legacy map for
189192mapping Linux IRQs 0-15 so that existing ISA drivers get the correct IRQ
190193numbers.
191194
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.
199202
200203A typical use case for simple domains is where an irqchip provider
201204is supporting both dynamic and static IRQ assignments.
@@ -206,13 +209,7 @@ that the driver using the simple domain call irq_create_mapping()
206209before any irq_find_mapping() since the latter will actually work
207210for the static IRQ assignment case.
208211
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
216213--------------------
217214
218215On some architectures, there may be multiple interrupt controllers
@@ -253,20 +250,40 @@ There are four major interfaces to use hierarchy irq_domain:
2532504) irq_domain_deactivate_irq(): deactivate interrupt controller hardware
254251 to stop delivering the interrupt.
255252
256- Following changes are needed to support hierarchy irq_domain:
253+ The following is needed to support hierarchy irq_domain:
257254
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
259256 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
268266irq_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)
270287irq_chip. That is, an irq_chip is associated with each irq_data along
271288the hierarchy. A child irq_chip may implement a required action by
272289itself 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
276293parent irq_chip when needed. So we could achieve a much cleaner
277294software architecture.
278295
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-
293296Debugging
294297=========
295298
296299Most of the internals of the IRQ subsystem are exposed in debugfs by
297300turning 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