[PATCHv7 4/9] ARM: dma-mapping: use asm-generic/dma-mapping-common.h

2012-02-29 Thread Marek Szyprowski
This patch modifies dma-mapping implementation on ARM architecture to
use common dma_map_ops structure and asm-generic/dma-mapping-common.h
helpers.

Signed-off-by: Marek Szyprowski m.szyprow...@samsung.com
Signed-off-by: Kyungmin Park kyungmin.p...@samsung.com
---
 arch/arm/Kconfig   |1 +
 arch/arm/include/asm/device.h  |1 +
 arch/arm/include/asm/dma-mapping.h |  196 +---
 arch/arm/mm/dma-mapping.c  |  148 ---
 4 files changed, 115 insertions(+), 231 deletions(-)

diff --git a/arch/arm/Kconfig b/arch/arm/Kconfig
index a48aecc..59102fb 100644
--- a/arch/arm/Kconfig
+++ b/arch/arm/Kconfig
@@ -4,6 +4,7 @@ config ARM
select HAVE_AOUT
select HAVE_DMA_API_DEBUG
select HAVE_IDE if PCI || ISA || PCMCIA
+   select HAVE_DMA_ATTRS
select HAVE_MEMBLOCK
select RTC_LIB
select SYS_SUPPORTS_APM_EMULATION
diff --git a/arch/arm/include/asm/device.h b/arch/arm/include/asm/device.h
index 7aa3680..6e2cb0e 100644
--- a/arch/arm/include/asm/device.h
+++ b/arch/arm/include/asm/device.h
@@ -7,6 +7,7 @@
 #define ASMARM_DEVICE_H
 
 struct dev_archdata {
+   struct dma_map_ops  *dma_ops;
 #ifdef CONFIG_DMABOUNCE
struct dmabounce_device_info *dmabounce;
 #endif
diff --git a/arch/arm/include/asm/dma-mapping.h 
b/arch/arm/include/asm/dma-mapping.h
index ba422f2..6aea6ca 100644
--- a/arch/arm/include/asm/dma-mapping.h
+++ b/arch/arm/include/asm/dma-mapping.h
@@ -11,6 +11,27 @@
 #include asm/memory.h
 
 #define ARM_DMA_ERROR  ~0
+extern struct dma_map_ops arm_dma_ops;
+
+static inline struct dma_map_ops *get_dma_ops(struct device *dev)
+{
+   if (dev  dev-archdata.dma_ops)
+   return dev-archdata.dma_ops;
+   return arm_dma_ops;
+}
+
+static inline void set_dma_ops(struct device *dev, struct dma_map_ops *ops)
+{
+   BUG_ON(!dev);
+   dev-archdata.dma_ops = ops;
+}
+
+#include asm-generic/dma-mapping-common.h
+
+static inline int dma_set_mask(struct device *dev, u64 mask)
+{
+   return get_dma_ops(dev)-set_dma_mask(dev, mask);
+}
 
 #ifdef __arch_page_to_dma
 #error Please update to __arch_pfn_to_dma
@@ -119,7 +140,6 @@ static inline void __dma_page_dev_to_cpu(struct page *page, 
unsigned long off,
 
 extern int dma_supported(struct device *, u64);
 extern int dma_set_mask(struct device *, u64);
-
 /*
  * DMA errors are defined by all-bits-set in the DMA address.
  */
@@ -297,179 +317,17 @@ static inline void __dma_unmap_page(struct device *dev, 
dma_addr_t handle,
 }
 #endif /* CONFIG_DMABOUNCE */
 
-/**
- * dma_map_single - map a single buffer for streaming DMA
- * @dev: valid struct device pointer, or NULL for ISA and EISA-like devices
- * @cpu_addr: CPU direct mapped address of buffer
- * @size: size of buffer to map
- * @dir: DMA transfer direction
- *
- * Ensure that any data held in the cache is appropriately discarded
- * or written back.
- *
- * The device owns this memory once this call has completed.  The CPU
- * can regain ownership by calling dma_unmap_single() or
- * dma_sync_single_for_cpu().
- */
-static inline dma_addr_t dma_map_single(struct device *dev, void *cpu_addr,
-   size_t size, enum dma_data_direction dir)
-{
-   unsigned long offset;
-   struct page *page;
-   dma_addr_t addr;
-
-   BUG_ON(!virt_addr_valid(cpu_addr));
-   BUG_ON(!virt_addr_valid(cpu_addr + size - 1));
-   BUG_ON(!valid_dma_direction(dir));
-
-   page = virt_to_page(cpu_addr);
-   offset = (unsigned long)cpu_addr  ~PAGE_MASK;
-   addr = __dma_map_page(dev, page, offset, size, dir);
-   debug_dma_map_page(dev, page, offset, size, dir, addr, true);
-
-   return addr;
-}
-
-/**
- * dma_map_page - map a portion of a page for streaming DMA
- * @dev: valid struct device pointer, or NULL for ISA and EISA-like devices
- * @page: page that buffer resides in
- * @offset: offset into page for start of buffer
- * @size: size of buffer to map
- * @dir: DMA transfer direction
- *
- * Ensure that any data held in the cache is appropriately discarded
- * or written back.
- *
- * The device owns this memory once this call has completed.  The CPU
- * can regain ownership by calling dma_unmap_page().
- */
-static inline dma_addr_t dma_map_page(struct device *dev, struct page *page,
-unsigned long offset, size_t size, enum dma_data_direction dir)
-{
-   dma_addr_t addr;
-
-   BUG_ON(!valid_dma_direction(dir));
-
-   addr = __dma_map_page(dev, page, offset, size, dir);
-   debug_dma_map_page(dev, page, offset, size, dir, addr, false);
-
-   return addr;
-}
-
-/**
- * dma_unmap_single - unmap a single buffer previously mapped
- * @dev: valid struct device pointer, or NULL for ISA and EISA-like devices
- * @handle: DMA address of buffer
- * @size: size of buffer (same as passed to dma_map_single)
- * @dir: DMA transfer direction (same as passed to dma_map_single)
- *
- * Unmap a single 

[PATCHv7 8/9] ARM: dma-mapping: use alloc, mmap, free from dma_ops

2012-02-29 Thread Marek Szyprowski
This patch converts dma_alloc/free/mmap_{coherent,writecombine}
functions to use generic alloc/free/mmap methods from dma_map_ops
structure. A new DMA_ATTR_WRITE_COMBINE DMA attribute have been
introduced to implement writecombine methods.

Signed-off-by: Marek Szyprowski m.szyprow...@samsung.com
Signed-off-by: Kyungmin Park kyungmin.p...@samsung.com
---
 arch/arm/common/dmabounce.c|3 +
 arch/arm/include/asm/dma-mapping.h |  107 ++--
 arch/arm/mm/dma-mapping.c  |   53 ++
 3 files changed, 98 insertions(+), 65 deletions(-)

diff --git a/arch/arm/common/dmabounce.c b/arch/arm/common/dmabounce.c
index 119f487..dbae5ad 100644
--- a/arch/arm/common/dmabounce.c
+++ b/arch/arm/common/dmabounce.c
@@ -449,6 +449,9 @@ static int dmabounce_set_mask(struct device *dev, u64 
dma_mask)
 }
 
 static struct dma_map_ops dmabounce_ops = {
+   .alloc  = arm_dma_alloc,
+   .free   = arm_dma_free,
+   .mmap   = arm_dma_mmap,
.map_page   = dmabounce_map_page,
.unmap_page = dmabounce_unmap_page,
.sync_single_for_cpu= dmabounce_sync_for_cpu,
diff --git a/arch/arm/include/asm/dma-mapping.h 
b/arch/arm/include/asm/dma-mapping.h
index 266cba6..4342b75 100644
--- a/arch/arm/include/asm/dma-mapping.h
+++ b/arch/arm/include/asm/dma-mapping.h
@@ -5,6 +5,7 @@
 
 #include linux/mm_types.h
 #include linux/scatterlist.h
+#include linux/dma-attrs.h
 #include linux/dma-debug.h
 
 #include asm-generic/dma-coherent.h
@@ -110,68 +111,115 @@ static inline void dma_free_noncoherent(struct device 
*dev, size_t size,
 extern int dma_supported(struct device *dev, u64 mask);
 
 /**
- * dma_alloc_coherent - allocate consistent memory for DMA
+ * arm_dma_alloc - allocate consistent memory for DMA
  * @dev: valid struct device pointer, or NULL for ISA and EISA-like devices
  * @size: required memory size
  * @handle: bus-specific DMA address
+ * @attrs: optinal attributes that specific mapping properties
  *
- * Allocate some uncached, unbuffered memory for a device for
- * performing DMA.  This function allocates pages, and will
- * return the CPU-viewed address, and sets @handle to be the
- * device-viewed address.
+ * Allocate some memory for a device for performing DMA.  This function
+ * allocates pages, and will return the CPU-viewed address, and sets @handle
+ * to be the device-viewed address.
  */
-extern void *dma_alloc_coherent(struct device *, size_t, dma_addr_t *, gfp_t);
+extern void *arm_dma_alloc(struct device *dev, size_t size, dma_addr_t *handle,
+  gfp_t gfp, struct dma_attrs *attrs);
+
+#define dma_alloc_coherent(d,s,h,f) dma_alloc_attrs(d,s,h,f,NULL)
+
+static inline void *dma_alloc_attrs(struct device *dev, size_t size,
+  dma_addr_t *dma_handle, gfp_t flag,
+  struct dma_attrs *attrs)
+{
+   struct dma_map_ops *ops = get_dma_ops(dev);
+   void *cpu_addr;
+   BUG_ON(!ops);
+
+   cpu_addr = ops-alloc(dev, size, dma_handle, flag, attrs);
+   debug_dma_alloc_coherent(dev, size, *dma_handle, cpu_addr);
+   return cpu_addr;
+}
 
 /**
- * dma_free_coherent - free memory allocated by dma_alloc_coherent
+ * arm_dma_free - free memory allocated by arm_dma_alloc
  * @dev: valid struct device pointer, or NULL for ISA and EISA-like devices
  * @size: size of memory originally requested in dma_alloc_coherent
  * @cpu_addr: CPU-view address returned from dma_alloc_coherent
  * @handle: device-view address returned from dma_alloc_coherent
+ * @attrs: optinal attributes that specific mapping properties
  *
  * Free (and unmap) a DMA buffer previously allocated by
- * dma_alloc_coherent().
+ * arm_dma_alloc().
  *
  * References to memory and mappings associated with cpu_addr/handle
  * during and after this call executing are illegal.
  */
-extern void dma_free_coherent(struct device *, size_t, void *, dma_addr_t);
+extern void arm_dma_free(struct device *dev, size_t size, void *cpu_addr,
+dma_addr_t handle, struct dma_attrs *attrs);
+
+#define dma_free_coherent(d,s,c,h) dma_free_attrs(d,s,c,h,NULL)
+
+static inline void dma_free_attrs(struct device *dev, size_t size,
+void *cpu_addr, dma_addr_t dma_handle,
+struct dma_attrs *attrs)
+{
+   struct dma_map_ops *ops = get_dma_ops(dev);
+   BUG_ON(!ops);
+
+   debug_dma_free_coherent(dev, size, cpu_addr, dma_handle);
+   ops-free(dev, size, cpu_addr, dma_handle, attrs);
+}
 
 /**
- * dma_mmap_coherent - map a coherent DMA allocation into user space
+ * arm_dma_mmap - map a coherent DMA allocation into user space
  * @dev: valid struct device pointer, or NULL for ISA and EISA-like devices
  * @vma: vm_area_struct describing requested user mapping
  * @cpu_addr: kernel CPU-view address returned from 

Re: RFC: Device isolation groups

2012-02-29 Thread Alex Williamson
On Thu, 2012-02-02 at 12:24 +1100, David Gibson wrote:
 On Wed, Feb 01, 2012 at 01:08:39PM -0700, Alex Williamson wrote:
  On Wed, 2012-02-01 at 15:46 +1100, David Gibson wrote:
   This patch series introduces a new infrastructure to the driver core
   for representing device isolation groups.  That is, groups of
   devices which can be isolated in such a way that the rest of the
   system can be protected from them, even in the presence of userspace
   or a guest OS directly driving the devices.
   
   Isolation will typically be due to an IOMMU which can safely remap DMA
   and interrupts coming from these devices.  We need to represent whole
   groups, rather than individual devices, because there are a number of
   cases where the group can be isolated as a whole, but devices within
   it cannot be safely isolated from each other - this usually occurs
   because the IOMMU cannot reliably distinguish which device in the
   group initiated a transaction.  In other words, isolation groups
   represent the minimum safe granularity for passthrough to guests or
   userspace.
   
   This series provides the core infraustrcture for tracking isolation
   groups, and example implementations initializing the groups
   appropriately for two PCI bridges (which include IOMMUs) found on IBM
   POWER systems.
   
   Actually using the group information is not included here, but David
   Woodhouse has expressed an interest in using a structure like this to
   represent operations in iommu_ops more correctly.
   
   Some tracking of groups is a prerequisite for safe passthrough of
   devices to guests or userspace, such as done by VFIO.  Current VFIO
   patches use the iommu_ops-device_group mechanism for this.  However,
   that mechanism is awkward, because without an in-kernel concrete
   representation of groups, enumerating a group requires traversing
   every device on a given bus type.  It also fails to cover some very
   plausible IOMMU topologies, because its groups cannot span devices on
   multiple bus types.
  
  So far so good, but there's not much meat on the bone yet.
 
 True..

Any update to this series?  It would be great if we could map out the
functionality to the point of breaking down and distributing work... or
determining if the end result has any value add to what VFIO already
does.  Thanks,

Alex

___
iommu mailing list
iommu@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/iommu


Re: [PATCH v9 0/2] iommu/exynos: Add IOMMU/System MMU driver for Samsung Exynos

2012-02-29 Thread Kyungmin Park
Hi,

Some comments.
1. It's not same patch series. since it has additional feature,
exynos5 series support which don't covered at previous time.
2. It assumes that name conversion is based on exynos5 as default. now
you use gsc at exynos4 even though there's no gsc block. It should be
fimc.

So I suggest to send exynos4 series patch as before and send
additional exynos5 patch series next.

Thank you,
Kyungmin Park

On 2/28/12, KyongHo Cho pullip@samsung.com wrote:
 Changes since v8:
 - exynos_iommu_map/unmap() just works for the page sizes
that System MMU supports. (Joerg's comment)
 - 1 platform device for 1 H/W though a multimedia accelerator
with several System MMUs attached.
This make controlling System MMU simpler.
 - Information between System MMU and the accelerators:
Shifted to accelerator's device structure from System MMU's

 Changes since v7:
 - Rebased with the recent commits of the following git branches
   * git.kernel.org/pub/scm/linux/kernel/git/joro/iommu.git/next
   * git.kernel.org/pub/scm/linux/kernel/git/kgene/linux-samsung.git/for-next
 - Changed magic numbers into macros
 - Setting owner of a System MMU in 'iommu' field of dev_archdata
 - Verbose message in the default fault handler
 - Some bug fixes.

 Changes since v6:
 - Totally rewrite exynos_iommu_map() and exynos_iommu_unmap() according
   to the change in iommu_map() and iommu_unmap().
 - Change special slab for Lv2 page table to kmalloc().

 Changes since v5:
 - Relation between device and a domain become n:1 (Joerg's comment)
 - Implements iommu_commit(). -- Removed

 Changes since v4:
 - exynos_iommu_unmap()returns unmapped size in page order
   (Ohad Ben-Cohen's comment)
 - Fixed typo error of resource names
 - Fixed missing #includemach/sysmmu.h
   in arch/arm/mach-exynos4/mach-armlex4210.c

 Changes since v3:
 - Used DEFINE_RES_MEM and DEFINE_RES_IRQ macros
   to define resources of System MMU (Russell King's comment)
 - Fixed removal of CONFIG_S5P_SLEEP definition
  (Sylwester Nawrocki's comment)

 Changes since v2:
 - Add lock for System MMU private data.
   And fixes the following problems pointed by Joerg Rodel:
 - Fix wrong argument to kmalloc() and get_free_pages()
 - Merged patches into 2 due to bisectability

 Changes since v1:
 Fixes of the following problems pointed by Russell King.:
  - Missing unlocking a spinlock in exynos_iommu_attach_dev().
  - atomic_t - int in sysmmu_drvdata.activations
  - sysmmu_platdata - sysmmu_drvdata
  - Change in error messages in irq handler
  - Removed casting in format of error message
  - omap_iommu_ops - exynos_iommu_ops in the last patch

 Patch Summary:
 [PATCH v8 1/2] ARM: EXYNOS: Change System MMU platform device definitions
 [PATCH v8 2/2] iommu/exynos: Add iommu driver for Exynos Platforms

 The first patche enhances System MMU platform device definition:
  - Removed System MMU for MDMA0 in TOP block because it is not
used. Use MDMA2 in LCD block.
  - Removed System MMU ID. Instead, a System MMU is bound to a device
that the System MMU is dedicated during machin initialization.
If a device driver wants to handle System MMU, it must bind its
device with System MMU with sysmmu_set_owner().
  - clkdev

 The last patch implements IOMMU API:
  - System MMU device driver is removed from arch/arm/plat-s5p
 to move it to driver/iommu directory.
  - Implements IOMMU API and System MMU driver that is moved from
 arch/arm/plat-s5p.

 Diffstats:
 arch/arm/mach-exynos/Kconfig|   11 +-
  arch/arm/mach-exynos/Makefile   |2 +-
  arch/arm/mach-exynos/clock-exynos4.c|   74 +-
  arch/arm/mach-exynos/clock-exynos4.h|2 +
  arch/arm/mach-exynos/clock-exynos4210.c |   11 +
  arch/arm/mach-exynos/clock-exynos4212.c |   28 +-
  arch/arm/mach-exynos/clock-exynos5.c|   85 ++
  arch/arm/mach-exynos/dev-sysmmu.c   |  454 ++-
  arch/arm/mach-exynos/include/mach/irqs.h|  179 ++--
  arch/arm/mach-exynos/include/mach/map.h |   38 +
  arch/arm/mach-exynos/include/mach/memory.h  |1 +
  arch/arm/mach-exynos/include/mach/regs-clock.h  |5 +
  arch/arm/mach-exynos/include/mach/regs-sysmmu.h |   28 -
  arch/arm/mach-exynos/include/mach/sysmmu.h  |   83 +-
  arch/arm/mach-exynos/mach-armlex4210.c  |1 -
  arch/arm/mach-exynos/mach-smdkv310.c|1 -
  arch/arm/plat-s5p/Kconfig   |8 -
  arch/arm/plat-s5p/Makefile  |1 -
  arch/arm/plat-s5p/sysmmu.c  |  313 ---
  arch/arm/plat-samsung/include/plat/devs.h   |1 -
  arch/arm/plat-samsung/include/plat/sysmmu.h |   95 --
  drivers/iommu/Kconfig   |   22 +
  drivers/iommu/Makefile  |1 +
  drivers/iommu/exynos-iommu.c| 1076
 +++
  24 files changed, 1698 insertions(+), 822 deletions(-)