Skip to content

Commit 42df43b

Browse files
committed
iommu/msm: Make use of iommu_device_register interface
Register the MSM IOMMUs to the iommu core and add sysfs entries for that driver. Signed-off-by: Joerg Roedel <[email protected]>
1 parent 9648cbc commit 42df43b

File tree

2 files changed

+76
-0
lines changed

2 files changed

+76
-0
lines changed

drivers/iommu/msm_iommu.c

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -371,6 +371,58 @@ static int msm_iommu_domain_config(struct msm_priv *priv)
371371
return 0;
372372
}
373373

374+
/* Must be called under msm_iommu_lock */
375+
static struct msm_iommu_dev *find_iommu_for_dev(struct device *dev)
376+
{
377+
struct msm_iommu_dev *iommu, *ret = NULL;
378+
struct msm_iommu_ctx_dev *master;
379+
380+
list_for_each_entry(iommu, &qcom_iommu_devices, dev_node) {
381+
master = list_first_entry(&iommu->ctx_list,
382+
struct msm_iommu_ctx_dev,
383+
list);
384+
if (master->of_node == dev->of_node) {
385+
ret = iommu;
386+
break;
387+
}
388+
}
389+
390+
return ret;
391+
}
392+
393+
static int msm_iommu_add_device(struct device *dev)
394+
{
395+
struct msm_iommu_dev *iommu;
396+
unsigned long flags;
397+
int ret = 0;
398+
399+
spin_lock_irqsave(&msm_iommu_lock, flags);
400+
401+
iommu = find_iommu_for_dev(dev);
402+
if (iommu)
403+
iommu_device_link(&iommu->iommu, dev);
404+
else
405+
ret = -ENODEV;
406+
407+
spin_unlock_irqrestore(&msm_iommu_lock, flags);
408+
409+
return ret;
410+
}
411+
412+
static void msm_iommu_remove_device(struct device *dev)
413+
{
414+
struct msm_iommu_dev *iommu;
415+
unsigned long flags;
416+
417+
spin_lock_irqsave(&msm_iommu_lock, flags);
418+
419+
iommu = find_iommu_for_dev(dev);
420+
if (iommu)
421+
iommu_device_unlink(&iommu->iommu, dev);
422+
423+
spin_unlock_irqrestore(&msm_iommu_lock, flags);
424+
}
425+
374426
static int msm_iommu_attach_dev(struct iommu_domain *domain, struct device *dev)
375427
{
376428
int ret = 0;
@@ -646,13 +698,16 @@ static struct iommu_ops msm_iommu_ops = {
646698
.unmap = msm_iommu_unmap,
647699
.map_sg = default_iommu_map_sg,
648700
.iova_to_phys = msm_iommu_iova_to_phys,
701+
.add_device = msm_iommu_add_device,
702+
.remove_device = msm_iommu_remove_device,
649703
.pgsize_bitmap = MSM_IOMMU_PGSIZES,
650704
.of_xlate = qcom_iommu_of_xlate,
651705
};
652706

653707
static int msm_iommu_probe(struct platform_device *pdev)
654708
{
655709
struct resource *r;
710+
resource_size_t ioaddr;
656711
struct msm_iommu_dev *iommu;
657712
int ret, par, val;
658713

@@ -696,6 +751,7 @@ static int msm_iommu_probe(struct platform_device *pdev)
696751
ret = PTR_ERR(iommu->base);
697752
goto fail;
698753
}
754+
ioaddr = r->start;
699755

700756
iommu->irq = platform_get_irq(pdev, 0);
701757
if (iommu->irq < 0) {
@@ -737,6 +793,23 @@ static int msm_iommu_probe(struct platform_device *pdev)
737793
}
738794

739795
list_add(&iommu->dev_node, &qcom_iommu_devices);
796+
797+
ret = iommu_device_sysfs_add(&iommu->iommu, iommu->dev, NULL,
798+
"msm-smmu.%pa", &ioaddr);
799+
if (ret) {
800+
pr_err("Could not add msm-smmu at %pa to sysfs\n", &ioaddr);
801+
goto fail;
802+
}
803+
804+
iommu_device_set_ops(&iommu->iommu, &msm_iommu_ops);
805+
iommu_device_set_fwnode(&iommu->iommu, &pdev->dev.of_node->fwnode);
806+
807+
ret = iommu_device_register(&iommu->iommu);
808+
if (ret) {
809+
pr_err("Could not register msm-smmu at %pa\n", &ioaddr);
810+
goto fail;
811+
}
812+
740813
of_iommu_set_ops(pdev->dev.of_node, &msm_iommu_ops);
741814

742815
pr_info("device mapped at %p, irq %d with %d ctx banks\n",

drivers/iommu/msm_iommu.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
#define MSM_IOMMU_H
2020

2121
#include <linux/interrupt.h>
22+
#include <linux/iommu.h>
2223
#include <linux/clk.h>
2324

2425
/* Sharability attributes of MSM IOMMU mappings */
@@ -68,6 +69,8 @@ struct msm_iommu_dev {
6869
struct list_head dom_node;
6970
struct list_head ctx_list;
7071
DECLARE_BITMAP(context_map, IOMMU_MAX_CBS);
72+
73+
struct iommu_device iommu;
7174
};
7275

7376
/**

0 commit comments

Comments
 (0)