gic.h 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  1. /*
  2. * Copyright (c) 2011-2012, Freescale Semiconductor, Inc.
  3. * All rights reserved.
  4. *
  5. * Redistribution and use in source and binary forms, with or without modification,
  6. * are permitted provided that the following conditions are met:
  7. *
  8. * o Redistributions of source code must retain the above copyright notice, this list
  9. * of conditions and the following disclaimer.
  10. *
  11. * o Redistributions in binary form must reproduce the above copyright notice, this
  12. * list of conditions and the following disclaimer in the documentation and/or
  13. * other materials provided with the distribution.
  14. *
  15. * o Neither the name of Freescale Semiconductor, Inc. nor the names of its
  16. * contributors may be used to endorse or promote products derived from this
  17. * software without specific prior written permission.
  18. *
  19. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
  20. * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  21. * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  22. * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
  23. * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  24. * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  25. * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
  26. * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  27. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  28. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  29. */
  30. #ifndef __GIC_H__
  31. #define __GIC_H__
  32. #include "sdk_types.h"
  33. //! @addtogroup gic
  34. //! @{
  35. ////////////////////////////////////////////////////////////////////////////////
  36. // Definitions
  37. ////////////////////////////////////////////////////////////////////////////////
  38. //! @brief Options for sending a software generated interrupt.
  39. //!
  40. //! These options are used for the @a filter_list parameter of the gic_send_sgi()
  41. //! function. They control how to select which CPUs that the interrupt is
  42. //! sent to.
  43. enum _gicd_sgi_filter
  44. {
  45. //! Forward the interrupt to the CPU interfaces specified in the @a target_list parameter.
  46. kGicSgiFilter_UseTargetList = 0,
  47. //! Forward the interrupt to all CPU interfaces except that of the processor that requested
  48. //! the interrupt.
  49. kGicSgiFilter_AllOtherCPUs = 1,
  50. //! Forward the interrupt only to the CPU interface of the processor that requested the
  51. //! interrupt.
  52. kGicSgiFilter_OnlyThisCPU = 2
  53. };
  54. ////////////////////////////////////////////////////////////////////////////////
  55. // API
  56. ////////////////////////////////////////////////////////////////////////////////
  57. #if defined(__cplusplus)
  58. extern "C" {
  59. #endif
  60. //! @name Initialization
  61. //@{
  62. //! @brief Init interrupt handling.
  63. //!
  64. //! This function is intended to be called only by the primary CPU init code, so it will
  65. //! only be called once during system bootup.
  66. //!
  67. //! Also inits the current CPU. You don't need to call gic_init_cpu() separately.
  68. //!
  69. //! @post The interrupt distributor and the current CPU interface are enabled. All interrupts
  70. //! that were pending are cleared, and all interrupts are made secure (group 0).
  71. void gic_init(void);
  72. //! @brief Init the current CPU's GIC interface.
  73. //!
  74. //! @post Enables the CPU interface and sets the priority mask to 255. Interrupt preemption
  75. //! is disabled by setting the Binary Point to a value of 7.
  76. void gic_init_cpu(void);
  77. //@}
  78. //! @name GIC Interrupt Distributor Functions
  79. //@{
  80. //! @brief Enable or disable the GIC Distributor.
  81. //!
  82. //! Enables or disables the GIC distributor passing both secure (group 0) and non-secure
  83. //! (group 1) interrupts to the CPU interfaces.
  84. //!
  85. //! @param enableIt Pass true to enable or false to disable.
  86. void gic_enable(bool enableIt);
  87. //! @brief Set the security mode for an interrupt.
  88. //!
  89. //! @param irqID The interrupt number.
  90. //! @param isSecure Whether the interrupt is taken to secure mode.
  91. void gic_set_irq_security(uint32_t irqID, bool isSecure);
  92. //! @brief Enable or disable an interrupt.
  93. //!
  94. //! @param irqID The number of the interrupt to control.
  95. //! @param isEnabled Pass true to enable or false to disable.
  96. void gic_enable_irq(uint32_t irqID, bool isEnabled);
  97. //! @brief Set whether a CPU will receive a particular interrupt.
  98. //!
  99. //! @param irqID The interrupt number.
  100. //! @param cpuNumber The CPU number. The first CPU core is 0.
  101. //! @param enableIt Whether to send the interrupt to the specified CPU. Pass true to enable
  102. //! or false to disable.
  103. void gic_set_cpu_target(uint32_t irqID, unsigned cpuNumber, bool enableIt);
  104. //! @brief Set an interrupt's priority.
  105. //!
  106. //! @param irq_id The interrupt number.
  107. //! @param priority The priority for the interrupt. In the range of 0 through 0xff, with
  108. //! 0 being the highest priority.
  109. void gic_set_irq_priority(uint32_t irq_id, uint32_t priority);
  110. //! @brief Send a software generated interrupt to a specific CPU.
  111. //!
  112. //! @param irq_id The interrupt number to send.
  113. //! @param target_list Each bit indicates a CPU to which the interrupt will be forwarded.
  114. //! Bit 0 is CPU 0, bit 1 is CPU 1, and so on. If the value is 0, then the interrupt
  115. //! will not be forwarded to any CPUs. This parameter is only used if @a filter_list
  116. //! is set to #kGicSgiFilter_UseTargetList.
  117. //! @param filter_list One of the enums of the #_gicd_sgi_filter enumeration. The selected
  118. //! option determines which CPUs the interrupt will be sent to. If the value
  119. //! is #kGicSgiFilter_UseTargetList, then the @a target_list parameter is used.
  120. void gic_send_sgi(uint32_t irq_id, uint32_t target_list, uint32_t filter_list);
  121. //@}
  122. //! @name GIC CPU Interface Functions
  123. //@{
  124. //! @brief Enable or disable the interface to the GIC for the current CPU.
  125. //!
  126. //! @param enableIt Pass true to enable or false to disable.
  127. void gic_cpu_enable(bool enableIt);
  128. //! @brief Set the mask of which interrupt priorities the CPU will receive.
  129. //!
  130. //! @param priority The lowest priority that will be passed to the current CPU. Pass 0xff to
  131. //! allow all priority interrupts to signal the CPU.
  132. void gic_set_cpu_priority_mask(uint32_t priority);
  133. //! @brief Acknowledge starting of interrupt handling and get the interrupt number.
  134. //!
  135. //! Normally, this function is called at the beginning of the IRQ handler. It tells the GIC
  136. //! that you are starting to handle an interupt, and returns the number of the interrupt you
  137. //! need to handle. After the interrupt is handled, you should call gic_write_end_of_irq()
  138. //! to signal that the interrupt is completely handled.
  139. //!
  140. //! In some cases, a spurious interrupt might happen. One possibility is if another CPU handles
  141. //! the interrupt. When a spurious interrupt occurs, the end of the interrupt should be indicated
  142. //! but nothing else.
  143. //!
  144. //! @return The number for the highest priority interrupt available for the calling CPU. If
  145. //! the return value is 1022 or 1023, a spurious interrupt has occurred.
  146. uint32_t gic_read_irq_ack(void);
  147. //! @brief Signal the end of handling an interrupt.
  148. //!
  149. //! @param irq_id The number of the interrupt for which handling has finished.
  150. void gic_write_end_of_irq(uint32_t irq_id);
  151. //@}
  152. #if defined(__cplusplus)
  153. }
  154. #endif
  155. //! @}
  156. #endif // __GIC_H__
  157. ////////////////////////////////////////////////////////////////////////////////
  158. // EOF
  159. ////////////////////////////////////////////////////////////////////////////////