Skip to content

Commit

Permalink
Merge tag 'dma-mapping-4.17' of git://git.infradead.org/users/hch/dma…
Browse files Browse the repository at this point in the history
…-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
  • Loading branch information
Linus Torvalds committed Apr 5, 2018
2 parents 1b2951d + 1f674e1 commit 652ede3
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 12 deletions.
19 changes: 14 additions & 5 deletions include/linux/dma-mapping.h
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -772,10 +772,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);
Expand Down
30 changes: 23 additions & 7 deletions include/linux/dmapool.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,20 +16,15 @@

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);

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);

/*
Expand All @@ -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

12 changes: 12 additions & 0 deletions include/linux/usb/gadget.h
Original file line number Diff line number Diff line change
Expand Up @@ -806,6 +806,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,
Expand All @@ -815,6 +816,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 */

/*-------------------------------------------------------------------------*/

Expand Down
5 changes: 5 additions & 0 deletions include/scsi/scsi_cmnd.h
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down

0 comments on commit 652ede3

Please sign in to comment.