@@ -3,8 +3,8 @@ 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
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
88systems with multiple interrupt controllers, the kernel must ensure
99that each one gets assigned non-overlapping allocations of Linux
1010IRQ numbers.
@@ -15,44 +15,63 @@ such as GPIO controllers avoid reimplementing identical callback
1515mechanisms as the IRQ core system by modelling their interrupt
1616handlers 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
2424For this reason, we need a mechanism to separate controller-local
2525interrupt 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
3232The 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 mapping is
34- preferred over interrupt controller drivers open coding their own
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
4143irq_domain Usage
4244================
43-
44- An interrupt controller driver creates and registers an irq_domain by
45- calling one of the irq_domain_create_*() functions. The function will
46- return a pointer to the irq_domain on success. The caller must provide the
47- 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.
4866
4967In most cases, the irq_domain will begin empty without any mappings
5068between hwirq and IRQ numbers. Mappings are added to the irq_domain
5169by calling irq_create_mapping() which accepts the irq_domain and a
52- hwirq number as arguments. If a mapping for the hwirq doesn't already
53- exist then it will allocate a new Linux irq_desc, associate it with
54- the hwirq, and call the .map() callback so the driver can perform any
55- 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.
5675
5776Once a mapping has been established, it can be retrieved or used via a
5877variety of methods:
@@ -74,7 +93,8 @@ be allocated.
7493
7594If the driver has the Linux IRQ number or the irq_data pointer, and
7695needs to know the associated hwirq number (such as in the irq_chip
77- 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 `.
7898
7999Types of irq_domain Mappings
80100============================
@@ -230,20 +250,40 @@ There are four major interfaces to use hierarchy irq_domain:
2302504) irq_domain_deactivate_irq(): deactivate interrupt controller hardware
231251 to stop delivering the interrupt.
232252
233- Following changes are needed to support hierarchy irq_domain:
253+ The following is needed to support hierarchy irq_domain:
234254
235- 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
236256 maintain irq_domain hierarchy information.
237- 2) a new field 'parent_data' is added to struct irq_data; it's used to
238- build hierarchy irq_data to match hierarchy irq_domains. The irq_data
239- is used to store irq_domain pointer and hardware irq number.
240- 3) new callbacks are added to struct irq_domain_ops to support hierarchy
241- irq_domain operations.
242-
243- With support of hierarchy irq_domain and hierarchy irq_data ready, an
244- 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
245266irq_data structure is allocated for each irq_domain associated with an
246- 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)
247287irq_chip. That is, an irq_chip is associated with each irq_data along
248288the hierarchy. A child irq_chip may implement a required action by
249289itself or by cooperating with its parent irq_chip.
@@ -253,20 +293,6 @@ with the hardware managed by itself and may ask for services from its
253293parent irq_chip when needed. So we could achieve a much cleaner
254294software architecture.
255295
256- For an interrupt controller driver to support hierarchy irq_domain, it
257- needs to:
258-
259- 1) Implement irq_domain_ops.alloc and irq_domain_ops.free
260- 2) Optionally implement irq_domain_ops.activate and
261- irq_domain_ops.deactivate.
262- 3) Optionally implement an irq_chip to manage the interrupt controller
263- hardware.
264- 4) No need to implement irq_domain_ops.map and irq_domain_ops.unmap,
265- they are unused with hierarchy irq_domain.
266-
267- Hierarchy irq_domain is in no way x86 specific, and is heavily used to
268- support other architectures, such as ARM, ARM64 etc.
269-
270296Debugging
271297=========
272298
0 commit comments