1 /***********************license start***************
2 * Copyright (c) 2003-2010 Cavium Inc. (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 Inc. 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 INC. 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: 70030 $<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 */
74 /* 64 WORKQ interrupts. */
76 /* 16 GPIO interrupts. */
77 CVMX_IRQ_GPIO0 = CVMX_IRQ_WORKQ0 + 64,
78 /* 4 MBOX interrupts. */
79 CVMX_IRQ_MBOX0 = CVMX_IRQ_GPIO0 + 16,
80 /* 3 UART interrupts. */
81 CVMX_IRQ_UART0 = CVMX_IRQ_MBOX0 + 4,
82 CVMX_IRQ_PCI_INT0 = CVMX_IRQ_UART0 + 3,
90 /* 2 TWSI interrupts */
92 CVMX_IRQ_RML = CVMX_IRQ_TWSI0 + 2,
93 /* 4 TRACE interrupts added in CN68XX */
95 /* 5 GMX_DRP interrupts added in CN68XX */
96 CVMX_IRQ_GMX_DRP0 = CVMX_IRQ_TRACE0 + 4,
97 CVMX_IRQ_GMX_DRP1, /* Doesn't apply on CN52XX or CN63XX */
98 CVMX_IRQ_IPD_DRP = CVMX_IRQ_GMX_DRP0 + 5,
99 CVMX_IRQ_KEY_ZERO, /* Doesn't apply on CN52XX or CN63XX */
100 /* 4 TIMER interrupts. */
102 /* 2 USB interrupts. */
103 CVMX_IRQ_USB0 = CVMX_IRQ_TIMER0 + 4, /* Doesn't apply on CN38XX or CN58XX */
104 CVMX_IRQ_PCM = CVMX_IRQ_USB0 + 2, /* Doesn't apply on CN52XX or CN63XX */
105 CVMX_IRQ_MPI, /* Doesn't apply on CN52XX or CN63XX */
106 CVMX_IRQ_POWIQ, /* Added in CN56XX */
107 CVMX_IRQ_IPDPPTHR, /* Added in CN56XX */
108 /* 2 MII interrupts. */
109 CVMX_IRQ_MII0, /* Added in CN56XX */
110 CVMX_IRQ_BOOTDMA = CVMX_IRQ_MII0 + 2, /* Added in CN56XX */
112 /* 32 WDOG interrupts. */
114 CVMX_IRQ_NAND = CVMX_IRQ_WDOG0 + 32, /* Added in CN52XX */
115 CVMX_IRQ_MIO, /* Added in CN63XX */
116 CVMX_IRQ_IOB, /* Added in CN63XX */
117 CVMX_IRQ_FPA, /* Added in CN63XX */
118 CVMX_IRQ_POW, /* Added in CN63XX */
119 CVMX_IRQ_L2C, /* Added in CN63XX */
120 CVMX_IRQ_IPD, /* Added in CN63XX */
121 CVMX_IRQ_PIP, /* Added in CN63XX */
122 CVMX_IRQ_PKO, /* Added in CN63XX */
123 CVMX_IRQ_ZIP, /* Added in CN63XX */
124 CVMX_IRQ_TIM, /* Added in CN63XX */
125 CVMX_IRQ_RAD, /* Added in CN63XX */
126 CVMX_IRQ_KEY, /* Added in CN63XX */
127 CVMX_IRQ_DFA, /* Added in CN63XX */
128 CVMX_IRQ_USBCTL, /* Added in CN63XX */
129 CVMX_IRQ_SLI, /* Added in CN63XX */
130 CVMX_IRQ_DPI, /* Added in CN63XX */
131 /* 5 AGX interrupts added in CN68XX. */
132 CVMX_IRQ_AGX0, /* Added in CN63XX */
134 CVMX_IRQ_AGL = CVMX_IRQ_AGX0 + 5, /* Added in CN63XX */
135 CVMX_IRQ_PTP, /* Added in CN63XX */
136 CVMX_IRQ_PEM0, /* Added in CN63XX */
137 CVMX_IRQ_PEM1, /* Added in CN63XX */
138 CVMX_IRQ_SRIO0, /* Added in CN63XX */
139 CVMX_IRQ_SRIO1, /* Added in CN63XX */
140 CVMX_IRQ_LMC0, /* Added in CN63XX */
141 /* 4 LMC interrupts added in CN68XX. */
142 CVMX_IRQ_DFM = CVMX_IRQ_LMC0 + 4, /* Added in CN63XX */
143 CVMX_IRQ_RST, /* Added in CN63XX */
144 CVMX_IRQ_ILK, /* Added for CN68XX */
145 CVMX_IRQ_SRIO2, /* Added in CN66XX */
146 CVMX_IRQ_DPI_DMA, /* Added in CN61XX */
147 /* 6 addition timers added in CN61XX */
148 CVMX_IRQ_TIMER4, /* Added in CN61XX */
149 CVMX_IRQ_MAX = CVMX_IRQ_TIMER4 + 6 /* One greater than the last valid number.*/
153 * Function prototype for the exception handler
155 typedef void (*cvmx_interrupt_exception_t)(uint64_t *registers);
158 * Function prototype for interrupt handlers
160 typedef void (*cvmx_interrupt_func_t)(int irq_number, uint64_t *registers, void *user_arg);
163 * Register an interrupt handler for the specified interrupt number.
165 * @param irq_number Interrupt number to register for (0-135)
166 * @param func Function to call on interrupt.
167 * @param user_arg User data to pass to the interrupt handler
169 void cvmx_interrupt_register(int irq_number, cvmx_interrupt_func_t func, void *user_arg);
172 * Set the exception handler for all non interrupt sources.
174 * @param handler New exception handler
175 * @return Old exception handler
177 cvmx_interrupt_exception_t cvmx_interrupt_set_exception(cvmx_interrupt_exception_t handler);
181 * Masks a given interrupt number.
183 * @param irq_number interrupt number to mask
185 extern void (*cvmx_interrupt_mask_irq)(int irq_number);
189 * Unmasks a given interrupt number
191 * @param irq_number interrupt number to unmask
193 extern void (*cvmx_interrupt_unmask_irq)(int irq_number);
196 /* Disable interrupts by clearing bit 0 of the COP0 status register,
197 ** and return the previous contents of the status register.
198 ** Note: this is only used to track interrupt status. */
199 static inline uint32_t cvmx_interrupt_disable_save(void)
204 : [flags]"=r" (flags));
208 /* Restore the contents of the cop0 status register. Used with
209 ** cvmx_interrupt_disable_save to allow recursive interrupt disabling */
210 static inline void cvmx_interrupt_restore(uint32_t flags)
212 /* If flags value indicates interrupts should be enabled, then enable them */
221 #define cvmx_local_irq_save(x) ({x = cvmx_interrupt_disable_save();})
222 #define cvmx_local_irq_restore(x) cvmx_interrupt_restore(x)
225 * Utility function to do interrupt safe printf
227 #ifdef CVMX_BUILD_FOR_LINUX_KERNEL
228 #define cvmx_safe_printf printk
229 #elif defined(CVMX_BUILD_FOR_LINUX_USER)
230 #define cvmx_safe_printf printf
232 extern void cvmx_safe_printf(const char* format, ... ) __attribute__ ((format(printf, 1, 2)));
235 #define PRINT_ERROR(format, ...) cvmx_safe_printf("ERROR " format, ##__VA_ARGS__)