hc
2024-02-20 102a0743326a03cd1a1202ceda21e175b7d3575c
kernel/drivers/iommu/exynos-iommu.c
....@@ -1,10 +1,7 @@
1
+// SPDX-License-Identifier: GPL-2.0-only
12 /*
23 * Copyright (c) 2011,2016 Samsung Electronics Co., Ltd.
34 * http://www.samsung.com
4
- *
5
- * This program is free software; you can redistribute it and/or modify
6
- * it under the terms of the GNU General Public License version 2 as
7
- * published by the Free Software Foundation.
85 */
96
107 #ifdef CONFIG_EXYNOS_IOMMU_DEBUG
....@@ -176,7 +173,7 @@
176173 #define REG_V5_FAULT_AR_VA 0x070
177174 #define REG_V5_FAULT_AW_VA 0x080
178175
179
-#define has_sysmmu(dev) (dev->archdata.iommu != NULL)
176
+#define has_sysmmu(dev) (dev_iommu_priv_get(dev) != NULL)
180177
181178 static struct device *dma_dev;
182179 static struct kmem_cache *lv2table_kmem_cache;
....@@ -229,7 +226,7 @@
229226 };
230227
231228 /*
232
- * This structure is attached to dev.archdata.iommu of the master device
229
+ * This structure is attached to dev->iommu->priv of the master device
233230 * on device add, contains a list of SYSMMU controllers defined by device tree,
234231 * which are bound to given master device. It is usually referenced by 'owner'
235232 * pointer.
....@@ -569,7 +566,7 @@
569566
570567 static const struct iommu_ops exynos_iommu_ops;
571568
572
-static int __init exynos_sysmmu_probe(struct platform_device *pdev)
569
+static int exynos_sysmmu_probe(struct platform_device *pdev)
573570 {
574571 int irq, ret;
575572 struct device *dev = &pdev->dev;
....@@ -586,10 +583,8 @@
586583 return PTR_ERR(data->sfrbase);
587584
588585 irq = platform_get_irq(pdev, 0);
589
- if (irq <= 0) {
590
- dev_err(dev, "Unable to find IRQ resource\n");
586
+ if (irq <= 0)
591587 return irq;
592
- }
593588
594589 ret = devm_request_irq(dev, irq, exynos_sysmmu_irq, 0,
595590 dev_name(dev), data);
....@@ -640,7 +635,7 @@
640635
641636 ret = iommu_device_register(&data->iommu);
642637 if (ret)
643
- return ret;
638
+ goto err_iommu_register;
644639
645640 platform_set_drvdata(pdev, data);
646641
....@@ -667,6 +662,10 @@
667662 pm_runtime_enable(dev);
668663
669664 return 0;
665
+
666
+err_iommu_register:
667
+ iommu_device_sysfs_remove(&data->iommu);
668
+ return ret;
670669 }
671670
672671 static int __maybe_unused exynos_sysmmu_suspend(struct device *dev)
....@@ -675,7 +674,7 @@
675674 struct device *master = data->master;
676675
677676 if (master) {
678
- struct exynos_iommu_owner *owner = master->archdata.iommu;
677
+ struct exynos_iommu_owner *owner = dev_iommu_priv_get(master);
679678
680679 mutex_lock(&owner->rpm_lock);
681680 if (data->domain) {
....@@ -693,7 +692,7 @@
693692 struct device *master = data->master;
694693
695694 if (master) {
696
- struct exynos_iommu_owner *owner = master->archdata.iommu;
695
+ struct exynos_iommu_owner *owner = dev_iommu_priv_get(master);
697696
698697 mutex_lock(&owner->rpm_lock);
699698 if (data->domain) {
....@@ -726,7 +725,7 @@
726725 }
727726 };
728727
729
-static inline void update_pte(sysmmu_pte_t *ent, sysmmu_pte_t val)
728
+static inline void exynos_iommu_set_pte(sysmmu_pte_t *ent, sysmmu_pte_t val)
730729 {
731730 dma_sync_single_for_cpu(dma_dev, virt_to_phys(ent), sizeof(*ent),
732731 DMA_TO_DEVICE);
....@@ -842,8 +841,8 @@
842841 static void exynos_iommu_detach_device(struct iommu_domain *iommu_domain,
843842 struct device *dev)
844843 {
845
- struct exynos_iommu_owner *owner = dev->archdata.iommu;
846844 struct exynos_iommu_domain *domain = to_exynos_domain(iommu_domain);
845
+ struct exynos_iommu_owner *owner = dev_iommu_priv_get(dev);
847846 phys_addr_t pagetable = virt_to_phys(domain->pgtable);
848847 struct sysmmu_drvdata *data, *next;
849848 unsigned long flags;
....@@ -880,8 +879,8 @@
880879 static int exynos_iommu_attach_device(struct iommu_domain *iommu_domain,
881880 struct device *dev)
882881 {
883
- struct exynos_iommu_owner *owner = dev->archdata.iommu;
884882 struct exynos_iommu_domain *domain = to_exynos_domain(iommu_domain);
883
+ struct exynos_iommu_owner *owner = dev_iommu_priv_get(dev);
885884 struct sysmmu_drvdata *data;
886885 phys_addr_t pagetable = virt_to_phys(domain->pgtable);
887886 unsigned long flags;
....@@ -938,7 +937,7 @@
938937 if (!pent)
939938 return ERR_PTR(-ENOMEM);
940939
941
- update_pte(sent, mk_lv1ent_page(virt_to_phys(pent)));
940
+ exynos_iommu_set_pte(sent, mk_lv1ent_page(virt_to_phys(pent)));
942941 kmemleak_ignore(pent);
943942 *pgcounter = NUM_LV2ENTRIES;
944943 handle = dma_map_single(dma_dev, pent, LV2TABLE_SIZE,
....@@ -999,7 +998,7 @@
999998 *pgcnt = 0;
1000999 }
10011000
1002
- update_pte(sent, mk_lv1ent_sect(paddr, prot));
1001
+ exynos_iommu_set_pte(sent, mk_lv1ent_sect(paddr, prot));
10031002
10041003 spin_lock(&domain->lock);
10051004 if (lv1ent_page_zero(sent)) {
....@@ -1023,7 +1022,7 @@
10231022 if (WARN_ON(!lv2ent_fault(pent)))
10241023 return -EADDRINUSE;
10251024
1026
- update_pte(pent, mk_lv2ent_spage(paddr, prot));
1025
+ exynos_iommu_set_pte(pent, mk_lv2ent_spage(paddr, prot));
10271026 *pgcnt -= 1;
10281027 } else { /* size == LPAGE_SIZE */
10291028 int i;
....@@ -1078,7 +1077,7 @@
10781077 */
10791078 static int exynos_iommu_map(struct iommu_domain *iommu_domain,
10801079 unsigned long l_iova, phys_addr_t paddr, size_t size,
1081
- int prot)
1080
+ int prot, gfp_t gfp)
10821081 {
10831082 struct exynos_iommu_domain *domain = to_exynos_domain(iommu_domain);
10841083 sysmmu_pte_t *entry;
....@@ -1133,7 +1132,8 @@
11331132 }
11341133
11351134 static size_t exynos_iommu_unmap(struct iommu_domain *iommu_domain,
1136
- unsigned long l_iova, size_t size)
1135
+ unsigned long l_iova, size_t size,
1136
+ struct iommu_iotlb_gather *gather)
11371137 {
11381138 struct exynos_iommu_domain *domain = to_exynos_domain(iommu_domain);
11391139 sysmmu_iova_t iova = (sysmmu_iova_t)l_iova;
....@@ -1154,7 +1154,7 @@
11541154 }
11551155
11561156 /* workaround for h/w bug in System MMU v3.3 */
1157
- update_pte(ent, ZERO_LV2LINK);
1157
+ exynos_iommu_set_pte(ent, ZERO_LV2LINK);
11581158 size = SECT_SIZE;
11591159 goto done;
11601160 }
....@@ -1175,7 +1175,7 @@
11751175 }
11761176
11771177 if (lv2ent_small(ent)) {
1178
- update_pte(ent, 0);
1178
+ exynos_iommu_set_pte(ent, 0);
11791179 size = SPAGE_SIZE;
11801180 domain->lv2entcnt[lv1ent_offset(iova)] += 1;
11811181 goto done;
....@@ -1239,19 +1239,13 @@
12391239 return phys;
12401240 }
12411241
1242
-static int exynos_iommu_add_device(struct device *dev)
1242
+static struct iommu_device *exynos_iommu_probe_device(struct device *dev)
12431243 {
1244
- struct exynos_iommu_owner *owner = dev->archdata.iommu;
1244
+ struct exynos_iommu_owner *owner = dev_iommu_priv_get(dev);
12451245 struct sysmmu_drvdata *data;
1246
- struct iommu_group *group;
12471246
12481247 if (!has_sysmmu(dev))
1249
- return -ENODEV;
1250
-
1251
- group = iommu_group_get_for_dev(dev);
1252
-
1253
- if (IS_ERR(group))
1254
- return PTR_ERR(group);
1248
+ return ERR_PTR(-ENODEV);
12551249
12561250 list_for_each_entry(data, &owner->controllers, owner_node) {
12571251 /*
....@@ -1263,14 +1257,17 @@
12631257 DL_FLAG_STATELESS |
12641258 DL_FLAG_PM_RUNTIME);
12651259 }
1266
- iommu_group_put(group);
12671260
1268
- return 0;
1261
+ /* There is always at least one entry, see exynos_iommu_of_xlate() */
1262
+ data = list_first_entry(&owner->controllers,
1263
+ struct sysmmu_drvdata, owner_node);
1264
+
1265
+ return &data->iommu;
12691266 }
12701267
1271
-static void exynos_iommu_remove_device(struct device *dev)
1268
+static void exynos_iommu_release_device(struct device *dev)
12721269 {
1273
- struct exynos_iommu_owner *owner = dev->archdata.iommu;
1270
+ struct exynos_iommu_owner *owner = dev_iommu_priv_get(dev);
12741271 struct sysmmu_drvdata *data;
12751272
12761273 if (!has_sysmmu(dev))
....@@ -1286,7 +1283,6 @@
12861283 iommu_group_put(group);
12871284 }
12881285 }
1289
- iommu_group_remove_device(dev);
12901286
12911287 list_for_each_entry(data, &owner->controllers, owner_node)
12921288 device_link_del(data->link);
....@@ -1295,8 +1291,8 @@
12951291 static int exynos_iommu_of_xlate(struct device *dev,
12961292 struct of_phandle_args *spec)
12971293 {
1298
- struct exynos_iommu_owner *owner = dev->archdata.iommu;
12991294 struct platform_device *sysmmu = of_find_device_by_node(spec->np);
1295
+ struct exynos_iommu_owner *owner = dev_iommu_priv_get(dev);
13001296 struct sysmmu_drvdata *data, *entry;
13011297
13021298 if (!sysmmu)
....@@ -1317,7 +1313,7 @@
13171313
13181314 INIT_LIST_HEAD(&owner->controllers);
13191315 mutex_init(&owner->rpm_lock);
1320
- dev->archdata.iommu = owner;
1316
+ dev_iommu_priv_set(dev, owner);
13211317 }
13221318
13231319 list_for_each_entry(entry, &owner->controllers, owner_node)
....@@ -1339,8 +1335,8 @@
13391335 .unmap = exynos_iommu_unmap,
13401336 .iova_to_phys = exynos_iommu_iova_to_phys,
13411337 .device_group = generic_device_group,
1342
- .add_device = exynos_iommu_add_device,
1343
- .remove_device = exynos_iommu_remove_device,
1338
+ .probe_device = exynos_iommu_probe_device,
1339
+ .release_device = exynos_iommu_release_device,
13441340 .pgsize_bitmap = SECT_SIZE | LPAGE_SIZE | SPAGE_SIZE,
13451341 .of_xlate = exynos_iommu_of_xlate,
13461342 };