drivers/iommu/mtk_iommu_v1.c
Source file repositories/reference/linux-study-clean/drivers/iommu/mtk_iommu_v1.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/iommu/mtk_iommu_v1.c- Extension
.c- Size
- 21074 bytes
- Lines
- 781
- Domain
- Driver Families
- Bucket
- drivers/iommu
- Inferred role
- Driver Families: implementation source
- Status
- source implementation candidate
Why This File Exists
Repeatable hardware-adapter layer. Deep compatibility for every driver is out of scope; this atlas records patterns, probe lifecycles, bus glue, IRQ/DMA usage, and links back to core abstractions.
- Repeatable hardware-adapter layer. Deep compatibility for every driver is out of scope; this atlas records patterns, probe lifecycles, bus glue, IRQ/DMA usage, and links back to core abstractions.
- Uses kernel synchronization; read lock ordering, sleepability, and interrupt context assumptions before translating.
- Touches IRQ or DMA behavior; this matters for the representative real-device path.
- Allocates kernel memory; connect allocation flags and lifetime to context constraints.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/bug.hlinux/clk.hlinux/component.hlinux/device.hlinux/dma-mapping.hlinux/err.hlinux/interrupt.hlinux/io.hlinux/iommu.hlinux/iopoll.hlinux/list.hlinux/module.hlinux/of_address.hlinux/of_irq.hlinux/of_platform.hlinux/platform_device.hlinux/slab.hlinux/spinlock.hlinux/string_choices.hasm/barrier.hdt-bindings/memory/mtk-memory-port.hdt-bindings/memory/mt2701-larb-port.hsoc/mediatek/smi.hasm/dma-iommu.h
Detected Declarations
struct dma_iommu_mappingstruct mtk_iommu_v1_suspend_regstruct mtk_iommu_v1_datastruct mtk_iommu_v1_domainfunction mtk_iommu_v1_bindfunction mtk_iommu_v1_unbindfunction mt2701_m4u_to_larbfunction mt2701_m4u_to_portfunction mtk_iommu_v1_tlb_flush_allfunction mtk_iommu_v1_tlb_flush_rangefunction mtk_iommu_v1_isrfunction mtk_iommu_v1_configfunction mtk_iommu_v1_domain_finalisefunction mtk_iommu_v1_domain_freefunction mtk_iommu_v1_attach_devicefunction mtk_iommu_v1_identity_attachfunction mtk_iommu_v1_mapfunction mtk_iommu_v1_unmapfunction mtk_iommu_v1_iova_to_physfunction mtk_iommu_v1_create_mappingfunction mtk_iommu_v1_probe_finalizefunction mtk_iommu_v1_release_devicefunction mtk_iommu_v1_hw_initfunction mtk_iommu_v1_probefunction mtk_iommu_v1_removefunction mtk_iommu_v1_suspendfunction mtk_iommu_v1_resume
Annotated Snippet
struct dma_iommu_mapping {
struct iommu_domain *domain;
};
#endif
#define REG_MMU_PT_BASE_ADDR 0x000
#define F_ALL_INVLD 0x2
#define F_MMU_INV_RANGE 0x1
#define F_INVLD_EN0 BIT(0)
#define F_INVLD_EN1 BIT(1)
#define F_MMU_FAULT_VA_MSK 0xfffff000
#define MTK_PROTECT_PA_ALIGN 128
#define REG_MMU_CTRL_REG 0x210
#define F_MMU_CTRL_COHERENT_EN BIT(8)
#define REG_MMU_IVRP_PADDR 0x214
#define REG_MMU_INT_CONTROL 0x220
#define F_INT_TRANSLATION_FAULT BIT(0)
#define F_INT_MAIN_MULTI_HIT_FAULT BIT(1)
#define F_INT_INVALID_PA_FAULT BIT(2)
#define F_INT_ENTRY_REPLACEMENT_FAULT BIT(3)
#define F_INT_TABLE_WALK_FAULT BIT(4)
#define F_INT_TLB_MISS_FAULT BIT(5)
#define F_INT_PFH_DMA_FIFO_OVERFLOW BIT(6)
#define F_INT_MISS_DMA_FIFO_OVERFLOW BIT(7)
#define F_MMU_TF_PROTECT_SEL(prot) (((prot) & 0x3) << 5)
#define F_INT_CLR_BIT BIT(12)
#define REG_MMU_FAULT_ST 0x224
#define REG_MMU_FAULT_VA 0x228
#define REG_MMU_INVLD_PA 0x22C
#define REG_MMU_INT_ID 0x388
#define REG_MMU_INVALIDATE 0x5c0
#define REG_MMU_INVLD_START_A 0x5c4
#define REG_MMU_INVLD_END_A 0x5c8
#define REG_MMU_INV_SEL 0x5d8
#define REG_MMU_STANDARD_AXI_MODE 0x5e8
#define REG_MMU_DCM 0x5f0
#define F_MMU_DCM_ON BIT(1)
#define REG_MMU_CPE_DONE 0x60c
#define F_DESC_VALID 0x2
#define F_DESC_NONSEC BIT(3)
#define MT2701_M4U_TF_LARB(TF) (6 - (((TF) >> 13) & 0x7))
#define MT2701_M4U_TF_PORT(TF) (((TF) >> 8) & 0xF)
/* MTK generation one iommu HW only support 4K size mapping */
#define MT2701_IOMMU_PAGE_SHIFT 12
#define MT2701_IOMMU_PAGE_SIZE (1UL << MT2701_IOMMU_PAGE_SHIFT)
#define MT2701_LARB_NR_MAX 3
/*
* MTK m4u support 4GB iova address space, and only support 4K page
* mapping. So the pagetable size should be exactly as 4M.
*/
#define M2701_IOMMU_PGT_SIZE SZ_4M
struct mtk_iommu_v1_suspend_reg {
u32 standard_axi_mode;
u32 dcm_dis;
u32 ctrl_reg;
u32 int_control0;
};
struct mtk_iommu_v1_data {
void __iomem *base;
int irq;
struct device *dev;
struct clk *bclk;
phys_addr_t protect_base; /* protect memory base */
struct mtk_iommu_v1_domain *m4u_dom;
struct iommu_device iommu;
struct dma_iommu_mapping *mapping;
struct mtk_smi_larb_iommu larb_imu[MTK_LARB_NR_MAX];
struct mtk_iommu_v1_suspend_reg reg;
};
struct mtk_iommu_v1_domain {
spinlock_t pgtlock; /* lock for page table */
struct iommu_domain domain;
u32 *pgt_va;
dma_addr_t pgt_pa;
struct mtk_iommu_v1_data *data;
};
Annotation
- Immediate include surface: `linux/bug.h`, `linux/clk.h`, `linux/component.h`, `linux/device.h`, `linux/dma-mapping.h`, `linux/err.h`, `linux/interrupt.h`, `linux/io.h`.
- Detected declarations: `struct dma_iommu_mapping`, `struct mtk_iommu_v1_suspend_reg`, `struct mtk_iommu_v1_data`, `struct mtk_iommu_v1_domain`, `function mtk_iommu_v1_bind`, `function mtk_iommu_v1_unbind`, `function mt2701_m4u_to_larb`, `function mt2701_m4u_to_port`, `function mtk_iommu_v1_tlb_flush_all`, `function mtk_iommu_v1_tlb_flush_range`.
- Atlas domain: Driver Families / drivers/iommu.
- Implementation status: source implementation candidate.
- Synchronization appears in or near this file; preserve lock ordering, sleepability, and interrupt-context constraints.
- IRQ or DMA behavior appears here, which is relevant to the selected PCIe/NVMe device path.
Implementation Notes
- This generated page is the file-by-file coverage layer; curated subsystem chapters should link here when they synthesize a multi-file control flow.
- Core OS pages should be promoted from atlas-only to deep-reviewed when they explain data structures, invariants, locking, lifecycle, and C implementation snippets.
- Driver-family pages are intentionally pattern-oriented unless they are part of the selected PCIe/NVMe representative device path.