2011-03-21 09:58:24 +00:00
|
|
|
/*-
|
|
|
|
* Copyright (c) 2010 Isilon Systems, Inc.
|
|
|
|
* Copyright (c) 2010 iX Systems, Inc.
|
|
|
|
* Copyright (c) 2010 Panasas, Inc.
|
2014-08-27 13:21:53 +00:00
|
|
|
* Copyright (c) 2013, 2014 Mellanox Technologies, Ltd.
|
2011-03-21 09:58:24 +00:00
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice unmodified, this list of conditions, and the following
|
|
|
|
* disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
|
|
|
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
|
|
|
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
|
|
|
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
|
|
|
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
|
|
|
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
|
|
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
|
|
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
|
|
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
|
|
|
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
2015-10-20 19:08:26 +00:00
|
|
|
*
|
|
|
|
* $FreeBSD$
|
2011-03-21 09:58:24 +00:00
|
|
|
*/
|
|
|
|
#ifndef _LINUX_DMA_MAPPING_H_
|
|
|
|
#define _LINUX_DMA_MAPPING_H_
|
|
|
|
|
|
|
|
#include <linux/types.h>
|
|
|
|
#include <linux/device.h>
|
|
|
|
#include <linux/err.h>
|
|
|
|
#include <linux/dma-attrs.h>
|
|
|
|
#include <linux/scatterlist.h>
|
|
|
|
#include <linux/mm.h>
|
|
|
|
#include <linux/page.h>
|
|
|
|
|
|
|
|
#include <sys/systm.h>
|
|
|
|
#include <sys/malloc.h>
|
|
|
|
|
|
|
|
#include <vm/vm.h>
|
|
|
|
#include <vm/vm_page.h>
|
|
|
|
#include <vm/pmap.h>
|
|
|
|
|
|
|
|
#include <machine/bus.h>
|
|
|
|
|
|
|
|
enum dma_data_direction {
|
|
|
|
DMA_BIDIRECTIONAL = 0,
|
|
|
|
DMA_TO_DEVICE = 1,
|
|
|
|
DMA_FROM_DEVICE = 2,
|
|
|
|
DMA_NONE = 3,
|
|
|
|
};
|
|
|
|
|
|
|
|
struct dma_map_ops {
|
|
|
|
void* (*alloc_coherent)(struct device *dev, size_t size,
|
|
|
|
dma_addr_t *dma_handle, gfp_t gfp);
|
|
|
|
void (*free_coherent)(struct device *dev, size_t size,
|
|
|
|
void *vaddr, dma_addr_t dma_handle);
|
|
|
|
dma_addr_t (*map_page)(struct device *dev, struct page *page,
|
|
|
|
unsigned long offset, size_t size, enum dma_data_direction dir,
|
|
|
|
struct dma_attrs *attrs);
|
|
|
|
void (*unmap_page)(struct device *dev, dma_addr_t dma_handle,
|
|
|
|
size_t size, enum dma_data_direction dir, struct dma_attrs *attrs);
|
|
|
|
int (*map_sg)(struct device *dev, struct scatterlist *sg,
|
|
|
|
int nents, enum dma_data_direction dir, struct dma_attrs *attrs);
|
|
|
|
void (*unmap_sg)(struct device *dev, struct scatterlist *sg, int nents,
|
|
|
|
enum dma_data_direction dir, struct dma_attrs *attrs);
|
|
|
|
void (*sync_single_for_cpu)(struct device *dev, dma_addr_t dma_handle,
|
|
|
|
size_t size, enum dma_data_direction dir);
|
|
|
|
void (*sync_single_for_device)(struct device *dev,
|
|
|
|
dma_addr_t dma_handle, size_t size, enum dma_data_direction dir);
|
|
|
|
void (*sync_single_range_for_cpu)(struct device *dev,
|
|
|
|
dma_addr_t dma_handle, unsigned long offset, size_t size,
|
|
|
|
enum dma_data_direction dir);
|
|
|
|
void (*sync_single_range_for_device)(struct device *dev,
|
|
|
|
dma_addr_t dma_handle, unsigned long offset, size_t size,
|
|
|
|
enum dma_data_direction dir);
|
|
|
|
void (*sync_sg_for_cpu)(struct device *dev, struct scatterlist *sg,
|
|
|
|
int nents, enum dma_data_direction dir);
|
|
|
|
void (*sync_sg_for_device)(struct device *dev, struct scatterlist *sg,
|
|
|
|
int nents, enum dma_data_direction dir);
|
|
|
|
int (*mapping_error)(struct device *dev, dma_addr_t dma_addr);
|
|
|
|
int (*dma_supported)(struct device *dev, u64 mask);
|
|
|
|
int is_phys;
|
|
|
|
};
|
|
|
|
|
2015-10-19 11:29:50 +00:00
|
|
|
#define DMA_BIT_MASK(n) ((2ULL << ((n) - 1)) - 1ULL)
|
2011-03-21 09:58:24 +00:00
|
|
|
|
2019-04-24 20:30:45 +00:00
|
|
|
int linux_dma_tag_init(struct device *dev, u64 mask);
|
|
|
|
void *linux_dma_alloc_coherent(struct device *dev, size_t size,
|
|
|
|
dma_addr_t *dma_handle, gfp_t flag);
|
|
|
|
dma_addr_t linux_dma_map_phys(struct device *dev, vm_paddr_t phys, size_t len);
|
|
|
|
void linux_dma_unmap(struct device *dev, dma_addr_t dma_addr, size_t size);
|
|
|
|
int linux_dma_map_sg_attrs(struct device *dev, struct scatterlist *sgl,
|
|
|
|
int nents, enum dma_data_direction dir, struct dma_attrs *attrs);
|
|
|
|
void linux_dma_unmap_sg_attrs(struct device *dev, struct scatterlist *sg,
|
|
|
|
int nents, enum dma_data_direction dir, struct dma_attrs *attrs);
|
|
|
|
|
2011-03-21 09:58:24 +00:00
|
|
|
static inline int
|
|
|
|
dma_supported(struct device *dev, u64 mask)
|
|
|
|
{
|
|
|
|
|
|
|
|
/* XXX busdma takes care of this elsewhere. */
|
|
|
|
return (1);
|
|
|
|
}
|
2018-03-23 15:50:01 +00:00
|
|
|
|
2011-03-21 09:58:24 +00:00
|
|
|
static inline int
|
|
|
|
dma_set_mask(struct device *dev, u64 dma_mask)
|
|
|
|
{
|
|
|
|
|
2019-04-24 20:30:45 +00:00
|
|
|
if (!dev->dma_priv || !dma_supported(dev, dma_mask))
|
2011-03-21 09:58:24 +00:00
|
|
|
return -EIO;
|
|
|
|
|
2019-04-24 20:30:45 +00:00
|
|
|
return (linux_dma_tag_init(dev, dma_mask));
|
2011-03-21 09:58:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static inline int
|
|
|
|
dma_set_coherent_mask(struct device *dev, u64 mask)
|
|
|
|
{
|
|
|
|
|
|
|
|
if (!dma_supported(dev, mask))
|
|
|
|
return -EIO;
|
2016-04-30 00:53:10 +00:00
|
|
|
/* XXX Currently we don't support a separate coherent mask. */
|
2011-03-21 09:58:24 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2019-03-13 17:42:31 +00:00
|
|
|
static inline int
|
|
|
|
dma_set_mask_and_coherent(struct device *dev, u64 mask)
|
|
|
|
{
|
|
|
|
int r;
|
|
|
|
|
|
|
|
r = dma_set_mask(dev, mask);
|
|
|
|
if (r == 0)
|
|
|
|
dma_set_coherent_mask(dev, mask);
|
|
|
|
return (r);
|
|
|
|
}
|
|
|
|
|
2011-03-21 09:58:24 +00:00
|
|
|
static inline void *
|
|
|
|
dma_alloc_coherent(struct device *dev, size_t size, dma_addr_t *dma_handle,
|
|
|
|
gfp_t flag)
|
|
|
|
{
|
2019-04-24 20:30:45 +00:00
|
|
|
return (linux_dma_alloc_coherent(dev, size, dma_handle, flag));
|
2011-03-21 09:58:24 +00:00
|
|
|
}
|
2015-01-19 20:39:48 +00:00
|
|
|
|
|
|
|
static inline void *
|
|
|
|
dma_zalloc_coherent(struct device *dev, size_t size, dma_addr_t *dma_handle,
|
|
|
|
gfp_t flag)
|
|
|
|
{
|
|
|
|
|
|
|
|
return (dma_alloc_coherent(dev, size, dma_handle, flag | __GFP_ZERO));
|
|
|
|
}
|
2018-03-23 15:50:01 +00:00
|
|
|
|
2011-03-21 09:58:24 +00:00
|
|
|
static inline void
|
|
|
|
dma_free_coherent(struct device *dev, size_t size, void *cpu_addr,
|
2019-04-24 20:30:45 +00:00
|
|
|
dma_addr_t dma_addr)
|
2011-03-21 09:58:24 +00:00
|
|
|
{
|
|
|
|
|
2019-04-24 20:30:45 +00:00
|
|
|
linux_dma_unmap(dev, dma_addr, size);
|
2018-08-25 19:38:08 +00:00
|
|
|
kmem_free((vm_offset_t)cpu_addr, size);
|
2011-03-21 09:58:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static inline dma_addr_t
|
|
|
|
dma_map_single_attrs(struct device *dev, void *ptr, size_t size,
|
|
|
|
enum dma_data_direction dir, struct dma_attrs *attrs)
|
|
|
|
{
|
|
|
|
|
2019-04-24 20:30:45 +00:00
|
|
|
return (linux_dma_map_phys(dev, vtophys(ptr), size));
|
2011-03-21 09:58:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static inline void
|
2019-04-24 20:30:45 +00:00
|
|
|
dma_unmap_single_attrs(struct device *dev, dma_addr_t dma_addr, size_t size,
|
2011-03-21 09:58:24 +00:00
|
|
|
enum dma_data_direction dir, struct dma_attrs *attrs)
|
|
|
|
{
|
2019-04-24 20:30:45 +00:00
|
|
|
|
|
|
|
linux_dma_unmap(dev, dma_addr, size);
|
2011-03-21 09:58:24 +00:00
|
|
|
}
|
|
|
|
|
2019-03-13 18:44:06 +00:00
|
|
|
static inline dma_addr_t
|
|
|
|
dma_map_page_attrs(struct device *dev, struct page *page, size_t offset,
|
|
|
|
size_t size, enum dma_data_direction dir, unsigned long attrs)
|
|
|
|
{
|
|
|
|
|
2019-04-24 20:30:45 +00:00
|
|
|
return (linux_dma_map_phys(dev, VM_PAGE_TO_PHYS(page) + offset, size));
|
2019-03-13 18:44:06 +00:00
|
|
|
}
|
|
|
|
|
2011-03-21 09:58:24 +00:00
|
|
|
static inline int
|
|
|
|
dma_map_sg_attrs(struct device *dev, struct scatterlist *sgl, int nents,
|
|
|
|
enum dma_data_direction dir, struct dma_attrs *attrs)
|
|
|
|
{
|
|
|
|
|
2019-04-24 20:30:45 +00:00
|
|
|
return (linux_dma_map_sg_attrs(dev, sgl, nents, dir, attrs));
|
2011-03-21 09:58:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static inline void
|
|
|
|
dma_unmap_sg_attrs(struct device *dev, struct scatterlist *sg, int nents,
|
|
|
|
enum dma_data_direction dir, struct dma_attrs *attrs)
|
|
|
|
{
|
2019-04-24 20:30:45 +00:00
|
|
|
|
|
|
|
linux_dma_unmap_sg_attrs(dev, sg, nents, dir, attrs);
|
2011-03-21 09:58:24 +00:00
|
|
|
}
|
2018-03-23 15:50:01 +00:00
|
|
|
|
2011-03-21 09:58:24 +00:00
|
|
|
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)
|
|
|
|
{
|
|
|
|
|
2019-04-24 20:30:45 +00:00
|
|
|
return (linux_dma_map_phys(dev, VM_PAGE_TO_PHYS(page) + offset, size));
|
2011-03-21 09:58:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static inline void
|
|
|
|
dma_unmap_page(struct device *dev, dma_addr_t dma_address, size_t size,
|
|
|
|
enum dma_data_direction direction)
|
|
|
|
{
|
2019-04-24 20:30:45 +00:00
|
|
|
|
|
|
|
linux_dma_unmap(dev, dma_address, size);
|
2011-03-21 09:58:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static inline void
|
|
|
|
dma_sync_single_for_cpu(struct device *dev, dma_addr_t dma_handle, size_t size,
|
|
|
|
enum dma_data_direction direction)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void
|
|
|
|
dma_sync_single(struct device *dev, dma_addr_t addr, size_t size,
|
|
|
|
enum dma_data_direction dir)
|
|
|
|
{
|
|
|
|
dma_sync_single_for_cpu(dev, addr, size, dir);
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void
|
|
|
|
dma_sync_single_for_device(struct device *dev, dma_addr_t dma_handle,
|
|
|
|
size_t size, enum dma_data_direction direction)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void
|
|
|
|
dma_sync_sg_for_cpu(struct device *dev, struct scatterlist *sg, int nelems,
|
|
|
|
enum dma_data_direction direction)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void
|
|
|
|
dma_sync_sg_for_device(struct device *dev, struct scatterlist *sg, int nelems,
|
|
|
|
enum dma_data_direction direction)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void
|
|
|
|
dma_sync_single_range_for_cpu(struct device *dev, dma_addr_t dma_handle,
|
|
|
|
unsigned long offset, size_t size, int direction)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void
|
|
|
|
dma_sync_single_range_for_device(struct device *dev, dma_addr_t dma_handle,
|
|
|
|
unsigned long offset, size_t size, int direction)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline int
|
|
|
|
dma_mapping_error(struct device *dev, dma_addr_t dma_addr)
|
|
|
|
{
|
|
|
|
|
2019-04-24 20:30:45 +00:00
|
|
|
return (dma_addr == 0);
|
2011-03-21 09:58:24 +00:00
|
|
|
}
|
|
|
|
|
2013-09-29 00:35:03 +00:00
|
|
|
static inline unsigned int dma_set_max_seg_size(struct device *dev,
|
2018-03-23 15:50:01 +00:00
|
|
|
unsigned int size)
|
2013-09-29 00:35:03 +00:00
|
|
|
{
|
2018-03-23 15:50:01 +00:00
|
|
|
return (0);
|
2013-09-29 00:35:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-03-21 09:58:24 +00:00
|
|
|
#define dma_map_single(d, a, s, r) dma_map_single_attrs(d, a, s, r, NULL)
|
|
|
|
#define dma_unmap_single(d, a, s, r) dma_unmap_single_attrs(d, a, s, r, NULL)
|
|
|
|
#define dma_map_sg(d, s, n, r) dma_map_sg_attrs(d, s, n, r, NULL)
|
|
|
|
#define dma_unmap_sg(d, s, n, r) dma_unmap_sg_attrs(d, s, n, r, NULL)
|
|
|
|
|
|
|
|
#define DEFINE_DMA_UNMAP_ADDR(name) dma_addr_t name
|
|
|
|
#define DEFINE_DMA_UNMAP_LEN(name) __u32 name
|
|
|
|
#define dma_unmap_addr(p, name) ((p)->name)
|
|
|
|
#define dma_unmap_addr_set(p, name, v) (((p)->name) = (v))
|
|
|
|
#define dma_unmap_len(p, name) ((p)->name)
|
|
|
|
#define dma_unmap_len_set(p, name, v) (((p)->name) = (v))
|
|
|
|
|
|
|
|
extern int uma_align_cache;
|
|
|
|
#define dma_get_cache_alignment() uma_align_cache
|
|
|
|
|
|
|
|
#endif /* _LINUX_DMA_MAPPING_H_ */
|