Skip to content

Commit 652ede3

Browse files
committed
Merge tag 'dma-mapping-4.17' of git://git.infradead.org/users/hch/dma-mapping
Pull dma-mapping updates from Christoph Hellwig: "Very light this round as the interesting dma mapping changes went through the x86 tree. This just provides proper stubs for architectures not supporting dma (Geert Uytterhoeven)" * tag 'dma-mapping-4.17' of git://git.infradead.org/users/hch/dma-mapping: usb: gadget: Add NO_DMA dummies for DMA mapping API scsi: Add NO_DMA dummies for SCSI DMA mapping API mm: Add NO_DMA dummies for DMA pool API dma-coherent: Add NO_DMA dummies for managed DMA API dma-mapping: Convert NO_DMA get_dma_ops() into a real dummy
2 parents 1b2951d + 1f674e1 commit 652ede3

File tree

4 files changed

+54
-12
lines changed

4 files changed

+54
-12
lines changed

include/linux/dma-mapping.h

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -212,14 +212,14 @@ static inline void set_dma_ops(struct device *dev,
212212
}
213213
#else
214214
/*
215-
* Define the dma api to allow compilation but not linking of
216-
* dma dependent code. Code that depends on the dma-mapping
217-
* API needs to set 'depends on HAS_DMA' in its Kconfig
215+
* Define the dma api to allow compilation of dma dependent code.
216+
* Code that depends on the dma-mapping API needs to set 'depends on HAS_DMA'
217+
* in its Kconfig, unless it already depends on <something> || COMPILE_TEST,
218+
* where <something> guarantuees the availability of the dma-mapping API.
218219
*/
219-
extern const struct dma_map_ops bad_dma_ops;
220220
static inline const struct dma_map_ops *get_dma_ops(struct device *dev)
221221
{
222-
return &bad_dma_ops;
222+
return NULL;
223223
}
224224
#endif
225225

@@ -772,10 +772,19 @@ static inline void dma_deconfigure(struct device *dev) {}
772772
/*
773773
* Managed DMA API
774774
*/
775+
#ifdef CONFIG_HAS_DMA
775776
extern void *dmam_alloc_coherent(struct device *dev, size_t size,
776777
dma_addr_t *dma_handle, gfp_t gfp);
777778
extern void dmam_free_coherent(struct device *dev, size_t size, void *vaddr,
778779
dma_addr_t dma_handle);
780+
#else /* !CONFIG_HAS_DMA */
781+
static inline void *dmam_alloc_coherent(struct device *dev, size_t size,
782+
dma_addr_t *dma_handle, gfp_t gfp)
783+
{ return NULL; }
784+
static inline void dmam_free_coherent(struct device *dev, size_t size,
785+
void *vaddr, dma_addr_t dma_handle) { }
786+
#endif /* !CONFIG_HAS_DMA */
787+
779788
extern void *dmam_alloc_attrs(struct device *dev, size_t size,
780789
dma_addr_t *dma_handle, gfp_t gfp,
781790
unsigned long attrs);

include/linux/dmapool.h

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,20 +16,15 @@
1616

1717
struct device;
1818

19+
#ifdef CONFIG_HAS_DMA
20+
1921
struct dma_pool *dma_pool_create(const char *name, struct device *dev,
2022
size_t size, size_t align, size_t allocation);
2123

2224
void dma_pool_destroy(struct dma_pool *pool);
2325

2426
void *dma_pool_alloc(struct dma_pool *pool, gfp_t mem_flags,
2527
dma_addr_t *handle);
26-
27-
static inline void *dma_pool_zalloc(struct dma_pool *pool, gfp_t mem_flags,
28-
dma_addr_t *handle)
29-
{
30-
return dma_pool_alloc(pool, mem_flags | __GFP_ZERO, handle);
31-
}
32-
3328
void dma_pool_free(struct dma_pool *pool, void *vaddr, dma_addr_t addr);
3429

3530
/*
@@ -39,5 +34,26 @@ struct dma_pool *dmam_pool_create(const char *name, struct device *dev,
3934
size_t size, size_t align, size_t allocation);
4035
void dmam_pool_destroy(struct dma_pool *pool);
4136

37+
#else /* !CONFIG_HAS_DMA */
38+
static inline struct dma_pool *dma_pool_create(const char *name,
39+
struct device *dev, size_t size, size_t align, size_t allocation)
40+
{ return NULL; }
41+
static inline void dma_pool_destroy(struct dma_pool *pool) { }
42+
static inline void *dma_pool_alloc(struct dma_pool *pool, gfp_t mem_flags,
43+
dma_addr_t *handle) { return NULL; }
44+
static inline void dma_pool_free(struct dma_pool *pool, void *vaddr,
45+
dma_addr_t addr) { }
46+
static inline struct dma_pool *dmam_pool_create(const char *name,
47+
struct device *dev, size_t size, size_t align, size_t allocation)
48+
{ return NULL; }
49+
static inline void dmam_pool_destroy(struct dma_pool *pool) { }
50+
#endif /* !CONFIG_HAS_DMA */
51+
52+
static inline void *dma_pool_zalloc(struct dma_pool *pool, gfp_t mem_flags,
53+
dma_addr_t *handle)
54+
{
55+
return dma_pool_alloc(pool, mem_flags | __GFP_ZERO, handle);
56+
}
57+
4258
#endif
4359

include/linux/usb/gadget.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -806,6 +806,7 @@ int usb_otg_descriptor_init(struct usb_gadget *gadget,
806806

807807
/* utility to simplify map/unmap of usb_requests to/from DMA */
808808

809+
#ifdef CONFIG_HAS_DMA
809810
extern int usb_gadget_map_request_by_dev(struct device *dev,
810811
struct usb_request *req, int is_in);
811812
extern int usb_gadget_map_request(struct usb_gadget *gadget,
@@ -815,6 +816,17 @@ extern void usb_gadget_unmap_request_by_dev(struct device *dev,
815816
struct usb_request *req, int is_in);
816817
extern void usb_gadget_unmap_request(struct usb_gadget *gadget,
817818
struct usb_request *req, int is_in);
819+
#else /* !CONFIG_HAS_DMA */
820+
static inline int usb_gadget_map_request_by_dev(struct device *dev,
821+
struct usb_request *req, int is_in) { return -ENOSYS; }
822+
static inline int usb_gadget_map_request(struct usb_gadget *gadget,
823+
struct usb_request *req, int is_in) { return -ENOSYS; }
824+
825+
static inline void usb_gadget_unmap_request_by_dev(struct device *dev,
826+
struct usb_request *req, int is_in) { }
827+
static inline void usb_gadget_unmap_request(struct usb_gadget *gadget,
828+
struct usb_request *req, int is_in) { }
829+
#endif /* !CONFIG_HAS_DMA */
818830

819831
/*-------------------------------------------------------------------------*/
820832

include/scsi/scsi_cmnd.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,8 +174,13 @@ extern void scsi_kunmap_atomic_sg(void *virt);
174174

175175
extern int scsi_init_io(struct scsi_cmnd *cmd);
176176

177+
#ifdef CONFIG_SCSI_DMA
177178
extern int scsi_dma_map(struct scsi_cmnd *cmd);
178179
extern void scsi_dma_unmap(struct scsi_cmnd *cmd);
180+
#else /* !CONFIG_SCSI_DMA */
181+
static inline int scsi_dma_map(struct scsi_cmnd *cmd) { return -ENOSYS; }
182+
static inline void scsi_dma_unmap(struct scsi_cmnd *cmd) { }
183+
#endif /* !CONFIG_SCSI_DMA */
179184

180185
static inline unsigned scsi_sg_count(struct scsi_cmnd *cmd)
181186
{

0 commit comments

Comments
 (0)