2015-10-01 13:13:58 -06:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2014-2015 ARM Ltd.
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License version 2 as
|
|
|
|
* published by the Free Software Foundation.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
#ifndef __DMA_IOMMU_H
|
|
|
|
#define __DMA_IOMMU_H
|
|
|
|
|
|
|
|
#ifdef __KERNEL__
|
2018-05-08 06:14:33 -06:00
|
|
|
#include <linux/types.h>
|
2015-10-01 13:13:58 -06:00
|
|
|
#include <asm/errno.h>
|
|
|
|
|
|
|
|
#ifdef CONFIG_IOMMU_DMA
|
2017-04-26 07:46:20 -06:00
|
|
|
#include <linux/dma-mapping.h>
|
2015-10-01 13:13:58 -06:00
|
|
|
#include <linux/iommu.h>
|
2016-09-12 10:13:59 -06:00
|
|
|
#include <linux/msi.h>
|
2015-10-01 13:13:58 -06:00
|
|
|
|
2018-10-23 16:02:34 -06:00
|
|
|
struct iova_domain;
|
|
|
|
|
2015-10-01 13:13:58 -06:00
|
|
|
int iommu_dma_init(void);
|
|
|
|
|
|
|
|
/* Domain management interface for IOMMU drivers */
|
|
|
|
int iommu_get_dma_cookie(struct iommu_domain *domain);
|
2017-01-19 13:57:46 -07:00
|
|
|
int iommu_get_msi_cookie(struct iommu_domain *domain, dma_addr_t base);
|
2015-10-01 13:13:58 -06:00
|
|
|
void iommu_put_dma_cookie(struct iommu_domain *domain);
|
|
|
|
|
|
|
|
/* Setup call for arch DMA mapping code */
|
2016-09-12 10:14:00 -06:00
|
|
|
int iommu_dma_init_domain(struct iommu_domain *domain, dma_addr_t base,
|
|
|
|
u64 size, struct device *dev);
|
2015-10-01 13:13:58 -06:00
|
|
|
|
|
|
|
/* General helpers for DMA-API <-> IOMMU-API interaction */
|
2017-01-06 06:28:12 -07:00
|
|
|
int dma_info_to_prot(enum dma_data_direction dir, bool coherent,
|
|
|
|
unsigned long attrs);
|
2015-10-01 13:13:58 -06:00
|
|
|
|
|
|
|
/*
|
|
|
|
* These implement the bulk of the relevant DMA mapping callbacks, but require
|
|
|
|
* the arch code to take care of attributes and cache maintenance
|
|
|
|
*/
|
2016-04-13 10:29:10 -06:00
|
|
|
struct page **iommu_dma_alloc(struct device *dev, size_t size, gfp_t gfp,
|
2016-08-03 14:46:00 -06:00
|
|
|
unsigned long attrs, int prot, dma_addr_t *handle,
|
2015-10-01 13:13:58 -06:00
|
|
|
void (*flush_page)(struct device *, const void *, phys_addr_t));
|
|
|
|
void iommu_dma_free(struct device *dev, struct page **pages, size_t size,
|
|
|
|
dma_addr_t *handle);
|
|
|
|
|
|
|
|
int iommu_dma_mmap(struct page **pages, size_t size, struct vm_area_struct *vma);
|
|
|
|
|
|
|
|
dma_addr_t iommu_dma_map_page(struct device *dev, struct page *page,
|
|
|
|
unsigned long offset, size_t size, int prot);
|
|
|
|
int iommu_dma_map_sg(struct device *dev, struct scatterlist *sg,
|
|
|
|
int nents, int prot);
|
2018-10-23 16:02:34 -06:00
|
|
|
size_t iommu_dma_prepare_map_sg(struct device *dev, struct iova_domain *iovad,
|
|
|
|
struct scatterlist *sg, int nents);
|
|
|
|
int iommu_dma_finalise_sg(struct device *dev, struct scatterlist *sg,
|
|
|
|
int nents, dma_addr_t dma_addr);
|
|
|
|
void iommu_dma_invalidate_sg(struct scatterlist *sg, int nents);
|
2015-10-01 13:13:58 -06:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Arch code with no special attribute handling may use these
|
|
|
|
* directly as DMA mapping callbacks for simplicity
|
|
|
|
*/
|
|
|
|
void iommu_dma_unmap_page(struct device *dev, dma_addr_t handle, size_t size,
|
2016-08-03 14:46:00 -06:00
|
|
|
enum dma_data_direction dir, unsigned long attrs);
|
2015-10-01 13:13:58 -06:00
|
|
|
void iommu_dma_unmap_sg(struct device *dev, struct scatterlist *sg, int nents,
|
2016-08-03 14:46:00 -06:00
|
|
|
enum dma_data_direction dir, unsigned long attrs);
|
2016-11-14 05:16:26 -07:00
|
|
|
dma_addr_t iommu_dma_map_resource(struct device *dev, phys_addr_t phys,
|
|
|
|
size_t size, enum dma_data_direction dir, unsigned long attrs);
|
|
|
|
void iommu_dma_unmap_resource(struct device *dev, dma_addr_t handle,
|
|
|
|
size_t size, enum dma_data_direction dir, unsigned long attrs);
|
2015-10-01 13:13:58 -06:00
|
|
|
int iommu_dma_mapping_error(struct device *dev, dma_addr_t dma_addr);
|
|
|
|
|
2016-09-12 10:13:59 -06:00
|
|
|
/* The DMA API isn't _quite_ the whole story, though... */
|
|
|
|
void iommu_dma_map_msi_msg(int irq, struct msi_msg *msg);
|
2017-03-16 11:00:19 -06:00
|
|
|
void iommu_dma_get_resv_regions(struct device *dev, struct list_head *list);
|
2016-09-12 10:13:59 -06:00
|
|
|
|
2019-12-10 18:49:48 -07:00
|
|
|
int iommu_dma_reserve_iova(struct device *dev, dma_addr_t base,
|
|
|
|
u64 size);
|
|
|
|
|
2019-12-12 23:43:52 -07:00
|
|
|
int iommu_dma_enable_best_fit_algo(struct device *dev);
|
|
|
|
|
2015-10-01 13:13:58 -06:00
|
|
|
#else
|
|
|
|
|
|
|
|
struct iommu_domain;
|
2016-09-12 10:13:59 -06:00
|
|
|
struct msi_msg;
|
2017-05-18 07:13:57 -06:00
|
|
|
struct device;
|
2015-10-01 13:13:58 -06:00
|
|
|
|
|
|
|
static inline int iommu_dma_init(void)
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline int iommu_get_dma_cookie(struct iommu_domain *domain)
|
|
|
|
{
|
|
|
|
return -ENODEV;
|
|
|
|
}
|
|
|
|
|
2017-01-19 13:57:46 -07:00
|
|
|
static inline int iommu_get_msi_cookie(struct iommu_domain *domain, dma_addr_t base)
|
|
|
|
{
|
|
|
|
return -ENODEV;
|
|
|
|
}
|
|
|
|
|
2015-10-01 13:13:58 -06:00
|
|
|
static inline void iommu_put_dma_cookie(struct iommu_domain *domain)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2016-09-12 10:13:59 -06:00
|
|
|
static inline void iommu_dma_map_msi_msg(int irq, struct msi_msg *msg)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2017-03-16 11:00:19 -06:00
|
|
|
static inline void iommu_dma_get_resv_regions(struct device *dev, struct list_head *list)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2019-12-10 18:49:48 -07:00
|
|
|
static inline int iommu_dma_reserve_iova(struct device *dev, dma_addr_t base,
|
|
|
|
u64 size)
|
|
|
|
{
|
|
|
|
return -ENODEV;
|
|
|
|
}
|
|
|
|
|
2019-12-12 23:43:52 -07:00
|
|
|
static inline int iommu_dma_enable_best_fit_algo(struct device *dev)
|
|
|
|
{
|
|
|
|
return -ENODEV;
|
|
|
|
}
|
|
|
|
|
2015-10-01 13:13:58 -06:00
|
|
|
#endif /* CONFIG_IOMMU_DMA */
|
|
|
|
#endif /* __KERNEL__ */
|
|
|
|
#endif /* __DMA_IOMMU_H */
|