]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
iommu/riscv: Add shutdown function for iommu driver
authorXu Lu <luxu.kernel@bytedance.com>
Fri, 3 Jan 2025 09:32:20 +0000 (17:32 +0800)
committerJoerg Roedel <jroedel@suse.de>
Mon, 6 Jan 2025 11:38:11 +0000 (12:38 +0100)
This commit supplies shutdown callback for iommu driver. The shutdown
callback resets necessary registers so that newly booted kernel can pass
riscv_iommu_init_check() after kexec. Also, the shutdown callback resets
iommu mode to bare instead of off so that new kernel can still use PCIE
devices even when CONFIG_RISCV_IOMMU is not enabled.

Signed-off-by: Xu Lu <luxu.kernel@bytedance.com>
Link: https://lore.kernel.org/r/20250103093220.38106-3-luxu.kernel@bytedance.com
Signed-off-by: Joerg Roedel <jroedel@suse.de>
drivers/iommu/riscv/iommu-pci.c
drivers/iommu/riscv/iommu-platform.c
drivers/iommu/riscv/iommu.c
drivers/iommu/riscv/iommu.h

index c7a89143014c589da7cc535ec28def2c0d0484bb..d82d2b00904c7742614880a9fe8528f0aedbb919 100644 (file)
@@ -101,6 +101,13 @@ static void riscv_iommu_pci_remove(struct pci_dev *pdev)
        riscv_iommu_remove(iommu);
 }
 
+static void riscv_iommu_pci_shutdown(struct pci_dev *pdev)
+{
+       struct riscv_iommu_device *iommu = dev_get_drvdata(&pdev->dev);
+
+       riscv_iommu_disable(iommu);
+}
+
 static const struct pci_device_id riscv_iommu_pci_tbl[] = {
        {PCI_VDEVICE(REDHAT, PCI_DEVICE_ID_REDHAT_RISCV_IOMMU), 0},
        {PCI_VDEVICE(RIVOS, PCI_DEVICE_ID_RIVOS_RISCV_IOMMU_GA), 0},
@@ -112,6 +119,7 @@ static struct pci_driver riscv_iommu_pci_driver = {
        .id_table = riscv_iommu_pci_tbl,
        .probe = riscv_iommu_pci_probe,
        .remove = riscv_iommu_pci_remove,
+       .shutdown = riscv_iommu_pci_shutdown,
        .driver = {
                .suppress_bind_attrs = true,
        },
index c722eebcdd9bcef7dc344e25854d73c46efff6fa..725e919b97ef404fa2ba10725c8583a31db79dfe 100644 (file)
@@ -140,6 +140,11 @@ static void riscv_iommu_platform_remove(struct platform_device *pdev)
                platform_device_msi_free_irqs_all(&pdev->dev);
 };
 
+static void riscv_iommu_platform_shutdown(struct platform_device *pdev)
+{
+       riscv_iommu_disable(dev_get_drvdata(&pdev->dev));
+};
+
 static const struct of_device_id riscv_iommu_of_match[] = {
        {.compatible = "riscv,iommu",},
        {},
@@ -148,6 +153,7 @@ static const struct of_device_id riscv_iommu_of_match[] = {
 static struct platform_driver riscv_iommu_platform_driver = {
        .probe = riscv_iommu_platform_probe,
        .remove = riscv_iommu_platform_remove,
+       .shutdown = riscv_iommu_platform_shutdown,
        .driver = {
                .name = "riscv,iommu",
                .of_match_table = riscv_iommu_of_match,
index 84806724f5680374542045b7cfb4bd82cc88c396..670b4302aca831189c946b37be5ae0a2cb0a6bf2 100644 (file)
@@ -651,9 +651,11 @@ static struct riscv_iommu_dc *riscv_iommu_get_dc(struct riscv_iommu_device *iomm
  * This is best effort IOMMU translation shutdown flow.
  * Disable IOMMU without waiting for hardware response.
  */
-static void riscv_iommu_disable(struct riscv_iommu_device *iommu)
+void riscv_iommu_disable(struct riscv_iommu_device *iommu)
 {
-       riscv_iommu_writeq(iommu, RISCV_IOMMU_REG_DDTP, 0);
+       riscv_iommu_writeq(iommu, RISCV_IOMMU_REG_DDTP,
+                          FIELD_PREP(RISCV_IOMMU_DDTP_IOMMU_MODE,
+                                     RISCV_IOMMU_DDTP_IOMMU_MODE_BARE));
        riscv_iommu_writel(iommu, RISCV_IOMMU_REG_CQCSR, 0);
        riscv_iommu_writel(iommu, RISCV_IOMMU_REG_FQCSR, 0);
        riscv_iommu_writel(iommu, RISCV_IOMMU_REG_PQCSR, 0);
index b1c4664542b48b3442c80205a9608e82c896940d..46df79dd5495706e9625fcff6380fad9fb4f9d04 100644 (file)
@@ -64,6 +64,7 @@ struct riscv_iommu_device {
 
 int riscv_iommu_init(struct riscv_iommu_device *iommu);
 void riscv_iommu_remove(struct riscv_iommu_device *iommu);
+void riscv_iommu_disable(struct riscv_iommu_device *iommu);
 
 #define riscv_iommu_readl(iommu, addr) \
        readl_relaxed((iommu)->reg + (addr))