drivers/misc/fastrpc.c
Source file repositories/reference/linux-study-clean/drivers/misc/fastrpc.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/misc/fastrpc.c- Extension
.c- Size
- 63770 bytes
- Lines
- 2617
- Domain
- Driver Families
- Bucket
- drivers/misc
- 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.
- Touches user memory; correctness depends on fault-safe copying and privilege boundary handling.
- 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/completion.hlinux/device.hlinux/dma-buf.hlinux/dma-mapping.hlinux/dma-resv.hlinux/idr.hlinux/list.hlinux/miscdevice.hlinux/module.hlinux/of_address.hlinux/of.hlinux/platform_device.hlinux/sort.hlinux/of_platform.hlinux/rpmsg.hlinux/scatterlist.hlinux/slab.hlinux/firmware/qcom/qcom_scm.huapi/misc/fastrpc.hlinux/of_reserved_mem.hlinux/bits.h
Detected Declarations
struct fastrpc_phy_pagestruct fastrpc_invoke_bufstruct fastrpc_remote_dmahandlestruct fastrpc_remote_bufstruct fastrpc_mmap_rsp_msgstruct fastrpc_mmap_req_msgstruct fastrpc_mem_map_req_msgstruct fastrpc_munmap_req_msgstruct fastrpc_mem_unmap_req_msgstruct fastrpc_msgstruct fastrpc_invoke_rspstruct fastrpc_buf_overlapstruct fastrpc_bufstruct fastrpc_dma_buf_attachmentstruct fastrpc_mapstruct fastrpc_invoke_ctxstruct fastrpc_session_ctxstruct fastrpc_soc_datastruct fastrpc_channel_ctxstruct fastrpc_devicestruct fastrpc_userfunction fastrpc_ipa_to_dma_addrfunction fastrpc_sid_offsetfunction fastrpc_free_mapfunction fastrpc_map_putfunction fastrpc_map_getfunction fastrpc_map_lookupfunction fastrpc_buf_freefunction __fastrpc_buf_allocfunction fastrpc_buf_allocfunction fastrpc_remote_heap_allocfunction fastrpc_channel_ctx_freefunction fastrpc_channel_ctx_getfunction fastrpc_channel_ctx_putfunction fastrpc_user_freefunction list_for_each_entry_safefunction list_for_each_entry_safefunction fastrpc_user_getfunction fastrpc_user_putfunction fastrpc_context_freefunction fastrpc_context_getfunction fastrpc_context_putfunction fastrpc_context_put_wqfunction olaps_cmpfunction fastrpc_get_buff_overlapsfunction fastrpc_map_dma_buffunction fastrpc_unmap_dma_buffunction fastrpc_release
Annotated Snippet
static const struct file_operations fastrpc_fops = {
.open = fastrpc_device_open,
.release = fastrpc_device_release,
.unlocked_ioctl = fastrpc_device_ioctl,
.compat_ioctl = fastrpc_device_ioctl,
};
static int fastrpc_cb_probe(struct platform_device *pdev)
{
struct fastrpc_channel_ctx *cctx;
struct fastrpc_session_ctx *sess;
struct device *dev = &pdev->dev;
int i, sessions = 0;
unsigned long flags;
int rc;
u32 dma_bits;
cctx = dev_get_drvdata(dev->parent);
if (!cctx)
return -EINVAL;
of_property_read_u32(dev->of_node, "qcom,nsessions", &sessions);
spin_lock_irqsave(&cctx->lock, flags);
if (cctx->sesscount >= FASTRPC_MAX_SESSIONS) {
dev_err(&pdev->dev, "too many sessions\n");
spin_unlock_irqrestore(&cctx->lock, flags);
return -ENOSPC;
}
dma_bits = cctx->soc_data->dma_addr_bits_default;
sess = &cctx->session[cctx->sesscount++];
sess->used = false;
sess->valid = true;
sess->dev = dev;
dev_set_drvdata(dev, sess);
if (cctx->domain_id == CDSP_DOMAIN_ID)
dma_bits = cctx->soc_data->dma_addr_bits_cdsp;
if (of_property_read_u32(dev->of_node, "reg", &sess->sid))
dev_info(dev, "FastRPC Session ID not specified in DT\n");
if (sessions > 0) {
struct fastrpc_session_ctx *dup_sess;
for (i = 1; i < sessions; i++) {
if (cctx->sesscount >= FASTRPC_MAX_SESSIONS)
break;
dup_sess = &cctx->session[cctx->sesscount++];
memcpy(dup_sess, sess, sizeof(*dup_sess));
}
}
spin_unlock_irqrestore(&cctx->lock, flags);
rc = dma_set_mask(dev, DMA_BIT_MASK(dma_bits));
if (rc) {
dev_err(dev, "%u-bit DMA enable failed\n", dma_bits);
return rc;
}
return 0;
}
static void fastrpc_cb_remove(struct platform_device *pdev)
{
struct fastrpc_channel_ctx *cctx = dev_get_drvdata(pdev->dev.parent);
struct fastrpc_session_ctx *sess = dev_get_drvdata(&pdev->dev);
unsigned long flags;
int i;
spin_lock_irqsave(&cctx->lock, flags);
for (i = 0; i < FASTRPC_MAX_SESSIONS; i++) {
if (cctx->session[i].sid == sess->sid) {
cctx->session[i].valid = false;
cctx->sesscount--;
}
}
spin_unlock_irqrestore(&cctx->lock, flags);
}
static const struct of_device_id fastrpc_match_table[] = {
{ .compatible = "qcom,fastrpc-compute-cb", },
{}
};
static struct platform_driver fastrpc_cb_driver = {
.probe = fastrpc_cb_probe,
.remove = fastrpc_cb_remove,
.driver = {
.name = "qcom,fastrpc-cb",
.of_match_table = fastrpc_match_table,
Annotation
- Immediate include surface: `linux/completion.h`, `linux/device.h`, `linux/dma-buf.h`, `linux/dma-mapping.h`, `linux/dma-resv.h`, `linux/idr.h`, `linux/list.h`, `linux/miscdevice.h`.
- Detected declarations: `struct fastrpc_phy_page`, `struct fastrpc_invoke_buf`, `struct fastrpc_remote_dmahandle`, `struct fastrpc_remote_buf`, `struct fastrpc_mmap_rsp_msg`, `struct fastrpc_mmap_req_msg`, `struct fastrpc_mem_map_req_msg`, `struct fastrpc_munmap_req_msg`, `struct fastrpc_mem_unmap_req_msg`, `struct fastrpc_msg`.
- Atlas domain: Driver Families / drivers/misc.
- Implementation status: pattern implementation candidate.
- This snippet crosses the user/kernel memory boundary; validate fault handling and access checks before translating the pattern.
- 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.