direct-io.hg

view xen/common/keyhandler.c @ 8401:11cd619db035

Changed UUID / Xen handle formatting to be compatible with the OSF DCE UUIDs.

Signed-off-by: Ewan Mellor <ewan@xensource.com>
author emellor@leeni.uk.xensource.com
date Tue Dec 20 17:16:15 2005 +0000 (2005-12-20)
parents ba9706473941
children 8d0b62f0aa8d
line source
1 /******************************************************************************
2 * keyhandler.c
3 */
5 #include <asm/regs.h>
6 #include <xen/keyhandler.h>
7 #include <xen/reboot.h>
8 #include <xen/event.h>
9 #include <xen/console.h>
10 #include <xen/serial.h>
11 #include <xen/sched.h>
12 #include <xen/softirq.h>
13 #include <xen/domain.h>
14 #include <asm/debugger.h>
16 #define KEY_MAX 256
17 #define STR_MAX 64
19 static struct {
20 union {
21 keyhandler_t *handler;
22 irq_keyhandler_t *irq_handler;
23 } u;
24 unsigned int flags;
25 char desc[STR_MAX];
26 } key_table[KEY_MAX];
28 #define KEYHANDLER_IRQ_CALLBACK 0x1
30 static unsigned char keypress_key;
32 static void keypress_softirq(void)
33 {
34 keyhandler_t *h;
35 unsigned char key = keypress_key;
36 if ( (h = key_table[key].u.handler) != NULL )
37 (*h)(key);
38 }
40 void handle_keypress(unsigned char key, struct cpu_user_regs *regs)
41 {
42 irq_keyhandler_t *h;
44 if ( key_table[key].flags & KEYHANDLER_IRQ_CALLBACK )
45 {
46 if ( (h = key_table[key].u.irq_handler) != NULL )
47 (*h)(key, regs);
48 }
49 else
50 {
51 keypress_key = key;
52 raise_softirq(KEYPRESS_SOFTIRQ);
53 }
54 }
56 void register_keyhandler(
57 unsigned char key, keyhandler_t *handler, char *desc)
58 {
59 ASSERT(key_table[key].u.handler == NULL);
60 key_table[key].u.handler = handler;
61 key_table[key].flags = 0;
62 strncpy(key_table[key].desc, desc, STR_MAX);
63 key_table[key].desc[STR_MAX-1] = '\0';
64 }
66 void register_irq_keyhandler(
67 unsigned char key, irq_keyhandler_t *handler, char *desc)
68 {
69 ASSERT(key_table[key].u.irq_handler == NULL);
70 key_table[key].u.irq_handler = handler;
71 key_table[key].flags = KEYHANDLER_IRQ_CALLBACK;
72 strncpy(key_table[key].desc, desc, STR_MAX);
73 key_table[key].desc[STR_MAX-1] = '\0';
74 }
76 static void show_handlers(unsigned char key)
77 {
78 int i;
79 printk("'%c' pressed -> showing installed handlers\n", key);
80 for ( i = 0; i < KEY_MAX; i++ )
81 if ( key_table[i].u.handler != NULL )
82 printk(" key '%c' (ascii '%02x') => %s\n",
83 (i<33 || i>126)?(' '):(i),i,
84 key_table[i].desc);
85 }
87 static void dump_registers(unsigned char key, struct cpu_user_regs *regs)
88 {
89 printk("'%c' pressed -> dumping registers\n", key);
90 show_registers(regs);
91 }
93 static void halt_machine(unsigned char key, struct cpu_user_regs *regs)
94 {
95 printk("'%c' pressed -> rebooting machine\n", key);
96 machine_restart(NULL);
97 }
99 static void do_task_queues(unsigned char key)
100 {
101 struct domain *d;
102 struct vcpu *v;
103 s_time_t now = NOW();
105 printk("'%c' pressed -> dumping task queues (now=0x%X:%08X)\n", key,
106 (u32)(now>>32), (u32)now);
108 read_lock(&domlist_lock);
110 for_each_domain ( d )
111 {
112 printk("Xen: DOM %u, flags=%lx refcnt=%d nr_pages=%d "
113 "xenheap_pages=%d\n", d->domain_id, d->domain_flags,
114 atomic_read(&d->refcnt), d->tot_pages, d->xenheap_pages);
115 /* The handle is printed according to the OSF DCE UUID spec., even
116 though it is not necessarily such a thing, for ease of use when it
117 _is_ one of those. */
118 printk(" handle=%02x%02x%02x%02x-%02x%02x-%02x%02x-"
119 "%02x%02x-%02x%02x%02x%02x%02x%02x\n",
120 d->handle[ 0], d->handle[ 1], d->handle[ 2], d->handle[ 3],
121 d->handle[ 4], d->handle[ 5], d->handle[ 6], d->handle[ 7],
122 d->handle[ 8], d->handle[ 9], d->handle[10], d->handle[11],
123 d->handle[12], d->handle[13], d->handle[14], d->handle[15]);
125 dump_pageframe_info(d);
127 for_each_vcpu ( d, v ) {
128 printk("Guest: %p CPU %d [has=%c] flags=%lx "
129 "upcall_pend = %02x, upcall_mask = %02x\n", v,
130 v->processor,
131 test_bit(_VCPUF_running, &v->vcpu_flags) ? 'T':'F',
132 v->vcpu_flags,
133 v->vcpu_info->evtchn_upcall_pending,
134 v->vcpu_info->evtchn_upcall_mask);
135 printk("Notifying guest... %d/%d\n", d->domain_id, v->vcpu_id);
136 printk("port %d/%d stat %d %d %d\n",
137 VIRQ_DEBUG, v->virq_to_evtchn[VIRQ_DEBUG],
138 test_bit(v->virq_to_evtchn[VIRQ_DEBUG],
139 &d->shared_info->evtchn_pending[0]),
140 test_bit(v->virq_to_evtchn[VIRQ_DEBUG],
141 &d->shared_info->evtchn_mask[0]),
142 test_bit(v->virq_to_evtchn[VIRQ_DEBUG]/BITS_PER_LONG,
143 &v->vcpu_info->evtchn_pending_sel));
144 send_guest_virq(v, VIRQ_DEBUG);
145 }
146 }
148 read_unlock(&domlist_lock);
149 }
151 extern void dump_runq(unsigned char key);
152 extern void print_sched_histo(unsigned char key);
153 extern void reset_sched_histo(unsigned char key);
154 #ifndef NDEBUG
155 extern void audit_domains_key(unsigned char key);
156 #endif
158 #ifdef PERF_COUNTERS
159 extern void perfc_printall(unsigned char key);
160 extern void perfc_reset(unsigned char key);
161 #endif
163 void do_debug_key(unsigned char key, struct cpu_user_regs *regs)
164 {
165 (void)debugger_trap_fatal(0xf001, regs);
166 nop(); /* Prevent the compiler doing tail call
167 optimisation, as that confuses xendbg a
168 bit. */
169 }
171 #ifndef NDEBUG
172 void debugtrace_key(unsigned char key)
173 {
174 debugtrace_send_to_console = !debugtrace_send_to_console;
175 debugtrace_dump();
176 printk("debugtrace_printk now writing to %s.\n",
177 debugtrace_send_to_console ? "console" : "buffer");
178 }
179 #endif
181 void initialize_keytable(void)
182 {
183 open_softirq(KEYPRESS_SOFTIRQ, keypress_softirq);
185 register_irq_keyhandler(
186 'd', dump_registers, "dump registers");
187 register_keyhandler(
188 'h', show_handlers, "show this message");
189 register_keyhandler(
190 'l', print_sched_histo, "print sched latency histogram");
191 register_keyhandler(
192 'L', reset_sched_histo, "reset sched latency histogram");
193 register_keyhandler(
194 'q', do_task_queues, "dump task queues + guest state");
195 register_keyhandler(
196 'r', dump_runq, "dump run queues");
197 register_irq_keyhandler(
198 'R', halt_machine, "reboot machine");
200 #ifndef NDEBUG
201 register_keyhandler(
202 'o', audit_domains_key, "audit domains >0 EXPERIMENTAL");
203 register_keyhandler(
204 'T', debugtrace_key, "toggle debugtrace to console/buffer");
205 #endif
207 #ifdef PERF_COUNTERS
208 register_keyhandler(
209 'p', perfc_printall, "print performance counters");
210 register_keyhandler(
211 'P', perfc_reset, "reset performance counters");
212 #endif
214 register_irq_keyhandler('%', do_debug_key, "Trap to xendbg");
215 }
217 /*
218 * Local variables:
219 * mode: C
220 * c-set-style: "BSD"
221 * c-basic-offset: 4
222 * tab-width: 4
223 * indent-tabs-mode: nil
224 * End:
225 */