Re: [PATCH v3 5/7] iommu/riscv: Device directory management.

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On 5/2/24 9:38 AM, Baolu Lu wrote:
On 5/1/24 4:01 AM, Tomasz Jeznach wrote:
@@ -128,6 +489,7 @@ void riscv_iommu_remove(struct riscv_iommu_device *iommu)
  {
      iommu_device_unregister(&iommu->iommu);
      iommu_device_sysfs_remove(&iommu->iommu);
+    riscv_iommu_iodir_set_mode(iommu, RISCV_IOMMU_DDTP_MODE_OFF);
  }
  int riscv_iommu_init(struct riscv_iommu_device *iommu)
@@ -138,12 +500,13 @@ int riscv_iommu_init(struct riscv_iommu_device *iommu)
      if (rc)
          return dev_err_probe(iommu->dev, rc, "unexpected device state\n");
-    /*
-     * Placeholder for a complete IOMMU device initialization.
-     * For now, only bare minimum: enable global identity mapping mode and register sysfs.
-     */
-    riscv_iommu_writeq(iommu, RISCV_IOMMU_REG_DDTP,
-               FIELD_PREP(RISCV_IOMMU_DDTP_MODE, RISCV_IOMMU_DDTP_MODE_BARE));
+    rc = riscv_iommu_iodir_alloc(iommu);
+    if (rc)
+        goto err_init;
+
+    rc = riscv_iommu_iodir_set_mode(iommu, RISCV_IOMMU_DDTP_MODE_MAX);
+    if (rc)
+        goto err_init;
      rc = iommu_device_sysfs_add(&iommu->iommu, NULL, NULL, "riscv-iommu@%s",
                      dev_name(iommu->dev));

The device directory root page might be allocated in
riscv_iommu_iodir_alloc(),

+    if (!iommu->ddt_root) {
+        iommu->ddt_root = riscv_iommu_get_pages(iommu, 0);
+        iommu->ddt_phys = __pa(iommu->ddt_root);
+    }

But I didn't find any place to free it in the error paths. Did I
overlook anything?

I found the answer by myself. devres_alloc() is used so the page memory
resources are managed by the driver core automatically. Please ignore
the above comment.

Not sure about the pages for paging domain. If all pages release is
deferred, it may cause big memory consumption. We have a trade-off here.
On one hand, this might speed up the domain mapping since all pages
might be preallocated; on the other hand, it will cost more memory.

Best regards,
baolu




[Index of Archives]     [Device Tree Compilter]     [Device Tree Spec]     [Linux Driver Backports]     [Video for Linux]     [Linux USB Devel]     [Linux PCI Devel]     [Linux Audio Users]     [Linux Kernel]     [Linux SCSI]     [XFree86]     [Yosemite Backpacking]


  Powered by Linux