]> CyberLeo.Net >> Repos - FreeBSD/releng/8.2.git/blob - sys/contrib/octeon-sdk/cvmx-interrupt.h
Copy stable/8 to releng/8.2 in preparation for FreeBSD-8.2 release.
[FreeBSD/releng/8.2.git] / sys / contrib / octeon-sdk / cvmx-interrupt.h
1 /***********************license start***************
2  *  Copyright (c) 2003-2008 Cavium Networks (support@cavium.com). All rights
3  *  reserved.
4  *
5  *
6  *  Redistribution and use in source and binary forms, with or without
7  *  modification, are permitted provided that the following conditions are
8  *  met:
9  *
10  *      * Redistributions of source code must retain the above copyright
11  *        notice, this list of conditions and the following disclaimer.
12  *
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.
17  *
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
21  *        permission.
22  *
23  *  TO THE MAXIMUM EXTENT PERMITTED BY LAW, THE SOFTWARE IS PROVIDED "AS IS"
24  *  AND WITH ALL FAULTS AND CAVIUM NETWORKS MAKES NO PROMISES, REPRESENTATIONS
25  *  OR WARRANTIES, EITHER EXPRESS, IMPLIED, STATUTORY, OR OTHERWISE, WITH
26  *  RESPECT TO THE SOFTWARE, INCLUDING ITS CONDITION, ITS CONFORMITY TO ANY
27  *  REPRESENTATION OR DESCRIPTION, OR THE EXISTENCE OF ANY LATENT OR PATENT
28  *  DEFECTS, AND CAVIUM SPECIFICALLY DISCLAIMS ALL IMPLIED (IF ANY) WARRANTIES
29  *  OF TITLE, MERCHANTABILITY, NONINFRINGEMENT, FITNESS FOR A PARTICULAR
30  *  PURPOSE, LACK OF VIRUSES, ACCURACY OR COMPLETENESS, QUIET ENJOYMENT, QUIET
31  *  POSSESSION OR CORRESPONDENCE TO DESCRIPTION.  THE ENTIRE RISK ARISING OUT
32  *  OF USE OR PERFORMANCE OF THE SOFTWARE LIES WITH YOU.
33  *
34  *
35  *  For any questions regarding licensing please contact marketing@caviumnetworks.com
36  *
37  ***********************license end**************************************/
38
39
40
41
42
43
44 /**
45  * @file
46  *
47  * Interface to the Mips interrupts.
48  *
49  * <hr>$Revision: 42203 $<hr>
50  */
51 #ifndef __CVMX_INTERRUPT_H__
52 #define __CVMX_INTERRUPT_H__
53
54 #ifdef  __cplusplus
55 extern "C" {
56 #endif
57
58 /**
59  * Enumeration of Interrupt numbers
60  */
61 typedef enum
62 {
63     /* 0 - 7 represent the 8 MIPS standard interrupt sources */
64     CVMX_IRQ_SW0        = 0,
65     CVMX_IRQ_SW1        = 1,
66     CVMX_IRQ_CIU0       = 2,
67     CVMX_IRQ_CIU1       = 3,
68     CVMX_IRQ_4          = 4,
69     CVMX_IRQ_5          = 5,
70     CVMX_IRQ_6          = 6,
71     CVMX_IRQ_7          = 7,
72
73     /* 8 - 71 represent the sources in CIU_INTX_EN0 */
74     CVMX_IRQ_WORKQ0     = 8,
75     CVMX_IRQ_WORKQ1     = 9,
76     CVMX_IRQ_WORKQ2     = 10,
77     CVMX_IRQ_WORKQ3     = 11,
78     CVMX_IRQ_WORKQ4     = 12,
79     CVMX_IRQ_WORKQ5     = 13,
80     CVMX_IRQ_WORKQ6     = 14,
81     CVMX_IRQ_WORKQ7     = 15,
82     CVMX_IRQ_WORKQ8     = 16,
83     CVMX_IRQ_WORKQ9     = 17,
84     CVMX_IRQ_WORKQ10    = 18,
85     CVMX_IRQ_WORKQ11    = 19,
86     CVMX_IRQ_WORKQ12    = 20,
87     CVMX_IRQ_WORKQ13    = 21,
88     CVMX_IRQ_WORKQ14    = 22,
89     CVMX_IRQ_WORKQ15    = 23,
90     CVMX_IRQ_GPIO0      = 24,
91     CVMX_IRQ_GPIO1      = 25,
92     CVMX_IRQ_GPIO2      = 26,
93     CVMX_IRQ_GPIO3      = 27,
94     CVMX_IRQ_GPIO4      = 28,
95     CVMX_IRQ_GPIO5      = 29,
96     CVMX_IRQ_GPIO6      = 30,
97     CVMX_IRQ_GPIO7      = 31,
98     CVMX_IRQ_GPIO8      = 32,
99     CVMX_IRQ_GPIO9      = 33,
100     CVMX_IRQ_GPIO10     = 34,
101     CVMX_IRQ_GPIO11     = 35,
102     CVMX_IRQ_GPIO12     = 36,
103     CVMX_IRQ_GPIO13     = 37,
104     CVMX_IRQ_GPIO14     = 38,
105     CVMX_IRQ_GPIO15     = 39,
106     CVMX_IRQ_MBOX0      = 40,
107     CVMX_IRQ_MBOX1      = 41,
108     CVMX_IRQ_UART0      = 42,
109     CVMX_IRQ_UART1      = 43,
110     CVMX_IRQ_PCI_INT0   = 44,
111     CVMX_IRQ_PCI_INT1   = 45,
112     CVMX_IRQ_PCI_INT2   = 46,
113     CVMX_IRQ_PCI_INT3   = 47,
114     CVMX_IRQ_PCI_MSI0   = 48,
115     CVMX_IRQ_PCI_MSI1   = 49,
116     CVMX_IRQ_PCI_MSI2   = 50,
117     CVMX_IRQ_PCI_MSI3   = 51,
118     CVMX_IRQ_RESERVED44 = 52,
119     CVMX_IRQ_TWSI       = 53,
120     CVMX_IRQ_RML        = 54,
121     CVMX_IRQ_TRACE      = 55,
122     CVMX_IRQ_GMX_DRP0   = 56,
123     CVMX_IRQ_GMX_DRP1   = 57,
124     CVMX_IRQ_IPD_DRP    = 58,
125     CVMX_IRQ_KEY_ZERO   = 59,
126     CVMX_IRQ_TIMER0     = 60,
127     CVMX_IRQ_TIMER1     = 61,
128     CVMX_IRQ_TIMER2     = 62,
129     CVMX_IRQ_TIMER3     = 63,
130     CVMX_IRQ_USB        = 64,   /* Doesn't apply on CN38XX or CN58XX */
131     CVMX_IRQ_PCM        = 65,
132     CVMX_IRQ_MPI        = 66,
133     CVMX_IRQ_TWSI2      = 67,   /* Added in CN56XX */
134     CVMX_IRQ_POWIQ      = 68,   /* Added in CN56XX */
135     CVMX_IRQ_IPDPPTHR   = 69,   /* Added in CN56XX */
136     CVMX_IRQ_MII        = 70,   /* Added in CN56XX */
137     CVMX_IRQ_BOOTDMA    = 71,   /* Added in CN56XX */
138
139     /* 72 - 135 represent the sources in CIU_INTX_EN1 */
140     CVMX_IRQ_WDOG0 = 72,
141     CVMX_IRQ_WDOG1 = 73,
142     CVMX_IRQ_WDOG2 = 74,
143     CVMX_IRQ_WDOG3 = 75,
144     CVMX_IRQ_WDOG4 = 76,
145     CVMX_IRQ_WDOG5 = 77,
146     CVMX_IRQ_WDOG6 = 78,
147     CVMX_IRQ_WDOG7 = 79,
148     CVMX_IRQ_WDOG8 = 80,
149     CVMX_IRQ_WDOG9 = 81,
150     CVMX_IRQ_WDOG10= 82,
151     CVMX_IRQ_WDOG11= 83,
152     CVMX_IRQ_WDOG12= 84,
153     CVMX_IRQ_WDOG13= 85,
154     CVMX_IRQ_WDOG14= 86,
155     CVMX_IRQ_WDOG15= 87
156     /* numbers 88 - 135 are reserved */
157 } cvmx_irq_t;
158
159 /**
160  * Function prototype for the exception handler
161  */
162 typedef void (*cvmx_interrupt_exception_t)(uint64_t registers[32]);
163
164 /**
165  * Function prototype for interrupt handlers
166  */
167 typedef void (*cvmx_interrupt_func_t)(int irq_number, uint64_t registers[32], void *user_arg);
168
169 /**
170  * Register an interrupt handler for the specified interrupt number.
171  *
172  * @param irq_number Interrupt number to register for (0-135)
173  * @param func       Function to call on interrupt.
174  * @param user_arg   User data to pass to the interrupt handler
175  */
176 void cvmx_interrupt_register(cvmx_irq_t irq_number, cvmx_interrupt_func_t func, void *user_arg);
177
178 /**
179  * Set the exception handler for all non interrupt sources.
180  *
181  * @param handler New exception handler
182  * @return Old exception handler
183  */
184 cvmx_interrupt_exception_t cvmx_interrupt_set_exception(cvmx_interrupt_exception_t handler);
185
186 /**
187  * Masks a given interrupt number.
188  * EN0 sources are masked on IP2
189  * EN1 sources are masked on IP3
190  *
191  * @param irq_number interrupt number to mask (0-135)
192  */
193 static inline void cvmx_interrupt_mask_irq(int irq_number)
194 {
195     if (irq_number<8)
196     {
197         uint32_t mask;
198         asm volatile ("mfc0 %0,$12,0" : "=r" (mask));
199         mask &= ~(1<< (8 + irq_number));
200         asm volatile ("mtc0 %0,$12,0" : : "r" (mask));
201     }
202     else if (irq_number < 8 + 64)
203     {
204         int ciu_bit = (irq_number - 8) & 63;
205         int ciu_offset = cvmx_get_core_num() * 2;
206         uint64_t mask = cvmx_read_csr(CVMX_CIU_INTX_EN0(ciu_offset));
207         mask &= ~(1ull << ciu_bit);
208         cvmx_write_csr(CVMX_CIU_INTX_EN0(ciu_offset), mask);
209     }
210     else
211     {
212         int ciu_bit = (irq_number - 8) & 63;
213         int ciu_offset = cvmx_get_core_num() * 2 + 1;
214         uint64_t mask = cvmx_read_csr(CVMX_CIU_INTX_EN1(ciu_offset));
215         mask &= ~(1ull << ciu_bit);
216         cvmx_write_csr(CVMX_CIU_INTX_EN1(ciu_offset), mask);
217     }
218 }
219
220
221 /**
222  * Unmasks a given interrupt number
223  * EN0 sources are unmasked on IP2
224  * EN1 sources are unmasked on IP3
225  *
226  * @param irq_number interrupt number to unmask (0-135)
227  */
228 static inline void cvmx_interrupt_unmask_irq(int irq_number)
229 {
230     if (irq_number<8)
231     {
232         uint32_t mask;
233         asm volatile ("mfc0 %0,$12,0" : "=r" (mask));
234         mask |= (1<< (8 + irq_number));
235         asm volatile ("mtc0 %0,$12,0" : : "r" (mask));
236     }
237     else if (irq_number < 8 + 64)
238     {
239         int ciu_bit = (irq_number - 8) & 63;
240         int ciu_offset = cvmx_get_core_num() * 2;
241         uint64_t mask = cvmx_read_csr(CVMX_CIU_INTX_EN0(ciu_offset));
242         mask |= (1ull << ciu_bit);
243         cvmx_write_csr(CVMX_CIU_INTX_EN0(ciu_offset), mask);
244     }
245     else
246     {
247         int ciu_bit = (irq_number - 8) & 63;
248         int ciu_offset = cvmx_get_core_num() * 2 + 1;
249         uint64_t mask = cvmx_read_csr(CVMX_CIU_INTX_EN1(ciu_offset));
250         mask |= (1ull << ciu_bit);
251         cvmx_write_csr(CVMX_CIU_INTX_EN1(ciu_offset), mask);
252     }
253 }
254
255
256 /* Disable interrupts by clearing bit 0 of the COP0 status register,
257 ** and return the previous contents of the status register.
258 ** Note: this is only used to track interrupt status. */
259 static inline uint32_t cvmx_interrupt_disable_save(void)
260 {
261     uint32_t flags;
262     asm volatile (
263         "DI   %[flags]\n"
264         : [flags]"=r" (flags));
265     return(flags);
266 }
267
268 /* Restore the contents of the cop0 status register.  Used with
269 ** cvmx_interrupt_disable_save to allow recursive interrupt disabling */
270 static inline void cvmx_interrupt_restore(uint32_t flags)
271 {
272     /* If flags value indicates interrupts should be enabled, then enable them */
273     if (flags & 1)
274     {
275         asm volatile (
276             "EI     \n"
277             ::);
278     }
279 }
280
281 /**
282  * Utility function to decode Octeon's RSL_INT_BLOCKS interrupts
283  * into error messages.
284  */
285 extern void cvmx_interrupt_rsl_decode(void);
286
287 /**
288  * Utility function to enable all RSL error interupts
289  */
290 extern void cvmx_interrupt_rsl_enable(void);
291
292 /**
293  * Utility function to do interrupt safe printf 
294  */
295 #ifdef CVMX_BUILD_FOR_LINUX_KERNEL
296         #define cvmx_safe_printf printk
297 #elif defined(CVMX_BUILD_FOR_LINUX_USER)
298         #define cvmx_safe_printf printf
299 #else
300         extern void cvmx_safe_printf(const char* format, ... ) __attribute__ ((format(printf, 1, 2)));
301 #endif 
302 #ifdef  __cplusplus
303 }
304 #endif
305
306 #endif