ia64/xen-unstable

changeset 158:99a121f0ecff

bitkeeper revision 1.29 (3e4ce07294MgHhL6FdnvhMOCv97X4w)

Merge labyrinth.cl.cam.ac.uk:/usr/groups/xeno/BK/xeno
into labyrinth.cl.cam.ac.uk:/local/scratch/kaf24/xeno-sched
author kaf24@labyrinth.cl.cam.ac.uk
date Fri Feb 14 12:26:26 2003 +0000 (2003-02-14)
parents 5b394412fded dad92510ffbb
children 5cb48c40f82d
files .rootkeys BitKeeper/etc/ignore xen-2.4.16/arch/i386/setup.c xen-2.4.16/common/domain.c xen-2.4.16/common/keyhandler.c xen-2.4.16/drivers/block/ll_rw_blk.c xen-2.4.16/drivers/block/xen_block.c xen-2.4.16/drivers/char/xen_kbd.c xen-2.4.16/drivers/char/xen_serial.c xen-2.4.16/drivers/ide/ide-xeno.c xen-2.4.16/include/hypervisor-ifs/block.h xen-2.4.16/include/hypervisor-ifs/hypervisor-if.h xen-2.4.16/include/xeno/keyhandler.h xenolinux-2.4.16-sparse/arch/xeno/drivers/block/block.c xenolinux-2.4.16-sparse/arch/xeno/drivers/block/xl_block.c xenolinux-2.4.16-sparse/drivers/block/ll_rw_blk.c xenolinux-2.4.16-sparse/include/linux/blk.h xenolinux-2.4.16-sparse/init/main.c
line diff
     1.1 --- a/.rootkeys	Thu Feb 13 18:08:51 2003 +0000
     1.2 +++ b/.rootkeys	Fri Feb 14 12:26:26 2003 +0000
     1.3 @@ -43,6 +43,7 @@ 3ddb79bdYO5D8Av12NHqPeSviav7cg xen-2.4.1
     1.4  3e32af9aRnYGl4GMOaDKp7JdfhOGhg xen-2.4.16/common/domain_page.c
     1.5  3ddb79bdeyutmaXEfpQvvxj7eQ0fCw xen-2.4.16/common/event.c
     1.6  3ddb79bd9drcFPVxd4w2GPOIjLlXpA xen-2.4.16/common/kernel.c
     1.7 +3e4cd9d8LAAghUY0hNIK72uc2ch_Nw xen-2.4.16/common/keyhandler.c
     1.8  3ddb79bduhSEZI8xa7IbGQCpap5y2A xen-2.4.16/common/lib.c
     1.9  3ddb79bdS39UXxUtZnaScie83-7VTQ xen-2.4.16/common/memory.c
    1.10  3ddb79bdN51qpRC-6bOH-v5hl_AK6A xen-2.4.16/common/network.c
    1.11 @@ -235,6 +236,7 @@ 3ddb79c2qAxCOABlkKtD8Txohe-qEw xen-2.4.1
    1.12  3ddb79c2b3qe-6Ann09FqZBF4IrJaQ xen-2.4.16/include/xeno/irq_cpustat.h
    1.13  3ddb79c11w_O7z7YZJnzuDSxaK5LlA xen-2.4.16/include/xeno/kdev_t.h
    1.14  3e4540ccPHqIIv2pvnQ1gV8LUnoHIg xen-2.4.16/include/xeno/kernel.h
    1.15 +3e4cd9d8elj_7EgAs9Of56RQ2Yq_4g xen-2.4.16/include/xeno/keyhandler.h
    1.16  3ddb79c1NfYlOrWNqgZkj9EwtFfJow xen-2.4.16/include/xeno/lib.h
    1.17  3ddb79c18Ajy7micDGQQfJ0zWgEHtA xen-2.4.16/include/xeno/list.h
    1.18  3ddb79c0_s2_wgV0cA6tztEaeyy1NA xen-2.4.16/include/xeno/major.h
    1.19 @@ -277,7 +279,6 @@ 3ddb79b7_rLvYZU3tOY6Wwuw_Sg3_w xenolinux
    1.20  3ddb79b8L4xnwrcvWk6nAbgKVbNkSA xenolinux-2.4.16-sparse/arch/xeno/config.in
    1.21  3ddb79b7v_Be34as7_mlzFlw65hOjQ xenolinux-2.4.16-sparse/arch/xeno/defconfig
    1.22  3ddb79b7KUvtx0knQJoRaBDZQeNidg xenolinux-2.4.16-sparse/arch/xeno/drivers/block/Makefile
    1.23 -3ddb79b6Rc0uAOGFthIFxq1KGWZ_Iw xenolinux-2.4.16-sparse/arch/xeno/drivers/block/block.c
    1.24  3e4a8cb7JECr--r1ipnrkd7NKdbUqQ xenolinux-2.4.16-sparse/arch/xeno/drivers/block/xl_block.c
    1.25  3e4a8cb7SLWsLTXQjv7ng6-3hL4pCA xenolinux-2.4.16-sparse/arch/xeno/drivers/block/xl_block_test.c
    1.26  3ddb79b7LLVJBGynxHSOh9A9l97sug xenolinux-2.4.16-sparse/arch/xeno/drivers/console/Makefile
     2.1 --- a/BitKeeper/etc/ignore	Thu Feb 13 18:08:51 2003 +0000
     2.2 +++ b/BitKeeper/etc/ignore	Fri Feb 14 12:26:26 2003 +0000
     2.3 @@ -19,3 +19,4 @@ xen-2.4.16/include/xeno/sched.h.orig
     2.4  xenolinux-2.4.16-sparse/arch/xeno/drivers/block/Makefile.orig
     2.5  xenolinux-2.4.16-sparse/arch/xeno/drivers/block/block.c.orig
     2.6  xenolinux-2.4.16-sparse/scripts/kconfig.tk
     2.7 +xen-2.4.16/foo
     3.1 --- a/xen-2.4.16/arch/i386/setup.c	Thu Feb 13 18:08:51 2003 +0000
     3.2 +++ b/xen-2.4.16/arch/i386/setup.c	Fri Feb 14 12:26:26 2003 +0000
     3.3 @@ -284,6 +284,7 @@ void __init start_of_day(void)
     3.4      extern int  setup_network_devices(void);
     3.5      extern void net_init(void);
     3.6      extern void initialize_block_io(void);
     3.7 +    extern void initialize_keytable(); 
     3.8      extern void initialize_serial(void);
     3.9      extern void initialize_keyboard(void);
    3.10  
    3.11 @@ -342,8 +343,9 @@ void __init start_of_day(void)
    3.12  #endif
    3.13      do_initcalls();
    3.14  
    3.15 +    initialize_keytable(); /* call back handling for key codes      */
    3.16      initialize_serial();   /* setup serial 'driver' (for debugging) */
    3.17 -    initialize_keyboard(); /* setup keyboard (also for debugging) */
    3.18 +    initialize_keyboard(); /* setup keyboard (also for debugging)   */
    3.19  
    3.20      if ( !setup_network_devices() )
    3.21          panic("Must have a network device!\n");
     4.1 --- a/xen-2.4.16/common/domain.c	Thu Feb 13 18:08:51 2003 +0000
     4.2 +++ b/xen-2.4.16/common/domain.c	Fri Feb 14 12:26:26 2003 +0000
     4.3 @@ -490,6 +490,8 @@ int setup_guestos(struct task_struct *p,
     4.4              frame_table;
     4.5          cur_address <<= PAGE_SHIFT;
     4.6      }
     4.7 +    page->type_count |= REFCNT_PIN_BIT;
     4.8 +    page->tot_count  |= REFCNT_PIN_BIT;
     4.9      page->flags = dom | PGT_l2_page_table;
    4.10      unmap_domain_mem(l1start);
    4.11  
    4.12 @@ -578,7 +580,11 @@ int setup_guestos(struct task_struct *p,
    4.13          unsigned char nfsroot[70];
    4.14          snprintf(nfsroot, 70, opt_nfsroot, dom); 
    4.15          snprintf(boot, 200,
    4.16 +#if 1
    4.17                  " root=/dev/nfs ip=%s:%s:%s:%s::eth0:off nfsroot=%s",
    4.18 +#else
    4.19 +                " ro root=/dev/xhda7 ip=%s:%s:%s:%s::eth0:off arfle=%s",
    4.20 +#endif
    4.21                   quad_to_str(opt_ipbase + dom, ipbase),
    4.22                   quad_to_str(opt_nfsserv, nfsserv),
    4.23                   quad_to_str(opt_gateway, gateway),
     5.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     5.2 +++ b/xen-2.4.16/common/keyhandler.c	Fri Feb 14 12:26:26 2003 +0000
     5.3 @@ -0,0 +1,125 @@
     5.4 +#include <xeno/keyhandler.h> 
     5.5 +#include <xeno/reboot.h>
     5.6 +
     5.7 +#define KEY_MAX 256
     5.8 +#define STR_MAX  64
     5.9 +
    5.10 +typedef struct _key_te { 
    5.11 +    key_handler *handler; 
    5.12 +    char         desc[STR_MAX]; 
    5.13 +} key_te_t; 
    5.14 +
    5.15 +static key_te_t key_table[KEY_MAX]; 
    5.16 +    
    5.17 +void add_key_handler(u_char key, key_handler *handler, char *desc) 
    5.18 +{
    5.19 +    int i; 
    5.20 +    char *str; 
    5.21 +
    5.22 +    if(key_table[key].handler != NULL) 
    5.23 +	printk("Warning: overwriting handler for key 0x%x\n", key); 
    5.24 +
    5.25 +    key_table[key].handler = handler; 
    5.26 +
    5.27 +    str = key_table[key].desc; 
    5.28 +    for(i = 0; i < STR_MAX; i++) {
    5.29 +	if(*desc) 
    5.30 +	    *str++ = *desc++; 
    5.31 +	else break; 
    5.32 +    }
    5.33 +    if (i == STR_MAX) 
    5.34 +	key_table[key].desc[STR_MAX-1] = '\0'; 
    5.35 +
    5.36 +    return; 
    5.37 +}
    5.38 +
    5.39 +key_handler *get_key_handler(u_char key)
    5.40 +{
    5.41 +    return key_table[key].handler; 
    5.42 +}
    5.43 +
    5.44 +
    5.45 +void show_handlers(u_char key, void *dev_id, struct pt_regs *regs) 
    5.46 +{
    5.47 +    int i; 
    5.48 +
    5.49 +    printk("'%c' pressed -> showing installed handlers\n", key); 
    5.50 +    for(i=0; i < KEY_MAX; i++) 
    5.51 +	if(key_table[i].handler) 
    5.52 +	    printk("ASCII '%02x' => %s\n", i, key_table[i].desc);
    5.53 +    return; 
    5.54 +}
    5.55 +
    5.56 +
    5.57 +void dump_registers(u_char key, void *dev_id, struct pt_regs *regs) 
    5.58 +{
    5.59 +    extern void show_registers(struct pt_regs *regs); 
    5.60 +
    5.61 +    printk("'%c' pressed -> dumping registers\n", key); 
    5.62 +    show_registers(regs); 
    5.63 +    return; 
    5.64 +}
    5.65 +
    5.66 +void halt_machine(u_char key, void *dev_id, struct pt_regs *regs) 
    5.67 +{
    5.68 +    printk("'%c' pressed -> rebooting machine\n", key); 
    5.69 +    machine_restart(NULL); 
    5.70 +    return; 
    5.71 +}
    5.72 +
    5.73 +
    5.74 +
    5.75 +/* XXX SMH: this is keir's fault */
    5.76 +static char *task_states[] = 
    5.77 +{ 
    5.78 +    "Running", 
    5.79 +    "Interruptible Sleep", 
    5.80 +    "Uninterruptible Sleep", 
    5.81 +    NULL, "Stopped", 
    5.82 +    NULL, NULL, NULL, "Dying", 
    5.83 +}; 
    5.84 +
    5.85 +void do_task_queues(u_char key, void *dev_id, struct pt_regs *regs) 
    5.86 +{
    5.87 +    u_long flags; 
    5.88 +    struct task_struct *p; 
    5.89 +    shared_info_t *s; 
    5.90 +
    5.91 +    printk("'%c' pressed -> dumping task queues\n", key); 
    5.92 +    read_lock_irqsave(&tasklist_lock, flags); 
    5.93 +    p = &idle0_task;
    5.94 +    do {
    5.95 +        printk("Xen: DOM %d, CPU %d [has=%c], state = %s, "
    5.96 +	       "hyp_events = %08x\n", 
    5.97 +	       p->domain, p->processor, p->has_cpu ? 'T':'F', 
    5.98 +	       task_states[p->state], p->hyp_events); 
    5.99 +	s = p->shared_info; 
   5.100 +	if(!is_idle_task(p)) {
   5.101 +	    printk("Guest: events = %08lx, event_enable = %08lx\n", 
   5.102 +		   s->events, s->events_enable); 
   5.103 +	    printk("Notifying guest...\n"); 
   5.104 +	    set_bit(_EVENT_DEBUG, &s->events); 
   5.105 +	}
   5.106 +    }
   5.107 +
   5.108 +    while ( (p = p->next_task) != &idle0_task );
   5.109 +    read_unlock_irqrestore(&tasklist_lock, flags); 
   5.110 +}
   5.111 +
   5.112 +
   5.113 +void initialize_keytable() 
   5.114 +{
   5.115 +    int i; 
   5.116 +
   5.117 +    /* first initialize key handler table */
   5.118 +    for(i = 0; i < KEY_MAX; i++) 
   5.119 +	key_table[i].handler = (key_handler *)NULL; 
   5.120 +	
   5.121 +    /* setup own handlers */
   5.122 +    add_key_handler('d', dump_registers, "dump registers"); 
   5.123 +    add_key_handler('h', show_handlers, "show this message");
   5.124 +    add_key_handler('q', do_task_queues, "dump task queues + guest state");
   5.125 +    add_key_handler('r', halt_machine, "reboot machine ungracefully"); 
   5.126 +    
   5.127 +    return; 
   5.128 +}
     6.1 --- a/xen-2.4.16/drivers/block/ll_rw_blk.c	Thu Feb 13 18:08:51 2003 +0000
     6.2 +++ b/xen-2.4.16/drivers/block/ll_rw_blk.c	Fri Feb 14 12:26:26 2003 +0000
     6.3 @@ -31,6 +31,9 @@
     6.4  #include <xeno/slab.h>
     6.5  #include <xeno/module.h>
     6.6  
     6.7 +/* XXX SMH: temporarily we just dive at xen_block completion handler */
     6.8 +extern void end_block_io_op(struct buffer_head *bh); 
     6.9 +
    6.10  static void end_buffer_dummy(struct buffer_head *bh, int uptodate)
    6.11  {
    6.12    /* do nothing */
    6.13 @@ -1030,6 +1033,8 @@ out:
    6.14  	return 0;
    6.15  end_io:
    6.16  	bh->b_end_io(bh, test_bit(BH_Uptodate, &bh->b_state));
    6.17 +	/* XXX SMH: do we need this every time? */
    6.18 +	end_block_io_op(bh);
    6.19  	return 0;
    6.20  }
    6.21  
    6.22 @@ -1101,6 +1106,8 @@ void generic_make_request (int rw, struc
    6.23  
    6.24  			/* Yecch again */
    6.25  			bh->b_end_io(bh, 0);
    6.26 +			/* XXX SMH */ 
    6.27 +			end_block_io_op(bh);
    6.28  			return;
    6.29  		}
    6.30  	}
    6.31 @@ -1142,10 +1149,6 @@ void generic_make_request (int rw, struc
    6.32   */
    6.33  void submit_bh(int rw, struct buffer_head * bh)
    6.34  {
    6.35 -	int count = bh->b_size >> 9;
    6.36 -
    6.37 -	/* 	printk(KERN_ALERT "submit_bh\n"); */
    6.38 -
    6.39  	if (!test_bit(BH_Lock, &bh->b_state))
    6.40  		BUG();
    6.41  
    6.42 @@ -1160,17 +1163,6 @@ void submit_bh(int rw, struct buffer_hea
    6.43  	/*	bh->b_rsector = bh->b_blocknr * count; */
    6.44  
    6.45  	generic_make_request(rw, bh);
    6.46 -
    6.47 -#if 0
    6.48 -	switch (rw) {
    6.49 -		case WRITE:
    6.50 -			kstat.pgpgout += count;
    6.51 -			break;
    6.52 -		default:
    6.53 -			kstat.pgpgin += count;
    6.54 -			break;
    6.55 -	}
    6.56 -#endif
    6.57  }
    6.58  
    6.59  /**
    6.60 @@ -1267,6 +1259,8 @@ void ll_rw_block(int rw, int nr, struct 
    6.61  			BUG();
    6.62  	end_io:
    6.63  			bh->b_end_io(bh, test_bit(BH_Uptodate, &bh->b_state));
    6.64 +			/* XXX SMH */
    6.65 +			end_block_io_op(bh);
    6.66  			continue;
    6.67  		}
    6.68  
    6.69 @@ -1275,6 +1269,7 @@ void ll_rw_block(int rw, int nr, struct 
    6.70  	return;
    6.71  
    6.72  sorry:
    6.73 +	printk("~~~");
    6.74  	/* Make sure we don't get infinite dirty retries.. */
    6.75  	for (i = 0; i < nr; i++)
    6.76  		mark_buffer_clean(bhs[i]);
     7.1 --- a/xen-2.4.16/drivers/block/xen_block.c	Thu Feb 13 18:08:51 2003 +0000
     7.2 +++ b/xen-2.4.16/drivers/block/xen_block.c	Fri Feb 14 12:26:26 2003 +0000
     7.3 @@ -15,6 +15,8 @@
     7.4  #include <asm-i386/io.h>
     7.5  #include <asm/spinlock.h>
     7.6  
     7.7 +#include <xeno/keyhandler.h>
     7.8 +
     7.9  #define XEN_BLK_DEBUG 0
    7.10  #define XEN_BLK_DEBUG_LEVEL KERN_ALERT
    7.11  
    7.12 @@ -28,10 +30,12 @@ typedef struct blk_request
    7.13    struct task_struct *domain;                           /* requesting domain */
    7.14  } blk_request_t;
    7.15  
    7.16 -static int pending_work;                  /* which domains have work for us? */
    7.17 +static int pending_work;              /* which domains have work for us? */
    7.18 +
    7.19  blk_request_t blk_request_list[XEN_BLK_REQUEST_LIST_SIZE];
    7.20 -struct list_head free_queue;                              /* unused requests */
    7.21 -struct list_head pending_queue;                      /* waiting for hardware */
    7.22 +
    7.23 +struct list_head free_queue;          /* unused requests */
    7.24 +struct list_head pending_queue;       /* waiting for hardware */
    7.25  struct list_head io_done_queue;       /* request completed. send to guest os */
    7.26  spinlock_t free_queue_lock;
    7.27  spinlock_t pending_queue_lock;
    7.28 @@ -49,61 +53,46 @@ int dispatch_debug_block_io (int index);
    7.29   * end_block_io_op
    7.30   *
    7.31   * IO has completed.  Need to notify the guest operating system.
    7.32 - * Called from hardware interrupt.
    7.33 + * Called from ll_rw_block -- currently /DIRECTLY/ -- XXX FIXME 
    7.34 + * (e.g. hook into proper end processing of ll_rw) 
    7.35   */
    7.36  
    7.37  void end_block_io_op(struct buffer_head * bh)
    7.38  {
    7.39 -  unsigned long cpu_mask;
    7.40 -  /* struct list_head *list;*/
    7.41 -  blk_request_t *blk_request = NULL;
    7.42 -  unsigned long flags;                                           /* irq save */
    7.43 -
    7.44 -#if 0
    7.45 -  printk("{E}"); 
    7.46 -#endif
    7.47 -  if (XEN_BLK_DEBUG)  printk(XEN_BLK_DEBUG_LEVEL
    7.48 -			     "XEN end_block_io_op,  bh: %lx\n",
    7.49 -			     (unsigned long)bh);
    7.50 -
    7.51 -  {
    7.52 -    char temp[100];
    7.53 -    sprintf(temp, "endio  bh: 0x%p, blkno: 0x%lx",
    7.54 -	    bh, bh->b_blocknr);
    7.55 -    printx(temp);
    7.56 -  }
    7.57 -
    7.58 -  spin_lock_irqsave(&pending_queue_lock, flags);
    7.59 -  /*
    7.60 -  list_for_each (list, &pending_queue)
    7.61 -  {
    7.62 -    blk_request = list_entry(list, blk_request_t, queue);
    7.63 -    if (blk_request->bh == bh)      
    7.64 -    {
    7.65 -      break;
    7.66 +    unsigned long cpu_mask;
    7.67 +    /* struct list_head *list;*/
    7.68 +    blk_request_t *blk_request = NULL;
    7.69 +    unsigned long flags; /* irq save */
    7.70 +    
    7.71 +    if (XEN_BLK_DEBUG)  
    7.72 +	printk(XEN_BLK_DEBUG_LEVEL "XEN end_block_io_op,  bh: %lx\n",
    7.73 +	       (unsigned long)bh);
    7.74 +    
    7.75 +    spin_lock_irqsave(&pending_queue_lock, flags);
    7.76 +    blk_request = (blk_request_t *)bh->b_xen_request;
    7.77 +    
    7.78 +    if (blk_request == NULL) {
    7.79 +	printk (KERN_ALERT
    7.80 +		"   block io interrupt received for unknown buffer [0x%lx]\n",
    7.81 +		(unsigned long) bh);
    7.82 +	spin_unlock_irqrestore(&pending_queue_lock, flags);
    7.83 +	BUG();
    7.84 +	return;
    7.85      }
    7.86 -  }
    7.87 -  */
    7.88 -  blk_request = (blk_request_t *)bh->b_xen_request;
    7.89 -  if (blk_request == NULL)
    7.90 -  {
    7.91 -    printk (KERN_ALERT
    7.92 -	    "   block io interrupt received for unknown buffer [0x%lx]\n",
    7.93 -	    (unsigned long) bh);
    7.94 +    
    7.95 +    list_del(&blk_request->queue);
    7.96      spin_unlock_irqrestore(&pending_queue_lock, flags);
    7.97 +    
    7.98 +    spin_lock_irqsave(&io_done_queue_lock, flags);
    7.99 +    list_add_tail(&blk_request->queue, &io_done_queue);
   7.100 +    
   7.101 +    /* enqueue work for 'flush_blk_queue' handler */
   7.102 +    cpu_mask = mark_hyp_event(blk_request->domain, _HYP_EVENT_BLK_RX);
   7.103 +    spin_unlock_irqrestore(&io_done_queue_lock, flags);
   7.104 +    
   7.105 +    /* now kick the hypervisor */
   7.106 +    hyp_event_notify(cpu_mask); 
   7.107      return;
   7.108 -  }
   7.109 -  list_del(&blk_request->queue);
   7.110 -  spin_unlock_irqrestore(&pending_queue_lock, flags);
   7.111 -
   7.112 -  spin_lock_irqsave(&io_done_queue_lock, flags);
   7.113 -  list_add_tail(&blk_request->queue, &io_done_queue);
   7.114 -  spin_unlock_irqrestore(&io_done_queue_lock, flags);
   7.115 -
   7.116 -  /* enqueue work */
   7.117 -  cpu_mask = mark_hyp_event(blk_request->domain, _HYP_EVENT_BLK_RX);
   7.118 -
   7.119 -  return;
   7.120  }
   7.121  
   7.122  /*
   7.123 @@ -115,125 +104,81 @@ void end_block_io_op(struct buffer_head 
   7.124  
   7.125  void flush_blk_queue(void)
   7.126  {
   7.127 -  blk_request_t *blk_request;
   7.128 -  int position = 0;
   7.129 -  blk_ring_t *blk_ring;
   7.130 -  unsigned long flags;
   7.131 -  int loop;
   7.132 +    blk_request_t *blk_request;
   7.133 +    int position = 0;
   7.134 +    blk_ring_t *blk_ring;
   7.135 +    unsigned long flags;
   7.136 +    int loop;
   7.137 +    
   7.138 +    spin_lock_irqsave(&io_done_queue_lock, flags);
   7.139 +    clear_bit(_HYP_EVENT_BLK_RX, &current->hyp_events);
   7.140 +    
   7.141 +    while (!list_empty(&io_done_queue)) {
   7.142 +
   7.143 +	blk_request = list_entry(io_done_queue.next, blk_request_t, queue);
   7.144 +	list_del (&blk_request->queue);
   7.145 +	spin_unlock_irqrestore(&io_done_queue_lock, flags);
   7.146 +	
   7.147 +	/* place on ring for guest os */ 
   7.148 +	blk_ring = blk_request->domain->blk_ring_base;
   7.149 +	position = blk_ring->brx_prod;
   7.150  
   7.151 -#if 0
   7.152 -  printk("{F}"); 
   7.153 -#endif
   7.154 -  /*
   7.155 -  if (XEN_BLK_DEBUG)  printk(XEN_BLK_DEBUG_LEVEL
   7.156 -			     "XEN flush_blk_queue\n");
   7.157 -  */
   7.158 +	if (XEN_BLK_DEBUG)  
   7.159 +	    printk(XEN_BLK_DEBUG_LEVEL "XEN flush_blk_queue [%d]\n", position);
   7.160 +
   7.161 +	memcpy(&blk_ring->brx_ring[position], &blk_request->request,
   7.162 +	       sizeof(blk_ring_entry_t));
   7.163 +	blk_ring->brx_prod = BLK_RX_RING_INC(blk_ring->brx_prod);
   7.164  
   7.165 -  clear_bit(_HYP_EVENT_BLK_RX, &current->hyp_events);
   7.166 +	/* notify appropriate guest os */
   7.167 +	set_bit(_EVENT_BLK_RX, &blk_request->domain->shared_info->events);
   7.168 +	
   7.169 +	/* free the buffer header allocated in do_block_io_op */
   7.170 +	if (blk_request->bh)
   7.171 +	    kfree(blk_request->bh); 
   7.172  
   7.173 -  /* NEED LOCK? */
   7.174 -  spin_lock_irqsave(&io_done_queue_lock, flags);
   7.175 -  while (!list_empty(&io_done_queue))
   7.176 -  {
   7.177 -    blk_request = list_entry(io_done_queue.next, blk_request_t, queue);
   7.178 -    list_del (&blk_request->queue);
   7.179 +	spin_lock_irqsave(&free_queue_lock, flags);
   7.180 +	list_add_tail(&blk_request->queue, &free_queue);
   7.181 +	spin_unlock_irqrestore(&free_queue_lock, flags);
   7.182 +
   7.183 +	spin_lock_irqsave(&io_done_queue_lock, flags);
   7.184 +    }
   7.185      spin_unlock_irqrestore(&io_done_queue_lock, flags);
   7.186  
   7.187 -    /* place on ring for guest os */ 
   7.188 -    blk_ring = blk_request->domain->blk_ring_base;
   7.189 -    position = blk_ring->rx_prod;
   7.190 -
   7.191 -    if (XEN_BLK_DEBUG)  printk(XEN_BLK_DEBUG_LEVEL
   7.192 -			       "XEN flush_blk_queue [%d]\n", position);
   7.193 -
   7.194 -    memcpy(&blk_ring->rx_ring[position], &blk_request->request,
   7.195 -	   sizeof(blk_ring_entry_t));
   7.196 -    blk_ring->rx_prod = BLK_RX_RING_INC(blk_ring->rx_prod);
   7.197 -
   7.198 -    /* notify appropriate guest os */
   7.199 -    set_bit(_EVENT_BLK_RX,
   7.200 -	    &blk_request->domain->shared_info->events);
   7.201  
   7.202 -    if (0)
   7.203 -    {
   7.204 -      int temp;
   7.205 -      struct buffer_head *bh = blk_request->bh;
   7.206 -      char * vbuffer = bh->b_data;
   7.207 -
   7.208 -      printk (KERN_ALERT "XEN return block 0x%lx\n", bh->b_blocknr);
   7.209 +    /* XXX SMH: below is ugly and dangerous -- fix */
   7.210 +    /*
   7.211 +     * now check if there is any pending work from any domain
   7.212 +     * that we were previously unable to process.
   7.213 +     *
   7.214 +     * NOTE: the current algorithm will check _every_ domain
   7.215 +     * and wake up _every_ domain that has pending work.
   7.216 +     * In the future, we should stop waking up domains once
   7.217 +     * there isn't any space for their requests any more
   7.218 +     * ALSO, we need to maintain a counter of the last domain
   7.219 +     * that we woke up for fairness... we shouldn't restart
   7.220 +     * at domain 0 every time (although we might want to special
   7.221 +     * case domain 0);
   7.222 +     */
   7.223 +    for (loop = 0; loop < XEN_BLOCK_MAX_DOMAINS; loop++) {
   7.224  
   7.225 -      for (temp = 0; temp < bh->b_size; temp++)
   7.226 -      {
   7.227 -	if (temp % 16 == 0)       printk ("[%04x]  ", temp);
   7.228 -	else if (temp % 4 == 0)   printk (" ");
   7.229 -	                          printk ("%02x",
   7.230 -					  vbuffer[temp] & 255);
   7.231 -	if ((temp + 1) % 16 == 0) printk ("\n");
   7.232 -      }
   7.233 -      printk ("\n\n");
   7.234 +	int domain = pending_work & (1 << loop);
   7.235 +
   7.236 +	if (domain) {
   7.237 +
   7.238 +	    struct task_struct *mytask = current;
   7.239 +
   7.240 +	    while (mytask->domain != loop)
   7.241 +		mytask = mytask->next_task;
   7.242 +
   7.243 +	    pending_work = pending_work & !(1 << loop);
   7.244 +	    do_block_io_op_domain(mytask);
   7.245 +	}
   7.246      }
   7.247  
   7.248 -    /* free the buffer header allocated in do_block_io_op */
   7.249 -    if (blk_request->bh)
   7.250 -    {
   7.251 -      kfree(blk_request->bh);                     /* alloc in do_block_io_op */
   7.252 -    }
   7.253 -
   7.254 -    spin_lock_irqsave(&free_queue_lock, flags);
   7.255 -    list_add_tail(&blk_request->queue, &free_queue);
   7.256 -    spin_unlock_irqrestore(&free_queue_lock, flags);
   7.257 -
   7.258 -    spin_lock_irqsave(&io_done_queue_lock, flags);
   7.259 -  }
   7.260 -  spin_unlock_irqrestore(&io_done_queue_lock, flags);
   7.261 -
   7.262 -  /*
   7.263 -   * now check if there is any pending work from any domain
   7.264 -   * that we were previously unable to process.
   7.265 -   *
   7.266 -   * NOTE: the current algorithm will check _every_ domain
   7.267 -   * and wake up _every_ domain that has pending work.
   7.268 -   * In the future, we should stop waking up domains once
   7.269 -   * there isn't any space for their requests any more
   7.270 -   * ALSO, we need to maintain a counter of the last domain
   7.271 -   * that we woke up for fairness... we shouldn't restart
   7.272 -   * at domain 0 every time (although we might want to special
   7.273 -   * case domain 0);
   7.274 -   */
   7.275 -  for (loop = 0; loop < XEN_BLOCK_MAX_DOMAINS; loop++)
   7.276 -  {
   7.277 -    int domain = pending_work & (1 << loop);
   7.278 +    return; 
   7.279 +}
   7.280  
   7.281 -    if (domain)
   7.282 -    {
   7.283 -      struct task_struct *mytask = current;
   7.284 -
   7.285 -      /*
   7.286 -      printk (KERN_ALERT 
   7.287 -	      "flush_blk_queue  pending_work: %x  domain: %d  loop: %d\n",
   7.288 -	      pending_work, domain, loop);
   7.289 -      */
   7.290 -      /* IS THERE A BETTER WAY OF FINDING THE TASK STRUCT FOR A 
   7.291 -       * PARTICULAR DOMAIN? 
   7.292 -       *
   7.293 -       * WHAT IF THE TASK GOES AWAY BEFORE WE HAVE A CHANCE TO
   7.294 -       * FINISH PROCESSING ALL OF ITS REQUESTS?
   7.295 -       */
   7.296 -      while (mytask->domain != loop)
   7.297 -      {
   7.298 -	mytask = mytask->next_task;
   7.299 -      }
   7.300 -      do_block_io_op_domain(mytask);
   7.301 -
   7.302 -      pending_work = pending_work & !(1 << loop);
   7.303 -      /*
   7.304 -      printk (KERN_ALERT 
   7.305 -	      "                 pending_work: %x  domain: %d  loop: %d\n",
   7.306 -	      pending_work, domain, loop);
   7.307 -      */
   7.308 -    }
   7.309 -  }
   7.310 -}
   7.311  
   7.312  /*
   7.313   * do_block_io_op
   7.314 @@ -244,186 +189,132 @@ void flush_blk_queue(void)
   7.315  
   7.316  long do_block_io_op (void)
   7.317  {
   7.318 -  return do_block_io_op_domain(current);
   7.319 +    return do_block_io_op_domain(current);
   7.320  }
   7.321  
   7.322 +
   7.323  /*
   7.324   * do_block_io_op
   7.325   *
   7.326   * handle the requests for a particular domain
   7.327   */
   7.328 -
   7.329  long do_block_io_op_domain (struct task_struct* task)
   7.330  {
   7.331 -  blk_ring_t *blk_ring = task->blk_ring_base;
   7.332 -  int loop;
   7.333 +    blk_ring_t *blk_ring = task->blk_ring_base;
   7.334 +    int loop, status;
   7.335 +
   7.336 +    if (XEN_BLK_DEBUG)  
   7.337 +	printk(XEN_BLK_DEBUG_LEVEL "XEN do_block_io_op %d %d\n",
   7.338 +	       blk_ring->btx_cons, blk_ring->btx_prod);
   7.339  
   7.340 -#if 0
   7.341 -  printk("{%d}", current->domain); 
   7.342 -#endif
   7.343 -  if (XEN_BLK_DEBUG)  printk(XEN_BLK_DEBUG_LEVEL
   7.344 -			     "XEN do_block_io_op %d %d\n",
   7.345 -			     blk_ring->tx_cons, blk_ring->tx_prod);
   7.346 +    for (loop = blk_ring->btx_cons; 
   7.347 +	 loop != blk_ring->btx_prod; 
   7.348 +	 loop = BLK_TX_RING_INC(loop)) {
   7.349 +
   7.350 +	status = 1;
   7.351  
   7.352 -  for (loop = blk_ring->tx_cons;
   7.353 -       loop != blk_ring->tx_prod;
   7.354 -       loop = BLK_TX_RING_INC(loop))
   7.355 -  {
   7.356 -    int status = 1;
   7.357 +	switch (blk_ring->btx_ring[loop].operation) {
   7.358 +
   7.359 +	case XEN_BLOCK_READ:
   7.360 +	case XEN_BLOCK_WRITE:
   7.361 +	    status = dispatch_rw_block_io(loop);
   7.362 +	    break;
   7.363  
   7.364 -    switch (blk_ring->tx_ring[loop].operation)
   7.365 -    {
   7.366 -      case XEN_BLOCK_READ :
   7.367 -      case XEN_BLOCK_WRITE :
   7.368 -      {
   7.369 -	status = dispatch_rw_block_io(loop);
   7.370 -	break;
   7.371 -      }
   7.372 -      case XEN_BLOCK_PROBE :
   7.373 -      {
   7.374 -	status = dispatch_probe_block_io(loop);
   7.375 -	break;
   7.376 -      }
   7.377 -      case XEN_BLOCK_DEBUG :
   7.378 -      {
   7.379 -	status = dispatch_debug_block_io(loop);
   7.380 -	break;
   7.381 -      }
   7.382 -      default :
   7.383 -      {
   7.384 -	printk (KERN_ALERT "error: unknown block io operation [%d]\n",
   7.385 -		blk_ring->tx_ring[loop].operation);
   7.386 -	BUG();
   7.387 -      }
   7.388 +	case XEN_BLOCK_PROBE:
   7.389 +	    status = dispatch_probe_block_io(loop);
   7.390 +	    break;
   7.391 +
   7.392 +	case XEN_BLOCK_DEBUG:
   7.393 +	    status = dispatch_debug_block_io(loop);
   7.394 +	    break;
   7.395 +
   7.396 +	default:
   7.397 +	    printk (KERN_ALERT "error: unknown block io operation [%d]\n",
   7.398 +		    blk_ring->btx_ring[loop].operation);
   7.399 +	    BUG();
   7.400 +	}
   7.401 +
   7.402 +
   7.403 +	if (status) {
   7.404 +	    /* 
   7.405 +	    ** Unable to successfully issue / complete command, maybe because
   7.406 +	    ** another resource (e.g. disk request buffers) is unavailable.
   7.407 +	    ** stop removing items from the communications ring and try later 
   7.408 +	    */
   7.409 +	    pending_work = pending_work | (1 << task->domain);
   7.410 +	    break;
   7.411 +	}
   7.412      }
   7.413  
   7.414 -    if (status)
   7.415 -    {
   7.416 -      /* unable to successfully issue / complete command, maybe because
   7.417 -       * another resource (e.g. disk request buffers) is unavailable.
   7.418 -       * stop removing items from the communications ring and try 
   7.419 -       * again later 
   7.420 -       */
   7.421 +    blk_ring->btx_cons = loop;
   7.422 +    return 0L;
   7.423 +}
   7.424  
   7.425 -      /*
   7.426 -      printk ("do_block_io_op_domain  domain:%d, pending_work: %x\n",
   7.427 -	      task->domain, pending_work);
   7.428 -      */
   7.429 -      pending_work = pending_work | (1 << task->domain);
   7.430 -      /*
   7.431 -      printk ("do_block_io_op_domain  domain:%d, pending_work: %x\n",
   7.432 -	      task->domain, pending_work);
   7.433 -      */
   7.434 -      break;
   7.435 -    }
   7.436 -  }
   7.437 -
   7.438 -  blk_ring->tx_cons = loop;
   7.439 -
   7.440 -  return 0L;
   7.441 -}
   7.442  
   7.443  int dispatch_debug_block_io (int index)
   7.444  {
   7.445 -  struct task_struct *task;
   7.446 -  blk_ring_t *blk_ring = current->blk_ring_base;
   7.447 -  char * buffer;
   7.448 -  char output[1000];
   7.449 -
   7.450 -  int foobar = (unsigned long)blk_ring->tx_ring[index].block_number;
   7.451 -
   7.452 -  printk (KERN_ALERT "dispatch_debug_block_io %d\n", foobar);
   7.453 -
   7.454 -  buffer = phys_to_virt(blk_ring->tx_ring[index].buffer);
   7.455 -  strcpy (buffer, "DEBUG\n");
   7.456 -
   7.457 -  task = current;
   7.458 -  sprintf (buffer, "current %d\n", current->domain);
   7.459 -  sprintf (buffer, "%s  tx: prod: %d, cons: %d, size: %d\n", buffer,
   7.460 -	   blk_ring->tx_prod, blk_ring->tx_cons, blk_ring->tx_ring_size);
   7.461 -  sprintf (buffer, "%s  rx: prod: %d, cons: %d, size: %d\n", buffer,
   7.462 -	   blk_ring->rx_prod, blk_ring->rx_cons, blk_ring->rx_ring_size);
   7.463 +    printk (KERN_ALERT "dispatch_debug_block_io: UNIMPL\n"); 
   7.464 +    return 1; 
   7.465 +}
   7.466  
   7.467 -  task = task->next_task;
   7.468 -  while (task != current)
   7.469 -  {
   7.470 -    blk_ring = task->blk_ring_base;
   7.471 -    sprintf (buffer, "%stask %d\n", buffer, task->domain);
   7.472 -    if (blk_ring != NULL)
   7.473 -    {
   7.474 -      sprintf (buffer, "%s  tx: prod: %d, cons: %d, size: %d\n",
   7.475 -	       buffer, blk_ring->tx_prod, blk_ring->tx_cons, 
   7.476 -	       blk_ring->tx_ring_size);
   7.477 -      sprintf (buffer, "%s  rx: prod: %d, cons: %d, size: %d\n",
   7.478 -	       buffer, blk_ring->rx_prod, blk_ring->rx_cons, 
   7.479 -	       blk_ring->rx_ring_size);
   7.480 -    }
   7.481 -    task = task->next_task;
   7.482 -  }
   7.483 -  dumpx(output, foobar);
   7.484 -  sprintf (buffer, "%s%s\n", buffer, output);
   7.485 -
   7.486 -  return 0;
   7.487 -}
   7.488 +extern void ide_probe_devices(xen_disk_info_t *xdi);
   7.489  
   7.490  int dispatch_probe_block_io (int index)
   7.491  {
   7.492 -  blk_ring_t *blk_ring = current->blk_ring_base;
   7.493 -  xen_disk_info_t *xdi;
   7.494 -
   7.495 -  xdi = phys_to_virt(blk_ring->tx_ring[index].buffer);
   7.496 +    blk_ring_t *blk_ring = current->blk_ring_base;
   7.497 +    xen_disk_info_t *xdi;
   7.498 +    
   7.499 +    xdi = phys_to_virt((unsigned long)blk_ring->btx_ring[index].buffer);
   7.500 +    
   7.501 +    ide_probe_devices(xdi);
   7.502 +    
   7.503 +    memcpy(&blk_ring->brx_ring[blk_ring->brx_prod], 
   7.504 +	   &blk_ring->btx_ring[index], 
   7.505 +	   sizeof(blk_ring_entry_t));
   7.506 +    blk_ring->brx_prod = BLK_RX_RING_INC(blk_ring->brx_prod);
   7.507 +    
   7.508 +    return 0;
   7.509 +}
   7.510  
   7.511 -  ide_probe_devices(xdi);
   7.512 -
   7.513 -  return 0;
   7.514 -}
   7.515 +extern void ll_rw_block(int rw, int nr, struct buffer_head * bhs[]); 
   7.516  
   7.517  int dispatch_rw_block_io (int index)
   7.518  {
   7.519 -  blk_ring_t *blk_ring = current->blk_ring_base;
   7.520 -  struct buffer_head *bh;
   7.521 -  struct request_queue *rq;
   7.522 -  int operation;
   7.523 -  blk_request_t *blk_request;
   7.524 -  unsigned long flags;
   7.525 -
   7.526 +    blk_ring_t *blk_ring = current->blk_ring_base;
   7.527 +    struct buffer_head *bh;
   7.528 +    struct request_queue *rq;
   7.529 +    int operation;
   7.530 +    blk_request_t *blk_request;
   7.531 +    unsigned long flags;
   7.532 +    
   7.533      /*
   7.534       * check to make sure that the block request seems at least
   7.535       * a bit legitimate
   7.536       */
   7.537 -    if ((blk_ring->tx_ring[index].block_size & (0x200 - 1)) != 0)
   7.538 -    {
   7.539 -      printk(KERN_ALERT
   7.540 -	     "    error: dodgy block size: %d\n", 
   7.541 -	     blk_ring->tx_ring[index].block_size);
   7.542 -      BUG();
   7.543 +    if ((blk_ring->btx_ring[index].block_size & (0x200 - 1)) != 0) {
   7.544 +	printk(KERN_ALERT "    error: dodgy block size: %d\n", 
   7.545 +	       blk_ring->btx_ring[index].block_size);
   7.546 +	BUG();
   7.547      }
   7.548 +    
   7.549  
   7.550 -    if (XEN_BLK_DEBUG) 
   7.551 -    {
   7.552 -    printk(XEN_BLK_DEBUG_LEVEL
   7.553 -	   "    tx_cons: %d  tx_prod %d  index: %d     op: %s, pri: %s\n",
   7.554 -	   blk_ring->tx_cons, blk_ring->tx_prod, index,
   7.555 -	   (blk_ring->tx_ring[index].operation == XEN_BLOCK_READ ? "read" : "write"),
   7.556 -	   (blk_ring->tx_ring[index].priority == XEN_BLOCK_SYNC ? "sync" : "async"));
   7.557 -    }
   7.558 -
   7.559 -    {
   7.560 -      char temp[100];
   7.561 -      sprintf(temp, "issue  buf: 0x%p, bh: 0x%p, blkno: 0x%lx",
   7.562 -	      blk_ring->tx_ring[index].buffer, bh,
   7.563 -	      (unsigned long)blk_ring->tx_ring[index].block_number);
   7.564 -      printx(temp);
   7.565 +    if (XEN_BLK_DEBUG) {
   7.566 +	printk(XEN_BLK_DEBUG_LEVEL "    btx_cons: %d  btx_prod %d  index: %d "
   7.567 +	       "op: %s, pri: %s\n", blk_ring->btx_cons, blk_ring->btx_prod, 
   7.568 +	       index, 
   7.569 +	       (blk_ring->btx_ring[index].operation == XEN_BLOCK_READ ? 
   7.570 +		"read" : "write"), 
   7.571 +	       (blk_ring->btx_ring[index].priority == XEN_BLOCK_SYNC ? 
   7.572 +		"sync" : "async"));
   7.573      }
   7.574  
   7.575      /* find an empty request slot */
   7.576      spin_lock_irqsave(&free_queue_lock, flags);
   7.577 -    if (list_empty(&free_queue))
   7.578 -    {
   7.579 -      /*      printk (KERN_ALERT "dispatch_rw_block_io EMPTY FREE LIST!! %d\n", index); */
   7.580 -      spin_unlock_irqrestore(&free_queue_lock, flags);
   7.581 -      return 1;
   7.582 +    if (list_empty(&free_queue)) {
   7.583 +	spin_unlock_irqrestore(&free_queue_lock, flags);
   7.584 +	return 1;
   7.585      }
   7.586 +
   7.587      blk_request = list_entry(free_queue.next, blk_request_t, queue);
   7.588      list_del(&blk_request->queue);
   7.589      spin_unlock_irqrestore(&free_queue_lock, flags);
   7.590 @@ -432,60 +323,109 @@ int dispatch_rw_block_io (int index)
   7.591      spin_lock_irqsave(&pending_queue_lock, flags);
   7.592      list_add_tail(&blk_request->queue, &pending_queue);
   7.593      spin_unlock_irqrestore(&pending_queue_lock, flags);
   7.594 -
   7.595 +    
   7.596      /* we'll be doing this frequently, would a cache be appropriate? */
   7.597      /* free in flush_blk_queue */
   7.598      bh = (struct buffer_head *) kmalloc(sizeof(struct buffer_head), 
   7.599  					GFP_KERNEL);
   7.600 -    if (!bh)
   7.601 -    {
   7.602 -      printk(KERN_ALERT "ERROR: bh is null\n");
   7.603 -      BUG();
   7.604 +    if (!bh) {
   7.605 +	printk(KERN_ALERT "ERROR: bh is null\n");
   7.606 +	BUG();
   7.607      }
   7.608  
   7.609      /* set just the important bits of the buffer header */
   7.610      memset (bh, 0, sizeof (struct buffer_head));
   7.611 -
   7.612 -    bh->b_blocknr = blk_ring->tx_ring[index].block_number;   /* block number */
   7.613 -    bh->b_size = blk_ring->tx_ring[index].block_size;          /* block size */
   7.614 -    bh->b_dev = blk_ring->tx_ring[index].device;   /* device (B_FREE = free) */
   7.615 -    bh->b_rsector = blk_ring->tx_ring[index].sector_number; /* sector number */
   7.616 -                                                    
   7.617 -    bh->b_data = phys_to_virt(blk_ring->tx_ring[index].buffer);
   7.618 -                                                          /* ptr to data blk */
   7.619 -    bh->b_count.counter = 1;                       /* users using this block */
   7.620 -    bh->b_xen_request = (void *)blk_request;           /* save block request */
   7.621      
   7.622 -
   7.623 -    if (blk_ring->tx_ring[index].operation == XEN_BLOCK_WRITE)
   7.624 -    {
   7.625 -      bh->b_state = ((1 << BH_JBD) |                  /* buffer state bitmap */
   7.626 -		     (1 << BH_Mapped) |
   7.627 -		     (1 << BH_Req) |
   7.628 -		     (1 << BH_Dirty) |
   7.629 -		     (1 << BH_Uptodate));
   7.630 -      operation = WRITE;
   7.631 -    }
   7.632 -    else
   7.633 -    {
   7.634 -      bh->b_state = (1 << BH_Mapped);                 /* buffer state bitmap */
   7.635 -      operation = READ;
   7.636 +    bh->b_blocknr       = blk_ring->btx_ring[index].block_number;
   7.637 +    bh->b_size          = blk_ring->btx_ring[index].block_size; 
   7.638 +    bh->b_dev           = blk_ring->btx_ring[index].device; 
   7.639 +    bh->b_rsector       = blk_ring->btx_ring[index].sector_number;
   7.640 +    bh->b_data          = phys_to_virt((unsigned long)
   7.641 +				       blk_ring->btx_ring[index].buffer);
   7.642 +    bh->b_count.counter = 1;
   7.643 +    bh->b_xen_request   = (void *)blk_request;  
   7.644 +    
   7.645 +    if (blk_ring->btx_ring[index].operation == XEN_BLOCK_WRITE) {
   7.646 +	bh->b_state = ((1 << BH_JBD) | (1 << BH_Mapped) | (1 << BH_Req) |
   7.647 +		       (1 << BH_Dirty) | (1 << BH_Uptodate));
   7.648 +	operation = WRITE;
   7.649 +    } else {
   7.650 +	bh->b_state = (1 << BH_Mapped);
   7.651 +	operation = READ;
   7.652      }
   7.653  
   7.654 -    /* save meta data about request */
   7.655 -    memcpy(&blk_request->request,                    /* NEED COPY_FROM_USER? */
   7.656 -	   &blk_ring->tx_ring[index], sizeof(blk_ring_entry_t));
   7.657 -    blk_request->bh = bh;
   7.658 -    blk_request->domain = current;                    /* save current domain */
   7.659 -
   7.660 +    /* save meta data about request XXX SMH: should copy_from_user() */
   7.661 +    memcpy(&blk_request->request,
   7.662 +	   &blk_ring->btx_ring[index], sizeof(blk_ring_entry_t));
   7.663 +    blk_request->bh     = bh;
   7.664 +    blk_request->domain = current; 
   7.665 +    
   7.666      /* dispatch single block request */
   7.667 -    ll_rw_block(operation, 1, &bh);                        /* linux top half */
   7.668 +    ll_rw_block(operation, 1, &bh);       /* linux top half */
   7.669      rq = blk_get_queue(bh->b_rdev);                         
   7.670 -    generic_unplug_device(rq);                          /* linux bottom half */
   7.671 +    generic_unplug_device(rq);            /* linux bottom half */
   7.672  
   7.673      return 0;
   7.674  }
   7.675  
   7.676 +
   7.677 +/*
   7.678 + * debug dump_queue
   7.679 + * arguments: queue head, name of queue
   7.680 + */
   7.681 +void dump_queue(struct list_head *queue, char *name)
   7.682 +{
   7.683 +    struct list_head *list;
   7.684 +    int loop = 0;
   7.685 +    
   7.686 +    printk ("QUEUE %s %lx   n: %lx, p: %lx\n", name,  (unsigned long)queue,
   7.687 +	    (unsigned long) queue->next, (unsigned long) queue->prev);
   7.688 +    list_for_each (list, queue) {
   7.689 +	printk ("  %s %d : %lx   n: %lx, p: %lx\n", name, loop++, 
   7.690 +		(unsigned long)list,
   7.691 +		(unsigned long)list->next, (unsigned long)list->prev);
   7.692 +    }
   7.693 +    return; 
   7.694 +}
   7.695 +
   7.696 +void dump_queue_head(struct list_head *queue, char *name)
   7.697 +{
   7.698 +    struct list_head *list;
   7.699 +    int loop = 0;
   7.700 +    
   7.701 +    printk ("QUEUE %s %lx   n: %lx, p: %lx\n", name,  (unsigned long)queue,
   7.702 +	    (unsigned long) queue->next, (unsigned long) queue->prev);
   7.703 +    list_for_each (list, queue) {
   7.704 +	printk ("      %d : %lx   n: %lx, p: %lx\n", loop++, 
   7.705 +		(unsigned long)list,
   7.706 +		(unsigned long)list->next, (unsigned long)list->prev);
   7.707 +	if (loop >= 5) return;
   7.708 +    }
   7.709 +}
   7.710 +
   7.711 +static void dump_blockq(u_char key, void *dev_id, struct pt_regs *regs) 
   7.712 +{
   7.713 +    u_long flags; 
   7.714 +
   7.715 +    printk("Dumping block queues:\n"); 
   7.716 +
   7.717 +    spin_lock_irqsave(&free_queue_lock, flags);
   7.718 +    dump_queue(&free_queue, "FREE QUEUE"); 
   7.719 +    spin_unlock_irqrestore(&free_queue_lock, flags);
   7.720 +
   7.721 +    spin_lock_irqsave(&pending_queue_lock, flags);
   7.722 +    dump_queue(&pending_queue, "PENDING QUEUE"); 
   7.723 +    spin_unlock_irqrestore(&pending_queue_lock, flags);
   7.724 +
   7.725 +    spin_lock_irqsave(&io_done_queue_lock, flags);
   7.726 +    dump_queue(&io_done_queue, "IO DONE QUEUE"); 
   7.727 +    spin_unlock_irqrestore(&io_done_queue_lock, flags);
   7.728 +
   7.729 +    return; 
   7.730 +}
   7.731 +
   7.732 +
   7.733 +
   7.734  /*
   7.735   * initialize_block_io
   7.736   *
   7.737 @@ -493,128 +433,33 @@ int dispatch_rw_block_io (int index)
   7.738   * called from arch/i386/setup.c::start_of_day
   7.739   */
   7.740  
   7.741 -void initialize_block_io ()
   7.742 -{
   7.743 -  int loop;
   7.744 -
   7.745 -  INIT_LIST_HEAD(&free_queue);
   7.746 -  INIT_LIST_HEAD(&pending_queue);
   7.747 -  INIT_LIST_HEAD(&io_done_queue);
   7.748 -  
   7.749 -  spin_lock_init(&free_queue_lock);
   7.750 -  spin_lock_init(&pending_queue_lock);
   7.751 -  spin_lock_init(&io_done_queue_lock);
   7.752 +void initialize_block_io (){
   7.753  
   7.754 -  for (loop = 0; loop < XEN_BLK_REQUEST_LIST_SIZE; loop++)
   7.755 -  {
   7.756 -    list_add_tail(&blk_request_list[loop].queue, &free_queue);
   7.757 -  }
   7.758 -
   7.759 -  /*
   7.760 -   * if bit i is true then domain i has work for us to do.
   7.761 -   */
   7.762 -  pending_work = 0;
   7.763 -
   7.764 -  return;
   7.765 +    int loop;
   7.766 +    
   7.767 +    INIT_LIST_HEAD(&free_queue);
   7.768 +    INIT_LIST_HEAD(&pending_queue);
   7.769 +    INIT_LIST_HEAD(&io_done_queue);
   7.770 +    
   7.771 +    spin_lock_init(&free_queue_lock);
   7.772 +    spin_lock_init(&pending_queue_lock);
   7.773 +    spin_lock_init(&io_done_queue_lock);
   7.774 +    
   7.775 +    for (loop = 0; loop < XEN_BLK_REQUEST_LIST_SIZE; loop++)
   7.776 +    {
   7.777 +	list_add_tail(&blk_request_list[loop].queue, &free_queue);
   7.778 +    }
   7.779 +    
   7.780 +    
   7.781 +    add_key_handler('b', dump_blockq, "dump xen ide block queues"); 
   7.782 +    
   7.783 +    /*
   7.784 +     * if bit i is true then domain i has work for us to do.
   7.785 +     */
   7.786 +    pending_work = 0;
   7.787 +    
   7.788 +    return;
   7.789  }
   7.790  
   7.791  
   7.792 -#ifdef DEBUG
   7.793  
   7.794 -/*
   7.795 - * debug dump_queue
   7.796 - * arguments: queue head, name of queue
   7.797 - */
   7.798 -void dump_queue(struct list_head *queue, char *name)
   7.799 -{
   7.800 -  struct list_head *list;
   7.801 -  int loop = 0;
   7.802 -
   7.803 -  printk ("QUEUE %s %lx   n: %lx, p: %lx\n", name,  (unsigned long)queue,
   7.804 -	  (unsigned long) queue->next, (unsigned long) queue->prev);
   7.805 -  list_for_each (list, queue)
   7.806 -  {
   7.807 -    printk ("  %s %d : %lx   n: %lx, p: %lx\n", name, loop++, 
   7.808 -	    (unsigned long)list,
   7.809 -	    (unsigned long)list->next, (unsigned long)list->prev);
   7.810 -  }
   7.811 -}
   7.812 -
   7.813 -void dump_queue_head(struct list_head *queue, char *name)
   7.814 -{
   7.815 -  struct list_head *list;
   7.816 -  int loop = 0;
   7.817 -
   7.818 -  printk ("QUEUE %s %lx   n: %lx, p: %lx\n", name,  (unsigned long)queue,
   7.819 -	  (unsigned long) queue->next, (unsigned long) queue->prev);
   7.820 -  list_for_each (list, queue)
   7.821 -  {
   7.822 -    printk ("      %d : %lx   n: %lx, p: %lx\n", loop++, 
   7.823 -	    (unsigned long)list,
   7.824 -	    (unsigned long)list->next, (unsigned long)list->prev);
   7.825 -    if (loop >= 5) return;
   7.826 -  }
   7.827 -}
   7.828 -
   7.829 -#endif /* DEBUG */
   7.830 -
   7.831 -
   7.832 -#define debug_block_size 200000
   7.833 -#define debug_output_size 10
   7.834 -
   7.835 -static int    countx = 0;
   7.836 -static char * arrayx[debug_block_size];
   7.837 -static int    outputx = 0;
   7.838 -
   7.839 -void
   7.840 -printx (char * string)
   7.841 -{
   7.842 -  char * s;
   7.843 -
   7.844 -  s = (char *) kmalloc(strlen(string), GFP_KERNEL);
   7.845 -  strcpy (s, string);
   7.846 -  arrayx[countx++] = s;
   7.847 -
   7.848 -  if (countx >= debug_block_size)
   7.849 -  {
   7.850 -    countx = 0;
   7.851 -    printk (KERN_ALERT "printx wrap\n");
   7.852 -  }
   7.853 -
   7.854 -}
   7.855 -
   7.856 -void
   7.857 -dumpx (char *buffer, int count)
   7.858 -{
   7.859 -  int loop;
   7.860 -  int start;
   7.861 -
   7.862 -  sprintf (buffer, "debug dump\n");
   7.863 -
   7.864 -  /*
   7.865 -  for (loop = outputx;
   7.866 -       loop < outputx + debug_output_size && loop < countx; 
   7.867 -       loop ++)
   7.868 -  {
   7.869 -    sprintf (buffer, "%s%02d:%s\n", buffer, loop, arrayx[loop]);
   7.870 -  }
   7.871 -  outputx = loop;
   7.872 -  */
   7.873 -  
   7.874 -  if (count == 0 || count > countx)
   7.875 -  {
   7.876 -    start = 0;
   7.877 -  }
   7.878 -  else
   7.879 -  {
   7.880 -    start = countx - count;
   7.881 -  }
   7.882 -
   7.883 -  printk (KERN_ALERT "DUMPX BUFFER\n");
   7.884 -  for (loop = start; loop < countx; loop++)
   7.885 -  {
   7.886 -    printk (KERN_ALERT "%4d %s\n", loop, arrayx[loop]);
   7.887 -  }
   7.888 -  printk (KERN_ALERT "DUMPX bye bye\n");
   7.889 -}
   7.890 -
     8.1 --- a/xen-2.4.16/drivers/char/xen_kbd.c	Thu Feb 13 18:08:51 2003 +0000
     8.2 +++ b/xen-2.4.16/drivers/char/xen_kbd.c	Fri Feb 14 12:26:26 2003 +0000
     8.3 @@ -1,5 +1,6 @@
     8.4  #include <asm-i386/io.h>
     8.5  #include <xeno/sched.h>    /* this has request_irq() proto for some reason */
     8.6 +#include <xeno/keyhandler.h>  
     8.7  
     8.8  #define KEYBOARD_IRQ 1
     8.9  
    8.10 @@ -22,74 +23,148 @@
    8.11  #define kbd_read_status() inb(KBD_STATUS_REG)
    8.12  
    8.13  
    8.14 +static int keyboard_shift = 0;
    8.15 +static int keyboard_control = 0;
    8.16  
    8.17 -static void
    8.18 -dispatch_scancode (unsigned char scancode)
    8.19 +/* the following is pretty gross... 
    8.20 + * stop reading if you don't want to throw up!
    8.21 + */
    8.22 +
    8.23 +static unsigned char keymap_normal[] =
    8.24  {
    8.25 +   0 , 0 , 0 , 0 ,  0 , 0 , 0 , 0 ,     0 , 0 , 0 , 0 ,  0 , 0 , 0 , 0 ,
    8.26 +   0 , 0 , 0 , 0 ,  0 , 0 , 0 , 0 ,     0 , 0 , 0 , 0 ,  0 , 0 , 0 , 0 ,
    8.27 +   0 , 0 , 0 , 0 ,  0 , 0 , 0 , 0 ,     0 , 0 , 0 , 0 ,  0 , 0 , 0 , 0 ,
    8.28 +   0 , 0 , 0 , 0 ,  0 , 0 , 0 , 0 ,     0 , 0 , 0 , 0 ,  0 , 0 , 0 , 0 ,
    8.29 +
    8.30 +   0 , 0 , 0 , 0 ,  0 , 0 , 0 , 0 ,     0 , 0 , 0 , 0 ,  0 , 0 , 0 , 0 ,
    8.31 +   0 , 0 , 0 , 0 ,  0 , 0 , 0 , 0 ,     0 , 0 , 0 , 0 ,  0 , 0 , 0 , 0 ,
    8.32 +   0 , 0 , 0 , 0 ,  0 , 0 , 0 , 0 ,     0 , 0 , 0 , 0 ,  0 , 0 , 0 , 0 ,
    8.33 +   0 , 0 , 0 , 0 ,  0 , 0 , 0 , 0 ,     0 , 0 , 0 , 0 ,  0 , 0 , 0 , 0 ,
    8.34 +
    8.35 +   0 , 0 ,'1','2', '3','4','5','6',    '7','8','9','0', '-','=','\b','\t',
    8.36 +  'q','w','e','r', 't','y','u','i',    'o','p','[',']','\r', 0 ,'a','s',
    8.37 +  'd','f','g','h', 'j','k','l',';',   '\'','`', 0 ,'#', 'z','x','c','v',
    8.38 +  'b','n','m',',', '.','/', 0 , 0 ,     0 , 0 , 0 , 0 ,  0 , 0 , 0 , 0 ,
    8.39 +
    8.40 +   0 , 0 , 0 , 0 ,  0 , 0 , 0 , 0 ,     0 , 0 , 0 , 0 ,  0 , 0 , 0 , 0 ,
    8.41 +   0 , 0 , 0 , 0 ,  0 , 0 ,'\\', 0 ,     0 , 0 , 0 , 0 ,  0 , 0 , 0 , 0 ,
    8.42 +   0 , 0 , 0 , 0 ,  0 , 0 , 0 , 0 ,     0 , 0 , 0 , 0 ,  0 , 0 , 0 , 0 ,
    8.43 +   0 , 0 , 0 , 0 ,  0 , 0 , 0 , 0 ,     0 , 0 , 0 , 0 ,  0 , 0 , 0 , 0 
    8.44 +};
    8.45 +
    8.46 +static unsigned char keymap_shift[] =
    8.47 +{
    8.48 +   0 , 0 , 0 , 0 ,  0 , 0 , 0 , 0 ,     0 , 0 , 0 , 0 ,  0 , 0 , 0 , 0 ,
    8.49 +   0 , 0 , 0 , 0 ,  0 , 0 , 0 , 0 ,     0 , 0 , 0 , 0 ,  0 , 0 , 0 , 0 ,
    8.50 +   0 , 0 , 0 , 0 ,  0 , 0 , 0 , 0 ,     0 , 0 , 0 , 0 ,  0 , 0 , 0 , 0 ,
    8.51 +   0 , 0 , 0 , 0 ,  0 , 0 , 0 , 0 ,     0 , 0 , 0 , 0 ,  0 , 0 , 0 , 0 ,
    8.52 +
    8.53 +   0 , 0 , 0 , 0 ,  0 , 0 , 0 , 0 ,     0 , 0 , 0 , 0 ,  0 , 0 , 0 , 0 ,
    8.54 +   0 , 0 , 0 , 0 ,  0 , 0 , 0 , 0 ,     0 , 0 , 0 , 0 ,  0 , 0 , 0 , 0 ,
    8.55 +   0 , 0 , 0 , 0 ,  0 , 0 , 0 , 0 ,     0 , 0 , 0 , 0 ,  0 , 0 , 0 , 0 ,
    8.56 +   0 , 0 , 0 , 0 ,  0 , 0 , 0 , 0 ,     0 , 0 , 0 , 0 ,  0 , 0 , 0 , 0 ,
    8.57  
    8.58 -    /*
    8.59 -     * we could be a bit more clever here, but why?
    8.60 -     * just add a jump to your debug routine for the appropriate character.
    8.61 -     */
    8.62 -    switch (scancode)
    8.63 -    {
    8.64 -    case 0x01 :                                                       /* esc */
    8.65 -	printk ("<esc>");
    8.66 -	break;
    8.67 -    case 0x9e :                                                         /* a */
    8.68 -	printk ("a");
    8.69 -	break;
    8.70 -    case 0x9f :                                                         /* s */
    8.71 -	printk ("s");
    8.72 +   0 , 0 ,'!','"', '#','$','%','^',    '&','*','(',')', '_','+','\b','\t',
    8.73 +  'Q','W','E','R', 'T','Y','U','I',    'O','P','{','}','\r', 0 ,'A','S',
    8.74 +  'D','F','G','H', 'J','K','L',':',    '@', 0 , 0 ,'~', 'Z','X','C','V',
    8.75 +  'B','N','M','<', '>','?', 0 , 0 ,     0 , 0 , 0 , 0 ,  0 , 0 , 0 , 0 ,
    8.76 +
    8.77 +   0 , 0 , 0 , 0 ,  0 , 0 , 0 , 0 ,     0 , 0 , 0 , 0 ,  0 , 0 , 0 , 0 ,
    8.78 +   0 , 0 , 0 , 0 ,  0 , 0 ,'|', 0 ,     0 , 0 , 0 , 0 ,  0 , 0 , 0 , 0 ,
    8.79 +   0 , 0 , 0 , 0 ,  0 , 0 , 0 , 0 ,     0 , 0 , 0 , 0 ,  0 , 0 , 0 , 0 ,
    8.80 +   0 , 0 , 0 , 0 ,  0 , 0 , 0 , 0 ,     0 , 0 , 0 , 0 ,  0 , 0 , 0 , 0 
    8.81 +};
    8.82 +
    8.83 +
    8.84 +static unsigned char keymap_control[] =
    8.85 +{ /* same as normal, except for a-z -> 1 to 26 */
    8.86 +   0 , 0 , 0 , 0 ,  0 , 0 , 0 , 0 ,     0 , 0 , 0 , 0 ,  0 , 0 , 0 , 0 ,
    8.87 +   0 , 0 , 0 , 0 ,  0 , 0 , 0 , 0 ,     0 , 0 , 0 , 0 ,  0 , 0 , 0 , 0 ,
    8.88 +   0 , 0 , 0 , 0 ,  0 , 0 , 0 , 0 ,     0 , 0 , 0 , 0 ,  0 , 0 , 0 , 0 ,
    8.89 +   0 , 0 , 0 , 0 ,  0 , 0 , 0 , 0 ,     0 , 0 , 0 , 0 ,  0 , 0 , 0 , 0 ,
    8.90 +
    8.91 +   0 , 0 , 0 , 0 ,  0 , 0 , 0 , 0 ,     0 , 0 , 0 , 0 ,  0 , 0 , 0 , 0 ,
    8.92 +   0 , 0 , 0 , 0 ,  0 , 0 , 0 , 0 ,     0 , 0 , 0 , 0 ,  0 , 0 , 0 , 0 ,
    8.93 +   0 , 0 , 0 , 0 ,  0 , 0 , 0 , 0 ,     0 , 0 , 0 , 0 ,  0 , 0 , 0 , 0 ,
    8.94 +   0 , 0 , 0 , 0 ,  0 , 0 , 0 , 0 ,     0 , 0 , 0 , 0 ,  0 , 0 , 0 , 0 ,
    8.95 +
    8.96 +   0 , 0 ,'1','2', '3','4','5','6',    '7','8','9','0', '-','=','\b','\t',
    8.97 +   17, 23, 5 , 18,  20, 25, 21, 9 ,     15, 16,'[',']','\r', 0 , 1 , 19,
    8.98 +   4 , 6 , 7 , 8 ,  10, 11, 12,';',   '\'','`', 0 ,'#', 26, 24, 3 , 22,
    8.99 +   2 , 14, 13,',', '.','/', 0 , 0 ,     0 , 0 , 0 , 0 ,  0 , 0 , 0 , 0 ,
   8.100 +
   8.101 +   0 , 0 , 0 , 0 ,  0 , 0 , 0 , 0 ,     0 , 0 , 0 , 0 ,  0 , 0 , 0 , 0 ,
   8.102 +   0 , 0 , 0 , 0 ,  0 , 0 ,'\\', 0 ,     0 , 0 , 0 , 0 ,  0 , 0 , 0 , 0 ,
   8.103 +   0 , 0 , 0 , 0 ,  0 , 0 , 0 , 0 ,     0 , 0 , 0 , 0 ,  0 , 0 , 0 , 0 ,
   8.104 +   0 , 0 , 0 , 0 ,  0 , 0 , 0 , 0 ,     0 , 0 , 0 , 0 ,  0 , 0 , 0 , 0 
   8.105 +};
   8.106 +
   8.107 +
   8.108 +static unsigned char convert_scancode (unsigned char scancode)
   8.109 +{
   8.110 +    unsigned char value = 0;
   8.111 +
   8.112 +    switch (scancode) {
   8.113 +
   8.114 +    case 0xba: /* caps lock UP */
   8.115 +    case 0x9d: /* ctrl (left) UP */
   8.116 +	keyboard_control = 0;
   8.117  	break;
   8.118 -    case 0xae :                                                         /* c */
   8.119 -	printk ("c");
   8.120 -	break;
   8.121 -    case 0xb0 :                                                         /* b */
   8.122 -	printk ("b");
   8.123 +
   8.124 +    case 0x3a: /* caps lock DOWN */
   8.125 +    case 0x1d: /* ctrl (left) DOWN */
   8.126 +	keyboard_control = 1;
   8.127  	break;
   8.128 -    case 0xbb :                                                        /* f1 */
   8.129 -	printk ("<f1>");
   8.130 -	break;
   8.131 -    case 0xbc :                                                        /* f2 */
   8.132 -	printk ("<f2>");
   8.133 +
   8.134 +    case 0xaa: /* shift (left) UP */
   8.135 +    case 0xb6: /* shift (right) UP */
   8.136 +	keyboard_shift = 0;
   8.137  	break;
   8.138 -    case 0xbd :                                                        /* f3 */
   8.139 -	printk ("<f3>");
   8.140 -	break;
   8.141 -    case 0xbe :                                                        /* f4 */
   8.142 -	printk ("<f4>");
   8.143 +
   8.144 +    case 0x2a: /* shift (left) DOWN */
   8.145 +    case 0x36: /* shift (right) DOWN */
   8.146 +	keyboard_shift = 1;
   8.147  	break;
   8.148 -    case 0xbf :                                                        /* f5 */
   8.149 -	/* xen_block_dump_state(); */
   8.150 -	break;
   8.151 -    default :
   8.152 -	/* printk ("%x ", scancode); */
   8.153 +
   8.154 +    default:   /* normal keys */
   8.155 +	if (keyboard_control)
   8.156 +	    value = keymap_control[scancode];
   8.157 +	else if (keyboard_shift)
   8.158 +	    value = keymap_shift[scancode];
   8.159 +	else
   8.160 +	    value = keymap_normal[scancode];
   8.161 +
   8.162      }
   8.163  
   8.164 -    return; 
   8.165 +    if (value) printk ("%c", value);
   8.166 +
   8.167 +    return value;
   8.168  }
   8.169  
   8.170 -
   8.171 -/* regs should be struct pt_regs */
   8.172 -
   8.173 -static void keyboard_interrupt(int irq, void *dev_id, void *regs)
   8.174 +static void keyboard_interrupt(int irq, void *dev_id, struct pt_regs *regs)
   8.175  {
   8.176      unsigned char status = kbd_read_status();
   8.177      unsigned int work = 10000;
   8.178 -    
   8.179 +
   8.180      while ((--work > 0) && (status & KBD_STAT_OBF))
   8.181      {
   8.182  	unsigned char scancode;
   8.183 -	
   8.184  	scancode = kbd_read_input();
   8.185  	
   8.186  	if (!(status & (KBD_STAT_GTO | KBD_STAT_PERR)))
   8.187  	{
   8.188  	    if (status & KBD_STAT_MOUSE_OBF)
   8.189  		/* mouse event, ignore */;
   8.190 -	    else
   8.191 -		dispatch_scancode (scancode);
   8.192 +	    else {
   8.193 +		unsigned char key; 
   8.194 +		key_handler *handler; 
   8.195 +		
   8.196 +		if((key = convert_scancode (scancode)) && 
   8.197 +		   (handler = get_key_handler(key))) 
   8.198 +		    (*handler)(key, dev_id, regs); 
   8.199 +		
   8.200 +	    }
   8.201  	}
   8.202  	status = kbd_read_status();
   8.203      }
     9.1 --- a/xen-2.4.16/drivers/char/xen_serial.c	Thu Feb 13 18:08:51 2003 +0000
     9.2 +++ b/xen-2.4.16/drivers/char/xen_serial.c	Fri Feb 14 12:26:26 2003 +0000
     9.3 @@ -1,6 +1,7 @@
     9.4  #include <asm-i386/io.h>
     9.5  #include <xeno/sched.h>    /* this has request_irq() proto for some reason */
     9.6 -
     9.7 +#include <xeno/keyhandler.h> 
     9.8 +#include <xeno/reboot.h>
     9.9  
    9.10  /* Register offsets */
    9.11  #define NS16550_RBR	0x00	/* receive buffer	*/
    9.12 @@ -43,51 +44,20 @@
    9.13  
    9.14  
    9.15  
    9.16 -/* 
    9.17 -** We keep an array of 'handlers' for each key code between 0 and 255; 
    9.18 -** this is intended to allow very simple debugging routines (toggle 
    9.19 -** debug flag, dump registers, reboot, etc) to be hooked in in a slightly
    9.20 -** nicer fashion than just editing this file :-) 
    9.21 -*/
    9.22 -
    9.23 -#define KEY_MAX 256
    9.24 -typedef void key_handler(u_char key); 
    9.25 -
    9.26 -static key_handler *key_table[KEY_MAX]; 
    9.27 -    
    9.28 -void add_key_handler(u_char key, key_handler *handler) 
    9.29 -{
    9.30 -    if(key_table[key] != NULL) 
    9.31 -	printk("Warning: overwriting handler for key 0x%x\n", key); 
    9.32 -
    9.33 -    key_table[key] = handler; 
    9.34 -    return; 
    9.35 -}
    9.36 -
    9.37 -
    9.38 -
    9.39  static int serial_echo = 0;   /* default is not to echo; change with 'e' */
    9.40  
    9.41 -void toggle_echo(u_char key) 
    9.42 +void toggle_echo(u_char key, void *dev_id, struct pt_regs *regs) 
    9.43  {
    9.44      serial_echo = !serial_echo; 
    9.45      return; 
    9.46  }
    9.47  
    9.48  
    9.49 -void halt_machine(u_char key) 
    9.50 -{
    9.51 -    /* This is 'debug me please' => just dump info and halt machine */
    9.52 -    printk("serial_rx_int: got EOT => halting machine.\n"); 
    9.53 -    printk("<not actually halting for now>\n"); 
    9.54 -    return; 
    9.55 -}
    9.56 -
    9.57 -
    9.58  
    9.59  static void serial_rx_int(int irq, void *dev_id, struct pt_regs *regs)
    9.60  {
    9.61      u_char c; 
    9.62 +    key_handler *handler; 
    9.63  
    9.64      /* XXX SMH: should probably check this is an RX interrupt :-) */
    9.65  
    9.66 @@ -95,8 +65,8 @@ static void serial_rx_int(int irq, void 
    9.67      c = inb(SERIAL_BASE + NS16550_RBR );
    9.68  
    9.69      /* if there's a handler, call it: we trust it won't screw us too badly */
    9.70 -    if(key_table[c]) 
    9.71 -	(*key_table[c])(c); 
    9.72 +    if((handler = get_key_handler(c)) != NULL) 
    9.73 +	(*handler)(c, dev_id, regs); 
    9.74  
    9.75      if(serial_echo) 
    9.76  	printk("%c", c); 
    9.77 @@ -104,19 +74,12 @@ static void serial_rx_int(int irq, void 
    9.78      return; 
    9.79  }
    9.80  
    9.81 -
    9.82  void initialize_serial() 
    9.83  {
    9.84 -    int i, fifo, rc; 
    9.85 -
    9.86 -    /* first initialize key handler table */
    9.87 -    for(i = 0; i < KEY_MAX; i++) 
    9.88 -	key_table[i] = (key_handler *)NULL; 
    9.89 -
    9.90 -    /* setup own handlers */
    9.91 -    add_key_handler(0x01, toggle_echo);    /* <esc> to toggle echo */
    9.92 -    add_key_handler(0x04, halt_machine);   /* CTRL-D to 'halt' */
    9.93 -
    9.94 +    int fifo, rc; 
    9.95 +    
    9.96 +    /* setup key handler */
    9.97 +    add_key_handler('~', toggle_echo, "toggle serial echo");
    9.98      
    9.99      /* Should detect this, but must be a ns16550a at least, surely? */
   9.100      fifo = 1;  
    10.1 --- a/xen-2.4.16/drivers/ide/ide-xeno.c	Thu Feb 13 18:08:51 2003 +0000
    10.2 +++ b/xen-2.4.16/drivers/ide/ide-xeno.c	Fri Feb 14 12:26:26 2003 +0000
    10.3 @@ -5,42 +5,37 @@
    10.4  #include <hypervisor-ifs/block.h>
    10.5  
    10.6  
    10.7 -void
    10.8 -ide_probe_devices (xen_disk_info_t* xdi)
    10.9 +void ide_probe_devices (xen_disk_info_t* xdi)
   10.10  {
   10.11 -  int loop;
   10.12 +    int loop;
   10.13 +    
   10.14 +    for (loop = 0; loop < MAX_HWIFS; ++loop) {
   10.15  
   10.16 -  for (loop = 0; loop < MAX_HWIFS; ++loop)
   10.17 -  {
   10.18 -    ide_hwif_t *hwif = &ide_hwifs[loop];
   10.19 -    if (hwif->present)
   10.20 -    {
   10.21 -      struct gendisk *gd = hwif->gd;
   10.22 -      unsigned int unit;
   10.23 +	ide_hwif_t *hwif = &ide_hwifs[loop];
   10.24 +	if (hwif->present) {
   10.25  
   10.26 -      for (unit = 0; unit < MAX_DRIVES; ++unit)
   10.27 -      {
   10.28 -	unsigned long capacity;
   10.29 +	    struct gendisk *gd = hwif->gd;
   10.30 +	    unsigned int unit;
   10.31 +
   10.32 +	    for (unit = 0; unit < MAX_DRIVES; ++unit) {
   10.33 +		unsigned long capacity;
   10.34 +		ide_drive_t *drive = &hwif->drives[unit];
   10.35  
   10.36 -	ide_drive_t *drive = &hwif->drives[unit];
   10.37 -
   10.38 -	if (drive->present)
   10.39 -	{
   10.40 -	  capacity = current_capacity (drive);
   10.41 -
   10.42 -	  xdi->disks[xdi->count].type = XEN_DISK_IDE;
   10.43 -	  xdi->disks[xdi->count].capacity = capacity;
   10.44 -	  xdi->count++;
   10.45 +		if (drive->present) {
   10.46 +		    capacity = current_capacity (drive);
   10.47 +		    xdi->disks[xdi->count].type = XEN_DISK_IDE;
   10.48 +		    xdi->disks[xdi->count].capacity = capacity;
   10.49 +		    xdi->count++;
   10.50  
   10.51 -	  printk (KERN_ALERT "IDE-XENO %d\n", xdi->count);
   10.52 -	  printk (KERN_ALERT "  capacity  0x%x\n", capacity);
   10.53 -	  printk (KERN_ALERT "  head      0x%x\n", drive->bios_head);
   10.54 -	  printk (KERN_ALERT "  sector    0x%x\n", drive->bios_sect);
   10.55 -	  printk (KERN_ALERT "  cylinder  0x%x\n", drive->bios_cyl);
   10.56 +		    printk (KERN_ALERT "IDE-XENO %d\n", xdi->count);
   10.57 +		    printk (KERN_ALERT "  capacity  0x%x\n", capacity);
   10.58 +		    printk (KERN_ALERT "  head      0x%x\n", drive->bios_head);
   10.59 +		    printk (KERN_ALERT "  sector    0x%x\n", drive->bios_sect);
   10.60 +		    printk (KERN_ALERT "  cylinder  0x%x\n", drive->bios_cyl);
   10.61 +		}
   10.62 +	    }
   10.63  	}
   10.64 -      }
   10.65      }
   10.66 -  }
   10.67  
   10.68    return;
   10.69  }
    11.1 --- a/xen-2.4.16/include/hypervisor-ifs/block.h	Thu Feb 13 18:08:51 2003 +0000
    11.2 +++ b/xen-2.4.16/include/hypervisor-ifs/block.h	Fri Feb 14 12:26:26 2003 +0000
    11.3 @@ -51,13 +51,13 @@ typedef struct blk_ring_entry
    11.4  
    11.5  typedef struct blk_ring_st 
    11.6  {
    11.7 -  blk_ring_entry_t *tx_ring;
    11.8 -  unsigned int      tx_prod, tx_cons;
    11.9 -  unsigned int 	    tx_ring_size;
   11.10 +  blk_ring_entry_t *btx_ring;
   11.11 +  unsigned int      btx_prod, btx_cons;
   11.12 +  unsigned int 	    btx_ring_size;
   11.13  
   11.14 -  blk_ring_entry_t *rx_ring;
   11.15 -  unsigned int      rx_prod, rx_cons;
   11.16 -  unsigned int	    rx_ring_size;
   11.17 +  blk_ring_entry_t *brx_ring;
   11.18 +  unsigned int      brx_prod, brx_cons;
   11.19 +  unsigned int	    brx_ring_size;
   11.20  } blk_ring_t;
   11.21  
   11.22  #define MAX_XEN_DISK_COUNT 100
    12.1 --- a/xen-2.4.16/include/hypervisor-ifs/hypervisor-if.h	Thu Feb 13 18:08:51 2003 +0000
    12.2 +++ b/xen-2.4.16/include/hypervisor-ifs/hypervisor-if.h	Fri Feb 14 12:26:26 2003 +0000
    12.3 @@ -107,10 +107,9 @@ typedef struct
    12.4  #define EVENT_BLK_RX   0x02 /* empty buffers for receive. */
    12.5  #define EVENT_TIMER    0x04 /* a timeout has been updated. */
    12.6  #define EVENT_DIE      0x08 /* OS is about to be killed. Clean up please! */
    12.7 -#define EVENT_NET_TX   0x10 /* packets for transmission. */
    12.8 -#define EVENT_NET_RX   0x20 /* empty buffers for receive. */
    12.9 -#define EVENT_NET2_TX  0x40 /* packets for transmission. */
   12.10 -#define EVENT_NET2_RX  0x80 /* empty buffers for receive. */
   12.11 +#define EVENT_DEBUG    0x10 /* request guest to dump debug info (gross!) */
   12.12 +#define EVENT_NET_TX   0x20 /* packets for transmission. */
   12.13 +#define EVENT_NET_RX   0x40 /* empty buffers for receive. */
   12.14  
   12.15  /* should these macros and the ones below test for range violation? */
   12.16  #define EVENT_NET_TX_FOR_VIF(x)    (EVENT_NET_TX << (2 * x))
   12.17 @@ -124,12 +123,12 @@ typedef struct
   12.18  #define _EVENT_DIE     3
   12.19  #define _EVENT_NET_TX  4
   12.20  #define _EVENT_NET_RX  5
   12.21 -#define _EVENT_NET2_TX 6
   12.22 -#define _EVENT_NET2_RX 7
   12.23 +#define _EVENT_DEBUG   6
   12.24  
   12.25  #define _EVENT_NET_TX_FOR_VIF(x)    (_EVENT_NET_TX + (2 * x))
   12.26  #define _EVENT_NET_RX_FOR_VIF(x)    (_EVENT_NET_RX + (2 * x))
   12.27  
   12.28 +
   12.29  /*
   12.30   * NB. We expect that this struct is smaller than a page.
   12.31   */
    13.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    13.2 +++ b/xen-2.4.16/include/xeno/keyhandler.h	Fri Feb 14 12:26:26 2003 +0000
    13.3 @@ -0,0 +1,16 @@
    13.4 +/* 
    13.5 +** We keep an array of 'handlers' for each key code between 0 and 255; 
    13.6 +** this is intended to allow very simple debugging routines (toggle 
    13.7 +** debug flag, dump registers, reboot, etc) to be hooked in in a slightly
    13.8 +** nicer fashion than just editing the serial/keyboard drivers. 
    13.9 +*/
   13.10 +#include <xeno/sched.h>
   13.11 +
   13.12 +typedef void key_handler(unsigned char key, void *dev_id, 
   13.13 +			 struct pt_regs *regs); 
   13.14 +
   13.15 +extern void add_key_handler(unsigned char key, 
   13.16 +			    key_handler *handler, char *desc); 
   13.17 +
   13.18 +extern key_handler *get_key_handler(unsigned char key); 
   13.19 +
    14.1 --- a/xenolinux-2.4.16-sparse/arch/xeno/drivers/block/block.c	Thu Feb 13 18:08:51 2003 +0000
    14.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    14.3 @@ -1,392 +0,0 @@
    14.4 -/******************************************************************************
    14.5 - * block.c
    14.6 - * 
    14.7 - * Virtual block driver for XenoLinux.
    14.8 - * 
    14.9 - * adapted from network.c
   14.10 - */
   14.11 -
   14.12 -#include <linux/config.h>
   14.13 -#include <linux/module.h>
   14.14 -
   14.15 -#include <linux/kernel.h>
   14.16 -#include <linux/sched.h>
   14.17 -#include <linux/slab.h>
   14.18 -#include <linux/string.h>
   14.19 -#include <linux/errno.h>
   14.20 -
   14.21 -#include <asm/hypervisor-ifs/block.h>
   14.22 -
   14.23 -#ifdef UNDEFINED
   14.24 -
   14.25 -#include <linux/netdevice.h>
   14.26 -#include <linux/inetdevice.h>
   14.27 -#include <linux/etherdevice.h>
   14.28 -#include <linux/skbuff.h>
   14.29 -#include <linux/init.h>
   14.30 -
   14.31 -#include <net/sock.h>
   14.32 -
   14.33 -#define BLK_TX_IRQ _EVENT_BLK_TX
   14.34 -#define BLK_RX_IRQ _EVENT_BLK_RX
   14.35 -
   14.36 -#define TX_MAX_ENTRIES (TX_RING_SIZE - 2)
   14.37 -#define RX_MAX_ENTRIES (RX_RING_SIZE - 2)
   14.38 -
   14.39 -#define TX_RING_INC(_i)    (((_i)+1) & (TX_RING_SIZE-1))
   14.40 -#define RX_RING_INC(_i)    (((_i)+1) & (RX_RING_SIZE-1))
   14.41 -#define TX_RING_ADD(_i,_j) (((_i)+(_j)) & (TX_RING_SIZE-1))
   14.42 -#define RX_RING_ADD(_i,_j) (((_i)+(_j)) & (RX_RING_SIZE-1))
   14.43 -
   14.44 -#define RX_BUF_SIZE 1600 /* Ethernet MTU + plenty of slack! */
   14.45 -
   14.46 -
   14.47 -
   14.48 -int	    network_probe(struct net_device *dev);
   14.49 -static int  network_open(struct net_device *dev);
   14.50 -static int  network_start_xmit(struct sk_buff *skb, struct net_device *dev);
   14.51 -static int  network_close(struct net_device *dev);
   14.52 -static struct net_device_stats *network_get_stats(struct net_device *dev);
   14.53 -static void network_rx_int(int irq, void *dev_id, struct pt_regs *ptregs);
   14.54 -static void network_tx_int(int irq, void *dev_id, struct pt_regs *ptregs);
   14.55 -static void network_tx_buf_gc(struct net_device *dev);
   14.56 -static void network_alloc_rx_buffers(struct net_device *dev);
   14.57 -static void network_free_rx_buffers(struct net_device *dev);
   14.58 -
   14.59 -static struct net_device dev_net_xeno;
   14.60 -
   14.61 -/*
   14.62 - * RX RING:   RX_IDX <= rx_cons <= rx_prod
   14.63 - * TX RING:   TX_IDX <= tx_cons <= tx_prod
   14.64 - * (*_IDX allocated privately here, *_cons & *_prod shared with hypervisor)
   14.65 - */
   14.66 -struct net_private
   14.67 -{
   14.68 -    struct net_device_stats stats;
   14.69 -    struct sk_buff **tx_skb_ring;
   14.70 -    struct sk_buff **rx_skb_ring;
   14.71 -    atomic_t tx_entries;
   14.72 -    unsigned int rx_idx, tx_idx, tx_full;
   14.73 -    net_ring_t *net_ring;
   14.74 -    spinlock_t tx_lock;
   14.75 -};
   14.76 -
   14.77 - 
   14.78 -int __init network_probe(struct net_device *dev)
   14.79 -{
   14.80 -    SET_MODULE_OWNER(dev);
   14.81 -
   14.82 -    memcpy(dev->dev_addr, "\xFE\xFD\x00\x00\x00\x00", 6);
   14.83 -
   14.84 -    dev->open = network_open;
   14.85 -    dev->hard_start_xmit = network_start_xmit;
   14.86 -    dev->stop = network_close;
   14.87 -    dev->get_stats = network_get_stats;
   14.88 -
   14.89 -    ether_setup(dev);
   14.90 -    
   14.91 -    return 0;
   14.92 -}
   14.93 -
   14.94 -
   14.95 -static int network_open(struct net_device *dev)
   14.96 -{
   14.97 -    struct net_private *np;
   14.98 -    int error;
   14.99 -
  14.100 -    np = kmalloc(sizeof(struct net_private), GFP_KERNEL);
  14.101 -    if ( np == NULL ) 
  14.102 -    {
  14.103 -        printk(KERN_WARNING "%s: No memory for private data\n", dev->name);
  14.104 -        return -ENOMEM;
  14.105 -    }
  14.106 -    memset(np, 0, sizeof(struct net_private));
  14.107 -    dev->priv = np;
  14.108 -
  14.109 -    spin_lock_init(&np->tx_lock);
  14.110 -
  14.111 -    atomic_set(&np->tx_entries, 0);
  14.112 -
  14.113 -    np->net_ring  = start_info.net_rings;
  14.114 -    np->net_ring->tx_prod = np->net_ring->tx_cons = np->net_ring->tx_event = 0;
  14.115 -    np->net_ring->rx_prod = np->net_ring->rx_cons = np->net_ring->rx_event = 0;
  14.116 -    np->net_ring->tx_ring = NULL;
  14.117 -    np->net_ring->rx_ring = NULL;
  14.118 -
  14.119 -    np->tx_skb_ring = kmalloc(TX_RING_SIZE * sizeof(struct sk_buff *),
  14.120 -                              GFP_KERNEL);
  14.121 -    np->rx_skb_ring = kmalloc(RX_RING_SIZE * sizeof(struct sk_buff *),
  14.122 -                              GFP_KERNEL);
  14.123 -    np->net_ring->tx_ring = kmalloc(TX_RING_SIZE * sizeof(tx_entry_t), 
  14.124 -                                  GFP_KERNEL);
  14.125 -    np->net_ring->rx_ring = kmalloc(RX_RING_SIZE * sizeof(rx_entry_t), 
  14.126 -                                  GFP_KERNEL);
  14.127 -    if ( (np->tx_skb_ring == NULL) || (np->rx_skb_ring == NULL) ||
  14.128 -         (np->net_ring->tx_ring == NULL) || (np->net_ring->rx_ring == NULL) )
  14.129 -    {
  14.130 -        printk(KERN_WARNING "%s; Could not allocate ring memory\n", dev->name);
  14.131 -        error = -ENOBUFS;
  14.132 -        goto fail;
  14.133 -    }
  14.134 -
  14.135 -    network_alloc_rx_buffers(dev);
  14.136 -
  14.137 -    error = request_irq(NET_RX_IRQ, network_rx_int, 0, "net-rx", dev);
  14.138 -    if ( error )
  14.139 -    {
  14.140 -        printk(KERN_WARNING "%s: Could not allocate receive interrupt\n",
  14.141 -               dev->name);
  14.142 -        goto fail;
  14.143 -    }
  14.144 -
  14.145 -    error = request_irq(NET_TX_IRQ, network_tx_int, 0, "net-tx", dev);
  14.146 -    if ( error )
  14.147 -    {
  14.148 -        printk(KERN_WARNING "%s: Could not allocate transmit interrupt\n",
  14.149 -               dev->name);
  14.150 -        free_irq(NET_RX_IRQ, dev);
  14.151 -        goto fail;
  14.152 -    }
  14.153 -
  14.154 -    printk("XenoLinux Virtual Network Driver installed as %s\n", dev->name);
  14.155 -
  14.156 -    netif_start_queue(dev);
  14.157 -
  14.158 -    MOD_INC_USE_COUNT;
  14.159 -
  14.160 -    return 0;
  14.161 -
  14.162 - fail:
  14.163 -    if ( np->net_ring->rx_ring ) kfree(np->net_ring->rx_ring);
  14.164 -    if ( np->net_ring->tx_ring ) kfree(np->net_ring->tx_ring);
  14.165 -    if ( np->rx_skb_ring ) kfree(np->rx_skb_ring);
  14.166 -    if ( np->tx_skb_ring ) kfree(np->tx_skb_ring);
  14.167 -    kfree(np);
  14.168 -    return error;
  14.169 -}
  14.170 -
  14.171 -
  14.172 -static void network_tx_buf_gc(struct net_device *dev)
  14.173 -{
  14.174 -    unsigned int i;
  14.175 -    struct net_private *np = dev->priv;
  14.176 -    struct sk_buff *skb;
  14.177 -    unsigned long flags;
  14.178 -
  14.179 -    spin_lock_irqsave(&np->tx_lock, flags);
  14.180 -
  14.181 -    for ( i = np->tx_idx; i != np->net_ring->tx_cons; i = TX_RING_INC(i) )
  14.182 -    {
  14.183 -        skb = np->tx_skb_ring[i];
  14.184 -        dev_kfree_skb_any(skb);
  14.185 -        atomic_dec(&np->tx_entries);
  14.186 -    }
  14.187 -
  14.188 -    np->tx_idx = i;
  14.189 -
  14.190 -    if ( np->tx_full && (atomic_read(&np->tx_entries) < TX_MAX_ENTRIES) )
  14.191 -    {
  14.192 -        np->tx_full = 0;
  14.193 -        netif_wake_queue(dev);
  14.194 -    }
  14.195 -
  14.196 -    spin_unlock_irqrestore(&np->tx_lock, flags);
  14.197 -}
  14.198 -
  14.199 -
  14.200 -static void network_alloc_rx_buffers(struct net_device *dev)
  14.201 -{
  14.202 -    unsigned int i;
  14.203 -    struct net_private *np = dev->priv;
  14.204 -    struct sk_buff *skb;
  14.205 -    unsigned int end = RX_RING_ADD(np->rx_idx, RX_MAX_ENTRIES);
  14.206 -
  14.207 -    for ( i = np->net_ring->rx_prod; i != end; i = RX_RING_INC(i) )
  14.208 -    {
  14.209 -        skb = dev_alloc_skb(RX_BUF_SIZE);
  14.210 -        if ( skb == NULL ) break;
  14.211 -        skb->dev = dev;
  14.212 -        skb_reserve(skb, 2); /* word align the IP header */
  14.213 -        np->rx_skb_ring[i] = skb;
  14.214 -        np->net_ring->rx_ring[i].addr = (unsigned long)skb->data;
  14.215 -        np->net_ring->rx_ring[i].size = RX_BUF_SIZE - 16; /* arbitrary */
  14.216 -    }
  14.217 -
  14.218 -    np->net_ring->rx_prod = i;
  14.219 -
  14.220 -    np->net_ring->rx_event = RX_RING_INC(np->rx_idx);
  14.221 -
  14.222 -    HYPERVISOR_net_update();
  14.223 -}
  14.224 -
  14.225 -
  14.226 -static void network_free_rx_buffers(struct net_device *dev)
  14.227 -{
  14.228 -    unsigned int i;
  14.229 -    struct net_private *np = dev->priv;
  14.230 -    struct sk_buff *skb;    
  14.231 -
  14.232 -    for ( i = np->rx_idx; i != np->net_ring->rx_prod; i = RX_RING_INC(i) )
  14.233 -    {
  14.234 -        skb = np->rx_skb_ring[i];
  14.235 -        dev_kfree_skb(skb);
  14.236 -    }
  14.237 -}
  14.238 -
  14.239 -
  14.240 -static int network_start_xmit(struct sk_buff *skb, struct net_device *dev)
  14.241 -{
  14.242 -    unsigned int i;
  14.243 -    struct net_private *np = (struct net_private *)dev->priv;
  14.244 -
  14.245 -    if ( np->tx_full )
  14.246 -    {
  14.247 -        printk(KERN_WARNING "%s: full queue wasn't stopped!\n", dev->name);
  14.248 -        netif_stop_queue(dev);
  14.249 -        return -ENOBUFS;
  14.250 -    }
  14.251 -
  14.252 -    i = np->net_ring->tx_prod;
  14.253 -    np->tx_skb_ring[i] = skb;
  14.254 -    np->net_ring->tx_ring[i].addr = (unsigned long)skb->data;
  14.255 -    np->net_ring->tx_ring[i].size = skb->len;
  14.256 -    np->net_ring->tx_prod = TX_RING_INC(i);
  14.257 -    atomic_inc(&np->tx_entries);
  14.258 -
  14.259 -    np->stats.tx_bytes += skb->len;
  14.260 -    np->stats.tx_packets++;
  14.261 -
  14.262 -    spin_lock_irq(&np->tx_lock);
  14.263 -    if ( atomic_read(&np->tx_entries) >= TX_MAX_ENTRIES )
  14.264 -    {
  14.265 -        np->tx_full = 1;
  14.266 -        netif_stop_queue(dev);
  14.267 -        np->net_ring->tx_event = TX_RING_ADD(np->tx_idx,
  14.268 -                                           atomic_read(&np->tx_entries) >> 1);
  14.269 -    }
  14.270 -    else
  14.271 -    {
  14.272 -        /* Avoid unnecessary tx interrupts. */
  14.273 -        np->net_ring->tx_event = TX_RING_INC(np->net_ring->tx_prod);
  14.274 -    }
  14.275 -    spin_unlock_irq(&np->tx_lock);
  14.276 -
  14.277 -    /* Must do this after setting tx_event: race with updates of tx_cons. */
  14.278 -    network_tx_buf_gc(dev);
  14.279 -
  14.280 -    HYPERVISOR_net_update();
  14.281 -
  14.282 -    return 0;
  14.283 -}
  14.284 -
  14.285 -
  14.286 -static void network_rx_int(int irq, void *dev_id, struct pt_regs *ptregs)
  14.287 -{
  14.288 -    unsigned int i;
  14.289 -    struct net_device *dev = (struct net_device *)dev_id;
  14.290 -    struct net_private *np = dev->priv;
  14.291 -    struct sk_buff *skb;
  14.292 -    
  14.293 - again:
  14.294 -    for ( i = np->rx_idx; i != np->net_ring->rx_cons; i = RX_RING_INC(i) )
  14.295 -    {
  14.296 -        skb = np->rx_skb_ring[i];
  14.297 -        skb_put(skb, np->net_ring->rx_ring[i].size);
  14.298 -        skb->protocol = eth_type_trans(skb, dev);
  14.299 -        np->stats.rx_packets++;
  14.300 -        np->stats.rx_bytes += np->net_ring->rx_ring[i].size;
  14.301 -        netif_rx(skb);
  14.302 -        dev->last_rx = jiffies;
  14.303 -    }
  14.304 -
  14.305 -    np->rx_idx = i;
  14.306 -
  14.307 -    network_alloc_rx_buffers(dev);
  14.308 -    
  14.309 -    /* Deal with hypervisor racing our resetting of rx_event. */
  14.310 -    smp_mb();
  14.311 -    if ( np->net_ring->rx_cons != i ) goto again;
  14.312 -}
  14.313 -
  14.314 -
  14.315 -static void network_tx_int(int irq, void *dev_id, struct pt_regs *ptregs)
  14.316 -{
  14.317 -    struct net_device *dev = (struct net_device *)dev_id;
  14.318 -    network_tx_buf_gc(dev);
  14.319 -}
  14.320 -
  14.321 -
  14.322 -static int network_close(struct net_device *dev)
  14.323 -{
  14.324 -    struct net_private *np = dev->priv;
  14.325 -
  14.326 -    netif_stop_queue(dev);
  14.327 -    free_irq(NET_RX_IRQ, dev);
  14.328 -    free_irq(NET_TX_IRQ, dev);
  14.329 -    network_free_rx_buffers(dev);
  14.330 -    kfree(np->net_ring->rx_ring);
  14.331 -    kfree(np->net_ring->tx_ring);
  14.332 -    kfree(np->rx_skb_ring);
  14.333 -    kfree(np->tx_skb_ring);
  14.334 -    kfree(np);
  14.335 -    MOD_DEC_USE_COUNT;
  14.336 -    return 0;
  14.337 -}
  14.338 -
  14.339 -
  14.340 -static struct net_device_stats *network_get_stats(struct net_device *dev)
  14.341 -{
  14.342 -    struct net_private *np = (struct net_private *)dev->priv;
  14.343 -    return &np->stats;
  14.344 -}
  14.345 -
  14.346 -
  14.347 -static int __init init_module(void)
  14.348 -{
  14.349 -    memset(&dev_net_xeno, 0, sizeof(dev_net_xeno));
  14.350 -    strcpy(dev_net_xeno.name, "eth%d");
  14.351 -    dev_net_xeno.init = network_probe;
  14.352 -    return (register_netdev(&dev_net_xeno) != 0) ? -EIO : 0;
  14.353 -}
  14.354 -
  14.355 -
  14.356 -static void __exit cleanup_module(void)
  14.357 -{
  14.358 -    unregister_netdev(&dev_net_xeno);
  14.359 -}
  14.360 -
  14.361 -#endif /* UNDEFINED */
  14.362 -
  14.363 -
  14.364 -static void block_initialize(void)
  14.365 -{
  14.366 -  blk_ring_t *blk_ring = start_info.blk_ring;
  14.367 -
  14.368 -  if ( blk_ring == NULL ) return;
  14.369 -
  14.370 -  blk_ring->tx_prod = blk_ring->tx_cons = blk_ring->tx_event = 0;
  14.371 -  blk_ring->rx_prod = blk_ring->rx_cons = blk_ring->rx_event = 0;
  14.372 -  blk_ring->tx_ring = NULL;
  14.373 -  blk_ring->rx_ring = NULL;
  14.374 -}
  14.375 -
  14.376 -
  14.377 -/*
  14.378 - * block_setup initialized the xeno block device driver
  14.379 - */
  14.380 -
  14.381 -static int __init init_module(void)
  14.382 -{
  14.383 -  block_initialize();
  14.384 -  printk("XenoLinux Virtual Block Device Driver installed\n");
  14.385 -  return 0;
  14.386 -}
  14.387 -
  14.388 -static void __exit cleanup_module(void)
  14.389 -{
  14.390 -  printk("XenoLinux Virtual Block Device Driver uninstalled\n");
  14.391 -}
  14.392 -
  14.393 -module_init(init_module);
  14.394 -module_exit(cleanup_module);
  14.395 -
    15.1 --- a/xenolinux-2.4.16-sparse/arch/xeno/drivers/block/xl_block.c	Thu Feb 13 18:08:51 2003 +0000
    15.2 +++ b/xenolinux-2.4.16-sparse/arch/xeno/drivers/block/xl_block.c	Fri Feb 14 12:26:26 2003 +0000
    15.3 @@ -30,19 +30,21 @@ typedef unsigned char	byte;
    15.4  
    15.5  void xlblk_ide_register_disk(int, unsigned long);
    15.6  
    15.7 -#define XLBLK_MAX 2                                        /* very arbitrary */
    15.8 -#define XLBLK_MAJOR_NAME "blk"
    15.9 +#define XLBLK_MAX 2                                /* very arbitrary */
   15.10 +#define XLBLK_MAJOR_NAME "xhd"
   15.11  #define IDE_PARTN_BITS 6                           /* from ide.h::PARTN_BITS */
   15.12  #define IDE_PARTN_MASK ((1<<IDE_PARTN_BITS)-1)     /* from ide.h::PARTN_MASK */
   15.13  static int xlblk_blk_size[XLBLK_MAX];
   15.14  static int xlblk_blksize_size[XLBLK_MAX];
   15.15 +static int xlblk_read_ahead; 
   15.16  static int xlblk_hardsect_size[XLBLK_MAX];
   15.17 -static int xlblk_read_ahead[XLBLK_MAX];
   15.18  static int xlblk_max_sectors[XLBLK_MAX];
   15.19  
   15.20  #define XLBLK_RX_IRQ _EVENT_BLK_RX
   15.21  #define XLBLK_TX_IRQ _EVENT_BLK_TX
   15.22  
   15.23 +#define DEBUG_IRQ    _EVENT_DEBUG 
   15.24 +
   15.25  typedef struct xlblk_device
   15.26  {
   15.27    struct buffer_head *bh;
   15.28 @@ -51,11 +53,6 @@ typedef struct xlblk_device
   15.29  
   15.30  xlblk_device_t xlblk_device;
   15.31  
   15.32 -/* USE_REQUEST_QUEUE = 1  use (multiple) request queues
   15.33 - *                   = 0  don't use IO request queue 
   15.34 - */
   15.35 -#define USE_REQUEST_QUEUE 1
   15.36 -
   15.37  #define XLBLK_DEBUG       0
   15.38  #define XLBLK_DEBUG_IOCTL 0
   15.39  
   15.40 @@ -80,130 +77,106 @@ void hypervisor_request(void *         i
   15.41  
   15.42  static int xenolinux_block_open(struct inode *inode, struct file *filep)
   15.43  {
   15.44 -  if (XLBLK_DEBUG) {
   15.45 -    printk (KERN_ALERT "xenolinux_block_open\n"); }
   15.46 -  return 0;
   15.47 +    if (XLBLK_DEBUG)
   15.48 +	printk (KERN_ALERT "xenolinux_block_open\n"); 
   15.49 +
   15.50 +    return 0;
   15.51  }
   15.52  
   15.53  static int xenolinux_block_release(struct inode *inode, struct file *filep)
   15.54  {
   15.55 -  if (XLBLK_DEBUG) {
   15.56 -    printk (KERN_ALERT "xenolinux_block_release\n"); }
   15.57 -  return 0;
   15.58 +    if (XLBLK_DEBUG)
   15.59 +	printk (KERN_ALERT "xenolinux_block_release\n");
   15.60 +
   15.61 +    return 0;
   15.62  }
   15.63  
   15.64  static int xenolinux_block_ioctl(struct inode *inode, struct file *filep,
   15.65  			  unsigned command, unsigned long argument)
   15.66  {
   15.67 -  int minor_dev;
   15.68 +    int minor_dev;
   15.69 +    struct hd_geometry *geo = (struct hd_geometry *)argument;
   15.70  
   15.71 -  if (XLBLK_DEBUG_IOCTL)
   15.72 -  {
   15.73 -    printk (KERN_ALERT "xenolinux_block_ioctl\n"); 
   15.74 -  }
   15.75 +    if (XLBLK_DEBUG_IOCTL)
   15.76 +	printk (KERN_ALERT "xenolinux_block_ioctl\n"); 
   15.77  
   15.78 -  /* check permissions */
   15.79 -  if (!capable(CAP_SYS_ADMIN)) return -EPERM;
   15.80 -  if (!inode)                  return -EINVAL;
   15.81 -  minor_dev = MINOR(inode->i_rdev);
   15.82 -  if (minor_dev >= XLBLK_MAX)  return -ENODEV;
   15.83 -
   15.84 -  if (XLBLK_DEBUG_IOCTL)
   15.85 -  {
   15.86 -    printk (KERN_ALERT  
   15.87 -	    "   command: 0x%x, argument: 0x%lx, minor: 0x%x\n",
   15.88 -	    command, (long) argument, minor_dev); 
   15.89 -  }
   15.90 +    /* check permissions */
   15.91 +    if (!capable(CAP_SYS_ADMIN)) return -EPERM;
   15.92 +    if (!inode)                  return -EINVAL;
   15.93 +    minor_dev = MINOR(inode->i_rdev);
   15.94 +    if (minor_dev >= XLBLK_MAX)  return -ENODEV;
   15.95 +    
   15.96 +    if (XLBLK_DEBUG_IOCTL)
   15.97 +	printk (KERN_ALERT "   command: 0x%x, argument: 0x%lx, minor: 0x%x\n",
   15.98 +		command, (long) argument, minor_dev); 
   15.99    
  15.100 -  switch (command)
  15.101 -  {
  15.102 -    case BLKGETSIZE :
  15.103 -    {
  15.104 -      if (XLBLK_DEBUG_IOCTL)
  15.105 -      {
  15.106 -	printk (KERN_ALERT
  15.107 -		"   BLKGETSIZE: %x %lx\n", BLKGETSIZE, 
  15.108 -		(long) xen_disk_info.disks[0].capacity); 
  15.109 -      }
  15.110 -      return put_user(xen_disk_info.disks[0].capacity, 
  15.111 -		      (unsigned long *) argument);
  15.112 -    }
  15.113 -    case BLKRRPART :
  15.114 -    {
  15.115 -      if (XLBLK_DEBUG_IOCTL) {
  15.116 -	printk (KERN_ALERT "   BLKRRPART: %x\n", BLKRRPART); }
  15.117 -      break;
  15.118 -    }
  15.119 -    case BLKSSZGET :
  15.120 -    {
  15.121 -      if (XLBLK_DEBUG_IOCTL) {
  15.122 -	printk (KERN_ALERT "   BLKSSZGET: %x 0x%x\n", BLKSSZGET,
  15.123 -		xlblk_hardsect_size[minor_dev]); }
  15.124 -      return xlblk_hardsect_size[minor_dev]; 
  15.125 +    switch (command) {
  15.126 +
  15.127 +    case BLKGETSIZE:
  15.128 +	if (XLBLK_DEBUG_IOCTL) 
  15.129 +	    printk (KERN_ALERT
  15.130 +		    "   BLKGETSIZE: %x %lx\n", BLKGETSIZE, 
  15.131 +		    (long) xen_disk_info.disks[0].capacity); 
  15.132 +	return put_user(xen_disk_info.disks[0].capacity, 
  15.133 +			(unsigned long *) argument);
  15.134 +
  15.135 +    case BLKRRPART:
  15.136 +	if (XLBLK_DEBUG_IOCTL)
  15.137 +	    printk (KERN_ALERT "   BLKRRPART: %x\n", BLKRRPART); 
  15.138 +	break;
  15.139 +
  15.140 +    case BLKSSZGET:
  15.141 +	if (XLBLK_DEBUG_IOCTL)
  15.142 +	    printk (KERN_ALERT "   BLKSSZGET: %x 0x%x\n", BLKSSZGET,
  15.143 +		    xlblk_hardsect_size[minor_dev]);
  15.144 +	return xlblk_hardsect_size[minor_dev]; 
  15.145 +
  15.146 +    case HDIO_GETGEO:
  15.147 +
  15.148 +	if (XLBLK_DEBUG_IOCTL)
  15.149 +	    printk (KERN_ALERT "   HDIO_GETGEO: %x\n", HDIO_GETGEO);
  15.150 +
  15.151 +	if (!argument) return -EINVAL;
  15.152 +	if (put_user(0x00,  (unsigned long *) &geo->start)) return -EFAULT;
  15.153 +	if (put_user(0xff,  (byte *)&geo->heads)) return -EFAULT;
  15.154 +	if (put_user(0x3f,  (byte *)&geo->sectors)) return -EFAULT;
  15.155 +	if (put_user(0x106, (unsigned short *)&geo->cylinders)) return -EFAULT;
  15.156 +	return 0;
  15.157 +
  15.158 +    case HDIO_GETGEO_BIG: 
  15.159 +
  15.160 +	if (XLBLK_DEBUG_IOCTL) 
  15.161 +	    printk (KERN_ALERT "   HDIO_GETGEO_BIG: %x\n", HDIO_GETGEO_BIG);
  15.162 +
  15.163 +	if (!argument) return -EINVAL;
  15.164 +	if (put_user(0x00,  (unsigned long *) &geo->start))  return -EFAULT;
  15.165 +	if (put_user(0xff,  (byte *)&geo->heads))   return -EFAULT;
  15.166 +	if (put_user(0x3f,  (byte *)&geo->sectors)) return -EFAULT;
  15.167 +	if (put_user(0x106, (unsigned int *) &geo->cylinders)) return -EFAULT;
  15.168 +
  15.169 +	return 0;
  15.170 +
  15.171 +    default:
  15.172 +	if (XLBLK_DEBUG_IOCTL) 
  15.173 +	    printk (KERN_ALERT "   eh? unknown ioctl\n");
  15.174 +	break;
  15.175      }
  15.176 -    case HDIO_GETGEO :
  15.177 -    {
  15.178 -      struct hd_geometry *geo = (struct hd_geometry *)argument;
  15.179 -
  15.180 -      if (XLBLK_DEBUG_IOCTL) {
  15.181 -	printk (KERN_ALERT "   HDIO_GETGEO: %x\n", HDIO_GETGEO); }
  15.182 -
  15.183 -      if (!argument) return -EINVAL;
  15.184 -      /*
  15.185 -      if (put_user(0x80,  (byte *)&geo->heads)) return -EFAULT;
  15.186 -      if (put_user(0x3f,  (byte *)&geo->sectors)) return -EFAULT;
  15.187 -      if (put_user(0x20b, (unsigned short *) &geo->cylinders)) return -EFAULT;
  15.188 -      */
  15.189 -      if (put_user(0x00,  (unsigned long *) &geo->start)) return -EFAULT;
  15.190 -      if (put_user(0xff,  (byte *)&geo->heads)) return -EFAULT;
  15.191 -      if (put_user(0x3f,  (byte *)&geo->sectors)) return -EFAULT;
  15.192 -      if (put_user(0x106, (unsigned short *) &geo->cylinders)) return -EFAULT;
  15.193 -
  15.194 -      return 0;
  15.195 -    }
  15.196 -    case HDIO_GETGEO_BIG :
  15.197 -    {
  15.198 -      struct hd_big_geometry *geo = (struct hd_big_geometry *) argument;
  15.199 -
  15.200 -      if (XLBLK_DEBUG_IOCTL) {
  15.201 -	printk (KERN_ALERT "   HDIO_GETGEO_BIG: %x\n", HDIO_GETGEO_BIG); }
  15.202 -
  15.203 -      if (!argument) return -EINVAL;
  15.204 -      /*
  15.205 -      if (put_user(0x80,  (byte *)&geo->heads))   return -EFAULT;
  15.206 -      if (put_user(0x3f,  (byte *)&geo->sectors)) return -EFAULT;
  15.207 -      if (put_user(0x20b, (unsigned int *) &geo->cylinders)) return -EFAULT;
  15.208 -      */
  15.209 -      if (put_user(0x00,  (unsigned long *) &geo->start))  return -EFAULT;
  15.210 -      if (put_user(0xff,  (byte *)&geo->heads))   return -EFAULT;
  15.211 -      if (put_user(0x3f,  (byte *)&geo->sectors)) return -EFAULT;
  15.212 -      if (put_user(0x106, (unsigned int *) &geo->cylinders)) return -EFAULT;
  15.213 -
  15.214 -      return 0;
  15.215 -    }
  15.216 -    default :
  15.217 -    {
  15.218 -      if (XLBLK_DEBUG_IOCTL) {
  15.219 -	printk (KERN_ALERT "   eh? unknown ioctl\n"); }
  15.220 -      break;
  15.221 -    }
  15.222 -  }
  15.223 -
  15.224 -  return 0;
  15.225 +    
  15.226 +    return 0;
  15.227  }
  15.228  
  15.229  static int xenolinux_block_check(kdev_t dev)
  15.230  {
  15.231 -  if (XLBLK_DEBUG) {
  15.232 -    printk (KERN_ALERT "xenolinux_block_check\n"); }
  15.233 -  return 0;
  15.234 +    if (XLBLK_DEBUG) 
  15.235 +      printk (KERN_ALERT "xenolinux_block_check\n");
  15.236 +    return 0;
  15.237  }
  15.238  
  15.239  static int xenolinux_block_revalidate(kdev_t dev)
  15.240  {
  15.241 -  if (XLBLK_DEBUG) {
  15.242 -    printk (KERN_ALERT "xenolinux_block_revalidate\n"); }
  15.243 -  return 0;
  15.244 +    if (XLBLK_DEBUG) 
  15.245 +	printk (KERN_ALERT "xenolinux_block_revalidate\n"); 
  15.246 +    return 0;
  15.247  }
  15.248  
  15.249  /*
  15.250 @@ -230,110 +203,88 @@ void hypervisor_request(void *         i
  15.251  			kdev_t         device,
  15.252  			int            mode)
  15.253  {
  15.254 -  blk_ring_t *blk_ring = start_info.blk_ring;
  15.255 -  int position;
  15.256 -  void *buffer_pa, *buffer_ma; 
  15.257 -  kdev_t phys_device = (kdev_t) 0;
  15.258 -  unsigned long sector_number = 0;
  15.259 +    blk_ring_t *blk_ring = start_info.blk_ring;
  15.260 +    int position;
  15.261 +    void *buffer_pa, *buffer_ma; 
  15.262 +    kdev_t phys_device = (kdev_t) 0;
  15.263 +    unsigned long sector_number = 0;
  15.264 +    struct gendisk *gd; 
  15.265 +    
  15.266  
  15.267 -#if 0
  15.268 -  printk(KERN_ALERT "[%x]", id); 
  15.269 -  printk (KERN_ALERT
  15.270 -	  "xlblk_req: id:%p op:%d, bf:%p, blk:%lu, sz:%u, dev:%x\n",
  15.271 -	  id, operation, buffer, block_number, block_size, device);
  15.272 -#endif
  15.273 +    buffer_pa = (void *)virt_to_phys(buffer); 
  15.274 +    buffer_ma = (void *)phys_to_machine((unsigned long)buffer_pa); 
  15.275  
  15.276 -  /* XXX SMH: now need to convert guest virtual address to machine address */
  15.277 -  buffer_pa = (void *)virt_to_phys((unsigned long)buffer); 
  15.278 -  buffer_ma = (void *)phys_to_machine((unsigned long)buffer_pa); 
  15.279 +    if (operation == XEN_BLOCK_PROBE) {
  15.280 +	phys_device = (kdev_t) 0;
  15.281 +	sector_number = 0;
  15.282  
  15.283 -#if 0
  15.284 -  printk(KERN_ALERT "va %p => pa %p => ma %p\n", buffer, buffer_pa, buffer_ma);
  15.285 -#endif
  15.286 +    } else if (operation == XEN_BLOCK_READ || operation == XEN_BLOCK_WRITE) {
  15.287  
  15.288 -  if (operation == XEN_BLOCK_PROBE)
  15.289 -  {
  15.290 -    phys_device = (kdev_t) 0;
  15.291 -    sector_number = 0;
  15.292 -  }
  15.293 -  else if (operation == XEN_BLOCK_READ || operation == XEN_BLOCK_WRITE)
  15.294 -  {
  15.295 -    /*
  15.296 -     * map logial major device to the physical device number 
  15.297 -     *
  15.298 -     *           XLBLK_MAJOR -> IDE0_MAJOR  (123 -> 3)
  15.299 -     */
  15.300 -    if (MAJOR(device) == XLBLK_MAJOR)
  15.301 -    {
  15.302 -      phys_device = MKDEV(IDE0_MAJOR, 0);
  15.303 -    }
  15.304 -    else
  15.305 -    {
  15.306 -      printk (KERN_ALERT
  15.307 -	      "error: xl_block::hypervisor_request: unknown device [0x%x]\n", 
  15.308 -	      device);
  15.309 -      BUG();
  15.310 -    }
  15.311 -  
  15.312 -    /*
  15.313 -     * compute real buffer location on disk
  15.314 -     * (from ll_rw_block.c::submit_bh)
  15.315 -     */
  15.316 -    {
  15.317 -      int idx = 0;
  15.318 +	/*
  15.319 +	 * map logial major device to the physical device number 
  15.320 +	 *
  15.321 +	 *           XLBLK_MAJOR -> IDE0_MAJOR  (123 -> 3)
  15.322 +	 */
  15.323 +	if (MAJOR(device) == XLBLK_MAJOR) 
  15.324 +	    phys_device = MKDEV(IDE0_MAJOR, 0);
  15.325 +	else {
  15.326 +	    printk (KERN_ALERT "error: xl_block::hypervisor_request: "
  15.327 +		    "unknown device [0x%x]\n", device);
  15.328 +	    BUG();
  15.329 +	}
  15.330 +
  15.331 +	/*
  15.332 +	 * compute real buffer location on disk
  15.333 +	 * (from ll_rw_block.c::submit_bh)
  15.334 +	 */
  15.335 +
  15.336 +
  15.337 +	sector_number = block_number /* * block_size >> 9 */;
  15.338  
  15.339 -      struct gendisk *gd = (struct gendisk *) xen_disk_info.disks[idx].gendisk;
  15.340 -      unsigned int minor = MINOR(device);
  15.341 +	if((gd = (struct gendisk *)xen_disk_info.disks[0].gendisk) != NULL)
  15.342 +	    sector_number += gd->part[MINOR(device)&IDE_PARTN_MASK].start_sect;
  15.343 +    }
  15.344  
  15.345 -      sector_number = block_number /* * block_size >> 9 */;
  15.346  
  15.347 -      if (gd != NULL)                     /* if we have a partition table... */
  15.348 -      {
  15.349 -	sector_number += gd->part[minor & IDE_PARTN_MASK].start_sect;
  15.350 -      }
  15.351 +    if (BLK_TX_RING_INC(blk_ring->btx_prod) == blk_ring->btx_cons) {
  15.352 +	printk (KERN_ALERT "hypervisor_request: btx_cons: %d, btx_prod:%d",
  15.353 +		blk_ring->btx_cons, blk_ring->btx_prod);
  15.354 +	BUG(); 
  15.355      }
  15.356 -  }
  15.357 -
  15.358 -  /*
  15.359 -   * CHECK TO SEE IF THERE IS SPACE IN THE RING
  15.360 -   */
  15.361 -  if (BLK_TX_RING_INC(blk_ring->tx_prod) == blk_ring->tx_cons)
  15.362 -  {
  15.363 -    printk (KERN_ALERT "hypervisor_request: tx_cons: %d, tx_prod:%d",
  15.364 -	    blk_ring->tx_cons, blk_ring->tx_prod);
  15.365 -  }
  15.366 +    
  15.367 +    /* Fill out a communications ring structure & trap to the hypervisor */
  15.368 +    position = blk_ring->btx_prod;
  15.369 +    blk_ring->btx_ring[position].id            = id;
  15.370 +    blk_ring->btx_ring[position].priority      = mode;
  15.371 +    blk_ring->btx_ring[position].operation     = operation;
  15.372 +    blk_ring->btx_ring[position].buffer        = buffer_ma;
  15.373 +    blk_ring->btx_ring[position].block_number  = block_number;
  15.374 +    blk_ring->btx_ring[position].block_size    = block_size;
  15.375 +    blk_ring->btx_ring[position].device        = phys_device;
  15.376 +    blk_ring->btx_ring[position].sector_number = sector_number;
  15.377  
  15.378 -  /* fill out a communications ring structure 
  15.379 -     and then trap into the hypervisor */
  15.380 -  position = blk_ring->tx_prod;
  15.381 -  blk_ring->tx_ring[position].id            = id;
  15.382 -  blk_ring->tx_ring[position].priority      = mode;
  15.383 -  blk_ring->tx_ring[position].operation     = operation;
  15.384 -  blk_ring->tx_ring[position].buffer        = buffer_ma;
  15.385 -  blk_ring->tx_ring[position].block_number  = block_number;
  15.386 -  blk_ring->tx_ring[position].block_size    = block_size;
  15.387 -  blk_ring->tx_ring[position].device        = phys_device;
  15.388 -  blk_ring->tx_ring[position].sector_number = sector_number;
  15.389 +    blk_ring->btx_prod = BLK_TX_RING_INC(blk_ring->btx_prod);
  15.390 +
  15.391 +    switch(mode) { 
  15.392  
  15.393 -  blk_ring->tx_prod = BLK_TX_RING_INC(blk_ring->tx_prod);
  15.394 +    case XEN_BLOCK_SYNC:  
  15.395 +	/* trap into hypervisor */
  15.396 +	HYPERVISOR_block_io_op();
  15.397 +	break; 
  15.398  
  15.399 -  if (mode == XEN_BLOCK_SYNC)
  15.400 -  {
  15.401 -    /* trap into hypervisor */
  15.402 -    HYPERVISOR_block_io_op();
  15.403 -  }
  15.404 -  else if (mode == XEN_BLOCK_ASYNC)
  15.405 -  {
  15.406 -    /* for now, do nothing.  the request will go in the ring and
  15.407 -       the next sync request will trigger the hypervisor to act */
  15.408 -  }
  15.409 -  else
  15.410 -  {
  15.411 -    /* ummm, unknown mode. */
  15.412 -    BUG();
  15.413 -  }
  15.414 +    case XEN_BLOCK_ASYNC:
  15.415 +	/* for now, do nothing.  the request will go in the ring and
  15.416 +	   the next sync request will trigger the hypervisor to act */
  15.417 +	printk("Oh dear-- ASYNC xen block of doom!\n"); 
  15.418 +	break; 
  15.419  
  15.420 -  return;
  15.421 +    default: 
  15.422 +	/* ummm, unknown mode. */
  15.423 +	printk("xl_block thingy: unknown mode %d\n", mode); 
  15.424 +	BUG();
  15.425 +    }
  15.426 +
  15.427 +    return;
  15.428  }
  15.429  
  15.430  
  15.431 @@ -345,138 +296,82 @@ void hypervisor_request(void *         i
  15.432   * TO DO: should probably release the io_request_lock and then re-acquire
  15.433   *        (see LDD p. 338)
  15.434   */
  15.435 -
  15.436  static void do_xlblk_request (request_queue_t *rq)
  15.437  {
  15.438 -  struct request *req;
  15.439 -
  15.440 -  if (XLBLK_DEBUG)
  15.441 -  {
  15.442 -    printk (KERN_ALERT "xlblk.c::do_xlblk_request for '%s'\n", DEVICE_NAME); 
  15.443 -  }
  15.444 -
  15.445 -  while (!QUEUE_EMPTY)
  15.446 -  {
  15.447 -    struct buffer_head *bh;
  15.448 -    unsigned long offset;
  15.449 -    unsigned long length;
  15.450 -    int rw;
  15.451 -
  15.452 -    req = CURRENT;
  15.453 -
  15.454 +    struct request *req;
  15.455 +    
  15.456      if (XLBLK_DEBUG)
  15.457 +	printk (KERN_ALERT "xlblk.c::do_xlblk_request for '%s'\n", 
  15.458 +		DEVICE_NAME); 
  15.459 +    
  15.460 +    while (!QUEUE_EMPTY)
  15.461      {
  15.462 -      printk (KERN_ALERT
  15.463 -	      "do_xlblk_request %p: cmd %i, sec %lx, (%li) bh:%p\n",
  15.464 -	      req, req->cmd, req->sector,
  15.465 -	      req->current_nr_sectors, req->bh);
  15.466 -    }
  15.467 +	struct buffer_head *bh;
  15.468 +	unsigned long offset;
  15.469 +	unsigned long length;
  15.470 +	int rw;
  15.471 +	
  15.472 +	if(rq->plugged) 
  15.473 +	    return ; 
  15.474 +	
  15.475 +	req = CURRENT;
  15.476 +	
  15.477 +	if (XLBLK_DEBUG) 
  15.478 +	    printk (KERN_ALERT
  15.479 +		    "do_xlblk_request %p: cmd %i, sec %lx, (%li) bh:%p\n",
  15.480 +		    req, req->cmd, req->sector,
  15.481 +		    req->current_nr_sectors, req->bh);
  15.482 +	
  15.483 +	/* is there space in the tx ring for this request?
  15.484 +	 * if the ring is full, then leave the request in the queue
  15.485 +	 *
  15.486 +	 * THIS IS A BIT BOGUS SINCE XEN COULD BE UPDATING BTX_CONS
  15.487 +	 * AT THE SAME TIME
  15.488 +	 */
  15.489 +	{
  15.490 +	    blk_ring_t *blk_ring = start_info.blk_ring;
  15.491 +	    
  15.492 +	    if (BLK_RX_RING_INC(blk_ring->btx_prod) == blk_ring->btx_cons)
  15.493 +	    {
  15.494 +		printk (KERN_ALERT "OOPS, TX LOOKS FULL  cons: %d  prod: %d\n",
  15.495 +			blk_ring->btx_cons, blk_ring->btx_prod);
  15.496 +		BUG(); 
  15.497 +		break;
  15.498 +	    }
  15.499 +	}
  15.500 +	
  15.501 +	req->errors = 0;
  15.502 +	blkdev_dequeue_request(req);
  15.503 +	
  15.504 +	bh = req->bh;
  15.505 +	
  15.506 +	while (bh)
  15.507 +	{
  15.508 +	    offset = bh->b_rsector << 9;
  15.509 +	    length = bh->b_size;
  15.510 +	    
  15.511 +	    rw = req->cmd;
  15.512 +	    if (rw == READA)  rw= READ;
  15.513 +	    if ((rw != READ) && (rw != WRITE)) {
  15.514 +		printk (KERN_ALERT
  15.515 +			"XenoLinux Virtual Block Device: bad cmd: %d\n", rw);
  15.516 +		BUG();
  15.517 +	    }
  15.518  
  15.519 -    /* is there space in the tx ring for this request?
  15.520 -     * if the ring is full, then leave the request in the queue
  15.521 -     *
  15.522 -     * THIS IS A BIT BOGUS SINCE XEN COULD BE UPDATING TX_CONS
  15.523 -     * AT THE SAME TIME
  15.524 -     */
  15.525 -    {
  15.526 -      blk_ring_t *blk_ring = start_info.blk_ring;
  15.527 -      
  15.528 -      if (BLK_RX_RING_INC(blk_ring->tx_prod) == blk_ring->tx_cons)
  15.529 -      {
  15.530 -	printk (KERN_ALERT "OOPS, TX LOOKS FULL  cons: %d  prod: %d\n",
  15.531 -		blk_ring->tx_cons, blk_ring->tx_prod);
  15.532 -	break;
  15.533 -      }
  15.534 -    }
  15.535 +	    hypervisor_request (req, rw == READ ? 
  15.536 +				XEN_BLOCK_READ : XEN_BLOCK_WRITE, 
  15.537 +				bh->b_data, bh->b_rsector, bh->b_size, 
  15.538 +				bh->b_dev, XEN_BLOCK_SYNC);
  15.539 +	    bh = bh->b_reqnext;
  15.540 +	}
  15.541  
  15.542 -    req->errors = 0;
  15.543 -    blkdev_dequeue_request(req);
  15.544 -
  15.545 -    bh = req->bh;
  15.546 -
  15.547 -    while (bh)
  15.548 -    {
  15.549 +	blkdev_dequeue_request(req);
  15.550  
  15.551 -    offset = bh->b_rsector << 9;
  15.552 -    length = bh->b_size;
  15.553 -    
  15.554 -    rw = req->cmd;
  15.555 -    if (rw == READA)  rw= READ;
  15.556 -    if ((rw != READ) && (rw != WRITE))
  15.557 -    {
  15.558 -      printk (KERN_ALERT
  15.559 -	      "XenoLinux Virtual Block Device: bad command: %d\n", rw);
  15.560 -      BUG();
  15.561      }
  15.562  
  15.563 -    /*
  15.564 -    if (XLBLK_DEBUG)
  15.565 -    {
  15.566 -      printk (KERN_ALERT "xlblk.c::do_xlblk_request\n");
  15.567 -      printk (KERN_ALERT "  b_blocknr: 0x%lx %ld\n", 
  15.568 -                         bh->b_blocknr, bh->b_blocknr);
  15.569 -      printk (KERN_ALERT "  b_size:    0x%x  %d\n", bh->b_size, bh->b_size);
  15.570 -      printk (KERN_ALERT "  b_dev:     0x%x  %d\n", bh->b_dev, bh->b_dev);
  15.571 -      printk (KERN_ALERT "  b_rsector: 0x%lx %ld\n", 
  15.572 -                         bh->b_rsector, bh->b_rsector);
  15.573 -    }
  15.574 -    */
  15.575 -
  15.576 -    hypervisor_request (req, rw == READ ? XEN_BLOCK_READ : XEN_BLOCK_WRITE, 
  15.577 -			bh->b_data, bh->b_rsector, bh->b_size, 
  15.578 -			bh->b_dev, XEN_BLOCK_SYNC);
  15.579 -
  15.580 -      bh = bh->b_reqnext;
  15.581 -    }
  15.582 -  }
  15.583 -
  15.584 -  return;
  15.585 +    return;
  15.586  }
  15.587  
  15.588 -/*
  15.589 - * xenolinux_block_request
  15.590 - *
  15.591 - * read a block without using a request queue
  15.592 - */
  15.593 -
  15.594 -static int xenolinux_block_request(request_queue_t *rq,
  15.595 -				   int rw,
  15.596 -				   struct buffer_head *bh)
  15.597 -{
  15.598 -  unsigned int minor;
  15.599 -  unsigned long offset;
  15.600 -  unsigned long length;
  15.601 -
  15.602 -  if (XLBLK_DEBUG) {
  15.603 -    printk (KERN_ALERT "xlblk.c::xenolinux_block_request: %lx %d %lx\n",
  15.604 -	    (unsigned long) rq, rw, (unsigned long) bh); }
  15.605 -  /*
  15.606 -  printk (KERN_ALERT "xlblk.c::xlblk_request: op:%d bh:%p sect:%lu sz:%u\n",
  15.607 -	  rw,  bh, bh->b_rsector, bh->b_size);
  15.608 -  */
  15.609 -
  15.610 -  minor = MINOR(bh->b_rdev);
  15.611 -
  15.612 -  offset = bh->b_rsector << 9;
  15.613 -  length = bh->b_size;
  15.614 -
  15.615 -  if (rw == READA)  rw= READ;
  15.616 -  if ((rw != READ) && (rw != WRITE))
  15.617 -  {
  15.618 -    printk (KERN_ALERT 
  15.619 -	    "XenoLinux Virtual Block Device: bad command: %d\n", rw);
  15.620 -    goto fail;
  15.621 -  }
  15.622 -
  15.623 -  hypervisor_request (bh, rw == READ ? XEN_BLOCK_READ : XEN_BLOCK_WRITE, 
  15.624 -		      bh->b_data, bh->b_rsector, bh->b_size, 
  15.625 -		      bh->b_dev, XEN_BLOCK_SYNC);
  15.626 -
  15.627 -  return 0;
  15.628 -
  15.629 - fail:
  15.630 -  return 0;
  15.631 -}
  15.632  
  15.633  static struct block_device_operations xenolinux_block_fops = 
  15.634  {
  15.635 @@ -489,335 +384,208 @@ static struct block_device_operations xe
  15.636  
  15.637  static void xlblk_rx_int(int irq, void *dev_id, struct pt_regs *ptregs)
  15.638  {
  15.639 -  xlblk_device_t *dev = (xlblk_device_t *)dev_id;
  15.640 -  blk_ring_t *blk_ring = start_info.blk_ring;
  15.641 -  struct buffer_head *bh;
  15.642 -  struct request *req;
  15.643 -  int loop;
  15.644 -
  15.645 -  for (loop = blk_ring->rx_cons;
  15.646 -       loop != blk_ring->rx_prod;
  15.647 -       loop = BLK_RX_RING_INC(loop))
  15.648 -  {
  15.649 -    blk_ring_entry_t *bret = &blk_ring->rx_ring[loop];
  15.650 -    void *buffer_pa, *buffer_va; 
  15.651 -
  15.652 -    buffer_pa = machine_to_phys((unsigned long)bret->buffer); 
  15.653 -    buffer_va = phys_to_virt((unsigned long)buffer_pa); 
  15.654 +    blk_ring_t *blk_ring = start_info.blk_ring;
  15.655 +    struct request *req;
  15.656 +    int loop;
  15.657 +    u_long flags; 
  15.658      
  15.659 -#if 0
  15.660 -    printk(KERN_ALERT "xlblk_rx_int: buffer ma %p => pa %p => va %p\n", 
  15.661 -	   bret->buffer, buffer_pa, buffer_va); 
  15.662 -
  15.663 -
  15.664 -    if (XLBLK_DEBUG)
  15.665 -    {
  15.666 -      printk (KERN_ALERT 
  15.667 -	      "xlblock::xlblk_rx_int [%s]\n",
  15.668 -	      (bret->operation == XEN_BLOCK_READ) ? "read" : "write");
  15.669 -      printk (KERN_ALERT 
  15.670 -	      "   vbuf: %lx, pbuf: %lx, blockno: %lx, size: %x, device %x\n",
  15.671 -	      (unsigned long) buffer_va, (unsigned long) bret->buffer,
  15.672 -	      bret->block_number, bret->block_size, bret->device);
  15.673 -      printk (KERN_ALERT "   bret: %p  bh: %p\n", bret, bret->id); 
  15.674 -    }
  15.675 -
  15.676 -    /*
  15.677 -    printk (KERN_ALERT
  15.678 -	    "xlblk_rx: id:%p op:%d, bf:%p, blk:%lu, sz:%u, dev:%x\n",
  15.679 -	    bret->id, bret->operation, bret->buffer, bret->block_number,
  15.680 -	    bret->block_size, bret->device);
  15.681 -    */
  15.682 -#endif
  15.683 -
  15.684 -    if (USE_REQUEST_QUEUE)
  15.685 -    {
  15.686 -      req = (struct request *)bret->id;
  15.687 -      printk(KERN_ALERT "|%x|", req); 
  15.688 -
  15.689 -      if (!end_that_request_first(req, 1, "NAME"))
  15.690 -      {
  15.691 -	blkdev_dequeue_request(req);
  15.692 -
  15.693 -	/* should be end_that_request_last(req)
  15.694 -	   to wake up waiting processes (with complete) */
  15.695 -	blkdev_release_request(req);
  15.696 -      }
  15.697 +    for (loop = blk_ring->brx_cons;
  15.698 +	 loop != blk_ring->brx_prod;
  15.699 +	 loop = BLK_RX_RING_INC(loop)) {
  15.700  
  15.701 -      /*
  15.702 -	if (XLBLK_DEBUG)
  15.703 -	{
  15.704 -	  int temp;
  15.705 -	  printk(KERN_ALERT 
  15.706 -		 "buff: 0x%p, blkno: 0x%lx, size: 0x%x, device 0x%x [%p]\n",
  15.707 -		 vbuffer, bret->block_number, bret->block_size, bret->device,
  15.708 -		 bh->b_end_io); 
  15.709 +	blk_ring_entry_t *bret = &blk_ring->brx_ring[loop];
  15.710 +	
  15.711 +	if(bret->operation == XEN_BLOCK_PROBE)
  15.712 +	    continue; 
  15.713  
  15.714 -	  for (temp = 0; temp < bret->block_size; temp++)
  15.715 -	  {
  15.716 -	    if (temp % 16 == 0)       printk ("[%4x]  ", temp);
  15.717 -	    else if (temp % 4 == 0)   printk (" ");
  15.718 -	                              printk ("%02x",
  15.719 -					      vbuffer[temp] & 255);
  15.720 -            if ((temp + 1) % 16 == 0) printk ("\n");
  15.721 -	  }
  15.722 -	  printk ("\n\n");
  15.723 -	}
  15.724 -      */
  15.725 -
  15.726 -#ifdef BOGUS
  15.727 -      req = (struct request *)bret->id;
  15.728 -      while ((bh = req->bh) != NULL)
  15.729 -      {
  15.730 -	req->bh = bh->b_reqnext;
  15.731 -	bh->b_reqnext = NULL;
  15.732 -	bh->b_end_io(bh,1);
  15.733 -      }
  15.734 -      blkdev_release_request(req);
  15.735 -#endif /* BOGUS  */
  15.736 +	spin_lock_irqsave(&io_request_lock, flags);
  15.737 +	req = (struct request *)bret->id;
  15.738 +	    
  15.739 +	if (!end_that_request_first(req, 1, "XenBlk"))
  15.740 +	    end_that_request_last(req);
  15.741 +	spin_unlock_irqrestore(&io_request_lock, flags);
  15.742 +	
  15.743      }
  15.744 -    else
  15.745 -    {
  15.746 -      bh = (struct buffer_head *)bret->id;
  15.747 -      bh->b_end_io(bh,1);
  15.748 -
  15.749 -      /*
  15.750 -	if (XLBLK_DEBUG)
  15.751 -	{
  15.752 -	  int temp;
  15.753 -#if 0
  15.754 -	  printk(KERN_ALERT 
  15.755 -		 "buff: 0x%p, blkno: 0x%lx, size: 0x%x, device 0x%x [%p]\n",
  15.756 -		 vbuffer, bret->block_number, bret->block_size, bret->device,
  15.757 -		 bh->b_end_io); 
  15.758 -#endif
  15.759 -
  15.760 -	  for (temp = 0; temp < bret->block_size; temp++)
  15.761 -	  {
  15.762 -	    if (temp % 16 == 0)       printk ("[%4x]  ", temp);
  15.763 -	    else if (temp % 4 == 0)   printk (" ");
  15.764 -	                              printk ("%02x",
  15.765 -					      vbuffer[temp] & 255);
  15.766 -            if ((temp + 1) % 16 == 0) printk ("\n");
  15.767 -	  }
  15.768 -	  printk ("\n\n");
  15.769 -	}
  15.770 -      */    
  15.771 -    }
  15.772 -  }
  15.773 -
  15.774 -  blk_ring->rx_cons = loop;
  15.775 +    
  15.776 +    blk_ring->brx_cons = loop;
  15.777  }
  15.778  
  15.779  static void xlblk_tx_int(int irq, void *dev_id, struct pt_regs *ptregs)
  15.780  {
  15.781 -  if (XLBLK_DEBUG) {
  15.782 -    printk (KERN_ALERT "--- xlblock::xlblk_tx_int\n"); }
  15.783 +    if (XLBLK_DEBUG) 
  15.784 +	printk (KERN_ALERT "--- xlblock::xlblk_tx_int\n"); 
  15.785  }
  15.786  
  15.787  int __init xlblk_init(void)
  15.788  {
  15.789 -  blk_ring_t *blk_ring = start_info.blk_ring;
  15.790 -  int loop, error, result;
  15.791 -
  15.792 -  /*
  15.793 -   * initialize memory rings to communicate with hypervisor 
  15.794 -   */
  15.795 +    blk_ring_t *blk_ring = start_info.blk_ring;
  15.796 +    int loop, error, result;
  15.797  
  15.798 -  if ( blk_ring == NULL ) return -ENOMEM;
  15.799 -
  15.800 -  blk_ring->tx_prod = blk_ring->tx_cons = 0;
  15.801 -  blk_ring->rx_prod = blk_ring->rx_cons = 0;
  15.802 -  blk_ring->tx_ring = NULL;
  15.803 -  blk_ring->rx_ring = NULL;
  15.804 +    /* initialize memory rings to communicate with hypervisor */
  15.805 +    if ( blk_ring == NULL ) return -ENOMEM;
  15.806  
  15.807 -  blk_ring->tx_ring = kmalloc(BLK_TX_RING_SIZE * sizeof(blk_ring_entry_t),
  15.808 -			      GFP_KERNEL);
  15.809 -  blk_ring->rx_ring = kmalloc(BLK_RX_RING_SIZE * sizeof(blk_ring_entry_t),
  15.810 -			      GFP_KERNEL);
  15.811 -
  15.812 -  if ((blk_ring->tx_ring == NULL) ||
  15.813 -      (blk_ring->rx_ring == NULL))
  15.814 -  {
  15.815 -    printk (KERN_ALERT 
  15.816 -	    "error, could not allocate ring memory for block device\n");
  15.817 -    error = -ENOBUFS;
  15.818 -    goto fail;
  15.819 -  }
  15.820 +    blk_ring->btx_prod = blk_ring->btx_cons = 0;
  15.821 +    blk_ring->brx_prod = blk_ring->brx_cons = 0;
  15.822 +    blk_ring->btx_ring = NULL;
  15.823 +    blk_ring->brx_ring = NULL;
  15.824 +    
  15.825 +    blk_ring->btx_ring = kmalloc(BLK_TX_RING_SIZE * sizeof(blk_ring_entry_t),
  15.826 +				 GFP_KERNEL);
  15.827 +    blk_ring->brx_ring = kmalloc(BLK_RX_RING_SIZE * sizeof(blk_ring_entry_t),
  15.828 +				 GFP_KERNEL);
  15.829  
  15.830 -  /*
  15.831 -   * setup soft interrupts to communicate with hypervisor
  15.832 -   */
  15.833 -
  15.834 -  error = request_irq(XLBLK_RX_IRQ, xlblk_rx_int, 0, "xlblk-rx", 
  15.835 -		      &xlblk_device);
  15.836 -  if (error)
  15.837 -  {
  15.838 -    printk(KERN_ALERT "Could not allocate receive interrupt\n");
  15.839 -    goto fail;
  15.840 -  }
  15.841 +    if ((blk_ring->btx_ring == NULL) || (blk_ring->brx_ring == NULL)) {
  15.842 +	printk (KERN_ALERT "could not alloc ring memory for block device\n");
  15.843 +	error = -ENOBUFS;
  15.844 +	goto fail;
  15.845 +    }
  15.846 +    
  15.847 +    error = request_irq(XLBLK_RX_IRQ, xlblk_rx_int, 0, 
  15.848 +			"xlblk-rx", &xlblk_device);
  15.849 +    if (error) {
  15.850 +	printk(KERN_ALERT "Could not allocate receive interrupt\n");
  15.851 +	goto fail;
  15.852 +    }
  15.853  
  15.854 -  error = request_irq(XLBLK_TX_IRQ, xlblk_tx_int, 0, "xlblk-tx", 
  15.855 -		      &xlblk_device);
  15.856 -  if (error)
  15.857 -  {
  15.858 -    printk(KERN_ALERT "Could not allocate transmit interrupt\n");
  15.859 -    free_irq(XLBLK_RX_IRQ, &xlblk_device);
  15.860 -    goto fail;
  15.861 -  }
  15.862 +    error = request_irq(XLBLK_TX_IRQ, xlblk_tx_int, 0, 
  15.863 +			"xlblk-tx", &xlblk_device);
  15.864 +    if (error) {
  15.865 +	printk(KERN_ALERT "Could not allocate transmit interrupt\n");
  15.866 +	free_irq(XLBLK_RX_IRQ, &xlblk_device);
  15.867 +	goto fail;
  15.868 +    }
  15.869  
  15.870 -  /*
  15.871 -   * get information about physical drives
  15.872 -   *
  15.873 -   */
  15.874 -  {
  15.875 -    /* NOTE: this should only occur in domain 0 */
  15.876      memset (&xen_disk_info, 0, sizeof(xen_disk_info));
  15.877      xen_disk_info.count = 0;
  15.878  
  15.879      hypervisor_request(NULL, XEN_BLOCK_PROBE, (char *) &xen_disk_info,
  15.880  		       0, 0, (kdev_t) 0, XEN_BLOCK_SYNC);
  15.881 -
  15.882 -    {
  15.883 -      int loop;
  15.884 -      for (loop = 0; loop < xen_disk_info.count; loop++)
  15.885 -      {
  15.886 +    for (loop = 0; loop < xen_disk_info.count; loop++) 
  15.887  	printk (KERN_ALERT "  %2d: type: %d, capacity: %ld\n",
  15.888  		loop, xen_disk_info.disks[loop].type, 
  15.889  		xen_disk_info.disks[loop].capacity);
  15.890 -      }
  15.891 -    }
  15.892 -  }
  15.893 -
  15.894 -  /*
  15.895 -   * initialize device driver
  15.896 -   */
  15.897  
  15.898 -  SET_MODULE_OWNER(&xenolinux_block_fops);
  15.899 +    
  15.900 +    SET_MODULE_OWNER(&xenolinux_block_fops);
  15.901 +    result = register_blkdev(xlblk_major, "block", &xenolinux_block_fops);
  15.902 +    if (result < 0) {
  15.903 +	printk (KERN_ALERT "xenolinux block: can't get major %d\n",
  15.904 +		xlblk_major);
  15.905 +	return result;
  15.906 +    }
  15.907  
  15.908 -  result = register_blkdev(xlblk_major, "block", &xenolinux_block_fops);
  15.909 -  if (result < 0)
  15.910 -  {
  15.911 -    printk (KERN_ALERT "xenolinux block: can't get major %d\n", xlblk_major);
  15.912 -    return result;
  15.913 -  }
  15.914 +    /* initialize global arrays in drivers/block/ll_rw_block.c */
  15.915 +    for (loop = 0; loop < XLBLK_MAX; loop++) {
  15.916 +	xlblk_blk_size[loop]      = xen_disk_info.disks[0].capacity;
  15.917 +	xlblk_blksize_size[loop]  = 512;
  15.918 +	xlblk_hardsect_size[loop] = 512;
  15.919 +	xlblk_max_sectors[loop]   = 128;
  15.920 +    }
  15.921 +    xlblk_read_ahead  = 8; 
  15.922  
  15.923 -  /* initialize global arrays in drivers/block/ll_rw_block.c */
  15.924 -  blk_size[xlblk_major] = xlblk_blk_size;
  15.925 -  blksize_size[xlblk_major] = xlblk_blksize_size;
  15.926 -  hardsect_size[xlblk_major] = xlblk_hardsect_size;
  15.927 -  read_ahead[xlblk_major] = xlblk_read_ahead;
  15.928 -  max_sectors[xlblk_major] = xlblk_max_sectors;
  15.929 -  for (loop = 0; loop < XLBLK_MAX; loop++)
  15.930 -  {
  15.931 -    xlblk_blk_size[loop] = xen_disk_info.disks[0].capacity;
  15.932 -    xlblk_blksize_size[loop] = 512;
  15.933 -    xlblk_hardsect_size[loop] = 512;
  15.934 -    xlblk_read_ahead[loop] = 8; 
  15.935 -    xlblk_max_sectors[loop] = 128;
  15.936 -  }
  15.937 +    blk_size[xlblk_major]      = xlblk_blk_size;
  15.938 +    blksize_size[xlblk_major]  = xlblk_blksize_size;
  15.939 +    hardsect_size[xlblk_major] = xlblk_hardsect_size;
  15.940 +    read_ahead[xlblk_major]    = xlblk_read_ahead; 
  15.941 +    max_sectors[xlblk_major]   = xlblk_max_sectors;
  15.942  
  15.943 -  if (USE_REQUEST_QUEUE)
  15.944 -  {
  15.945 -    /* NEED TO MODIFY THIS TO HANDLE MULTIPLE QUEUES
  15.946 -     * also, should replace do_xlblk_request with blk.h::DEVICE_REQUEST
  15.947 -     */
  15.948      blk_init_queue(BLK_DEFAULT_QUEUE(xlblk_major), do_xlblk_request);
  15.949 +    /* 
  15.950 +    ** XXX SMH: we don't leave req on queue => are happy for evelator
  15.951 +    ** to reorder things including it. (main reason for this decision
  15.952 +    ** is that it works while 'standard' case doesn't. Ho hum). 
  15.953 +    */
  15.954      blk_queue_headactive(BLK_DEFAULT_QUEUE(xlblk_major), 0);
  15.955 -  }
  15.956 -  else
  15.957 -  {
  15.958 -    /* we don't use __make_request in ll_rw_blk */
  15.959 -    blk_queue_make_request(BLK_DEFAULT_QUEUE(xlblk_major), 
  15.960 -			   xenolinux_block_request);
  15.961 -  }
  15.962 -  xlblk_ide_register_disk(0, xen_disk_info.disks[0].capacity);
  15.963 +
  15.964 +    xlblk_ide_register_disk(0, xen_disk_info.disks[0].capacity);
  15.965  
  15.966 -  /*
  15.967 -   * completion 
  15.968 -   */
  15.969 -  printk(KERN_ALERT 
  15.970 -	 "XenoLinux Virtual Block Device Driver installed [device: %d]\n",
  15.971 -	 xlblk_major);
  15.972 -  return 0;
  15.973 +    printk(KERN_ALERT 
  15.974 +	   "XenoLinux Virtual Block Device Driver installed [device: %d]\n",
  15.975 +	   xlblk_major);
  15.976 +    return 0;
  15.977  
  15.978   fail:
  15.979 -  if (blk_ring->tx_ring) kfree(blk_ring->tx_ring);
  15.980 -  if (blk_ring->rx_ring) kfree(blk_ring->rx_ring);
  15.981 -  return error;
  15.982 +    if (blk_ring->btx_ring) kfree(blk_ring->btx_ring);
  15.983 +    if (blk_ring->brx_ring) kfree(blk_ring->brx_ring);
  15.984 +    return error;
  15.985  }
  15.986  
  15.987  void xlblk_ide_register_disk(int idx, unsigned long capacity)
  15.988  {
  15.989 -  int units;
  15.990 -  int minors;
  15.991 -  struct gendisk *gd;
  15.992 -
  15.993 -  /* plagarized from ide-probe.c::init_gendisk */
  15.994 +    int units;
  15.995 +    int minors;
  15.996 +    struct gendisk *gd;
  15.997  
  15.998 -  units = 2;                                       /* from ide.h::MAX_DRIVES */
  15.999 -
 15.1000 -  minors    = units * (1<<IDE_PARTN_BITS);
 15.1001 -  gd        = kmalloc (sizeof(struct gendisk), GFP_KERNEL);
 15.1002 -  gd->sizes = kmalloc (minors * sizeof(int), GFP_KERNEL);
 15.1003 -  gd->part  = kmalloc (minors * sizeof(struct hd_struct), GFP_KERNEL);
 15.1004 -  memset(gd->part, 0, minors * sizeof(struct hd_struct));
 15.1005 +    /* plagarized from ide-probe.c::init_gendisk */
 15.1006 +    
 15.1007 +    units = 2; /* from ide.h::MAX_DRIVES */
 15.1008  
 15.1009 -  gd->major       = xlblk_major;                  /* our major device number */
 15.1010 -  gd->major_name  = XLBLK_MAJOR_NAME;          /* treated special in genhd.c */
 15.1011 -  gd->minor_shift = IDE_PARTN_BITS;               /* num bits for partitions */
 15.1012 -  gd->max_p	  = 1<<IDE_PARTN_BITS;         /* 1 + max partitions / drive */
 15.1013 -  gd->nr_real	  = units;                        /* current num real drives */
 15.1014 -  gd->real_devices= NULL;                /* ptr to internal data (was: hwif) */
 15.1015 -  gd->next	  = NULL;                       /* linked list of major devs */
 15.1016 -  gd->fops        = &xenolinux_block_fops;                /* file operations */
 15.1017 -  gd->de_arr      = kmalloc (sizeof *gd->de_arr * units, GFP_KERNEL);
 15.1018 -  gd->flags	  = kmalloc (sizeof *gd->flags * units, GFP_KERNEL);
 15.1019 -  if (gd->de_arr)   memset (gd->de_arr, 0, sizeof *gd->de_arr * units);
 15.1020 -  if (gd->flags)    memset (gd->flags, 0, sizeof *gd->flags * units);
 15.1021 -  add_gendisk(gd);
 15.1022 +    minors    = units * (1<<IDE_PARTN_BITS);
 15.1023 +    gd        = kmalloc (sizeof(struct gendisk), GFP_KERNEL);
 15.1024 +    gd->sizes = kmalloc (minors * sizeof(int), GFP_KERNEL);
 15.1025 +    gd->part  = kmalloc (minors * sizeof(struct hd_struct), GFP_KERNEL);
 15.1026 +    memset(gd->part, 0, minors * sizeof(struct hd_struct));
 15.1027 +    
 15.1028 +    gd->major        = xlblk_major;  
 15.1029 +    gd->major_name   = XLBLK_MAJOR_NAME;
 15.1030 +    gd->minor_shift  = IDE_PARTN_BITS; 
 15.1031 +    gd->max_p	     = 1<<IDE_PARTN_BITS;
 15.1032 +    gd->nr_real	     = units;           
 15.1033 +    gd->real_devices = NULL;          
 15.1034 +    gd->next	     = NULL;            
 15.1035 +    gd->fops         = &xenolinux_block_fops;
 15.1036 +    gd->de_arr       = kmalloc (sizeof *gd->de_arr * units, GFP_KERNEL);
 15.1037 +    gd->flags	     = kmalloc (sizeof *gd->flags * units, GFP_KERNEL);
 15.1038  
 15.1039 -  xen_disk_info.disks[idx].gendisk = gd;
 15.1040 +    if (gd->de_arr)  
 15.1041 +	memset (gd->de_arr, 0, sizeof *gd->de_arr * units);
 15.1042 +
 15.1043 +    if (gd->flags) 
 15.1044 +	memset (gd->flags, 0, sizeof *gd->flags * units);
 15.1045 +
 15.1046 +    add_gendisk(gd);
 15.1047 +
 15.1048 +    xen_disk_info.disks[idx].gendisk = gd;
 15.1049  
 15.1050 -  /* default disk size is just a big number.  in the future, we
 15.1051 -     need a message to probe the devices to determine the actual size */
 15.1052 -  register_disk(gd, MKDEV(xlblk_major, 0), 1<<IDE_PARTN_BITS,
 15.1053 -		&xenolinux_block_fops, capacity);
 15.1054 +    /* default disk size is just a big number.  in the future, we
 15.1055 +       need a message to probe the devices to determine the actual size */
 15.1056 +    register_disk(gd, MKDEV(xlblk_major, 0), 1<<IDE_PARTN_BITS,
 15.1057 +		  &xenolinux_block_fops, capacity);
 15.1058  
 15.1059 -  return;
 15.1060 +    return;
 15.1061  }
 15.1062  
 15.1063 +
 15.1064 +
 15.1065  static void __exit xlblk_cleanup(void)
 15.1066  {
 15.1067 -  /* CHANGE FOR MULTIQUEUE */
 15.1068 -  blk_cleanup_queue(BLK_DEFAULT_QUEUE(xlblk_major));
 15.1069 +    /* CHANGE FOR MULTIQUEUE */
 15.1070 +    blk_cleanup_queue(BLK_DEFAULT_QUEUE(xlblk_major));
 15.1071 +
 15.1072 +    /* clean up global arrays */
 15.1073 +    read_ahead[xlblk_major] = 0;
 15.1074  
 15.1075 -  /* clean up global arrays */
 15.1076 -  read_ahead[xlblk_major] = 0;
 15.1077 -  if (blk_size[xlblk_major]) kfree(blk_size[xlblk_major]);
 15.1078 -  blk_size[xlblk_major] = NULL;
 15.1079 -  if (blksize_size[xlblk_major]) kfree(blksize_size[xlblk_major]);
 15.1080 -  blksize_size[xlblk_major] = NULL;
 15.1081 -  if (hardsect_size[xlblk_major]) kfree(hardsect_size[xlblk_major]);
 15.1082 -  hardsect_size[xlblk_major] = NULL;
 15.1083 +    if (blk_size[xlblk_major]) 
 15.1084 +	kfree(blk_size[xlblk_major]);
 15.1085 +    blk_size[xlblk_major] = NULL;
 15.1086 +
 15.1087 +    if (blksize_size[xlblk_major]) 
 15.1088 +	kfree(blksize_size[xlblk_major]);
 15.1089 +    blksize_size[xlblk_major] = NULL;
 15.1090  
 15.1091 -  /*
 15.1092 -   *
 15.1093 -   * TODO: FOR EACH GENDISK, FREE 
 15.1094 -   *
 15.1095 -   */
 15.1096 +    if (hardsect_size[xlblk_major]) 
 15.1097 +	kfree(hardsect_size[xlblk_major]);
 15.1098 +    hardsect_size[xlblk_major] = NULL;
 15.1099 +    
 15.1100 +    /* XXX: free each gendisk */
 15.1101 +    if (unregister_blkdev(xlblk_major, "block"))
 15.1102 +	printk(KERN_ALERT
 15.1103 +	       "XenoLinux Virtual Block Device Driver uninstalled w/ errs\n");
 15.1104 +    else
 15.1105 +	printk(KERN_ALERT 
 15.1106 +	       "XenoLinux Virtual Block Device Driver uninstalled\n");
 15.1107  
 15.1108 -  if (unregister_blkdev(xlblk_major, "block"))
 15.1109 -  {
 15.1110 -    printk(KERN_ALERT
 15.1111 -	   "XenoLinux Virtual Block Device Driver uninstalled with errors\n");
 15.1112 -  }
 15.1113 -  else
 15.1114 -  {
 15.1115 -    printk(KERN_ALERT "XenoLinux Virtual Block Device Driver uninstalled\n");
 15.1116 -  }
 15.1117 -
 15.1118 -  return;
 15.1119 +    return;
 15.1120  }
 15.1121  
 15.1122  
    16.1 --- a/xenolinux-2.4.16-sparse/drivers/block/ll_rw_blk.c	Thu Feb 13 18:08:51 2003 +0000
    16.2 +++ b/xenolinux-2.4.16-sparse/drivers/block/ll_rw_blk.c	Fri Feb 14 12:26:26 2003 +0000
    16.3 @@ -533,6 +533,8 @@ static inline void add_request(request_q
    16.4  
    16.5  	if (!q->plugged && q->head_active && insert_here == &q->queue_head) {
    16.6  		spin_unlock_irq(&io_request_lock);
    16.7 +		printk("list_empty(&q->queue_head) is %d\n", 
    16.8 +		       list_empty(&q->queue_head)); 
    16.9  		BUG();
   16.10  	}
   16.11  
   16.12 @@ -771,6 +773,7 @@ get_rq:
   16.13  	req->bhtail = bh;
   16.14  	req->rq_dev = bh->b_rdev;
   16.15  	blk_started_io(count);
   16.16 +
   16.17  	add_request(q, req, insert_here);
   16.18  out:
   16.19  	if (freereq)
    17.1 --- a/xenolinux-2.4.16-sparse/include/linux/blk.h	Thu Feb 13 18:08:51 2003 +0000
    17.2 +++ b/xenolinux-2.4.16-sparse/include/linux/blk.h	Fri Feb 14 12:26:26 2003 +0000
    17.3 @@ -326,7 +326,7 @@ static void floppy_off(unsigned int nr);
    17.4  
    17.5  #elif (MAJOR_NR == XLBLK_MAJOR)
    17.6  
    17.7 -#define DEVICE_NAME "blk"
    17.8 +#define DEVICE_NAME "xeno disk"
    17.9  #define DEVICE_REQUEST do_xlblk_request
   17.10  /* #define DEVICE_INTR */
   17.11  #define DEVICE_NR(device) (MINOR(device))
    18.1 --- a/xenolinux-2.4.16-sparse/init/main.c	Thu Feb 13 18:08:51 2003 +0000
    18.2 +++ b/xenolinux-2.4.16-sparse/init/main.c	Fri Feb 14 12:26:26 2003 +0000
    18.3 @@ -149,7 +149,7 @@ static struct dev_name_struct {
    18.4  	const int num;
    18.5  } root_dev_names[] __initdata = {
    18.6  	{ "nfs",     0x00ff },
    18.7 -        { "blk",     0x7b00 },
    18.8 +    { "xhda",    0x7b00 },
    18.9  	{ "hda",     0x0300 },
   18.10  	{ "hdb",     0x0340 },
   18.11  	{ "loop",    0x0700 },