direct-io.hg

changeset 15099:3b3f00d42dc4

[IA64] Create Xen machine vector

This allows us to easily switch between hardware or software iommu and
simple remapping. The Xen machine vector is only intended for domU
guests at this point.

Signed-off-by: Alex Williamson <alex.williamson@hp.com>
author Alex Williamson <alex.williamson@hp.com>
date Mon May 07 08:52:12 2007 -0600 (2007-05-07)
parents a08261650b8a
children fc0a9a40f151
files linux-2.6-xen-sparse/arch/ia64/Kconfig linux-2.6-xen-sparse/arch/ia64/Makefile linux-2.6-xen-sparse/arch/ia64/kernel/acpi.c linux-2.6-xen-sparse/arch/ia64/xen/machvec.c linux-2.6-xen-sparse/arch/ia64/xen/xen_dma.c linux-2.6-xen-sparse/include/asm-ia64/machvec.h linux-2.6-xen-sparse/include/asm-ia64/machvec_xen.h
line diff
     1.1 --- a/linux-2.6-xen-sparse/arch/ia64/Kconfig	Mon May 07 08:45:15 2007 -0600
     1.2 +++ b/linux-2.6-xen-sparse/arch/ia64/Kconfig	Mon May 07 08:52:12 2007 -0600
     1.3 @@ -161,6 +161,10 @@ config IA64_SGI_SN2
     1.4  config IA64_HP_SIM
     1.5  	bool "Ski-simulator"
     1.6  
     1.7 +config IA64_XEN
     1.8 +	bool "Xen guest"
     1.9 +	depends on XEN
    1.10 +
    1.11  endchoice
    1.12  
    1.13  choice
     2.1 --- a/linux-2.6-xen-sparse/arch/ia64/Makefile	Mon May 07 08:45:15 2007 -0600
     2.2 +++ b/linux-2.6-xen-sparse/arch/ia64/Makefile	Mon May 07 08:52:12 2007 -0600
     2.3 @@ -60,6 +60,7 @@ core-$(CONFIG_IA64_DIG) 	+= arch/ia64/di
     2.4  core-$(CONFIG_IA64_GENERIC) 	+= arch/ia64/dig/
     2.5  core-$(CONFIG_IA64_HP_ZX1)	+= arch/ia64/dig/
     2.6  core-$(CONFIG_IA64_HP_ZX1_SWIOTLB) += arch/ia64/dig/
     2.7 +core-$(CONFIG_IA64_XEN)		+= arch/ia64/dig/
     2.8  core-$(CONFIG_IA64_SGI_SN2)	+= arch/ia64/sn/
     2.9  core-$(CONFIG_XEN)		+= arch/ia64/xen/
    2.10  
     3.1 --- a/linux-2.6-xen-sparse/arch/ia64/kernel/acpi.c	Mon May 07 08:45:15 2007 -0600
     3.2 +++ b/linux-2.6-xen-sparse/arch/ia64/kernel/acpi.c	Mon May 07 08:52:12 2007 -0600
     3.3 @@ -109,6 +109,10 @@ const char *acpi_get_sysname(void)
     3.4  		return "hpzx1";
     3.5  	} else if (!strcmp(hdr->oem_id, "SGI")) {
     3.6  		return "sn2";
     3.7 +#ifdef CONFIG_XEN
     3.8 +	} else if (is_running_on_xen() && !strcmp(hdr->oem_id, "XEN")) {
     3.9 +		return "xen";
    3.10 +#endif
    3.11  	}
    3.12  
    3.13  	return "dig";
    3.14 @@ -123,6 +127,8 @@ const char *acpi_get_sysname(void)
    3.15  	return "sn2";
    3.16  # elif defined (CONFIG_IA64_DIG)
    3.17  	return "dig";
    3.18 +# elif defined (CONFIG_IA64_XEN)
    3.19 +	return "xen";
    3.20  # else
    3.21  #	error Unknown platform.  Fix acpi.c.
    3.22  # endif
     4.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     4.2 +++ b/linux-2.6-xen-sparse/arch/ia64/xen/machvec.c	Mon May 07 08:52:12 2007 -0600
     4.3 @@ -0,0 +1,4 @@
     4.4 +#define MACHVEC_PLATFORM_NAME           xen
     4.5 +#define MACHVEC_PLATFORM_HEADER         <asm/machvec_xen.h>
     4.6 +#include <asm/machvec_init.h>
     4.7 +
     5.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     5.2 +++ b/linux-2.6-xen-sparse/arch/ia64/xen/xen_dma.c	Mon May 07 08:52:12 2007 -0600
     5.3 @@ -0,0 +1,145 @@
     5.4 +/*
     5.5 + * Copyright (C) 2007 Hewlett-Packard Development Company, L.P.
     5.6 + * 	Alex Williamson <alex.williamson@hp.com>
     5.7 + *
     5.8 + * Basic DMA mapping services for Xen guests.
     5.9 + * Based on arch/i386/kernel/pci-dma-xen.c.
    5.10 + *
    5.11 + * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    5.12 + * This program is free software; you can redistribute it and/or modify
    5.13 + * it under the terms of the GNU General Public License as published by
    5.14 + * the Free Software Foundation; either version 2 of the License, or
    5.15 + * (at your option) any later version.
    5.16 + *
    5.17 + * This program is distributed in the hope that it will be useful,
    5.18 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
    5.19 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    5.20 + * GNU General Public License for more details.
    5.21 + *
    5.22 + * You should have received a copy of the GNU General Public License
    5.23 + * along with this program; if not, write to the Free Software
    5.24 + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
    5.25 + * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    5.26 + */
    5.27 +
    5.28 +#include <linux/dma-mapping.h>
    5.29 +#include <linux/mm.h>
    5.30 +#include <asm/scatterlist.h>
    5.31 +
    5.32 +#define IOMMU_BUG_ON(test)					\
    5.33 +do {								\
    5.34 +	if (unlikely(test)) {					\
    5.35 +		printk(KERN_ALERT "Fatal DMA error!\n");	\
    5.36 +		BUG();						\
    5.37 +	}							\
    5.38 +} while (0)
    5.39 +
    5.40 +
    5.41 +/*
    5.42 + * This should be broken out of swiotlb and put in a common place
    5.43 + * when merged with upstream Linux.
    5.44 + */
    5.45 +static inline int
    5.46 +address_needs_mapping(struct device *hwdev, dma_addr_t addr)
    5.47 +{
    5.48 +	dma_addr_t mask = 0xffffffff;
    5.49 +
    5.50 +	/* If the device has a mask, use it, otherwise default to 32 bits */
    5.51 +	if (hwdev && hwdev->dma_mask)
    5.52 +		mask = *hwdev->dma_mask;
    5.53 +	return (addr & ~mask) != 0;
    5.54 +}
    5.55 +
    5.56 +int
    5.57 +xen_map_sg(struct device *hwdev, struct scatterlist *sg, int nents,
    5.58 +	   int direction)
    5.59 +{
    5.60 +	int i;
    5.61 +
    5.62 +	for (i = 0 ; i < nents ; i++) {
    5.63 +		sg[i].dma_address = page_to_bus(sg[i].page) + sg[i].offset;
    5.64 +		sg[i].dma_length  = sg[i].length;
    5.65 +
    5.66 +		IOMMU_BUG_ON(address_needs_mapping(hwdev, sg[i].dma_address));
    5.67 +	}
    5.68 +
    5.69 +	return nents;
    5.70 +}
    5.71 +EXPORT_SYMBOL(xen_map_sg);
    5.72 +
    5.73 +void
    5.74 +xen_unmap_sg(struct device *hwdev, struct scatterlist *sg, int nents,
    5.75 +	     int direction)
    5.76 +{
    5.77 +}
    5.78 +EXPORT_SYMBOL(xen_unmap_sg);
    5.79 +
    5.80 +int
    5.81 +xen_dma_mapping_error(dma_addr_t dma_addr)
    5.82 +{
    5.83 +	return 0;
    5.84 +}
    5.85 +EXPORT_SYMBOL(xen_dma_mapping_error);
    5.86 +
    5.87 +int
    5.88 +xen_dma_supported(struct device *dev, u64 mask)
    5.89 +{
    5.90 +	return 1;
    5.91 +}
    5.92 +EXPORT_SYMBOL(xen_dma_supported);
    5.93 +
    5.94 +void *
    5.95 +xen_alloc_coherent(struct device *dev, size_t size,
    5.96 +		   dma_addr_t *dma_handle, gfp_t gfp)
    5.97 +{
    5.98 +	unsigned long vaddr;
    5.99 +	unsigned int order = get_order(size);
   5.100 +
   5.101 +	vaddr = __get_free_pages(gfp, order);
   5.102 +
   5.103 +	if (!vaddr)
   5.104 +		return NULL;
   5.105 +
   5.106 +	if (xen_create_contiguous_region(vaddr, order,
   5.107 +					 dev->coherent_dma_mask)) {
   5.108 +		free_pages(vaddr, order);
   5.109 +		return NULL;
   5.110 +	}
   5.111 +
   5.112 +	memset((void *)vaddr, 0, size);
   5.113 +	*dma_handle = virt_to_bus((void *)vaddr);
   5.114 +
   5.115 +	return (void *)vaddr;
   5.116 +}
   5.117 +EXPORT_SYMBOL(xen_alloc_coherent);
   5.118 +
   5.119 +void
   5.120 +xen_free_coherent(struct device *dev, size_t size,
   5.121 +		      void *vaddr, dma_addr_t dma_handle)
   5.122 +{
   5.123 +	unsigned int order =  get_order(size);
   5.124 +
   5.125 +	xen_destroy_contiguous_region((unsigned long)vaddr, order);
   5.126 +	free_pages((unsigned long)vaddr, order);
   5.127 +}
   5.128 +EXPORT_SYMBOL(xen_free_coherent);
   5.129 +
   5.130 +dma_addr_t
   5.131 +xen_map_single(struct device *dev, void *ptr, size_t size,
   5.132 +	       int direction)
   5.133 +{
   5.134 +	dma_addr_t dma_addr = virt_to_bus(ptr);
   5.135 +
   5.136 +	IOMMU_BUG_ON(range_straddles_page_boundary(ptr, size));
   5.137 +	IOMMU_BUG_ON(address_needs_mapping(dev, dma_addr));
   5.138 +
   5.139 +	return dma_addr;
   5.140 +}
   5.141 +EXPORT_SYMBOL(xen_map_single);
   5.142 +
   5.143 +void
   5.144 +xen_unmap_single(struct device *dev, dma_addr_t dma_addr, size_t size,
   5.145 +		 int direction)
   5.146 +{
   5.147 +}
   5.148 +EXPORT_SYMBOL(xen_unmap_single);
     6.1 --- a/linux-2.6-xen-sparse/include/asm-ia64/machvec.h	Mon May 07 08:45:15 2007 -0600
     6.2 +++ b/linux-2.6-xen-sparse/include/asm-ia64/machvec.h	Mon May 07 08:52:12 2007 -0600
     6.3 @@ -108,6 +108,8 @@ extern void machvec_tlb_migrate_finish (
     6.4  #  include <asm/machvec_hpzx1_swiotlb.h>
     6.5  # elif defined (CONFIG_IA64_SGI_SN2)
     6.6  #  include <asm/machvec_sn2.h>
     6.7 +# elif defined (CONFIG_IA64_XEN)
     6.8 +#  include <asm/machvec_xen.h>
     6.9  # elif defined (CONFIG_IA64_GENERIC)
    6.10  
    6.11  # ifdef MACHVEC_PLATFORM_HEADER
     7.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     7.2 +++ b/linux-2.6-xen-sparse/include/asm-ia64/machvec_xen.h	Mon May 07 08:52:12 2007 -0600
     7.3 @@ -0,0 +1,37 @@
     7.4 +#ifndef _ASM_IA64_MACHVEC_XEN_h
     7.5 +#define _ASM_IA64_MACHVEC_XEN_h
     7.6 +
     7.7 +extern ia64_mv_setup_t			dig_setup;
     7.8 +extern ia64_mv_dma_alloc_coherent	xen_alloc_coherent;
     7.9 +extern ia64_mv_dma_free_coherent	xen_free_coherent;
    7.10 +extern ia64_mv_dma_map_single		xen_map_single;
    7.11 +extern ia64_mv_dma_unmap_single		xen_unmap_single;
    7.12 +extern ia64_mv_dma_map_sg		xen_map_sg;
    7.13 +extern ia64_mv_dma_unmap_sg		xen_unmap_sg;
    7.14 +extern ia64_mv_dma_supported		xen_dma_supported;
    7.15 +extern ia64_mv_dma_mapping_error	xen_dma_mapping_error;
    7.16 +
    7.17 +/*
    7.18 + * This stuff has dual use!
    7.19 + *
    7.20 + * For a generic kernel, the macros are used to initialize the
    7.21 + * platform's machvec structure.  When compiling a non-generic kernel,
    7.22 + * the macros are used directly.
    7.23 + */
    7.24 +#define platform_name				"xen"
    7.25 +#define platform_setup				dig_setup
    7.26 +#define platform_dma_init			machvec_noop
    7.27 +#define platform_dma_alloc_coherent		xen_alloc_coherent
    7.28 +#define platform_dma_free_coherent		xen_free_coherent
    7.29 +#define platform_dma_map_single			xen_map_single
    7.30 +#define platform_dma_unmap_single		xen_unmap_single
    7.31 +#define platform_dma_map_sg			xen_map_sg
    7.32 +#define platform_dma_unmap_sg			xen_unmap_sg
    7.33 +#define platform_dma_sync_single_for_cpu	machvec_dma_sync_single
    7.34 +#define platform_dma_sync_sg_for_cpu		machvec_dma_sync_sg
    7.35 +#define platform_dma_sync_single_for_device	machvec_dma_sync_single
    7.36 +#define platform_dma_sync_sg_for_device		machvec_dma_sync_sg
    7.37 +#define platform_dma_supported			xen_dma_supported
    7.38 +#define platform_dma_mapping_error		xen_dma_mapping_error
    7.39 +
    7.40 +#endif /* _ASM_IA64_MACHVEC_XEN_h */