hc
2024-02-20 102a0743326a03cd1a1202ceda21e175b7d3575c
kernel/drivers/iommu/sun50i-iommu.c
....@@ -28,6 +28,7 @@
2828 #include <linux/types.h>
2929
3030 #define IOMMU_RESET_REG 0x010
31
+#define IOMMU_RESET_RELEASE_ALL 0xffffffff
3132 #define IOMMU_ENABLE_REG 0x020
3233 #define IOMMU_ENABLE_ENABLE BIT(0)
3334
....@@ -271,7 +272,7 @@
271272 enum sun50i_iommu_aci aci;
272273 u32 flags = 0;
273274
274
- if (prot & (IOMMU_READ | IOMMU_WRITE))
275
+ if ((prot & (IOMMU_READ | IOMMU_WRITE)) == (IOMMU_READ | IOMMU_WRITE))
275276 aci = SUN50I_IOMMU_ACI_RD_WR;
276277 else if (prot & IOMMU_READ)
277278 aci = SUN50I_IOMMU_ACI_RD;
....@@ -512,7 +513,7 @@
512513 sun50i_iommu_free_page_table(iommu, drop_pt);
513514 }
514515
515
- sun50i_table_flush(sun50i_domain, page_table, PT_SIZE);
516
+ sun50i_table_flush(sun50i_domain, page_table, NUM_PT_ENTRIES);
516517 sun50i_table_flush(sun50i_domain, dte_addr, 1);
517518
518519 return page_table;
....@@ -602,7 +603,6 @@
602603 struct sun50i_iommu_domain *sun50i_domain;
603604
604605 if (type != IOMMU_DOMAIN_DMA &&
605
- type != IOMMU_DOMAIN_IDENTITY &&
606606 type != IOMMU_DOMAIN_UNMANAGED)
607607 return NULL;
608608
....@@ -880,8 +880,8 @@
880880
881881 static irqreturn_t sun50i_iommu_irq(int irq, void *dev_id)
882882 {
883
+ u32 status, l1_status, l2_status, resets;
883884 struct sun50i_iommu *iommu = dev_id;
884
- u32 status;
885885
886886 spin_lock(&iommu->iommu_lock);
887887
....@@ -890,6 +890,9 @@
890890 spin_unlock(&iommu->iommu_lock);
891891 return IRQ_NONE;
892892 }
893
+
894
+ l1_status = iommu_read(iommu, IOMMU_L1PG_INT_REG);
895
+ l2_status = iommu_read(iommu, IOMMU_L2PG_INT_REG);
893896
894897 if (status & IOMMU_INT_INVALID_L2PG)
895898 sun50i_iommu_handle_pt_irq(iommu,
....@@ -904,8 +907,9 @@
904907
905908 iommu_write(iommu, IOMMU_INT_CLR_REG, status);
906909
907
- iommu_write(iommu, IOMMU_RESET_REG, ~status);
908
- iommu_write(iommu, IOMMU_RESET_REG, status);
910
+ resets = (status | l1_status | l2_status) & IOMMU_INT_MASTER_MASK;
911
+ iommu_write(iommu, IOMMU_RESET_REG, ~resets);
912
+ iommu_write(iommu, IOMMU_RESET_REG, IOMMU_RESET_RELEASE_ALL);
909913
910914 spin_unlock(&iommu->iommu_lock);
911915