]> git.ipfire.org Git - people/ms/u-boot.git/blob - lib_ppc/interrupts.c
Conditionally add -fno-stack-protector to CFLAGS
[people/ms/u-boot.git] / lib_ppc / interrupts.c
1 /*
2 * (C) Copyright 2000-2002
3 * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
4 *
5 * (C) Copyright 2003
6 * Gleb Natapov <gnatapov@mrv.com>
7 *
8 * See file CREDITS for list of people who contributed to this
9 * project.
10 *
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.
15 *
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.
20 *
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,
24 * MA 02111-1307 USA
25 */
26
27 #include <common.h>
28 #include <asm/processor.h>
29 #include <watchdog.h>
30 #ifdef CONFIG_STATUS_LED
31 #include <status_led.h>
32 #endif
33
34 #ifdef CONFIG_SHOW_ACTIVITY
35 extern void board_show_activity (ulong);
36 #endif /* CONFIG_SHOW_ACTIVITY */
37
38 #ifndef CFG_WATCHDOG_FREQ
39 #define CFG_WATCHDOG_FREQ (CFG_HZ / 2)
40 #endif
41
42 extern int interrupt_init_cpu (unsigned *);
43 extern void timer_interrupt_cpu (struct pt_regs *);
44
45 static unsigned decrementer_count; /* count value for 1e6/HZ microseconds */
46
47 static __inline__ unsigned long get_msr (void)
48 {
49 unsigned long msr;
50
51 asm volatile ("mfmsr %0":"=r" (msr):);
52
53 return msr;
54 }
55
56 static __inline__ void set_msr (unsigned long msr)
57 {
58 asm volatile ("mtmsr %0"::"r" (msr));
59 }
60
61 static __inline__ unsigned long get_dec (void)
62 {
63 unsigned long val;
64
65 asm volatile ("mfdec %0":"=r" (val):);
66
67 return val;
68 }
69
70
71 static __inline__ void set_dec (unsigned long val)
72 {
73 if (val)
74 asm volatile ("mtdec %0"::"r" (val));
75 }
76
77
78 void enable_interrupts (void)
79 {
80 set_msr (get_msr () | MSR_EE);
81 }
82
83 /* returns flag if MSR_EE was set before */
84 int disable_interrupts (void)
85 {
86 ulong msr = get_msr ();
87
88 set_msr (msr & ~MSR_EE);
89 return ((msr & MSR_EE) != 0);
90 }
91
92 int interrupt_init (void)
93 {
94 int ret;
95
96 /* call cpu specific function from $(CPU)/interrupts.c */
97 ret = interrupt_init_cpu (&decrementer_count);
98
99 if (ret)
100 return ret;
101
102 set_dec (decrementer_count);
103
104 set_msr (get_msr () | MSR_EE);
105
106 return (0);
107 }
108
109 static volatile ulong timestamp = 0;
110
111 void timer_interrupt (struct pt_regs *regs)
112 {
113 /* call cpu specific function from $(CPU)/interrupts.c */
114 timer_interrupt_cpu (regs);
115
116 /* Restore Decrementer Count */
117 set_dec (decrementer_count);
118
119 timestamp++;
120
121 #if defined(CONFIG_WATCHDOG) || defined (CONFIG_HW_WATCHDOG)
122 if ((timestamp % (CFG_WATCHDOG_FREQ)) == 0)
123 WATCHDOG_RESET ();
124 #endif /* CONFIG_WATCHDOG || CONFIG_HW_WATCHDOG */
125
126 #ifdef CONFIG_STATUS_LED
127 status_led_tick (timestamp);
128 #endif /* CONFIG_STATUS_LED */
129
130 #ifdef CONFIG_SHOW_ACTIVITY
131 board_show_activity (timestamp);
132 #endif /* CONFIG_SHOW_ACTIVITY */
133 }
134
135 void reset_timer (void)
136 {
137 timestamp = 0;
138 }
139
140 ulong get_timer (ulong base)
141 {
142 return (timestamp - base);
143 }
144
145 void set_timer (ulong t)
146 {
147 timestamp = t;
148 }