Skip to content

Commit 1ca55d5

Browse files
Oleksandr Tyshchenkojgross1
authored andcommitted
xen/grant-dma-iommu: Introduce stub IOMMU driver
In order to reuse generic IOMMU device tree bindings by Xen grant DMA-mapping layer we need to add this stub driver from a fw_devlink perspective (grant-dma-ops cannot be converted into the proper IOMMU driver). Otherwise, just reusing IOMMU bindings (without having a corresponding driver) leads to the deferred probe timeout afterwards, because the IOMMU device never becomes available. This stub driver does nothing except registering empty iommu_ops, the upper layer "of_iommu" will treat this as NO_IOMMU condition and won't return -EPROBE_DEFER. As this driver is quite different from the most hardware IOMMU implementations and only needed in Xen guests, place it in drivers/xen directory. The subsequent commit will make use of it. Signed-off-by: Oleksandr Tyshchenko <oleksandr_tyshchenko@epam.com> Reviewed-by: Stefano Stabellini <sstabellini@kernel.org> Link: https://lore.kernel.org/r/1654197833-25362-7-git-send-email-olekstysh@gmail.com Signed-off-by: Juergen Gross <jgross@suse.com>
1 parent add413a commit 1ca55d5

3 files changed

Lines changed: 83 additions & 0 deletions

File tree

drivers/xen/Kconfig

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -335,6 +335,10 @@ config XEN_UNPOPULATED_ALLOC
335335
having to balloon out RAM regions in order to obtain physical memory
336336
space to create such mappings.
337337

338+
config XEN_GRANT_DMA_IOMMU
339+
bool
340+
select IOMMU_API
341+
338342
config XEN_GRANT_DMA_OPS
339343
bool
340344
select DMA_OPS

drivers/xen/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,3 +40,4 @@ xen-privcmd-y := privcmd.o privcmd-buf.o
4040
obj-$(CONFIG_XEN_FRONT_PGDIR_SHBUF) += xen-front-pgdir-shbuf.o
4141
obj-$(CONFIG_XEN_UNPOPULATED_ALLOC) += unpopulated-alloc.o
4242
obj-$(CONFIG_XEN_GRANT_DMA_OPS) += grant-dma-ops.o
43+
obj-$(CONFIG_XEN_GRANT_DMA_IOMMU) += grant-dma-iommu.o

drivers/xen/grant-dma-iommu.c

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
// SPDX-License-Identifier: GPL-2.0
2+
/*
3+
* Stub IOMMU driver which does nothing.
4+
* The main purpose of it being present is to reuse generic IOMMU device tree
5+
* bindings by Xen grant DMA-mapping layer.
6+
*
7+
* Copyright (C) 2022 EPAM Systems Inc.
8+
*/
9+
10+
#include <linux/iommu.h>
11+
#include <linux/of.h>
12+
#include <linux/platform_device.h>
13+
14+
struct grant_dma_iommu_device {
15+
struct device *dev;
16+
struct iommu_device iommu;
17+
};
18+
19+
/* Nothing is really needed here */
20+
static const struct iommu_ops grant_dma_iommu_ops;
21+
22+
static const struct of_device_id grant_dma_iommu_of_match[] = {
23+
{ .compatible = "xen,grant-dma" },
24+
{ },
25+
};
26+
27+
static int grant_dma_iommu_probe(struct platform_device *pdev)
28+
{
29+
struct grant_dma_iommu_device *mmu;
30+
int ret;
31+
32+
mmu = devm_kzalloc(&pdev->dev, sizeof(*mmu), GFP_KERNEL);
33+
if (!mmu)
34+
return -ENOMEM;
35+
36+
mmu->dev = &pdev->dev;
37+
38+
ret = iommu_device_register(&mmu->iommu, &grant_dma_iommu_ops, &pdev->dev);
39+
if (ret)
40+
return ret;
41+
42+
platform_set_drvdata(pdev, mmu);
43+
44+
return 0;
45+
}
46+
47+
static int grant_dma_iommu_remove(struct platform_device *pdev)
48+
{
49+
struct grant_dma_iommu_device *mmu = platform_get_drvdata(pdev);
50+
51+
platform_set_drvdata(pdev, NULL);
52+
iommu_device_unregister(&mmu->iommu);
53+
54+
return 0;
55+
}
56+
57+
static struct platform_driver grant_dma_iommu_driver = {
58+
.driver = {
59+
.name = "grant-dma-iommu",
60+
.of_match_table = grant_dma_iommu_of_match,
61+
},
62+
.probe = grant_dma_iommu_probe,
63+
.remove = grant_dma_iommu_remove,
64+
};
65+
66+
static int __init grant_dma_iommu_init(void)
67+
{
68+
struct device_node *iommu_np;
69+
70+
iommu_np = of_find_matching_node(NULL, grant_dma_iommu_of_match);
71+
if (!iommu_np)
72+
return 0;
73+
74+
of_node_put(iommu_np);
75+
76+
return platform_driver_register(&grant_dma_iommu_driver);
77+
}
78+
subsys_initcall(grant_dma_iommu_init);

0 commit comments

Comments
 (0)