pic.h 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306
  1. /*
  2. * Copyright 2003-2011 NetLogic Microsystems, Inc. (NetLogic). All rights
  3. * reserved.
  4. *
  5. * This software is available to you under a choice of one of two
  6. * licenses. You may choose to be licensed under the terms of the GNU
  7. * General Public License (GPL) Version 2, available from the file
  8. * COPYING in the main directory of this source tree, or the NetLogic
  9. * license below:
  10. *
  11. * Redistribution and use in source and binary forms, with or without
  12. * modification, are permitted provided that the following conditions
  13. * are met:
  14. *
  15. * 1. Redistributions of source code must retain the above copyright
  16. * notice, this list of conditions and the following disclaimer.
  17. * 2. Redistributions in binary form must reproduce the above copyright
  18. * notice, this list of conditions and the following disclaimer in
  19. * the documentation and/or other materials provided with the
  20. * distribution.
  21. *
  22. * THIS SOFTWARE IS PROVIDED BY NETLOGIC ``AS IS'' AND ANY EXPRESS OR
  23. * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  24. * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  25. * ARE DISCLAIMED. IN NO EVENT SHALL NETLOGIC OR CONTRIBUTORS BE LIABLE
  26. * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  27. * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  28. * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
  29. * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
  30. * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
  31. * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
  32. * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  33. */
  34. #ifndef _ASM_NLM_XLR_PIC_H
  35. #define _ASM_NLM_XLR_PIC_H
  36. #define PIC_CLK_HZ 66666666
  37. #define pic_timer_freq() PIC_CLK_HZ
  38. /* PIC hardware interrupt numbers */
  39. #define PIC_IRT_WD_INDEX 0
  40. #define PIC_IRT_TIMER_0_INDEX 1
  41. #define PIC_IRT_TIMER_INDEX(i) ((i) + PIC_IRT_TIMER_0_INDEX)
  42. #define PIC_IRT_TIMER_1_INDEX 2
  43. #define PIC_IRT_TIMER_2_INDEX 3
  44. #define PIC_IRT_TIMER_3_INDEX 4
  45. #define PIC_IRT_TIMER_4_INDEX 5
  46. #define PIC_IRT_TIMER_5_INDEX 6
  47. #define PIC_IRT_TIMER_6_INDEX 7
  48. #define PIC_IRT_TIMER_7_INDEX 8
  49. #define PIC_IRT_CLOCK_INDEX PIC_IRT_TIMER_7_INDEX
  50. #define PIC_IRT_UART_0_INDEX 9
  51. #define PIC_IRT_UART_1_INDEX 10
  52. #define PIC_IRT_I2C_0_INDEX 11
  53. #define PIC_IRT_I2C_1_INDEX 12
  54. #define PIC_IRT_PCMCIA_INDEX 13
  55. #define PIC_IRT_GPIO_INDEX 14
  56. #define PIC_IRT_HYPER_INDEX 15
  57. #define PIC_IRT_PCIX_INDEX 16
  58. /* XLS */
  59. #define PIC_IRT_CDE_INDEX 15
  60. #define PIC_IRT_BRIDGE_TB_XLS_INDEX 16
  61. /* XLS */
  62. #define PIC_IRT_GMAC0_INDEX 17
  63. #define PIC_IRT_GMAC1_INDEX 18
  64. #define PIC_IRT_GMAC2_INDEX 19
  65. #define PIC_IRT_GMAC3_INDEX 20
  66. #define PIC_IRT_XGS0_INDEX 21
  67. #define PIC_IRT_XGS1_INDEX 22
  68. #define PIC_IRT_HYPER_FATAL_INDEX 23
  69. #define PIC_IRT_PCIX_FATAL_INDEX 24
  70. #define PIC_IRT_BRIDGE_AERR_INDEX 25
  71. #define PIC_IRT_BRIDGE_BERR_INDEX 26
  72. #define PIC_IRT_BRIDGE_TB_XLR_INDEX 27
  73. #define PIC_IRT_BRIDGE_AERR_NMI_INDEX 28
  74. /* XLS */
  75. #define PIC_IRT_GMAC4_INDEX 21
  76. #define PIC_IRT_GMAC5_INDEX 22
  77. #define PIC_IRT_GMAC6_INDEX 23
  78. #define PIC_IRT_GMAC7_INDEX 24
  79. #define PIC_IRT_BRIDGE_ERR_INDEX 25
  80. #define PIC_IRT_PCIE_LINK0_INDEX 26
  81. #define PIC_IRT_PCIE_LINK1_INDEX 27
  82. #define PIC_IRT_PCIE_LINK2_INDEX 23
  83. #define PIC_IRT_PCIE_LINK3_INDEX 24
  84. #define PIC_IRT_PCIE_XLSB0_LINK2_INDEX 28
  85. #define PIC_IRT_PCIE_XLSB0_LINK3_INDEX 29
  86. #define PIC_IRT_SRIO_LINK0_INDEX 26
  87. #define PIC_IRT_SRIO_LINK1_INDEX 27
  88. #define PIC_IRT_SRIO_LINK2_INDEX 28
  89. #define PIC_IRT_SRIO_LINK3_INDEX 29
  90. #define PIC_IRT_PCIE_INT_INDEX 28
  91. #define PIC_IRT_PCIE_FATAL_INDEX 29
  92. #define PIC_IRT_GPIO_B_INDEX 30
  93. #define PIC_IRT_USB_INDEX 31
  94. /* XLS */
  95. #define PIC_NUM_IRTS 32
  96. #define PIC_CLOCK_TIMER 7
  97. /* PIC Registers */
  98. #define PIC_CTRL 0x00
  99. #define PIC_CTRL_STE 8 /* timer enable start bit */
  100. #define PIC_IPI 0x04
  101. #define PIC_INT_ACK 0x06
  102. #define WD_MAX_VAL_0 0x08
  103. #define WD_MAX_VAL_1 0x09
  104. #define WD_MASK_0 0x0a
  105. #define WD_MASK_1 0x0b
  106. #define WD_HEARBEAT_0 0x0c
  107. #define WD_HEARBEAT_1 0x0d
  108. #define PIC_IRT_0_BASE 0x40
  109. #define PIC_IRT_1_BASE 0x80
  110. #define PIC_TIMER_MAXVAL_0_BASE 0x100
  111. #define PIC_TIMER_MAXVAL_1_BASE 0x110
  112. #define PIC_TIMER_COUNT_0_BASE 0x120
  113. #define PIC_TIMER_COUNT_1_BASE 0x130
  114. #define PIC_IRT_0(picintr) (PIC_IRT_0_BASE + (picintr))
  115. #define PIC_IRT_1(picintr) (PIC_IRT_1_BASE + (picintr))
  116. #define PIC_TIMER_MAXVAL_0(i) (PIC_TIMER_MAXVAL_0_BASE + (i))
  117. #define PIC_TIMER_MAXVAL_1(i) (PIC_TIMER_MAXVAL_1_BASE + (i))
  118. #define PIC_TIMER_COUNT_0(i) (PIC_TIMER_COUNT_0_BASE + (i))
  119. #define PIC_TIMER_COUNT_1(i) (PIC_TIMER_COUNT_0_BASE + (i))
  120. /*
  121. * Mapping between hardware interrupt numbers and IRQs on CPU
  122. * we use a simple scheme to map PIC interrupts 0-31 to IRQs
  123. * 8-39. This leaves the IRQ 0-7 for cpu interrupts like
  124. * count/compare and FMN
  125. */
  126. #define PIC_IRQ_BASE 8
  127. #define PIC_INTR_TO_IRQ(i) (PIC_IRQ_BASE + (i))
  128. #define PIC_IRQ_TO_INTR(i) ((i) - PIC_IRQ_BASE)
  129. #define PIC_IRT_FIRST_IRQ PIC_IRQ_BASE
  130. #define PIC_WD_IRQ PIC_INTR_TO_IRQ(PIC_IRT_WD_INDEX)
  131. #define PIC_TIMER_0_IRQ PIC_INTR_TO_IRQ(PIC_IRT_TIMER_0_INDEX)
  132. #define PIC_TIMER_1_IRQ PIC_INTR_TO_IRQ(PIC_IRT_TIMER_1_INDEX)
  133. #define PIC_TIMER_2_IRQ PIC_INTR_TO_IRQ(PIC_IRT_TIMER_2_INDEX)
  134. #define PIC_TIMER_3_IRQ PIC_INTR_TO_IRQ(PIC_IRT_TIMER_3_INDEX)
  135. #define PIC_TIMER_4_IRQ PIC_INTR_TO_IRQ(PIC_IRT_TIMER_4_INDEX)
  136. #define PIC_TIMER_5_IRQ PIC_INTR_TO_IRQ(PIC_IRT_TIMER_5_INDEX)
  137. #define PIC_TIMER_6_IRQ PIC_INTR_TO_IRQ(PIC_IRT_TIMER_6_INDEX)
  138. #define PIC_TIMER_7_IRQ PIC_INTR_TO_IRQ(PIC_IRT_TIMER_7_INDEX)
  139. #define PIC_CLOCK_IRQ (PIC_TIMER_7_IRQ)
  140. #define PIC_UART_0_IRQ PIC_INTR_TO_IRQ(PIC_IRT_UART_0_INDEX)
  141. #define PIC_UART_1_IRQ PIC_INTR_TO_IRQ(PIC_IRT_UART_1_INDEX)
  142. #define PIC_I2C_0_IRQ PIC_INTR_TO_IRQ(PIC_IRT_I2C_0_INDEX)
  143. #define PIC_I2C_1_IRQ PIC_INTR_TO_IRQ(PIC_IRT_I2C_1_INDEX)
  144. #define PIC_PCMCIA_IRQ PIC_INTR_TO_IRQ(PIC_IRT_PCMCIA_INDEX)
  145. #define PIC_GPIO_IRQ PIC_INTR_TO_IRQ(PIC_IRT_GPIO_INDEX)
  146. #define PIC_HYPER_IRQ PIC_INTR_TO_IRQ(PIC_IRT_HYPER_INDEX)
  147. #define PIC_PCIX_IRQ PIC_INTR_TO_IRQ(PIC_IRT_PCIX_INDEX)
  148. /* XLS */
  149. #define PIC_CDE_IRQ PIC_INTR_TO_IRQ(PIC_IRT_CDE_INDEX)
  150. #define PIC_BRIDGE_TB_XLS_IRQ PIC_INTR_TO_IRQ(PIC_IRT_BRIDGE_TB_XLS_INDEX)
  151. /* end XLS */
  152. #define PIC_GMAC_0_IRQ PIC_INTR_TO_IRQ(PIC_IRT_GMAC0_INDEX)
  153. #define PIC_GMAC_1_IRQ PIC_INTR_TO_IRQ(PIC_IRT_GMAC1_INDEX)
  154. #define PIC_GMAC_2_IRQ PIC_INTR_TO_IRQ(PIC_IRT_GMAC2_INDEX)
  155. #define PIC_GMAC_3_IRQ PIC_INTR_TO_IRQ(PIC_IRT_GMAC3_INDEX)
  156. #define PIC_XGS_0_IRQ PIC_INTR_TO_IRQ(PIC_IRT_XGS0_INDEX)
  157. #define PIC_XGS_1_IRQ PIC_INTR_TO_IRQ(PIC_IRT_XGS1_INDEX)
  158. #define PIC_HYPER_FATAL_IRQ PIC_INTR_TO_IRQ(PIC_IRT_HYPER_FATAL_INDEX)
  159. #define PIC_PCIX_FATAL_IRQ PIC_INTR_TO_IRQ(PIC_IRT_PCIX_FATAL_INDEX)
  160. #define PIC_BRIDGE_AERR_IRQ PIC_INTR_TO_IRQ(PIC_IRT_BRIDGE_AERR_INDEX)
  161. #define PIC_BRIDGE_BERR_IRQ PIC_INTR_TO_IRQ(PIC_IRT_BRIDGE_BERR_INDEX)
  162. #define PIC_BRIDGE_TB_XLR_IRQ PIC_INTR_TO_IRQ(PIC_IRT_BRIDGE_TB_XLR_INDEX)
  163. #define PIC_BRIDGE_AERR_NMI_IRQ PIC_INTR_TO_IRQ(PIC_IRT_BRIDGE_AERR_NMI_INDEX)
  164. /* XLS defines */
  165. #define PIC_GMAC_4_IRQ PIC_INTR_TO_IRQ(PIC_IRT_GMAC4_INDEX)
  166. #define PIC_GMAC_5_IRQ PIC_INTR_TO_IRQ(PIC_IRT_GMAC5_INDEX)
  167. #define PIC_GMAC_6_IRQ PIC_INTR_TO_IRQ(PIC_IRT_GMAC6_INDEX)
  168. #define PIC_GMAC_7_IRQ PIC_INTR_TO_IRQ(PIC_IRT_GMAC7_INDEX)
  169. #define PIC_BRIDGE_ERR_IRQ PIC_INTR_TO_IRQ(PIC_IRT_BRIDGE_ERR_INDEX)
  170. #define PIC_PCIE_LINK0_IRQ PIC_INTR_TO_IRQ(PIC_IRT_PCIE_LINK0_INDEX)
  171. #define PIC_PCIE_LINK1_IRQ PIC_INTR_TO_IRQ(PIC_IRT_PCIE_LINK1_INDEX)
  172. #define PIC_PCIE_LINK2_IRQ PIC_INTR_TO_IRQ(PIC_IRT_PCIE_LINK2_INDEX)
  173. #define PIC_PCIE_LINK3_IRQ PIC_INTR_TO_IRQ(PIC_IRT_PCIE_LINK3_INDEX)
  174. #define PIC_PCIE_XLSB0_LINK2_IRQ PIC_INTR_TO_IRQ(PIC_IRT_PCIE_XLSB0_LINK2_INDEX)
  175. #define PIC_PCIE_XLSB0_LINK3_IRQ PIC_INTR_TO_IRQ(PIC_IRT_PCIE_XLSB0_LINK3_INDEX)
  176. #define PIC_SRIO_LINK0_IRQ PIC_INTR_TO_IRQ(PIC_IRT_SRIO_LINK0_INDEX)
  177. #define PIC_SRIO_LINK1_IRQ PIC_INTR_TO_IRQ(PIC_IRT_SRIO_LINK1_INDEX)
  178. #define PIC_SRIO_LINK2_IRQ PIC_INTR_TO_IRQ(PIC_IRT_SRIO_LINK2_INDEX)
  179. #define PIC_SRIO_LINK3_IRQ PIC_INTR_TO_IRQ(PIC_IRT_SRIO_LINK3_INDEX)
  180. #define PIC_PCIE_INT_IRQ PIC_INTR_TO_IRQ(PIC_IRT_PCIE_INT__INDEX)
  181. #define PIC_PCIE_FATAL_IRQ PIC_INTR_TO_IRQ(PIC_IRT_PCIE_FATAL_INDEX)
  182. #define PIC_GPIO_B_IRQ PIC_INTR_TO_IRQ(PIC_IRT_GPIO_B_INDEX)
  183. #define PIC_USB_IRQ PIC_INTR_TO_IRQ(PIC_IRT_USB_INDEX)
  184. #define PIC_IRT_LAST_IRQ PIC_USB_IRQ
  185. /* end XLS */
  186. #ifndef __ASSEMBLY__
  187. #define PIC_IRQ_IS_EDGE_TRIGGERED(irq) (((irq) >= PIC_TIMER_0_IRQ) && \
  188. ((irq) <= PIC_TIMER_7_IRQ))
  189. #define PIC_IRQ_IS_IRT(irq) (((irq) >= PIC_IRT_FIRST_IRQ) && \
  190. ((irq) <= PIC_IRT_LAST_IRQ))
  191. static inline int
  192. nlm_irq_to_irt(int irq)
  193. {
  194. if (PIC_IRQ_IS_IRT(irq) == 0)
  195. return -1;
  196. return PIC_IRQ_TO_INTR(irq);
  197. }
  198. static inline int
  199. nlm_irt_to_irq(int irt)
  200. {
  201. return PIC_INTR_TO_IRQ(irt);
  202. }
  203. static inline void
  204. nlm_pic_enable_irt(uint64_t base, int irt)
  205. {
  206. uint32_t reg;
  207. reg = nlm_read_reg(base, PIC_IRT_1(irt));
  208. nlm_write_reg(base, PIC_IRT_1(irt), reg | (1u << 31));
  209. }
  210. static inline void
  211. nlm_pic_disable_irt(uint64_t base, int irt)
  212. {
  213. uint32_t reg;
  214. reg = nlm_read_reg(base, PIC_IRT_1(irt));
  215. nlm_write_reg(base, PIC_IRT_1(irt), reg & ~(1u << 31));
  216. }
  217. static inline void
  218. nlm_pic_send_ipi(uint64_t base, int hwt, int irq, int nmi)
  219. {
  220. unsigned int tid, pid;
  221. tid = hwt & 0x3;
  222. pid = (hwt >> 2) & 0x07;
  223. nlm_write_reg(base, PIC_IPI,
  224. (pid << 20) | (tid << 16) | (nmi << 8) | irq);
  225. }
  226. static inline void
  227. nlm_pic_ack(uint64_t base, int irt)
  228. {
  229. nlm_write_reg(base, PIC_INT_ACK, 1u << irt);
  230. }
  231. static inline void
  232. nlm_pic_init_irt(uint64_t base, int irt, int irq, int hwt, int en)
  233. {
  234. nlm_write_reg(base, PIC_IRT_0(irt), (1u << hwt));
  235. /* local scheduling, invalid, level by default */
  236. nlm_write_reg(base, PIC_IRT_1(irt),
  237. (en << 30) | (1 << 6) | irq);
  238. }
  239. static inline uint64_t
  240. nlm_pic_read_timer(uint64_t base, int timer)
  241. {
  242. uint32_t up1, up2, low;
  243. up1 = nlm_read_reg(base, PIC_TIMER_COUNT_1(timer));
  244. low = nlm_read_reg(base, PIC_TIMER_COUNT_0(timer));
  245. up2 = nlm_read_reg(base, PIC_TIMER_COUNT_1(timer));
  246. if (up1 != up2) /* wrapped, get the new low */
  247. low = nlm_read_reg(base, PIC_TIMER_COUNT_0(timer));
  248. return ((uint64_t)up2 << 32) | low;
  249. }
  250. static inline uint32_t
  251. nlm_pic_read_timer32(uint64_t base, int timer)
  252. {
  253. return nlm_read_reg(base, PIC_TIMER_COUNT_0(timer));
  254. }
  255. static inline void
  256. nlm_pic_set_timer(uint64_t base, int timer, uint64_t value, int irq, int cpu)
  257. {
  258. uint32_t up, low;
  259. uint64_t pic_ctrl = nlm_read_reg(base, PIC_CTRL);
  260. int en;
  261. en = (irq > 0);
  262. up = value >> 32;
  263. low = value & 0xFFFFFFFF;
  264. nlm_write_reg(base, PIC_TIMER_MAXVAL_0(timer), low);
  265. nlm_write_reg(base, PIC_TIMER_MAXVAL_1(timer), up);
  266. nlm_pic_init_irt(base, PIC_IRT_TIMER_INDEX(timer), irq, cpu, 0);
  267. /* enable the timer */
  268. pic_ctrl |= (1 << (PIC_CTRL_STE + timer));
  269. nlm_write_reg(base, PIC_CTRL, pic_ctrl);
  270. }
  271. #endif
  272. #endif /* _ASM_NLM_XLR_PIC_H */