Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

Merge tag 'arm-smmu-updates' of git://git.kernel.org/pub/scm/linux/kernel/git/will/linux into arm/smmu

Arm SMMU updates for 5.12

- Support for MT8192 IOMMU from Mediatek

- Arm v7s io-pgtable extensions for MT8192

- Removal of TLBI_ON_MAP quirk

- New Qualcomm compatible strings

- Allow SVA without hardware broadcast TLB maintenance on SMMUv3

- Virtualization Host Extension support for SMMUv3 (SVA)

- Allow SMMUv3 PMU (perf) driver to be built independently from IOMMU

- Misc cleanups

+981 -356
+2
Documentation/devicetree/bindings/iommu/arm,smmu.yaml
··· 34 34 items: 35 35 - enum: 36 36 - qcom,sc7180-smmu-500 37 + - qcom,sc8180x-smmu-500 37 38 - qcom,sdm845-smmu-500 38 39 - qcom,sm8150-smmu-500 39 40 - qcom,sm8250-smmu-500 41 + - qcom,sm8350-smmu-500 40 42 - const: arm,mmu-500 41 43 - description: Qcom Adreno GPUs implementing "arm,smmu-v2" 42 44 items:
-105
Documentation/devicetree/bindings/iommu/mediatek,iommu.txt
··· 1 - * Mediatek IOMMU Architecture Implementation 2 - 3 - Some Mediatek SOCs contain a Multimedia Memory Management Unit (M4U), and 4 - this M4U have two generations of HW architecture. Generation one uses flat 5 - pagetable, and only supports 4K size page mapping. Generation two uses the 6 - ARM Short-Descriptor translation table format for address translation. 7 - 8 - About the M4U Hardware Block Diagram, please check below: 9 - 10 - EMI (External Memory Interface) 11 - | 12 - m4u (Multimedia Memory Management Unit) 13 - | 14 - +--------+ 15 - | | 16 - gals0-rx gals1-rx (Global Async Local Sync rx) 17 - | | 18 - | | 19 - gals0-tx gals1-tx (Global Async Local Sync tx) 20 - | | Some SoCs may have GALS. 21 - +--------+ 22 - | 23 - SMI Common(Smart Multimedia Interface Common) 24 - | 25 - +----------------+------- 26 - | | 27 - | gals-rx There may be GALS in some larbs. 28 - | | 29 - | | 30 - | gals-tx 31 - | | 32 - SMI larb0 SMI larb1 ... SoCs have several SMI local arbiter(larb). 33 - (display) (vdec) 34 - | | 35 - | | 36 - +-----+-----+ +----+----+ 37 - | | | | | | 38 - | | |... | | | ... There are different ports in each larb. 39 - | | | | | | 40 - OVL0 RDMA0 WDMA0 MC PP VLD 41 - 42 - As above, The Multimedia HW will go through SMI and M4U while it 43 - access EMI. SMI is a bridge between m4u and the Multimedia HW. It contain 44 - smi local arbiter and smi common. It will control whether the Multimedia 45 - HW should go though the m4u for translation or bypass it and talk 46 - directly with EMI. And also SMI help control the power domain and clocks for 47 - each local arbiter. 48 - Normally we specify a local arbiter(larb) for each multimedia HW 49 - like display, video decode, and camera. And there are different ports 50 - in each larb. Take a example, There are many ports like MC, PP, VLD in the 51 - video decode local arbiter, all these ports are according to the video HW. 52 - In some SoCs, there may be a GALS(Global Async Local Sync) module between 53 - smi-common and m4u, and additional GALS module between smi-larb and 54 - smi-common. GALS can been seen as a "asynchronous fifo" which could help 55 - synchronize for the modules in different clock frequency. 56 - 57 - Required properties: 58 - - compatible : must be one of the following string: 59 - "mediatek,mt2701-m4u" for mt2701 which uses generation one m4u HW. 60 - "mediatek,mt2712-m4u" for mt2712 which uses generation two m4u HW. 61 - "mediatek,mt6779-m4u" for mt6779 which uses generation two m4u HW. 62 - "mediatek,mt7623-m4u", "mediatek,mt2701-m4u" for mt7623 which uses 63 - generation one m4u HW. 64 - "mediatek,mt8167-m4u" for mt8167 which uses generation two m4u HW. 65 - "mediatek,mt8173-m4u" for mt8173 which uses generation two m4u HW. 66 - "mediatek,mt8183-m4u" for mt8183 which uses generation two m4u HW. 67 - - reg : m4u register base and size. 68 - - interrupts : the interrupt of m4u. 69 - - clocks : must contain one entry for each clock-names. 70 - - clock-names : Only 1 optional clock: 71 - - "bclk": the block clock of m4u. 72 - Here is the list which require this "bclk": 73 - - mt2701, mt2712, mt7623 and mt8173. 74 - Note that m4u use the EMI clock which always has been enabled before kernel 75 - if there is no this "bclk". 76 - - mediatek,larbs : List of phandle to the local arbiters in the current Socs. 77 - Refer to bindings/memory-controllers/mediatek,smi-larb.txt. It must sort 78 - according to the local arbiter index, like larb0, larb1, larb2... 79 - - iommu-cells : must be 1. This is the mtk_m4u_id according to the HW. 80 - Specifies the mtk_m4u_id as defined in 81 - dt-binding/memory/mt2701-larb-port.h for mt2701, mt7623 82 - dt-binding/memory/mt2712-larb-port.h for mt2712, 83 - dt-binding/memory/mt6779-larb-port.h for mt6779, 84 - dt-binding/memory/mt8167-larb-port.h for mt8167, 85 - dt-binding/memory/mt8173-larb-port.h for mt8173, and 86 - dt-binding/memory/mt8183-larb-port.h for mt8183. 87 - 88 - Example: 89 - iommu: iommu@10205000 { 90 - compatible = "mediatek,mt8173-m4u"; 91 - reg = <0 0x10205000 0 0x1000>; 92 - interrupts = <GIC_SPI 139 IRQ_TYPE_LEVEL_LOW>; 93 - clocks = <&infracfg CLK_INFRA_M4U>; 94 - clock-names = "bclk"; 95 - mediatek,larbs = <&larb0 &larb1 &larb2 &larb3 &larb4 &larb5>; 96 - #iommu-cells = <1>; 97 - }; 98 - 99 - Example for a client device: 100 - display { 101 - compatible = "mediatek,mt8173-disp"; 102 - iommus = <&iommu M4U_PORT_DISP_OVL0>, 103 - <&iommu M4U_PORT_DISP_RDMA0>; 104 - ... 105 - };
+183
Documentation/devicetree/bindings/iommu/mediatek,iommu.yaml
··· 1 + # SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) 2 + %YAML 1.2 3 + --- 4 + $id: http://devicetree.org/schemas/iommu/mediatek,iommu.yaml# 5 + $schema: http://devicetree.org/meta-schemas/core.yaml# 6 + 7 + title: MediaTek IOMMU Architecture Implementation 8 + 9 + maintainers: 10 + - Yong Wu <yong.wu@mediatek.com> 11 + 12 + description: |+ 13 + Some MediaTek SOCs contain a Multimedia Memory Management Unit (M4U), and 14 + this M4U have two generations of HW architecture. Generation one uses flat 15 + pagetable, and only supports 4K size page mapping. Generation two uses the 16 + ARM Short-Descriptor translation table format for address translation. 17 + 18 + About the M4U Hardware Block Diagram, please check below: 19 + 20 + EMI (External Memory Interface) 21 + | 22 + m4u (Multimedia Memory Management Unit) 23 + | 24 + +--------+ 25 + | | 26 + gals0-rx gals1-rx (Global Async Local Sync rx) 27 + | | 28 + | | 29 + gals0-tx gals1-tx (Global Async Local Sync tx) 30 + | | Some SoCs may have GALS. 31 + +--------+ 32 + | 33 + SMI Common(Smart Multimedia Interface Common) 34 + | 35 + +----------------+------- 36 + | | 37 + | gals-rx There may be GALS in some larbs. 38 + | | 39 + | | 40 + | gals-tx 41 + | | 42 + SMI larb0 SMI larb1 ... SoCs have several SMI local arbiter(larb). 43 + (display) (vdec) 44 + | | 45 + | | 46 + +-----+-----+ +----+----+ 47 + | | | | | | 48 + | | |... | | | ... There are different ports in each larb. 49 + | | | | | | 50 + OVL0 RDMA0 WDMA0 MC PP VLD 51 + 52 + As above, The Multimedia HW will go through SMI and M4U while it 53 + access EMI. SMI is a bridge between m4u and the Multimedia HW. It contain 54 + smi local arbiter and smi common. It will control whether the Multimedia 55 + HW should go though the m4u for translation or bypass it and talk 56 + directly with EMI. And also SMI help control the power domain and clocks for 57 + each local arbiter. 58 + 59 + Normally we specify a local arbiter(larb) for each multimedia HW 60 + like display, video decode, and camera. And there are different ports 61 + in each larb. Take a example, There are many ports like MC, PP, VLD in the 62 + video decode local arbiter, all these ports are according to the video HW. 63 + 64 + In some SoCs, there may be a GALS(Global Async Local Sync) module between 65 + smi-common and m4u, and additional GALS module between smi-larb and 66 + smi-common. GALS can been seen as a "asynchronous fifo" which could help 67 + synchronize for the modules in different clock frequency. 68 + 69 + properties: 70 + compatible: 71 + oneOf: 72 + - enum: 73 + - mediatek,mt2701-m4u # generation one 74 + - mediatek,mt2712-m4u # generation two 75 + - mediatek,mt6779-m4u # generation two 76 + - mediatek,mt8167-m4u # generation two 77 + - mediatek,mt8173-m4u # generation two 78 + - mediatek,mt8183-m4u # generation two 79 + - mediatek,mt8192-m4u # generation two 80 + 81 + - description: mt7623 generation one 82 + items: 83 + - const: mediatek,mt7623-m4u 84 + - const: mediatek,mt2701-m4u 85 + 86 + reg: 87 + maxItems: 1 88 + 89 + interrupts: 90 + maxItems: 1 91 + 92 + clocks: 93 + items: 94 + - description: bclk is the block clock. 95 + 96 + clock-names: 97 + items: 98 + - const: bclk 99 + 100 + mediatek,larbs: 101 + $ref: /schemas/types.yaml#/definitions/phandle-array 102 + minItems: 1 103 + maxItems: 32 104 + description: | 105 + List of phandle to the local arbiters in the current Socs. 106 + Refer to bindings/memory-controllers/mediatek,smi-larb.yaml. It must sort 107 + according to the local arbiter index, like larb0, larb1, larb2... 108 + 109 + '#iommu-cells': 110 + const: 1 111 + description: | 112 + This is the mtk_m4u_id according to the HW. Specifies the mtk_m4u_id as 113 + defined in 114 + dt-binding/memory/mt2701-larb-port.h for mt2701 and mt7623, 115 + dt-binding/memory/mt2712-larb-port.h for mt2712, 116 + dt-binding/memory/mt6779-larb-port.h for mt6779, 117 + dt-binding/memory/mt8167-larb-port.h for mt8167, 118 + dt-binding/memory/mt8173-larb-port.h for mt8173, 119 + dt-binding/memory/mt8183-larb-port.h for mt8183, 120 + dt-binding/memory/mt8192-larb-port.h for mt8192. 121 + 122 + power-domains: 123 + maxItems: 1 124 + 125 + required: 126 + - compatible 127 + - reg 128 + - interrupts 129 + - mediatek,larbs 130 + - '#iommu-cells' 131 + 132 + allOf: 133 + - if: 134 + properties: 135 + compatible: 136 + contains: 137 + enum: 138 + - mediatek,mt2701-m4u 139 + - mediatek,mt2712-m4u 140 + - mediatek,mt8173-m4u 141 + - mediatek,mt8192-m4u 142 + 143 + then: 144 + required: 145 + - clocks 146 + 147 + - if: 148 + properties: 149 + compatible: 150 + enum: 151 + - mediatek,mt8192-m4u 152 + 153 + then: 154 + required: 155 + - power-domains 156 + 157 + additionalProperties: false 158 + 159 + examples: 160 + - | 161 + #include <dt-bindings/clock/mt8173-clk.h> 162 + #include <dt-bindings/interrupt-controller/arm-gic.h> 163 + 164 + iommu: iommu@10205000 { 165 + compatible = "mediatek,mt8173-m4u"; 166 + reg = <0x10205000 0x1000>; 167 + interrupts = <GIC_SPI 139 IRQ_TYPE_LEVEL_LOW>; 168 + clocks = <&infracfg CLK_INFRA_M4U>; 169 + clock-names = "bclk"; 170 + mediatek,larbs = <&larb0 &larb1 &larb2 171 + &larb3 &larb4 &larb5>; 172 + #iommu-cells = <1>; 173 + }; 174 + 175 + - | 176 + #include <dt-bindings/memory/mt8173-larb-port.h> 177 + 178 + /* Example for a client device */ 179 + display { 180 + compatible = "mediatek,mt8173-disp"; 181 + iommus = <&iommu M4U_PORT_DISP_OVL0>, 182 + <&iommu M4U_PORT_DISP_RDMA0>; 183 + };
+9
MAINTAINERS
··· 11178 11178 F: Documentation/devicetree/bindings/i2c/i2c-mt65xx.txt 11179 11179 F: drivers/i2c/busses/i2c-mt65xx.c 11180 11180 11181 + MEDIATEK IOMMU DRIVER 11182 + M: Yong Wu <yong.wu@mediatek.com> 11183 + L: iommu@lists.linux-foundation.org 11184 + L: linux-mediatek@lists.infradead.org (moderated for non-subscribers) 11185 + S: Supported 11186 + F: Documentation/devicetree/bindings/iommu/mediatek* 11187 + F: drivers/iommu/mtk-iommu* 11188 + F: include/dt-bindings/memory/mt*-port.h 11189 + 11181 11190 MEDIATEK JPEG DRIVER 11182 11191 M: Rick Chang <rick.chang@mediatek.com> 11183 11192 M: Bin Liu <bin.liu@mediatek.com>
+7 -3
drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3-sva.c
··· 182 182 unsigned long start, unsigned long end) 183 183 { 184 184 struct arm_smmu_mmu_notifier *smmu_mn = mn_to_smmu(mn); 185 + struct arm_smmu_domain *smmu_domain = smmu_mn->domain; 186 + size_t size = end - start + 1; 185 187 186 - arm_smmu_atc_inv_domain(smmu_mn->domain, mm->pasid, start, 187 - end - start + 1); 188 + if (!(smmu_domain->smmu->features & ARM_SMMU_FEAT_BTM)) 189 + arm_smmu_tlb_inv_range_asid(start, size, smmu_mn->cd->asid, 190 + PAGE_SIZE, false, smmu_domain); 191 + arm_smmu_atc_inv_domain(smmu_domain, mm->pasid, start, size); 188 192 } 189 193 190 194 static void arm_smmu_mm_release(struct mmu_notifier *mn, struct mm_struct *mm) ··· 395 391 unsigned long reg, fld; 396 392 unsigned long oas; 397 393 unsigned long asid_bits; 398 - u32 feat_mask = ARM_SMMU_FEAT_BTM | ARM_SMMU_FEAT_COHERENCY; 394 + u32 feat_mask = ARM_SMMU_FEAT_COHERENCY; 399 395 400 396 if (vabits_actual == 52) 401 397 feat_mask |= ARM_SMMU_FEAT_VAX;
+91 -63
drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c
··· 88 88 { 0, NULL}, 89 89 }; 90 90 91 - static inline void __iomem *arm_smmu_page1_fixup(unsigned long offset, 92 - struct arm_smmu_device *smmu) 93 - { 94 - if (offset > SZ_64K) 95 - return smmu->page1 + offset - SZ_64K; 96 - 97 - return smmu->base + offset; 98 - } 99 - 100 91 static void parse_driver_options(struct arm_smmu_device *smmu) 101 92 { 102 93 int i = 0; ··· 263 272 cmd[1] |= FIELD_PREP(CMDQ_CFGI_1_RANGE, 31); 264 273 break; 265 274 case CMDQ_OP_TLBI_NH_VA: 275 + cmd[0] |= FIELD_PREP(CMDQ_TLBI_0_VMID, ent->tlbi.vmid); 276 + fallthrough; 277 + case CMDQ_OP_TLBI_EL2_VA: 266 278 cmd[0] |= FIELD_PREP(CMDQ_TLBI_0_NUM, ent->tlbi.num); 267 279 cmd[0] |= FIELD_PREP(CMDQ_TLBI_0_SCALE, ent->tlbi.scale); 268 - cmd[0] |= FIELD_PREP(CMDQ_TLBI_0_VMID, ent->tlbi.vmid); 269 280 cmd[0] |= FIELD_PREP(CMDQ_TLBI_0_ASID, ent->tlbi.asid); 270 281 cmd[1] |= FIELD_PREP(CMDQ_TLBI_1_LEAF, ent->tlbi.leaf); 271 282 cmd[1] |= FIELD_PREP(CMDQ_TLBI_1_TTL, ent->tlbi.ttl); ··· 288 295 fallthrough; 289 296 case CMDQ_OP_TLBI_S12_VMALL: 290 297 cmd[0] |= FIELD_PREP(CMDQ_TLBI_0_VMID, ent->tlbi.vmid); 298 + break; 299 + case CMDQ_OP_TLBI_EL2_ASID: 300 + cmd[0] |= FIELD_PREP(CMDQ_TLBI_0_ASID, ent->tlbi.asid); 291 301 break; 292 302 case CMDQ_OP_ATC_INV: 293 303 cmd[0] |= FIELD_PREP(CMDQ_0_SSV, ent->substream_valid); ··· 882 886 void arm_smmu_tlb_inv_asid(struct arm_smmu_device *smmu, u16 asid) 883 887 { 884 888 struct arm_smmu_cmdq_ent cmd = { 885 - .opcode = CMDQ_OP_TLBI_NH_ASID, 889 + .opcode = smmu->features & ARM_SMMU_FEAT_E2H ? 890 + CMDQ_OP_TLBI_EL2_ASID : CMDQ_OP_TLBI_NH_ASID, 886 891 .tlbi.asid = asid, 887 892 }; 888 893 ··· 1266 1269 } 1267 1270 1268 1271 if (s1_cfg) { 1272 + u64 strw = smmu->features & ARM_SMMU_FEAT_E2H ? 1273 + STRTAB_STE_1_STRW_EL2 : STRTAB_STE_1_STRW_NSEL1; 1274 + 1269 1275 BUG_ON(ste_live); 1270 1276 dst[1] = cpu_to_le64( 1271 1277 FIELD_PREP(STRTAB_STE_1_S1DSS, STRTAB_STE_1_S1DSS_SSID0) | 1272 1278 FIELD_PREP(STRTAB_STE_1_S1CIR, STRTAB_STE_1_S1C_CACHE_WBRA) | 1273 1279 FIELD_PREP(STRTAB_STE_1_S1COR, STRTAB_STE_1_S1C_CACHE_WBRA) | 1274 1280 FIELD_PREP(STRTAB_STE_1_S1CSH, ARM_SMMU_SH_ISH) | 1275 - FIELD_PREP(STRTAB_STE_1_STRW, STRTAB_STE_1_STRW_NSEL1)); 1281 + FIELD_PREP(STRTAB_STE_1_STRW, strw)); 1276 1282 1277 1283 if (smmu->features & ARM_SMMU_FEAT_STALLS && 1278 1284 !(smmu->features & ARM_SMMU_FEAT_STALL_FORCE)) ··· 1667 1667 arm_smmu_atc_inv_domain(smmu_domain, 0, 0, 0); 1668 1668 } 1669 1669 1670 - static void arm_smmu_tlb_inv_range(unsigned long iova, size_t size, 1671 - size_t granule, bool leaf, 1672 - struct arm_smmu_domain *smmu_domain) 1670 + static void __arm_smmu_tlb_inv_range(struct arm_smmu_cmdq_ent *cmd, 1671 + unsigned long iova, size_t size, 1672 + size_t granule, 1673 + struct arm_smmu_domain *smmu_domain) 1673 1674 { 1674 1675 struct arm_smmu_device *smmu = smmu_domain->smmu; 1675 - unsigned long start = iova, end = iova + size, num_pages = 0, tg = 0; 1676 + unsigned long end = iova + size, num_pages = 0, tg = 0; 1676 1677 size_t inv_range = granule; 1677 1678 struct arm_smmu_cmdq_batch cmds = {}; 1678 - struct arm_smmu_cmdq_ent cmd = { 1679 - .tlbi = { 1680 - .leaf = leaf, 1681 - }, 1682 - }; 1683 1679 1684 1680 if (!size) 1685 1681 return; 1686 - 1687 - if (smmu_domain->stage == ARM_SMMU_DOMAIN_S1) { 1688 - cmd.opcode = CMDQ_OP_TLBI_NH_VA; 1689 - cmd.tlbi.asid = smmu_domain->s1_cfg.cd.asid; 1690 - } else { 1691 - cmd.opcode = CMDQ_OP_TLBI_S2_IPA; 1692 - cmd.tlbi.vmid = smmu_domain->s2_cfg.vmid; 1693 - } 1694 1682 1695 1683 if (smmu->features & ARM_SMMU_FEAT_RANGE_INV) { 1696 1684 /* Get the leaf page size */ 1697 1685 tg = __ffs(smmu_domain->domain.pgsize_bitmap); 1698 1686 1699 1687 /* Convert page size of 12,14,16 (log2) to 1,2,3 */ 1700 - cmd.tlbi.tg = (tg - 10) / 2; 1688 + cmd->tlbi.tg = (tg - 10) / 2; 1701 1689 1702 1690 /* Determine what level the granule is at */ 1703 - cmd.tlbi.ttl = 4 - ((ilog2(granule) - 3) / (tg - 3)); 1691 + cmd->tlbi.ttl = 4 - ((ilog2(granule) - 3) / (tg - 3)); 1704 1692 1705 1693 num_pages = size >> tg; 1706 1694 } ··· 1706 1718 1707 1719 /* Determine the power of 2 multiple number of pages */ 1708 1720 scale = __ffs(num_pages); 1709 - cmd.tlbi.scale = scale; 1721 + cmd->tlbi.scale = scale; 1710 1722 1711 1723 /* Determine how many chunks of 2^scale size we have */ 1712 1724 num = (num_pages >> scale) & CMDQ_TLBI_RANGE_NUM_MAX; 1713 - cmd.tlbi.num = num - 1; 1725 + cmd->tlbi.num = num - 1; 1714 1726 1715 1727 /* range is num * 2^scale * pgsize */ 1716 1728 inv_range = num << (scale + tg); ··· 1719 1731 num_pages -= num << scale; 1720 1732 } 1721 1733 1722 - cmd.tlbi.addr = iova; 1723 - arm_smmu_cmdq_batch_add(smmu, &cmds, &cmd); 1734 + cmd->tlbi.addr = iova; 1735 + arm_smmu_cmdq_batch_add(smmu, &cmds, cmd); 1724 1736 iova += inv_range; 1725 1737 } 1726 1738 arm_smmu_cmdq_batch_submit(smmu, &cmds); 1739 + } 1740 + 1741 + static void arm_smmu_tlb_inv_range_domain(unsigned long iova, size_t size, 1742 + size_t granule, bool leaf, 1743 + struct arm_smmu_domain *smmu_domain) 1744 + { 1745 + struct arm_smmu_cmdq_ent cmd = { 1746 + .tlbi = { 1747 + .leaf = leaf, 1748 + }, 1749 + }; 1750 + 1751 + if (smmu_domain->stage == ARM_SMMU_DOMAIN_S1) { 1752 + cmd.opcode = smmu_domain->smmu->features & ARM_SMMU_FEAT_E2H ? 1753 + CMDQ_OP_TLBI_EL2_VA : CMDQ_OP_TLBI_NH_VA; 1754 + cmd.tlbi.asid = smmu_domain->s1_cfg.cd.asid; 1755 + } else { 1756 + cmd.opcode = CMDQ_OP_TLBI_S2_IPA; 1757 + cmd.tlbi.vmid = smmu_domain->s2_cfg.vmid; 1758 + } 1759 + __arm_smmu_tlb_inv_range(&cmd, iova, size, granule, smmu_domain); 1727 1760 1728 1761 /* 1729 1762 * Unfortunately, this can't be leaf-only since we may have 1730 1763 * zapped an entire table. 1731 1764 */ 1732 - arm_smmu_atc_inv_domain(smmu_domain, 0, start, size); 1765 + arm_smmu_atc_inv_domain(smmu_domain, 0, iova, size); 1766 + } 1767 + 1768 + void arm_smmu_tlb_inv_range_asid(unsigned long iova, size_t size, int asid, 1769 + size_t granule, bool leaf, 1770 + struct arm_smmu_domain *smmu_domain) 1771 + { 1772 + struct arm_smmu_cmdq_ent cmd = { 1773 + .opcode = smmu_domain->smmu->features & ARM_SMMU_FEAT_E2H ? 1774 + CMDQ_OP_TLBI_EL2_VA : CMDQ_OP_TLBI_NH_VA, 1775 + .tlbi = { 1776 + .asid = asid, 1777 + .leaf = leaf, 1778 + }, 1779 + }; 1780 + 1781 + __arm_smmu_tlb_inv_range(&cmd, iova, size, granule, smmu_domain); 1733 1782 } 1734 1783 1735 1784 static void arm_smmu_tlb_inv_page_nosync(struct iommu_iotlb_gather *gather, ··· 1782 1757 static void arm_smmu_tlb_inv_walk(unsigned long iova, size_t size, 1783 1758 size_t granule, void *cookie) 1784 1759 { 1785 - arm_smmu_tlb_inv_range(iova, size, granule, false, cookie); 1760 + arm_smmu_tlb_inv_range_domain(iova, size, granule, false, cookie); 1786 1761 } 1787 1762 1788 1763 static const struct iommu_flush_ops arm_smmu_flush_ops = { ··· 2305 2280 { 2306 2281 struct arm_smmu_domain *smmu_domain = to_smmu_domain(domain); 2307 2282 2308 - arm_smmu_tlb_inv_range(gather->start, gather->end - gather->start, 2309 - gather->pgsize, true, smmu_domain); 2283 + arm_smmu_tlb_inv_range_domain(gather->start, 2284 + gather->end - gather->start + 1, 2285 + gather->pgsize, true, smmu_domain); 2310 2286 } 2311 2287 2312 2288 static phys_addr_t ··· 2637 2611 /* Probing and initialisation functions */ 2638 2612 static int arm_smmu_init_one_queue(struct arm_smmu_device *smmu, 2639 2613 struct arm_smmu_queue *q, 2614 + void __iomem *page, 2640 2615 unsigned long prod_off, 2641 2616 unsigned long cons_off, 2642 2617 size_t dwords, const char *name) ··· 2666 2639 1 << q->llq.max_n_shift, name); 2667 2640 } 2668 2641 2669 - q->prod_reg = arm_smmu_page1_fixup(prod_off, smmu); 2670 - q->cons_reg = arm_smmu_page1_fixup(cons_off, smmu); 2642 + q->prod_reg = page + prod_off; 2643 + q->cons_reg = page + cons_off; 2671 2644 q->ent_dwords = dwords; 2672 2645 2673 2646 q->q_base = Q_BASE_RWA; ··· 2711 2684 int ret; 2712 2685 2713 2686 /* cmdq */ 2714 - ret = arm_smmu_init_one_queue(smmu, &smmu->cmdq.q, ARM_SMMU_CMDQ_PROD, 2715 - ARM_SMMU_CMDQ_CONS, CMDQ_ENT_DWORDS, 2716 - "cmdq"); 2687 + ret = arm_smmu_init_one_queue(smmu, &smmu->cmdq.q, smmu->base, 2688 + ARM_SMMU_CMDQ_PROD, ARM_SMMU_CMDQ_CONS, 2689 + CMDQ_ENT_DWORDS, "cmdq"); 2717 2690 if (ret) 2718 2691 return ret; 2719 2692 ··· 2722 2695 return ret; 2723 2696 2724 2697 /* evtq */ 2725 - ret = arm_smmu_init_one_queue(smmu, &smmu->evtq.q, ARM_SMMU_EVTQ_PROD, 2726 - ARM_SMMU_EVTQ_CONS, EVTQ_ENT_DWORDS, 2727 - "evtq"); 2698 + ret = arm_smmu_init_one_queue(smmu, &smmu->evtq.q, smmu->page1, 2699 + ARM_SMMU_EVTQ_PROD, ARM_SMMU_EVTQ_CONS, 2700 + EVTQ_ENT_DWORDS, "evtq"); 2728 2701 if (ret) 2729 2702 return ret; 2730 2703 ··· 2732 2705 if (!(smmu->features & ARM_SMMU_FEAT_PRI)) 2733 2706 return 0; 2734 2707 2735 - return arm_smmu_init_one_queue(smmu, &smmu->priq.q, ARM_SMMU_PRIQ_PROD, 2736 - ARM_SMMU_PRIQ_CONS, PRIQ_ENT_DWORDS, 2737 - "priq"); 2708 + return arm_smmu_init_one_queue(smmu, &smmu->priq.q, smmu->page1, 2709 + ARM_SMMU_PRIQ_PROD, ARM_SMMU_PRIQ_CONS, 2710 + PRIQ_ENT_DWORDS, "priq"); 2738 2711 } 2739 2712 2740 2713 static int arm_smmu_init_l1_strtab(struct arm_smmu_device *smmu) ··· 3087 3060 writel_relaxed(reg, smmu->base + ARM_SMMU_CR1); 3088 3061 3089 3062 /* CR2 (random crap) */ 3090 - reg = CR2_PTM | CR2_RECINVSID | CR2_E2H; 3063 + reg = CR2_PTM | CR2_RECINVSID; 3064 + 3065 + if (smmu->features & ARM_SMMU_FEAT_E2H) 3066 + reg |= CR2_E2H; 3067 + 3091 3068 writel_relaxed(reg, smmu->base + ARM_SMMU_CR2); 3092 3069 3093 3070 /* Stream table */ ··· 3130 3099 3131 3100 /* Event queue */ 3132 3101 writeq_relaxed(smmu->evtq.q.q_base, smmu->base + ARM_SMMU_EVTQ_BASE); 3133 - writel_relaxed(smmu->evtq.q.llq.prod, 3134 - arm_smmu_page1_fixup(ARM_SMMU_EVTQ_PROD, smmu)); 3135 - writel_relaxed(smmu->evtq.q.llq.cons, 3136 - arm_smmu_page1_fixup(ARM_SMMU_EVTQ_CONS, smmu)); 3102 + writel_relaxed(smmu->evtq.q.llq.prod, smmu->page1 + ARM_SMMU_EVTQ_PROD); 3103 + writel_relaxed(smmu->evtq.q.llq.cons, smmu->page1 + ARM_SMMU_EVTQ_CONS); 3137 3104 3138 3105 enables |= CR0_EVTQEN; 3139 3106 ret = arm_smmu_write_reg_sync(smmu, enables, ARM_SMMU_CR0, ··· 3146 3117 writeq_relaxed(smmu->priq.q.q_base, 3147 3118 smmu->base + ARM_SMMU_PRIQ_BASE); 3148 3119 writel_relaxed(smmu->priq.q.llq.prod, 3149 - arm_smmu_page1_fixup(ARM_SMMU_PRIQ_PROD, smmu)); 3120 + smmu->page1 + ARM_SMMU_PRIQ_PROD); 3150 3121 writel_relaxed(smmu->priq.q.llq.cons, 3151 - arm_smmu_page1_fixup(ARM_SMMU_PRIQ_CONS, smmu)); 3122 + smmu->page1 + ARM_SMMU_PRIQ_CONS); 3152 3123 3153 3124 enables |= CR0_PRIQEN; 3154 3125 ret = arm_smmu_write_reg_sync(smmu, enables, ARM_SMMU_CR0, ··· 3250 3221 smmu->options |= ARM_SMMU_OPT_MSIPOLL; 3251 3222 } 3252 3223 3253 - if (reg & IDR0_HYP) 3224 + if (reg & IDR0_HYP) { 3254 3225 smmu->features |= ARM_SMMU_FEAT_HYP; 3226 + if (cpus_have_cap(ARM64_HAS_VIRT_HOST_EXTN)) 3227 + smmu->features |= ARM_SMMU_FEAT_E2H; 3228 + } 3255 3229 3256 3230 /* 3257 3231 * The coherency feature as set by FW is used in preference to the ID ··· 3521 3489 static void __iomem *arm_smmu_ioremap(struct device *dev, resource_size_t start, 3522 3490 resource_size_t size) 3523 3491 { 3524 - struct resource res = { 3525 - .flags = IORESOURCE_MEM, 3526 - .start = start, 3527 - .end = start + size - 1, 3528 - }; 3492 + struct resource res = DEFINE_RES_MEM(start, size); 3529 3493 3530 3494 return devm_ioremap_resource(dev, &res); 3531 3495 }
+10 -4
drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h
··· 139 139 #define ARM_SMMU_CMDQ_CONS 0x9c 140 140 141 141 #define ARM_SMMU_EVTQ_BASE 0xa0 142 - #define ARM_SMMU_EVTQ_PROD 0x100a8 143 - #define ARM_SMMU_EVTQ_CONS 0x100ac 142 + #define ARM_SMMU_EVTQ_PROD 0xa8 143 + #define ARM_SMMU_EVTQ_CONS 0xac 144 144 #define ARM_SMMU_EVTQ_IRQ_CFG0 0xb0 145 145 #define ARM_SMMU_EVTQ_IRQ_CFG1 0xb8 146 146 #define ARM_SMMU_EVTQ_IRQ_CFG2 0xbc 147 147 148 148 #define ARM_SMMU_PRIQ_BASE 0xc0 149 - #define ARM_SMMU_PRIQ_PROD 0x100c8 150 - #define ARM_SMMU_PRIQ_CONS 0x100cc 149 + #define ARM_SMMU_PRIQ_PROD 0xc8 150 + #define ARM_SMMU_PRIQ_CONS 0xcc 151 151 #define ARM_SMMU_PRIQ_IRQ_CFG0 0xd0 152 152 #define ARM_SMMU_PRIQ_IRQ_CFG1 0xd8 153 153 #define ARM_SMMU_PRIQ_IRQ_CFG2 0xdc ··· 430 430 #define CMDQ_OP_TLBI_NH_ASID 0x11 431 431 #define CMDQ_OP_TLBI_NH_VA 0x12 432 432 #define CMDQ_OP_TLBI_EL2_ALL 0x20 433 + #define CMDQ_OP_TLBI_EL2_ASID 0x21 434 + #define CMDQ_OP_TLBI_EL2_VA 0x22 433 435 #define CMDQ_OP_TLBI_S12_VMALL 0x28 434 436 #define CMDQ_OP_TLBI_S2_IPA 0x2a 435 437 #define CMDQ_OP_TLBI_NSNH_ALL 0x30 ··· 606 604 #define ARM_SMMU_FEAT_RANGE_INV (1 << 15) 607 605 #define ARM_SMMU_FEAT_BTM (1 << 16) 608 606 #define ARM_SMMU_FEAT_SVA (1 << 17) 607 + #define ARM_SMMU_FEAT_E2H (1 << 18) 609 608 u32 features; 610 609 611 610 #define ARM_SMMU_OPT_SKIP_PREFETCH (1 << 0) ··· 697 694 int arm_smmu_write_ctx_desc(struct arm_smmu_domain *smmu_domain, int ssid, 698 695 struct arm_smmu_ctx_desc *cd); 699 696 void arm_smmu_tlb_inv_asid(struct arm_smmu_device *smmu, u16 asid); 697 + void arm_smmu_tlb_inv_range_asid(unsigned long iova, size_t size, int asid, 698 + size_t granule, bool leaf, 699 + struct arm_smmu_domain *smmu_domain); 700 700 bool arm_smmu_free_asid(struct arm_smmu_ctx_desc *cd); 701 701 int arm_smmu_atc_inv_domain(struct arm_smmu_domain *smmu_domain, int ssid, 702 702 unsigned long iova, size_t size);
+5
drivers/iommu/arm/arm-smmu/arm-smmu-qcom.c
··· 166 166 { .compatible = "qcom,mdss" }, 167 167 { .compatible = "qcom,sc7180-mdss" }, 168 168 { .compatible = "qcom,sc7180-mss-pil" }, 169 + { .compatible = "qcom,sc8180x-mdss" }, 169 170 { .compatible = "qcom,sdm845-mdss" }, 170 171 { .compatible = "qcom,sdm845-mss-pil" }, 171 172 { } ··· 207 206 smr = arm_smmu_gr0_read(smmu, ARM_SMMU_GR0_SMR(i)); 208 207 209 208 if (FIELD_GET(ARM_SMMU_SMR_VALID, smr)) { 209 + /* Ignore valid bit for SMR mask extraction. */ 210 + smr &= ~ARM_SMMU_SMR_VALID; 210 211 smmu->smrs[i].id = FIELD_GET(ARM_SMMU_SMR_ID, smr); 211 212 smmu->smrs[i].mask = FIELD_GET(ARM_SMMU_SMR_MASK, smr); 212 213 smmu->smrs[i].valid = true; ··· 330 327 static const struct of_device_id __maybe_unused qcom_smmu_impl_of_match[] = { 331 328 { .compatible = "qcom,msm8998-smmu-v2" }, 332 329 { .compatible = "qcom,sc7180-smmu-500" }, 330 + { .compatible = "qcom,sc8180x-smmu-500" }, 333 331 { .compatible = "qcom,sdm630-smmu-v2" }, 334 332 { .compatible = "qcom,sdm845-smmu-500" }, 335 333 { .compatible = "qcom,sm8150-smmu-500" }, 336 334 { .compatible = "qcom,sm8250-smmu-500" }, 335 + { .compatible = "qcom,sm8350-smmu-500" }, 337 336 { } 338 337 }; 339 338
+31 -34
drivers/iommu/io-pgtable-arm-v7s.c
··· 44 44 45 45 /* 46 46 * We have 32 bits total; 12 bits resolved at level 1, 8 bits at level 2, 47 - * and 12 bits in a page. With some carefully-chosen coefficients we can 48 - * hide the ugly inconsistencies behind these macros and at least let the 49 - * rest of the code pretend to be somewhat sane. 47 + * and 12 bits in a page. 48 + * MediaTek extend 2 bits to reach 34bits, 14 bits at lvl1 and 8 bits at lvl2. 50 49 */ 51 50 #define ARM_V7S_ADDR_BITS 32 52 - #define _ARM_V7S_LVL_BITS(lvl) (16 - (lvl) * 4) 53 - #define ARM_V7S_LVL_SHIFT(lvl) (ARM_V7S_ADDR_BITS - (4 + 8 * (lvl))) 51 + #define _ARM_V7S_LVL_BITS(lvl, cfg) ((lvl) == 1 ? ((cfg)->ias - 20) : 8) 52 + #define ARM_V7S_LVL_SHIFT(lvl) ((lvl) == 1 ? 20 : 12) 54 53 #define ARM_V7S_TABLE_SHIFT 10 55 54 56 - #define ARM_V7S_PTES_PER_LVL(lvl) (1 << _ARM_V7S_LVL_BITS(lvl)) 57 - #define ARM_V7S_TABLE_SIZE(lvl) \ 58 - (ARM_V7S_PTES_PER_LVL(lvl) * sizeof(arm_v7s_iopte)) 55 + #define ARM_V7S_PTES_PER_LVL(lvl, cfg) (1 << _ARM_V7S_LVL_BITS(lvl, cfg)) 56 + #define ARM_V7S_TABLE_SIZE(lvl, cfg) \ 57 + (ARM_V7S_PTES_PER_LVL(lvl, cfg) * sizeof(arm_v7s_iopte)) 59 58 60 59 #define ARM_V7S_BLOCK_SIZE(lvl) (1UL << ARM_V7S_LVL_SHIFT(lvl)) 61 60 #define ARM_V7S_LVL_MASK(lvl) ((u32)(~0U << ARM_V7S_LVL_SHIFT(lvl))) 62 61 #define ARM_V7S_TABLE_MASK ((u32)(~0U << ARM_V7S_TABLE_SHIFT)) 63 - #define _ARM_V7S_IDX_MASK(lvl) (ARM_V7S_PTES_PER_LVL(lvl) - 1) 64 - #define ARM_V7S_LVL_IDX(addr, lvl) ({ \ 62 + #define _ARM_V7S_IDX_MASK(lvl, cfg) (ARM_V7S_PTES_PER_LVL(lvl, cfg) - 1) 63 + #define ARM_V7S_LVL_IDX(addr, lvl, cfg) ({ \ 65 64 int _l = lvl; \ 66 - ((u32)(addr) >> ARM_V7S_LVL_SHIFT(_l)) & _ARM_V7S_IDX_MASK(_l); \ 65 + ((addr) >> ARM_V7S_LVL_SHIFT(_l)) & _ARM_V7S_IDX_MASK(_l, cfg); \ 67 66 }) 68 67 69 68 /* ··· 111 112 #define ARM_V7S_TEX_MASK 0x7 112 113 #define ARM_V7S_ATTR_TEX(val) (((val) & ARM_V7S_TEX_MASK) << ARM_V7S_TEX_SHIFT) 113 114 114 - /* MediaTek extend the two bits for PA 32bit/33bit */ 115 + /* MediaTek extend the bits below for PA 32bit/33bit/34bit */ 115 116 #define ARM_V7S_ATTR_MTK_PA_BIT32 BIT(9) 116 117 #define ARM_V7S_ATTR_MTK_PA_BIT33 BIT(4) 118 + #define ARM_V7S_ATTR_MTK_PA_BIT34 BIT(5) 117 119 118 120 /* *well, except for TEX on level 2 large pages, of course :( */ 119 121 #define ARM_V7S_CONT_PAGE_TEX_SHIFT 6 ··· 194 194 pte |= ARM_V7S_ATTR_MTK_PA_BIT32; 195 195 if (paddr & BIT_ULL(33)) 196 196 pte |= ARM_V7S_ATTR_MTK_PA_BIT33; 197 + if (paddr & BIT_ULL(34)) 198 + pte |= ARM_V7S_ATTR_MTK_PA_BIT34; 197 199 return pte; 198 200 } 199 201 ··· 220 218 paddr |= BIT_ULL(32); 221 219 if (pte & ARM_V7S_ATTR_MTK_PA_BIT33) 222 220 paddr |= BIT_ULL(33); 221 + if (pte & ARM_V7S_ATTR_MTK_PA_BIT34) 222 + paddr |= BIT_ULL(34); 223 223 return paddr; 224 224 } 225 225 ··· 238 234 struct device *dev = cfg->iommu_dev; 239 235 phys_addr_t phys; 240 236 dma_addr_t dma; 241 - size_t size = ARM_V7S_TABLE_SIZE(lvl); 237 + size_t size = ARM_V7S_TABLE_SIZE(lvl, cfg); 242 238 void *table = NULL; 243 239 244 240 if (lvl == 1) ··· 284 280 { 285 281 struct io_pgtable_cfg *cfg = &data->iop.cfg; 286 282 struct device *dev = cfg->iommu_dev; 287 - size_t size = ARM_V7S_TABLE_SIZE(lvl); 283 + size_t size = ARM_V7S_TABLE_SIZE(lvl, cfg); 288 284 289 285 if (!cfg->coherent_walk) 290 286 dma_unmap_single(dev, __arm_v7s_dma_addr(table), size, ··· 428 424 arm_v7s_iopte *tblp; 429 425 size_t sz = ARM_V7S_BLOCK_SIZE(lvl); 430 426 431 - tblp = ptep - ARM_V7S_LVL_IDX(iova, lvl); 427 + tblp = ptep - ARM_V7S_LVL_IDX(iova, lvl, cfg); 432 428 if (WARN_ON(__arm_v7s_unmap(data, NULL, iova + i * sz, 433 429 sz, lvl, tblp) != sz)) 434 430 return -EINVAL; ··· 481 477 int num_entries = size >> ARM_V7S_LVL_SHIFT(lvl); 482 478 483 479 /* Find our entry at the current level */ 484 - ptep += ARM_V7S_LVL_IDX(iova, lvl); 480 + ptep += ARM_V7S_LVL_IDX(iova, lvl, cfg); 485 481 486 482 /* If we can install a leaf entry at this level, then do so */ 487 483 if (num_entries) ··· 523 519 phys_addr_t paddr, size_t size, int prot, gfp_t gfp) 524 520 { 525 521 struct arm_v7s_io_pgtable *data = io_pgtable_ops_to_data(ops); 526 - struct io_pgtable *iop = &data->iop; 527 522 int ret; 528 523 529 524 if (WARN_ON(iova >= (1ULL << data->iop.cfg.ias) || ··· 538 535 * Synchronise all PTE updates for the new mapping before there's 539 536 * a chance for anything to kick off a table walk for the new iova. 540 537 */ 541 - if (iop->cfg.quirks & IO_PGTABLE_QUIRK_TLBI_ON_MAP) { 542 - io_pgtable_tlb_flush_walk(iop, iova, size, 543 - ARM_V7S_BLOCK_SIZE(2)); 544 - } else { 545 - wmb(); 546 - } 538 + wmb(); 547 539 548 540 return ret; 549 541 } ··· 548 550 struct arm_v7s_io_pgtable *data = io_pgtable_to_data(iop); 549 551 int i; 550 552 551 - for (i = 0; i < ARM_V7S_PTES_PER_LVL(1); i++) { 553 + for (i = 0; i < ARM_V7S_PTES_PER_LVL(1, &data->iop.cfg); i++) { 552 554 arm_v7s_iopte pte = data->pgd[i]; 553 555 554 556 if (ARM_V7S_PTE_IS_TABLE(pte, 1)) ··· 600 602 if (!tablep) 601 603 return 0; /* Bytes unmapped */ 602 604 603 - num_ptes = ARM_V7S_PTES_PER_LVL(2); 605 + num_ptes = ARM_V7S_PTES_PER_LVL(2, cfg); 604 606 num_entries = size >> ARM_V7S_LVL_SHIFT(2); 605 - unmap_idx = ARM_V7S_LVL_IDX(iova, 2); 607 + unmap_idx = ARM_V7S_LVL_IDX(iova, 2, cfg); 606 608 607 609 pte = arm_v7s_prot_to_pte(arm_v7s_pte_to_prot(blk_pte, 1), 2, cfg); 608 610 if (num_entries > 1) ··· 644 646 if (WARN_ON(lvl > 2)) 645 647 return 0; 646 648 647 - idx = ARM_V7S_LVL_IDX(iova, lvl); 649 + idx = ARM_V7S_LVL_IDX(iova, lvl, &iop->cfg); 648 650 ptep += idx; 649 651 do { 650 652 pte[i] = READ_ONCE(ptep[i]); ··· 715 717 { 716 718 struct arm_v7s_io_pgtable *data = io_pgtable_ops_to_data(ops); 717 719 718 - if (WARN_ON(upper_32_bits(iova))) 720 + if (WARN_ON(iova >= (1ULL << data->iop.cfg.ias))) 719 721 return 0; 720 722 721 723 return __arm_v7s_unmap(data, gather, iova, size, 1, data->pgd); ··· 730 732 u32 mask; 731 733 732 734 do { 733 - ptep += ARM_V7S_LVL_IDX(iova, ++lvl); 735 + ptep += ARM_V7S_LVL_IDX(iova, ++lvl, &data->iop.cfg); 734 736 pte = READ_ONCE(*ptep); 735 737 ptep = iopte_deref(pte, lvl, data); 736 738 } while (ARM_V7S_PTE_IS_TABLE(pte, lvl)); ··· 749 751 { 750 752 struct arm_v7s_io_pgtable *data; 751 753 752 - if (cfg->ias > ARM_V7S_ADDR_BITS) 754 + if (cfg->ias > (arm_v7s_is_mtk_enabled(cfg) ? 34 : ARM_V7S_ADDR_BITS)) 753 755 return NULL; 754 756 755 - if (cfg->oas > (arm_v7s_is_mtk_enabled(cfg) ? 34 : ARM_V7S_ADDR_BITS)) 757 + if (cfg->oas > (arm_v7s_is_mtk_enabled(cfg) ? 35 : ARM_V7S_ADDR_BITS)) 756 758 return NULL; 757 759 758 760 if (cfg->quirks & ~(IO_PGTABLE_QUIRK_ARM_NS | 759 761 IO_PGTABLE_QUIRK_NO_PERMS | 760 - IO_PGTABLE_QUIRK_TLBI_ON_MAP | 761 762 IO_PGTABLE_QUIRK_ARM_MTK_EXT | 762 763 IO_PGTABLE_QUIRK_NON_STRICT)) 763 764 return NULL; ··· 772 775 773 776 spin_lock_init(&data->split_lock); 774 777 data->l2_tables = kmem_cache_create("io-pgtable_armv7s_l2", 775 - ARM_V7S_TABLE_SIZE(2), 776 - ARM_V7S_TABLE_SIZE(2), 778 + ARM_V7S_TABLE_SIZE(2, cfg), 779 + ARM_V7S_TABLE_SIZE(2, cfg), 777 780 ARM_V7S_TABLE_SLAB_FLAGS, NULL); 778 781 if (!data->l2_tables) 779 782 goto out_free_data;
+18 -5
drivers/iommu/iommu.c
··· 2426 2426 size -= pgsize; 2427 2427 } 2428 2428 2429 - if (ops->iotlb_sync_map) 2430 - ops->iotlb_sync_map(domain); 2431 - 2432 2429 /* unroll mapping in case something went wrong */ 2433 2430 if (ret) 2434 2431 iommu_unmap(domain, orig_iova, orig_size - size); ··· 2435 2438 return ret; 2436 2439 } 2437 2440 2441 + static int _iommu_map(struct iommu_domain *domain, unsigned long iova, 2442 + phys_addr_t paddr, size_t size, int prot, gfp_t gfp) 2443 + { 2444 + const struct iommu_ops *ops = domain->ops; 2445 + int ret; 2446 + 2447 + ret = __iommu_map(domain, iova, paddr, size, prot, GFP_KERNEL); 2448 + if (ret == 0 && ops->iotlb_sync_map) 2449 + ops->iotlb_sync_map(domain, iova, size); 2450 + 2451 + return ret; 2452 + } 2453 + 2438 2454 int iommu_map(struct iommu_domain *domain, unsigned long iova, 2439 2455 phys_addr_t paddr, size_t size, int prot) 2440 2456 { 2441 2457 might_sleep(); 2442 - return __iommu_map(domain, iova, paddr, size, prot, GFP_KERNEL); 2458 + return _iommu_map(domain, iova, paddr, size, prot, GFP_KERNEL); 2443 2459 } 2444 2460 EXPORT_SYMBOL_GPL(iommu_map); 2445 2461 2446 2462 int iommu_map_atomic(struct iommu_domain *domain, unsigned long iova, 2447 2463 phys_addr_t paddr, size_t size, int prot) 2448 2464 { 2449 - return __iommu_map(domain, iova, paddr, size, prot, GFP_ATOMIC); 2465 + return _iommu_map(domain, iova, paddr, size, prot, GFP_ATOMIC); 2450 2466 } 2451 2467 EXPORT_SYMBOL_GPL(iommu_map_atomic); 2452 2468 ··· 2543 2533 struct scatterlist *sg, unsigned int nents, int prot, 2544 2534 gfp_t gfp) 2545 2535 { 2536 + const struct iommu_ops *ops = domain->ops; 2546 2537 size_t len = 0, mapped = 0; 2547 2538 phys_addr_t start; 2548 2539 unsigned int i = 0; ··· 2574 2563 sg = sg_next(sg); 2575 2564 } 2576 2565 2566 + if (ops->iotlb_sync_map) 2567 + ops->iotlb_sync_map(domain, iova, mapped); 2577 2568 return mapped; 2578 2569 2579 2570 out_err:
+9 -1
drivers/iommu/msm_iommu.c
··· 343 343 spin_lock_init(&priv->pgtlock); 344 344 345 345 priv->cfg = (struct io_pgtable_cfg) { 346 - .quirks = IO_PGTABLE_QUIRK_TLBI_ON_MAP, 347 346 .pgsize_bitmap = msm_iommu_ops.pgsize_bitmap, 348 347 .ias = 32, 349 348 .oas = 32, ··· 487 488 spin_unlock_irqrestore(&priv->pgtlock, flags); 488 489 489 490 return ret; 491 + } 492 + 493 + static void msm_iommu_sync_map(struct iommu_domain *domain, unsigned long iova, 494 + size_t size) 495 + { 496 + struct msm_priv *priv = to_msm_priv(domain); 497 + 498 + __flush_iotlb_range(iova, size, SZ_4K, false, priv); 490 499 } 491 500 492 501 static size_t msm_iommu_unmap(struct iommu_domain *domain, unsigned long iova, ··· 687 680 * kick starting the other master. 688 681 */ 689 682 .iotlb_sync = NULL, 683 + .iotlb_sync_map = msm_iommu_sync_map, 690 684 .iova_to_phys = msm_iommu_iova_to_phys, 691 685 .probe_device = msm_iommu_probe_device, 692 686 .release_device = msm_iommu_release_device,
+304 -105
drivers/iommu/mtk_iommu.c
··· 3 3 * Copyright (c) 2015-2016 MediaTek Inc. 4 4 * Author: Yong Wu <yong.wu@mediatek.com> 5 5 */ 6 + #include <linux/bitfield.h> 6 7 #include <linux/bug.h> 7 8 #include <linux/clk.h> 8 9 #include <linux/component.h> 9 10 #include <linux/device.h> 11 + #include <linux/dma-direct.h> 10 12 #include <linux/dma-iommu.h> 11 13 #include <linux/err.h> 12 14 #include <linux/interrupt.h> ··· 22 20 #include <linux/of_irq.h> 23 21 #include <linux/of_platform.h> 24 22 #include <linux/platform_device.h> 23 + #include <linux/pm_runtime.h> 25 24 #include <linux/regmap.h> 26 25 #include <linux/slab.h> 27 26 #include <linux/spinlock.h> ··· 91 88 #define F_REG_MMU1_FAULT_MASK GENMASK(13, 7) 92 89 93 90 #define REG_MMU0_FAULT_VA 0x13c 91 + #define F_MMU_INVAL_VA_31_12_MASK GENMASK(31, 12) 92 + #define F_MMU_INVAL_VA_34_32_MASK GENMASK(11, 9) 93 + #define F_MMU_INVAL_PA_34_32_MASK GENMASK(8, 6) 94 94 #define F_MMU_FAULT_VA_WRITE_BIT BIT(1) 95 95 #define F_MMU_FAULT_VA_LAYER_BIT BIT(0) 96 96 ··· 109 103 110 104 #define MTK_PROTECT_PA_ALIGN 256 111 105 112 - /* 113 - * Get the local arbiter ID and the portid within the larb arbiter 114 - * from mtk_m4u_id which is defined by MTK_M4U_ID. 115 - */ 116 - #define MTK_M4U_TO_LARB(id) (((id) >> 5) & 0xf) 117 - #define MTK_M4U_TO_PORT(id) ((id) & 0x1f) 118 - 119 106 #define HAS_4GB_MODE BIT(0) 120 107 /* HW will use the EMI clock if there isn't the "bclk". */ 121 108 #define HAS_BCLK BIT(1) ··· 118 119 #define HAS_SUB_COMM BIT(5) 119 120 #define WR_THROT_EN BIT(6) 120 121 #define HAS_LEGACY_IVRP_PADDR BIT(7) 122 + #define IOVA_34_EN BIT(8) 121 123 122 124 #define MTK_IOMMU_HAS_FLAG(pdata, _x) \ 123 125 ((((pdata)->flags) & (_x)) == (_x)) ··· 127 127 struct io_pgtable_cfg cfg; 128 128 struct io_pgtable_ops *iop; 129 129 130 + struct mtk_iommu_data *data; 130 131 struct iommu_domain domain; 131 132 }; 132 133 133 134 static const struct iommu_ops mtk_iommu_ops; 135 + 136 + static int mtk_iommu_hw_init(const struct mtk_iommu_data *data); 137 + 138 + #define MTK_IOMMU_TLB_ADDR(iova) ({ \ 139 + dma_addr_t _addr = iova; \ 140 + ((lower_32_bits(_addr) & GENMASK(31, 12)) | upper_32_bits(_addr));\ 141 + }) 134 142 135 143 /* 136 144 * In M4U 4GB mode, the physical address is remapped as below: ··· 168 160 169 161 #define for_each_m4u(data) list_for_each_entry(data, &m4ulist, list) 170 162 163 + struct mtk_iommu_iova_region { 164 + dma_addr_t iova_base; 165 + unsigned long long size; 166 + }; 167 + 168 + static const struct mtk_iommu_iova_region single_domain[] = { 169 + {.iova_base = 0, .size = SZ_4G}, 170 + }; 171 + 172 + static const struct mtk_iommu_iova_region mt8192_multi_dom[] = { 173 + { .iova_base = 0x0, .size = SZ_4G}, /* disp: 0 ~ 4G */ 174 + #if IS_ENABLED(CONFIG_ARCH_DMA_ADDR_T_64BIT) 175 + { .iova_base = SZ_4G, .size = SZ_4G}, /* vdec: 4G ~ 8G */ 176 + { .iova_base = SZ_4G * 2, .size = SZ_4G}, /* CAM/MDP: 8G ~ 12G */ 177 + { .iova_base = 0x240000000ULL, .size = 0x4000000}, /* CCU0 */ 178 + { .iova_base = 0x244000000ULL, .size = 0x4000000}, /* CCU1 */ 179 + #endif 180 + }; 181 + 171 182 /* 172 183 * There may be 1 or 2 M4U HWs, But we always expect they are in the same domain 173 184 * for the performance. ··· 209 182 return container_of(dom, struct mtk_iommu_domain, domain); 210 183 } 211 184 212 - static void mtk_iommu_tlb_flush_all(void *cookie) 185 + static void mtk_iommu_tlb_flush_all(struct mtk_iommu_data *data) 213 186 { 214 - struct mtk_iommu_data *data = cookie; 215 - 216 187 for_each_m4u(data) { 188 + if (pm_runtime_get_if_in_use(data->dev) <= 0) 189 + continue; 190 + 217 191 writel_relaxed(F_INVLD_EN1 | F_INVLD_EN0, 218 192 data->base + data->plat_data->inv_sel_reg); 219 193 writel_relaxed(F_ALL_INVLD, data->base + REG_MMU_INVALIDATE); 220 194 wmb(); /* Make sure the tlb flush all done */ 195 + 196 + pm_runtime_put(data->dev); 221 197 } 222 198 } 223 199 224 200 static void mtk_iommu_tlb_flush_range_sync(unsigned long iova, size_t size, 225 - size_t granule, void *cookie) 201 + size_t granule, 202 + struct mtk_iommu_data *data) 226 203 { 227 - struct mtk_iommu_data *data = cookie; 204 + bool has_pm = !!data->dev->pm_domain; 228 205 unsigned long flags; 229 206 int ret; 230 207 u32 tmp; 231 208 232 209 for_each_m4u(data) { 210 + if (has_pm) { 211 + if (pm_runtime_get_if_in_use(data->dev) <= 0) 212 + continue; 213 + } 214 + 233 215 spin_lock_irqsave(&data->tlb_lock, flags); 234 216 writel_relaxed(F_INVLD_EN1 | F_INVLD_EN0, 235 217 data->base + data->plat_data->inv_sel_reg); 236 218 237 - writel_relaxed(iova, data->base + REG_MMU_INVLD_START_A); 238 - writel_relaxed(iova + size - 1, 219 + writel_relaxed(MTK_IOMMU_TLB_ADDR(iova), 220 + data->base + REG_MMU_INVLD_START_A); 221 + writel_relaxed(MTK_IOMMU_TLB_ADDR(iova + size - 1), 239 222 data->base + REG_MMU_INVLD_END_A); 240 223 writel_relaxed(F_MMU_INV_RANGE, 241 224 data->base + REG_MMU_INVALIDATE); ··· 256 219 if (ret) { 257 220 dev_warn(data->dev, 258 221 "Partial TLB flush timed out, falling back to full flush\n"); 259 - mtk_iommu_tlb_flush_all(cookie); 222 + mtk_iommu_tlb_flush_all(data); 260 223 } 261 224 /* Clear the CPE status */ 262 225 writel_relaxed(0, data->base + REG_MMU_CPE_DONE); 263 226 spin_unlock_irqrestore(&data->tlb_lock, flags); 227 + 228 + if (has_pm) 229 + pm_runtime_put(data->dev); 264 230 } 265 231 } 266 - 267 - static void mtk_iommu_tlb_flush_page_nosync(struct iommu_iotlb_gather *gather, 268 - unsigned long iova, size_t granule, 269 - void *cookie) 270 - { 271 - struct mtk_iommu_data *data = cookie; 272 - struct iommu_domain *domain = &data->m4u_dom->domain; 273 - 274 - iommu_iotlb_gather_add_page(domain, gather, iova, granule); 275 - } 276 - 277 - static const struct iommu_flush_ops mtk_iommu_flush_ops = { 278 - .tlb_flush_all = mtk_iommu_tlb_flush_all, 279 - .tlb_flush_walk = mtk_iommu_tlb_flush_range_sync, 280 - .tlb_add_page = mtk_iommu_tlb_flush_page_nosync, 281 - }; 282 232 283 233 static irqreturn_t mtk_iommu_isr(int irq, void *dev_id) 284 234 { 285 235 struct mtk_iommu_data *data = dev_id; 286 236 struct mtk_iommu_domain *dom = data->m4u_dom; 287 - u32 int_state, regval, fault_iova, fault_pa; 288 237 unsigned int fault_larb, fault_port, sub_comm = 0; 238 + u32 int_state, regval, va34_32, pa34_32; 239 + u64 fault_iova, fault_pa; 289 240 bool layer, write; 290 241 291 242 /* Read error info from registers */ ··· 289 264 } 290 265 layer = fault_iova & F_MMU_FAULT_VA_LAYER_BIT; 291 266 write = fault_iova & F_MMU_FAULT_VA_WRITE_BIT; 267 + if (MTK_IOMMU_HAS_FLAG(data->plat_data, IOVA_34_EN)) { 268 + va34_32 = FIELD_GET(F_MMU_INVAL_VA_34_32_MASK, fault_iova); 269 + pa34_32 = FIELD_GET(F_MMU_INVAL_PA_34_32_MASK, fault_iova); 270 + fault_iova = fault_iova & F_MMU_INVAL_VA_31_12_MASK; 271 + fault_iova |= (u64)va34_32 << 32; 272 + fault_pa |= (u64)pa34_32 << 32; 273 + } 274 + 292 275 fault_port = F_MMU_INT_ID_PORT_ID(regval); 293 276 if (MTK_IOMMU_HAS_FLAG(data->plat_data, HAS_SUB_COMM)) { 294 277 fault_larb = F_MMU_INT_ID_COMM_ID(regval); ··· 310 277 write ? IOMMU_FAULT_WRITE : IOMMU_FAULT_READ)) { 311 278 dev_err_ratelimited( 312 279 data->dev, 313 - "fault type=0x%x iova=0x%x pa=0x%x larb=%d port=%d layer=%d %s\n", 280 + "fault type=0x%x iova=0x%llx pa=0x%llx larb=%d port=%d layer=%d %s\n", 314 281 int_state, fault_iova, fault_pa, fault_larb, fault_port, 315 282 layer, write ? "write" : "read"); 316 283 } ··· 325 292 return IRQ_HANDLED; 326 293 } 327 294 328 - static void mtk_iommu_config(struct mtk_iommu_data *data, 329 - struct device *dev, bool enable) 295 + static int mtk_iommu_get_domain_id(struct device *dev, 296 + const struct mtk_iommu_plat_data *plat_data) 297 + { 298 + const struct mtk_iommu_iova_region *rgn = plat_data->iova_region; 299 + const struct bus_dma_region *dma_rgn = dev->dma_range_map; 300 + int i, candidate = -1; 301 + dma_addr_t dma_end; 302 + 303 + if (!dma_rgn || plat_data->iova_region_nr == 1) 304 + return 0; 305 + 306 + dma_end = dma_rgn->dma_start + dma_rgn->size - 1; 307 + for (i = 0; i < plat_data->iova_region_nr; i++, rgn++) { 308 + /* Best fit. */ 309 + if (dma_rgn->dma_start == rgn->iova_base && 310 + dma_end == rgn->iova_base + rgn->size - 1) 311 + return i; 312 + /* ok if it is inside this region. */ 313 + if (dma_rgn->dma_start >= rgn->iova_base && 314 + dma_end < rgn->iova_base + rgn->size) 315 + candidate = i; 316 + } 317 + 318 + if (candidate >= 0) 319 + return candidate; 320 + dev_err(dev, "Can NOT find the iommu domain id(%pad 0x%llx).\n", 321 + &dma_rgn->dma_start, dma_rgn->size); 322 + return -EINVAL; 323 + } 324 + 325 + static void mtk_iommu_config(struct mtk_iommu_data *data, struct device *dev, 326 + bool enable, unsigned int domid) 330 327 { 331 328 struct mtk_smi_larb_iommu *larb_mmu; 332 329 unsigned int larbid, portid; 333 330 struct iommu_fwspec *fwspec = dev_iommu_fwspec_get(dev); 331 + const struct mtk_iommu_iova_region *region; 334 332 int i; 335 333 336 334 for (i = 0; i < fwspec->num_ids; ++i) { 337 335 larbid = MTK_M4U_TO_LARB(fwspec->ids[i]); 338 336 portid = MTK_M4U_TO_PORT(fwspec->ids[i]); 337 + 339 338 larb_mmu = &data->larb_imu[larbid]; 340 339 341 - dev_dbg(dev, "%s iommu port: %d\n", 342 - enable ? "enable" : "disable", portid); 340 + region = data->plat_data->iova_region + domid; 341 + larb_mmu->bank[portid] = upper_32_bits(region->iova_base); 342 + 343 + dev_dbg(dev, "%s iommu for larb(%s) port %d dom %d bank %d.\n", 344 + enable ? "enable" : "disable", dev_name(larb_mmu->dev), 345 + portid, domid, larb_mmu->bank[portid]); 343 346 344 347 if (enable) 345 348 larb_mmu->mmu |= MTK_SMI_MMU_EN(portid); ··· 384 315 } 385 316 } 386 317 387 - static int mtk_iommu_domain_finalise(struct mtk_iommu_domain *dom) 318 + static int mtk_iommu_domain_finalise(struct mtk_iommu_domain *dom, 319 + struct mtk_iommu_data *data, 320 + unsigned int domid) 388 321 { 389 - struct mtk_iommu_data *data = mtk_iommu_get_m4u_data(); 322 + const struct mtk_iommu_iova_region *region; 323 + 324 + /* Use the exist domain as there is only one pgtable here. */ 325 + if (data->m4u_dom) { 326 + dom->iop = data->m4u_dom->iop; 327 + dom->cfg = data->m4u_dom->cfg; 328 + dom->domain.pgsize_bitmap = data->m4u_dom->cfg.pgsize_bitmap; 329 + goto update_iova_region; 330 + } 390 331 391 332 dom->cfg = (struct io_pgtable_cfg) { 392 333 .quirks = IO_PGTABLE_QUIRK_ARM_NS | 393 334 IO_PGTABLE_QUIRK_NO_PERMS | 394 - IO_PGTABLE_QUIRK_TLBI_ON_MAP | 395 335 IO_PGTABLE_QUIRK_ARM_MTK_EXT, 396 336 .pgsize_bitmap = mtk_iommu_ops.pgsize_bitmap, 397 - .ias = 32, 398 - .oas = 34, 399 - .tlb = &mtk_iommu_flush_ops, 337 + .ias = MTK_IOMMU_HAS_FLAG(data->plat_data, IOVA_34_EN) ? 34 : 32, 400 338 .iommu_dev = data->dev, 401 339 }; 340 + 341 + if (MTK_IOMMU_HAS_FLAG(data->plat_data, HAS_4GB_MODE)) 342 + dom->cfg.oas = data->enable_4GB ? 33 : 32; 343 + else 344 + dom->cfg.oas = 35; 402 345 403 346 dom->iop = alloc_io_pgtable_ops(ARM_V7S, &dom->cfg, data); 404 347 if (!dom->iop) { ··· 420 339 421 340 /* Update our support page sizes bitmap */ 422 341 dom->domain.pgsize_bitmap = dom->cfg.pgsize_bitmap; 342 + 343 + update_iova_region: 344 + /* Update the iova region for this domain */ 345 + region = data->plat_data->iova_region + domid; 346 + dom->domain.geometry.aperture_start = region->iova_base; 347 + dom->domain.geometry.aperture_end = region->iova_base + region->size - 1; 348 + dom->domain.geometry.force_aperture = true; 423 349 return 0; 424 350 } 425 351 ··· 441 353 if (!dom) 442 354 return NULL; 443 355 444 - if (iommu_get_dma_cookie(&dom->domain)) 445 - goto free_dom; 446 - 447 - if (mtk_iommu_domain_finalise(dom)) 448 - goto put_dma_cookie; 449 - 450 - dom->domain.geometry.aperture_start = 0; 451 - dom->domain.geometry.aperture_end = DMA_BIT_MASK(32); 452 - dom->domain.geometry.force_aperture = true; 356 + if (iommu_get_dma_cookie(&dom->domain)) { 357 + kfree(dom); 358 + return NULL; 359 + } 453 360 454 361 return &dom->domain; 455 - 456 - put_dma_cookie: 457 - iommu_put_dma_cookie(&dom->domain); 458 - free_dom: 459 - kfree(dom); 460 - return NULL; 461 362 } 462 363 463 364 static void mtk_iommu_domain_free(struct iommu_domain *domain) 464 365 { 465 - struct mtk_iommu_domain *dom = to_mtk_domain(domain); 466 - 467 - free_io_pgtable_ops(dom->iop); 468 366 iommu_put_dma_cookie(domain); 469 367 kfree(to_mtk_domain(domain)); 470 368 } ··· 460 386 { 461 387 struct mtk_iommu_data *data = dev_iommu_priv_get(dev); 462 388 struct mtk_iommu_domain *dom = to_mtk_domain(domain); 389 + struct device *m4udev = data->dev; 390 + int ret, domid; 463 391 464 - if (!data) 465 - return -ENODEV; 392 + domid = mtk_iommu_get_domain_id(dev, data->plat_data); 393 + if (domid < 0) 394 + return domid; 466 395 467 - /* Update the pgtable base address register of the M4U HW */ 468 - if (!data->m4u_dom) { 396 + if (!dom->data) { 397 + if (mtk_iommu_domain_finalise(dom, data, domid)) 398 + return -ENODEV; 399 + dom->data = data; 400 + } 401 + 402 + if (!data->m4u_dom) { /* Initialize the M4U HW */ 403 + ret = pm_runtime_resume_and_get(m4udev); 404 + if (ret < 0) 405 + return ret; 406 + 407 + ret = mtk_iommu_hw_init(data); 408 + if (ret) { 409 + pm_runtime_put(m4udev); 410 + return ret; 411 + } 469 412 data->m4u_dom = dom; 470 413 writel(dom->cfg.arm_v7s_cfg.ttbr & MMU_PT_ADDR_MASK, 471 414 data->base + REG_MMU_PT_BASE_ADDR); 415 + 416 + pm_runtime_put(m4udev); 472 417 } 473 418 474 - mtk_iommu_config(data, dev, true); 419 + mtk_iommu_config(data, dev, true, domid); 475 420 return 0; 476 421 } 477 422 ··· 499 406 { 500 407 struct mtk_iommu_data *data = dev_iommu_priv_get(dev); 501 408 502 - if (!data) 503 - return; 504 - 505 - mtk_iommu_config(data, dev, false); 409 + mtk_iommu_config(data, dev, false, 0); 506 410 } 507 411 508 412 static int mtk_iommu_map(struct iommu_domain *domain, unsigned long iova, 509 413 phys_addr_t paddr, size_t size, int prot, gfp_t gfp) 510 414 { 511 415 struct mtk_iommu_domain *dom = to_mtk_domain(domain); 512 - struct mtk_iommu_data *data = mtk_iommu_get_m4u_data(); 513 416 514 417 /* The "4GB mode" M4U physically can not use the lower remap of Dram. */ 515 - if (data->enable_4GB) 418 + if (dom->data->enable_4GB) 516 419 paddr |= BIT_ULL(32); 517 420 518 421 /* Synchronize with the tlb_lock */ ··· 520 431 struct iommu_iotlb_gather *gather) 521 432 { 522 433 struct mtk_iommu_domain *dom = to_mtk_domain(domain); 434 + unsigned long end = iova + size - 1; 523 435 436 + if (gather->start > iova) 437 + gather->start = iova; 438 + if (gather->end < end) 439 + gather->end = end; 524 440 return dom->iop->unmap(dom->iop, iova, size, gather); 525 441 } 526 442 527 443 static void mtk_iommu_flush_iotlb_all(struct iommu_domain *domain) 528 444 { 529 - mtk_iommu_tlb_flush_all(mtk_iommu_get_m4u_data()); 445 + struct mtk_iommu_domain *dom = to_mtk_domain(domain); 446 + 447 + mtk_iommu_tlb_flush_all(dom->data); 530 448 } 531 449 532 450 static void mtk_iommu_iotlb_sync(struct iommu_domain *domain, 533 451 struct iommu_iotlb_gather *gather) 534 452 { 535 - struct mtk_iommu_data *data = mtk_iommu_get_m4u_data(); 536 - size_t length = gather->end - gather->start; 537 - 538 - if (gather->start == ULONG_MAX) 539 - return; 453 + struct mtk_iommu_domain *dom = to_mtk_domain(domain); 454 + size_t length = gather->end - gather->start + 1; 540 455 541 456 mtk_iommu_tlb_flush_range_sync(gather->start, length, gather->pgsize, 542 - data); 457 + dom->data); 458 + } 459 + 460 + static void mtk_iommu_sync_map(struct iommu_domain *domain, unsigned long iova, 461 + size_t size) 462 + { 463 + struct mtk_iommu_domain *dom = to_mtk_domain(domain); 464 + 465 + mtk_iommu_tlb_flush_range_sync(iova, size, size, dom->data); 543 466 } 544 467 545 468 static phys_addr_t mtk_iommu_iova_to_phys(struct iommu_domain *domain, 546 469 dma_addr_t iova) 547 470 { 548 471 struct mtk_iommu_domain *dom = to_mtk_domain(domain); 549 - struct mtk_iommu_data *data = mtk_iommu_get_m4u_data(); 550 472 phys_addr_t pa; 551 473 552 474 pa = dom->iop->iova_to_phys(dom->iop, iova); 553 - if (data->enable_4GB && pa >= MTK_IOMMU_4GB_MODE_REMAP_BASE) 475 + if (dom->data->enable_4GB && pa >= MTK_IOMMU_4GB_MODE_REMAP_BASE) 554 476 pa &= ~BIT_ULL(32); 555 477 556 478 return pa; ··· 593 493 static struct iommu_group *mtk_iommu_device_group(struct device *dev) 594 494 { 595 495 struct mtk_iommu_data *data = mtk_iommu_get_m4u_data(); 496 + struct iommu_group *group; 497 + int domid; 596 498 597 499 if (!data) 598 500 return ERR_PTR(-ENODEV); 599 501 600 - /* All the client devices are in the same m4u iommu-group */ 601 - if (!data->m4u_group) { 602 - data->m4u_group = iommu_group_alloc(); 603 - if (IS_ERR(data->m4u_group)) 604 - dev_err(dev, "Failed to allocate M4U IOMMU group\n"); 502 + domid = mtk_iommu_get_domain_id(dev, data->plat_data); 503 + if (domid < 0) 504 + return ERR_PTR(domid); 505 + 506 + group = data->m4u_group[domid]; 507 + if (!group) { 508 + group = iommu_group_alloc(); 509 + if (!IS_ERR(group)) 510 + data->m4u_group[domid] = group; 605 511 } else { 606 - iommu_group_ref_get(data->m4u_group); 512 + iommu_group_ref_get(group); 607 513 } 608 - return data->m4u_group; 514 + return group; 609 515 } 610 516 611 517 static int mtk_iommu_of_xlate(struct device *dev, struct of_phandle_args *args) ··· 636 530 return iommu_fwspec_add_ids(dev, args->args, 1); 637 531 } 638 532 533 + static void mtk_iommu_get_resv_regions(struct device *dev, 534 + struct list_head *head) 535 + { 536 + struct mtk_iommu_data *data = dev_iommu_priv_get(dev); 537 + unsigned int domid = mtk_iommu_get_domain_id(dev, data->plat_data), i; 538 + const struct mtk_iommu_iova_region *resv, *curdom; 539 + struct iommu_resv_region *region; 540 + int prot = IOMMU_WRITE | IOMMU_READ; 541 + 542 + if (domid < 0) 543 + return; 544 + curdom = data->plat_data->iova_region + domid; 545 + for (i = 0; i < data->plat_data->iova_region_nr; i++) { 546 + resv = data->plat_data->iova_region + i; 547 + 548 + /* Only reserve when the region is inside the current domain */ 549 + if (resv->iova_base <= curdom->iova_base || 550 + resv->iova_base + resv->size >= curdom->iova_base + curdom->size) 551 + continue; 552 + 553 + region = iommu_alloc_resv_region(resv->iova_base, resv->size, 554 + prot, IOMMU_RESV_RESERVED); 555 + if (!region) 556 + return; 557 + 558 + list_add_tail(&region->list, head); 559 + } 560 + } 561 + 639 562 static const struct iommu_ops mtk_iommu_ops = { 640 563 .domain_alloc = mtk_iommu_domain_alloc, 641 564 .domain_free = mtk_iommu_domain_free, ··· 674 539 .unmap = mtk_iommu_unmap, 675 540 .flush_iotlb_all = mtk_iommu_flush_iotlb_all, 676 541 .iotlb_sync = mtk_iommu_iotlb_sync, 542 + .iotlb_sync_map = mtk_iommu_sync_map, 677 543 .iova_to_phys = mtk_iommu_iova_to_phys, 678 544 .probe_device = mtk_iommu_probe_device, 679 545 .release_device = mtk_iommu_release_device, 680 546 .device_group = mtk_iommu_device_group, 681 547 .of_xlate = mtk_iommu_of_xlate, 548 + .get_resv_regions = mtk_iommu_get_resv_regions, 549 + .put_resv_regions = generic_iommu_put_resv_regions, 682 550 .pgsize_bitmap = SZ_4K | SZ_64K | SZ_1M | SZ_16M, 683 551 }; 684 552 ··· 777 639 { 778 640 struct mtk_iommu_data *data; 779 641 struct device *dev = &pdev->dev; 642 + struct device_node *larbnode, *smicomm_node; 643 + struct platform_device *plarbdev; 644 + struct device_link *link; 780 645 struct resource *res; 781 646 resource_size_t ioaddr; 782 647 struct component_match *match = NULL; ··· 846 705 return larb_nr; 847 706 848 707 for (i = 0; i < larb_nr; i++) { 849 - struct device_node *larbnode; 850 - struct platform_device *plarbdev; 851 708 u32 id; 852 709 853 710 larbnode = of_parse_phandle(dev->of_node, "mediatek,larbs", i); ··· 872 733 compare_of, larbnode); 873 734 } 874 735 875 - platform_set_drvdata(pdev, data); 736 + /* Get smi-common dev from the last larb. */ 737 + smicomm_node = of_parse_phandle(larbnode, "mediatek,smi", 0); 738 + if (!smicomm_node) 739 + return -EINVAL; 876 740 877 - ret = mtk_iommu_hw_init(data); 878 - if (ret) 879 - return ret; 741 + plarbdev = of_find_device_by_node(smicomm_node); 742 + of_node_put(smicomm_node); 743 + data->smicomm_dev = &plarbdev->dev; 744 + 745 + pm_runtime_enable(dev); 746 + 747 + link = device_link_add(data->smicomm_dev, dev, 748 + DL_FLAG_STATELESS | DL_FLAG_PM_RUNTIME); 749 + if (!link) { 750 + dev_err(dev, "Unable link %s.\n", dev_name(data->smicomm_dev)); 751 + goto out_runtime_disable; 752 + } 753 + 754 + platform_set_drvdata(pdev, data); 880 755 881 756 ret = iommu_device_sysfs_add(&data->iommu, dev, NULL, 882 757 "mtk-iommu.%pa", &ioaddr); 883 758 if (ret) 884 - return ret; 759 + goto out_link_remove; 885 760 886 761 iommu_device_set_ops(&data->iommu, &mtk_iommu_ops); 887 762 iommu_device_set_fwnode(&data->iommu, &pdev->dev.of_node->fwnode); 888 763 889 764 ret = iommu_device_register(&data->iommu); 890 765 if (ret) 891 - return ret; 766 + goto out_sysfs_remove; 892 767 893 768 spin_lock_init(&data->tlb_lock); 894 769 list_add_tail(&data->list, &m4ulist); 895 770 896 - if (!iommu_present(&platform_bus_type)) 897 - bus_set_iommu(&platform_bus_type, &mtk_iommu_ops); 771 + if (!iommu_present(&platform_bus_type)) { 772 + ret = bus_set_iommu(&platform_bus_type, &mtk_iommu_ops); 773 + if (ret) 774 + goto out_list_del; 775 + } 898 776 899 - return component_master_add_with_match(dev, &mtk_iommu_com_ops, match); 777 + ret = component_master_add_with_match(dev, &mtk_iommu_com_ops, match); 778 + if (ret) 779 + goto out_bus_set_null; 780 + return ret; 781 + 782 + out_bus_set_null: 783 + bus_set_iommu(&platform_bus_type, NULL); 784 + out_list_del: 785 + list_del(&data->list); 786 + iommu_device_unregister(&data->iommu); 787 + out_sysfs_remove: 788 + iommu_device_sysfs_remove(&data->iommu); 789 + out_link_remove: 790 + device_link_remove(data->smicomm_dev, dev); 791 + out_runtime_disable: 792 + pm_runtime_disable(dev); 793 + return ret; 900 794 } 901 795 902 796 static int mtk_iommu_remove(struct platform_device *pdev) ··· 943 771 bus_set_iommu(&platform_bus_type, NULL); 944 772 945 773 clk_disable_unprepare(data->bclk); 774 + device_link_remove(data->smicomm_dev, &pdev->dev); 775 + pm_runtime_disable(&pdev->dev); 946 776 devm_free_irq(&pdev->dev, data->irq, data); 947 777 component_master_del(&pdev->dev, &mtk_iommu_com_ops); 948 778 return 0; 949 779 } 950 780 951 - static int __maybe_unused mtk_iommu_suspend(struct device *dev) 781 + static int __maybe_unused mtk_iommu_runtime_suspend(struct device *dev) 952 782 { 953 783 struct mtk_iommu_data *data = dev_get_drvdata(dev); 954 784 struct mtk_iommu_suspend_reg *reg = &data->reg; ··· 968 794 return 0; 969 795 } 970 796 971 - static int __maybe_unused mtk_iommu_resume(struct device *dev) 797 + static int __maybe_unused mtk_iommu_runtime_resume(struct device *dev) 972 798 { 973 799 struct mtk_iommu_data *data = dev_get_drvdata(dev); 974 800 struct mtk_iommu_suspend_reg *reg = &data->reg; ··· 976 802 void __iomem *base = data->base; 977 803 int ret; 978 804 805 + /* Avoid first resume to affect the default value of registers below. */ 806 + if (!m4u_dom) 807 + return 0; 979 808 ret = clk_prepare_enable(data->bclk); 980 809 if (ret) { 981 810 dev_err(data->dev, "Failed to enable clk(%d) in resume\n", ret); ··· 992 815 writel_relaxed(reg->int_main_control, base + REG_MMU_INT_MAIN_CONTROL); 993 816 writel_relaxed(reg->ivrp_paddr, base + REG_MMU_IVRP_PADDR); 994 817 writel_relaxed(reg->vld_pa_rng, base + REG_MMU_VLD_PA_RNG); 995 - if (m4u_dom) 996 - writel(m4u_dom->cfg.arm_v7s_cfg.ttbr & MMU_PT_ADDR_MASK, 997 - base + REG_MMU_PT_BASE_ADDR); 818 + writel(m4u_dom->cfg.arm_v7s_cfg.ttbr & MMU_PT_ADDR_MASK, base + REG_MMU_PT_BASE_ADDR); 998 819 return 0; 999 820 } 1000 821 1001 822 static const struct dev_pm_ops mtk_iommu_pm_ops = { 1002 - SET_NOIRQ_SYSTEM_SLEEP_PM_OPS(mtk_iommu_suspend, mtk_iommu_resume) 823 + SET_RUNTIME_PM_OPS(mtk_iommu_runtime_suspend, mtk_iommu_runtime_resume, NULL) 824 + SET_LATE_SYSTEM_SLEEP_PM_OPS(pm_runtime_force_suspend, 825 + pm_runtime_force_resume) 1003 826 }; 1004 827 1005 828 static const struct mtk_iommu_plat_data mt2712_data = { 1006 829 .m4u_plat = M4U_MT2712, 1007 830 .flags = HAS_4GB_MODE | HAS_BCLK | HAS_VLD_PA_RNG, 1008 831 .inv_sel_reg = REG_MMU_INV_SEL_GEN1, 832 + .iova_region = single_domain, 833 + .iova_region_nr = ARRAY_SIZE(single_domain), 1009 834 .larbid_remap = {{0}, {1}, {2}, {3}, {4}, {5}, {6}, {7}}, 1010 835 }; 1011 836 ··· 1015 836 .m4u_plat = M4U_MT6779, 1016 837 .flags = HAS_SUB_COMM | OUT_ORDER_WR_EN | WR_THROT_EN, 1017 838 .inv_sel_reg = REG_MMU_INV_SEL_GEN2, 839 + .iova_region = single_domain, 840 + .iova_region_nr = ARRAY_SIZE(single_domain), 1018 841 .larbid_remap = {{0}, {1}, {2}, {3}, {5}, {7, 8}, {10}, {9}}, 1019 842 }; 1020 843 ··· 1024 843 .m4u_plat = M4U_MT8167, 1025 844 .flags = RESET_AXI | HAS_LEGACY_IVRP_PADDR, 1026 845 .inv_sel_reg = REG_MMU_INV_SEL_GEN1, 846 + .iova_region = single_domain, 847 + .iova_region_nr = ARRAY_SIZE(single_domain), 1027 848 .larbid_remap = {{0}, {1}, {2}}, /* Linear mapping. */ 1028 849 }; 1029 850 ··· 1034 851 .flags = HAS_4GB_MODE | HAS_BCLK | RESET_AXI | 1035 852 HAS_LEGACY_IVRP_PADDR, 1036 853 .inv_sel_reg = REG_MMU_INV_SEL_GEN1, 854 + .iova_region = single_domain, 855 + .iova_region_nr = ARRAY_SIZE(single_domain), 1037 856 .larbid_remap = {{0}, {1}, {2}, {3}, {4}, {5}}, /* Linear mapping. */ 1038 857 }; 1039 858 ··· 1043 858 .m4u_plat = M4U_MT8183, 1044 859 .flags = RESET_AXI, 1045 860 .inv_sel_reg = REG_MMU_INV_SEL_GEN1, 861 + .iova_region = single_domain, 862 + .iova_region_nr = ARRAY_SIZE(single_domain), 1046 863 .larbid_remap = {{0}, {4}, {5}, {6}, {7}, {2}, {3}, {1}}, 864 + }; 865 + 866 + static const struct mtk_iommu_plat_data mt8192_data = { 867 + .m4u_plat = M4U_MT8192, 868 + .flags = HAS_BCLK | HAS_SUB_COMM | OUT_ORDER_WR_EN | 869 + WR_THROT_EN | IOVA_34_EN, 870 + .inv_sel_reg = REG_MMU_INV_SEL_GEN2, 871 + .iova_region = mt8192_multi_dom, 872 + .iova_region_nr = ARRAY_SIZE(mt8192_multi_dom), 873 + .larbid_remap = {{0}, {1}, {4, 5}, {7}, {2}, {9, 11, 19, 20}, 874 + {0, 14, 16}, {0, 13, 18, 17}}, 1047 875 }; 1048 876 1049 877 static const struct of_device_id mtk_iommu_of_ids[] = { ··· 1065 867 { .compatible = "mediatek,mt8167-m4u", .data = &mt8167_data}, 1066 868 { .compatible = "mediatek,mt8173-m4u", .data = &mt8173_data}, 1067 869 { .compatible = "mediatek,mt8183-m4u", .data = &mt8183_data}, 870 + { .compatible = "mediatek,mt8192-m4u", .data = &mt8192_data}, 1068 871 {} 1069 872 }; 1070 873
+11 -1
drivers/iommu/mtk_iommu.h
··· 17 17 #include <linux/spinlock.h> 18 18 #include <linux/dma-mapping.h> 19 19 #include <soc/mediatek/smi.h> 20 + #include <dt-bindings/memory/mtk-memory-port.h> 20 21 21 22 #define MTK_LARB_COM_MAX 8 22 23 #define MTK_LARB_SUBCOM_MAX 4 24 + 25 + #define MTK_IOMMU_GROUP_MAX 8 23 26 24 27 struct mtk_iommu_suspend_reg { 25 28 union { ··· 45 42 M4U_MT8167, 46 43 M4U_MT8173, 47 44 M4U_MT8183, 45 + M4U_MT8192, 48 46 }; 47 + 48 + struct mtk_iommu_iova_region; 49 49 50 50 struct mtk_iommu_plat_data { 51 51 enum mtk_iommu_plat m4u_plat; 52 52 u32 flags; 53 53 u32 inv_sel_reg; 54 + 55 + unsigned int iova_region_nr; 56 + const struct mtk_iommu_iova_region *iova_region; 54 57 unsigned char larbid_remap[MTK_LARB_COM_MAX][MTK_LARB_SUBCOM_MAX]; 55 58 }; 56 59 ··· 70 61 phys_addr_t protect_base; /* protect memory base */ 71 62 struct mtk_iommu_suspend_reg reg; 72 63 struct mtk_iommu_domain *m4u_dom; 73 - struct iommu_group *m4u_group; 64 + struct iommu_group *m4u_group[MTK_IOMMU_GROUP_MAX]; 74 65 bool enable_4GB; 75 66 spinlock_t tlb_lock; /* lock for tlb range flush */ 76 67 77 68 struct iommu_device iommu; 78 69 const struct mtk_iommu_plat_data *plat_data; 70 + struct device *smicomm_dev; 79 71 80 72 struct dma_iommu_mapping *mapping; /* For mtk_iommu_v1.c */ 81 73
+5 -2
drivers/iommu/tegra-gart.c
··· 261 261 return 0; 262 262 } 263 263 264 - static void gart_iommu_sync_map(struct iommu_domain *domain) 264 + static void gart_iommu_sync_map(struct iommu_domain *domain, unsigned long iova, 265 + size_t size) 265 266 { 266 267 FLUSH_GART_REGS(gart_handle); 267 268 } ··· 270 269 static void gart_iommu_sync(struct iommu_domain *domain, 271 270 struct iommu_iotlb_gather *gather) 272 271 { 273 - gart_iommu_sync_map(domain); 272 + size_t length = gather->end - gather->start + 1; 273 + 274 + gart_iommu_sync_map(domain, gather->start, length); 274 275 } 275 276 276 277 static const struct iommu_ops gart_iommu_ops = {
+8
drivers/memory/mtk-smi.c
··· 15 15 #include <linux/pm_runtime.h> 16 16 #include <soc/mediatek/smi.h> 17 17 #include <dt-bindings/memory/mt2701-larb-port.h> 18 + #include <dt-bindings/memory/mtk-memory-port.h> 18 19 19 20 /* mt8173 */ 20 21 #define SMI_LARB_MMU_EN 0xf00 ··· 44 43 /* mt2712 */ 45 44 #define SMI_LARB_NONSEC_CON(id) (0x380 + ((id) * 4)) 46 45 #define F_MMU_EN BIT(0) 46 + #define BANK_SEL(id) ({ \ 47 + u32 _id = (id) & 0x3; \ 48 + (_id << 8 | _id << 10 | _id << 12 | _id << 14); \ 49 + }) 47 50 48 51 /* SMI COMMON */ 49 52 #define SMI_BUS_SEL 0x220 ··· 92 87 const struct mtk_smi_larb_gen *larb_gen; 93 88 int larbid; 94 89 u32 *mmu; 90 + unsigned char *bank; 95 91 }; 96 92 97 93 static int mtk_smi_clk_enable(const struct mtk_smi *smi) ··· 159 153 if (dev == larb_mmu[i].dev) { 160 154 larb->larbid = i; 161 155 larb->mmu = &larb_mmu[i].mmu; 156 + larb->bank = larb_mmu[i].bank; 162 157 return 0; 163 158 } 164 159 } ··· 178 171 for_each_set_bit(i, (unsigned long *)larb->mmu, 32) { 179 172 reg = readl_relaxed(larb->base + SMI_LARB_NONSEC_CON(i)); 180 173 reg |= F_MMU_EN; 174 + reg |= BANK_SEL(larb->bank[i]); 181 175 writel(reg, larb->base + SMI_LARB_NONSEC_CON(i)); 182 176 } 183 177 }
+1 -1
drivers/perf/Kconfig
··· 62 62 63 63 config ARM_SMMU_V3_PMU 64 64 tristate "ARM SMMUv3 Performance Monitors Extension" 65 - depends on ARM64 && ACPI && ARM_SMMU_V3 65 + depends on ARM64 && ACPI 66 66 help 67 67 Provides support for the ARM SMMUv3 Performance Monitor Counter 68 68 Groups (PMCG), which provide monitoring of transactions passing
+2 -2
include/dt-bindings/memory/mt2701-larb-port.h
··· 4 4 * Author: Honghui Zhang <honghui.zhang@mediatek.com> 5 5 */ 6 6 7 - #ifndef _MT2701_LARB_PORT_H_ 8 - #define _MT2701_LARB_PORT_H_ 7 + #ifndef _DT_BINDINGS_MEMORY_MT2701_LARB_PORT_H_ 8 + #define _DT_BINDINGS_MEMORY_MT2701_LARB_PORT_H_ 9 9 10 10 /* 11 11 * Mediatek m4u generation 1 such as mt2701 has flat m4u port numbers,
+3 -3
include/dt-bindings/memory/mt2712-larb-port.h
··· 3 3 * Copyright (c) 2017 MediaTek Inc. 4 4 * Author: Yong Wu <yong.wu@mediatek.com> 5 5 */ 6 - #ifndef __DTS_IOMMU_PORT_MT2712_H 7 - #define __DTS_IOMMU_PORT_MT2712_H 6 + #ifndef _DT_BINDINGS_MEMORY_MT2712_LARB_PORT_H_ 7 + #define _DT_BINDINGS_MEMORY_MT2712_LARB_PORT_H_ 8 8 9 - #define MTK_M4U_ID(larb, port) (((larb) << 5) | (port)) 9 + #include <dt-bindings/memory/mtk-memory-port.h> 10 10 11 11 #define M4U_LARB0_ID 0 12 12 #define M4U_LARB1_ID 1
+3 -3
include/dt-bindings/memory/mt6779-larb-port.h
··· 4 4 * Author: Chao Hao <chao.hao@mediatek.com> 5 5 */ 6 6 7 - #ifndef _DTS_IOMMU_PORT_MT6779_H_ 8 - #define _DTS_IOMMU_PORT_MT6779_H_ 7 + #ifndef _DT_BINDINGS_MEMORY_MT6779_LARB_PORT_H_ 8 + #define _DT_BINDINGS_MEMORY_MT6779_LARB_PORT_H_ 9 9 10 - #define MTK_M4U_ID(larb, port) (((larb) << 5) | (port)) 10 + #include <dt-bindings/memory/mtk-memory-port.h> 11 11 12 12 #define M4U_LARB0_ID 0 13 13 #define M4U_LARB1_ID 1
+3 -3
include/dt-bindings/memory/mt8167-larb-port.h
··· 5 5 * Author: Honghui Zhang <honghui.zhang@mediatek.com> 6 6 * Author: Fabien Parent <fparent@baylibre.com> 7 7 */ 8 - #ifndef __DTS_IOMMU_PORT_MT8167_H 9 - #define __DTS_IOMMU_PORT_MT8167_H 8 + #ifndef _DT_BINDINGS_MEMORY_MT8167_LARB_PORT_H_ 9 + #define _DT_BINDINGS_MEMORY_MT8167_LARB_PORT_H_ 10 10 11 - #define MTK_M4U_ID(larb, port) (((larb) << 5) | (port)) 11 + #include <dt-bindings/memory/mtk-memory-port.h> 12 12 13 13 #define M4U_LARB0_ID 0 14 14 #define M4U_LARB1_ID 1
+3 -3
include/dt-bindings/memory/mt8173-larb-port.h
··· 3 3 * Copyright (c) 2015-2016 MediaTek Inc. 4 4 * Author: Yong Wu <yong.wu@mediatek.com> 5 5 */ 6 - #ifndef __DTS_IOMMU_PORT_MT8173_H 7 - #define __DTS_IOMMU_PORT_MT8173_H 6 + #ifndef _DT_BINDINGS_MEMORY_MT8173_LARB_PORT_H_ 7 + #define _DT_BINDINGS_MEMORY_MT8173_LARB_PORT_H_ 8 8 9 - #define MTK_M4U_ID(larb, port) (((larb) << 5) | (port)) 9 + #include <dt-bindings/memory/mtk-memory-port.h> 10 10 11 11 #define M4U_LARB0_ID 0 12 12 #define M4U_LARB1_ID 1
+3 -3
include/dt-bindings/memory/mt8183-larb-port.h
··· 3 3 * Copyright (c) 2018 MediaTek Inc. 4 4 * Author: Yong Wu <yong.wu@mediatek.com> 5 5 */ 6 - #ifndef __DTS_IOMMU_PORT_MT8183_H 7 - #define __DTS_IOMMU_PORT_MT8183_H 6 + #ifndef _DT_BINDINGS_MEMORY_MT8183_LARB_PORT_H_ 7 + #define _DT_BINDINGS_MEMORY_MT8183_LARB_PORT_H_ 8 8 9 - #define MTK_M4U_ID(larb, port) (((larb) << 5) | (port)) 9 + #include <dt-bindings/memory/mtk-memory-port.h> 10 10 11 11 #define M4U_LARB0_ID 0 12 12 #define M4U_LARB1_ID 1
+243
include/dt-bindings/memory/mt8192-larb-port.h
··· 1 + /* SPDX-License-Identifier: GPL-2.0-only */ 2 + /* 3 + * Copyright (c) 2020 MediaTek Inc. 4 + * 5 + * Author: Chao Hao <chao.hao@mediatek.com> 6 + * Author: Yong Wu <yong.wu@mediatek.com> 7 + */ 8 + #ifndef _DT_BINDINGS_MEMORY_MT8192_LARB_PORT_H_ 9 + #define _DT_BINDINGS_MEMORY_MT8192_LARB_PORT_H_ 10 + 11 + #include <dt-bindings/memory/mtk-memory-port.h> 12 + 13 + /* 14 + * MM IOMMU supports 16GB dma address. 15 + * 16 + * The address will preassign like this: 17 + * 18 + * modules dma-address-region larbs-ports 19 + * disp 0 ~ 4G larb0/1 20 + * vcodec 4G ~ 8G larb4/5/7 21 + * cam/mdp 8G ~ 12G larb2/9/11/13/14/16/17/18/19/20 22 + * CCU0 0x4000_0000 ~ 0x43ff_ffff larb13: port 9/10 23 + * CCU1 0x4400_0000 ~ 0x47ff_ffff larb14: port 4/5 24 + * 25 + * larb3/6/8/10/12/15 is null. 26 + */ 27 + 28 + /* larb0 */ 29 + #define M4U_PORT_L0_DISP_POSTMASK0 MTK_M4U_ID(0, 0) 30 + #define M4U_PORT_L0_OVL_RDMA0_HDR MTK_M4U_ID(0, 1) 31 + #define M4U_PORT_L0_OVL_RDMA0 MTK_M4U_ID(0, 2) 32 + #define M4U_PORT_L0_DISP_RDMA0 MTK_M4U_ID(0, 3) 33 + #define M4U_PORT_L0_DISP_WDMA0 MTK_M4U_ID(0, 4) 34 + #define M4U_PORT_L0_DISP_FAKE0 MTK_M4U_ID(0, 5) 35 + 36 + /* larb1 */ 37 + #define M4U_PORT_L1_OVL_2L_RDMA0_HDR MTK_M4U_ID(1, 0) 38 + #define M4U_PORT_L1_OVL_2L_RDMA2_HDR MTK_M4U_ID(1, 1) 39 + #define M4U_PORT_L1_OVL_2L_RDMA0 MTK_M4U_ID(1, 2) 40 + #define M4U_PORT_L1_OVL_2L_RDMA2 MTK_M4U_ID(1, 3) 41 + #define M4U_PORT_L1_DISP_MDP_RDMA4 MTK_M4U_ID(1, 4) 42 + #define M4U_PORT_L1_DISP_RDMA4 MTK_M4U_ID(1, 5) 43 + #define M4U_PORT_L1_DISP_UFBC_WDMA0 MTK_M4U_ID(1, 6) 44 + #define M4U_PORT_L1_DISP_FAKE1 MTK_M4U_ID(1, 7) 45 + 46 + /* larb2 */ 47 + #define M4U_PORT_L2_MDP_RDMA0 MTK_M4U_ID(2, 0) 48 + #define M4U_PORT_L2_MDP_RDMA1 MTK_M4U_ID(2, 1) 49 + #define M4U_PORT_L2_MDP_WROT0 MTK_M4U_ID(2, 2) 50 + #define M4U_PORT_L2_MDP_WROT1 MTK_M4U_ID(2, 3) 51 + #define M4U_PORT_L2_MDP_DISP_FAKE0 MTK_M4U_ID(2, 4) 52 + 53 + /* larb3: null */ 54 + 55 + /* larb4 */ 56 + #define M4U_PORT_L4_VDEC_MC_EXT MTK_M4U_ID(4, 0) 57 + #define M4U_PORT_L4_VDEC_UFO_EXT MTK_M4U_ID(4, 1) 58 + #define M4U_PORT_L4_VDEC_PP_EXT MTK_M4U_ID(4, 2) 59 + #define M4U_PORT_L4_VDEC_PRED_RD_EXT MTK_M4U_ID(4, 3) 60 + #define M4U_PORT_L4_VDEC_PRED_WR_EXT MTK_M4U_ID(4, 4) 61 + #define M4U_PORT_L4_VDEC_PPWRAP_EXT MTK_M4U_ID(4, 5) 62 + #define M4U_PORT_L4_VDEC_TILE_EXT MTK_M4U_ID(4, 6) 63 + #define M4U_PORT_L4_VDEC_VLD_EXT MTK_M4U_ID(4, 7) 64 + #define M4U_PORT_L4_VDEC_VLD2_EXT MTK_M4U_ID(4, 8) 65 + #define M4U_PORT_L4_VDEC_AVC_MV_EXT MTK_M4U_ID(4, 9) 66 + #define M4U_PORT_L4_VDEC_RG_CTRL_DMA_EXT MTK_M4U_ID(4, 10) 67 + 68 + /* larb5 */ 69 + #define M4U_PORT_L5_VDEC_LAT0_VLD_EXT MTK_M4U_ID(5, 0) 70 + #define M4U_PORT_L5_VDEC_LAT0_VLD2_EXT MTK_M4U_ID(5, 1) 71 + #define M4U_PORT_L5_VDEC_LAT0_AVC_MV_EXT MTK_M4U_ID(5, 2) 72 + #define M4U_PORT_L5_VDEC_LAT0_PRED_RD_EXT MTK_M4U_ID(5, 3) 73 + #define M4U_PORT_L5_VDEC_LAT0_TILE_EXT MTK_M4U_ID(5, 4) 74 + #define M4U_PORT_L5_VDEC_LAT0_WDMA_EXT MTK_M4U_ID(5, 5) 75 + #define M4U_PORT_L5_VDEC_LAT0_RG_CTRL_DMA_EXT MTK_M4U_ID(5, 6) 76 + #define M4U_PORT_L5_VDEC_UFO_ENC_EXT MTK_M4U_ID(5, 7) 77 + 78 + /* larb6: null */ 79 + 80 + /* larb7 */ 81 + #define M4U_PORT_L7_VENC_RCPU MTK_M4U_ID(7, 0) 82 + #define M4U_PORT_L7_VENC_REC MTK_M4U_ID(7, 1) 83 + #define M4U_PORT_L7_VENC_BSDMA MTK_M4U_ID(7, 2) 84 + #define M4U_PORT_L7_VENC_SV_COMV MTK_M4U_ID(7, 3) 85 + #define M4U_PORT_L7_VENC_RD_COMV MTK_M4U_ID(7, 4) 86 + #define M4U_PORT_L7_VENC_CUR_LUMA MTK_M4U_ID(7, 5) 87 + #define M4U_PORT_L7_VENC_CUR_CHROMA MTK_M4U_ID(7, 6) 88 + #define M4U_PORT_L7_VENC_REF_LUMA MTK_M4U_ID(7, 7) 89 + #define M4U_PORT_L7_VENC_REF_CHROMA MTK_M4U_ID(7, 8) 90 + #define M4U_PORT_L7_JPGENC_Y_RDMA MTK_M4U_ID(7, 9) 91 + #define M4U_PORT_L7_JPGENC_Q_RDMA MTK_M4U_ID(7, 10) 92 + #define M4U_PORT_L7_JPGENC_C_TABLE MTK_M4U_ID(7, 11) 93 + #define M4U_PORT_L7_JPGENC_BSDMA MTK_M4U_ID(7, 12) 94 + #define M4U_PORT_L7_VENC_SUB_R_LUMA MTK_M4U_ID(7, 13) 95 + #define M4U_PORT_L7_VENC_SUB_W_LUMA MTK_M4U_ID(7, 14) 96 + 97 + /* larb8: null */ 98 + 99 + /* larb9 */ 100 + #define M4U_PORT_L9_IMG_IMGI_D1 MTK_M4U_ID(9, 0) 101 + #define M4U_PORT_L9_IMG_IMGBI_D1 MTK_M4U_ID(9, 1) 102 + #define M4U_PORT_L9_IMG_DMGI_D1 MTK_M4U_ID(9, 2) 103 + #define M4U_PORT_L9_IMG_DEPI_D1 MTK_M4U_ID(9, 3) 104 + #define M4U_PORT_L9_IMG_ICE_D1 MTK_M4U_ID(9, 4) 105 + #define M4U_PORT_L9_IMG_SMTI_D1 MTK_M4U_ID(9, 5) 106 + #define M4U_PORT_L9_IMG_SMTO_D2 MTK_M4U_ID(9, 6) 107 + #define M4U_PORT_L9_IMG_SMTO_D1 MTK_M4U_ID(9, 7) 108 + #define M4U_PORT_L9_IMG_CRZO_D1 MTK_M4U_ID(9, 8) 109 + #define M4U_PORT_L9_IMG_IMG3O_D1 MTK_M4U_ID(9, 9) 110 + #define M4U_PORT_L9_IMG_VIPI_D1 MTK_M4U_ID(9, 10) 111 + #define M4U_PORT_L9_IMG_SMTI_D5 MTK_M4U_ID(9, 11) 112 + #define M4U_PORT_L9_IMG_TIMGO_D1 MTK_M4U_ID(9, 12) 113 + #define M4U_PORT_L9_IMG_UFBC_W0 MTK_M4U_ID(9, 13) 114 + #define M4U_PORT_L9_IMG_UFBC_R0 MTK_M4U_ID(9, 14) 115 + 116 + /* larb10: null */ 117 + 118 + /* larb11 */ 119 + #define M4U_PORT_L11_IMG_IMGI_D1 MTK_M4U_ID(11, 0) 120 + #define M4U_PORT_L11_IMG_IMGBI_D1 MTK_M4U_ID(11, 1) 121 + #define M4U_PORT_L11_IMG_DMGI_D1 MTK_M4U_ID(11, 2) 122 + #define M4U_PORT_L11_IMG_DEPI_D1 MTK_M4U_ID(11, 3) 123 + #define M4U_PORT_L11_IMG_ICE_D1 MTK_M4U_ID(11, 4) 124 + #define M4U_PORT_L11_IMG_SMTI_D1 MTK_M4U_ID(11, 5) 125 + #define M4U_PORT_L11_IMG_SMTO_D2 MTK_M4U_ID(11, 6) 126 + #define M4U_PORT_L11_IMG_SMTO_D1 MTK_M4U_ID(11, 7) 127 + #define M4U_PORT_L11_IMG_CRZO_D1 MTK_M4U_ID(11, 8) 128 + #define M4U_PORT_L11_IMG_IMG3O_D1 MTK_M4U_ID(11, 9) 129 + #define M4U_PORT_L11_IMG_VIPI_D1 MTK_M4U_ID(11, 10) 130 + #define M4U_PORT_L11_IMG_SMTI_D5 MTK_M4U_ID(11, 11) 131 + #define M4U_PORT_L11_IMG_TIMGO_D1 MTK_M4U_ID(11, 12) 132 + #define M4U_PORT_L11_IMG_UFBC_W0 MTK_M4U_ID(11, 13) 133 + #define M4U_PORT_L11_IMG_UFBC_R0 MTK_M4U_ID(11, 14) 134 + #define M4U_PORT_L11_IMG_WPE_RDMA1 MTK_M4U_ID(11, 15) 135 + #define M4U_PORT_L11_IMG_WPE_RDMA0 MTK_M4U_ID(11, 16) 136 + #define M4U_PORT_L11_IMG_WPE_WDMA MTK_M4U_ID(11, 17) 137 + #define M4U_PORT_L11_IMG_MFB_RDMA0 MTK_M4U_ID(11, 18) 138 + #define M4U_PORT_L11_IMG_MFB_RDMA1 MTK_M4U_ID(11, 19) 139 + #define M4U_PORT_L11_IMG_MFB_RDMA2 MTK_M4U_ID(11, 20) 140 + #define M4U_PORT_L11_IMG_MFB_RDMA3 MTK_M4U_ID(11, 21) 141 + #define M4U_PORT_L11_IMG_MFB_RDMA4 MTK_M4U_ID(11, 22) 142 + #define M4U_PORT_L11_IMG_MFB_RDMA5 MTK_M4U_ID(11, 23) 143 + #define M4U_PORT_L11_IMG_MFB_WDMA0 MTK_M4U_ID(11, 24) 144 + #define M4U_PORT_L11_IMG_MFB_WDMA1 MTK_M4U_ID(11, 25) 145 + 146 + /* larb12: null */ 147 + 148 + /* larb13 */ 149 + #define M4U_PORT_L13_CAM_MRAWI MTK_M4U_ID(13, 0) 150 + #define M4U_PORT_L13_CAM_MRAWO0 MTK_M4U_ID(13, 1) 151 + #define M4U_PORT_L13_CAM_MRAWO1 MTK_M4U_ID(13, 2) 152 + #define M4U_PORT_L13_CAM_CAMSV1 MTK_M4U_ID(13, 3) 153 + #define M4U_PORT_L13_CAM_CAMSV2 MTK_M4U_ID(13, 4) 154 + #define M4U_PORT_L13_CAM_CAMSV3 MTK_M4U_ID(13, 5) 155 + #define M4U_PORT_L13_CAM_CAMSV4 MTK_M4U_ID(13, 6) 156 + #define M4U_PORT_L13_CAM_CAMSV5 MTK_M4U_ID(13, 7) 157 + #define M4U_PORT_L13_CAM_CAMSV6 MTK_M4U_ID(13, 8) 158 + #define M4U_PORT_L13_CAM_CCUI MTK_M4U_ID(13, 9) 159 + #define M4U_PORT_L13_CAM_CCUO MTK_M4U_ID(13, 10) 160 + #define M4U_PORT_L13_CAM_FAKE MTK_M4U_ID(13, 11) 161 + 162 + /* larb14 */ 163 + #define M4U_PORT_L14_CAM_RESERVE1 MTK_M4U_ID(14, 0) 164 + #define M4U_PORT_L14_CAM_RESERVE2 MTK_M4U_ID(14, 1) 165 + #define M4U_PORT_L14_CAM_RESERVE3 MTK_M4U_ID(14, 2) 166 + #define M4U_PORT_L14_CAM_CAMSV0 MTK_M4U_ID(14, 3) 167 + #define M4U_PORT_L14_CAM_CCUI MTK_M4U_ID(14, 4) 168 + #define M4U_PORT_L14_CAM_CCUO MTK_M4U_ID(14, 5) 169 + 170 + /* larb15: null */ 171 + 172 + /* larb16 */ 173 + #define M4U_PORT_L16_CAM_IMGO_R1_A MTK_M4U_ID(16, 0) 174 + #define M4U_PORT_L16_CAM_RRZO_R1_A MTK_M4U_ID(16, 1) 175 + #define M4U_PORT_L16_CAM_CQI_R1_A MTK_M4U_ID(16, 2) 176 + #define M4U_PORT_L16_CAM_BPCI_R1_A MTK_M4U_ID(16, 3) 177 + #define M4U_PORT_L16_CAM_YUVO_R1_A MTK_M4U_ID(16, 4) 178 + #define M4U_PORT_L16_CAM_UFDI_R2_A MTK_M4U_ID(16, 5) 179 + #define M4U_PORT_L16_CAM_RAWI_R2_A MTK_M4U_ID(16, 6) 180 + #define M4U_PORT_L16_CAM_RAWI_R3_A MTK_M4U_ID(16, 7) 181 + #define M4U_PORT_L16_CAM_AAO_R1_A MTK_M4U_ID(16, 8) 182 + #define M4U_PORT_L16_CAM_AFO_R1_A MTK_M4U_ID(16, 9) 183 + #define M4U_PORT_L16_CAM_FLKO_R1_A MTK_M4U_ID(16, 10) 184 + #define M4U_PORT_L16_CAM_LCESO_R1_A MTK_M4U_ID(16, 11) 185 + #define M4U_PORT_L16_CAM_CRZO_R1_A MTK_M4U_ID(16, 12) 186 + #define M4U_PORT_L16_CAM_LTMSO_R1_A MTK_M4U_ID(16, 13) 187 + #define M4U_PORT_L16_CAM_RSSO_R1_A MTK_M4U_ID(16, 14) 188 + #define M4U_PORT_L16_CAM_AAHO_R1_A MTK_M4U_ID(16, 15) 189 + #define M4U_PORT_L16_CAM_LSCI_R1_A MTK_M4U_ID(16, 16) 190 + 191 + /* larb17 */ 192 + #define M4U_PORT_L17_CAM_IMGO_R1_B MTK_M4U_ID(17, 0) 193 + #define M4U_PORT_L17_CAM_RRZO_R1_B MTK_M4U_ID(17, 1) 194 + #define M4U_PORT_L17_CAM_CQI_R1_B MTK_M4U_ID(17, 2) 195 + #define M4U_PORT_L17_CAM_BPCI_R1_B MTK_M4U_ID(17, 3) 196 + #define M4U_PORT_L17_CAM_YUVO_R1_B MTK_M4U_ID(17, 4) 197 + #define M4U_PORT_L17_CAM_UFDI_R2_B MTK_M4U_ID(17, 5) 198 + #define M4U_PORT_L17_CAM_RAWI_R2_B MTK_M4U_ID(17, 6) 199 + #define M4U_PORT_L17_CAM_RAWI_R3_B MTK_M4U_ID(17, 7) 200 + #define M4U_PORT_L17_CAM_AAO_R1_B MTK_M4U_ID(17, 8) 201 + #define M4U_PORT_L17_CAM_AFO_R1_B MTK_M4U_ID(17, 9) 202 + #define M4U_PORT_L17_CAM_FLKO_R1_B MTK_M4U_ID(17, 10) 203 + #define M4U_PORT_L17_CAM_LCESO_R1_B MTK_M4U_ID(17, 11) 204 + #define M4U_PORT_L17_CAM_CRZO_R1_B MTK_M4U_ID(17, 12) 205 + #define M4U_PORT_L17_CAM_LTMSO_R1_B MTK_M4U_ID(17, 13) 206 + #define M4U_PORT_L17_CAM_RSSO_R1_B MTK_M4U_ID(17, 14) 207 + #define M4U_PORT_L17_CAM_AAHO_R1_B MTK_M4U_ID(17, 15) 208 + #define M4U_PORT_L17_CAM_LSCI_R1_B MTK_M4U_ID(17, 16) 209 + 210 + /* larb18 */ 211 + #define M4U_PORT_L18_CAM_IMGO_R1_C MTK_M4U_ID(18, 0) 212 + #define M4U_PORT_L18_CAM_RRZO_R1_C MTK_M4U_ID(18, 1) 213 + #define M4U_PORT_L18_CAM_CQI_R1_C MTK_M4U_ID(18, 2) 214 + #define M4U_PORT_L18_CAM_BPCI_R1_C MTK_M4U_ID(18, 3) 215 + #define M4U_PORT_L18_CAM_YUVO_R1_C MTK_M4U_ID(18, 4) 216 + #define M4U_PORT_L18_CAM_UFDI_R2_C MTK_M4U_ID(18, 5) 217 + #define M4U_PORT_L18_CAM_RAWI_R2_C MTK_M4U_ID(18, 6) 218 + #define M4U_PORT_L18_CAM_RAWI_R3_C MTK_M4U_ID(18, 7) 219 + #define M4U_PORT_L18_CAM_AAO_R1_C MTK_M4U_ID(18, 8) 220 + #define M4U_PORT_L18_CAM_AFO_R1_C MTK_M4U_ID(18, 9) 221 + #define M4U_PORT_L18_CAM_FLKO_R1_C MTK_M4U_ID(18, 10) 222 + #define M4U_PORT_L18_CAM_LCESO_R1_C MTK_M4U_ID(18, 11) 223 + #define M4U_PORT_L18_CAM_CRZO_R1_C MTK_M4U_ID(18, 12) 224 + #define M4U_PORT_L18_CAM_LTMSO_R1_C MTK_M4U_ID(18, 13) 225 + #define M4U_PORT_L18_CAM_RSSO_R1_C MTK_M4U_ID(18, 14) 226 + #define M4U_PORT_L18_CAM_AAHO_R1_C MTK_M4U_ID(18, 15) 227 + #define M4U_PORT_L18_CAM_LSCI_R1_C MTK_M4U_ID(18, 16) 228 + 229 + /* larb19 */ 230 + #define M4U_PORT_L19_IPE_DVS_RDMA MTK_M4U_ID(19, 0) 231 + #define M4U_PORT_L19_IPE_DVS_WDMA MTK_M4U_ID(19, 1) 232 + #define M4U_PORT_L19_IPE_DVP_RDMA MTK_M4U_ID(19, 2) 233 + #define M4U_PORT_L19_IPE_DVP_WDMA MTK_M4U_ID(19, 3) 234 + 235 + /* larb20 */ 236 + #define M4U_PORT_L20_IPE_FDVT_RDA MTK_M4U_ID(20, 0) 237 + #define M4U_PORT_L20_IPE_FDVT_RDB MTK_M4U_ID(20, 1) 238 + #define M4U_PORT_L20_IPE_FDVT_WRA MTK_M4U_ID(20, 2) 239 + #define M4U_PORT_L20_IPE_FDVT_WRB MTK_M4U_ID(20, 3) 240 + #define M4U_PORT_L20_IPE_RSC_RDMA0 MTK_M4U_ID(20, 4) 241 + #define M4U_PORT_L20_IPE_RSC_WDMA MTK_M4U_ID(20, 5) 242 + 243 + #endif
+15
include/dt-bindings/memory/mtk-memory-port.h
··· 1 + /* SPDX-License-Identifier: GPL-2.0-only */ 2 + /* 3 + * Copyright (c) 2020 MediaTek Inc. 4 + * Author: Yong Wu <yong.wu@mediatek.com> 5 + */ 6 + #ifndef __DT_BINDINGS_MEMORY_MTK_MEMORY_PORT_H_ 7 + #define __DT_BINDINGS_MEMORY_MTK_MEMORY_PORT_H_ 8 + 9 + #define MTK_LARB_NR_MAX 32 10 + 11 + #define MTK_M4U_ID(larb, port) (((larb) << 5) | (port)) 12 + #define MTK_M4U_TO_LARB(id) (((id) >> 5) & 0x1f) 13 + #define MTK_M4U_TO_PORT(id) ((id) & 0x1f) 14 + 15 + #endif
+7 -10
include/linux/io-pgtable.h
··· 68 68 * hardware which does not implement the permissions of a given 69 69 * format, and/or requires some format-specific default value. 70 70 * 71 - * IO_PGTABLE_QUIRK_TLBI_ON_MAP: If the format forbids caching invalid 72 - * (unmapped) entries but the hardware might do so anyway, perform 73 - * TLB maintenance when mapping as well as when unmapping. 74 - * 75 71 * IO_PGTABLE_QUIRK_ARM_MTK_EXT: (ARM v7s format) MediaTek IOMMUs extend 76 - * to support up to 34 bits PA where the bit32 and bit33 are 77 - * encoded in the bit9 and bit4 of the PTE respectively. 72 + * to support up to 35 bits PA where the bit32, bit33 and bit34 are 73 + * encoded in the bit9, bit4 and bit5 of the PTE respectively. 78 74 * 79 75 * IO_PGTABLE_QUIRK_NON_STRICT: Skip issuing synchronous leaf TLBIs 80 76 * on unmap, for DMA domains using the flush queue mechanism for ··· 84 88 */ 85 89 #define IO_PGTABLE_QUIRK_ARM_NS BIT(0) 86 90 #define IO_PGTABLE_QUIRK_NO_PERMS BIT(1) 87 - #define IO_PGTABLE_QUIRK_TLBI_ON_MAP BIT(2) 88 91 #define IO_PGTABLE_QUIRK_ARM_MTK_EXT BIT(3) 89 92 #define IO_PGTABLE_QUIRK_NON_STRICT BIT(4) 90 93 #define IO_PGTABLE_QUIRK_ARM_TTBR1 BIT(5) ··· 209 214 210 215 static inline void io_pgtable_tlb_flush_all(struct io_pgtable *iop) 211 216 { 212 - iop->cfg.tlb->tlb_flush_all(iop->cookie); 217 + if (iop->cfg.tlb && iop->cfg.tlb->tlb_flush_all) 218 + iop->cfg.tlb->tlb_flush_all(iop->cookie); 213 219 } 214 220 215 221 static inline void 216 222 io_pgtable_tlb_flush_walk(struct io_pgtable *iop, unsigned long iova, 217 223 size_t size, size_t granule) 218 224 { 219 - iop->cfg.tlb->tlb_flush_walk(iova, size, granule, iop->cookie); 225 + if (iop->cfg.tlb && iop->cfg.tlb->tlb_flush_walk) 226 + iop->cfg.tlb->tlb_flush_walk(iova, size, granule, iop->cookie); 220 227 } 221 228 222 229 static inline void ··· 226 229 struct iommu_iotlb_gather * gather, unsigned long iova, 227 230 size_t granule) 228 231 { 229 - if (iop->cfg.tlb->tlb_add_page) 232 + if (iop->cfg.tlb && iop->cfg.tlb->tlb_add_page) 230 233 iop->cfg.tlb->tlb_add_page(gather, iova, granule, iop->cookie); 231 234 } 232 235
+4 -3
include/linux/iommu.h
··· 170 170 * struct iommu_iotlb_gather - Range information for a pending IOTLB flush 171 171 * 172 172 * @start: IOVA representing the start of the range to be flushed 173 - * @end: IOVA representing the end of the range to be flushed (exclusive) 173 + * @end: IOVA representing the end of the range to be flushed (inclusive) 174 174 * @pgsize: The interval at which to perform the flush 175 175 * 176 176 * This structure is intended to be updated by multiple calls to the ··· 246 246 size_t (*unmap)(struct iommu_domain *domain, unsigned long iova, 247 247 size_t size, struct iommu_iotlb_gather *iotlb_gather); 248 248 void (*flush_iotlb_all)(struct iommu_domain *domain); 249 - void (*iotlb_sync_map)(struct iommu_domain *domain); 249 + void (*iotlb_sync_map)(struct iommu_domain *domain, unsigned long iova, 250 + size_t size); 250 251 void (*iotlb_sync)(struct iommu_domain *domain, 251 252 struct iommu_iotlb_gather *iotlb_gather); 252 253 phys_addr_t (*iova_to_phys)(struct iommu_domain *domain, dma_addr_t iova); ··· 539 538 struct iommu_iotlb_gather *gather, 540 539 unsigned long iova, size_t size) 541 540 { 542 - unsigned long start = iova, end = start + size; 541 + unsigned long start = iova, end = start + size - 1; 543 542 544 543 /* 545 544 * If the new page is disjoint from the current range or is mapped at
+1 -2
include/soc/mediatek/smi.h
··· 11 11 12 12 #ifdef CONFIG_MTK_SMI 13 13 14 - #define MTK_LARB_NR_MAX 16 15 - 16 14 #define MTK_SMI_MMU_EN(port) BIT(port) 17 15 18 16 struct mtk_smi_larb_iommu { 19 17 struct device *dev; 20 18 unsigned int mmu; 19 + unsigned char bank[32]; 21 20 }; 22 21 23 22 /*