Merge branch 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/dtor/input
[linux-btrfs-devel.git] / arch / cris / arch-v32 / mach-a3 / vcs_hook.c
blob58b1a5469fd7b4401ea0568d1ad019a46506bec1
1 /*
2 * Simulator hook mechanism
3 */
5 #include "vcs_hook.h"
6 #include <asm/io.h>
7 #include <stdarg.h>
9 #define HOOK_TRIG_ADDR 0xb7000000
10 #define HOOK_MEM_BASE_ADDR 0xce000000
12 static volatile unsigned *hook_base;
14 #define HOOK_DATA(offset) hook_base[offset]
15 #define VHOOK_DATA(offset) hook_base[offset]
16 #define HOOK_TRIG(funcid) \
17 do { \
18 *((unsigned *) HOOK_TRIG_ADDR) = funcid; \
19 } while (0)
20 #define HOOK_DATA_BYTE(offset) ((unsigned char *)hook_base)[offset]
22 static void hook_init(void)
24 static int first = 1;
25 if (first) {
26 first = 0;
27 hook_base = ioremap(HOOK_MEM_BASE_ADDR, 8192);
31 static unsigned hook_trig(unsigned id)
33 unsigned ret;
35 /* preempt_disable(); */
37 /* Dummy read from mem to make sure data has propagated to memory
38 * before trigging */
39 ret = *hook_base;
41 /* trigger hook */
42 HOOK_TRIG(id);
44 /* wait for call to finish */
45 while (VHOOK_DATA(0) > 0) ;
47 /* extract return value */
49 ret = VHOOK_DATA(1);
51 return ret;
54 int hook_call(unsigned id, unsigned pcnt, ...)
56 va_list ap;
57 int i;
58 unsigned ret;
60 hook_init();
62 HOOK_DATA(0) = id;
64 va_start(ap, pcnt);
65 for (i = 1; i <= pcnt; i++)
66 HOOK_DATA(i) = va_arg(ap, unsigned);
67 va_end(ap);
69 ret = hook_trig(id);
71 return ret;
74 int hook_call_str(unsigned id, unsigned size, const char *str)
76 int i;
77 unsigned ret;
79 hook_init();
81 HOOK_DATA(0) = id;
82 HOOK_DATA(1) = size;
84 for (i = 0; i < size; i++)
85 HOOK_DATA_BYTE(8 + i) = str[i];
86 HOOK_DATA_BYTE(8 + i) = 0;
88 ret = hook_trig(id);
90 return ret;
93 void print_str(const char *str)
95 int i;
96 /* find null at end of string */
97 for (i = 1; str[i]; i++) ;
98 hook_call(hook_print_str, i, str);
101 void CPU_WATCHDOG_TIMEOUT(unsigned t)