drivers/iommu/sprd-iommu.c
Source file repositories/reference/linux-study-clean/drivers/iommu/sprd-iommu.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/iommu/sprd-iommu.c- Extension
.c- Size
- 13889 bytes
- Lines
- 543
- 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/clk.hlinux/device.hlinux/dma-mapping.hlinux/errno.hlinux/iommu.hlinux/mfd/syscon.hlinux/module.hlinux/of_platform.hlinux/platform_device.hlinux/regmap.hlinux/slab.h
Detected Declarations
struct sprd_iommu_devicestruct sprd_iommu_domainenum sprd_iommu_versionfunction sprd_iommu_writefunction sprd_iommu_readfunction sprd_iommu_update_bitsfunction sprd_iommu_get_versionfunction sprd_iommu_pgt_sizefunction sprd_iommu_first_vpnfunction sprd_iommu_vpn_rangefunction sprd_iommu_first_ppnfunction sprd_iommu_default_ppnfunction sprd_iommu_hw_enfunction sprd_iommu_cleanupfunction sprd_iommu_domain_freefunction sprd_iommu_attach_devicefunction sprd_iommu_mapfunction sprd_iommu_unmapfunction sprd_iommu_sync_mapfunction sprd_iommu_syncfunction sprd_iommu_iova_to_physfunction sprd_iommu_of_xlatefunction sprd_iommu_clk_enablefunction sprd_iommu_clk_disablefunction sprd_iommu_probefunction sprd_iommu_remove
Annotated Snippet
struct sprd_iommu_device {
struct sprd_iommu_domain *dom;
enum sprd_iommu_version ver;
u32 *prot_page_va;
dma_addr_t prot_page_pa;
void __iomem *base;
struct device *dev;
struct iommu_device iommu;
struct clk *eb;
};
struct sprd_iommu_domain {
spinlock_t pgtlock; /* lock for page table */
struct iommu_domain domain;
u32 *pgt_va; /* page table virtual address base */
dma_addr_t pgt_pa; /* page table physical address base */
struct sprd_iommu_device *sdev;
};
static const struct iommu_ops sprd_iommu_ops;
static struct sprd_iommu_domain *to_sprd_domain(struct iommu_domain *dom)
{
return container_of(dom, struct sprd_iommu_domain, domain);
}
static inline void
sprd_iommu_write(struct sprd_iommu_device *sdev, unsigned int reg, u32 val)
{
writel_relaxed(val, sdev->base + reg);
}
static inline u32
sprd_iommu_read(struct sprd_iommu_device *sdev, unsigned int reg)
{
return readl_relaxed(sdev->base + reg);
}
static inline void
sprd_iommu_update_bits(struct sprd_iommu_device *sdev, unsigned int reg,
u32 mask, u32 shift, u32 val)
{
u32 t = sprd_iommu_read(sdev, reg);
t = (t & (~(mask << shift))) | ((val & mask) << shift);
sprd_iommu_write(sdev, reg, t);
}
static inline int
sprd_iommu_get_version(struct sprd_iommu_device *sdev)
{
int ver = (sprd_iommu_read(sdev, SPRD_IOMMU_VERSION) &
SPRD_VERSION_MASK) >> SPRD_VERSION_SHIFT;
switch (ver) {
case SPRD_IOMMU_EX:
case SPRD_IOMMU_VAU:
return ver;
default:
return -EINVAL;
}
}
static size_t
sprd_iommu_pgt_size(struct iommu_domain *domain)
{
return ((domain->geometry.aperture_end -
domain->geometry.aperture_start + 1) >>
SPRD_IOMMU_PAGE_SHIFT) * sizeof(u32);
}
static struct iommu_domain *sprd_iommu_domain_alloc_paging(struct device *dev)
{
struct sprd_iommu_domain *dom;
dom = kzalloc_obj(*dom);
if (!dom)
return NULL;
spin_lock_init(&dom->pgtlock);
dom->domain.pgsize_bitmap = SPRD_IOMMU_PAGE_SIZE;
dom->domain.geometry.aperture_start = 0;
dom->domain.geometry.aperture_end = SZ_256M - 1;
dom->domain.geometry.force_aperture = true;
return &dom->domain;
}
Annotation
- Immediate include surface: `linux/clk.h`, `linux/device.h`, `linux/dma-mapping.h`, `linux/errno.h`, `linux/iommu.h`, `linux/mfd/syscon.h`, `linux/module.h`, `linux/of_platform.h`.
- Detected declarations: `struct sprd_iommu_device`, `struct sprd_iommu_domain`, `enum sprd_iommu_version`, `function sprd_iommu_write`, `function sprd_iommu_read`, `function sprd_iommu_update_bits`, `function sprd_iommu_get_version`, `function sprd_iommu_pgt_size`, `function sprd_iommu_first_vpn`, `function sprd_iommu_vpn_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.