ia64/xen-unstable

changeset 150:12beced1bf62

bitkeeper revision 1.22.2.19 (3e4b7b8133Hv55IsHEhGL5J0n8II1A)

tweak (fix compiler warnings + error handling)
author smh22@boulderdash.cl.cam.ac.uk
date Thu Feb 13 11:03:29 2003 +0000 (2003-02-13)
parents 9641fabdd4fd
children 0834a70d2e19
files xen-2.4.16/drivers/char/xen_kbd.c xen-2.4.16/drivers/char/xen_serial.c
line diff
     1.1 --- a/xen-2.4.16/drivers/char/xen_kbd.c	Thu Feb 13 11:00:22 2003 +0000
     1.2 +++ b/xen-2.4.16/drivers/char/xen_kbd.c	Thu Feb 13 11:03:29 2003 +0000
     1.3 @@ -1,4 +1,5 @@
     1.4  #include <asm-i386/io.h>
     1.5 +#include <xeno/sched.h>    /* this has request_irq() proto for some reason */
     1.6  
     1.7  #define KEYBOARD_IRQ 1
     1.8  
     1.9 @@ -21,9 +22,11 @@
    1.10  #define kbd_read_status() inb(KBD_STATUS_REG)
    1.11  
    1.12  
    1.13 +
    1.14  static void
    1.15  dispatch_scancode (unsigned char scancode)
    1.16  {
    1.17 +
    1.18      /*
    1.19       * we could be a bit more clever here, but why?
    1.20       * just add a jump to your debug routine for the appropriate character.
    1.21 @@ -98,14 +101,9 @@ static void keyboard_interrupt(int irq, 
    1.22  }
    1.23  
    1.24  
    1.25 -extern int request_irq(unsigned int, 
    1.26 -		       void (*handler)(int, void *, struct pt_regs *),
    1.27 -		       unsigned long, const char *, void *);
    1.28 -
    1.29 -
    1.30  void initialize_keyboard()
    1.31  {
    1.32 -    if(!request_irq(KEYBOARD_IRQ, keyboard_interrupt, 0, "keyboard", NULL))
    1.33 +    if(request_irq(KEYBOARD_IRQ, keyboard_interrupt, 0, "keyboard", NULL))
    1.34  	printk("initialize_keyboard: failed to alloc IRQ %d\n", KEYBOARD_IRQ); 
    1.35  
    1.36      return; 
     2.1 --- a/xen-2.4.16/drivers/char/xen_serial.c	Thu Feb 13 11:00:22 2003 +0000
     2.2 +++ b/xen-2.4.16/drivers/char/xen_serial.c	Thu Feb 13 11:03:29 2003 +0000
     2.3 @@ -1,4 +1,6 @@
     2.4  #include <asm-i386/io.h>
     2.5 +#include <xeno/sched.h>    /* this has request_irq() proto for some reason */
     2.6 +
     2.7  
     2.8  /* Register offsets */
     2.9  #define NS16550_RBR	0x00	/* receive buffer	*/
    2.10 @@ -38,42 +40,86 @@
    2.11  #define NS16550_MCR_LOOP	0x10	/* Loop			*/
    2.12  
    2.13  #define SERIAL_BASE 0x3f8  /* XXX SMH: horrible hardwired COM1   */
    2.14 -#define SERAIL_ECHO 0      /* XXX SMH: set to 1 for 'echo' on rx */
    2.15 +
    2.16 +
    2.17 +
    2.18 +/* 
    2.19 +** We keep an array of 'handlers' for each key code between 0 and 255; 
    2.20 +** this is intended to allow very simple debugging routines (toggle 
    2.21 +** debug flag, dump registers, reboot, etc) to be hooked in in a slightly
    2.22 +** nicer fashion than just editing this file :-) 
    2.23 +*/
    2.24 +
    2.25 +#define KEY_MAX 256
    2.26 +typedef void key_handler(u_char key); 
    2.27 +
    2.28 +static key_handler *key_table[KEY_MAX]; 
    2.29 +    
    2.30 +void add_key_handler(u_char key, key_handler *handler) 
    2.31 +{
    2.32 +    if(key_table[key] != NULL) 
    2.33 +	printk("Warning: overwriting handler for key 0x%x\n", key); 
    2.34 +
    2.35 +    key_table[key] = handler; 
    2.36 +    return; 
    2.37 +}
    2.38 +
    2.39 +
    2.40 +
    2.41 +static int serial_echo = 0;   /* default is not to echo; change with 'e' */
    2.42 +
    2.43 +void toggle_echo(u_char key) 
    2.44 +{
    2.45 +    serial_echo = !serial_echo; 
    2.46 +    return; 
    2.47 +}
    2.48 +
    2.49 +
    2.50 +void halt_machine(u_char key) 
    2.51 +{
    2.52 +    /* This is 'debug me please' => just dump info and halt machine */
    2.53 +    printk("serial_rx_int: got EOT => halting machine.\n"); 
    2.54 +    printk("<not actually halting for now>\n"); 
    2.55 +    return; 
    2.56 +}
    2.57  
    2.58  
    2.59  
    2.60  static void serial_rx_int(int irq, void *dev_id, struct pt_regs *regs)
    2.61  {
    2.62 -    int c; 
    2.63 +    u_char c; 
    2.64  
    2.65      /* XXX SMH: should probably check this is an RX interrupt :-) */
    2.66  
    2.67      /* clear the interrupt by reading the character */
    2.68      c = inb(SERIAL_BASE + NS16550_RBR );
    2.69  
    2.70 -    if (c==0x04) {
    2.71 -	/* This is 'debug me please' => just dump info and halt machine */
    2.72 -	printk("serial_rx_int: got EOT => halting machine.\n"); 
    2.73 -	printk("<not actually halting for now>\n"); 
    2.74 -    }
    2.75 +    /* if there's a handler, call it: we trust it won't screw us too badly */
    2.76 +    if(key_table[c]) 
    2.77 +	(*key_table[c])(c); 
    2.78  
    2.79 -#ifdef SERIAL_ECHO
    2.80 -    printk("%c", c); 
    2.81 -#endif
    2.82 +    if(serial_echo) 
    2.83 +	printk("%c", c); 
    2.84  
    2.85      return; 
    2.86  }
    2.87  
    2.88  
    2.89 -extern int request_irq(unsigned int, 
    2.90 -		       void (*handler)(int, void *, struct pt_regs *),
    2.91 -		       unsigned long, const char *, void *);
    2.92 -
    2.93 -
    2.94  void initialize_serial() 
    2.95  {
    2.96 -    int fifo = 1;  /* must be a ns16550a at least, surely? */
    2.97 +    int i, fifo, rc; 
    2.98 +
    2.99 +    /* first initialize key handler table */
   2.100 +    for(i = 0; i < KEY_MAX; i++) 
   2.101 +	key_table[i] = (key_handler *)NULL; 
   2.102  
   2.103 +    /* setup own handlers */
   2.104 +    add_key_handler(0x01, toggle_echo);    /* <esc> to toggle echo */
   2.105 +    add_key_handler(0x04, halt_machine);   /* CTRL-D to 'halt' */
   2.106 +
   2.107 +    
   2.108 +    /* Should detect this, but must be a ns16550a at least, surely? */
   2.109 +    fifo = 1;  
   2.110      if(fifo) {
   2.111  	/* Clear FIFOs, enable, trigger at 1 byte */
   2.112  	outb(NS16550_FCR_TRG1 | NS16550_FCR_ENABLE |
   2.113 @@ -84,10 +130,11 @@ void initialize_serial()
   2.114      outb(NS16550_IER_ERDAI, SERIAL_BASE + NS16550_IER ); /* Setup interrupts */
   2.115  
   2.116      /* XXX SMH: this is a hack; probably is IRQ4 but grab both anyway */
   2.117 -    if(!request_irq(4, serial_rx_int, 0, "serial", 0x1234))
   2.118 -	printk("initialize_serial: failed to get IRQ4 :-(\n"); 
   2.119 -    if(!request_irq(3, serial_rx_int, 0, "serial", 0x5678))
   2.120 -	printk("initialize_serial: failed to get IRQ3 :-(\n"); 
   2.121 +    if((rc = request_irq(4, serial_rx_int, 0, "serial", (void *)0x1234)))
   2.122 +	printk("initialize_serial: failed to get IRQ4, rc=%d\n", rc); 
   2.123 +
   2.124 +    if((rc = request_irq(3, serial_rx_int, 0, "serial", (void *)0x1234)))
   2.125 +	printk("initialize_serial: failed to get IRQ3, rc=%d\n", rc); 
   2.126      
   2.127      return; 
   2.128  }