Nicholas Flintham | 1e3d311 | 2013-04-10 10:48:38 +0100 | [diff] [blame^] | 1 | /* |
| 2 | * Copyright (C) 2007-2008 Advanced Micro Devices, Inc. |
| 3 | * Author: Joerg Roedel <joerg.roedel@amd.com> |
| 4 | * |
| 5 | * This program is free software; you can redistribute it and/or modify it |
| 6 | * under the terms of the GNU General Public License version 2 as published |
| 7 | * by the Free Software Foundation. |
| 8 | * |
| 9 | * This program is distributed in the hope that it will be useful, |
| 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 | * GNU General Public License for more details. |
| 13 | * |
| 14 | * You should have received a copy of the GNU General Public License |
| 15 | * along with this program; if not, write to the Free Software |
| 16 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
| 17 | */ |
| 18 | |
| 19 | #ifndef __LINUX_IOMMU_H |
| 20 | #define __LINUX_IOMMU_H |
| 21 | |
| 22 | #include <linux/types.h> |
| 23 | #include <linux/errno.h> |
| 24 | #include <linux/scatterlist.h> |
| 25 | |
| 26 | #define IOMMU_READ (1) |
| 27 | #define IOMMU_WRITE (2) |
| 28 | #define IOMMU_CACHE (4) |
| 29 | |
| 30 | struct iommu_ops; |
| 31 | struct bus_type; |
| 32 | struct device; |
| 33 | struct iommu_domain; |
| 34 | |
| 35 | #define IOMMU_FAULT_READ 0x0 |
| 36 | #define IOMMU_FAULT_WRITE 0x1 |
| 37 | |
| 38 | typedef int (*iommu_fault_handler_t)(struct iommu_domain *, |
| 39 | struct device *, unsigned long, int); |
| 40 | |
| 41 | struct iommu_domain { |
| 42 | struct iommu_ops *ops; |
| 43 | void *priv; |
| 44 | iommu_fault_handler_t handler; |
| 45 | }; |
| 46 | |
| 47 | #define IOMMU_CAP_CACHE_COHERENCY 0x1 |
| 48 | #define IOMMU_CAP_INTR_REMAP 0x2 |
| 49 | |
| 50 | #ifdef CONFIG_IOMMU_API |
| 51 | |
| 52 | struct iommu_ops { |
| 53 | int (*domain_init)(struct iommu_domain *domain, int flags); |
| 54 | void (*domain_destroy)(struct iommu_domain *domain); |
| 55 | int (*attach_dev)(struct iommu_domain *domain, struct device *dev); |
| 56 | void (*detach_dev)(struct iommu_domain *domain, struct device *dev); |
| 57 | int (*map)(struct iommu_domain *domain, unsigned long iova, |
| 58 | phys_addr_t paddr, size_t size, int prot); |
| 59 | size_t (*unmap)(struct iommu_domain *domain, unsigned long iova, |
| 60 | size_t size); |
| 61 | int (*map_range)(struct iommu_domain *domain, unsigned int iova, |
| 62 | struct scatterlist *sg, unsigned int len, int prot); |
| 63 | int (*unmap_range)(struct iommu_domain *domain, unsigned int iova, |
| 64 | unsigned int len); |
| 65 | phys_addr_t (*iova_to_phys)(struct iommu_domain *domain, |
| 66 | unsigned long iova); |
| 67 | int (*domain_has_cap)(struct iommu_domain *domain, |
| 68 | unsigned long cap); |
| 69 | phys_addr_t (*get_pt_base_addr)(struct iommu_domain *domain); |
| 70 | int (*device_group)(struct device *dev, unsigned int *groupid); |
| 71 | unsigned long pgsize_bitmap; |
| 72 | }; |
| 73 | |
| 74 | extern int bus_set_iommu(struct bus_type *bus, struct iommu_ops *ops); |
| 75 | extern bool iommu_present(struct bus_type *bus); |
| 76 | extern struct iommu_domain *iommu_domain_alloc(struct bus_type *bus, int flags); |
| 77 | extern void iommu_domain_free(struct iommu_domain *domain); |
| 78 | extern int iommu_attach_device(struct iommu_domain *domain, |
| 79 | struct device *dev); |
| 80 | extern void iommu_detach_device(struct iommu_domain *domain, |
| 81 | struct device *dev); |
| 82 | extern int iommu_map(struct iommu_domain *domain, unsigned long iova, |
| 83 | phys_addr_t paddr, size_t size, int prot); |
| 84 | extern size_t iommu_unmap(struct iommu_domain *domain, unsigned long iova, |
| 85 | size_t size); |
| 86 | extern int iommu_map_range(struct iommu_domain *domain, unsigned int iova, |
| 87 | struct scatterlist *sg, unsigned int len, int prot); |
| 88 | extern int iommu_unmap_range(struct iommu_domain *domain, unsigned int iova, |
| 89 | unsigned int len); |
| 90 | extern phys_addr_t iommu_iova_to_phys(struct iommu_domain *domain, |
| 91 | unsigned long iova); |
| 92 | extern int iommu_domain_has_cap(struct iommu_domain *domain, |
| 93 | unsigned long cap); |
| 94 | extern phys_addr_t iommu_get_pt_base_addr(struct iommu_domain *domain); |
| 95 | extern void iommu_set_fault_handler(struct iommu_domain *domain, |
| 96 | iommu_fault_handler_t handler); |
| 97 | extern int iommu_device_group(struct device *dev, unsigned int *groupid); |
| 98 | |
| 99 | static inline int report_iommu_fault(struct iommu_domain *domain, |
| 100 | struct device *dev, unsigned long iova, int flags) |
| 101 | { |
| 102 | int ret = -ENOSYS; |
| 103 | |
| 104 | if (domain->handler) |
| 105 | ret = domain->handler(domain, dev, iova, flags); |
| 106 | |
| 107 | return ret; |
| 108 | } |
| 109 | |
| 110 | #else |
| 111 | |
| 112 | struct iommu_ops {}; |
| 113 | |
| 114 | static inline bool iommu_present(struct bus_type *bus) |
| 115 | { |
| 116 | return false; |
| 117 | } |
| 118 | |
| 119 | static inline struct iommu_domain *iommu_domain_alloc(struct bus_type *bus, int flags) |
| 120 | { |
| 121 | return NULL; |
| 122 | } |
| 123 | |
| 124 | static inline void iommu_domain_free(struct iommu_domain *domain) |
| 125 | { |
| 126 | } |
| 127 | |
| 128 | static inline int iommu_attach_device(struct iommu_domain *domain, |
| 129 | struct device *dev) |
| 130 | { |
| 131 | return -ENODEV; |
| 132 | } |
| 133 | |
| 134 | static inline void iommu_detach_device(struct iommu_domain *domain, |
| 135 | struct device *dev) |
| 136 | { |
| 137 | } |
| 138 | |
| 139 | static inline int iommu_map(struct iommu_domain *domain, unsigned long iova, |
| 140 | phys_addr_t paddr, int gfp_order, int prot) |
| 141 | { |
| 142 | return -ENODEV; |
| 143 | } |
| 144 | |
| 145 | static inline int iommu_unmap(struct iommu_domain *domain, unsigned long iova, |
| 146 | int gfp_order) |
| 147 | { |
| 148 | return -ENODEV; |
| 149 | } |
| 150 | |
| 151 | static inline int iommu_map_range(struct iommu_domain *domain, |
| 152 | unsigned int iova, struct scatterlist *sg, |
| 153 | unsigned int len, int prot) |
| 154 | { |
| 155 | return -ENODEV; |
| 156 | } |
| 157 | |
| 158 | static inline int iommu_unmap_range(struct iommu_domain *domain, |
| 159 | unsigned int iova, unsigned int len) |
| 160 | { |
| 161 | return -ENODEV; |
| 162 | } |
| 163 | |
| 164 | static inline phys_addr_t iommu_iova_to_phys(struct iommu_domain *domain, |
| 165 | unsigned long iova) |
| 166 | { |
| 167 | return 0; |
| 168 | } |
| 169 | |
| 170 | static inline int domain_has_cap(struct iommu_domain *domain, |
| 171 | unsigned long cap) |
| 172 | { |
| 173 | return 0; |
| 174 | } |
| 175 | |
| 176 | static inline phys_addr_t iommu_get_pt_base_addr(struct iommu_domain *domain) |
| 177 | { |
| 178 | return 0; |
| 179 | } |
| 180 | |
| 181 | static inline void iommu_set_fault_handler(struct iommu_domain *domain, |
| 182 | iommu_fault_handler_t handler) |
| 183 | { |
| 184 | } |
| 185 | |
| 186 | static inline int iommu_device_group(struct device *dev, unsigned int *groupid) |
| 187 | { |
| 188 | return -ENODEV; |
| 189 | } |
| 190 | |
| 191 | #endif |
| 192 | |
| 193 | #endif |