]>
git.ipfire.org Git - people/ms/u-boot.git/blob - cpu/ppc4xx/interrupts.c
2 * (C) Copyright 2000-2002
3 * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
5 * (C) Copyright 2002 (440 port)
6 * Scott McNutt, Artesyn Communication Producs, smcnutt@artsyncp.com
8 * See file CREDITS for list of people who contributed to this
11 * This program is free software; you can redistribute it and/or
12 * modify it under the terms of the GNU General Public License as
13 * published by the Free Software Foundation; either version 2 of
14 * the License, or (at your option) any later version.
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
21 * You should have received a copy of the GNU General Public License
22 * along with this program; if not, write to the Free Software
23 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
30 #include <asm/processor.h>
32 #include <ppc_asm.tmpl>
36 /****************************************************************************/
38 unsigned decrementer_count
; /* count value for 1e6/HZ microseconds */
40 /****************************************************************************/
43 * CPM interrupt vector functions.
46 interrupt_handler_t
*handler
;
51 static struct irq_action irq_vecs
[32];
53 #if defined(CONFIG_440)
54 static struct irq_action irq_vecs1
[32]; /* For UIC1 */
56 void uic1_interrupt( void * parms
); /* UIC1 handler */
59 /****************************************************************************/
61 static __inline__
unsigned long get_msr(void)
65 asm volatile("mfmsr %0" : "=r" (msr
) :);
69 static __inline__
void set_msr(unsigned long msr
)
71 asm volatile("mtmsr %0" : : "r" (msr
));
74 #if defined(CONFIG_440)
76 /* SPRN changed in 440 */
77 static __inline__
void set_evpr(unsigned long val
)
79 asm volatile("mtspr 0x03f,%0" : : "r" (val
));
82 #else /* !defined(CONFIG_440) */
84 static __inline__
unsigned long get_dec(void)
88 asm volatile("mfdec %0" : "=r" (val
) :);
93 static __inline__
void set_dec(unsigned long val
)
95 asm volatile("mtdec %0" : : "r" (val
));
99 static __inline__
void set_pit(unsigned long val
)
101 asm volatile("mtpit %0" : : "r" (val
));
105 static __inline__
void set_tcr(unsigned long val
)
107 asm volatile("mttcr %0" : : "r" (val
));
111 static __inline__
void set_evpr(unsigned long val
)
113 asm volatile("mtevpr %0" : : "r" (val
));
115 #endif /* defined(CONFIG_440 */
118 void enable_interrupts (void)
120 set_msr (get_msr() | MSR_EE
);
123 /* returns flag if MSR_EE was set before */
124 int disable_interrupts (void)
126 ulong msr
= get_msr();
127 set_msr (msr
& ~MSR_EE
);
128 return ((msr
& MSR_EE
) != 0);
131 /****************************************************************************/
133 int interrupt_init(void)
135 DECLARE_GLOBAL_DATA_PTR
;
141 * Mark all irqs as free
143 for (vec
=0; vec
<32; vec
++) {
144 irq_vecs
[vec
].handler
= NULL
;
145 irq_vecs
[vec
].arg
= NULL
;
146 irq_vecs
[vec
].count
= 0;
147 #if defined(CONFIG_440)
148 irq_vecs1
[vec
].handler
= NULL
;
149 irq_vecs1
[vec
].arg
= NULL
;
150 irq_vecs1
[vec
].count
= 0;
158 #if defined(CONFIG_440)
160 val
&= (~0x04400000); /* clear DIS & ARE */
162 mtspr( dec
, 0 ); /* Prevent exception after TSR clear*/
163 mtspr( decar
, 0 ); /* clear reload */
164 mtspr( tsr
, 0x08000000 ); /* clear DEC status */
165 val
= gd
->bd
->bi_intfreq
/100; /* 10 msec */
166 mtspr( decar
, val
); /* Set auto-reload value */
167 mtspr( dec
, val
); /* Set inital val */
169 set_pit(gd
->bd
->bi_intfreq
/ 1000);
171 #endif /* CONFIG_4xx */
190 set_evpr(0x00000000);
192 #if defined(CONFIG_440)
193 /* Install the UIC1 handlers */
194 irq_install_handler(VECNUM_UIC1NC
, uic1_interrupt
, 0);
195 irq_install_handler(VECNUM_UIC1C
, uic1_interrupt
, 0);
198 * Enable external interrupts (including PIT)
200 set_msr (get_msr() | MSR_EE
);
205 /****************************************************************************/
208 * Handle external interrupts
210 void external_interrupt(struct pt_regs
*regs
)
217 * Read masked interrupt status register to determine interrupt source
219 uic_msr
= mfdcr(uicmsr
);
223 while (msr_shift
!= 0) {
224 if (msr_shift
& 0x80000000) {
226 * Increment irq counter (for debug purpose only)
228 irq_vecs
[vec
].count
++;
230 if (irq_vecs
[vec
].handler
!= NULL
) {
232 (*irq_vecs
[vec
].handler
)(irq_vecs
[vec
].arg
);
234 mtdcr(uicer
, mfdcr(uicer
) & ~(0x80000000 >> vec
));
235 printf ("Masking bogus interrupt vector 0x%x\n", vec
);
239 * After servicing the interrupt, we have to remove the status indicator.
241 mtdcr(uicsr
, (0x80000000 >> vec
));
245 * Shift msr to next position and increment vector
252 #if defined(CONFIG_440)
253 /* Handler for UIC1 interrupt */
254 void uic1_interrupt( void * parms
)
261 * Read masked interrupt status register to determine interrupt source
263 uic1_msr
= mfdcr(uic1msr
);
264 msr_shift
= uic1_msr
;
267 while (msr_shift
!= 0) {
268 if (msr_shift
& 0x80000000) {
270 * Increment irq counter (for debug purpose only)
272 irq_vecs1
[vec
].count
++;
274 if (irq_vecs1
[vec
].handler
!= NULL
) {
276 (*irq_vecs1
[vec
].handler
)(irq_vecs1
[vec
].arg
);
278 mtdcr(uic1er
, mfdcr(uic1er
) & ~(0x80000000 >> vec
));
279 printf ("Masking bogus interrupt vector (uic1) 0x%x\n", vec
);
283 * After servicing the interrupt, we have to remove the status indicator.
285 mtdcr(uic1sr
, (0x80000000 >> vec
));
289 * Shift msr to next position and increment vector
295 #endif /* defined(CONFIG_440) */
297 /****************************************************************************/
300 * Install and free a interrupt handler.
304 irq_install_handler(int vec
, interrupt_handler_t
*handler
, void *arg
)
306 struct irq_action
*irqa
= irq_vecs
;
309 #if defined(CONFIG_440)
316 if (irqa
[i
].handler
!= NULL
) {
317 printf ("Interrupt vector %d: handler 0x%x replacing 0x%x\n",
318 vec
, (uint
)handler
, (uint
)irqa
[i
].handler
);
320 irqa
[i
].handler
= handler
;
323 #if defined(CONFIG_440)
325 mtdcr(uic1er
, mfdcr(uic1er
) | (0x80000000 >> i
));
328 mtdcr(uicer
, mfdcr(uicer
) | (0x80000000 >> i
));
330 printf ("Install interrupt for vector %d ==> %p\n", vec
, handler
);
335 irq_free_handler(int vec
)
337 struct irq_action
*irqa
= irq_vecs
;
340 #if defined(CONFIG_440)
348 printf ("Free interrupt for vector %d ==> %p\n",
349 vec
, irq_vecs
[vec
].handler
);
352 #if defined(CONFIG_440)
354 mtdcr(uic1er
, mfdcr(uic1er
) & ~(0x80000000 >> i
));
357 mtdcr(uicer
, mfdcr(uicer
) & ~(0x80000000 >> i
));
359 irqa
[i
].handler
= NULL
;
363 /****************************************************************************/
366 volatile ulong timestamp
= 0;
369 * timer_interrupt - gets called when the decrementer overflows,
370 * with interrupts disabled.
371 * Trivial implementation - no need to be really accurate.
373 void timer_interrupt(struct pt_regs
*regs
)
376 printf ("*** Timer Interrupt *** ");
380 #if defined(CONFIG_WATCHDOG)
381 if ((timestamp
% 1000) == 0)
382 reset_4xx_watchdog();
383 #endif /* CONFIG_WATCHDOG */
386 /****************************************************************************/
388 void reset_timer (void)
393 ulong
get_timer (ulong base
)
395 return (timestamp
- base
);
398 void set_timer (ulong t
)
403 /****************************************************************************/
406 #if (CONFIG_COMMANDS & CFG_CMD_IRQ)
408 /*******************************************************************************
410 * irqinfo - print information about PCI devices
414 do_irqinfo(cmd_tbl_t
*cmdtp
, int flag
, int argc
, char *argv
[])
418 printf ("\nInterrupt-Information:\n");
419 #if defined(CONFIG_440)
420 printf ("\nUIC 0\n");
422 printf ("Nr Routine Arg Count\n");
424 for (vec
=0; vec
<32; vec
++) {
425 if (irq_vecs
[vec
].handler
!= NULL
) {
426 printf ("%02d %08lx %08lx %d\n",
428 (ulong
)irq_vecs
[vec
].handler
,
429 (ulong
)irq_vecs
[vec
].arg
,
430 irq_vecs
[vec
].count
);
434 #if defined(CONFIG_440)
435 printf ("\nUIC 1\n");
436 printf ("Nr Routine Arg Count\n");
438 for (vec
=0; vec
<32; vec
++)
440 if (irq_vecs1
[vec
].handler
!= NULL
)
441 printf ("%02d %08lx %08lx %d\n",
442 vec
+31, (ulong
)irq_vecs1
[vec
].handler
,
443 (ulong
)irq_vecs1
[vec
].arg
, irq_vecs1
[vec
].count
);
451 #endif /* CONFIG_COMMANDS & CFG_CMD_IRQ */