Hiroshi DOYU | a9dcad5 | 2009-01-26 15:13:40 +0200 | [diff] [blame] | 1 | /* |
| 2 | * omap iommu: tlb and pagetable primitives |
| 3 | * |
Hiroshi DOYU | c127c7d | 2010-02-15 10:03:32 -0800 | [diff] [blame] | 4 | * Copyright (C) 2008-2010 Nokia Corporation |
Hiroshi DOYU | a9dcad5 | 2009-01-26 15:13:40 +0200 | [diff] [blame] | 5 | * |
| 6 | * Written by Hiroshi DOYU <Hiroshi.DOYU@nokia.com>, |
| 7 | * Paul Mundt and Toshihiro Kobayashi |
| 8 | * |
| 9 | * This program is free software; you can redistribute it and/or modify |
| 10 | * it under the terms of the GNU General Public License version 2 as |
| 11 | * published by the Free Software Foundation. |
| 12 | */ |
| 13 | |
Josue Albarran | bfee0cf | 2017-07-28 15:49:14 -0500 | [diff] [blame^] | 14 | #include <linux/dma-mapping.h> |
Hiroshi DOYU | a9dcad5 | 2009-01-26 15:13:40 +0200 | [diff] [blame] | 15 | #include <linux/err.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 16 | #include <linux/slab.h> |
Hiroshi DOYU | a9dcad5 | 2009-01-26 15:13:40 +0200 | [diff] [blame] | 17 | #include <linux/interrupt.h> |
| 18 | #include <linux/ioport.h> |
Hiroshi DOYU | a9dcad5 | 2009-01-26 15:13:40 +0200 | [diff] [blame] | 19 | #include <linux/platform_device.h> |
Ohad Ben-Cohen | f626b52 | 2011-06-02 01:46:12 +0300 | [diff] [blame] | 20 | #include <linux/iommu.h> |
Tony Lindgren | c8d35c8 | 2012-11-02 12:24:03 -0700 | [diff] [blame] | 21 | #include <linux/omap-iommu.h> |
Ohad Ben-Cohen | f626b52 | 2011-06-02 01:46:12 +0300 | [diff] [blame] | 22 | #include <linux/mutex.h> |
| 23 | #include <linux/spinlock.h> |
Tony Lindgren | ed1c7de | 2012-11-02 12:24:06 -0700 | [diff] [blame] | 24 | #include <linux/io.h> |
Omar Ramirez Luna | ebf7cda | 2012-11-19 19:05:51 -0600 | [diff] [blame] | 25 | #include <linux/pm_runtime.h> |
Florian Vaussard | 3c92748 | 2014-02-28 14:42:36 -0600 | [diff] [blame] | 26 | #include <linux/of.h> |
| 27 | #include <linux/of_iommu.h> |
| 28 | #include <linux/of_irq.h> |
Suman Anna | 7d68277 | 2014-09-04 17:27:30 -0500 | [diff] [blame] | 29 | #include <linux/of_platform.h> |
Suman Anna | 3ca9299 | 2015-10-02 18:02:44 -0500 | [diff] [blame] | 30 | #include <linux/regmap.h> |
| 31 | #include <linux/mfd/syscon.h> |
Hiroshi DOYU | a9dcad5 | 2009-01-26 15:13:40 +0200 | [diff] [blame] | 32 | |
Tony Lindgren | 2ab7c84 | 2012-11-02 12:24:14 -0700 | [diff] [blame] | 33 | #include <linux/platform_data/iommu-omap.h> |
Hiroshi DOYU | a9dcad5 | 2009-01-26 15:13:40 +0200 | [diff] [blame] | 34 | |
Ido Yariv | 2f7702a | 2012-11-02 12:24:00 -0700 | [diff] [blame] | 35 | #include "omap-iopgtable.h" |
Tony Lindgren | ed1c7de | 2012-11-02 12:24:06 -0700 | [diff] [blame] | 36 | #include "omap-iommu.h" |
Hiroshi DOYU | a9dcad5 | 2009-01-26 15:13:40 +0200 | [diff] [blame] | 37 | |
Joerg Roedel | 01611fe | 2017-04-12 00:21:30 -0500 | [diff] [blame] | 38 | static const struct iommu_ops omap_iommu_ops; |
| 39 | |
Suman Anna | 5acc97d | 2014-03-17 20:31:34 -0500 | [diff] [blame] | 40 | #define to_iommu(dev) \ |
| 41 | ((struct omap_iommu *)platform_get_drvdata(to_platform_device(dev))) |
| 42 | |
Ohad Ben-Cohen | 66bc8cf | 2011-11-10 11:32:27 +0200 | [diff] [blame] | 43 | /* bitmap of the page sizes currently supported */ |
| 44 | #define OMAP_IOMMU_PGSIZES (SZ_4K | SZ_64K | SZ_1M | SZ_16M) |
| 45 | |
Ido Yariv | 7bd9e25 | 2012-11-02 12:24:09 -0700 | [diff] [blame] | 46 | #define MMU_LOCK_BASE_SHIFT 10 |
| 47 | #define MMU_LOCK_BASE_MASK (0x1f << MMU_LOCK_BASE_SHIFT) |
| 48 | #define MMU_LOCK_BASE(x) \ |
| 49 | ((x & MMU_LOCK_BASE_MASK) >> MMU_LOCK_BASE_SHIFT) |
| 50 | |
| 51 | #define MMU_LOCK_VICT_SHIFT 4 |
| 52 | #define MMU_LOCK_VICT_MASK (0x1f << MMU_LOCK_VICT_SHIFT) |
| 53 | #define MMU_LOCK_VICT(x) \ |
| 54 | ((x & MMU_LOCK_VICT_MASK) >> MMU_LOCK_VICT_SHIFT) |
| 55 | |
Hiroshi DOYU | a9dcad5 | 2009-01-26 15:13:40 +0200 | [diff] [blame] | 56 | static struct platform_driver omap_iommu_driver; |
| 57 | static struct kmem_cache *iopte_cachep; |
| 58 | |
| 59 | /** |
Joerg Roedel | 8cf851e | 2015-03-26 13:43:09 +0100 | [diff] [blame] | 60 | * to_omap_domain - Get struct omap_iommu_domain from generic iommu_domain |
| 61 | * @dom: generic iommu domain handle |
| 62 | **/ |
| 63 | static struct omap_iommu_domain *to_omap_domain(struct iommu_domain *dom) |
| 64 | { |
| 65 | return container_of(dom, struct omap_iommu_domain, domain); |
| 66 | } |
| 67 | |
| 68 | /** |
Ohad Ben-Cohen | 6c32df4 | 2011-08-17 22:57:56 +0300 | [diff] [blame] | 69 | * omap_iommu_save_ctx - Save registers for pm off-mode support |
Ohad Ben-Cohen | fabdbca | 2011-10-11 00:18:33 +0200 | [diff] [blame] | 70 | * @dev: client device |
Hiroshi DOYU | a9dcad5 | 2009-01-26 15:13:40 +0200 | [diff] [blame] | 71 | **/ |
Ohad Ben-Cohen | fabdbca | 2011-10-11 00:18:33 +0200 | [diff] [blame] | 72 | void omap_iommu_save_ctx(struct device *dev) |
Hiroshi DOYU | a9dcad5 | 2009-01-26 15:13:40 +0200 | [diff] [blame] | 73 | { |
Ohad Ben-Cohen | fabdbca | 2011-10-11 00:18:33 +0200 | [diff] [blame] | 74 | struct omap_iommu *obj = dev_to_omap_iommu(dev); |
Suman Anna | bd4396f | 2014-10-22 17:22:27 -0500 | [diff] [blame] | 75 | u32 *p = obj->ctx; |
| 76 | int i; |
Ohad Ben-Cohen | fabdbca | 2011-10-11 00:18:33 +0200 | [diff] [blame] | 77 | |
Suman Anna | bd4396f | 2014-10-22 17:22:27 -0500 | [diff] [blame] | 78 | for (i = 0; i < (MMU_REG_SIZE / sizeof(u32)); i++) { |
| 79 | p[i] = iommu_read_reg(obj, i * sizeof(u32)); |
| 80 | dev_dbg(obj->dev, "%s\t[%02d] %08x\n", __func__, i, p[i]); |
| 81 | } |
Hiroshi DOYU | a9dcad5 | 2009-01-26 15:13:40 +0200 | [diff] [blame] | 82 | } |
Ohad Ben-Cohen | 6c32df4 | 2011-08-17 22:57:56 +0300 | [diff] [blame] | 83 | EXPORT_SYMBOL_GPL(omap_iommu_save_ctx); |
Hiroshi DOYU | a9dcad5 | 2009-01-26 15:13:40 +0200 | [diff] [blame] | 84 | |
| 85 | /** |
Ohad Ben-Cohen | 6c32df4 | 2011-08-17 22:57:56 +0300 | [diff] [blame] | 86 | * omap_iommu_restore_ctx - Restore registers for pm off-mode support |
Ohad Ben-Cohen | fabdbca | 2011-10-11 00:18:33 +0200 | [diff] [blame] | 87 | * @dev: client device |
Hiroshi DOYU | a9dcad5 | 2009-01-26 15:13:40 +0200 | [diff] [blame] | 88 | **/ |
Ohad Ben-Cohen | fabdbca | 2011-10-11 00:18:33 +0200 | [diff] [blame] | 89 | void omap_iommu_restore_ctx(struct device *dev) |
Hiroshi DOYU | a9dcad5 | 2009-01-26 15:13:40 +0200 | [diff] [blame] | 90 | { |
Ohad Ben-Cohen | fabdbca | 2011-10-11 00:18:33 +0200 | [diff] [blame] | 91 | struct omap_iommu *obj = dev_to_omap_iommu(dev); |
Suman Anna | bd4396f | 2014-10-22 17:22:27 -0500 | [diff] [blame] | 92 | u32 *p = obj->ctx; |
| 93 | int i; |
Ohad Ben-Cohen | fabdbca | 2011-10-11 00:18:33 +0200 | [diff] [blame] | 94 | |
Suman Anna | bd4396f | 2014-10-22 17:22:27 -0500 | [diff] [blame] | 95 | for (i = 0; i < (MMU_REG_SIZE / sizeof(u32)); i++) { |
| 96 | iommu_write_reg(obj, p[i], i * sizeof(u32)); |
| 97 | dev_dbg(obj->dev, "%s\t[%02d] %08x\n", __func__, i, p[i]); |
| 98 | } |
Hiroshi DOYU | a9dcad5 | 2009-01-26 15:13:40 +0200 | [diff] [blame] | 99 | } |
Ohad Ben-Cohen | 6c32df4 | 2011-08-17 22:57:56 +0300 | [diff] [blame] | 100 | EXPORT_SYMBOL_GPL(omap_iommu_restore_ctx); |
Hiroshi DOYU | a9dcad5 | 2009-01-26 15:13:40 +0200 | [diff] [blame] | 101 | |
Suman Anna | 3ca9299 | 2015-10-02 18:02:44 -0500 | [diff] [blame] | 102 | static void dra7_cfg_dspsys_mmu(struct omap_iommu *obj, bool enable) |
| 103 | { |
| 104 | u32 val, mask; |
| 105 | |
| 106 | if (!obj->syscfg) |
| 107 | return; |
| 108 | |
| 109 | mask = (1 << (obj->id * DSP_SYS_MMU_CONFIG_EN_SHIFT)); |
| 110 | val = enable ? mask : 0; |
| 111 | regmap_update_bits(obj->syscfg, DSP_SYS_MMU_CONFIG, mask, val); |
| 112 | } |
| 113 | |
Suman Anna | bd4396f | 2014-10-22 17:22:27 -0500 | [diff] [blame] | 114 | static void __iommu_set_twl(struct omap_iommu *obj, bool on) |
| 115 | { |
| 116 | u32 l = iommu_read_reg(obj, MMU_CNTL); |
| 117 | |
| 118 | if (on) |
| 119 | iommu_write_reg(obj, MMU_IRQ_TWL_MASK, MMU_IRQENABLE); |
| 120 | else |
| 121 | iommu_write_reg(obj, MMU_IRQ_TLB_MISS_MASK, MMU_IRQENABLE); |
| 122 | |
| 123 | l &= ~MMU_CNTL_MASK; |
| 124 | if (on) |
| 125 | l |= (MMU_CNTL_MMU_EN | MMU_CNTL_TWL_EN); |
| 126 | else |
| 127 | l |= (MMU_CNTL_MMU_EN); |
| 128 | |
| 129 | iommu_write_reg(obj, l, MMU_CNTL); |
| 130 | } |
| 131 | |
| 132 | static int omap2_iommu_enable(struct omap_iommu *obj) |
| 133 | { |
| 134 | u32 l, pa; |
| 135 | |
| 136 | if (!obj->iopgd || !IS_ALIGNED((u32)obj->iopgd, SZ_16K)) |
| 137 | return -EINVAL; |
| 138 | |
| 139 | pa = virt_to_phys(obj->iopgd); |
| 140 | if (!IS_ALIGNED(pa, SZ_16K)) |
| 141 | return -EINVAL; |
| 142 | |
| 143 | l = iommu_read_reg(obj, MMU_REVISION); |
| 144 | dev_info(obj->dev, "%s: version %d.%d\n", obj->name, |
| 145 | (l >> 4) & 0xf, l & 0xf); |
| 146 | |
| 147 | iommu_write_reg(obj, pa, MMU_TTB); |
| 148 | |
Suman Anna | 3ca9299 | 2015-10-02 18:02:44 -0500 | [diff] [blame] | 149 | dra7_cfg_dspsys_mmu(obj, true); |
| 150 | |
Suman Anna | bd4396f | 2014-10-22 17:22:27 -0500 | [diff] [blame] | 151 | if (obj->has_bus_err_back) |
| 152 | iommu_write_reg(obj, MMU_GP_REG_BUS_ERR_BACK_EN, MMU_GP_REG); |
| 153 | |
| 154 | __iommu_set_twl(obj, true); |
| 155 | |
| 156 | return 0; |
| 157 | } |
| 158 | |
| 159 | static void omap2_iommu_disable(struct omap_iommu *obj) |
| 160 | { |
| 161 | u32 l = iommu_read_reg(obj, MMU_CNTL); |
| 162 | |
| 163 | l &= ~MMU_CNTL_MASK; |
| 164 | iommu_write_reg(obj, l, MMU_CNTL); |
Suman Anna | 3ca9299 | 2015-10-02 18:02:44 -0500 | [diff] [blame] | 165 | dra7_cfg_dspsys_mmu(obj, false); |
Suman Anna | bd4396f | 2014-10-22 17:22:27 -0500 | [diff] [blame] | 166 | |
| 167 | dev_dbg(obj->dev, "%s is shutting down\n", obj->name); |
| 168 | } |
| 169 | |
Ohad Ben-Cohen | 6c32df4 | 2011-08-17 22:57:56 +0300 | [diff] [blame] | 170 | static int iommu_enable(struct omap_iommu *obj) |
Hiroshi DOYU | a9dcad5 | 2009-01-26 15:13:40 +0200 | [diff] [blame] | 171 | { |
| 172 | int err; |
Omar Ramirez Luna | 72b15b6 | 2012-11-19 19:05:50 -0600 | [diff] [blame] | 173 | struct platform_device *pdev = to_platform_device(obj->dev); |
Kiran Padwal | 99cb9ae | 2014-10-30 11:59:47 +0530 | [diff] [blame] | 174 | struct iommu_platform_data *pdata = dev_get_platdata(&pdev->dev); |
Hiroshi DOYU | a9dcad5 | 2009-01-26 15:13:40 +0200 | [diff] [blame] | 175 | |
Florian Vaussard | 90e569c | 2014-02-28 14:42:34 -0600 | [diff] [blame] | 176 | if (pdata && pdata->deassert_reset) { |
Omar Ramirez Luna | 72b15b6 | 2012-11-19 19:05:50 -0600 | [diff] [blame] | 177 | err = pdata->deassert_reset(pdev, pdata->reset_name); |
| 178 | if (err) { |
| 179 | dev_err(obj->dev, "deassert_reset failed: %d\n", err); |
| 180 | return err; |
| 181 | } |
| 182 | } |
| 183 | |
Omar Ramirez Luna | ebf7cda | 2012-11-19 19:05:51 -0600 | [diff] [blame] | 184 | pm_runtime_get_sync(obj->dev); |
Hiroshi DOYU | a9dcad5 | 2009-01-26 15:13:40 +0200 | [diff] [blame] | 185 | |
Suman Anna | bd4396f | 2014-10-22 17:22:27 -0500 | [diff] [blame] | 186 | err = omap2_iommu_enable(obj); |
Hiroshi DOYU | a9dcad5 | 2009-01-26 15:13:40 +0200 | [diff] [blame] | 187 | |
Hiroshi DOYU | a9dcad5 | 2009-01-26 15:13:40 +0200 | [diff] [blame] | 188 | return err; |
| 189 | } |
| 190 | |
Ohad Ben-Cohen | 6c32df4 | 2011-08-17 22:57:56 +0300 | [diff] [blame] | 191 | static void iommu_disable(struct omap_iommu *obj) |
Hiroshi DOYU | a9dcad5 | 2009-01-26 15:13:40 +0200 | [diff] [blame] | 192 | { |
Omar Ramirez Luna | 72b15b6 | 2012-11-19 19:05:50 -0600 | [diff] [blame] | 193 | struct platform_device *pdev = to_platform_device(obj->dev); |
Kiran Padwal | 99cb9ae | 2014-10-30 11:59:47 +0530 | [diff] [blame] | 194 | struct iommu_platform_data *pdata = dev_get_platdata(&pdev->dev); |
Omar Ramirez Luna | 72b15b6 | 2012-11-19 19:05:50 -0600 | [diff] [blame] | 195 | |
Suman Anna | bd4396f | 2014-10-22 17:22:27 -0500 | [diff] [blame] | 196 | omap2_iommu_disable(obj); |
Hiroshi DOYU | a9dcad5 | 2009-01-26 15:13:40 +0200 | [diff] [blame] | 197 | |
Omar Ramirez Luna | ebf7cda | 2012-11-19 19:05:51 -0600 | [diff] [blame] | 198 | pm_runtime_put_sync(obj->dev); |
Omar Ramirez Luna | 72b15b6 | 2012-11-19 19:05:50 -0600 | [diff] [blame] | 199 | |
Florian Vaussard | 90e569c | 2014-02-28 14:42:34 -0600 | [diff] [blame] | 200 | if (pdata && pdata->assert_reset) |
Omar Ramirez Luna | 72b15b6 | 2012-11-19 19:05:50 -0600 | [diff] [blame] | 201 | pdata->assert_reset(pdev, pdata->reset_name); |
Hiroshi DOYU | a9dcad5 | 2009-01-26 15:13:40 +0200 | [diff] [blame] | 202 | } |
| 203 | |
| 204 | /* |
| 205 | * TLB operations |
| 206 | */ |
Ohad Ben-Cohen | e1f2381 | 2011-08-16 14:58:14 +0300 | [diff] [blame] | 207 | static u32 iotlb_cr_to_virt(struct cr_regs *cr) |
Hiroshi DOYU | a9dcad5 | 2009-01-26 15:13:40 +0200 | [diff] [blame] | 208 | { |
Suman Anna | bd4396f | 2014-10-22 17:22:27 -0500 | [diff] [blame] | 209 | u32 page_size = cr->cam & MMU_CAM_PGSZ_MASK; |
| 210 | u32 mask = get_cam_va_mask(cr->cam & page_size); |
| 211 | |
| 212 | return cr->cam & mask; |
Hiroshi DOYU | a9dcad5 | 2009-01-26 15:13:40 +0200 | [diff] [blame] | 213 | } |
Hiroshi DOYU | a9dcad5 | 2009-01-26 15:13:40 +0200 | [diff] [blame] | 214 | |
| 215 | static u32 get_iopte_attr(struct iotlb_entry *e) |
| 216 | { |
Suman Anna | bd4396f | 2014-10-22 17:22:27 -0500 | [diff] [blame] | 217 | u32 attr; |
| 218 | |
| 219 | attr = e->mixed << 5; |
| 220 | attr |= e->endian; |
| 221 | attr |= e->elsz >> 3; |
| 222 | attr <<= (((e->pgsz == MMU_CAM_PGSZ_4K) || |
| 223 | (e->pgsz == MMU_CAM_PGSZ_64K)) ? 0 : 6); |
| 224 | return attr; |
Hiroshi DOYU | a9dcad5 | 2009-01-26 15:13:40 +0200 | [diff] [blame] | 225 | } |
| 226 | |
Ohad Ben-Cohen | 6c32df4 | 2011-08-17 22:57:56 +0300 | [diff] [blame] | 227 | static u32 iommu_report_fault(struct omap_iommu *obj, u32 *da) |
Hiroshi DOYU | a9dcad5 | 2009-01-26 15:13:40 +0200 | [diff] [blame] | 228 | { |
Suman Anna | bd4396f | 2014-10-22 17:22:27 -0500 | [diff] [blame] | 229 | u32 status, fault_addr; |
| 230 | |
| 231 | status = iommu_read_reg(obj, MMU_IRQSTATUS); |
| 232 | status &= MMU_IRQ_MASK; |
| 233 | if (!status) { |
| 234 | *da = 0; |
| 235 | return 0; |
| 236 | } |
| 237 | |
| 238 | fault_addr = iommu_read_reg(obj, MMU_FAULT_AD); |
| 239 | *da = fault_addr; |
| 240 | |
| 241 | iommu_write_reg(obj, status, MMU_IRQSTATUS); |
| 242 | |
| 243 | return status; |
Hiroshi DOYU | a9dcad5 | 2009-01-26 15:13:40 +0200 | [diff] [blame] | 244 | } |
| 245 | |
Suman Anna | 69c2c19 | 2015-07-20 17:33:25 -0500 | [diff] [blame] | 246 | void iotlb_lock_get(struct omap_iommu *obj, struct iotlb_lock *l) |
Hiroshi DOYU | a9dcad5 | 2009-01-26 15:13:40 +0200 | [diff] [blame] | 247 | { |
| 248 | u32 val; |
| 249 | |
| 250 | val = iommu_read_reg(obj, MMU_LOCK); |
| 251 | |
| 252 | l->base = MMU_LOCK_BASE(val); |
| 253 | l->vict = MMU_LOCK_VICT(val); |
Hiroshi DOYU | a9dcad5 | 2009-01-26 15:13:40 +0200 | [diff] [blame] | 254 | } |
| 255 | |
Suman Anna | 69c2c19 | 2015-07-20 17:33:25 -0500 | [diff] [blame] | 256 | void iotlb_lock_set(struct omap_iommu *obj, struct iotlb_lock *l) |
Hiroshi DOYU | a9dcad5 | 2009-01-26 15:13:40 +0200 | [diff] [blame] | 257 | { |
| 258 | u32 val; |
| 259 | |
Hiroshi DOYU | a9dcad5 | 2009-01-26 15:13:40 +0200 | [diff] [blame] | 260 | val = (l->base << MMU_LOCK_BASE_SHIFT); |
| 261 | val |= (l->vict << MMU_LOCK_VICT_SHIFT); |
| 262 | |
| 263 | iommu_write_reg(obj, val, MMU_LOCK); |
| 264 | } |
| 265 | |
Ohad Ben-Cohen | 6c32df4 | 2011-08-17 22:57:56 +0300 | [diff] [blame] | 266 | static void iotlb_read_cr(struct omap_iommu *obj, struct cr_regs *cr) |
Hiroshi DOYU | a9dcad5 | 2009-01-26 15:13:40 +0200 | [diff] [blame] | 267 | { |
Suman Anna | bd4396f | 2014-10-22 17:22:27 -0500 | [diff] [blame] | 268 | cr->cam = iommu_read_reg(obj, MMU_READ_CAM); |
| 269 | cr->ram = iommu_read_reg(obj, MMU_READ_RAM); |
Hiroshi DOYU | a9dcad5 | 2009-01-26 15:13:40 +0200 | [diff] [blame] | 270 | } |
| 271 | |
Ohad Ben-Cohen | 6c32df4 | 2011-08-17 22:57:56 +0300 | [diff] [blame] | 272 | static void iotlb_load_cr(struct omap_iommu *obj, struct cr_regs *cr) |
Hiroshi DOYU | a9dcad5 | 2009-01-26 15:13:40 +0200 | [diff] [blame] | 273 | { |
Suman Anna | bd4396f | 2014-10-22 17:22:27 -0500 | [diff] [blame] | 274 | iommu_write_reg(obj, cr->cam | MMU_CAM_V, MMU_CAM); |
| 275 | iommu_write_reg(obj, cr->ram, MMU_RAM); |
Hiroshi DOYU | a9dcad5 | 2009-01-26 15:13:40 +0200 | [diff] [blame] | 276 | |
| 277 | iommu_write_reg(obj, 1, MMU_FLUSH_ENTRY); |
| 278 | iommu_write_reg(obj, 1, MMU_LD_TLB); |
| 279 | } |
| 280 | |
Hiroshi DOYU | 37c2836 | 2010-04-27 05:37:12 +0000 | [diff] [blame] | 281 | /* only used in iotlb iteration for-loop */ |
Suman Anna | 69c2c19 | 2015-07-20 17:33:25 -0500 | [diff] [blame] | 282 | struct cr_regs __iotlb_read_cr(struct omap_iommu *obj, int n) |
Hiroshi DOYU | 37c2836 | 2010-04-27 05:37:12 +0000 | [diff] [blame] | 283 | { |
| 284 | struct cr_regs cr; |
| 285 | struct iotlb_lock l; |
| 286 | |
| 287 | iotlb_lock_get(obj, &l); |
| 288 | l.vict = n; |
| 289 | iotlb_lock_set(obj, &l); |
| 290 | iotlb_read_cr(obj, &cr); |
| 291 | |
| 292 | return cr; |
| 293 | } |
| 294 | |
Suman Anna | bd4396f | 2014-10-22 17:22:27 -0500 | [diff] [blame] | 295 | #ifdef PREFETCH_IOTLB |
| 296 | static struct cr_regs *iotlb_alloc_cr(struct omap_iommu *obj, |
| 297 | struct iotlb_entry *e) |
| 298 | { |
| 299 | struct cr_regs *cr; |
| 300 | |
| 301 | if (!e) |
| 302 | return NULL; |
| 303 | |
| 304 | if (e->da & ~(get_cam_va_mask(e->pgsz))) { |
| 305 | dev_err(obj->dev, "%s:\twrong alignment: %08x\n", __func__, |
| 306 | e->da); |
| 307 | return ERR_PTR(-EINVAL); |
| 308 | } |
| 309 | |
| 310 | cr = kmalloc(sizeof(*cr), GFP_KERNEL); |
| 311 | if (!cr) |
| 312 | return ERR_PTR(-ENOMEM); |
| 313 | |
| 314 | cr->cam = (e->da & MMU_CAM_VATAG_MASK) | e->prsvd | e->pgsz | e->valid; |
| 315 | cr->ram = e->pa | e->endian | e->elsz | e->mixed; |
| 316 | |
| 317 | return cr; |
| 318 | } |
| 319 | |
Hiroshi DOYU | a9dcad5 | 2009-01-26 15:13:40 +0200 | [diff] [blame] | 320 | /** |
| 321 | * load_iotlb_entry - Set an iommu tlb entry |
| 322 | * @obj: target iommu |
| 323 | * @e: an iommu tlb entry info |
| 324 | **/ |
Ohad Ben-Cohen | 6c32df4 | 2011-08-17 22:57:56 +0300 | [diff] [blame] | 325 | static int load_iotlb_entry(struct omap_iommu *obj, struct iotlb_entry *e) |
Hiroshi DOYU | a9dcad5 | 2009-01-26 15:13:40 +0200 | [diff] [blame] | 326 | { |
Hiroshi DOYU | a9dcad5 | 2009-01-26 15:13:40 +0200 | [diff] [blame] | 327 | int err = 0; |
| 328 | struct iotlb_lock l; |
| 329 | struct cr_regs *cr; |
| 330 | |
| 331 | if (!obj || !obj->nr_tlb_entries || !e) |
| 332 | return -EINVAL; |
| 333 | |
Omar Ramirez Luna | ebf7cda | 2012-11-19 19:05:51 -0600 | [diff] [blame] | 334 | pm_runtime_get_sync(obj->dev); |
Hiroshi DOYU | a9dcad5 | 2009-01-26 15:13:40 +0200 | [diff] [blame] | 335 | |
Kanigeri, Hari | be6d802 | 2010-04-22 23:26:11 +0000 | [diff] [blame] | 336 | iotlb_lock_get(obj, &l); |
| 337 | if (l.base == obj->nr_tlb_entries) { |
| 338 | dev_warn(obj->dev, "%s: preserve entries full\n", __func__); |
Hiroshi DOYU | a9dcad5 | 2009-01-26 15:13:40 +0200 | [diff] [blame] | 339 | err = -EBUSY; |
| 340 | goto out; |
| 341 | } |
Kanigeri, Hari | be6d802 | 2010-04-22 23:26:11 +0000 | [diff] [blame] | 342 | if (!e->prsvd) { |
Hiroshi DOYU | 37c2836 | 2010-04-27 05:37:12 +0000 | [diff] [blame] | 343 | int i; |
| 344 | struct cr_regs tmp; |
Kanigeri, Hari | be6d802 | 2010-04-22 23:26:11 +0000 | [diff] [blame] | 345 | |
Hiroshi DOYU | 37c2836 | 2010-04-27 05:37:12 +0000 | [diff] [blame] | 346 | for_each_iotlb_cr(obj, obj->nr_tlb_entries, i, tmp) |
Kanigeri, Hari | be6d802 | 2010-04-22 23:26:11 +0000 | [diff] [blame] | 347 | if (!iotlb_cr_valid(&tmp)) |
| 348 | break; |
Hiroshi DOYU | 37c2836 | 2010-04-27 05:37:12 +0000 | [diff] [blame] | 349 | |
Kanigeri, Hari | be6d802 | 2010-04-22 23:26:11 +0000 | [diff] [blame] | 350 | if (i == obj->nr_tlb_entries) { |
| 351 | dev_dbg(obj->dev, "%s: full: no entry\n", __func__); |
| 352 | err = -EBUSY; |
| 353 | goto out; |
| 354 | } |
Hiroshi DOYU | 37c2836 | 2010-04-27 05:37:12 +0000 | [diff] [blame] | 355 | |
| 356 | iotlb_lock_get(obj, &l); |
Kanigeri, Hari | be6d802 | 2010-04-22 23:26:11 +0000 | [diff] [blame] | 357 | } else { |
| 358 | l.vict = l.base; |
| 359 | iotlb_lock_set(obj, &l); |
| 360 | } |
Hiroshi DOYU | a9dcad5 | 2009-01-26 15:13:40 +0200 | [diff] [blame] | 361 | |
| 362 | cr = iotlb_alloc_cr(obj, e); |
| 363 | if (IS_ERR(cr)) { |
Omar Ramirez Luna | ebf7cda | 2012-11-19 19:05:51 -0600 | [diff] [blame] | 364 | pm_runtime_put_sync(obj->dev); |
Hiroshi DOYU | a9dcad5 | 2009-01-26 15:13:40 +0200 | [diff] [blame] | 365 | return PTR_ERR(cr); |
| 366 | } |
| 367 | |
| 368 | iotlb_load_cr(obj, cr); |
| 369 | kfree(cr); |
| 370 | |
Kanigeri, Hari | be6d802 | 2010-04-22 23:26:11 +0000 | [diff] [blame] | 371 | if (e->prsvd) |
| 372 | l.base++; |
Hiroshi DOYU | a9dcad5 | 2009-01-26 15:13:40 +0200 | [diff] [blame] | 373 | /* increment victim for next tlb load */ |
| 374 | if (++l.vict == obj->nr_tlb_entries) |
Kanigeri, Hari | be6d802 | 2010-04-22 23:26:11 +0000 | [diff] [blame] | 375 | l.vict = l.base; |
Hiroshi DOYU | a9dcad5 | 2009-01-26 15:13:40 +0200 | [diff] [blame] | 376 | iotlb_lock_set(obj, &l); |
| 377 | out: |
Omar Ramirez Luna | ebf7cda | 2012-11-19 19:05:51 -0600 | [diff] [blame] | 378 | pm_runtime_put_sync(obj->dev); |
Hiroshi DOYU | a9dcad5 | 2009-01-26 15:13:40 +0200 | [diff] [blame] | 379 | return err; |
| 380 | } |
Hiroshi DOYU | a9dcad5 | 2009-01-26 15:13:40 +0200 | [diff] [blame] | 381 | |
Ohad Ben-Cohen | 5da14a4 | 2011-08-16 15:19:10 +0300 | [diff] [blame] | 382 | #else /* !PREFETCH_IOTLB */ |
| 383 | |
Ohad Ben-Cohen | 6c32df4 | 2011-08-17 22:57:56 +0300 | [diff] [blame] | 384 | static int load_iotlb_entry(struct omap_iommu *obj, struct iotlb_entry *e) |
Ohad Ben-Cohen | 5da14a4 | 2011-08-16 15:19:10 +0300 | [diff] [blame] | 385 | { |
| 386 | return 0; |
| 387 | } |
| 388 | |
| 389 | #endif /* !PREFETCH_IOTLB */ |
| 390 | |
Ohad Ben-Cohen | 6c32df4 | 2011-08-17 22:57:56 +0300 | [diff] [blame] | 391 | static int prefetch_iotlb_entry(struct omap_iommu *obj, struct iotlb_entry *e) |
Ohad Ben-Cohen | 5da14a4 | 2011-08-16 15:19:10 +0300 | [diff] [blame] | 392 | { |
| 393 | return load_iotlb_entry(obj, e); |
| 394 | } |
Hiroshi DOYU | a9dcad5 | 2009-01-26 15:13:40 +0200 | [diff] [blame] | 395 | |
| 396 | /** |
| 397 | * flush_iotlb_page - Clear an iommu tlb entry |
| 398 | * @obj: target iommu |
| 399 | * @da: iommu device virtual address |
| 400 | * |
| 401 | * Clear an iommu tlb entry which includes 'da' address. |
| 402 | **/ |
Ohad Ben-Cohen | 6c32df4 | 2011-08-17 22:57:56 +0300 | [diff] [blame] | 403 | static void flush_iotlb_page(struct omap_iommu *obj, u32 da) |
Hiroshi DOYU | a9dcad5 | 2009-01-26 15:13:40 +0200 | [diff] [blame] | 404 | { |
Hiroshi DOYU | a9dcad5 | 2009-01-26 15:13:40 +0200 | [diff] [blame] | 405 | int i; |
Hiroshi DOYU | 37c2836 | 2010-04-27 05:37:12 +0000 | [diff] [blame] | 406 | struct cr_regs cr; |
Hiroshi DOYU | a9dcad5 | 2009-01-26 15:13:40 +0200 | [diff] [blame] | 407 | |
Omar Ramirez Luna | ebf7cda | 2012-11-19 19:05:51 -0600 | [diff] [blame] | 408 | pm_runtime_get_sync(obj->dev); |
Hiroshi DOYU | a9dcad5 | 2009-01-26 15:13:40 +0200 | [diff] [blame] | 409 | |
Hiroshi DOYU | 37c2836 | 2010-04-27 05:37:12 +0000 | [diff] [blame] | 410 | for_each_iotlb_cr(obj, obj->nr_tlb_entries, i, cr) { |
Hiroshi DOYU | a9dcad5 | 2009-01-26 15:13:40 +0200 | [diff] [blame] | 411 | u32 start; |
| 412 | size_t bytes; |
| 413 | |
Hiroshi DOYU | a9dcad5 | 2009-01-26 15:13:40 +0200 | [diff] [blame] | 414 | if (!iotlb_cr_valid(&cr)) |
| 415 | continue; |
| 416 | |
| 417 | start = iotlb_cr_to_virt(&cr); |
| 418 | bytes = iopgsz_to_bytes(cr.cam & 3); |
| 419 | |
| 420 | if ((start <= da) && (da < start + bytes)) { |
| 421 | dev_dbg(obj->dev, "%s: %08x<=%08x(%x)\n", |
| 422 | __func__, start, da, bytes); |
Hari Kanigeri | 0fa035e | 2010-08-20 13:50:18 +0000 | [diff] [blame] | 423 | iotlb_load_cr(obj, &cr); |
Hiroshi DOYU | a9dcad5 | 2009-01-26 15:13:40 +0200 | [diff] [blame] | 424 | iommu_write_reg(obj, 1, MMU_FLUSH_ENTRY); |
Laurent Pinchart | f7129a0 | 2014-03-07 23:47:03 +0100 | [diff] [blame] | 425 | break; |
Hiroshi DOYU | a9dcad5 | 2009-01-26 15:13:40 +0200 | [diff] [blame] | 426 | } |
| 427 | } |
Omar Ramirez Luna | ebf7cda | 2012-11-19 19:05:51 -0600 | [diff] [blame] | 428 | pm_runtime_put_sync(obj->dev); |
Hiroshi DOYU | a9dcad5 | 2009-01-26 15:13:40 +0200 | [diff] [blame] | 429 | |
| 430 | if (i == obj->nr_tlb_entries) |
| 431 | dev_dbg(obj->dev, "%s: no page for %08x\n", __func__, da); |
| 432 | } |
Hiroshi DOYU | a9dcad5 | 2009-01-26 15:13:40 +0200 | [diff] [blame] | 433 | |
| 434 | /** |
| 435 | * flush_iotlb_all - Clear all iommu tlb entries |
| 436 | * @obj: target iommu |
| 437 | **/ |
Ohad Ben-Cohen | 6c32df4 | 2011-08-17 22:57:56 +0300 | [diff] [blame] | 438 | static void flush_iotlb_all(struct omap_iommu *obj) |
Hiroshi DOYU | a9dcad5 | 2009-01-26 15:13:40 +0200 | [diff] [blame] | 439 | { |
| 440 | struct iotlb_lock l; |
| 441 | |
Omar Ramirez Luna | ebf7cda | 2012-11-19 19:05:51 -0600 | [diff] [blame] | 442 | pm_runtime_get_sync(obj->dev); |
Hiroshi DOYU | a9dcad5 | 2009-01-26 15:13:40 +0200 | [diff] [blame] | 443 | |
| 444 | l.base = 0; |
| 445 | l.vict = 0; |
| 446 | iotlb_lock_set(obj, &l); |
| 447 | |
| 448 | iommu_write_reg(obj, 1, MMU_GFLUSH); |
| 449 | |
Omar Ramirez Luna | ebf7cda | 2012-11-19 19:05:51 -0600 | [diff] [blame] | 450 | pm_runtime_put_sync(obj->dev); |
Hiroshi DOYU | a9dcad5 | 2009-01-26 15:13:40 +0200 | [diff] [blame] | 451 | } |
Hiroshi DOYU | a9dcad5 | 2009-01-26 15:13:40 +0200 | [diff] [blame] | 452 | |
Hiroshi DOYU | a9dcad5 | 2009-01-26 15:13:40 +0200 | [diff] [blame] | 453 | /* |
| 454 | * H/W pagetable operations |
| 455 | */ |
Josue Albarran | bfee0cf | 2017-07-28 15:49:14 -0500 | [diff] [blame^] | 456 | static void flush_iopte_range(struct device *dev, dma_addr_t dma, |
| 457 | unsigned long offset, int num_entries) |
Hiroshi DOYU | a9dcad5 | 2009-01-26 15:13:40 +0200 | [diff] [blame] | 458 | { |
Josue Albarran | bfee0cf | 2017-07-28 15:49:14 -0500 | [diff] [blame^] | 459 | size_t size = num_entries * sizeof(u32); |
| 460 | |
| 461 | dma_sync_single_range_for_device(dev, dma, offset, size, DMA_TO_DEVICE); |
Hiroshi DOYU | a9dcad5 | 2009-01-26 15:13:40 +0200 | [diff] [blame] | 462 | } |
| 463 | |
Josue Albarran | bfee0cf | 2017-07-28 15:49:14 -0500 | [diff] [blame^] | 464 | static void iopte_free(struct omap_iommu *obj, u32 *iopte, bool dma_valid) |
Hiroshi DOYU | a9dcad5 | 2009-01-26 15:13:40 +0200 | [diff] [blame] | 465 | { |
Josue Albarran | bfee0cf | 2017-07-28 15:49:14 -0500 | [diff] [blame^] | 466 | dma_addr_t pt_dma; |
Hiroshi DOYU | a9dcad5 | 2009-01-26 15:13:40 +0200 | [diff] [blame] | 467 | |
Hiroshi DOYU | a9dcad5 | 2009-01-26 15:13:40 +0200 | [diff] [blame] | 468 | /* Note: freed iopte's must be clean ready for re-use */ |
Josue Albarran | bfee0cf | 2017-07-28 15:49:14 -0500 | [diff] [blame^] | 469 | if (iopte) { |
| 470 | if (dma_valid) { |
| 471 | pt_dma = virt_to_phys(iopte); |
| 472 | dma_unmap_single(obj->dev, pt_dma, IOPTE_TABLE_SIZE, |
| 473 | DMA_TO_DEVICE); |
| 474 | } |
| 475 | |
Zhouyi Zhou | e28045a | 2014-03-05 18:20:19 +0800 | [diff] [blame] | 476 | kmem_cache_free(iopte_cachep, iopte); |
Josue Albarran | bfee0cf | 2017-07-28 15:49:14 -0500 | [diff] [blame^] | 477 | } |
Hiroshi DOYU | a9dcad5 | 2009-01-26 15:13:40 +0200 | [diff] [blame] | 478 | } |
| 479 | |
Josue Albarran | bfee0cf | 2017-07-28 15:49:14 -0500 | [diff] [blame^] | 480 | static u32 *iopte_alloc(struct omap_iommu *obj, u32 *iopgd, |
| 481 | dma_addr_t *pt_dma, u32 da) |
Hiroshi DOYU | a9dcad5 | 2009-01-26 15:13:40 +0200 | [diff] [blame] | 482 | { |
| 483 | u32 *iopte; |
Josue Albarran | bfee0cf | 2017-07-28 15:49:14 -0500 | [diff] [blame^] | 484 | unsigned long offset = iopgd_index(da) * sizeof(da); |
Hiroshi DOYU | a9dcad5 | 2009-01-26 15:13:40 +0200 | [diff] [blame] | 485 | |
| 486 | /* a table has already existed */ |
| 487 | if (*iopgd) |
| 488 | goto pte_ready; |
| 489 | |
| 490 | /* |
| 491 | * do the allocation outside the page table lock |
| 492 | */ |
| 493 | spin_unlock(&obj->page_table_lock); |
| 494 | iopte = kmem_cache_zalloc(iopte_cachep, GFP_KERNEL); |
| 495 | spin_lock(&obj->page_table_lock); |
| 496 | |
| 497 | if (!*iopgd) { |
| 498 | if (!iopte) |
| 499 | return ERR_PTR(-ENOMEM); |
| 500 | |
Josue Albarran | bfee0cf | 2017-07-28 15:49:14 -0500 | [diff] [blame^] | 501 | *pt_dma = dma_map_single(obj->dev, iopte, IOPTE_TABLE_SIZE, |
| 502 | DMA_TO_DEVICE); |
| 503 | if (dma_mapping_error(obj->dev, *pt_dma)) { |
| 504 | dev_err(obj->dev, "DMA map error for L2 table\n"); |
| 505 | iopte_free(obj, iopte, false); |
| 506 | return ERR_PTR(-ENOMEM); |
| 507 | } |
Hiroshi DOYU | a9dcad5 | 2009-01-26 15:13:40 +0200 | [diff] [blame] | 508 | |
Josue Albarran | bfee0cf | 2017-07-28 15:49:14 -0500 | [diff] [blame^] | 509 | /* |
| 510 | * we rely on dma address and the physical address to be |
| 511 | * the same for mapping the L2 table |
| 512 | */ |
| 513 | if (WARN_ON(*pt_dma != virt_to_phys(iopte))) { |
| 514 | dev_err(obj->dev, "DMA translation error for L2 table\n"); |
| 515 | dma_unmap_single(obj->dev, *pt_dma, IOPTE_TABLE_SIZE, |
| 516 | DMA_TO_DEVICE); |
| 517 | iopte_free(obj, iopte, false); |
| 518 | return ERR_PTR(-ENOMEM); |
| 519 | } |
| 520 | |
| 521 | *iopgd = virt_to_phys(iopte) | IOPGD_TABLE; |
| 522 | |
| 523 | flush_iopte_range(obj->dev, obj->pd_dma, offset, 1); |
Hiroshi DOYU | a9dcad5 | 2009-01-26 15:13:40 +0200 | [diff] [blame] | 524 | dev_vdbg(obj->dev, "%s: a new pte:%p\n", __func__, iopte); |
| 525 | } else { |
| 526 | /* We raced, free the reduniovant table */ |
Josue Albarran | bfee0cf | 2017-07-28 15:49:14 -0500 | [diff] [blame^] | 527 | iopte_free(obj, iopte, false); |
Hiroshi DOYU | a9dcad5 | 2009-01-26 15:13:40 +0200 | [diff] [blame] | 528 | } |
| 529 | |
| 530 | pte_ready: |
| 531 | iopte = iopte_offset(iopgd, da); |
Josue Albarran | bfee0cf | 2017-07-28 15:49:14 -0500 | [diff] [blame^] | 532 | *pt_dma = virt_to_phys(iopte); |
Hiroshi DOYU | a9dcad5 | 2009-01-26 15:13:40 +0200 | [diff] [blame] | 533 | dev_vdbg(obj->dev, |
| 534 | "%s: da:%08x pgd:%p *pgd:%08x pte:%p *pte:%08x\n", |
| 535 | __func__, da, iopgd, *iopgd, iopte, *iopte); |
| 536 | |
| 537 | return iopte; |
| 538 | } |
| 539 | |
Ohad Ben-Cohen | 6c32df4 | 2011-08-17 22:57:56 +0300 | [diff] [blame] | 540 | static int iopgd_alloc_section(struct omap_iommu *obj, u32 da, u32 pa, u32 prot) |
Hiroshi DOYU | a9dcad5 | 2009-01-26 15:13:40 +0200 | [diff] [blame] | 541 | { |
| 542 | u32 *iopgd = iopgd_offset(obj, da); |
Josue Albarran | bfee0cf | 2017-07-28 15:49:14 -0500 | [diff] [blame^] | 543 | unsigned long offset = iopgd_index(da) * sizeof(da); |
Hiroshi DOYU | a9dcad5 | 2009-01-26 15:13:40 +0200 | [diff] [blame] | 544 | |
Hiroshi DOYU | 4abb761 | 2010-05-06 18:24:04 +0300 | [diff] [blame] | 545 | if ((da | pa) & ~IOSECTION_MASK) { |
| 546 | dev_err(obj->dev, "%s: %08x:%08x should aligned on %08lx\n", |
| 547 | __func__, da, pa, IOSECTION_SIZE); |
| 548 | return -EINVAL; |
| 549 | } |
| 550 | |
Hiroshi DOYU | a9dcad5 | 2009-01-26 15:13:40 +0200 | [diff] [blame] | 551 | *iopgd = (pa & IOSECTION_MASK) | prot | IOPGD_SECTION; |
Josue Albarran | bfee0cf | 2017-07-28 15:49:14 -0500 | [diff] [blame^] | 552 | flush_iopte_range(obj->dev, obj->pd_dma, offset, 1); |
Hiroshi DOYU | a9dcad5 | 2009-01-26 15:13:40 +0200 | [diff] [blame] | 553 | return 0; |
| 554 | } |
| 555 | |
Ohad Ben-Cohen | 6c32df4 | 2011-08-17 22:57:56 +0300 | [diff] [blame] | 556 | static int iopgd_alloc_super(struct omap_iommu *obj, u32 da, u32 pa, u32 prot) |
Hiroshi DOYU | a9dcad5 | 2009-01-26 15:13:40 +0200 | [diff] [blame] | 557 | { |
| 558 | u32 *iopgd = iopgd_offset(obj, da); |
Josue Albarran | bfee0cf | 2017-07-28 15:49:14 -0500 | [diff] [blame^] | 559 | unsigned long offset = iopgd_index(da) * sizeof(da); |
Hiroshi DOYU | a9dcad5 | 2009-01-26 15:13:40 +0200 | [diff] [blame] | 560 | int i; |
| 561 | |
Hiroshi DOYU | 4abb761 | 2010-05-06 18:24:04 +0300 | [diff] [blame] | 562 | if ((da | pa) & ~IOSUPER_MASK) { |
| 563 | dev_err(obj->dev, "%s: %08x:%08x should aligned on %08lx\n", |
| 564 | __func__, da, pa, IOSUPER_SIZE); |
| 565 | return -EINVAL; |
| 566 | } |
| 567 | |
Hiroshi DOYU | a9dcad5 | 2009-01-26 15:13:40 +0200 | [diff] [blame] | 568 | for (i = 0; i < 16; i++) |
| 569 | *(iopgd + i) = (pa & IOSUPER_MASK) | prot | IOPGD_SUPER; |
Josue Albarran | bfee0cf | 2017-07-28 15:49:14 -0500 | [diff] [blame^] | 570 | flush_iopte_range(obj->dev, obj->pd_dma, offset, 16); |
Hiroshi DOYU | a9dcad5 | 2009-01-26 15:13:40 +0200 | [diff] [blame] | 571 | return 0; |
| 572 | } |
| 573 | |
Ohad Ben-Cohen | 6c32df4 | 2011-08-17 22:57:56 +0300 | [diff] [blame] | 574 | static int iopte_alloc_page(struct omap_iommu *obj, u32 da, u32 pa, u32 prot) |
Hiroshi DOYU | a9dcad5 | 2009-01-26 15:13:40 +0200 | [diff] [blame] | 575 | { |
| 576 | u32 *iopgd = iopgd_offset(obj, da); |
Josue Albarran | bfee0cf | 2017-07-28 15:49:14 -0500 | [diff] [blame^] | 577 | dma_addr_t pt_dma; |
| 578 | u32 *iopte = iopte_alloc(obj, iopgd, &pt_dma, da); |
| 579 | unsigned long offset = iopte_index(da) * sizeof(da); |
Hiroshi DOYU | a9dcad5 | 2009-01-26 15:13:40 +0200 | [diff] [blame] | 580 | |
| 581 | if (IS_ERR(iopte)) |
| 582 | return PTR_ERR(iopte); |
| 583 | |
| 584 | *iopte = (pa & IOPAGE_MASK) | prot | IOPTE_SMALL; |
Josue Albarran | bfee0cf | 2017-07-28 15:49:14 -0500 | [diff] [blame^] | 585 | flush_iopte_range(obj->dev, pt_dma, offset, 1); |
Hiroshi DOYU | a9dcad5 | 2009-01-26 15:13:40 +0200 | [diff] [blame] | 586 | |
| 587 | dev_vdbg(obj->dev, "%s: da:%08x pa:%08x pte:%p *pte:%08x\n", |
| 588 | __func__, da, pa, iopte, *iopte); |
| 589 | |
| 590 | return 0; |
| 591 | } |
| 592 | |
Ohad Ben-Cohen | 6c32df4 | 2011-08-17 22:57:56 +0300 | [diff] [blame] | 593 | static int iopte_alloc_large(struct omap_iommu *obj, u32 da, u32 pa, u32 prot) |
Hiroshi DOYU | a9dcad5 | 2009-01-26 15:13:40 +0200 | [diff] [blame] | 594 | { |
| 595 | u32 *iopgd = iopgd_offset(obj, da); |
Josue Albarran | bfee0cf | 2017-07-28 15:49:14 -0500 | [diff] [blame^] | 596 | dma_addr_t pt_dma; |
| 597 | u32 *iopte = iopte_alloc(obj, iopgd, &pt_dma, da); |
| 598 | unsigned long offset = iopte_index(da) * sizeof(da); |
Hiroshi DOYU | a9dcad5 | 2009-01-26 15:13:40 +0200 | [diff] [blame] | 599 | int i; |
| 600 | |
Hiroshi DOYU | 4abb761 | 2010-05-06 18:24:04 +0300 | [diff] [blame] | 601 | if ((da | pa) & ~IOLARGE_MASK) { |
| 602 | dev_err(obj->dev, "%s: %08x:%08x should aligned on %08lx\n", |
| 603 | __func__, da, pa, IOLARGE_SIZE); |
| 604 | return -EINVAL; |
| 605 | } |
| 606 | |
Hiroshi DOYU | a9dcad5 | 2009-01-26 15:13:40 +0200 | [diff] [blame] | 607 | if (IS_ERR(iopte)) |
| 608 | return PTR_ERR(iopte); |
| 609 | |
| 610 | for (i = 0; i < 16; i++) |
| 611 | *(iopte + i) = (pa & IOLARGE_MASK) | prot | IOPTE_LARGE; |
Josue Albarran | bfee0cf | 2017-07-28 15:49:14 -0500 | [diff] [blame^] | 612 | flush_iopte_range(obj->dev, pt_dma, offset, 16); |
Hiroshi DOYU | a9dcad5 | 2009-01-26 15:13:40 +0200 | [diff] [blame] | 613 | return 0; |
| 614 | } |
| 615 | |
Ohad Ben-Cohen | 6c32df4 | 2011-08-17 22:57:56 +0300 | [diff] [blame] | 616 | static int |
| 617 | iopgtable_store_entry_core(struct omap_iommu *obj, struct iotlb_entry *e) |
Hiroshi DOYU | a9dcad5 | 2009-01-26 15:13:40 +0200 | [diff] [blame] | 618 | { |
Ohad Ben-Cohen | 6c32df4 | 2011-08-17 22:57:56 +0300 | [diff] [blame] | 619 | int (*fn)(struct omap_iommu *, u32, u32, u32); |
Hiroshi DOYU | a9dcad5 | 2009-01-26 15:13:40 +0200 | [diff] [blame] | 620 | u32 prot; |
| 621 | int err; |
| 622 | |
| 623 | if (!obj || !e) |
| 624 | return -EINVAL; |
| 625 | |
| 626 | switch (e->pgsz) { |
| 627 | case MMU_CAM_PGSZ_16M: |
| 628 | fn = iopgd_alloc_super; |
| 629 | break; |
| 630 | case MMU_CAM_PGSZ_1M: |
| 631 | fn = iopgd_alloc_section; |
| 632 | break; |
| 633 | case MMU_CAM_PGSZ_64K: |
| 634 | fn = iopte_alloc_large; |
| 635 | break; |
| 636 | case MMU_CAM_PGSZ_4K: |
| 637 | fn = iopte_alloc_page; |
| 638 | break; |
| 639 | default: |
| 640 | fn = NULL; |
Hiroshi DOYU | a9dcad5 | 2009-01-26 15:13:40 +0200 | [diff] [blame] | 641 | break; |
| 642 | } |
| 643 | |
Suman Anna | 7c1ab60 | 2016-04-04 17:46:19 -0500 | [diff] [blame] | 644 | if (WARN_ON(!fn)) |
| 645 | return -EINVAL; |
| 646 | |
Hiroshi DOYU | a9dcad5 | 2009-01-26 15:13:40 +0200 | [diff] [blame] | 647 | prot = get_iopte_attr(e); |
| 648 | |
| 649 | spin_lock(&obj->page_table_lock); |
| 650 | err = fn(obj, e->da, e->pa, prot); |
| 651 | spin_unlock(&obj->page_table_lock); |
| 652 | |
| 653 | return err; |
| 654 | } |
| 655 | |
| 656 | /** |
Ohad Ben-Cohen | 6c32df4 | 2011-08-17 22:57:56 +0300 | [diff] [blame] | 657 | * omap_iopgtable_store_entry - Make an iommu pte entry |
Hiroshi DOYU | a9dcad5 | 2009-01-26 15:13:40 +0200 | [diff] [blame] | 658 | * @obj: target iommu |
| 659 | * @e: an iommu tlb entry info |
| 660 | **/ |
Suman Anna | 4899a56 | 2014-10-22 17:22:32 -0500 | [diff] [blame] | 661 | static int |
| 662 | omap_iopgtable_store_entry(struct omap_iommu *obj, struct iotlb_entry *e) |
Hiroshi DOYU | a9dcad5 | 2009-01-26 15:13:40 +0200 | [diff] [blame] | 663 | { |
| 664 | int err; |
| 665 | |
| 666 | flush_iotlb_page(obj, e->da); |
| 667 | err = iopgtable_store_entry_core(obj, e); |
Hiroshi DOYU | a9dcad5 | 2009-01-26 15:13:40 +0200 | [diff] [blame] | 668 | if (!err) |
Ohad Ben-Cohen | 5da14a4 | 2011-08-16 15:19:10 +0300 | [diff] [blame] | 669 | prefetch_iotlb_entry(obj, e); |
Hiroshi DOYU | a9dcad5 | 2009-01-26 15:13:40 +0200 | [diff] [blame] | 670 | return err; |
| 671 | } |
Hiroshi DOYU | a9dcad5 | 2009-01-26 15:13:40 +0200 | [diff] [blame] | 672 | |
| 673 | /** |
| 674 | * iopgtable_lookup_entry - Lookup an iommu pte entry |
| 675 | * @obj: target iommu |
| 676 | * @da: iommu device virtual address |
| 677 | * @ppgd: iommu pgd entry pointer to be returned |
| 678 | * @ppte: iommu pte entry pointer to be returned |
| 679 | **/ |
Ohad Ben-Cohen | e1f2381 | 2011-08-16 14:58:14 +0300 | [diff] [blame] | 680 | static void |
| 681 | iopgtable_lookup_entry(struct omap_iommu *obj, u32 da, u32 **ppgd, u32 **ppte) |
Hiroshi DOYU | a9dcad5 | 2009-01-26 15:13:40 +0200 | [diff] [blame] | 682 | { |
| 683 | u32 *iopgd, *iopte = NULL; |
| 684 | |
| 685 | iopgd = iopgd_offset(obj, da); |
| 686 | if (!*iopgd) |
| 687 | goto out; |
| 688 | |
Hiroshi DOYU | a1a5445 | 2010-05-13 09:45:35 +0300 | [diff] [blame] | 689 | if (iopgd_is_table(*iopgd)) |
Hiroshi DOYU | a9dcad5 | 2009-01-26 15:13:40 +0200 | [diff] [blame] | 690 | iopte = iopte_offset(iopgd, da); |
| 691 | out: |
| 692 | *ppgd = iopgd; |
| 693 | *ppte = iopte; |
| 694 | } |
Hiroshi DOYU | a9dcad5 | 2009-01-26 15:13:40 +0200 | [diff] [blame] | 695 | |
Ohad Ben-Cohen | 6c32df4 | 2011-08-17 22:57:56 +0300 | [diff] [blame] | 696 | static size_t iopgtable_clear_entry_core(struct omap_iommu *obj, u32 da) |
Hiroshi DOYU | a9dcad5 | 2009-01-26 15:13:40 +0200 | [diff] [blame] | 697 | { |
| 698 | size_t bytes; |
| 699 | u32 *iopgd = iopgd_offset(obj, da); |
| 700 | int nent = 1; |
Josue Albarran | bfee0cf | 2017-07-28 15:49:14 -0500 | [diff] [blame^] | 701 | dma_addr_t pt_dma; |
| 702 | unsigned long pd_offset = iopgd_index(da) * sizeof(da); |
| 703 | unsigned long pt_offset = iopte_index(da) * sizeof(da); |
Hiroshi DOYU | a9dcad5 | 2009-01-26 15:13:40 +0200 | [diff] [blame] | 704 | |
| 705 | if (!*iopgd) |
| 706 | return 0; |
| 707 | |
Hiroshi DOYU | a1a5445 | 2010-05-13 09:45:35 +0300 | [diff] [blame] | 708 | if (iopgd_is_table(*iopgd)) { |
Hiroshi DOYU | a9dcad5 | 2009-01-26 15:13:40 +0200 | [diff] [blame] | 709 | int i; |
| 710 | u32 *iopte = iopte_offset(iopgd, da); |
| 711 | |
| 712 | bytes = IOPTE_SIZE; |
| 713 | if (*iopte & IOPTE_LARGE) { |
| 714 | nent *= 16; |
| 715 | /* rewind to the 1st entry */ |
Hiroshi DOYU | c127c7d | 2010-02-15 10:03:32 -0800 | [diff] [blame] | 716 | iopte = iopte_offset(iopgd, (da & IOLARGE_MASK)); |
Hiroshi DOYU | a9dcad5 | 2009-01-26 15:13:40 +0200 | [diff] [blame] | 717 | } |
| 718 | bytes *= nent; |
| 719 | memset(iopte, 0, nent * sizeof(*iopte)); |
Josue Albarran | bfee0cf | 2017-07-28 15:49:14 -0500 | [diff] [blame^] | 720 | pt_dma = virt_to_phys(iopte); |
| 721 | flush_iopte_range(obj->dev, pt_dma, pt_offset, nent); |
Hiroshi DOYU | a9dcad5 | 2009-01-26 15:13:40 +0200 | [diff] [blame] | 722 | |
| 723 | /* |
| 724 | * do table walk to check if this table is necessary or not |
| 725 | */ |
| 726 | iopte = iopte_offset(iopgd, 0); |
| 727 | for (i = 0; i < PTRS_PER_IOPTE; i++) |
| 728 | if (iopte[i]) |
| 729 | goto out; |
| 730 | |
Josue Albarran | bfee0cf | 2017-07-28 15:49:14 -0500 | [diff] [blame^] | 731 | iopte_free(obj, iopte, true); |
Hiroshi DOYU | a9dcad5 | 2009-01-26 15:13:40 +0200 | [diff] [blame] | 732 | nent = 1; /* for the next L1 entry */ |
| 733 | } else { |
| 734 | bytes = IOPGD_SIZE; |
Hiroshi DOYU | dcc730d | 2009-10-22 14:46:32 -0700 | [diff] [blame] | 735 | if ((*iopgd & IOPGD_SUPER) == IOPGD_SUPER) { |
Hiroshi DOYU | a9dcad5 | 2009-01-26 15:13:40 +0200 | [diff] [blame] | 736 | nent *= 16; |
| 737 | /* rewind to the 1st entry */ |
Hiroshi DOYU | 8d33ea5 | 2010-02-15 10:03:32 -0800 | [diff] [blame] | 738 | iopgd = iopgd_offset(obj, (da & IOSUPER_MASK)); |
Hiroshi DOYU | a9dcad5 | 2009-01-26 15:13:40 +0200 | [diff] [blame] | 739 | } |
| 740 | bytes *= nent; |
| 741 | } |
| 742 | memset(iopgd, 0, nent * sizeof(*iopgd)); |
Josue Albarran | bfee0cf | 2017-07-28 15:49:14 -0500 | [diff] [blame^] | 743 | flush_iopte_range(obj->dev, obj->pd_dma, pd_offset, nent); |
Hiroshi DOYU | a9dcad5 | 2009-01-26 15:13:40 +0200 | [diff] [blame] | 744 | out: |
| 745 | return bytes; |
| 746 | } |
| 747 | |
| 748 | /** |
| 749 | * iopgtable_clear_entry - Remove an iommu pte entry |
| 750 | * @obj: target iommu |
| 751 | * @da: iommu device virtual address |
| 752 | **/ |
Ohad Ben-Cohen | 6c32df4 | 2011-08-17 22:57:56 +0300 | [diff] [blame] | 753 | static size_t iopgtable_clear_entry(struct omap_iommu *obj, u32 da) |
Hiroshi DOYU | a9dcad5 | 2009-01-26 15:13:40 +0200 | [diff] [blame] | 754 | { |
| 755 | size_t bytes; |
| 756 | |
| 757 | spin_lock(&obj->page_table_lock); |
| 758 | |
| 759 | bytes = iopgtable_clear_entry_core(obj, da); |
| 760 | flush_iotlb_page(obj, da); |
| 761 | |
| 762 | spin_unlock(&obj->page_table_lock); |
| 763 | |
| 764 | return bytes; |
| 765 | } |
Hiroshi DOYU | a9dcad5 | 2009-01-26 15:13:40 +0200 | [diff] [blame] | 766 | |
Ohad Ben-Cohen | 6c32df4 | 2011-08-17 22:57:56 +0300 | [diff] [blame] | 767 | static void iopgtable_clear_entry_all(struct omap_iommu *obj) |
Hiroshi DOYU | a9dcad5 | 2009-01-26 15:13:40 +0200 | [diff] [blame] | 768 | { |
Josue Albarran | bfee0cf | 2017-07-28 15:49:14 -0500 | [diff] [blame^] | 769 | unsigned long offset; |
Hiroshi DOYU | a9dcad5 | 2009-01-26 15:13:40 +0200 | [diff] [blame] | 770 | int i; |
| 771 | |
| 772 | spin_lock(&obj->page_table_lock); |
| 773 | |
| 774 | for (i = 0; i < PTRS_PER_IOPGD; i++) { |
| 775 | u32 da; |
| 776 | u32 *iopgd; |
| 777 | |
| 778 | da = i << IOPGD_SHIFT; |
| 779 | iopgd = iopgd_offset(obj, da); |
Josue Albarran | bfee0cf | 2017-07-28 15:49:14 -0500 | [diff] [blame^] | 780 | offset = iopgd_index(da) * sizeof(da); |
Hiroshi DOYU | a9dcad5 | 2009-01-26 15:13:40 +0200 | [diff] [blame] | 781 | |
| 782 | if (!*iopgd) |
| 783 | continue; |
| 784 | |
Hiroshi DOYU | a1a5445 | 2010-05-13 09:45:35 +0300 | [diff] [blame] | 785 | if (iopgd_is_table(*iopgd)) |
Josue Albarran | bfee0cf | 2017-07-28 15:49:14 -0500 | [diff] [blame^] | 786 | iopte_free(obj, iopte_offset(iopgd, 0), true); |
Hiroshi DOYU | a9dcad5 | 2009-01-26 15:13:40 +0200 | [diff] [blame] | 787 | |
| 788 | *iopgd = 0; |
Josue Albarran | bfee0cf | 2017-07-28 15:49:14 -0500 | [diff] [blame^] | 789 | flush_iopte_range(obj->dev, obj->pd_dma, offset, 1); |
Hiroshi DOYU | a9dcad5 | 2009-01-26 15:13:40 +0200 | [diff] [blame] | 790 | } |
| 791 | |
| 792 | flush_iotlb_all(obj); |
| 793 | |
| 794 | spin_unlock(&obj->page_table_lock); |
| 795 | } |
| 796 | |
| 797 | /* |
| 798 | * Device IOMMU generic operations |
| 799 | */ |
| 800 | static irqreturn_t iommu_fault_handler(int irq, void *data) |
| 801 | { |
David Cohen | d594f1f | 2011-02-16 19:35:51 +0000 | [diff] [blame] | 802 | u32 da, errs; |
Hiroshi DOYU | a9dcad5 | 2009-01-26 15:13:40 +0200 | [diff] [blame] | 803 | u32 *iopgd, *iopte; |
Ohad Ben-Cohen | 6c32df4 | 2011-08-17 22:57:56 +0300 | [diff] [blame] | 804 | struct omap_iommu *obj = data; |
Ohad Ben-Cohen | e7f10f0 | 2011-09-13 15:26:29 -0400 | [diff] [blame] | 805 | struct iommu_domain *domain = obj->domain; |
Joerg Roedel | 8cf851e | 2015-03-26 13:43:09 +0100 | [diff] [blame] | 806 | struct omap_iommu_domain *omap_domain = to_omap_domain(domain); |
Hiroshi DOYU | a9dcad5 | 2009-01-26 15:13:40 +0200 | [diff] [blame] | 807 | |
Suman Anna | 2088ecb | 2014-10-22 17:22:19 -0500 | [diff] [blame] | 808 | if (!omap_domain->iommu_dev) |
Hiroshi DOYU | a9dcad5 | 2009-01-26 15:13:40 +0200 | [diff] [blame] | 809 | return IRQ_NONE; |
| 810 | |
David Cohen | d594f1f | 2011-02-16 19:35:51 +0000 | [diff] [blame] | 811 | errs = iommu_report_fault(obj, &da); |
Laurent Pinchart | c56b2dd | 2011-05-10 16:56:46 +0200 | [diff] [blame] | 812 | if (errs == 0) |
| 813 | return IRQ_HANDLED; |
David Cohen | d594f1f | 2011-02-16 19:35:51 +0000 | [diff] [blame] | 814 | |
| 815 | /* Fault callback or TLB/PTE Dynamic loading */ |
Ohad Ben-Cohen | e7f10f0 | 2011-09-13 15:26:29 -0400 | [diff] [blame] | 816 | if (!report_iommu_fault(domain, obj->dev, da, 0)) |
Hiroshi DOYU | a9dcad5 | 2009-01-26 15:13:40 +0200 | [diff] [blame] | 817 | return IRQ_HANDLED; |
| 818 | |
Fernando Guzman Lugo | 159d3e3 | 2017-07-28 15:49:13 -0500 | [diff] [blame] | 819 | iommu_write_reg(obj, 0, MMU_IRQENABLE); |
Hiroshi DOYU | 37b2981 | 2010-05-24 02:01:52 +0000 | [diff] [blame] | 820 | |
Hiroshi DOYU | a9dcad5 | 2009-01-26 15:13:40 +0200 | [diff] [blame] | 821 | iopgd = iopgd_offset(obj, da); |
| 822 | |
Hiroshi DOYU | a1a5445 | 2010-05-13 09:45:35 +0300 | [diff] [blame] | 823 | if (!iopgd_is_table(*iopgd)) { |
Suman Anna | b6c2e09 | 2013-05-30 18:10:59 -0500 | [diff] [blame] | 824 | dev_err(obj->dev, "%s: errs:0x%08x da:0x%08x pgd:0x%p *pgd:px%08x\n", |
Suman Anna | 5835b6a | 2015-07-20 17:33:32 -0500 | [diff] [blame] | 825 | obj->name, errs, da, iopgd, *iopgd); |
Hiroshi DOYU | a9dcad5 | 2009-01-26 15:13:40 +0200 | [diff] [blame] | 826 | return IRQ_NONE; |
| 827 | } |
| 828 | |
| 829 | iopte = iopte_offset(iopgd, da); |
| 830 | |
Suman Anna | b6c2e09 | 2013-05-30 18:10:59 -0500 | [diff] [blame] | 831 | dev_err(obj->dev, "%s: errs:0x%08x da:0x%08x pgd:0x%p *pgd:0x%08x pte:0x%p *pte:0x%08x\n", |
Suman Anna | 5835b6a | 2015-07-20 17:33:32 -0500 | [diff] [blame] | 832 | obj->name, errs, da, iopgd, *iopgd, iopte, *iopte); |
Hiroshi DOYU | a9dcad5 | 2009-01-26 15:13:40 +0200 | [diff] [blame] | 833 | |
| 834 | return IRQ_NONE; |
| 835 | } |
| 836 | |
Hiroshi DOYU | a9dcad5 | 2009-01-26 15:13:40 +0200 | [diff] [blame] | 837 | /** |
Ohad Ben-Cohen | f626b52 | 2011-06-02 01:46:12 +0300 | [diff] [blame] | 838 | * omap_iommu_attach() - attach iommu device to an iommu domain |
Joerg Roedel | ede1c2e | 2017-04-12 00:21:29 -0500 | [diff] [blame] | 839 | * @obj: target omap iommu device |
Ohad Ben-Cohen | f626b52 | 2011-06-02 01:46:12 +0300 | [diff] [blame] | 840 | * @iopgd: page table |
Hiroshi DOYU | a9dcad5 | 2009-01-26 15:13:40 +0200 | [diff] [blame] | 841 | **/ |
Joerg Roedel | ede1c2e | 2017-04-12 00:21:29 -0500 | [diff] [blame] | 842 | static int omap_iommu_attach(struct omap_iommu *obj, u32 *iopgd) |
Hiroshi DOYU | a9dcad5 | 2009-01-26 15:13:40 +0200 | [diff] [blame] | 843 | { |
Suman Anna | 7ee08b9e | 2014-02-28 14:42:33 -0600 | [diff] [blame] | 844 | int err; |
Hiroshi DOYU | a9dcad5 | 2009-01-26 15:13:40 +0200 | [diff] [blame] | 845 | |
Ohad Ben-Cohen | f626b52 | 2011-06-02 01:46:12 +0300 | [diff] [blame] | 846 | spin_lock(&obj->iommu_lock); |
Hiroshi DOYU | a9dcad5 | 2009-01-26 15:13:40 +0200 | [diff] [blame] | 847 | |
Josue Albarran | bfee0cf | 2017-07-28 15:49:14 -0500 | [diff] [blame^] | 848 | obj->pd_dma = dma_map_single(obj->dev, iopgd, IOPGD_TABLE_SIZE, |
| 849 | DMA_TO_DEVICE); |
| 850 | if (dma_mapping_error(obj->dev, obj->pd_dma)) { |
| 851 | dev_err(obj->dev, "DMA map error for L1 table\n"); |
| 852 | err = -ENOMEM; |
| 853 | goto out_err; |
| 854 | } |
| 855 | |
Ohad Ben-Cohen | f626b52 | 2011-06-02 01:46:12 +0300 | [diff] [blame] | 856 | obj->iopgd = iopgd; |
| 857 | err = iommu_enable(obj); |
| 858 | if (err) |
Josue Albarran | bfee0cf | 2017-07-28 15:49:14 -0500 | [diff] [blame^] | 859 | goto out_err; |
Ohad Ben-Cohen | f626b52 | 2011-06-02 01:46:12 +0300 | [diff] [blame] | 860 | flush_iotlb_all(obj); |
| 861 | |
Ohad Ben-Cohen | f626b52 | 2011-06-02 01:46:12 +0300 | [diff] [blame] | 862 | spin_unlock(&obj->iommu_lock); |
Hiroshi DOYU | a9dcad5 | 2009-01-26 15:13:40 +0200 | [diff] [blame] | 863 | |
| 864 | dev_dbg(obj->dev, "%s: %s\n", __func__, obj->name); |
Joerg Roedel | ede1c2e | 2017-04-12 00:21:29 -0500 | [diff] [blame] | 865 | |
| 866 | return 0; |
Hiroshi DOYU | a9dcad5 | 2009-01-26 15:13:40 +0200 | [diff] [blame] | 867 | |
Josue Albarran | bfee0cf | 2017-07-28 15:49:14 -0500 | [diff] [blame^] | 868 | out_err: |
Ohad Ben-Cohen | f626b52 | 2011-06-02 01:46:12 +0300 | [diff] [blame] | 869 | spin_unlock(&obj->iommu_lock); |
Joerg Roedel | ede1c2e | 2017-04-12 00:21:29 -0500 | [diff] [blame] | 870 | |
| 871 | return err; |
Hiroshi DOYU | a9dcad5 | 2009-01-26 15:13:40 +0200 | [diff] [blame] | 872 | } |
Hiroshi DOYU | a9dcad5 | 2009-01-26 15:13:40 +0200 | [diff] [blame] | 873 | |
| 874 | /** |
Ohad Ben-Cohen | f626b52 | 2011-06-02 01:46:12 +0300 | [diff] [blame] | 875 | * omap_iommu_detach - release iommu device |
Hiroshi DOYU | a9dcad5 | 2009-01-26 15:13:40 +0200 | [diff] [blame] | 876 | * @obj: target iommu |
| 877 | **/ |
Ohad Ben-Cohen | 6c32df4 | 2011-08-17 22:57:56 +0300 | [diff] [blame] | 878 | static void omap_iommu_detach(struct omap_iommu *obj) |
Hiroshi DOYU | a9dcad5 | 2009-01-26 15:13:40 +0200 | [diff] [blame] | 879 | { |
Roel Kluin | acf9d46 | 2010-01-08 10:29:05 -0800 | [diff] [blame] | 880 | if (!obj || IS_ERR(obj)) |
Hiroshi DOYU | a9dcad5 | 2009-01-26 15:13:40 +0200 | [diff] [blame] | 881 | return; |
| 882 | |
Ohad Ben-Cohen | f626b52 | 2011-06-02 01:46:12 +0300 | [diff] [blame] | 883 | spin_lock(&obj->iommu_lock); |
Hiroshi DOYU | a9dcad5 | 2009-01-26 15:13:40 +0200 | [diff] [blame] | 884 | |
Josue Albarran | bfee0cf | 2017-07-28 15:49:14 -0500 | [diff] [blame^] | 885 | dma_unmap_single(obj->dev, obj->pd_dma, IOPGD_TABLE_SIZE, |
| 886 | DMA_TO_DEVICE); |
Suman Anna | 2088ecb | 2014-10-22 17:22:19 -0500 | [diff] [blame] | 887 | iommu_disable(obj); |
Josue Albarran | bfee0cf | 2017-07-28 15:49:14 -0500 | [diff] [blame^] | 888 | obj->pd_dma = 0; |
Ohad Ben-Cohen | f626b52 | 2011-06-02 01:46:12 +0300 | [diff] [blame] | 889 | obj->iopgd = NULL; |
| 890 | |
| 891 | spin_unlock(&obj->iommu_lock); |
Hiroshi DOYU | a9dcad5 | 2009-01-26 15:13:40 +0200 | [diff] [blame] | 892 | |
| 893 | dev_dbg(obj->dev, "%s: %s\n", __func__, obj->name); |
| 894 | } |
David Cohen | d594f1f | 2011-02-16 19:35:51 +0000 | [diff] [blame] | 895 | |
Suman Anna | 3ca9299 | 2015-10-02 18:02:44 -0500 | [diff] [blame] | 896 | static int omap_iommu_dra7_get_dsp_system_cfg(struct platform_device *pdev, |
| 897 | struct omap_iommu *obj) |
| 898 | { |
| 899 | struct device_node *np = pdev->dev.of_node; |
| 900 | int ret; |
| 901 | |
| 902 | if (!of_device_is_compatible(np, "ti,dra7-dsp-iommu")) |
| 903 | return 0; |
| 904 | |
| 905 | if (!of_property_read_bool(np, "ti,syscon-mmuconfig")) { |
| 906 | dev_err(&pdev->dev, "ti,syscon-mmuconfig property is missing\n"); |
| 907 | return -EINVAL; |
| 908 | } |
| 909 | |
| 910 | obj->syscfg = |
| 911 | syscon_regmap_lookup_by_phandle(np, "ti,syscon-mmuconfig"); |
| 912 | if (IS_ERR(obj->syscfg)) { |
| 913 | /* can fail with -EPROBE_DEFER */ |
| 914 | ret = PTR_ERR(obj->syscfg); |
| 915 | return ret; |
| 916 | } |
| 917 | |
| 918 | if (of_property_read_u32_index(np, "ti,syscon-mmuconfig", 1, |
| 919 | &obj->id)) { |
| 920 | dev_err(&pdev->dev, "couldn't get the IOMMU instance id within subsystem\n"); |
| 921 | return -EINVAL; |
| 922 | } |
| 923 | |
| 924 | if (obj->id != 0 && obj->id != 1) { |
| 925 | dev_err(&pdev->dev, "invalid IOMMU instance id\n"); |
| 926 | return -EINVAL; |
| 927 | } |
| 928 | |
| 929 | return 0; |
| 930 | } |
| 931 | |
Hiroshi DOYU | a9dcad5 | 2009-01-26 15:13:40 +0200 | [diff] [blame] | 932 | /* |
| 933 | * OMAP Device MMU(IOMMU) detection |
| 934 | */ |
Greg Kroah-Hartman | d34d651 | 2012-12-21 15:05:21 -0800 | [diff] [blame] | 935 | static int omap_iommu_probe(struct platform_device *pdev) |
Hiroshi DOYU | a9dcad5 | 2009-01-26 15:13:40 +0200 | [diff] [blame] | 936 | { |
| 937 | int err = -ENODEV; |
Hiroshi DOYU | a9dcad5 | 2009-01-26 15:13:40 +0200 | [diff] [blame] | 938 | int irq; |
Ohad Ben-Cohen | 6c32df4 | 2011-08-17 22:57:56 +0300 | [diff] [blame] | 939 | struct omap_iommu *obj; |
Hiroshi DOYU | a9dcad5 | 2009-01-26 15:13:40 +0200 | [diff] [blame] | 940 | struct resource *res; |
Florian Vaussard | 3c92748 | 2014-02-28 14:42:36 -0600 | [diff] [blame] | 941 | struct device_node *of = pdev->dev.of_node; |
Hiroshi DOYU | a9dcad5 | 2009-01-26 15:13:40 +0200 | [diff] [blame] | 942 | |
Suman Anna | 49a57ef | 2017-04-12 00:21:27 -0500 | [diff] [blame] | 943 | if (!of) { |
| 944 | pr_err("%s: only DT-based devices are supported\n", __func__); |
| 945 | return -ENODEV; |
| 946 | } |
| 947 | |
Suman Anna | f129b3d | 2014-02-28 14:42:32 -0600 | [diff] [blame] | 948 | obj = devm_kzalloc(&pdev->dev, sizeof(*obj) + MMU_REG_SIZE, GFP_KERNEL); |
Hiroshi DOYU | a9dcad5 | 2009-01-26 15:13:40 +0200 | [diff] [blame] | 949 | if (!obj) |
| 950 | return -ENOMEM; |
| 951 | |
Suman Anna | 49a57ef | 2017-04-12 00:21:27 -0500 | [diff] [blame] | 952 | obj->name = dev_name(&pdev->dev); |
| 953 | obj->nr_tlb_entries = 32; |
| 954 | err = of_property_read_u32(of, "ti,#tlb-entries", &obj->nr_tlb_entries); |
| 955 | if (err && err != -EINVAL) |
| 956 | return err; |
| 957 | if (obj->nr_tlb_entries != 32 && obj->nr_tlb_entries != 8) |
| 958 | return -EINVAL; |
| 959 | if (of_find_property(of, "ti,iommu-bus-err-back", NULL)) |
| 960 | obj->has_bus_err_back = MMU_GP_REG_BUS_ERR_BACK_EN; |
Florian Vaussard | 3c92748 | 2014-02-28 14:42:36 -0600 | [diff] [blame] | 961 | |
Hiroshi DOYU | a9dcad5 | 2009-01-26 15:13:40 +0200 | [diff] [blame] | 962 | obj->dev = &pdev->dev; |
| 963 | obj->ctx = (void *)obj + sizeof(*obj); |
Hiroshi DOYU | a9dcad5 | 2009-01-26 15:13:40 +0200 | [diff] [blame] | 964 | |
Ohad Ben-Cohen | f626b52 | 2011-06-02 01:46:12 +0300 | [diff] [blame] | 965 | spin_lock_init(&obj->iommu_lock); |
Hiroshi DOYU | a9dcad5 | 2009-01-26 15:13:40 +0200 | [diff] [blame] | 966 | spin_lock_init(&obj->page_table_lock); |
Hiroshi DOYU | a9dcad5 | 2009-01-26 15:13:40 +0200 | [diff] [blame] | 967 | |
| 968 | res = platform_get_resource(pdev, IORESOURCE_MEM, 0); |
Suman Anna | f129b3d | 2014-02-28 14:42:32 -0600 | [diff] [blame] | 969 | obj->regbase = devm_ioremap_resource(obj->dev, res); |
| 970 | if (IS_ERR(obj->regbase)) |
| 971 | return PTR_ERR(obj->regbase); |
Aaro Koskinen | da4a0f7 | 2011-03-14 12:28:32 +0000 | [diff] [blame] | 972 | |
Suman Anna | 3ca9299 | 2015-10-02 18:02:44 -0500 | [diff] [blame] | 973 | err = omap_iommu_dra7_get_dsp_system_cfg(pdev, obj); |
| 974 | if (err) |
| 975 | return err; |
| 976 | |
Hiroshi DOYU | a9dcad5 | 2009-01-26 15:13:40 +0200 | [diff] [blame] | 977 | irq = platform_get_irq(pdev, 0); |
Suman Anna | f129b3d | 2014-02-28 14:42:32 -0600 | [diff] [blame] | 978 | if (irq < 0) |
| 979 | return -ENODEV; |
| 980 | |
| 981 | err = devm_request_irq(obj->dev, irq, iommu_fault_handler, IRQF_SHARED, |
| 982 | dev_name(obj->dev), obj); |
Hiroshi DOYU | a9dcad5 | 2009-01-26 15:13:40 +0200 | [diff] [blame] | 983 | if (err < 0) |
Suman Anna | f129b3d | 2014-02-28 14:42:32 -0600 | [diff] [blame] | 984 | return err; |
Hiroshi DOYU | a9dcad5 | 2009-01-26 15:13:40 +0200 | [diff] [blame] | 985 | platform_set_drvdata(pdev, obj); |
| 986 | |
Joerg Roedel | 28ae1e3 | 2017-04-12 00:21:31 -0500 | [diff] [blame] | 987 | obj->group = iommu_group_alloc(); |
| 988 | if (IS_ERR(obj->group)) |
| 989 | return PTR_ERR(obj->group); |
| 990 | |
Joerg Roedel | 01611fe | 2017-04-12 00:21:30 -0500 | [diff] [blame] | 991 | err = iommu_device_sysfs_add(&obj->iommu, obj->dev, NULL, obj->name); |
| 992 | if (err) |
Joerg Roedel | 28ae1e3 | 2017-04-12 00:21:31 -0500 | [diff] [blame] | 993 | goto out_group; |
Joerg Roedel | 01611fe | 2017-04-12 00:21:30 -0500 | [diff] [blame] | 994 | |
| 995 | iommu_device_set_ops(&obj->iommu, &omap_iommu_ops); |
| 996 | |
| 997 | err = iommu_device_register(&obj->iommu); |
| 998 | if (err) |
| 999 | goto out_sysfs; |
| 1000 | |
Omar Ramirez Luna | ebf7cda | 2012-11-19 19:05:51 -0600 | [diff] [blame] | 1001 | pm_runtime_irq_safe(obj->dev); |
| 1002 | pm_runtime_enable(obj->dev); |
| 1003 | |
Suman Anna | 61c7535 | 2014-10-22 17:22:30 -0500 | [diff] [blame] | 1004 | omap_iommu_debugfs_add(obj); |
| 1005 | |
Hiroshi DOYU | a9dcad5 | 2009-01-26 15:13:40 +0200 | [diff] [blame] | 1006 | dev_info(&pdev->dev, "%s registered\n", obj->name); |
Joerg Roedel | 28ae1e3 | 2017-04-12 00:21:31 -0500 | [diff] [blame] | 1007 | |
Hiroshi DOYU | a9dcad5 | 2009-01-26 15:13:40 +0200 | [diff] [blame] | 1008 | return 0; |
Joerg Roedel | 01611fe | 2017-04-12 00:21:30 -0500 | [diff] [blame] | 1009 | |
| 1010 | out_sysfs: |
| 1011 | iommu_device_sysfs_remove(&obj->iommu); |
Joerg Roedel | 28ae1e3 | 2017-04-12 00:21:31 -0500 | [diff] [blame] | 1012 | out_group: |
| 1013 | iommu_group_put(obj->group); |
Joerg Roedel | 01611fe | 2017-04-12 00:21:30 -0500 | [diff] [blame] | 1014 | return err; |
Hiroshi DOYU | a9dcad5 | 2009-01-26 15:13:40 +0200 | [diff] [blame] | 1015 | } |
| 1016 | |
Greg Kroah-Hartman | d34d651 | 2012-12-21 15:05:21 -0800 | [diff] [blame] | 1017 | static int omap_iommu_remove(struct platform_device *pdev) |
Hiroshi DOYU | a9dcad5 | 2009-01-26 15:13:40 +0200 | [diff] [blame] | 1018 | { |
Ohad Ben-Cohen | 6c32df4 | 2011-08-17 22:57:56 +0300 | [diff] [blame] | 1019 | struct omap_iommu *obj = platform_get_drvdata(pdev); |
Hiroshi DOYU | a9dcad5 | 2009-01-26 15:13:40 +0200 | [diff] [blame] | 1020 | |
Joerg Roedel | 28ae1e3 | 2017-04-12 00:21:31 -0500 | [diff] [blame] | 1021 | iommu_group_put(obj->group); |
| 1022 | obj->group = NULL; |
| 1023 | |
Joerg Roedel | 01611fe | 2017-04-12 00:21:30 -0500 | [diff] [blame] | 1024 | iommu_device_sysfs_remove(&obj->iommu); |
| 1025 | iommu_device_unregister(&obj->iommu); |
| 1026 | |
Suman Anna | 61c7535 | 2014-10-22 17:22:30 -0500 | [diff] [blame] | 1027 | omap_iommu_debugfs_remove(obj); |
Hiroshi DOYU | a9dcad5 | 2009-01-26 15:13:40 +0200 | [diff] [blame] | 1028 | |
Omar Ramirez Luna | ebf7cda | 2012-11-19 19:05:51 -0600 | [diff] [blame] | 1029 | pm_runtime_disable(obj->dev); |
| 1030 | |
Hiroshi DOYU | a9dcad5 | 2009-01-26 15:13:40 +0200 | [diff] [blame] | 1031 | dev_info(&pdev->dev, "%s removed\n", obj->name); |
Hiroshi DOYU | a9dcad5 | 2009-01-26 15:13:40 +0200 | [diff] [blame] | 1032 | return 0; |
| 1033 | } |
| 1034 | |
Kiran Padwal | d943b0f | 2014-09-11 19:07:36 +0530 | [diff] [blame] | 1035 | static const struct of_device_id omap_iommu_of_match[] = { |
Florian Vaussard | 3c92748 | 2014-02-28 14:42:36 -0600 | [diff] [blame] | 1036 | { .compatible = "ti,omap2-iommu" }, |
| 1037 | { .compatible = "ti,omap4-iommu" }, |
| 1038 | { .compatible = "ti,dra7-iommu" }, |
Suman Anna | 3ca9299 | 2015-10-02 18:02:44 -0500 | [diff] [blame] | 1039 | { .compatible = "ti,dra7-dsp-iommu" }, |
Florian Vaussard | 3c92748 | 2014-02-28 14:42:36 -0600 | [diff] [blame] | 1040 | {}, |
| 1041 | }; |
Florian Vaussard | 3c92748 | 2014-02-28 14:42:36 -0600 | [diff] [blame] | 1042 | |
Hiroshi DOYU | a9dcad5 | 2009-01-26 15:13:40 +0200 | [diff] [blame] | 1043 | static struct platform_driver omap_iommu_driver = { |
| 1044 | .probe = omap_iommu_probe, |
Greg Kroah-Hartman | d34d651 | 2012-12-21 15:05:21 -0800 | [diff] [blame] | 1045 | .remove = omap_iommu_remove, |
Hiroshi DOYU | a9dcad5 | 2009-01-26 15:13:40 +0200 | [diff] [blame] | 1046 | .driver = { |
| 1047 | .name = "omap-iommu", |
Florian Vaussard | 3c92748 | 2014-02-28 14:42:36 -0600 | [diff] [blame] | 1048 | .of_match_table = of_match_ptr(omap_iommu_of_match), |
Hiroshi DOYU | a9dcad5 | 2009-01-26 15:13:40 +0200 | [diff] [blame] | 1049 | }, |
| 1050 | }; |
| 1051 | |
Laurent Pinchart | 286f600 | 2014-03-08 00:44:38 +0100 | [diff] [blame] | 1052 | static u32 iotlb_init_entry(struct iotlb_entry *e, u32 da, u32 pa, int pgsz) |
Tony Lindgren | ed1c7de | 2012-11-02 12:24:06 -0700 | [diff] [blame] | 1053 | { |
| 1054 | memset(e, 0, sizeof(*e)); |
| 1055 | |
| 1056 | e->da = da; |
| 1057 | e->pa = pa; |
Suman Anna | d760e3e | 2014-03-17 20:31:32 -0500 | [diff] [blame] | 1058 | e->valid = MMU_CAM_V; |
Laurent Pinchart | 286f600 | 2014-03-08 00:44:38 +0100 | [diff] [blame] | 1059 | e->pgsz = pgsz; |
| 1060 | e->endian = MMU_RAM_ENDIAN_LITTLE; |
| 1061 | e->elsz = MMU_RAM_ELSZ_8; |
| 1062 | e->mixed = 0; |
Tony Lindgren | ed1c7de | 2012-11-02 12:24:06 -0700 | [diff] [blame] | 1063 | |
| 1064 | return iopgsz_to_bytes(e->pgsz); |
| 1065 | } |
| 1066 | |
Ohad Ben-Cohen | f626b52 | 2011-06-02 01:46:12 +0300 | [diff] [blame] | 1067 | static int omap_iommu_map(struct iommu_domain *domain, unsigned long da, |
Suman Anna | 5835b6a | 2015-07-20 17:33:32 -0500 | [diff] [blame] | 1068 | phys_addr_t pa, size_t bytes, int prot) |
Ohad Ben-Cohen | f626b52 | 2011-06-02 01:46:12 +0300 | [diff] [blame] | 1069 | { |
Joerg Roedel | 8cf851e | 2015-03-26 13:43:09 +0100 | [diff] [blame] | 1070 | struct omap_iommu_domain *omap_domain = to_omap_domain(domain); |
Ohad Ben-Cohen | 6c32df4 | 2011-08-17 22:57:56 +0300 | [diff] [blame] | 1071 | struct omap_iommu *oiommu = omap_domain->iommu_dev; |
Ohad Ben-Cohen | f626b52 | 2011-06-02 01:46:12 +0300 | [diff] [blame] | 1072 | struct device *dev = oiommu->dev; |
Ohad Ben-Cohen | f626b52 | 2011-06-02 01:46:12 +0300 | [diff] [blame] | 1073 | struct iotlb_entry e; |
| 1074 | int omap_pgsz; |
Laurent Pinchart | 286f600 | 2014-03-08 00:44:38 +0100 | [diff] [blame] | 1075 | u32 ret; |
Ohad Ben-Cohen | f626b52 | 2011-06-02 01:46:12 +0300 | [diff] [blame] | 1076 | |
Ohad Ben-Cohen | f626b52 | 2011-06-02 01:46:12 +0300 | [diff] [blame] | 1077 | omap_pgsz = bytes_to_iopgsz(bytes); |
| 1078 | if (omap_pgsz < 0) { |
| 1079 | dev_err(dev, "invalid size to map: %d\n", bytes); |
| 1080 | return -EINVAL; |
| 1081 | } |
| 1082 | |
Joerg Roedel | 1d7f449 | 2015-01-22 14:42:06 +0100 | [diff] [blame] | 1083 | dev_dbg(dev, "mapping da 0x%lx to pa %pa size 0x%x\n", da, &pa, bytes); |
Ohad Ben-Cohen | f626b52 | 2011-06-02 01:46:12 +0300 | [diff] [blame] | 1084 | |
Laurent Pinchart | 286f600 | 2014-03-08 00:44:38 +0100 | [diff] [blame] | 1085 | iotlb_init_entry(&e, da, pa, omap_pgsz); |
Ohad Ben-Cohen | f626b52 | 2011-06-02 01:46:12 +0300 | [diff] [blame] | 1086 | |
Ohad Ben-Cohen | 6c32df4 | 2011-08-17 22:57:56 +0300 | [diff] [blame] | 1087 | ret = omap_iopgtable_store_entry(oiommu, &e); |
Ohad Ben-Cohen | b4550d4 | 2011-09-02 13:32:31 -0400 | [diff] [blame] | 1088 | if (ret) |
Ohad Ben-Cohen | 6c32df4 | 2011-08-17 22:57:56 +0300 | [diff] [blame] | 1089 | dev_err(dev, "omap_iopgtable_store_entry failed: %d\n", ret); |
Ohad Ben-Cohen | f626b52 | 2011-06-02 01:46:12 +0300 | [diff] [blame] | 1090 | |
Ohad Ben-Cohen | b4550d4 | 2011-09-02 13:32:31 -0400 | [diff] [blame] | 1091 | return ret; |
Ohad Ben-Cohen | f626b52 | 2011-06-02 01:46:12 +0300 | [diff] [blame] | 1092 | } |
| 1093 | |
Ohad Ben-Cohen | 5009065 | 2011-11-10 11:32:25 +0200 | [diff] [blame] | 1094 | static size_t omap_iommu_unmap(struct iommu_domain *domain, unsigned long da, |
Suman Anna | 5835b6a | 2015-07-20 17:33:32 -0500 | [diff] [blame] | 1095 | size_t size) |
Ohad Ben-Cohen | f626b52 | 2011-06-02 01:46:12 +0300 | [diff] [blame] | 1096 | { |
Joerg Roedel | 8cf851e | 2015-03-26 13:43:09 +0100 | [diff] [blame] | 1097 | struct omap_iommu_domain *omap_domain = to_omap_domain(domain); |
Ohad Ben-Cohen | 6c32df4 | 2011-08-17 22:57:56 +0300 | [diff] [blame] | 1098 | struct omap_iommu *oiommu = omap_domain->iommu_dev; |
Ohad Ben-Cohen | f626b52 | 2011-06-02 01:46:12 +0300 | [diff] [blame] | 1099 | struct device *dev = oiommu->dev; |
Ohad Ben-Cohen | f626b52 | 2011-06-02 01:46:12 +0300 | [diff] [blame] | 1100 | |
Ohad Ben-Cohen | 5009065 | 2011-11-10 11:32:25 +0200 | [diff] [blame] | 1101 | dev_dbg(dev, "unmapping da 0x%lx size %u\n", da, size); |
Ohad Ben-Cohen | f626b52 | 2011-06-02 01:46:12 +0300 | [diff] [blame] | 1102 | |
Ohad Ben-Cohen | 5009065 | 2011-11-10 11:32:25 +0200 | [diff] [blame] | 1103 | return iopgtable_clear_entry(oiommu, da); |
Ohad Ben-Cohen | f626b52 | 2011-06-02 01:46:12 +0300 | [diff] [blame] | 1104 | } |
| 1105 | |
| 1106 | static int |
| 1107 | omap_iommu_attach_dev(struct iommu_domain *domain, struct device *dev) |
| 1108 | { |
Joerg Roedel | 8cf851e | 2015-03-26 13:43:09 +0100 | [diff] [blame] | 1109 | struct omap_iommu_domain *omap_domain = to_omap_domain(domain); |
Ohad Ben-Cohen | fabdbca | 2011-10-11 00:18:33 +0200 | [diff] [blame] | 1110 | struct omap_iommu_arch_data *arch_data = dev->archdata.iommu; |
Joerg Roedel | ede1c2e | 2017-04-12 00:21:29 -0500 | [diff] [blame] | 1111 | struct omap_iommu *oiommu; |
Ohad Ben-Cohen | f626b52 | 2011-06-02 01:46:12 +0300 | [diff] [blame] | 1112 | int ret = 0; |
| 1113 | |
Joerg Roedel | ede1c2e | 2017-04-12 00:21:29 -0500 | [diff] [blame] | 1114 | if (!arch_data || !arch_data->iommu_dev) { |
Suman Anna | e3f595b | 2014-09-04 17:27:29 -0500 | [diff] [blame] | 1115 | dev_err(dev, "device doesn't have an associated iommu\n"); |
| 1116 | return -EINVAL; |
| 1117 | } |
| 1118 | |
Ohad Ben-Cohen | f626b52 | 2011-06-02 01:46:12 +0300 | [diff] [blame] | 1119 | spin_lock(&omap_domain->lock); |
| 1120 | |
| 1121 | /* only a single device is supported per domain for now */ |
| 1122 | if (omap_domain->iommu_dev) { |
| 1123 | dev_err(dev, "iommu domain is already attached\n"); |
| 1124 | ret = -EBUSY; |
| 1125 | goto out; |
| 1126 | } |
| 1127 | |
Joerg Roedel | ede1c2e | 2017-04-12 00:21:29 -0500 | [diff] [blame] | 1128 | oiommu = arch_data->iommu_dev; |
| 1129 | |
Ohad Ben-Cohen | f626b52 | 2011-06-02 01:46:12 +0300 | [diff] [blame] | 1130 | /* get a handle to and enable the omap iommu */ |
Joerg Roedel | ede1c2e | 2017-04-12 00:21:29 -0500 | [diff] [blame] | 1131 | ret = omap_iommu_attach(oiommu, omap_domain->pgtable); |
| 1132 | if (ret) { |
Ohad Ben-Cohen | f626b52 | 2011-06-02 01:46:12 +0300 | [diff] [blame] | 1133 | dev_err(dev, "can't get omap iommu: %d\n", ret); |
| 1134 | goto out; |
| 1135 | } |
| 1136 | |
Joerg Roedel | ede1c2e | 2017-04-12 00:21:29 -0500 | [diff] [blame] | 1137 | omap_domain->iommu_dev = oiommu; |
Omar Ramirez Luna | 803b527 | 2012-04-18 13:09:41 -0500 | [diff] [blame] | 1138 | omap_domain->dev = dev; |
Ohad Ben-Cohen | e7f10f0 | 2011-09-13 15:26:29 -0400 | [diff] [blame] | 1139 | oiommu->domain = domain; |
Ohad Ben-Cohen | f626b52 | 2011-06-02 01:46:12 +0300 | [diff] [blame] | 1140 | |
| 1141 | out: |
| 1142 | spin_unlock(&omap_domain->lock); |
| 1143 | return ret; |
| 1144 | } |
| 1145 | |
Omar Ramirez Luna | 803b527 | 2012-04-18 13:09:41 -0500 | [diff] [blame] | 1146 | static void _omap_iommu_detach_dev(struct omap_iommu_domain *omap_domain, |
Suman Anna | 5835b6a | 2015-07-20 17:33:32 -0500 | [diff] [blame] | 1147 | struct device *dev) |
Ohad Ben-Cohen | f626b52 | 2011-06-02 01:46:12 +0300 | [diff] [blame] | 1148 | { |
Ohad Ben-Cohen | fabdbca | 2011-10-11 00:18:33 +0200 | [diff] [blame] | 1149 | struct omap_iommu *oiommu = dev_to_omap_iommu(dev); |
Ohad Ben-Cohen | f626b52 | 2011-06-02 01:46:12 +0300 | [diff] [blame] | 1150 | |
| 1151 | /* only a single device is supported per domain for now */ |
| 1152 | if (omap_domain->iommu_dev != oiommu) { |
| 1153 | dev_err(dev, "invalid iommu device\n"); |
Omar Ramirez Luna | 803b527 | 2012-04-18 13:09:41 -0500 | [diff] [blame] | 1154 | return; |
Ohad Ben-Cohen | f626b52 | 2011-06-02 01:46:12 +0300 | [diff] [blame] | 1155 | } |
| 1156 | |
| 1157 | iopgtable_clear_entry_all(oiommu); |
| 1158 | |
| 1159 | omap_iommu_detach(oiommu); |
| 1160 | |
Joerg Roedel | ede1c2e | 2017-04-12 00:21:29 -0500 | [diff] [blame] | 1161 | omap_domain->iommu_dev = NULL; |
Omar Ramirez Luna | 803b527 | 2012-04-18 13:09:41 -0500 | [diff] [blame] | 1162 | omap_domain->dev = NULL; |
Suman Anna | f24d9ad | 2014-10-22 17:22:33 -0500 | [diff] [blame] | 1163 | oiommu->domain = NULL; |
Omar Ramirez Luna | 803b527 | 2012-04-18 13:09:41 -0500 | [diff] [blame] | 1164 | } |
Ohad Ben-Cohen | f626b52 | 2011-06-02 01:46:12 +0300 | [diff] [blame] | 1165 | |
Omar Ramirez Luna | 803b527 | 2012-04-18 13:09:41 -0500 | [diff] [blame] | 1166 | static void omap_iommu_detach_dev(struct iommu_domain *domain, |
Suman Anna | 5835b6a | 2015-07-20 17:33:32 -0500 | [diff] [blame] | 1167 | struct device *dev) |
Omar Ramirez Luna | 803b527 | 2012-04-18 13:09:41 -0500 | [diff] [blame] | 1168 | { |
Joerg Roedel | 8cf851e | 2015-03-26 13:43:09 +0100 | [diff] [blame] | 1169 | struct omap_iommu_domain *omap_domain = to_omap_domain(domain); |
Omar Ramirez Luna | 803b527 | 2012-04-18 13:09:41 -0500 | [diff] [blame] | 1170 | |
| 1171 | spin_lock(&omap_domain->lock); |
| 1172 | _omap_iommu_detach_dev(omap_domain, dev); |
Ohad Ben-Cohen | f626b52 | 2011-06-02 01:46:12 +0300 | [diff] [blame] | 1173 | spin_unlock(&omap_domain->lock); |
| 1174 | } |
| 1175 | |
Joerg Roedel | 8cf851e | 2015-03-26 13:43:09 +0100 | [diff] [blame] | 1176 | static struct iommu_domain *omap_iommu_domain_alloc(unsigned type) |
Ohad Ben-Cohen | f626b52 | 2011-06-02 01:46:12 +0300 | [diff] [blame] | 1177 | { |
| 1178 | struct omap_iommu_domain *omap_domain; |
| 1179 | |
Joerg Roedel | 8cf851e | 2015-03-26 13:43:09 +0100 | [diff] [blame] | 1180 | if (type != IOMMU_DOMAIN_UNMANAGED) |
| 1181 | return NULL; |
| 1182 | |
Ohad Ben-Cohen | f626b52 | 2011-06-02 01:46:12 +0300 | [diff] [blame] | 1183 | omap_domain = kzalloc(sizeof(*omap_domain), GFP_KERNEL); |
Suman Anna | 99ee98d | 2015-07-20 17:33:29 -0500 | [diff] [blame] | 1184 | if (!omap_domain) |
Ohad Ben-Cohen | f626b52 | 2011-06-02 01:46:12 +0300 | [diff] [blame] | 1185 | goto out; |
Ohad Ben-Cohen | f626b52 | 2011-06-02 01:46:12 +0300 | [diff] [blame] | 1186 | |
| 1187 | omap_domain->pgtable = kzalloc(IOPGD_TABLE_SIZE, GFP_KERNEL); |
Suman Anna | 99ee98d | 2015-07-20 17:33:29 -0500 | [diff] [blame] | 1188 | if (!omap_domain->pgtable) |
Ohad Ben-Cohen | f626b52 | 2011-06-02 01:46:12 +0300 | [diff] [blame] | 1189 | goto fail_nomem; |
Ohad Ben-Cohen | f626b52 | 2011-06-02 01:46:12 +0300 | [diff] [blame] | 1190 | |
| 1191 | /* |
| 1192 | * should never fail, but please keep this around to ensure |
| 1193 | * we keep the hardware happy |
| 1194 | */ |
Suman Anna | 433c434 | 2016-04-04 17:46:20 -0500 | [diff] [blame] | 1195 | if (WARN_ON(!IS_ALIGNED((long)omap_domain->pgtable, IOPGD_TABLE_SIZE))) |
| 1196 | goto fail_align; |
Ohad Ben-Cohen | f626b52 | 2011-06-02 01:46:12 +0300 | [diff] [blame] | 1197 | |
Ohad Ben-Cohen | f626b52 | 2011-06-02 01:46:12 +0300 | [diff] [blame] | 1198 | spin_lock_init(&omap_domain->lock); |
| 1199 | |
Joerg Roedel | 8cf851e | 2015-03-26 13:43:09 +0100 | [diff] [blame] | 1200 | omap_domain->domain.geometry.aperture_start = 0; |
| 1201 | omap_domain->domain.geometry.aperture_end = (1ULL << 32) - 1; |
| 1202 | omap_domain->domain.geometry.force_aperture = true; |
Ohad Ben-Cohen | f626b52 | 2011-06-02 01:46:12 +0300 | [diff] [blame] | 1203 | |
Joerg Roedel | 8cf851e | 2015-03-26 13:43:09 +0100 | [diff] [blame] | 1204 | return &omap_domain->domain; |
Ohad Ben-Cohen | f626b52 | 2011-06-02 01:46:12 +0300 | [diff] [blame] | 1205 | |
Suman Anna | 433c434 | 2016-04-04 17:46:20 -0500 | [diff] [blame] | 1206 | fail_align: |
| 1207 | kfree(omap_domain->pgtable); |
Ohad Ben-Cohen | f626b52 | 2011-06-02 01:46:12 +0300 | [diff] [blame] | 1208 | fail_nomem: |
| 1209 | kfree(omap_domain); |
| 1210 | out: |
Joerg Roedel | 8cf851e | 2015-03-26 13:43:09 +0100 | [diff] [blame] | 1211 | return NULL; |
Ohad Ben-Cohen | f626b52 | 2011-06-02 01:46:12 +0300 | [diff] [blame] | 1212 | } |
| 1213 | |
Joerg Roedel | 8cf851e | 2015-03-26 13:43:09 +0100 | [diff] [blame] | 1214 | static void omap_iommu_domain_free(struct iommu_domain *domain) |
Ohad Ben-Cohen | f626b52 | 2011-06-02 01:46:12 +0300 | [diff] [blame] | 1215 | { |
Joerg Roedel | 8cf851e | 2015-03-26 13:43:09 +0100 | [diff] [blame] | 1216 | struct omap_iommu_domain *omap_domain = to_omap_domain(domain); |
Ohad Ben-Cohen | f626b52 | 2011-06-02 01:46:12 +0300 | [diff] [blame] | 1217 | |
Omar Ramirez Luna | 803b527 | 2012-04-18 13:09:41 -0500 | [diff] [blame] | 1218 | /* |
| 1219 | * An iommu device is still attached |
| 1220 | * (currently, only one device can be attached) ? |
| 1221 | */ |
| 1222 | if (omap_domain->iommu_dev) |
| 1223 | _omap_iommu_detach_dev(omap_domain, omap_domain->dev); |
| 1224 | |
Ohad Ben-Cohen | f626b52 | 2011-06-02 01:46:12 +0300 | [diff] [blame] | 1225 | kfree(omap_domain->pgtable); |
| 1226 | kfree(omap_domain); |
| 1227 | } |
| 1228 | |
| 1229 | static phys_addr_t omap_iommu_iova_to_phys(struct iommu_domain *domain, |
Suman Anna | 5835b6a | 2015-07-20 17:33:32 -0500 | [diff] [blame] | 1230 | dma_addr_t da) |
Ohad Ben-Cohen | f626b52 | 2011-06-02 01:46:12 +0300 | [diff] [blame] | 1231 | { |
Joerg Roedel | 8cf851e | 2015-03-26 13:43:09 +0100 | [diff] [blame] | 1232 | struct omap_iommu_domain *omap_domain = to_omap_domain(domain); |
Ohad Ben-Cohen | 6c32df4 | 2011-08-17 22:57:56 +0300 | [diff] [blame] | 1233 | struct omap_iommu *oiommu = omap_domain->iommu_dev; |
Ohad Ben-Cohen | f626b52 | 2011-06-02 01:46:12 +0300 | [diff] [blame] | 1234 | struct device *dev = oiommu->dev; |
| 1235 | u32 *pgd, *pte; |
| 1236 | phys_addr_t ret = 0; |
| 1237 | |
| 1238 | iopgtable_lookup_entry(oiommu, da, &pgd, &pte); |
| 1239 | |
| 1240 | if (pte) { |
| 1241 | if (iopte_is_small(*pte)) |
| 1242 | ret = omap_iommu_translate(*pte, da, IOPTE_MASK); |
| 1243 | else if (iopte_is_large(*pte)) |
| 1244 | ret = omap_iommu_translate(*pte, da, IOLARGE_MASK); |
| 1245 | else |
Suman Anna | 2abfcfb | 2013-05-30 18:10:38 -0500 | [diff] [blame] | 1246 | dev_err(dev, "bogus pte 0x%x, da 0x%llx", *pte, |
Suman Anna | 5835b6a | 2015-07-20 17:33:32 -0500 | [diff] [blame] | 1247 | (unsigned long long)da); |
Ohad Ben-Cohen | f626b52 | 2011-06-02 01:46:12 +0300 | [diff] [blame] | 1248 | } else { |
| 1249 | if (iopgd_is_section(*pgd)) |
| 1250 | ret = omap_iommu_translate(*pgd, da, IOSECTION_MASK); |
| 1251 | else if (iopgd_is_super(*pgd)) |
| 1252 | ret = omap_iommu_translate(*pgd, da, IOSUPER_MASK); |
| 1253 | else |
Suman Anna | 2abfcfb | 2013-05-30 18:10:38 -0500 | [diff] [blame] | 1254 | dev_err(dev, "bogus pgd 0x%x, da 0x%llx", *pgd, |
Suman Anna | 5835b6a | 2015-07-20 17:33:32 -0500 | [diff] [blame] | 1255 | (unsigned long long)da); |
Ohad Ben-Cohen | f626b52 | 2011-06-02 01:46:12 +0300 | [diff] [blame] | 1256 | } |
| 1257 | |
| 1258 | return ret; |
| 1259 | } |
| 1260 | |
Laurent Pinchart | 07a0203 | 2014-02-28 14:42:38 -0600 | [diff] [blame] | 1261 | static int omap_iommu_add_device(struct device *dev) |
| 1262 | { |
| 1263 | struct omap_iommu_arch_data *arch_data; |
Joerg Roedel | ede1c2e | 2017-04-12 00:21:29 -0500 | [diff] [blame] | 1264 | struct omap_iommu *oiommu; |
Joerg Roedel | 28ae1e3 | 2017-04-12 00:21:31 -0500 | [diff] [blame] | 1265 | struct iommu_group *group; |
Laurent Pinchart | 07a0203 | 2014-02-28 14:42:38 -0600 | [diff] [blame] | 1266 | struct device_node *np; |
Suman Anna | 7d68277 | 2014-09-04 17:27:30 -0500 | [diff] [blame] | 1267 | struct platform_device *pdev; |
Joerg Roedel | 01611fe | 2017-04-12 00:21:30 -0500 | [diff] [blame] | 1268 | int ret; |
Laurent Pinchart | 07a0203 | 2014-02-28 14:42:38 -0600 | [diff] [blame] | 1269 | |
| 1270 | /* |
| 1271 | * Allocate the archdata iommu structure for DT-based devices. |
| 1272 | * |
| 1273 | * TODO: Simplify this when removing non-DT support completely from the |
| 1274 | * IOMMU users. |
| 1275 | */ |
| 1276 | if (!dev->of_node) |
| 1277 | return 0; |
| 1278 | |
| 1279 | np = of_parse_phandle(dev->of_node, "iommus", 0); |
| 1280 | if (!np) |
| 1281 | return 0; |
| 1282 | |
Suman Anna | 7d68277 | 2014-09-04 17:27:30 -0500 | [diff] [blame] | 1283 | pdev = of_find_device_by_node(np); |
| 1284 | if (WARN_ON(!pdev)) { |
| 1285 | of_node_put(np); |
| 1286 | return -EINVAL; |
| 1287 | } |
| 1288 | |
Joerg Roedel | ede1c2e | 2017-04-12 00:21:29 -0500 | [diff] [blame] | 1289 | oiommu = platform_get_drvdata(pdev); |
| 1290 | if (!oiommu) { |
| 1291 | of_node_put(np); |
| 1292 | return -EINVAL; |
| 1293 | } |
| 1294 | |
Laurent Pinchart | 07a0203 | 2014-02-28 14:42:38 -0600 | [diff] [blame] | 1295 | arch_data = kzalloc(sizeof(*arch_data), GFP_KERNEL); |
| 1296 | if (!arch_data) { |
| 1297 | of_node_put(np); |
| 1298 | return -ENOMEM; |
| 1299 | } |
| 1300 | |
Joerg Roedel | 01611fe | 2017-04-12 00:21:30 -0500 | [diff] [blame] | 1301 | ret = iommu_device_link(&oiommu->iommu, dev); |
| 1302 | if (ret) { |
| 1303 | kfree(arch_data); |
| 1304 | of_node_put(np); |
| 1305 | return ret; |
| 1306 | } |
| 1307 | |
Joerg Roedel | ede1c2e | 2017-04-12 00:21:29 -0500 | [diff] [blame] | 1308 | arch_data->iommu_dev = oiommu; |
Laurent Pinchart | 07a0203 | 2014-02-28 14:42:38 -0600 | [diff] [blame] | 1309 | dev->archdata.iommu = arch_data; |
| 1310 | |
Joerg Roedel | 28ae1e3 | 2017-04-12 00:21:31 -0500 | [diff] [blame] | 1311 | /* |
| 1312 | * IOMMU group initialization calls into omap_iommu_device_group, which |
| 1313 | * needs a valid dev->archdata.iommu pointer |
| 1314 | */ |
| 1315 | group = iommu_group_get_for_dev(dev); |
| 1316 | if (IS_ERR(group)) { |
| 1317 | iommu_device_unlink(&oiommu->iommu, dev); |
| 1318 | dev->archdata.iommu = NULL; |
| 1319 | kfree(arch_data); |
| 1320 | return PTR_ERR(group); |
| 1321 | } |
| 1322 | iommu_group_put(group); |
| 1323 | |
Laurent Pinchart | 07a0203 | 2014-02-28 14:42:38 -0600 | [diff] [blame] | 1324 | of_node_put(np); |
| 1325 | |
| 1326 | return 0; |
| 1327 | } |
| 1328 | |
| 1329 | static void omap_iommu_remove_device(struct device *dev) |
| 1330 | { |
| 1331 | struct omap_iommu_arch_data *arch_data = dev->archdata.iommu; |
| 1332 | |
| 1333 | if (!dev->of_node || !arch_data) |
| 1334 | return; |
| 1335 | |
Joerg Roedel | 01611fe | 2017-04-12 00:21:30 -0500 | [diff] [blame] | 1336 | iommu_device_unlink(&arch_data->iommu_dev->iommu, dev); |
Joerg Roedel | 28ae1e3 | 2017-04-12 00:21:31 -0500 | [diff] [blame] | 1337 | iommu_group_remove_device(dev); |
Joerg Roedel | 01611fe | 2017-04-12 00:21:30 -0500 | [diff] [blame] | 1338 | |
Joerg Roedel | ede1c2e | 2017-04-12 00:21:29 -0500 | [diff] [blame] | 1339 | dev->archdata.iommu = NULL; |
Laurent Pinchart | 07a0203 | 2014-02-28 14:42:38 -0600 | [diff] [blame] | 1340 | kfree(arch_data); |
Joerg Roedel | 01611fe | 2017-04-12 00:21:30 -0500 | [diff] [blame] | 1341 | |
Laurent Pinchart | 07a0203 | 2014-02-28 14:42:38 -0600 | [diff] [blame] | 1342 | } |
| 1343 | |
Joerg Roedel | 28ae1e3 | 2017-04-12 00:21:31 -0500 | [diff] [blame] | 1344 | static struct iommu_group *omap_iommu_device_group(struct device *dev) |
| 1345 | { |
| 1346 | struct omap_iommu_arch_data *arch_data = dev->archdata.iommu; |
Joerg Roedel | 8faf5e5 | 2017-06-28 12:50:16 +0200 | [diff] [blame] | 1347 | struct iommu_group *group = ERR_PTR(-EINVAL); |
Joerg Roedel | 28ae1e3 | 2017-04-12 00:21:31 -0500 | [diff] [blame] | 1348 | |
| 1349 | if (arch_data->iommu_dev) |
| 1350 | group = arch_data->iommu_dev->group; |
| 1351 | |
| 1352 | return group; |
| 1353 | } |
| 1354 | |
Thierry Reding | b22f643 | 2014-06-27 09:03:12 +0200 | [diff] [blame] | 1355 | static const struct iommu_ops omap_iommu_ops = { |
Joerg Roedel | 8cf851e | 2015-03-26 13:43:09 +0100 | [diff] [blame] | 1356 | .domain_alloc = omap_iommu_domain_alloc, |
| 1357 | .domain_free = omap_iommu_domain_free, |
Ohad Ben-Cohen | f626b52 | 2011-06-02 01:46:12 +0300 | [diff] [blame] | 1358 | .attach_dev = omap_iommu_attach_dev, |
| 1359 | .detach_dev = omap_iommu_detach_dev, |
| 1360 | .map = omap_iommu_map, |
| 1361 | .unmap = omap_iommu_unmap, |
Olav Haugan | 315786e | 2014-10-25 09:55:16 -0700 | [diff] [blame] | 1362 | .map_sg = default_iommu_map_sg, |
Ohad Ben-Cohen | f626b52 | 2011-06-02 01:46:12 +0300 | [diff] [blame] | 1363 | .iova_to_phys = omap_iommu_iova_to_phys, |
Laurent Pinchart | 07a0203 | 2014-02-28 14:42:38 -0600 | [diff] [blame] | 1364 | .add_device = omap_iommu_add_device, |
| 1365 | .remove_device = omap_iommu_remove_device, |
Joerg Roedel | 28ae1e3 | 2017-04-12 00:21:31 -0500 | [diff] [blame] | 1366 | .device_group = omap_iommu_device_group, |
Ohad Ben-Cohen | 66bc8cf | 2011-11-10 11:32:27 +0200 | [diff] [blame] | 1367 | .pgsize_bitmap = OMAP_IOMMU_PGSIZES, |
Ohad Ben-Cohen | f626b52 | 2011-06-02 01:46:12 +0300 | [diff] [blame] | 1368 | }; |
| 1369 | |
Hiroshi DOYU | a9dcad5 | 2009-01-26 15:13:40 +0200 | [diff] [blame] | 1370 | static int __init omap_iommu_init(void) |
| 1371 | { |
| 1372 | struct kmem_cache *p; |
| 1373 | const unsigned long flags = SLAB_HWCACHE_ALIGN; |
| 1374 | size_t align = 1 << 10; /* L2 pagetable alignement */ |
Thierry Reding | f938aab | 2015-02-06 11:44:06 +0100 | [diff] [blame] | 1375 | struct device_node *np; |
Suman Anna | abaa7e5 | 2017-04-12 00:21:26 -0500 | [diff] [blame] | 1376 | int ret; |
Thierry Reding | f938aab | 2015-02-06 11:44:06 +0100 | [diff] [blame] | 1377 | |
| 1378 | np = of_find_matching_node(NULL, omap_iommu_of_match); |
| 1379 | if (!np) |
| 1380 | return 0; |
| 1381 | |
| 1382 | of_node_put(np); |
Hiroshi DOYU | a9dcad5 | 2009-01-26 15:13:40 +0200 | [diff] [blame] | 1383 | |
| 1384 | p = kmem_cache_create("iopte_cache", IOPTE_TABLE_SIZE, align, flags, |
Josue Albarran | bfee0cf | 2017-07-28 15:49:14 -0500 | [diff] [blame^] | 1385 | NULL); |
Hiroshi DOYU | a9dcad5 | 2009-01-26 15:13:40 +0200 | [diff] [blame] | 1386 | if (!p) |
| 1387 | return -ENOMEM; |
| 1388 | iopte_cachep = p; |
| 1389 | |
Suman Anna | 61c7535 | 2014-10-22 17:22:30 -0500 | [diff] [blame] | 1390 | omap_iommu_debugfs_init(); |
| 1391 | |
Suman Anna | abaa7e5 | 2017-04-12 00:21:26 -0500 | [diff] [blame] | 1392 | ret = platform_driver_register(&omap_iommu_driver); |
| 1393 | if (ret) { |
| 1394 | pr_err("%s: failed to register driver\n", __func__); |
| 1395 | goto fail_driver; |
| 1396 | } |
| 1397 | |
| 1398 | ret = bus_set_iommu(&platform_bus_type, &omap_iommu_ops); |
| 1399 | if (ret) |
| 1400 | goto fail_bus; |
| 1401 | |
| 1402 | return 0; |
| 1403 | |
| 1404 | fail_bus: |
| 1405 | platform_driver_unregister(&omap_iommu_driver); |
| 1406 | fail_driver: |
| 1407 | kmem_cache_destroy(iopte_cachep); |
| 1408 | return ret; |
Hiroshi DOYU | a9dcad5 | 2009-01-26 15:13:40 +0200 | [diff] [blame] | 1409 | } |
Ohad Ben-Cohen | 435792d | 2012-02-26 12:14:14 +0200 | [diff] [blame] | 1410 | subsys_initcall(omap_iommu_init); |
Suman Anna | 0cdbf72 | 2015-07-20 17:33:24 -0500 | [diff] [blame] | 1411 | /* must be ready before omap3isp is probed */ |