1#include <common.h>
2#include <asm/processor.h>
3#include <memio.h>
4#include <linux/ctype.h>
5
6static __inline__ unsigned long
7get_msr(void)
8{
9 unsigned long msr;
10
11 asm volatile("mfmsr %0" : "=r" (msr) :);
12 return msr;
13}
14
15static __inline__ void
16set_msr(unsigned long msr)
17{
18 asm volatile("mtmsr %0" : : "r" (msr));
19}
20
21static __inline__ unsigned long
22get_dec(void)
23{
24 unsigned long val;
25
26 asm volatile("mfdec %0" : "=r" (val) :);
27 return val;
28}
29
30
31static __inline__ void
32set_dec(unsigned long val)
33{
34 asm volatile("mtdec %0" : : "r" (val));
35}
36
37
38void
39enable_interrupts(void)
40{
41 set_msr (get_msr() | MSR_EE);
42}
43
44
45int
46disable_interrupts(void)
47{
48 ulong msr;
49
50 msr = get_msr();
51 set_msr (msr & ~MSR_EE);
52 return ((msr & MSR_EE) != 0);
53}
54
55u8 in8(u32 port)
56{
57 return in_byte(port);
58}
59
60void out8(u32 port, u8 val)
61{
62 out_byte(port, val);
63}
64
65unsigned long in32(u32 port)
66{
67 return in_long(port);
68}
69
70unsigned long simple_strtoul(const char *cp,char **endp,unsigned int base)
71{
72 unsigned long result = 0,value;
73
74 if (*cp == '0') {
75 cp++;
76 if ((*cp == 'x') && isxdigit(cp[1])) {
77 base = 16;
78 cp++;
79 }
80 if (!base) {
81 base = 8;
82 }
83 }
84 if (!base) {
85 base = 10;
86 }
87 while (isxdigit(*cp) && (value = isdigit(*cp) ? *cp-'0' : (islower(*cp)
88 ? toupper(*cp) : *cp)-'A'+10) < base) {
89 result = result*base + value;
90 cp++;
91 }
92 if (endp)
93 *endp = (char *)cp;
94 return result;
95}
96
97long simple_strtol(const char *cp,char **endp,unsigned int base)
98{
99 if(*cp=='-')
100 return -simple_strtoul(cp+1,endp,base);
101 return simple_strtoul(cp,endp,base);
102}
103
104static inline void
105soft_restart(unsigned long addr)
106{
107
108
109
110 __asm__ __volatile__ ("mtspr 26, %0" :: "r" (addr));
111 __asm__ __volatile__ ("li 4, (1 << 6)" ::: "r4");
112 __asm__ __volatile__ ("mtspr 27, 4");
113 __asm__ __volatile__ ("rfi");
114
115 while(1);
116}
117
118void
119do_reset (void)
120{
121 ulong addr;
122
123 __asm__ __volatile__ ("mfspr 3, 1008" ::: "r3");
124 __asm__ __volatile__ ("ori 5, 5, 0xcc00" ::: "r5");
125 __asm__ __volatile__ ("ori 4, 3, 0xc00" ::: "r4");
126 __asm__ __volatile__ ("andc 5, 3, 5" ::: "r5");
127 __asm__ __volatile__ ("sync");
128 __asm__ __volatile__ ("mtspr 1008, 4");
129 __asm__ __volatile__ ("isync");
130 __asm__ __volatile__ ("sync");
131 __asm__ __volatile__ ("mtspr 1008, 5");
132 __asm__ __volatile__ ("isync");
133 __asm__ __volatile__ ("sync");
134
135#ifdef CONFIG_SYS_RESET_ADDRESS
136 addr = CONFIG_SYS_RESET_ADDRESS;
137#else
138
139
140
141
142
143
144 addr = CONFIG_SYS_MONITOR_BASE - sizeof (ulong);
145#endif
146 soft_restart(addr);
147 while(1);
148}
149