Index: 2006-01-05/arch/x86_64/kernel/pci-gart.c =================================================================== --- 2006-01-05.orig/arch/x86_64/kernel/pci-gart.c 2006-01-05 17:12:42.394165456 +0100 +++ 2006-01-05/arch/x86_64/kernel/pci-gart.c 2006-01-05 14:53:43.000000000 +0100 @@ -409,7 +409,8 @@ static dma_addr_t dma_map_area(struct de } /* Map a single area into the IOMMU */ -dma_addr_t dma_map_single(struct device *dev, void *addr, size_t size, int dir) +dma_addr_t dma_map_single(struct device *dev, void *addr, size_t size, + enum dma_data_direction dir) { unsigned long phys_mem, bus; @@ -515,7 +516,8 @@ static inline int dma_map_cont(struct sc * DMA map all entries in a scatterlist. * Merge chunks that have page aligned sizes into a continuous mapping. */ -int dma_map_sg(struct device *dev, struct scatterlist *sg, int nents, int dir) +int dma_map_sg(struct device *dev, struct scatterlist *sg, int nents, + enum dma_data_direction dir) { int i; int out; @@ -587,7 +589,7 @@ error: * Free a DMA mapping. */ void dma_unmap_single(struct device *dev, dma_addr_t dma_addr, - size_t size, int direction) + size_t size, enum dma_data_direction direction) { unsigned long iommu_page; int npages; @@ -613,7 +615,8 @@ void dma_unmap_single(struct device *dev /* * Wrapper for pci_unmap_single working with scatterlists. */ -void dma_unmap_sg(struct device *dev, struct scatterlist *sg, int nents, int dir) +void dma_unmap_sg(struct device *dev, struct scatterlist *sg, int nents, + enum dma_data_direction dir) { int i; if (swiotlb) { Index: 2006-01-05/arch/x86_64/kernel/pci-nommu-xen.c =================================================================== --- 2006-01-05.orig/arch/x86_64/kernel/pci-nommu-xen.c 2006-01-05 17:12:42.393165608 +0100 +++ 2006-01-05/arch/x86_64/kernel/pci-nommu-xen.c 2006-01-05 14:03:59.000000000 +0100 @@ -10,9 +10,6 @@ int iommu_merge = 0; EXPORT_SYMBOL(iommu_merge); -dma_addr_t bad_dma_address; -EXPORT_SYMBOL(bad_dma_address); - int iommu_bio_merge = 0; EXPORT_SYMBOL(iommu_bio_merge); Index: 2006-01-05/include/asm-x86_64/dma-mapping.h =================================================================== --- 2006-01-05.orig/include/asm-x86_64/dma-mapping.h 2006-01-05 17:12:42.395165304 +0100 +++ 2006-01-05/include/asm-x86_64/dma-mapping.h 2006-01-05 14:59:19.000000000 +0100 @@ -7,33 +7,63 @@ */ #include - +#include +#include #include #include #include +#ifndef CONFIG_XEN + extern dma_addr_t bad_dma_address; #define dma_mapping_error(x) \ (swiotlb ? swiotlb_dma_mapping_error(x) : ((x) == bad_dma_address)) +#else + +extern int dma_mapping_error(dma_addr_t dma_addr); + +static inline int +address_needs_mapping(struct device *hwdev, dma_addr_t addr) +{ + dma_addr_t mask = 0xffffffff; + /* If the device has a mask, use it, otherwise default to 32 bits */ + if (hwdev && hwdev->dma_mask) + mask = *hwdev->dma_mask; + return (addr & ~mask) != 0; +} + +static inline int +range_straddles_page_boundary(void *p, size_t size) +{ + extern unsigned long *contiguous_bitmap; + return (((((unsigned long)p & ~PAGE_MASK) + size) > PAGE_SIZE) && + !test_bit(__pa(p) >> PAGE_SHIFT, contiguous_bitmap)); +} + +#define dma_alloc_noncoherent(d, s, h, f) dma_alloc_coherent(d, s, h, f) +#define dma_free_noncoherent(d, s, v, h) dma_free_coherent(d, s, v, h) + +#endif + void *dma_alloc_coherent(struct device *dev, size_t size, dma_addr_t *dma_handle, gfp_t gfp); void dma_free_coherent(struct device *dev, size_t size, void *vaddr, dma_addr_t dma_handle); -#ifdef CONFIG_GART_IOMMU +#if defined(CONFIG_GART_IOMMU) || defined(CONFIG_XEN) extern dma_addr_t dma_map_single(struct device *hwdev, void *ptr, size_t size, - int direction); -extern void dma_unmap_single(struct device *dev, dma_addr_t addr,size_t size, - int direction); + enum dma_data_direction direction); +extern void dma_unmap_single(struct device *dev, dma_addr_t addr, size_t size, + enum dma_data_direction direction); #else /* No IOMMU */ static inline dma_addr_t dma_map_single(struct device *hwdev, void *ptr, - size_t size, int direction) + size_t size, enum dma_data_direction direction) { dma_addr_t addr; @@ -47,7 +77,7 @@ static inline dma_addr_t dma_map_single( } static inline void dma_unmap_single(struct device *hwdev, dma_addr_t dma_addr, - size_t size, int direction) + size_t size, enum dma_data_direction direction) { if (direction == DMA_NONE) out_of_line_bug(); @@ -56,12 +86,26 @@ static inline void dma_unmap_single(stru #endif +#ifndef CONFIG_XEN + #define dma_map_page(dev,page,offset,size,dir) \ dma_map_single((dev), page_address(page)+(offset), (size), (dir)) +#define dma_unmap_page dma_unmap_single + +#else + +extern dma_addr_t +dma_map_page(struct device *hwdev, struct page *page, unsigned long offset, + size_t size, enum dma_data_direction direction); +extern void +dma_unmap_page(struct device *hwdev, dma_addr_t dma_address, size_t size, + enum dma_data_direction direction); + +#endif static inline void dma_sync_single_for_cpu(struct device *hwdev, - dma_addr_t dma_handle, - size_t size, int direction) + dma_addr_t dma_handle, size_t size, + enum dma_data_direction direction) { if (direction == DMA_NONE) out_of_line_bug(); @@ -73,10 +117,10 @@ static inline void dma_sync_single_for_c } static inline void dma_sync_single_for_device(struct device *hwdev, - dma_addr_t dma_handle, - size_t size, int direction) + dma_addr_t dma_handle, size_t size, + enum dma_data_direction direction) { - if (direction == DMA_NONE) + if (direction == DMA_NONE) out_of_line_bug(); if (swiotlb) @@ -87,8 +131,8 @@ static inline void dma_sync_single_for_d static inline void dma_sync_single_range_for_cpu(struct device *hwdev, dma_addr_t dma_handle, - unsigned long offset, - size_t size, int direction) + unsigned long offset, size_t size, + enum dma_data_direction direction) { if (direction == DMA_NONE) out_of_line_bug(); @@ -101,8 +145,8 @@ static inline void dma_sync_single_range static inline void dma_sync_single_range_for_device(struct device *hwdev, dma_addr_t dma_handle, - unsigned long offset, - size_t size, int direction) + unsigned long offset, size_t size, + enum dma_data_direction direction) { if (direction == DMA_NONE) out_of_line_bug(); @@ -114,8 +158,8 @@ static inline void dma_sync_single_range } static inline void dma_sync_sg_for_cpu(struct device *hwdev, - struct scatterlist *sg, - int nelems, int direction) + struct scatterlist *sg, int nelems, + enum dma_data_direction direction) { if (direction == DMA_NONE) out_of_line_bug(); @@ -127,8 +171,8 @@ static inline void dma_sync_sg_for_cpu(s } static inline void dma_sync_sg_for_device(struct device *hwdev, - struct scatterlist *sg, - int nelems, int direction) + struct scatterlist *sg, int nelems, + enum dma_data_direction direction) { if (direction == DMA_NONE) out_of_line_bug(); @@ -140,11 +184,9 @@ static inline void dma_sync_sg_for_devic } extern int dma_map_sg(struct device *hwdev, struct scatterlist *sg, - int nents, int direction); + int nents, enum dma_data_direction direction); extern void dma_unmap_sg(struct device *hwdev, struct scatterlist *sg, - int nents, int direction); - -#define dma_unmap_page dma_unmap_single + int nents, enum dma_data_direction direction); extern int dma_supported(struct device *hwdev, u64 mask); extern int dma_get_cache_alignment(void); @@ -163,4 +205,20 @@ static inline void dma_cache_sync(void * flush_write_buffers(); } +#ifdef CONFIG_XEN + +#define ARCH_HAS_DMA_DECLARE_COHERENT_MEMORY +extern int +dma_declare_coherent_memory(struct device *dev, dma_addr_t bus_addr, + dma_addr_t device_addr, size_t size, int flags); + +extern void +dma_release_declared_memory(struct device *dev); + +extern void * +dma_mark_declared_memory_occupied(struct device *dev, + dma_addr_t device_addr, size_t size); + +#endif + #endif Index: 2006-01-05/include/asm-x86_64/mach-xen/asm/dma-mapping.h =================================================================== --- 2006-01-05.orig/include/asm-x86_64/mach-xen/asm/dma-mapping.h 2006-01-05 17:12:42.395165304 +0100 +++ /dev/null 1970-01-01 00:00:00.000000000 +0000 @@ -1,154 +0,0 @@ -#ifndef _ASM_DMA_MAPPING_H -#define _ASM_DMA_MAPPING_H - -/* - * IOMMU interface. See Documentation/DMA-mapping.txt and DMA-API.txt for - * documentation. - */ - -#include -#include -#include -#include -#include -#include - -static inline int -address_needs_mapping(struct device *hwdev, dma_addr_t addr) -{ - dma_addr_t mask = 0xffffffff; - /* If the device has a mask, use it, otherwise default to 32 bits */ - if (hwdev && hwdev->dma_mask) - mask = *hwdev->dma_mask; - return (addr & ~mask) != 0; -} - -static inline int -range_straddles_page_boundary(void *p, size_t size) -{ - extern unsigned long *contiguous_bitmap; - return (((((unsigned long)p & ~PAGE_MASK) + size) > PAGE_SIZE) && - !test_bit(__pa(p) >> PAGE_SHIFT, contiguous_bitmap)); -} - -#define dma_alloc_noncoherent(d, s, h, f) dma_alloc_coherent(d, s, h, f) -#define dma_free_noncoherent(d, s, v, h) dma_free_coherent(d, s, v, h) - -void *dma_alloc_coherent(struct device *dev, size_t size, - dma_addr_t *dma_handle, gfp_t flag); - -void dma_free_coherent(struct device *dev, size_t size, - void *vaddr, dma_addr_t dma_handle); - -extern dma_addr_t -dma_map_single(struct device *dev, void *ptr, size_t size, - enum dma_data_direction direction); - -extern void -dma_unmap_single(struct device *dev, dma_addr_t dma_addr, size_t size, - enum dma_data_direction direction); - -extern int dma_map_sg(struct device *hwdev, struct scatterlist *sg, - int nents, enum dma_data_direction direction); -extern void dma_unmap_sg(struct device *hwdev, struct scatterlist *sg, - int nents, enum dma_data_direction direction); - -extern dma_addr_t -dma_map_page(struct device *dev, struct page *page, unsigned long offset, - size_t size, enum dma_data_direction direction); - -extern void -dma_unmap_page(struct device *dev, dma_addr_t dma_address, size_t size, - enum dma_data_direction direction); - -static inline void -dma_sync_single_for_cpu(struct device *dev, dma_addr_t dma_handle, size_t size, - enum dma_data_direction direction) -{ - if (swiotlb) - swiotlb_sync_single_for_cpu(dev, dma_handle, size, direction); -} - -static inline void -dma_sync_single_for_device(struct device *dev, dma_addr_t dma_handle, size_t size, - enum dma_data_direction direction) -{ - if (swiotlb) - swiotlb_sync_single_for_device(dev, dma_handle, size, direction); -} - -static inline void -dma_sync_single_range_for_cpu(struct device *dev, dma_addr_t dma_handle, - unsigned long offset, size_t size, - enum dma_data_direction direction) -{ - dma_sync_single_for_cpu(dev, dma_handle+offset, size, direction); -} - -static inline void -dma_sync_single_range_for_device(struct device *dev, dma_addr_t dma_handle, - unsigned long offset, size_t size, - enum dma_data_direction direction) -{ - dma_sync_single_for_device(dev, dma_handle+offset, size, direction); -} - -static inline void -dma_sync_sg_for_cpu(struct device *dev, struct scatterlist *sg, int nelems, - enum dma_data_direction direction) -{ - if (swiotlb) - swiotlb_sync_sg_for_cpu(dev,sg,nelems,direction); - flush_write_buffers(); -} - -static inline void -dma_sync_sg_for_device(struct device *dev, struct scatterlist *sg, int nelems, - enum dma_data_direction direction) -{ - if (swiotlb) - swiotlb_sync_sg_for_device(dev,sg,nelems,direction); - flush_write_buffers(); -} - -extern int -dma_mapping_error(dma_addr_t dma_addr); - -extern int -dma_supported(struct device *dev, u64 mask); - -static inline int -dma_set_mask(struct device *dev, u64 mask) -{ - if(!dev->dma_mask || !dma_supported(dev, mask)) - return -EIO; - - *dev->dma_mask = mask; - - return 0; -} - -extern int dma_get_cache_alignment(void); - -#define dma_is_consistent(d) (1) - -static inline void -dma_cache_sync(void *vaddr, size_t size, - enum dma_data_direction direction) -{ - flush_write_buffers(); -} - -#define ARCH_HAS_DMA_DECLARE_COHERENT_MEMORY -extern int -dma_declare_coherent_memory(struct device *dev, dma_addr_t bus_addr, - dma_addr_t device_addr, size_t size, int flags); - -extern void -dma_release_declared_memory(struct device *dev); - -extern void * -dma_mark_declared_memory_occupied(struct device *dev, - dma_addr_t device_addr, size_t size); - -#endif Index: 2006-01-05/include/asm-x86_64/swiotlb.h =================================================================== --- 2006-01-05.orig/include/asm-x86_64/swiotlb.h 2006-01-05 17:12:42.396165152 +0100 +++ 2006-01-05/include/asm-x86_64/swiotlb.h 2006-01-05 16:27:35.000000000 +0100 @@ -1,5 +1,5 @@ #ifndef _ASM_SWIOTLB_H -#define _ASM_SWTIOLB_H 1 +#define _ASM_SWIOTLB_H 1 #include @@ -45,4 +45,20 @@ extern int swiotlb; #define swiotlb 0 #endif +#ifdef CONFIG_XEN + +extern dma_addr_t swiotlb_map_page(struct device *hwdev, struct page *page, + unsigned long offset, size_t size, + enum dma_data_direction direction); +extern void swiotlb_unmap_page(struct device *hwdev, dma_addr_t dma_address, + size_t size, enum dma_data_direction direction); +extern int swiotlb_dma_supported(struct device *hwdev, u64 mask); + +#define swiotlb_sync_single_range_for_cpu(dev, dma_handle, offset, size, direction) \ + swiotlb_sync_single_for_cpu(dev, (dma_handle) + (offset), size, direction) +#define swiotlb_sync_single_range_for_device(dev, dma_handle, offset, size, direction) \ + swiotlb_sync_single_for_device(dev, (dma_handle) + (offset), size, direction) + +#endif + #endif Index: 2006-01-05/arch/x86_64/kernel/pci-dma.c =================================================================== --- 2006-01-05.orig/arch/x86_64/kernel/pci-dma.c 2006-01-05 17:12:42.393165608 +0100 +++ 2006-01-05/arch/x86_64/kernel/pci-dma.c 2006-01-05 15:50:40.000000000 +0100 @@ -25,7 +25,7 @@ * the same here. */ int dma_map_sg(struct device *hwdev, struct scatterlist *sg, - int nents, int direction) + int nents, enum dma_data_direction direction) { int i; @@ -46,7 +46,7 @@ EXPORT_SYMBOL(dma_map_sg); * pci_unmap_single() above. */ void dma_unmap_sg(struct device *dev, struct scatterlist *sg, - int nents, int dir) + int nents, enum dma_data_direction dir) { int i; for (i = 0; i < nents; i++) {