drivers/rpmsg/rpmsg_char.c
Source file repositories/reference/linux-study-clean/drivers/rpmsg/rpmsg_char.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/rpmsg/rpmsg_char.c- Extension
.c- Size
- 13750 bytes
- Lines
- 583
- Domain
- Driver Families
- Bucket
- drivers/rpmsg
- 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.
- 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/cdev.hlinux/device.hlinux/fs.hlinux/idr.hlinux/kernel.hlinux/module.hlinux/poll.hlinux/rpmsg.hlinux/skbuff.hlinux/slab.hlinux/uaccess.huapi/linux/rpmsg.hrpmsg_char.hrpmsg_internal.h
Detected Declarations
struct rpmsg_eptdevfunction rpmsg_chrdev_eptdev_destroyfunction rpmsg_ept_cbfunction rpmsg_ept_flow_cbfunction rpmsg_eptdev_openfunction rpmsg_eptdev_releasefunction rpmsg_eptdev_read_iterfunction rpmsg_eptdev_write_iterfunction rpmsg_eptdev_pollfunction rpmsg_eptdev_ioctlfunction name_showfunction src_showfunction dst_showfunction rpmsg_eptdev_release_devicefunction rpmsg_chrdev_eptdev_addfunction rpmsg_chrdev_eptdev_createfunction rpmsg_chrdev_probefunction rpmsg_chrdev_removefunction rpmsg_chrdev_initfunction rpmsg_chrdev_exitexport rpmsg_chrdev_eptdev_destroyexport rpmsg_chrdev_eptdev_create
Annotated Snippet
static const struct file_operations rpmsg_eptdev_fops = {
.owner = THIS_MODULE,
.open = rpmsg_eptdev_open,
.release = rpmsg_eptdev_release,
.read_iter = rpmsg_eptdev_read_iter,
.write_iter = rpmsg_eptdev_write_iter,
.poll = rpmsg_eptdev_poll,
.unlocked_ioctl = rpmsg_eptdev_ioctl,
.compat_ioctl = compat_ptr_ioctl,
};
static ssize_t name_show(struct device *dev, struct device_attribute *attr,
char *buf)
{
struct rpmsg_eptdev *eptdev = dev_get_drvdata(dev);
return sprintf(buf, "%s\n", eptdev->chinfo.name);
}
static DEVICE_ATTR_RO(name);
static ssize_t src_show(struct device *dev, struct device_attribute *attr,
char *buf)
{
struct rpmsg_eptdev *eptdev = dev_get_drvdata(dev);
return sprintf(buf, "%d\n", eptdev->chinfo.src);
}
static DEVICE_ATTR_RO(src);
static ssize_t dst_show(struct device *dev, struct device_attribute *attr,
char *buf)
{
struct rpmsg_eptdev *eptdev = dev_get_drvdata(dev);
return sprintf(buf, "%d\n", eptdev->chinfo.dst);
}
static DEVICE_ATTR_RO(dst);
static struct attribute *rpmsg_eptdev_attrs[] = {
&dev_attr_name.attr,
&dev_attr_src.attr,
&dev_attr_dst.attr,
NULL
};
ATTRIBUTE_GROUPS(rpmsg_eptdev);
static void rpmsg_eptdev_release_device(struct device *dev)
{
struct rpmsg_eptdev *eptdev = dev_to_eptdev(dev);
ida_free(&rpmsg_ept_ida, dev->id);
ida_free(&rpmsg_minor_ida, MINOR(eptdev->dev.devt));
kfree(eptdev);
}
static struct rpmsg_eptdev *rpmsg_chrdev_eptdev_alloc(struct rpmsg_device *rpdev,
struct device *parent)
{
struct rpmsg_eptdev *eptdev;
struct device *dev;
eptdev = kzalloc_obj(*eptdev);
if (!eptdev)
return ERR_PTR(-ENOMEM);
dev = &eptdev->dev;
eptdev->rpdev = rpdev;
mutex_init(&eptdev->ept_lock);
spin_lock_init(&eptdev->queue_lock);
skb_queue_head_init(&eptdev->queue);
init_waitqueue_head(&eptdev->readq);
device_initialize(dev);
dev->class = &rpmsg_class;
dev->parent = parent;
dev->groups = rpmsg_eptdev_groups;
dev_set_drvdata(dev, eptdev);
cdev_init(&eptdev->cdev, &rpmsg_eptdev_fops);
eptdev->cdev.owner = THIS_MODULE;
return eptdev;
}
static int rpmsg_chrdev_eptdev_add(struct rpmsg_eptdev *eptdev, struct rpmsg_channel_info chinfo)
{
struct device *dev = &eptdev->dev;
int ret;
Annotation
- Immediate include surface: `linux/cdev.h`, `linux/device.h`, `linux/fs.h`, `linux/idr.h`, `linux/kernel.h`, `linux/module.h`, `linux/poll.h`, `linux/rpmsg.h`.
- Detected declarations: `struct rpmsg_eptdev`, `function rpmsg_chrdev_eptdev_destroy`, `function rpmsg_ept_cb`, `function rpmsg_ept_flow_cb`, `function rpmsg_eptdev_open`, `function rpmsg_eptdev_release`, `function rpmsg_eptdev_read_iter`, `function rpmsg_eptdev_write_iter`, `function rpmsg_eptdev_poll`, `function rpmsg_eptdev_ioctl`.
- Atlas domain: Driver Families / drivers/rpmsg.
- 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.
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.