drivers/cdx/controller/cdx_rpmsg.c
Source file repositories/reference/linux-study-clean/drivers/cdx/controller/cdx_rpmsg.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/cdx/controller/cdx_rpmsg.c- Extension
.c- Size
- 4596 bytes
- Lines
- 203
- Domain
- Driver Families
- Bucket
- drivers/cdx
- 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.
- 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/rpmsg.hlinux/remoteproc.hlinux/of.hlinux/platform_device.hlinux/cdx/cdx_bus.hlinux/module.h../cdx.hcdx_controller.hmcdi_functions.hmcdid.h
Detected Declarations
function cdx_rpmsg_sendfunction cdx_attach_to_rprocfunction cdx_detach_to_r5function cdx_rpmsg_cbfunction cdx_rpmsg_post_probe_workfunction cdx_rpmsg_probefunction cdx_rpmsg_removefunction cdx_setup_rpmsgfunction cdx_destroy_rpmsg
Annotated Snippet
// SPDX-License-Identifier: GPL-2.0
/*
* Platform driver for CDX bus.
*
* Copyright (C) 2022-2023, Advanced Micro Devices, Inc.
*/
#include <linux/rpmsg.h>
#include <linux/remoteproc.h>
#include <linux/of.h>
#include <linux/platform_device.h>
#include <linux/cdx/cdx_bus.h>
#include <linux/module.h>
#include "../cdx.h"
#include "cdx_controller.h"
#include "mcdi_functions.h"
#include "mcdid.h"
static struct rpmsg_device_id cdx_rpmsg_id_table[] = {
{ .name = "mcdi_ipc" },
{ },
};
MODULE_DEVICE_TABLE(rpmsg, cdx_rpmsg_id_table);
int cdx_rpmsg_send(struct cdx_mcdi *cdx_mcdi,
const struct cdx_dword *hdr, size_t hdr_len,
const struct cdx_dword *sdu, size_t sdu_len)
{
unsigned char *send_buf;
int ret;
send_buf = kzalloc(hdr_len + sdu_len, GFP_KERNEL);
if (!send_buf)
return -ENOMEM;
memcpy(send_buf, hdr, hdr_len);
memcpy(send_buf + hdr_len, sdu, sdu_len);
ret = rpmsg_send(cdx_mcdi->ept, send_buf, hdr_len + sdu_len);
kfree(send_buf);
return ret;
}
static int cdx_attach_to_rproc(struct platform_device *pdev)
{
struct device_node *r5_core_node;
struct cdx_controller *cdx_c;
struct cdx_mcdi *cdx_mcdi;
struct device *dev;
struct rproc *rp;
int ret;
dev = &pdev->dev;
cdx_c = platform_get_drvdata(pdev);
cdx_mcdi = cdx_c->priv;
r5_core_node = of_parse_phandle(dev->of_node, "xlnx,rproc", 0);
if (!r5_core_node) {
dev_err(&pdev->dev, "xlnx,rproc: invalid phandle\n");
return -EINVAL;
}
rp = rproc_get_by_phandle(r5_core_node->phandle);
if (!rp) {
ret = -EPROBE_DEFER;
goto pdev_err;
}
/* Attach to remote processor */
ret = rproc_boot(rp);
if (ret) {
dev_err(&pdev->dev, "Failed to attach to remote processor\n");
rproc_put(rp);
goto pdev_err;
}
cdx_mcdi->r5_rproc = rp;
pdev_err:
of_node_put(r5_core_node);
return ret;
}
static void cdx_detach_to_r5(struct platform_device *pdev)
{
struct cdx_controller *cdx_c;
struct cdx_mcdi *cdx_mcdi;
cdx_c = platform_get_drvdata(pdev);
Annotation
- Immediate include surface: `linux/rpmsg.h`, `linux/remoteproc.h`, `linux/of.h`, `linux/platform_device.h`, `linux/cdx/cdx_bus.h`, `linux/module.h`, `../cdx.h`, `cdx_controller.h`.
- Detected declarations: `function cdx_rpmsg_send`, `function cdx_attach_to_rproc`, `function cdx_detach_to_r5`, `function cdx_rpmsg_cb`, `function cdx_rpmsg_post_probe_work`, `function cdx_rpmsg_probe`, `function cdx_rpmsg_remove`, `function cdx_setup_rpmsg`, `function cdx_destroy_rpmsg`.
- Atlas domain: Driver Families / drivers/cdx.
- Implementation status: source implementation candidate.
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.