GUI: Fix Tomato RAF theme for all builds. Compilation typo.
[tomato.git] / release / src-rt-6.x.4708 / cfe / cfe / arch / mips / cpu / sb1250 / src / sb1250_ircpoll.S
blobe8f5c8d48b7b1cab53dec268cebe40f55fbf84ba
1 /*  *********************************************************************
2     *  SB1250 Board Support Package
3     *  
4     *  IRQ polling                              File: sb1250_ircpoll.S
5     *  
6     *  This module contains code to poll the interrupt controller
7     *  and invoke the servicing of pending, unmasked interrupts.
8     *  
9     *********************************************************************  
10     *
11     *  Copyright 2000,2001,2002,2003
12     *  Broadcom Corporation. All rights reserved.
13     *  
14     *  This software is furnished under license and may be used and 
15     *  copied only in accordance with the following terms and 
16     *  conditions.  Subject to these conditions, you may download, 
17     *  copy, install, use, modify and distribute modified or unmodified 
18     *  copies of this software in source and/or binary form.  No title 
19     *  or ownership is transferred hereby.
20     *  
21     *  1) Any source code used, modified or distributed must reproduce 
22     *     and retain this copyright notice and list of conditions 
23     *     as they appear in the source file.
24     *  
25     *  2) No right is granted to use any trade name, trademark, or 
26     *     logo of Broadcom Corporation.  The "Broadcom Corporation" 
27     *     name may not be used to endorse or promote products derived 
28     *     from this software without the prior written permission of 
29     *     Broadcom Corporation.
30     *  
31     *  3) THIS SOFTWARE IS PROVIDED "AS-IS" AND ANY EXPRESS OR
32     *     IMPLIED WARRANTIES, INCLUDING BUT NOT LIMITED TO, ANY IMPLIED
33     *     WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR 
34     *     PURPOSE, OR NON-INFRINGEMENT ARE DISCLAIMED. IN NO EVENT 
35     *     SHALL BROADCOM BE LIABLE FOR ANY DAMAGES WHATSOEVER, AND IN 
36     *     PARTICULAR, BROADCOM SHALL NOT BE LIABLE FOR DIRECT, INDIRECT,
37     *     INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 
38     *     (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
39     *     GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
40     *     BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY 
41     *     OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR 
42     *     TORT (INCLUDING NEGLIGENCE OR OTHERWISE), EVEN IF ADVISED OF 
43     *     THE POSSIBILITY OF SUCH DAMAGE.
44     ********************************************************************* */
46 #include "mipsmacros.h"
47 #incldue "initdata.h"
48 #include "sbmips.h"
49 #include "sb1250_regs.h"
50 #include "sb1250_int.h"
53  * External interrupt conventions:
54  *   i5 (IP7) is reserved for sources within the CPU
55  *   i0 (IP2) is used for polling and always masked
56  *   i1 (IP3) is used for armed interrupts that are registered (not yet)
57  *   i2-i4 are available for specific devices.
58  */
59         
60 /* EOIs are issued when LDT interrupts are programmed as levels. */
61         
62 #define A_LDT_EOI 0x90000000d8000000
63 #define D_EOI_MDT (0x7 << 2)
64         
66  * Dispatch function address.  Access to this function pointer assumes
67  * that gp has been initialized and any relocation has been done.
68  */
69         .sdata
71         .globl  irq_dispatch
72 irq_dispatch:
73         _LONG_  0
75         .text   
76         
77 /*  *********************************************************************
78     * sb1250_irq_install()
79     *   
80     * Initialize dispatch pointer.  See CALLINIT_RELOC in mipsmacros.h
81     * for the logic used here.  This function should be called after
82     * any relocation is done and gp is initialized.
83     *
84     * This function should be called with interrupts disabled.
85     *
86     * Input parameters: 
87     *   nothing
88     *
89     * Return value:     
90     *   nothing                                 
91     ********************************************************************* */
92         
93         .set    push
94         .set    noreorder
96         .extern sb1250_dispatch_irq
98 dispatch_func:
99         _LONG_  sb1250_dispatch_irq
100         
101 LEAF(sb1250_irq_install)
102         
103         move    a0, ra                          /* LOADREL can clobber */
104         LOADREL(v0,dispatch_func)
105         move    ra, a0
106         LR      v0, 0(v0)
107 #if CFG_EMBEDDED_PIC
108         beq     gp, zero, 1f                    /* is this ever ok? */
109         LR      v1, mem_textreloc
110         daddu   v0, v0, v1
111 #endif
112 1:      SR      v0, irq_dispatch
114         jr      ra
115         nop     
117 END(sb1250_irq_install)
119         .set    pop
121         
122 /*  *********************************************************************
123     *  CFE_IRQ_POLL
124     *  
125     *  Scan the interrupt_source_status and interrupt_ldt registers.
126     *  For those not masked by the interrupt_mask register, invoke
127     *  cfe_dispatch_irq with the interrupt number as argument.
128     *
129     *  For LDT-signaled interrupts, also clear the pending vector.
130     *  
131     *  For asynchronous dispatch, called with interrupts disabled.
132     *
133     *  Input parameters: 
134     *      nothing
135     *      
136     *  Return value:
137     *      nothing
138     ********************************************************************* */
140         .set    push
141         .set    noreorder
142         .set    noat
143         .set    mips64
146         /* This version also shows one way of saving 64-bit registers
147         in systems that don't necessarily preserve the high 32 bits
148         across subroutine calls.  That is not an issue for CFE with
149         current compilation options but is required for, e.g., 32-bit
150         Linux and NetBSD systems. */
151         
152 LEAF(cfe_irq_poll)
154         daddiu  sp, -56         /* saved register space */
155         sd      s0, 32(sp)
156         sd      s1, 40(sp)
157         sd      ra, 48(sp)
159         mfc0    a0, C0_CAUSE
160         andi    a0, a0, M_CAUSE_IP2
161         beqz    a0, 4f
162         
163         la      v0, K1BASE + A_IMR_CPU0_BASE
164         ld      a1, R_IMR_INTERRUPT_MASK(v0)    
165         ld      s0, R_IMR_INTERRUPT_SOURCE_STATUS(v0)
166         ld      s1, R_IMR_LDT_INTERRUPT(v0)
167         nor     a1, a1, zero    /* Negate mask to turn it into an and mask */
168         or      s0, s0, s1      /* Unified pending bits */
169         and     s0, s0, a1      /* Bit vector of unmasked pending IRQs */
170         and     s1, s1, a1      /* ... and unmasked LDT IRQs */
171         beqz    s0, 4f          /* No interrupts.  Return */
172         nop
173         
174         /* Clear the accumulated LDT (edge-triggered) interrupts */
175         sd      s1, R_IMR_LDT_INTERRUPT_CLR(v0)
177         /* The bit scan loop */
178         dclz    s1, s0          /* Find index of the next interrupt */
180         li      a1, 1
181         dsubu   a0, zero, s1
182         daddiu  a0, a0, 63     
183         dsllv   a1, a1, a0
184         xor     s0, s0, a1      /* clear current bit */
185         LR      v0, irq_dispatch
186         jalr    ra, v0
187         dsrl32  s1, s0, 0       /* Save upper 32 bits of unified vector */
189         dsll32  s0, s0, 0       /* clear upper bits of s0            */
190         dsll32  s1, s1, 0       /* get saved back in the right place */
191         dsrl32  s0, s0, 0       /* realign s0                        */
192         or      s0, s0, s1      /* restore the saved bits            */
193         bnez    s0, 3b          /* More interrupts to service?       */
194         dclz    s1, s0          /* unroll for branch delay slot */
195 4:                        
196         ld      ra, 48(sp)      /* restore registers */
197         ld      s1, 40(sp)
198         ld      s0, 32(sp)
199         
200         jr      ra
201         daddiu  sp, 56          /* saved register space */
202                 
203 END(cfe_irq_poll)
204         
205         .set    pop
208 /*  *********************************************************************
209     * sb1250_irq_arm()
210     *   
211     * Set up CP0 Status and Cause per conventions above (not really -- yet)
212     *
213     * This function should be called with interrupts disabled.
214     *
215     * Input parameters: 
216     *   nothing
217     *
218     * Return value:     
219     *   nothing                                 
220     ********************************************************************* */
221         
222         .set    push
223         .set    noreorder
225 LEAF(sb1250_irq_arm)
226         
227         mfc0    t0,C0_CAUSE
228         or      t0,t0,M_CAUSE_IV
229         mtc0    t0,C0_CAUSE
231         mfc0    t0,C0_SR
232         li      t1,M_SR_IMMASK          /* Mask all interrupt levels */
233         nor     t1,t1,zero
234         and     t0,t0,t1
235         or      t0,t0,M_SR_IE           /* but set IE */
236         mtc0    t0,C0_SR
237         
238         ssnop
239         ssnop
240         ssnop
241         ssnop
243         jr      ra
244         nop     
246 END(sb1250_irq_arm)
248         .set    pop
252         
253         .set    push
254         .set    noreorder
256 LEAF(cfe_irq_disable)
257         
258         mfc0    t0,C0_SR
259         li      t1,M_SR_IMMASK|M_SR_IE
260         li      t2,~(M_SR_IMMASK|M_SR_IE)
261         and     v0,t0,t1                /* current mask bits */
262         and     t0,t0,t2
263         mtc0    t0,C0_SR                /* all enables cleared */
264         
265         ssnop
266         ssnop
267         ssnop
268         ssnop
270         jr      ra
271         nop     
273 END(cfe_irq_disable)
275         .set    pop
277         
278         
279         .set    push
280         .set    noreorder
282 LEAF(cfe_irq_enable)
283         
284         mfc0    t0,C0_SR
285         li      t1,M_SR_IMMASK|M_SR_IE
286         li      t2,~(M_SR_IMMASK|M_SR_IE)
287         and     a0,a0,t1
288         and     t0,t0,t2
289         or      t0,t0,a0
290         mtc0    t0,C0_SR
291         
292         ssnop
293         ssnop
294         ssnop
295         ssnop
297         jr      ra
298         nop     
300 END(cfe_irq_enable)
302         .set    pop
305 /*  *********************************************************************
306     * sb1250_update_sr(clear,set)
307     *   
308     * Upate Status.IM according to masks
309     *
310     * Caller should disable interrupts if the effect is to be atomic.
311     *
312     * Input parameters: 
313     *   a0         SR bits to be cleared
314     *   a1         SR bits to be set    
315     *
316     * Return value:     
317     *   none
318     ********************************************************************* */
319         
320         .set    push
321         .set    noreorder
323 LEAF(sb1250_update_sr)
324         
325         nor     a0,a0,zero
326         mfc0    t0,C0_SR
327         and     t0,t0,a0                /* current mask bits */
328         or      t0,t0,a1
329         mtc0    t0,C0_SR                /* all enables cleared */
330         
331         ssnop
332         ssnop
333         ssnop
334         ssnop
336         jr      ra
337         nop     
339 END(sb1250_update_sr)
341         .set    pop