Commit 1ca55d50 authored by Oleksandr Tyshchenko's avatar Oleksandr Tyshchenko Committed by Juergen Gross

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: default avatarOleksandr Tyshchenko <oleksandr_tyshchenko@epam.com>
Reviewed-by: default avatarStefano Stabellini <sstabellini@kernel.org>
Link: https://lore.kernel.org/r/1654197833-25362-7-git-send-email-olekstysh@gmail.comSigned-off-by: default avatarJuergen Gross <jgross@suse.com>
parent add413a1
...@@ -335,6 +335,10 @@ config XEN_UNPOPULATED_ALLOC ...@@ -335,6 +335,10 @@ config XEN_UNPOPULATED_ALLOC
having to balloon out RAM regions in order to obtain physical memory having to balloon out RAM regions in order to obtain physical memory
space to create such mappings. space to create such mappings.
config XEN_GRANT_DMA_IOMMU
bool
select IOMMU_API
config XEN_GRANT_DMA_OPS config XEN_GRANT_DMA_OPS
bool bool
select DMA_OPS select DMA_OPS
......
...@@ -40,3 +40,4 @@ xen-privcmd-y := privcmd.o privcmd-buf.o ...@@ -40,3 +40,4 @@ xen-privcmd-y := privcmd.o privcmd-buf.o
obj-$(CONFIG_XEN_FRONT_PGDIR_SHBUF) += xen-front-pgdir-shbuf.o obj-$(CONFIG_XEN_FRONT_PGDIR_SHBUF) += xen-front-pgdir-shbuf.o
obj-$(CONFIG_XEN_UNPOPULATED_ALLOC) += unpopulated-alloc.o obj-$(CONFIG_XEN_UNPOPULATED_ALLOC) += unpopulated-alloc.o
obj-$(CONFIG_XEN_GRANT_DMA_OPS) += grant-dma-ops.o obj-$(CONFIG_XEN_GRANT_DMA_OPS) += grant-dma-ops.o
obj-$(CONFIG_XEN_GRANT_DMA_IOMMU) += grant-dma-iommu.o
// SPDX-License-Identifier: GPL-2.0
/*
* Stub IOMMU driver which does nothing.
* The main purpose of it being present is to reuse generic IOMMU device tree
* bindings by Xen grant DMA-mapping layer.
*
* Copyright (C) 2022 EPAM Systems Inc.
*/
#include <linux/iommu.h>
#include <linux/of.h>
#include <linux/platform_device.h>
struct grant_dma_iommu_device {
struct device *dev;
struct iommu_device iommu;
};
/* Nothing is really needed here */
static const struct iommu_ops grant_dma_iommu_ops;
static const struct of_device_id grant_dma_iommu_of_match[] = {
{ .compatible = "xen,grant-dma" },
{ },
};
static int grant_dma_iommu_probe(struct platform_device *pdev)
{
struct grant_dma_iommu_device *mmu;
int ret;
mmu = devm_kzalloc(&pdev->dev, sizeof(*mmu), GFP_KERNEL);
if (!mmu)
return -ENOMEM;
mmu->dev = &pdev->dev;
ret = iommu_device_register(&mmu->iommu, &grant_dma_iommu_ops, &pdev->dev);
if (ret)
return ret;
platform_set_drvdata(pdev, mmu);
return 0;
}
static int grant_dma_iommu_remove(struct platform_device *pdev)
{
struct grant_dma_iommu_device *mmu = platform_get_drvdata(pdev);
platform_set_drvdata(pdev, NULL);
iommu_device_unregister(&mmu->iommu);
return 0;
}
static struct platform_driver grant_dma_iommu_driver = {
.driver = {
.name = "grant-dma-iommu",
.of_match_table = grant_dma_iommu_of_match,
},
.probe = grant_dma_iommu_probe,
.remove = grant_dma_iommu_remove,
};
static int __init grant_dma_iommu_init(void)
{
struct device_node *iommu_np;
iommu_np = of_find_matching_node(NULL, grant_dma_iommu_of_match);
if (!iommu_np)
return 0;
of_node_put(iommu_np);
return platform_driver_register(&grant_dma_iommu_driver);
}
subsys_initcall(grant_dma_iommu_init);
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment