blob: 27dcaabfb4db2f186bb6df8c5fb016a049c2d2d4 [file] [log] [blame]
Grant Likely7ab3a832012-02-14 14:06:47 -07001irq_domain interrupt number mapping library
2
3The current design of the Linux kernel uses a single large number
4space where each separate IRQ source is assigned a different number.
5This is simple when there is only one interrupt controller, but in
6systems with multiple interrupt controllers the kernel must ensure
7that each one gets assigned non-overlapping allocations of Linux
8IRQ numbers.
9
10The irq_alloc_desc*() and irq_free_desc*() APIs provide allocation of
11irq numbers, but they don't provide any support for reverse mapping of
12the controller-local IRQ (hwirq) number into the Linux IRQ number
13space.
14
15The irq_domain library adds mapping between hwirq and IRQ numbers on
16top of the irq_alloc_desc*() API. An irq_domain to manage mapping is
17preferred over interrupt controller drivers open coding their own
18reverse mapping scheme.
19
20irq_domain also implements translation from Device Tree interrupt
21specifiers to hwirq numbers, and can be easily extended to support
22other IRQ topology data sources.
23
24=== irq_domain usage ===
25An interrupt controller driver creates and registers an irq_domain by
26calling one of the irq_domain_add_*() functions (each mapping method
27has a different allocator function, more on that later). The function
28will return a pointer to the irq_domain on success. The caller must
29provide the allocator function with an irq_domain_ops structure with
30the .map callback populated as a minimum.
31
32In most cases, the irq_domain will begin empty without any mappings
33between hwirq and IRQ numbers. Mappings are added to the irq_domain
34by calling irq_create_mapping() which accepts the irq_domain and a
35hwirq number as arguments. If a mapping for the hwirq doesn't already
36exist then it will allocate a new Linux irq_desc, associate it with
37the hwirq, and call the .map() callback so the driver can perform any
38required hardware setup.
39
40When an interrupt is received, irq_find_mapping() function should
41be used to find the Linux IRQ number from the hwirq number.
42
43If the driver has the Linux IRQ number or the irq_data pointer, and
44needs to know the associated hwirq number (such as in the irq_chip
45callbacks) then it can be directly obtained from irq_data->hwirq.
46
47=== Types of irq_domain mappings ===
48There are several mechanisms available for reverse mapping from hwirq
49to Linux irq, and each mechanism uses a different allocation function.
50Which reverse map type should be used depends on the use case. Each
51of the reverse map types are described below:
52
53==== Linear ====
54irq_domain_add_linear()
55
56The linear reverse map maintains a fixed size table indexed by the
57hwirq number. When a hwirq is mapped, an irq_desc is allocated for
58the hwirq, and the IRQ number is stored in the table.
59
60The Linear map is a good choice when the maximum number of hwirqs is
61fixed and a relatively small number (~ < 256). The advantages of this
62map are fixed time lookup for IRQ numbers, and irq_descs are only
63allocated for in-use IRQs. The disadvantage is that the table must be
64as large as the largest possible hwirq number.
65
66The majority of drivers should use the linear map.
67
68==== Tree ====
69irq_domain_add_tree()
70
71The irq_domain maintains a radix tree map from hwirq numbers to Linux
72IRQs. When an hwirq is mapped, an irq_desc is allocated and the
73hwirq is used as the lookup key for the radix tree.
74
75The tree map is a good choice if the hwirq number can be very large
76since it doesn't need to allocate a table as large as the largest
77hwirq number. The disadvantage is that hwirq to IRQ number lookup is
78dependent on how many entries are in the table.
79
80Very few drivers should need this mapping. At the moment, powerpc
81iseries is the only user.
82
83==== No Map ===-
84irq_domain_add_nomap()
85
86The No Map mapping is to be used when the hwirq number is
87programmable in the hardware. In this case it is best to program the
88Linux IRQ number into the hardware itself so that no mapping is
89required. Calling irq_create_direct_mapping() will allocate a Linux
90IRQ number and call the .map() callback so that driver can program the
91Linux IRQ number into the hardware.
92
93Most drivers cannot use this mapping.
94
95==== Legacy ====
96irq_domain_add_legacy()
97irq_domain_add_legacy_isa()
98
99The Legacy mapping is a special case for drivers that already have a
100range of irq_descs allocated for the hwirqs. It is used when the
101driver cannot be immediately converted to use the linear mapping. For
102example, many embedded system board support files use a set of #defines
103for IRQ numbers that are passed to struct device registrations. In that
104case the Linux IRQ numbers cannot be dynamically assigned and the legacy
105mapping should be used.
106
107The legacy map assumes a contiguous range of IRQ numbers has already
108been allocated for the controller and that the IRQ number can be
109calculated by adding a fixed offset to the hwirq number, and
110visa-versa. The disadvantage is that it requires the interrupt
111controller to manage IRQ allocations and it requires an irq_desc to be
112allocated for every hwirq, even if it is unused.
113
114The legacy map should only be used if fixed IRQ mappings must be
115supported. For example, ISA controllers would use the legacy map for
116mapping Linux IRQs 0-15 so that existing ISA drivers get the correct IRQ
117numbers.