1 /***********************license start***************
2 * Copyright (c) 2003-2010 Cavium Networks (support@cavium.com). All rights
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions are
10 * * Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
13 * * Redistributions in binary form must reproduce the above
14 * copyright notice, this list of conditions and the following
15 * disclaimer in the documentation and/or other materials provided
16 * with the distribution.
18 * * Neither the name of Cavium Networks nor the names of
19 * its contributors may be used to endorse or promote products
20 * derived from this software without specific prior written
23 * This Software, including technical data, may be subject to U.S. export control
24 * laws, including the U.S. Export Administration Act and its associated
25 * regulations, and may be subject to export or import regulations in other
28 * TO THE MAXIMUM EXTENT PERMITTED BY LAW, THE SOFTWARE IS PROVIDED "AS IS"
29 * AND WITH ALL FAULTS AND CAVIUM NETWORKS MAKES NO PROMISES, REPRESENTATIONS OR
30 * WARRANTIES, EITHER EXPRESS, IMPLIED, STATUTORY, OR OTHERWISE, WITH RESPECT TO
31 * THE SOFTWARE, INCLUDING ITS CONDITION, ITS CONFORMITY TO ANY REPRESENTATION OR
32 * DESCRIPTION, OR THE EXISTENCE OF ANY LATENT OR PATENT DEFECTS, AND CAVIUM
33 * SPECIFICALLY DISCLAIMS ALL IMPLIED (IF ANY) WARRANTIES OF TITLE,
34 * MERCHANTABILITY, NONINFRINGEMENT, FITNESS FOR A PARTICULAR PURPOSE, LACK OF
35 * VIRUSES, ACCURACY OR COMPLETENESS, QUIET ENJOYMENT, QUIET POSSESSION OR
36 * CORRESPONDENCE TO DESCRIPTION. THE ENTIRE RISK ARISING OUT OF USE OR
37 * PERFORMANCE OF THE SOFTWARE LIES WITH YOU.
38 ***********************license end**************************************/
49 * Interface to the Mips interrupts.
51 * <hr>$Revision: 49448 $<hr>
53 #ifndef __CVMX_INTERRUPT_H__
54 #define __CVMX_INTERRUPT_H__
61 * Enumeration of Interrupt numbers
65 /* 0 - 7 represent the 8 MIPS standard interrupt sources */
75 /* 8 - 71 represent the sources in CIU_INTX_EN0 */
86 CVMX_IRQ_WORKQ10 = 18,
87 CVMX_IRQ_WORKQ11 = 19,
88 CVMX_IRQ_WORKQ12 = 20,
89 CVMX_IRQ_WORKQ13 = 21,
90 CVMX_IRQ_WORKQ14 = 22,
91 CVMX_IRQ_WORKQ15 = 23,
102 CVMX_IRQ_GPIO10 = 34,
103 CVMX_IRQ_GPIO11 = 35,
104 CVMX_IRQ_GPIO12 = 36,
105 CVMX_IRQ_GPIO13 = 37,
106 CVMX_IRQ_GPIO14 = 38,
107 CVMX_IRQ_GPIO15 = 39,
112 CVMX_IRQ_PCI_INT0 = 44,
113 CVMX_IRQ_PCI_INT1 = 45,
114 CVMX_IRQ_PCI_INT2 = 46,
115 CVMX_IRQ_PCI_INT3 = 47,
116 CVMX_IRQ_PCI_MSI0 = 48,
117 CVMX_IRQ_PCI_MSI1 = 49,
118 CVMX_IRQ_PCI_MSI2 = 50,
119 CVMX_IRQ_PCI_MSI3 = 51,
120 CVMX_IRQ_RESERVED44 = 52,
124 CVMX_IRQ_GMX_DRP0 = 56,
125 CVMX_IRQ_GMX_DRP1 = 57, /* Doesn't apply on CN52XX or CN63XX */
126 CVMX_IRQ_IPD_DRP = 58,
127 CVMX_IRQ_KEY_ZERO = 59, /* Doesn't apply on CN52XX or CN63XX */
128 CVMX_IRQ_TIMER0 = 60,
129 CVMX_IRQ_TIMER1 = 61,
130 CVMX_IRQ_TIMER2 = 62,
131 CVMX_IRQ_TIMER3 = 63,
132 CVMX_IRQ_USB0 = 64, /* Doesn't apply on CN38XX or CN58XX */
133 CVMX_IRQ_PCM = 65, /* Doesn't apply on CN52XX or CN63XX */
134 CVMX_IRQ_MPI = 66, /* Doesn't apply on CN52XX or CN63XX */
135 CVMX_IRQ_TWSI2 = 67, /* Added in CN56XX */
136 CVMX_IRQ_POWIQ = 68, /* Added in CN56XX */
137 CVMX_IRQ_IPDPPTHR = 69, /* Added in CN56XX */
138 CVMX_IRQ_MII = 70, /* Added in CN56XX */
139 CVMX_IRQ_BOOTDMA = 71, /* Added in CN56XX */
141 /* 72 - 135 represent the sources in CIU_INTX_EN1 */
158 CVMX_IRQ_UART2 = 88, /* Added in CN52XX */
159 CVMX_IRQ_USB1 = 89, /* Added in CN52XX */
160 CVMX_IRQ_MII1 = 90, /* Added in CN52XX */
161 CVMX_IRQ_NAND = 91, /* Added in CN52XX */
162 CVMX_IRQ_MIO = 92, /* Added in CN63XX */
163 CVMX_IRQ_IOB = 93, /* Added in CN63XX */
164 CVMX_IRQ_FPA = 94, /* Added in CN63XX */
165 CVMX_IRQ_POW = 95, /* Added in CN63XX */
166 CVMX_IRQ_L2C = 96, /* Added in CN63XX */
167 CVMX_IRQ_IPD = 97, /* Added in CN63XX */
168 CVMX_IRQ_PIP = 98, /* Added in CN63XX */
169 CVMX_IRQ_PKO = 99, /* Added in CN63XX */
170 CVMX_IRQ_ZIP = 100, /* Added in CN63XX */
171 CVMX_IRQ_TIM = 101, /* Added in CN63XX */
172 CVMX_IRQ_RAD = 102, /* Added in CN63XX */
173 CVMX_IRQ_KEY = 103, /* Added in CN63XX */
174 CVMX_IRQ_DFA = 104, /* Added in CN63XX */
175 CVMX_IRQ_USB = 105, /* Added in CN63XX */
176 CVMX_IRQ_SLI = 106, /* Added in CN63XX */
177 CVMX_IRQ_DPI = 107, /* Added in CN63XX */
178 CVMX_IRQ_AGX0 = 108, /* Added in CN63XX */
179 /* 109 - 117 are reserved */
180 CVMX_IRQ_AGL = 118, /* Added in CN63XX */
181 CVMX_IRQ_PTP = 119, /* Added in CN63XX */
182 CVMX_IRQ_PEM0 = 120, /* Added in CN63XX */
183 CVMX_IRQ_PEM1 = 121, /* Added in CN63XX */
184 CVMX_IRQ_SRIO0 = 122, /* Added in CN63XX */
185 CVMX_IRQ_SRIO1 = 123, /* Added in CN63XX */
186 CVMX_IRQ_LMC0 = 124, /* Added in CN63XX */
187 /* Interrupts 125 - 127 are reserved */
188 CVMX_IRQ_DFM = 128, /* Added in CN63XX */
189 /* Interrupts 129 - 135 are reserved */
193 * Function prototype for the exception handler
195 typedef void (*cvmx_interrupt_exception_t)(uint64_t registers[32]);
198 * Function prototype for interrupt handlers
200 typedef void (*cvmx_interrupt_func_t)(int irq_number, uint64_t registers[32], void *user_arg);
203 * Register an interrupt handler for the specified interrupt number.
205 * @param irq_number Interrupt number to register for (0-135)
206 * @param func Function to call on interrupt.
207 * @param user_arg User data to pass to the interrupt handler
209 void cvmx_interrupt_register(cvmx_irq_t irq_number, cvmx_interrupt_func_t func, void *user_arg);
212 * Set the exception handler for all non interrupt sources.
214 * @param handler New exception handler
215 * @return Old exception handler
217 cvmx_interrupt_exception_t cvmx_interrupt_set_exception(cvmx_interrupt_exception_t handler);
220 * Masks a given interrupt number.
221 * EN0 sources are masked on IP2
222 * EN1 sources are masked on IP3
224 * @param irq_number interrupt number to mask (0-135)
226 static inline void cvmx_interrupt_mask_irq(int irq_number)
231 asm volatile ("mfc0 %0,$12,0" : "=r" (mask));
232 mask &= ~(1<< (8 + irq_number));
233 asm volatile ("mtc0 %0,$12,0" : : "r" (mask));
235 else if (irq_number < 8 + 64)
237 int ciu_bit = (irq_number - 8) & 63;
238 int ciu_offset = cvmx_get_core_num() * 2;
239 uint64_t mask = cvmx_read_csr(CVMX_CIU_INTX_EN0(ciu_offset));
240 mask &= ~(1ull << ciu_bit);
241 cvmx_write_csr(CVMX_CIU_INTX_EN0(ciu_offset), mask);
245 int ciu_bit = (irq_number - 8) & 63;
246 int ciu_offset = cvmx_get_core_num() * 2 + 1;
247 uint64_t mask = cvmx_read_csr(CVMX_CIU_INTX_EN1(ciu_offset));
248 mask &= ~(1ull << ciu_bit);
249 cvmx_write_csr(CVMX_CIU_INTX_EN1(ciu_offset), mask);
255 * Unmasks a given interrupt number
256 * EN0 sources are unmasked on IP2
257 * EN1 sources are unmasked on IP3
259 * @param irq_number interrupt number to unmask (0-135)
261 static inline void cvmx_interrupt_unmask_irq(int irq_number)
266 asm volatile ("mfc0 %0,$12,0" : "=r" (mask));
267 mask |= (1<< (8 + irq_number));
268 asm volatile ("mtc0 %0,$12,0" : : "r" (mask));
270 else if (irq_number < 8 + 64)
272 int ciu_bit = (irq_number - 8) & 63;
273 int ciu_offset = cvmx_get_core_num() * 2;
274 uint64_t mask = cvmx_read_csr(CVMX_CIU_INTX_EN0(ciu_offset));
275 mask |= (1ull << ciu_bit);
276 cvmx_write_csr(CVMX_CIU_INTX_EN0(ciu_offset), mask);
280 int ciu_bit = (irq_number - 8) & 63;
281 int ciu_offset = cvmx_get_core_num() * 2 + 1;
282 uint64_t mask = cvmx_read_csr(CVMX_CIU_INTX_EN1(ciu_offset));
283 mask |= (1ull << ciu_bit);
284 cvmx_write_csr(CVMX_CIU_INTX_EN1(ciu_offset), mask);
289 /* Disable interrupts by clearing bit 0 of the COP0 status register,
290 ** and return the previous contents of the status register.
291 ** Note: this is only used to track interrupt status. */
292 static inline uint32_t cvmx_interrupt_disable_save(void)
297 : [flags]"=r" (flags));
301 /* Restore the contents of the cop0 status register. Used with
302 ** cvmx_interrupt_disable_save to allow recursive interrupt disabling */
303 static inline void cvmx_interrupt_restore(uint32_t flags)
305 /* If flags value indicates interrupts should be enabled, then enable them */
314 #define cvmx_local_irq_save(x) ({x = cvmx_interrupt_disable_save();})
315 #define cvmx_local_irq_restore(x) cvmx_interrupt_restore(x)
318 * Utility function to do interrupt safe printf
320 #ifdef CVMX_BUILD_FOR_LINUX_KERNEL
321 #define cvmx_safe_printf printk
322 #elif defined(CVMX_BUILD_FOR_LINUX_USER)
323 #define cvmx_safe_printf printf
325 extern void cvmx_safe_printf(const char* format, ... ) __attribute__ ((format(printf, 1, 2)));
328 #define PRINT_ERROR(format, ...) cvmx_safe_printf("ERROR " format, ##__VA_ARGS__)