IRQ-domain.txt 5.1 KB

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