drivers/remoteproc/mtk_scp.c
Source file repositories/reference/linux-study-clean/drivers/remoteproc/mtk_scp.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/remoteproc/mtk_scp.c- Extension
.c- Size
- 44716 bytes
- Lines
- 1647
- Domain
- Driver Families
- Bucket
- drivers/remoteproc
- Inferred role
- Driver Families: exported/initcall integration point
- Status
- integration 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.
- Exports symbols or registers init work; inspect boot/module ordering and who consumes the exported contract.
- 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
asm/barrier.hlinux/clk.hlinux/dma-mapping.hlinux/err.hlinux/interrupt.hlinux/kernel.hlinux/module.hlinux/of_address.hlinux/of_platform.hlinux/of_reserved_mem.hlinux/platform_device.hlinux/remoteproc.hlinux/remoteproc/mtk_scp.hlinux/rpmsg/mtk_rpmsg.hlinux/string.hmtk_common.hremoteproc_internal.h
Detected Declarations
function scp_getfunction scp_putfunction scp_wdt_handlerfunction scp_init_ipi_handlerfunction scp_ipi_handlerfunction scp_ipi_initfunction mt8183_scp_reset_assertfunction mt8183_scp_reset_deassertfunction mt8192_scp_reset_assertfunction mt8192_scp_reset_deassertfunction mt8195_scp_c1_reset_assertfunction mt8195_scp_c1_reset_deassertfunction mt8183_scp_irq_handlerfunction mt8192_scp_irq_handlerfunction mt8195_scp_irq_handlerfunction mt8195_scp_c1_irq_handlerfunction scp_irq_handlerfunction scp_elf_load_segmentsfunction scp_elf_read_ipi_buf_addrfunction mt8183_scp_clk_getfunction mt8192_scp_clk_getfunction mt8195_scp_clk_getfunction mt8183_scp_before_loadfunction scp_sram_power_onfunction scp_sram_power_offfunction mt8186_scp_before_loadfunction mt8188_scp_l2tcm_onfunction mt8188_scp_before_loadfunction mt8188_scp_c1_before_loadfunction mt8192_scp_before_loadfunction mt8195_scp_l2tcm_onfunction mt8195_scp_before_loadfunction mt8195_scp_c1_before_loadfunction scp_loadfunction scp_parse_fwfunction scp_startfunction mt8183_scp_stopfunction mt8188_scp_l2tcm_offfunction mt8188_scp_stopfunction mt8188_scp_c1_stopfunction mt8192_scp_stopfunction mt8195_scp_l2tcm_offfunction mt8195_scp_stopfunction mt8195_scp_c1_stopfunction scp_stopfunction scp_preparefunction scp_unpreparefunction scp_get_device
Annotated Snippet
if (filesz > memsz) {
dev_err(dev, "bad phdr filesz 0x%x memsz 0x%x\n",
filesz, memsz);
ret = -EINVAL;
break;
}
if (offset + filesz > fw->size) {
dev_err(dev, "truncated fw: need 0x%x avail 0x%zx\n",
offset + filesz, fw->size);
ret = -EINVAL;
break;
}
/* grab the kernel address for this device address */
ptr = (void __iomem *)rproc_da_to_va(rproc, da, memsz, NULL);
if (!ptr) {
dev_err(dev, "bad phdr da 0x%x mem 0x%x\n", da, memsz);
ret = -EINVAL;
break;
}
/* put the segment where the remote processor expects it */
scp_memcpy_aligned(ptr, elf_data + phdr->p_offset, filesz);
}
return ret;
}
static int scp_elf_read_ipi_buf_addr(struct mtk_scp *scp,
const struct firmware *fw,
size_t *offset)
{
struct elf32_hdr *ehdr;
struct elf32_shdr *shdr, *shdr_strtab;
int i;
const u8 *elf_data = fw->data;
const char *strtab;
ehdr = (struct elf32_hdr *)elf_data;
shdr = (struct elf32_shdr *)(elf_data + ehdr->e_shoff);
shdr_strtab = shdr + ehdr->e_shstrndx;
strtab = (const char *)(elf_data + shdr_strtab->sh_offset);
for (i = 0; i < ehdr->e_shnum; i++, shdr++) {
if (strcmp(strtab + shdr->sh_name,
SECTION_NAME_IPI_BUFFER) == 0) {
*offset = shdr->sh_addr;
return 0;
}
}
return -ENOENT;
}
static int mt8183_scp_clk_get(struct mtk_scp *scp)
{
struct device *dev = scp->dev;
int ret = 0;
scp->clk = devm_clk_get(dev, "main");
if (IS_ERR(scp->clk)) {
dev_err(dev, "Failed to get clock\n");
ret = PTR_ERR(scp->clk);
}
return ret;
}
static int mt8192_scp_clk_get(struct mtk_scp *scp)
{
return mt8183_scp_clk_get(scp);
}
static int mt8195_scp_clk_get(struct mtk_scp *scp)
{
scp->clk = NULL;
return 0;
}
static int mt8183_scp_before_load(struct mtk_scp *scp)
{
/* Clear SCP to host interrupt */
writel(MT8183_SCP_IPC_INT_BIT, scp->cluster->reg_base + MT8183_SCP_TO_HOST);
/* Reset clocks before loading FW */
writel(0x0, scp->cluster->reg_base + MT8183_SCP_CLK_SW_SEL);
writel(0x0, scp->cluster->reg_base + MT8183_SCP_CLK_DIV_SEL);
Annotation
- Immediate include surface: `asm/barrier.h`, `linux/clk.h`, `linux/dma-mapping.h`, `linux/err.h`, `linux/interrupt.h`, `linux/kernel.h`, `linux/module.h`, `linux/of_address.h`.
- Detected declarations: `function scp_get`, `function scp_put`, `function scp_wdt_handler`, `function scp_init_ipi_handler`, `function scp_ipi_handler`, `function scp_ipi_init`, `function mt8183_scp_reset_assert`, `function mt8183_scp_reset_deassert`, `function mt8192_scp_reset_assert`, `function mt8192_scp_reset_deassert`.
- Atlas domain: Driver Families / drivers/remoteproc.
- Implementation status: integration 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.