pic.h 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415
  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 _NLM_HAL_PIC_H
  35. #define _NLM_HAL_PIC_H
  36. /* PIC Specific registers */
  37. #define PIC_CTRL 0x00
  38. /* PIC control register defines */
  39. #define PIC_CTRL_ITV 32 /* interrupt timeout value */
  40. #define PIC_CTRL_ICI 19 /* ICI interrupt timeout enable */
  41. #define PIC_CTRL_ITE 18 /* interrupt timeout enable */
  42. #define PIC_CTRL_STE 10 /* system timer interrupt enable */
  43. #define PIC_CTRL_WWR1 8 /* watchdog 1 wraparound count for reset */
  44. #define PIC_CTRL_WWR0 6 /* watchdog 0 wraparound count for reset */
  45. #define PIC_CTRL_WWN1 4 /* watchdog 1 wraparound count for NMI */
  46. #define PIC_CTRL_WWN0 2 /* watchdog 0 wraparound count for NMI */
  47. #define PIC_CTRL_WTE 0 /* watchdog timer enable */
  48. /* PIC Status register defines */
  49. #define PIC_ICI_STATUS 33 /* ICI interrupt timeout status */
  50. #define PIC_ITE_STATUS 32 /* interrupt timeout status */
  51. #define PIC_STS_STATUS 4 /* System timer interrupt status */
  52. #define PIC_WNS_STATUS 2 /* NMI status for watchdog timers */
  53. #define PIC_WIS_STATUS 0 /* Interrupt status for watchdog timers */
  54. /* PIC IPI control register offsets */
  55. #define PIC_IPICTRL_NMI 32
  56. #define PIC_IPICTRL_RIV 20 /* received interrupt vector */
  57. #define PIC_IPICTRL_IDB 16 /* interrupt destination base */
  58. #define PIC_IPICTRL_DTE 0 /* interrupt destination thread enables */
  59. /* PIC IRT register offsets */
  60. #define PIC_IRT_ENABLE 31
  61. #define PIC_IRT_NMI 29
  62. #define PIC_IRT_SCH 28 /* Scheduling scheme */
  63. #define PIC_IRT_RVEC 20 /* Interrupt receive vectors */
  64. #define PIC_IRT_DT 19 /* Destination type */
  65. #define PIC_IRT_DB 16 /* Destination base */
  66. #define PIC_IRT_DTE 0 /* Destination thread enables */
  67. #define PIC_BYTESWAP 0x02
  68. #define PIC_STATUS 0x04
  69. #define PIC_INTR_TIMEOUT 0x06
  70. #define PIC_ICI0_INTR_TIMEOUT 0x08
  71. #define PIC_ICI1_INTR_TIMEOUT 0x0a
  72. #define PIC_ICI2_INTR_TIMEOUT 0x0c
  73. #define PIC_IPI_CTL 0x0e
  74. #define PIC_INT_ACK 0x10
  75. #define PIC_INT_PENDING0 0x12
  76. #define PIC_INT_PENDING1 0x14
  77. #define PIC_INT_PENDING2 0x16
  78. #define PIC_WDOG0_MAXVAL 0x18
  79. #define PIC_WDOG0_COUNT 0x1a
  80. #define PIC_WDOG0_ENABLE0 0x1c
  81. #define PIC_WDOG0_ENABLE1 0x1e
  82. #define PIC_WDOG0_BEATCMD 0x20
  83. #define PIC_WDOG0_BEAT0 0x22
  84. #define PIC_WDOG0_BEAT1 0x24
  85. #define PIC_WDOG1_MAXVAL 0x26
  86. #define PIC_WDOG1_COUNT 0x28
  87. #define PIC_WDOG1_ENABLE0 0x2a
  88. #define PIC_WDOG1_ENABLE1 0x2c
  89. #define PIC_WDOG1_BEATCMD 0x2e
  90. #define PIC_WDOG1_BEAT0 0x30
  91. #define PIC_WDOG1_BEAT1 0x32
  92. #define PIC_WDOG_MAXVAL(i) (PIC_WDOG0_MAXVAL + ((i) ? 7 : 0))
  93. #define PIC_WDOG_COUNT(i) (PIC_WDOG0_COUNT + ((i) ? 7 : 0))
  94. #define PIC_WDOG_ENABLE0(i) (PIC_WDOG0_ENABLE0 + ((i) ? 7 : 0))
  95. #define PIC_WDOG_ENABLE1(i) (PIC_WDOG0_ENABLE1 + ((i) ? 7 : 0))
  96. #define PIC_WDOG_BEATCMD(i) (PIC_WDOG0_BEATCMD + ((i) ? 7 : 0))
  97. #define PIC_WDOG_BEAT0(i) (PIC_WDOG0_BEAT0 + ((i) ? 7 : 0))
  98. #define PIC_WDOG_BEAT1(i) (PIC_WDOG0_BEAT1 + ((i) ? 7 : 0))
  99. #define PIC_TIMER0_MAXVAL 0x34
  100. #define PIC_TIMER1_MAXVAL 0x36
  101. #define PIC_TIMER2_MAXVAL 0x38
  102. #define PIC_TIMER3_MAXVAL 0x3a
  103. #define PIC_TIMER4_MAXVAL 0x3c
  104. #define PIC_TIMER5_MAXVAL 0x3e
  105. #define PIC_TIMER6_MAXVAL 0x40
  106. #define PIC_TIMER7_MAXVAL 0x42
  107. #define PIC_TIMER_MAXVAL(i) (PIC_TIMER0_MAXVAL + ((i) * 2))
  108. #define PIC_TIMER0_COUNT 0x44
  109. #define PIC_TIMER1_COUNT 0x46
  110. #define PIC_TIMER2_COUNT 0x48
  111. #define PIC_TIMER3_COUNT 0x4a
  112. #define PIC_TIMER4_COUNT 0x4c
  113. #define PIC_TIMER5_COUNT 0x4e
  114. #define PIC_TIMER6_COUNT 0x50
  115. #define PIC_TIMER7_COUNT 0x52
  116. #define PIC_TIMER_COUNT(i) (PIC_TIMER0_COUNT + ((i) * 2))
  117. #define PIC_ITE0_N0_N1 0x54
  118. #define PIC_ITE1_N0_N1 0x58
  119. #define PIC_ITE2_N0_N1 0x5c
  120. #define PIC_ITE3_N0_N1 0x60
  121. #define PIC_ITE4_N0_N1 0x64
  122. #define PIC_ITE5_N0_N1 0x68
  123. #define PIC_ITE6_N0_N1 0x6c
  124. #define PIC_ITE7_N0_N1 0x70
  125. #define PIC_ITE_N0_N1(i) (PIC_ITE0_N0_N1 + ((i) * 4))
  126. #define PIC_ITE0_N2_N3 0x56
  127. #define PIC_ITE1_N2_N3 0x5a
  128. #define PIC_ITE2_N2_N3 0x5e
  129. #define PIC_ITE3_N2_N3 0x62
  130. #define PIC_ITE4_N2_N3 0x66
  131. #define PIC_ITE5_N2_N3 0x6a
  132. #define PIC_ITE6_N2_N3 0x6e
  133. #define PIC_ITE7_N2_N3 0x72
  134. #define PIC_ITE_N2_N3(i) (PIC_ITE0_N2_N3 + ((i) * 4))
  135. #define PIC_IRT0 0x74
  136. #define PIC_IRT(i) (PIC_IRT0 + ((i) * 2))
  137. #define TIMER_CYCLES_MAXVAL 0xffffffffffffffffULL
  138. /*
  139. * IRT Map
  140. */
  141. #define PIC_NUM_IRTS 160
  142. #define PIC_IRT_WD_0_INDEX 0
  143. #define PIC_IRT_WD_1_INDEX 1
  144. #define PIC_IRT_WD_NMI_0_INDEX 2
  145. #define PIC_IRT_WD_NMI_1_INDEX 3
  146. #define PIC_IRT_TIMER_0_INDEX 4
  147. #define PIC_IRT_TIMER_1_INDEX 5
  148. #define PIC_IRT_TIMER_2_INDEX 6
  149. #define PIC_IRT_TIMER_3_INDEX 7
  150. #define PIC_IRT_TIMER_4_INDEX 8
  151. #define PIC_IRT_TIMER_5_INDEX 9
  152. #define PIC_IRT_TIMER_6_INDEX 10
  153. #define PIC_IRT_TIMER_7_INDEX 11
  154. #define PIC_IRT_CLOCK_INDEX PIC_IRT_TIMER_7_INDEX
  155. #define PIC_IRT_TIMER_INDEX(num) ((num) + PIC_IRT_TIMER_0_INDEX)
  156. /* 11 and 12 */
  157. #define PIC_NUM_MSG_Q_IRTS 32
  158. #define PIC_IRT_MSG_Q0_INDEX 12
  159. #define PIC_IRT_MSG_Q_INDEX(qid) ((qid) + PIC_IRT_MSG_Q0_INDEX)
  160. /* 12 to 43 */
  161. #define PIC_IRT_MSG_0_INDEX 44
  162. #define PIC_IRT_MSG_1_INDEX 45
  163. /* 44 and 45 */
  164. #define PIC_NUM_PCIE_MSIX_IRTS 32
  165. #define PIC_IRT_PCIE_MSIX_0_INDEX 46
  166. #define PIC_IRT_PCIE_MSIX_INDEX(num) ((num) + PIC_IRT_PCIE_MSIX_0_INDEX)
  167. /* 46 to 77 */
  168. #define PIC_NUM_PCIE_LINK_IRTS 4
  169. #define PIC_IRT_PCIE_LINK_0_INDEX 78
  170. #define PIC_IRT_PCIE_LINK_1_INDEX 79
  171. #define PIC_IRT_PCIE_LINK_2_INDEX 80
  172. #define PIC_IRT_PCIE_LINK_3_INDEX 81
  173. #define PIC_IRT_PCIE_LINK_INDEX(num) ((num) + PIC_IRT_PCIE_LINK_0_INDEX)
  174. /* 78 to 81 */
  175. #define PIC_NUM_NA_IRTS 32
  176. /* 82 to 113 */
  177. #define PIC_IRT_NA_0_INDEX 82
  178. #define PIC_IRT_NA_INDEX(num) ((num) + PIC_IRT_NA_0_INDEX)
  179. #define PIC_IRT_POE_INDEX 114
  180. #define PIC_NUM_USB_IRTS 6
  181. #define PIC_IRT_USB_0_INDEX 115
  182. #define PIC_IRT_EHCI_0_INDEX 115
  183. #define PIC_IRT_OHCI_0_INDEX 116
  184. #define PIC_IRT_OHCI_1_INDEX 117
  185. #define PIC_IRT_EHCI_1_INDEX 118
  186. #define PIC_IRT_OHCI_2_INDEX 119
  187. #define PIC_IRT_OHCI_3_INDEX 120
  188. #define PIC_IRT_USB_INDEX(num) ((num) + PIC_IRT_USB_0_INDEX)
  189. /* 115 to 120 */
  190. #define PIC_IRT_GDX_INDEX 121
  191. #define PIC_IRT_SEC_INDEX 122
  192. #define PIC_IRT_RSA_INDEX 123
  193. #define PIC_NUM_COMP_IRTS 4
  194. #define PIC_IRT_COMP_0_INDEX 124
  195. #define PIC_IRT_COMP_INDEX(num) ((num) + PIC_IRT_COMP_0_INDEX)
  196. /* 124 to 127 */
  197. #define PIC_IRT_GBU_INDEX 128
  198. #define PIC_IRT_ICC_0_INDEX 129 /* ICC - Inter Chip Coherency */
  199. #define PIC_IRT_ICC_1_INDEX 130
  200. #define PIC_IRT_ICC_2_INDEX 131
  201. #define PIC_IRT_CAM_INDEX 132
  202. #define PIC_IRT_UART_0_INDEX 133
  203. #define PIC_IRT_UART_1_INDEX 134
  204. #define PIC_IRT_I2C_0_INDEX 135
  205. #define PIC_IRT_I2C_1_INDEX 136
  206. #define PIC_IRT_SYS_0_INDEX 137
  207. #define PIC_IRT_SYS_1_INDEX 138
  208. #define PIC_IRT_JTAG_INDEX 139
  209. #define PIC_IRT_PIC_INDEX 140
  210. #define PIC_IRT_NBU_INDEX 141
  211. #define PIC_IRT_TCU_INDEX 142
  212. #define PIC_IRT_GCU_INDEX 143 /* GBC - Global Coherency */
  213. #define PIC_IRT_DMC_0_INDEX 144
  214. #define PIC_IRT_DMC_1_INDEX 145
  215. #define PIC_NUM_GPIO_IRTS 4
  216. #define PIC_IRT_GPIO_0_INDEX 146
  217. #define PIC_IRT_GPIO_INDEX(num) ((num) + PIC_IRT_GPIO_0_INDEX)
  218. /* 146 to 149 */
  219. #define PIC_IRT_NOR_INDEX 150
  220. #define PIC_IRT_NAND_INDEX 151
  221. #define PIC_IRT_SPI_INDEX 152
  222. #define PIC_IRT_MMC_INDEX 153
  223. #define PIC_CLOCK_TIMER 7
  224. #define PIC_IRQ_BASE 8
  225. #if !defined(LOCORE) && !defined(__ASSEMBLY__)
  226. #define PIC_IRT_FIRST_IRQ (PIC_IRQ_BASE)
  227. #define PIC_IRT_LAST_IRQ 63
  228. #define PIC_IRQ_IS_IRT(irq) ((irq) >= PIC_IRT_FIRST_IRQ)
  229. /*
  230. * Misc
  231. */
  232. #define PIC_IRT_VALID 1
  233. #define PIC_LOCAL_SCHEDULING 1
  234. #define PIC_GLOBAL_SCHEDULING 0
  235. #define nlm_read_pic_reg(b, r) nlm_read_reg64(b, r)
  236. #define nlm_write_pic_reg(b, r, v) nlm_write_reg64(b, r, v)
  237. #define nlm_get_pic_pcibase(node) nlm_pcicfg_base(XLP_IO_PIC_OFFSET(node))
  238. #define nlm_get_pic_regbase(node) (nlm_get_pic_pcibase(node) + XLP_IO_PCI_HDRSZ)
  239. /* IRT and h/w interrupt routines */
  240. static inline int
  241. nlm_pic_read_irt(uint64_t base, int irt_index)
  242. {
  243. return nlm_read_pic_reg(base, PIC_IRT(irt_index));
  244. }
  245. static inline uint64_t
  246. nlm_pic_read_control(uint64_t base)
  247. {
  248. return nlm_read_pic_reg(base, PIC_CTRL);
  249. }
  250. static inline void
  251. nlm_pic_write_control(uint64_t base, uint64_t control)
  252. {
  253. nlm_write_pic_reg(base, PIC_CTRL, control);
  254. }
  255. static inline void
  256. nlm_pic_update_control(uint64_t base, uint64_t control)
  257. {
  258. uint64_t val;
  259. val = nlm_read_pic_reg(base, PIC_CTRL);
  260. nlm_write_pic_reg(base, PIC_CTRL, control | val);
  261. }
  262. static inline void
  263. nlm_set_irt_to_cpu(uint64_t base, int irt, int cpu)
  264. {
  265. uint64_t val;
  266. val = nlm_read_pic_reg(base, PIC_IRT(irt));
  267. val |= cpu & 0xf;
  268. if (cpu > 15)
  269. val |= 1 << 16;
  270. nlm_write_pic_reg(base, PIC_IRT(irt), val);
  271. }
  272. static inline void
  273. nlm_pic_write_irt(uint64_t base, int irt_num, int en, int nmi,
  274. int sch, int vec, int dt, int db, int dte)
  275. {
  276. uint64_t val;
  277. val = (((uint64_t)en & 0x1) << 31) | ((nmi & 0x1) << 29) |
  278. ((sch & 0x1) << 28) | ((vec & 0x3f) << 20) |
  279. ((dt & 0x1) << 19) | ((db & 0x7) << 16) |
  280. (dte & 0xffff);
  281. nlm_write_pic_reg(base, PIC_IRT(irt_num), val);
  282. }
  283. static inline void
  284. nlm_pic_write_irt_direct(uint64_t base, int irt_num, int en, int nmi,
  285. int sch, int vec, int cpu)
  286. {
  287. nlm_pic_write_irt(base, irt_num, en, nmi, sch, vec, 1,
  288. (cpu >> 4), /* thread group */
  289. 1 << (cpu & 0xf)); /* thread mask */
  290. }
  291. static inline uint64_t
  292. nlm_pic_read_timer(uint64_t base, int timer)
  293. {
  294. return nlm_read_pic_reg(base, PIC_TIMER_COUNT(timer));
  295. }
  296. static inline void
  297. nlm_pic_write_timer(uint64_t base, int timer, uint64_t value)
  298. {
  299. nlm_write_pic_reg(base, PIC_TIMER_COUNT(timer), value);
  300. }
  301. static inline void
  302. nlm_pic_set_timer(uint64_t base, int timer, uint64_t value, int irq, int cpu)
  303. {
  304. uint64_t pic_ctrl = nlm_read_pic_reg(base, PIC_CTRL);
  305. int en;
  306. en = (irq > 0);
  307. nlm_write_pic_reg(base, PIC_TIMER_MAXVAL(timer), value);
  308. nlm_pic_write_irt_direct(base, PIC_IRT_TIMER_INDEX(timer),
  309. en, 0, 0, irq, cpu);
  310. /* enable the timer */
  311. pic_ctrl |= (1 << (PIC_CTRL_STE + timer));
  312. nlm_write_pic_reg(base, PIC_CTRL, pic_ctrl);
  313. }
  314. static inline void
  315. nlm_pic_enable_irt(uint64_t base, int irt)
  316. {
  317. uint64_t reg;
  318. reg = nlm_read_pic_reg(base, PIC_IRT(irt));
  319. nlm_write_pic_reg(base, PIC_IRT(irt), reg | (1u << 31));
  320. }
  321. static inline void
  322. nlm_pic_disable_irt(uint64_t base, int irt)
  323. {
  324. uint32_t reg;
  325. reg = nlm_read_pic_reg(base, PIC_IRT(irt));
  326. nlm_write_pic_reg(base, PIC_IRT(irt), reg & ~((uint64_t)1 << 31));
  327. }
  328. static inline void
  329. nlm_pic_send_ipi(uint64_t base, int hwt, int irq, int nmi)
  330. {
  331. uint64_t ipi;
  332. int node, ncpu;
  333. node = hwt / 32;
  334. ncpu = hwt & 0x1f;
  335. ipi = ((uint64_t)nmi << 31) | (irq << 20) | (node << 17) |
  336. (1 << (ncpu & 0xf));
  337. if (ncpu > 15)
  338. ipi |= 0x10000; /* Setting bit 16 to select cpus 16-31 */
  339. nlm_write_pic_reg(base, PIC_IPI_CTL, ipi);
  340. }
  341. static inline void
  342. nlm_pic_ack(uint64_t base, int irt_num)
  343. {
  344. nlm_write_pic_reg(base, PIC_INT_ACK, irt_num);
  345. /* Ack the Status register for Watchdog & System timers */
  346. if (irt_num < 12)
  347. nlm_write_pic_reg(base, PIC_STATUS, (1 << irt_num));
  348. }
  349. static inline void
  350. nlm_pic_init_irt(uint64_t base, int irt, int irq, int hwt)
  351. {
  352. nlm_pic_write_irt_direct(base, irt, 0, 0, 0, irq, 0);
  353. }
  354. extern uint64_t nlm_pic_base;
  355. int nlm_irq_to_irt(int irq);
  356. int nlm_irt_to_irq(int irt);
  357. #endif /* __ASSEMBLY__ */
  358. #endif /* _NLM_HAL_PIC_H */