ia64/xen-unstable

changeset 7016:4cff74aa6246

Merged?
author emellor@ewan
date Thu Sep 22 14:01:01 2005 +0100 (2005-09-22)
parents 7646b18d4b32 8dbcf407a680
children d7c794130ac5 eba5afe9aa37
files linux-2.6-xen-sparse/drivers/xen/blkback/common.h linux-2.6-xen-sparse/drivers/xen/blkback/interface.c linux-2.6-xen-sparse/drivers/xen/blktap/common.h linux-2.6-xen-sparse/drivers/xen/blktap/interface.c linux-2.6-xen-sparse/drivers/xen/netback/common.h linux-2.6-xen-sparse/drivers/xen/netback/interface.c linux-2.6-xen-sparse/drivers/xen/tpmback/common.h linux-2.6-xen-sparse/drivers/xen/tpmback/interface.c linux-2.6-xen-sparse/drivers/xen/usbback/common.h linux-2.6-xen-sparse/drivers/xen/usbback/interface.c linux-2.6-xen-sparse/drivers/xen/util.c linux-2.6-xen-sparse/include/asm-xen/driver_util.h
line diff
     1.1 --- a/linux-2.6-xen-sparse/drivers/xen/blkback/common.h	Thu Sep 22 11:35:35 2005 +0100
     1.2 +++ b/linux-2.6-xen-sparse/drivers/xen/blkback/common.h	Thu Sep 22 14:01:01 2005 +0100
     1.3 @@ -17,6 +17,7 @@
     1.4  #include <asm-xen/xen-public/io/blkif.h>
     1.5  #include <asm-xen/xen-public/io/ring.h>
     1.6  #include <asm-xen/gnttab.h>
     1.7 +#include <asm-xen/driver_util.h>
     1.8  
     1.9  #if 0
    1.10  #define ASSERT(_p) \
    1.11 @@ -42,11 +43,11 @@ typedef struct blkif_st {
    1.12      domid_t           domid;
    1.13      unsigned int      handle;
    1.14      /* Physical parameters of the comms window. */
    1.15 -    unsigned long     shmem_frame;
    1.16      unsigned int      evtchn;
    1.17      unsigned int      remote_evtchn;
    1.18      /* Comms information. */
    1.19      blkif_back_ring_t blk_ring;
    1.20 +    struct vm_struct *blk_ring_area;
    1.21      /* VBDs attached to this interface. */
    1.22      struct vbd        vbd;
    1.23      /* Private fields. */
    1.24 @@ -60,8 +61,8 @@ typedef struct blkif_st {
    1.25      atomic_t         refcnt;
    1.26  
    1.27      struct work_struct free_work;
    1.28 -    u16 shmem_handle;
    1.29 -    unsigned long shmem_vaddr;
    1.30 +
    1.31 +    u16         shmem_handle;
    1.32      grant_ref_t shmem_ref;
    1.33  } blkif_t;
    1.34  
     2.1 --- a/linux-2.6-xen-sparse/drivers/xen/blkback/interface.c	Thu Sep 22 11:35:35 2005 +0100
     2.2 +++ b/linux-2.6-xen-sparse/drivers/xen/blkback/interface.c	Thu Sep 22 14:01:01 2005 +0100
     2.3 @@ -8,7 +8,6 @@
     2.4  
     2.5  #include "common.h"
     2.6  #include <asm-xen/evtchn.h>
     2.7 -#include <asm-xen/driver_util.h>
     2.8  
     2.9  static kmem_cache_t *blkif_cachep;
    2.10  
    2.11 @@ -29,16 +28,18 @@ blkif_t *alloc_blkif(domid_t domid)
    2.12      return blkif;
    2.13  }
    2.14  
    2.15 -static int map_frontend_page(blkif_t *blkif, unsigned long localaddr,
    2.16 -			     unsigned long shared_page)
    2.17 +static int map_frontend_page(blkif_t *blkif, unsigned long shared_page)
    2.18  {
    2.19      struct gnttab_map_grant_ref op;
    2.20 -    op.host_addr = localaddr;
    2.21 -    op.flags = GNTMAP_host_map;
    2.22 -    op.ref = shared_page;
    2.23 -    op.dom = blkif->domid;
    2.24  
    2.25 -    BUG_ON( HYPERVISOR_grant_table_op(GNTTABOP_map_grant_ref, &op, 1) );
    2.26 +    op.host_addr = (unsigned long)blkif->blk_ring_area->addr;
    2.27 +    op.flags     = GNTMAP_host_map;
    2.28 +    op.ref       = shared_page;
    2.29 +    op.dom       = blkif->domid;
    2.30 +
    2.31 +    lock_vm_area(blkif->blk_ring_area);
    2.32 +    BUG_ON(HYPERVISOR_grant_table_op(GNTTABOP_map_grant_ref, &op, 1));
    2.33 +    unlock_vm_area(blkif->blk_ring_area);
    2.34  
    2.35      if (op.handle < 0) {
    2.36  	DPRINTK(" Grant table operation failure !\n");
    2.37 @@ -47,7 +48,7 @@ static int map_frontend_page(blkif_t *bl
    2.38  
    2.39      blkif->shmem_ref = shared_page;
    2.40      blkif->shmem_handle = op.handle;
    2.41 -    blkif->shmem_vaddr = localaddr;
    2.42 +
    2.43      return 0;
    2.44  }
    2.45  
    2.46 @@ -55,27 +56,29 @@ static void unmap_frontend_page(blkif_t 
    2.47  {
    2.48      struct gnttab_unmap_grant_ref op;
    2.49  
    2.50 -    op.host_addr = blkif->shmem_vaddr;
    2.51 -    op.handle = blkif->shmem_handle;
    2.52 +    op.host_addr    = (unsigned long)blkif->blk_ring_area->addr;
    2.53 +    op.handle       = blkif->shmem_handle;
    2.54      op.dev_bus_addr = 0;
    2.55 +
    2.56 +    lock_vm_area(blkif->blk_ring_area);
    2.57      BUG_ON(HYPERVISOR_grant_table_op(GNTTABOP_unmap_grant_ref, &op, 1));
    2.58 +    unlock_vm_area(blkif->blk_ring_area);
    2.59  }
    2.60  
    2.61  int blkif_map(blkif_t *blkif, unsigned long shared_page, unsigned int evtchn)
    2.62  {
    2.63 -    struct vm_struct *vma;
    2.64      blkif_sring_t *sring;
    2.65      evtchn_op_t op = { .cmd = EVTCHNOP_bind_interdomain };
    2.66      int err;
    2.67  
    2.68      BUG_ON(blkif->remote_evtchn);
    2.69  
    2.70 -    if ( (vma = prepare_vm_area(PAGE_SIZE)) == NULL )
    2.71 +    if ( (blkif->blk_ring_area = alloc_vm_area(PAGE_SIZE)) == NULL )
    2.72  	return -ENOMEM;
    2.73  
    2.74 -    err = map_frontend_page(blkif, (unsigned long)vma->addr, shared_page);
    2.75 +    err = map_frontend_page(blkif, shared_page);
    2.76      if (err) {
    2.77 -        vunmap(vma->addr);
    2.78 +        free_vm_area(blkif->blk_ring_area);
    2.79  	return err;
    2.80      }
    2.81  
    2.82 @@ -86,21 +89,20 @@ int blkif_map(blkif_t *blkif, unsigned l
    2.83      err = HYPERVISOR_event_channel_op(&op);
    2.84      if (err) {
    2.85  	unmap_frontend_page(blkif);
    2.86 -	vunmap(vma->addr);
    2.87 +        free_vm_area(blkif->blk_ring_area);
    2.88  	return err;
    2.89      }
    2.90  
    2.91      blkif->evtchn = op.u.bind_interdomain.port1;
    2.92      blkif->remote_evtchn = evtchn;
    2.93  
    2.94 -    sring = (blkif_sring_t *)vma->addr;
    2.95 +    sring = (blkif_sring_t *)blkif->blk_ring_area->addr;
    2.96      SHARED_RING_INIT(sring);
    2.97      BACK_RING_INIT(&blkif->blk_ring, sring, PAGE_SIZE);
    2.98  
    2.99      bind_evtchn_to_irqhandler(blkif->evtchn, blkif_be_int, 0, "blkif-backend",
   2.100  			      blkif);
   2.101 -    blkif->status        = CONNECTED;
   2.102 -    blkif->shmem_frame   = shared_page;
   2.103 +    blkif->status = CONNECTED;
   2.104  
   2.105      return 0;
   2.106  }
   2.107 @@ -124,7 +126,7 @@ static void free_blkif(void *arg)
   2.108  
   2.109      if (blkif->blk_ring.sring) {
   2.110  	unmap_frontend_page(blkif);
   2.111 -	vunmap(blkif->blk_ring.sring);
   2.112 +        free_vm_area(blkif->blk_ring_area);
   2.113  	blkif->blk_ring.sring = NULL;
   2.114      }
   2.115  
     3.1 --- a/linux-2.6-xen-sparse/drivers/xen/blktap/blktap.h	Thu Sep 22 11:35:35 2005 +0100
     3.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     3.3 @@ -1,229 +0,0 @@
     3.4 -/*
     3.5 - * blktap.h
     3.6 - * 
     3.7 - * Interfaces for the Xen block tap driver.
     3.8 - * 
     3.9 - * (c) 2004, Andrew Warfield, University of Cambridge
    3.10 - * 
    3.11 - */
    3.12 -
    3.13 -#ifndef __BLKTAP_H__
    3.14 -#define __BLKTAP_H__
    3.15 -
    3.16 -#include <linux/version.h>
    3.17 -#include <linux/blkdev.h>
    3.18 -#include <linux/config.h>
    3.19 -#include <linux/sched.h>
    3.20 -#include <linux/interrupt.h>
    3.21 -#include <linux/slab.h>
    3.22 -#include <linux/blkdev.h>
    3.23 -#include <asm/io.h>
    3.24 -#include <asm/setup.h>
    3.25 -#include <asm/pgalloc.h>
    3.26 -#include <asm/hypervisor.h>
    3.27 -#include <asm-xen/xen-public/io/blkif.h>
    3.28 -#include <asm-xen/xen-public/io/ring.h>
    3.29 -
    3.30 -/* Used to signal to the backend that this is a tap domain. */
    3.31 -#define BLKTAP_COOKIE 0xbeadfeed
    3.32 -
    3.33 -/* -------[ debug / pretty printing ]--------------------------------- */
    3.34 -
    3.35 -#define PRINTK(_f, _a...) printk(KERN_ALERT "(file=%s, line=%d) " _f, \
    3.36 -                           __FILE__ , __LINE__ , ## _a )
    3.37 -#if 0
    3.38 -#define DPRINTK(_f, _a...) printk(KERN_ALERT "(file=%s, line=%d) " _f, \
    3.39 -                           __FILE__ , __LINE__ , ## _a )
    3.40 -#else
    3.41 -#define DPRINTK(_f, _a...) ((void)0)
    3.42 -#endif
    3.43 -
    3.44 -#if 1
    3.45 -#define ASSERT(_p) \
    3.46 -    if ( !(_p) ) { printk("Assertion '%s' failed, line %d, file %s", #_p , \
    3.47 -    __LINE__, __FILE__); *(int*)0=0; }
    3.48 -#else
    3.49 -#define ASSERT(_p) ((void)0)
    3.50 -#endif
    3.51 -
    3.52 -#define WPRINTK(fmt, args...) printk(KERN_WARNING "blk_tap: " fmt, ##args)
    3.53 -
    3.54 -
    3.55 -/* -------[ state descriptors ]--------------------------------------- */
    3.56 -
    3.57 -#define BLKIF_STATE_CLOSED       0
    3.58 -#define BLKIF_STATE_DISCONNECTED 1
    3.59 -#define BLKIF_STATE_CONNECTED    2
    3.60 -
    3.61 -/* -------[ connection tracking ]------------------------------------- */
    3.62 -
    3.63 -#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
    3.64 -#define VMALLOC_VMADDR(x) ((unsigned long)(x))
    3.65 -#endif
    3.66 -
    3.67 -extern spinlock_t blkif_io_lock;
    3.68 -
    3.69 -typedef struct blkif_st {
    3.70 -    /* Unique identifier for this interface. */
    3.71 -    domid_t             domid;
    3.72 -    unsigned int        handle;
    3.73 -    /* Physical parameters of the comms window. */
    3.74 -    unsigned long       shmem_frame;
    3.75 -    unsigned int        evtchn;
    3.76 -    /* Comms information. */
    3.77 -    blkif_back_ring_t   blk_ring;
    3.78 -    
    3.79 -    enum { DISCONNECTED, DISCONNECTING, CONNECTED } status;
    3.80 -    /*
    3.81 -     * DISCONNECT response is deferred until pending requests are ack'ed.
    3.82 -     * We therefore need to store the id from the original request.
    3.83 -     */    
    3.84 -    u8                  disconnect_rspid;
    3.85 -    struct blkif_st    *hash_next;
    3.86 -    struct list_head    blkdev_list;
    3.87 -    spinlock_t          blk_ring_lock;
    3.88 -    atomic_t            refcnt;
    3.89 -    struct work_struct work;
    3.90 -#ifdef CONFIG_XEN_BLKDEV_GRANT
    3.91 -    u16 shmem_handle;
    3.92 -    unsigned long shmem_vaddr;
    3.93 -    grant_ref_t shmem_ref;
    3.94 -#endif
    3.95 -} blkif_t;
    3.96 -
    3.97 -blkif_t *blkif_find_by_handle(domid_t domid, unsigned int handle);
    3.98 -void blkif_disconnect_complete(blkif_t *blkif);
    3.99 -#define blkif_get(_b) (atomic_inc(&(_b)->refcnt))
   3.100 -#define blkif_put(_b)                             \
   3.101 -    do {                                          \
   3.102 -        if ( atomic_dec_and_test(&(_b)->refcnt) ) \
   3.103 -            blkif_disconnect_complete(_b);        \
   3.104 -    } while (0)
   3.105 -
   3.106 -
   3.107 -/* -------[ active request tracking ]--------------------------------- */
   3.108 -
   3.109 -typedef struct {
   3.110 -    blkif_t       *blkif;
   3.111 -    unsigned long  id;
   3.112 -    int            nr_pages;
   3.113 -    int            next_free;
   3.114 -} active_req_t;
   3.115 -
   3.116 -typedef unsigned int ACTIVE_RING_IDX;
   3.117 -
   3.118 -active_req_t *lookup_active_req(ACTIVE_RING_IDX idx);
   3.119 -
   3.120 -extern inline unsigned int ID_TO_IDX(unsigned long id) 
   3.121 -{ 
   3.122 -    return ( id & 0x0000ffff );
   3.123 -}
   3.124 -
   3.125 -extern inline domid_t ID_TO_DOM(unsigned long id) 
   3.126 -{ 
   3.127 -    return (id >> 16); 
   3.128 -}
   3.129 -
   3.130 -void active_reqs_init(void);
   3.131 -
   3.132 -/* -------[ interposition -> character device interface ]------------- */
   3.133 -
   3.134 -/* /dev/xen/blktap resides at device number major=10, minor=200        */ 
   3.135 -#define BLKTAP_MINOR 202
   3.136 -
   3.137 -/* size of the extra VMA area to map in attached pages. */
   3.138 -#define BLKTAP_VMA_PAGES BLKIF_RING_SIZE
   3.139 -
   3.140 -/* blktap IOCTLs:                                                      */
   3.141 -#define BLKTAP_IOCTL_KICK_FE         1
   3.142 -#define BLKTAP_IOCTL_KICK_BE         2
   3.143 -#define BLKTAP_IOCTL_SETMODE         3
   3.144 -#define BLKTAP_IOCTL_PRINT_IDXS      100  
   3.145 -
   3.146 -/* blktap switching modes: (Set with BLKTAP_IOCTL_SETMODE)             */
   3.147 -#define BLKTAP_MODE_PASSTHROUGH      0x00000000  /* default            */
   3.148 -#define BLKTAP_MODE_INTERCEPT_FE     0x00000001
   3.149 -#define BLKTAP_MODE_INTERCEPT_BE     0x00000002
   3.150 -#define BLKTAP_MODE_COPY_FE          0x00000004
   3.151 -#define BLKTAP_MODE_COPY_BE          0x00000008
   3.152 -#define BLKTAP_MODE_COPY_FE_PAGES    0x00000010
   3.153 -#define BLKTAP_MODE_COPY_BE_PAGES    0x00000020
   3.154 -
   3.155 -#define BLKTAP_MODE_INTERPOSE \
   3.156 -           (BLKTAP_MODE_INTERCEPT_FE | BLKTAP_MODE_INTERCEPT_BE)
   3.157 -
   3.158 -#define BLKTAP_MODE_COPY_BOTH \
   3.159 -           (BLKTAP_MODE_COPY_FE | BLKTAP_MODE_COPY_BE)
   3.160 -
   3.161 -#define BLKTAP_MODE_COPY_BOTH_PAGES \
   3.162 -           (BLKTAP_MODE_COPY_FE_PAGES | BLKTAP_MODE_COPY_BE_PAGES)
   3.163 -
   3.164 -static inline int BLKTAP_MODE_VALID(unsigned long arg)
   3.165 -{
   3.166 -    return (
   3.167 -        ( arg == BLKTAP_MODE_PASSTHROUGH  ) ||
   3.168 -        ( arg == BLKTAP_MODE_INTERCEPT_FE ) ||
   3.169 -        ( arg == BLKTAP_MODE_INTERCEPT_BE ) ||
   3.170 -        ( arg == BLKTAP_MODE_INTERPOSE    ) ||
   3.171 -        ( (arg & ~BLKTAP_MODE_COPY_FE_PAGES) == BLKTAP_MODE_COPY_FE ) ||
   3.172 -        ( (arg & ~BLKTAP_MODE_COPY_BE_PAGES) == BLKTAP_MODE_COPY_BE ) ||
   3.173 -        ( (arg & ~BLKTAP_MODE_COPY_BOTH_PAGES) == BLKTAP_MODE_COPY_BOTH )
   3.174 -        );
   3.175 -}
   3.176 -
   3.177 -
   3.178 -
   3.179 -/* -------[ Mappings to User VMA ]------------------------------------ */
   3.180 -#define BATCH_PER_DOMAIN 16
   3.181 -
   3.182 -/* -------[ Here be globals ]----------------------------------------- */
   3.183 -extern unsigned long blktap_mode;
   3.184 -
   3.185 -/* Connection to a single backend domain. */
   3.186 -extern blkif_front_ring_t blktap_be_ring;
   3.187 -extern unsigned int blktap_be_evtchn;
   3.188 -extern unsigned int blktap_be_state;
   3.189 -
   3.190 -/* User ring status. */
   3.191 -extern unsigned long blktap_ring_ok;
   3.192 -
   3.193 -/* -------[ ...and function prototypes. ]----------------------------- */
   3.194 -
   3.195 -/* init function for character device interface.                       */
   3.196 -int blktap_init(void);
   3.197 -
   3.198 -/* init function for the blkif cache. */
   3.199 -void __init blkif_interface_init(void);
   3.200 -void __init blkdev_schedule_init(void);
   3.201 -void blkif_deschedule(blkif_t *blkif);
   3.202 -
   3.203 -/* interfaces to the char driver, passing messages to and from apps.   */
   3.204 -void blktap_kick_user(void);
   3.205 -
   3.206 -/* user ring access functions: */
   3.207 -int blktap_write_fe_ring(blkif_request_t *req);
   3.208 -int blktap_write_be_ring(blkif_response_t *rsp);
   3.209 -int blktap_write_ctrl_ring(ctrl_msg_t *msg);
   3.210 -
   3.211 -/* fe/be ring access functions: */
   3.212 -int write_resp_to_fe_ring(blkif_t *blkif, blkif_response_t *rsp);
   3.213 -int write_req_to_be_ring(blkif_request_t *req);
   3.214 -
   3.215 -/* event notification functions */
   3.216 -void kick_fe_domain(blkif_t *blkif);
   3.217 -void kick_be_domain(void);
   3.218 -
   3.219 -/* Interrupt handlers. */
   3.220 -irqreturn_t blkif_ptbe_int(int irq, void *dev_id, 
   3.221 -                                  struct pt_regs *ptregs);
   3.222 -irqreturn_t blkif_ptfe_int(int irq, void *dev_id, struct pt_regs *regs);
   3.223 -
   3.224 -/* Control message receiver. */
   3.225 -extern void blkif_ctrlif_rx(ctrl_msg_t *msg, unsigned long id);
   3.226 -
   3.227 -/* debug */
   3.228 -void print_fe_ring_idxs(void);
   3.229 -void print_be_ring_idxs(void);
   3.230 -        
   3.231 -#define __BLKINT_H__
   3.232 -#endif
     4.1 --- a/linux-2.6-xen-sparse/drivers/xen/blktap/common.h	Thu Sep 22 11:35:35 2005 +0100
     4.2 +++ b/linux-2.6-xen-sparse/drivers/xen/blktap/common.h	Thu Sep 22 14:01:01 2005 +0100
     4.3 @@ -17,6 +17,7 @@
     4.4  #include <asm-xen/xen-public/io/blkif.h>
     4.5  #include <asm-xen/xen-public/io/ring.h>
     4.6  #include <asm-xen/gnttab.h>
     4.7 +#include <asm-xen/driver_util.h>
     4.8  
     4.9  #if 0
    4.10  #define ASSERT(_p) \
    4.11 @@ -44,11 +45,11 @@ typedef struct blkif_st {
    4.12      domid_t           domid;
    4.13      unsigned int      handle;
    4.14      /* Physical parameters of the comms window. */
    4.15 -    unsigned long     shmem_frame;
    4.16      unsigned int      evtchn;
    4.17      unsigned int      remote_evtchn;
    4.18      /* Comms information. */
    4.19      blkif_back_ring_t blk_ring;
    4.20 +    struct vm_struct *blk_ring_area;
    4.21      /* VBDs attached to this interface. */
    4.22      struct vbd        vbd;
    4.23      /* Private fields. */
    4.24 @@ -62,9 +63,9 @@ typedef struct blkif_st {
    4.25      atomic_t         refcnt;
    4.26  
    4.27      struct work_struct free_work;
    4.28 -    u16 shmem_handle;
    4.29 -    unsigned long shmem_vaddr;
    4.30 -    grant_ref_t shmem_ref;
    4.31 +
    4.32 +    u16              shmem_handle;
    4.33 +    grant_ref_t      shmem_ref;
    4.34  } blkif_t;
    4.35  
    4.36  blkif_t *alloc_blkif(domid_t domid);
     5.1 --- a/linux-2.6-xen-sparse/drivers/xen/blktap/interface.c	Thu Sep 22 11:35:35 2005 +0100
     5.2 +++ b/linux-2.6-xen-sparse/drivers/xen/blktap/interface.c	Thu Sep 22 14:01:01 2005 +0100
     5.3 @@ -8,135 +8,148 @@
     5.4  
     5.5  #include "common.h"
     5.6  #include <asm-xen/evtchn.h>
     5.7 -#include <asm-xen/driver_util.h>
     5.8  
     5.9  static kmem_cache_t *blkif_cachep;
    5.10  
    5.11  blkif_t *alloc_blkif(domid_t domid)
    5.12  {
    5.13 -    blkif_t *blkif;
    5.14 -
    5.15 -    blkif = kmem_cache_alloc(blkif_cachep, GFP_KERNEL);
    5.16 -    if (!blkif)
    5.17 -	    return ERR_PTR(-ENOMEM);
    5.18 +	blkif_t *blkif;
    5.19  
    5.20 -    memset(blkif, 0, sizeof(*blkif));
    5.21 -    blkif->domid = domid;
    5.22 -    blkif->status = DISCONNECTED;
    5.23 -    spin_lock_init(&blkif->blk_ring_lock);
    5.24 -    atomic_set(&blkif->refcnt, 1);
    5.25 +	blkif = kmem_cache_alloc(blkif_cachep, GFP_KERNEL);
    5.26 +	if (!blkif)
    5.27 +		return ERR_PTR(-ENOMEM);
    5.28  
    5.29 -    return blkif;
    5.30 +	memset(blkif, 0, sizeof(*blkif));
    5.31 +	blkif->domid = domid;
    5.32 +	blkif->status = DISCONNECTED;
    5.33 +	spin_lock_init(&blkif->blk_ring_lock);
    5.34 +	atomic_set(&blkif->refcnt, 1);
    5.35 +
    5.36 +	return blkif;
    5.37  }
    5.38  
    5.39 -static int map_frontend_page(blkif_t *blkif, unsigned long localaddr,
    5.40 -			     unsigned long shared_page)
    5.41 +static int map_frontend_page(blkif_t *blkif, unsigned long shared_page)
    5.42  {
    5.43 -    struct gnttab_map_grant_ref op;
    5.44 -    op.host_addr = localaddr;
    5.45 -    op.flags = GNTMAP_host_map;
    5.46 -    op.ref = shared_page;
    5.47 -    op.dom = blkif->domid;
    5.48 +	struct gnttab_map_grant_ref op;
    5.49  
    5.50 -    BUG_ON( HYPERVISOR_grant_table_op(GNTTABOP_map_grant_ref, &op, 1) );
    5.51 +	op.host_addr = (unsigned long)blkif->blk_ring_area->addr;
    5.52 +	op.flags     = GNTMAP_host_map;
    5.53 +	op.ref       = shared_page;
    5.54 +	op.dom       = blkif->domid;
    5.55  
    5.56 -    if (op.handle < 0) {
    5.57 -	DPRINTK(" Grant table operation failure !\n");
    5.58 -	return op.handle;
    5.59 -    }
    5.60 +	lock_vm_area(blkif->blk_ring_area);
    5.61 +	BUG_ON(HYPERVISOR_grant_table_op(GNTTABOP_map_grant_ref, &op, 1));
    5.62 +	unlock_vm_area(blkif->blk_ring_area);
    5.63  
    5.64 -    blkif->shmem_ref = shared_page;
    5.65 -    blkif->shmem_handle = op.handle;
    5.66 -    blkif->shmem_vaddr = localaddr;
    5.67 -    return 0;
    5.68 +	if (op.handle < 0) {
    5.69 +		DPRINTK(" Grant table operation failure !\n");
    5.70 +		return op.handle;
    5.71 +	}
    5.72 +
    5.73 +	blkif->shmem_ref    = shared_page;
    5.74 +	blkif->shmem_handle = op.handle;
    5.75 +
    5.76 +	return 0;
    5.77  }
    5.78  
    5.79  static void unmap_frontend_page(blkif_t *blkif)
    5.80  {
    5.81 -    struct gnttab_unmap_grant_ref op;
    5.82 +	struct gnttab_unmap_grant_ref op;
    5.83  
    5.84 -    op.host_addr = blkif->shmem_vaddr;
    5.85 -    op.handle = blkif->shmem_handle;
    5.86 -    op.dev_bus_addr = 0;
    5.87 -    BUG_ON(HYPERVISOR_grant_table_op(GNTTABOP_unmap_grant_ref, &op, 1));
    5.88 +	op.host_addr    = (unsigned long)blkif->blk_ring_area->addr;
    5.89 +	op.handle       = blkif->shmem_handle;
    5.90 +	op.dev_bus_addr = 0;
    5.91 +
    5.92 +	lock_vm_area(blkif->blk_ring_area);
    5.93 +	BUG_ON(HYPERVISOR_grant_table_op(GNTTABOP_unmap_grant_ref, &op, 1));
    5.94 +	unlock_vm_area(blkif->blk_ring_area);
    5.95  }
    5.96  
    5.97  int blkif_map(blkif_t *blkif, unsigned long shared_page, unsigned int evtchn)
    5.98  {
    5.99 -    struct vm_struct *vma;
   5.100 -    blkif_sring_t *sring;
   5.101 -    evtchn_op_t op = { .cmd = EVTCHNOP_bind_interdomain };
   5.102 -    int err;
   5.103 -
   5.104 -    BUG_ON(blkif->remote_evtchn);
   5.105 -
   5.106 -    if ( (vma = prepare_vm_area(PAGE_SIZE)) == NULL )
   5.107 -	return -ENOMEM;
   5.108 -
   5.109 -    err = map_frontend_page(blkif, (unsigned long)vma->addr, shared_page);
   5.110 -    if (err) {
   5.111 -        vunmap(vma->addr);
   5.112 -	return err;
   5.113 -    }
   5.114 +	blkif_sring_t *sring;
   5.115 +	evtchn_op_t op = { .cmd = EVTCHNOP_bind_interdomain };
   5.116 +	int err;
   5.117  
   5.118 -    op.u.bind_interdomain.dom1 = DOMID_SELF;
   5.119 -    op.u.bind_interdomain.dom2 = blkif->domid;
   5.120 -    op.u.bind_interdomain.port1 = 0;
   5.121 -    op.u.bind_interdomain.port2 = evtchn;
   5.122 -    err = HYPERVISOR_event_channel_op(&op);
   5.123 -    if (err) {
   5.124 -	unmap_frontend_page(blkif);
   5.125 -	vunmap(vma->addr);
   5.126 -	return err;
   5.127 -    }
   5.128 +	BUG_ON(blkif->remote_evtchn);
   5.129  
   5.130 -    blkif->evtchn = op.u.bind_interdomain.port1;
   5.131 -    blkif->remote_evtchn = evtchn;
   5.132 +	if ((blkif->blk_ring_area = alloc_vm_area(PAGE_SIZE)) == NULL)
   5.133 +		return -ENOMEM;
   5.134  
   5.135 -    sring = (blkif_sring_t *)vma->addr;
   5.136 -    SHARED_RING_INIT(sring);
   5.137 -    BACK_RING_INIT(&blkif->blk_ring, sring, PAGE_SIZE);
   5.138 +	err = map_frontend_page(blkif, shared_page);
   5.139 +	if (err) {
   5.140 +		free_vm_area(blkif->blk_ring_area);
   5.141 +		return err;
   5.142 +	}
   5.143  
   5.144 -    bind_evtchn_to_irqhandler(blkif->evtchn, blkif_be_int, 0, "blkif-backend",
   5.145 -			      blkif);
   5.146 -    blkif->status        = CONNECTED;
   5.147 -    blkif->shmem_frame   = shared_page;
   5.148 +	op.u.bind_interdomain.dom1 = DOMID_SELF;
   5.149 +	op.u.bind_interdomain.dom2 = blkif->domid;
   5.150 +	op.u.bind_interdomain.port1 = 0;
   5.151 +	op.u.bind_interdomain.port2 = evtchn;
   5.152 +	err = HYPERVISOR_event_channel_op(&op);
   5.153 +	if (err) {
   5.154 +		unmap_frontend_page(blkif);
   5.155 +		free_vm_area(blkif->blk_ring_area);
   5.156 +		return err;
   5.157 +	}
   5.158  
   5.159 -    return 0;
   5.160 +
   5.161 +	blkif->evtchn = op.u.bind_interdomain.port1;
   5.162 +	blkif->remote_evtchn = evtchn;
   5.163 +
   5.164 +	sring = (blkif_sring_t *)blkif->blk_ring_area->addr;
   5.165 +	SHARED_RING_INIT(sring);
   5.166 +	BACK_RING_INIT(&blkif->blk_ring, sring, PAGE_SIZE);
   5.167 +
   5.168 +	bind_evtchn_to_irqhandler(
   5.169 +		blkif->evtchn, blkif_be_int, 0, "blkif-backend", blkif);
   5.170 +	blkif->status        = CONNECTED;
   5.171 +
   5.172 +	return 0;
   5.173  }
   5.174  
   5.175  static void free_blkif(void *arg)
   5.176  {
   5.177 -    evtchn_op_t op = { .cmd = EVTCHNOP_close };
   5.178 -    blkif_t *blkif = (blkif_t *)arg;
   5.179 -
   5.180 -    op.u.close.port = blkif->evtchn;
   5.181 -    op.u.close.dom = DOMID_SELF;
   5.182 -    HYPERVISOR_event_channel_op(&op);
   5.183 -    op.u.close.port = blkif->remote_evtchn;
   5.184 -    op.u.close.dom = blkif->domid;
   5.185 -    HYPERVISOR_event_channel_op(&op);
   5.186 +	evtchn_op_t op = { .cmd = EVTCHNOP_close };
   5.187 +	blkif_t *blkif = (blkif_t *)arg;
   5.188  
   5.189 -    if (blkif->evtchn)
   5.190 -        unbind_evtchn_from_irqhandler(blkif->evtchn, blkif);
   5.191 +	op.u.close.port = blkif->evtchn;
   5.192 +	op.u.close.dom = DOMID_SELF;
   5.193 +	HYPERVISOR_event_channel_op(&op);
   5.194 +	op.u.close.port = blkif->remote_evtchn;
   5.195 +	op.u.close.dom = blkif->domid;
   5.196 +	HYPERVISOR_event_channel_op(&op);
   5.197  
   5.198 -    if (blkif->blk_ring.sring) {
   5.199 -	unmap_frontend_page(blkif);
   5.200 -	vunmap(blkif->blk_ring.sring);
   5.201 -	blkif->blk_ring.sring = NULL;
   5.202 -    }
   5.203 +	if (blkif->evtchn)
   5.204 +		unbind_evtchn_from_irqhandler(blkif->evtchn, blkif);
   5.205  
   5.206 -    kmem_cache_free(blkif_cachep, blkif);
   5.207 +	if (blkif->blk_ring.sring) {
   5.208 +		unmap_frontend_page(blkif);
   5.209 +		free_vm_area(blkif->blk_ring_area);
   5.210 +		blkif->blk_ring.sring = NULL;
   5.211 +	}
   5.212 +
   5.213 +	kmem_cache_free(blkif_cachep, blkif);
   5.214  }
   5.215  
   5.216  void free_blkif_callback(blkif_t *blkif)
   5.217  {
   5.218 -    INIT_WORK(&blkif->free_work, free_blkif, (void *)blkif);
   5.219 -    schedule_work(&blkif->free_work);
   5.220 +	INIT_WORK(&blkif->free_work, free_blkif, (void *)blkif);
   5.221 +	schedule_work(&blkif->free_work);
   5.222  }
   5.223  
   5.224  void __init blkif_interface_init(void)
   5.225  {
   5.226 -    blkif_cachep = kmem_cache_create("blkif_cache", sizeof(blkif_t), 
   5.227 -                                     0, 0, NULL, NULL);
   5.228 +	blkif_cachep = kmem_cache_create(
   5.229 +		"blkif_cache", sizeof(blkif_t), 0, 0, NULL, NULL);
   5.230  }
   5.231 +
   5.232 +/*
   5.233 + * Local variables:
   5.234 + *  c-file-style: "linux"
   5.235 + *  indent-tabs-mode: t
   5.236 + *  c-indent-level: 8
   5.237 + *  c-basic-offset: 8
   5.238 + *  tab-width: 8
   5.239 + * End:
   5.240 + */
     6.1 --- a/linux-2.6-xen-sparse/drivers/xen/netback/common.h	Thu Sep 22 11:35:35 2005 +0100
     6.2 +++ b/linux-2.6-xen-sparse/drivers/xen/netback/common.h	Thu Sep 22 14:01:01 2005 +0100
     6.3 @@ -20,6 +20,7 @@
     6.4  #include <asm/pgalloc.h>
     6.5  #include <asm-xen/xen-public/grant_table.h>
     6.6  #include <asm-xen/gnttab.h>
     6.7 +#include <asm-xen/driver_util.h>
     6.8  
     6.9  #define GRANT_INVALID_REF (0xFFFF)
    6.10  
    6.11 @@ -46,24 +47,17 @@ typedef struct netif_st {
    6.12  	u8               fe_dev_addr[6];
    6.13  
    6.14  	/* Physical parameters of the comms window. */
    6.15 -	unsigned long    tx_shmem_frame;
    6.16 -#ifdef CONFIG_XEN_NETDEV_GRANT
    6.17  	u16              tx_shmem_handle;
    6.18 -	unsigned long    tx_shmem_vaddr; 
    6.19  	grant_ref_t      tx_shmem_ref; 
    6.20 -#endif
    6.21 -	unsigned long    rx_shmem_frame;
    6.22 -#ifdef CONFIG_XEN_NETDEV_GRANT
    6.23  	u16              rx_shmem_handle;
    6.24 -	unsigned long    rx_shmem_vaddr; 
    6.25  	grant_ref_t      rx_shmem_ref; 
    6.26 -#endif
    6.27  	unsigned int     evtchn;
    6.28  	unsigned int     remote_evtchn;
    6.29  
    6.30  	/* The shared rings and indexes. */
    6.31  	netif_tx_interface_t *tx;
    6.32  	netif_rx_interface_t *rx;
    6.33 +	struct vm_struct *comms_area;
    6.34  
    6.35  	/* Private indexes into shared ring. */
    6.36  	NETIF_RING_IDX rx_req_cons;
     7.1 --- a/linux-2.6-xen-sparse/drivers/xen/netback/interface.c	Thu Sep 22 11:35:35 2005 +0100
     7.2 +++ b/linux-2.6-xen-sparse/drivers/xen/netback/interface.c	Thu Sep 22 14:01:01 2005 +0100
     7.3 @@ -8,7 +8,6 @@
     7.4  
     7.5  #include "common.h"
     7.6  #include <linux/rtnetlink.h>
     7.7 -#include <asm-xen/driver_util.h>
     7.8  
     7.9  static void __netif_up(netif_t *netif)
    7.10  {
    7.11 @@ -113,20 +112,20 @@ netif_t *alloc_netif(domid_t domid, unsi
    7.12  	return netif;
    7.13  }
    7.14  
    7.15 -static int map_frontend_pages(netif_t *netif, unsigned long localaddr,
    7.16 -                              unsigned long tx_ring_ref, 
    7.17 -                              unsigned long rx_ring_ref)
    7.18 +static int map_frontend_pages(
    7.19 +	netif_t *netif, grant_ref_t tx_ring_ref, grant_ref_t rx_ring_ref)
    7.20  {
    7.21 -#ifdef CONFIG_XEN_NETDEV_GRANT
    7.22  	struct gnttab_map_grant_ref op;
    7.23  
    7.24 -	/* Map: Use the Grant table reference */
    7.25 -	op.host_addr = localaddr;
    7.26 +	op.host_addr = (unsigned long)netif->comms_area->addr;
    7.27  	op.flags     = GNTMAP_host_map;
    7.28  	op.ref       = tx_ring_ref;
    7.29  	op.dom       = netif->domid;
    7.30      
    7.31 -	BUG_ON( HYPERVISOR_grant_table_op(GNTTABOP_map_grant_ref, &op, 1) );
    7.32 +	lock_vm_area(netif->comms_area);
    7.33 +	BUG_ON(HYPERVISOR_grant_table_op(GNTTABOP_map_grant_ref, &op, 1));
    7.34 +	unlock_vm_area(netif->comms_area);
    7.35 +
    7.36  	if (op.handle < 0) { 
    7.37  		DPRINTK(" Gnttab failure mapping tx_ring_ref!\n");
    7.38  		return op.handle;
    7.39 @@ -134,15 +133,16 @@ static int map_frontend_pages(netif_t *n
    7.40  
    7.41  	netif->tx_shmem_ref    = tx_ring_ref;
    7.42  	netif->tx_shmem_handle = op.handle;
    7.43 -	netif->tx_shmem_vaddr  = localaddr;
    7.44  
    7.45 -	/* Map: Use the Grant table reference */
    7.46 -	op.host_addr = localaddr + PAGE_SIZE;
    7.47 +	op.host_addr = (unsigned long)netif->comms_area->addr + PAGE_SIZE;
    7.48  	op.flags     = GNTMAP_host_map;
    7.49  	op.ref       = rx_ring_ref;
    7.50  	op.dom       = netif->domid;
    7.51  
    7.52 -	BUG_ON( HYPERVISOR_grant_table_op(GNTTABOP_map_grant_ref, &op, 1) );
    7.53 +	lock_vm_area(netif->comms_area);
    7.54 +	BUG_ON(HYPERVISOR_grant_table_op(GNTTABOP_map_grant_ref, &op, 1));
    7.55 +	unlock_vm_area(netif->comms_area);
    7.56 +
    7.57  	if (op.handle < 0) { 
    7.58  		DPRINTK(" Gnttab failure mapping rx_ring_ref!\n");
    7.59  		return op.handle;
    7.60 @@ -150,63 +150,44 @@ static int map_frontend_pages(netif_t *n
    7.61  
    7.62  	netif->rx_shmem_ref    = rx_ring_ref;
    7.63  	netif->rx_shmem_handle = op.handle;
    7.64 -	netif->rx_shmem_vaddr  = localaddr + PAGE_SIZE;
    7.65 -
    7.66 -#else
    7.67 -	pgprot_t prot = __pgprot(_KERNPG_TABLE);
    7.68 -	int      err;
    7.69 -
    7.70 -	err = direct_remap_pfn_range(
    7.71 -		&init_mm, localaddr,
    7.72 -		tx_ring_ref, PAGE_SIZE,
    7.73 -		prot, netif->domid); 
    7.74 -    
    7.75 -	err |= direct_remap_pfn_range(
    7.76 -		&init_mm, localaddr + PAGE_SIZE,
    7.77 -		rx_ring_ref, PAGE_SIZE,
    7.78 -		prot, netif->domid);
    7.79 -
    7.80 -	if (err)
    7.81 -		return err;
    7.82 -#endif
    7.83  
    7.84  	return 0;
    7.85  }
    7.86  
    7.87  static void unmap_frontend_pages(netif_t *netif)
    7.88  {
    7.89 -#ifdef CONFIG_XEN_NETDEV_GRANT
    7.90  	struct gnttab_unmap_grant_ref op;
    7.91  
    7.92 -	op.host_addr    = netif->tx_shmem_vaddr;
    7.93 +	op.host_addr    = (unsigned long)netif->comms_area->addr;
    7.94  	op.handle       = netif->tx_shmem_handle;
    7.95  	op.dev_bus_addr = 0;
    7.96 +
    7.97 +	lock_vm_area(netif->comms_area);
    7.98  	BUG_ON(HYPERVISOR_grant_table_op(GNTTABOP_unmap_grant_ref, &op, 1));
    7.99 +	unlock_vm_area(netif->comms_area);
   7.100  
   7.101 -	op.host_addr    = netif->rx_shmem_vaddr;
   7.102 +	op.host_addr    = (unsigned long)netif->comms_area->addr + PAGE_SIZE;
   7.103  	op.handle       = netif->rx_shmem_handle;
   7.104  	op.dev_bus_addr = 0;
   7.105 +
   7.106 +	lock_vm_area(netif->comms_area);
   7.107  	BUG_ON(HYPERVISOR_grant_table_op(GNTTABOP_unmap_grant_ref, &op, 1));
   7.108 -#endif
   7.109 -
   7.110 -	return; 
   7.111 +	unlock_vm_area(netif->comms_area);
   7.112  }
   7.113  
   7.114  int netif_map(netif_t *netif, unsigned long tx_ring_ref,
   7.115  	      unsigned long rx_ring_ref, unsigned int evtchn)
   7.116  {
   7.117 -	struct vm_struct *vma;
   7.118  	evtchn_op_t op = { .cmd = EVTCHNOP_bind_interdomain };
   7.119  	int err;
   7.120  
   7.121 -	vma = prepare_vm_area(2*PAGE_SIZE);
   7.122 -	if (vma == NULL)
   7.123 +	netif->comms_area = alloc_vm_area(2*PAGE_SIZE);
   7.124 +	if (netif->comms_area == NULL)
   7.125  		return -ENOMEM;
   7.126  
   7.127 -	err = map_frontend_pages(
   7.128 -		netif, (unsigned long)vma->addr, tx_ring_ref, rx_ring_ref);
   7.129 +	err = map_frontend_pages(netif, tx_ring_ref, rx_ring_ref);
   7.130  	if (err) {
   7.131 -		vunmap(vma->addr);
   7.132 +		free_vm_area(netif->comms_area);
   7.133  		return err;
   7.134  	}
   7.135  
   7.136 @@ -217,15 +198,16 @@ int netif_map(netif_t *netif, unsigned l
   7.137  	err = HYPERVISOR_event_channel_op(&op);
   7.138  	if (err) {
   7.139  		unmap_frontend_pages(netif);
   7.140 -		vunmap(vma->addr);
   7.141 +		free_vm_area(netif->comms_area);
   7.142  		return err;
   7.143  	}
   7.144  
   7.145  	netif->evtchn = op.u.bind_interdomain.port1;
   7.146  	netif->remote_evtchn = evtchn;
   7.147  
   7.148 -	netif->tx = (netif_tx_interface_t *)vma->addr;
   7.149 -	netif->rx = (netif_rx_interface_t *)((char *)vma->addr + PAGE_SIZE);
   7.150 +	netif->tx = (netif_tx_interface_t *)netif->comms_area->addr;
   7.151 +	netif->rx = (netif_rx_interface_t *)
   7.152 +		((char *)netif->comms_area->addr + PAGE_SIZE);
   7.153  	netif->tx->resp_prod = netif->rx->resp_prod = 0;
   7.154  	netif_get(netif);
   7.155  	wmb(); /* Other CPUs see new state before interface is started. */
   7.156 @@ -262,7 +244,7 @@ static void free_netif_callback(void *ar
   7.157  
   7.158  	if (netif->tx) {
   7.159  		unmap_frontend_pages(netif);
   7.160 -		vunmap(netif->tx); /* Frees netif->rx as well. */
   7.161 +		free_vm_area(netif->comms_area);
   7.162  	}
   7.163  
   7.164  	free_netdev(netif->dev);
     8.1 --- a/linux-2.6-xen-sparse/drivers/xen/tpmback/common.h	Thu Sep 22 11:35:35 2005 +0100
     8.2 +++ b/linux-2.6-xen-sparse/drivers/xen/tpmback/common.h	Thu Sep 22 14:01:01 2005 +0100
     8.3 @@ -11,6 +11,7 @@
     8.4  #include <linux/interrupt.h>
     8.5  #include <linux/slab.h>
     8.6  #include <asm-xen/evtchn.h>
     8.7 +#include <asm-xen/driver_util.h>
     8.8  #include <asm-xen/xen-public/io/tpmif.h>
     8.9  #include <asm/io.h>
    8.10  #include <asm/pgalloc.h>
    8.11 @@ -33,12 +34,12 @@ typedef struct tpmif_st {
    8.12  	unsigned int handle;
    8.13  
    8.14  	/* Physical parameters of the comms window. */
    8.15 -	unsigned long tx_shmem_frame;
    8.16  	unsigned int evtchn;
    8.17  	unsigned int remote_evtchn;
    8.18  
    8.19  	/* The shared rings and indexes. */
    8.20  	tpmif_tx_interface_t *tx;
    8.21 +	struct vm_struct *tx_area;
    8.22  
    8.23  	/* Miscellaneous private stuff. */
    8.24  	enum { DISCONNECTED, DISCONNECTING, CONNECTED } status;
    8.25 @@ -54,9 +55,7 @@ typedef struct tpmif_st {
    8.26  	struct work_struct work;
    8.27  
    8.28  	u16 shmem_handle;
    8.29 -	unsigned long shmem_vaddr;
    8.30  	grant_ref_t shmem_ref;
    8.31 -
    8.32  } tpmif_t;
    8.33  
    8.34  void tpmif_disconnect_complete(tpmif_t * tpmif);
     9.1 --- a/linux-2.6-xen-sparse/drivers/xen/tpmback/interface.c	Thu Sep 22 11:35:35 2005 +0100
     9.2 +++ b/linux-2.6-xen-sparse/drivers/xen/tpmback/interface.c	Thu Sep 22 14:01:01 2005 +0100
     9.3 @@ -13,9 +13,6 @@
     9.4  
     9.5  #include "common.h"
     9.6  #include <asm-xen/balloon.h>
     9.7 -#include <asm-xen/driver_util.h>
     9.8 -
     9.9 -#define VMALLOC_VMADDR(x) ((unsigned long)(x))
    9.10  
    9.11  #define TPMIF_HASHSZ (2 << 5)
    9.12  #define TPMIF_HASH(_d,_h) (((int)(_d)^(int)(_h))&(TPMIF_HASHSZ-1))
    9.13 @@ -79,17 +76,18 @@ tpmif_find(domid_t domid, long int insta
    9.14  }
    9.15  
    9.16  static int
    9.17 -map_frontend_page(tpmif_t * tpmif, unsigned long localaddr,
    9.18 -		  unsigned long shared_page)
    9.19 +map_frontend_page(tpmif_t *tpmif, unsigned long shared_page)
    9.20  {
    9.21  	struct gnttab_map_grant_ref op = {
    9.22 -		.host_addr = localaddr,
    9.23 +		.host_addr = (unsigned long)tpmif->tx_area->addr,
    9.24  		.flags = GNTMAP_host_map,
    9.25  		.ref = shared_page,
    9.26  		.dom = tpmif->domid,
    9.27  	};
    9.28  
    9.29 +	lock_vm_area(tpmif->tx_area);
    9.30  	BUG_ON(HYPERVISOR_grant_table_op(GNTTABOP_map_grant_ref, &op, 1));
    9.31 +	unlock_vm_area(tpmif->tx_area);
    9.32  
    9.33  	if (op.handle < 0) {
    9.34  		DPRINTK(" Grant table operation failure !\n");
    9.35 @@ -98,37 +96,38 @@ map_frontend_page(tpmif_t * tpmif, unsig
    9.36  
    9.37  	tpmif->shmem_ref = shared_page;
    9.38  	tpmif->shmem_handle = op.handle;
    9.39 -	tpmif->shmem_vaddr = localaddr;
    9.40 +
    9.41  	return 0;
    9.42  }
    9.43  
    9.44  static void
    9.45 -unmap_frontend_page(tpmif_t * tpmif)
    9.46 +unmap_frontend_page(tpmif_t *tpmif)
    9.47  {
    9.48  	struct gnttab_unmap_grant_ref op;
    9.49  
    9.50 -	op.host_addr = tpmif->shmem_vaddr;
    9.51 -	op.handle = tpmif->shmem_handle;
    9.52 +	op.host_addr    = (unsigned long)tpmif->tx_area->addr;
    9.53 +	op.handle       = tpmif->shmem_handle;
    9.54  	op.dev_bus_addr = 0;
    9.55  
    9.56 +	lock_vm_area(tpmif->tx_area);
    9.57  	BUG_ON(HYPERVISOR_grant_table_op(GNTTABOP_unmap_grant_ref, &op, 1));
    9.58 +	unlock_vm_area(tpmif->tx_area);
    9.59  }
    9.60  
    9.61  int
    9.62 -tpmif_map(tpmif_t * tpmif, unsigned long shared_page, unsigned int evtchn)
    9.63 +tpmif_map(tpmif_t *tpmif, unsigned long shared_page, unsigned int evtchn)
    9.64  {
    9.65 -	struct vm_struct *vma;
    9.66  	evtchn_op_t op = {.cmd = EVTCHNOP_bind_interdomain };
    9.67  	int err;
    9.68  
    9.69  	BUG_ON(tpmif->remote_evtchn);
    9.70  
    9.71 -	if ((vma = prepare_vm_area(PAGE_SIZE)) == NULL)
    9.72 +	if ((tpmif->tx_area = alloc_vm_area(PAGE_SIZE)) == NULL)
    9.73  		return -ENOMEM;
    9.74  
    9.75 -	err = map_frontend_page(tpmif, VMALLOC_VMADDR(vma->addr), shared_page);
    9.76 +	err = map_frontend_page(tpmif, shared_page);
    9.77  	if (err) {
    9.78 -		vunmap(vma->addr);
    9.79 +		free_vm_area(tpmif->tx_area);
    9.80  		return err;
    9.81  	}
    9.82  
    9.83 @@ -139,14 +138,14 @@ tpmif_map(tpmif_t * tpmif, unsigned long
    9.84  	err = HYPERVISOR_event_channel_op(&op);
    9.85  	if (err) {
    9.86  		unmap_frontend_page(tpmif);
    9.87 -		vunmap(vma->addr);
    9.88 +		free_vm_area(tpmif->tx_area);
    9.89  		return err;
    9.90  	}
    9.91  
    9.92  	tpmif->evtchn = op.u.bind_interdomain.port1;
    9.93  	tpmif->remote_evtchn = evtchn;
    9.94  
    9.95 -	tpmif->tx = (tpmif_tx_interface_t *) vma->addr;
    9.96 +	tpmif->tx = (tpmif_tx_interface_t *)tpmif->tx_area->addr;
    9.97  
    9.98  	bind_evtchn_to_irqhandler(tpmif->evtchn,
    9.99  				  tpmif_be_int, 0, "tpmif-backend", tpmif);
   9.100 @@ -175,7 +174,7 @@ static void
   9.101  
   9.102  	if (tpmif->tx) {
   9.103  		unmap_frontend_page(tpmif);
   9.104 -		vunmap(tpmif->tx);
   9.105 +		free_vm_area(tpmif->tx_area);
   9.106  	}
   9.107  
   9.108  	free_tpmif(tpmif);
   9.109 @@ -194,3 +193,13 @@ tpmif_interface_init(void)
   9.110  	tpmif_cachep = kmem_cache_create("tpmif_cache", sizeof (tpmif_t),
   9.111  					 0, 0, NULL, NULL);
   9.112  }
   9.113 +
   9.114 +/*
   9.115 + * Local variables:
   9.116 + *  c-file-style: "linux"
   9.117 + *  indent-tabs-mode: t
   9.118 + *  c-indent-level: 8
   9.119 + *  c-basic-offset: 8
   9.120 + *  tab-width: 8
   9.121 + * End:
   9.122 + */
    10.1 --- a/linux-2.6-xen-sparse/drivers/xen/usbback/common.h	Thu Sep 22 11:35:35 2005 +0100
    10.2 +++ b/linux-2.6-xen-sparse/drivers/xen/usbback/common.h	Thu Sep 22 14:01:01 2005 +0100
    10.3 @@ -13,7 +13,7 @@
    10.4  #include <asm/setup.h>
    10.5  #include <asm/pgalloc.h>
    10.6  #include <asm/hypervisor.h>
    10.7 -
    10.8 +#include <asm-xen/driver_util.h>
    10.9  #include <asm-xen/xen-public/io/usbif.h>
   10.10  
   10.11  #if 0
   10.12 @@ -38,6 +38,7 @@ struct usbif_priv_st {
   10.13      unsigned int     evtchn;
   10.14      /* Comms Information */
   10.15      usbif_back_ring_t usb_ring;
   10.16 +    struct vm_struct *usb_ring_area;
   10.17      /* Private fields. */
   10.18      enum { DISCONNECTED, DISCONNECTING, CONNECTED } status;
   10.19      /*
    11.1 --- a/linux-2.6-xen-sparse/drivers/xen/usbback/interface.c	Thu Sep 22 11:35:35 2005 +0100
    11.2 +++ b/linux-2.6-xen-sparse/drivers/xen/usbback/interface.c	Thu Sep 22 14:01:01 2005 +0100
    11.3 @@ -7,7 +7,6 @@
    11.4   */
    11.5  
    11.6  #include "common.h"
    11.7 -#include <asm-xen/driver_util.h>
    11.8  
    11.9  #define USBIF_HASHSZ 1024
   11.10  #define USBIF_HASH(_d) (((int)(_d))&(USBIF_HASHSZ-1))
   11.11 @@ -34,7 +33,7 @@ static void __usbif_disconnect_complete(
   11.12       * may be outstanding requests at the device whose asynchronous responses
   11.13       * must still be notified to the remote driver.
   11.14       */
   11.15 -    vunmap(usbif->usb_ring.sring);
   11.16 +    free_vm_area(usbif->usb_ring_area);
   11.17  
   11.18      /* Construct the deferred response message. */
   11.19      cmsg.type         = CMSG_USBIF_BE;
   11.20 @@ -140,7 +139,6 @@ void usbif_connect(usbif_be_connect_t *c
   11.21      domid_t       domid  = connect->domid;
   11.22      unsigned int  evtchn = connect->evtchn;
   11.23      unsigned long shmem_frame = connect->shmem_frame;
   11.24 -    struct vm_struct *vma;
   11.25      pgprot_t      prot;
   11.26      int           error;
   11.27      usbif_priv_t *up;
   11.28 @@ -155,14 +153,14 @@ void usbif_connect(usbif_be_connect_t *c
   11.29          return;
   11.30      }
   11.31  
   11.32 -    if ( (vma = prepare_vm_area(PAGE_SIZE)) == NULL )
   11.33 +    if ( (up->usb_ring_area = alloc_vm_area(PAGE_SIZE)) == NULL )
   11.34      {
   11.35          connect->status = USBIF_BE_STATUS_OUT_OF_MEMORY;
   11.36          return;
   11.37      }
   11.38  
   11.39      prot = __pgprot(_KERNPG_TABLE);
   11.40 -    error = direct_remap_pfn_range(&init_mm, VMALLOC_VMADDR(vma->addr),
   11.41 +    error = direct_remap_pfn_range(&init_mm, AREALLOC_AREADDR(area->addr),
   11.42                                      shmem_frame, PAGE_SIZE,
   11.43                                      prot, domid);
   11.44      if ( error != 0 )
   11.45 @@ -173,18 +171,18 @@ void usbif_connect(usbif_be_connect_t *c
   11.46              connect->status = USBIF_BE_STATUS_MAPPING_ERROR;
   11.47          else
   11.48              connect->status = USBIF_BE_STATUS_ERROR;
   11.49 -        vunmap(vma->addr);
   11.50 +        free_vm_area(up->usb_ring_area);
   11.51          return;
   11.52      }
   11.53  
   11.54      if ( up->status != DISCONNECTED )
   11.55      {
   11.56          connect->status = USBIF_BE_STATUS_INTERFACE_CONNECTED;
   11.57 -        vunmap(vma->addr);
   11.58 +        free_vm_area(up->usb_ring_area);
   11.59          return;
   11.60      }
   11.61  
   11.62 -    sring = (usbif_sring_t *)vma->addr;
   11.63 +    sring = (usbif_sring_t *)area->addr;
   11.64      SHARED_RING_INIT(sring);
   11.65      BACK_RING_INIT(&up->usb_ring, sring, PAGE_SIZE);
   11.66  
    12.1 --- a/linux-2.6-xen-sparse/drivers/xen/util.c	Thu Sep 22 11:35:35 2005 +0100
    12.2 +++ b/linux-2.6-xen-sparse/drivers/xen/util.c	Thu Sep 22 14:01:01 2005 +0100
    12.3 @@ -3,16 +3,15 @@
    12.4  #include <linux/slab.h>
    12.5  #include <linux/vmalloc.h>
    12.6  #include <asm/uaccess.h>
    12.7 +#include <asm-xen/driver_util.h>
    12.8  
    12.9 -static int touch_fn(
   12.10 -	pte_t *pte, struct page *pte_page, unsigned long addr, void *data)
   12.11 +static int f(pte_t *pte, struct page *pte_page, unsigned long addr, void *data)
   12.12  {
   12.13 -	char c;
   12.14 -	BUG_ON(!__get_user(c, (char *)addr));
   12.15 +	/* generic_page_range() does all the hard work. */
   12.16  	return 0;
   12.17  }
   12.18  
   12.19 -struct vm_struct *prepare_vm_area(unsigned long size)
   12.20 +struct vm_struct *alloc_vm_area(unsigned long size)
   12.21  {
   12.22  	struct vm_struct *area;
   12.23  
   12.24 @@ -21,20 +20,48 @@ struct vm_struct *prepare_vm_area(unsign
   12.25  		return NULL;
   12.26  
   12.27  	/*
   12.28 -         * This ensures that page tables are constructed for this region
   12.29 -         * of kernel virtual address space. Furthermore, by touching each
   12.30 -         * memory page (in touch_fn()) we ensure that the page tables are
   12.31 -         * mapped into the current mm as well as init_mm.
   12.32 -         */
   12.33 +	 * This ensures that page tables are constructed for this region
   12.34 +	 * of kernel virtual address space and mapped into init_mm.
   12.35 +	 */
   12.36  	if (generic_page_range(&init_mm, (unsigned long)area->addr,
   12.37 -			       area->size, touch_fn, NULL)) {
   12.38 -		vunmap(area->addr);
   12.39 +			       area->size, f, NULL)) {
   12.40 +		free_vm_area(area);
   12.41  		return NULL;
   12.42  	}
   12.43  
   12.44  	return area;
   12.45  }
   12.46  
   12.47 +void free_vm_area(struct vm_struct *area)
   12.48 +{
   12.49 +	BUG_ON(remove_vm_area(area->addr) != area);
   12.50 +	kfree(area);
   12.51 +}
   12.52 +
   12.53 +void lock_vm_area(struct vm_struct *area)
   12.54 +{
   12.55 +	unsigned long i;
   12.56 +	char c;
   12.57 +
   12.58 +	/*
   12.59 +	 * Prevent context switch to a lazy mm that doesn't have this area
   12.60 +	 * mapped into its page tables.
   12.61 +	 */
   12.62 +	preempt_disable();
   12.63 +
   12.64 +	/*
   12.65 +	 * Ensure that the page tables are mapped into the current mm. The
   12.66 +	 * page-fault path will copy the page directory pointers from init_mm.
   12.67 +	 */
   12.68 +	for (i = 0; i < area->size; i += PAGE_SIZE)
   12.69 +		(void)__get_user(c, (char *)area->addr + i);
   12.70 +}
   12.71 +
   12.72 +void unlock_vm_area(struct vm_struct *area)
   12.73 +{
   12.74 +	preempt_enable();
   12.75 +}
   12.76 +
   12.77  /*
   12.78   * Local variables:
   12.79   *  c-file-style: "linux"
    13.1 --- a/linux-2.6-xen-sparse/include/asm-xen/driver_util.h	Thu Sep 22 11:35:35 2005 +0100
    13.2 +++ b/linux-2.6-xen-sparse/include/asm-xen/driver_util.h	Thu Sep 22 14:01:01 2005 +0100
    13.3 @@ -5,6 +5,12 @@
    13.4  #include <linux/config.h>
    13.5  #include <linux/vmalloc.h>
    13.6  
    13.7 -extern struct vm_struct *prepare_vm_area(unsigned long size);
    13.8 +/* Allocate/destroy a 'vmalloc' VM area. */
    13.9 +extern struct vm_struct *alloc_vm_area(unsigned long size);
   13.10 +extern void free_vm_area(struct vm_struct *area);
   13.11 +
   13.12 +/* Lock an area so that PTEs are accessible in the current address space. */
   13.13 +extern void lock_vm_area(struct vm_struct *area);
   13.14 +extern void unlock_vm_area(struct vm_struct *area);
   13.15  
   13.16  #endif /* __ASM_XEN_DRIVER_UTIL_H__ */