This is a follow on to my paravirtualizing swiotlb RFC. I still need
to merge this together with what Isaku has been submitting, but this
patch enables ia64 machine vector support and provides a paravirtualized
swiotlb (based on lib/swiotlb.c instead of the xen-i386 one) and
sba_iommu for hardware iommu support on hp systems. I took the easy way
out on swiotlb and copied the new, pv version to arch/ia64/xen/. This
is not ideal, but it's a lot better than what we have now. I went ahead
and changed the virt_to_phys() calls to virt_to_bus() since this already
matches what's in current Linux upstream. I think I've maintained
transparent PV throughout, but please let me know if you see any spots I
missed (and any other comments as well).
I'll start trying to get caught up on the backlog of patches now that
3.1.0 is hopefully starting to wind down and chances of another pull of
the ia64 tree before final release are slim. If you want to try this,
please add the following files to the sparse tree before applying the
patch:
linux-2.6-xen-sparse/arch/ia64/hp/common/sba_iommu.c
linux-2.6-xen-sparse/arch/ia64/xen/swiotlb.c (copy from lib/swiotlb.c)
Thanks,
Alex
PS - I've only modified the -xen build config below. The -xen0 config
will be modified similarly. I don't really see a reason for the -xenU
config to change from the DIG flavor.
Signed-off-by: Alex Williamson <alex.williamson@xxxxxx>
---
diff -r 9313d0ce09f8 buildconfigs/linux-defconfig_xen_ia64
--- a/buildconfigs/linux-defconfig_xen_ia64 Tue Apr 24 09:26:32 2007 -0600
+++ b/buildconfigs/linux-defconfig_xen_ia64 Wed May 02 22:52:33 2007 -0600
@@ -1,8 +1,9 @@
#
# Automatically generated make config: don't edit
-# Linux kernel version: 2.6.18-xen
-# Mon Jan 29 10:01:13 2007
-#
+# Linux kernel version: 2.6.18
+# Mon Apr 30 13:14:05 2007
+#
+CONFIG_DEFCONFIG_LIST="/lib/modules/$UNAME_RELEASE/.config"
#
# Code maturity level options
@@ -99,8 +100,8 @@ CONFIG_SCHED_NO_NO_OMIT_FRAME_POINTER=y
CONFIG_SCHED_NO_NO_OMIT_FRAME_POINTER=y
CONFIG_DMA_IS_DMA32=y
CONFIG_AUDIT_ARCH=y
-# CONFIG_IA64_GENERIC is not set
-CONFIG_IA64_DIG=y
+CONFIG_IA64_GENERIC=y
+# CONFIG_IA64_DIG is not set
# CONFIG_IA64_HP_ZX1 is not set
# CONFIG_IA64_HP_ZX1_SWIOTLB is not set
# CONFIG_IA64_SGI_SN2 is not set
@@ -120,6 +121,7 @@ CONFIG_IA64_L1_CACHE_SHIFT=7
CONFIG_IA64_L1_CACHE_SHIFT=7
CONFIG_IA64_CYCLONE=y
CONFIG_IOSAPIC=y
+# CONFIG_IA64_SGI_SN_XP is not set
CONFIG_FORCE_MAX_ZONEORDER=11
CONFIG_SMP=y
CONFIG_NR_CPUS=16
@@ -129,23 +131,37 @@ CONFIG_ARCH_ENABLE_MEMORY_HOTPLUG=y
# CONFIG_PERMIT_BSP_REMOVE is not set
# CONFIG_PREEMPT is not set
CONFIG_SELECT_MEMORY_MODEL=y
-CONFIG_FLATMEM_MANUAL=y
-# CONFIG_DISCONTIGMEM_MANUAL is not set
+# CONFIG_FLATMEM_MANUAL is not set
+CONFIG_DISCONTIGMEM_MANUAL=y
# CONFIG_SPARSEMEM_MANUAL is not set
-CONFIG_FLATMEM=y
+CONFIG_DISCONTIGMEM=y
CONFIG_FLAT_NODE_MEM_MAP=y
+CONFIG_NEED_MULTIPLE_NODES=y
# CONFIG_SPARSEMEM_STATIC is not set
CONFIG_SPLIT_PTLOCK_CPUS=4
+# CONFIG_MIGRATION is not set
CONFIG_RESOURCES_64BIT=y
CONFIG_ARCH_SELECT_MEMORY_MODEL=y
CONFIG_ARCH_DISCONTIGMEM_ENABLE=y
CONFIG_ARCH_FLATMEM_ENABLE=y
CONFIG_ARCH_SPARSEMEM_ENABLE=y
-# CONFIG_VIRTUAL_MEM_MAP is not set
+CONFIG_ARCH_DISCONTIGMEM_DEFAULT=y
+CONFIG_NUMA=y
+CONFIG_NODES_SHIFT=10
+CONFIG_VIRTUAL_MEM_MAP=y
+CONFIG_HOLES_IN_ZONE=y
+CONFIG_HAVE_ARCH_EARLY_PFN_TO_NID=y
+CONFIG_HAVE_ARCH_NODEDATA_EXTENSION=y
# CONFIG_IA32_SUPPORT is not set
-CONFIG_IA64_MCA_RECOVERY=y
+# CONFIG_IA64_MCA_RECOVERY is not set
CONFIG_PERFMON=y
CONFIG_IA64_PALINFO=y
+CONFIG_SGI_SN=y
+
+#
+# SN Devices
+#
+# CONFIG_SGI_IOC3 is not set
#
# Firmware Drivers
@@ -172,6 +188,7 @@ CONFIG_ACPI_PROCESSOR=y
CONFIG_ACPI_PROCESSOR=y
CONFIG_ACPI_HOTPLUG_CPU=y
CONFIG_ACPI_THERMAL=y
+CONFIG_ACPI_NUMA=y
CONFIG_ACPI_BLACKLIST_YEAR=0
# CONFIG_ACPI_DEBUG is not set
CONFIG_ACPI_EC=y
@@ -203,6 +220,7 @@ CONFIG_HOTPLUG_PCI_ACPI=y
# CONFIG_HOTPLUG_PCI_ACPI_IBM is not set
# CONFIG_HOTPLUG_PCI_CPCI is not set
# CONFIG_HOTPLUG_PCI_SHPC is not set
+# CONFIG_HOTPLUG_PCI_SGI is not set
#
# PCCARD (PCMCIA/CardBus) support
@@ -747,6 +765,8 @@ CONFIG_SERIAL_NONSTANDARD=y
# CONFIG_SX is not set
# CONFIG_RIO is not set
# CONFIG_STALDRV is not set
+# CONFIG_SGI_SNSC is not set
+# CONFIG_SGI_TIOCX is not set
#
# Serial drivers
@@ -755,6 +775,7 @@ CONFIG_SERIAL_NONSTANDARD=y
#
# Non-8250 serial port support
#
+# CONFIG_SERIAL_SGI_L1_CONSOLE is not set
# CONFIG_SERIAL_JSM is not set
CONFIG_UNIX98_PTYS=y
CONFIG_LEGACY_PTYS=y
@@ -782,6 +803,8 @@ CONFIG_AGP=y
# CONFIG_AGP_SIS is not set
# CONFIG_AGP_VIA is not set
CONFIG_AGP_I460=y
+# CONFIG_AGP_HP_ZX1 is not set
+# CONFIG_AGP_SGI_TIOCA is not set
CONFIG_DRM=y
# CONFIG_DRM_TDFX is not set
# CONFIG_DRM_R128 is not set
@@ -793,6 +816,7 @@ CONFIG_DRM=y
# CONFIG_RAW_DRIVER is not set
# CONFIG_HPET is not set
# CONFIG_HANGCHECK_TIMER is not set
+# CONFIG_MMTIMER is not set
#
# TPM devices
@@ -1541,6 +1565,13 @@ CONFIG_IRQ_PER_CPU=y
CONFIG_IRQ_PER_CPU=y
#
+# HP Simulator drivers
+#
+# CONFIG_HP_SIMETH is not set
+# CONFIG_HP_SIMSERIAL is not set
+# CONFIG_HP_SIMSCSI is not set
+
+#
# Instrumentation Support
#
# CONFIG_PROFILING is not set
@@ -1615,9 +1646,6 @@ CONFIG_CRYPTO_DES=y
#
# Hardware crypto devices
#
-# CONFIG_XEN_UTIL is not set
-CONFIG_XEN_BALLOON=y
-CONFIG_XEN_REBOOT=y
# CONFIG_XEN_SMPBOOT is not set
CONFIG_XEN_INTERFACE_VERSION=0x00030205
@@ -1650,8 +1678,6 @@ CONFIG_XEN_COMPAT_030002_AND_LATER=y
CONFIG_XEN_COMPAT_030002_AND_LATER=y
# CONFIG_XEN_COMPAT_030004_AND_LATER is not set
# CONFIG_XEN_COMPAT_LATEST_ONLY is not set
-CONFIG_XEN_COMPAT_030002=y
-CONFIG_XEN_COMPAT_030004=y
+CONFIG_XEN_COMPAT=0x030002
CONFIG_HAVE_IRQ_IGNORE_UNHANDLED=y
CONFIG_NO_IDLE_HZ=y
-CONFIG_XEN_DEVMEM=y
diff -r 9313d0ce09f8 linux-2.6-xen-sparse/arch/ia64/xen/Makefile
--- a/linux-2.6-xen-sparse/arch/ia64/xen/Makefile Tue Apr 24 09:26:32
2007 -0600
+++ b/linux-2.6-xen-sparse/arch/ia64/xen/Makefile Wed May 02 22:52:34
2007 -0600
@@ -3,7 +3,5 @@
#
obj-y := hypercall.o xenivt.o xenentry.o xensetup.o xenpal.o xenhpski.o \
- hypervisor.o pci-dma-xen.o util.o xencomm.o xcom_hcall.o \
- xcom_mini.o xcom_privcmd.o mem.o
-
-pci-dma-xen-y := ../../i386/kernel/pci-dma-xen.o
+ hypervisor.o util.o xencomm.o xcom_hcall.o xcom_mini.o \
+ xcom_privcmd.o mem.o
diff -r 9313d0ce09f8 linux-2.6-xen-sparse/include/asm-ia64/dma-mapping.h
--- a/linux-2.6-xen-sparse/include/asm-ia64/dma-mapping.h Tue Apr 24
09:26:32 2007 -0600
+++ b/linux-2.6-xen-sparse/include/asm-ia64/dma-mapping.h Wed May 02
22:52:34 2007 -0600
@@ -13,7 +13,6 @@
#include <asm/swiotlb.h>
#endif
-#ifndef CONFIG_XEN
#define dma_alloc_coherent platform_dma_alloc_coherent
#define dma_alloc_noncoherent platform_dma_alloc_coherent /* coherent
mem. is cheap */
#define dma_free_coherent platform_dma_free_coherent
@@ -27,47 +26,6 @@
#define dma_sync_single_for_device platform_dma_sync_single_for_device
#define dma_sync_sg_for_device platform_dma_sync_sg_for_device
#define dma_mapping_error platform_dma_mapping_error
-#else
-int dma_map_sg(struct device *hwdev, struct scatterlist *sg, int nents,
- enum dma_data_direction direction);
-void dma_unmap_sg(struct device *hwdev, struct scatterlist *sg, int nents,
- enum dma_data_direction direction);
-int dma_supported(struct device *dev, u64 mask);
-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);
-dma_addr_t dma_map_single(struct device *dev, void *ptr, size_t size,
- enum dma_data_direction direction);
-void dma_unmap_single(struct device *dev, dma_addr_t dma_addr, size_t size,
- enum dma_data_direction direction);
-void dma_sync_single_for_cpu(struct device *dev, dma_addr_t dma_handle,
- size_t size, enum dma_data_direction direction);
-void dma_sync_single_for_device(struct device *dev, dma_addr_t dma_handle,
- size_t size,
- enum dma_data_direction direction);
-int dma_mapping_error(dma_addr_t dma_addr);
-
-#define flush_write_buffers() do { } while (0)
-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();
-}
-#endif
-
#define dma_map_page(dev, pg, off, size, dir) \
dma_map_single(dev, page_address(pg) + (off), (size), (dir))
#define dma_unmap_page(dev, dma_addr, size, dir) \
@@ -83,9 +41,7 @@ dma_sync_sg_for_device(struct device *de
#define dma_sync_single_range_for_device(dev, dma_handle, offset, size, dir)
\
dma_sync_single_for_device(dev, dma_handle, size, dir)
-#ifndef CONFIG_XEN
#define dma_supported platform_dma_supported
-#endif
static inline int
dma_set_mask (struct device *dev, u64 mask)
@@ -111,26 +67,19 @@ dma_cache_sync (void *vaddr, size_t size
#define dma_is_consistent(dma_handle) (1) /* all we do is coherent
memory... */
#ifdef CONFIG_XEN
-/* arch/i386/kernel/swiotlb.o requires */
-void contiguous_bitmap_init(unsigned long end_pfn);
-
-static inline int
-address_needs_mapping(struct device *hwdev, dma_addr_t addr)
-{
- dma_addr_t mask = DMA_64BIT_MASK;
- /* If the device has a mask, use it, otherwise default to 64 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;
+
+ if (!is_running_on_xen())
+ return 0;
+
return (((((unsigned long)p & ~PAGE_MASK) + size) > PAGE_SIZE) &&
!test_bit(__pa(p) >> PAGE_SHIFT, contiguous_bitmap));
}
+#else
+#define range_straddles_page_boundary(addr, size) (0)
#endif
#endif /* _ASM_IA64_DMA_MAPPING_H */
diff -r 9313d0ce09f8 linux-2.6-xen-sparse/include/asm-ia64/machvec_dig.h
--- a/linux-2.6-xen-sparse/include/asm-ia64/machvec_dig.h Tue Apr 24
09:26:32 2007 -0600
+++ b/linux-2.6-xen-sparse/include/asm-ia64/machvec_dig.h Wed May 02
22:52:34 2007 -0600
@@ -13,19 +13,4 @@ extern ia64_mv_setup_t dig_setup;
#define platform_name "dig"
#define platform_setup dig_setup
-#ifdef CONFIG_XEN
-# define platform_dma_map_sg dma_map_sg
-# define platform_dma_unmap_sg dma_unmap_sg
-# define platform_dma_mapping_error dma_mapping_error
-# define platform_dma_supported dma_supported
-# define platform_dma_alloc_coherent dma_alloc_coherent
-# define platform_dma_free_coherent dma_free_coherent
-# define platform_dma_map_single dma_map_single
-# define platform_dma_unmap_single dma_unmap_single
-# define platform_dma_sync_single_for_cpu \
- dma_sync_single_for_cpu
-# define platform_dma_sync_single_for_device \
- dma_sync_single_for_device
-#endif
-
#endif /* _ASM_IA64_MACHVEC_DIG_h */
diff -r 9313d0ce09f8 linux-2.6-xen-sparse/lib/Makefile
--- a/linux-2.6-xen-sparse/lib/Makefile Tue Apr 24 09:26:32 2007 -0600
+++ b/linux-2.6-xen-sparse/lib/Makefile Wed May 02 22:52:34 2007 -0600
@@ -52,7 +52,12 @@ obj-$(CONFIG_AUDIT_GENERIC) += audit.o
obj-$(CONFIG_AUDIT_GENERIC) += audit.o
obj-$(CONFIG_SWIOTLB) += swiotlb.o
+ifeq ($(CONFIG_X86),y)
swiotlb-$(CONFIG_XEN) := ../arch/i386/kernel/swiotlb.o
+endif
+ifeq ($(CONFIG_IA64),y)
+swiotlb-$(CONFIG_XEN) := ../arch/ia64/xen/swiotlb.o
+endif
hostprogs-y := gen_crc32table
clean-files := crc32table.h
--- linux-2.6-xen-sparse/arch/ia64/xen/swiotlb.c 2006-09-19
21:42:06.000000000 -0600
+++ linux-2.6-xen-sparse/arch/ia64/xen/swiotlb.c 2007-05-02
22:52:34.000000000 -0600
@@ -32,11 +32,22 @@
#include <linux/init.h>
#include <linux/bootmem.h>
+#ifdef CONFIG_XEN
+/*
+ * What DMA mask should Xen use to remap the bounce buffer pool? Most
+ * reports seem to indicate 30 bits is sufficient, except maybe for old
+ * sound cards that we probably don't care about anyway. If we need to,
+ * we could put in some smarts to try to lower, but hopefully it's not
+ * necessary.
+ */
+#define DMA_BITS (30)
+#endif
+
#define OFFSET(val,align) ((unsigned long) \
( (val) & ( (align) - 1)))
#define SG_ENT_VIRT_ADDRESS(sg) (page_address((sg)->page) +
(sg)->offset)
-#define SG_ENT_PHYS_ADDRESS(SG) virt_to_phys(SG_ENT_VIRT_ADDRESS(SG))
+#define SG_ENT_PHYS_ADDRESS(SG) virt_to_bus(SG_ENT_VIRT_ADDRESS(SG))
/*
* Maximum allowable number of contiguous slabs to map,
@@ -139,6 +150,10 @@
io_tlb_nslabs = ALIGN(io_tlb_nslabs, IO_TLB_SEGSIZE);
}
+#ifdef CONFIG_XEN
+ if (is_running_on_xen())
+ io_tlb_nslabs = roundup_pow_of_two(io_tlb_nslabs);
+#endif
/*
* Get IO TLB memory from the low pages
*/
@@ -147,6 +162,17 @@
panic("Cannot allocate SWIOTLB buffer");
io_tlb_end = io_tlb_start + io_tlb_nslabs * (1 << IO_TLB_SHIFT);
+#ifdef CONFIG_XEN
+ for (i = 0 ; i < io_tlb_nslabs ; i += IO_TLB_SEGSIZE) {
+ if (xen_create_contiguous_region(
+ (unsigned long)io_tlb_start +
+ (i << IO_TLB_SHIFT),
+ get_order(IO_TLB_SEGSIZE << IO_TLB_SHIFT),
+ DMA_BITS))
+ panic("Failed to setup Xen contiguous region");
+ }
+#endif
+
/*
* Allocate and initialize the free list array. This array is used
* to find contiguous free memory regions of size up to IO_TLB_SEGSIZE
@@ -162,6 +188,11 @@
* Get the overflow emergency buffer
*/
io_tlb_overflow_buffer = alloc_bootmem_low(io_tlb_overflow);
+#ifdef CONFIG_XEN
+ if (xen_create_contiguous_region((unsigned long)io_tlb_overflow_buffer,
+ get_order(io_tlb_overflow), DMA_BITS))
+ panic("Failed to setup Xen contiguous region for overflow");
+#endif
printk(KERN_INFO "Placing software IO TLB between 0x%lx - 0x%lx\n",
virt_to_phys(io_tlb_start), virt_to_phys(io_tlb_end));
}
@@ -188,6 +219,10 @@
io_tlb_nslabs = ALIGN(io_tlb_nslabs, IO_TLB_SEGSIZE);
}
+#ifdef CONFIG_XEN
+ if (is_running_on_xen())
+ io_tlb_nslabs = roundup_pow_of_two(io_tlb_nslabs);
+#endif
/*
* Get IO TLB memory from the low pages
*/
@@ -213,6 +248,16 @@
io_tlb_end = io_tlb_start + io_tlb_nslabs * (1 << IO_TLB_SHIFT);
memset(io_tlb_start, 0, io_tlb_nslabs * (1 << IO_TLB_SHIFT));
+#ifdef CONFIG_XEN
+ for (i = 0 ; i < io_tlb_nslabs ; i += IO_TLB_SEGSIZE) {
+ if (xen_create_contiguous_region(
+ (unsigned long)io_tlb_start +
+ (i << IO_TLB_SHIFT),
+ get_order(IO_TLB_SEGSIZE << IO_TLB_SHIFT),
+ DMA_BITS))
+ panic("Failed to setup Xen contiguous region");
+ }
+#endif
/*
* Allocate and initialize the free list array. This array is used
* to find contiguous free memory regions of size up to IO_TLB_SEGSIZE
@@ -242,6 +287,11 @@
if (!io_tlb_overflow_buffer)
goto cleanup4;
+#ifdef CONFIG_XEN
+ if (xen_create_contiguous_region((unsigned long)io_tlb_overflow_buffer,
+ get_order(io_tlb_overflow), DMA_BITS))
+ panic("Failed to setup Xen contiguous region for overflow");
+#endif
printk(KERN_INFO "Placing %ldMB software IO TLB between 0x%lx - "
"0x%lx\n", (io_tlb_nslabs * (1 << IO_TLB_SHIFT)) >> 20,
virt_to_phys(io_tlb_start), virt_to_phys(io_tlb_end));
@@ -445,7 +495,25 @@
flags |= GFP_DMA;
ret = (void *)__get_free_pages(flags, order);
- if (ret && address_needs_mapping(hwdev, virt_to_phys(ret))) {
+#ifdef CONFIG_XEN
+ if (ret && is_running_on_xen()) {
+ if (xen_create_contiguous_region((unsigned long)ret, order,
+ fls64(hwdev->coherent_dma_mask))) {
+ free_pages((unsigned long)ret, order);
+ ret = NULL;
+ } else {
+ /*
+ * Short circuit the rest, xen_create_contiguous_region
+ * should fail if it didn't give us an address within
+ * the mask requested.
+ */
+ memset(ret, 0, size);
+ *dma_handle = virt_to_bus(ret);
+ return ret;
+ }
+ }
+#endif
+ if (ret && address_needs_mapping(hwdev, virt_to_bus(ret))) {
/*
* The allocated memory isn't reachable by the device.
* Fall back on swiotlb_map_single().
@@ -465,11 +533,11 @@
if (swiotlb_dma_mapping_error(handle))
return NULL;
- ret = phys_to_virt(handle);
+ ret = bus_to_virt(handle);
}
memset(ret, 0, size);
- dev_addr = virt_to_phys(ret);
+ dev_addr = virt_to_bus(ret);
/* Confirm address can be DMA'd by device */
if (address_needs_mapping(hwdev, dev_addr)) {
@@ -487,9 +555,13 @@
dma_addr_t dma_handle)
{
if (!(vaddr >= (void *)io_tlb_start
- && vaddr < (void *)io_tlb_end))
+ && vaddr < (void *)io_tlb_end)) {
+#ifdef CONFIG_XEN
+ xen_destroy_contiguous_region((unsigned long)vaddr,
+ get_order(size));
+#endif
free_pages((unsigned long) vaddr, get_order(size));
- else
+ } else
/* DMA_TO_DEVICE to avoid memcpy in unmap_single */
swiotlb_unmap_single (hwdev, dma_handle, size, DMA_TO_DEVICE);
}
@@ -525,7 +597,7 @@
dma_addr_t
swiotlb_map_single(struct device *hwdev, void *ptr, size_t size, int dir)
{
- unsigned long dev_addr = virt_to_phys(ptr);
+ unsigned long dev_addr = virt_to_bus(ptr);
void *map;
BUG_ON(dir == DMA_NONE);
@@ -534,7 +606,8 @@
* we can safely return the device addr and not worry about bounce
* buffering it.
*/
- if (!address_needs_mapping(hwdev, dev_addr) && !swiotlb_force)
+ if (!range_straddles_page_boundary(ptr, size) &&
+ !address_needs_mapping(hwdev, dev_addr) && !swiotlb_force)
return dev_addr;
/*
@@ -546,7 +619,7 @@
map = io_tlb_overflow_buffer;
}
- dev_addr = virt_to_phys(map);
+ dev_addr = virt_to_bus(map);
/*
* Ensure that the address returned is DMA'ble
@@ -588,13 +661,22 @@
swiotlb_unmap_single(struct device *hwdev, dma_addr_t dev_addr, size_t size,
int dir)
{
- char *dma_addr = phys_to_virt(dev_addr);
+ char *dma_addr = bus_to_virt(dev_addr);
BUG_ON(dir == DMA_NONE);
if (dma_addr >= io_tlb_start && dma_addr < io_tlb_end)
unmap_single(hwdev, dma_addr, size, dir);
+#ifdef CONFIG_XEN
+ else {
+ xen_destroy_contiguous_region((unsigned long)dma_addr,
+ get_order(size));
+ if (dir == DMA_FROM_DEVICE)
+ mark_clean(dma_addr, size);
+ }
+#else
else if (dir == DMA_FROM_DEVICE)
mark_clean(dma_addr, size);
+#endif
}
/*
@@ -611,7 +693,7 @@
swiotlb_sync_single(struct device *hwdev, dma_addr_t dev_addr,
size_t size, int dir, int target)
{
- char *dma_addr = phys_to_virt(dev_addr);
+ char *dma_addr = bus_to_virt(dev_addr);
BUG_ON(dir == DMA_NONE);
if (dma_addr >= io_tlb_start && dma_addr < io_tlb_end)
@@ -642,7 +724,7 @@
unsigned long offset, size_t size,
int dir, int target)
{
- char *dma_addr = phys_to_virt(dev_addr) + offset;
+ char *dma_addr = bus_to_virt(dev_addr) + offset;
BUG_ON(dir == DMA_NONE);
if (dma_addr >= io_tlb_start && dma_addr < io_tlb_end)
@@ -695,7 +777,7 @@
for (i = 0; i < nelems; i++, sg++) {
addr = SG_ENT_VIRT_ADDRESS(sg);
- dev_addr = virt_to_phys(addr);
+ dev_addr = virt_to_bus(addr);
if (swiotlb_force || address_needs_mapping(hwdev, dev_addr)) {
void *map = map_single(hwdev, addr, sg->length, dir);
sg->dma_address = virt_to_bus(map);
@@ -728,7 +810,7 @@
for (i = 0; i < nelems; i++, sg++)
if (sg->dma_address != SG_ENT_PHYS_ADDRESS(sg))
- unmap_single(hwdev, (void *)
phys_to_virt(sg->dma_address), sg->dma_length, dir);
+ unmap_single(hwdev, (void *)
bus_to_virt(sg->dma_address), sg->dma_length, dir);
else if (dir == DMA_FROM_DEVICE)
mark_clean(SG_ENT_VIRT_ADDRESS(sg), sg->dma_length);
}
@@ -771,7 +853,7 @@
int
swiotlb_dma_mapping_error(dma_addr_t dma_addr)
{
- return (dma_addr == virt_to_phys(io_tlb_overflow_buffer));
+ return (dma_addr == virt_to_bus(io_tlb_overflow_buffer));
}
/*
@@ -783,7 +865,7 @@
int
swiotlb_dma_supported (struct device *hwdev, u64 mask)
{
- return (virt_to_phys (io_tlb_end) - 1) <= mask;
+ return (virt_to_bus(io_tlb_end) - 1) <= mask;
}
EXPORT_SYMBOL(swiotlb_init);
--- linux-2.6-xen-sparse/arch/ia64/hp/common/sba_iommu.c 2006-09-19
21:42:06.000000000 -0600
+++ linux-2.6-xen-sparse/arch/ia64/hp/common/sba_iommu.c 2007-05-02
22:52:34.000000000 -0600
@@ -894,15 +894,14 @@
unsigned long flags;
#endif
#ifdef ALLOW_IOV_BYPASS
- unsigned long pci_addr = virt_to_phys(addr);
-#endif
+ unsigned long pci_addr = virt_to_bus(addr);
-#ifdef ALLOW_IOV_BYPASS
ASSERT(to_pci_dev(dev)->dma_mask);
/*
** Check if the PCI device can DMA to ptr... if so, just return ptr
*/
- if (likely((pci_addr & ~to_pci_dev(dev)->dma_mask) == 0)) {
+ if (likely(pci_addr & ~to_pci_dev(dev)->dma_mask) == 0 &&
+ !range_straddles_page_boundary(addr, size)) {
/*
** Device is bit capable of DMA'ing to the buffer...
** just return the PCI address of ptr
@@ -944,7 +943,7 @@
while (size > 0) {
ASSERT(((u8 *)pdir_start)[7] == 0); /* verify availability */
- sba_io_pdir_entry(pdir_start, (unsigned long) addr);
+ sba_io_pdir_entry(pdir_start, virt_to_bus(addr));
DBG_RUN(" pdir 0x%p %lx\n", pdir_start, *pdir_start);
@@ -973,13 +972,13 @@
void *addr;
if (size <= iovp_size) {
- addr = phys_to_virt(ioc->pdir_base[off] &
- ~0xE000000000000FFFULL);
+ addr = bus_to_virt(ioc->pdir_base[off] &
+ ~0xE000000000000FFFULL);
mark_clean(addr, size);
} else {
do {
- addr = phys_to_virt(ioc->pdir_base[off] &
- ~0xE000000000000FFFULL);
+ addr = bus_to_virt(ioc->pdir_base[off] &
+ ~0xE000000000000FFFULL);
mark_clean(addr, min(size, iovp_size));
off++;
size -= iovp_size;
@@ -1018,7 +1017,7 @@
#ifdef ENABLE_MARK_CLEAN
if (dir == DMA_FROM_DEVICE) {
- mark_clean(phys_to_virt(iova), size);
+ mark_clean(bus_to_virt(iova), size);
}
#endif
return;
@@ -1102,9 +1101,14 @@
return NULL;
memset(addr, 0, size);
- *dma_handle = virt_to_phys(addr);
#ifdef ALLOW_IOV_BYPASS
+#ifdef CONFIG_XEN
+ if (xen_create_contiguous_region((unsigned long)addr, get_order(size),
+ fls64(dev->coherent_dma_mask)))
+ goto iommu_map;
+#endif
+ *dma_handle = virt_to_bus(addr);
ASSERT(dev->coherent_dma_mask);
/*
** Check if the PCI device can DMA to ptr... if so, just return ptr
@@ -1115,6 +1119,9 @@
return addr;
}
+#ifdef CONFIG_XEN
+iommu_map:
+#endif
#endif
/*
@@ -1138,6 +1145,13 @@
*/
void sba_free_coherent (struct device *dev, size_t size, void *vaddr,
dma_addr_t dma_handle)
{
+#if defined(ALLOW_IOV_BYPASS) && defined(CONFIG_XEN)
+ struct ioc *ioc = GET_IOC(dev);
+
+ if (likely((dma_handle & ioc->imask) != ioc->ibase))
+ xen_destroy_contiguous_region((unsigned long)vaddr,
+ get_order(size));
+#endif
sba_unmap_single(dev, dma_handle, size, 0);
free_pages((unsigned long) vaddr, get_order(size));
}
@@ -1219,7 +1233,8 @@
dma_offset=0; /* only want offset on first chunk */
cnt = ROUNDUP(cnt, iovp_size);
do {
- sba_io_pdir_entry(pdirp, vaddr);
+ sba_io_pdir_entry(pdirp,
+ virt_to_bus((void *)vaddr));
vaddr += iovp_size;
cnt -= iovp_size;
pdirp++;
@@ -1406,7 +1421,7 @@
if (likely((ioc->dma_mask & ~to_pci_dev(dev)->dma_mask) == 0)) {
for (sg = sglist ; filled < nents ; filled++, sg++){
sg->dma_length = sg->length;
- sg->dma_address = virt_to_phys(sba_sg_address(sg));
+ sg->dma_address = virt_to_bus(sba_sg_address(sg));
}
return filled;
}
@@ -1560,13 +1575,19 @@
if (!ioc->pdir_base)
panic(PFX "Couldn't allocate I/O Page Table\n");
+#ifdef CONFIG_XEN
+ /* The page table needs to be pinned in Xen memory */
+ if (xen_create_contiguous_region((unsigned long)ioc->pdir_base,
+ get_order(ioc->pdir_size), 0))
+ panic(PFX "Couldn't contiguously map I/O Page Table\n");
+#endif
memset(ioc->pdir_base, 0, ioc->pdir_size);
DBG_INIT("%s() IOV page size %ldK pdir %p size %x\n", __FUNCTION__,
iovp_size >> 10, ioc->pdir_base, ioc->pdir_size);
ASSERT(ALIGN((unsigned long) ioc->pdir_base, 4*1024) == (unsigned long)
ioc->pdir_base);
- WRITE_REG(virt_to_phys(ioc->pdir_base), ioc->ioc_hpa + IOC_PDIR_BASE);
+ WRITE_REG(virt_to_bus(ioc->pdir_base), ioc->ioc_hpa + IOC_PDIR_BASE);
/*
** If an AGP device is present, only use half of the IOV space
@@ -1603,7 +1624,7 @@
for ( ; (u64) poison_addr < addr + iovp_size; poison_addr +=
poison_size)
memcpy(poison_addr, spill_poison, poison_size);
- prefetch_spill_page = virt_to_phys(addr);
+ prefetch_spill_page = virt_to_bus(addr);
DBG_INIT("%s() prefetch spill addr: 0x%lx\n", __FUNCTION__,
prefetch_spill_page);
}
_______________________________________________
Xen-ia64-devel mailing list
Xen-ia64-devel@xxxxxxxxxxxxxxxxxxx
http://lists.xensource.com/xen-ia64-devel
|