drivers/iommu/sun50i-iommu.c
Source file repositories/reference/linux-study-clean/drivers/iommu/sun50i-iommu.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/iommu/sun50i-iommu.c- Extension
.c- Size
- 30320 bytes
- Lines
- 1092
- 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/bitfield.hlinux/bug.hlinux/clk.hlinux/device.hlinux/dma-direction.hlinux/dma-mapping.hlinux/err.hlinux/errno.hlinux/interrupt.hlinux/iommu.hlinux/iopoll.hlinux/ioport.hlinux/log2.hlinux/module.hlinux/of_platform.hlinux/platform_device.hlinux/pm.hlinux/pm_runtime.hlinux/reset.hlinux/sizes.hlinux/slab.hlinux/spinlock.hlinux/types.hiommu-pages.h
Detected Declarations
struct sun50i_iommustruct sun50i_iommu_domainenum sun50i_iommu_acifunction iommu_readfunction iommu_writefunction Tablefunction sun50i_iova_get_pte_indexfunction sun50i_iova_get_page_offsetfunction sun50i_dte_get_pt_addressfunction sun50i_dte_is_pt_validfunction sun50i_mk_dtefunction sun50i_pte_get_page_addressfunction sun50i_get_pte_acifunction sun50i_pte_is_page_validfunction sun50i_mk_ptefunction sun50i_table_flushfunction sun50i_iommu_zap_iovafunction sun50i_iommu_zap_ptw_cachefunction sun50i_iommu_zap_rangefunction sun50i_iommu_flush_all_tlbfunction sun50i_iommu_flush_iotlb_allfunction sun50i_iommu_iotlb_sync_mapfunction sun50i_iommu_iotlb_syncfunction sun50i_iommu_enablefunction sun50i_iommu_disablefunction sun50i_iommu_free_page_tablefunction sun50i_iommu_mapfunction sun50i_iommu_unmapfunction sun50i_iommu_iova_to_physfunction sun50i_iommu_domain_alloc_pagingfunction sun50i_iommu_domain_freefunction sun50i_iommu_attach_domainfunction sun50i_iommu_detach_domainfunction sun50i_iommu_identity_attachfunction sun50i_iommu_attach_devicefunction sun50i_iommu_of_xlatefunction sun50i_iommu_report_faultfunction sun50i_iommu_handle_pt_irqfunction sun50i_iommu_handle_perm_irqfunction sun50i_iommu_irqfunction sun50i_iommu_probe
Annotated Snippet
struct sun50i_iommu {
struct iommu_device iommu;
/* Lock to modify the IOMMU registers */
spinlock_t iommu_lock;
struct device *dev;
void __iomem *base;
struct reset_control *reset;
struct clk *clk;
struct iommu_domain *domain;
struct kmem_cache *pt_pool;
};
struct sun50i_iommu_domain {
struct iommu_domain domain;
/* Number of devices attached to the domain */
refcount_t refcnt;
/* L1 Page Table */
u32 *dt;
dma_addr_t dt_dma;
struct sun50i_iommu *iommu;
};
static struct sun50i_iommu_domain *to_sun50i_domain(struct iommu_domain *domain)
{
return container_of(domain, struct sun50i_iommu_domain, domain);
}
static struct sun50i_iommu *sun50i_iommu_from_dev(struct device *dev)
{
return dev_iommu_priv_get(dev);
}
static u32 iommu_read(struct sun50i_iommu *iommu, u32 offset)
{
return readl(iommu->base + offset);
}
static void iommu_write(struct sun50i_iommu *iommu, u32 offset, u32 value)
{
writel(value, iommu->base + offset);
}
/*
* The Allwinner H6 IOMMU uses a 2-level page table.
*
* The first level is the usual Directory Table (DT), that consists of
* 4096 4-bytes Directory Table Entries (DTE), each pointing to a Page
* Table (PT).
*
* Each PT consits of 256 4-bytes Page Table Entries (PTE), each
* pointing to a 4kB page of physical memory.
*
* The IOMMU supports a single DT, pointed by the IOMMU_TTB_REG
* register that contains its physical address.
*/
#define SUN50I_IOVA_DTE_MASK GENMASK(31, 20)
#define SUN50I_IOVA_PTE_MASK GENMASK(19, 12)
#define SUN50I_IOVA_PAGE_MASK GENMASK(11, 0)
static u32 sun50i_iova_get_dte_index(dma_addr_t iova)
{
return FIELD_GET(SUN50I_IOVA_DTE_MASK, iova);
}
static u32 sun50i_iova_get_pte_index(dma_addr_t iova)
{
return FIELD_GET(SUN50I_IOVA_PTE_MASK, iova);
}
static u32 sun50i_iova_get_page_offset(dma_addr_t iova)
{
return FIELD_GET(SUN50I_IOVA_PAGE_MASK, iova);
}
/*
* Each Directory Table Entry has a Page Table address and a valid
* bit:
* +---------------------+-----------+-+
* | PT address | Reserved |V|
* +---------------------+-----------+-+
* 31:10 - Page Table address
* 9:2 - Reserved
Annotation
- Immediate include surface: `linux/bitfield.h`, `linux/bug.h`, `linux/clk.h`, `linux/device.h`, `linux/dma-direction.h`, `linux/dma-mapping.h`, `linux/err.h`, `linux/errno.h`.
- Detected declarations: `struct sun50i_iommu`, `struct sun50i_iommu_domain`, `enum sun50i_iommu_aci`, `function iommu_read`, `function iommu_write`, `function Table`, `function sun50i_iova_get_pte_index`, `function sun50i_iova_get_page_offset`, `function sun50i_dte_get_pt_address`, `function sun50i_dte_is_pt_valid`.
- 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.