Skip to content

Rpi 6.7.y iommu support #5833

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jan 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions drivers/iommu/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -487,4 +487,11 @@ config SPRD_IOMMU

Say Y here if you want to use the multimedia devices listed above.

config BCM2712_IOMMU
tristate "BCM2712 IOMMU driver"
depends on ARM64 && ARCH_BCM
select IOMMU_API
help
IOMMU driver for BCM2712

endif # IOMMU_SUPPORT
1 change: 1 addition & 0 deletions drivers/iommu/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,4 @@ obj-$(CONFIG_VIRTIO_IOMMU) += virtio-iommu.o
obj-$(CONFIG_IOMMU_SVA) += iommu-sva.o io-pgfault.o
obj-$(CONFIG_SPRD_IOMMU) += sprd-iommu.o
obj-$(CONFIG_APPLE_DART) += apple-dart.o
obj-$(CONFIG_BCM2712_IOMMU) += bcm2712-iommu.o bcm2712-iommu-cache.o
77 changes: 77 additions & 0 deletions drivers/iommu/bcm2712-iommu-cache.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
// SPDX-License-Identifier: GPL-2.0-only
/*
* IOMMU driver for BCM2712
*
* Copyright (c) 2023 Raspberry Pi Ltd.
*/

#include "bcm2712-iommu.h"

#include <linux/err.h>
#include <linux/of_platform.h>
#include <linux/platform_device.h>
#include <linux/spinlock.h>

#define MMUC_CONTROL_ENABLE 1
#define MMUC_CONTROL_FLUSH 2
#define MMUC_CONTROL_FLUSHING 4

void bcm2712_iommu_cache_flush(struct bcm2712_iommu_cache *cache)
{
unsigned long flags;
int i;

spin_lock_irqsave(&cache->hw_lock, flags);
if (cache->reg_base) {
/* Enable and flush the TLB cache */
writel(MMUC_CONTROL_ENABLE | MMUC_CONTROL_FLUSH,
cache->reg_base);

/* Wait for flush to complete: it should be very quick */
for (i = 0; i < 1024; i++) {
if (!(MMUC_CONTROL_FLUSHING & readl(cache->reg_base)))
break;
cpu_relax();
}
}
spin_unlock_irqrestore(&cache->hw_lock, flags);
}

static int bcm2712_iommu_cache_probe(struct platform_device *pdev)
{
struct bcm2712_iommu_cache *cache;

dev_info(&pdev->dev, __func__);
cache = devm_kzalloc(&pdev->dev, sizeof(*cache), GFP_KERNEL);
if (!cache)
return -ENOMEM;

cache->dev = &pdev->dev;
platform_set_drvdata(pdev, cache);
spin_lock_init(&cache->hw_lock);

/* Get IOMMUC registers; we only use the first register (IOMMUC_CTRL) */
cache->reg_base = devm_platform_ioremap_resource(pdev, 0);
if (IS_ERR(cache->reg_base)) {
dev_err(&pdev->dev, "Failed to get IOMMU Cache registers address\n");
cache->reg_base = NULL;
}
return 0;
}

static const struct of_device_id bcm2712_iommu_cache_of_match[] = {
{
. compatible = "brcm,bcm2712-iommuc"
},
{ /* sentinel */ },
};

static struct platform_driver bcm2712_iommu_cache_driver = {
.probe = bcm2712_iommu_cache_probe,
.driver = {
.name = "bcm2712-iommu-cache",
.of_match_table = bcm2712_iommu_cache_of_match
},
};

builtin_platform_driver(bcm2712_iommu_cache_driver);
Loading