diff options
Diffstat (limited to 'arch/powerpc/kernel')
-rw-r--r-- | arch/powerpc/kernel/Makefile | 7 | ||||
-rw-r--r-- | arch/powerpc/kernel/align.c | 530 | ||||
-rw-r--r-- | arch/powerpc/kernel/idle_64.c | 121 | ||||
-rw-r--r-- | arch/powerpc/kernel/misc_32.S | 8 | ||||
-rw-r--r-- | arch/powerpc/kernel/nvram_64.c | 742 | ||||
-rw-r--r-- | arch/powerpc/kernel/pci_64.c | 18 | ||||
-rw-r--r-- | arch/powerpc/kernel/ppc_ksyms.c | 3 | ||||
-rw-r--r-- | arch/powerpc/kernel/ptrace-common.h | 164 | ||||
-rw-r--r-- | arch/powerpc/kernel/ptrace.c | 3 | ||||
-rw-r--r-- | arch/powerpc/kernel/ptrace32.c | 3 | ||||
-rw-r--r-- | arch/powerpc/kernel/rtas-rtc.c | 6 | ||||
-rw-r--r-- | arch/powerpc/kernel/time.c | 28 |
12 files changed, 1598 insertions, 35 deletions
diff --git a/arch/powerpc/kernel/Makefile b/arch/powerpc/kernel/Makefile index 4970e3721a84..9ed551b6c172 100644 --- a/arch/powerpc/kernel/Makefile +++ b/arch/powerpc/kernel/Makefile | |||
@@ -12,12 +12,12 @@ CFLAGS_btext.o += -fPIC | |||
12 | endif | 12 | endif |
13 | 13 | ||
14 | obj-y := semaphore.o cputable.o ptrace.o syscalls.o \ | 14 | obj-y := semaphore.o cputable.o ptrace.o syscalls.o \ |
15 | irq.o signal_32.o pmc.o vdso.o | 15 | irq.o align.o signal_32.o pmc.o vdso.o |
16 | obj-y += vdso32/ | 16 | obj-y += vdso32/ |
17 | obj-$(CONFIG_PPC64) += setup_64.o binfmt_elf32.o sys_ppc32.o \ | 17 | obj-$(CONFIG_PPC64) += setup_64.o binfmt_elf32.o sys_ppc32.o \ |
18 | signal_64.o ptrace32.o systbl.o \ | 18 | signal_64.o ptrace32.o systbl.o \ |
19 | paca.o ioctl32.o cpu_setup_power4.o \ | 19 | paca.o ioctl32.o cpu_setup_power4.o \ |
20 | firmware.o sysfs.o udbg.o | 20 | firmware.o sysfs.o udbg.o idle_64.o |
21 | obj-$(CONFIG_PPC64) += vdso64/ | 21 | obj-$(CONFIG_PPC64) += vdso64/ |
22 | obj-$(CONFIG_ALTIVEC) += vecemu.o vector.o | 22 | obj-$(CONFIG_ALTIVEC) += vecemu.o vector.o |
23 | obj-$(CONFIG_POWER4) += idle_power4.o | 23 | obj-$(CONFIG_POWER4) += idle_power4.o |
@@ -35,6 +35,7 @@ obj-$(CONFIG_PPC_PSERIES) += udbg_16550.o | |||
35 | obj-$(CONFIG_PPC_MAPLE) += udbg_16550.o | 35 | obj-$(CONFIG_PPC_MAPLE) += udbg_16550.o |
36 | udbgscc-$(CONFIG_PPC64) := udbg_scc.o | 36 | udbgscc-$(CONFIG_PPC64) := udbg_scc.o |
37 | obj-$(CONFIG_PPC_PMAC) += $(udbgscc-y) | 37 | obj-$(CONFIG_PPC_PMAC) += $(udbgscc-y) |
38 | obj64-$(CONFIG_PPC_MULTIPLATFORM) += nvram_64.o | ||
38 | 39 | ||
39 | ifeq ($(CONFIG_PPC_MERGE),y) | 40 | ifeq ($(CONFIG_PPC_MERGE),y) |
40 | 41 | ||
@@ -78,5 +79,7 @@ smpobj-$(CONFIG_SMP) += smp.o | |||
78 | 79 | ||
79 | endif | 80 | endif |
80 | 81 | ||
82 | obj-$(CONFIG_PPC64) += $(obj64-y) | ||
83 | |||
81 | extra-$(CONFIG_PPC_FPU) += fpu.o | 84 | extra-$(CONFIG_PPC_FPU) += fpu.o |
82 | extra-$(CONFIG_PPC64) += entry_64.o | 85 | extra-$(CONFIG_PPC64) += entry_64.o |
diff --git a/arch/powerpc/kernel/align.c b/arch/powerpc/kernel/align.c new file mode 100644 index 000000000000..faaec9c6f78f --- /dev/null +++ b/arch/powerpc/kernel/align.c | |||
@@ -0,0 +1,530 @@ | |||
1 | /* align.c - handle alignment exceptions for the Power PC. | ||
2 | * | ||
3 | * Copyright (c) 1996 Paul Mackerras <paulus@cs.anu.edu.au> | ||
4 | * Copyright (c) 1998-1999 TiVo, Inc. | ||
5 | * PowerPC 403GCX modifications. | ||
6 | * Copyright (c) 1999 Grant Erickson <grant@lcse.umn.edu> | ||
7 | * PowerPC 403GCX/405GP modifications. | ||
8 | * Copyright (c) 2001-2002 PPC64 team, IBM Corp | ||
9 | * 64-bit and Power4 support | ||
10 | * Copyright (c) 2005 Benjamin Herrenschmidt, IBM Corp | ||
11 | * <benh@kernel.crashing.org> | ||
12 | * Merge ppc32 and ppc64 implementations | ||
13 | * | ||
14 | * This program is free software; you can redistribute it and/or | ||
15 | * modify it under the terms of the GNU General Public License | ||
16 | * as published by the Free Software Foundation; either version | ||
17 | * 2 of the License, or (at your option) any later version. | ||
18 | */ | ||
19 | |||
20 | #include <linux/kernel.h> | ||
21 | #include <linux/mm.h> | ||
22 | #include <asm/processor.h> | ||
23 | #include <asm/uaccess.h> | ||
24 | #include <asm/system.h> | ||
25 | #include <asm/cache.h> | ||
26 | #include <asm/cputable.h> | ||
27 | |||
28 | struct aligninfo { | ||
29 | unsigned char len; | ||
30 | unsigned char flags; | ||
31 | }; | ||
32 | |||
33 | #define IS_XFORM(inst) (((inst) >> 26) == 31) | ||
34 | #define IS_DSFORM(inst) (((inst) >> 26) >= 56) | ||
35 | |||
36 | #define INVALID { 0, 0 } | ||
37 | |||
38 | #define LD 1 /* load */ | ||
39 | #define ST 2 /* store */ | ||
40 | #define SE 4 /* sign-extend value */ | ||
41 | #define F 8 /* to/from fp regs */ | ||
42 | #define U 0x10 /* update index register */ | ||
43 | #define M 0x20 /* multiple load/store */ | ||
44 | #define SW 0x40 /* byte swap int or ... */ | ||
45 | #define S 0x40 /* ... single-precision fp */ | ||
46 | #define SX 0x40 /* byte count in XER */ | ||
47 | #define HARD 0x80 /* string, stwcx. */ | ||
48 | |||
49 | #define DCBZ 0x5f /* 8xx/82xx dcbz faults when cache not enabled */ | ||
50 | |||
51 | #define SWAP(a, b) (t = (a), (a) = (b), (b) = t) | ||
52 | |||
53 | /* | ||
54 | * The PowerPC stores certain bits of the instruction that caused the | ||
55 | * alignment exception in the DSISR register. This array maps those | ||
56 | * bits to information about the operand length and what the | ||
57 | * instruction would do. | ||
58 | */ | ||
59 | static struct aligninfo aligninfo[128] = { | ||
60 | { 4, LD }, /* 00 0 0000: lwz / lwarx */ | ||
61 | INVALID, /* 00 0 0001 */ | ||
62 | { 4, ST }, /* 00 0 0010: stw */ | ||
63 | INVALID, /* 00 0 0011 */ | ||
64 | { 2, LD }, /* 00 0 0100: lhz */ | ||
65 | { 2, LD+SE }, /* 00 0 0101: lha */ | ||
66 | { 2, ST }, /* 00 0 0110: sth */ | ||
67 | { 4, LD+M }, /* 00 0 0111: lmw */ | ||
68 | { 4, LD+F+S }, /* 00 0 1000: lfs */ | ||
69 | { 8, LD+F }, /* 00 0 1001: lfd */ | ||
70 | { 4, ST+F+S }, /* 00 0 1010: stfs */ | ||
71 | { 8, ST+F }, /* 00 0 1011: stfd */ | ||
72 | INVALID, /* 00 0 1100 */ | ||
73 | { 8, LD }, /* 00 0 1101: ld/ldu/lwa */ | ||
74 | INVALID, /* 00 0 1110 */ | ||
75 | { 8, ST }, /* 00 0 1111: std/stdu */ | ||
76 | { 4, LD+U }, /* 00 1 0000: lwzu */ | ||
77 | INVALID, /* 00 1 0001 */ | ||
78 | { 4, ST+U }, /* 00 1 0010: stwu */ | ||
79 | INVALID, /* 00 1 0011 */ | ||
80 | { 2, LD+U }, /* 00 1 0100: lhzu */ | ||
81 | { 2, LD+SE+U }, /* 00 1 0101: lhau */ | ||
82 | { 2, ST+U }, /* 00 1 0110: sthu */ | ||
83 | { 4, ST+M }, /* 00 1 0111: stmw */ | ||
84 | { 4, LD+F+S+U }, /* 00 1 1000: lfsu */ | ||
85 | { 8, LD+F+U }, /* 00 1 1001: lfdu */ | ||
86 | { 4, ST+F+S+U }, /* 00 1 1010: stfsu */ | ||
87 | { 8, ST+F+U }, /* 00 1 1011: stfdu */ | ||
88 | INVALID, /* 00 1 1100 */ | ||
89 | INVALID, /* 00 1 1101 */ | ||
90 | INVALID, /* 00 1 1110 */ | ||
91 | INVALID, /* 00 1 1111 */ | ||
92 | { 8, LD }, /* 01 0 0000: ldx */ | ||
93 | INVALID, /* 01 0 0001 */ | ||
94 | { 8, ST }, /* 01 0 0010: stdx */ | ||
95 | INVALID, /* 01 0 0011 */ | ||
96 | INVALID, /* 01 0 0100 */ | ||
97 | { 4, LD+SE }, /* 01 0 0101: lwax */ | ||
98 | INVALID, /* 01 0 0110 */ | ||
99 | INVALID, /* 01 0 0111 */ | ||
100 | { 4, LD+M+HARD+SX }, /* 01 0 1000: lswx */ | ||
101 | { 4, LD+M+HARD }, /* 01 0 1001: lswi */ | ||
102 | { 4, ST+M+HARD+SX }, /* 01 0 1010: stswx */ | ||
103 | { 4, ST+M+HARD }, /* 01 0 1011: stswi */ | ||
104 | INVALID, /* 01 0 1100 */ | ||
105 | { 8, LD+U }, /* 01 0 1101: ldu */ | ||
106 | INVALID, /* 01 0 1110 */ | ||
107 | { 8, ST+U }, /* 01 0 1111: stdu */ | ||
108 | { 8, LD+U }, /* 01 1 0000: ldux */ | ||
109 | INVALID, /* 01 1 0001 */ | ||
110 | { 8, ST+U }, /* 01 1 0010: stdux */ | ||
111 | INVALID, /* 01 1 0011 */ | ||
112 | INVALID, /* 01 1 0100 */ | ||
113 | { 4, LD+SE+U }, /* 01 1 0101: lwaux */ | ||
114 | INVALID, /* 01 1 0110 */ | ||
115 | INVALID, /* 01 1 0111 */ | ||
116 | INVALID, /* 01 1 1000 */ | ||
117 | INVALID, /* 01 1 1001 */ | ||
118 | INVALID, /* 01 1 1010 */ | ||
119 | INVALID, /* 01 1 1011 */ | ||
120 | INVALID, /* 01 1 1100 */ | ||
121 | INVALID, /* 01 1 1101 */ | ||
122 | INVALID, /* 01 1 1110 */ | ||
123 | INVALID, /* 01 1 1111 */ | ||
124 | INVALID, /* 10 0 0000 */ | ||
125 | INVALID, /* 10 0 0001 */ | ||
126 | INVALID, /* 10 0 0010: stwcx. */ | ||
127 | INVALID, /* 10 0 0011 */ | ||
128 | INVALID, /* 10 0 0100 */ | ||
129 | INVALID, /* 10 0 0101 */ | ||
130 | INVALID, /* 10 0 0110 */ | ||
131 | INVALID, /* 10 0 0111 */ | ||
132 | { 4, LD+SW }, /* 10 0 1000: lwbrx */ | ||
133 | INVALID, /* 10 0 1001 */ | ||
134 | { 4, ST+SW }, /* 10 0 1010: stwbrx */ | ||
135 | INVALID, /* 10 0 1011 */ | ||
136 | { 2, LD+SW }, /* 10 0 1100: lhbrx */ | ||
137 | { 4, LD+SE }, /* 10 0 1101 lwa */ | ||
138 | { 2, ST+SW }, /* 10 0 1110: sthbrx */ | ||
139 | INVALID, /* 10 0 1111 */ | ||
140 | INVALID, /* 10 1 0000 */ | ||
141 | INVALID, /* 10 1 0001 */ | ||
142 | INVALID, /* 10 1 0010 */ | ||
143 | INVALID, /* 10 1 0011 */ | ||
144 | INVALID, /* 10 1 0100 */ | ||
145 | INVALID, /* 10 1 0101 */ | ||
146 | INVALID, /* 10 1 0110 */ | ||
147 | INVALID, /* 10 1 0111 */ | ||
148 | INVALID, /* 10 1 1000 */ | ||
149 | INVALID, /* 10 1 1001 */ | ||
150 | INVALID, /* 10 1 1010 */ | ||
151 | INVALID, /* 10 1 1011 */ | ||
152 | INVALID, /* 10 1 1100 */ | ||
153 | INVALID, /* 10 1 1101 */ | ||
154 | INVALID, /* 10 1 1110 */ | ||
155 | { 0, ST+HARD }, /* 10 1 1111: dcbz */ | ||
156 | { 4, LD }, /* 11 0 0000: lwzx */ | ||
157 | INVALID, /* 11 0 0001 */ | ||
158 | { 4, ST }, /* 11 0 0010: stwx */ | ||
159 | INVALID, /* 11 0 0011 */ | ||
160 | { 2, LD }, /* 11 0 0100: lhzx */ | ||
161 | { 2, LD+SE }, /* 11 0 0101: lhax */ | ||
162 | { 2, ST }, /* 11 0 0110: sthx */ | ||
163 | INVALID, /* 11 0 0111 */ | ||
164 | { 4, LD+F+S }, /* 11 0 1000: lfsx */ | ||
165 | { 8, LD+F }, /* 11 0 1001: lfdx */ | ||
166 | { 4, ST+F+S }, /* 11 0 1010: stfsx */ | ||
167 | { 8, ST+F }, /* 11 0 1011: stfdx */ | ||
168 | INVALID, /* 11 0 1100 */ | ||
169 | { 8, LD+M }, /* 11 0 1101: lmd */ | ||
170 | INVALID, /* 11 0 1110 */ | ||
171 | { 8, ST+M }, /* 11 0 1111: stmd */ | ||
172 | { 4, LD+U }, /* 11 1 0000: lwzux */ | ||
173 | INVALID, /* 11 1 0001 */ | ||
174 | { 4, ST+U }, /* 11 1 0010: stwux */ | ||
175 | INVALID, /* 11 1 0011 */ | ||
176 | { 2, LD+U }, /* 11 1 0100: lhzux */ | ||
177 | { 2, LD+SE+U }, /* 11 1 0101: lhaux */ | ||
178 | { 2, ST+U }, /* 11 1 0110: sthux */ | ||
179 | INVALID, /* 11 1 0111 */ | ||
180 | { 4, LD+F+S+U }, /* 11 1 1000: lfsux */ | ||
181 | { 8, LD+F+U }, /* 11 1 1001: lfdux */ | ||
182 | { 4, ST+F+S+U }, /* 11 1 1010: stfsux */ | ||
183 | { 8, ST+F+U }, /* 11 1 1011: stfdux */ | ||
184 | INVALID, /* 11 1 1100 */ | ||
185 | INVALID, /* 11 1 1101 */ | ||
186 | INVALID, /* 11 1 1110 */ | ||
187 | INVALID, /* 11 1 1111 */ | ||
188 | }; | ||
189 | |||
190 | /* | ||
191 | * Create a DSISR value from the instruction | ||
192 | */ | ||
193 | static inline unsigned make_dsisr(unsigned instr) | ||
194 | { | ||
195 | unsigned dsisr; | ||
196 | |||
197 | |||
198 | /* bits 6:15 --> 22:31 */ | ||
199 | dsisr = (instr & 0x03ff0000) >> 16; | ||
200 | |||
201 | if (IS_XFORM(instr)) { | ||
202 | /* bits 29:30 --> 15:16 */ | ||
203 | dsisr |= (instr & 0x00000006) << 14; | ||
204 | /* bit 25 --> 17 */ | ||
205 | dsisr |= (instr & 0x00000040) << 8; | ||
206 | /* bits 21:24 --> 18:21 */ | ||
207 | dsisr |= (instr & 0x00000780) << 3; | ||
208 | } else { | ||
209 | /* bit 5 --> 17 */ | ||
210 | dsisr |= (instr & 0x04000000) >> 12; | ||
211 | /* bits 1: 4 --> 18:21 */ | ||
212 | dsisr |= (instr & 0x78000000) >> 17; | ||
213 | /* bits 30:31 --> 12:13 */ | ||
214 | if (IS_DSFORM(instr)) | ||
215 | dsisr |= (instr & 0x00000003) << 18; | ||
216 | } | ||
217 | |||
218 | return dsisr; | ||
219 | } | ||
220 | |||
221 | /* | ||
222 | * The dcbz (data cache block zero) instruction | ||
223 | * gives an alignment fault if used on non-cacheable | ||
224 | * memory. We handle the fault mainly for the | ||
225 | * case when we are running with the cache disabled | ||
226 | * for debugging. | ||
227 | */ | ||
228 | static int emulate_dcbz(struct pt_regs *regs, unsigned char __user *addr) | ||
229 | { | ||
230 | long __user *p; | ||
231 | int i, size; | ||
232 | |||
233 | #ifdef __powerpc64__ | ||
234 | size = ppc64_caches.dline_size; | ||
235 | #else | ||
236 | size = L1_CACHE_BYTES; | ||
237 | #endif | ||
238 | p = (long __user *) (regs->dar & -size); | ||
239 | if (user_mode(regs) && !access_ok(VERIFY_WRITE, p, size)) | ||
240 | return -EFAULT; | ||
241 | for (i = 0; i < size / sizeof(long); ++i) | ||
242 | if (__put_user(0, p+i)) | ||
243 | return -EFAULT; | ||
244 | return 1; | ||
245 | } | ||
246 | |||
247 | /* | ||
248 | * Emulate load & store multiple instructions | ||
249 | * On 64-bit machines, these instructions only affect/use the | ||
250 | * bottom 4 bytes of each register, and the loads clear the | ||
251 | * top 4 bytes of the affected register. | ||
252 | */ | ||
253 | #ifdef CONFIG_PPC64 | ||
254 | #define REG_BYTE(rp, i) *((u8 *)((rp) + ((i) >> 2)) + ((i) & 3) + 4) | ||
255 | #else | ||
256 | #define REG_BYTE(rp, i) *((u8 *)(rp) + (i)) | ||
257 | #endif | ||
258 | |||
259 | static int emulate_multiple(struct pt_regs *regs, unsigned char __user *addr, | ||
260 | unsigned int reg, unsigned int nb, | ||
261 | unsigned int flags, unsigned int instr) | ||
262 | { | ||
263 | unsigned long *rptr; | ||
264 | unsigned int nb0, i; | ||
265 | |||
266 | /* | ||
267 | * We do not try to emulate 8 bytes multiple as they aren't really | ||
268 | * available in our operating environments and we don't try to | ||
269 | * emulate multiples operations in kernel land as they should never | ||
270 | * be used/generated there at least not on unaligned boundaries | ||
271 | */ | ||
272 | if (unlikely((nb > 4) || !user_mode(regs))) | ||
273 | return 0; | ||
274 | |||
275 | /* lmw, stmw, lswi/x, stswi/x */ | ||
276 | nb0 = 0; | ||
277 | if (flags & HARD) { | ||
278 | if (flags & SX) { | ||
279 | nb = regs->xer & 127; | ||
280 | if (nb == 0) | ||
281 | return 1; | ||
282 | } else { | ||
283 | if (__get_user(instr, | ||
284 | (unsigned int __user *)regs->nip)) | ||
285 | return -EFAULT; | ||
286 | nb = (instr >> 11) & 0x1f; | ||
287 | if (nb == 0) | ||
288 | nb = 32; | ||
289 | } | ||
290 | if (nb + reg * 4 > 128) { | ||
291 | nb0 = nb + reg * 4 - 128; | ||
292 | nb = 128 - reg * 4; | ||
293 | } | ||
294 | } else { | ||
295 | /* lwm, stmw */ | ||
296 | nb = (32 - reg) * 4; | ||
297 | } | ||
298 | |||
299 | if (!access_ok((flags & ST ? VERIFY_WRITE: VERIFY_READ), addr, nb+nb0)) | ||
300 | return -EFAULT; /* bad address */ | ||
301 | |||
302 | rptr = ®s->gpr[reg]; | ||
303 | if (flags & LD) { | ||
304 | /* | ||
305 | * This zeroes the top 4 bytes of the affected registers | ||
306 | * in 64-bit mode, and also zeroes out any remaining | ||
307 | * bytes of the last register for lsw*. | ||
308 | */ | ||
309 | memset(rptr, 0, ((nb + 3) / 4) * sizeof(unsigned long)); | ||
310 | if (nb0 > 0) | ||
311 | memset(®s->gpr[0], 0, | ||
312 | ((nb0 + 3) / 4) * sizeof(unsigned long)); | ||
313 | |||
314 | for (i = 0; i < nb; ++i) | ||
315 | if (__get_user(REG_BYTE(rptr, i), addr + i)) | ||
316 | return -EFAULT; | ||
317 | if (nb0 > 0) { | ||
318 | rptr = ®s->gpr[0]; | ||
319 | addr += nb; | ||
320 | for (i = 0; i < nb0; ++i) | ||
321 | if (__get_user(REG_BYTE(rptr, i), addr + i)) | ||
322 | return -EFAULT; | ||
323 | } | ||
324 | |||
325 | } else { | ||
326 | for (i = 0; i < nb; ++i) | ||
327 | if (__put_user(REG_BYTE(rptr, i), addr + i)) | ||
328 | return -EFAULT; | ||
329 | if (nb0 > 0) { | ||
330 | rptr = ®s->gpr[0]; | ||
331 | addr += nb; | ||
332 | for (i = 0; i < nb0; ++i) | ||
333 | if (__put_user(REG_BYTE(rptr, i), addr + i)) | ||
334 | return -EFAULT; | ||
335 | } | ||
336 | } | ||
337 | return 1; | ||
338 | } | ||
339 | |||
340 | |||
341 | /* | ||
342 | * Called on alignment exception. Attempts to fixup | ||
343 | * | ||
344 | * Return 1 on success | ||
345 | * Return 0 if unable to handle the interrupt | ||
346 | * Return -EFAULT if data address is bad | ||
347 | */ | ||
348 | |||
349 | int fix_alignment(struct pt_regs *regs) | ||
350 | { | ||
351 | unsigned int instr, nb, flags; | ||
352 | unsigned int reg, areg; | ||
353 | unsigned int dsisr; | ||
354 | unsigned char __user *addr; | ||
355 | unsigned char __user *p; | ||
356 | int ret, t; | ||
357 | union { | ||
358 | u64 ll; | ||
359 | double dd; | ||
360 | unsigned char v[8]; | ||
361 | struct { | ||
362 | unsigned hi32; | ||
363 | int low32; | ||
364 | } x32; | ||
365 | struct { | ||
366 | unsigned char hi48[6]; | ||
367 | short low16; | ||
368 | } x16; | ||
369 | } data; | ||
370 | |||
371 | /* | ||
372 | * We require a complete register set, if not, then our assembly | ||
373 | * is broken | ||
374 | */ | ||
375 | CHECK_FULL_REGS(regs); | ||
376 | |||
377 | dsisr = regs->dsisr; | ||
378 | |||
379 | /* Some processors don't provide us with a DSISR we can use here, | ||
380 | * let's make one up from the instruction | ||
381 | */ | ||
382 | if (cpu_has_feature(CPU_FTR_NODSISRALIGN)) { | ||
383 | unsigned int real_instr; | ||
384 | if (unlikely(__get_user(real_instr, | ||
385 | (unsigned int __user *)regs->nip))) | ||
386 | return -EFAULT; | ||
387 | dsisr = make_dsisr(real_instr); | ||
388 | } | ||
389 | |||
390 | /* extract the operation and registers from the dsisr */ | ||
391 | reg = (dsisr >> 5) & 0x1f; /* source/dest register */ | ||
392 | areg = dsisr & 0x1f; /* register to update */ | ||
393 | instr = (dsisr >> 10) & 0x7f; | ||
394 | instr |= (dsisr >> 13) & 0x60; | ||
395 | |||
396 | /* Lookup the operation in our table */ | ||
397 | nb = aligninfo[instr].len; | ||
398 | flags = aligninfo[instr].flags; | ||
399 | |||
400 | /* DAR has the operand effective address */ | ||
401 | addr = (unsigned char __user *)regs->dar; | ||
402 | |||
403 | /* A size of 0 indicates an instruction we don't support, with | ||
404 | * the exception of DCBZ which is handled as a special case here | ||
405 | */ | ||
406 | if (instr == DCBZ) | ||
407 | return emulate_dcbz(regs, addr); | ||
408 | if (unlikely(nb == 0)) | ||
409 | return 0; | ||
410 | |||
411 | /* Load/Store Multiple instructions are handled in their own | ||
412 | * function | ||
413 | */ | ||
414 | if (flags & M) | ||
415 | return emulate_multiple(regs, addr, reg, nb, flags, instr); | ||
416 | |||
417 | /* Verify the address of the operand */ | ||
418 | if (unlikely(user_mode(regs) && | ||
419 | !access_ok((flags & ST ? VERIFY_WRITE : VERIFY_READ), | ||
420 | addr, nb))) | ||
421 | return -EFAULT; | ||
422 | |||
423 | /* Force the fprs into the save area so we can reference them */ | ||
424 | if (flags & F) { | ||
425 | /* userland only */ | ||
426 | if (unlikely(!user_mode(regs))) | ||
427 | return 0; | ||
428 | flush_fp_to_thread(current); | ||
429 | } | ||
430 | |||
431 | /* If we are loading, get the data from user space, else | ||
432 | * get it from register values | ||
433 | */ | ||
434 | if (flags & LD) { | ||
435 | data.ll = 0; | ||
436 | ret = 0; | ||
437 | p = addr; | ||
438 | switch (nb) { | ||
439 | case 8: | ||
440 | ret |= __get_user(data.v[0], p++); | ||
441 | ret |= __get_user(data.v[1], p++); | ||
442 | ret |= __get_user(data.v[2], p++); | ||
443 | ret |= __get_user(data.v[3], p++); | ||
444 | case 4: | ||
445 | ret |= __get_user(data.v[4], p++); | ||
446 | ret |= __get_user(data.v[5], p++); | ||
447 | case 2: | ||
448 | ret |= __get_user(data.v[6], p++); | ||
449 | ret |= __get_user(data.v[7], p++); | ||
450 | if (unlikely(ret)) | ||
451 | return -EFAULT; | ||
452 | } | ||
453 | } else if (flags & F) | ||
454 | data.dd = current->thread.fpr[reg]; | ||
455 | else | ||
456 | data.ll = regs->gpr[reg]; | ||
457 | |||
458 | /* Perform other misc operations like sign extension, byteswap, | ||
459 | * or floating point single precision conversion | ||
460 | */ | ||
461 | switch (flags & ~U) { | ||
462 | case LD+SE: /* sign extend */ | ||
463 | if ( nb == 2 ) | ||
464 | data.ll = data.x16.low16; | ||
465 | else /* nb must be 4 */ | ||
466 | data.ll = data.x32.low32; | ||
467 | break; | ||
468 | case LD+S: /* byte-swap */ | ||
469 | case ST+S: | ||
470 | if (nb == 2) { | ||
471 | SWAP(data.v[6], data.v[7]); | ||
472 | } else { | ||
473 | SWAP(data.v[4], data.v[7]); | ||
474 | SWAP(data.v[5], data.v[6]); | ||
475 | } | ||
476 | break; | ||
477 | |||
478 | /* Single-precision FP load and store require conversions... */ | ||
479 | case LD+F+S: | ||
480 | #ifdef CONFIG_PPC_FPU | ||
481 | preempt_disable(); | ||
482 | enable_kernel_fp(); | ||
483 | cvt_fd((float *)&data.v[4], &data.dd, ¤t->thread); | ||
484 | preempt_enable(); | ||
485 | #else | ||
486 | return 0; | ||
487 | #endif | ||
488 | break; | ||
489 | case ST+F+S: | ||
490 | #ifdef CONFIG_PPC_FPU | ||
491 | preempt_disable(); | ||
492 | enable_kernel_fp(); | ||
493 | cvt_df(&data.dd, (float *)&data.v[4], ¤t->thread); | ||
494 | preempt_enable(); | ||
495 | #else | ||
496 | return 0; | ||
497 | #endif | ||
498 | break; | ||
499 | } | ||
500 | |||
501 | /* Store result to memory or update registers */ | ||
502 | if (flags & ST) { | ||
503 | ret = 0; | ||
504 | p = addr; | ||
505 | switch (nb) { | ||
506 | case 8: | ||
507 | ret |= __put_user(data.v[0], p++); | ||
508 | ret |= __put_user(data.v[1], p++); | ||
509 | ret |= __put_user(data.v[2], p++); | ||
510 | ret |= __put_user(data.v[3], p++); | ||
511 | case 4: | ||
512 | ret |= __put_user(data.v[4], p++); | ||
513 | ret |= __put_user(data.v[5], p++); | ||
514 | case 2: | ||
515 | ret |= __put_user(data.v[6], p++); | ||
516 | ret |= __put_user(data.v[7], p++); | ||
517 | } | ||
518 | if (unlikely(ret)) | ||
519 | return -EFAULT; | ||
520 | } else if (flags & F) | ||
521 | current->thread.fpr[reg] = data.dd; | ||
522 | else | ||
523 | regs->gpr[reg] = data.ll; | ||
524 | |||
525 | /* Update RA as needed */ | ||
526 | if (flags & U) | ||
527 | regs->gpr[areg] = regs->dar; | ||
528 | |||
529 | return 1; | ||
530 | } | ||
diff --git a/arch/powerpc/kernel/idle_64.c b/arch/powerpc/kernel/idle_64.c new file mode 100644 index 000000000000..b879d3057ef8 --- /dev/null +++ b/arch/powerpc/kernel/idle_64.c | |||
@@ -0,0 +1,121 @@ | |||
1 | /* | ||
2 | * Idle daemon for PowerPC. Idle daemon will handle any action | ||
3 | * that needs to be taken when the system becomes idle. | ||
4 | * | ||
5 | * Originally Written by Cort Dougan (cort@cs.nmt.edu) | ||
6 | * | ||
7 | * iSeries supported added by Mike Corrigan <mikejc@us.ibm.com> | ||
8 | * | ||
9 | * Additional shared processor, SMT, and firmware support | ||
10 | * Copyright (c) 2003 Dave Engebretsen <engebret@us.ibm.com> | ||
11 | * | ||
12 | * This program is free software; you can redistribute it and/or | ||
13 | * modify it under the terms of the GNU General Public License | ||
14 | * as published by the Free Software Foundation; either version | ||
15 | * 2 of the License, or (at your option) any later version. | ||
16 | */ | ||
17 | |||
18 | #include <linux/config.h> | ||
19 | #include <linux/sched.h> | ||
20 | #include <linux/kernel.h> | ||
21 | #include <linux/smp.h> | ||
22 | #include <linux/cpu.h> | ||
23 | #include <linux/sysctl.h> | ||
24 | |||
25 | #include <asm/system.h> | ||
26 | #include <asm/processor.h> | ||
27 | #include <asm/cputable.h> | ||
28 | #include <asm/time.h> | ||
29 | #include <asm/machdep.h> | ||
30 | #include <asm/smp.h> | ||
31 | |||
32 | extern void power4_idle(void); | ||
33 | |||
34 | void default_idle(void) | ||
35 | { | ||
36 | unsigned int cpu = smp_processor_id(); | ||
37 | set_thread_flag(TIF_POLLING_NRFLAG); | ||
38 | |||
39 | while (1) { | ||
40 | if (!need_resched()) { | ||
41 | while (!need_resched() && !cpu_is_offline(cpu)) { | ||
42 | ppc64_runlatch_off(); | ||
43 | |||
44 | /* | ||
45 | * Go into low thread priority and possibly | ||
46 | * low power mode. | ||
47 | */ | ||
48 | HMT_low(); | ||
49 | HMT_very_low(); | ||
50 | } | ||
51 | |||
52 | HMT_medium(); | ||
53 | } | ||
54 | |||
55 | ppc64_runlatch_on(); | ||
56 | preempt_enable_no_resched(); | ||
57 | schedule(); | ||
58 | preempt_disable(); | ||
59 | if (cpu_is_offline(cpu) && system_state == SYSTEM_RUNNING) | ||
60 | cpu_die(); | ||
61 | } | ||
62 | } | ||
63 | |||
64 | void native_idle(void) | ||
65 | { | ||
66 | while (1) { | ||
67 | ppc64_runlatch_off(); | ||
68 | |||
69 | if (!need_resched()) | ||
70 | power4_idle(); | ||
71 | |||
72 | if (need_resched()) { | ||
73 | ppc64_runlatch_on(); | ||
74 | preempt_enable_no_resched(); | ||
75 | schedule(); | ||
76 | preempt_disable(); | ||
77 | } | ||
78 | |||
79 | if (cpu_is_offline(smp_processor_id()) && | ||
80 | system_state == SYSTEM_RUNNING) | ||
81 | cpu_die(); | ||
82 | } | ||
83 | } | ||
84 | |||
85 | void cpu_idle(void) | ||
86 | { | ||
87 | BUG_ON(NULL == ppc_md.idle_loop); | ||
88 | ppc_md.idle_loop(); | ||
89 | } | ||
90 | |||
91 | int powersave_nap; | ||
92 | |||
93 | #ifdef CONFIG_SYSCTL | ||
94 | /* | ||
95 | * Register the sysctl to set/clear powersave_nap. | ||
96 | */ | ||
97 | static ctl_table powersave_nap_ctl_table[]={ | ||
98 | { | ||
99 | .ctl_name = KERN_PPC_POWERSAVE_NAP, | ||
100 | .procname = "powersave-nap", | ||
101 | .data = &powersave_nap, | ||
102 | .maxlen = sizeof(int), | ||
103 | .mode = 0644, | ||
104 | .proc_handler = &proc_dointvec, | ||
105 | }, | ||
106 | { 0, }, | ||
107 | }; | ||
108 | static ctl_table powersave_nap_sysctl_root[] = { | ||
109 | { 1, "kernel", NULL, 0, 0755, powersave_nap_ctl_table, }, | ||
110 | { 0,}, | ||
111 | }; | ||
112 | |||
113 | static int __init | ||
114 | register_powersave_nap_sysctl(void) | ||
115 | { | ||
116 | register_sysctl_table(powersave_nap_sysctl_root, 0); | ||
117 | |||
118 | return 0; | ||
119 | } | ||
120 | __initcall(register_powersave_nap_sysctl); | ||
121 | #endif | ||
diff --git a/arch/powerpc/kernel/misc_32.S b/arch/powerpc/kernel/misc_32.S index f6d84a75ed26..624a983a9676 100644 --- a/arch/powerpc/kernel/misc_32.S +++ b/arch/powerpc/kernel/misc_32.S | |||
@@ -27,14 +27,6 @@ | |||
27 | 27 | ||
28 | .text | 28 | .text |
29 | 29 | ||
30 | .align 5 | ||
31 | _GLOBAL(__delay) | ||
32 | cmpwi 0,r3,0 | ||
33 | mtctr r3 | ||
34 | beqlr | ||
35 | 1: bdnz 1b | ||
36 | blr | ||
37 | |||
38 | /* | 30 | /* |
39 | * This returns the high 64 bits of the product of two 64-bit numbers. | 31 | * This returns the high 64 bits of the product of two 64-bit numbers. |
40 | */ | 32 | */ |
diff --git a/arch/powerpc/kernel/nvram_64.c b/arch/powerpc/kernel/nvram_64.c new file mode 100644 index 000000000000..c0fcd29918ce --- /dev/null +++ b/arch/powerpc/kernel/nvram_64.c | |||
@@ -0,0 +1,742 @@ | |||
1 | /* | ||
2 | * c 2001 PPC 64 Team, IBM Corp | ||
3 | * | ||
4 | * This program is free software; you can redistribute it and/or | ||
5 | * modify it under the terms of the GNU General Public License | ||
6 | * as published by the Free Software Foundation; either version | ||
7 | * 2 of the License, or (at your option) any later version. | ||
8 | * | ||
9 | * /dev/nvram driver for PPC64 | ||
10 | * | ||
11 | * This perhaps should live in drivers/char | ||
12 | * | ||
13 | * TODO: Split the /dev/nvram part (that one can use | ||
14 | * drivers/char/generic_nvram.c) from the arch & partition | ||
15 | * parsing code. | ||
16 | */ | ||
17 | |||
18 | #include <linux/module.h> | ||
19 | |||
20 | #include <linux/types.h> | ||
21 | #include <linux/errno.h> | ||
22 | #include <linux/fs.h> | ||
23 | #include <linux/miscdevice.h> | ||
24 | #include <linux/fcntl.h> | ||
25 | #include <linux/nvram.h> | ||
26 | #include <linux/init.h> | ||
27 | #include <linux/slab.h> | ||
28 | #include <linux/spinlock.h> | ||
29 | #include <asm/uaccess.h> | ||
30 | #include <asm/nvram.h> | ||
31 | #include <asm/rtas.h> | ||
32 | #include <asm/prom.h> | ||
33 | #include <asm/machdep.h> | ||
34 | |||
35 | #undef DEBUG_NVRAM | ||
36 | |||
37 | static int nvram_scan_partitions(void); | ||
38 | static int nvram_setup_partition(void); | ||
39 | static int nvram_create_os_partition(void); | ||
40 | static int nvram_remove_os_partition(void); | ||
41 | |||
42 | static struct nvram_partition * nvram_part; | ||
43 | static long nvram_error_log_index = -1; | ||
44 | static long nvram_error_log_size = 0; | ||
45 | |||
46 | int no_logging = 1; /* Until we initialize everything, | ||
47 | * make sure we don't try logging | ||
48 | * anything */ | ||
49 | |||
50 | extern volatile int error_log_cnt; | ||
51 | |||
52 | struct err_log_info { | ||
53 | int error_type; | ||
54 | unsigned int seq_num; | ||
55 | }; | ||
56 | |||
57 | static loff_t dev_nvram_llseek(struct file *file, loff_t offset, int origin) | ||
58 | { | ||
59 | int size; | ||
60 | |||
61 | if (ppc_md.nvram_size == NULL) | ||
62 | return -ENODEV; | ||
63 | size = ppc_md.nvram_size(); | ||
64 | |||
65 | switch (origin) { | ||
66 | case 1: | ||
67 | offset += file->f_pos; | ||
68 | break; | ||
69 | case 2: | ||
70 | offset += size; | ||
71 | break; | ||
72 | } | ||
73 | if (offset < 0) | ||
74 | return -EINVAL; | ||
75 | file->f_pos = offset; | ||
76 | return file->f_pos; | ||
77 | } | ||
78 | |||
79 | |||
80 | static ssize_t dev_nvram_read(struct file *file, char __user *buf, | ||
81 | size_t count, loff_t *ppos) | ||
82 | { | ||
83 | ssize_t len; | ||
84 | char *tmp_buffer; | ||
85 | int size; | ||
86 | |||
87 | if (ppc_md.nvram_size == NULL) | ||
88 | return -ENODEV; | ||
89 | size = ppc_md.nvram_size(); | ||
90 | |||
91 | if (!access_ok(VERIFY_WRITE, buf, count)) | ||
92 | return -EFAULT; | ||
93 | if (*ppos >= size) | ||
94 | return 0; | ||
95 | if (count > size) | ||
96 | count = size; | ||
97 | |||
98 | tmp_buffer = (char *) kmalloc(count, GFP_KERNEL); | ||
99 | if (!tmp_buffer) { | ||
100 | printk(KERN_ERR "dev_read_nvram: kmalloc failed\n"); | ||
101 | return -ENOMEM; | ||
102 | } | ||
103 | |||
104 | len = ppc_md.nvram_read(tmp_buffer, count, ppos); | ||
105 | if ((long)len <= 0) { | ||
106 | kfree(tmp_buffer); | ||
107 | return len; | ||
108 | } | ||
109 | |||
110 | if (copy_to_user(buf, tmp_buffer, len)) { | ||
111 | kfree(tmp_buffer); | ||
112 | return -EFAULT; | ||
113 | } | ||
114 | |||
115 | kfree(tmp_buffer); | ||
116 | return len; | ||
117 | |||
118 | } | ||
119 | |||
120 | static ssize_t dev_nvram_write(struct file *file, const char __user *buf, | ||
121 | size_t count, loff_t *ppos) | ||
122 | { | ||
123 | ssize_t len; | ||
124 | char * tmp_buffer; | ||
125 | int size; | ||
126 | |||
127 | if (ppc_md.nvram_size == NULL) | ||
128 | return -ENODEV; | ||
129 | size = ppc_md.nvram_size(); | ||
130 | |||
131 | if (!access_ok(VERIFY_READ, buf, count)) | ||
132 | return -EFAULT; | ||
133 | if (*ppos >= size) | ||
134 | return 0; | ||
135 | if (count > size) | ||
136 | count = size; | ||
137 | |||
138 | tmp_buffer = (char *) kmalloc(count, GFP_KERNEL); | ||
139 | if (!tmp_buffer) { | ||
140 | printk(KERN_ERR "dev_nvram_write: kmalloc failed\n"); | ||
141 | return -ENOMEM; | ||
142 | } | ||
143 | |||
144 | if (copy_from_user(tmp_buffer, buf, count)) { | ||
145 | kfree(tmp_buffer); | ||
146 | return -EFAULT; | ||
147 | } | ||
148 | |||
149 | len = ppc_md.nvram_write(tmp_buffer, count, ppos); | ||
150 | if ((long)len <= 0) { | ||
151 | kfree(tmp_buffer); | ||
152 | return len; | ||
153 | } | ||
154 | |||
155 | kfree(tmp_buffer); | ||
156 | return len; | ||
157 | } | ||
158 | |||
159 | static int dev_nvram_ioctl(struct inode *inode, struct file *file, | ||
160 | unsigned int cmd, unsigned long arg) | ||
161 | { | ||
162 | switch(cmd) { | ||
163 | #ifdef CONFIG_PPC_PMAC | ||
164 | case OBSOLETE_PMAC_NVRAM_GET_OFFSET: | ||
165 | printk(KERN_WARNING "nvram: Using obsolete PMAC_NVRAM_GET_OFFSET ioctl\n"); | ||
166 | case IOC_NVRAM_GET_OFFSET: { | ||
167 | int part, offset; | ||
168 | |||
169 | if (_machine != PLATFORM_POWERMAC) | ||
170 | return -EINVAL; | ||
171 | if (copy_from_user(&part, (void __user*)arg, sizeof(part)) != 0) | ||
172 | return -EFAULT; | ||
173 | if (part < pmac_nvram_OF || part > pmac_nvram_NR) | ||
174 | return -EINVAL; | ||
175 | offset = pmac_get_partition(part); | ||
176 | if (offset < 0) | ||
177 | return offset; | ||
178 | if (copy_to_user((void __user*)arg, &offset, sizeof(offset)) != 0) | ||
179 | return -EFAULT; | ||
180 | return 0; | ||
181 | } | ||
182 | #endif /* CONFIG_PPC_PMAC */ | ||
183 | } | ||
184 | return -EINVAL; | ||
185 | } | ||
186 | |||
187 | struct file_operations nvram_fops = { | ||
188 | .owner = THIS_MODULE, | ||
189 | .llseek = dev_nvram_llseek, | ||
190 | .read = dev_nvram_read, | ||
191 | .write = dev_nvram_write, | ||
192 | .ioctl = dev_nvram_ioctl, | ||
193 | }; | ||
194 | |||
195 | static struct miscdevice nvram_dev = { | ||
196 | NVRAM_MINOR, | ||
197 | "nvram", | ||
198 | &nvram_fops | ||
199 | }; | ||
200 | |||
201 | |||
202 | #ifdef DEBUG_NVRAM | ||
203 | static void nvram_print_partitions(char * label) | ||
204 | { | ||
205 | struct list_head * p; | ||
206 | struct nvram_partition * tmp_part; | ||
207 | |||
208 | printk(KERN_WARNING "--------%s---------\n", label); | ||
209 | printk(KERN_WARNING "indx\t\tsig\tchks\tlen\tname\n"); | ||
210 | list_for_each(p, &nvram_part->partition) { | ||
211 | tmp_part = list_entry(p, struct nvram_partition, partition); | ||
212 | printk(KERN_WARNING "%d \t%02x\t%02x\t%d\t%s\n", | ||
213 | tmp_part->index, tmp_part->header.signature, | ||
214 | tmp_part->header.checksum, tmp_part->header.length, | ||
215 | tmp_part->header.name); | ||
216 | } | ||
217 | } | ||
218 | #endif | ||
219 | |||
220 | |||
221 | static int nvram_write_header(struct nvram_partition * part) | ||
222 | { | ||
223 | loff_t tmp_index; | ||
224 | int rc; | ||
225 | |||
226 | tmp_index = part->index; | ||
227 | rc = ppc_md.nvram_write((char *)&part->header, NVRAM_HEADER_LEN, &tmp_index); | ||
228 | |||
229 | return rc; | ||
230 | } | ||
231 | |||
232 | |||
233 | static unsigned char nvram_checksum(struct nvram_header *p) | ||
234 | { | ||
235 | unsigned int c_sum, c_sum2; | ||
236 | unsigned short *sp = (unsigned short *)p->name; /* assume 6 shorts */ | ||
237 | c_sum = p->signature + p->length + sp[0] + sp[1] + sp[2] + sp[3] + sp[4] + sp[5]; | ||
238 | |||
239 | /* The sum may have spilled into the 3rd byte. Fold it back. */ | ||
240 | c_sum = ((c_sum & 0xffff) + (c_sum >> 16)) & 0xffff; | ||
241 | /* The sum cannot exceed 2 bytes. Fold it into a checksum */ | ||
242 | c_sum2 = (c_sum >> 8) + (c_sum << 8); | ||
243 | c_sum = ((c_sum + c_sum2) >> 8) & 0xff; | ||
244 | return c_sum; | ||
245 | } | ||
246 | |||
247 | |||
248 | /* | ||
249 | * Find an nvram partition, sig can be 0 for any | ||
250 | * partition or name can be NULL for any name, else | ||
251 | * tries to match both | ||
252 | */ | ||
253 | struct nvram_partition *nvram_find_partition(int sig, const char *name) | ||
254 | { | ||
255 | struct nvram_partition * part; | ||
256 | struct list_head * p; | ||
257 | |||
258 | list_for_each(p, &nvram_part->partition) { | ||
259 | part = list_entry(p, struct nvram_partition, partition); | ||
260 | |||
261 | if (sig && part->header.signature != sig) | ||
262 | continue; | ||
263 | if (name && 0 != strncmp(name, part->header.name, 12)) | ||
264 | continue; | ||
265 | return part; | ||
266 | } | ||
267 | return NULL; | ||
268 | } | ||
269 | EXPORT_SYMBOL(nvram_find_partition); | ||
270 | |||
271 | |||
272 | static int nvram_remove_os_partition(void) | ||
273 | { | ||
274 | struct list_head *i; | ||
275 | struct list_head *j; | ||
276 | struct nvram_partition * part; | ||
277 | struct nvram_partition * cur_part; | ||
278 | int rc; | ||
279 | |||
280 | list_for_each(i, &nvram_part->partition) { | ||
281 | part = list_entry(i, struct nvram_partition, partition); | ||
282 | if (part->header.signature != NVRAM_SIG_OS) | ||
283 | continue; | ||
284 | |||
285 | /* Make os partition a free partition */ | ||
286 | part->header.signature = NVRAM_SIG_FREE; | ||
287 | sprintf(part->header.name, "wwwwwwwwwwww"); | ||
288 | part->header.checksum = nvram_checksum(&part->header); | ||
289 | |||
290 | /* Merge contiguous free partitions backwards */ | ||
291 | list_for_each_prev(j, &part->partition) { | ||
292 | cur_part = list_entry(j, struct nvram_partition, partition); | ||
293 | if (cur_part == nvram_part || cur_part->header.signature != NVRAM_SIG_FREE) { | ||
294 | break; | ||
295 | } | ||
296 | |||
297 | part->header.length += cur_part->header.length; | ||
298 | part->header.checksum = nvram_checksum(&part->header); | ||
299 | part->index = cur_part->index; | ||
300 | |||
301 | list_del(&cur_part->partition); | ||
302 | kfree(cur_part); | ||
303 | j = &part->partition; /* fixup our loop */ | ||
304 | } | ||
305 | |||
306 | /* Merge contiguous free partitions forwards */ | ||
307 | list_for_each(j, &part->partition) { | ||
308 | cur_part = list_entry(j, struct nvram_partition, partition); | ||
309 | if (cur_part == nvram_part || cur_part->header.signature != NVRAM_SIG_FREE) { | ||
310 | break; | ||
311 | } | ||
312 | |||
313 | part->header.length += cur_part->header.length; | ||
314 | part->header.checksum = nvram_checksum(&part->header); | ||
315 | |||
316 | list_del(&cur_part->partition); | ||
317 | kfree(cur_part); | ||
318 | j = &part->partition; /* fixup our loop */ | ||
319 | } | ||
320 | |||
321 | rc = nvram_write_header(part); | ||
322 | if (rc <= 0) { | ||
323 | printk(KERN_ERR "nvram_remove_os_partition: nvram_write failed (%d)\n", rc); | ||
324 | return rc; | ||
325 | } | ||
326 | |||
327 | } | ||
328 | |||
329 | return 0; | ||
330 | } | ||
331 | |||
332 | /* nvram_create_os_partition | ||
333 | * | ||
334 | * Create a OS linux partition to buffer error logs. | ||
335 | * Will create a partition starting at the first free | ||
336 | * space found if space has enough room. | ||
337 | */ | ||
338 | static int nvram_create_os_partition(void) | ||
339 | { | ||
340 | struct nvram_partition *part; | ||
341 | struct nvram_partition *new_part; | ||
342 | struct nvram_partition *free_part = NULL; | ||
343 | int seq_init[2] = { 0, 0 }; | ||
344 | loff_t tmp_index; | ||
345 | long size = 0; | ||
346 | int rc; | ||
347 | |||
348 | /* Find a free partition that will give us the maximum needed size | ||
349 | If can't find one that will give us the minimum size needed */ | ||
350 | list_for_each_entry(part, &nvram_part->partition, partition) { | ||
351 | if (part->header.signature != NVRAM_SIG_FREE) | ||
352 | continue; | ||
353 | |||
354 | if (part->header.length >= NVRAM_MAX_REQ) { | ||
355 | size = NVRAM_MAX_REQ; | ||
356 | free_part = part; | ||
357 | break; | ||
358 | } | ||
359 | if (!size && part->header.length >= NVRAM_MIN_REQ) { | ||
360 | size = NVRAM_MIN_REQ; | ||
361 | free_part = part; | ||
362 | } | ||
363 | } | ||
364 | if (!size) | ||
365 | return -ENOSPC; | ||
366 | |||
367 | /* Create our OS partition */ | ||
368 | new_part = kmalloc(sizeof(*new_part), GFP_KERNEL); | ||
369 | if (!new_part) { | ||
370 | printk(KERN_ERR "nvram_create_os_partition: kmalloc failed\n"); | ||
371 | return -ENOMEM; | ||
372 | } | ||
373 | |||
374 | new_part->index = free_part->index; | ||
375 | new_part->header.signature = NVRAM_SIG_OS; | ||
376 | new_part->header.length = size; | ||
377 | strcpy(new_part->header.name, "ppc64,linux"); | ||
378 | new_part->header.checksum = nvram_checksum(&new_part->header); | ||
379 | |||
380 | rc = nvram_write_header(new_part); | ||
381 | if (rc <= 0) { | ||
382 | printk(KERN_ERR "nvram_create_os_partition: nvram_write_header \ | ||
383 | failed (%d)\n", rc); | ||
384 | return rc; | ||
385 | } | ||
386 | |||
387 | /* make sure and initialize to zero the sequence number and the error | ||
388 | type logged */ | ||
389 | tmp_index = new_part->index + NVRAM_HEADER_LEN; | ||
390 | rc = ppc_md.nvram_write((char *)&seq_init, sizeof(seq_init), &tmp_index); | ||
391 | if (rc <= 0) { | ||
392 | printk(KERN_ERR "nvram_create_os_partition: nvram_write " | ||
393 | "failed (%d)\n", rc); | ||
394 | return rc; | ||
395 | } | ||
396 | |||
397 | nvram_error_log_index = new_part->index + NVRAM_HEADER_LEN; | ||
398 | nvram_error_log_size = ((part->header.length - 1) * | ||
399 | NVRAM_BLOCK_LEN) - sizeof(struct err_log_info); | ||
400 | |||
401 | list_add_tail(&new_part->partition, &free_part->partition); | ||
402 | |||
403 | if (free_part->header.length <= size) { | ||
404 | list_del(&free_part->partition); | ||
405 | kfree(free_part); | ||
406 | return 0; | ||
407 | } | ||
408 | |||
409 | /* Adjust the partition we stole the space from */ | ||
410 | free_part->index += size * NVRAM_BLOCK_LEN; | ||
411 | free_part->header.length -= size; | ||
412 | free_part->header.checksum = nvram_checksum(&free_part->header); | ||
413 | |||
414 | rc = nvram_write_header(free_part); | ||
415 | if (rc <= 0) { | ||
416 | printk(KERN_ERR "nvram_create_os_partition: nvram_write_header " | ||
417 | "failed (%d)\n", rc); | ||
418 | return rc; | ||
419 | } | ||
420 | |||
421 | return 0; | ||
422 | } | ||
423 | |||
424 | |||
425 | /* nvram_setup_partition | ||
426 | * | ||
427 | * This will setup the partition we need for buffering the | ||
428 | * error logs and cleanup partitions if needed. | ||
429 | * | ||
430 | * The general strategy is the following: | ||
431 | * 1.) If there is ppc64,linux partition large enough then use it. | ||
432 | * 2.) If there is not a ppc64,linux partition large enough, search | ||
433 | * for a free partition that is large enough. | ||
434 | * 3.) If there is not a free partition large enough remove | ||
435 | * _all_ OS partitions and consolidate the space. | ||
436 | * 4.) Will first try getting a chunk that will satisfy the maximum | ||
437 | * error log size (NVRAM_MAX_REQ). | ||
438 | * 5.) If the max chunk cannot be allocated then try finding a chunk | ||
439 | * that will satisfy the minum needed (NVRAM_MIN_REQ). | ||
440 | */ | ||
441 | static int nvram_setup_partition(void) | ||
442 | { | ||
443 | struct list_head * p; | ||
444 | struct nvram_partition * part; | ||
445 | int rc; | ||
446 | |||
447 | /* For now, we don't do any of this on pmac, until I | ||
448 | * have figured out if it's worth killing some unused stuffs | ||
449 | * in our nvram, as Apple defined partitions use pretty much | ||
450 | * all of the space | ||
451 | */ | ||
452 | if (_machine == PLATFORM_POWERMAC) | ||
453 | return -ENOSPC; | ||
454 | |||
455 | /* see if we have an OS partition that meets our needs. | ||
456 | will try getting the max we need. If not we'll delete | ||
457 | partitions and try again. */ | ||
458 | list_for_each(p, &nvram_part->partition) { | ||
459 | part = list_entry(p, struct nvram_partition, partition); | ||
460 | if (part->header.signature != NVRAM_SIG_OS) | ||
461 | continue; | ||
462 | |||
463 | if (strcmp(part->header.name, "ppc64,linux")) | ||
464 | continue; | ||
465 | |||
466 | if (part->header.length >= NVRAM_MIN_REQ) { | ||
467 | /* found our partition */ | ||
468 | nvram_error_log_index = part->index + NVRAM_HEADER_LEN; | ||
469 | nvram_error_log_size = ((part->header.length - 1) * | ||
470 | NVRAM_BLOCK_LEN) - sizeof(struct err_log_info); | ||
471 | return 0; | ||
472 | } | ||
473 | } | ||
474 | |||
475 | /* try creating a partition with the free space we have */ | ||
476 | rc = nvram_create_os_partition(); | ||
477 | if (!rc) { | ||
478 | return 0; | ||
479 | } | ||
480 | |||
481 | /* need to free up some space */ | ||
482 | rc = nvram_remove_os_partition(); | ||
483 | if (rc) { | ||
484 | return rc; | ||
485 | } | ||
486 | |||
487 | /* create a partition in this new space */ | ||
488 | rc = nvram_create_os_partition(); | ||
489 | if (rc) { | ||
490 | printk(KERN_ERR "nvram_create_os_partition: Could not find a " | ||
491 | "NVRAM partition large enough\n"); | ||
492 | return rc; | ||
493 | } | ||
494 | |||
495 | return 0; | ||
496 | } | ||
497 | |||
498 | |||
499 | static int nvram_scan_partitions(void) | ||
500 | { | ||
501 | loff_t cur_index = 0; | ||
502 | struct nvram_header phead; | ||
503 | struct nvram_partition * tmp_part; | ||
504 | unsigned char c_sum; | ||
505 | char * header; | ||
506 | int total_size; | ||
507 | int err; | ||
508 | |||
509 | if (ppc_md.nvram_size == NULL) | ||
510 | return -ENODEV; | ||
511 | total_size = ppc_md.nvram_size(); | ||
512 | |||
513 | header = (char *) kmalloc(NVRAM_HEADER_LEN, GFP_KERNEL); | ||
514 | if (!header) { | ||
515 | printk(KERN_ERR "nvram_scan_partitions: Failed kmalloc\n"); | ||
516 | return -ENOMEM; | ||
517 | } | ||
518 | |||
519 | while (cur_index < total_size) { | ||
520 | |||
521 | err = ppc_md.nvram_read(header, NVRAM_HEADER_LEN, &cur_index); | ||
522 | if (err != NVRAM_HEADER_LEN) { | ||
523 | printk(KERN_ERR "nvram_scan_partitions: Error parsing " | ||
524 | "nvram partitions\n"); | ||
525 | goto out; | ||
526 | } | ||
527 | |||
528 | cur_index -= NVRAM_HEADER_LEN; /* nvram_read will advance us */ | ||
529 | |||
530 | memcpy(&phead, header, NVRAM_HEADER_LEN); | ||
531 | |||
532 | err = 0; | ||
533 | c_sum = nvram_checksum(&phead); | ||
534 | if (c_sum != phead.checksum) { | ||
535 | printk(KERN_WARNING "WARNING: nvram partition checksum" | ||
536 | " was %02x, should be %02x!\n", | ||
537 | phead.checksum, c_sum); | ||
538 | printk(KERN_WARNING "Terminating nvram partition scan\n"); | ||
539 | goto out; | ||
540 | } | ||
541 | if (!phead.length) { | ||
542 | printk(KERN_WARNING "WARNING: nvram corruption " | ||
543 | "detected: 0-length partition\n"); | ||
544 | goto out; | ||
545 | } | ||
546 | tmp_part = (struct nvram_partition *) | ||
547 | kmalloc(sizeof(struct nvram_partition), GFP_KERNEL); | ||
548 | err = -ENOMEM; | ||
549 | if (!tmp_part) { | ||
550 | printk(KERN_ERR "nvram_scan_partitions: kmalloc failed\n"); | ||
551 | goto out; | ||
552 | } | ||
553 | |||
554 | memcpy(&tmp_part->header, &phead, NVRAM_HEADER_LEN); | ||
555 | tmp_part->index = cur_index; | ||
556 | list_add_tail(&tmp_part->partition, &nvram_part->partition); | ||
557 | |||
558 | cur_index += phead.length * NVRAM_BLOCK_LEN; | ||
559 | } | ||
560 | err = 0; | ||
561 | |||
562 | out: | ||
563 | kfree(header); | ||
564 | return err; | ||
565 | } | ||
566 | |||
567 | static int __init nvram_init(void) | ||
568 | { | ||
569 | int error; | ||
570 | int rc; | ||
571 | |||
572 | if (ppc_md.nvram_size == NULL || ppc_md.nvram_size() <= 0) | ||
573 | return -ENODEV; | ||
574 | |||
575 | rc = misc_register(&nvram_dev); | ||
576 | if (rc != 0) { | ||
577 | printk(KERN_ERR "nvram_init: failed to register device\n"); | ||
578 | return rc; | ||
579 | } | ||
580 | |||
581 | /* initialize our anchor for the nvram partition list */ | ||
582 | nvram_part = (struct nvram_partition *) kmalloc(sizeof(struct nvram_partition), GFP_KERNEL); | ||
583 | if (!nvram_part) { | ||
584 | printk(KERN_ERR "nvram_init: Failed kmalloc\n"); | ||
585 | return -ENOMEM; | ||
586 | } | ||
587 | INIT_LIST_HEAD(&nvram_part->partition); | ||
588 | |||
589 | /* Get all the NVRAM partitions */ | ||
590 | error = nvram_scan_partitions(); | ||
591 | if (error) { | ||
592 | printk(KERN_ERR "nvram_init: Failed nvram_scan_partitions\n"); | ||
593 | return error; | ||
594 | } | ||
595 | |||
596 | if(nvram_setup_partition()) | ||
597 | printk(KERN_WARNING "nvram_init: Could not find nvram partition" | ||
598 | " for nvram buffered error logging.\n"); | ||
599 | |||
600 | #ifdef DEBUG_NVRAM | ||
601 | nvram_print_partitions("NVRAM Partitions"); | ||
602 | #endif | ||
603 | |||
604 | return rc; | ||
605 | } | ||
606 | |||
607 | void __exit nvram_cleanup(void) | ||
608 | { | ||
609 | misc_deregister( &nvram_dev ); | ||
610 | } | ||
611 | |||
612 | |||
613 | #ifdef CONFIG_PPC_PSERIES | ||
614 | |||
615 | /* nvram_write_error_log | ||
616 | * | ||
617 | * We need to buffer the error logs into nvram to ensure that we have | ||
618 | * the failure information to decode. If we have a severe error there | ||
619 | * is no way to guarantee that the OS or the machine is in a state to | ||
620 | * get back to user land and write the error to disk. For example if | ||
621 | * the SCSI device driver causes a Machine Check by writing to a bad | ||
622 | * IO address, there is no way of guaranteeing that the device driver | ||
623 | * is in any state that is would also be able to write the error data | ||
624 | * captured to disk, thus we buffer it in NVRAM for analysis on the | ||
625 | * next boot. | ||
626 | * | ||
627 | * In NVRAM the partition containing the error log buffer will looks like: | ||
628 | * Header (in bytes): | ||
629 | * +-----------+----------+--------+------------+------------------+ | ||
630 | * | signature | checksum | length | name | data | | ||
631 | * |0 |1 |2 3|4 15|16 length-1| | ||
632 | * +-----------+----------+--------+------------+------------------+ | ||
633 | * | ||
634 | * The 'data' section would look like (in bytes): | ||
635 | * +--------------+------------+-----------------------------------+ | ||
636 | * | event_logged | sequence # | error log | | ||
637 | * |0 3|4 7|8 nvram_error_log_size-1| | ||
638 | * +--------------+------------+-----------------------------------+ | ||
639 | * | ||
640 | * event_logged: 0 if event has not been logged to syslog, 1 if it has | ||
641 | * sequence #: The unique sequence # for each event. (until it wraps) | ||
642 | * error log: The error log from event_scan | ||
643 | */ | ||
644 | int nvram_write_error_log(char * buff, int length, unsigned int err_type) | ||
645 | { | ||
646 | int rc; | ||
647 | loff_t tmp_index; | ||
648 | struct err_log_info info; | ||
649 | |||
650 | if (no_logging) { | ||
651 | return -EPERM; | ||
652 | } | ||
653 | |||
654 | if (nvram_error_log_index == -1) { | ||
655 | return -ESPIPE; | ||
656 | } | ||
657 | |||
658 | if (length > nvram_error_log_size) { | ||
659 | length = nvram_error_log_size; | ||
660 | } | ||
661 | |||
662 | info.error_type = err_type; | ||
663 | info.seq_num = error_log_cnt; | ||
664 | |||
665 | tmp_index = nvram_error_log_index; | ||
666 | |||
667 | rc = ppc_md.nvram_write((char *)&info, sizeof(struct err_log_info), &tmp_index); | ||
668 | if (rc <= 0) { | ||
669 | printk(KERN_ERR "nvram_write_error_log: Failed nvram_write (%d)\n", rc); | ||
670 | return rc; | ||
671 | } | ||
672 | |||
673 | rc = ppc_md.nvram_write(buff, length, &tmp_index); | ||
674 | if (rc <= 0) { | ||
675 | printk(KERN_ERR "nvram_write_error_log: Failed nvram_write (%d)\n", rc); | ||
676 | return rc; | ||
677 | } | ||
678 | |||
679 | return 0; | ||
680 | } | ||
681 | |||
682 | /* nvram_read_error_log | ||
683 | * | ||
684 | * Reads nvram for error log for at most 'length' | ||
685 | */ | ||
686 | int nvram_read_error_log(char * buff, int length, unsigned int * err_type) | ||
687 | { | ||
688 | int rc; | ||
689 | loff_t tmp_index; | ||
690 | struct err_log_info info; | ||
691 | |||
692 | if (nvram_error_log_index == -1) | ||
693 | return -1; | ||
694 | |||
695 | if (length > nvram_error_log_size) | ||
696 | length = nvram_error_log_size; | ||
697 | |||
698 | tmp_index = nvram_error_log_index; | ||
699 | |||
700 | rc = ppc_md.nvram_read((char *)&info, sizeof(struct err_log_info), &tmp_index); | ||
701 | if (rc <= 0) { | ||
702 | printk(KERN_ERR "nvram_read_error_log: Failed nvram_read (%d)\n", rc); | ||
703 | return rc; | ||
704 | } | ||
705 | |||
706 | rc = ppc_md.nvram_read(buff, length, &tmp_index); | ||
707 | if (rc <= 0) { | ||
708 | printk(KERN_ERR "nvram_read_error_log: Failed nvram_read (%d)\n", rc); | ||
709 | return rc; | ||
710 | } | ||
711 | |||
712 | error_log_cnt = info.seq_num; | ||
713 | *err_type = info.error_type; | ||
714 | |||
715 | return 0; | ||
716 | } | ||
717 | |||
718 | /* This doesn't actually zero anything, but it sets the event_logged | ||
719 | * word to tell that this event is safely in syslog. | ||
720 | */ | ||
721 | int nvram_clear_error_log(void) | ||
722 | { | ||
723 | loff_t tmp_index; | ||
724 | int clear_word = ERR_FLAG_ALREADY_LOGGED; | ||
725 | int rc; | ||
726 | |||
727 | tmp_index = nvram_error_log_index; | ||
728 | |||
729 | rc = ppc_md.nvram_write((char *)&clear_word, sizeof(int), &tmp_index); | ||
730 | if (rc <= 0) { | ||
731 | printk(KERN_ERR "nvram_clear_error_log: Failed nvram_write (%d)\n", rc); | ||
732 | return rc; | ||
733 | } | ||
734 | |||
735 | return 0; | ||
736 | } | ||
737 | |||
738 | #endif /* CONFIG_PPC_PSERIES */ | ||
739 | |||
740 | module_init(nvram_init); | ||
741 | module_exit(nvram_cleanup); | ||
742 | MODULE_LICENSE("GPL"); | ||
diff --git a/arch/powerpc/kernel/pci_64.c b/arch/powerpc/kernel/pci_64.c index 5a5b24685081..8b6008ab217d 100644 --- a/arch/powerpc/kernel/pci_64.c +++ b/arch/powerpc/kernel/pci_64.c | |||
@@ -40,7 +40,7 @@ | |||
40 | #endif | 40 | #endif |
41 | 41 | ||
42 | unsigned long pci_probe_only = 1; | 42 | unsigned long pci_probe_only = 1; |
43 | unsigned long pci_assign_all_buses = 0; | 43 | int pci_assign_all_buses = 0; |
44 | 44 | ||
45 | /* | 45 | /* |
46 | * legal IO pages under MAX_ISA_PORT. This is to ensure we don't touch | 46 | * legal IO pages under MAX_ISA_PORT. This is to ensure we don't touch |
@@ -55,11 +55,6 @@ static void fixup_resource(struct resource *res, struct pci_dev *dev); | |||
55 | static void do_bus_setup(struct pci_bus *bus); | 55 | static void do_bus_setup(struct pci_bus *bus); |
56 | #endif | 56 | #endif |
57 | 57 | ||
58 | unsigned int pcibios_assign_all_busses(void) | ||
59 | { | ||
60 | return pci_assign_all_buses; | ||
61 | } | ||
62 | |||
63 | /* pci_io_base -- the base address from which io bars are offsets. | 58 | /* pci_io_base -- the base address from which io bars are offsets. |
64 | * This is the lowest I/O base address (so bar values are always positive), | 59 | * This is the lowest I/O base address (so bar values are always positive), |
65 | * and it *must* be the start of ISA space if an ISA bus exists because | 60 | * and it *must* be the start of ISA space if an ISA bus exists because |
@@ -1186,17 +1181,6 @@ void phbs_remap_io(void) | |||
1186 | remap_bus_range(hose->bus); | 1181 | remap_bus_range(hose->bus); |
1187 | } | 1182 | } |
1188 | 1183 | ||
1189 | /* | ||
1190 | * ppc64 can have multifunction devices that do not respond to function 0. | ||
1191 | * In this case we must scan all functions. | ||
1192 | * XXX this can go now, we use the OF device tree in all the | ||
1193 | * cases that caused problems. -- paulus | ||
1194 | */ | ||
1195 | int pcibios_scan_all_fns(struct pci_bus *bus, int devfn) | ||
1196 | { | ||
1197 | return 0; | ||
1198 | } | ||
1199 | |||
1200 | static void __devinit fixup_resource(struct resource *res, struct pci_dev *dev) | 1184 | static void __devinit fixup_resource(struct resource *res, struct pci_dev *dev) |
1201 | { | 1185 | { |
1202 | struct pci_controller *hose = pci_bus_to_host(dev->bus); | 1186 | struct pci_controller *hose = pci_bus_to_host(dev->bus); |
diff --git a/arch/powerpc/kernel/ppc_ksyms.c b/arch/powerpc/kernel/ppc_ksyms.c index 59846b40d521..af4d1bc9a2eb 100644 --- a/arch/powerpc/kernel/ppc_ksyms.c +++ b/arch/powerpc/kernel/ppc_ksyms.c | |||
@@ -146,9 +146,6 @@ EXPORT_SYMBOL(pci_bus_io_base); | |||
146 | EXPORT_SYMBOL(pci_bus_io_base_phys); | 146 | EXPORT_SYMBOL(pci_bus_io_base_phys); |
147 | EXPORT_SYMBOL(pci_bus_mem_base_phys); | 147 | EXPORT_SYMBOL(pci_bus_mem_base_phys); |
148 | EXPORT_SYMBOL(pci_bus_to_hose); | 148 | EXPORT_SYMBOL(pci_bus_to_hose); |
149 | EXPORT_SYMBOL(pci_resource_to_bus); | ||
150 | EXPORT_SYMBOL(pci_phys_to_bus); | ||
151 | EXPORT_SYMBOL(pci_bus_to_phys); | ||
152 | #endif /* CONFIG_PCI */ | 149 | #endif /* CONFIG_PCI */ |
153 | 150 | ||
154 | #ifdef CONFIG_NOT_COHERENT_CACHE | 151 | #ifdef CONFIG_NOT_COHERENT_CACHE |
diff --git a/arch/powerpc/kernel/ptrace-common.h b/arch/powerpc/kernel/ptrace-common.h new file mode 100644 index 000000000000..b1babb729673 --- /dev/null +++ b/arch/powerpc/kernel/ptrace-common.h | |||
@@ -0,0 +1,164 @@ | |||
1 | /* | ||
2 | * linux/arch/ppc64/kernel/ptrace-common.h | ||
3 | * | ||
4 | * Copyright (c) 2002 Stephen Rothwell, IBM Coproration | ||
5 | * Extracted from ptrace.c and ptrace32.c | ||
6 | * | ||
7 | * This file is subject to the terms and conditions of the GNU General | ||
8 | * Public License. See the file README.legal in the main directory of | ||
9 | * this archive for more details. | ||
10 | */ | ||
11 | |||
12 | #ifndef _PPC64_PTRACE_COMMON_H | ||
13 | #define _PPC64_PTRACE_COMMON_H | ||
14 | |||
15 | #include <linux/config.h> | ||
16 | #include <asm/system.h> | ||
17 | |||
18 | /* | ||
19 | * Set of msr bits that gdb can change on behalf of a process. | ||
20 | */ | ||
21 | #define MSR_DEBUGCHANGE (MSR_FE0 | MSR_SE | MSR_BE | MSR_FE1) | ||
22 | |||
23 | /* | ||
24 | * Get contents of register REGNO in task TASK. | ||
25 | */ | ||
26 | static inline unsigned long get_reg(struct task_struct *task, int regno) | ||
27 | { | ||
28 | unsigned long tmp = 0; | ||
29 | |||
30 | /* | ||
31 | * Put the correct FP bits in, they might be wrong as a result | ||
32 | * of our lazy FP restore. | ||
33 | */ | ||
34 | if (regno == PT_MSR) { | ||
35 | tmp = ((unsigned long *)task->thread.regs)[PT_MSR]; | ||
36 | tmp |= task->thread.fpexc_mode; | ||
37 | } else if (regno < (sizeof(struct pt_regs) / sizeof(unsigned long))) { | ||
38 | tmp = ((unsigned long *)task->thread.regs)[regno]; | ||
39 | } | ||
40 | |||
41 | return tmp; | ||
42 | } | ||
43 | |||
44 | /* | ||
45 | * Write contents of register REGNO in task TASK. | ||
46 | */ | ||
47 | static inline int put_reg(struct task_struct *task, int regno, | ||
48 | unsigned long data) | ||
49 | { | ||
50 | if (regno < PT_SOFTE) { | ||
51 | if (regno == PT_MSR) | ||
52 | data = (data & MSR_DEBUGCHANGE) | ||
53 | | (task->thread.regs->msr & ~MSR_DEBUGCHANGE); | ||
54 | ((unsigned long *)task->thread.regs)[regno] = data; | ||
55 | return 0; | ||
56 | } | ||
57 | return -EIO; | ||
58 | } | ||
59 | |||
60 | static inline void set_single_step(struct task_struct *task) | ||
61 | { | ||
62 | struct pt_regs *regs = task->thread.regs; | ||
63 | if (regs != NULL) | ||
64 | regs->msr |= MSR_SE; | ||
65 | set_ti_thread_flag(task->thread_info, TIF_SINGLESTEP); | ||
66 | } | ||
67 | |||
68 | static inline void clear_single_step(struct task_struct *task) | ||
69 | { | ||
70 | struct pt_regs *regs = task->thread.regs; | ||
71 | if (regs != NULL) | ||
72 | regs->msr &= ~MSR_SE; | ||
73 | clear_ti_thread_flag(task->thread_info, TIF_SINGLESTEP); | ||
74 | } | ||
75 | |||
76 | #ifdef CONFIG_ALTIVEC | ||
77 | /* | ||
78 | * Get/set all the altivec registers vr0..vr31, vscr, vrsave, in one go. | ||
79 | * The transfer totals 34 quadword. Quadwords 0-31 contain the | ||
80 | * corresponding vector registers. Quadword 32 contains the vscr as the | ||
81 | * last word (offset 12) within that quadword. Quadword 33 contains the | ||
82 | * vrsave as the first word (offset 0) within the quadword. | ||
83 | * | ||
84 | * This definition of the VMX state is compatible with the current PPC32 | ||
85 | * ptrace interface. This allows signal handling and ptrace to use the | ||
86 | * same structures. This also simplifies the implementation of a bi-arch | ||
87 | * (combined (32- and 64-bit) gdb. | ||
88 | */ | ||
89 | |||
90 | /* | ||
91 | * Get contents of AltiVec register state in task TASK | ||
92 | */ | ||
93 | static inline int get_vrregs(unsigned long __user *data, | ||
94 | struct task_struct *task) | ||
95 | { | ||
96 | unsigned long regsize; | ||
97 | |||
98 | /* copy AltiVec registers VR[0] .. VR[31] */ | ||
99 | regsize = 32 * sizeof(vector128); | ||
100 | if (copy_to_user(data, task->thread.vr, regsize)) | ||
101 | return -EFAULT; | ||
102 | data += (regsize / sizeof(unsigned long)); | ||
103 | |||
104 | /* copy VSCR */ | ||
105 | regsize = 1 * sizeof(vector128); | ||
106 | if (copy_to_user(data, &task->thread.vscr, regsize)) | ||
107 | return -EFAULT; | ||
108 | data += (regsize / sizeof(unsigned long)); | ||
109 | |||
110 | /* copy VRSAVE */ | ||
111 | if (put_user(task->thread.vrsave, (u32 __user *)data)) | ||
112 | return -EFAULT; | ||
113 | |||
114 | return 0; | ||
115 | } | ||
116 | |||
117 | /* | ||
118 | * Write contents of AltiVec register state into task TASK. | ||
119 | */ | ||
120 | static inline int set_vrregs(struct task_struct *task, | ||
121 | unsigned long __user *data) | ||
122 | { | ||
123 | unsigned long regsize; | ||
124 | |||
125 | /* copy AltiVec registers VR[0] .. VR[31] */ | ||
126 | regsize = 32 * sizeof(vector128); | ||
127 | if (copy_from_user(task->thread.vr, data, regsize)) | ||
128 | return -EFAULT; | ||
129 | data += (regsize / sizeof(unsigned long)); | ||
130 | |||
131 | /* copy VSCR */ | ||
132 | regsize = 1 * sizeof(vector128); | ||
133 | if (copy_from_user(&task->thread.vscr, data, regsize)) | ||
134 | return -EFAULT; | ||
135 | data += (regsize / sizeof(unsigned long)); | ||
136 | |||
137 | /* copy VRSAVE */ | ||
138 | if (get_user(task->thread.vrsave, (u32 __user *)data)) | ||
139 | return -EFAULT; | ||
140 | |||
141 | return 0; | ||
142 | } | ||
143 | #endif | ||
144 | |||
145 | static inline int ptrace_set_debugreg(struct task_struct *task, | ||
146 | unsigned long addr, unsigned long data) | ||
147 | { | ||
148 | /* We only support one DABR and no IABRS at the moment */ | ||
149 | if (addr > 0) | ||
150 | return -EINVAL; | ||
151 | |||
152 | /* The bottom 3 bits are flags */ | ||
153 | if ((data & ~0x7UL) >= TASK_SIZE) | ||
154 | return -EIO; | ||
155 | |||
156 | /* Ensure translation is on */ | ||
157 | if (data && !(data & DABR_TRANSLATION)) | ||
158 | return -EIO; | ||
159 | |||
160 | task->thread.dabr = data; | ||
161 | return 0; | ||
162 | } | ||
163 | |||
164 | #endif /* _PPC64_PTRACE_COMMON_H */ | ||
diff --git a/arch/powerpc/kernel/ptrace.c b/arch/powerpc/kernel/ptrace.c index 3d2abd95c7ae..400793c71304 100644 --- a/arch/powerpc/kernel/ptrace.c +++ b/arch/powerpc/kernel/ptrace.c | |||
@@ -36,8 +36,9 @@ | |||
36 | #include <asm/page.h> | 36 | #include <asm/page.h> |
37 | #include <asm/pgtable.h> | 37 | #include <asm/pgtable.h> |
38 | #include <asm/system.h> | 38 | #include <asm/system.h> |
39 | |||
39 | #ifdef CONFIG_PPC64 | 40 | #ifdef CONFIG_PPC64 |
40 | #include <asm/ptrace-common.h> | 41 | #include "ptrace-common.h" |
41 | #endif | 42 | #endif |
42 | 43 | ||
43 | #ifdef CONFIG_PPC32 | 44 | #ifdef CONFIG_PPC32 |
diff --git a/arch/powerpc/kernel/ptrace32.c b/arch/powerpc/kernel/ptrace32.c index 91eb952e0293..61762640b877 100644 --- a/arch/powerpc/kernel/ptrace32.c +++ b/arch/powerpc/kernel/ptrace32.c | |||
@@ -33,7 +33,8 @@ | |||
33 | #include <asm/page.h> | 33 | #include <asm/page.h> |
34 | #include <asm/pgtable.h> | 34 | #include <asm/pgtable.h> |
35 | #include <asm/system.h> | 35 | #include <asm/system.h> |
36 | #include <asm/ptrace-common.h> | 36 | |
37 | #include "ptrace-common.h" | ||
37 | 38 | ||
38 | /* | 39 | /* |
39 | * does not yet catch signals sent when the child dies. | 40 | * does not yet catch signals sent when the child dies. |
diff --git a/arch/powerpc/kernel/rtas-rtc.c b/arch/powerpc/kernel/rtas-rtc.c index 7b948662704c..635d3b9a8811 100644 --- a/arch/powerpc/kernel/rtas-rtc.c +++ b/arch/powerpc/kernel/rtas-rtc.c | |||
@@ -15,7 +15,7 @@ unsigned long __init rtas_get_boot_time(void) | |||
15 | { | 15 | { |
16 | int ret[8]; | 16 | int ret[8]; |
17 | int error, wait_time; | 17 | int error, wait_time; |
18 | unsigned long max_wait_tb; | 18 | u64 max_wait_tb; |
19 | 19 | ||
20 | max_wait_tb = get_tb() + tb_ticks_per_usec * 1000 * MAX_RTC_WAIT; | 20 | max_wait_tb = get_tb() + tb_ticks_per_usec * 1000 * MAX_RTC_WAIT; |
21 | do { | 21 | do { |
@@ -45,7 +45,7 @@ void rtas_get_rtc_time(struct rtc_time *rtc_tm) | |||
45 | { | 45 | { |
46 | int ret[8]; | 46 | int ret[8]; |
47 | int error, wait_time; | 47 | int error, wait_time; |
48 | unsigned long max_wait_tb; | 48 | u64 max_wait_tb; |
49 | 49 | ||
50 | max_wait_tb = get_tb() + tb_ticks_per_usec * 1000 * MAX_RTC_WAIT; | 50 | max_wait_tb = get_tb() + tb_ticks_per_usec * 1000 * MAX_RTC_WAIT; |
51 | do { | 51 | do { |
@@ -80,7 +80,7 @@ void rtas_get_rtc_time(struct rtc_time *rtc_tm) | |||
80 | int rtas_set_rtc_time(struct rtc_time *tm) | 80 | int rtas_set_rtc_time(struct rtc_time *tm) |
81 | { | 81 | { |
82 | int error, wait_time; | 82 | int error, wait_time; |
83 | unsigned long max_wait_tb; | 83 | u64 max_wait_tb; |
84 | 84 | ||
85 | max_wait_tb = get_tb() + tb_ticks_per_usec * 1000 * MAX_RTC_WAIT; | 85 | max_wait_tb = get_tb() + tb_ticks_per_usec * 1000 * MAX_RTC_WAIT; |
86 | do { | 86 | do { |
diff --git a/arch/powerpc/kernel/time.c b/arch/powerpc/kernel/time.c index 070b4b458aaf..de8479769bb7 100644 --- a/arch/powerpc/kernel/time.c +++ b/arch/powerpc/kernel/time.c | |||
@@ -130,6 +130,34 @@ unsigned long tb_last_stamp; | |||
130 | */ | 130 | */ |
131 | DEFINE_PER_CPU(unsigned long, last_jiffy); | 131 | DEFINE_PER_CPU(unsigned long, last_jiffy); |
132 | 132 | ||
133 | void __delay(unsigned long loops) | ||
134 | { | ||
135 | unsigned long start; | ||
136 | int diff; | ||
137 | |||
138 | if (__USE_RTC()) { | ||
139 | start = get_rtcl(); | ||
140 | do { | ||
141 | /* the RTCL register wraps at 1000000000 */ | ||
142 | diff = get_rtcl() - start; | ||
143 | if (diff < 0) | ||
144 | diff += 1000000000; | ||
145 | } while (diff < loops); | ||
146 | } else { | ||
147 | start = get_tbl(); | ||
148 | while (get_tbl() - start < loops) | ||
149 | HMT_low(); | ||
150 | HMT_medium(); | ||
151 | } | ||
152 | } | ||
153 | EXPORT_SYMBOL(__delay); | ||
154 | |||
155 | void udelay(unsigned long usecs) | ||
156 | { | ||
157 | __delay(tb_ticks_per_usec * usecs); | ||
158 | } | ||
159 | EXPORT_SYMBOL(udelay); | ||
160 | |||
133 | static __inline__ void timer_check_rtc(void) | 161 | static __inline__ void timer_check_rtc(void) |
134 | { | 162 | { |
135 | /* | 163 | /* |