3 * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
6 * Josh Huber <huber@mclx.com>, Mission Critical Linux, Inc.
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,
28 * interrupts.c - just enough support for the decrementer/timer
32 #include <asm/processor.h>
35 /****************************************************************************/
37 unsigned decrementer_count; /* count value for 1e6/HZ microseconds */
39 /****************************************************************************/
41 static __inline__ unsigned long
46 asm volatile("mfmsr %0" : "=r" (msr) :);
50 static __inline__ void
51 set_msr(unsigned long msr)
53 asm volatile("mtmsr %0" : : "r" (msr));
56 static __inline__ unsigned long
61 asm volatile("mfdec %0" : "=r" (val) :);
66 static __inline__ void
67 set_dec(unsigned long val)
69 asm volatile("mtdec %0" : : "r" (val));
74 enable_interrupts(void)
76 set_msr (get_msr() | MSR_EE);
79 /* returns flag if MSR_EE was set before */
81 disable_interrupts(void)
83 ulong msr = get_msr();
84 set_msr (msr & ~MSR_EE);
85 return ((msr & MSR_EE) != 0);
88 /****************************************************************************/
90 int interrupt_init(void)
92 decrementer_count = get_tbclk() / CFG_HZ;
95 puts("interrupt_init: setting actual decremter\n");
97 set_dec (get_tbclk() / CFG_HZ);
100 printf("interrupt_init: enabling interrupts (msr = %08lx)\n",
103 set_msr (get_msr() | MSR_EE);
106 printf("interrupt_init: done. (msr = %08lx)\n", get_msr());
111 /****************************************************************************/
114 * Handle external interrupts
117 external_interrupt(struct pt_regs *regs)
119 puts("external_interrupt (oops!)\n");
122 volatile ulong timestamp = 0;
125 * timer_interrupt - gets called when the decrementer overflows,
126 * with interrupts disabled.
127 * Trivial implementation - no need to be really accurate.
130 timer_interrupt(struct pt_regs *regs)
132 set_dec(decrementer_count);
136 /****************************************************************************/
145 get_timer(ulong base)
147 return (timestamp - base);
156 /****************************************************************************/
159 * Install and free a interrupt handler.
163 irq_install_handler(int vec, interrupt_handler_t *handler, void *arg)
169 irq_free_handler(int vec)
174 /****************************************************************************/
177 do_irqinfo(cmd_tbl_t *cmdtp, bd_t *bd, int flag, int argc, char *argv[])
179 puts("IRQ related functions are unimplemented currently.\n");