Allow compile-testing NO_DMA (core)
Subsystems (4)
v2 cover Allow compile-testing NO_DMA (core)
Hi all,
If NO_DMA=y, get_dma_ops() returns a reference to the non-existing symbol bad_dma_ops, thus causing a link failure if it is ever used.
The intention of this is twofold:
1. To catch users of the DMA API on systems that do no support the DMA mapping API,
2. To avoid building drivers that cannot work on such systems anyway.
However, the disadvantage is that we have to keep on adding dependencies on HAS_DMA all over the place.
Thanks to the COMPILE_TEST symbol, lots of drivers now depend on one or more platform dependencies (that imply HAS_DMA) || COMPILE_TEST, thus already covering intention #2. Having to add an explicit dependency on HAS_DMA here is cumbersome, and hinders compile-testing.
Hence I think the time is ripe to reconsider the link failure. This patch series:
- Changes get_dma_ops() to return NULL instead,
- Adds a few more dummies to enable compile-testing.
A follow-up patch series will:
- Remove dependencies on HAS_DMA for symbols that already have platform dependencies implying HAS_DMA.
Changes compared to v1:
- Add Reviewed-by, Acked-by,
- Group NO_DMA-stubs for the DMA pool API under a single #ifdef,
- Split the big Kconfig patch in per-subsystem patches, split-off in a follow-up series.
This series is against v4.16-rc5. It can also be found at
https://git.kernel.org/pub/scm/linux/kernel/git/geert/linux-m68k.git/log/?h=no-dma-compile-testing-v2
It has been compile-tested with allmodconfig and allyesconfig for m68k/sun3, and has received attention from the kbuild test robot.
Thanks!
Geert Uytterhoeven (5):
dma-mapping: Convert NO_DMA get_dma_ops() into a real dummy
dma-coherent: Add NO_DMA dummies for managed DMA API
usb: gadget: Add NO_DMA dummies for DMA mapping API
mm: Add NO_DMA dummies for DMA pool API
scsi: Add NO_DMA dummies for SCSI DMA mapping API
include/linux/dma-mapping.h | 19 ++++++++++++++----- include/linux/dmapool.h | 30 +++++++++++++++++++++++------- include/linux/usb/gadget.h | 12 ++++++++++++ include/scsi/scsi_cmnd.h | 5 +++++ 4 files changed, 54 insertions(+), 12 deletions(-)
Signature · 12 lines
2.7.4
Gr{oetje,eeting}s,
Geert
--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- [email protected]
In personal conversations with technical people, I call myself a hacker. But
when I'm talking to journalists I just say "programmer" or something like that.
-- Linus TorvaldsPATCH v2 1/5 dma-mapping: Convert NO_DMA get_dma_ops() into a real dummy
If NO_DMA=y, get_dma_ops() returns a reference to the non-existing symbol bad_dma_ops, thus causing a link failure if it is ever used.
Make get_dma_ops() return NULL instead, to avoid the link failure. This allows to improve compile-testing, and limits the need to keep on sprinkling dependencies on HAS_DMA all over the place.
---
v2:
- Add Reviewed-by, Acked-by,
- Drop RFC state.
--- include/linux/dma-mapping.h | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-)
include/linux/dma-mapping.h +5 -5
@@ -212,14 +212,14 @@ static inline void set_dma_ops(struct device *dev, }#else /* -* Define the dma api to allow compilation but not linking of -* dma dependent code. Code that depends on the dma-mapping -* API needs to set 'depends on HAS_DMA' in its Kconfig +* Define the dma api to allow compilation of dma dependent code. +* Code that depends on the dma-mapping API needs to set 'depends on HAS_DMA' +* in its Kconfig, unless it already depends on <something> || COMPILE_TEST, +* where <something> guarantuees the availability of the dma-mapping API. */ -extern const struct dma_map_ops bad_dma_ops;static inline const struct dma_map_ops *get_dma_ops (struct device *dev) { -return &bad_dma_ops; +return NULL ; }#endif
Signature · 1 line
2.7.4
PATCH v2 2/5 dma-coherent: Add NO_DMA dummies for managed DMA API
In reply to Geert UytterhoevenAdd dummies for dmam_{alloc,free}_coherent(), to allow compile-testing if NO_DMA=y.
This prevents the following from showing up later:
ERROR: "dmam_alloc_coherent" [drivers/net/ethernet/arc/arc_emac.ko] undefined!
ERROR: "dmam_free_coherent" [drivers/net/ethernet/apm/xgene/xgene-enet.ko] undefined!
ERROR: "dmam_alloc_coherent" [drivers/net/ethernet/apm/xgene/xgene-enet.ko] undefined!
ERROR: "dmam_alloc_coherent" [drivers/mtd/nand/hisi504_nand.ko] undefined!
ERROR: "dmam_alloc_coherent" [drivers/mmc/host/dw_mmc.ko] undefined!
---
v2:
- Add Reviewed-by, Acked-by,
- Drop RFC state.
--- include/linux/dma-mapping.h | 9 +++++++++ 1 file changed, 9 insertions(+)
include/linux/dma-mapping.h +9 -0
@@ -776,10 +776,19 @@ static inline void dma_deconfigure(struct device *dev) {}/* * Managed DMA API */ +#ifdef CONFIG_HAS_DMA extern void *dmam_alloc_coherent (struct device *dev,size_t size,dma_addr_t *dma_handle,gfp_t gfp);extern void dmam_free_coherent (struct device *dev,size_t size,void *vaddr,dma_addr_t dma_handle); +#else /* !CONFIG_HAS_DMA */ +static inline void *dmam_alloc_coherent (struct device *dev,size_t size, +dma_addr_t *dma_handle,gfp_t gfp) +{return NULL ; } +static inline void dmam_free_coherent (struct device *dev,size_t size, +void *vaddr,dma_addr_t dma_handle) { } +#endif /* !CONFIG_HAS_DMA */ +extern void *dmam_alloc_attrs (struct device *dev,size_t size,dma_addr_t *dma_handle,gfp_t gfp,unsigned long attrs);
Signature · 1 line
2.7.4
PATCH v2 3/5 usb: gadget: Add NO_DMA dummies for DMA mapping API
In reply to Geert UytterhoevenAdd dummies for usb_gadget_{,un}map_request{,_by_dev}(), to allow compile-testing if NO_DMA=y.
This prevents the following from showing up later:
ERROR: "usb_gadget_unmap_request_by_dev" [drivers/usb/renesas_usbhs/renesas_usbhs.ko] undefined!
ERROR: "usb_gadget_map_request_by_dev" [drivers/usb/renesas_usbhs/renesas_usbhs.ko] undefined!
ERROR: "usb_gadget_map_request" [drivers/usb/mtu3/mtu3.ko] undefined!
ERROR: "usb_gadget_unmap_request" [drivers/usb/mtu3/mtu3.ko] undefined!
ERROR: "usb_gadget_map_request" [drivers/usb/gadget/udc/renesas_usb3.ko] undefined!
ERROR: "usb_gadget_unmap_request" [drivers/usb/gadget/udc/renesas_usb3.ko] undefined!
---
v2:
- Add Reviewed-by, Acked-by,
- Drop RFC state.
--- include/linux/usb/gadget.h | 12 ++++++++++++ 1 file changed, 12 insertions(+)
include/linux/usb/gadget.h +12 -0
@@ -805,6 +805,7 @@ int usb_otg_descriptor_init(struct usb_gadget *gadget,/* utility to simplify map/unmap of usb_requests to/from DMA */ +#ifdef CONFIG_HAS_DMA extern int usb_gadget_map_request_by_dev (struct device *dev,struct usb_request *req,int is_in); extern int usb_gadget_map_request(struct usb_gadget *gadget,
@@ -814,6 +815,17 @@ extern void usb_gadget_unmap_request_by_dev(struct device *dev, struct usb_request *req, int is_in);extern void usb_gadget_unmap_request (struct usb_gadget *gadget,struct usb_request *req,int is_in); +#else /* !CONFIG_HAS_DMA */ +static inline int usb_gadget_map_request_by_dev (struct device *dev, +struct usb_request *req,int is_in) {return -ENOSYS ; } +static inline int usb_gadget_map_request (struct usb_gadget *gadget, +struct usb_request *req,int is_in) {return -ENOSYS ; } + +static inline void usb_gadget_unmap_request_by_dev (struct device *dev, +struct usb_request *req,int is_in) { } +static inline void usb_gadget_unmap_request (struct usb_gadget *gadget, +struct usb_request *req,int is_in) { } +#endif /* !CONFIG_HAS_DMA */ /*-------------------------------------------------------------------------*/
Signature · 1 line
2.7.4
Re: [PATCH v2 3/5] usb: gadget: Add NO_DMA dummies for DMA mapping API
Quoted 12 lines · Geert Uytterhoeven
Add dummies for usb_gadget_{,un}map_request{,_by_dev}(), to allow compile-testing if NO_DMA=y.
This prevents the following from showing up later:
ERROR: "
usb_gadget_unmap_request_by_dev" [drivers/usb/renesas_usbhs/renesas_usbhs.ko] undefined!
ERROR: "usb_gadget_map_request_by_dev" [drivers/usb/renesas_usbhs/renesas_usbhs.ko] undefined!
ERROR: "usb_gadget_map_request" [drivers/usb/mtu3/mtu3.ko] undefined!
ERROR: "usb_gadget_unmap_request" [drivers/usb/mtu3/mtu3.ko] undefined!
ERROR: "usb_gadget_map_request" [drivers/usb/gadget/udc/renesas_usb3.ko] undefined!
ERROR: "usb_gadget_unmap_request" [drivers/usb/gadget/udc/renesas_usb3.ko] undefined!
Quoted 4 lines
Signed-off-by Geert Uytterhoeven <[email protected]>Reviewed-by Mark Brown <[email protected]>Acked-by Robin Murphy <[email protected]>
PATCH v2 4/5 mm: Add NO_DMA dummies for DMA pool API
In reply to Geert UytterhoevenAdd dummies for dma{,m}_pool_{create,destroy,alloc,free}(), to allow compile-testing if NO_DMA=y.
This prevents the following from showing up later:
ERROR: "dma_pool_destroy" [drivers/usb/mtu3/mtu3.ko] undefined!
ERROR: "dma_pool_free" [drivers/usb/mtu3/mtu3.ko] undefined!
ERROR: "dma_pool_alloc" [drivers/usb/mtu3/mtu3.ko] undefined!
ERROR: "dma_pool_create" [drivers/usb/mtu3/mtu3.ko] undefined!
ERROR: "dma_pool_destroy" [drivers/scsi/hisi_sas/hisi_sas_main.ko] undefined!
ERROR: "dma_pool_free" [drivers/scsi/hisi_sas/hisi_sas_main.ko] undefined!
ERROR: "dma_pool_alloc" [drivers/scsi/hisi_sas/hisi_sas_main.ko] undefined!
ERROR: "dma_pool_create" [drivers/scsi/hisi_sas/hisi_sas_main.ko] undefined!
ERROR: "dma_pool_alloc" [drivers/mailbox/bcm-pdc-mailbox.ko] undefined!
ERROR: "dma_pool_free" [drivers/mailbox/bcm-pdc-mailbox.ko] undefined!
ERROR: "dma_pool_create" [drivers/mailbox/bcm-pdc-mailbox.ko] undefined!
ERROR: "dma_pool_destroy" [drivers/mailbox/bcm-pdc-mailbox.ko] undefined!
---
v2:
- Add Reviewed-by, Acked-by,
- Drop RFC state,
- Group NO_DMA-stubs under a single #ifdef,
- Move dma_pool_zalloc() definition down.
--- include/linux/dmapool.h | 30 +++++++++++++++++++++++------- 1 file changed, 23 insertions(+), 7 deletions(-)
include/linux/dmapool.h +23 -7
@@ -16,6 +16,8 @@struct device ; +#ifdef CONFIG_HAS_DMA +struct dma_pool *dma_pool_create (const char *name,struct device *dev,size_t size,size_t align,size_t allocation);
@@ -23,13 +25,6 @@ void dma_pool_destroy(struct dma_pool *pool);void *dma_pool_alloc (struct dma_pool *pool,gfp_t mem_flags,dma_addr_t *handle); - -static inline void *dma_pool_zalloc (struct dma_pool *pool,gfp_t mem_flags, -dma_addr_t *handle) -{ -return dma_pool_alloc (pool, mem_flags | __GFP_ZERO, handle); -} -void dma_pool_free (struct dma_pool *pool,void *vaddr,dma_addr_t addr);/*
@@ -39,5 +34,26 @@ struct dma_pool *dmam_pool_create(const char *name, struct device *dev, size_t size, size_t align, size_t allocation);void dmam_pool_destroy (struct dma_pool *pool); +#else /* !CONFIG_HAS_DMA */ +static inline struct dma_pool *dma_pool_create (const char *name, +struct device *dev,size_t size,size_t align,size_t allocation) +{return NULL ; } +static inline void dma_pool_destroy (struct dma_pool *pool) { } +static inline void *dma_pool_alloc (struct dma_pool *pool,gfp_t mem_flags, +dma_addr_t *handle) {return NULL ; } +static inline void dma_pool_free (struct dma_pool *pool,void *vaddr, +dma_addr_t addr) { } +static inline struct dma_pool *dmam_pool_create (const char *name, +struct device *dev,size_t size,size_t align,size_t allocation) +{return NULL ; } +static inline void dmam_pool_destroy (struct dma_pool *pool) { } +#endif /* !CONFIG_HAS_DMA */ + +static inline void *dma_pool_zalloc (struct dma_pool *pool,gfp_t mem_flags, +dma_addr_t *handle) +{ +return dma_pool_alloc (pool, mem_flags | __GFP_ZERO, handle); +} +#endif
Signature · 1 line
2.7.4
PATCH v2 5/5 scsi: Add NO_DMA dummies for SCSI DMA mapping API
In reply to Geert UytterhoevenAdd dummies for scsi_dma_{,un}map(), to allow compile-testing if NO_DMA=y.
This prevents the following from showing up later:
ERROR: "scsi_dma_unmap" [drivers/firewire/firewire-sbp2.ko] undefined!
ERROR: "scsi_dma_map" [drivers/firewire/firewire-sbp2.ko] undefined!
---
v2:
- Add Reviewed-by, Acked-by,
- Drop RFC state.
--- include/scsi/scsi_cmnd.h | 5 +++++ 1 file changed, 5 insertions(+)
include/scsi/scsi_cmnd.h +5 -0
@@ -174,8 +174,13 @@ extern void scsi_kunmap_atomic_sg(void *virt);extern int scsi_init_io (struct scsi_cmnd *cmd); +#ifdef CONFIG_SCSI_DMA extern int scsi_dma_map (struct scsi_cmnd *cmd);extern void scsi_dma_unmap (struct scsi_cmnd *cmd); +#else /* !CONFIG_SCSI_DMA */ +static inline int scsi_dma_map (struct scsi_cmnd *cmd) {return -ENOSYS ; } +static inline void scsi_dma_unmap (struct scsi_cmnd *cmd) { } +#endif /* !CONFIG_SCSI_DMA */ static inline unsigned scsi_sg_count (struct scsi_cmnd *cmd) {
Signature · 1 line
2.7.4
Christoph Hellwig
AppliedThanks Geert,
applied to the dma-mapping tree for 4.17.