ia64/xen-unstable

changeset 2591:aa75f00efa54

bitkeeper revision 1.1159.99.1 (41614d0bCFm_w7iZTkZCC7k5oNSaqw)

Cleanup device initialization.
Add support for bidirectional virtual consoles.
author cl349@freefall.cl.cam.ac.uk
date Mon Oct 04 13:15:55 2004 +0000 (2004-10-04)
parents 80fce5fd8284
children 654b2df93458
files netbsd-2.0-xen-sparse/sys/arch/xen/i386/hypervisor_machdep.c netbsd-2.0-xen-sparse/sys/arch/xen/include/if_xennetvar.h netbsd-2.0-xen-sparse/sys/arch/xen/include/xbdvar.h netbsd-2.0-xen-sparse/sys/arch/xen/xen/ctrl_if.c netbsd-2.0-xen-sparse/sys/arch/xen/xen/hypervisor.c netbsd-2.0-xen-sparse/sys/arch/xen/xen/if_xennet.c netbsd-2.0-xen-sparse/sys/arch/xen/xen/xbd.c netbsd-2.0-xen-sparse/sys/arch/xen/xen/xencons.c
line diff
     1.1 --- a/netbsd-2.0-xen-sparse/sys/arch/xen/i386/hypervisor_machdep.c	Sat Oct 02 14:25:55 2004 +0000
     1.2 +++ b/netbsd-2.0-xen-sparse/sys/arch/xen/i386/hypervisor_machdep.c	Mon Oct 04 13:15:55 2004 +0000
     1.3 @@ -127,8 +127,7 @@ stipending()
     1.4  					hypervisor_acknowledge_irq(irq);
     1.5  					ci->ci_ipending |= (1 << irq);
     1.6  					if (ret == 0 && ci->ci_ilevel <
     1.7 -					    ci->ci_isources[irq]->is_handlers
     1.8 -					    ->ih_level)
     1.9 +					    ci->ci_isources[irq]->is_maxlevel)
    1.10  						ret = 1;
    1.11  				}
    1.12  #if 0 /* XXXcl dev/evtchn */
     2.1 --- a/netbsd-2.0-xen-sparse/sys/arch/xen/include/if_xennetvar.h	Sat Oct 02 14:25:55 2004 +0000
     2.2 +++ b/netbsd-2.0-xen-sparse/sys/arch/xen/include/if_xennetvar.h	Mon Oct 04 13:15:55 2004 +0000
     2.3 @@ -81,6 +81,8 @@ struct xennet_softc {
     2.4  
     2.5  	netif_tx_interface_t	*sc_tx;
     2.6  	netif_rx_interface_t	*sc_rx;
     2.7 +	struct vm_page		*sc_pg_tx;
     2.8 +	struct vm_page		*sc_pg_rx;
     2.9  
    2.10  	uint32_t		sc_tx_entries;
    2.11  	uint32_t		sc_tx_resp_cons;
    2.12 @@ -102,6 +104,7 @@ struct xennet_attach_args {
    2.13  struct nfs_diskless;
    2.14  
    2.15  int xennet_scan(struct device *, struct xennet_attach_args *, cfprint_t);
    2.16 +void xennet_scan_finish(struct device *);
    2.17  void xennet_start(struct ifnet *);
    2.18  int xennet_ioctl(struct ifnet *ifp, u_long cmd, caddr_t data);
    2.19  void xennet_watchdog(struct ifnet *ifp);
     3.1 --- a/netbsd-2.0-xen-sparse/sys/arch/xen/include/xbdvar.h	Sat Oct 02 14:25:55 2004 +0000
     3.2 +++ b/netbsd-2.0-xen-sparse/sys/arch/xen/include/xbdvar.h	Mon Oct 04 13:15:55 2004 +0000
     3.3 @@ -52,5 +52,6 @@ struct xbd_attach_args {
     3.4  };
     3.5  
     3.6  int xbd_scan(struct device *, struct xbd_attach_args *, cfprint_t);
     3.7 +void xbd_scan_finish(struct device *);
     3.8  
     3.9  #endif /* _XEN_XBDVAR_H_ */
     4.1 --- a/netbsd-2.0-xen-sparse/sys/arch/xen/xen/ctrl_if.c	Sat Oct 02 14:25:55 2004 +0000
     4.2 +++ b/netbsd-2.0-xen-sparse/sys/arch/xen/xen/ctrl_if.c	Mon Oct 04 13:15:55 2004 +0000
     4.3 @@ -20,8 +20,9 @@
     4.4  #include <machine/ctrl_if.h>
     4.5  #include <machine/evtchn.h>
     4.6  
     4.7 +void printk(char *, ...);
     4.8  #if 0
     4.9 -#define DPRINTK(_f, _a...) printf("(file=%s, line=%d) " _f, \
    4.10 +#define DPRINTK(_f, _a...) printk("(file=%s, line=%d) " _f, \
    4.11                             __FILE__ , __LINE__ , ## _a )
    4.12  #else
    4.13  #define DPRINTK(_f, _a...) ((void)0)
    4.14 @@ -34,7 +35,7 @@
    4.15   */
    4.16  int initdom_ctrlif_domcontroller_port = -1;
    4.17  
    4.18 -static int ctrl_if_evtchn;
    4.19 +/* static */ int ctrl_if_evtchn = -1;
    4.20  static int ctrl_if_irq;
    4.21  static struct simplelock ctrl_if_lock;
    4.22  
    4.23 @@ -148,9 +149,10 @@ static void __ctrl_if_rxmsg_deferred(voi
    4.24  
    4.25  	while ( ctrl_if_rxmsg_deferred_cons != dp )
    4.26  	{
    4.27 -		msg = &ctrl_if_rxmsg_deferred[MASK_CONTROL_IDX(
    4.28 -						      ctrl_if_rxmsg_deferred_cons++)];
    4.29 +		msg = &ctrl_if_rxmsg_deferred[
    4.30 +		    MASK_CONTROL_IDX(ctrl_if_rxmsg_deferred_cons)];
    4.31  		(*ctrl_if_rxmsg_handler[msg->type])(msg, 0);
    4.32 +		ctrl_if_rxmsg_deferred_cons++;
    4.33  	}
    4.34  }
    4.35  
    4.36 @@ -166,7 +168,7 @@ static void __ctrl_if_rx_tasklet(unsigne
    4.37  
    4.38      while ( ctrl_if_rx_req_cons != rp )
    4.39      {
    4.40 -        pmsg = &ctrl_if->rx_ring[MASK_CONTROL_IDX(ctrl_if_rx_req_cons++)];
    4.41 +        pmsg = &ctrl_if->rx_ring[MASK_CONTROL_IDX(ctrl_if_rx_req_cons)];
    4.42          memcpy(&msg, pmsg, offsetof(ctrl_msg_t, msg));
    4.43  
    4.44          DPRINTK("Rx-Req %u/%u :: %d/%d\n", 
    4.45 @@ -184,6 +186,8 @@ static void __ctrl_if_rx_tasklet(unsigne
    4.46                     &msg, offsetof(ctrl_msg_t, msg) + msg.length);
    4.47          else
    4.48              (*ctrl_if_rxmsg_handler[msg.type])(&msg, 0);
    4.49 +
    4.50 +	ctrl_if_rx_req_cons++;
    4.51      }
    4.52  
    4.53      if ( dp != ctrl_if_rxmsg_deferred_prod )
    4.54 @@ -206,11 +210,15 @@ static int ctrl_if_interrupt(void *arg)
    4.55      if ( ctrl_if_tx_resp_cons != ctrl_if->tx_resp_prod ||
    4.56  	ctrl_if_rx_req_cons != ctrl_if->rx_req_prod ) {
    4.57  #if 0
    4.58 +#if 0
    4.59  	    wakeup(&ctrl_if_kthread);
    4.60  #else
    4.61  	    if (ctrl_if_softintr)
    4.62  		    softintr_schedule(ctrl_if_softintr);
    4.63  #endif
    4.64 +#else
    4.65 +	    ctrl_if_kthread((void *)1);
    4.66 +#endif
    4.67      }
    4.68  
    4.69      return 0;
    4.70 @@ -225,6 +233,7 @@ ctrl_if_send_message_noblock(
    4.71      control_if_t *ctrl_if = get_ctrl_if();
    4.72      unsigned long flags;
    4.73      int           i;
    4.74 +    int s;
    4.75  
    4.76      save_and_cli(flags);
    4.77      simple_lock(&ctrl_if_lock);
    4.78 @@ -233,7 +242,11 @@ ctrl_if_send_message_noblock(
    4.79      {
    4.80          simple_unlock(&ctrl_if_lock);
    4.81  	restore_flags(flags);
    4.82 -        return -EAGAIN;
    4.83 +	s = splhigh();
    4.84 +	if ( ctrl_if_tx_resp_cons != ctrl_if->tx_resp_prod )
    4.85 +		__ctrl_if_tx_tasklet(0);
    4.86 +	splx(s);
    4.87 +        return EAGAIN;
    4.88      }
    4.89  
    4.90      msg->id = 0xFF;
    4.91 @@ -275,10 +288,13 @@ ctrl_if_send_message_block(
    4.92  
    4.93  	while ((rc = ctrl_if_send_message_noblock(msg, hnd, id)) == EAGAIN) {
    4.94  		/* XXXcl possible race -> add a lock and ltsleep */
    4.95 +#if 1
    4.96 +#else
    4.97  		rc = tsleep((caddr_t) &ctrl_if_tx_wait, PUSER | PCATCH,
    4.98  		    "ctrl_if", 0);
    4.99  		if (rc)
   4.100  			break;
   4.101 +#endif
   4.102  	}
   4.103  
   4.104  	return rc;
   4.105 @@ -456,7 +472,6 @@ ctrl_if_kthread(void *arg)
   4.106  {
   4.107  	control_if_t *ctrl_if = get_ctrl_if();
   4.108  
   4.109 -	// printf("ctrl_if_kthread starting\n");
   4.110  	for (;;) {
   4.111  		if ( ctrl_if_tx_resp_cons != ctrl_if->tx_resp_prod )
   4.112  			__ctrl_if_tx_tasklet(0);
   4.113 @@ -464,10 +479,6 @@ ctrl_if_kthread(void *arg)
   4.114  		if ( ctrl_if_rx_req_cons != ctrl_if->rx_req_prod )
   4.115  			__ctrl_if_rx_tasklet(0);
   4.116  
   4.117 -		if ( ctrl_if_rxmsg_deferred_cons !=
   4.118 -		    ctrl_if_rxmsg_deferred_prod )
   4.119 -			__ctrl_if_rxmsg_deferred(NULL);
   4.120 -
   4.121  		if (arg) {
   4.122  			// printf("ctrl_if_kthread one-shot done\n");
   4.123  			return;
   4.124 @@ -479,13 +490,19 @@ ctrl_if_kthread(void *arg)
   4.125  }
   4.126  
   4.127  static void
   4.128 -ctrl_if_create_kthread(void *arg)
   4.129 +ctrl_if_softintr_handler(void *arg)
   4.130  {
   4.131 +	static int in_handler = 0;
   4.132  
   4.133 -	printf("ctrl_if_kthread creating\n");
   4.134 -	if (kthread_create1(ctrl_if_kthread, arg, NULL, "ctrl_if"))
   4.135 -		printf("ctrl_if_kthread create failed\n");
   4.136 -	softintr_schedule(ctrl_if_softintr);
   4.137 +	if (in_handler++ != 0) {
   4.138 +		ctrl_if_evtchn = -1;
   4.139 +		panic("recurse");
   4.140 +	}
   4.141 +
   4.142 +	if ( ctrl_if_rxmsg_deferred_cons != ctrl_if_rxmsg_deferred_prod )
   4.143 +		__ctrl_if_rxmsg_deferred(NULL);
   4.144 +
   4.145 +	in_handler--;
   4.146  }
   4.147  
   4.148  #ifdef notyet
   4.149 @@ -528,20 +545,29 @@ void ctrl_if_resume(void)
   4.150      hypervisor_enable_irq(ctrl_if_irq);
   4.151  }
   4.152  
   4.153 +void ctrl_if_early_init(void);
   4.154 +void ctrl_if_early_init(void)
   4.155 +{
   4.156 +
   4.157 +	simple_lock_init(&ctrl_if_lock);
   4.158 +
   4.159 +	ctrl_if_evtchn = xen_start_info.domain_controller_evtchn;
   4.160 +}
   4.161 +
   4.162  void ctrl_if_init(void)
   4.163  {
   4.164 -        int i;
   4.165 +	int i;
   4.166  
   4.167 -    for ( i = 0; i < 256; i++ )
   4.168 -        ctrl_if_rxmsg_handler[i] = ctrl_if_rxmsg_default_handler;
   4.169 +	for ( i = 0; i < 256; i++ )
   4.170 +		ctrl_if_rxmsg_handler[i] = ctrl_if_rxmsg_default_handler;
   4.171  
   4.172 -    simple_lock_init(&ctrl_if_lock);
   4.173 +	if (ctrl_if_evtchn == -1)
   4.174 +		ctrl_if_early_init();
   4.175  
   4.176 -    if (0) kthread_create(ctrl_if_create_kthread, NULL);
   4.177 -    ctrl_if_softintr =
   4.178 -	    softintr_establish(IPL_SOFTNET, ctrl_if_kthread, (void *)1);
   4.179 +	ctrl_if_softintr = softintr_establish(IPL_SOFTNET,
   4.180 +	    ctrl_if_softintr_handler, NULL);
   4.181  
   4.182 -    ctrl_if_resume();
   4.183 +	ctrl_if_resume();
   4.184  }
   4.185  
   4.186  
     5.1 --- a/netbsd-2.0-xen-sparse/sys/arch/xen/xen/hypervisor.c	Sat Oct 02 14:25:55 2004 +0000
     5.2 +++ b/netbsd-2.0-xen-sparse/sys/arch/xen/xen/hypervisor.c	Mon Oct 04 13:15:55 2004 +0000
     5.3 @@ -133,6 +133,18 @@ hypervisor_match(parent, match, aux)
     5.4  	return 0;
     5.5  }
     5.6  
     5.7 +static void
     5.8 +scan_finish(struct device *parent)
     5.9 +{
    5.10 +
    5.11 +#if NXENNET > 0
    5.12 +	xennet_scan_finish(parent);
    5.13 +#endif
    5.14 +#if NXBD > 0
    5.15 +	xbd_scan_finish(parent);
    5.16 +#endif
    5.17 +}
    5.18 +
    5.19  /*
    5.20   * Attach the hypervisor.
    5.21   */
    5.22 @@ -183,6 +195,9 @@ hypervisor_attach(parent, self, aux)
    5.23  		xenvfr_init();
    5.24  	}
    5.25  #endif
    5.26 +#if NXENNET > 0 || NXBD > 0
    5.27 +	config_interrupts(self, scan_finish);
    5.28 +#endif
    5.29  }
    5.30  
    5.31  int
     6.1 --- a/netbsd-2.0-xen-sparse/sys/arch/xen/xen/if_xennet.c	Sat Oct 02 14:25:55 2004 +0000
     6.2 +++ b/netbsd-2.0-xen-sparse/sys/arch/xen/xen/if_xennet.c	Mon Oct 04 13:15:55 2004 +0000
     6.3 @@ -106,8 +106,9 @@
     6.4  #define XEDB_MBUF	0x08
     6.5  #define XEDB_MEM	0x10
     6.6  int xennet_debug = 0x0;
     6.7 -#define DPRINTF(x) if (xennet_debug) printf x;
     6.8 -#define DPRINTFN(n,x) if (xennet_debug & (n)) printf x;
     6.9 +void printk(char *, ...);
    6.10 +#define DPRINTF(x) if (xennet_debug) printk x;
    6.11 +#define DPRINTFN(n,x) if (xennet_debug & (n)) printk x;
    6.12  #else
    6.13  #define DPRINTF(x)
    6.14  #define DPRINTFN(n,x)
    6.15 @@ -174,13 +175,21 @@ static int nxennet_media = (sizeof(xenne
    6.16  #endif
    6.17  
    6.18  
    6.19 +static int
    6.20 +xennet_wait_for_interfaces(void)
    6.21 +{
    6.22 +
    6.23 +	while (netctrl.xc_interfaces != netctrl.xc_connected)
    6.24 +		HYPERVISOR_yield();
    6.25 +	return 0;
    6.26 +}
    6.27 +
    6.28  int
    6.29  xennet_scan(struct device *self, struct xennet_attach_args *xneta,
    6.30      cfprint_t print)
    6.31  {
    6.32  	ctrl_msg_t cmsg;
    6.33  	netif_fe_driver_status_t st;
    6.34 -	int err = 0;
    6.35  
    6.36  	if ((xen_start_info.flags & SIF_INITDOMAIN) ||
    6.37  	    (xen_start_info.flags & SIF_NET_BE_DOMAIN))
    6.38 @@ -203,13 +212,17 @@ xennet_scan(struct device *self, struct 
    6.39  	memcpy(cmsg.msg, &st, sizeof(st));
    6.40  	ctrl_if_send_message_block(&cmsg, NULL, 0, 0);
    6.41  
    6.42 -#if 0
    6.43 +	return 0;
    6.44 +}
    6.45 +
    6.46 +void
    6.47 +xennet_scan_finish(struct device *parent)
    6.48 +{
    6.49 +	int err;
    6.50 +
    6.51  	err = xennet_wait_for_interfaces();
    6.52  	if (err)
    6.53  		ctrl_if_unregister_receiver(CMSG_NETIF_FE, xennet_ctrlif_rx);
    6.54 -#endif
    6.55 -
    6.56 -	return err;
    6.57  }
    6.58  
    6.59  int
    6.60 @@ -270,7 +283,7 @@ find_device(int handle)
    6.61  		if (xs->sc_ifno == handle)
    6.62  			break;
    6.63  	}
    6.64 -	return xs;
    6.65 +	return dv ? xs : NULL;
    6.66  }
    6.67  
    6.68  static void
    6.69 @@ -278,6 +291,7 @@ xennet_ctrlif_rx(ctrl_msg_t *msg, unsign
    6.70  {
    6.71  	int respond = 1;
    6.72  
    6.73 +	DPRINTFN(XEDB_EVENT, ("> ctrlif_rx=%d\n", msg->subtype));
    6.74  	switch (msg->subtype) {
    6.75  	case CMSG_NETIF_FE_INTERFACE_STATUS:
    6.76  		if (msg->length != sizeof(netif_fe_interface_status_t))
    6.77 @@ -307,7 +321,8 @@ static void
    6.78  xennet_driver_status_change(netif_fe_driver_status_t *status)
    6.79  {
    6.80  
    6.81 -	DPRINTFN(XEDB_EVENT, ("> status=%d\n", status->status));
    6.82 +	DPRINTFN(XEDB_EVENT, ("xennet_driver_status_change(%d)\n",
    6.83 +		     status->status));
    6.84  
    6.85  	netctrl.xc_up = status->status;
    6.86  	xennet_driver_count_connected();
    6.87 @@ -340,10 +355,9 @@ xennet_interface_status_change(netif_fe_
    6.88  	netif_fe_interface_connect_t up;
    6.89  	struct xennet_softc *sc;
    6.90  	struct ifnet *ifp;
    6.91 -	struct vm_page *pg_tx, *pg_rx;
    6.92  	struct xennet_attach_args xneta;
    6.93  
    6.94 -	DPRINTFN(XEDB_EVENT, ("> status=%d handle=%d mac=%02x:%02x:%02x:%02x:%02x:%02x\n",
    6.95 +	DPRINTFN(XEDB_EVENT, ("xennet_interface_status_change(%d,%d,%02x:%02x:%02x:%02x:%02x:%02x)\n",
    6.96  	    status->status,
    6.97  	    status->handle,
    6.98  	    status->mac[0], status->mac[1], status->mac[2],
    6.99 @@ -363,6 +377,11 @@ xennet_interface_status_change(netif_fe_
   6.100  	}
   6.101  	ifp = &sc->sc_ethercom.ec_if;
   6.102  
   6.103 +	DPRINTFN(XEDB_EVENT, ("xennet_interface_status_change(%d,%p,%02x:%02x:%02x:%02x:%02x:%02x)\n",
   6.104 +		     status->handle, sc,
   6.105 +		     status->mac[0], status->mac[1], status->mac[2],
   6.106 +		     status->mac[3], status->mac[4], status->mac[5]));
   6.107 +
   6.108  	switch (status->status) {
   6.109  	case NETIF_INTERFACE_STATUS_CLOSED:
   6.110  		printf("Unexpected netif-CLOSED message in state %d\n",
   6.111 @@ -411,28 +430,30 @@ xennet_interface_status_change(netif_fe_
   6.112  		}
   6.113  #endif
   6.114  
   6.115 -		/* Move from CLOSED to DISCONNECTED state. */
   6.116 -		sc->sc_tx = (netif_tx_interface_t *)
   6.117 -			uvm_km_valloc_align(kernel_map, PAGE_SIZE, PAGE_SIZE);
   6.118 -		if (sc->sc_tx == NULL)
   6.119 -			panic("netif: no tx va");
   6.120 -		sc->sc_rx = (netif_rx_interface_t *)
   6.121 -			uvm_km_valloc_align(kernel_map, PAGE_SIZE, PAGE_SIZE);
   6.122 -		if (sc->sc_rx == NULL)
   6.123 -			panic("netif: no rx va");
   6.124 -		pg_tx = uvm_pagealloc(NULL, 0, NULL, UVM_PGA_ZERO);
   6.125 -		if (pg_tx == NULL) {
   6.126 -			panic("netif: no tx pages");
   6.127 +		if (sc->sc_backend_state == BEST_CLOSED) {
   6.128 +			/* Move from CLOSED to DISCONNECTED state. */
   6.129 +			sc->sc_tx = (netif_tx_interface_t *)
   6.130 +				uvm_km_valloc_align(kernel_map, PAGE_SIZE, PAGE_SIZE);
   6.131 +			if (sc->sc_tx == NULL)
   6.132 +				panic("netif: no tx va");
   6.133 +			sc->sc_rx = (netif_rx_interface_t *)
   6.134 +				uvm_km_valloc_align(kernel_map, PAGE_SIZE, PAGE_SIZE);
   6.135 +			if (sc->sc_rx == NULL)
   6.136 +				panic("netif: no rx va");
   6.137 +			sc->sc_pg_tx = uvm_pagealloc(NULL, 0, NULL, UVM_PGA_ZERO);
   6.138 +			if (sc->sc_pg_tx == NULL) {
   6.139 +				panic("netif: no tx pages");
   6.140 +			}
   6.141 +			pmap_kenter_pa((vaddr_t)sc->sc_tx, VM_PAGE_TO_PHYS(sc->sc_pg_tx),
   6.142 +			    VM_PROT_READ | VM_PROT_WRITE);
   6.143 +			sc->sc_pg_rx = uvm_pagealloc(NULL, 0, NULL, UVM_PGA_ZERO);
   6.144 +			if (sc->sc_pg_rx == NULL) {
   6.145 +				panic("netif: no rx pages");
   6.146 +			}
   6.147 +			pmap_kenter_pa((vaddr_t)sc->sc_rx, VM_PAGE_TO_PHYS(sc->sc_pg_rx),
   6.148 +			    VM_PROT_READ | VM_PROT_WRITE);
   6.149 +			sc->sc_backend_state = BEST_DISCONNECTED;
   6.150  		}
   6.151 -		pmap_kenter_pa((vaddr_t)sc->sc_tx, VM_PAGE_TO_PHYS(pg_tx),
   6.152 -		    VM_PROT_READ | VM_PROT_WRITE);
   6.153 -		pg_rx = uvm_pagealloc(NULL, 0, NULL, UVM_PGA_ZERO);
   6.154 -		if (pg_rx == NULL) {
   6.155 -			panic("netif: no rx pages");
   6.156 -		}
   6.157 -		pmap_kenter_pa((vaddr_t)sc->sc_rx, VM_PAGE_TO_PHYS(pg_rx),
   6.158 -		    VM_PROT_READ | VM_PROT_WRITE);
   6.159 -		sc->sc_backend_state = BEST_DISCONNECTED;
   6.160  
   6.161  		/* Construct an interface-CONNECT message for the
   6.162  		 * domain controller. */
   6.163 @@ -440,8 +461,8 @@ xennet_interface_status_change(netif_fe_
   6.164  		cmsg.subtype   = CMSG_NETIF_FE_INTERFACE_CONNECT;
   6.165  		cmsg.length    = sizeof(netif_fe_interface_connect_t);
   6.166  		up.handle      = status->handle;
   6.167 -		up.tx_shmem_frame = xpmap_ptom(VM_PAGE_TO_PHYS(pg_tx)) >> PAGE_SHIFT;
   6.168 -		up.rx_shmem_frame = xpmap_ptom(VM_PAGE_TO_PHYS(pg_rx)) >> PAGE_SHIFT;
   6.169 +		up.tx_shmem_frame = xpmap_ptom(VM_PAGE_TO_PHYS(sc->sc_pg_tx)) >> PAGE_SHIFT;
   6.170 +		up.rx_shmem_frame = xpmap_ptom(VM_PAGE_TO_PHYS(sc->sc_pg_rx)) >> PAGE_SHIFT;
   6.171  		memcpy(cmsg.msg, &up, sizeof(up));
   6.172  
   6.173  		/* Tell the controller to bring up the interface. */
   6.174 @@ -514,6 +535,7 @@ xennet_interface_status_change(netif_fe_
   6.175  		    status->status);
   6.176  		break;
   6.177  	}
   6.178 +	DPRINTFN(XEDB_EVENT, ("xennet_interface_status_change()\n"));
   6.179  }
   6.180  
   6.181  static void
   6.182 @@ -806,8 +828,6 @@ network_alloc_rx_buffers(struct xennet_s
   6.183  	int s;
   6.184  
   6.185  	ringidx = sc->sc_rx->req_prod;
   6.186 -	if (0) printf("network_alloc_rx_buffers prod %d cons %d\n", ringidx,
   6.187 -	    sc->sc_rx_resp_cons);
   6.188  	if ((ringidx - sc->sc_rx_resp_cons) > (RX_MAX_ENTRIES / 2))
   6.189  		return;
   6.190  
     7.1 --- a/netbsd-2.0-xen-sparse/sys/arch/xen/xen/xbd.c	Sat Oct 02 14:25:55 2004 +0000
     7.2 +++ b/netbsd-2.0-xen-sparse/sys/arch/xen/xen/xbd.c	Mon Oct 04 13:15:55 2004 +0000
     7.3 @@ -809,7 +809,7 @@ send_driver_status(int ok)
     7.4  		.subtype = CMSG_BLKIF_FE_DRIVER_STATUS,
     7.5  		.length  = sizeof(blkif_fe_driver_status_t),
     7.6  	};
     7.7 -	blkif_fe_driver_status_t *msg = (void*)cmsg.msg;
     7.8 +	blkif_fe_driver_status_t *msg = (blkif_fe_driver_status_t *)cmsg.msg;
     7.9      
    7.10  	msg->status = ok ? BLKIF_DRIVER_STATUS_UP : BLKIF_DRIVER_STATUS_DOWN;
    7.11  
    7.12 @@ -825,7 +825,8 @@ send_interface_connect(void)
    7.13  		.subtype = CMSG_BLKIF_FE_INTERFACE_CONNECT,
    7.14  		.length  = sizeof(blkif_fe_interface_connect_t),
    7.15  	};
    7.16 -	blkif_fe_interface_connect_t *msg = (void*)cmsg.msg;
    7.17 +	blkif_fe_interface_connect_t *msg =
    7.18 +		(blkif_fe_interface_connect_t *)cmsg.msg;
    7.19      	paddr_t pa;
    7.20  
    7.21  	pmap_extract(pmap_kernel(), (vaddr_t)blk_ring, &pa);
    7.22 @@ -866,6 +867,15 @@ setup_sysctl(void)
    7.23  		diskcookies = pnode;
    7.24  }
    7.25  
    7.26 +static int
    7.27 +xbd_wait_for_interfaces(void)
    7.28 +{
    7.29 +
    7.30 +	while (state != STATE_CONNECTED)
    7.31 +		HYPERVISOR_yield();
    7.32 +	return 0;
    7.33 +}
    7.34 +
    7.35  int
    7.36  xbd_scan(struct device *self, struct xbd_attach_args *mainbus_xbda,
    7.37      cfprint_t print)
    7.38 @@ -912,11 +922,17 @@ xbd_scan(struct device *self, struct xbd
    7.39  
    7.40  	send_driver_status(1);
    7.41  
    7.42 -#if 0
    7.43 -	enable_update_events(self);
    7.44 -#endif
    7.45 +	return 0;
    7.46 +}
    7.47  
    7.48 -	return 0;
    7.49 +void
    7.50 +xbd_scan_finish(struct device *parent)
    7.51 +{
    7.52 +	int err;
    7.53 +
    7.54 +	err = xbd_wait_for_interfaces();
    7.55 +	if (err)
    7.56 +		ctrl_if_unregister_receiver(CMSG_NETIF_FE, xbd_ctrlif_rx);
    7.57  }
    7.58  
    7.59  #if NXBD > 0
     8.1 --- a/netbsd-2.0-xen-sparse/sys/arch/xen/xen/xencons.c	Sat Oct 02 14:25:55 2004 +0000
     8.2 +++ b/netbsd-2.0-xen-sparse/sys/arch/xen/xen/xencons.c	Mon Oct 04 13:15:55 2004 +0000
     8.3 @@ -46,6 +46,8 @@
     8.4  #include <machine/stdarg.h>
     8.5  #include <machine/xen.h>
     8.6  #include <machine/hypervisor.h>
     8.7 +#include <machine/evtchn.h>
     8.8 +#include <machine/ctrl_if.h>
     8.9  
    8.10  #include <dev/cons.h>
    8.11  
    8.12 @@ -87,6 +89,7 @@ const struct cdevsw xencons_cdevsw = {
    8.13  };
    8.14  
    8.15  
    8.16 +static void xencons_rx(ctrl_msg_t *, unsigned long);
    8.17  void xenconscn_attach(void);
    8.18  int xenconscn_getc(dev_t);
    8.19  void xenconscn_putc(dev_t, int);
    8.20 @@ -131,6 +134,8 @@ xencons_attach(struct device *parent, st
    8.21  
    8.22  		/* Set db_max_line to avoid paging. */
    8.23  		db_max_line = 0x7fffffff;
    8.24 +
    8.25 +		(void)ctrl_if_register_receiver(CMSG_CONSOLE, xencons_rx, 0);
    8.26  	}
    8.27  }
    8.28  
    8.29 @@ -258,7 +263,6 @@ xencons_start(struct tty *tp)
    8.30  {
    8.31  	struct clist *cl;
    8.32  	int s, len;
    8.33 -	u_char buf[XENCONS_BURST+1];
    8.34  
    8.35  	s = spltty();
    8.36  	if (tp->t_state & (TS_TIMEOUT | TS_BUSY | TS_TTSTOP))
    8.37 @@ -271,8 +275,22 @@ xencons_start(struct tty *tp)
    8.38  	 * expensive and we don't want our serial ports to overflow.
    8.39  	 */
    8.40  	cl = &tp->t_outq;
    8.41 -	len = q_to_b(cl, buf, XENCONS_BURST);
    8.42 -	(void)HYPERVISOR_console_io(CONSOLEIO_write, len, buf);
    8.43 +	if (xen_start_info.flags & SIF_INITDOMAIN) {
    8.44 +		u_char buf[XENCONS_BURST+1];
    8.45 +
    8.46 +		len = q_to_b(cl, buf, XENCONS_BURST);
    8.47 +		(void)HYPERVISOR_console_io(CONSOLEIO_write, len, buf);
    8.48 +	} else {
    8.49 +		ctrl_msg_t msg;
    8.50 +
    8.51 +		len = q_to_b(cl, msg.msg, sizeof(msg.msg));
    8.52 +		msg.type = CMSG_CONSOLE;
    8.53 +		msg.subtype = CMSG_CONSOLE_DATA;
    8.54 +		msg.length = len;
    8.55 +		ctrl_if_send_message_noblock(&msg, NULL, 0);
    8.56 +		/* XXX check return value and queue wait for space
    8.57 +		 * thread/softint */
    8.58 +	}
    8.59  
    8.60  	s = spltty();
    8.61  	tp->t_state &= ~TS_BUSY;
    8.62 @@ -298,13 +316,47 @@ xencons_stop(struct tty *tp, int flag)
    8.63  }
    8.64  
    8.65  
    8.66 +/* Non-privileged receive callback. */
    8.67 +static void
    8.68 +xencons_rx(ctrl_msg_t *msg, unsigned long id)
    8.69 +{
    8.70 +	int i;
    8.71 +	int s;
    8.72 +	// unsigned long flags;
    8.73 +	struct xencons_softc *sc;
    8.74 +	struct tty *tp;
    8.75  
    8.76 +	sc = device_lookup(&xencons_cd, XENCONS_UNIT(cn_tab->cn_dev));
    8.77 +	if (sc == NULL)
    8.78 +		goto out;
    8.79 +
    8.80 +	tp = sc->sc_tty;
    8.81 +	if (tp == NULL)
    8.82 +		goto out;
    8.83 +
    8.84 +	s = spltty();
    8.85 +	// save_and_cli(flags);
    8.86 +	// simple_lock(&xencons_lock);
    8.87 +	for (i = 0; i < msg->length; i++)
    8.88 +		(*tp->t_linesw->l_rint)(msg->msg[i], tp);
    8.89 +	// simple_unlock(&xencons_lock);
    8.90 +	// restore_flags(flags);
    8.91 +	splx(s);
    8.92 +
    8.93 + out:
    8.94 +	msg->length = 0;
    8.95 +	ctrl_if_send_response(msg);
    8.96 +}
    8.97 +
    8.98 +void ctrl_if_early_init(void);
    8.99  void
   8.100  xenconscn_attach()
   8.101  {
   8.102  
   8.103  	cn_tab = &xencons;
   8.104  
   8.105 +	ctrl_if_early_init();
   8.106 +
   8.107  	xencons_isconsole = 1;
   8.108  }
   8.109  
   8.110 @@ -316,18 +368,29 @@ xenconscn_getc(dev_t dev)
   8.111  	for (;;);
   8.112  }
   8.113  
   8.114 -#define MAXLINELEN 1024
   8.115  void
   8.116  xenconscn_putc(dev_t dev, int c)
   8.117  {
   8.118 -	static char buf[1024+1];
   8.119 -	static int bufpos = 0;
   8.120 +	extern int ctrl_if_evtchn;
   8.121 +
   8.122 +	if (xen_start_info.flags & SIF_INITDOMAIN ||
   8.123 +		ctrl_if_evtchn == -1) {
   8.124 +		u_char buf[1];
   8.125  
   8.126 -	buf[bufpos++] = c;
   8.127 -	if (c == '\n') {
   8.128 -		buf[bufpos] = 0;
   8.129 -		(void)HYPERVISOR_console_io(CONSOLEIO_write, bufpos, buf);
   8.130 -		bufpos = 0;
   8.131 +		buf[0] = c;
   8.132 +		(void)HYPERVISOR_console_io(CONSOLEIO_write, 1, buf);
   8.133 +	} else {
   8.134 +		ctrl_msg_t msg;
   8.135 +
   8.136 +		msg.type = CMSG_CONSOLE;
   8.137 +		msg.subtype = CMSG_CONSOLE_DATA;
   8.138 +		msg.length = 1;
   8.139 +		msg.msg[0] = c;
   8.140 +		while (ctrl_if_send_message_noblock(&msg, NULL, 0) == EAGAIN) {
   8.141 +			HYPERVISOR_yield();
   8.142 +			/* XXX check return value and queue wait for space
   8.143 +			 * thread/softint */
   8.144 +		}
   8.145  	}
   8.146  }
   8.147