RFC: dma_mmap_coherent() for powerpc/ppc architecture and ALSA?
Subsystems (7)
Quoted 14 lines
-------- Original-Nachricht --------
Datum: Fri, 09 Jun 2006 20:46:32 -0400
Von: Lee Revell <[email protected]>
An: Benjamin Herrenschmidt <[email protected]>
Betreff: Re: RFC:dma_mmap_coherent()for powerpc/ppc architecture and ALSA?Quoted 6 lines · Benjamin Herrenschmidt
Quoted 5 lines
This leads me to the question, if there are any plans to include the
dma_mmap_coherent()function (for powerpc/ppc and/or any other platform) in one of the next kernel versions and if an adapation of the ALSA drivers is planned. Or is there a simple way (hack) to fix this problem?
Quoted 3 lines
Quoted 1 line
You are welcome to do a patch implementing this :)
Please cc: alsa-devel when you do so.
:)
Well, implementing the dma_mmap_coherent() function isn't the problem, because it is already implemented for the ARM architecture. But as far as I understand this would require a rewrite of all the ALSA drivers (or at least a rewrite of the ALSA's DMA helper functions).
Original mail included for alsa-devel mailing list:
Quoted 22 lines
I'm trying to adapt Linux for the AmigaOne, which is a G3/G4 PPC desktop system with a non cache coherent northbridge (MAI ArticiaS), a VIA82C686B southbridge and the U-boot firmware. Due to the cache coherency problem I compiled in the
CONFIG_NOT_COHERENT_CACHEoption (arch/ppc/kernel/dma-mapping.c) in the AmigaOne Linux kernel.While that fixes the DMA data corruption problem, it causes a kernel oops or a complete system lookup after starting sound playback. With kernel versions =<2.6.14 the oops messages refered to a
BUG()entry inmm/rmap.c. Therefore I tried out a newer kernel (2.6.16.15), where the oops refers to the ALSA functionsnd_pcm_mmap_data_nopage()implemented inpcm_native.c.Well, after searching a while in some old linux kernel threads, I found this thread here:
http://www.thisishull.net/showthread.php?t=22080&page=3&pp=10Based on the information in this thread, I came to the conclusion that
ALSA simply won't work on non cache coherent architectures (except ARM),
because the generic DMA API was never expanded to support the
functionality required by ALSA (namely mapping dma pages into user space > withdma_mmap_coherent()).
Quoted 4 lines
This leads me to the question, if there are any plans to include the
dma_mmap_coherent()function (for powerpc/ppc and/or any other platform) in one of the next kernel versions and if an adapation of the ALSA drivers is planned. Or is there a simple way (hack) to fix this problem?
Gerhard
Signature · 2 lines
Der GMX SmartSurfer hilft bis zu 70% Ihrer Onlinekosten zu sparen! Ideal für Modem und ISDN: http://www.gmx.net/de/go/smartsurfer
At Sat, 10 Jun 2006 10:22:23 +0200,
Quoted 17 lines · Gerhard Pircher
Quoted 17 lines
-------- Original-Nachricht --------
Datum: Fri, 09 Jun 2006 20:46:32 -0400
Von: Lee Revell <[email protected]>
An: Benjamin Herrenschmidt <[email protected]>
Betreff: Re: RFC:dma_mmap_coherent()for powerpc/ppc architecture and ALSA?Quoted 7 lines · Benjamin Herrenschmidt
Quoted 5 lines
This leads me to the question, if there are any plans to include the
dma_mmap_coherent()function (for powerpc/ppc and/or any other platform) in one of the next kernel versions and if an adapation of the ALSA drivers is planned. Or is there a simple way (hack) to fix this problem?You are welcome to do a patch implementing this :)
Quoted 7 lines
Quoted 1 line
Please cc: alsa-devel when you do so.
:)
Well, implementing the
dma_mmap_coherent()function isn't the problem, because it is already implemented for the ARM architecture.
Actually, I wrote dma_coherent_mmap patch long time ago but it has been left forgotten. The patch attached below seems applicable to 2.6.17 tree, but I'm not sure whether it still works properly. It's untested on most of architectures.
Quoted 3 lines
But as far as I understand this would require a
rewrite of all the ALSA drivers (or at least a rewrite of the ALSA's DMA helper functions).
Yes. The change of ALSA side has been also on my tree. But it was still pending since I'm not satisfied with the design yet. If you're interested in it, let me know. I'll post the patch.
Takashi
arch/frv/mb93090-mb00/pci-dma-nommu.c +8 -0
@@ -106,6 +106,14 @@ void dma_free_coherent(struct device *hwEXPORT_SYMBOL (dma_free_coherent); +int dma_mmap_coherent (struct device *dev,struct vm_area_struct *vma, +void *cpu_addr,dma_addr_t handle,size_t size) +{ +return -ENXIO ; +} + +EXPORT_SYMBOL (dma_mmap_coherent); +/* * Map a single buffer of the indicated size for DMA in streaming mode. * The 32-bit bus address to use is returned.
arch/frv/mb93090-mb00/pci-dma.c +15 -0
@@ -37,6 +37,21 @@ void dma_free_coherent(struct device *hwEXPORT_SYMBOL (dma_free_coherent); +int dma_mmap_coherent (struct device *dev,struct vm_area_struct *vma, +void *cpu_addr,dma_addr_t handle,size_t size) +{ +unsigned long pfn; + +/* bus is equivalent with phys */ + pfn = ((unsigned long )handle) >>PAGE_SHIFT ; +return remap_pfn_range (vma, vma->vm_start, + pfn + vma->vm_pgoff, + vma->vm_end - vma->vm_start, + vma->vm_page_prot); +} + +EXPORT_SYMBOL (dma_mmap_coherent); +/* * Map a single buffer of the indicated size for DMA in streaming mode. * The 32-bit bus address to use is returned.
arch/mips/mm/dma-coherent.c +18 -0
@@ -59,6 +59,24 @@ void dma_free_coherent(struct device *deEXPORT_SYMBOL (dma_free_coherent); +int dma_mmap_noncoherent (struct device *dev,struct vm_area_struct *vma, +void *cpu_addr,dma_addr_t handle,size_t size) +{ +unsigned long pfn =page_to_pfn (virt_to_page (cpu_addr)); +return remap_pfn_range (vma, vma->vm_start, + pfn + vma->vm_pgoff, + vma->vm_end - vma->vm_start, + vma->vm_page_prot); +} + +EXPORT_SYMBOL (dma_mmap_noncoherent); + +int dma_mmap_coherent (struct device *dev,struct vm_area_struct *vma, +void *cpu_addr,dma_addr_t handle,size_t size) + __attribute__((alias ("dma_mmap_noncoherent" ))); + +EXPORT_SYMBOL (dma_mmap_coherent); +dma_addr_t dma_map_single (struct device *dev,void *ptr,size_t size,enum dma_data_direction direction) {
arch/mips/mm/dma-ip27.c +21 -0
@@ -64,6 +64,27 @@ void dma_free_coherent(struct device *deEXPORT_SYMBOL (dma_free_coherent); +int dma_mmap_noncoherent (struct device *dev,struct vm_area_struct *vma, +void *cpu_addr,dma_addr_t handle,size_t size) +{ +unsigned long pfn =page_to_pfn (virt_to_page (cpu_addr)); +return remap_pfn_range (vma, vma->vm_start, + pfn + vma->vm_pgoff, + vma->vm_end - vma->vm_start, + vma->vm_page_prot); +} + +EXPORT_SYMBOL (dma_mmap_noncoherent); + +int dma_mmap_coherent (struct device *dev,struct vm_area_struct *vma, +void *cpu_addr,dma_addr_t handle,size_t size) +{ + vma->vm_page_prot =pgprot_noncached (vma->vm_page_prot); +return dma_mmap_noncoherent (dev, vma, cpu_addr, handle, size); +} + +EXPORT_SYMBOL (dma_mmap_coherent); +dma_addr_t dma_map_single (struct device *dev,void *ptr,size_t size,enum dma_data_direction direction) {
arch/mips/mm/dma-ip32.c +23 -0
@@ -95,6 +95,29 @@ void dma_free_coherent(struct device *deEXPORT_SYMBOL (dma_free_coherent); +int dma_mmap_noncoherent (struct device *dev,struct vm_area_struct *vma, +void *cpu_addr,dma_addr_t handle,size_t size) +{ +unsigned long pfn =page_to_pfn (virt_to_page (cpu_addr)); +return remap_pfn_range (vma, vma->vm_start, + pfn + vma->vm_pgoff, + vma->vm_end - vma->vm_start, + vma->vm_page_prot); +} + +EXPORT_SYMBOL (dma_mmap_noncoherent); + +int dma_mmap_coherent (struct device *dev,struct vm_area_struct *vma, +void *cpu_addr,dma_addr_t handle,size_t size) +{ + vma->vm_page_prot =pgprot_noncached (vma->vm_page_prot); +return dma_mmap_noncoherent (dev, vma, + (void *)CAC_ADDR ((unsigned long )cpu_addr), + handle, size); +} + +EXPORT_SYMBOL (dma_mmap_coherent); +static inline void __dma_sync (unsigned long addr,size_t size,enum dma_data_direction direction) {
arch/mips/mm/dma-noncoherent.c +23 -0
@@ -79,6 +79,29 @@ void dma_free_coherent(struct device *deEXPORT_SYMBOL (dma_free_coherent); +int dma_mmap_noncoherent (struct device *dev,struct vm_area_struct *vma, +void *cpu_addr,dma_addr_t handle,size_t size) +{ +unsigned long pfn =page_to_pfn (virt_to_page (cpu_addr)); +return remap_pfn_range (vma, vma->vm_start, + pfn + vma->vm_pgoff, + vma->vm_end - vma->vm_start, + vma->vm_page_prot); +} + +EXPORT_SYMBOL (dma_mmap_noncoherent); + +int dma_mmap_coherent (struct device *dev,struct vm_area_struct *vma, +void *cpu_addr,dma_addr_t handle,size_t size) +{ + vma->vm_page_prot =pgprot_noncached (vma->vm_page_prot); +return dma_mmap_noncoherent (dev, vma, + (void *)CAC_ADDR ((unsigned long )cpu_addr), + handle, size); +} + +EXPORT_SYMBOL (dma_mmap_coherent); +static inline void __dma_sync (unsigned long addr,size_t size,enum dma_data_direction direction) {
arch/parisc/kernel/pci-dma.c +27 -0
@@ -396,6 +396,23 @@ static void pa11_dma_free_consistent (stfree_pages ((unsigned long )__va (dma_handle), order); } +static int pa11_mmap_noncoherent (struct device *dev,struct vm_area_struct *vma, +void *cpu_addr,dma_addr_t handle,size_t size) +{ +unsigned long pfn = (unsigned long )handle >>PAGE_SHIFT ; +return remap_pfn_range (vma, vma->vm_start, + pfn + vma->vm_pgoff, + vma->vm_end - vma->vm_start, + vma->vm_page_prot); +} + +static int pa11_mmap_coherent (struct device *dev,struct vm_area_struct *vma, +void *cpu_addr,dma_addr_t handle,size_t size) +{ + vma->vm_page_prot =pgprot_noncached (vma->vm_page_prot); +return pa11_mmap_noncoherent (dev, vma, cpu_addr, handle, size); +} +static dma_addr_t pa11_dma_map_single (struct device *dev,void *addr,size_t size,enum dma_data_direction direction) {if (direction ==DMA_NONE ) {
@@ -509,6 +526,8 @@ struct hppa_dma_ops pcxl_dma_ops = { .dma_sync_single_for_device = pa11_dma_sync_single_for_device, .dma_sync_sg_for_cpu = pa11_dma_sync_sg_for_cpu, .dma_sync_sg_for_device = pa11_dma_sync_sg_for_device, + .mmap_coherent = pa11_mmap_coherent, + .mmap_noncoherent = pa11_mmap_noncoherent, }; static void *fail_alloc_consistent(struct device *dev, size_t size,
@@ -537,6 +556,12 @@ static void pa11_dma_free_noncoherent(streturn ; } +static int fail_mmap_coherent (struct device *dev,struct vm_area_struct *vma, +void *cpu_addr,dma_addr_t handle,size_t size) +{ +return -ENXIO ; +} +struct hppa_dma_ops pcx_dma_ops = { .dma_supported = pa11_dma_supported, .alloc_consistent = fail_alloc_consistent,
@@ -550,6 +575,8 @@ struct hppa_dma_ops pcx_dma_ops = { .dma_sync_single_for_device = pa11_dma_sync_single_for_device, .dma_sync_sg_for_cpu = pa11_dma_sync_sg_for_cpu, .dma_sync_sg_for_device = pa11_dma_sync_sg_for_device, + .mmap_coherent = fail_mmap_coherent, + .mmap_noncoherent = fail_mmap_coherent, };
arch/sh/mm/consistent.c +10 -0
@@ -59,6 +59,15 @@ void consistent_free(void *vaddr, size_t } } +int consistent_mmap (struct vm_area_struct *vma,void *vaddr,size_t size) +{ + vaddr = (void *)P1SEGADDR ((unsigned long )vaddr); +return remap_pfn_range (vma, vma->vm_start, +page_to_pfn (virt_to_page (vaddr)) + vma->vm_pgoff, + vma->vm_end - vma->vm_start, + vma->vm_page_prot); +} +void consistent_sync (void *vaddr,size_t size,int direction) {void * p1addr = (void *)P1SEGADDR ((unsigned long )vaddr);
@@ -80,5 +89,6 @@ void consistent_sync(void *vaddr, size_tEXPORT_SYMBOL (consistent_alloc);EXPORT_SYMBOL (consistent_free); +EXPORT_SYMBOL (consistent_mmap);EXPORT_SYMBOL (consistent_sync);
arch/sparc/kernel/ioport.c +16 -0
@@ -508,6 +508,22 @@ void pci_free_consistent(struct pci_devfree_pages (pgp,get_order (n)); } +/* Mmap a consistent area allocated via pci_alloc_consistent */ +int pci_mmap_consistent (struct pci_dev *pdev,struct vm_area_struct *vma, +void *cpu_addr,dma_addr_t handle,size_t size) +{ +unsigned long pfn; + +/* calculate pfn from bus address */ + pfn = pfn_base + (((unsigned long )handle - phys_base) >>PAGE_SHIFT ); + +return remap_pfn_range (vma, vma->vm_start, + pfn + vma->vm_pgoff, + vma->vm_end - vma->vm_start, + vma->vm_page_prot); +} + +/* Map a single buffer of the indicated size for DMA in streaming mode. * The 32-bit bus address to use is returned. *
arch/sparc/kernel/sparc_ksyms.c +1 -0
@@ -198,6 +198,7 @@ EXPORT_SYMBOL(insl);EXPORT_SYMBOL (outsl);EXPORT_SYMBOL (pci_alloc_consistent);EXPORT_SYMBOL (pci_free_consistent); +EXPORT_SYMBOL (pci_mmap_consistent);EXPORT_SYMBOL (pci_map_single);EXPORT_SYMBOL (pci_unmap_single);EXPORT_SYMBOL (pci_dma_sync_single_for_cpu);
arch/sparc64/kernel/pci_iommu.c +12 -0
@@ -290,6 +290,18 @@ static void pci_4u_free_consistent(strucfree_pages ((unsigned long )cpu, order); } +/* Mmap a consistent area allocated via pci_alloc_consistent */ +int pci_mmap_consistent (struct pci_dev *pdev,struct vm_area_struct *vma, +void *cpu_addr,dma_addr_t handle,size_t size) +{ +unsigned long pfn =page_to_pfn (virt_to_page (cpu_addr)); + +return remap_pfn_range (vma, vma->vm_start, + pfn + vma->vm_pgoff, + vma->vm_end - vma->vm_start, + vma->vm_page_prot); +} +/* Map a single buffer at PTR of SZ bytes for PCI DMA * in streaming mode. */
arch/sparc64/kernel/sparc64_ksyms.c +1 -0
@@ -223,6 +223,7 @@ EXPORT_SYMBOL(isa_chain);EXPORT_SYMBOL (pci_memspace_mask);EXPORT_SYMBOL (pci_alloc_consistent);EXPORT_SYMBOL (pci_free_consistent); +EXPORT_SYMBOL (pci_mmap_consistent);EXPORT_SYMBOL (pci_map_single);EXPORT_SYMBOL (pci_unmap_single);EXPORT_SYMBOL (pci_map_sg);
arch/x86_64/kernel/pci-dma.c +16 -0
@@ -166,6 +166,22 @@ void dma_free_coherent(struct device *de }EXPORT_SYMBOL (dma_free_coherent); +int dma_mmap_coherent (struct device *dev,struct vm_area_struct *vma, +void *cpu_addr,dma_addr_t handle,size_t size) +{ +unsigned long pfn; + +if (dma_ops->mmap_coherent) +return dma_ops->mmap_coherent (dev, vma, cpu_addr, handle, size); + + pfn =page_to_pfn (virt_to_page (cpu_addr)); +return remap_pfn_range (vma, vma->vm_start, + pfn + vma->vm_pgoff, + vma->vm_end - vma->vm_start, + vma->vm_page_prot); +} +EXPORT_SYMBOL (dma_mmap_coherent); +int dma_supported (struct device *dev,u64 mask) {if (dma_ops->dma_supported)
include/asm-alpha/dma-mapping.h +12 -0
@@ -50,8 +50,20 @@ #define dma_mapping_error(addr) (0)#endif /* !CONFIG_PCI */ +static inline int +dma_mmap_coherent (struct device *dev,struct vm_area_struct *vma, +void *cpu_addr,dma_addr_t handle,size_t size) +{ +unsigned long pfn =page_to_pfn (virt_to_page (cpu_addr)); +return remap_pfn_range (vma, vma->vm_start, + pfn + vma->vm_pgoff, + vma->vm_end - vma->vm_start, + vma->vm_page_prot); +} +#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) +#define dma_mmap_noncoherent (d, v, a, h, s) dma_mmap_coherent(d, v, a, h, s)#define dma_is_consistent (dev) (1)int dma_set_mask (struct device *dev,u64 mask);
include/asm-cris/dma-mapping.h +22 -0
@@ -12,6 +12,7 @@ #include <asm/scatterlist.h>#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) +#define dma_mmap_noncoherent (d, v, a, h, s) dma_mmap_coherent(d, v, a, h, s)#ifdef CONFIG_PCI void *dma_alloc_coherent(struct device *dev, size_t size,
@@ -19,6 +20,18 @@ void *dma_alloc_coherent(struct device *void dma_free_coherent (struct device *dev,size_t size,void *vaddr,dma_addr_t dma_handle); + +static inline int +dma_mmap_coherent (struct device *dev,struct vm_area_struct *vma, +void *cpu_addr,dma_addr_t handle,size_t size) +{ +unsigned long pfn =page_to_pfn (virt_to_page (cpu_addr)); +return remap_pfn_range (vma, vma->vm_start, + pfn + vma->vm_pgoff, + vma->vm_end - vma->vm_start, + vma->vm_page_prot); +} +#else static inline void * dma_alloc_coherent(struct device *dev, size_t size, dma_addr_t *dma_handle,
@@ -34,6 +47,15 @@ dma_free_coherent(struct device *dev, si {BUG (); } + +static inline int +dma_mmap_coherent (struct device *dev,struct vm_area_struct *vma, +void *cpu_addr,dma_addr_t handle,size_t size) +{ +BUG (); +return -ENXIO ; +} +#endif static inline dma_addr_t dma_map_single(struct device *dev, void *ptr, size_t size,
include/asm-frv/dma-mapping.h +4 -0
@@ -9,12 +9,16 @@ #include <asm/io.h>#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) +#define dma_mmap_noncoherent (d, v, a, h, s) dma_mmap_coherent(d, v, a, h, s)extern unsigned long __nongprelbss dma_coherent_mem_start;extern unsigned long __nongprelbss dma_coherent_mem_end;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); +int dma_mmap_coherent (struct device *dev,struct vm_area_struct *vma, +void *cpu_addr,dma_addr_t handle,size_t size); +/* * These macros should be used after a pci_map_sg call has been done
include/asm-generic/dma-mapping-broken.h +8 -0
@@ -19,4 +19,12 @@ dma_free_coherent(struct device *dev, si BUG(); } +static inline int +dma_mmap_coherent (struct device *dev,struct vm_area_struct *vma, +void *cpu_addr,dma_addr_t handle,size_t size) +{ +BUG (); +return -ENXIO ; +} +#endif /* _ASM_GENERIC_DMA_MAPPING_H */
include/asm-generic/dma-mapping.h +22 -0
@@ -37,9 +37,13 @@ static inline void * dma_alloc_coherent(struct device *dev, size_t size, dma_addr_t *dma_handle, gfp_t flag) { +#ifdef CONFIG_MMU BUG_ON(dev->bus != &pci_bus_type);return pci_alloc_consistent (to_pci_dev (dev), size, dma_handle); +#else +return -ENXIO ; +#endif } static inline void
@@ -51,6 +55,15 @@ dma_free_coherent(struct device *dev, sipci_free_consistent (to_pci_dev (dev), size, cpu_addr, dma_handle); } +static inline int +dma_mmap_coherent (struct device *dev,struct vm_area_struct *vma, +void *cpu_addr,dma_addr_t handle,size_t size) +{ +BUG_ON (dev->bus != &pci_bus_type); + +return pci_mmap_consistent (to_pci_dev (dev), vma, cpu_addr, handle, size); +} +static inline dma_addr_t dma_map_single (struct device *dev,void *cpu_addr,size_t size,enum dma_data_direction direction)
@@ -181,6 +194,14 @@ dma_free_coherent(struct device *dev, siBUG (); } +static inline int +dma_mmap_coherent (struct device *dev,struct vm_area_struct *vma, +void *cpu_addr,dma_addr_t handle,size_t size) +{ +BUG (); +return -ENXIO ; +} +static inline dma_addr_t dma_map_single (struct device *dev,void *cpu_addr,size_t size,enum dma_data_direction direction)
@@ -267,6 +288,7 @@ #endif#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) +#define dma_mmap_noncoherent (d, v, a, h, s) dma_mmap_coherent(d, v, a, h, s)#define dma_is_consistent (d) (1) static inline int
include/asm-i386/dma-mapping.h +12 -0
@@ -10,6 +10,7 @@ #include <asm/bug.h>#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) +#define dma_mmap_noncoherent (d, v, a, h, s) dma_mmap_coherent(d, v, a, h, s)void *dma_alloc_coherent (struct device *dev,size_t size,dma_addr_t *dma_handle,gfp_t flag);
@@ -17,6 +18,17 @@ void *dma_alloc_coherent(struct device *void dma_free_coherent (struct device *dev,size_t size,void *vaddr,dma_addr_t dma_handle); +static inline int +dma_mmap_coherent (struct device *dev,struct vm_area_struct *vma, +void *cpu_addr,dma_addr_t handle,size_t size) +{ +unsigned long pfn =page_to_pfn (virt_to_page (cpu_addr)); +return remap_pfn_range (vma, vma->vm_start, + pfn + vma->vm_pgoff, + vma->vm_end - vma->vm_start, + vma->vm_page_prot); +} +static inline dma_addr_t dma_map_single (struct device *dev,void *ptr,size_t size,enum dma_data_direction direction)
include/asm-ia64/dma-mapping.h +14 -0
@@ -12,6 +12,20 @@ #define dma_alloc_coherent platform_dma_#define dma_alloc_noncoherent platform_dma_alloc_coherent/* coherent mem. is cheap */ #define dma_free_coherent platform_dma_free_coherent#define dma_free_noncoherent platform_dma_free_coherent + +static inline int +dma_mmap_coherent (struct device *dev,struct vm_area_struct *vma, +void *cpu_addr,dma_addr_t handle,size_t size) +{ +unsigned long pfn =page_to_pfn (virt_to_page (cpu_addr)); +return remap_pfn_range (vma, vma->vm_start, + pfn + vma->vm_pgoff, + vma->vm_end - vma->vm_start, + vma->vm_page_prot); +} + +#define dma_mmap_noncoherent dma_mmap_coherent +#define dma_map_single platform_dma_map_single#define dma_map_sg platform_dma_map_sg#define dma_unmap_single platform_dma_unmap_single
include/asm-m32r/dma-mapping.h +1 -23
@@ -1,23 +1 @@ -#ifndef _ASM_M32R_DMA_MAPPING_H -#define _ASM_M32R_DMA_MAPPING_H - -/* -* NOTE: Do not include <asm-generic/dma-mapping.h> -* Because it requires PCI stuffs, but current M32R don't provide these. -*/ - -static inline void * -dma_alloc_coherent (struct device *dev,size_t size,dma_addr_t *dma_handle, -gfp_t flag) -{ -return (void *)NULL ; -} - -static inline void -dma_free_coherent (struct device *dev,size_t size,void *cpu_addr, -dma_addr_t dma_handle) -{ -return ; -} - -#endif /* _ASM_M32R_DMA_MAPPING_H */ +#include <asm-generic/dma-mapping-broken.h>
include/asm-mips/dma-mapping.h +6 -0
@@ -16,6 +16,12 @@ void *dma_alloc_coherent(struct device *void dma_free_coherent (struct device *dev,size_t size,void *vaddr,dma_addr_t dma_handle); +int dma_mmap_noncoherent (struct device *dev,struct vm_area_struct *vma, +void *cpu_addr,dma_addr_t handle,size_t size); + +int dma_mmap_coherent (struct device *dev,struct vm_area_struct *vma, +void *cpu_addr,dma_addr_t handle,size_t size); +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,
include/asm-parisc/dma-mapping.h +18 -0
@@ -20,6 +20,10 @@ struct hppa_dma_ops {void (*dma_sync_single_for_device)(struct device *dev,dma_addr_t iova,unsigned long offset,size_t size,enum dma_data_direction direction);void (*dma_sync_sg_for_cpu)(struct device *dev,struct scatterlist *sg,int nelems,enum dma_data_direction direction);void (*dma_sync_sg_for_device)(struct device *dev,struct scatterlist *sg,int nelems,enum dma_data_direction direction); +int (*mmap_coherent)(struct device *dev,struct vm_area_struct *vma, +void *cpu_addr,dma_addr_t handle,size_t size); +int (*mmap_noncoherent)(struct device *dev,struct vm_area_struct *vma, +void *cpu_addr,dma_addr_t handle,size_t size); };/*
@@ -75,6 +79,20 @@ dma_free_noncoherent(struct device *dev, hppa_dma_ops->free_consistent (dev, size, vaddr, dma_handle); } +static inline int +dma_mmap_coherent (struct device *dev,struct vm_area_struct *vma, +void *cpu_addr,dma_addr_t handle,size_t size) +{ + hppa_dma_ops->mmap_coherent (dev, vma, cpu_addr, handle, size); +} + +static inline int +dma_mmap_noncoherent (struct device *dev,struct vm_area_struct *vma, +void *cpu_addr,dma_addr_t handle,size_t size) +{ + hppa_dma_ops->mmap_noncoherent (dev, vma, cpu_addr, handle, size); +} +static inline dma_addr_t dma_map_single (struct device *dev,void *ptr,size_t size,enum dma_data_direction direction)
include/asm-powerpc/dma-mapping.h +12 -0
@@ -167,6 +167,17 @@ #define dma_unmap_sg(dev, sg, nents, dir#endif /* CONFIG_PPC64 */ +static inline int +dma_mmap_coherent (struct device *dev,struct vm_area_struct *vma, +void *cpu_addr,dma_addr_t handle,size_t size) +{ +unsigned long pfn =page_to_pfn (virt_to_page (cpu_addr)); +return remap_pfn_range (vma, vma->vm_start, + pfn + vma->vm_pgoff, + vma->vm_end - vma->vm_start, + vma->vm_page_prot); +} +static inline void dma_sync_single_for_cpu (struct device *dev,dma_addr_t dma_handle,size_t size,enum dma_data_direction direction)
@@ -218,6 +229,7 @@ #endif#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) +#define dma_mmap_noncoherent (d, v, a, h, s) dma_mmap_coherent(d, v, a, h, s)#ifdef CONFIG_NOT_COHERENT_CACHE #define dma_is_consistent (d) (0)#else
include/asm-sh/dma-mapping.h +11 -0
@@ -12,6 +12,7 @@ extern struct bus_type pci_bus_type;/* arch/sh/mm/consistent.c */ extern void *consistent_alloc (gfp_t gfp,size_t size,dma_addr_t *handle);extern void consistent_free (void *vaddr,size_t size); +extern int consistent_mmap (struct vm_area_struct *vma,void *vaddr,size_t size);extern void consistent_sync (void *vaddr,size_t size,int direction);#define dma_supported (dev, mask) (1)
@@ -54,6 +55,16 @@ static inline void dma_free_coherent(strconsistent_free (vaddr, size); } +static inline int +dma_mmap_coherent (struct device *dev,struct vm_area_struct *vma, +void *cpu_addr,dma_addr_t handle,size_t size) +{ +if (sh_mv.mv_consistent_alloc) +return -ENXIO ; +else +return consistent_mmap (vma, cpu_addr, size); +} +static inline void dma_cache_sync (void *vaddr,size_t size,enum dma_data_direction dir) {
include/asm-sh64/dma-mapping.h +17 -0
@@ -11,6 +11,8 @@ extern void *consistent_alloc(struct pci dma_addr_t *dma_handle);extern void consistent_free (struct pci_dev *hwdev,size_t size,void *vaddr,dma_addr_t dma_handle); +extern int consistent_mmap (struct vm_area_struct *vma,void *vaddr, +dma_addr_t handle,size_t size);#define dma_supported (dev, mask) (1)
@@ -36,6 +38,21 @@ static inline void dma_free_coherent(strconsistent_free (NULL , size, vaddr, dma_handle); } +static inline int +dma_mmap_coherent (struct device *dev,struct vm_area_struct *vma, +void *cpu_addr,dma_addr_t handle,size_t size) +{ +unsigned long pfn; + +/* dma_handle is equivalent with phys addr */ + pfn = (unsigned long )handle >>PAGE_SHIFT ; +return remap_pfn_range (vma, vma->vm_start, + pfn + vma->vm_pgoff, + vma->vm_end - vma->vm_start, + vma->vm_page_prot); + +} +static inline void dma_cache_sync (void *vaddr,size_t size,enum dma_data_direction dir) {
include/asm-sparc/dma-mapping.h +1 -14
@@ -6,20 +6,7 @@ #include <linux/config.h>#ifdef CONFIG_PCI #include <asm-generic/dma-mapping.h> #else - -static inline void *dma_alloc_coherent (struct device *dev,size_t size, -dma_addr_t *dma_handle,gfp_t flag) -{ -BUG (); -return NULL ; -} - -static inline void dma_free_coherent (struct device *dev,size_t size, -void *vaddr,dma_addr_t dma_handle) -{ -BUG (); -} - +#include <asm-generic/dma-mapping-broken.h> #endif /* PCI */ #endif /* _ASM_SPARC_DMA_MAPPING_H */
include/asm-sparc64/dma-mapping.h +1 -16
@@ -145,22 +145,7 @@ dma_mapping_error(dma_addr_t dma_addr) }#else - -struct device ; - -static inline void *dma_alloc_coherent (struct device *dev,size_t size, -dma_addr_t *dma_handle,gfp_t flag) -{ -BUG (); -return NULL ; -} - -static inline void dma_free_coherent (struct device *dev,size_t size, -void *vaddr,dma_addr_t dma_handle) -{ -BUG (); -} - +#include <asm-generic/dma-mapping-broken.h> #endif /* PCI */ #endif /* _ASM_SPARC64_DMA_MAPPING_H */
include/asm-x86_64/dma-mapping.h +7 -0
@@ -49,6 +49,10 @@ struct dma_mapping_ops { struct scatterlist *sg, int nents, int direction);int (*dma_supported)(struct device *hwdev,u64 mask); +int (*mmap_coherent)(struct device *hwdev, +struct vm_area_struct *vma, +void *cpu_addr,dma_addr_t handle, +size_t size);int is_phys; };
@@ -69,6 +73,9 @@ extern void *dma_alloc_coherent(struct dextern void dma_free_coherent (struct device *dev,size_t size,void *vaddr,dma_addr_t dma_handle); +extern int dma_mmap_coherent (struct device *dev,struct vm_area_struct *vma, +void *cpu_addr,dma_addr_t handle,size_t size); +static inline dma_addr_t dma_map_single (struct device *hwdev,void *ptr,size_t size,int direction)
include/asm-xtensa/dma-mapping.h +11 -0
@@ -33,6 +33,17 @@ void *dma_alloc_coherent(struct device *void dma_free_coherent (struct device *dev,size_t size,void *vaddr,dma_addr_t dma_handle); +static inline int +dma_mmap_coherent (struct device *dev,struct vm_area_struct *vma, +void *cpu_addr,dma_addr_t handle,size_t size) +{ +struct page *page =virt_to_page (bus_to_virt (handle)); +return remap_pfn_range (vma, vma->vm_start, +page_to_pfn (page) + vma->vm_pgoff, + vma->vm_end - vma->vm_start, + vma->vm_page_prot); +} +static inline dma_addr_t dma_map_single (struct device *dev,void *ptr,size_t size,enum dma_data_direction direction)
Quoted 8 lines
-------- Original-Nachricht --------
Datum: Mon, 12 Jun 2006 12:51:16 +0200
Von: Takashi Iwai <[email protected]>
An: Gerhard Pircher <[email protected]>
Betreff: Re: RFC:dma_mmap_coherent()for powerpc/ppc architecture and ALSA?
Quoted 8 lines
Quoted 3 lines
Well, implementing the
dma_mmap_coherent()function isn't the problem, because it is already implemented for the ARM architecture.Actually, I wrote
dma_coherent_mmappatch long time ago but it has been left forgotten. The patch attached below seems applicable to 2.6.17 tree, but I'm not sure whether it still works properly. It's untested on most of architectures.
Thanks, that helps me a lot!
Quoted 7 lines
Quoted 3 lines
But as far as I understand this would require a rewrite of all the ALSA drivers (or at least a rewrite of the ALSA's DMA helper functions).
Yes. The change of ALSA side has been also on my tree. But it was still pending since I'm not satisfied with the design yet. If you're interested in it, let me know. I'll post the patch.
Yes, please! Then I can test, if the dma_mmap_coherent() patch works on
my non cache coherent powerpc machine. Do you think the DMA Layer/ALSA patches will go upstream in one of the next ALSA/Linux kernel versions?
Thanks!
Gerhard
Signature · 2 lines
Der GMX SmartSurfer hilft bis zu 70% Ihrer Onlinekosten zu sparen! Ideal für Modem und ISDN: http://www.gmx.net/de/go/smartsurfer
At Mon, 12 Jun 2006 16:42:54 +0200,
Quoted 11 lines · Gerhard Pircher
Quoted 8 lines
Quoted 4 lines
But as far as I understand this would require a rewrite of all the ALSA drivers (or at least a rewrite of the ALSA's DMA helper functions).
Yes. The change of ALSA side has been also on my tree. But it was still pending since I'm not satisfied with the design yet. If you're interested in it, let me know. I'll post the patch.
Yes, please! Then I can test, if the
dma_mmap_coherent()patch works on my non cache coherent powerpc machine.
For using dma_mmap_coherent(), the patch below should suffice. (Also you need to enable HAVE_DMA_MMAP_COHERENT there not only for
ARM.)
Quoted 2 lines
Do you think the DMA Layer/ALSA patches will go upstream in one of the next ALSA/Linux kernel versions?
Definitely no 2.6.18 material yet.
Takashi
sound/core/pcm_native.c +22 -0
@@ -3123,6 +3123,10 @@ static int snd_pcm_mmap_control(struct s }#endif /* coherent mmap */ +#if defined(CONFIG_ARM ) +#define HAVE_DMA_MMAP_COHERENT +#endif +/* * nopage callback for mmapping a RAM page */
@@ -3166,6 +3170,14 @@ static struct vm_operations_struct snd_p .nopage = snd_pcm_mmap_data_nopage, }; +#ifdef HAVE_DMA_MMAP_COHERENT +static struct vm_operations_struct snd_pcm_vm_ops_data_one_map = +{ + .open = snd_pcm_mmap_data_open, + .close = snd_pcm_mmap_data_close, +}; +#endif +/* * mmap the DMA buffer on RAM */
@@ -3175,6 +3187,16 @@ static int snd_pcm_default_mmap(struct s area->vm_ops = &snd_pcm_vm_ops_data; area->vm_private_data = substream; area->vm_flags |=VM_RESERVED ; +#ifdef HAVE_DMA_MMAP_COHERENT +if (substream->dma_buffer.dev.type ==SNDRV_DMA_TYPE_DEV ) { + area->vm_ops = &snd_pcm_vm_ops_data_one_map; +if (dma_mmap_coherent (substream->dma_buffer.dev.dev, area, + substream->runtime->dma_area, + substream->runtime->dma_addr, + area->vm_end - area->vm_start)) +return -EAGAIN ; + } +#endif atomic_inc (&substream->mmap_count);return 0 ; }