ia64/xen-unstable

changeset 2970:34da3b621a8a

bitkeeper revision 1.1159.170.18 (419631f46LScNrXRGEL-VrxeFQPSBA)

Clean up keyhandler interface. Now register a new keyhandler with
register_keyhandler() or register_irq_keyhandler().
author kaf24@freefall.cl.cam.ac.uk
date Sat Nov 13 16:10:28 2004 +0000 (2004-11-13)
parents 0e2d163a08c8
children 4d94e2b30873
files xen/arch/x86/pdb-stub.c xen/common/ac_timer.c xen/common/keyhandler.c xen/include/xen/keyhandler.h
line diff
     1.1 --- a/xen/arch/x86/pdb-stub.c	Sat Nov 13 15:49:25 2004 +0000
     1.2 +++ b/xen/arch/x86/pdb-stub.c	Sat Nov 13 16:10:28 2004 +0000
     1.3 @@ -1244,7 +1244,7 @@ void initialize_pdb()
     1.4      /* Acknowledge any spurious GDB packets. */
     1.5      pdb_put_char('+');
     1.6  
     1.7 -    add_key_handler('D', pdb_key_pressed, "enter pervasive debugger");
     1.8 +    register_keyhandler('D', pdb_key_pressed, "enter pervasive debugger");
     1.9  
    1.10      pdb_initialized = 1;
    1.11  }
     2.1 --- a/xen/common/ac_timer.c	Sat Nov 13 15:49:25 2004 +0000
     2.2 +++ b/xen/common/ac_timer.c	Sat Nov 13 16:10:28 2004 +0000
     2.3 @@ -286,5 +286,5 @@ void __init ac_timer_init(void)
     2.4          spin_lock_init(&ac_timers[i].lock);
     2.5      }
     2.6  
     2.7 -    add_key_handler('a', dump_timerq, "dump ac_timer queues");
     2.8 +    register_keyhandler('a', dump_timerq, "dump ac_timer queues");
     2.9  }
     3.1 --- a/xen/common/keyhandler.c	Sat Nov 13 15:49:25 2004 +0000
     3.2 +++ b/xen/common/keyhandler.c	Sat Nov 13 16:10:28 2004 +0000
     3.3 @@ -1,3 +1,6 @@
     3.4 +/******************************************************************************
     3.5 + * keyhandler.c
     3.6 + */
     3.7  
     3.8  #include <xen/keyhandler.h> 
     3.9  #include <xen/reboot.h>
    3.10 @@ -10,49 +13,61 @@
    3.11  #define KEY_MAX 256
    3.12  #define STR_MAX  64
    3.13  
    3.14 -static struct { 
    3.15 -    key_handler *handler;
    3.16 -    int          flags;
    3.17 +static struct {
    3.18 +    union {
    3.19 +        keyhandler_t     *handler;
    3.20 +        irq_keyhandler_t *irq_handler;
    3.21 +    } u;
    3.22 +    unsigned int flags;
    3.23      char         desc[STR_MAX]; 
    3.24  } key_table[KEY_MAX]; 
    3.25  
    3.26 -#define KEYHANDLER_NO_DEFER 0x1
    3.27 +#define KEYHANDLER_IRQ_CALLBACK 0x1
    3.28  
    3.29  static unsigned char keypress_key;
    3.30  
    3.31  void keypress_softirq(void)
    3.32  {
    3.33 -    key_handler  *h;
    3.34 +    keyhandler_t *h;
    3.35      unsigned char key = keypress_key;
    3.36 -    if ( (h = key_table[key].handler) != NULL )
    3.37 +    if ( (h = key_table[key].u.handler) != NULL )
    3.38          (*h)(key);
    3.39  }
    3.40  
    3.41  void handle_keypress(unsigned char key, struct xen_regs *regs)
    3.42  {
    3.43 -    key_handler  *h;
    3.44 +    irq_keyhandler_t *h;
    3.45  
    3.46 -    keypress_key = key;
    3.47 -    if ( (key_table[key].flags & KEYHANDLER_NO_DEFER) &&
    3.48 -         ((h = key_table[key].handler) != NULL) )
    3.49 -        ((void (*)(unsigned char, struct xen_regs *))*h)(key, regs);
    3.50 +    if ( key_table[key].flags & KEYHANDLER_IRQ_CALLBACK )
    3.51 +    {
    3.52 +        if ( (h = key_table[key].u.irq_handler) != NULL )
    3.53 +            (*h)(key, regs);
    3.54 +    }
    3.55      else
    3.56 +    {
    3.57 +        keypress_key = key;
    3.58          raise_softirq(KEYPRESS_SOFTIRQ);
    3.59 +    }
    3.60  }
    3.61  
    3.62 -void add_key_handler(unsigned char key, key_handler *handler, char *desc)
    3.63 +void register_keyhandler(
    3.64 +    unsigned char key, keyhandler_t *handler, char *desc)
    3.65  {
    3.66 -    key_table[key].handler = handler;
    3.67 -    key_table[key].flags = 0;
    3.68 +    ASSERT(key_table[key].u.handler == NULL);
    3.69 +    key_table[key].u.handler = handler;
    3.70 +    key_table[key].flags     = 0;
    3.71      strncpy(key_table[key].desc, desc, STR_MAX);
    3.72      key_table[key].desc[STR_MAX-1] = '\0'; 
    3.73  }
    3.74  
    3.75 -void add_key_handler_no_defer(unsigned char key, key_handler *handler,
    3.76 -                              char *desc)
    3.77 +void register_irq_keyhandler(
    3.78 +    unsigned char key, irq_keyhandler_t *handler, char *desc)
    3.79  {
    3.80 -    add_key_handler(key, handler, desc);
    3.81 -    key_table[key].flags |= KEYHANDLER_NO_DEFER;
    3.82 +    ASSERT(key_table[key].u.irq_handler == NULL);
    3.83 +    key_table[key].u.irq_handler = handler;
    3.84 +    key_table[key].flags         = KEYHANDLER_IRQ_CALLBACK;
    3.85 +    strncpy(key_table[key].desc, desc, STR_MAX);
    3.86 +    key_table[key].desc[STR_MAX-1] = '\0'; 
    3.87  }
    3.88  
    3.89  static void show_handlers(unsigned char key)
    3.90 @@ -60,16 +75,15 @@ static void show_handlers(unsigned char 
    3.91      int i; 
    3.92      printk("'%c' pressed -> showing installed handlers\n", key);
    3.93      for ( i = 0; i < KEY_MAX; i++ ) 
    3.94 -        if ( key_table[i].handler != NULL ) 
    3.95 +        if ( key_table[i].u.handler != NULL ) 
    3.96              printk(" key '%c' (ascii '%02x') => %s\n", 
    3.97                     (i<33 || i>126)?(' '):(i),i,
    3.98                     key_table[i].desc);
    3.99  }
   3.100  
   3.101  
   3.102 -static void dump_registers(unsigned char key)
   3.103 +static void dump_registers(unsigned char key, struct xen_regs *regs)
   3.104  {
   3.105 -    struct xen_regs *regs = (struct xen_regs *)get_execution_context();
   3.106      extern void show_registers(struct xen_regs *regs); 
   3.107      printk("'%c' pressed -> dumping registers\n", key); 
   3.108      show_registers(regs); 
   3.109 @@ -143,20 +157,30 @@ void initialize_keytable(void)
   3.110  {
   3.111      open_softirq(KEYPRESS_SOFTIRQ, keypress_softirq);
   3.112  
   3.113 -    add_key_handler('d', dump_registers, "dump registers"); 
   3.114 -    add_key_handler('h', show_handlers, "show this message");
   3.115 -    add_key_handler('l', print_sched_histo, "print sched latency histogram");
   3.116 -    add_key_handler('L', reset_sched_histo, "reset sched latency histogram");
   3.117 -    add_key_handler('q', do_task_queues, "dump task queues + guest state");
   3.118 -    add_key_handler('r', dump_runq,      "dump run queues");
   3.119 -    add_key_handler('R', halt_machine,   "reboot machine"); 
   3.120 +    register_irq_keyhandler(
   3.121 +        'd', dump_registers, "dump registers"); 
   3.122 +    register_keyhandler(
   3.123 +        'h', show_handlers, "show this message");
   3.124 +    register_keyhandler(
   3.125 +        'l', print_sched_histo, "print sched latency histogram");
   3.126 +    register_keyhandler(
   3.127 +        'L', reset_sched_histo, "reset sched latency histogram");
   3.128 +    register_keyhandler(
   3.129 +        'q', do_task_queues, "dump task queues + guest state");
   3.130 +    register_keyhandler(
   3.131 +        'r', dump_runq,      "dump run queues");
   3.132 +    register_keyhandler(
   3.133 +        'R', halt_machine,   "reboot machine"); 
   3.134  
   3.135  #ifndef NDEBUG
   3.136 -    add_key_handler('o', audit_domains_key,  "audit domains >0 EXPERIMENTAL"); 
   3.137 +    register_keyhandler(
   3.138 +        'o', audit_domains_key,  "audit domains >0 EXPERIMENTAL"); 
   3.139  #endif
   3.140  
   3.141  #ifdef PERF_COUNTERS
   3.142 -    add_key_handler('p', perfc_printall, "print performance counters"); 
   3.143 -    add_key_handler('P', perfc_reset,    "reset performance counters"); 
   3.144 +    register_keyhandler(
   3.145 +        'p', perfc_printall, "print performance counters"); 
   3.146 +    register_keyhandler(
   3.147 +        'P', perfc_reset,    "reset performance counters"); 
   3.148  #endif
   3.149  }
     4.1 --- a/xen/include/xen/keyhandler.h	Sat Nov 13 15:49:25 2004 +0000
     4.2 +++ b/xen/include/xen/keyhandler.h	Sat Nov 13 16:10:28 2004 +0000
     4.3 @@ -1,16 +1,35 @@
     4.4 -/* 
     4.5 -** We keep an array of 'handlers' for each key code between 0 and 255; 
     4.6 -** this is intended to allow very simple debugging routines (toggle 
     4.7 -** debug flag, dump registers, reboot, etc) to be hooked in in a slightly
     4.8 -** nicer fashion than just editing the serial/keyboard drivers. 
     4.9 -*/
    4.10 -struct xen_regs;
    4.11 +/******************************************************************************
    4.12 + * keyhandler.h
    4.13 + * 
    4.14 + * We keep an array of 'handlers' for each key code between 0 and 255; 
    4.15 + * this is intended to allow very simple debugging routines (toggle 
    4.16 + * debug flag, dump registers, reboot, etc) to be hooked in in a slightly
    4.17 + * nicer fashion than just editing the serial/keyboard drivers. 
    4.18 + */
    4.19 +
    4.20 +#ifndef __XEN_KEYHANDLER_H__
    4.21 +#define __XEN_KEYHANDLER_H__
    4.22 +
    4.23 +#include <asm/regs.h>
    4.24  
    4.25 -typedef void key_handler(unsigned char key);
    4.26 +/*
    4.27 + * Register a callback function for key @key. The callback occurs in
    4.28 + * softirq context with no locks held and interrupts enabled.
    4.29 + */
    4.30 +typedef void keyhandler_t(unsigned char key);
    4.31 +extern void register_keyhandler(
    4.32 +    unsigned char key, keyhandler_t *handler, char *desc); 
    4.33  
    4.34 -extern void add_key_handler(unsigned char key, 
    4.35 -			    key_handler *handler, char *desc); 
    4.36 -extern void add_key_handler_no_defer(unsigned char key, 
    4.37 -                                     key_handler *handler, char *desc); 
    4.38 +/*
    4.39 + * Register an IRQ callback function for key @key. The callback occurs
    4.40 + * synchronously in hard-IRQ context with interrupts disabled. The @regs
    4.41 + * callback parameter points at the interrupted register context.
    4.42 + */
    4.43 +typedef void irq_keyhandler_t(unsigned char key, struct xen_regs *regs);
    4.44 +extern void register_irq_keyhandler(
    4.45 +    unsigned char key, irq_keyhandler_t *handler, char *desc); 
    4.46  
    4.47 +/* Inject a keypress into the key-handling subsystem. */
    4.48  extern void handle_keypress(unsigned char key, struct xen_regs *regs);
    4.49 +
    4.50 +#endif /* __XEN_KEYHANDLER_H__ */