ia64/xen-unstable

changeset 9695:c3bb51c443a7

Make grant table map/unmap argument, host_addr, feature-specific.
Introduce gnttab_set_map_op() and gnttab_set_unmap_op() to initialize.

Signed-off-by: Isaku Yamahata <yamahata@valinux.co.jp>
author kaf24@firebug.cl.cam.ac.uk
date Thu Apr 13 10:29:27 2006 +0100 (2006-04-13)
parents a9ae49b52c28
children 0267063e050c
files linux-2.6-xen-sparse/drivers/xen/blkback/blkback.c linux-2.6-xen-sparse/drivers/xen/blkback/interface.c linux-2.6-xen-sparse/drivers/xen/blktap/blktap.c linux-2.6-xen-sparse/drivers/xen/blktap/interface.c linux-2.6-xen-sparse/drivers/xen/netback/interface.c linux-2.6-xen-sparse/drivers/xen/netback/netback.c linux-2.6-xen-sparse/drivers/xen/tpmback/interface.c linux-2.6-xen-sparse/drivers/xen/tpmback/tpmback.c linux-2.6-xen-sparse/drivers/xen/xenbus/xenbus_backend_client.c linux-2.6-xen-sparse/include/xen/gnttab.h
line diff
     1.1 --- a/linux-2.6-xen-sparse/drivers/xen/blkback/blkback.c	Thu Apr 13 10:12:16 2006 +0100
     1.2 +++ b/linux-2.6-xen-sparse/drivers/xen/blkback/blkback.c	Thu Apr 13 10:29:27 2006 +0100
     1.3 @@ -186,9 +186,8 @@ static void fast_flush_area(pending_req_
     1.4  		handle = pending_handle(req, i);
     1.5  		if (handle == BLKBACK_INVALID_HANDLE)
     1.6  			continue;
     1.7 -		unmap[invcount].host_addr    = vaddr(req, i);
     1.8 -		unmap[invcount].dev_bus_addr = 0;
     1.9 -		unmap[invcount].handle       = handle;
    1.10 +		gnttab_set_unmap_op(&unmap[i], vaddr(req, i), GNTMAP_host_map,
    1.11 +				    handle);
    1.12  		pending_handle(req, i) = BLKBACK_INVALID_HANDLE;
    1.13  		invcount++;
    1.14  	}
    1.15 @@ -384,6 +383,8 @@ static void dispatch_rw_block_io(blkif_t
    1.16  	pending_req->nr_pages  = nseg;
    1.17  
    1.18  	for (i = 0; i < nseg; i++) {
    1.19 +		uint32_t flags;
    1.20 +
    1.21  		seg[i].nsec = req->seg[i].last_sect -
    1.22  			req->seg[i].first_sect + 1;
    1.23  
    1.24 @@ -392,12 +393,11 @@ static void dispatch_rw_block_io(blkif_t
    1.25  			goto fail_response;
    1.26  		preq.nr_sects += seg[i].nsec;
    1.27  
    1.28 -		map[i].host_addr = vaddr(pending_req, i);
    1.29 -		map[i].dom = blkif->domid;
    1.30 -		map[i].ref = req->seg[i].gref;
    1.31 -		map[i].flags = GNTMAP_host_map;
    1.32 +		flags = GNTMAP_host_map;
    1.33  		if ( operation == WRITE )
    1.34 -			map[i].flags |= GNTMAP_readonly;
    1.35 +			flags |= GNTMAP_readonly;
    1.36 +		gnttab_set_map_op(&map[i], vaddr(pending_req, i), flags,
    1.37 +				  req->seg[i].gref, blkif->domid);
    1.38  	}
    1.39  
    1.40  	ret = HYPERVISOR_grant_table_op(GNTTABOP_map_grant_ref, map, nseg);
     2.1 --- a/linux-2.6-xen-sparse/drivers/xen/blkback/interface.c	Thu Apr 13 10:12:16 2006 +0100
     2.2 +++ b/linux-2.6-xen-sparse/drivers/xen/blkback/interface.c	Thu Apr 13 10:29:27 2006 +0100
     2.3 @@ -58,10 +58,8 @@ static int map_frontend_page(blkif_t *bl
     2.4  	struct gnttab_map_grant_ref op;
     2.5  	int ret;
     2.6  
     2.7 -	op.host_addr = (unsigned long)blkif->blk_ring_area->addr;
     2.8 -	op.flags     = GNTMAP_host_map;
     2.9 -	op.ref       = shared_page;
    2.10 -	op.dom       = blkif->domid;
    2.11 +	gnttab_set_map_op(&op, (unsigned long)blkif->blk_ring_area->addr,
    2.12 +			  GNTMAP_host_map, shared_page, blkif->domid);
    2.13  
    2.14  	lock_vm_area(blkif->blk_ring_area);
    2.15  	ret = HYPERVISOR_grant_table_op(GNTTABOP_map_grant_ref, &op, 1);
    2.16 @@ -90,9 +88,8 @@ static void unmap_frontend_page(blkif_t 
    2.17  	struct gnttab_unmap_grant_ref op;
    2.18  	int ret;
    2.19  
    2.20 -	op.host_addr    = (unsigned long)blkif->blk_ring_area->addr;
    2.21 -	op.handle       = blkif->shmem_handle;
    2.22 -	op.dev_bus_addr = 0;
    2.23 +	gnttab_set_unmap_op(&op, (unsigned long)blkif->blk_ring_area->addr,
    2.24 +			    GNTMAP_host_map, blkif->shmem_handle);
    2.25  
    2.26  	lock_vm_area(blkif->blk_ring_area);
    2.27  	ret = HYPERVISOR_grant_table_op(GNTTABOP_unmap_grant_ref, &op, 1);
     3.1 --- a/linux-2.6-xen-sparse/drivers/xen/blktap/blktap.c	Thu Apr 13 10:12:16 2006 +0100
     3.2 +++ b/linux-2.6-xen-sparse/drivers/xen/blktap/blktap.c	Thu Apr 13 10:29:27 2006 +0100
     3.3 @@ -418,9 +418,9 @@ static void fast_flush_area(int idx, int
     3.4  		if (BLKTAP_INVALID_HANDLE(handle))
     3.5  			continue;
     3.6  
     3.7 -		unmap[op].host_addr = MMAP_VADDR(mmap_vstart, idx, i);
     3.8 -		unmap[op].dev_bus_addr = 0;
     3.9 -		unmap[op].handle = handle->kernel;
    3.10 +		gnttab_set_unmap_op(&unmap[op],
    3.11 +				    MMAP_VADDR(mmap_vstart, idx, i),
    3.12 +				    GNTMAP_host_map, handle->kernel);
    3.13  		op++;
    3.14  
    3.15  		if (create_lookup_pte_addr(
    3.16 @@ -430,9 +430,10 @@ static void fast_flush_area(int idx, int
    3.17  			DPRINTK("Couldn't get a pte addr!\n");
    3.18  			return;
    3.19  		}
    3.20 -		unmap[op].host_addr    = ptep;
    3.21 -		unmap[op].dev_bus_addr = 0;
    3.22 -		unmap[op].handle       = handle->user;
    3.23 +		gnttab_set_unmap_grnat_ref(&unmap[op], ptep,
    3.24 +					   GNTMAP_host_map |
    3.25 +					   GNTMAP_application_map |
    3.26 +					   GNTMAP_contains_pte, handle->user);
    3.27  		op++;
    3.28              
    3.29  		BLKTAP_INVALIDATE_HANDLE(handle);
    3.30 @@ -703,21 +704,21 @@ static void dispatch_rw_block_io(blkif_t
    3.31  		unsigned long uvaddr;
    3.32  		unsigned long kvaddr;
    3.33  		uint64_t ptep;
    3.34 +		uint32_t flags;
    3.35  
    3.36  		uvaddr = MMAP_VADDR(user_vstart, pending_idx, i);
    3.37  		kvaddr = MMAP_VADDR(mmap_vstart, pending_idx, i);
    3.38  
    3.39 -		/* Map the remote page to kernel. */
    3.40 -		map[op].host_addr = kvaddr;
    3.41 -		map[op].dom   = blkif->domid;
    3.42 -		map[op].ref   = req->seg[i].gref;
    3.43 -		map[op].flags = GNTMAP_host_map;
    3.44 +		flags = GNTMAP_host_map;
    3.45  		/* This needs a bit more thought in terms of interposition: 
    3.46  		 * If we want to be able to modify pages during write using 
    3.47  		 * grant table mappings, the guest will either need to allow 
    3.48  		 * it, or we'll need to incur a copy. Bit of an fbufs moment. ;) */
    3.49  		if (req->operation == BLKIF_OP_WRITE)
    3.50 -			map[op].flags |= GNTMAP_readonly;
    3.51 +			flags |= GNTMAP_readonly;
    3.52 +		/* Map the remote page to kernel. */
    3.53 +		gnttab_set_map_op(&map[op], kvaddr, flags, req->seg[i].gref,
    3.54 +				  blkif->domid);
    3.55  		op++;
    3.56  
    3.57  		/* Now map it to user. */
    3.58 @@ -728,14 +729,13 @@ static void dispatch_rw_block_io(blkif_t
    3.59  			goto bad_descriptor;
    3.60  		}
    3.61  
    3.62 -		map[op].host_addr = ptep;
    3.63 -		map[op].dom       = blkif->domid;
    3.64 -		map[op].ref       = req->seg[i].gref;
    3.65 -		map[op].flags     = GNTMAP_host_map | GNTMAP_application_map
    3.66 +		flags = GNTMAP_host_map | GNTMAP_application_map
    3.67  			| GNTMAP_contains_pte;
    3.68  		/* Above interposition comment applies here as well. */
    3.69  		if (req->operation == BLKIF_OP_WRITE)
    3.70 -			map[op].flags |= GNTMAP_readonly;
    3.71 +			flags |= GNTMAP_readonly;
    3.72 +		gnttab_set_map_op(&map[op], ptep, flags, req->seg[i].gref,
    3.73 +				  blkif->domid);
    3.74  		op++;
    3.75  	}
    3.76  
     4.1 --- a/linux-2.6-xen-sparse/drivers/xen/blktap/interface.c	Thu Apr 13 10:12:16 2006 +0100
     4.2 +++ b/linux-2.6-xen-sparse/drivers/xen/blktap/interface.c	Thu Apr 13 10:29:27 2006 +0100
     4.3 @@ -33,10 +33,8 @@ static int map_frontend_page(blkif_t *bl
     4.4  	struct gnttab_map_grant_ref op;
     4.5  	int ret;
     4.6  
     4.7 -	op.host_addr = (unsigned long)blkif->blk_ring_area->addr;
     4.8 -	op.flags     = GNTMAP_host_map;
     4.9 -	op.ref       = shared_page;
    4.10 -	op.dom       = blkif->domid;
    4.11 +	gnttab_set_map_op(&op, (unsigned long)blkif->blk_ring_area->addr,
    4.12 +			  GNTMAP_host_map, shared_page, blkif->domid);
    4.13  
    4.14  	lock_vm_area(blkif->blk_ring_area);
    4.15  	ret = HYPERVISOR_grant_table_op(GNTTABOP_map_grant_ref, &op, 1);
    4.16 @@ -59,9 +57,8 @@ static void unmap_frontend_page(blkif_t 
    4.17  	struct gnttab_unmap_grant_ref op;
    4.18  	int ret;
    4.19  
    4.20 -	op.host_addr    = (unsigned long)blkif->blk_ring_area->addr;
    4.21 -	op.handle       = blkif->shmem_handle;
    4.22 -	op.dev_bus_addr = 0;
    4.23 +	gnttab_set_unmap_op(&op, (unsigned long)blkif->blk_ring_area->addr,
    4.24 +			    GNTMAP_host_map, blkif->shmem_handle);
    4.25  
    4.26  	lock_vm_area(blkif->blk_ring_area);
    4.27  	ret = HYPERVISOR_grant_table_op(GNTTABOP_unmap_grant_ref, &op, 1);
     5.1 --- a/linux-2.6-xen-sparse/drivers/xen/netback/interface.c	Thu Apr 13 10:12:16 2006 +0100
     5.2 +++ b/linux-2.6-xen-sparse/drivers/xen/netback/interface.c	Thu Apr 13 10:29:27 2006 +0100
     5.3 @@ -150,10 +150,8 @@ static int map_frontend_pages(
     5.4  	struct gnttab_map_grant_ref op;
     5.5  	int ret;
     5.6  
     5.7 -	op.host_addr = (unsigned long)netif->tx_comms_area->addr;
     5.8 -	op.flags     = GNTMAP_host_map;
     5.9 -	op.ref       = tx_ring_ref;
    5.10 -	op.dom       = netif->domid;
    5.11 +	gnttab_set_map_op(&op, (unsigned long)netif->tx_comms_area->addr,
    5.12 +			  GNTMAP_host_map, tx_ring_ref, netif->domid);
    5.13      
    5.14  	lock_vm_area(netif->tx_comms_area);
    5.15  	ret = HYPERVISOR_grant_table_op(GNTTABOP_map_grant_ref, &op, 1);
    5.16 @@ -168,10 +166,8 @@ static int map_frontend_pages(
    5.17  	netif->tx_shmem_ref    = tx_ring_ref;
    5.18  	netif->tx_shmem_handle = op.handle;
    5.19  
    5.20 -	op.host_addr = (unsigned long)netif->rx_comms_area->addr;
    5.21 -	op.flags     = GNTMAP_host_map;
    5.22 -	op.ref       = rx_ring_ref;
    5.23 -	op.dom       = netif->domid;
    5.24 +	gnttab_set_map_op(&op, (unsigned long)netif->rx_comms_area->addr,
    5.25 +			  GNTMAP_host_map, rx_ring_ref, netif->domid);
    5.26  
    5.27  	lock_vm_area(netif->rx_comms_area);
    5.28  	ret = HYPERVISOR_grant_table_op(GNTTABOP_map_grant_ref, &op, 1);
    5.29 @@ -194,18 +190,16 @@ static void unmap_frontend_pages(netif_t
    5.30  	struct gnttab_unmap_grant_ref op;
    5.31  	int ret;
    5.32  
    5.33 -	op.host_addr    = (unsigned long)netif->tx_comms_area->addr;
    5.34 -	op.handle       = netif->tx_shmem_handle;
    5.35 -	op.dev_bus_addr = 0;
    5.36 +	gnttab_set_unmap_op(&op, (unsigned long)netif->tx_comms_area->addr,
    5.37 +			    GNTMAP_host_map, netif->tx_shmem_handle);
    5.38  
    5.39  	lock_vm_area(netif->tx_comms_area);
    5.40  	ret = HYPERVISOR_grant_table_op(GNTTABOP_unmap_grant_ref, &op, 1);
    5.41  	unlock_vm_area(netif->tx_comms_area);
    5.42  	BUG_ON(ret);
    5.43  
    5.44 -	op.host_addr    = (unsigned long)netif->rx_comms_area->addr;
    5.45 -	op.handle       = netif->rx_shmem_handle;
    5.46 -	op.dev_bus_addr = 0;
    5.47 +	gnttab_set_unmap_op(&op, (unsigned long)netif->rx_comms_area->addr,
    5.48 +			    GNTMAP_host_map, netif->rx_shmem_handle);
    5.49  
    5.50  	lock_vm_area(netif->rx_comms_area);
    5.51  	ret = HYPERVISOR_grant_table_op(GNTTABOP_unmap_grant_ref, &op, 1);
     6.1 --- a/linux-2.6-xen-sparse/drivers/xen/netback/netback.c	Thu Apr 13 10:12:16 2006 +0100
     6.2 +++ b/linux-2.6-xen-sparse/drivers/xen/netback/netback.c	Thu Apr 13 10:29:27 2006 +0100
     6.3 @@ -453,9 +453,9 @@ inline static void net_tx_action_dealloc
     6.4  	gop = tx_unmap_ops;
     6.5  	while (dc != dp) {
     6.6  		pending_idx = dealloc_ring[MASK_PEND_IDX(dc++)];
     6.7 -		gop->host_addr    = MMAP_VADDR(pending_idx);
     6.8 -		gop->dev_bus_addr = 0;
     6.9 -		gop->handle       = grant_tx_handle[pending_idx];
    6.10 +		gnttab_set_unmap_op(gop, MMAP_VADDR(pending_idx),
    6.11 +				    GNTMAP_host_map,
    6.12 +				    grant_tx_handle[pending_idx]);
    6.13  		gop++;
    6.14  	}
    6.15  	ret = HYPERVISOR_grant_table_op(
    6.16 @@ -579,10 +579,9 @@ static void net_tx_action(unsigned long 
    6.17  		/* Packets passed to netif_rx() must have some headroom. */
    6.18  		skb_reserve(skb, 16);
    6.19  
    6.20 -		mop->host_addr = MMAP_VADDR(pending_idx);
    6.21 -		mop->dom       = netif->domid;
    6.22 -		mop->ref       = txreq.gref;
    6.23 -		mop->flags     = GNTMAP_host_map | GNTMAP_readonly;
    6.24 +		gnttab_set_map_op(mop, MMAP_VADDR(pending_idx),
    6.25 +				  GNTMAP_host_map | GNTMAP_readonly,
    6.26 +				  txreq.gref, netif->domid);
    6.27  		mop++;
    6.28  
    6.29  		memcpy(&pending_tx_info[pending_idx].req,
     7.1 --- a/linux-2.6-xen-sparse/drivers/xen/tpmback/interface.c	Thu Apr 13 10:12:16 2006 +0100
     7.2 +++ b/linux-2.6-xen-sparse/drivers/xen/tpmback/interface.c	Thu Apr 13 10:29:27 2006 +0100
     7.3 @@ -13,6 +13,7 @@
     7.4  
     7.5  #include "common.h"
     7.6  #include <xen/balloon.h>
     7.7 +#include <xen/gnttab.h>
     7.8  
     7.9  static kmem_cache_t *tpmif_cachep;
    7.10  int num_frontends = 0;
    7.11 @@ -72,12 +73,10 @@ tpmif_t *tpmif_find(domid_t domid, long 
    7.12  static int map_frontend_page(tpmif_t *tpmif, unsigned long shared_page)
    7.13  {
    7.14  	int ret;
    7.15 -	struct gnttab_map_grant_ref op = {
    7.16 -		.host_addr = (unsigned long)tpmif->tx_area->addr,
    7.17 -		.flags = GNTMAP_host_map,
    7.18 -		.ref = shared_page,
    7.19 -		.dom = tpmif->domid,
    7.20 -	};
    7.21 +	struct gnttab_map_grant_ref op;
    7.22 +
    7.23 +	gnttab_set_map_op(&op, (unsigned long)tpmif->tx_area->addr,
    7.24 +			  GNTMAP_host_map, shared_page, tpmif->domid);
    7.25  
    7.26  	lock_vm_area(tpmif->tx_area);
    7.27  	ret = HYPERVISOR_grant_table_op(GNTTABOP_map_grant_ref, &op, 1);
    7.28 @@ -100,9 +99,8 @@ static void unmap_frontend_page(tpmif_t 
    7.29  	struct gnttab_unmap_grant_ref op;
    7.30  	int ret;
    7.31  
    7.32 -	op.host_addr    = (unsigned long)tpmif->tx_area->addr;
    7.33 -	op.handle       = tpmif->shmem_handle;
    7.34 -	op.dev_bus_addr = 0;
    7.35 +	gnttab_set_unmap_op(&op, (unsigned long)tpmif->tx_area->addr,
    7.36 +			    GNTMAP_host_map, tpmif->shmem_handle);
    7.37  
    7.38  	lock_vm_area(tpmif->tx_area);
    7.39  	ret = HYPERVISOR_grant_table_op(GNTTABOP_unmap_grant_ref, &op, 1);
     8.1 --- a/linux-2.6-xen-sparse/drivers/xen/tpmback/tpmback.c	Thu Apr 13 10:12:16 2006 +0100
     8.2 +++ b/linux-2.6-xen-sparse/drivers/xen/tpmback/tpmback.c	Thu Apr 13 10:29:27 2006 +0100
     8.3 @@ -21,6 +21,7 @@
     8.4  #include <asm/uaccess.h>
     8.5  #include <xen/xenbus.h>
     8.6  #include <xen/interface/grant_table.h>
     8.7 +#include <xen/gnttab.h>
     8.8  
     8.9  /* local data structures */
    8.10  struct data_exchange {
    8.11 @@ -278,10 +279,8 @@ int _packet_write(struct packet *pak,
    8.12  			return 0;
    8.13  		}
    8.14  
    8.15 -		map_op.host_addr = MMAP_VADDR(tpmif, i);
    8.16 -		map_op.flags = GNTMAP_host_map;
    8.17 -		map_op.ref = tx->ref;
    8.18 -		map_op.dom = tpmif->domid;
    8.19 +		gnttab_set_map_op(&map_op, MMAP_VADDR(tpmif, i),
    8.20 +				  GNTMAP_host_map, tx->ref, tpmif->domid);
    8.21  
    8.22  		if (unlikely(HYPERVISOR_grant_table_op(GNTTABOP_map_grant_ref,
    8.23  						       &map_op, 1))) {
    8.24 @@ -308,9 +307,8 @@ int _packet_write(struct packet *pak,
    8.25  		}
    8.26  		tx->size = tocopy;
    8.27  
    8.28 -		unmap_op.host_addr = MMAP_VADDR(tpmif, i);
    8.29 -		unmap_op.handle = handle;
    8.30 -		unmap_op.dev_bus_addr = 0;
    8.31 +		gnttab_set_unmap_op(&unmap_op, MMAP_VADDR(tpmif, i),
    8.32 +				    GNTMAP_host_map, handle);
    8.33  
    8.34  		if (unlikely
    8.35  		    (HYPERVISOR_grant_table_op
    8.36 @@ -422,10 +420,8 @@ static int packet_read_shmem(struct pack
    8.37  
    8.38  		tx = &tpmif->tx->ring[i].req;
    8.39  
    8.40 -		map_op.host_addr = MMAP_VADDR(tpmif, i);
    8.41 -		map_op.flags = GNTMAP_host_map;
    8.42 -		map_op.ref = tx->ref;
    8.43 -		map_op.dom = tpmif->domid;
    8.44 +		gnttab_set_map_op(&map_op, MMAP_VADDR(tpmif, i),
    8.45 +				  GNTMAP_host_map, tx->ref, tpmif->domid);
    8.46  
    8.47  		if (unlikely(HYPERVISOR_grant_table_op(GNTTABOP_map_grant_ref,
    8.48  						       &map_op, 1))) {
    8.49 @@ -461,9 +457,8 @@ static int packet_read_shmem(struct pack
    8.50  			tpmif->domid, buffer[offset], buffer[offset + 1],
    8.51  			buffer[offset + 2], buffer[offset + 3]);
    8.52  
    8.53 -		unmap_op.host_addr = MMAP_VADDR(tpmif, i);
    8.54 -		unmap_op.handle = handle;
    8.55 -		unmap_op.dev_bus_addr = 0;
    8.56 +		gnttab_set_unmap_op(&unmap_op, MMAP_VADDR(tpmif, i),
    8.57 +				    GNTMAP_host_map, handle);
    8.58  
    8.59  		if (unlikely
    8.60  		    (HYPERVISOR_grant_table_op
     9.1 --- a/linux-2.6-xen-sparse/drivers/xen/xenbus/xenbus_backend_client.c	Thu Apr 13 10:12:16 2006 +0100
     9.2 +++ b/linux-2.6-xen-sparse/drivers/xen/xenbus/xenbus_backend_client.c	Thu Apr 13 10:29:27 2006 +0100
     9.3 @@ -37,11 +37,7 @@
     9.4  /* Based on Rusty Russell's skeleton driver's map_page */
     9.5  int xenbus_map_ring_valloc(struct xenbus_device *dev, int gnt_ref, void **vaddr)
     9.6  {
     9.7 -	struct gnttab_map_grant_ref op = {
     9.8 -		.flags = GNTMAP_host_map,
     9.9 -		.ref   = gnt_ref,
    9.10 -		.dom   = dev->otherend_id,
    9.11 -	};
    9.12 +	struct gnttab_map_grant_ref op;
    9.13  	struct vm_struct *area;
    9.14  
    9.15  	*vaddr = NULL;
    9.16 @@ -50,8 +46,9 @@ int xenbus_map_ring_valloc(struct xenbus
    9.17  	if (!area)
    9.18  		return -ENOMEM;
    9.19  
    9.20 -	op.host_addr = (unsigned long)area->addr;
    9.21 -
    9.22 +	gnttab_set_map_op(&op, (unsigned long)area->addr, GNTMAP_host_map,
    9.23 +			  gnt_ref, dev->otherend_id);
    9.24 +	
    9.25  	lock_vm_area(area);
    9.26  	BUG_ON(HYPERVISOR_grant_table_op(GNTTABOP_map_grant_ref, &op, 1));
    9.27  	unlock_vm_area(area);
    9.28 @@ -76,13 +73,10 @@ EXPORT_SYMBOL_GPL(xenbus_map_ring_valloc
    9.29  int xenbus_map_ring(struct xenbus_device *dev, int gnt_ref,
    9.30  		   grant_handle_t *handle, void *vaddr)
    9.31  {
    9.32 -	struct gnttab_map_grant_ref op = {
    9.33 -		.host_addr = (unsigned long)vaddr,
    9.34 -		.flags     = GNTMAP_host_map,
    9.35 -		.ref       = gnt_ref,
    9.36 -		.dom       = dev->otherend_id,
    9.37 -	};
    9.38 -
    9.39 +	struct gnttab_map_grant_ref op;
    9.40 +	
    9.41 +	gnttab_set_map_op(&op, (unsigned long)vaddr, GNTMAP_host_map,
    9.42 +			  gnt_ref, dev->otherend_id);
    9.43  	BUG_ON(HYPERVISOR_grant_table_op(GNTTABOP_map_grant_ref, &op, 1));
    9.44  
    9.45  	if (op.status != GNTST_okay) {
    9.46 @@ -101,9 +95,7 @@ EXPORT_SYMBOL_GPL(xenbus_map_ring);
    9.47  int xenbus_unmap_ring_vfree(struct xenbus_device *dev, void *vaddr)
    9.48  {
    9.49  	struct vm_struct *area;
    9.50 -	struct gnttab_unmap_grant_ref op = {
    9.51 -		.host_addr = (unsigned long)vaddr,
    9.52 -	};
    9.53 +	struct gnttab_unmap_grant_ref op;
    9.54  
    9.55  	/* It'd be nice if linux/vmalloc.h provided a find_vm_area(void *addr)
    9.56  	 * method so that we don't have to muck with vmalloc internals here.
    9.57 @@ -124,7 +116,8 @@ int xenbus_unmap_ring_vfree(struct xenbu
    9.58  		return GNTST_bad_virt_addr;
    9.59  	}
    9.60  
    9.61 -	op.handle = (grant_handle_t)area->phys_addr;
    9.62 +	gnttab_set_unmap_op(&op, (unsigned long)vaddr, GNTMAP_host_map,
    9.63 +			    (grant_handle_t)area->phys_addr);
    9.64  
    9.65  	lock_vm_area(area);
    9.66  	BUG_ON(HYPERVISOR_grant_table_op(GNTTABOP_unmap_grant_ref, &op, 1));
    9.67 @@ -145,11 +138,10 @@ EXPORT_SYMBOL_GPL(xenbus_unmap_ring_vfre
    9.68  int xenbus_unmap_ring(struct xenbus_device *dev,
    9.69  		     grant_handle_t handle, void *vaddr)
    9.70  {
    9.71 -	struct gnttab_unmap_grant_ref op = {
    9.72 -		.host_addr = (unsigned long)vaddr,
    9.73 -		.handle    = handle,
    9.74 -	};
    9.75 +	struct gnttab_unmap_grant_ref op;
    9.76  
    9.77 +	gnttab_set_unmap_op(&op, (unsigned long)vaddr, GNTMAP_host_map,
    9.78 +			    handle);
    9.79  	BUG_ON(HYPERVISOR_grant_table_op(GNTTABOP_unmap_grant_ref, &op, 1));
    9.80  
    9.81  	if (op.status != GNTST_okay)
    10.1 --- a/linux-2.6-xen-sparse/include/xen/gnttab.h	Thu Apr 13 10:12:16 2006 +0100
    10.2 +++ b/linux-2.6-xen-sparse/include/xen/gnttab.h	Thu Apr 13 10:29:27 2006 +0100
    10.3 @@ -40,6 +40,7 @@
    10.4  #include <linux/config.h>
    10.5  #include <asm/hypervisor.h>
    10.6  #include <xen/interface/grant_table.h>
    10.7 +#include <xen/features.h>
    10.8  
    10.9  /* NR_GRANT_FRAMES must be less than or equal to that configured in Xen */
   10.10  #ifdef __ia64__
   10.11 @@ -113,6 +114,37 @@ void gnttab_grant_foreign_transfer_ref(g
   10.12  int gnttab_suspend(void);
   10.13  int gnttab_resume(void);
   10.14  
   10.15 +static inline void
   10.16 +gnttab_set_map_op(struct gnttab_map_grant_ref *map, unsigned long addr,
   10.17 +		  uint32_t flags, grant_ref_t ref, domid_t domid)
   10.18 +{
   10.19 +	if (flags & GNTMAP_contains_pte)
   10.20 +		map->host_addr = addr;
   10.21 +	else if (xen_feature(XENFEAT_auto_translated_physmap))
   10.22 +		map->host_addr = __pa(addr);
   10.23 +	else
   10.24 +		map->host_addr = addr;
   10.25 +
   10.26 +	map->flags = flags;
   10.27 +	map->ref = ref;
   10.28 +	map->dom = domid;
   10.29 +}
   10.30 +
   10.31 +static inline void
   10.32 +gnttab_set_unmap_op(struct gnttab_unmap_grant_ref *unmap, unsigned long addr,
   10.33 +		    uint32_t flags, grant_handle_t handle)
   10.34 +{
   10.35 +	if (flags & GNTMAP_contains_pte)
   10.36 +		unmap->host_addr = addr;
   10.37 +	else if (xen_feature(XENFEAT_auto_translated_physmap))
   10.38 +		unmap->host_addr = __pa(addr);
   10.39 +	else
   10.40 +		unmap->host_addr = addr;
   10.41 +
   10.42 +	unmap->handle = handle;
   10.43 +	unmap->dev_bus_addr = 0;
   10.44 +}
   10.45 +
   10.46  #endif /* __ASM_GNTTAB_H__ */
   10.47  
   10.48  /*