ASoC: Revert "ASoC: Add new parameter to s3c24xx_pcm_enqueue"
[linux-2.6/btrfs-unstable.git] / arch / sparc64 / kernel / ftrace.c
blob4298d0aee7137caf896c6e20605620b1b58b0124
1 #include <linux/spinlock.h>
2 #include <linux/hardirq.h>
3 #include <linux/ftrace.h>
4 #include <linux/percpu.h>
5 #include <linux/init.h>
6 #include <linux/list.h>
8 #include <asm/ftrace.h>
10 static const u32 ftrace_nop = 0x01000000;
12 notrace unsigned char *ftrace_nop_replace(void)
14 return (char *)&ftrace_nop;
17 notrace unsigned char *ftrace_call_replace(unsigned long ip, unsigned long addr)
19 static u32 call;
20 s32 off;
22 off = ((s32)addr - (s32)ip);
23 call = 0x40000000 | ((u32)off >> 2);
25 return (unsigned char *) &call;
28 notrace int
29 ftrace_modify_code(unsigned long ip, unsigned char *old_code,
30 unsigned char *new_code)
32 u32 old = *(u32 *)old_code;
33 u32 new = *(u32 *)new_code;
34 u32 replaced;
35 int faulted;
37 __asm__ __volatile__(
38 "1: cas [%[ip]], %[old], %[new]\n"
39 " flush %[ip]\n"
40 " mov 0, %[faulted]\n"
41 "2:\n"
42 " .section .fixup,#alloc,#execinstr\n"
43 " .align 4\n"
44 "3: sethi %%hi(2b), %[faulted]\n"
45 " jmpl %[faulted] + %%lo(2b), %%g0\n"
46 " mov 1, %[faulted]\n"
47 " .previous\n"
48 " .section __ex_table,\"a\"\n"
49 " .align 4\n"
50 " .word 1b, 3b\n"
51 " .previous\n"
52 : "=r" (replaced), [faulted] "=r" (faulted)
53 : [new] "0" (new), [old] "r" (old), [ip] "r" (ip)
54 : "memory");
56 if (replaced != old && replaced != new)
57 faulted = 2;
59 return faulted;
62 notrace int ftrace_update_ftrace_func(ftrace_func_t func)
64 unsigned long ip = (unsigned long)(&ftrace_call);
65 unsigned char old[MCOUNT_INSN_SIZE], *new;
67 memcpy(old, &ftrace_call, MCOUNT_INSN_SIZE);
68 new = ftrace_call_replace(ip, (unsigned long)func);
69 return ftrace_modify_code(ip, old, new);
72 notrace int ftrace_mcount_set(unsigned long *data)
74 unsigned long ip = (long)(&mcount_call);
75 unsigned long *addr = data;
76 unsigned char old[MCOUNT_INSN_SIZE], *new;
79 * Replace the mcount stub with a pointer to the
80 * ip recorder function.
82 memcpy(old, &mcount_call, MCOUNT_INSN_SIZE);
83 new = ftrace_call_replace(ip, *addr);
84 *addr = ftrace_modify_code(ip, old, new);
86 return 0;
90 int __init ftrace_dyn_arch_init(void *data)
92 ftrace_mcount_set(data);
93 return 0;