ia64/xen-unstable

view xen/common/keyhandler.c @ 2981:b49a4a760280

bitkeeper revision 1.1159.170.25 (4198cc3b-yQEJ6t2KXb0BZw64jh66Q)

Merge freefall.cl.cam.ac.uk:/auto/groups/xeno/BK/xeno.bk
into freefall.cl.cam.ac.uk:/auto/groups/xeno/users/cl349/BK/xen.bk-ddb
author cl349@freefall.cl.cam.ac.uk
date Mon Nov 15 15:33:15 2004 +0000 (2004-11-15)
parents 34da3b621a8a 43bbf6841c7f
children f0fe276ae088 20087d779fb6 4644bea63898
line source
1 /******************************************************************************
2 * keyhandler.c
3 */
5 #include <xen/keyhandler.h>
6 #include <xen/reboot.h>
7 #include <xen/event.h>
8 #include <xen/console.h>
9 #include <xen/serial.h>
10 #include <xen/sched.h>
11 #include <xen/softirq.h>
13 #define KEY_MAX 256
14 #define STR_MAX 64
16 static struct {
17 union {
18 keyhandler_t *handler;
19 irq_keyhandler_t *irq_handler;
20 } u;
21 unsigned int flags;
22 char desc[STR_MAX];
23 } key_table[KEY_MAX];
25 #define KEYHANDLER_IRQ_CALLBACK 0x1
27 static unsigned char keypress_key;
29 void keypress_softirq(void)
30 {
31 keyhandler_t *h;
32 unsigned char key = keypress_key;
33 if ( (h = key_table[key].u.handler) != NULL )
34 (*h)(key);
35 }
37 void handle_keypress(unsigned char key, struct xen_regs *regs)
38 {
39 irq_keyhandler_t *h;
41 if ( key_table[key].flags & KEYHANDLER_IRQ_CALLBACK )
42 {
43 if ( (h = key_table[key].u.irq_handler) != NULL )
44 (*h)(key, regs);
45 }
46 else
47 {
48 keypress_key = key;
49 raise_softirq(KEYPRESS_SOFTIRQ);
50 }
51 }
53 void register_keyhandler(
54 unsigned char key, keyhandler_t *handler, char *desc)
55 {
56 ASSERT(key_table[key].u.handler == NULL);
57 key_table[key].u.handler = handler;
58 key_table[key].flags = 0;
59 strncpy(key_table[key].desc, desc, STR_MAX);
60 key_table[key].desc[STR_MAX-1] = '\0';
61 }
63 void register_irq_keyhandler(
64 unsigned char key, irq_keyhandler_t *handler, char *desc)
65 {
66 ASSERT(key_table[key].u.irq_handler == NULL);
67 key_table[key].u.irq_handler = handler;
68 key_table[key].flags = KEYHANDLER_IRQ_CALLBACK;
69 strncpy(key_table[key].desc, desc, STR_MAX);
70 key_table[key].desc[STR_MAX-1] = '\0';
71 }
73 static void show_handlers(unsigned char key)
74 {
75 int i;
76 printk("'%c' pressed -> showing installed handlers\n", key);
77 for ( i = 0; i < KEY_MAX; i++ )
78 if ( key_table[i].u.handler != NULL )
79 printk(" key '%c' (ascii '%02x') => %s\n",
80 (i<33 || i>126)?(' '):(i),i,
81 key_table[i].desc);
82 }
85 static void dump_registers(unsigned char key, struct xen_regs *regs)
86 {
87 extern void show_registers(struct xen_regs *regs);
88 printk("'%c' pressed -> dumping registers\n", key);
89 show_registers(regs);
90 }
92 static void halt_machine(unsigned char key, struct xen_regs *regs)
93 {
94 printk("'%c' pressed -> rebooting machine\n", key);
95 machine_restart(NULL);
96 }
98 void do_task_queues(unsigned char key)
99 {
100 struct domain *d;
101 s_time_t now = NOW();
102 struct list_head *ent;
103 struct pfn_info *page;
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, CPU %d [has=%c] flags=%lx refcnt=%d nr_pages=%d "
113 "xenheap_pages=%d\n",
114 d->id, d->processor,
115 test_bit(DF_RUNNING, &d->flags) ? 'T':'F', d->flags,
116 atomic_read(&d->refcnt), d->tot_pages, d->xenheap_pages);
118 if ( d->tot_pages < 10 )
119 {
120 list_for_each ( ent, &d->page_list )
121 {
122 page = list_entry(ent, struct pfn_info, list);
123 printk("Page %08x: caf=%08x, taf=%08x\n",
124 page_to_phys(page), page->count_info,
125 page->u.inuse.type_info);
126 }
127 }
129 page = virt_to_page(d->shared_info);
130 printk("Shared_info@%08x: caf=%08x, taf=%08x\n",
131 page_to_phys(page), page->count_info,
132 page->u.inuse.type_info);
134 printk("Guest: upcall_pend = %02x, upcall_mask = %02x\n",
135 d->shared_info->vcpu_data[0].evtchn_upcall_pending,
136 d->shared_info->vcpu_data[0].evtchn_upcall_mask);
137 printk("Notifying guest...\n");
138 send_guest_virq(d, VIRQ_DEBUG);
139 }
141 read_unlock(&domlist_lock);
142 }
144 extern void dump_runq(unsigned char key);
145 extern void print_sched_histo(unsigned char key);
146 extern void reset_sched_histo(unsigned char key);
147 #ifndef NDEBUG
148 extern void audit_domains_key(unsigned char key);
149 #endif
151 #ifdef PERF_COUNTERS
152 extern void perfc_printall(unsigned char key);
153 extern void perfc_reset(unsigned char key);
154 #endif
156 void initialize_keytable(void)
157 {
158 open_softirq(KEYPRESS_SOFTIRQ, keypress_softirq);
160 register_irq_keyhandler(
161 'd', dump_registers, "dump registers");
162 register_keyhandler(
163 'h', show_handlers, "show this message");
164 register_keyhandler(
165 'l', print_sched_histo, "print sched latency histogram");
166 register_keyhandler(
167 'L', reset_sched_histo, "reset sched latency histogram");
168 register_keyhandler(
169 'q', do_task_queues, "dump task queues + guest state");
170 register_keyhandler(
171 'r', dump_runq, "dump run queues");
172 register_irq_keyhandler(
173 'R', halt_machine, "reboot machine");
175 #ifndef NDEBUG
176 register_keyhandler(
177 'o', audit_domains_key, "audit domains >0 EXPERIMENTAL");
178 #endif
180 #ifdef PERF_COUNTERS
181 register_keyhandler(
182 'p', perfc_printall, "print performance counters");
183 register_keyhandler(
184 'P', perfc_reset, "reset performance counters");
185 #endif
186 }