KyongHo Cho | 2a96536 | 2012-05-12 05:56:09 +0900 | [diff] [blame] | 1 | /* linux/drivers/iommu/exynos_iommu.c |
| 2 | * |
| 3 | * Copyright (c) 2011 Samsung Electronics Co., Ltd. |
| 4 | * http://www.samsung.com |
| 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 version 2 as |
| 8 | * published by the Free Software Foundation. |
| 9 | */ |
| 10 | |
| 11 | #ifdef CONFIG_EXYNOS_IOMMU_DEBUG |
| 12 | #define DEBUG |
| 13 | #endif |
| 14 | |
| 15 | #include <linux/io.h> |
| 16 | #include <linux/interrupt.h> |
| 17 | #include <linux/platform_device.h> |
| 18 | #include <linux/slab.h> |
| 19 | #include <linux/pm_runtime.h> |
| 20 | #include <linux/clk.h> |
| 21 | #include <linux/err.h> |
| 22 | #include <linux/mm.h> |
| 23 | #include <linux/iommu.h> |
| 24 | #include <linux/errno.h> |
| 25 | #include <linux/list.h> |
| 26 | #include <linux/memblock.h> |
| 27 | #include <linux/export.h> |
| 28 | |
| 29 | #include <asm/cacheflush.h> |
| 30 | #include <asm/pgtable.h> |
| 31 | |
Cho KyongHo | d09d78f | 2014-05-12 11:44:58 +0530 | [diff] [blame] | 32 | typedef u32 sysmmu_iova_t; |
| 33 | typedef u32 sysmmu_pte_t; |
| 34 | |
Sachin Kamat | f171aba | 2014-08-04 10:06:28 +0530 | [diff] [blame] | 35 | /* We do not consider super section mapping (16MB) */ |
KyongHo Cho | 2a96536 | 2012-05-12 05:56:09 +0900 | [diff] [blame] | 36 | #define SECT_ORDER 20 |
| 37 | #define LPAGE_ORDER 16 |
| 38 | #define SPAGE_ORDER 12 |
| 39 | |
| 40 | #define SECT_SIZE (1 << SECT_ORDER) |
| 41 | #define LPAGE_SIZE (1 << LPAGE_ORDER) |
| 42 | #define SPAGE_SIZE (1 << SPAGE_ORDER) |
| 43 | |
| 44 | #define SECT_MASK (~(SECT_SIZE - 1)) |
| 45 | #define LPAGE_MASK (~(LPAGE_SIZE - 1)) |
| 46 | #define SPAGE_MASK (~(SPAGE_SIZE - 1)) |
| 47 | |
Cho KyongHo | 66a7ed8 | 2014-05-12 11:45:04 +0530 | [diff] [blame] | 48 | #define lv1ent_fault(sent) ((*(sent) == ZERO_LV2LINK) || \ |
| 49 | ((*(sent) & 3) == 0) || ((*(sent) & 3) == 3)) |
| 50 | #define lv1ent_zero(sent) (*(sent) == ZERO_LV2LINK) |
| 51 | #define lv1ent_page_zero(sent) ((*(sent) & 3) == 1) |
| 52 | #define lv1ent_page(sent) ((*(sent) != ZERO_LV2LINK) && \ |
| 53 | ((*(sent) & 3) == 1)) |
KyongHo Cho | 2a96536 | 2012-05-12 05:56:09 +0900 | [diff] [blame] | 54 | #define lv1ent_section(sent) ((*(sent) & 3) == 2) |
| 55 | |
| 56 | #define lv2ent_fault(pent) ((*(pent) & 3) == 0) |
| 57 | #define lv2ent_small(pent) ((*(pent) & 2) == 2) |
| 58 | #define lv2ent_large(pent) ((*(pent) & 3) == 1) |
| 59 | |
Cho KyongHo | d09d78f | 2014-05-12 11:44:58 +0530 | [diff] [blame] | 60 | static u32 sysmmu_page_offset(sysmmu_iova_t iova, u32 size) |
| 61 | { |
| 62 | return iova & (size - 1); |
| 63 | } |
KyongHo Cho | 2a96536 | 2012-05-12 05:56:09 +0900 | [diff] [blame] | 64 | |
Cho KyongHo | d09d78f | 2014-05-12 11:44:58 +0530 | [diff] [blame] | 65 | #define section_phys(sent) (*(sent) & SECT_MASK) |
| 66 | #define section_offs(iova) sysmmu_page_offset((iova), SECT_SIZE) |
| 67 | #define lpage_phys(pent) (*(pent) & LPAGE_MASK) |
| 68 | #define lpage_offs(iova) sysmmu_page_offset((iova), LPAGE_SIZE) |
| 69 | #define spage_phys(pent) (*(pent) & SPAGE_MASK) |
| 70 | #define spage_offs(iova) sysmmu_page_offset((iova), SPAGE_SIZE) |
KyongHo Cho | 2a96536 | 2012-05-12 05:56:09 +0900 | [diff] [blame] | 71 | |
| 72 | #define NUM_LV1ENTRIES 4096 |
Cho KyongHo | d09d78f | 2014-05-12 11:44:58 +0530 | [diff] [blame] | 73 | #define NUM_LV2ENTRIES (SECT_SIZE / SPAGE_SIZE) |
KyongHo Cho | 2a96536 | 2012-05-12 05:56:09 +0900 | [diff] [blame] | 74 | |
Cho KyongHo | d09d78f | 2014-05-12 11:44:58 +0530 | [diff] [blame] | 75 | static u32 lv1ent_offset(sysmmu_iova_t iova) |
| 76 | { |
| 77 | return iova >> SECT_ORDER; |
| 78 | } |
| 79 | |
| 80 | static u32 lv2ent_offset(sysmmu_iova_t iova) |
| 81 | { |
| 82 | return (iova >> SPAGE_ORDER) & (NUM_LV2ENTRIES - 1); |
| 83 | } |
| 84 | |
| 85 | #define LV2TABLE_SIZE (NUM_LV2ENTRIES * sizeof(sysmmu_pte_t)) |
KyongHo Cho | 2a96536 | 2012-05-12 05:56:09 +0900 | [diff] [blame] | 86 | |
| 87 | #define SPAGES_PER_LPAGE (LPAGE_SIZE / SPAGE_SIZE) |
| 88 | |
| 89 | #define lv2table_base(sent) (*(sent) & 0xFFFFFC00) |
| 90 | |
| 91 | #define mk_lv1ent_sect(pa) ((pa) | 2) |
| 92 | #define mk_lv1ent_page(pa) ((pa) | 1) |
| 93 | #define mk_lv2ent_lpage(pa) ((pa) | 1) |
| 94 | #define mk_lv2ent_spage(pa) ((pa) | 2) |
| 95 | |
| 96 | #define CTRL_ENABLE 0x5 |
| 97 | #define CTRL_BLOCK 0x7 |
| 98 | #define CTRL_DISABLE 0x0 |
| 99 | |
Cho KyongHo | eeb5184 | 2014-05-12 11:45:03 +0530 | [diff] [blame] | 100 | #define CFG_LRU 0x1 |
| 101 | #define CFG_QOS(n) ((n & 0xF) << 7) |
| 102 | #define CFG_MASK 0x0150FFFF /* Selecting bit 0-15, 20, 22 and 24 */ |
| 103 | #define CFG_ACGEN (1 << 24) /* System MMU 3.3 only */ |
| 104 | #define CFG_SYSSEL (1 << 22) /* System MMU 3.2 only */ |
| 105 | #define CFG_FLPDCACHE (1 << 20) /* System MMU 3.2+ only */ |
| 106 | |
KyongHo Cho | 2a96536 | 2012-05-12 05:56:09 +0900 | [diff] [blame] | 107 | #define REG_MMU_CTRL 0x000 |
| 108 | #define REG_MMU_CFG 0x004 |
| 109 | #define REG_MMU_STATUS 0x008 |
| 110 | #define REG_MMU_FLUSH 0x00C |
| 111 | #define REG_MMU_FLUSH_ENTRY 0x010 |
| 112 | #define REG_PT_BASE_ADDR 0x014 |
| 113 | #define REG_INT_STATUS 0x018 |
| 114 | #define REG_INT_CLEAR 0x01C |
| 115 | |
| 116 | #define REG_PAGE_FAULT_ADDR 0x024 |
| 117 | #define REG_AW_FAULT_ADDR 0x028 |
| 118 | #define REG_AR_FAULT_ADDR 0x02C |
| 119 | #define REG_DEFAULT_SLAVE_ADDR 0x030 |
| 120 | |
| 121 | #define REG_MMU_VERSION 0x034 |
| 122 | |
Cho KyongHo | eeb5184 | 2014-05-12 11:45:03 +0530 | [diff] [blame] | 123 | #define MMU_MAJ_VER(val) ((val) >> 7) |
| 124 | #define MMU_MIN_VER(val) ((val) & 0x7F) |
| 125 | #define MMU_RAW_VER(reg) (((reg) >> 21) & ((1 << 11) - 1)) /* 11 bits */ |
| 126 | |
| 127 | #define MAKE_MMU_VER(maj, min) ((((maj) & 0xF) << 7) | ((min) & 0x7F)) |
| 128 | |
KyongHo Cho | 2a96536 | 2012-05-12 05:56:09 +0900 | [diff] [blame] | 129 | #define REG_PB0_SADDR 0x04C |
| 130 | #define REG_PB0_EADDR 0x050 |
| 131 | #define REG_PB1_SADDR 0x054 |
| 132 | #define REG_PB1_EADDR 0x058 |
| 133 | |
Cho KyongHo | 6b21a5d | 2014-05-12 11:45:02 +0530 | [diff] [blame] | 134 | #define has_sysmmu(dev) (dev->archdata.iommu != NULL) |
| 135 | |
Cho KyongHo | 734c3c7 | 2014-05-12 11:44:48 +0530 | [diff] [blame] | 136 | static struct kmem_cache *lv2table_kmem_cache; |
Cho KyongHo | 66a7ed8 | 2014-05-12 11:45:04 +0530 | [diff] [blame] | 137 | static sysmmu_pte_t *zero_lv2_table; |
| 138 | #define ZERO_LV2LINK mk_lv1ent_page(virt_to_phys(zero_lv2_table)) |
Cho KyongHo | 734c3c7 | 2014-05-12 11:44:48 +0530 | [diff] [blame] | 139 | |
Cho KyongHo | d09d78f | 2014-05-12 11:44:58 +0530 | [diff] [blame] | 140 | static sysmmu_pte_t *section_entry(sysmmu_pte_t *pgtable, sysmmu_iova_t iova) |
KyongHo Cho | 2a96536 | 2012-05-12 05:56:09 +0900 | [diff] [blame] | 141 | { |
| 142 | return pgtable + lv1ent_offset(iova); |
| 143 | } |
| 144 | |
Cho KyongHo | d09d78f | 2014-05-12 11:44:58 +0530 | [diff] [blame] | 145 | static sysmmu_pte_t *page_entry(sysmmu_pte_t *sent, sysmmu_iova_t iova) |
KyongHo Cho | 2a96536 | 2012-05-12 05:56:09 +0900 | [diff] [blame] | 146 | { |
Cho KyongHo | d09d78f | 2014-05-12 11:44:58 +0530 | [diff] [blame] | 147 | return (sysmmu_pte_t *)phys_to_virt( |
Cho KyongHo | 7222e8d | 2014-05-12 11:44:46 +0530 | [diff] [blame] | 148 | lv2table_base(sent)) + lv2ent_offset(iova); |
KyongHo Cho | 2a96536 | 2012-05-12 05:56:09 +0900 | [diff] [blame] | 149 | } |
| 150 | |
| 151 | enum exynos_sysmmu_inttype { |
| 152 | SYSMMU_PAGEFAULT, |
| 153 | SYSMMU_AR_MULTIHIT, |
| 154 | SYSMMU_AW_MULTIHIT, |
| 155 | SYSMMU_BUSERROR, |
| 156 | SYSMMU_AR_SECURITY, |
| 157 | SYSMMU_AR_ACCESS, |
| 158 | SYSMMU_AW_SECURITY, |
| 159 | SYSMMU_AW_PROTECTION, /* 7 */ |
| 160 | SYSMMU_FAULT_UNKNOWN, |
| 161 | SYSMMU_FAULTS_NUM |
| 162 | }; |
| 163 | |
KyongHo Cho | 2a96536 | 2012-05-12 05:56:09 +0900 | [diff] [blame] | 164 | static unsigned short fault_reg_offset[SYSMMU_FAULTS_NUM] = { |
| 165 | REG_PAGE_FAULT_ADDR, |
| 166 | REG_AR_FAULT_ADDR, |
| 167 | REG_AW_FAULT_ADDR, |
| 168 | REG_DEFAULT_SLAVE_ADDR, |
| 169 | REG_AR_FAULT_ADDR, |
| 170 | REG_AR_FAULT_ADDR, |
| 171 | REG_AW_FAULT_ADDR, |
| 172 | REG_AW_FAULT_ADDR |
| 173 | }; |
| 174 | |
| 175 | static char *sysmmu_fault_name[SYSMMU_FAULTS_NUM] = { |
| 176 | "PAGE FAULT", |
| 177 | "AR MULTI-HIT FAULT", |
| 178 | "AW MULTI-HIT FAULT", |
| 179 | "BUS ERROR", |
| 180 | "AR SECURITY PROTECTION FAULT", |
| 181 | "AR ACCESS PROTECTION FAULT", |
| 182 | "AW SECURITY PROTECTION FAULT", |
| 183 | "AW ACCESS PROTECTION FAULT", |
| 184 | "UNKNOWN FAULT" |
| 185 | }; |
| 186 | |
Cho KyongHo | 6b21a5d | 2014-05-12 11:45:02 +0530 | [diff] [blame] | 187 | /* attached to dev.archdata.iommu of the master device */ |
| 188 | struct exynos_iommu_owner { |
| 189 | struct list_head client; /* entry of exynos_iommu_domain.clients */ |
| 190 | struct device *dev; |
| 191 | struct device *sysmmu; |
| 192 | struct iommu_domain *domain; |
| 193 | void *vmm_data; /* IO virtual memory manager's data */ |
| 194 | spinlock_t lock; /* Lock to preserve consistency of System MMU */ |
| 195 | }; |
| 196 | |
KyongHo Cho | 2a96536 | 2012-05-12 05:56:09 +0900 | [diff] [blame] | 197 | struct exynos_iommu_domain { |
| 198 | struct list_head clients; /* list of sysmmu_drvdata.node */ |
Cho KyongHo | d09d78f | 2014-05-12 11:44:58 +0530 | [diff] [blame] | 199 | sysmmu_pte_t *pgtable; /* lv1 page table, 16KB */ |
KyongHo Cho | 2a96536 | 2012-05-12 05:56:09 +0900 | [diff] [blame] | 200 | short *lv2entcnt; /* free lv2 entry counter for each section */ |
| 201 | spinlock_t lock; /* lock for this structure */ |
| 202 | spinlock_t pgtablelock; /* lock for modifying page table @ pgtable */ |
| 203 | }; |
| 204 | |
| 205 | struct sysmmu_drvdata { |
KyongHo Cho | 2a96536 | 2012-05-12 05:56:09 +0900 | [diff] [blame] | 206 | struct device *sysmmu; /* System MMU's device descriptor */ |
Cho KyongHo | 6b21a5d | 2014-05-12 11:45:02 +0530 | [diff] [blame] | 207 | struct device *master; /* Owner of system MMU */ |
Cho KyongHo | 7222e8d | 2014-05-12 11:44:46 +0530 | [diff] [blame] | 208 | void __iomem *sfrbase; |
| 209 | struct clk *clk; |
Cho KyongHo | 7060587 | 2014-05-12 11:44:55 +0530 | [diff] [blame] | 210 | struct clk *clk_master; |
KyongHo Cho | 2a96536 | 2012-05-12 05:56:09 +0900 | [diff] [blame] | 211 | int activations; |
Cho KyongHo | 9d4e7a2 | 2014-05-12 11:44:57 +0530 | [diff] [blame] | 212 | spinlock_t lock; |
KyongHo Cho | 2a96536 | 2012-05-12 05:56:09 +0900 | [diff] [blame] | 213 | struct iommu_domain *domain; |
Cho KyongHo | 7222e8d | 2014-05-12 11:44:46 +0530 | [diff] [blame] | 214 | phys_addr_t pgtable; |
KyongHo Cho | 2a96536 | 2012-05-12 05:56:09 +0900 | [diff] [blame] | 215 | }; |
| 216 | |
| 217 | static bool set_sysmmu_active(struct sysmmu_drvdata *data) |
| 218 | { |
| 219 | /* return true if the System MMU was not active previously |
| 220 | and it needs to be initialized */ |
| 221 | return ++data->activations == 1; |
| 222 | } |
| 223 | |
| 224 | static bool set_sysmmu_inactive(struct sysmmu_drvdata *data) |
| 225 | { |
| 226 | /* return true if the System MMU is needed to be disabled */ |
| 227 | BUG_ON(data->activations < 1); |
| 228 | return --data->activations == 0; |
| 229 | } |
| 230 | |
| 231 | static bool is_sysmmu_active(struct sysmmu_drvdata *data) |
| 232 | { |
| 233 | return data->activations > 0; |
| 234 | } |
| 235 | |
| 236 | static void sysmmu_unblock(void __iomem *sfrbase) |
| 237 | { |
| 238 | __raw_writel(CTRL_ENABLE, sfrbase + REG_MMU_CTRL); |
| 239 | } |
| 240 | |
Cho KyongHo | eeb5184 | 2014-05-12 11:45:03 +0530 | [diff] [blame] | 241 | static unsigned int __raw_sysmmu_version(struct sysmmu_drvdata *data) |
| 242 | { |
| 243 | return MMU_RAW_VER(__raw_readl(data->sfrbase + REG_MMU_VERSION)); |
| 244 | } |
| 245 | |
KyongHo Cho | 2a96536 | 2012-05-12 05:56:09 +0900 | [diff] [blame] | 246 | static bool sysmmu_block(void __iomem *sfrbase) |
| 247 | { |
| 248 | int i = 120; |
| 249 | |
| 250 | __raw_writel(CTRL_BLOCK, sfrbase + REG_MMU_CTRL); |
| 251 | while ((i > 0) && !(__raw_readl(sfrbase + REG_MMU_STATUS) & 1)) |
| 252 | --i; |
| 253 | |
| 254 | if (!(__raw_readl(sfrbase + REG_MMU_STATUS) & 1)) { |
| 255 | sysmmu_unblock(sfrbase); |
| 256 | return false; |
| 257 | } |
| 258 | |
| 259 | return true; |
| 260 | } |
| 261 | |
| 262 | static void __sysmmu_tlb_invalidate(void __iomem *sfrbase) |
| 263 | { |
| 264 | __raw_writel(0x1, sfrbase + REG_MMU_FLUSH); |
| 265 | } |
| 266 | |
| 267 | static void __sysmmu_tlb_invalidate_entry(void __iomem *sfrbase, |
Cho KyongHo | d09d78f | 2014-05-12 11:44:58 +0530 | [diff] [blame] | 268 | sysmmu_iova_t iova, unsigned int num_inv) |
KyongHo Cho | 2a96536 | 2012-05-12 05:56:09 +0900 | [diff] [blame] | 269 | { |
Cho KyongHo | 3ad6b7f | 2014-05-12 11:44:49 +0530 | [diff] [blame] | 270 | unsigned int i; |
Sachin Kamat | 365409d | 2014-05-22 09:50:56 +0530 | [diff] [blame] | 271 | |
Cho KyongHo | 3ad6b7f | 2014-05-12 11:44:49 +0530 | [diff] [blame] | 272 | for (i = 0; i < num_inv; i++) { |
| 273 | __raw_writel((iova & SPAGE_MASK) | 1, |
| 274 | sfrbase + REG_MMU_FLUSH_ENTRY); |
| 275 | iova += SPAGE_SIZE; |
| 276 | } |
KyongHo Cho | 2a96536 | 2012-05-12 05:56:09 +0900 | [diff] [blame] | 277 | } |
| 278 | |
| 279 | static void __sysmmu_set_ptbase(void __iomem *sfrbase, |
Cho KyongHo | d09d78f | 2014-05-12 11:44:58 +0530 | [diff] [blame] | 280 | phys_addr_t pgd) |
KyongHo Cho | 2a96536 | 2012-05-12 05:56:09 +0900 | [diff] [blame] | 281 | { |
KyongHo Cho | 2a96536 | 2012-05-12 05:56:09 +0900 | [diff] [blame] | 282 | __raw_writel(pgd, sfrbase + REG_PT_BASE_ADDR); |
| 283 | |
| 284 | __sysmmu_tlb_invalidate(sfrbase); |
| 285 | } |
| 286 | |
Cho KyongHo | 1fab7fa | 2014-05-12 11:44:56 +0530 | [diff] [blame] | 287 | static void show_fault_information(const char *name, |
| 288 | enum exynos_sysmmu_inttype itype, |
Cho KyongHo | d09d78f | 2014-05-12 11:44:58 +0530 | [diff] [blame] | 289 | phys_addr_t pgtable_base, sysmmu_iova_t fault_addr) |
KyongHo Cho | 2a96536 | 2012-05-12 05:56:09 +0900 | [diff] [blame] | 290 | { |
Cho KyongHo | d09d78f | 2014-05-12 11:44:58 +0530 | [diff] [blame] | 291 | sysmmu_pte_t *ent; |
KyongHo Cho | 2a96536 | 2012-05-12 05:56:09 +0900 | [diff] [blame] | 292 | |
| 293 | if ((itype >= SYSMMU_FAULTS_NUM) || (itype < SYSMMU_PAGEFAULT)) |
| 294 | itype = SYSMMU_FAULT_UNKNOWN; |
| 295 | |
Cho KyongHo | d09d78f | 2014-05-12 11:44:58 +0530 | [diff] [blame] | 296 | pr_err("%s occurred at %#x by %s(Page table base: %pa)\n", |
Cho KyongHo | 1fab7fa | 2014-05-12 11:44:56 +0530 | [diff] [blame] | 297 | sysmmu_fault_name[itype], fault_addr, name, &pgtable_base); |
KyongHo Cho | 2a96536 | 2012-05-12 05:56:09 +0900 | [diff] [blame] | 298 | |
Cho KyongHo | 7222e8d | 2014-05-12 11:44:46 +0530 | [diff] [blame] | 299 | ent = section_entry(phys_to_virt(pgtable_base), fault_addr); |
Cho KyongHo | d09d78f | 2014-05-12 11:44:58 +0530 | [diff] [blame] | 300 | pr_err("\tLv1 entry: %#x\n", *ent); |
KyongHo Cho | 2a96536 | 2012-05-12 05:56:09 +0900 | [diff] [blame] | 301 | |
| 302 | if (lv1ent_page(ent)) { |
| 303 | ent = page_entry(ent, fault_addr); |
Cho KyongHo | d09d78f | 2014-05-12 11:44:58 +0530 | [diff] [blame] | 304 | pr_err("\t Lv2 entry: %#x\n", *ent); |
KyongHo Cho | 2a96536 | 2012-05-12 05:56:09 +0900 | [diff] [blame] | 305 | } |
KyongHo Cho | 2a96536 | 2012-05-12 05:56:09 +0900 | [diff] [blame] | 306 | } |
| 307 | |
| 308 | static irqreturn_t exynos_sysmmu_irq(int irq, void *dev_id) |
| 309 | { |
Sachin Kamat | f171aba | 2014-08-04 10:06:28 +0530 | [diff] [blame] | 310 | /* SYSMMU is in blocked state when interrupt occurred. */ |
KyongHo Cho | 2a96536 | 2012-05-12 05:56:09 +0900 | [diff] [blame] | 311 | struct sysmmu_drvdata *data = dev_id; |
KyongHo Cho | 2a96536 | 2012-05-12 05:56:09 +0900 | [diff] [blame] | 312 | enum exynos_sysmmu_inttype itype; |
Cho KyongHo | d09d78f | 2014-05-12 11:44:58 +0530 | [diff] [blame] | 313 | sysmmu_iova_t addr = -1; |
Cho KyongHo | 7222e8d | 2014-05-12 11:44:46 +0530 | [diff] [blame] | 314 | int ret = -ENOSYS; |
KyongHo Cho | 2a96536 | 2012-05-12 05:56:09 +0900 | [diff] [blame] | 315 | |
KyongHo Cho | 2a96536 | 2012-05-12 05:56:09 +0900 | [diff] [blame] | 316 | WARN_ON(!is_sysmmu_active(data)); |
| 317 | |
Cho KyongHo | 9d4e7a2 | 2014-05-12 11:44:57 +0530 | [diff] [blame] | 318 | spin_lock(&data->lock); |
| 319 | |
Cho KyongHo | 7060587 | 2014-05-12 11:44:55 +0530 | [diff] [blame] | 320 | if (!IS_ERR(data->clk_master)) |
| 321 | clk_enable(data->clk_master); |
Cho KyongHo | 9d4e7a2 | 2014-05-12 11:44:57 +0530 | [diff] [blame] | 322 | |
Cho KyongHo | 7222e8d | 2014-05-12 11:44:46 +0530 | [diff] [blame] | 323 | itype = (enum exynos_sysmmu_inttype) |
| 324 | __ffs(__raw_readl(data->sfrbase + REG_INT_STATUS)); |
| 325 | if (WARN_ON(!((itype >= 0) && (itype < SYSMMU_FAULT_UNKNOWN)))) |
KyongHo Cho | 2a96536 | 2012-05-12 05:56:09 +0900 | [diff] [blame] | 326 | itype = SYSMMU_FAULT_UNKNOWN; |
Cho KyongHo | 7222e8d | 2014-05-12 11:44:46 +0530 | [diff] [blame] | 327 | else |
| 328 | addr = __raw_readl(data->sfrbase + fault_reg_offset[itype]); |
KyongHo Cho | 2a96536 | 2012-05-12 05:56:09 +0900 | [diff] [blame] | 329 | |
Cho KyongHo | 1fab7fa | 2014-05-12 11:44:56 +0530 | [diff] [blame] | 330 | if (itype == SYSMMU_FAULT_UNKNOWN) { |
| 331 | pr_err("%s: Fault is not occurred by System MMU '%s'!\n", |
| 332 | __func__, dev_name(data->sysmmu)); |
| 333 | pr_err("%s: Please check if IRQ is correctly configured.\n", |
| 334 | __func__); |
| 335 | BUG(); |
| 336 | } else { |
Cho KyongHo | d09d78f | 2014-05-12 11:44:58 +0530 | [diff] [blame] | 337 | unsigned int base = |
Cho KyongHo | 1fab7fa | 2014-05-12 11:44:56 +0530 | [diff] [blame] | 338 | __raw_readl(data->sfrbase + REG_PT_BASE_ADDR); |
| 339 | show_fault_information(dev_name(data->sysmmu), |
| 340 | itype, base, addr); |
| 341 | if (data->domain) |
| 342 | ret = report_iommu_fault(data->domain, |
Cho KyongHo | 6b21a5d | 2014-05-12 11:45:02 +0530 | [diff] [blame] | 343 | data->master, addr, itype); |
KyongHo Cho | 2a96536 | 2012-05-12 05:56:09 +0900 | [diff] [blame] | 344 | } |
| 345 | |
Cho KyongHo | 1fab7fa | 2014-05-12 11:44:56 +0530 | [diff] [blame] | 346 | /* fault is not recovered by fault handler */ |
| 347 | BUG_ON(ret != 0); |
KyongHo Cho | 2a96536 | 2012-05-12 05:56:09 +0900 | [diff] [blame] | 348 | |
Cho KyongHo | 1fab7fa | 2014-05-12 11:44:56 +0530 | [diff] [blame] | 349 | __raw_writel(1 << itype, data->sfrbase + REG_INT_CLEAR); |
| 350 | |
| 351 | sysmmu_unblock(data->sfrbase); |
KyongHo Cho | 2a96536 | 2012-05-12 05:56:09 +0900 | [diff] [blame] | 352 | |
Cho KyongHo | 7060587 | 2014-05-12 11:44:55 +0530 | [diff] [blame] | 353 | if (!IS_ERR(data->clk_master)) |
| 354 | clk_disable(data->clk_master); |
| 355 | |
Cho KyongHo | 9d4e7a2 | 2014-05-12 11:44:57 +0530 | [diff] [blame] | 356 | spin_unlock(&data->lock); |
KyongHo Cho | 2a96536 | 2012-05-12 05:56:09 +0900 | [diff] [blame] | 357 | |
| 358 | return IRQ_HANDLED; |
| 359 | } |
| 360 | |
Cho KyongHo | 6b21a5d | 2014-05-12 11:45:02 +0530 | [diff] [blame] | 361 | static void __sysmmu_disable_nocount(struct sysmmu_drvdata *data) |
KyongHo Cho | 2a96536 | 2012-05-12 05:56:09 +0900 | [diff] [blame] | 362 | { |
Cho KyongHo | 7060587 | 2014-05-12 11:44:55 +0530 | [diff] [blame] | 363 | if (!IS_ERR(data->clk_master)) |
| 364 | clk_enable(data->clk_master); |
| 365 | |
Cho KyongHo | 7222e8d | 2014-05-12 11:44:46 +0530 | [diff] [blame] | 366 | __raw_writel(CTRL_DISABLE, data->sfrbase + REG_MMU_CTRL); |
Cho KyongHo | 6b21a5d | 2014-05-12 11:45:02 +0530 | [diff] [blame] | 367 | __raw_writel(0, data->sfrbase + REG_MMU_CFG); |
KyongHo Cho | 2a96536 | 2012-05-12 05:56:09 +0900 | [diff] [blame] | 368 | |
Cho KyongHo | 46c16d1 | 2014-05-12 11:44:54 +0530 | [diff] [blame] | 369 | clk_disable(data->clk); |
Cho KyongHo | 7060587 | 2014-05-12 11:44:55 +0530 | [diff] [blame] | 370 | if (!IS_ERR(data->clk_master)) |
| 371 | clk_disable(data->clk_master); |
Cho KyongHo | 6b21a5d | 2014-05-12 11:45:02 +0530 | [diff] [blame] | 372 | } |
KyongHo Cho | 2a96536 | 2012-05-12 05:56:09 +0900 | [diff] [blame] | 373 | |
Cho KyongHo | 6b21a5d | 2014-05-12 11:45:02 +0530 | [diff] [blame] | 374 | static bool __sysmmu_disable(struct sysmmu_drvdata *data) |
| 375 | { |
| 376 | bool disabled; |
| 377 | unsigned long flags; |
| 378 | |
| 379 | spin_lock_irqsave(&data->lock, flags); |
| 380 | |
| 381 | disabled = set_sysmmu_inactive(data); |
| 382 | |
| 383 | if (disabled) { |
| 384 | data->pgtable = 0; |
| 385 | data->domain = NULL; |
| 386 | |
| 387 | __sysmmu_disable_nocount(data); |
| 388 | |
| 389 | dev_dbg(data->sysmmu, "Disabled\n"); |
| 390 | } else { |
| 391 | dev_dbg(data->sysmmu, "%d times left to disable\n", |
| 392 | data->activations); |
| 393 | } |
| 394 | |
Cho KyongHo | 9d4e7a2 | 2014-05-12 11:44:57 +0530 | [diff] [blame] | 395 | spin_unlock_irqrestore(&data->lock, flags); |
KyongHo Cho | 2a96536 | 2012-05-12 05:56:09 +0900 | [diff] [blame] | 396 | |
KyongHo Cho | 2a96536 | 2012-05-12 05:56:09 +0900 | [diff] [blame] | 397 | return disabled; |
| 398 | } |
| 399 | |
Cho KyongHo | 6b21a5d | 2014-05-12 11:45:02 +0530 | [diff] [blame] | 400 | static void __sysmmu_init_config(struct sysmmu_drvdata *data) |
| 401 | { |
Cho KyongHo | eeb5184 | 2014-05-12 11:45:03 +0530 | [diff] [blame] | 402 | unsigned int cfg = CFG_LRU | CFG_QOS(15); |
| 403 | unsigned int ver; |
| 404 | |
| 405 | ver = __raw_sysmmu_version(data); |
| 406 | if (MMU_MAJ_VER(ver) == 3) { |
| 407 | if (MMU_MIN_VER(ver) >= 2) { |
| 408 | cfg |= CFG_FLPDCACHE; |
| 409 | if (MMU_MIN_VER(ver) == 3) { |
| 410 | cfg |= CFG_ACGEN; |
| 411 | cfg &= ~CFG_LRU; |
| 412 | } else { |
| 413 | cfg |= CFG_SYSSEL; |
| 414 | } |
| 415 | } |
| 416 | } |
Cho KyongHo | 6b21a5d | 2014-05-12 11:45:02 +0530 | [diff] [blame] | 417 | |
| 418 | __raw_writel(cfg, data->sfrbase + REG_MMU_CFG); |
| 419 | } |
| 420 | |
| 421 | static void __sysmmu_enable_nocount(struct sysmmu_drvdata *data) |
| 422 | { |
| 423 | if (!IS_ERR(data->clk_master)) |
| 424 | clk_enable(data->clk_master); |
| 425 | clk_enable(data->clk); |
| 426 | |
| 427 | __raw_writel(CTRL_BLOCK, data->sfrbase + REG_MMU_CTRL); |
| 428 | |
| 429 | __sysmmu_init_config(data); |
| 430 | |
| 431 | __sysmmu_set_ptbase(data->sfrbase, data->pgtable); |
| 432 | |
| 433 | __raw_writel(CTRL_ENABLE, data->sfrbase + REG_MMU_CTRL); |
| 434 | |
| 435 | if (!IS_ERR(data->clk_master)) |
| 436 | clk_disable(data->clk_master); |
| 437 | } |
| 438 | |
| 439 | static int __sysmmu_enable(struct sysmmu_drvdata *data, |
| 440 | phys_addr_t pgtable, struct iommu_domain *domain) |
| 441 | { |
| 442 | int ret = 0; |
| 443 | unsigned long flags; |
| 444 | |
| 445 | spin_lock_irqsave(&data->lock, flags); |
| 446 | if (set_sysmmu_active(data)) { |
| 447 | data->pgtable = pgtable; |
| 448 | data->domain = domain; |
| 449 | |
| 450 | __sysmmu_enable_nocount(data); |
| 451 | |
| 452 | dev_dbg(data->sysmmu, "Enabled\n"); |
| 453 | } else { |
| 454 | ret = (pgtable == data->pgtable) ? 1 : -EBUSY; |
| 455 | |
| 456 | dev_dbg(data->sysmmu, "already enabled\n"); |
| 457 | } |
| 458 | |
| 459 | if (WARN_ON(ret < 0)) |
| 460 | set_sysmmu_inactive(data); /* decrement count */ |
| 461 | |
| 462 | spin_unlock_irqrestore(&data->lock, flags); |
| 463 | |
| 464 | return ret; |
| 465 | } |
| 466 | |
KyongHo Cho | 2a96536 | 2012-05-12 05:56:09 +0900 | [diff] [blame] | 467 | /* __exynos_sysmmu_enable: Enables System MMU |
| 468 | * |
| 469 | * returns -error if an error occurred and System MMU is not enabled, |
| 470 | * 0 if the System MMU has been just enabled and 1 if System MMU was already |
| 471 | * enabled before. |
| 472 | */ |
Cho KyongHo | 6b21a5d | 2014-05-12 11:45:02 +0530 | [diff] [blame] | 473 | static int __exynos_sysmmu_enable(struct device *dev, phys_addr_t pgtable, |
| 474 | struct iommu_domain *domain) |
KyongHo Cho | 2a96536 | 2012-05-12 05:56:09 +0900 | [diff] [blame] | 475 | { |
Cho KyongHo | 7222e8d | 2014-05-12 11:44:46 +0530 | [diff] [blame] | 476 | int ret = 0; |
KyongHo Cho | 2a96536 | 2012-05-12 05:56:09 +0900 | [diff] [blame] | 477 | unsigned long flags; |
Cho KyongHo | 6b21a5d | 2014-05-12 11:45:02 +0530 | [diff] [blame] | 478 | struct exynos_iommu_owner *owner = dev->archdata.iommu; |
| 479 | struct sysmmu_drvdata *data; |
KyongHo Cho | 2a96536 | 2012-05-12 05:56:09 +0900 | [diff] [blame] | 480 | |
Cho KyongHo | 6b21a5d | 2014-05-12 11:45:02 +0530 | [diff] [blame] | 481 | BUG_ON(!has_sysmmu(dev)); |
KyongHo Cho | 2a96536 | 2012-05-12 05:56:09 +0900 | [diff] [blame] | 482 | |
Cho KyongHo | 6b21a5d | 2014-05-12 11:45:02 +0530 | [diff] [blame] | 483 | spin_lock_irqsave(&owner->lock, flags); |
KyongHo Cho | 2a96536 | 2012-05-12 05:56:09 +0900 | [diff] [blame] | 484 | |
Cho KyongHo | 6b21a5d | 2014-05-12 11:45:02 +0530 | [diff] [blame] | 485 | data = dev_get_drvdata(owner->sysmmu); |
KyongHo Cho | 2a96536 | 2012-05-12 05:56:09 +0900 | [diff] [blame] | 486 | |
Cho KyongHo | 6b21a5d | 2014-05-12 11:45:02 +0530 | [diff] [blame] | 487 | ret = __sysmmu_enable(data, pgtable, domain); |
| 488 | if (ret >= 0) |
| 489 | data->master = dev; |
KyongHo Cho | 2a96536 | 2012-05-12 05:56:09 +0900 | [diff] [blame] | 490 | |
Cho KyongHo | 6b21a5d | 2014-05-12 11:45:02 +0530 | [diff] [blame] | 491 | spin_unlock_irqrestore(&owner->lock, flags); |
KyongHo Cho | 2a96536 | 2012-05-12 05:56:09 +0900 | [diff] [blame] | 492 | |
| 493 | return ret; |
| 494 | } |
| 495 | |
Cho KyongHo | d09d78f | 2014-05-12 11:44:58 +0530 | [diff] [blame] | 496 | int exynos_sysmmu_enable(struct device *dev, phys_addr_t pgtable) |
KyongHo Cho | 2a96536 | 2012-05-12 05:56:09 +0900 | [diff] [blame] | 497 | { |
KyongHo Cho | 2a96536 | 2012-05-12 05:56:09 +0900 | [diff] [blame] | 498 | BUG_ON(!memblock_is_memory(pgtable)); |
| 499 | |
Cho KyongHo | 6b21a5d | 2014-05-12 11:45:02 +0530 | [diff] [blame] | 500 | return __exynos_sysmmu_enable(dev, pgtable, NULL); |
KyongHo Cho | 2a96536 | 2012-05-12 05:56:09 +0900 | [diff] [blame] | 501 | } |
| 502 | |
Sachin Kamat | 77e3835 | 2013-02-06 13:55:17 +0530 | [diff] [blame] | 503 | static bool exynos_sysmmu_disable(struct device *dev) |
KyongHo Cho | 2a96536 | 2012-05-12 05:56:09 +0900 | [diff] [blame] | 504 | { |
Cho KyongHo | 6b21a5d | 2014-05-12 11:45:02 +0530 | [diff] [blame] | 505 | unsigned long flags; |
| 506 | bool disabled = true; |
| 507 | struct exynos_iommu_owner *owner = dev->archdata.iommu; |
| 508 | struct sysmmu_drvdata *data; |
KyongHo Cho | 2a96536 | 2012-05-12 05:56:09 +0900 | [diff] [blame] | 509 | |
Cho KyongHo | 6b21a5d | 2014-05-12 11:45:02 +0530 | [diff] [blame] | 510 | BUG_ON(!has_sysmmu(dev)); |
| 511 | |
| 512 | spin_lock_irqsave(&owner->lock, flags); |
| 513 | |
| 514 | data = dev_get_drvdata(owner->sysmmu); |
| 515 | |
| 516 | disabled = __sysmmu_disable(data); |
| 517 | if (disabled) |
| 518 | data->master = NULL; |
| 519 | |
| 520 | spin_unlock_irqrestore(&owner->lock, flags); |
KyongHo Cho | 2a96536 | 2012-05-12 05:56:09 +0900 | [diff] [blame] | 521 | |
| 522 | return disabled; |
| 523 | } |
| 524 | |
Cho KyongHo | 66a7ed8 | 2014-05-12 11:45:04 +0530 | [diff] [blame] | 525 | static void __sysmmu_tlb_invalidate_flpdcache(struct sysmmu_drvdata *data, |
| 526 | sysmmu_iova_t iova) |
| 527 | { |
| 528 | if (__raw_sysmmu_version(data) == MAKE_MMU_VER(3, 3)) |
| 529 | __raw_writel(iova | 0x1, data->sfrbase + REG_MMU_FLUSH_ENTRY); |
| 530 | } |
| 531 | |
| 532 | static void sysmmu_tlb_invalidate_flpdcache(struct device *dev, |
| 533 | sysmmu_iova_t iova) |
| 534 | { |
| 535 | unsigned long flags; |
| 536 | struct exynos_iommu_owner *owner = dev->archdata.iommu; |
| 537 | struct sysmmu_drvdata *data = dev_get_drvdata(owner->sysmmu); |
| 538 | |
| 539 | if (!IS_ERR(data->clk_master)) |
| 540 | clk_enable(data->clk_master); |
| 541 | |
| 542 | spin_lock_irqsave(&data->lock, flags); |
| 543 | if (is_sysmmu_active(data)) |
| 544 | __sysmmu_tlb_invalidate_flpdcache(data, iova); |
| 545 | spin_unlock_irqrestore(&data->lock, flags); |
| 546 | |
| 547 | if (!IS_ERR(data->clk_master)) |
| 548 | clk_disable(data->clk_master); |
| 549 | } |
| 550 | |
Cho KyongHo | d09d78f | 2014-05-12 11:44:58 +0530 | [diff] [blame] | 551 | static void sysmmu_tlb_invalidate_entry(struct device *dev, sysmmu_iova_t iova, |
Cho KyongHo | 3ad6b7f | 2014-05-12 11:44:49 +0530 | [diff] [blame] | 552 | size_t size) |
KyongHo Cho | 2a96536 | 2012-05-12 05:56:09 +0900 | [diff] [blame] | 553 | { |
Cho KyongHo | 6b21a5d | 2014-05-12 11:45:02 +0530 | [diff] [blame] | 554 | struct exynos_iommu_owner *owner = dev->archdata.iommu; |
KyongHo Cho | 2a96536 | 2012-05-12 05:56:09 +0900 | [diff] [blame] | 555 | unsigned long flags; |
Cho KyongHo | 6b21a5d | 2014-05-12 11:45:02 +0530 | [diff] [blame] | 556 | struct sysmmu_drvdata *data; |
| 557 | |
| 558 | data = dev_get_drvdata(owner->sysmmu); |
KyongHo Cho | 2a96536 | 2012-05-12 05:56:09 +0900 | [diff] [blame] | 559 | |
Cho KyongHo | 9d4e7a2 | 2014-05-12 11:44:57 +0530 | [diff] [blame] | 560 | spin_lock_irqsave(&data->lock, flags); |
KyongHo Cho | 2a96536 | 2012-05-12 05:56:09 +0900 | [diff] [blame] | 561 | if (is_sysmmu_active(data)) { |
Cho KyongHo | 3ad6b7f | 2014-05-12 11:44:49 +0530 | [diff] [blame] | 562 | unsigned int num_inv = 1; |
Cho KyongHo | 7060587 | 2014-05-12 11:44:55 +0530 | [diff] [blame] | 563 | |
| 564 | if (!IS_ERR(data->clk_master)) |
| 565 | clk_enable(data->clk_master); |
| 566 | |
Cho KyongHo | 3ad6b7f | 2014-05-12 11:44:49 +0530 | [diff] [blame] | 567 | /* |
| 568 | * L2TLB invalidation required |
| 569 | * 4KB page: 1 invalidation |
Sachin Kamat | f171aba | 2014-08-04 10:06:28 +0530 | [diff] [blame] | 570 | * 64KB page: 16 invalidations |
| 571 | * 1MB page: 64 invalidations |
Cho KyongHo | 3ad6b7f | 2014-05-12 11:44:49 +0530 | [diff] [blame] | 572 | * because it is set-associative TLB |
| 573 | * with 8-way and 64 sets. |
| 574 | * 1MB page can be cached in one of all sets. |
| 575 | * 64KB page can be one of 16 consecutive sets. |
| 576 | */ |
Cho KyongHo | eeb5184 | 2014-05-12 11:45:03 +0530 | [diff] [blame] | 577 | if (MMU_MAJ_VER(__raw_sysmmu_version(data)) == 2) |
Cho KyongHo | 3ad6b7f | 2014-05-12 11:44:49 +0530 | [diff] [blame] | 578 | num_inv = min_t(unsigned int, size / PAGE_SIZE, 64); |
| 579 | |
Cho KyongHo | 7222e8d | 2014-05-12 11:44:46 +0530 | [diff] [blame] | 580 | if (sysmmu_block(data->sfrbase)) { |
| 581 | __sysmmu_tlb_invalidate_entry( |
Cho KyongHo | 3ad6b7f | 2014-05-12 11:44:49 +0530 | [diff] [blame] | 582 | data->sfrbase, iova, num_inv); |
Cho KyongHo | 7222e8d | 2014-05-12 11:44:46 +0530 | [diff] [blame] | 583 | sysmmu_unblock(data->sfrbase); |
KyongHo Cho | 2a96536 | 2012-05-12 05:56:09 +0900 | [diff] [blame] | 584 | } |
Cho KyongHo | 7060587 | 2014-05-12 11:44:55 +0530 | [diff] [blame] | 585 | if (!IS_ERR(data->clk_master)) |
| 586 | clk_disable(data->clk_master); |
KyongHo Cho | 2a96536 | 2012-05-12 05:56:09 +0900 | [diff] [blame] | 587 | } else { |
Cho KyongHo | 6b21a5d | 2014-05-12 11:45:02 +0530 | [diff] [blame] | 588 | dev_dbg(dev, "disabled. Skipping TLB invalidation @ %#x\n", |
| 589 | iova); |
KyongHo Cho | 2a96536 | 2012-05-12 05:56:09 +0900 | [diff] [blame] | 590 | } |
Cho KyongHo | 9d4e7a2 | 2014-05-12 11:44:57 +0530 | [diff] [blame] | 591 | spin_unlock_irqrestore(&data->lock, flags); |
KyongHo Cho | 2a96536 | 2012-05-12 05:56:09 +0900 | [diff] [blame] | 592 | } |
| 593 | |
| 594 | void exynos_sysmmu_tlb_invalidate(struct device *dev) |
| 595 | { |
Cho KyongHo | 6b21a5d | 2014-05-12 11:45:02 +0530 | [diff] [blame] | 596 | struct exynos_iommu_owner *owner = dev->archdata.iommu; |
KyongHo Cho | 2a96536 | 2012-05-12 05:56:09 +0900 | [diff] [blame] | 597 | unsigned long flags; |
Cho KyongHo | 6b21a5d | 2014-05-12 11:45:02 +0530 | [diff] [blame] | 598 | struct sysmmu_drvdata *data; |
| 599 | |
| 600 | data = dev_get_drvdata(owner->sysmmu); |
KyongHo Cho | 2a96536 | 2012-05-12 05:56:09 +0900 | [diff] [blame] | 601 | |
Cho KyongHo | 9d4e7a2 | 2014-05-12 11:44:57 +0530 | [diff] [blame] | 602 | spin_lock_irqsave(&data->lock, flags); |
KyongHo Cho | 2a96536 | 2012-05-12 05:56:09 +0900 | [diff] [blame] | 603 | if (is_sysmmu_active(data)) { |
Cho KyongHo | 7060587 | 2014-05-12 11:44:55 +0530 | [diff] [blame] | 604 | if (!IS_ERR(data->clk_master)) |
| 605 | clk_enable(data->clk_master); |
Cho KyongHo | 7222e8d | 2014-05-12 11:44:46 +0530 | [diff] [blame] | 606 | if (sysmmu_block(data->sfrbase)) { |
| 607 | __sysmmu_tlb_invalidate(data->sfrbase); |
| 608 | sysmmu_unblock(data->sfrbase); |
KyongHo Cho | 2a96536 | 2012-05-12 05:56:09 +0900 | [diff] [blame] | 609 | } |
Cho KyongHo | 7060587 | 2014-05-12 11:44:55 +0530 | [diff] [blame] | 610 | if (!IS_ERR(data->clk_master)) |
| 611 | clk_disable(data->clk_master); |
KyongHo Cho | 2a96536 | 2012-05-12 05:56:09 +0900 | [diff] [blame] | 612 | } else { |
Cho KyongHo | 6b21a5d | 2014-05-12 11:45:02 +0530 | [diff] [blame] | 613 | dev_dbg(dev, "disabled. Skipping TLB invalidation\n"); |
KyongHo Cho | 2a96536 | 2012-05-12 05:56:09 +0900 | [diff] [blame] | 614 | } |
Cho KyongHo | 9d4e7a2 | 2014-05-12 11:44:57 +0530 | [diff] [blame] | 615 | spin_unlock_irqrestore(&data->lock, flags); |
KyongHo Cho | 2a96536 | 2012-05-12 05:56:09 +0900 | [diff] [blame] | 616 | } |
| 617 | |
Cho KyongHo | 6b21a5d | 2014-05-12 11:45:02 +0530 | [diff] [blame] | 618 | static int __init exynos_sysmmu_probe(struct platform_device *pdev) |
KyongHo Cho | 2a96536 | 2012-05-12 05:56:09 +0900 | [diff] [blame] | 619 | { |
Cho KyongHo | 46c16d1 | 2014-05-12 11:44:54 +0530 | [diff] [blame] | 620 | int irq, ret; |
Cho KyongHo | 7222e8d | 2014-05-12 11:44:46 +0530 | [diff] [blame] | 621 | struct device *dev = &pdev->dev; |
KyongHo Cho | 2a96536 | 2012-05-12 05:56:09 +0900 | [diff] [blame] | 622 | struct sysmmu_drvdata *data; |
Cho KyongHo | 7222e8d | 2014-05-12 11:44:46 +0530 | [diff] [blame] | 623 | struct resource *res; |
KyongHo Cho | 2a96536 | 2012-05-12 05:56:09 +0900 | [diff] [blame] | 624 | |
Cho KyongHo | 46c16d1 | 2014-05-12 11:44:54 +0530 | [diff] [blame] | 625 | data = devm_kzalloc(dev, sizeof(*data), GFP_KERNEL); |
| 626 | if (!data) |
| 627 | return -ENOMEM; |
KyongHo Cho | 2a96536 | 2012-05-12 05:56:09 +0900 | [diff] [blame] | 628 | |
Cho KyongHo | 7222e8d | 2014-05-12 11:44:46 +0530 | [diff] [blame] | 629 | res = platform_get_resource(pdev, IORESOURCE_MEM, 0); |
Cho KyongHo | 46c16d1 | 2014-05-12 11:44:54 +0530 | [diff] [blame] | 630 | data->sfrbase = devm_ioremap_resource(dev, res); |
| 631 | if (IS_ERR(data->sfrbase)) |
| 632 | return PTR_ERR(data->sfrbase); |
Cho KyongHo | 7222e8d | 2014-05-12 11:44:46 +0530 | [diff] [blame] | 633 | |
Cho KyongHo | 46c16d1 | 2014-05-12 11:44:54 +0530 | [diff] [blame] | 634 | irq = platform_get_irq(pdev, 0); |
| 635 | if (irq <= 0) { |
Cho KyongHo | 0bf4e54 | 2014-05-12 11:45:00 +0530 | [diff] [blame] | 636 | dev_err(dev, "Unable to find IRQ resource\n"); |
Cho KyongHo | 46c16d1 | 2014-05-12 11:44:54 +0530 | [diff] [blame] | 637 | return irq; |
Cho KyongHo | 7222e8d | 2014-05-12 11:44:46 +0530 | [diff] [blame] | 638 | } |
| 639 | |
Cho KyongHo | 46c16d1 | 2014-05-12 11:44:54 +0530 | [diff] [blame] | 640 | ret = devm_request_irq(dev, irq, exynos_sysmmu_irq, 0, |
Cho KyongHo | 7222e8d | 2014-05-12 11:44:46 +0530 | [diff] [blame] | 641 | dev_name(dev), data); |
KyongHo Cho | 2a96536 | 2012-05-12 05:56:09 +0900 | [diff] [blame] | 642 | if (ret) { |
Cho KyongHo | 46c16d1 | 2014-05-12 11:44:54 +0530 | [diff] [blame] | 643 | dev_err(dev, "Unabled to register handler of irq %d\n", irq); |
| 644 | return ret; |
KyongHo Cho | 2a96536 | 2012-05-12 05:56:09 +0900 | [diff] [blame] | 645 | } |
| 646 | |
Cho KyongHo | 46c16d1 | 2014-05-12 11:44:54 +0530 | [diff] [blame] | 647 | data->clk = devm_clk_get(dev, "sysmmu"); |
| 648 | if (IS_ERR(data->clk)) { |
| 649 | dev_err(dev, "Failed to get clock!\n"); |
| 650 | return PTR_ERR(data->clk); |
| 651 | } else { |
| 652 | ret = clk_prepare(data->clk); |
| 653 | if (ret) { |
| 654 | dev_err(dev, "Failed to prepare clk\n"); |
| 655 | return ret; |
| 656 | } |
KyongHo Cho | 2a96536 | 2012-05-12 05:56:09 +0900 | [diff] [blame] | 657 | } |
| 658 | |
Cho KyongHo | 7060587 | 2014-05-12 11:44:55 +0530 | [diff] [blame] | 659 | data->clk_master = devm_clk_get(dev, "master"); |
| 660 | if (!IS_ERR(data->clk_master)) { |
| 661 | ret = clk_prepare(data->clk_master); |
| 662 | if (ret) { |
| 663 | clk_unprepare(data->clk); |
| 664 | dev_err(dev, "Failed to prepare master's clk\n"); |
| 665 | return ret; |
| 666 | } |
| 667 | } |
| 668 | |
KyongHo Cho | 2a96536 | 2012-05-12 05:56:09 +0900 | [diff] [blame] | 669 | data->sysmmu = dev; |
Cho KyongHo | 9d4e7a2 | 2014-05-12 11:44:57 +0530 | [diff] [blame] | 670 | spin_lock_init(&data->lock); |
KyongHo Cho | 2a96536 | 2012-05-12 05:56:09 +0900 | [diff] [blame] | 671 | |
Cho KyongHo | 7222e8d | 2014-05-12 11:44:46 +0530 | [diff] [blame] | 672 | platform_set_drvdata(pdev, data); |
| 673 | |
Cho KyongHo | f4723ec | 2014-05-12 11:44:52 +0530 | [diff] [blame] | 674 | pm_runtime_enable(dev); |
KyongHo Cho | 2a96536 | 2012-05-12 05:56:09 +0900 | [diff] [blame] | 675 | |
KyongHo Cho | 2a96536 | 2012-05-12 05:56:09 +0900 | [diff] [blame] | 676 | return 0; |
KyongHo Cho | 2a96536 | 2012-05-12 05:56:09 +0900 | [diff] [blame] | 677 | } |
| 678 | |
Cho KyongHo | 6b21a5d | 2014-05-12 11:45:02 +0530 | [diff] [blame] | 679 | static const struct of_device_id sysmmu_of_match[] __initconst = { |
| 680 | { .compatible = "samsung,exynos-sysmmu", }, |
| 681 | { }, |
| 682 | }; |
| 683 | |
| 684 | static struct platform_driver exynos_sysmmu_driver __refdata = { |
| 685 | .probe = exynos_sysmmu_probe, |
| 686 | .driver = { |
KyongHo Cho | 2a96536 | 2012-05-12 05:56:09 +0900 | [diff] [blame] | 687 | .name = "exynos-sysmmu", |
Cho KyongHo | 6b21a5d | 2014-05-12 11:45:02 +0530 | [diff] [blame] | 688 | .of_match_table = sysmmu_of_match, |
KyongHo Cho | 2a96536 | 2012-05-12 05:56:09 +0900 | [diff] [blame] | 689 | } |
| 690 | }; |
| 691 | |
| 692 | static inline void pgtable_flush(void *vastart, void *vaend) |
| 693 | { |
| 694 | dmac_flush_range(vastart, vaend); |
| 695 | outer_flush_range(virt_to_phys(vastart), |
| 696 | virt_to_phys(vaend)); |
| 697 | } |
| 698 | |
| 699 | static int exynos_iommu_domain_init(struct iommu_domain *domain) |
| 700 | { |
| 701 | struct exynos_iommu_domain *priv; |
Cho KyongHo | 66a7ed8 | 2014-05-12 11:45:04 +0530 | [diff] [blame] | 702 | int i; |
KyongHo Cho | 2a96536 | 2012-05-12 05:56:09 +0900 | [diff] [blame] | 703 | |
| 704 | priv = kzalloc(sizeof(*priv), GFP_KERNEL); |
| 705 | if (!priv) |
| 706 | return -ENOMEM; |
| 707 | |
Cho KyongHo | 66a7ed8 | 2014-05-12 11:45:04 +0530 | [diff] [blame] | 708 | priv->pgtable = (sysmmu_pte_t *)__get_free_pages(GFP_KERNEL, 2); |
KyongHo Cho | 2a96536 | 2012-05-12 05:56:09 +0900 | [diff] [blame] | 709 | if (!priv->pgtable) |
| 710 | goto err_pgtable; |
| 711 | |
Cho KyongHo | 66a7ed8 | 2014-05-12 11:45:04 +0530 | [diff] [blame] | 712 | priv->lv2entcnt = (short *)__get_free_pages(GFP_KERNEL | __GFP_ZERO, 1); |
KyongHo Cho | 2a96536 | 2012-05-12 05:56:09 +0900 | [diff] [blame] | 713 | if (!priv->lv2entcnt) |
| 714 | goto err_counter; |
| 715 | |
Sachin Kamat | f171aba | 2014-08-04 10:06:28 +0530 | [diff] [blame] | 716 | /* Workaround for System MMU v3.3 to prevent caching 1MiB mapping */ |
Cho KyongHo | 66a7ed8 | 2014-05-12 11:45:04 +0530 | [diff] [blame] | 717 | for (i = 0; i < NUM_LV1ENTRIES; i += 8) { |
| 718 | priv->pgtable[i + 0] = ZERO_LV2LINK; |
| 719 | priv->pgtable[i + 1] = ZERO_LV2LINK; |
| 720 | priv->pgtable[i + 2] = ZERO_LV2LINK; |
| 721 | priv->pgtable[i + 3] = ZERO_LV2LINK; |
| 722 | priv->pgtable[i + 4] = ZERO_LV2LINK; |
| 723 | priv->pgtable[i + 5] = ZERO_LV2LINK; |
| 724 | priv->pgtable[i + 6] = ZERO_LV2LINK; |
| 725 | priv->pgtable[i + 7] = ZERO_LV2LINK; |
| 726 | } |
| 727 | |
KyongHo Cho | 2a96536 | 2012-05-12 05:56:09 +0900 | [diff] [blame] | 728 | pgtable_flush(priv->pgtable, priv->pgtable + NUM_LV1ENTRIES); |
| 729 | |
| 730 | spin_lock_init(&priv->lock); |
| 731 | spin_lock_init(&priv->pgtablelock); |
| 732 | INIT_LIST_HEAD(&priv->clients); |
| 733 | |
Sachin Kamat | eb51637 | 2012-08-01 14:35:17 +0530 | [diff] [blame] | 734 | domain->geometry.aperture_start = 0; |
| 735 | domain->geometry.aperture_end = ~0UL; |
| 736 | domain->geometry.force_aperture = true; |
Joerg Roedel | 3177bb7 | 2012-07-11 12:41:10 +0200 | [diff] [blame] | 737 | |
KyongHo Cho | 2a96536 | 2012-05-12 05:56:09 +0900 | [diff] [blame] | 738 | domain->priv = priv; |
| 739 | return 0; |
| 740 | |
| 741 | err_counter: |
| 742 | free_pages((unsigned long)priv->pgtable, 2); |
| 743 | err_pgtable: |
| 744 | kfree(priv); |
| 745 | return -ENOMEM; |
| 746 | } |
| 747 | |
| 748 | static void exynos_iommu_domain_destroy(struct iommu_domain *domain) |
| 749 | { |
| 750 | struct exynos_iommu_domain *priv = domain->priv; |
Cho KyongHo | 6b21a5d | 2014-05-12 11:45:02 +0530 | [diff] [blame] | 751 | struct exynos_iommu_owner *owner; |
KyongHo Cho | 2a96536 | 2012-05-12 05:56:09 +0900 | [diff] [blame] | 752 | unsigned long flags; |
| 753 | int i; |
| 754 | |
| 755 | WARN_ON(!list_empty(&priv->clients)); |
| 756 | |
| 757 | spin_lock_irqsave(&priv->lock, flags); |
| 758 | |
Cho KyongHo | 6b21a5d | 2014-05-12 11:45:02 +0530 | [diff] [blame] | 759 | list_for_each_entry(owner, &priv->clients, client) { |
| 760 | while (!exynos_sysmmu_disable(owner->dev)) |
KyongHo Cho | 2a96536 | 2012-05-12 05:56:09 +0900 | [diff] [blame] | 761 | ; /* until System MMU is actually disabled */ |
| 762 | } |
| 763 | |
Cho KyongHo | 6b21a5d | 2014-05-12 11:45:02 +0530 | [diff] [blame] | 764 | while (!list_empty(&priv->clients)) |
| 765 | list_del_init(priv->clients.next); |
| 766 | |
KyongHo Cho | 2a96536 | 2012-05-12 05:56:09 +0900 | [diff] [blame] | 767 | spin_unlock_irqrestore(&priv->lock, flags); |
| 768 | |
| 769 | for (i = 0; i < NUM_LV1ENTRIES; i++) |
| 770 | if (lv1ent_page(priv->pgtable + i)) |
Cho KyongHo | 734c3c7 | 2014-05-12 11:44:48 +0530 | [diff] [blame] | 771 | kmem_cache_free(lv2table_kmem_cache, |
| 772 | phys_to_virt(lv2table_base(priv->pgtable + i))); |
KyongHo Cho | 2a96536 | 2012-05-12 05:56:09 +0900 | [diff] [blame] | 773 | |
| 774 | free_pages((unsigned long)priv->pgtable, 2); |
| 775 | free_pages((unsigned long)priv->lv2entcnt, 1); |
| 776 | kfree(domain->priv); |
| 777 | domain->priv = NULL; |
| 778 | } |
| 779 | |
| 780 | static int exynos_iommu_attach_device(struct iommu_domain *domain, |
| 781 | struct device *dev) |
| 782 | { |
Cho KyongHo | 6b21a5d | 2014-05-12 11:45:02 +0530 | [diff] [blame] | 783 | struct exynos_iommu_owner *owner = dev->archdata.iommu; |
KyongHo Cho | 2a96536 | 2012-05-12 05:56:09 +0900 | [diff] [blame] | 784 | struct exynos_iommu_domain *priv = domain->priv; |
Cho KyongHo | 7222e8d | 2014-05-12 11:44:46 +0530 | [diff] [blame] | 785 | phys_addr_t pagetable = virt_to_phys(priv->pgtable); |
KyongHo Cho | 2a96536 | 2012-05-12 05:56:09 +0900 | [diff] [blame] | 786 | unsigned long flags; |
| 787 | int ret; |
| 788 | |
KyongHo Cho | 2a96536 | 2012-05-12 05:56:09 +0900 | [diff] [blame] | 789 | spin_lock_irqsave(&priv->lock, flags); |
| 790 | |
Cho KyongHo | 6b21a5d | 2014-05-12 11:45:02 +0530 | [diff] [blame] | 791 | ret = __exynos_sysmmu_enable(dev, pagetable, domain); |
KyongHo Cho | 2a96536 | 2012-05-12 05:56:09 +0900 | [diff] [blame] | 792 | if (ret == 0) { |
Cho KyongHo | 6b21a5d | 2014-05-12 11:45:02 +0530 | [diff] [blame] | 793 | list_add_tail(&owner->client, &priv->clients); |
| 794 | owner->domain = domain; |
KyongHo Cho | 2a96536 | 2012-05-12 05:56:09 +0900 | [diff] [blame] | 795 | } |
| 796 | |
| 797 | spin_unlock_irqrestore(&priv->lock, flags); |
| 798 | |
| 799 | if (ret < 0) { |
Cho KyongHo | 7222e8d | 2014-05-12 11:44:46 +0530 | [diff] [blame] | 800 | dev_err(dev, "%s: Failed to attach IOMMU with pgtable %pa\n", |
| 801 | __func__, &pagetable); |
Cho KyongHo | 7222e8d | 2014-05-12 11:44:46 +0530 | [diff] [blame] | 802 | return ret; |
KyongHo Cho | 2a96536 | 2012-05-12 05:56:09 +0900 | [diff] [blame] | 803 | } |
| 804 | |
Cho KyongHo | 7222e8d | 2014-05-12 11:44:46 +0530 | [diff] [blame] | 805 | dev_dbg(dev, "%s: Attached IOMMU with pgtable %pa %s\n", |
| 806 | __func__, &pagetable, (ret == 0) ? "" : ", again"); |
| 807 | |
KyongHo Cho | 2a96536 | 2012-05-12 05:56:09 +0900 | [diff] [blame] | 808 | return ret; |
| 809 | } |
| 810 | |
| 811 | static void exynos_iommu_detach_device(struct iommu_domain *domain, |
| 812 | struct device *dev) |
| 813 | { |
Cho KyongHo | 6b21a5d | 2014-05-12 11:45:02 +0530 | [diff] [blame] | 814 | struct exynos_iommu_owner *owner; |
KyongHo Cho | 2a96536 | 2012-05-12 05:56:09 +0900 | [diff] [blame] | 815 | struct exynos_iommu_domain *priv = domain->priv; |
Cho KyongHo | 7222e8d | 2014-05-12 11:44:46 +0530 | [diff] [blame] | 816 | phys_addr_t pagetable = virt_to_phys(priv->pgtable); |
KyongHo Cho | 2a96536 | 2012-05-12 05:56:09 +0900 | [diff] [blame] | 817 | unsigned long flags; |
KyongHo Cho | 2a96536 | 2012-05-12 05:56:09 +0900 | [diff] [blame] | 818 | |
| 819 | spin_lock_irqsave(&priv->lock, flags); |
| 820 | |
Cho KyongHo | 6b21a5d | 2014-05-12 11:45:02 +0530 | [diff] [blame] | 821 | list_for_each_entry(owner, &priv->clients, client) { |
| 822 | if (owner == dev->archdata.iommu) { |
| 823 | if (exynos_sysmmu_disable(dev)) { |
| 824 | list_del_init(&owner->client); |
| 825 | owner->domain = NULL; |
| 826 | } |
KyongHo Cho | 2a96536 | 2012-05-12 05:56:09 +0900 | [diff] [blame] | 827 | break; |
| 828 | } |
| 829 | } |
| 830 | |
KyongHo Cho | 2a96536 | 2012-05-12 05:56:09 +0900 | [diff] [blame] | 831 | spin_unlock_irqrestore(&priv->lock, flags); |
| 832 | |
Cho KyongHo | 6b21a5d | 2014-05-12 11:45:02 +0530 | [diff] [blame] | 833 | if (owner == dev->archdata.iommu) |
| 834 | dev_dbg(dev, "%s: Detached IOMMU with pgtable %pa\n", |
| 835 | __func__, &pagetable); |
| 836 | else |
| 837 | dev_err(dev, "%s: No IOMMU is attached\n", __func__); |
KyongHo Cho | 2a96536 | 2012-05-12 05:56:09 +0900 | [diff] [blame] | 838 | } |
| 839 | |
Cho KyongHo | 66a7ed8 | 2014-05-12 11:45:04 +0530 | [diff] [blame] | 840 | static sysmmu_pte_t *alloc_lv2entry(struct exynos_iommu_domain *priv, |
| 841 | sysmmu_pte_t *sent, sysmmu_iova_t iova, short *pgcounter) |
KyongHo Cho | 2a96536 | 2012-05-12 05:56:09 +0900 | [diff] [blame] | 842 | { |
Cho KyongHo | 61128f0 | 2014-05-12 11:44:47 +0530 | [diff] [blame] | 843 | if (lv1ent_section(sent)) { |
Cho KyongHo | d09d78f | 2014-05-12 11:44:58 +0530 | [diff] [blame] | 844 | WARN(1, "Trying mapping on %#08x mapped with 1MiB page", iova); |
Cho KyongHo | 61128f0 | 2014-05-12 11:44:47 +0530 | [diff] [blame] | 845 | return ERR_PTR(-EADDRINUSE); |
| 846 | } |
| 847 | |
KyongHo Cho | 2a96536 | 2012-05-12 05:56:09 +0900 | [diff] [blame] | 848 | if (lv1ent_fault(sent)) { |
Cho KyongHo | d09d78f | 2014-05-12 11:44:58 +0530 | [diff] [blame] | 849 | sysmmu_pte_t *pent; |
Cho KyongHo | 66a7ed8 | 2014-05-12 11:45:04 +0530 | [diff] [blame] | 850 | bool need_flush_flpd_cache = lv1ent_zero(sent); |
KyongHo Cho | 2a96536 | 2012-05-12 05:56:09 +0900 | [diff] [blame] | 851 | |
Cho KyongHo | 734c3c7 | 2014-05-12 11:44:48 +0530 | [diff] [blame] | 852 | pent = kmem_cache_zalloc(lv2table_kmem_cache, GFP_ATOMIC); |
Cho KyongHo | d09d78f | 2014-05-12 11:44:58 +0530 | [diff] [blame] | 853 | BUG_ON((unsigned int)pent & (LV2TABLE_SIZE - 1)); |
KyongHo Cho | 2a96536 | 2012-05-12 05:56:09 +0900 | [diff] [blame] | 854 | if (!pent) |
Cho KyongHo | 61128f0 | 2014-05-12 11:44:47 +0530 | [diff] [blame] | 855 | return ERR_PTR(-ENOMEM); |
KyongHo Cho | 2a96536 | 2012-05-12 05:56:09 +0900 | [diff] [blame] | 856 | |
Cho KyongHo | 7222e8d | 2014-05-12 11:44:46 +0530 | [diff] [blame] | 857 | *sent = mk_lv1ent_page(virt_to_phys(pent)); |
KyongHo Cho | 2a96536 | 2012-05-12 05:56:09 +0900 | [diff] [blame] | 858 | *pgcounter = NUM_LV2ENTRIES; |
| 859 | pgtable_flush(pent, pent + NUM_LV2ENTRIES); |
| 860 | pgtable_flush(sent, sent + 1); |
Cho KyongHo | 66a7ed8 | 2014-05-12 11:45:04 +0530 | [diff] [blame] | 861 | |
| 862 | /* |
Sachin Kamat | f171aba | 2014-08-04 10:06:28 +0530 | [diff] [blame] | 863 | * If pre-fetched SLPD is a faulty SLPD in zero_l2_table, |
| 864 | * FLPD cache may cache the address of zero_l2_table. This |
| 865 | * function replaces the zero_l2_table with new L2 page table |
| 866 | * to write valid mappings. |
Cho KyongHo | 66a7ed8 | 2014-05-12 11:45:04 +0530 | [diff] [blame] | 867 | * Accessing the valid area may cause page fault since FLPD |
Sachin Kamat | f171aba | 2014-08-04 10:06:28 +0530 | [diff] [blame] | 868 | * cache may still cache zero_l2_table for the valid area |
| 869 | * instead of new L2 page table that has the mapping |
| 870 | * information of the valid area. |
Cho KyongHo | 66a7ed8 | 2014-05-12 11:45:04 +0530 | [diff] [blame] | 871 | * Thus any replacement of zero_l2_table with other valid L2 |
| 872 | * page table must involve FLPD cache invalidation for System |
| 873 | * MMU v3.3. |
| 874 | * FLPD cache invalidation is performed with TLB invalidation |
| 875 | * by VPN without blocking. It is safe to invalidate TLB without |
| 876 | * blocking because the target address of TLB invalidation is |
| 877 | * not currently mapped. |
| 878 | */ |
| 879 | if (need_flush_flpd_cache) { |
| 880 | struct exynos_iommu_owner *owner; |
Sachin Kamat | 365409d | 2014-05-22 09:50:56 +0530 | [diff] [blame] | 881 | |
Cho KyongHo | 66a7ed8 | 2014-05-12 11:45:04 +0530 | [diff] [blame] | 882 | spin_lock(&priv->lock); |
| 883 | list_for_each_entry(owner, &priv->clients, client) |
| 884 | sysmmu_tlb_invalidate_flpdcache( |
| 885 | owner->dev, iova); |
| 886 | spin_unlock(&priv->lock); |
| 887 | } |
KyongHo Cho | 2a96536 | 2012-05-12 05:56:09 +0900 | [diff] [blame] | 888 | } |
| 889 | |
| 890 | return page_entry(sent, iova); |
| 891 | } |
| 892 | |
Cho KyongHo | 66a7ed8 | 2014-05-12 11:45:04 +0530 | [diff] [blame] | 893 | static int lv1set_section(struct exynos_iommu_domain *priv, |
| 894 | sysmmu_pte_t *sent, sysmmu_iova_t iova, |
Cho KyongHo | 61128f0 | 2014-05-12 11:44:47 +0530 | [diff] [blame] | 895 | phys_addr_t paddr, short *pgcnt) |
KyongHo Cho | 2a96536 | 2012-05-12 05:56:09 +0900 | [diff] [blame] | 896 | { |
Cho KyongHo | 61128f0 | 2014-05-12 11:44:47 +0530 | [diff] [blame] | 897 | if (lv1ent_section(sent)) { |
Cho KyongHo | d09d78f | 2014-05-12 11:44:58 +0530 | [diff] [blame] | 898 | WARN(1, "Trying mapping on 1MiB@%#08x that is mapped", |
Cho KyongHo | 61128f0 | 2014-05-12 11:44:47 +0530 | [diff] [blame] | 899 | iova); |
KyongHo Cho | 2a96536 | 2012-05-12 05:56:09 +0900 | [diff] [blame] | 900 | return -EADDRINUSE; |
Cho KyongHo | 61128f0 | 2014-05-12 11:44:47 +0530 | [diff] [blame] | 901 | } |
KyongHo Cho | 2a96536 | 2012-05-12 05:56:09 +0900 | [diff] [blame] | 902 | |
| 903 | if (lv1ent_page(sent)) { |
Cho KyongHo | 61128f0 | 2014-05-12 11:44:47 +0530 | [diff] [blame] | 904 | if (*pgcnt != NUM_LV2ENTRIES) { |
Cho KyongHo | d09d78f | 2014-05-12 11:44:58 +0530 | [diff] [blame] | 905 | WARN(1, "Trying mapping on 1MiB@%#08x that is mapped", |
Cho KyongHo | 61128f0 | 2014-05-12 11:44:47 +0530 | [diff] [blame] | 906 | iova); |
KyongHo Cho | 2a96536 | 2012-05-12 05:56:09 +0900 | [diff] [blame] | 907 | return -EADDRINUSE; |
Cho KyongHo | 61128f0 | 2014-05-12 11:44:47 +0530 | [diff] [blame] | 908 | } |
KyongHo Cho | 2a96536 | 2012-05-12 05:56:09 +0900 | [diff] [blame] | 909 | |
Cho KyongHo | 734c3c7 | 2014-05-12 11:44:48 +0530 | [diff] [blame] | 910 | kmem_cache_free(lv2table_kmem_cache, page_entry(sent, 0)); |
KyongHo Cho | 2a96536 | 2012-05-12 05:56:09 +0900 | [diff] [blame] | 911 | *pgcnt = 0; |
| 912 | } |
| 913 | |
| 914 | *sent = mk_lv1ent_sect(paddr); |
| 915 | |
| 916 | pgtable_flush(sent, sent + 1); |
| 917 | |
Cho KyongHo | 66a7ed8 | 2014-05-12 11:45:04 +0530 | [diff] [blame] | 918 | spin_lock(&priv->lock); |
| 919 | if (lv1ent_page_zero(sent)) { |
| 920 | struct exynos_iommu_owner *owner; |
| 921 | /* |
| 922 | * Flushing FLPD cache in System MMU v3.3 that may cache a FLPD |
| 923 | * entry by speculative prefetch of SLPD which has no mapping. |
| 924 | */ |
| 925 | list_for_each_entry(owner, &priv->clients, client) |
| 926 | sysmmu_tlb_invalidate_flpdcache(owner->dev, iova); |
| 927 | } |
| 928 | spin_unlock(&priv->lock); |
| 929 | |
KyongHo Cho | 2a96536 | 2012-05-12 05:56:09 +0900 | [diff] [blame] | 930 | return 0; |
| 931 | } |
| 932 | |
Cho KyongHo | d09d78f | 2014-05-12 11:44:58 +0530 | [diff] [blame] | 933 | static int lv2set_page(sysmmu_pte_t *pent, phys_addr_t paddr, size_t size, |
KyongHo Cho | 2a96536 | 2012-05-12 05:56:09 +0900 | [diff] [blame] | 934 | short *pgcnt) |
| 935 | { |
| 936 | if (size == SPAGE_SIZE) { |
Cho KyongHo | 0bf4e54 | 2014-05-12 11:45:00 +0530 | [diff] [blame] | 937 | if (WARN_ON(!lv2ent_fault(pent))) |
KyongHo Cho | 2a96536 | 2012-05-12 05:56:09 +0900 | [diff] [blame] | 938 | return -EADDRINUSE; |
| 939 | |
| 940 | *pent = mk_lv2ent_spage(paddr); |
| 941 | pgtable_flush(pent, pent + 1); |
| 942 | *pgcnt -= 1; |
| 943 | } else { /* size == LPAGE_SIZE */ |
| 944 | int i; |
Sachin Kamat | 365409d | 2014-05-22 09:50:56 +0530 | [diff] [blame] | 945 | |
KyongHo Cho | 2a96536 | 2012-05-12 05:56:09 +0900 | [diff] [blame] | 946 | for (i = 0; i < SPAGES_PER_LPAGE; i++, pent++) { |
Cho KyongHo | 0bf4e54 | 2014-05-12 11:45:00 +0530 | [diff] [blame] | 947 | if (WARN_ON(!lv2ent_fault(pent))) { |
Cho KyongHo | 61128f0 | 2014-05-12 11:44:47 +0530 | [diff] [blame] | 948 | if (i > 0) |
| 949 | memset(pent - i, 0, sizeof(*pent) * i); |
KyongHo Cho | 2a96536 | 2012-05-12 05:56:09 +0900 | [diff] [blame] | 950 | return -EADDRINUSE; |
| 951 | } |
| 952 | |
| 953 | *pent = mk_lv2ent_lpage(paddr); |
| 954 | } |
| 955 | pgtable_flush(pent - SPAGES_PER_LPAGE, pent); |
| 956 | *pgcnt -= SPAGES_PER_LPAGE; |
| 957 | } |
| 958 | |
| 959 | return 0; |
| 960 | } |
| 961 | |
Cho KyongHo | 66a7ed8 | 2014-05-12 11:45:04 +0530 | [diff] [blame] | 962 | /* |
| 963 | * *CAUTION* to the I/O virtual memory managers that support exynos-iommu: |
| 964 | * |
Sachin Kamat | f171aba | 2014-08-04 10:06:28 +0530 | [diff] [blame] | 965 | * System MMU v3.x has advanced logic to improve address translation |
Cho KyongHo | 66a7ed8 | 2014-05-12 11:45:04 +0530 | [diff] [blame] | 966 | * performance with caching more page table entries by a page table walk. |
Sachin Kamat | f171aba | 2014-08-04 10:06:28 +0530 | [diff] [blame] | 967 | * However, the logic has a bug that while caching faulty page table entries, |
| 968 | * System MMU reports page fault if the cached fault entry is hit even though |
| 969 | * the fault entry is updated to a valid entry after the entry is cached. |
| 970 | * To prevent caching faulty page table entries which may be updated to valid |
| 971 | * entries later, the virtual memory manager should care about the workaround |
| 972 | * for the problem. The following describes the workaround. |
Cho KyongHo | 66a7ed8 | 2014-05-12 11:45:04 +0530 | [diff] [blame] | 973 | * |
| 974 | * Any two consecutive I/O virtual address regions must have a hole of 128KiB |
Sachin Kamat | f171aba | 2014-08-04 10:06:28 +0530 | [diff] [blame] | 975 | * at maximum to prevent misbehavior of System MMU 3.x (workaround for h/w bug). |
Cho KyongHo | 66a7ed8 | 2014-05-12 11:45:04 +0530 | [diff] [blame] | 976 | * |
Sachin Kamat | f171aba | 2014-08-04 10:06:28 +0530 | [diff] [blame] | 977 | * Precisely, any start address of I/O virtual region must be aligned with |
Cho KyongHo | 66a7ed8 | 2014-05-12 11:45:04 +0530 | [diff] [blame] | 978 | * the following sizes for System MMU v3.1 and v3.2. |
| 979 | * System MMU v3.1: 128KiB |
| 980 | * System MMU v3.2: 256KiB |
| 981 | * |
| 982 | * Because System MMU v3.3 caches page table entries more aggressively, it needs |
Sachin Kamat | f171aba | 2014-08-04 10:06:28 +0530 | [diff] [blame] | 983 | * more workarounds. |
| 984 | * - Any two consecutive I/O virtual regions must have a hole of size larger |
| 985 | * than or equal to 128KiB. |
Cho KyongHo | 66a7ed8 | 2014-05-12 11:45:04 +0530 | [diff] [blame] | 986 | * - Start address of an I/O virtual region must be aligned by 128KiB. |
| 987 | */ |
Cho KyongHo | d09d78f | 2014-05-12 11:44:58 +0530 | [diff] [blame] | 988 | static int exynos_iommu_map(struct iommu_domain *domain, unsigned long l_iova, |
KyongHo Cho | 2a96536 | 2012-05-12 05:56:09 +0900 | [diff] [blame] | 989 | phys_addr_t paddr, size_t size, int prot) |
| 990 | { |
| 991 | struct exynos_iommu_domain *priv = domain->priv; |
Cho KyongHo | d09d78f | 2014-05-12 11:44:58 +0530 | [diff] [blame] | 992 | sysmmu_pte_t *entry; |
| 993 | sysmmu_iova_t iova = (sysmmu_iova_t)l_iova; |
KyongHo Cho | 2a96536 | 2012-05-12 05:56:09 +0900 | [diff] [blame] | 994 | unsigned long flags; |
| 995 | int ret = -ENOMEM; |
| 996 | |
| 997 | BUG_ON(priv->pgtable == NULL); |
| 998 | |
| 999 | spin_lock_irqsave(&priv->pgtablelock, flags); |
| 1000 | |
| 1001 | entry = section_entry(priv->pgtable, iova); |
| 1002 | |
| 1003 | if (size == SECT_SIZE) { |
Cho KyongHo | 66a7ed8 | 2014-05-12 11:45:04 +0530 | [diff] [blame] | 1004 | ret = lv1set_section(priv, entry, iova, paddr, |
KyongHo Cho | 2a96536 | 2012-05-12 05:56:09 +0900 | [diff] [blame] | 1005 | &priv->lv2entcnt[lv1ent_offset(iova)]); |
| 1006 | } else { |
Cho KyongHo | d09d78f | 2014-05-12 11:44:58 +0530 | [diff] [blame] | 1007 | sysmmu_pte_t *pent; |
KyongHo Cho | 2a96536 | 2012-05-12 05:56:09 +0900 | [diff] [blame] | 1008 | |
Cho KyongHo | 66a7ed8 | 2014-05-12 11:45:04 +0530 | [diff] [blame] | 1009 | pent = alloc_lv2entry(priv, entry, iova, |
KyongHo Cho | 2a96536 | 2012-05-12 05:56:09 +0900 | [diff] [blame] | 1010 | &priv->lv2entcnt[lv1ent_offset(iova)]); |
| 1011 | |
Cho KyongHo | 61128f0 | 2014-05-12 11:44:47 +0530 | [diff] [blame] | 1012 | if (IS_ERR(pent)) |
| 1013 | ret = PTR_ERR(pent); |
KyongHo Cho | 2a96536 | 2012-05-12 05:56:09 +0900 | [diff] [blame] | 1014 | else |
| 1015 | ret = lv2set_page(pent, paddr, size, |
| 1016 | &priv->lv2entcnt[lv1ent_offset(iova)]); |
| 1017 | } |
| 1018 | |
Cho KyongHo | 61128f0 | 2014-05-12 11:44:47 +0530 | [diff] [blame] | 1019 | if (ret) |
Cho KyongHo | 0bf4e54 | 2014-05-12 11:45:00 +0530 | [diff] [blame] | 1020 | pr_err("%s: Failed(%d) to map %#zx bytes @ %#x\n", |
| 1021 | __func__, ret, size, iova); |
KyongHo Cho | 2a96536 | 2012-05-12 05:56:09 +0900 | [diff] [blame] | 1022 | |
| 1023 | spin_unlock_irqrestore(&priv->pgtablelock, flags); |
| 1024 | |
| 1025 | return ret; |
| 1026 | } |
| 1027 | |
Cho KyongHo | 66a7ed8 | 2014-05-12 11:45:04 +0530 | [diff] [blame] | 1028 | static void exynos_iommu_tlb_invalidate_entry(struct exynos_iommu_domain *priv, |
| 1029 | sysmmu_iova_t iova, size_t size) |
| 1030 | { |
| 1031 | struct exynos_iommu_owner *owner; |
| 1032 | unsigned long flags; |
| 1033 | |
| 1034 | spin_lock_irqsave(&priv->lock, flags); |
| 1035 | |
| 1036 | list_for_each_entry(owner, &priv->clients, client) |
| 1037 | sysmmu_tlb_invalidate_entry(owner->dev, iova, size); |
| 1038 | |
| 1039 | spin_unlock_irqrestore(&priv->lock, flags); |
| 1040 | } |
| 1041 | |
KyongHo Cho | 2a96536 | 2012-05-12 05:56:09 +0900 | [diff] [blame] | 1042 | static size_t exynos_iommu_unmap(struct iommu_domain *domain, |
Cho KyongHo | d09d78f | 2014-05-12 11:44:58 +0530 | [diff] [blame] | 1043 | unsigned long l_iova, size_t size) |
KyongHo Cho | 2a96536 | 2012-05-12 05:56:09 +0900 | [diff] [blame] | 1044 | { |
| 1045 | struct exynos_iommu_domain *priv = domain->priv; |
Cho KyongHo | d09d78f | 2014-05-12 11:44:58 +0530 | [diff] [blame] | 1046 | sysmmu_iova_t iova = (sysmmu_iova_t)l_iova; |
| 1047 | sysmmu_pte_t *ent; |
Cho KyongHo | 61128f0 | 2014-05-12 11:44:47 +0530 | [diff] [blame] | 1048 | size_t err_pgsize; |
Cho KyongHo | d09d78f | 2014-05-12 11:44:58 +0530 | [diff] [blame] | 1049 | unsigned long flags; |
KyongHo Cho | 2a96536 | 2012-05-12 05:56:09 +0900 | [diff] [blame] | 1050 | |
| 1051 | BUG_ON(priv->pgtable == NULL); |
| 1052 | |
| 1053 | spin_lock_irqsave(&priv->pgtablelock, flags); |
| 1054 | |
| 1055 | ent = section_entry(priv->pgtable, iova); |
| 1056 | |
| 1057 | if (lv1ent_section(ent)) { |
Cho KyongHo | 0bf4e54 | 2014-05-12 11:45:00 +0530 | [diff] [blame] | 1058 | if (WARN_ON(size < SECT_SIZE)) { |
Cho KyongHo | 61128f0 | 2014-05-12 11:44:47 +0530 | [diff] [blame] | 1059 | err_pgsize = SECT_SIZE; |
| 1060 | goto err; |
| 1061 | } |
KyongHo Cho | 2a96536 | 2012-05-12 05:56:09 +0900 | [diff] [blame] | 1062 | |
Sachin Kamat | f171aba | 2014-08-04 10:06:28 +0530 | [diff] [blame] | 1063 | /* workaround for h/w bug in System MMU v3.3 */ |
| 1064 | *ent = ZERO_LV2LINK; |
KyongHo Cho | 2a96536 | 2012-05-12 05:56:09 +0900 | [diff] [blame] | 1065 | pgtable_flush(ent, ent + 1); |
| 1066 | size = SECT_SIZE; |
| 1067 | goto done; |
| 1068 | } |
| 1069 | |
| 1070 | if (unlikely(lv1ent_fault(ent))) { |
| 1071 | if (size > SECT_SIZE) |
| 1072 | size = SECT_SIZE; |
| 1073 | goto done; |
| 1074 | } |
| 1075 | |
| 1076 | /* lv1ent_page(sent) == true here */ |
| 1077 | |
| 1078 | ent = page_entry(ent, iova); |
| 1079 | |
| 1080 | if (unlikely(lv2ent_fault(ent))) { |
| 1081 | size = SPAGE_SIZE; |
| 1082 | goto done; |
| 1083 | } |
| 1084 | |
| 1085 | if (lv2ent_small(ent)) { |
| 1086 | *ent = 0; |
| 1087 | size = SPAGE_SIZE; |
Cho KyongHo | 6cb47ed | 2014-05-12 11:44:51 +0530 | [diff] [blame] | 1088 | pgtable_flush(ent, ent + 1); |
KyongHo Cho | 2a96536 | 2012-05-12 05:56:09 +0900 | [diff] [blame] | 1089 | priv->lv2entcnt[lv1ent_offset(iova)] += 1; |
| 1090 | goto done; |
| 1091 | } |
| 1092 | |
| 1093 | /* lv1ent_large(ent) == true here */ |
Cho KyongHo | 0bf4e54 | 2014-05-12 11:45:00 +0530 | [diff] [blame] | 1094 | if (WARN_ON(size < LPAGE_SIZE)) { |
Cho KyongHo | 61128f0 | 2014-05-12 11:44:47 +0530 | [diff] [blame] | 1095 | err_pgsize = LPAGE_SIZE; |
| 1096 | goto err; |
| 1097 | } |
KyongHo Cho | 2a96536 | 2012-05-12 05:56:09 +0900 | [diff] [blame] | 1098 | |
| 1099 | memset(ent, 0, sizeof(*ent) * SPAGES_PER_LPAGE); |
Cho KyongHo | 6cb47ed | 2014-05-12 11:44:51 +0530 | [diff] [blame] | 1100 | pgtable_flush(ent, ent + SPAGES_PER_LPAGE); |
KyongHo Cho | 2a96536 | 2012-05-12 05:56:09 +0900 | [diff] [blame] | 1101 | |
| 1102 | size = LPAGE_SIZE; |
| 1103 | priv->lv2entcnt[lv1ent_offset(iova)] += SPAGES_PER_LPAGE; |
| 1104 | done: |
| 1105 | spin_unlock_irqrestore(&priv->pgtablelock, flags); |
| 1106 | |
Cho KyongHo | 66a7ed8 | 2014-05-12 11:45:04 +0530 | [diff] [blame] | 1107 | exynos_iommu_tlb_invalidate_entry(priv, iova, size); |
KyongHo Cho | 2a96536 | 2012-05-12 05:56:09 +0900 | [diff] [blame] | 1108 | |
KyongHo Cho | 2a96536 | 2012-05-12 05:56:09 +0900 | [diff] [blame] | 1109 | return size; |
Cho KyongHo | 61128f0 | 2014-05-12 11:44:47 +0530 | [diff] [blame] | 1110 | err: |
| 1111 | spin_unlock_irqrestore(&priv->pgtablelock, flags); |
| 1112 | |
Cho KyongHo | 0bf4e54 | 2014-05-12 11:45:00 +0530 | [diff] [blame] | 1113 | pr_err("%s: Failed: size(%#zx) @ %#x is smaller than page size %#zx\n", |
| 1114 | __func__, size, iova, err_pgsize); |
Cho KyongHo | 61128f0 | 2014-05-12 11:44:47 +0530 | [diff] [blame] | 1115 | |
| 1116 | return 0; |
KyongHo Cho | 2a96536 | 2012-05-12 05:56:09 +0900 | [diff] [blame] | 1117 | } |
| 1118 | |
| 1119 | static phys_addr_t exynos_iommu_iova_to_phys(struct iommu_domain *domain, |
Varun Sethi | bb5547a | 2013-03-29 01:23:58 +0530 | [diff] [blame] | 1120 | dma_addr_t iova) |
KyongHo Cho | 2a96536 | 2012-05-12 05:56:09 +0900 | [diff] [blame] | 1121 | { |
| 1122 | struct exynos_iommu_domain *priv = domain->priv; |
Cho KyongHo | d09d78f | 2014-05-12 11:44:58 +0530 | [diff] [blame] | 1123 | sysmmu_pte_t *entry; |
KyongHo Cho | 2a96536 | 2012-05-12 05:56:09 +0900 | [diff] [blame] | 1124 | unsigned long flags; |
| 1125 | phys_addr_t phys = 0; |
| 1126 | |
| 1127 | spin_lock_irqsave(&priv->pgtablelock, flags); |
| 1128 | |
| 1129 | entry = section_entry(priv->pgtable, iova); |
| 1130 | |
| 1131 | if (lv1ent_section(entry)) { |
| 1132 | phys = section_phys(entry) + section_offs(iova); |
| 1133 | } else if (lv1ent_page(entry)) { |
| 1134 | entry = page_entry(entry, iova); |
| 1135 | |
| 1136 | if (lv2ent_large(entry)) |
| 1137 | phys = lpage_phys(entry) + lpage_offs(iova); |
| 1138 | else if (lv2ent_small(entry)) |
| 1139 | phys = spage_phys(entry) + spage_offs(iova); |
| 1140 | } |
| 1141 | |
| 1142 | spin_unlock_irqrestore(&priv->pgtablelock, flags); |
| 1143 | |
| 1144 | return phys; |
| 1145 | } |
| 1146 | |
Antonios Motakis | bf4a1c9 | 2014-05-12 11:44:59 +0530 | [diff] [blame] | 1147 | static int exynos_iommu_add_device(struct device *dev) |
| 1148 | { |
| 1149 | struct iommu_group *group; |
| 1150 | int ret; |
| 1151 | |
| 1152 | group = iommu_group_get(dev); |
| 1153 | |
| 1154 | if (!group) { |
| 1155 | group = iommu_group_alloc(); |
| 1156 | if (IS_ERR(group)) { |
| 1157 | dev_err(dev, "Failed to allocate IOMMU group\n"); |
| 1158 | return PTR_ERR(group); |
| 1159 | } |
| 1160 | } |
| 1161 | |
| 1162 | ret = iommu_group_add_device(group, dev); |
| 1163 | iommu_group_put(group); |
| 1164 | |
| 1165 | return ret; |
| 1166 | } |
| 1167 | |
| 1168 | static void exynos_iommu_remove_device(struct device *dev) |
| 1169 | { |
| 1170 | iommu_group_remove_device(dev); |
| 1171 | } |
| 1172 | |
Thierry Reding | b22f643 | 2014-06-27 09:03:12 +0200 | [diff] [blame] | 1173 | static const struct iommu_ops exynos_iommu_ops = { |
Bjorn Helgaas | ba5fa6f | 2014-05-08 14:49:14 -0600 | [diff] [blame] | 1174 | .domain_init = exynos_iommu_domain_init, |
| 1175 | .domain_destroy = exynos_iommu_domain_destroy, |
| 1176 | .attach_dev = exynos_iommu_attach_device, |
| 1177 | .detach_dev = exynos_iommu_detach_device, |
| 1178 | .map = exynos_iommu_map, |
| 1179 | .unmap = exynos_iommu_unmap, |
Olav Haugan | 315786e | 2014-10-25 09:55:16 -0700 | [diff] [blame] | 1180 | .map_sg = default_iommu_map_sg, |
Bjorn Helgaas | ba5fa6f | 2014-05-08 14:49:14 -0600 | [diff] [blame] | 1181 | .iova_to_phys = exynos_iommu_iova_to_phys, |
| 1182 | .add_device = exynos_iommu_add_device, |
| 1183 | .remove_device = exynos_iommu_remove_device, |
KyongHo Cho | 2a96536 | 2012-05-12 05:56:09 +0900 | [diff] [blame] | 1184 | .pgsize_bitmap = SECT_SIZE | LPAGE_SIZE | SPAGE_SIZE, |
| 1185 | }; |
| 1186 | |
| 1187 | static int __init exynos_iommu_init(void) |
| 1188 | { |
| 1189 | int ret; |
| 1190 | |
Cho KyongHo | 734c3c7 | 2014-05-12 11:44:48 +0530 | [diff] [blame] | 1191 | lv2table_kmem_cache = kmem_cache_create("exynos-iommu-lv2table", |
| 1192 | LV2TABLE_SIZE, LV2TABLE_SIZE, 0, NULL); |
| 1193 | if (!lv2table_kmem_cache) { |
| 1194 | pr_err("%s: Failed to create kmem cache\n", __func__); |
| 1195 | return -ENOMEM; |
| 1196 | } |
| 1197 | |
KyongHo Cho | 2a96536 | 2012-05-12 05:56:09 +0900 | [diff] [blame] | 1198 | ret = platform_driver_register(&exynos_sysmmu_driver); |
Cho KyongHo | 734c3c7 | 2014-05-12 11:44:48 +0530 | [diff] [blame] | 1199 | if (ret) { |
| 1200 | pr_err("%s: Failed to register driver\n", __func__); |
| 1201 | goto err_reg_driver; |
| 1202 | } |
KyongHo Cho | 2a96536 | 2012-05-12 05:56:09 +0900 | [diff] [blame] | 1203 | |
Cho KyongHo | 66a7ed8 | 2014-05-12 11:45:04 +0530 | [diff] [blame] | 1204 | zero_lv2_table = kmem_cache_zalloc(lv2table_kmem_cache, GFP_KERNEL); |
| 1205 | if (zero_lv2_table == NULL) { |
| 1206 | pr_err("%s: Failed to allocate zero level2 page table\n", |
| 1207 | __func__); |
| 1208 | ret = -ENOMEM; |
| 1209 | goto err_zero_lv2; |
| 1210 | } |
| 1211 | |
Cho KyongHo | 734c3c7 | 2014-05-12 11:44:48 +0530 | [diff] [blame] | 1212 | ret = bus_set_iommu(&platform_bus_type, &exynos_iommu_ops); |
| 1213 | if (ret) { |
| 1214 | pr_err("%s: Failed to register exynos-iommu driver.\n", |
| 1215 | __func__); |
| 1216 | goto err_set_iommu; |
| 1217 | } |
KyongHo Cho | 2a96536 | 2012-05-12 05:56:09 +0900 | [diff] [blame] | 1218 | |
Cho KyongHo | 734c3c7 | 2014-05-12 11:44:48 +0530 | [diff] [blame] | 1219 | return 0; |
| 1220 | err_set_iommu: |
Cho KyongHo | 66a7ed8 | 2014-05-12 11:45:04 +0530 | [diff] [blame] | 1221 | kmem_cache_free(lv2table_kmem_cache, zero_lv2_table); |
| 1222 | err_zero_lv2: |
Cho KyongHo | 734c3c7 | 2014-05-12 11:44:48 +0530 | [diff] [blame] | 1223 | platform_driver_unregister(&exynos_sysmmu_driver); |
| 1224 | err_reg_driver: |
| 1225 | kmem_cache_destroy(lv2table_kmem_cache); |
KyongHo Cho | 2a96536 | 2012-05-12 05:56:09 +0900 | [diff] [blame] | 1226 | return ret; |
| 1227 | } |
| 1228 | subsys_initcall(exynos_iommu_init); |