ia64/xen-unstable

changeset 9845:a1d0761b59ca

Change the xenbus_map_ring_valloc() interface and implementation so
that it is buildable as a module.
Signed-off-by: Jan Beulich <jbeulich@novell.com>
author kaf24@firebug.cl.cam.ac.uk
date Tue Apr 25 14:20:08 2006 +0100 (2006-04-25)
parents 428babd7c1e0
children 101bfb71cc56
files linux-2.6-xen-sparse/drivers/xen/pciback/pciback.h linux-2.6-xen-sparse/drivers/xen/pciback/xenbus.c linux-2.6-xen-sparse/drivers/xen/xenbus/xenbus_backend_client.c linux-2.6-xen-sparse/include/xen/xenbus.h
line diff
     1.1 --- a/linux-2.6-xen-sparse/drivers/xen/pciback/pciback.h	Tue Apr 25 11:12:16 2006 +0100
     1.2 +++ b/linux-2.6-xen-sparse/drivers/xen/pciback/pciback.h	Tue Apr 25 14:20:08 2006 +0100
     1.3 @@ -29,6 +29,7 @@ struct pciback_device {
     1.4  
     1.5  	int evtchn_irq;
     1.6  
     1.7 +	struct vm_struct *sh_area;
     1.8  	struct xen_pci_sharedinfo *sh_info;
     1.9  };
    1.10  
     2.1 --- a/linux-2.6-xen-sparse/drivers/xen/pciback/xenbus.c	Tue Apr 25 11:12:16 2006 +0100
     2.2 +++ b/linux-2.6-xen-sparse/drivers/xen/pciback/xenbus.c	Tue Apr 25 14:20:08 2006 +0100
     2.3 @@ -26,6 +26,7 @@ static struct pciback_device *alloc_pdev
     2.4  
     2.5  	spin_lock_init(&pdev->dev_lock);
     2.6  
     2.7 +	pdev->sh_area = NULL;
     2.8  	pdev->sh_info = NULL;
     2.9  	pdev->evtchn_irq = INVALID_EVTCHN_IRQ;
    2.10  	pdev->be_watching = 0;
    2.11 @@ -48,7 +49,7 @@ static void free_pdev(struct pciback_dev
    2.12  		unbind_from_irqhandler(pdev->evtchn_irq, pdev);
    2.13  
    2.14  	if (pdev->sh_info)
    2.15 -		xenbus_unmap_ring_vfree(pdev->xdev, pdev->sh_info);
    2.16 +		xenbus_unmap_ring_vfree(pdev->xdev, pdev->sh_area);
    2.17  
    2.18  	pciback_release_devices(pdev);
    2.19  
    2.20 @@ -63,15 +64,19 @@ static int pciback_do_attach(struct pcib
    2.21  {
    2.22  	int err = 0;
    2.23  	int evtchn;
    2.24 +	struct vm_struct *area;
    2.25 +
    2.26  	dev_dbg(&pdev->xdev->dev,
    2.27  		"Attaching to frontend resources - gnt_ref=%d evtchn=%d\n",
    2.28  		gnt_ref, remote_evtchn);
    2.29  
    2.30 -	err =
    2.31 -	    xenbus_map_ring_valloc(pdev->xdev, gnt_ref,
    2.32 -				   (void **)&pdev->sh_info);
    2.33 -	if (err)
    2.34 +	area = xenbus_map_ring_valloc(pdev->xdev, gnt_ref);
    2.35 +	if (IS_ERR(area)) {
    2.36 +		err = PTR_ERR(area);
    2.37  		goto out;
    2.38 +	}
    2.39 +	pdev->sh_area = area;
    2.40 +	pdev->sh_info = area->addr;
    2.41  
    2.42  	err = xenbus_bind_evtchn(pdev->xdev, remote_evtchn, &evtchn);
    2.43  	if (err)
     3.1 --- a/linux-2.6-xen-sparse/drivers/xen/xenbus/xenbus_backend_client.c	Tue Apr 25 11:12:16 2006 +0100
     3.2 +++ b/linux-2.6-xen-sparse/drivers/xen/xenbus/xenbus_backend_client.c	Tue Apr 25 14:20:08 2006 +0100
     3.3 @@ -30,21 +30,20 @@
     3.4   * IN THE SOFTWARE.
     3.5   */
     3.6  
     3.7 +#include <linux/err.h>
     3.8  #include <xen/gnttab.h>
     3.9  #include <xen/xenbus.h>
    3.10  #include <xen/driver_util.h>
    3.11  
    3.12  /* Based on Rusty Russell's skeleton driver's map_page */
    3.13 -int xenbus_map_ring_valloc(struct xenbus_device *dev, int gnt_ref, void **vaddr)
    3.14 +struct vm_struct *xenbus_map_ring_valloc(struct xenbus_device *dev, int gnt_ref)
    3.15  {
    3.16  	struct gnttab_map_grant_ref op;
    3.17  	struct vm_struct *area;
    3.18  
    3.19 -	*vaddr = NULL;
    3.20 -
    3.21  	area = alloc_vm_area(PAGE_SIZE);
    3.22  	if (!area)
    3.23 -		return -ENOMEM;
    3.24 +		return ERR_PTR(-ENOMEM);
    3.25  
    3.26  	gnttab_set_map_op(&op, (unsigned long)area->addr, GNTMAP_host_map,
    3.27  			  gnt_ref, dev->otherend_id);
    3.28 @@ -58,14 +57,14 @@ int xenbus_map_ring_valloc(struct xenbus
    3.29  		xenbus_dev_fatal(dev, op.status,
    3.30  				 "mapping in shared page %d from domain %d",
    3.31  				 gnt_ref, dev->otherend_id);
    3.32 -		return op.status;
    3.33 +		BUG_ON(!IS_ERR(ERR_PTR(op.status)));
    3.34 +		return ERR_PTR(op.status);
    3.35  	}
    3.36  
    3.37  	/* Stuff the handle in an unused field */
    3.38  	area->phys_addr = (unsigned long)op.handle;
    3.39  
    3.40 -	*vaddr = area->addr;
    3.41 -	return 0;
    3.42 +	return area;
    3.43  }
    3.44  EXPORT_SYMBOL_GPL(xenbus_map_ring_valloc);
    3.45  
    3.46 @@ -92,30 +91,10 @@ EXPORT_SYMBOL_GPL(xenbus_map_ring);
    3.47  
    3.48  
    3.49  /* Based on Rusty Russell's skeleton driver's unmap_page */
    3.50 -int xenbus_unmap_ring_vfree(struct xenbus_device *dev, void *vaddr)
    3.51 +int xenbus_unmap_ring_vfree(struct xenbus_device *dev, struct vm_struct *area)
    3.52  {
    3.53 -	struct vm_struct *area;
    3.54  	struct gnttab_unmap_grant_ref op;
    3.55  
    3.56 -	/* It'd be nice if linux/vmalloc.h provided a find_vm_area(void *addr)
    3.57 -	 * method so that we don't have to muck with vmalloc internals here.
    3.58 -	 * We could force the user to hang on to their struct vm_struct from
    3.59 -	 * xenbus_map_ring_valloc, but these 6 lines considerably simplify
    3.60 -	 * this API.
    3.61 -	 */
    3.62 -	read_lock(&vmlist_lock);
    3.63 -	for (area = vmlist; area != NULL; area = area->next) {
    3.64 -		if (area->addr == vaddr)
    3.65 -			break;
    3.66 -	}
    3.67 -	read_unlock(&vmlist_lock);
    3.68 -
    3.69 -	if (!area) {
    3.70 -		xenbus_dev_error(dev, -ENOENT,
    3.71 -				 "can't find mapped virtual address %p", vaddr);
    3.72 -		return GNTST_bad_virt_addr;
    3.73 -	}
    3.74 -
    3.75  	gnttab_set_unmap_op(&op, (unsigned long)vaddr, GNTMAP_host_map,
    3.76  			    (grant_handle_t)area->phys_addr);
    3.77  
     4.1 --- a/linux-2.6-xen-sparse/include/xen/xenbus.h	Tue Apr 25 11:12:16 2006 +0100
     4.2 +++ b/linux-2.6-xen-sparse/include/xen/xenbus.h	Tue Apr 25 14:20:08 2006 +0100
     4.3 @@ -228,8 +228,8 @@ int xenbus_grant_ring(struct xenbus_devi
     4.4   * or -ENOMEM on error. If an error is returned, device will switch to
     4.5   * XenbusStateClosing and the error message will be saved in XenStore.
     4.6   */
     4.7 -int xenbus_map_ring_valloc(struct xenbus_device *dev,
     4.8 -			   int gnt_ref, void **vaddr);
     4.9 +struct vm_struct *xenbus_map_ring_valloc(struct xenbus_device *dev,
    4.10 +					 int gnt_ref);
    4.11  int xenbus_map_ring(struct xenbus_device *dev, int gnt_ref,
    4.12  			   grant_handle_t *handle, void *vaddr);
    4.13  
    4.14 @@ -241,7 +241,7 @@ int xenbus_map_ring(struct xenbus_device
    4.15   * Returns 0 on success and returns GNTST_* on error
    4.16   * (see xen/include/interface/grant_table.h).
    4.17   */
    4.18 -int xenbus_unmap_ring_vfree(struct xenbus_device *dev, void *vaddr);
    4.19 +int xenbus_unmap_ring_vfree(struct xenbus_device *dev, struct vm_struct *);
    4.20  int xenbus_unmap_ring(struct xenbus_device *dev,
    4.21  		      grant_handle_t handle, void *vaddr);
    4.22