Laurent Pinchart | d25a2a1 | 2014-04-02 12:47:37 +0200 | [diff] [blame] | 1 | /* |
| 2 | * IPMMU VMSA |
| 3 | * |
| 4 | * Copyright (C) 2014 Renesas Electronics Corporation |
| 5 | * |
| 6 | * This program is free software; you can redistribute it and/or modify |
| 7 | * it under the terms of the GNU General Public License as published by |
| 8 | * the Free Software Foundation; version 2 of the License. |
| 9 | */ |
| 10 | |
Magnus Damm | dbb7069 | 2017-05-17 19:06:38 +0900 | [diff] [blame] | 11 | #include <linux/bitmap.h> |
Laurent Pinchart | d25a2a1 | 2014-04-02 12:47:37 +0200 | [diff] [blame] | 12 | #include <linux/delay.h> |
Magnus Damm | 3ae4729 | 2017-05-17 19:07:10 +0900 | [diff] [blame] | 13 | #include <linux/dma-iommu.h> |
Laurent Pinchart | d25a2a1 | 2014-04-02 12:47:37 +0200 | [diff] [blame] | 14 | #include <linux/dma-mapping.h> |
| 15 | #include <linux/err.h> |
| 16 | #include <linux/export.h> |
| 17 | #include <linux/interrupt.h> |
| 18 | #include <linux/io.h> |
| 19 | #include <linux/iommu.h> |
| 20 | #include <linux/module.h> |
Laurent Pinchart | 275f505 | 2014-03-17 01:02:46 +0100 | [diff] [blame] | 21 | #include <linux/of.h> |
Magnus Damm | 7b2d596 | 2017-07-17 22:05:41 +0900 | [diff] [blame] | 22 | #include <linux/of_platform.h> |
Laurent Pinchart | d25a2a1 | 2014-04-02 12:47:37 +0200 | [diff] [blame] | 23 | #include <linux/platform_device.h> |
| 24 | #include <linux/sizes.h> |
| 25 | #include <linux/slab.h> |
| 26 | |
Magnus Damm | 3ae4729 | 2017-05-17 19:07:10 +0900 | [diff] [blame] | 27 | #if defined(CONFIG_ARM) && !defined(CONFIG_IOMMU_DMA) |
Laurent Pinchart | d25a2a1 | 2014-04-02 12:47:37 +0200 | [diff] [blame] | 28 | #include <asm/dma-iommu.h> |
| 29 | #include <asm/pgalloc.h> |
Magnus Damm | 3ae4729 | 2017-05-17 19:07:10 +0900 | [diff] [blame] | 30 | #endif |
Laurent Pinchart | d25a2a1 | 2014-04-02 12:47:37 +0200 | [diff] [blame] | 31 | |
Laurent Pinchart | f20ed39 | 2015-01-20 18:30:04 +0200 | [diff] [blame] | 32 | #include "io-pgtable.h" |
| 33 | |
Magnus Damm | dbb7069 | 2017-05-17 19:06:38 +0900 | [diff] [blame] | 34 | #define IPMMU_CTX_MAX 1 |
| 35 | |
Laurent Pinchart | d25a2a1 | 2014-04-02 12:47:37 +0200 | [diff] [blame] | 36 | struct ipmmu_vmsa_device { |
| 37 | struct device *dev; |
| 38 | void __iomem *base; |
Magnus Damm | 01da21e | 2017-07-17 22:05:10 +0900 | [diff] [blame] | 39 | struct iommu_device iommu; |
Laurent Pinchart | d25a2a1 | 2014-04-02 12:47:37 +0200 | [diff] [blame] | 40 | |
Laurent Pinchart | d25a2a1 | 2014-04-02 12:47:37 +0200 | [diff] [blame] | 41 | unsigned int num_utlbs; |
Magnus Damm | dbb7069 | 2017-05-17 19:06:38 +0900 | [diff] [blame] | 42 | spinlock_t lock; /* Protects ctx and domains[] */ |
| 43 | DECLARE_BITMAP(ctx, IPMMU_CTX_MAX); |
| 44 | struct ipmmu_vmsa_domain *domains[IPMMU_CTX_MAX]; |
Laurent Pinchart | d25a2a1 | 2014-04-02 12:47:37 +0200 | [diff] [blame] | 45 | |
| 46 | struct dma_iommu_mapping *mapping; |
| 47 | }; |
| 48 | |
| 49 | struct ipmmu_vmsa_domain { |
| 50 | struct ipmmu_vmsa_device *mmu; |
Joerg Roedel | 5914c5f | 2015-03-26 13:43:16 +0100 | [diff] [blame] | 51 | struct iommu_domain io_domain; |
Laurent Pinchart | d25a2a1 | 2014-04-02 12:47:37 +0200 | [diff] [blame] | 52 | |
Laurent Pinchart | f20ed39 | 2015-01-20 18:30:04 +0200 | [diff] [blame] | 53 | struct io_pgtable_cfg cfg; |
| 54 | struct io_pgtable_ops *iop; |
| 55 | |
Laurent Pinchart | d25a2a1 | 2014-04-02 12:47:37 +0200 | [diff] [blame] | 56 | unsigned int context_id; |
| 57 | spinlock_t lock; /* Protects mappings */ |
Laurent Pinchart | d25a2a1 | 2014-04-02 12:47:37 +0200 | [diff] [blame] | 58 | }; |
| 59 | |
Magnus Damm | 0fbc8b0 | 2017-05-17 19:07:20 +0900 | [diff] [blame] | 60 | struct ipmmu_vmsa_iommu_priv { |
Laurent Pinchart | 192d204 | 2014-05-15 12:40:42 +0200 | [diff] [blame] | 61 | struct ipmmu_vmsa_device *mmu; |
Magnus Damm | 3ae4729 | 2017-05-17 19:07:10 +0900 | [diff] [blame] | 62 | struct device *dev; |
| 63 | struct list_head list; |
Laurent Pinchart | 192d204 | 2014-05-15 12:40:42 +0200 | [diff] [blame] | 64 | }; |
| 65 | |
Joerg Roedel | 5914c5f | 2015-03-26 13:43:16 +0100 | [diff] [blame] | 66 | static struct ipmmu_vmsa_domain *to_vmsa_domain(struct iommu_domain *dom) |
| 67 | { |
| 68 | return container_of(dom, struct ipmmu_vmsa_domain, io_domain); |
| 69 | } |
| 70 | |
Magnus Damm | 0fbc8b0 | 2017-05-17 19:07:20 +0900 | [diff] [blame] | 71 | static struct ipmmu_vmsa_iommu_priv *to_priv(struct device *dev) |
| 72 | { |
Robin Murphy | 3c49ed3 | 2017-07-17 22:05:31 +0900 | [diff] [blame] | 73 | return dev->iommu_fwspec ? dev->iommu_fwspec->iommu_priv : NULL; |
Magnus Damm | 0fbc8b0 | 2017-05-17 19:07:20 +0900 | [diff] [blame] | 74 | } |
| 75 | |
Laurent Pinchart | d25a2a1 | 2014-04-02 12:47:37 +0200 | [diff] [blame] | 76 | #define TLB_LOOP_TIMEOUT 100 /* 100us */ |
| 77 | |
| 78 | /* ----------------------------------------------------------------------------- |
| 79 | * Registers Definition |
| 80 | */ |
| 81 | |
Laurent Pinchart | 275f505 | 2014-03-17 01:02:46 +0100 | [diff] [blame] | 82 | #define IM_NS_ALIAS_OFFSET 0x800 |
| 83 | |
Laurent Pinchart | d25a2a1 | 2014-04-02 12:47:37 +0200 | [diff] [blame] | 84 | #define IM_CTX_SIZE 0x40 |
| 85 | |
| 86 | #define IMCTR 0x0000 |
| 87 | #define IMCTR_TRE (1 << 17) |
| 88 | #define IMCTR_AFE (1 << 16) |
| 89 | #define IMCTR_RTSEL_MASK (3 << 4) |
| 90 | #define IMCTR_RTSEL_SHIFT 4 |
| 91 | #define IMCTR_TREN (1 << 3) |
| 92 | #define IMCTR_INTEN (1 << 2) |
| 93 | #define IMCTR_FLUSH (1 << 1) |
| 94 | #define IMCTR_MMUEN (1 << 0) |
| 95 | |
| 96 | #define IMCAAR 0x0004 |
| 97 | |
| 98 | #define IMTTBCR 0x0008 |
| 99 | #define IMTTBCR_EAE (1 << 31) |
| 100 | #define IMTTBCR_PMB (1 << 30) |
| 101 | #define IMTTBCR_SH1_NON_SHAREABLE (0 << 28) |
| 102 | #define IMTTBCR_SH1_OUTER_SHAREABLE (2 << 28) |
| 103 | #define IMTTBCR_SH1_INNER_SHAREABLE (3 << 28) |
| 104 | #define IMTTBCR_SH1_MASK (3 << 28) |
| 105 | #define IMTTBCR_ORGN1_NC (0 << 26) |
| 106 | #define IMTTBCR_ORGN1_WB_WA (1 << 26) |
| 107 | #define IMTTBCR_ORGN1_WT (2 << 26) |
| 108 | #define IMTTBCR_ORGN1_WB (3 << 26) |
| 109 | #define IMTTBCR_ORGN1_MASK (3 << 26) |
| 110 | #define IMTTBCR_IRGN1_NC (0 << 24) |
| 111 | #define IMTTBCR_IRGN1_WB_WA (1 << 24) |
| 112 | #define IMTTBCR_IRGN1_WT (2 << 24) |
| 113 | #define IMTTBCR_IRGN1_WB (3 << 24) |
| 114 | #define IMTTBCR_IRGN1_MASK (3 << 24) |
| 115 | #define IMTTBCR_TSZ1_MASK (7 << 16) |
| 116 | #define IMTTBCR_TSZ1_SHIFT 16 |
| 117 | #define IMTTBCR_SH0_NON_SHAREABLE (0 << 12) |
| 118 | #define IMTTBCR_SH0_OUTER_SHAREABLE (2 << 12) |
| 119 | #define IMTTBCR_SH0_INNER_SHAREABLE (3 << 12) |
| 120 | #define IMTTBCR_SH0_MASK (3 << 12) |
| 121 | #define IMTTBCR_ORGN0_NC (0 << 10) |
| 122 | #define IMTTBCR_ORGN0_WB_WA (1 << 10) |
| 123 | #define IMTTBCR_ORGN0_WT (2 << 10) |
| 124 | #define IMTTBCR_ORGN0_WB (3 << 10) |
| 125 | #define IMTTBCR_ORGN0_MASK (3 << 10) |
| 126 | #define IMTTBCR_IRGN0_NC (0 << 8) |
| 127 | #define IMTTBCR_IRGN0_WB_WA (1 << 8) |
| 128 | #define IMTTBCR_IRGN0_WT (2 << 8) |
| 129 | #define IMTTBCR_IRGN0_WB (3 << 8) |
| 130 | #define IMTTBCR_IRGN0_MASK (3 << 8) |
| 131 | #define IMTTBCR_SL0_LVL_2 (0 << 4) |
| 132 | #define IMTTBCR_SL0_LVL_1 (1 << 4) |
| 133 | #define IMTTBCR_TSZ0_MASK (7 << 0) |
| 134 | #define IMTTBCR_TSZ0_SHIFT O |
| 135 | |
| 136 | #define IMBUSCR 0x000c |
| 137 | #define IMBUSCR_DVM (1 << 2) |
| 138 | #define IMBUSCR_BUSSEL_SYS (0 << 0) |
| 139 | #define IMBUSCR_BUSSEL_CCI (1 << 0) |
| 140 | #define IMBUSCR_BUSSEL_IMCAAR (2 << 0) |
| 141 | #define IMBUSCR_BUSSEL_CCI_IMCAAR (3 << 0) |
| 142 | #define IMBUSCR_BUSSEL_MASK (3 << 0) |
| 143 | |
| 144 | #define IMTTLBR0 0x0010 |
| 145 | #define IMTTUBR0 0x0014 |
| 146 | #define IMTTLBR1 0x0018 |
| 147 | #define IMTTUBR1 0x001c |
| 148 | |
| 149 | #define IMSTR 0x0020 |
| 150 | #define IMSTR_ERRLVL_MASK (3 << 12) |
| 151 | #define IMSTR_ERRLVL_SHIFT 12 |
| 152 | #define IMSTR_ERRCODE_TLB_FORMAT (1 << 8) |
| 153 | #define IMSTR_ERRCODE_ACCESS_PERM (4 << 8) |
| 154 | #define IMSTR_ERRCODE_SECURE_ACCESS (5 << 8) |
| 155 | #define IMSTR_ERRCODE_MASK (7 << 8) |
| 156 | #define IMSTR_MHIT (1 << 4) |
| 157 | #define IMSTR_ABORT (1 << 2) |
| 158 | #define IMSTR_PF (1 << 1) |
| 159 | #define IMSTR_TF (1 << 0) |
| 160 | |
| 161 | #define IMMAIR0 0x0028 |
| 162 | #define IMMAIR1 0x002c |
| 163 | #define IMMAIR_ATTR_MASK 0xff |
| 164 | #define IMMAIR_ATTR_DEVICE 0x04 |
| 165 | #define IMMAIR_ATTR_NC 0x44 |
| 166 | #define IMMAIR_ATTR_WBRWA 0xff |
| 167 | #define IMMAIR_ATTR_SHIFT(n) ((n) << 3) |
| 168 | #define IMMAIR_ATTR_IDX_NC 0 |
| 169 | #define IMMAIR_ATTR_IDX_WBRWA 1 |
| 170 | #define IMMAIR_ATTR_IDX_DEV 2 |
| 171 | |
| 172 | #define IMEAR 0x0030 |
| 173 | |
| 174 | #define IMPCTR 0x0200 |
| 175 | #define IMPSTR 0x0208 |
| 176 | #define IMPEAR 0x020c |
| 177 | #define IMPMBA(n) (0x0280 + ((n) * 4)) |
| 178 | #define IMPMBD(n) (0x02c0 + ((n) * 4)) |
| 179 | |
| 180 | #define IMUCTR(n) (0x0300 + ((n) * 16)) |
| 181 | #define IMUCTR_FIXADDEN (1 << 31) |
| 182 | #define IMUCTR_FIXADD_MASK (0xff << 16) |
| 183 | #define IMUCTR_FIXADD_SHIFT 16 |
| 184 | #define IMUCTR_TTSEL_MMU(n) ((n) << 4) |
| 185 | #define IMUCTR_TTSEL_PMB (8 << 4) |
| 186 | #define IMUCTR_TTSEL_MASK (15 << 4) |
| 187 | #define IMUCTR_FLUSH (1 << 1) |
| 188 | #define IMUCTR_MMUEN (1 << 0) |
| 189 | |
| 190 | #define IMUASID(n) (0x0308 + ((n) * 16)) |
| 191 | #define IMUASID_ASID8_MASK (0xff << 8) |
| 192 | #define IMUASID_ASID8_SHIFT 8 |
| 193 | #define IMUASID_ASID0_MASK (0xff << 0) |
| 194 | #define IMUASID_ASID0_SHIFT 0 |
| 195 | |
| 196 | /* ----------------------------------------------------------------------------- |
Laurent Pinchart | d25a2a1 | 2014-04-02 12:47:37 +0200 | [diff] [blame] | 197 | * Read/Write Access |
| 198 | */ |
| 199 | |
| 200 | static u32 ipmmu_read(struct ipmmu_vmsa_device *mmu, unsigned int offset) |
| 201 | { |
| 202 | return ioread32(mmu->base + offset); |
| 203 | } |
| 204 | |
| 205 | static void ipmmu_write(struct ipmmu_vmsa_device *mmu, unsigned int offset, |
| 206 | u32 data) |
| 207 | { |
| 208 | iowrite32(data, mmu->base + offset); |
| 209 | } |
| 210 | |
| 211 | static u32 ipmmu_ctx_read(struct ipmmu_vmsa_domain *domain, unsigned int reg) |
| 212 | { |
| 213 | return ipmmu_read(domain->mmu, domain->context_id * IM_CTX_SIZE + reg); |
| 214 | } |
| 215 | |
| 216 | static void ipmmu_ctx_write(struct ipmmu_vmsa_domain *domain, unsigned int reg, |
| 217 | u32 data) |
| 218 | { |
| 219 | ipmmu_write(domain->mmu, domain->context_id * IM_CTX_SIZE + reg, data); |
| 220 | } |
| 221 | |
| 222 | /* ----------------------------------------------------------------------------- |
| 223 | * TLB and microTLB Management |
| 224 | */ |
| 225 | |
| 226 | /* Wait for any pending TLB invalidations to complete */ |
| 227 | static void ipmmu_tlb_sync(struct ipmmu_vmsa_domain *domain) |
| 228 | { |
| 229 | unsigned int count = 0; |
| 230 | |
| 231 | while (ipmmu_ctx_read(domain, IMCTR) & IMCTR_FLUSH) { |
| 232 | cpu_relax(); |
| 233 | if (++count == TLB_LOOP_TIMEOUT) { |
| 234 | dev_err_ratelimited(domain->mmu->dev, |
| 235 | "TLB sync timed out -- MMU may be deadlocked\n"); |
| 236 | return; |
| 237 | } |
| 238 | udelay(1); |
| 239 | } |
| 240 | } |
| 241 | |
| 242 | static void ipmmu_tlb_invalidate(struct ipmmu_vmsa_domain *domain) |
| 243 | { |
| 244 | u32 reg; |
| 245 | |
| 246 | reg = ipmmu_ctx_read(domain, IMCTR); |
| 247 | reg |= IMCTR_FLUSH; |
| 248 | ipmmu_ctx_write(domain, IMCTR, reg); |
| 249 | |
| 250 | ipmmu_tlb_sync(domain); |
| 251 | } |
| 252 | |
| 253 | /* |
| 254 | * Enable MMU translation for the microTLB. |
| 255 | */ |
| 256 | static void ipmmu_utlb_enable(struct ipmmu_vmsa_domain *domain, |
Laurent Pinchart | 192d204 | 2014-05-15 12:40:42 +0200 | [diff] [blame] | 257 | unsigned int utlb) |
Laurent Pinchart | d25a2a1 | 2014-04-02 12:47:37 +0200 | [diff] [blame] | 258 | { |
| 259 | struct ipmmu_vmsa_device *mmu = domain->mmu; |
| 260 | |
Laurent Pinchart | 192d204 | 2014-05-15 12:40:42 +0200 | [diff] [blame] | 261 | /* |
| 262 | * TODO: Reference-count the microTLB as several bus masters can be |
| 263 | * connected to the same microTLB. |
| 264 | */ |
| 265 | |
Laurent Pinchart | d25a2a1 | 2014-04-02 12:47:37 +0200 | [diff] [blame] | 266 | /* TODO: What should we set the ASID to ? */ |
Laurent Pinchart | 192d204 | 2014-05-15 12:40:42 +0200 | [diff] [blame] | 267 | ipmmu_write(mmu, IMUASID(utlb), 0); |
Laurent Pinchart | d25a2a1 | 2014-04-02 12:47:37 +0200 | [diff] [blame] | 268 | /* TODO: Do we need to flush the microTLB ? */ |
Laurent Pinchart | 192d204 | 2014-05-15 12:40:42 +0200 | [diff] [blame] | 269 | ipmmu_write(mmu, IMUCTR(utlb), |
Laurent Pinchart | d25a2a1 | 2014-04-02 12:47:37 +0200 | [diff] [blame] | 270 | IMUCTR_TTSEL_MMU(domain->context_id) | IMUCTR_FLUSH | |
| 271 | IMUCTR_MMUEN); |
| 272 | } |
| 273 | |
| 274 | /* |
| 275 | * Disable MMU translation for the microTLB. |
| 276 | */ |
| 277 | static void ipmmu_utlb_disable(struct ipmmu_vmsa_domain *domain, |
Laurent Pinchart | 192d204 | 2014-05-15 12:40:42 +0200 | [diff] [blame] | 278 | unsigned int utlb) |
Laurent Pinchart | d25a2a1 | 2014-04-02 12:47:37 +0200 | [diff] [blame] | 279 | { |
| 280 | struct ipmmu_vmsa_device *mmu = domain->mmu; |
| 281 | |
Laurent Pinchart | 192d204 | 2014-05-15 12:40:42 +0200 | [diff] [blame] | 282 | ipmmu_write(mmu, IMUCTR(utlb), 0); |
Laurent Pinchart | d25a2a1 | 2014-04-02 12:47:37 +0200 | [diff] [blame] | 283 | } |
| 284 | |
Laurent Pinchart | f20ed39 | 2015-01-20 18:30:04 +0200 | [diff] [blame] | 285 | static void ipmmu_tlb_flush_all(void *cookie) |
Laurent Pinchart | d25a2a1 | 2014-04-02 12:47:37 +0200 | [diff] [blame] | 286 | { |
Laurent Pinchart | f20ed39 | 2015-01-20 18:30:04 +0200 | [diff] [blame] | 287 | struct ipmmu_vmsa_domain *domain = cookie; |
| 288 | |
| 289 | ipmmu_tlb_invalidate(domain); |
| 290 | } |
| 291 | |
Robin Murphy | 06c610e | 2015-12-07 18:18:53 +0000 | [diff] [blame] | 292 | static void ipmmu_tlb_add_flush(unsigned long iova, size_t size, |
| 293 | size_t granule, bool leaf, void *cookie) |
Laurent Pinchart | f20ed39 | 2015-01-20 18:30:04 +0200 | [diff] [blame] | 294 | { |
| 295 | /* The hardware doesn't support selective TLB flush. */ |
| 296 | } |
| 297 | |
Bhumika Goyal | 8da4af9 | 2017-08-28 23:47:27 +0530 | [diff] [blame] | 298 | static const struct iommu_gather_ops ipmmu_gather_ops = { |
Laurent Pinchart | f20ed39 | 2015-01-20 18:30:04 +0200 | [diff] [blame] | 299 | .tlb_flush_all = ipmmu_tlb_flush_all, |
| 300 | .tlb_add_flush = ipmmu_tlb_add_flush, |
| 301 | .tlb_sync = ipmmu_tlb_flush_all, |
Laurent Pinchart | f20ed39 | 2015-01-20 18:30:04 +0200 | [diff] [blame] | 302 | }; |
| 303 | |
Laurent Pinchart | d25a2a1 | 2014-04-02 12:47:37 +0200 | [diff] [blame] | 304 | /* ----------------------------------------------------------------------------- |
| 305 | * Domain/Context Management |
| 306 | */ |
| 307 | |
Magnus Damm | dbb7069 | 2017-05-17 19:06:38 +0900 | [diff] [blame] | 308 | static int ipmmu_domain_allocate_context(struct ipmmu_vmsa_device *mmu, |
| 309 | struct ipmmu_vmsa_domain *domain) |
| 310 | { |
| 311 | unsigned long flags; |
| 312 | int ret; |
| 313 | |
| 314 | spin_lock_irqsave(&mmu->lock, flags); |
| 315 | |
| 316 | ret = find_first_zero_bit(mmu->ctx, IPMMU_CTX_MAX); |
| 317 | if (ret != IPMMU_CTX_MAX) { |
| 318 | mmu->domains[ret] = domain; |
| 319 | set_bit(ret, mmu->ctx); |
| 320 | } |
| 321 | |
| 322 | spin_unlock_irqrestore(&mmu->lock, flags); |
| 323 | |
| 324 | return ret; |
| 325 | } |
| 326 | |
Oleksandr Tyshchenko | a175a67 | 2017-08-23 17:31:42 +0300 | [diff] [blame] | 327 | static void ipmmu_domain_free_context(struct ipmmu_vmsa_device *mmu, |
| 328 | unsigned int context_id) |
| 329 | { |
| 330 | unsigned long flags; |
| 331 | |
| 332 | spin_lock_irqsave(&mmu->lock, flags); |
| 333 | |
| 334 | clear_bit(context_id, mmu->ctx); |
| 335 | mmu->domains[context_id] = NULL; |
| 336 | |
| 337 | spin_unlock_irqrestore(&mmu->lock, flags); |
| 338 | } |
| 339 | |
Laurent Pinchart | d25a2a1 | 2014-04-02 12:47:37 +0200 | [diff] [blame] | 340 | static int ipmmu_domain_init_context(struct ipmmu_vmsa_domain *domain) |
| 341 | { |
Geert Uytterhoeven | f64232e | 2015-12-22 20:01:06 +0100 | [diff] [blame] | 342 | u64 ttbr; |
Magnus Damm | dbb7069 | 2017-05-17 19:06:38 +0900 | [diff] [blame] | 343 | int ret; |
Laurent Pinchart | f20ed39 | 2015-01-20 18:30:04 +0200 | [diff] [blame] | 344 | |
| 345 | /* |
| 346 | * Allocate the page table operations. |
| 347 | * |
| 348 | * VMSA states in section B3.6.3 "Control of Secure or Non-secure memory |
| 349 | * access, Long-descriptor format" that the NStable bit being set in a |
| 350 | * table descriptor will result in the NStable and NS bits of all child |
| 351 | * entries being ignored and considered as being set. The IPMMU seems |
| 352 | * not to comply with this, as it generates a secure access page fault |
| 353 | * if any of the NStable and NS bits isn't set when running in |
| 354 | * non-secure mode. |
| 355 | */ |
| 356 | domain->cfg.quirks = IO_PGTABLE_QUIRK_ARM_NS; |
Magnus Damm | 26b6aec | 2017-05-17 19:07:41 +0900 | [diff] [blame] | 357 | domain->cfg.pgsize_bitmap = SZ_1G | SZ_2M | SZ_4K; |
Laurent Pinchart | f20ed39 | 2015-01-20 18:30:04 +0200 | [diff] [blame] | 358 | domain->cfg.ias = 32; |
| 359 | domain->cfg.oas = 40; |
| 360 | domain->cfg.tlb = &ipmmu_gather_ops; |
Geert Uytterhoeven | 3b6bb5b | 2017-01-31 12:17:07 +0100 | [diff] [blame] | 361 | domain->io_domain.geometry.aperture_end = DMA_BIT_MASK(32); |
| 362 | domain->io_domain.geometry.force_aperture = true; |
Robin Murphy | ff2ed96 | 2015-07-29 19:46:08 +0100 | [diff] [blame] | 363 | /* |
| 364 | * TODO: Add support for coherent walk through CCI with DVM and remove |
| 365 | * cache handling. For now, delegate it to the io-pgtable code. |
| 366 | */ |
| 367 | domain->cfg.iommu_dev = domain->mmu->dev; |
Laurent Pinchart | f20ed39 | 2015-01-20 18:30:04 +0200 | [diff] [blame] | 368 | |
Laurent Pinchart | d25a2a1 | 2014-04-02 12:47:37 +0200 | [diff] [blame] | 369 | /* |
Magnus Damm | dbb7069 | 2017-05-17 19:06:38 +0900 | [diff] [blame] | 370 | * Find an unused context. |
Laurent Pinchart | d25a2a1 | 2014-04-02 12:47:37 +0200 | [diff] [blame] | 371 | */ |
Magnus Damm | dbb7069 | 2017-05-17 19:06:38 +0900 | [diff] [blame] | 372 | ret = ipmmu_domain_allocate_context(domain->mmu, domain); |
Oleksandr Tyshchenko | a175a67 | 2017-08-23 17:31:42 +0300 | [diff] [blame] | 373 | if (ret == IPMMU_CTX_MAX) |
Magnus Damm | dbb7069 | 2017-05-17 19:06:38 +0900 | [diff] [blame] | 374 | return -EBUSY; |
Magnus Damm | dbb7069 | 2017-05-17 19:06:38 +0900 | [diff] [blame] | 375 | |
| 376 | domain->context_id = ret; |
Laurent Pinchart | d25a2a1 | 2014-04-02 12:47:37 +0200 | [diff] [blame] | 377 | |
Oleksandr Tyshchenko | a175a67 | 2017-08-23 17:31:42 +0300 | [diff] [blame] | 378 | domain->iop = alloc_io_pgtable_ops(ARM_32_LPAE_S1, &domain->cfg, |
| 379 | domain); |
| 380 | if (!domain->iop) { |
| 381 | ipmmu_domain_free_context(domain->mmu, domain->context_id); |
| 382 | return -EINVAL; |
| 383 | } |
| 384 | |
Laurent Pinchart | d25a2a1 | 2014-04-02 12:47:37 +0200 | [diff] [blame] | 385 | /* TTBR0 */ |
Laurent Pinchart | f20ed39 | 2015-01-20 18:30:04 +0200 | [diff] [blame] | 386 | ttbr = domain->cfg.arm_lpae_s1_cfg.ttbr[0]; |
Laurent Pinchart | d25a2a1 | 2014-04-02 12:47:37 +0200 | [diff] [blame] | 387 | ipmmu_ctx_write(domain, IMTTLBR0, ttbr); |
| 388 | ipmmu_ctx_write(domain, IMTTUBR0, ttbr >> 32); |
| 389 | |
| 390 | /* |
| 391 | * TTBCR |
| 392 | * We use long descriptors with inner-shareable WBWA tables and allocate |
| 393 | * the whole 32-bit VA space to TTBR0. |
| 394 | */ |
| 395 | ipmmu_ctx_write(domain, IMTTBCR, IMTTBCR_EAE | |
| 396 | IMTTBCR_SH0_INNER_SHAREABLE | IMTTBCR_ORGN0_WB_WA | |
| 397 | IMTTBCR_IRGN0_WB_WA | IMTTBCR_SL0_LVL_1); |
| 398 | |
Laurent Pinchart | f20ed39 | 2015-01-20 18:30:04 +0200 | [diff] [blame] | 399 | /* MAIR0 */ |
| 400 | ipmmu_ctx_write(domain, IMMAIR0, domain->cfg.arm_lpae_s1_cfg.mair[0]); |
Laurent Pinchart | d25a2a1 | 2014-04-02 12:47:37 +0200 | [diff] [blame] | 401 | |
| 402 | /* IMBUSCR */ |
| 403 | ipmmu_ctx_write(domain, IMBUSCR, |
| 404 | ipmmu_ctx_read(domain, IMBUSCR) & |
| 405 | ~(IMBUSCR_DVM | IMBUSCR_BUSSEL_MASK)); |
| 406 | |
| 407 | /* |
| 408 | * IMSTR |
| 409 | * Clear all interrupt flags. |
| 410 | */ |
| 411 | ipmmu_ctx_write(domain, IMSTR, ipmmu_ctx_read(domain, IMSTR)); |
| 412 | |
| 413 | /* |
| 414 | * IMCTR |
| 415 | * Enable the MMU and interrupt generation. The long-descriptor |
| 416 | * translation table format doesn't use TEX remapping. Don't enable AF |
| 417 | * software management as we have no use for it. Flush the TLB as |
| 418 | * required when modifying the context registers. |
| 419 | */ |
| 420 | ipmmu_ctx_write(domain, IMCTR, IMCTR_INTEN | IMCTR_FLUSH | IMCTR_MMUEN); |
| 421 | |
| 422 | return 0; |
| 423 | } |
| 424 | |
| 425 | static void ipmmu_domain_destroy_context(struct ipmmu_vmsa_domain *domain) |
| 426 | { |
| 427 | /* |
| 428 | * Disable the context. Flush the TLB as required when modifying the |
| 429 | * context registers. |
| 430 | * |
| 431 | * TODO: Is TLB flush really needed ? |
| 432 | */ |
| 433 | ipmmu_ctx_write(domain, IMCTR, IMCTR_FLUSH); |
| 434 | ipmmu_tlb_sync(domain); |
Magnus Damm | dbb7069 | 2017-05-17 19:06:38 +0900 | [diff] [blame] | 435 | ipmmu_domain_free_context(domain->mmu, domain->context_id); |
Laurent Pinchart | d25a2a1 | 2014-04-02 12:47:37 +0200 | [diff] [blame] | 436 | } |
| 437 | |
| 438 | /* ----------------------------------------------------------------------------- |
| 439 | * Fault Handling |
| 440 | */ |
| 441 | |
| 442 | static irqreturn_t ipmmu_domain_irq(struct ipmmu_vmsa_domain *domain) |
| 443 | { |
| 444 | const u32 err_mask = IMSTR_MHIT | IMSTR_ABORT | IMSTR_PF | IMSTR_TF; |
| 445 | struct ipmmu_vmsa_device *mmu = domain->mmu; |
| 446 | u32 status; |
| 447 | u32 iova; |
| 448 | |
| 449 | status = ipmmu_ctx_read(domain, IMSTR); |
| 450 | if (!(status & err_mask)) |
| 451 | return IRQ_NONE; |
| 452 | |
| 453 | iova = ipmmu_ctx_read(domain, IMEAR); |
| 454 | |
| 455 | /* |
| 456 | * Clear the error status flags. Unlike traditional interrupt flag |
| 457 | * registers that must be cleared by writing 1, this status register |
| 458 | * seems to require 0. The error address register must be read before, |
| 459 | * otherwise its value will be 0. |
| 460 | */ |
| 461 | ipmmu_ctx_write(domain, IMSTR, 0); |
| 462 | |
| 463 | /* Log fatal errors. */ |
| 464 | if (status & IMSTR_MHIT) |
| 465 | dev_err_ratelimited(mmu->dev, "Multiple TLB hits @0x%08x\n", |
| 466 | iova); |
| 467 | if (status & IMSTR_ABORT) |
| 468 | dev_err_ratelimited(mmu->dev, "Page Table Walk Abort @0x%08x\n", |
| 469 | iova); |
| 470 | |
| 471 | if (!(status & (IMSTR_PF | IMSTR_TF))) |
| 472 | return IRQ_NONE; |
| 473 | |
| 474 | /* |
| 475 | * Try to handle page faults and translation faults. |
| 476 | * |
| 477 | * TODO: We need to look up the faulty device based on the I/O VA. Use |
| 478 | * the IOMMU device for now. |
| 479 | */ |
Joerg Roedel | 5914c5f | 2015-03-26 13:43:16 +0100 | [diff] [blame] | 480 | if (!report_iommu_fault(&domain->io_domain, mmu->dev, iova, 0)) |
Laurent Pinchart | d25a2a1 | 2014-04-02 12:47:37 +0200 | [diff] [blame] | 481 | return IRQ_HANDLED; |
| 482 | |
| 483 | dev_err_ratelimited(mmu->dev, |
| 484 | "Unhandled fault: status 0x%08x iova 0x%08x\n", |
| 485 | status, iova); |
| 486 | |
| 487 | return IRQ_HANDLED; |
| 488 | } |
| 489 | |
| 490 | static irqreturn_t ipmmu_irq(int irq, void *dev) |
| 491 | { |
| 492 | struct ipmmu_vmsa_device *mmu = dev; |
Magnus Damm | dbb7069 | 2017-05-17 19:06:38 +0900 | [diff] [blame] | 493 | irqreturn_t status = IRQ_NONE; |
| 494 | unsigned int i; |
| 495 | unsigned long flags; |
Laurent Pinchart | d25a2a1 | 2014-04-02 12:47:37 +0200 | [diff] [blame] | 496 | |
Magnus Damm | dbb7069 | 2017-05-17 19:06:38 +0900 | [diff] [blame] | 497 | spin_lock_irqsave(&mmu->lock, flags); |
Laurent Pinchart | d25a2a1 | 2014-04-02 12:47:37 +0200 | [diff] [blame] | 498 | |
Magnus Damm | dbb7069 | 2017-05-17 19:06:38 +0900 | [diff] [blame] | 499 | /* |
| 500 | * Check interrupts for all active contexts. |
| 501 | */ |
| 502 | for (i = 0; i < IPMMU_CTX_MAX; i++) { |
| 503 | if (!mmu->domains[i]) |
| 504 | continue; |
| 505 | if (ipmmu_domain_irq(mmu->domains[i]) == IRQ_HANDLED) |
| 506 | status = IRQ_HANDLED; |
| 507 | } |
Laurent Pinchart | d25a2a1 | 2014-04-02 12:47:37 +0200 | [diff] [blame] | 508 | |
Magnus Damm | dbb7069 | 2017-05-17 19:06:38 +0900 | [diff] [blame] | 509 | spin_unlock_irqrestore(&mmu->lock, flags); |
| 510 | |
| 511 | return status; |
Laurent Pinchart | d25a2a1 | 2014-04-02 12:47:37 +0200 | [diff] [blame] | 512 | } |
| 513 | |
| 514 | /* ----------------------------------------------------------------------------- |
Laurent Pinchart | d25a2a1 | 2014-04-02 12:47:37 +0200 | [diff] [blame] | 515 | * IOMMU Operations |
| 516 | */ |
| 517 | |
Magnus Damm | 8e73bf6 | 2017-05-17 19:06:59 +0900 | [diff] [blame] | 518 | static struct iommu_domain *__ipmmu_domain_alloc(unsigned type) |
Laurent Pinchart | d25a2a1 | 2014-04-02 12:47:37 +0200 | [diff] [blame] | 519 | { |
| 520 | struct ipmmu_vmsa_domain *domain; |
| 521 | |
| 522 | domain = kzalloc(sizeof(*domain), GFP_KERNEL); |
| 523 | if (!domain) |
Joerg Roedel | 5914c5f | 2015-03-26 13:43:16 +0100 | [diff] [blame] | 524 | return NULL; |
Laurent Pinchart | d25a2a1 | 2014-04-02 12:47:37 +0200 | [diff] [blame] | 525 | |
| 526 | spin_lock_init(&domain->lock); |
| 527 | |
Joerg Roedel | 5914c5f | 2015-03-26 13:43:16 +0100 | [diff] [blame] | 528 | return &domain->io_domain; |
Laurent Pinchart | d25a2a1 | 2014-04-02 12:47:37 +0200 | [diff] [blame] | 529 | } |
| 530 | |
Robin Murphy | 1c7e7c0 | 2017-10-13 19:23:39 +0100 | [diff] [blame^] | 531 | static struct iommu_domain *ipmmu_domain_alloc(unsigned type) |
| 532 | { |
| 533 | struct iommu_domain *io_domain = NULL; |
| 534 | |
| 535 | switch (type) { |
| 536 | case IOMMU_DOMAIN_UNMANAGED: |
| 537 | io_domain = __ipmmu_domain_alloc(type); |
| 538 | break; |
| 539 | |
| 540 | case IOMMU_DOMAIN_DMA: |
| 541 | io_domain = __ipmmu_domain_alloc(type); |
| 542 | if (io_domain && iommu_get_dma_cookie(io_domain)) { |
| 543 | kfree(io_domain); |
| 544 | io_domain = NULL; |
| 545 | } |
| 546 | break; |
| 547 | } |
| 548 | |
| 549 | return io_domain; |
| 550 | } |
| 551 | |
Joerg Roedel | 5914c5f | 2015-03-26 13:43:16 +0100 | [diff] [blame] | 552 | static void ipmmu_domain_free(struct iommu_domain *io_domain) |
Laurent Pinchart | d25a2a1 | 2014-04-02 12:47:37 +0200 | [diff] [blame] | 553 | { |
Joerg Roedel | 5914c5f | 2015-03-26 13:43:16 +0100 | [diff] [blame] | 554 | struct ipmmu_vmsa_domain *domain = to_vmsa_domain(io_domain); |
Laurent Pinchart | d25a2a1 | 2014-04-02 12:47:37 +0200 | [diff] [blame] | 555 | |
| 556 | /* |
| 557 | * Free the domain resources. We assume that all devices have already |
| 558 | * been detached. |
| 559 | */ |
Robin Murphy | 1c7e7c0 | 2017-10-13 19:23:39 +0100 | [diff] [blame^] | 560 | iommu_put_dma_cookie(io_domain); |
Laurent Pinchart | d25a2a1 | 2014-04-02 12:47:37 +0200 | [diff] [blame] | 561 | ipmmu_domain_destroy_context(domain); |
Laurent Pinchart | f20ed39 | 2015-01-20 18:30:04 +0200 | [diff] [blame] | 562 | free_io_pgtable_ops(domain->iop); |
Laurent Pinchart | d25a2a1 | 2014-04-02 12:47:37 +0200 | [diff] [blame] | 563 | kfree(domain); |
| 564 | } |
| 565 | |
| 566 | static int ipmmu_attach_device(struct iommu_domain *io_domain, |
| 567 | struct device *dev) |
| 568 | { |
Magnus Damm | 0fbc8b0 | 2017-05-17 19:07:20 +0900 | [diff] [blame] | 569 | struct ipmmu_vmsa_iommu_priv *priv = to_priv(dev); |
Magnus Damm | 7b2d596 | 2017-07-17 22:05:41 +0900 | [diff] [blame] | 570 | struct iommu_fwspec *fwspec = dev->iommu_fwspec; |
Magnus Damm | 0fbc8b0 | 2017-05-17 19:07:20 +0900 | [diff] [blame] | 571 | struct ipmmu_vmsa_device *mmu = priv->mmu; |
Joerg Roedel | 5914c5f | 2015-03-26 13:43:16 +0100 | [diff] [blame] | 572 | struct ipmmu_vmsa_domain *domain = to_vmsa_domain(io_domain); |
Laurent Pinchart | d25a2a1 | 2014-04-02 12:47:37 +0200 | [diff] [blame] | 573 | unsigned long flags; |
Laurent Pinchart | a166d31 | 2014-07-24 01:36:43 +0200 | [diff] [blame] | 574 | unsigned int i; |
Laurent Pinchart | d25a2a1 | 2014-04-02 12:47:37 +0200 | [diff] [blame] | 575 | int ret = 0; |
| 576 | |
Magnus Damm | 7b2d596 | 2017-07-17 22:05:41 +0900 | [diff] [blame] | 577 | if (!priv || !priv->mmu) { |
Laurent Pinchart | d25a2a1 | 2014-04-02 12:47:37 +0200 | [diff] [blame] | 578 | dev_err(dev, "Cannot attach to IPMMU\n"); |
| 579 | return -ENXIO; |
| 580 | } |
| 581 | |
| 582 | spin_lock_irqsave(&domain->lock, flags); |
| 583 | |
| 584 | if (!domain->mmu) { |
| 585 | /* The domain hasn't been used yet, initialize it. */ |
| 586 | domain->mmu = mmu; |
| 587 | ret = ipmmu_domain_init_context(domain); |
| 588 | } else if (domain->mmu != mmu) { |
| 589 | /* |
| 590 | * Something is wrong, we can't attach two devices using |
| 591 | * different IOMMUs to the same domain. |
| 592 | */ |
| 593 | dev_err(dev, "Can't attach IPMMU %s to domain on IPMMU %s\n", |
| 594 | dev_name(mmu->dev), dev_name(domain->mmu->dev)); |
| 595 | ret = -EINVAL; |
Magnus Damm | 3ae4729 | 2017-05-17 19:07:10 +0900 | [diff] [blame] | 596 | } else |
| 597 | dev_info(dev, "Reusing IPMMU context %u\n", domain->context_id); |
Laurent Pinchart | d25a2a1 | 2014-04-02 12:47:37 +0200 | [diff] [blame] | 598 | |
| 599 | spin_unlock_irqrestore(&domain->lock, flags); |
| 600 | |
| 601 | if (ret < 0) |
| 602 | return ret; |
| 603 | |
Magnus Damm | 7b2d596 | 2017-07-17 22:05:41 +0900 | [diff] [blame] | 604 | for (i = 0; i < fwspec->num_ids; ++i) |
| 605 | ipmmu_utlb_enable(domain, fwspec->ids[i]); |
Laurent Pinchart | d25a2a1 | 2014-04-02 12:47:37 +0200 | [diff] [blame] | 606 | |
| 607 | return 0; |
| 608 | } |
| 609 | |
| 610 | static void ipmmu_detach_device(struct iommu_domain *io_domain, |
| 611 | struct device *dev) |
| 612 | { |
Magnus Damm | 7b2d596 | 2017-07-17 22:05:41 +0900 | [diff] [blame] | 613 | struct iommu_fwspec *fwspec = dev->iommu_fwspec; |
Joerg Roedel | 5914c5f | 2015-03-26 13:43:16 +0100 | [diff] [blame] | 614 | struct ipmmu_vmsa_domain *domain = to_vmsa_domain(io_domain); |
Laurent Pinchart | a166d31 | 2014-07-24 01:36:43 +0200 | [diff] [blame] | 615 | unsigned int i; |
Laurent Pinchart | d25a2a1 | 2014-04-02 12:47:37 +0200 | [diff] [blame] | 616 | |
Magnus Damm | 7b2d596 | 2017-07-17 22:05:41 +0900 | [diff] [blame] | 617 | for (i = 0; i < fwspec->num_ids; ++i) |
| 618 | ipmmu_utlb_disable(domain, fwspec->ids[i]); |
Laurent Pinchart | d25a2a1 | 2014-04-02 12:47:37 +0200 | [diff] [blame] | 619 | |
| 620 | /* |
| 621 | * TODO: Optimize by disabling the context when no device is attached. |
| 622 | */ |
| 623 | } |
| 624 | |
| 625 | static int ipmmu_map(struct iommu_domain *io_domain, unsigned long iova, |
| 626 | phys_addr_t paddr, size_t size, int prot) |
| 627 | { |
Joerg Roedel | 5914c5f | 2015-03-26 13:43:16 +0100 | [diff] [blame] | 628 | struct ipmmu_vmsa_domain *domain = to_vmsa_domain(io_domain); |
Laurent Pinchart | d25a2a1 | 2014-04-02 12:47:37 +0200 | [diff] [blame] | 629 | |
| 630 | if (!domain) |
| 631 | return -ENODEV; |
| 632 | |
Laurent Pinchart | f20ed39 | 2015-01-20 18:30:04 +0200 | [diff] [blame] | 633 | return domain->iop->map(domain->iop, iova, paddr, size, prot); |
Laurent Pinchart | d25a2a1 | 2014-04-02 12:47:37 +0200 | [diff] [blame] | 634 | } |
| 635 | |
| 636 | static size_t ipmmu_unmap(struct iommu_domain *io_domain, unsigned long iova, |
| 637 | size_t size) |
| 638 | { |
Joerg Roedel | 5914c5f | 2015-03-26 13:43:16 +0100 | [diff] [blame] | 639 | struct ipmmu_vmsa_domain *domain = to_vmsa_domain(io_domain); |
Laurent Pinchart | d25a2a1 | 2014-04-02 12:47:37 +0200 | [diff] [blame] | 640 | |
Laurent Pinchart | f20ed39 | 2015-01-20 18:30:04 +0200 | [diff] [blame] | 641 | return domain->iop->unmap(domain->iop, iova, size); |
Laurent Pinchart | d25a2a1 | 2014-04-02 12:47:37 +0200 | [diff] [blame] | 642 | } |
| 643 | |
Robin Murphy | 32b1244 | 2017-09-28 15:55:01 +0100 | [diff] [blame] | 644 | static void ipmmu_iotlb_sync(struct iommu_domain *io_domain) |
| 645 | { |
| 646 | struct ipmmu_vmsa_domain *domain = to_vmsa_domain(io_domain); |
| 647 | |
| 648 | if (domain->mmu) |
| 649 | ipmmu_tlb_flush_all(domain); |
| 650 | } |
| 651 | |
Laurent Pinchart | d25a2a1 | 2014-04-02 12:47:37 +0200 | [diff] [blame] | 652 | static phys_addr_t ipmmu_iova_to_phys(struct iommu_domain *io_domain, |
| 653 | dma_addr_t iova) |
| 654 | { |
Joerg Roedel | 5914c5f | 2015-03-26 13:43:16 +0100 | [diff] [blame] | 655 | struct ipmmu_vmsa_domain *domain = to_vmsa_domain(io_domain); |
Laurent Pinchart | d25a2a1 | 2014-04-02 12:47:37 +0200 | [diff] [blame] | 656 | |
| 657 | /* TODO: Is locking needed ? */ |
| 658 | |
Laurent Pinchart | f20ed39 | 2015-01-20 18:30:04 +0200 | [diff] [blame] | 659 | return domain->iop->iova_to_phys(domain->iop, iova); |
Laurent Pinchart | d25a2a1 | 2014-04-02 12:47:37 +0200 | [diff] [blame] | 660 | } |
| 661 | |
Magnus Damm | 7b2d596 | 2017-07-17 22:05:41 +0900 | [diff] [blame] | 662 | static int ipmmu_init_platform_device(struct device *dev, |
| 663 | struct of_phandle_args *args) |
Laurent Pinchart | 192d204 | 2014-05-15 12:40:42 +0200 | [diff] [blame] | 664 | { |
Magnus Damm | 7b2d596 | 2017-07-17 22:05:41 +0900 | [diff] [blame] | 665 | struct platform_device *ipmmu_pdev; |
Magnus Damm | 0fbc8b0 | 2017-05-17 19:07:20 +0900 | [diff] [blame] | 666 | struct ipmmu_vmsa_iommu_priv *priv; |
Laurent Pinchart | d25a2a1 | 2014-04-02 12:47:37 +0200 | [diff] [blame] | 667 | |
Magnus Damm | 7b2d596 | 2017-07-17 22:05:41 +0900 | [diff] [blame] | 668 | ipmmu_pdev = of_find_device_by_node(args->np); |
| 669 | if (!ipmmu_pdev) |
Laurent Pinchart | bb590c9 | 2015-01-24 23:13:50 +0200 | [diff] [blame] | 670 | return -ENODEV; |
| 671 | |
Magnus Damm | 7b2d596 | 2017-07-17 22:05:41 +0900 | [diff] [blame] | 672 | priv = kzalloc(sizeof(*priv), GFP_KERNEL); |
| 673 | if (!priv) |
Laurent Pinchart | bb590c9 | 2015-01-24 23:13:50 +0200 | [diff] [blame] | 674 | return -ENOMEM; |
| 675 | |
Magnus Damm | 7b2d596 | 2017-07-17 22:05:41 +0900 | [diff] [blame] | 676 | priv->mmu = platform_get_drvdata(ipmmu_pdev); |
Magnus Damm | 0fbc8b0 | 2017-05-17 19:07:20 +0900 | [diff] [blame] | 677 | priv->dev = dev; |
Robin Murphy | 3c49ed3 | 2017-07-17 22:05:31 +0900 | [diff] [blame] | 678 | dev->iommu_fwspec->iommu_priv = priv; |
Magnus Damm | 383fef5f | 2017-05-17 19:06:48 +0900 | [diff] [blame] | 679 | return 0; |
Magnus Damm | 383fef5f | 2017-05-17 19:06:48 +0900 | [diff] [blame] | 680 | } |
| 681 | |
Magnus Damm | 49558da | 2017-07-17 22:05:20 +0900 | [diff] [blame] | 682 | static int ipmmu_of_xlate(struct device *dev, |
| 683 | struct of_phandle_args *spec) |
| 684 | { |
Magnus Damm | 7b2d596 | 2017-07-17 22:05:41 +0900 | [diff] [blame] | 685 | iommu_fwspec_add_ids(dev, spec->args, 1); |
| 686 | |
Magnus Damm | 49558da | 2017-07-17 22:05:20 +0900 | [diff] [blame] | 687 | /* Initialize once - xlate() will call multiple times */ |
| 688 | if (to_priv(dev)) |
| 689 | return 0; |
| 690 | |
Magnus Damm | 7b2d596 | 2017-07-17 22:05:41 +0900 | [diff] [blame] | 691 | return ipmmu_init_platform_device(dev, spec); |
Magnus Damm | 49558da | 2017-07-17 22:05:20 +0900 | [diff] [blame] | 692 | } |
| 693 | |
Magnus Damm | 3ae4729 | 2017-05-17 19:07:10 +0900 | [diff] [blame] | 694 | #if defined(CONFIG_ARM) && !defined(CONFIG_IOMMU_DMA) |
| 695 | |
Magnus Damm | 383fef5f | 2017-05-17 19:06:48 +0900 | [diff] [blame] | 696 | static int ipmmu_add_device(struct device *dev) |
| 697 | { |
Magnus Damm | 383fef5f | 2017-05-17 19:06:48 +0900 | [diff] [blame] | 698 | struct ipmmu_vmsa_device *mmu = NULL; |
| 699 | struct iommu_group *group; |
| 700 | int ret; |
| 701 | |
Magnus Damm | 49558da | 2017-07-17 22:05:20 +0900 | [diff] [blame] | 702 | /* |
| 703 | * Only let through devices that have been verified in xlate() |
| 704 | */ |
| 705 | if (!to_priv(dev)) |
| 706 | return -ENODEV; |
Magnus Damm | 383fef5f | 2017-05-17 19:06:48 +0900 | [diff] [blame] | 707 | |
Laurent Pinchart | d25a2a1 | 2014-04-02 12:47:37 +0200 | [diff] [blame] | 708 | /* Create a device group and add the device to it. */ |
| 709 | group = iommu_group_alloc(); |
| 710 | if (IS_ERR(group)) { |
| 711 | dev_err(dev, "Failed to allocate IOMMU group\n"); |
Laurent Pinchart | a166d31 | 2014-07-24 01:36:43 +0200 | [diff] [blame] | 712 | ret = PTR_ERR(group); |
| 713 | goto error; |
Laurent Pinchart | d25a2a1 | 2014-04-02 12:47:37 +0200 | [diff] [blame] | 714 | } |
| 715 | |
| 716 | ret = iommu_group_add_device(group, dev); |
| 717 | iommu_group_put(group); |
| 718 | |
| 719 | if (ret < 0) { |
| 720 | dev_err(dev, "Failed to add device to IPMMU group\n"); |
Laurent Pinchart | a166d31 | 2014-07-24 01:36:43 +0200 | [diff] [blame] | 721 | group = NULL; |
| 722 | goto error; |
Laurent Pinchart | d25a2a1 | 2014-04-02 12:47:37 +0200 | [diff] [blame] | 723 | } |
| 724 | |
Laurent Pinchart | d25a2a1 | 2014-04-02 12:47:37 +0200 | [diff] [blame] | 725 | /* |
| 726 | * Create the ARM mapping, used by the ARM DMA mapping core to allocate |
| 727 | * VAs. This will allocate a corresponding IOMMU domain. |
| 728 | * |
| 729 | * TODO: |
| 730 | * - Create one mapping per context (TLB). |
| 731 | * - Make the mapping size configurable ? We currently use a 2GB mapping |
| 732 | * at a 1GB offset to ensure that NULL VAs will fault. |
| 733 | */ |
Magnus Damm | 0fbc8b0 | 2017-05-17 19:07:20 +0900 | [diff] [blame] | 734 | mmu = to_priv(dev)->mmu; |
Laurent Pinchart | d25a2a1 | 2014-04-02 12:47:37 +0200 | [diff] [blame] | 735 | if (!mmu->mapping) { |
| 736 | struct dma_iommu_mapping *mapping; |
| 737 | |
| 738 | mapping = arm_iommu_create_mapping(&platform_bus_type, |
Joerg Roedel | 720b0ce | 2014-05-26 13:07:01 +0200 | [diff] [blame] | 739 | SZ_1G, SZ_2G); |
Laurent Pinchart | d25a2a1 | 2014-04-02 12:47:37 +0200 | [diff] [blame] | 740 | if (IS_ERR(mapping)) { |
| 741 | dev_err(mmu->dev, "failed to create ARM IOMMU mapping\n"); |
Laurent Pinchart | b8f80bf | 2014-03-14 14:00:56 +0100 | [diff] [blame] | 742 | ret = PTR_ERR(mapping); |
| 743 | goto error; |
Laurent Pinchart | d25a2a1 | 2014-04-02 12:47:37 +0200 | [diff] [blame] | 744 | } |
| 745 | |
| 746 | mmu->mapping = mapping; |
| 747 | } |
| 748 | |
| 749 | /* Attach the ARM VA mapping to the device. */ |
| 750 | ret = arm_iommu_attach_device(dev, mmu->mapping); |
| 751 | if (ret < 0) { |
| 752 | dev_err(dev, "Failed to attach device to VA mapping\n"); |
| 753 | goto error; |
| 754 | } |
| 755 | |
| 756 | return 0; |
| 757 | |
| 758 | error: |
Magnus Damm | 383fef5f | 2017-05-17 19:06:48 +0900 | [diff] [blame] | 759 | if (mmu) |
| 760 | arm_iommu_release_mapping(mmu->mapping); |
Laurent Pinchart | a166d31 | 2014-07-24 01:36:43 +0200 | [diff] [blame] | 761 | |
| 762 | if (!IS_ERR_OR_NULL(group)) |
| 763 | iommu_group_remove_device(dev); |
| 764 | |
Laurent Pinchart | d25a2a1 | 2014-04-02 12:47:37 +0200 | [diff] [blame] | 765 | return ret; |
| 766 | } |
| 767 | |
| 768 | static void ipmmu_remove_device(struct device *dev) |
| 769 | { |
| 770 | arm_iommu_detach_device(dev); |
| 771 | iommu_group_remove_device(dev); |
Laurent Pinchart | d25a2a1 | 2014-04-02 12:47:37 +0200 | [diff] [blame] | 772 | } |
| 773 | |
Thierry Reding | b22f643 | 2014-06-27 09:03:12 +0200 | [diff] [blame] | 774 | static const struct iommu_ops ipmmu_ops = { |
Joerg Roedel | 5914c5f | 2015-03-26 13:43:16 +0100 | [diff] [blame] | 775 | .domain_alloc = ipmmu_domain_alloc, |
| 776 | .domain_free = ipmmu_domain_free, |
Laurent Pinchart | d25a2a1 | 2014-04-02 12:47:37 +0200 | [diff] [blame] | 777 | .attach_dev = ipmmu_attach_device, |
| 778 | .detach_dev = ipmmu_detach_device, |
| 779 | .map = ipmmu_map, |
| 780 | .unmap = ipmmu_unmap, |
Olav Haugan | 315786e | 2014-10-25 09:55:16 -0700 | [diff] [blame] | 781 | .map_sg = default_iommu_map_sg, |
Laurent Pinchart | d25a2a1 | 2014-04-02 12:47:37 +0200 | [diff] [blame] | 782 | .iova_to_phys = ipmmu_iova_to_phys, |
| 783 | .add_device = ipmmu_add_device, |
| 784 | .remove_device = ipmmu_remove_device, |
Laurent Pinchart | f20ed39 | 2015-01-20 18:30:04 +0200 | [diff] [blame] | 785 | .pgsize_bitmap = SZ_1G | SZ_2M | SZ_4K, |
Magnus Damm | 49558da | 2017-07-17 22:05:20 +0900 | [diff] [blame] | 786 | .of_xlate = ipmmu_of_xlate, |
Laurent Pinchart | d25a2a1 | 2014-04-02 12:47:37 +0200 | [diff] [blame] | 787 | }; |
| 788 | |
Magnus Damm | 3ae4729 | 2017-05-17 19:07:10 +0900 | [diff] [blame] | 789 | #endif /* !CONFIG_ARM && CONFIG_IOMMU_DMA */ |
| 790 | |
| 791 | #ifdef CONFIG_IOMMU_DMA |
| 792 | |
| 793 | static DEFINE_SPINLOCK(ipmmu_slave_devices_lock); |
| 794 | static LIST_HEAD(ipmmu_slave_devices); |
| 795 | |
Magnus Damm | 3ae4729 | 2017-05-17 19:07:10 +0900 | [diff] [blame] | 796 | static int ipmmu_add_device_dma(struct device *dev) |
| 797 | { |
Magnus Damm | 3ae4729 | 2017-05-17 19:07:10 +0900 | [diff] [blame] | 798 | struct iommu_group *group; |
| 799 | |
Magnus Damm | 0fbc8b0 | 2017-05-17 19:07:20 +0900 | [diff] [blame] | 800 | /* |
| 801 | * Only let through devices that have been verified in xlate() |
Magnus Damm | 0fbc8b0 | 2017-05-17 19:07:20 +0900 | [diff] [blame] | 802 | */ |
Robin Murphy | 3c49ed3 | 2017-07-17 22:05:31 +0900 | [diff] [blame] | 803 | if (!to_priv(dev)) |
Magnus Damm | 3ae4729 | 2017-05-17 19:07:10 +0900 | [diff] [blame] | 804 | return -ENODEV; |
| 805 | |
| 806 | group = iommu_group_get_for_dev(dev); |
| 807 | if (IS_ERR(group)) |
| 808 | return PTR_ERR(group); |
| 809 | |
| 810 | spin_lock(&ipmmu_slave_devices_lock); |
Magnus Damm | 0fbc8b0 | 2017-05-17 19:07:20 +0900 | [diff] [blame] | 811 | list_add(&to_priv(dev)->list, &ipmmu_slave_devices); |
Magnus Damm | 3ae4729 | 2017-05-17 19:07:10 +0900 | [diff] [blame] | 812 | spin_unlock(&ipmmu_slave_devices_lock); |
| 813 | return 0; |
| 814 | } |
| 815 | |
| 816 | static void ipmmu_remove_device_dma(struct device *dev) |
| 817 | { |
Magnus Damm | 0fbc8b0 | 2017-05-17 19:07:20 +0900 | [diff] [blame] | 818 | struct ipmmu_vmsa_iommu_priv *priv = to_priv(dev); |
Magnus Damm | 3ae4729 | 2017-05-17 19:07:10 +0900 | [diff] [blame] | 819 | |
| 820 | spin_lock(&ipmmu_slave_devices_lock); |
Magnus Damm | 0fbc8b0 | 2017-05-17 19:07:20 +0900 | [diff] [blame] | 821 | list_del(&priv->list); |
Magnus Damm | 3ae4729 | 2017-05-17 19:07:10 +0900 | [diff] [blame] | 822 | spin_unlock(&ipmmu_slave_devices_lock); |
| 823 | |
| 824 | iommu_group_remove_device(dev); |
| 825 | } |
| 826 | |
| 827 | static struct device *ipmmu_find_sibling_device(struct device *dev) |
| 828 | { |
Magnus Damm | 0fbc8b0 | 2017-05-17 19:07:20 +0900 | [diff] [blame] | 829 | struct ipmmu_vmsa_iommu_priv *priv = to_priv(dev); |
| 830 | struct ipmmu_vmsa_iommu_priv *sibling_priv = NULL; |
Magnus Damm | 3ae4729 | 2017-05-17 19:07:10 +0900 | [diff] [blame] | 831 | bool found = false; |
| 832 | |
| 833 | spin_lock(&ipmmu_slave_devices_lock); |
| 834 | |
Magnus Damm | 0fbc8b0 | 2017-05-17 19:07:20 +0900 | [diff] [blame] | 835 | list_for_each_entry(sibling_priv, &ipmmu_slave_devices, list) { |
| 836 | if (priv == sibling_priv) |
Magnus Damm | 3ae4729 | 2017-05-17 19:07:10 +0900 | [diff] [blame] | 837 | continue; |
Magnus Damm | 0fbc8b0 | 2017-05-17 19:07:20 +0900 | [diff] [blame] | 838 | if (sibling_priv->mmu == priv->mmu) { |
Magnus Damm | 3ae4729 | 2017-05-17 19:07:10 +0900 | [diff] [blame] | 839 | found = true; |
| 840 | break; |
| 841 | } |
| 842 | } |
| 843 | |
| 844 | spin_unlock(&ipmmu_slave_devices_lock); |
| 845 | |
Magnus Damm | 0fbc8b0 | 2017-05-17 19:07:20 +0900 | [diff] [blame] | 846 | return found ? sibling_priv->dev : NULL; |
Magnus Damm | 3ae4729 | 2017-05-17 19:07:10 +0900 | [diff] [blame] | 847 | } |
| 848 | |
| 849 | static struct iommu_group *ipmmu_find_group_dma(struct device *dev) |
| 850 | { |
| 851 | struct iommu_group *group; |
| 852 | struct device *sibling; |
| 853 | |
| 854 | sibling = ipmmu_find_sibling_device(dev); |
| 855 | if (sibling) |
| 856 | group = iommu_group_get(sibling); |
weiyongjun (A) | 105a004 | 2017-10-17 12:11:22 +0000 | [diff] [blame] | 857 | if (!sibling || !group) |
Magnus Damm | 3ae4729 | 2017-05-17 19:07:10 +0900 | [diff] [blame] | 858 | group = generic_device_group(dev); |
| 859 | |
| 860 | return group; |
| 861 | } |
| 862 | |
Magnus Damm | 3ae4729 | 2017-05-17 19:07:10 +0900 | [diff] [blame] | 863 | static const struct iommu_ops ipmmu_ops = { |
Robin Murphy | 1c7e7c0 | 2017-10-13 19:23:39 +0100 | [diff] [blame^] | 864 | .domain_alloc = ipmmu_domain_alloc, |
| 865 | .domain_free = ipmmu_domain_free, |
Magnus Damm | 3ae4729 | 2017-05-17 19:07:10 +0900 | [diff] [blame] | 866 | .attach_dev = ipmmu_attach_device, |
| 867 | .detach_dev = ipmmu_detach_device, |
| 868 | .map = ipmmu_map, |
| 869 | .unmap = ipmmu_unmap, |
Robin Murphy | 32b1244 | 2017-09-28 15:55:01 +0100 | [diff] [blame] | 870 | .flush_iotlb_all = ipmmu_iotlb_sync, |
| 871 | .iotlb_sync = ipmmu_iotlb_sync, |
Magnus Damm | 3ae4729 | 2017-05-17 19:07:10 +0900 | [diff] [blame] | 872 | .map_sg = default_iommu_map_sg, |
| 873 | .iova_to_phys = ipmmu_iova_to_phys, |
| 874 | .add_device = ipmmu_add_device_dma, |
| 875 | .remove_device = ipmmu_remove_device_dma, |
| 876 | .device_group = ipmmu_find_group_dma, |
| 877 | .pgsize_bitmap = SZ_1G | SZ_2M | SZ_4K, |
Magnus Damm | 49558da | 2017-07-17 22:05:20 +0900 | [diff] [blame] | 878 | .of_xlate = ipmmu_of_xlate, |
Magnus Damm | 3ae4729 | 2017-05-17 19:07:10 +0900 | [diff] [blame] | 879 | }; |
| 880 | |
| 881 | #endif /* CONFIG_IOMMU_DMA */ |
| 882 | |
Laurent Pinchart | d25a2a1 | 2014-04-02 12:47:37 +0200 | [diff] [blame] | 883 | /* ----------------------------------------------------------------------------- |
| 884 | * Probe/remove and init |
| 885 | */ |
| 886 | |
| 887 | static void ipmmu_device_reset(struct ipmmu_vmsa_device *mmu) |
| 888 | { |
| 889 | unsigned int i; |
| 890 | |
| 891 | /* Disable all contexts. */ |
| 892 | for (i = 0; i < 4; ++i) |
| 893 | ipmmu_write(mmu, i * IM_CTX_SIZE + IMCTR, 0); |
| 894 | } |
| 895 | |
| 896 | static int ipmmu_probe(struct platform_device *pdev) |
| 897 | { |
| 898 | struct ipmmu_vmsa_device *mmu; |
| 899 | struct resource *res; |
| 900 | int irq; |
| 901 | int ret; |
| 902 | |
Laurent Pinchart | d25a2a1 | 2014-04-02 12:47:37 +0200 | [diff] [blame] | 903 | mmu = devm_kzalloc(&pdev->dev, sizeof(*mmu), GFP_KERNEL); |
| 904 | if (!mmu) { |
| 905 | dev_err(&pdev->dev, "cannot allocate device data\n"); |
| 906 | return -ENOMEM; |
| 907 | } |
| 908 | |
| 909 | mmu->dev = &pdev->dev; |
Laurent Pinchart | d25a2a1 | 2014-04-02 12:47:37 +0200 | [diff] [blame] | 910 | mmu->num_utlbs = 32; |
Magnus Damm | dbb7069 | 2017-05-17 19:06:38 +0900 | [diff] [blame] | 911 | spin_lock_init(&mmu->lock); |
| 912 | bitmap_zero(mmu->ctx, IPMMU_CTX_MAX); |
Laurent Pinchart | d25a2a1 | 2014-04-02 12:47:37 +0200 | [diff] [blame] | 913 | |
| 914 | /* Map I/O memory and request IRQ. */ |
| 915 | res = platform_get_resource(pdev, IORESOURCE_MEM, 0); |
| 916 | mmu->base = devm_ioremap_resource(&pdev->dev, res); |
| 917 | if (IS_ERR(mmu->base)) |
| 918 | return PTR_ERR(mmu->base); |
| 919 | |
Laurent Pinchart | 275f505 | 2014-03-17 01:02:46 +0100 | [diff] [blame] | 920 | /* |
| 921 | * The IPMMU has two register banks, for secure and non-secure modes. |
| 922 | * The bank mapped at the beginning of the IPMMU address space |
| 923 | * corresponds to the running mode of the CPU. When running in secure |
| 924 | * mode the non-secure register bank is also available at an offset. |
| 925 | * |
| 926 | * Secure mode operation isn't clearly documented and is thus currently |
| 927 | * not implemented in the driver. Furthermore, preliminary tests of |
| 928 | * non-secure operation with the main register bank were not successful. |
| 929 | * Offset the registers base unconditionally to point to the non-secure |
| 930 | * alias space for now. |
| 931 | */ |
| 932 | mmu->base += IM_NS_ALIAS_OFFSET; |
| 933 | |
Laurent Pinchart | d25a2a1 | 2014-04-02 12:47:37 +0200 | [diff] [blame] | 934 | irq = platform_get_irq(pdev, 0); |
| 935 | if (irq < 0) { |
| 936 | dev_err(&pdev->dev, "no IRQ found\n"); |
| 937 | return irq; |
| 938 | } |
| 939 | |
| 940 | ret = devm_request_irq(&pdev->dev, irq, ipmmu_irq, 0, |
| 941 | dev_name(&pdev->dev), mmu); |
| 942 | if (ret < 0) { |
| 943 | dev_err(&pdev->dev, "failed to request IRQ %d\n", irq); |
Axel Lin | e222d6a | 2014-11-01 11:45:32 +0800 | [diff] [blame] | 944 | return ret; |
Laurent Pinchart | d25a2a1 | 2014-04-02 12:47:37 +0200 | [diff] [blame] | 945 | } |
| 946 | |
| 947 | ipmmu_device_reset(mmu); |
| 948 | |
Magnus Damm | 7af9a5f | 2017-08-21 14:53:35 +0900 | [diff] [blame] | 949 | ret = iommu_device_sysfs_add(&mmu->iommu, &pdev->dev, NULL, |
| 950 | dev_name(&pdev->dev)); |
| 951 | if (ret) |
| 952 | return ret; |
| 953 | |
Magnus Damm | 01da21e | 2017-07-17 22:05:10 +0900 | [diff] [blame] | 954 | iommu_device_set_ops(&mmu->iommu, &ipmmu_ops); |
| 955 | iommu_device_set_fwnode(&mmu->iommu, &pdev->dev.of_node->fwnode); |
| 956 | |
| 957 | ret = iommu_device_register(&mmu->iommu); |
| 958 | if (ret) |
| 959 | return ret; |
| 960 | |
Laurent Pinchart | d25a2a1 | 2014-04-02 12:47:37 +0200 | [diff] [blame] | 961 | /* |
| 962 | * We can't create the ARM mapping here as it requires the bus to have |
| 963 | * an IOMMU, which only happens when bus_set_iommu() is called in |
| 964 | * ipmmu_init() after the probe function returns. |
| 965 | */ |
| 966 | |
Laurent Pinchart | d25a2a1 | 2014-04-02 12:47:37 +0200 | [diff] [blame] | 967 | platform_set_drvdata(pdev, mmu); |
| 968 | |
| 969 | return 0; |
| 970 | } |
| 971 | |
| 972 | static int ipmmu_remove(struct platform_device *pdev) |
| 973 | { |
| 974 | struct ipmmu_vmsa_device *mmu = platform_get_drvdata(pdev); |
| 975 | |
Magnus Damm | 7af9a5f | 2017-08-21 14:53:35 +0900 | [diff] [blame] | 976 | iommu_device_sysfs_remove(&mmu->iommu); |
Magnus Damm | 01da21e | 2017-07-17 22:05:10 +0900 | [diff] [blame] | 977 | iommu_device_unregister(&mmu->iommu); |
| 978 | |
Magnus Damm | 3ae4729 | 2017-05-17 19:07:10 +0900 | [diff] [blame] | 979 | #if defined(CONFIG_ARM) && !defined(CONFIG_IOMMU_DMA) |
Laurent Pinchart | d25a2a1 | 2014-04-02 12:47:37 +0200 | [diff] [blame] | 980 | arm_iommu_release_mapping(mmu->mapping); |
Magnus Damm | 3ae4729 | 2017-05-17 19:07:10 +0900 | [diff] [blame] | 981 | #endif |
Laurent Pinchart | d25a2a1 | 2014-04-02 12:47:37 +0200 | [diff] [blame] | 982 | |
| 983 | ipmmu_device_reset(mmu); |
| 984 | |
| 985 | return 0; |
| 986 | } |
| 987 | |
Laurent Pinchart | 275f505 | 2014-03-17 01:02:46 +0100 | [diff] [blame] | 988 | static const struct of_device_id ipmmu_of_ids[] = { |
| 989 | { .compatible = "renesas,ipmmu-vmsa", }, |
Axel Lin | ac04f85 | 2015-03-17 08:06:45 +0800 | [diff] [blame] | 990 | { } |
Laurent Pinchart | 275f505 | 2014-03-17 01:02:46 +0100 | [diff] [blame] | 991 | }; |
| 992 | |
Laurent Pinchart | d25a2a1 | 2014-04-02 12:47:37 +0200 | [diff] [blame] | 993 | static struct platform_driver ipmmu_driver = { |
| 994 | .driver = { |
Laurent Pinchart | d25a2a1 | 2014-04-02 12:47:37 +0200 | [diff] [blame] | 995 | .name = "ipmmu-vmsa", |
Laurent Pinchart | 275f505 | 2014-03-17 01:02:46 +0100 | [diff] [blame] | 996 | .of_match_table = of_match_ptr(ipmmu_of_ids), |
Laurent Pinchart | d25a2a1 | 2014-04-02 12:47:37 +0200 | [diff] [blame] | 997 | }, |
| 998 | .probe = ipmmu_probe, |
| 999 | .remove = ipmmu_remove, |
| 1000 | }; |
| 1001 | |
| 1002 | static int __init ipmmu_init(void) |
| 1003 | { |
| 1004 | int ret; |
| 1005 | |
| 1006 | ret = platform_driver_register(&ipmmu_driver); |
| 1007 | if (ret < 0) |
| 1008 | return ret; |
| 1009 | |
| 1010 | if (!iommu_present(&platform_bus_type)) |
| 1011 | bus_set_iommu(&platform_bus_type, &ipmmu_ops); |
| 1012 | |
| 1013 | return 0; |
| 1014 | } |
| 1015 | |
| 1016 | static void __exit ipmmu_exit(void) |
| 1017 | { |
| 1018 | return platform_driver_unregister(&ipmmu_driver); |
| 1019 | } |
| 1020 | |
| 1021 | subsys_initcall(ipmmu_init); |
| 1022 | module_exit(ipmmu_exit); |
| 1023 | |
| 1024 | MODULE_DESCRIPTION("IOMMU API for Renesas VMSA-compatible IPMMU"); |
| 1025 | MODULE_AUTHOR("Laurent Pinchart <laurent.pinchart@ideasonboard.com>"); |
| 1026 | MODULE_LICENSE("GPL v2"); |