blob: 2112f21f73d82bd7ced1bbfb4b58c91b1cc5ab44 [file] [log] [blame]
David Brazdil0f672f62019-12-10 10:32:29 +00001/* SPDX-License-Identifier: GPL-2.0-only */
Andrew Scullb4b6d4a2019-01-02 15:54:55 +00002/*
3 * Copyright (C) 2014-2015 ARM Ltd.
Andrew Scullb4b6d4a2019-01-02 15:54:55 +00004 */
5#ifndef __DMA_IOMMU_H
6#define __DMA_IOMMU_H
7
David Brazdil0f672f62019-12-10 10:32:29 +00008#include <linux/errno.h>
Andrew Scullb4b6d4a2019-01-02 15:54:55 +00009#include <linux/types.h>
Andrew Scullb4b6d4a2019-01-02 15:54:55 +000010
11#ifdef CONFIG_IOMMU_DMA
12#include <linux/dma-mapping.h>
13#include <linux/iommu.h>
14#include <linux/msi.h>
15
Andrew Scullb4b6d4a2019-01-02 15:54:55 +000016/* Domain management interface for IOMMU drivers */
17int iommu_get_dma_cookie(struct iommu_domain *domain);
18int iommu_get_msi_cookie(struct iommu_domain *domain, dma_addr_t base);
19void iommu_put_dma_cookie(struct iommu_domain *domain);
20
21/* Setup call for arch DMA mapping code */
David Brazdil0f672f62019-12-10 10:32:29 +000022void iommu_setup_dma_ops(struct device *dev, u64 dma_base, u64 size);
Andrew Scullb4b6d4a2019-01-02 15:54:55 +000023
24/* The DMA API isn't _quite_ the whole story, though... */
David Brazdil0f672f62019-12-10 10:32:29 +000025/*
26 * iommu_dma_prepare_msi() - Map the MSI page in the IOMMU device
27 *
28 * The MSI page will be stored in @desc.
29 *
30 * Return: 0 on success otherwise an error describing the failure.
31 */
32int iommu_dma_prepare_msi(struct msi_desc *desc, phys_addr_t msi_addr);
33
34/* Update the MSI message if required. */
35void iommu_dma_compose_msi_msg(struct msi_desc *desc,
36 struct msi_msg *msg);
37
Andrew Scullb4b6d4a2019-01-02 15:54:55 +000038void iommu_dma_get_resv_regions(struct device *dev, struct list_head *list);
39
David Brazdil0f672f62019-12-10 10:32:29 +000040#else /* CONFIG_IOMMU_DMA */
Andrew Scullb4b6d4a2019-01-02 15:54:55 +000041
42struct iommu_domain;
David Brazdil0f672f62019-12-10 10:32:29 +000043struct msi_desc;
Andrew Scullb4b6d4a2019-01-02 15:54:55 +000044struct msi_msg;
45struct device;
46
David Brazdil0f672f62019-12-10 10:32:29 +000047static inline void iommu_setup_dma_ops(struct device *dev, u64 dma_base,
48 u64 size)
Andrew Scullb4b6d4a2019-01-02 15:54:55 +000049{
Andrew Scullb4b6d4a2019-01-02 15:54:55 +000050}
51
52static inline int iommu_get_dma_cookie(struct iommu_domain *domain)
53{
54 return -ENODEV;
55}
56
57static inline int iommu_get_msi_cookie(struct iommu_domain *domain, dma_addr_t base)
58{
59 return -ENODEV;
60}
61
62static inline void iommu_put_dma_cookie(struct iommu_domain *domain)
63{
64}
65
David Brazdil0f672f62019-12-10 10:32:29 +000066static inline int iommu_dma_prepare_msi(struct msi_desc *desc,
67 phys_addr_t msi_addr)
68{
69 return 0;
70}
71
72static inline void iommu_dma_compose_msi_msg(struct msi_desc *desc,
73 struct msi_msg *msg)
Andrew Scullb4b6d4a2019-01-02 15:54:55 +000074{
75}
76
77static inline void iommu_dma_get_resv_regions(struct device *dev, struct list_head *list)
78{
79}
80
81#endif /* CONFIG_IOMMU_DMA */
Andrew Scullb4b6d4a2019-01-02 15:54:55 +000082#endif /* __DMA_IOMMU_H */