ia64/xen-unstable

changeset 2594:a4fbb98f00cb

bitkeeper revision 1.1159.1.202 (41616cc2-ciBh_VkJKwmQaCL6BEU6Q)

Merge labyrinth.cl.cam.ac.uk:/auto/groups/xeno/BK/xeno.bk
into labyrinth.cl.cam.ac.uk:/auto/anfs/scratch/labyrinth/iap10/xeno-clone/xeno.bk
author iap10@labyrinth.cl.cam.ac.uk
date Mon Oct 04 15:31:14 2004 +0000 (2004-10-04)
parents 98bdf2c88015 a28d3cf3832c
children 6ceaf7d959a7
files netbsd-2.0-xen-sparse/sys/arch/xen/i386/hypervisor_machdep.c netbsd-2.0-xen-sparse/sys/arch/xen/include/ctrl_if.h 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 xen/arch/x86/memory.c xen/include/asm-x86/mm.h
line diff
     1.1 --- a/netbsd-2.0-xen-sparse/sys/arch/xen/i386/hypervisor_machdep.c	Sun Oct 03 14:35:11 2004 +0000
     1.2 +++ b/netbsd-2.0-xen-sparse/sys/arch/xen/i386/hypervisor_machdep.c	Mon Oct 04 15:31:14 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/ctrl_if.h	Sun Oct 03 14:35:11 2004 +0000
     2.2 +++ b/netbsd-2.0-xen-sparse/sys/arch/xen/include/ctrl_if.h	Mon Oct 04 15:31:14 2004 +0000
     2.3 @@ -117,6 +117,7 @@ void ctrl_if_suspend(void);
     2.4  void ctrl_if_resume(void);
     2.5  
     2.6  /* Start-of-day setup. */
     2.7 +void ctrl_if_early_init(void);
     2.8  void ctrl_if_init(void);
     2.9  
    2.10  /*
     3.1 --- a/netbsd-2.0-xen-sparse/sys/arch/xen/include/if_xennetvar.h	Sun Oct 03 14:35:11 2004 +0000
     3.2 +++ b/netbsd-2.0-xen-sparse/sys/arch/xen/include/if_xennetvar.h	Mon Oct 04 15:31:14 2004 +0000
     3.3 @@ -81,6 +81,8 @@ struct xennet_softc {
     3.4  
     3.5  	netif_tx_interface_t	*sc_tx;
     3.6  	netif_rx_interface_t	*sc_rx;
     3.7 +	struct vm_page		*sc_pg_tx;
     3.8 +	struct vm_page		*sc_pg_rx;
     3.9  
    3.10  	uint32_t		sc_tx_entries;
    3.11  	uint32_t		sc_tx_resp_cons;
    3.12 @@ -102,6 +104,7 @@ struct xennet_attach_args {
    3.13  struct nfs_diskless;
    3.14  
    3.15  int xennet_scan(struct device *, struct xennet_attach_args *, cfprint_t);
    3.16 +void xennet_scan_finish(struct device *);
    3.17  void xennet_start(struct ifnet *);
    3.18  int xennet_ioctl(struct ifnet *ifp, u_long cmd, caddr_t data);
    3.19  void xennet_watchdog(struct ifnet *ifp);
     4.1 --- a/netbsd-2.0-xen-sparse/sys/arch/xen/include/xbdvar.h	Sun Oct 03 14:35:11 2004 +0000
     4.2 +++ b/netbsd-2.0-xen-sparse/sys/arch/xen/include/xbdvar.h	Mon Oct 04 15:31:14 2004 +0000
     4.3 @@ -52,5 +52,6 @@ struct xbd_attach_args {
     4.4  };
     4.5  
     4.6  int xbd_scan(struct device *, struct xbd_attach_args *, cfprint_t);
     4.7 +void xbd_scan_finish(struct device *);
     4.8  
     4.9  #endif /* _XEN_XBDVAR_H_ */
     5.1 --- a/netbsd-2.0-xen-sparse/sys/arch/xen/xen/ctrl_if.c	Sun Oct 03 14:35:11 2004 +0000
     5.2 +++ b/netbsd-2.0-xen-sparse/sys/arch/xen/xen/ctrl_if.c	Mon Oct 04 15:31:14 2004 +0000
     5.3 @@ -13,15 +13,15 @@
     5.4  #include <sys/systm.h>
     5.5  #include <sys/proc.h>
     5.6  #include <sys/malloc.h>
     5.7 -#include <sys/kthread.h>
     5.8  
     5.9  #include <machine/xen.h>
    5.10  #include <machine/hypervisor.h>
    5.11  #include <machine/ctrl_if.h>
    5.12  #include <machine/evtchn.h>
    5.13  
    5.14 +void printk(char *, ...);
    5.15  #if 0
    5.16 -#define DPRINTK(_f, _a...) printf("(file=%s, line=%d) " _f, \
    5.17 +#define DPRINTK(_f, _a...) printk("(file=%s, line=%d) " _f, \
    5.18                             __FILE__ , __LINE__ , ## _a )
    5.19  #else
    5.20  #define DPRINTK(_f, _a...) ((void)0)
    5.21 @@ -34,7 +34,7 @@
    5.22   */
    5.23  int initdom_ctrlif_domcontroller_port = -1;
    5.24  
    5.25 -static int ctrl_if_evtchn;
    5.26 +/* static */ int ctrl_if_evtchn = -1;
    5.27  static int ctrl_if_irq;
    5.28  static struct simplelock ctrl_if_lock;
    5.29  
    5.30 @@ -76,8 +76,6 @@ static void __ctrl_if_tx_tasklet(unsigne
    5.31  
    5.32  static void __ctrl_if_rx_tasklet(unsigned long data);
    5.33  
    5.34 -static void ctrl_if_kthread(void *);
    5.35 -
    5.36  #define get_ctrl_if() ((control_if_t *)((char *)HYPERVISOR_shared_info + 2048))
    5.37  #define TX_FULL(_c)   \
    5.38      (((_c)->tx_req_prod - ctrl_if_tx_resp_cons) == CONTROL_RING_SIZE)
    5.39 @@ -148,9 +146,10 @@ static void __ctrl_if_rxmsg_deferred(voi
    5.40  
    5.41  	while ( ctrl_if_rxmsg_deferred_cons != dp )
    5.42  	{
    5.43 -		msg = &ctrl_if_rxmsg_deferred[MASK_CONTROL_IDX(
    5.44 -						      ctrl_if_rxmsg_deferred_cons++)];
    5.45 +		msg = &ctrl_if_rxmsg_deferred[
    5.46 +		    MASK_CONTROL_IDX(ctrl_if_rxmsg_deferred_cons)];
    5.47  		(*ctrl_if_rxmsg_handler[msg->type])(msg, 0);
    5.48 +		ctrl_if_rxmsg_deferred_cons++;
    5.49  	}
    5.50  }
    5.51  
    5.52 @@ -166,7 +165,7 @@ static void __ctrl_if_rx_tasklet(unsigne
    5.53  
    5.54      while ( ctrl_if_rx_req_cons != rp )
    5.55      {
    5.56 -        pmsg = &ctrl_if->rx_ring[MASK_CONTROL_IDX(ctrl_if_rx_req_cons++)];
    5.57 +        pmsg = &ctrl_if->rx_ring[MASK_CONTROL_IDX(ctrl_if_rx_req_cons)];
    5.58          memcpy(&msg, pmsg, offsetof(ctrl_msg_t, msg));
    5.59  
    5.60          DPRINTK("Rx-Req %u/%u :: %d/%d\n", 
    5.61 @@ -184,36 +183,30 @@ static void __ctrl_if_rx_tasklet(unsigne
    5.62                     &msg, offsetof(ctrl_msg_t, msg) + msg.length);
    5.63          else
    5.64              (*ctrl_if_rxmsg_handler[msg.type])(&msg, 0);
    5.65 +
    5.66 +	ctrl_if_rx_req_cons++;
    5.67      }
    5.68  
    5.69      if ( dp != ctrl_if_rxmsg_deferred_prod )
    5.70      {
    5.71          __insn_barrier();
    5.72          ctrl_if_rxmsg_deferred_prod = dp;
    5.73 -#if 0
    5.74 -        wakeup(&ctrl_if_kthread);
    5.75 -#else
    5.76  	if (ctrl_if_softintr)
    5.77  		softintr_schedule(ctrl_if_softintr);
    5.78 -#endif
    5.79      }
    5.80  }
    5.81  
    5.82  static int ctrl_if_interrupt(void *arg)
    5.83  {
    5.84 -    control_if_t *ctrl_if = get_ctrl_if();
    5.85 +	control_if_t *ctrl_if = get_ctrl_if();
    5.86 +
    5.87 +	if ( ctrl_if_tx_resp_cons != ctrl_if->tx_resp_prod )
    5.88 +		__ctrl_if_tx_tasklet(0);
    5.89  
    5.90 -    if ( ctrl_if_tx_resp_cons != ctrl_if->tx_resp_prod ||
    5.91 -	ctrl_if_rx_req_cons != ctrl_if->rx_req_prod ) {
    5.92 -#if 0
    5.93 -	    wakeup(&ctrl_if_kthread);
    5.94 -#else
    5.95 -	    if (ctrl_if_softintr)
    5.96 -		    softintr_schedule(ctrl_if_softintr);
    5.97 -#endif
    5.98 -    }
    5.99 +	if ( ctrl_if_rx_req_cons != ctrl_if->rx_req_prod )
   5.100 +		__ctrl_if_rx_tasklet(0);
   5.101  
   5.102 -    return 0;
   5.103 +	return 0;
   5.104  }
   5.105  
   5.106  int
   5.107 @@ -225,6 +218,7 @@ ctrl_if_send_message_noblock(
   5.108      control_if_t *ctrl_if = get_ctrl_if();
   5.109      unsigned long flags;
   5.110      int           i;
   5.111 +    int s;
   5.112  
   5.113      save_and_cli(flags);
   5.114      simple_lock(&ctrl_if_lock);
   5.115 @@ -233,7 +227,11 @@ ctrl_if_send_message_noblock(
   5.116      {
   5.117          simple_unlock(&ctrl_if_lock);
   5.118  	restore_flags(flags);
   5.119 -        return -EAGAIN;
   5.120 +	s = splhigh();
   5.121 +	if ( ctrl_if_tx_resp_cons != ctrl_if->tx_resp_prod )
   5.122 +		__ctrl_if_tx_tasklet(0);
   5.123 +	splx(s);
   5.124 +        return EAGAIN;
   5.125      }
   5.126  
   5.127      msg->id = 0xFF;
   5.128 @@ -275,10 +273,14 @@ ctrl_if_send_message_block(
   5.129  
   5.130  	while ((rc = ctrl_if_send_message_noblock(msg, hnd, id)) == EAGAIN) {
   5.131  		/* XXXcl possible race -> add a lock and ltsleep */
   5.132 +#if 1
   5.133 +		HYPERVISOR_yield();
   5.134 +#else
   5.135  		rc = tsleep((caddr_t) &ctrl_if_tx_wait, PUSER | PCATCH,
   5.136  		    "ctrl_if", 0);
   5.137  		if (rc)
   5.138  			break;
   5.139 +#endif
   5.140  	}
   5.141  
   5.142  	return rc;
   5.143 @@ -443,49 +445,16 @@ ctrl_if_unregister_receiver(
   5.144      restore_flags(flags);
   5.145  
   5.146      /* Ensure that @hnd will not be executed after this function returns. */
   5.147 -#if 0
   5.148 -    wakeup(&ctrl_if_kthread);
   5.149 -#else
   5.150      if (ctrl_if_softintr)
   5.151  	    softintr_schedule(ctrl_if_softintr);
   5.152 -#endif
   5.153  }
   5.154  
   5.155  static void
   5.156 -ctrl_if_kthread(void *arg)
   5.157 -{
   5.158 -	control_if_t *ctrl_if = get_ctrl_if();
   5.159 -
   5.160 -	// printf("ctrl_if_kthread starting\n");
   5.161 -	for (;;) {
   5.162 -		if ( ctrl_if_tx_resp_cons != ctrl_if->tx_resp_prod )
   5.163 -			__ctrl_if_tx_tasklet(0);
   5.164 -
   5.165 -		if ( ctrl_if_rx_req_cons != ctrl_if->rx_req_prod )
   5.166 -			__ctrl_if_rx_tasklet(0);
   5.167 -
   5.168 -		if ( ctrl_if_rxmsg_deferred_cons !=
   5.169 -		    ctrl_if_rxmsg_deferred_prod )
   5.170 -			__ctrl_if_rxmsg_deferred(NULL);
   5.171 -
   5.172 -		if (arg) {
   5.173 -			// printf("ctrl_if_kthread one-shot done\n");
   5.174 -			return;
   5.175 -		}
   5.176 -
   5.177 -		tsleep((caddr_t)&ctrl_if_kthread, PUSER | PCATCH,
   5.178 -		    "ctrl_if", 0);
   5.179 -	}
   5.180 -}
   5.181 -
   5.182 -static void
   5.183 -ctrl_if_create_kthread(void *arg)
   5.184 +ctrl_if_softintr_handler(void *arg)
   5.185  {
   5.186  
   5.187 -	printf("ctrl_if_kthread creating\n");
   5.188 -	if (kthread_create1(ctrl_if_kthread, arg, NULL, "ctrl_if"))
   5.189 -		printf("ctrl_if_kthread create failed\n");
   5.190 -	softintr_schedule(ctrl_if_softintr);
   5.191 +	if ( ctrl_if_rxmsg_deferred_cons != ctrl_if_rxmsg_deferred_prod )
   5.192 +		__ctrl_if_rxmsg_deferred(NULL);
   5.193  }
   5.194  
   5.195  #ifdef notyet
   5.196 @@ -528,20 +497,28 @@ void ctrl_if_resume(void)
   5.197      hypervisor_enable_irq(ctrl_if_irq);
   5.198  }
   5.199  
   5.200 +void ctrl_if_early_init(void)
   5.201 +{
   5.202 +
   5.203 +	simple_lock_init(&ctrl_if_lock);
   5.204 +
   5.205 +	ctrl_if_evtchn = xen_start_info.domain_controller_evtchn;
   5.206 +}
   5.207 +
   5.208  void ctrl_if_init(void)
   5.209  {
   5.210 -        int i;
   5.211 +	int i;
   5.212  
   5.213 -    for ( i = 0; i < 256; i++ )
   5.214 -        ctrl_if_rxmsg_handler[i] = ctrl_if_rxmsg_default_handler;
   5.215 +	for ( i = 0; i < 256; i++ )
   5.216 +		ctrl_if_rxmsg_handler[i] = ctrl_if_rxmsg_default_handler;
   5.217  
   5.218 -    simple_lock_init(&ctrl_if_lock);
   5.219 +	if (ctrl_if_evtchn == -1)
   5.220 +		ctrl_if_early_init();
   5.221  
   5.222 -    if (0) kthread_create(ctrl_if_create_kthread, NULL);
   5.223 -    ctrl_if_softintr =
   5.224 -	    softintr_establish(IPL_SOFTNET, ctrl_if_kthread, (void *)1);
   5.225 +	ctrl_if_softintr = softintr_establish(IPL_SOFTNET,
   5.226 +	    ctrl_if_softintr_handler, NULL);
   5.227  
   5.228 -    ctrl_if_resume();
   5.229 +	ctrl_if_resume();
   5.230  }
   5.231  
   5.232  
     6.1 --- a/netbsd-2.0-xen-sparse/sys/arch/xen/xen/hypervisor.c	Sun Oct 03 14:35:11 2004 +0000
     6.2 +++ b/netbsd-2.0-xen-sparse/sys/arch/xen/xen/hypervisor.c	Mon Oct 04 15:31:14 2004 +0000
     6.3 @@ -133,6 +133,18 @@ hypervisor_match(parent, match, aux)
     6.4  	return 0;
     6.5  }
     6.6  
     6.7 +static void
     6.8 +scan_finish(struct device *parent)
     6.9 +{
    6.10 +
    6.11 +#if NXENNET > 0
    6.12 +	xennet_scan_finish(parent);
    6.13 +#endif
    6.14 +#if NXBD > 0
    6.15 +	xbd_scan_finish(parent);
    6.16 +#endif
    6.17 +}
    6.18 +
    6.19  /*
    6.20   * Attach the hypervisor.
    6.21   */
    6.22 @@ -183,6 +195,9 @@ hypervisor_attach(parent, self, aux)
    6.23  		xenvfr_init();
    6.24  	}
    6.25  #endif
    6.26 +#if NXENNET > 0 || NXBD > 0
    6.27 +	config_interrupts(self, scan_finish);
    6.28 +#endif
    6.29  }
    6.30  
    6.31  int
     7.1 --- a/netbsd-2.0-xen-sparse/sys/arch/xen/xen/if_xennet.c	Sun Oct 03 14:35:11 2004 +0000
     7.2 +++ b/netbsd-2.0-xen-sparse/sys/arch/xen/xen/if_xennet.c	Mon Oct 04 15:31:14 2004 +0000
     7.3 @@ -106,8 +106,9 @@
     7.4  #define XEDB_MBUF	0x08
     7.5  #define XEDB_MEM	0x10
     7.6  int xennet_debug = 0x0;
     7.7 -#define DPRINTF(x) if (xennet_debug) printf x;
     7.8 -#define DPRINTFN(n,x) if (xennet_debug & (n)) printf x;
     7.9 +void printk(char *, ...);
    7.10 +#define DPRINTF(x) if (xennet_debug) printk x;
    7.11 +#define DPRINTFN(n,x) if (xennet_debug & (n)) printk x;
    7.12  #else
    7.13  #define DPRINTF(x)
    7.14  #define DPRINTFN(n,x)
    7.15 @@ -174,13 +175,21 @@ static int nxennet_media = (sizeof(xenne
    7.16  #endif
    7.17  
    7.18  
    7.19 +static int
    7.20 +xennet_wait_for_interfaces(void)
    7.21 +{
    7.22 +
    7.23 +	while (netctrl.xc_interfaces != netctrl.xc_connected)
    7.24 +		HYPERVISOR_yield();
    7.25 +	return 0;
    7.26 +}
    7.27 +
    7.28  int
    7.29  xennet_scan(struct device *self, struct xennet_attach_args *xneta,
    7.30      cfprint_t print)
    7.31  {
    7.32  	ctrl_msg_t cmsg;
    7.33  	netif_fe_driver_status_t st;
    7.34 -	int err = 0;
    7.35  
    7.36  	if ((xen_start_info.flags & SIF_INITDOMAIN) ||
    7.37  	    (xen_start_info.flags & SIF_NET_BE_DOMAIN))
    7.38 @@ -203,13 +212,17 @@ xennet_scan(struct device *self, struct 
    7.39  	memcpy(cmsg.msg, &st, sizeof(st));
    7.40  	ctrl_if_send_message_block(&cmsg, NULL, 0, 0);
    7.41  
    7.42 -#if 0
    7.43 +	return 0;
    7.44 +}
    7.45 +
    7.46 +void
    7.47 +xennet_scan_finish(struct device *parent)
    7.48 +{
    7.49 +	int err;
    7.50 +
    7.51  	err = xennet_wait_for_interfaces();
    7.52  	if (err)
    7.53  		ctrl_if_unregister_receiver(CMSG_NETIF_FE, xennet_ctrlif_rx);
    7.54 -#endif
    7.55 -
    7.56 -	return err;
    7.57  }
    7.58  
    7.59  int
    7.60 @@ -270,7 +283,7 @@ find_device(int handle)
    7.61  		if (xs->sc_ifno == handle)
    7.62  			break;
    7.63  	}
    7.64 -	return xs;
    7.65 +	return dv ? xs : NULL;
    7.66  }
    7.67  
    7.68  static void
    7.69 @@ -278,6 +291,7 @@ xennet_ctrlif_rx(ctrl_msg_t *msg, unsign
    7.70  {
    7.71  	int respond = 1;
    7.72  
    7.73 +	DPRINTFN(XEDB_EVENT, ("> ctrlif_rx=%d\n", msg->subtype));
    7.74  	switch (msg->subtype) {
    7.75  	case CMSG_NETIF_FE_INTERFACE_STATUS:
    7.76  		if (msg->length != sizeof(netif_fe_interface_status_t))
    7.77 @@ -307,7 +321,8 @@ static void
    7.78  xennet_driver_status_change(netif_fe_driver_status_t *status)
    7.79  {
    7.80  
    7.81 -	DPRINTFN(XEDB_EVENT, ("> status=%d\n", status->status));
    7.82 +	DPRINTFN(XEDB_EVENT, ("xennet_driver_status_change(%d)\n",
    7.83 +		     status->status));
    7.84  
    7.85  	netctrl.xc_up = status->status;
    7.86  	xennet_driver_count_connected();
    7.87 @@ -340,10 +355,9 @@ xennet_interface_status_change(netif_fe_
    7.88  	netif_fe_interface_connect_t up;
    7.89  	struct xennet_softc *sc;
    7.90  	struct ifnet *ifp;
    7.91 -	struct vm_page *pg_tx, *pg_rx;
    7.92  	struct xennet_attach_args xneta;
    7.93  
    7.94 -	DPRINTFN(XEDB_EVENT, ("> status=%d handle=%d mac=%02x:%02x:%02x:%02x:%02x:%02x\n",
    7.95 +	DPRINTFN(XEDB_EVENT, ("xennet_interface_status_change(%d,%d,%02x:%02x:%02x:%02x:%02x:%02x)\n",
    7.96  	    status->status,
    7.97  	    status->handle,
    7.98  	    status->mac[0], status->mac[1], status->mac[2],
    7.99 @@ -363,6 +377,11 @@ xennet_interface_status_change(netif_fe_
   7.100  	}
   7.101  	ifp = &sc->sc_ethercom.ec_if;
   7.102  
   7.103 +	DPRINTFN(XEDB_EVENT, ("xennet_interface_status_change(%d,%p,%02x:%02x:%02x:%02x:%02x:%02x)\n",
   7.104 +		     status->handle, sc,
   7.105 +		     status->mac[0], status->mac[1], status->mac[2],
   7.106 +		     status->mac[3], status->mac[4], status->mac[5]));
   7.107 +
   7.108  	switch (status->status) {
   7.109  	case NETIF_INTERFACE_STATUS_CLOSED:
   7.110  		printf("Unexpected netif-CLOSED message in state %d\n",
   7.111 @@ -411,28 +430,30 @@ xennet_interface_status_change(netif_fe_
   7.112  		}
   7.113  #endif
   7.114  
   7.115 -		/* Move from CLOSED to DISCONNECTED state. */
   7.116 -		sc->sc_tx = (netif_tx_interface_t *)
   7.117 -			uvm_km_valloc_align(kernel_map, PAGE_SIZE, PAGE_SIZE);
   7.118 -		if (sc->sc_tx == NULL)
   7.119 -			panic("netif: no tx va");
   7.120 -		sc->sc_rx = (netif_rx_interface_t *)
   7.121 -			uvm_km_valloc_align(kernel_map, PAGE_SIZE, PAGE_SIZE);
   7.122 -		if (sc->sc_rx == NULL)
   7.123 -			panic("netif: no rx va");
   7.124 -		pg_tx = uvm_pagealloc(NULL, 0, NULL, UVM_PGA_ZERO);
   7.125 -		if (pg_tx == NULL) {
   7.126 -			panic("netif: no tx pages");
   7.127 +		if (sc->sc_backend_state == BEST_CLOSED) {
   7.128 +			/* Move from CLOSED to DISCONNECTED state. */
   7.129 +			sc->sc_tx = (netif_tx_interface_t *)
   7.130 +				uvm_km_valloc_align(kernel_map, PAGE_SIZE, PAGE_SIZE);
   7.131 +			if (sc->sc_tx == NULL)
   7.132 +				panic("netif: no tx va");
   7.133 +			sc->sc_rx = (netif_rx_interface_t *)
   7.134 +				uvm_km_valloc_align(kernel_map, PAGE_SIZE, PAGE_SIZE);
   7.135 +			if (sc->sc_rx == NULL)
   7.136 +				panic("netif: no rx va");
   7.137 +			sc->sc_pg_tx = uvm_pagealloc(NULL, 0, NULL, UVM_PGA_ZERO);
   7.138 +			if (sc->sc_pg_tx == NULL) {
   7.139 +				panic("netif: no tx pages");
   7.140 +			}
   7.141 +			pmap_kenter_pa((vaddr_t)sc->sc_tx, VM_PAGE_TO_PHYS(sc->sc_pg_tx),
   7.142 +			    VM_PROT_READ | VM_PROT_WRITE);
   7.143 +			sc->sc_pg_rx = uvm_pagealloc(NULL, 0, NULL, UVM_PGA_ZERO);
   7.144 +			if (sc->sc_pg_rx == NULL) {
   7.145 +				panic("netif: no rx pages");
   7.146 +			}
   7.147 +			pmap_kenter_pa((vaddr_t)sc->sc_rx, VM_PAGE_TO_PHYS(sc->sc_pg_rx),
   7.148 +			    VM_PROT_READ | VM_PROT_WRITE);
   7.149 +			sc->sc_backend_state = BEST_DISCONNECTED;
   7.150  		}
   7.151 -		pmap_kenter_pa((vaddr_t)sc->sc_tx, VM_PAGE_TO_PHYS(pg_tx),
   7.152 -		    VM_PROT_READ | VM_PROT_WRITE);
   7.153 -		pg_rx = uvm_pagealloc(NULL, 0, NULL, UVM_PGA_ZERO);
   7.154 -		if (pg_rx == NULL) {
   7.155 -			panic("netif: no rx pages");
   7.156 -		}
   7.157 -		pmap_kenter_pa((vaddr_t)sc->sc_rx, VM_PAGE_TO_PHYS(pg_rx),
   7.158 -		    VM_PROT_READ | VM_PROT_WRITE);
   7.159 -		sc->sc_backend_state = BEST_DISCONNECTED;
   7.160  
   7.161  		/* Construct an interface-CONNECT message for the
   7.162  		 * domain controller. */
   7.163 @@ -440,8 +461,8 @@ xennet_interface_status_change(netif_fe_
   7.164  		cmsg.subtype   = CMSG_NETIF_FE_INTERFACE_CONNECT;
   7.165  		cmsg.length    = sizeof(netif_fe_interface_connect_t);
   7.166  		up.handle      = status->handle;
   7.167 -		up.tx_shmem_frame = xpmap_ptom(VM_PAGE_TO_PHYS(pg_tx)) >> PAGE_SHIFT;
   7.168 -		up.rx_shmem_frame = xpmap_ptom(VM_PAGE_TO_PHYS(pg_rx)) >> PAGE_SHIFT;
   7.169 +		up.tx_shmem_frame = xpmap_ptom(VM_PAGE_TO_PHYS(sc->sc_pg_tx)) >> PAGE_SHIFT;
   7.170 +		up.rx_shmem_frame = xpmap_ptom(VM_PAGE_TO_PHYS(sc->sc_pg_rx)) >> PAGE_SHIFT;
   7.171  		memcpy(cmsg.msg, &up, sizeof(up));
   7.172  
   7.173  		/* Tell the controller to bring up the interface. */
   7.174 @@ -514,6 +535,7 @@ xennet_interface_status_change(netif_fe_
   7.175  		    status->status);
   7.176  		break;
   7.177  	}
   7.178 +	DPRINTFN(XEDB_EVENT, ("xennet_interface_status_change()\n"));
   7.179  }
   7.180  
   7.181  static void
   7.182 @@ -806,8 +828,6 @@ network_alloc_rx_buffers(struct xennet_s
   7.183  	int s;
   7.184  
   7.185  	ringidx = sc->sc_rx->req_prod;
   7.186 -	if (0) printf("network_alloc_rx_buffers prod %d cons %d\n", ringidx,
   7.187 -	    sc->sc_rx_resp_cons);
   7.188  	if ((ringidx - sc->sc_rx_resp_cons) > (RX_MAX_ENTRIES / 2))
   7.189  		return;
   7.190  
     8.1 --- a/netbsd-2.0-xen-sparse/sys/arch/xen/xen/xbd.c	Sun Oct 03 14:35:11 2004 +0000
     8.2 +++ b/netbsd-2.0-xen-sparse/sys/arch/xen/xen/xbd.c	Mon Oct 04 15:31:14 2004 +0000
     8.3 @@ -809,7 +809,7 @@ send_driver_status(int ok)
     8.4  		.subtype = CMSG_BLKIF_FE_DRIVER_STATUS,
     8.5  		.length  = sizeof(blkif_fe_driver_status_t),
     8.6  	};
     8.7 -	blkif_fe_driver_status_t *msg = (void*)cmsg.msg;
     8.8 +	blkif_fe_driver_status_t *msg = (blkif_fe_driver_status_t *)cmsg.msg;
     8.9      
    8.10  	msg->status = ok ? BLKIF_DRIVER_STATUS_UP : BLKIF_DRIVER_STATUS_DOWN;
    8.11  
    8.12 @@ -825,7 +825,8 @@ send_interface_connect(void)
    8.13  		.subtype = CMSG_BLKIF_FE_INTERFACE_CONNECT,
    8.14  		.length  = sizeof(blkif_fe_interface_connect_t),
    8.15  	};
    8.16 -	blkif_fe_interface_connect_t *msg = (void*)cmsg.msg;
    8.17 +	blkif_fe_interface_connect_t *msg =
    8.18 +		(blkif_fe_interface_connect_t *)cmsg.msg;
    8.19      	paddr_t pa;
    8.20  
    8.21  	pmap_extract(pmap_kernel(), (vaddr_t)blk_ring, &pa);
    8.22 @@ -866,6 +867,15 @@ setup_sysctl(void)
    8.23  		diskcookies = pnode;
    8.24  }
    8.25  
    8.26 +static int
    8.27 +xbd_wait_for_interfaces(void)
    8.28 +{
    8.29 +
    8.30 +	while (state != STATE_CONNECTED)
    8.31 +		HYPERVISOR_yield();
    8.32 +	return 0;
    8.33 +}
    8.34 +
    8.35  int
    8.36  xbd_scan(struct device *self, struct xbd_attach_args *mainbus_xbda,
    8.37      cfprint_t print)
    8.38 @@ -912,11 +922,17 @@ xbd_scan(struct device *self, struct xbd
    8.39  
    8.40  	send_driver_status(1);
    8.41  
    8.42 -#if 0
    8.43 -	enable_update_events(self);
    8.44 -#endif
    8.45 +	return 0;
    8.46 +}
    8.47  
    8.48 -	return 0;
    8.49 +void
    8.50 +xbd_scan_finish(struct device *parent)
    8.51 +{
    8.52 +	int err;
    8.53 +
    8.54 +	err = xbd_wait_for_interfaces();
    8.55 +	if (err)
    8.56 +		ctrl_if_unregister_receiver(CMSG_NETIF_FE, xbd_ctrlif_rx);
    8.57  }
    8.58  
    8.59  #if NXBD > 0
     9.1 --- a/netbsd-2.0-xen-sparse/sys/arch/xen/xen/xencons.c	Sun Oct 03 14:35:11 2004 +0000
     9.2 +++ b/netbsd-2.0-xen-sparse/sys/arch/xen/xen/xencons.c	Mon Oct 04 15:31:14 2004 +0000
     9.3 @@ -46,6 +46,8 @@
     9.4  #include <machine/stdarg.h>
     9.5  #include <machine/xen.h>
     9.6  #include <machine/hypervisor.h>
     9.7 +#include <machine/evtchn.h>
     9.8 +#include <machine/ctrl_if.h>
     9.9  
    9.10  #include <dev/cons.h>
    9.11  
    9.12 @@ -87,6 +89,7 @@ const struct cdevsw xencons_cdevsw = {
    9.13  };
    9.14  
    9.15  
    9.16 +static void xencons_rx(ctrl_msg_t *, unsigned long);
    9.17  void xenconscn_attach(void);
    9.18  int xenconscn_getc(dev_t);
    9.19  void xenconscn_putc(dev_t, int);
    9.20 @@ -131,6 +134,8 @@ xencons_attach(struct device *parent, st
    9.21  
    9.22  		/* Set db_max_line to avoid paging. */
    9.23  		db_max_line = 0x7fffffff;
    9.24 +
    9.25 +		(void)ctrl_if_register_receiver(CMSG_CONSOLE, xencons_rx, 0);
    9.26  	}
    9.27  }
    9.28  
    9.29 @@ -258,7 +263,6 @@ xencons_start(struct tty *tp)
    9.30  {
    9.31  	struct clist *cl;
    9.32  	int s, len;
    9.33 -	u_char buf[XENCONS_BURST+1];
    9.34  
    9.35  	s = spltty();
    9.36  	if (tp->t_state & (TS_TIMEOUT | TS_BUSY | TS_TTSTOP))
    9.37 @@ -271,8 +275,22 @@ xencons_start(struct tty *tp)
    9.38  	 * expensive and we don't want our serial ports to overflow.
    9.39  	 */
    9.40  	cl = &tp->t_outq;
    9.41 -	len = q_to_b(cl, buf, XENCONS_BURST);
    9.42 -	(void)HYPERVISOR_console_io(CONSOLEIO_write, len, buf);
    9.43 +	if (xen_start_info.flags & SIF_INITDOMAIN) {
    9.44 +		u_char buf[XENCONS_BURST+1];
    9.45 +
    9.46 +		len = q_to_b(cl, buf, XENCONS_BURST);
    9.47 +		(void)HYPERVISOR_console_io(CONSOLEIO_write, len, buf);
    9.48 +	} else {
    9.49 +		ctrl_msg_t msg;
    9.50 +
    9.51 +		len = q_to_b(cl, msg.msg, sizeof(msg.msg));
    9.52 +		msg.type = CMSG_CONSOLE;
    9.53 +		msg.subtype = CMSG_CONSOLE_DATA;
    9.54 +		msg.length = len;
    9.55 +		ctrl_if_send_message_noblock(&msg, NULL, 0);
    9.56 +		/* XXX check return value and queue wait for space
    9.57 +		 * thread/softint */
    9.58 +	}
    9.59  
    9.60  	s = spltty();
    9.61  	tp->t_state &= ~TS_BUSY;
    9.62 @@ -298,6 +316,37 @@ xencons_stop(struct tty *tp, int flag)
    9.63  }
    9.64  
    9.65  
    9.66 +/* Non-privileged receive callback. */
    9.67 +static void
    9.68 +xencons_rx(ctrl_msg_t *msg, unsigned long id)
    9.69 +{
    9.70 +	int i;
    9.71 +	int s;
    9.72 +	// unsigned long flags;
    9.73 +	struct xencons_softc *sc;
    9.74 +	struct tty *tp;
    9.75 +
    9.76 +	sc = device_lookup(&xencons_cd, XENCONS_UNIT(cn_tab->cn_dev));
    9.77 +	if (sc == NULL)
    9.78 +		goto out;
    9.79 +
    9.80 +	tp = sc->sc_tty;
    9.81 +	if (tp == NULL)
    9.82 +		goto out;
    9.83 +
    9.84 +	s = spltty();
    9.85 +	// save_and_cli(flags);
    9.86 +	// simple_lock(&xencons_lock);
    9.87 +	for (i = 0; i < msg->length; i++)
    9.88 +		(*tp->t_linesw->l_rint)(msg->msg[i], tp);
    9.89 +	// simple_unlock(&xencons_lock);
    9.90 +	// restore_flags(flags);
    9.91 +	splx(s);
    9.92 +
    9.93 + out:
    9.94 +	msg->length = 0;
    9.95 +	ctrl_if_send_response(msg);
    9.96 +}
    9.97  
    9.98  void
    9.99  xenconscn_attach()
   9.100 @@ -305,6 +354,8 @@ xenconscn_attach()
   9.101  
   9.102  	cn_tab = &xencons;
   9.103  
   9.104 +	ctrl_if_early_init();
   9.105 +
   9.106  	xencons_isconsole = 1;
   9.107  }
   9.108  
   9.109 @@ -316,18 +367,29 @@ xenconscn_getc(dev_t dev)
   9.110  	for (;;);
   9.111  }
   9.112  
   9.113 -#define MAXLINELEN 1024
   9.114  void
   9.115  xenconscn_putc(dev_t dev, int c)
   9.116  {
   9.117 -	static char buf[1024+1];
   9.118 -	static int bufpos = 0;
   9.119 +	extern int ctrl_if_evtchn;
   9.120 +
   9.121 +	if (xen_start_info.flags & SIF_INITDOMAIN ||
   9.122 +		ctrl_if_evtchn == -1) {
   9.123 +		u_char buf[1];
   9.124  
   9.125 -	buf[bufpos++] = c;
   9.126 -	if (c == '\n') {
   9.127 -		buf[bufpos] = 0;
   9.128 -		(void)HYPERVISOR_console_io(CONSOLEIO_write, bufpos, buf);
   9.129 -		bufpos = 0;
   9.130 +		buf[0] = c;
   9.131 +		(void)HYPERVISOR_console_io(CONSOLEIO_write, 1, buf);
   9.132 +	} else {
   9.133 +		ctrl_msg_t msg;
   9.134 +
   9.135 +		msg.type = CMSG_CONSOLE;
   9.136 +		msg.subtype = CMSG_CONSOLE_DATA;
   9.137 +		msg.length = 1;
   9.138 +		msg.msg[0] = c;
   9.139 +		while (ctrl_if_send_message_noblock(&msg, NULL, 0) == EAGAIN) {
   9.140 +			HYPERVISOR_yield();
   9.141 +			/* XXX check return value and queue wait for space
   9.142 +			 * thread/softint */
   9.143 +		}
   9.144  	}
   9.145  }
   9.146  
    10.1 --- a/xen/arch/x86/memory.c	Sun Oct 03 14:35:11 2004 +0000
    10.2 +++ b/xen/arch/x86/memory.c	Mon Oct 04 15:31:14 2004 +0000
    10.3 @@ -1642,36 +1642,13 @@ void ptwr_flush(const int which)
    10.4  {
    10.5      unsigned long pte, *ptep;
    10.6      l1_pgentry_t *pl1e;
    10.7 +    l2_pgentry_t *pl2e, nl2e;
    10.8      int cpu = smp_processor_id();
    10.9      int i;
   10.10  
   10.11      ptep = (unsigned long *)&linear_pg_table
   10.12          [ptwr_info[cpu].ptinfo[which].l1va>>PAGE_SHIFT];
   10.13  
   10.14 -    pl1e = ptwr_info[cpu].ptinfo[which].pl1e;
   10.15 -    for ( i = 0; i < ENTRIES_PER_L1_PAGETABLE; i++ ) {
   10.16 -        l1_pgentry_t ol1e, nl1e;
   10.17 -        nl1e = ptwr_info[cpu].ptinfo[which].page[i];
   10.18 -        ol1e = pl1e[i];
   10.19 -        if (likely(l1_pgentry_val(ol1e) == l1_pgentry_val(nl1e)))
   10.20 -            continue;
   10.21 -        if (likely(l1_pgentry_val(ol1e) == (l1_pgentry_val(nl1e) | _PAGE_RW)))
   10.22 -        {
   10.23 -            if (likely(readonly_page_from_l1e(nl1e))) {
   10.24 -                pl1e[i] = nl1e;
   10.25 -                continue;
   10.26 -            }
   10.27 -        }
   10.28 -        if (unlikely(l1_pgentry_val(ol1e) & _PAGE_PRESENT))
   10.29 -            put_page_from_l1e(ol1e, current);
   10.30 -        if (unlikely(!get_page_from_l1e(nl1e, current))) {
   10.31 -            MEM_LOG("ptwr: Could not re-validate l1 page\n");
   10.32 -            domain_crash();
   10.33 -        }
   10.34 -        pl1e[i] = nl1e;
   10.35 -    }
   10.36 -    unmap_domain_mem(pl1e);
   10.37 -
   10.38      /* make pt page write protected */
   10.39      if ( unlikely(__get_user(pte, ptep)) ) {
   10.40          MEM_LOG("ptwr: Could not read pte at %p\n", ptep);
   10.41 @@ -1679,19 +1656,46 @@ void ptwr_flush(const int which)
   10.42      }
   10.43      PTWR_PRINTK(PP_ALL, ("disconnected_l1va at %p is %08lx\n",
   10.44                           ptep, pte));
   10.45 -    pte = (ptwr_info[cpu].ptinfo[which].pte & PAGE_MASK) |
   10.46 -        (pte & ~(PAGE_MASK|_PAGE_RW));
   10.47 +    pte &= ~_PAGE_RW;
   10.48      if ( unlikely(__put_user(pte, ptep)) ) {
   10.49          MEM_LOG("ptwr: Could not update pte at %p\n", ptep);
   10.50          domain_crash();
   10.51      }
   10.52 +    __flush_tlb_one(ptwr_info[cpu].ptinfo[which].l1va);
   10.53 +    PTWR_PRINTK(PP_ALL, ("disconnected_l1va at %p now %08lx\n",
   10.54 +                         ptep, pte));
   10.55 +
   10.56 +    pl1e = ptwr_info[cpu].ptinfo[which].pl1e;
   10.57 +    for ( i = 0; i < ENTRIES_PER_L1_PAGETABLE; i++ ) {
   10.58 +        l1_pgentry_t ol1e, nl1e;
   10.59 +        ol1e = ptwr_info[cpu].ptinfo[which].page[i];
   10.60 +        nl1e = pl1e[i];
   10.61 +        if (likely(l1_pgentry_val(ol1e) == l1_pgentry_val(nl1e)))
   10.62 +            continue;
   10.63 +        if (likely(l1_pgentry_val(ol1e) == (l1_pgentry_val(nl1e) | _PAGE_RW))
   10.64 +	    && readonly_page_from_l1e(nl1e))
   10.65 +	    continue;
   10.66 +        if (unlikely(l1_pgentry_val(ol1e) & _PAGE_PRESENT))
   10.67 +            put_page_from_l1e(ol1e, current);
   10.68 +        if (unlikely(!get_page_from_l1e(nl1e, current))) {
   10.69 +            MEM_LOG("ptwr: Could not re-validate l1 page\n");
   10.70 +            domain_crash();
   10.71 +        }
   10.72 +    }
   10.73 +    unmap_domain_mem(pl1e);
   10.74 +
   10.75 +    if (which == PTWR_PT_ACTIVE) {
   10.76 +	/* reconnect l1 page */
   10.77 +	pl2e = &linear_l2_table[ptwr_info[cpu].active_pteidx];
   10.78 +	nl2e = mk_l2_pgentry(l2_pgentry_val(*pl2e) | _PAGE_PRESENT);
   10.79 +	update_l2e(pl2e, *pl2e, nl2e);
   10.80 +    }
   10.81  
   10.82      if ( unlikely(current->mm.shadow_mode) )
   10.83      {
   10.84          unsigned long spte;
   10.85          unsigned long sstat = 
   10.86 -            get_shadow_status(&current->mm, 
   10.87 -                              ptwr_info[cpu].ptinfo[which].pte >> PAGE_SHIFT);
   10.88 +            get_shadow_status(&current->mm, pte >> PAGE_SHIFT);
   10.89  
   10.90          if ( sstat & PSH_shadowed ) 
   10.91          { 
   10.92 @@ -1715,10 +1719,6 @@ void ptwr_flush(const int which)
   10.93                     [ptwr_info[cpu].ptinfo[which].l1va>>PAGE_SHIFT]);
   10.94      }
   10.95  
   10.96 -    __flush_tlb_one(ptwr_info[cpu].ptinfo[which].l1va);
   10.97 -    PTWR_PRINTK(PP_ALL, ("disconnected_l1va at %p now %08lx\n",
   10.98 -                         ptep, pte));
   10.99 -
  10.100      ptwr_info[cpu].ptinfo[which].l1va = 0;
  10.101  }
  10.102  
  10.103 @@ -1727,7 +1727,7 @@ int ptwr_do_page_fault(unsigned long add
  10.104      /* write page fault, check if we're trying to modify an l1 page table */
  10.105      unsigned long pte, pfn;
  10.106      struct pfn_info *page;
  10.107 -    l2_pgentry_t *pl2e;
  10.108 +    l2_pgentry_t *pl2e, nl2e;
  10.109      int cpu = smp_processor_id();
  10.110      int which;
  10.111  
  10.112 @@ -1771,8 +1771,13 @@ int ptwr_do_page_fault(unsigned long add
  10.113                  ptwr_flush(which);
  10.114              ptwr_info[cpu].ptinfo[which].l1va = addr | 1;
  10.115  
  10.116 -            if (which == PTWR_PT_ACTIVE)
  10.117 +            if (which == PTWR_PT_ACTIVE) {
  10.118                  ptwr_info[cpu].active_pteidx = va_mask;
  10.119 +		/* disconnect l1 page */
  10.120 +		nl2e = mk_l2_pgentry((l2_pgentry_val(*pl2e) & ~_PAGE_PRESENT));
  10.121 +		update_l2e(pl2e, *pl2e, nl2e);
  10.122 +		flush_tlb();
  10.123 +	    }
  10.124  
  10.125              ptwr_info[cpu].ptinfo[which].pl1e =
  10.126                  map_domain_mem(pfn << PAGE_SHIFT);
  10.127 @@ -1781,10 +1786,7 @@ int ptwr_do_page_fault(unsigned long add
  10.128                     ENTRIES_PER_L1_PAGETABLE * sizeof(l1_pgentry_t));
  10.129  
  10.130              /* make pt page writable */
  10.131 -            ptwr_info[cpu].ptinfo[which].pte = pte;
  10.132 -            pte = (virt_to_phys(ptwr_info[cpu].ptinfo[which].page) &
  10.133 -                   PAGE_MASK) | _PAGE_RW | (pte & ~PAGE_MASK);
  10.134 -
  10.135 +            pte |= _PAGE_RW;
  10.136              PTWR_PRINTK(PP_ALL, ("update %p pte to %08lx\n",
  10.137                                   &linear_pg_table[addr>>PAGE_SHIFT], pte));
  10.138              if ( unlikely(__put_user(pte, (unsigned long *)
    11.1 --- a/xen/include/asm-x86/mm.h	Sun Oct 03 14:35:11 2004 +0000
    11.2 +++ b/xen/include/asm-x86/mm.h	Mon Oct 04 15:31:14 2004 +0000
    11.3 @@ -254,7 +254,6 @@ extern vm_assist_info_t vm_assist_info[]
    11.4  typedef struct {
    11.5      unsigned long l1va;
    11.6      l1_pgentry_t *page;
    11.7 -    unsigned long pte;
    11.8      l1_pgentry_t *pl1e;
    11.9  } ptwr_ptinfo_t;
   11.10