drivers/media/platform/mediatek/vpu/mtk_vpu.c
Source file repositories/reference/linux-study-clean/drivers/media/platform/mediatek/vpu/mtk_vpu.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/media/platform/mediatek/vpu/mtk_vpu.c- Extension
.c- Size
- 26475 bytes
- Lines
- 1056
- Domain
- Driver Families
- Bucket
- drivers/media
- Inferred role
- Driver Families: operation-table or driver-model contract
- Status
- pattern 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.
- Defines an operation table; this is where Linux turns generic core objects into subsystem-specific behavior.
- 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/debugfs.hlinux/firmware.hlinux/interrupt.hlinux/iommu.hlinux/module.hlinux/of.hlinux/of_platform.hlinux/of_reserved_mem.hlinux/platform_device.hlinux/sched.hlinux/sizes.hlinux/dma-mapping.hmtk_vpu.h
Detected Declarations
struct vpu_memstruct vpu_regsstruct vpu_wdt_handlerstruct vpu_wdtstruct vpu_runstruct vpu_ipi_descstruct share_objstruct mtk_vpuenum vpu_fw_typefunction vpu_cfg_writelfunction vpu_cfg_readlfunction vpu_runningfunction vpu_clock_disablefunction vpu_clock_enablefunction vpu_dump_statusfunction vpu_ipi_registerfunction vpu_ipi_sendfunction vpu_wdt_reset_funcfunction vpu_wdt_reg_handlerfunction vpu_get_vdec_hw_capafunction vpu_get_venc_hw_capafunction load_requested_vpufunction vpu_load_firmwarefunction vpu_init_ipi_handlerfunction vpu_debug_readfunction vpu_free_ext_memfunction vpu_alloc_ext_memfunction vpu_ipi_handlerfunction vpu_ipi_initfunction vpu_irq_handlerfunction mtk_vpu_probefunction mtk_vpu_removefunction mtk_vpu_suspendfunction mtk_vpu_resumeexport vpu_ipi_registerexport vpu_ipi_sendexport vpu_wdt_reg_handlerexport vpu_get_vdec_hw_capaexport vpu_get_venc_hw_capaexport vpu_mapping_dm_addrexport vpu_get_plat_deviceexport vpu_load_firmware
Annotated Snippet
static const struct file_operations vpu_debug_fops = {
.open = simple_open,
.read = vpu_debug_read,
};
#endif /* CONFIG_DEBUG_FS */
static void vpu_free_ext_mem(struct mtk_vpu *vpu, u8 fw_type)
{
struct device *dev = vpu->dev;
size_t fw_ext_size = fw_type ? VPU_EXT_D_SIZE : VPU_EXT_P_SIZE;
dma_free_coherent(dev, fw_ext_size, vpu->extmem[fw_type].va,
vpu->extmem[fw_type].pa);
}
static int vpu_alloc_ext_mem(struct mtk_vpu *vpu, u32 fw_type)
{
struct device *dev = vpu->dev;
size_t fw_ext_size = fw_type ? VPU_EXT_D_SIZE : VPU_EXT_P_SIZE;
u32 vpu_ext_mem0 = fw_type ? VPU_DMEM_EXT0_ADDR : VPU_PMEM_EXT0_ADDR;
u32 vpu_ext_mem1 = fw_type ? VPU_DMEM_EXT1_ADDR : VPU_PMEM_EXT1_ADDR;
u32 offset_4gb = vpu->enable_4GB ? 0x40000000 : 0;
vpu->extmem[fw_type].va = dma_alloc_coherent(dev,
fw_ext_size,
&vpu->extmem[fw_type].pa,
GFP_KERNEL);
if (!vpu->extmem[fw_type].va) {
dev_err(dev, "Failed to allocate the extended program memory\n");
return -ENOMEM;
}
/* Disable extend0. Enable extend1 */
vpu_cfg_writel(vpu, 0x1, vpu_ext_mem0);
vpu_cfg_writel(vpu, (vpu->extmem[fw_type].pa & 0xFFFFF000) + offset_4gb,
vpu_ext_mem1);
dev_info(dev, "%s extend memory phy=0x%llx virt=0x%p\n",
fw_type ? "Data" : "Program",
(unsigned long long)vpu->extmem[fw_type].pa,
vpu->extmem[fw_type].va);
return 0;
}
static void vpu_ipi_handler(struct mtk_vpu *vpu)
{
struct share_obj __iomem *rcv_obj = vpu->recv_buf;
struct vpu_ipi_desc *ipi_desc = vpu->ipi_desc;
unsigned char data[SHARE_BUF_SIZE];
s32 id = readl(&rcv_obj->id);
memcpy_fromio(data, rcv_obj->share_buf, sizeof(data));
if (id < IPI_MAX && ipi_desc[id].handler) {
ipi_desc[id].handler(data, readl(&rcv_obj->len),
ipi_desc[id].priv);
if (id > IPI_VPU_INIT) {
vpu->ipi_id_ack[id] = true;
wake_up(&vpu->ack_wq);
}
} else {
dev_err(vpu->dev, "No such ipi id = %d\n", id);
}
}
static int vpu_ipi_init(struct mtk_vpu *vpu)
{
/* Disable VPU to host interrupt */
vpu_cfg_writel(vpu, 0x0, VPU_TO_HOST);
/* shared buffer initialization */
vpu->recv_buf = vpu->reg.tcm + VPU_DTCM_OFFSET;
vpu->send_buf = vpu->recv_buf + 1;
memset_io(vpu->recv_buf, 0, sizeof(struct share_obj));
memset_io(vpu->send_buf, 0, sizeof(struct share_obj));
return 0;
}
static irqreturn_t vpu_irq_handler(int irq, void *priv)
{
struct mtk_vpu *vpu = priv;
u32 vpu_to_host;
int ret;
/*
* Clock should have been enabled already.
* Enable again in case vpu_ipi_send times out
* and has disabled the clock.
*/
Annotation
- Immediate include surface: `linux/clk.h`, `linux/debugfs.h`, `linux/firmware.h`, `linux/interrupt.h`, `linux/iommu.h`, `linux/module.h`, `linux/of.h`, `linux/of_platform.h`.
- Detected declarations: `struct vpu_mem`, `struct vpu_regs`, `struct vpu_wdt_handler`, `struct vpu_wdt`, `struct vpu_run`, `struct vpu_ipi_desc`, `struct share_obj`, `struct mtk_vpu`, `enum vpu_fw_type`, `function vpu_cfg_writel`.
- Atlas domain: Driver Families / drivers/media.
- Implementation status: pattern 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.