dma-mapping-broken.h: flesh-out DMA API stubs
Subsystems (6)
PATCH 1/1 dma-mapping-broken.h: flesh-out DMA API stubs
This allows some drivers compile on arches that don't support DMA (e.g. s390).
---
Is there any reason why this header should not cover the whole DMA API?
Compile-tested only...
include/asm-generic/dma-mapping-broken.h | 134 ++++++++++++++++++++++++++++++ 1 files changed, 134 insertions(+), 0 deletions(-)
include/asm-generic/dma-mapping-broken.h +112 -0
@@ -21,4 +21,116 @@ dma_free_coherent(struct device *dev, size_t size, void *cpu_addr,#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) +static inline dma_addr_t +dma_map_single (struct device *dev,void *ptr,size_t size, +enum dma_data_direction direction) +{ +BUG (); +return (dma_addr_t )0 ; +} + +static inline void +dma_unmap_single (struct device *dev,dma_addr_t dma_addr,size_t size, +enum dma_data_direction direction) +{ +BUG (); +} + +static inline int +dma_map_sg (struct device *dev,struct scatterlist *sg,int nents, +enum dma_data_direction direction) +{ +BUG (); +return 0 ; +} + +static inline void +dma_unmap_sg (struct device *dev,struct scatterlist *sg,int nhwentries, +enum dma_data_direction direction) +{ +BUG (); +} + +static inline dma_addr_t +dma_map_page (struct device *dev,struct page *page,unsigned long offset, +size_t size,enum dma_data_direction direction) +{ +BUG (); +return (dma_addr_t )0 ; +} + +static inline void +dma_unmap_page (struct device *dev,dma_addr_t dma_address,size_t size, +enum dma_data_direction direction) +{ +BUG (); +} + +static inline void +dma_sync_single_for_cpu (struct device *dev,dma_addr_t dma_handle,size_t size, +enum dma_data_direction direction) +{ +BUG (); +} + +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) +{ +BUG (); +} + +static inline void +dma_sync_sg_for_cpu (struct device *dev,struct scatterlist *sg,int nelems, +enum dma_data_direction direction) +{ +BUG (); +} + +#define dma_sync_single_for_device dma_sync_single_for_cpu +#define dma_sync_single_range_for_device dma_sync_single_range_for_cpu +#define dma_sync_sg_for_device dma_sync_sg_for_cpu + +static inline int +dma_mapping_error (dma_addr_t dma_addr) +{ +BUG (); +return 1 ; +} + +static inline int +dma_supported (struct device *dev,u64 mask) +{ +return 0 ; +} + +static inline int +dma_set_mask (struct device *dev,u64 mask) +{ +BUG (); +return -EIO ; +} + +static inline int +dma_get_cache_alignment (void ) +{ +BUG (); +return 0 ; +} + +int +dma_is_consistent (struct device *dev,dma_addr_t dma_handle) +{ +BUG (); +return 0 ; +} + +static inline void +dma_cache_sync (struct device *dev,void *vaddr,size_t size, +enum dma_data_direction direction) +{ +BUG (); +} +#endif /* _ASM_GENERIC_DMA_MAPPING_H */
Signature · 1 line
1.4.4.2
Quoted 2 lines · John W. Linville
This allows some drivers compile on arches that don't support DMA (e.g. s390).
Which drivers are we talking about? Last time I checked an allmodconfig just compiled.
I'd rather like to the opposite: rip out everything that depends on DMA (via e.g. CONFIG_HAS_DMA), so we don't have to compile in all the unused code. If that is is possible...
Signature · 8 lines
Heiko Carstens Linux on System z Development IBM Deutschland Entwicklung GmbH Vorsitzender des Aufsichtsrats: Johann Weihen Geschaeftsfuehrung : Herbert Kircher Sitz der Gesellschaft: Boeblingen Registergericht: Amtsgericht Stuttgart, HRB 243294
How about this for telling that an architecture doesn't support DMA? At least we could get rid of dma-mapping-broken.h and don't need to compile some afterwards dead code.
--- arch/s390/Kconfig | 3 +++ drivers/base/Makefile | 4 ++-- include/asm-s390/dma-mapping.h | 2 -- lib/Kconfig | 5 +++++ 4 files changed, 10 insertions(+), 4 deletions(-)
arch/s390/Kconfig +3 -0
@@ -44,6 +44,9 @@ config GENERIC_TIME config NO_IOMEM def_bool y +config NO_DMA + def_bool y + mainmenu "Linux Kernel Configuration" config S390
drivers/base/Makefile +2 -2
@@ -2,10 +2,10 @@ obj-y := core.o sys.o bus.o dd.o \ driver.o class.o platform.o \ - cpu.o firmware.o init.o map.o dmapool.o \ - dma-mapping.o devres.o \ + cpu.o firmware.o init.o map.o devres.o \ attribute_container.o transport_class.o obj-y += power/ +obj-$(CONFIG_DMA) += dma-mapping.o dmapool.o obj-$(CONFIG_ISA) += isa.o obj-$(CONFIG_FW_LOADER) += firmware_class.o obj-$(CONFIG_NUMA) += node.o
include/asm-s390/dma-mapping.h +0 -2
@@ -9,6 +9,4 @@#ifndef _ASM_DMA_MAPPING_H#define _ASM_DMA_MAPPING_H -#include <asm-generic/dma-mapping-broken.h> -#endif /* _ASM_DMA_MAPPING_H */
lib/Kconfig +5 -0
@@ -111,4 +111,9 @@ config HAS_IOPORT depends on HAS_IOMEM && !NO_IOPORT default y +config HAS_DMA + boolean + depends on !NO_DMA + default y + endmenu
Signature · 8 lines
Heiko Carstens Linux on System z Development IBM Deutschland Entwicklung GmbH Vorsitzender des Aufsichtsrats: Johann Weihen Geschaeftsfuehrung : Herbert Kircher Sitz der Gesellschaft: Boeblingen Registergericht: Amtsgericht Stuttgart, HRB 243294
Quoted 31 lines · Heiko Carstens
How about this for telling that an architecture doesn't support DMA? At least we could get rid of
dma-mapping-broken.hand don't need to compile some afterwards dead code.Signed-off-by Heiko Carstens <[email protected]>--- arch/s390/Kconfig | 3 +++ drivers/base/Makefile | 4 ++-- include/asm-s390/dma-mapping.h | 2 -- lib/Kconfig | 5 +++++ 4 files changed, 10 insertions(+), 4 deletions(-)Index: linux-2.6/arch/s390/Kconfig
===================================================================arch/s390/Kconfig +3
-0@@ -44,6 +44,9 @@ config GENERIC_TIME config NO_IOMEM def_bool y +config NO_DMA + def_bool y + mainmenu "Linux Kernel Configuration" config S390Index: linux-2.6/drivers/base/Makefile
===================================================================
drivers/base/Makefile line 8
Quoted 9 lines
drivers/base/Makefile +2
-2@@ -2,10 +2,10 @@ obj-y := core.o sys.o bus.o dd.o \ driver.o class.o platform.o \ - cpu.o firmware.o init.o map.o dmapool.o \ - dma-mapping.o devres.o \ + cpu.o firmware.o init.o map.o devres.o \ attribute_container.o transport_class.o obj-y += power/ +obj-$(CONFIG_DMA) += dma-mapping.o dmapool.o
This should have been CONFIG_HAS_DMA. Anyway I'm going to resend this one if nobody objects.
Quoted 28 lines
drivers/base/Makefile +0
-0obj-$(CONFIG_ISA) += isa.o obj-$(CONFIG_FW_LOADER) += firmware_class.o obj-$(CONFIG_NUMA) += node.oIndex:
linux-2.6/include/asm-s390/dma-mapping.h
===================================================================include/asm-s390/dma-mapping.h +0
-2@@ -9,6 +9,4 @@#ifndef _ASM_DMA_MAPPING_H#define _ASM_DMA_MAPPING_H -#include <asm-generic/dma-mapping-broken.h> -#endif /* _ASM_DMA_MAPPING_H */ Index: linux-2.6/lib/Kconfig
===================================================================lib/Kconfig +5
-0@@ -111,4 +111,9 @@ config HAS_IOPORT depends on HAS_IOMEM && !NO_IOPORT default y +config HAS_DMA + boolean + depends on !NO_DMA + default y + endmenu
Signature · 8 lines
Heiko Carstens Linux on System z Development IBM Deutschland Entwicklung GmbH Vorsitzender des Aufsichtsrats: Johann Weihen Geschaeftsfuehrung : Herbert Kircher Sitz der Gesellschaft: Boeblingen Registergericht: Amtsgericht Stuttgart, HRB 243294
Quoted 5 lines · Heiko Carstens
How about this for telling that an architecture doesn't support DMA? At least we could get rid of
dma-mapping-broken.hand don't need to compile some afterwards dead code.Signed-off-by Heiko Carstens <[email protected]>
This like a lot better of an idea than stubbing out things which should never be built in the first place...
Cheers,
Kyle
Quoted 9 lines · Kyle McMartin
Quoted 5 lines · Heiko Carstens
How about this for telling that an architecture doesn't support DMA? At least we could get rid of
dma-mapping-broken.hand don't need to compile some afterwards dead code.Signed-off-by Heiko Carstens <[email protected]>This like a lot better of an idea than stubbing out things which should never be built in the first place...
My only thought was that the intent must have been to allow compilation of a driver that checks for DMA at runtime (via dma_supported). But, I guess dma_supported is intended as a platform-level check?
If the DMA availability is at the arch level then such a driver could use (albeit ugly) compile flags to cover that situation...?
Well, either way is fine with me.
John
Signature · 2 lines
John W. Linville [email protected]
PATCH 1/1 Introduce CONFIG_HAS_DMA.
From: Heiko Carstens <[email protected]>
Architectures that don't support DMA can say so by adding a config NO_DMA to their Kconfig file. This will prevent compilation of some dma specific driver code. Also dma-mapping-broken.h isn't needed anymore on at least s390.
This avoids compilation and linking of otherwise dead/broken code.
---
Other architectures that include dma-mapping-broken.h are arm26, h8300, m68k, m68knommu and v850. If these could be converted as well we could get rid of the header file.
arch/s390/Kconfig | 3 +++ drivers/base/Makefile | 4 ++-- include/asm-s390/dma-mapping.h | 2 -- lib/Kconfig | 5 +++++ 4 files changed, 10 insertions(+), 4 deletions(-)
arch/s390/Kconfig +3 -0
@@ -44,6 +44,9 @@ config GENERIC_TIME config NO_IOMEM def_bool y +config NO_DMA + def_bool y + mainmenu "Linux Kernel Configuration" config S390
drivers/base/Makefile +2 -2
@@ -2,10 +2,10 @@ obj-y := core.o sys.o bus.o dd.o \ driver.o class.o platform.o \ - cpu.o firmware.o init.o map.o dmapool.o \ - dma-mapping.o devres.o \ + cpu.o firmware.o init.o map.o devres.o \ attribute_container.o transport_class.o obj-y += power/ +obj-$(CONFIG_HAS_DMA) += dma-mapping.o dmapool.o obj-$(CONFIG_ISA) += isa.o obj-$(CONFIG_FW_LOADER) += firmware_class.o obj-$(CONFIG_NUMA) += node.o
include/asm-s390/dma-mapping.h +0 -2
@@ -9,6 +9,4 @@#ifndef _ASM_DMA_MAPPING_H#define _ASM_DMA_MAPPING_H -#include <asm-generic/dma-mapping-broken.h> -#endif /* _ASM_DMA_MAPPING_H */
lib/Kconfig +5 -0
@@ -111,4 +111,9 @@ config HAS_IOPORT depends on HAS_IOMEM && !NO_IOPORT default y +config HAS_DMA + boolean + depends on !NO_DMA + default y + endmenu
Signature · 8 lines
Heiko Carstens Linux on System z Development IBM Deutschland Entwicklung GmbH Vorsitzender des Aufsichtsrats: Johann Weihen Geschaeftsfuehrung : Herbert Kircher Sitz der Gesellschaft: Boeblingen Registergericht: Amtsgericht Stuttgart, HRB 243294
Re: [patch] Introduce CONFIG_HAS_DMA.
[ apologies for reviving an old conversation ]
Quoted 8 lines · Heiko Carstens
From: Heiko Carstens <[email protected]>
Architectures that don't support DMA can say so by adding a config
NO_DMAto theirKconfigfile. This will prevent compilation of some dma specific driver code. Alsodma-mapping-broken.hisn't needed anymore on at least s390.
This avoids compilation and linking of otherwise dead/broken code.
I went back and read the thread leading up to this patch and I am of the opinion that John's approach (adding more stubs to dma-mapping-broken.h:
http://marc.info/?l=linux-kernel&m=117219377712232&w=2) is needed in _addition_ to this Kconfig option. In my particular case I have an API with a DMA and a non-DMA path written in such a way that the DMA path can be compiled away. Without dma-mapping-broken.h support the API is unnecessarily forced to violate point 2 of Documentation/SubmittingPatches (#ifdefs are ugly).
In other words let CONFIG_HAS_DMA prevent pure DMA code from being built, but do not preclude "clever" implementations from calling broken code.
If there are no objections I plan to resubmit John's changes with the addition below, which allows CONFIG_HAS_DMA=n architectures to delete their respective dma-mapping.h file.
include/linux/dma-mapping.h +0 -0
@@ -31,7 +31,11 @@ static inline int valid_dma_direction(int dma_direction) (dma_direction == DMA_FROM_DEVICE));
}
+#ifdef CONFIG_HAS_DMA
#include <asm/dma-mapping.h>
+#else
+#include <asm-generic/dma-mapping-broken.h>
+#endif
/* Backwards compat, remove in 2.7.x */
#define dma_sync_single dma_sync_single_for_cpu
Re: [patch] Introduce CONFIG_HAS_DMA.
Quoted 9 lines · Dan Williams
I went back and read the thread leading up to this patch and I am of the opinion that John's approach (adding more stubs to
dma-mapping-broken.h:
http://marc.info/?l=linux-kernel&m=117219377712232&w=2) is needed in _addition_ to thisKconfigoption. In my particular case I have an API with a DMA and a non-DMA path written in such a way that the DMA path can be compiled away. Withoutdma-mapping-broken.hsupport the API is unnecessarily forced to violate point 2 ofDocumentation/SubmittingPatches(#ifdefs are ugly).
IMO, well-placed #ifdefs are preferrable to dragging non-working code around. Like:
- put the DMA path in a file only build for MY_STUFF_USE_DMA
- let MY_STUFF select MY_STUFF_USE_DMA if HAS_DMA
- have a header file that points to the implementation for MY_STUFF_USE_DMA and uses well defined stubs for !MY_STUFF_USE_DMA, like returning ICannotDoThat for check_if_can_do() (kind of like what include/linux/sysfs.h does, for example)
This contains the #ifdefs in a header, doesn't compile stuff that won't work anyway on !HAS_DMA, and adds the ability to disable MY_STUFF_USE_DMA even if HAS_DMA at a later time if someone wants it.
Quoted 3 lines
In other words let
CONFIG_HAS_DMAprevent pure DMA code from being built, but do not preclude "clever" implementations from calling broken code.
If it calls broken code, it may not be so "clever" after all :)
What I don't like about this is
- compiles stuff that is not needed on !HAS_DMA
- worse, compiles stuff that will not work on !HAS_DMA
- does not encourage to split code properly into a DMA and a non-DMA part
RE: [patch] Introduce CONFIG_HAS_DMA.
[ please let me know if you want to be dropped from the cc ]
Quoted 9 lines
From: Cornelia Huck [mailto:[email protected]]
IMO, well-placed #ifdefs are preferrable to dragging non-working code around. Like:- put the DMA path in a file only build for
MY_STUFF_USE_DMA
- letMY_STUFFselectMY_STUFF_USE_DMAifHAS_DMA
- have a header file that points to the implementation forMY_STUFF_USE_DMAand uses well defined stubs for !MY_STUFF_USE_DMA, like returning ICannotDoThat forcheck_if_can_do()(kind of like
what
Quoted 3 lines
include/linux/sysfs.hdoes, for example)This contains the #ifdefs in a header, doesn't compile stuff that
won't
Quoted 9 lines
work anyway on !HAS_DMA, and adds the ability to disable
MY_STUFF_USE_DMAeven ifHAS_DMAat a later time if someone wants it.Quoted 3 lines
In other words let
CONFIG_HAS_DMAprevent pure DMA code from being built, but do not preclude "clever" implementations from calling broken code.If it calls broken code, it may not be so "clever" after all :)
Yes, at run time, but not necessarily at compile time.
Quoted 6 lines
What I don't like about this is
- compiles stuff that is not needed on !HAS_DMA
- worse, compiles stuff that will not work on !HAS_DMA
- does not encourage to split code properly into a DMA and a non-DMA part
I came to the same conclusions as I started to implement the bug-stubs. The patch (to follow) attempts to satisfy all the concerns you outline as well as my observation that async_tx requires no factoring for the !HAS_DMA case.
With the patch non-dma-architectures that try to build code with true dependencies on the DMA api will fail to link i.e.:
CONFIG_DMA_ENGINE=y CONFIG_HAS_DMA=n ASYNC_MEMCPY=y
CC init/version.o LD init/built-in.o LD .tmp_vmlinux1
async_tx/built-in.o: In function `async_memcpy':
xor.c:(.text+0x770): undefined reference to dma_map_page' xor.c:(.text+0x798): undefined reference to dma_map_page' xor.c:(.text+0x968): undefined reference to `dma_map_page'
Now changing CONFIG_DMA_ENGINE to depend on HAS_DMA (which is more correct than saying !S390). Results in:CONFIG_DMA_ENGINE=n CONFIG_HAS_DMA=n ASYNC_MEMCPY=y
CC init/version.o LD init/built-in.o LD .tmp_vmlinux1 KSYM .tmp_kallsyms1.S AS .tmp_kallsyms1.o LD .tmp_vmlinux2 KSYM .tmp_kallsyms2.S AS .tmp_kallsyms2.o LD vmlinux
This also allows include/asm-s390/dma-mapping.h to be dropped.
Dan
PATCH 1/1 dma-mapping: prevent dma dependent code from linking on !HAS_DMA archs
Continuing the work started in 411f0f3edc141a582190d3605cadd1d993abb6df ...
This enables code with a dma path, that compiles away, to build without requiring additional code factoring. It also prevents code that calls dma_alloc_coherent and dma_free_coherent from linking whereas previously the code would hit a BUG() at run time. Finally, it allows archs that set !HAS_DMA to delete their asm/dma-mapping.h file.
---
arch/arm26/Kconfig | 3 + arch/h8300/Kconfig | 3 + arch/m32r/Kconfig | 3 + drivers/dma/Kconfig | 2 - include/asm-arm26/dma-mapping.h | 2 - include/asm-generic/dma-mapping-broken.h | 82 ++++++++++++++++++++++++++---- include/asm-h8300/dma-mapping.h | 1 include/asm-m32r/dma-mapping.h | 6 -- include/asm-s390/dma-mapping.h | 12 ---- include/linux/dma-mapping.h | 4 + 10 files changed, 84 insertions(+), 34 deletions(-)
arch/arm26/Kconfig +3 -0
@@ -17,6 +17,9 @@ config MMU bool default y +config NO_DMA + def_bool y + config ARCH_ACORN bool default y
arch/h8300/Kconfig +3 -0
@@ -68,6 +68,9 @@ config TIME_LOW_RES config NO_IOPORT def_bool y +config NO_DMA + def_bool y + config ISA bool default y
arch/m32r/Kconfig +3 -0
@@ -31,6 +31,9 @@ config GENERIC_IRQ_PROBE config NO_IOPORT def_bool y +config NO_DMA + def_bool y + source "init/Kconfig"
drivers/dma/Kconfig +1 -1
@@ -3,7 +3,7 @@ # menu "DMA Engine support" - depends on !S390 + depends on HAS_DMA config DMA_ENGINE bool "Support for DMA engines"
include/asm-arm26/dma-mapping.h deleted +0 -2
@@ -1,2 +0,0 @@ -#include <asm-generic/dma-mapping-broken.h> -
include/asm-generic/dma-mapping-broken.h +70 -12
94 lines not on this page · raw message
include/asm-h8300/dma-mapping.h deleted +0 -1
@@ -1 +0,0 @@ -#include <asm-generic/dma-mapping-broken.h>
include/asm-m32r/dma-mapping.h deleted +0 -6
@@ -1,6 +0,0 @@ -#ifndef _ASM_M32R_DMA_MAPPING_H -#define _ASM_M32R_DMA_MAPPING_H - -#include <asm-generic/dma-mapping-broken.h> - -#endif /* _ASM_M32R_DMA_MAPPING_H */
include/asm-s390/dma-mapping.h deleted +0 -12
@@ -1,12 +0,0 @@ -/* -* include/asm-s390/dma-mapping.h -* -* S390 version -* -* This file exists so that #include <dma-mapping.h> doesn't break anything. -*/ - -#ifndef _ASM_DMA_MAPPING_H -#define _ASM_DMA_MAPPING_H - -#endif /* _ASM_DMA_MAPPING_H */
include/linux/dma-mapping.h +4 -0
@@ -31,7 +31,11 @@ static inline int valid_dma_direction(int dma_direction) (dma_direction == DMA_FROM_DEVICE)); } +#ifdef CONFIG_HAS_DMA #include <asm/dma-mapping.h> +#else +#include <asm-generic/dma-mapping-broken.h> +#endif /* Backwards compat, remove in 2.7.x */ #define dma_sync_single dma_sync_single_for_cpu
Re: [patch] Introduce CONFIG_HAS_DMA.
In reply to Williams, Dan JQuoted 7 lines · Dan J
With the patch non-dma-architectures that try to build code with true dependencies on the DMA api will fail to link i.e.:
CONFIG_DMA_ENGINE=yCONFIG_HAS_DMA=nASYNC_MEMCPY=yCC init/version.o LD init/built-in.o LD .tmp_vmlinux1
Quoted 7 lines
async_tx/built-in.o: In function `async_memcpy':
xor.c:(.text+0x770): undefined reference todma_map_page' xor.c:(.text+0x798): undefined reference todma_map_page' xor.c:(.text+0x968): undefined reference to `dma_map_page'Now changing
CONFIG_DMA_ENGINEto depend onHAS_DMA(which is more correct than saying !S390).
Makes sense.
Quoted 12 lines
Results in:
CONFIG_DMA_ENGINE=nCONFIG_HAS_DMA=nASYNC_MEMCPY=yCC init/version.o LD init/built-in.o LD .tmp_vmlinux1 KSYM .tmp_kallsyms1.S AS .tmp_kallsyms1.o LD .tmp_vmlinux2 KSYM .tmp_kallsyms2.S AS .tmp_kallsyms2.o LD vmlinux
Quoted 1 line
This also allows
include/asm-s390/dma-mapping.hto be dropped.
Cool. Thanks for looking into that.